Inilah gunanya HM10, modul BLE (Bluetooth Energy) ideal untuk proyek konsumsi energi. Dengan fungsi BLE, Anda dapat menggunakan Arduino 5V/GND untuk menghubungkan lampu LED dan kemudian melakukan 1 operasi. Ini berarti BLE adalah daftar berkabel. Dapat memverifikasi ponsel dan mod BLE, baik Android atau laptop. Seperti iPhone, ini juga merupakan penggunaan utama pemindai BLE dan aplikasi serupa lainnya.
BLE menggunakan 5V untuk mentransmisikan ke 3.3V karena pembagi tegangan 1Ω dan 2Ω perlu dihubungkan ke Tx Arduino. Dalam video tersebut, kita dapat menggunakan codigo melalui Arduino untuk membuka kunci modul modul honeycomb dan berinteraksi dengannya.
final:
#include "SoftwareSerial.h"// import the serial library #include "AFMotor.h" AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #1, 64KHz pwm AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm AF_DCMotor motor3(3, MOTOR12_64KHZ); // create motor #2, 64KHz pwm AF_DCMotor motor4(4, MOTOR12_64KHZ); // create motor #2, 64KHz pwm SoftwareSerial btserial(10, 2); // RX, TX char c=" "; boolean NL = true; void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Motor test!"); btserial.begin(9600); motor1.setSpeed(200); // set the speed to 200/255 motor2.setSpeed(200); // set the speed to 200/255 motor3.setSpeed(200); // set the speed to 200/255 motor4.setSpeed(200); // set the speed to 200/255 } void loop() { // Leer bluetooth, si es 1, Adelante... if (btserial.available()){ c=btserial.read(); Serial.write(c); if(c=='1'){ // if number 1 pressed .... Serial.write("Forward"); forward(); } if(c=='2'){// if number 2 pressed .... Serial.write("Backward"); backward(); } if(c=='3'){// if number 3 pressed .... Serial.write("Left"); left(); } if(c=='4'){// if number 4 pressed .... Serial.write("Right"); right(); } if(c=='5'){// if number 5 pressed .... Serial.write("BRAKE"); brake(); } } // Serial Monitor Write BT if (Serial.available()){ c = Serial.read(); // do not send line end characters to the HM-10 if (c!=10 & c!=13 ) { btserial.write(c); } // If there is a new line print the ">" character. if (NL) { Serial.print("rn>"); NL = false; } Serial.write(c); if (c==10) { NL = true; } } } void forward(){ Serial.println("running forward"); motor1.run(FORWARD); motor2.run(FORWARD); motor3.run(FORWARD); motor4.run(FORWARD); delay(3000); brake(); } void backward(){ Serial.println("running backward"); motor1.run(BACKWARD); motor2.run(BACKWARD); motor3.run(BACKWARD); motor4.run(BACKWARD); delay(3000); brake(); } void left(){ motor3.run(FORWARD); motor2.run(BACKWARD); } void right(){ motor4.run(FORWARD); motor1.run(FORWARD); } void brake(){ motor1.run(RELEASE); motor2.run(RELEASE); motor3.run(RELEASE); motor4.run(RELEASE); }