37
Open the serial port assistant software "HMComAssistant.exe" and select the Arduino port and set
baud(115200) for bluetooth, then press “Open Com” and enter the data you want to send to
bluetooth(1 or 0 in our demo code). Finally, press “Send” to send the data to control the LED on and
off. When you enter the data ‘1’ and send it, the LED will light on and receive the prompt “LED ON”.
When you send the data "0", the LED will lights off and receive the prompt "LED OFF".
What will you see
1. Declare the pin of led, and a variable to store the data we send from the serial port.
2. Setup the led as output and initialize the serial monitor and set the baud(115200) that correspond
to our bluetooth.
3. Check if the serial port has received the data from bluetooth. If yes, store the data in the variable
“state”.
4. If data received is “0”, turn LED off.
5. If data received is “1”, turn LED on.
Code overview
Code usage
Set the baud for serial monitor correspond to our bluetooth module. “115200” is the default baud rate
for our bluetooth module. If we set the wrong baud for Arduino serial monitor, it may cause
communication failure or garbled communication between Bluetooth and Arduino.
Serial baud rate: Serial.begin(115200);
Determine if the serial monitor has received data. We send the data to Bluetooth, and then Bluetooth
sends the data to the Arduino serial monitor. If we send data, the expression "Serial.available ()> 0" is
true, otherwise it is false.
Received data: Serial.available()>0
Function to read data from the serial monitor. Then, we store the data in the variable "state", and we
turn on or off the led based on the value of this variable.
Read serial data: state = Serial.read();
This is Crowtail- ESP8266 Node MCU, it adds six crowtail interfaces on the board, so you can easily
use this board with other crowtail modules. We intergrate a USB-Serial chip that can upload code.
Lesson 18 – ESP8266 web server
Introduction
Содержание Crowtail Deluxe Kit
Страница 47: ......