Arduino Variable Timer Relay

Some electronic or electrical appliances needs time limited power supply, or usage of some devices are depends on limitted time. To automate electrical devices depends on time simple and robust solution given based on arduino. By using this Arduino Variable timer relay we can control high voltage electrical appliances or electronic devices.




To indicate the time duration and status 16×2 LCD display is included in this design, once the program uploaded to the Arduino then it can work independent with some external battery power source.

Connection Diagram

Construction and Working 

In this project arduino uno board is used to control SPDT (Single pole double throw) Relay and 16 x 2 character LCD indicates the time duration status. Digital pins D2 to D7 are connected to the LCD display. VR1 varible resistor helps to control the contrast of LCD display, Transistor Q1 BC547 reacts as a Switching device and controls the power supply to the Relay coil depends on arduino output.

There are three push buttons are placed to set different time durations, S1 Switch makes the count start, S2 changes the Hours and S3 changes the Minutes of time duration. Output signal from the Arduino is taken from D8 pin and it drives the Relay through transistor.

After making the connection, upload the following arduino sketch and pretest the operation with real timer clock.

Note:- Candle with extreme care if you using High voltage supply at the Relay end.

Arduino Code for Variable timer Relay

 

#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);
const int set = 9;
int hours=10;
int start=11; 
int relay=8;
int b=0,h=0,t=0;
int buttonState = 0; 
int lastButtonState = 0;
 
void setup() {
  
  pinMode(set,INPUT);
  pinMode(hours,INPUT);
  pinMode(relay,OUTPUT);
  pinMode(start,INPUT);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Adjustable Timer");  
}
int timer( int b,int h)
{
         if(b<=9)
           {
            lcd.setCursor(3,1);
            lcd.print(0);
            lcd.setCursor(4,1);
            lcd.print(b);
          }
     else{lcd.setCursor(3,1);lcd.print(b);}
         lcd.setCursor(2,1);
         lcd.print(":");
     if(h<=9)
           {
            lcd.setCursor(0,1);
            lcd.print(0);
            lcd.setCursor(1,1);
            lcd.print(h);
          }
     else{lcd.setCursor(0,1);lcd.print(h);}
  
  }
void loop() 
      {
  
         buttonState = digitalRead(set);
                  
       if (buttonState != lastButtonState)
       {  
        
       if(buttonState == HIGH)
         {
            
           lcd.clear();
           lcd.print("Set time in min:");
            
          ++b;
           timer(b,h);
                            
       }
          
         lastButtonState = buttonState;
          }

      if (digitalRead(hours)== HIGH)

         {
              lcd.clear();
              lcd.print("Set time in hours");
              ++h;
              timer(b,h);
              while(digitalRead(hours)==HIGH);
             
             
          }  

          if(digitalRead(start)==HIGH)
          {
             lcd.clear();
             t=((h*60)+(b))*1000;
             lcd.print("Timer is set for");
             timer(b,h);
             digitalWrite(relay,HIGH);
             delay(t);
             digitalWrite(relay,LOW);
             while(digitalRead(start) == HIGH );
                        
           }
             
     
      }





One Comment

  1. Tur June 5, 2018 Reply

Add a Comment

Your email address will not be published. Required fields are marked *