How to make a Countdown on 16x2 LCD

I want to make it so once i upload the sketch the countdown starts for 5 min and when the time is up a buzzer goes off. im using a 16x2 LCD and a Ardruino UNO R3 Board

The image is how i have my LCD set up and i dont know where to put the buzzer or how to connect it

jpock69:
I want to make it so once i upload the sketch the countdown starts for 5 min and when the time is up a buzzer goes off. im using a 16x2 LCD and a Ardruino UNO R3 Board

The image is how i have my LCD set up and i dont know where to put the buzzer or how to connect it

Do I understand correctly? You want to upload the sketch each and every time you want to run the countdown timer?

If this is true, why not just turn the power off and back on?

Paul

ithat workds to

i just dont kow how to achive it,

jpock69:
i just dont kow how to achive it,

Active or passive Buzzer
Just connect it any I/o pin with a current limit resistor in series
Here is a countdown time for seven segment You can hack/adapt it for your Use

typematrix:
Active or passive Buzzer
Just connect it any I/o pin with a current limit resistor in series
Here is a countdown time for seven segment You can hack/adapt it for your Use

GitHub - gavinlyonsrepo/timer_arduino: Countdown Timer: Range 1-99 minutes. Output: time (mm:ss) to seven segment display(TM1637) and Audio to Buzzer. Input: Push button to start. 10K Pot used for time select.

I know im dumb i dont know that much about ardruino how do i use the github repo., and i/o, and are you asking if i have active or passive buzzer? i have both

Works on a 2560 in the serial monitor. Was unable to test with the 16x2 LCD.

#include <LiquidCrystal.h>

const int 
    RS = 12, 
    EN = 11, 
    D4 = 5, 
    D5 = 4, 
    D6 = 3, 
    D7 = 2;
const int
    pinActiveBeeper = 7;    //whatever pin you're using for the active beeper
    
LiquidCrystal lcd( RS, EN, D4, D5, D6, D7 );

const unsigned long 
    culPeriod = 5ul*60ul*1000ul; //5 minutes x 60 seconds/min x 1000mS/second

//nice string generation for LCD and serial monitor
char
    szStr[16];   
//timer variables
// timeStart is set in setup() and marks the beginning of the countdown
// timeNow is updated each pass of the loop and used to check how much time (in milliseconds) has elapsed
unsigned long
    timeNow,
    timeStart;

void setup() 
{
    //set up the serial monitor
    Serial.begin(9600);
    //initialize the 16x2 LCD, clear it and print "Countdown" on the first line
    lcd.begin(16, 2);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Countdown:");
    
    //get the time marking the beginning of the countdown
    timeStart = millis();
    
}//setup

void loop() 
{
    //these "static" variables are used to know when to update the display
    //basically, when one of the minutes, seconds or tenths changes, the display
    //is updated and a message sent to the serial monitor
    static unsigned long
        lastminutes = 0,
        lastseconds = 0,
        lasttenths = 0;
    //from the time remaining in milliseconds, calculate the "human readable" min/sec/tenths 
    unsigned long
        minutes,
        seconds,
        tenths;
    unsigned long
        timeRemaining;

    //get the millisecond count now
    timeNow = millis();

    //culPeriod is set to the number of milliseconds in 5 minutes (5 x 60 x 1000)
    //if the difference between the time we started setup() and now is equal to 
    //or greater than that value the countdown is done
    if( (timeNow-timeStart) < culPeriod )
    {
        //not there yet; calc the time remaining in milliseconds
        timeRemaining = culPeriod - (timeNow - timeStart);
        //conver to minutes, seconds and tenths of a second
        minutes = timeRemaining / 60000ul;
        seconds = (timeRemaining - (minutes * 60000ul))/1000ul;
        tenths = (timeRemaining - (minutes * 60000ul) - (seconds * 1000ul)) / 100ul;
        //if any of those digits has changed since the last pass, send the updated
        //values to the LCD and serial monitor
        if( (minutes != lastminutes) || (seconds != lastseconds) || (tenths != lasttenths) )
        {
            sprintf( szStr, "%lu:%02lu:%d", minutes, seconds, tenths );
            Serial.println( szStr );
            lcd.setCursor(0, 1);
            lcd.print( szStr );
            //update the last values with the current values
            lastminutes = minutes;
            lastseconds = seconds;
            lasttenths = tenths;
            
        }//if
        
    }//if
    else
    {
        //sound the active beeper (assumes a high on the pin turns it on) for 1-second
        Serial.println( "Beep on" );
        digitalWrite( pinActiveBeeper, HIGH );
        //normally don't use delay but since the action right after this is to halt and catch fire, why not?
        delay(1000);
        Serial.println( "Beep off" );
        digitalWrite( pinActiveBeeper, LOW );

        //halt and wait for reset to re-do countdown
        while(1);
        
    }//else
    
}//loop

