Wednesday, April 22, 2020

Arduino Programmable On/Off Timer Switch for Automation


COMPONENTS ARE REQUIRED:-

1 arduino uno 
3 switches
4 10k ohm resistor
1 wood box
1 liquid crystal LCD 12*2
1 5v relay
1 silicon diode
1 socket
1 button
.....some jumpers wire

CODE:-

#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);
const int set = 8;
int hours=10;
int start=11; 
int relay=9;
long b=0,h=0;
long 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(8,1);
            lcd.print(0);
            lcd.setCursor(9,1);
            lcd.print(b); 
  }
     else{lcd.setCursor(8,1);
     lcd.print(b);}
         lcd.setCursor(0,1);
         lcd.print("=====");
         lcd.setCursor(7,1);
         lcd.print(":");
         lcd.setCursor(10,1);
         lcd.print("=====");
     if(h<=9)
           {
            lcd.setCursor(5,1);
            lcd.print(0);
            lcd.setCursor(6,1);
            lcd.print(h);
          }
     else{lcd.setCursor(5,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*3600)+(b*60))*1000;
             lcd.print("Timer is set for");
             timer(b,h);
             digitalWrite(relay,HIGH);
             delay(t);
             digitalWrite(relay,LOW);
             while(digitalRead(start) == HIGH );
            }
             }


2 comments:

  1. Good articles, Have you heard of LFDS (Le_Meridian Funding Service, Email: lfdsloans@outlook.com --WhatsApp Contact:+1-9893943740--lfdsloans@lemeridianfds.com) is as USA/UK funding service they grant me loan of $95,000.00 to launch my business and I have been paying them annually for two years now and I still have 2 years left although I enjoy working with them because they are genuine Loan lender who can give you any kind of loan.

    ReplyDelete
  2. Great explanation. It helped a lot. Thanks for sharing this.

    amazon discount code

    ReplyDelete