Go Down

Topic: CONTROL PIR SENSOR WITH MYMQTT APP (Read 72 times) previous topic - next topic

Mike7nt

Hi guys i have a pir sensor and a relay, I have a code for the combination of pir and relay.I want to control the relay with the mymqtt app from my phone with on,off: on means sensor is on and after that run the code of pir and relay where pir take prices val=0 no motion val=1 yes motion and if val=1 relay low for example.in other situation off pir means  the other code the code of pir and relay didn't run.i think must create an if(payload==0) {
              digitalWrite(pir,LOW);
       
              client.publish("mytopic",pir sensor is on); and after i want this code to run

int lamp = 8; // choose the pin for the RELAY
int inputPin = 4; // choose the input pin (for PIR sensor)

int val = 0; // variable for reading the pin status

void setup() {

pinMode(lamp, OUTPUT); // declare lamp as output

pinMode(inputPin, INPUT); // declare sensor as input

Serial.begin(9600);

}

void loop(){

val = digitalRead(inputPin); // read input value

Serial.println(val);

if( val== 1) {

digitalWrite(lamp,HIGH); // turn ON the lamp

} else {

digitalWrite(lamp,LOW); // turn OFF the lamp

}

} and finaly when i press the off pir no activate and above code didnt run

AWOL

I deleted the duplicate of this thread.

Do not cross-post, cross-posting wastes time.

Please remember to use code tags when posting code.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up