Hi!, I'm currently building my project using Arduino. I need to send & receive 2 sensor values using 2 HC-05 modules Using Hardware Serial communication. there are a Pir & an ultrasonic sensor as the sensors in the master arduino. I used Serial.parseInt(); to receive data to slave Arduino. That works good but sometimes my Pir value is 1 in the slave Arduino when the master Arduino sends value 0. I think it's my Master Arduino code's fault. But I don't know to fix it. help me!. This is the code below I used for Master Arduino.
#define trig 7
#define pir_pin 5
#define echo 4
String pir_read;
int c;
void setup() {
/*int memory=EEPROM.read(0);
distance=memory * 10;*/
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(pir_pin, INPUT);
Serial.begin(38400);
}
void loop() {
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
int pir = digitalRead(pir_pin);
long t = pulseIn(echo, HIGH);
long Cm = t / 29 / 2;
Serial.print("C");
Serial.println(Cm);
delay(5);
Serial.print("\tP");
Serial.print(pir);
Serial.print(" ");
delay(5);
}
Let the master send a message to the slave to pull of a PIR reading. Then the master stays silent giving the slave the needed time slot do do its sensor reading.
Post a block drawing of the setup. When the master sends data the slave should read that data. You tell detect. Too many unknown things to give any more suggestion.
No, it's not! It's a cut out. Always post the entire code. All helpers are complete newbies to Your code and need the entire code to get some idea what it tries to do.
If You want to claim You write code then use comments telling what the lines are intended to do. We have no clue. It will be the same for You after time has passed.
That tabell of master and slave output tells nothing so far.