I am trying to get my PIR sensor to activate and deactivate the relay when motion is sensed. I was able to get it to turn on, but once on, it will not turned off. I have run into a lot of code but they all turn off the relay when no motion is detected. I have it connected to the N.O. on the tinkerkit relay and have downloaded the tinkerkit library. Here's the code I was able to come up with so far:
#include <TinkerKit.h>
int pirPin = 13;
int ledPin = 12;
TKRelay relay(11);
I had to rewrite the code from scratch because my computer had issues.I am not sure how to use the state function of even how to begin the next code. Can you please give me an example?
then this one will never happen (and it needs an "if" added) because the initial 'if' already occurred:
else{ if (sensor_1==HIGH && relay_1==HIGH){//error occurs here
so you may need to adjust your logic.
Also, many PIRs just have an open collector output to pull an input low, you may need a 10K pullup to bring it back high.
Thanks CrossRoads, any idea on how i can adjust the code to open the circuit back up? I am new to programming and don't know much. Also, you mean to add the resistor to the out pin on the PIR?
You seem to be reading the PIR pin, and then writing it. Once declared as an INPUT, all that writing it does is enable/disable the internal pullup resistor.
So read it, and after you see it active, keep reading it until it goes inactive, then act when you see it go inactive again.
I had modified the code and added a pull up 10k ohm resistor to vcc, 100 ohm resistor to the out. I am still getting the same thing. Here the code as it stands now:
#include <TinkerKit.h>
int pirPin = 13;
int ledPin = 12;
TKRelay relay(11);