Help in my alarm code

Hi,

I'm doing alarm clock and digital clock

I need to display the time and date then press the button to set the alarm (3 TIMES)
when I set the alarm the LCD display the time and date again.

Its not working with me
can you help me please WHERE IS MY MISTAKE !!

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html
then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

#include <Wire.h>
#include<EEPROM.h>
#include <RTClib.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd (7, 4, 5, 11, 3, 2);
RTC_DS1307 RTC;
int temp,inc,hours1,minut,add=11;
int next=10;    
int INC=9;
int set_mad=8;
 
#define buzzer 13

int HOUR,MINUT,SECOND;
 
void setup()
{
 Wire.begin();
 RTC.begin();
 lcd.begin(16,2);
 pinMode(INC, INPUT);
 pinMode(next, INPUT);
 pinMode(set_mad, INPUT);
 pinMode(buzzer, OUTPUT);
 digitalWrite(next, HIGH);
 digitalWrite(set_mad, HIGH);
 digitalWrite(INC, HIGH);

 
   lcd.setCursor(0,0);
   lcd.print("Medicin reminder");
   
    delay(2000);
  
 
 if(!RTC.isrunning())
 {
 RTC.adjust(DateTime(__DATE__,__TIME__));
 }
}
 
void loop()
{
   int temp=0,val=1,temp4;
   DateTime now = RTC.now();
   if(digitalRead(set_mad) == 0)      //set medicine time
   { 
     lcd.setCursor(0,0);
    lcd.print("  Set Medicine  ");
    lcd.setCursor(0,1);
   lcd.print("  Reminder time ");
    delay(2000);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter Time 1");
    defualt();
    time(1);
    delay(1000);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter Time 2");
    defualt();
    delay(1000);
    time(2);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter Time 3");
    defualt();    
time(3);
     lcd.setCursor(0,0);
   lcd.print("Medicin reminder");
   lcd.setCursor(0,1);
   lcd.print("  time has set  ");
    delay(2000);
 }
 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Time:");
 lcd.setCursor(6,0);
 lcd.print(HOUR=now.hour(),DEC); 
 lcd.print(":");
 lcd.print(MINUT=now.minute(),DEC);
 lcd.print(":");
 lcd.print(SECOND=now.second(),DEC);
 lcd.setCursor(0,1);
 lcd.print("Date: ");
 lcd.print(now.day(),DEC);
 lcd.print("/");
 lcd.print(now.month(),DEC);
 lcd.print("/");
 lcd.print(now.year(),DEC);
 match();
 delay(200);
}
 
void defualt()
{
  lcd.setCursor(0,1);
  lcd.print(HOUR);
  lcd.print(":");
  lcd.print(MINUT);
  lcd.print(":");
  lcd.print(SECOND);
}
 
/*Function to set alarm time and feed time into Internal eeprom*/
 
void time(int x)  
{
  int temp=1,minuts=0,hours=0,seconds=0;
    while(temp==1)
    {
     if(digitalRead(INC)==0)
     {
      HOUR++;
      if(HOUR==24)
      {
       HOUR=0;
      }
      while(digitalRead(INC)==0);
     }     
lcd.clear();
      lcd.setCursor(0,0);
    lcd.print("Enter Time ");
   lcd.print(x); 
    lcd.setCursor(0,1);
    lcd.print(HOUR);
    lcd.print(":");
    lcd.print(MINUT);
    lcd.print(":");
    lcd.print(SECOND);
    delay(100);
    if(digitalRead(next)==0)
    {
      hours1=HOUR;
      EEPROM.write(add++,hours1);
     temp=2;
     while(digitalRead(next)==0);
    }
    } 
    while(temp==2)
    {     
if(digitalRead(INC)==0)
     {
      MINUT++;
      if(MINUT==60)
      {MINUT=0;}
      while(digitalRead(INC)==0);
     }
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Enter Time ");
    lcd.print(x); 
    lcd.setCursor(0,1);
    lcd.print(HOUR);
    lcd.print(":");
    lcd.print(MINUT);
    lcd.print(":");
    lcd.print(SECOND);
    delay(100);
      if(digitalRead(next)==0)
      {
       minut=MINUT;
       EEPROM.write(add++, minut);
       temp=0;
       while(digitalRead(next)==0);
      }
    }
    delay(1000);
    
}
 
 
/* Function to check medication time */
 
