So i tried to reworked with my code and try to make it clean as possible to try to reduce the error
#include <RH_ASK.h>
#include <SPI.h>
RH_ASK driver;
boolean recheck = true;
boolean buttonState = 1;
const int buttonPin = 2;
const int PIR = 7;
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH); //put input to high and wait for button to pull it low
pinMode(PIR, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13, recheck);
buttonState = digitalRead(buttonPin);
boolean sense = digitalRead(PIR); //shouldn't this be boolean?
if (buttonState == HIGH) {
recheck = false;
}
if (buttonState == LOW) {
//this line seems redundant
// if (recheck == true) {}
if (sense == HIGH) {
recheck = true;
}
}
Serial.println(recheck);
if ( recheck == true) {
const char *msg = "a";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
Serial.println("Sent message a");
}
delay(500); //slot in a short delay else it may give errors sometimes.
}
However, it still gives the same results as the root problem: the arduino still freezes when the button is pressed and the PIR sensor detect movement.
So I guess I have to agree to the fact regarding
wvmarle:
So my money is on the problem being related to whatever this "driver" is doing.
Even if it is true, what and why does it conflict and cause a halt to the arduino itself? it doesnt make sense
The library is RadioHead, just in case somebody asking.