I have a system which uses an arduino uno, Pir sensor, and a 5v relay. When the pir sensor detects motion, it opens the 5v relay. I recently purchased an Hc-06 module to beable to control this via my mobile device.
I created an app on Mit app inventor. Its a simple app where when a button labelled "On" is pressed it sends a one, and when a button labelled "Off" is pressed, it sends a 0.
My problem however is, I want the app to be able to manually override the function of the PIR, so once i am connected , even it the PIR detects motion it wont open or close the relay, is there a button I can add for this funcionality via MIT app inventor ? how would i do that
Dear @Aumari_Joseph,
what @nishyanthkumar has posted is perfect on AI2 side, but let me suggest you a few things on Arduino side, since recently I've done something very similar, though I've used a NODEMCU ( based on 8266) instead. In my hardware configuration the PIR is acquired on D1.
I guess you are very familiar with Arduino programming, nevertheless I hope these few lines can help you and save your time. The code represents just a chunk of the setup() and of the loop() functions. Obviously you have to add your code that suits your needs. Image and code here below.
//=====================================================================================================================================
void setup()
{
Serial.begin(115200); // Initializes the Serial Monitor
BTSerial.begin(38400); // initializes the BT comm's (supposing SoftwareSerial library used and correctly initialized)
WaitToRead = millis(); // To avoid the first PIR acquisition after the reset
overridden = false; // overridden declared as global bool. Purpose: to override the PIR detection by App
DontReadAgain = true; // declared as global bool . Purpose: to avoid too fast PIR readings
}
//=====================================================================================================================================
void loop()
{
if (BTSerial.available > 0) // Something from App ? (HC06)
{ char command = BTSerial.read();
if (command == '0') overridden = false else overridden = true;
}
if ((digitalRead(D1) == HIGH) && !DontReadAgain && !overridden) // PIR detected a movement but it sends info to the server only if WaitToRead has elapsed
{ // and not overridden
#ifdef Debug
Serial.println("PIR triggered");
#endif
RelayCYcle(); // Actuate the relay
DontReadAgain = true; // Avoid too frequent trigger's repetition
WaitToRead = millis(); // Now
}
if(millis()- WaitToRead >= 5000) DontReadAgain = false; // Mask off too frequent PIR acquisitions. After 5 seconds the PIR can be freed again
}
Last, but not least, you can take a look to @Juan_Antonio's web site (KIO4) for further hints on AI2 and Arduino (almost any model) BT comm's.
Best wishes for your project.
I have made some progress, When button 3 is set to "currently on", and the "On" button is pressed which sends a "1", the relay will remain open regardless of if motion is detected or not. However, when the "Off" button is pressed and a "0" is sent, I would like it to stay off regardless of if motion is detected or not, but it still detects motion.
In summary I want the PIR to be disabled when the app is set to "currently on", and I want it to be enabled when the app is sent to "currently off". Your reply has been super helpful and I will continue to work on this project