The code counts down fine, thank you so much, but where do i add the active buzzer?

I don't know what buzzer you have. Assuming it's a two-wire device, connect the '+' of the buzzer to pin 7 and the other side to GND and see what happens.

You'll have to add the line "pinMode( pinActiveBeeper, OUTPUT);" to setup too...

Blackfin:
You'll have to add the line "pinMode( pinActiveBeeper, OUTPUT);" to setup too...

where in the code would i add this?

It's in this version:

#include <LiquidCrystal.h>

const int 
    RS = 12, 
    EN = 11, 
    D4 = 5, 
    D5 = 4, 
    D6 = 3, 
    D7 = 2;
const int
    pinActiveBeeper = 7;    //whatever pin you're using for the active beeper
    
LiquidCrystal lcd( RS, EN, D4, D5, D6, D7 );

const unsigned long 
    culPeriod = 5ul*60ul*1000ul; //5 minutes x 60 seconds/min x 1000mS/second

//nice string generation for LCD and serial monitor
char
    szStr[16];   
//timer variables
// timeStart is set in setup() and marks the beginning of the countdown
// timeNow is updated each pass of the loop and used to check how much time (in milliseconds) has elapsed
unsigned long
    timeNow,
    timeStart;

void setup() 
{
    //set up the serial monitor
    Serial.begin(9600);
    //initialize the 16x2 LCD, clear it and print "Countdown" on the first line
    lcd.begin(16, 2);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Countdown:");

    pinMode( pinActiveBeeper, OUTPUT );
    digitalWrite( pinActiveBeeper, LOW );
    
    //get the time marking the beginning of the countdown
    timeStart = millis();
    
}//setup

void loop() 
{
    //these "static" variables are used to know when to update the display
    //basically, when one of the minutes, seconds or tenths changes, the display
    //is updated and a message sent to the serial monitor
    static unsigned long
        lastminutes = 0,
        lastseconds = 0,
        lasttenths = 0;
    //from the time remaining in milliseconds, calculate the "human readable" min/sec/tenths 
    unsigned long
        minutes,
        seconds,
        tenths;
    unsigned long
        timeRemaining;

    //get the millisecond count now
    timeNow = millis();

    //culPeriod is set to the number of milliseconds in 5 minutes (5 x 60 x 1000)
    //if the difference between the time we started setup() and now is equal to 
    //or greater than that value the countdown is done
    if( (timeNow-timeStart) < culPeriod )
    {
        //not there yet; calc the time remaining in milliseconds
        timeRemaining = culPeriod - (timeNow - timeStart);
        //conver to minutes, seconds and tenths of a second
        minutes = timeRemaining / 60000ul;
        seconds = (timeRemaining - (minutes * 60000ul))/1000ul;
        tenths = (timeRemaining - (minutes * 60000ul) - (seconds * 1000ul)) / 100ul;
        //if any of those digits has changed since the last pass, send the updated
        //values to the LCD and serial monitor
        if( (minutes != lastminutes) || (seconds != lastseconds) || (tenths != lasttenths) )
        {
            sprintf( szStr, "%lu:%02lu:%d", minutes, seconds, tenths );
            Serial.println( szStr );
            lcd.setCursor(0, 1);
            lcd.print( szStr );
            //update the last values with the current values
            lastminutes = minutes;
            lastseconds = seconds;
            lasttenths = tenths;
            
        }//if
        
    }//if
    else
    {
        //sound the active beeper (assumes a high on the pin turns it on) for 1-second
        Serial.println( "Beep on" );
        digitalWrite( pinActiveBeeper, HIGH );
        //normally don't use delay but since the action right after this is to halt and catch fire, why not?
        delay(1000);
        Serial.println( "Beep off" );
        digitalWrite( pinActiveBeeper, LOW );

        //halt and wait for reset to re-do countdown
        while(1);
        
    }//else
    
}//loop

where in the code would i add this?

to setup

last thing, if i need to change how long the timer is where in the code would i change it, i tried but the time went from 5min to like 200000 seconds

culPeriod = 5ul60ul1000ul; //5 minutes x 60 seconds/min x 1000mS/second

change this 5 to desired minutes

thanks, and what would i change to back it goe beep beep beep beep, not one beep

jpock69:
thanks, and what would i change to back it goe beep beep beep beep, not one beep

Can you try doing this yourself and posting what you come up with?

well im dumb but i will try

i added

for (int x=0; x<5; x++) {

to the code to loop it

for (int x=0; x<5; x++) {
digitalWrite( pinActiveBeeper, HIGH );
//normally don't use delay but since the action right after this is to halt and catch fire, why not?
delay(650);
Serial.println( "Beep off" );
digitalWrite( pinActiveBeeper, LOW );
delay(650);
}

works fine. thanks everyone here who helped