Previously, we discussed how to use Wi-Fi module with Arduino and Arduino 4 channel relay. Making them working togather with smartphone not that easy. Bluetooth is Easier Than Wi-Fi From Programming Aspect To Build Wireless Electrical Switch. Here is Part I of The Arduino Bluetooth Remote Control Tutorial.
There are various bluetooth modules for Arduino including modules supporting BLE. A bluetooth module operates at 2.4GHz short-range radio frequency band. Bluetooth has a range around 30 meters. A commonly used module is HC 05 bluetooth module. HM-10 Bluetooth module supports BLE. The required Android App for the M-10 Bluetooth module is available on Google Play :
1 | https://play.google.com/store/apps/details?id=appinventor.ai_Esdrastlc.BLE_ControPanell&hl=en_US |
There is another application named BLE Scanner. Both of them are useful in testing and development.
---
Android 8.0 will not find some HM-10 clone BLE modules when scanning for them out of a a bug in the firmware of those modules. The HM-10 is a tiny 3.3-V BLE Bluetooth 4.0 module based on the TI CC2540/CC2541 Bluetooth SoC. It can be controlled via AT commands, which are sent over the serial UART connection. Most of the latest HM-10 modules, though, are based on the CC2541 chip, with lower power and a shorter range than the former CC2540 version. Cheap clones are cleverly pointed as CC2541, may be CC2540. Their hardware-firmware ombination has some issues (that is a long topic). Original HM-10 manufactured by Jinan Huamao technology Co.) is back version of the chip. Detecting clone is not closest to easy. You will see, original HM-10 itself has many versions :
1 | http://www.jnhuamao.cn/bluetooth.asp |
You should try to buy genuine HM-10.
Arduino Bluetooth Remote Control : First Wirelessly Control a LED
For this purpose, we need :
- One HM-10 Bluetooth module
- Arduino Uno
- Breadboard
- Jumpers
- One LED
- One 220 Ohm resistor
Connect HM-10 bluetooth module with Arduino Uno in this way :
Module’s VCC –> Arduino Uno’s 3.3V or 5V
Module’s GND –> Arduino Uno’s GND
Module’s TX –> Arduino Uno’s digital pin 10
Module’s RX –> Arduino Uno’s digital pin 11
Test serial output with the above setup (without LED) with this sketch :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <SoftwareSerial.h> SoftwareSerial mySerial(10,11); void setup() { mySerial.begin(9600); Serial.begin(9600); delay(100); } void loop() { if (Serial.available()>0) mySerial.write(Serial.read()); if (mySerial.available()>0) Serial.write(mySerial.read()); } |
Install BLE Scanner App on Android mobile phone and scan. You will get the module. Default passcode to pair usually something like 123456789 or 0000000000 (9 zeros) or 111111111 (9 ones). After getting paired, you will get a list of services of the module. The last on the list will be “custom service”. On the custom service menu, there will three icons bearing the letters R (Read), W (Write) and N (Notify). Tap the W icon, type the text and send. The sent text will appear on the serial monitor. In this way, you can print data on LCD display too.
Many of the new readers, users noticed that AT commands used for these devices. AT commands in short is just sending command from the serial terminal.
Next, we will control LED from the Android Smartphone. Arduino already has a led at pin 13, so it is optional to connect the LED on breadboard with pin 13.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | int ledPin = 13; char read_bt; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); // debug on serial port } void loop() { if (Serial.available() > 0) { read_bt = Serial.read(); if(read_bt=='A') digitalWrite(ledPin, HIGH); if(read_bt=='B') digitalWrite(ledPin, LOW); } } |
Notice the lines :
1 2 3 4 5 | ... if(read_bt=='A') ... if(read_bt=='B') ... |
A and B are custom labels of button on Android mobile. Any Android App for this purpose which supports editing of button name will work with it. We can control it from PC/Mac serial terminal too, this is example code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <SoftwareSerial.h> int led = 13; SoftwareSerial Bluetooth(10, 11); void setup() { Serial.begin(9600); Bluetooth.begin(9600); pinMode(led, OUTPUT); } void loop() { int command; if (Bluetooth.available()) { command = Bluetooth.read(); Serial.println("Input received:"); if (command != 0) { Serial.println("0 / ON"); digitalWrite(led, HIGH); } else { Serial.println("1 / OFF"); digitalWrite(led, LOW); } } } |
This is the first part of the guide to get used around controlling DC operated device, like LED. Next guide will be on integrating the relay to control a test AC bulb.
Tagged With 8 channel relay arduino bluetooth control , bluetooth remote for arduino , arduino bluetooth remote control , arduino wireless remote control , bluetooth remote to control Arduino uno , arduino bluetooth part , arduino bluetooth remote , windows 10 remote arduino tutorials , arduino bluetooth controlled laptop , arduino as bluetooth transmitter