Arduino Doctor Who Countdown timer prop - HELP!!!

Rustymetaldog

New Member
Hello RPF'ers,

I'm trying to conquer the world of Arduino to make this countdown timer prop.

Now this will seem pretty simple to those of you who know what you're doing, but I have spent HOURS and HOURS to get to this point, and am now stuck, which is where you come in!

I'm making a countdown timer, but after prototyping it with an UNO (which makes it work fine) why won't it work just the same on my NANO? I am totally stuck.

With the UNO, it counts down to 0000, from 9999 as soon as it powers on. Hit the button and it resets and begins to countdown again - great! With the NANO, it lights up as 9999, but the countdown won't start. Nothing happens at all.

I'm using the exact same pinout, switches and resistors on both boards, but cannot fathom out why it won't "run".

Here's the arduino sketch I have cobbled together after many failed attempts:

/*
Stop-Watch
Push button re-start the timer
*/

int a = 5;
int b = 7;
int c = 9;
int d = 11;
int e = 12;
int f = 6;
int g = 8;
int p = 10;

int d4 = 4;
int d3 = 3;
int d2 = 2;
int d1 = 1;

int startStopReset = 13;

long n = 9999000; //start time: 300000 = 30s seconds
int x = 100;
int del = 55;

void setup()
{
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(d4, OUTPUT);
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(p, OUTPUT);
pinMode(startStopReset, INPUT);
digitalWrite(startStopReset, LOW);
}

void loop()
{
clearLEDs();
pickDigit(1);
pickNumber((n/x/10000)%10);
delayMicroseconds(del);

clearLEDs();
pickDigit(2);
pickNumber((n/x/1000)%10);
delayMicroseconds(del);

clearLEDs();
pickDigit(3);
dispDec(3);
pickNumber((n/x/100)%10);
delayMicroseconds(del);

clearLEDs();
pickDigit(4);
pickNumber(n/x/10%10);
delayMicroseconds(del);

n--; //'n++' for stopwatch

if (digitalRead(13) == LOW)
{
n = 9999999; //re-start time: 200000 = 20s seconds
}
}

void pickDigit(int x)
{
digitalWrite(d1, HIGH);
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);

switch(x)
{
case 1:
digitalWrite(d1, LOW);
break;
case 2:
digitalWrite(d2, LOW);
break;
case 3:
digitalWrite(d3, LOW);
digitalWrite(p, HIGH); //new
break;
default:
digitalWrite(d4, LOW);
break;
}
}

void pickNumber(int x)
{
switch(x)
{
default:
zero();
break;
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
case 7:
seven();
break;
case 8:
eight();
break;
case 9:
nine();
break;
}
}

void dispDec(int x)
{
digitalWrite(p, LOW);
}

void clearLEDs()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(p, LOW);
}

void zero()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}

void one()
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}

void two()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
}

void three()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
}

void four()
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}

void five()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}

void six()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}

void seven()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}

void eight()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}

void nine()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}

Is it really obvious why it won't work on the NANO?

Here's an image of the wiring of it all, in case that helps too... this is the working Arduino UNO version

2016-10-22 15.05.58.jpg

PLEASE if anybody has any ideas, I'd be extremely interested to know if you can help me to fix this!

THANKS!

Andy
 
Hi Andy,

I too am just learning Arduino and I wanted to try my hand at your circuit.

Since I do not have 4 - 7 seg. displays to test the code in it's entirety, I
took 7 - 3mm leds and substituted them for the led's in a display.
I hooked up the 7 led's to a=5, b=7, c=9, d=11, e=12, f=6, g=8 outputs and tied all the cathodes
together (common cathode) to the lowest case number output pin 4.

I did notice that the countdown did not start at all. All the LED's stayed lit
signifying the number 9. I pressed the n/o button to pin 13 and it did not start the count down,
until I pulled pin 13 high with a 10k resistor. Then the reset button worked great.
Now each time I press the button it reset with no false (floating) signal.
Maybe this information will help with your NANO and that's all you need.....

I do have a question:

Does the counter hold at 0000 when complete ?

Here is a link to a quicky video:



.
 
Last edited by a moderator:
Propmaster 2000 thank you so much for trying this AND making a movie of it!

Very much appreciated, I'm glad it's working for you - but will it work on a Nano? That's my problem, I have it working fine on my Uno, but want it to work on my Nano....

If you can try it on a Nano AND get it to work, that would be amazing!

On my Nano set-up I've tried adding the 10k resistor on pin 13 by the switch, and sadly it hasn't made any difference, but I can see what you're thinking re the pull down of the current...

And regarding your question, I'm now waiting to see if it stops at 0000 when complete, I'm only at 8450 right now so it will be a little while!
 
James Purcell - which arduino forum, another one here on the RPF or the actual Arduino Site? Send me a link if there's somewheremore specific on the RPF to post this?

I was hoping this could be an interesting prop-based thing some of us would be interested in like the Iron Man Arduino threads, but I haven't posted anywhere else yet, just here, yesterday. I don't think you can have too many LED counters! And if you can actually understand how it works, even better!
 
