IAN LANG ELECTRONICS

A nice chucky-egg in the morning is just the thing to get you out to wherever it is you work (unless of course you work on an egg-farm and then you're probably sick of the sight of them, and then again you might be allergic to eggs and so it wouldn't be so I'll start again).

 

A nice chucky egg is just the thing to get people who are not allergic to eggs and don't work on an egg-farm out to work in the morning . Unless you don't like eggs. But I'm not starting again again.

 

The point of all that, in case you were wondering, is that your Arduino has remarkably accurate timing capabilities that you can exploit for your own ends. In this case we are going to make an egg timer using a single LED segment display, the 74HC595 and two buttons. Here's a circuit:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The observant amongst you will notice that it is almost exactly the same as the last one; the only difference being that we've hooked in the decimal point to pin 15 of the shift register. We're going to need to set up two switches and a piezo buzzer, the piezo buzzer needs to be attached to pin 12 on one side and GND on the other. It doesn't matter which way round. The switches we set up like this:

Arduino Project No 3

Go Back

Egg Timer with 7 Segment LED Display

Once again we are setting our switches to pull the default  on the pin low. There's no particular reason for choosing default low or high, it is just an irrational prejudice I've developed over time.

 

The input lead of one of your switches goes to pin 8 of your Arduino board, and this is the GO switch. The other goes to pin 9, and this is the set switch.

 

There follows some code to slap your board with:

5V

GND

Input Pin

int checkflag =0;

int time =0;

int arstart =-2;

int timearray []={182,120,183,150,158,180,159,210,204,240,205,270,218,300};

void setup(){

int x=2;while (x<5){

  pinMode (x,OUTPUT);x=x+1;}

  pinMode (8,INPUT);

  pinMode (9,INPUT);

  digitalWrite(4, LOW);

    shiftOut(2,3, MSBFIRST,126);  

    digitalWrite(4, HIGH);}

void loop (){

   if (checkflag==1){

 count ();}

 else{

if (digitalRead (9) ==1){

  arstart=arstart+2;

  if (arstart>12){

    arstart=0;}

  digitalWrite(4, LOW);

    shiftOut(2,3, MSBFIRST,timearray[arstart]);  

    digitalWrite(4, HIGH);

    delay (500);}}

 if (digitalRead (8) ==1){

  if (checkflag==0) {

checkflag=1;

time=0;

count ();}}}

void siren (){

  for (int t=0;t<24;t++){

   for (int j=200; j<400;j=j+5){

    tone (12,j,30);

delay (30);}}

  digitalWrite(4, LOW);

    shiftOut(2,3, MSBFIRST,126);  

    digitalWrite(4, HIGH);

checkflag=0;

arstart=-2;}

void count (){

   if(arstart !=-2);{

    delay (1000);

   time=time+1;

   if (timearray [arstart+1] !=time){}

   else{

     siren ();}}}

 

 

And assuming all has gone well, what should happen here is that the 7 segment display should show zero. Now if you press the set button, the display will show 2. This means two minutes. Press it again,and you get a figure 2 and the decimal point. This is two and a half minutes, or two minutes and thirty seconds if you will. Press again and you get a figure 3, three minutes, 3 and a decimal point means three mins thirty secs and so on up until 5.

 

The reason for this time range is that a proper English boiled egg should be three and a half to four minutes. The Americans believe that a boiled egg should be done between two and three minutes. They are of course wrong, but there are 300,000,000 of them and so if we were designing commercially we'd have to indulge their foibles. They're still wrong though. We just don't tell them so. Some of our European cousins believe that four to five minutes is a good time to boil an egg. They're Europeans. They don't know any better. But there are even more of those than there are Americans. Therefore, wrong as they all are, we must pander to them, whilst at the same time leaving room for the English way, which is of course the correct one. The Scots, Welsh and Irish do it our way too. They've learned.

 

So, set it for two minutes and then push the go button. Time it if you want to. After two minutes, the alarm will go off, and after that the display will set itself to zero. (There's no visible indicator that the circuit is active. As an exercise, see if you can include one.)

 

Do the same for the rest of the range and you should find a remarkable degree of accuracy.

 

Over the page we analyse the code as always.

 

 

More>

If you are a bit stuck on how to put a visual indicator in to see if the timer is active or not, here's one solution:

 

Solution