# Setting Alarm via android - Please read~

**URL:** <https://forum.arduino.cc/t/setting-alarm-via-android-please-read/308666>\
**Category:** Programming\
**Created:** [May 1, 2015, 1:40pm UTC](https://forum.arduino.cc/t/setting-alarm-via-android-please-read/308666 "2015-05-01T13:40:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kentchen329](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@kentchen329](https://forum.arduino.cc/u/kentchen329)\
**Post date:** [May 1, 2015, 1:40pm UTC](https://forum.arduino.cc/t/setting-alarm-via-android-please-read/308666/1 "2015-05-01T13:40:48Z")

</div>

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.

```cpp
#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](https://forum.arduino.cc/uploads/short-url/lERbu8d8EmUHCbh6qEMLHsDM8VB.ino) (1.37 KB)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 1, 2015, 1:51pm UTC](https://forum.arduino.cc/t/setting-alarm-via-android-please-read/308666/2 "2015-05-01T13:51:35Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![kentchen329](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@kentchen329](https://forum.arduino.cc/u/kentchen329)\
**Post date:** [May 1, 2015, 2:04pm UTC](https://forum.arduino.cc/t/setting-alarm-via-android-please-read/308666/3 "2015-05-01T14:04:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 1, 2015, 2:06pm UTC](https://forum.arduino.cc/t/setting-alarm-via-android-please-read/308666/4 "2015-05-01T14:06:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mistergreen](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@mistergreen](https://forum.arduino.cc/u/mistergreen)\
**Post date:** [May 1, 2015, 2:26pm UTC](https://forum.arduino.cc/t/setting-alarm-via-android-please-read/308666/5 "2015-05-01T14:26:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kentchen329](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@kentchen329](https://forum.arduino.cc/u/kentchen329)\
**Post date:** [May 1, 2015, 2:57pm UTC](https://forum.arduino.cc/t/setting-alarm-via-android-please-read/308666/6 "2015-05-01T14:57:23Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![mistergreen](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@mistergreen](https://forum.arduino.cc/u/mistergreen)\
**Post date:** [May 1, 2015, 3:45pm UTC](https://forum.arduino.cc/t/setting-alarm-via-android-please-read/308666/7 "2015-05-01T15:45:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 9:16pm UTC](https://forum.arduino.cc/t/setting-alarm-via-android-please-read/308666/8 "2021-05-05T21:16:07Z")

</div>

Closed on May 5, 2021, 9:16pm UTC


