Bluetooth HM-10 Module

Bluetooth HM-10 Module

How to control a component via Bluetooth using an HM-10 module.

  • 7,969 views
  • 2 comments
  • 14 respects

Components and supplies

Apps and online services

About this project

The Arduino has been badly cut without a shield in its connectivity to the outside world and so I ventured on the subject of Bluetooth, using the BLE module HM-10 (ZS-040) with Chip CC2541 (3 Euro).

As it turned out later, the BLE module communicates via serial inputs and outputs, so that via smartphone apps ("ElegooBLE" or "Serial") the "code words" to which to respond via BLE module is transmitted to the Arduino and be interpreted.

In my example, I transmit "ein" to turn on the LED (the internal on 13, as well as a white external to A0 (long leg in A0, short leg in GND) and an "aus" for turning off the LEDs.

Wiring: VCC <> 5V or 3.3V, GND <> GND, RXD <> 11, TXD <> 10.

void loop() {
 if (SerialBT.available()){      // Daten liegen an
    msg = SerialBT.readString(); // Nachricht lesen
    if (msg == "ein") {
        digitalWrite(LED, HIGH);
        digitalWrite(LED_ext, HIGH);
        SerialBT.print("LED an Pin ");
        SerialBT.print(LED);
        SerialBT.println(" ist eingeschaltet!");
     } 
     else
     if (msg == "aus") {
        digitalWrite(LED, LOW);
        digitalWrite(LED_ext, LOW);
        SerialBT.print("LED an Pin ");
        SerialBT.print(LED);
        SerialBT.println(" ist ausgeschaltet!");
     }
     else {
        SerialBT.print("Kommando <");
        SerialBT.print(msg);
        SerialBT.println("> nicht bekannt");
     }
   }
}                                          

For the German reader I recommend a further article from the Heise publishing house.

In my simulation, I've also tried different Arduino shields: as the ports of the Arduino are passed to the shields, it works right away with both the PHPoC Arduino shield (P4S-348) and the 1Sheeld + without the additional inclusion of their special ones Libraries.

Have you noticed that the BLE modules are wrapped in an extra protective film? I've never experienced that in any other sensor.

The use of Bluetooth allows control within a radius of a few meters (up to 10) around the location of the device, which opens up further fields of application.

Code

Control your Arduino with BLE HM-10C/C++
//////////////////////////////////////////////////
//
// Kleines interaktives Demo
// (c) 2016, Michael Stal
//  Nutzung:
//     Sketch auf Arduino laden
//     An Arduino HM-10 anschließen
//     
//     Über BLE App serielle Verbindung aufbauen,
//     "ein" oder "aus" ins Textfeld eingeben, 
//     und LED beobachten.
//
///////////////////////////////////////////////////


// Wir verwenden Software Serial
#define softserial

// Eingebaute LED nutzen:
const int LED  = 13;
const int LED_ext  = A0;


#ifdef softserial
  #include <SoftwareSerial.h>
  const int BTRX = 10;  // 11
  const int BTTX = 11;  // 10
  SoftwareSerial SerialBT(BTRX, BTTX);
#else 
  HardwareSerial SerialBT = Serial1;
#endif


// Die versendete Nachricht:
String msg; 


///////////////////////////////////////////////////
//
// setup
//    Verbindung mit HM-10 aufbauen
//
///////////////////////////////////////////////////

void setup() {
  SerialBT.begin(9600);
  SerialBT.println("Bluetooth-Verbindung steht");
  pinMode(LED, OUTPUT);
}

///////////////////////////////////////////////////
//
// loop
//    In jeder Iteration auf Nachricht warten,
//    Nachricht analysieren,
//    Aktion auslösen (LED ein/aus)
//
///////////////////////////////////////////////////

void loop() {
  if (SerialBT.available()){      // Daten liegen an
     msg = SerialBT.readString(); // Nachricht lesen
     if (msg == "ein") {
         digitalWrite(LED, HIGH);
         digitalWrite(LED_ext, HIGH);
         SerialBT.print("LED an Pin ");
         SerialBT.print(LED);
         SerialBT.println(" ist eingeschaltet!");
      } 
      else
      if (msg == "aus") {
         digitalWrite(LED, LOW);
         digitalWrite(LED_ext, LOW);
         SerialBT.print("LED an Pin ");
         SerialBT.print(LED);
         SerialBT.println(" ist ausgeschaltet!");
      }
      else {
         SerialBT.print("Kommando <");
         SerialBT.print(msg);
         SerialBT.println("> nicht bekannt");
      }
    }
}                                          

Comments

Similar projects you might like

Attiny85/84 with Bluetooth

by Robin

  • 12,651 views
  • 0 comments
  • 54 respects

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 482,790 views
  • 49 comments
  • 285 respects

Bluetooth control led with lcd led status display real time.

Project tutorial by Youssef Sabaa

  • 17,292 views
  • 4 comments
  • 34 respects

Bluetooth Controlled Car

Project tutorial by JANAK13

  • 3,483 views
  • 8 comments
  • 20 respects
Add projectSign up / Login