Hi Rusty,

Instead of waiting for the timer to time out at the regular speed, change the value of [ int x = 100; ] to [ int x = 1; ] only during the test process
which will speed up the counter.
.
It will count down to 0000 much faster.
Once you have it as you want, then put the value back to 100.

FYI: I did this with my rudimentary set up and it does not stop at 0000.
It will start over at 9999 and continue to count down from there.

.
 
Last edited:
propmaster 2000 - yes, I can see how this changes the speed, thnaks!

My only issue is I can't get any of it to work with my Nano.

And re your quesiton, once it gets to 0000 it just stops, displaying 0000 until I press the button to reset to 9999 when it begins the countdown afresh....
 
Last edited by a moderator:
I received my 4 Number - 7 segment display and wired it to my UNO with the countdown sketch and as before it
does not stop at all zeros when the countdown is complete. It just repeats again.

Are you having any luck getting the sketch to work with a NANO?
 
Last edited:
Hello! I'm having much more sucess using an Adafruit backpack display! Just found them and trying to understand the code to make it do what I need...
 
I think I will continue to fiddle with the sketch to see if I can get it to work with my UNO better, as well as a NANO I just got.
The counting part seems to work OK for me on the UNO, but it won't stop counting at 0000. It just repeats.

I did load the sketch to my NANO and it doesn't count at all. It just sits at 9999 :^(

ADDED NOTE:

I went to the Adafruit web sight and checked out the backpack display.
Ya only need 4 wires (2-power and 2-data) to make it work from an UNO or probably even the NANO or smaller......
(pro-micro, pro--mini, trinket, etc.)
Just create the code, send to display with a suitable controller and make it count. Nice.

I think if you want it to be a real time counter, ya may need a real time clock chip.

If ya feel like posting your progress with the backpack, I'd be interested in seeing what you come up with.
 
Last edited:
Propmaster2000 - I bought the Adafruit display - it is INFINITELY better than the previous way I was attemptimg this.

Only 4 wires between the LED and the UNO, AND it works with the NANO, though the pinout diagrams for the NANO seem to differ everywhere you look... but I got it working.

I couldn't have done it without all the learning from the "original" method, and am now looking into how I can modify the sketch code to make it run the numbers in different ways, but it seems feasible. I don't know much about coding though...

I'm also keen to add a switch to start it running, but now I have the Adafruit unit I think it is possible, I'll post more as it happens!
 
Nice! That's good to know.
I am glad you have found the answer to your dilemma .
The Adafruit LED display backpack sounds like the way to go.

LED timers and counters are getting harder to find these days unless you build your own (LCD seems to be the norm).
I did manage to get the original sketch to work in my UNO.
I ended up putting a smaller value resistor to pin 13 (of the start switch) and fiddled with the code a bit.
It's a bit to late however since you found a way better option :^)

Still wanting the NANO to work as well.....funny how I've adopted your original issue with the NANO :^/
Oh well, I dig a challenge.
 
I'm sorry you now have MY old problem!

Seems like the Adafruit is working well - the sketch is easy to modify what's displayed, and it WORKS! Even with the NANO!!!

The pinout diagram for the NANO is different everywhere you look - trust me, get the Adafruit and you'll be very happy - life's too short!
 
No problems. I like to see if I can mess around with the code and make it do what works for me.
That being said,

Do you know how I can add an output signal (LED indication?) when the counter reaches and holds at 0000 ?
Id like to maybe add a buzzer or light......

I don't know enough about coding or where to add it without messing up the counter code itself.

