Programmable timer with arduino

Programmable timer 

https://projectsnproduct.blogspot.com/2020/04/arduino-programmable-onoff-timer-switch.html?m=1







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 );

            }

             }



Comments

Popular posts from this blog

Proteus simulation 4x4 Matrix Keypad with Arduino and LCD screen

Digital Clock with Arduino and RTC Module and P10 LEDmatrix

Interfacing KY038 sound sensor with Raspberry pi Pico