A simple countdown timer on Arduino
A sketch of an example of a countdown timer for Arduino.
This code provides an example of a Countdown Timer.
The action consists in setting the variable with the required number of seconds and after running the code, the time counts down. After the end, a notification is displayed.
#include <Wire.h> // library for I2C protocol
#include <LiquidCrystal_I2C.h> // library for LCD 1602
LiquidCrystal_I2C LCD(0x27, 16, 2); // assign a name to the display
int runTimer = 1;
int runFor = 900;
int buzzerPin = 13;
int relayPin = 4;
int data = 0;
void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(relayPin, OUTPUT);
LCD.begin();
LCD.backlight();
}
void loop() {
if(runTimer == 1){
digitalWrite(relayPin, LOW);
LCD.clear();
LCD.print("TIMER=");
//start timer
timer();
} else {
digitalWrite(relayPin, HIGH);
}
runTimer = 0;
LCD.noDisplay();
delay(250);
for(int duration = 0; duration < 100; duration ++){
digitalWrite(buzzerPin, HIGH);
delayMicroseconds(500);
digitalWrite(buzzerPin, LOW);
delayMicroseconds(500);
}
LCD.display();
delay(250);
}
void timer(){
for(int timer = runFor; timer > 0; --timer){
if(timer >= 10) {
LCD.setCursor(6,0);
}else{
LCD.setCursor(6,0);
LCD.print("0");
LCD.setCursor(7,0);
}
LCD.print(timer);
LCD.print("second");
delay(1000);
}
LCD.setCursor(0,0);
LCD.clear();
LCD.print("Alert");
}
Find out about the update of this script first in our telegram channel: https://t.me/proweblabxyz