void match()
{
  int tem[17];
  for (int i = 11; i < 17; i++)
  {
    tem[i] = EEPROM.read(i);
  }
  if(HOUR == tem[11] && MINUT == tem[12]) 
  {
   beep();
   beep();
   beep();
   beep();
   lcd.setCursor(0,0);
   lcd.print("  Take Group One  ");
   lcd.setCursor(0,1);
   lcd.print("     Medicine     ");
   beep();
   beep();
   beep();
   beep();
  }
 
   if(HOUR == tem[13] && MINUT == tem[14])
   {
      beep();
   beep();
   beep();
   beep();
    lcd.setCursor(0,0);
   lcd.print("  Take Group Two  ");
   lcd.setCursor(0,1);
   lcd.print("     Medicine     ");
    beep();
   beep();
   beep();
   beep();
   }
 
 
   if(HOUR == tem[15] && MINUT == tem[16] )
   {  
     beep();
   beep();
   beep();
   beep();
    lcd.setCursor(0,0);
   lcd.print("Take Group Three ");
   lcd.setCursor(0,1);
   lcd.print("     Medicine    ");
   beep();
   beep();
   beep();
   beep();
   }
}
 
/* function to buzzer indication */
 
void beep()
{
   digitalWrite(buzzer,HIGH);
   delay(500);
   digitalWrite(buzzer, LOW);
   delay(500);
}

Sorry about that I hope its clear now

One mistake I see

void match()
{
  int tem[17];
  for (int i = 11; i < 17; i++)
  {
    tem = EEPROM.read(i);
  }
  ...
  ...

'tem' is an array; I guess it should be

void match()
{
  int tem[17];
  for (int i = 11; i < 17; i++)
  {
    tem[i] = EEPROM.read(i);
  }
  ...
  ...
}

PS: Please describe what 'it is not working' means? What do you expect and what does happen.

Hi,
Its the same

The output is not correct in my code so It doesn't display the time and date in the start.
but
it shows the message ( Enter Time1) and when I try to choose the time it can just choose 1 in Hour and 1 in min then move to ( Enter Time2) and just I can choose 2 in houre and 2 in min

....
when I set the alarm It dosnt back to the date and time.

!!!!

Thank you

The output is shown exactly like the attachment

so It dosnlt show the time and date in the first and end

and

So in Time 1 I can just choose number 1 in hour and minute

in Time 2 I can just choose number 2 in hour and minute

Time 3 I can just choose number 3 in hour and minute

when i choose 3 in time 3 it shows the time of my computer and ican just change it 1 time

I hope I explain my problem so someone can help me!!

Don't be so impatient, you just come across as rude, I only come here 2 or 3 times a day, some more, some less. I don't have the time at the moment to help, but others MAY.

Your time(int x) function works as expected. I can set time1 hours and minutes (e.g. 7:30), time2 hours and minutes (e.g. 10:30) and time3 hours and minutes (e.g. 12:0).

Setting time2 after time1 continues from the setting of time1; so if time1 is set for 7:30, the start time for time2 is 7:30 and continues from there. Same for time3 and time2.

Writing to and reading from eeprom works a well.

Only thing I could not test is the LCD and the RTC; I used Serial.print/ln() statements and a fake clock to simulate.

As your problem description is not 100% clear to me, let me try to explain your code (as I understand it); maybe you can find a flaw in your code that way.

If set_mad is not pressed, you set (and display) HOUR, MINUT and SECOND; HOUR, MINUT and SECOND now reflect the RTC time.

Next you press set_mad and call defualt(); this will display the (previous) RTC time; it is what is shown in 5.jpg.
From your code, I'm not sure why you get the image as displayed in 1.jpg. As I don't have an RTC, I do get that.

Next you set the first alarm time using time(int x); as said, that works correctly. It uses HOUR and MINUT and increments them when you press INC, switches from hour to minute when you press next and exits if your press.

Next you call defualt() again; this will display the new HOUR and MINUT set in the previous step.

Next you set the second alarm time starting with HOUR and MINUT.

And you repeat the last two steps for the third alarm time.

And lastly you display date and time where displaying time sets the HOUR, MINUT and SECOND to the RTC time.

Hope this short analysis helps a bit.

Thanks for your help but it is not working :frowning:

'It does not work' is always so vague :wink:

sterretje:
Setting time2 after time1 continues from the setting of time1; so if time1 is set for 7:30, the start time for time2 is 7:30 and continues from there. Same for time3 and time2.

Is this what you expect to happen? And that does not happen? If it does not work as explained, please describe what happens for each step of the setting of the 3 alarm times.

sterretje:
As your problem description is not 100% clear to me, let me try to explain your code (as I understand it); maybe you can find a flaw in your code that way.
...
...

Was the given analysis correct?

Plz help me plz give me the code its vry urgent plz snd me on nt39681@gmail.com plz plz

Plz sm1 help me

nitinsharma:
Plz sm1 help me

is any there plz hlp me plz

@nitinsharma

Please GO HERE and read the help and advice on how to best get a response..

Then start your OWN thread with the relevant information.

By the way you are allowed to use full words on this forum and smartphone short hand is not the best way to ask for help.