Sending and receiving data
You can configure a microcontroller to communicate with an HC-12 module using software serial, as we have seen previously. However, make sure that the SET
pin is not pulled to the ground when in normal operation.
Let’s consider a simple sketch that will output whatever the HC-12 module receives to the serial console of the computer to which the microcontroller is connected.
Exercise 10.1 – displaying whatever the HC-12 module receives
Follow these steps to read whatever the HC-12 module receives and print it out on the serial monitor on your computer:
- Begin by importing
SoftwareSerial
:#include <SoftwareSerial.h>
- Create an instance of
SoftwareSerial
calledHC12
. This takes two parameters, the first being the pin thatTX
is connected to, and the second being the pin thatRX
is connected to:SoftwareSerial HC12(10, 11);
- Initialize the serial port on the microcontroller to a baud rate of
9600
. Do the same for the software...