Setting Alarm via android - Please read~

I’m using a android phone to set alarm on Arduino, but it doesn’t work. Could you please how to solve this issue? This is my code.

#include <SoftwareSerial.h>
#include <Time.h>  
#include <TimeAlarms.h>
#define TIME_HEADER  "T"  // Header tag for serial time sync message
#define TIME1_HEADER "A"  // Header tag for Hour in Alarm
#define TIME2_HEADER "B"  // Header tag for Minute in Alarm

int ledPin1 = 4;
int m;
int n;
unsigned long pctime;


void setup()  
{
  Serial.begin(9600);
  Serial1.begin(9600);
  pinMode(ledPin1, OUTPUT);
}


void loop()
{ 
  digitalClockDisplay();
  Alarm.alarmRepeat(m,n,00,DailyAlarm);
  Alarm.delay(1000);

  switch(Serial1.read())
  {
    case 84: //ASCII "T"
    pctime = Serial1.parseInt();
    setTime(pctime);
    break;
    
    case 65: //ASCII "A"
    m = Serial1.parseInt();
    break;
  
    case 66: //ASCII "B"
    n = Serial1.parseInt();
    break;
  }
}


void DailyAlarm()
{
  Serial.println("This is Daily Alarm");
  digitalWrite(ledPin1, HIGH);
  delay(1000);
  digitalWrite(ledPin1, LOW);
}


void digitalClockDisplay()
{
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.print(" ");
  Serial.print(m);
  Serial.print(" ");
  Serial.print(n);
  Serial.println();
}


void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
  Serial.print('0');
  Serial.print(digits);
}

Question.ino (1.37 KB)

I'm using a android phone to set alarm on Arduino, but it doesn't work.

Fix it, then.

The code does something. You want it to do something. We have no idea what either of those things are.

I use phone to send " TIME_HEADER “T”+ unix time" to set Arduino’s Time, it does work. But when I try to set hour and minute in the Alarm function by the same way it doesn’t work.

You should only be changing the alarm time if something changed. You should be getting rid of the alarm object with the old time, and creating a new object with the new time.

Some serial output would be interesting.

How are you connecting to SoftwareSerial with the Android? USB with some android app?

Where is setTime(pctime) function? Where is the function to set Alarm? So many questions.

mistergreen:
How are you connecting to SoftwareSerial with the Android? USB with some android app?

Where is setTime(pctime) function? Where is the function to set Alarm? So many questions.

I'm using bluetooth to connect Android phone with android app. I would like to sent a alarm setting time to Alarm.alarmRepeat() function.

switch(Serial1.read()) // to identify the Header Tag
{
case 84: //ASCII "T" // If find Header Tag = T
pctime = Serial1.parseInt();
setTime(pctime); //setTime() function is from Time.h library
break;

case 65: //ASCII "A" // If find Header Tag = A
m = Serial1.parseInt(); // m is used for hour in Alarm.alarmRepeat() function.
break;

case 66: //ASCII "B" // If find Header Tag = B
n = Serial1.parseInt(); // n is used for minute in Alarm.alarmRepeat() function.
break;
}

Alarm.alarmRepeat(m,n,00,DailyAlarm); //Set hour as m, minute as n

Do you have a bluetooth module on your arduino? I don’t see a bluetooth library.

Can you confirm android to arduino comm is working? Just serial print “Hello World” or anything.

Oh I see - Alarm.alarmRepeat(m,n,00,DailyAlarm); //Set hour as m, minute as n?
You realize you’re redefining the alarm constantly in the loop. You need to call it once when the time is set on the android.

Still so many questions.