Sidewalk: The IoT network from Amazon
08.05.2024
Elektronik | Funk | Software
Der Technik-Blog
There is also a video on YouTube for this article: Arduino HC08 Bluetooth Module - LED control with iOS and Android (German)
In this article we show how to connect the HC-08 Bluetooth module to the Arduino Uno board. This module is compatible with Apple iOS and is also used with an iPhone in this review. Of course, the module also compatible with Android. The sample code for Arduino can switch the on-board LED (pin 13) with two commands.
The module works with 5 volts, which means that the 5 volt power supply can be taken directly from the Arduino. In addition to the two lines for the power supply two more data lines are needed. The data transmission works via a serial connection with 9600 baud rate at pin 11 and 12. By default, pins 1 and 2 can be used. But we also want to see an output at the SerialMonitor in. Therefore we access the SoftwareSerial connection on pin 10 and 11. The module comes preconfigured and does not need to be configured anymore.
The module is very easy to pair and is compatible with all newer devices that support the BLE standard. For the first connection, the manufacturer recommends the App LightBlue. If you want to connect your Android smartphone you can download BLE Scanner from Google Play Store. Then you need another app that can send commands to the module. It works like the serial monitor of the Arduino IDE. However, the connection does not run here via a COM port but via Bluetooth.
You can also use two other Bluetooth modules with your Arduino. The other modules are unfortunately not compatible with Apple but cheaper. With the HC-05, the Bluetooth name can be changed relatively easily and a password can also be configured. However, the HC-05 and HC-08 modules can only run in slave mode. So if you want to actively build a connection from the module to another device, you can only switch to the HC-06. You can order the modules between 5 to 20 euros
The example code can execute received commands. In addition, when the command is executed, the arduino send a feedback back via Bluetooth. There are two commands that can switch the integrated LED on pin 13.
led_on: This command turn the LED on.
led_off: This command turn the LED off.
The code converts the received data into a string. The string can then be compared with an IF query and trigger appropriate actions. In addition, all received commands are also displayed in the Serial Monitor on your PC.
#include <SoftwareSerial.h> SoftwareSerial btSerial(10, 11); // RX, TX PIN String bt_rx; int ledpin = 13; void setup() { Serial.begin(9600); pinMode(ledpin, OUTPUT); btSerial.begin(9600); } void loop() { if (btSerial.available()) { bt_rx = btSerial.readString(); Serial.print("Received:"); Serial.println(bt_rx); if (bt_rx == "led_on") { digitalWrite(ledpin, HIGH); btSerial.println("LED turned on"); } if (bt_rx == "led_off") { digitalWrite(ledpin, LOW); btSerial.println("LED turned off"); } } }
PT1000 sensors can not be measured directly analog with a microcontroller. How to build a PT100 Converter with LM358 and Arduino?
read moreThe PT100 is a very precise industrial temperature sensor. This article is about building a measuring amplifier for reading a PT100 on the Arduino
read moreAEQ-WEB © 2015-2024 All Right Reserved