Arduino Relay Timer


4,189

5

4

Ref Link::: Arduino Alarm

https://www.picmicrolab.com/lcd-digital-alarm-cloc...

Timers were used in many applications in our day to day life.One can see the timers in washing machines,micro ovens etc. These devices uses timer to switch the loads for particular amount of time.Traditionally, various loads would have been manually controlled, i.e., the operator would turn ON the loads and after desired conditions met, the loads again would have been turned off by the operator.

Here i am going to explain about Arduino Relay Timer, which doesn't require any External Real Time Clock module like DS1307.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Circuit Explanation

Components

  • Arduino Board
  • LCD
  • Push buttons
  • Relay

Working
Initially when the circuit is switched LCD will display ” adjustable timer By Technical Hub”.after 2 secs the lcd will again shows the

Count 0:00:00

set to 0:00:00

  • Press the switch /push button (select button / connected to arduino pin 11)
  • Now using the two buttons(mins and hours (connected to arduino pin 8,9 resp..)) set the timer.Button connected to 8th pin is used to set the timer in minutes and button connected to 9th pin is used to set the timer in hours.
  • Set the time by pressing these buttons.When each button is pressed , time is incremented every time.
  • Now click on start button to switch the load.
  • When the count time == set to time load will be switched off automatically.
  • To set the timer next time click the reset button on the arduino and set the timer again.

Step 2: Code

you can download it from here:

https://drive.google.com/open?id=15DpFyfoZkwJoXggZ...

OR

You can copy and paste the following code

#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);

int TimeHours10s =  0;
int TimeHours1s =  0;
int TimeMinutes10s =  0;
int TimeMinutes1s =  0;
int TimeSeconds10s =  0;
int TimeSeconds1s =  0;
int AlarmHours10s =  0;
int AlarmHours1s =  0;
int AlarmMinutes10s =  0;
int AlarmMinutes1s =  0;
int AlarmSeconds10s =  0;
int AlarmSeconds1s =  0;

int t=0;
int l=0;
int Select = 11;
int start = 10;
int Min = 8;
int Hour = 9;
int Buzzer =12;

void setup() 
{
  // initialize I/O pins.
  
  pinMode(Select,INPUT);  //
  pinMode(start, INPUT);  //
  pinMode(Hour, INPUT);  //
  pinMode(Min, INPUT);  //
  pinMode(Buzzer, OUTPUT);  //
  
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.print("Adjustable Timer"); 
  lcd.setCursor(0,1);
  lcd.print("By Tech garage");
  delay(2000);
  lcd.clear();
}

void loop() 
{
  
//CalculateTime();  
ShowTime();
ShowAlarm();
delay(500);
CompareAlarmTime();
//-------------------------------------setting up Alarm Value------------

if (digitalRead(Select)== HIGH)
{
  t=1;
  }
if(t==1 && digitalRead(Min)== HIGH)
{
  AlarmMinutes1s++;
  delay(500);
  CalculateAlarm();
}
if(t==1 && digitalRead(Hour)== HIGH)
{
  AlarmHours1s++;
  delay(500);
  CalculateAlarm();
}
//----------------------------------------------------------------

if(digitalRead(start)== HIGH)
{
  l=1;

 }
  if(l==1)
  {   CalculateTime();
  }
delay(500);
}

void ShowTime()
  {
  //--------------------------------------------
  // Turn on the display
  lcd.display();
  lcd.setCursor(0, 0); // top left
  lcd.print("Count  ");//
  if(TimeHours10s == 0)
  lcd.print(" ");//
  else
  lcd.print(TimeHours10s);//
  lcd.print(TimeHours1s);//
  lcd.print(":");//
  lcd.print(TimeMinutes10s);//
  lcd.print(TimeMinutes1s);//
  lcd.print(":");//
  lcd.print(TimeSeconds10s);//
  lcd.print(TimeSeconds1s);//
  lcd.setCursor(0, 0); // top left
  }

