I have a tuned arduino greenhouse watering project written in the Arduino IDE (not in B4R). In addition, I would like to write the code in B4A for Android-Bluetooth-Adruino communication. I want to use the BLE module HM-10. I have no experience with that. I ran this: https://circuitdigest.com/microcont...10-ble-module-to-control-led-with-android-app. But that doesn't suit me. I would like an application where: 1. read data from adruino (temperature, humidity) - button, 2. enter a command to manually turn on / off the valve on the arduino - 2 buttons. Can anyone from the skeleton code help me? Code on Android side and Arduino side in Arduino IDE?
Arduino code without sending data example
#include <SoftwareSerial.h>
SoftwareSerial HM10(2, 3); // RX = 2, TX = 3
char appData;
String inData = "";
void setup()
{
Serial.begin(9600);
Serial.println("HM10 serial started at 9600");
HM10.begin(9600); // set HM10 serial at 9600 baud rate
pinMode(13, OUTPUT); // onboard LED
digitalWrite(13, LOW); // switch OFF LED
}
void loop()
{
HM10.listen(); // listen the HM10 port
while (HM10.available() > 0) { // if HM10 sends something then read
appData = HM10.read();
inData = String(appData); // save the data in string format
Serial.write(appData);
}
if (Serial.available()) { // Read user input if available.
delay(10);
HM10.write(Serial.read());
}
if ( inData == "F") {
Serial.println("LED OFF");
digitalWrite(13, LOW); // switch OFF LED
delay(500);
}
if ( inData == "N") {
Serial.println("LED ON");
digitalWrite(13, HIGH); // switch OFF LED
delay(500);
digitalWrite(13, LOW); // switch OFF LED
delay(500);
}
}
Arduino code without sending data example
#include <SoftwareSerial.h>
SoftwareSerial HM10(2, 3); // RX = 2, TX = 3
char appData;
String inData = "";
void setup()
{
Serial.begin(9600);
Serial.println("HM10 serial started at 9600");
HM10.begin(9600); // set HM10 serial at 9600 baud rate
pinMode(13, OUTPUT); // onboard LED
digitalWrite(13, LOW); // switch OFF LED
}
void loop()
{
HM10.listen(); // listen the HM10 port
while (HM10.available() > 0) { // if HM10 sends something then read
appData = HM10.read();
inData = String(appData); // save the data in string format
Serial.write(appData);
}
if (Serial.available()) { // Read user input if available.
delay(10);
HM10.write(Serial.read());
}
if ( inData == "F") {
Serial.println("LED OFF");
digitalWrite(13, LOW); // switch OFF LED
delay(500);
}
if ( inData == "N") {
Serial.println("LED ON");
digitalWrite(13, HIGH); // switch OFF LED
delay(500);
digitalWrite(13, LOW); // switch OFF LED
delay(500);
}
}
Last edited: