Hi all,
I'm trying to use a esp32 to control a pump and solenoid via an app on my phone. The arduino serial monitor is receiving data but the app seems to be sending the wrong data. For example to turn the pump on I expect to receive "11" but the serial monitor reads 49.
I am following this tutorial https://www.youtube.com/watch?v=aM2ktMKAunw&ab_channel=MoThunderz
My esp32 code is as follows:
#include <BluetoothSerial.h>
#define pump 13
#define solenoid 12
BluetoothSerial SerialBT;
int incoming;
void setup() {
Serial.begin(115200);
pinMode(pump, OUTPUT);
pinMode(solenoid, OUTPUT);
btStart();
Serial.println("Bluetooth On");
SerialBT.begin("ESP32_BT"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
delay(5000);
}
void loop() {
if (SerialBT.available()) {
incoming = SerialBT.read(); //Read what we receive
Serial.println(incoming);
// separate button ID from button value -> button ID is 10, 20, 30, etc, value is 1 or 0
int button = floor(incoming / 10);
int value = incoming % 10;
switch (button) {
case 1:
Serial.print("Button 1:");
Serial.println(value);
digitalWrite(pump, value);
break;
case 2:
Serial.print("Button 2:");
Serial.println(value);
digitalWrite(solenoid, value);
break;
case 3:
Serial.print("Button 3:");
Serial.println(value);
digitalWrite(pump, value);
digitalWrite(solenoid, value);
break;
}
}
}
Here are my app blocks