So, i need to send sound sensor data from an Arduino Uno to the ESP8266 (ESP-01), so it can output a push notification to my phone whenever there's a loud noise. I have the sensor just powered and hooked up to the Analog 0 pin, and the ESP powered and hooked up to the Arduino Serial pins in reverse (RX to TX, TX to RX)
This is the code i have on the Arduino:
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.write(analogRead(A0) + "\r\n");
delay(100);
}
And this is the code i have on the ESP:
(i'm omitting the notification part for clarity, it doesn't even use Serial, so i don't think it should interfere)
void setup() {
Serial.begin(115200);
}
void loop() {
String val;
val = Serial.readString();
if( val.toInt() < 50 ){ sendNotification("Hello!"); delay(10000);}
}
I have tested the Sensor output and it seems fine, whenever i snap or clap the readings show a peak (although reversed, it stays on 1023 constantly then peaks to around 0~50), and the ESP can also send notifications normally. But the trigger on the notification never seems to fire, so i guess the ESP is not receiving the data properly.
I'm new-ish to Arduino, so i don't know if i'm doing something wrong here, Thanks in advance!
Serial.println(analogRead(A0));
will send the value as text terminated by \r\n. at receive side use at least readStringUntil – Juraj Nov 21 '20 at 15:19