Question using IFTTT with Photon

Hello,
would this be an appropriate place to request help with my particle photon and ifttt call function?
To summarize…
I’m working on a simple alarm which calls my phone once the sensor is triggered. However, once the “trigger” is pulled HIGH, it just continues calling, indefinitely.
I’m new to the particle.publish thing and been out of coding for a few years. I was hoping someone might be willing to look at the code and offer their two cents.
I apologize if this was not the correct thread.

Best Regards,

                    - Al -

No code to look at :wink:

I used this tutorial http://diotlabs.daraghbyrne.me/7-communicating-events/pir/ combined with the guide for using IFTTT https://docs.particle.io/guide/tools-and-features/ifttt/ for my project. What are you using as your sensor, a PIR? You can set it up to send a notification instead of calling. You can also setup a delay in the code so that it doesn’t trigger so many times.

Youre right, lol… I didn’t want to over impose to early. Thank you. Here is what I have so far:

================================================================================

#include "lib1.h"https://build.particle.io/build/5841b0f76e9ca75f4b000159#flash

char sensorValue;
int num;
int GreenLight = 2;
int RedLight = 3;
int PowerOnLight = 7;
int speaker = 0;
char AlarmTrigger;
char Motion;
int True;
                 
      void setup()
      {
          pinMode(sensorValue, INPUT);       // Our input from the door connection
          pinMode(7, OUTPUT);                  // Green "OK" Indicator light
          pinMode(GreenLight, OUTPUT);           //GreenAlarm
          pinMode(RedLight, OUTPUT);               // Red Alarm Light
          pinMode(0, OUTPUT);                        // Speaker for alarm
          pinMode(5, OUTPUT);                           // This is an extra output in case we decide to use later
          Particle.variable("sensorValue", sensorValue);
          Particle.variable("AlarmTrigger", AlarmTrigger);
          Particle.variable("Motion", "LOW");
          int True = 1;
          Serial.begin(9600);      // sets the serial port to 9600
          
             digitalWrite(7, HIGH);   
             delay (100);
             digitalWrite(7, LOW);
             delay (100);
             digitalWrite(7, HIGH);   
             delay (90);
             digitalWrite(7, LOW);
             delay (90);
             digitalWrite(7, HIGH);   
             delay (80);
             digitalWrite(7, LOW);
             delay (80);
             digitalWrite(7, HIGH);   
             delay (70);
             digitalWrite(7, LOW);
             delay (70);
             digitalWrite(7, HIGH);   
             delay (60);
             digitalWrite(7, LOW);
             delay(60);
             digitalWrite(7, HIGH);
             tone(0, 9000, 1000);
             delay(250);
             tone(0, 6000, 700);
             delay(300);
             tone(0, 9000, 1000);
             delay(250);
      }
     
      void loop()
      {       
        sensorValue = digitalRead(1);       // Door is closed
              if (sensorValue == LOW)
              //if (sensorValue == LOW)          //               
              {                             //// Particle.publish("sensorValue", sensorValue = 0);
                              /// Particle.publish("sensorValue", );
                // Particle.publish("AlarmTrigger", LOW);
                // Particle.publish("Motion", LOW);
                              
                delay(250);
                digitalWrite(GreenLight, HIGH); 
                digitalWrite(RedLight, LOW);
                digitalWrite(5, LOW);
                digitalWrite(0, LOW);
                delay(250); 
              }
                   else if (sensorValue == HIGH)    // Door is opened
              {  
                 //Particle.publish("AlarmTrigger", HIGH);
                 Particle.publish("Motion", "HIGH");
                 Particle.publish("Alarmtrigger", HIGH);
                 delay(250);
                 digitalWrite(GreenLight, LOW);
                 digitalWrite(RedLight, HIGH);
                 digitalWrite(0, HIGH);
                 digitalWrite(5, HIGH); 
                   delay(300);
                   digitalWrite (RedLight, LOW);
                   tone(0, 6000, 3600);
                   delay (300);
                   digitalWrite(3, HIGH);
                   tone (0, 900, 6060);
                   delay (300);
                   digitalWrite (RedLight, LOW);
                   tone (0, 7000, 450);
                   delay (300);
                   digitalWrite (RedLight, HIGH);
                   tone (0, 1850, 3420);
                   delay(100);
                   tone(0, 6000, 3600);
                   delay (300);
                   tone (0, 1000, 6060);
                   delay (300);
                   tone (0, 1850, 3420);
                   delay (300);
                   tone (0, 7000, 450);
                   delay(100);
                   Particle.publish("AlarmTrigger", LOW);
                   Particle.publish("Motion", "LOW");
                   
                   exit;
              }
                            return;
      }

Thank you.
I will look through these docs and see what insight I can gain.
Yes, I plan to use a PIR sensor, however, for now I am just using a pushbutton for testing purposes.

For your switch you should use INPUT_PULLUP or INPUT_PULLDOWN (depending on the level you areclosing to) to prevent your pin (which you should call D1) from floating.

Can you use the pin names that are printed on the board (D0~D7, A0~A5, …) instead of the anonymous pin numbers.

Ok, great. Will try to implement this - thank you.

You are also using sensorValue as pin number in setup() and as target variable in loop() that’s also not the best to do.

With this

char sensorValue; // <-- will be initialized 0
...
void setup()
{
  pinMode(sensorValue, INPUT); // <-- set D0 as input
  ...
}
void loop()
{
  sensorValue = digitalRead(1); // <-- here you are reading D1 which wasn't setup properly
  ...
}

Also this isn’t right

  Particle.publish("Alarmtrigger", HIGH); // <-- 2nd parameter needs to be a string 
  ...
  Particle.publish("AlarmTrigger", LOW);

You should also check for change in state and not just the state alone to prevent multiple triggers from one incident.

… I will go ahead and scratch that line out of there now.

@ScruffR fixes all the things. Haha. Something I’ve come to learn from hanging out on the forums.

2 Likes

On the IFTTT end, here is my recipe.

BTW: Now its just calling constantly regardless if the pin is pulled high or not

Seen my updated post?

Ok, just now saw it.
So for the string, should I use “HIGH”?
as in: Particle.publish(“AlarmTrigger”, “HIGH”);

I appreciate all the help you guys have to offer and hope to contribute to this forum myself one day.

Mainly about the uninitialized D1 pin - but all the other points need to be heeded too :wink:

Ok great.
I will do my best to make the modifications you provided when I get my next break. (About to change shifts at work)
If you don’t mind, I will plan to post my results/progress tomorrow morning and go from there.
Thanks again.

Personally I wouldn’t use the variable monitor, since IFTTT checks those on a fairly slow rate, causing it to miss things, or ‘hang’ on others.
I’d rather act on a publish, since the device is then in charge of the update rate. (Only update when something has actually changed)

@Moors7 Agreed. When I’m using IFTTT, I have it trigger via upon publish.

I want to thank everyone for their help.
This morning, using the code with the PIR calibrations in the links offered by @Kurticus, was able to start from scratch.
@Moors7, I took your advice for the IFTTT recipe.
I’m happy to say that the alarm is working now.
@ScruffR: Again, I want everyone for their efforts
Best Regards.

3 Likes