Timer switch with Relay and LCD Arduino code

A timer switch is an electrical switch that is operated by means of a timer circuit or timer mechanism that measures specific time intervals. It can be used to switch ON or OFF a device after a particular period of time set by the user.

In the below circuit, the output of the Arduino is connected to a relay module that can be used to ON or OFF appliances connected to an external supply like an AC power source, battery supply, etc.

This is a basic program to switch off the device after a particular time period since it is switched ON. When we power on the circuit the output pin 9 will be in a low state by default. Hence the Load connected to the relay will remain OFF. In the circuit a push-button is connected to pin2, it is the ON button to turn ON the output. Once it is pressed the output at pin 9 switches to a high state, the relay energizes and the relay contacts switch to NO terminal which switches ON the load or appliances connected to it.

Arduino Switch OFF Timer - Code

const int switch_on = 2, output = 9;
int offtime = 1, off_timer_start = 0;
void setup() {
  pinMode(switch_on, INPUT);
  pinMode(output, OUTPUT);
}

void loop() {
  int x = ((millis() / 1000) - off_timer_start) / 60;
  if (digitalRead(switch_on) == HIGH) {
    off_timer_start = (millis() / 1000);
    digitalWrite(output, HIGH);
  } else if (x >= offtime && digitalRead(output == HIGH)) {
    digitalWrite(output, LOW);
  }
  delay(1000);
}
Previous
Previous

Switch OFF timer with time adjust and LCD display

Next
Next

Arduino Push Button Counter Code LCD Circuit