:^(

Thanks for any advise you wish to offer.

propmaster2000

.
 
If I understand the original code rightly: there are four digits, selected by d1/d4 (Arduino pins D1 through D4) low; and each of the 7-segment displays is wired in parallel so that segment A for each is connected to pin D5; B to D7; and so on through G (common cathode to ground). 'p' is special - the decimal after display 3. There's also a button on pin D13 that pulls to ground, from what I see in the wiring.

In which case, I think the original problem (and the reason that the Nano wasn't counting down, but staying on 9999) is that you've got input for pin 13 set wrong. You want

pinMode(13, INPUT);
digitalWrite(13, HIGH); // enable internal pull-up resistor

... which just means that pin 13 will be at +5v input, until you press the button. When you push the button, it will be connected to ground, and the voltage drops to 0. Which means that digitalRead(13) will return HIGH normally, and then LOW when the button is pressed.

To add an output when it reaches zero, first you need to pick a pin - I'll pick A0 - and set it up as an output, like

pinMode(A0, OUTPUT);

... and then when the count reaches zero, just do a

digitalWrite(A0, HIGH);

... clearing it again when the button is pressed with

digitalWrite(A0, LOW);


... all of which might look like this, if I were to rewrite it. Note: this is completely untested but was a fun lunch exercise. :)


Code:
#include <Arduino.h>
#include <TimerOne.h> // see http://playground.arduino.cc/Code/Timer1


#define MAXTIMER 9999
int currentValue = MAXTIMER;


int segments[7] = { 5, 7, 9, 11, 12, 6, 8 };
int p = 10;


int digits[10][7] = { { 1, 1, 1, 1, 1, 1, 0 }, // 0
           { 0, 1, 1, 0, 0, 0, 0 }, // 1
           { 1, 1, 0, 1, 1, 0, 1 }, // 2
           { 1, 1, 1, 1, 0, 0, 1 }, // 3
           { 0, 1, 1, 0, 0, 1, 1 }, // 4
           { 1, 0, 1, 1, 0, 1, 1 }, // 5
           { 1, 0, 1, 1, 1, 1, 1 }, // 6
           { 1, 1, 1, 0, 0, 0, 0 }, // 7
           { 1, 1, 1, 1, 1, 1, 1 }, // 8
           { 1, 1, 1, 1, 0, 1, 1 }  // 9
};


int displays[4] = { 4, 3, 2, 1 }; // from lowest value to highest value


int startStopReset = 13;
int alarmPin = A0;
int delayBetweenDigits = 55;


void setup()
{
  for (int i=0; i<7; i++) {
    pinMode(segments[i], OUTPUT);
  }


  pinMode(p, OUTPUT);
  
  for (int i=0; i<4; i++) {
    pinMode(displays[i], OUTPUT);
  }


  pinMode(alarmPin, OUTPUT);


  pinMode(startStopReset, INPUT);
  digitalWrite(startStopReset, HIGH); // enable internal pull-up resistor
  
  Timer1.initialize(100000); // Fire every one tenth of a second
  Timer1.attachInterrupt(timerFired);
}


void timerFired()
{
  if (currentValue > 0) {
    currentValue--;
  } else {
    digitalWrite(alarmPin, HIGH);
  }
}


void loop()
{
  // check the switch for a reset condition
  if (digitalRead(startStopReset) == LOW) {
    currentValue = MAXTIMER;     // reset the timer
    digitalWrite(alarmPin, LOW); // reset the alarm
  }
  
  // Display the numbers
  int multiplier = 1;
  for (int i=0; i<4; i++) {
    outputDigit(i, ((currentValue / multiplier) % 10));
    multiplier *= 10;
  }
}


void outputDigit(int digitIndex, int value)
{
  // Clear all of the segments; we don't want to accidentally display
  // the numbers for (e.g.) display #0 on display #1, while we're switching.
  for (int i=0; i<7; i++) {
    digitalWrite(segments[i], LOW);
  }
  // Turn off the decimal
  digitalWrite(p, LOW);


  // Clear the four displays; don't want a number to appear where it doesn't
  // belong
  for (int i=0; i<4; i++) {
    digitalWrite(displays[i], HIGH);
  }


  // switch to the display that we want to update
  digitalWrite(displays[digitIndex], LOW);


  // Write the new digit on that display
  for (int i=0; i<7; i++) {
    digitalWrite(segments[i], digits[value][i]);
  }
  // Display the decimal after the third display (0, 1, 2 -- so #2 is
  // the third)
  if (digitIndex == 2) {
    digitalWrite(p, HIGH);
  }
  
  // Let it sit on the display long enough to see it
  delayMicroseconds(delayBetweenDigits);
}
 
Thanks jorj for the input :^)

I ended up adding an ext. pull up resistor to pin 13 and that seemed to solve my problem.

The pullup pin 13 with the internal resistor code didn't work for me.

Thanks for the new code (sketch above) as well.

P.S. I am also looking into the Adafruit green backpack matrix/7seg. display.
It is kind of an interesting way to make a counter/timer.
I think to make it an accurate timer, it needs an external clock however.
DS1307
https://www.adafruit.com/product/264
https://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/assembly?view=all



propmaster2000 .
 
Last edited by a moderator:
I managed to fiddle with the sketch code of the Adafruit Backback display to get it to count down from any number I set.
3600 seconds is 60 minutes (1 hr.)
Works pretty well.


propmaster2000

.
 
Last edited by a moderator:
Hey Rustymetaldog,

Did you ever get your seven seg. display to do what you had originally planned for it (countdown timer/counter)?
I know that the backpack display is much easier to use (only a 4 wire connection) and apparently it works with a NANO controller.

I did notice that the backpack 4 digit, 7 segment display is a bit larger in size then my original 4 digit display.
Looking forward to your progress.

.
 
One thing about the green backpack display in my case is that it is a bit bright in low light.
I've been trying to figure out how to dim the display within the code.

Adafruit indicates that it can be done with a small amount of code (brightness setting), but I can't figure out where and how to use it.

.
 
Last edited:
This thread is more than 7 years old.

Your message may be considered spam for the following reasons:

  1. This thread hasn't been active in some time. A new post in this thread might not contribute constructively to this discussion after so long.
If you wish to reply despite these issues, check the box below before replying.
Be aware that malicious compliance may result in more severe penalties.
Back
Top