void ShowAlarm()
  {
  //--------------------------------------------
  // Turn on the display
  //lcd.display();
  lcd.setCursor(0, 1); // bottom left
  lcd.print("set to ");//
  if(AlarmHours10s == 0)
  lcd.print(" ");//
  else
  lcd.print(AlarmHours10s);//
  lcd.print(AlarmHours1s);//
  lcd.print(":");//
  lcd.print(AlarmMinutes10s);//
  lcd.print(AlarmMinutes1s);//
  lcd.print(":");//
  lcd.print(AlarmSeconds10s);//
  lcd.print(AlarmSeconds1s);//
  lcd.setCursor(0, 1); // bottom left
  }

void CalculateTime()
{
 TimeSeconds1s++;
  if(TimeSeconds1s == 10)
  {
  TimeSeconds1s = 0;
  TimeSeconds10s++;
  }
  if(TimeSeconds10s == 6)
  {
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeMinutes1s++;
  }
  if(TimeMinutes1s == 10)
  {
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeMinutes10s++;
  }
  if(TimeMinutes10s == 6)
  {
  TimeMinutes10s = 0;
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeHours1s++;
  }
  if(TimeHours1s == 10) 
  {
  TimeHours1s=0;
  TimeMinutes10s = 0;
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
  TimeHours10s++;
  }
  if(TimeHours10s == 2 && TimeHours1s == 4) 
  {
  TimeHours10s=0; 
  TimeHours1s=0;
  TimeMinutes10s = 0;
  TimeMinutes1s = 0;
  TimeSeconds10s = 0;
  TimeSeconds1s = 0;
 
  } 
}

 void CalculateAlarm()
{
 //AlarmSeconds1s++;
  if(AlarmSeconds1s == 10)
  {
  AlarmSeconds1s = 0;
  AlarmSeconds10s++;
  }
  if(AlarmSeconds10s == 6)
  {
  AlarmSeconds10s = 0;
  AlarmSeconds1s = 0;
  AlarmMinutes1s++;
  }
  if(AlarmMinutes1s == 10)
  {
  AlarmMinutes1s = 0;
  AlarmSeconds10s = 0;
  AlarmSeconds1s = 0;
  AlarmMinutes10s++;
  }
  if(AlarmMinutes10s == 6)
  {
  AlarmMinutes10s = 0;
  AlarmMinutes1s = 0;
  AlarmSeconds10s = 0;
  AlarmSeconds1s = 0;
  AlarmHours1s++;
  }
  if(AlarmHours1s == 10) 
  {
  AlarmHours1s=0;
  AlarmMinutes10s = 0;
  AlarmMinutes1s = 0;
  AlarmSeconds10s = 0;
  AlarmSeconds1s = 0;
  AlarmHours10s++;
  }
  if(AlarmHours10s == 2 && AlarmHours1s == 4) 
  {
  AlarmHours10s=0; 
  AlarmHours1s=0;
  AlarmMinutes10s = 0;
  AlarmMinutes1s = 0;
  AlarmSeconds10s = 0;
  AlarmSeconds1s = 0;
  } 
}
 void CompareAlarmTime()
 {
  if(TimeHours10s >= AlarmHours10s && TimeHours1s >= AlarmHours1s && TimeMinutes10s >= AlarmMinutes10s && TimeMinutes1s >= AlarmMinutes1s )
  {
   digitalWrite(Buzzer, LOW); 
   
  }
  else
  {digitalWrite(Buzzer, HIGH); 
    }
  
 }

Step 3: Testing the Output

https://www.youtube.com/watch?v=SlKp6gJXyFE

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    4 Discussions

    None
    Ciza

    Question 2 months ago on Step 2

    Can you explain me instruction by instruction in order to know well about the this codes

    1 answer
    None
    BhaskarP6Ciza

    Answer 2 months ago

    i don't have time for that sorry mate, now i've written comments in the program check it once

    None
    Ciza

    2 months ago on Step 1

    I've tried this kind of project and i got the problem in counting where I 've used the clock for counting in order to see if the counting is perfect but I found the counting is not perfect so, how can I solve this problem so why the counting sequence will follow as for the clock or watch when I use chronometer

    1 reply
    None
    BhaskarP6Ciza

    Reply 2 months ago

    see arduino does has inbuilt watch dog timer, so you can rely on it or else you need to add some external clock like DS1307. may be the bug might be in your code like you might have put delays or smething like that, if possible post your code here