Android Question Android-Bluetooth-Adruino communication (BLE)

Jerryk

Member
Licensed User
Longtime User
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);
}
}
 
Last edited:

stari

Active Member
Licensed User
Longtime User
Android side:

Arduino side i make in MicroBasic PRO for AVR from MikroElektronika.
 
Upvote 0

eric19740521

Member
Licensed User
Longtime User
I have no experience with HC-10, I already have HC-05, I checked the internet, and the usage is mostly similar... So I will tell you my experience with HC-05... Maybe you can buy it An HC-05 to complete! !
A simple watering, LED lights, relays, etc., it is recommended to use HC-05, or ESP32

1.HC-05

In the process of learning, I made esp32/arduino/B4x into a video and put it on YouTube..
Chinese commentary. You can translate it into English


B4A Code(Chinese commentary. You can translate it into English)
https://github.com/eric19740521/b4a20220107
https://github.com/eric19740521/car20220119
I just checked and it can be modified with my code and it should work
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…