Go Down

Topic: Help requested : Countdown timer  (Read 3083 times) previous topic - next topic

AMANVIRDI

NOOB ALERT

Firstly ,Sorry if this comes across as a basic/ elementary level query. Any help would be appreciated

Problem : LCD shows only " PRESS Button " and timer stuck at "00:00:00)

Trying to get a coutdown timer going when a push button is pressed , and relay comes on during countdown time .

Attached below is the sketch :

#include <Wire.h>
#include <LiquidCrystal.h>
#define relayPin 8 // the pin relay is connected
#define relayType L
const int relay_pin = 8;
const int button_pin = 10;
long duration;// holds the duration of time
long rememTime;// holds current run time
const int maxtime= 600;// max time 10 mins
int relayState=0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // put your setup code here, to run once:
 pinMode(relay_pin,OUTPUT);
  pinMode(button_pin,INPUT_PULLUP);

  lcd.begin(16, 2);
  // set up the LCD's number of columns and rows:
  lcd.setCursor(0, 0);
  // Print a message to the LCD.
  lcd.print("PRESS BUTTON");
  lcd.setCursor(4, 1);
  lcd.print("00:00:00");
    delay(2000);
 
}

void loop() {
  // put your main code here, to run repeatedly:
if (  button_pin == LOW){
lcd.clear();
lcd.print("PROCESS ON ");
rememTime=millis()/1000 ;
relayState= 1;
digitalWrite(relayPin, HIGH);
  }
  if(  ( millis()/1000- rememTime) > maxtime) {
relayState = 0;// change relay state to OFF
digitalWrite(relayPin, LOW);

  }
}

TheMemberFormerlyKnownAsAWOL

button_pin has the value 8.
LOW has the value 0.
They are never going to be equal.

You need to digitalRead(button_pin).

Please remember to use code tags when posting code
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

Go Up