Arduino radio hc-12
From wikiluntti
Introduction
LoRa, hc12, hc-12
- Frequency band is from 433.4 MHz to 473.0 MHz
- 100 channels with a stepping of 400 KHz between each channel
- Transmitting power is from -1dBm (0.79mW) to 20dBm (100mW). A half-duplex 20 dBm (100 mW) transmitter
- Receiving sensitivity is from -117dBm (0.019pW) to -100dBm (10pW)
Connect a 22 µF to 1 mF reservoir capacitor in parallel with the HC-12 "Gnd" and "Vcc" pins.
Set
Pins:
- Set pin of the module to Ground (set the pin to low logic level).
- Vcc 3.3V and GND to GND
- TXD -> 11
- RXD -> 10
Note that the pins needs to be reversed: The TX pin in the HC-12 needs to be plugged to RX pin of the Arduino.
The syntax of the softaware serial is:
SoftwareSerial(rxPin, txPin, inverse_logic)
Code for setting AT commands:
#include <SoftwareSerial.h>
SoftwareSerial HC12(11, 10); // HC-12 TX Pin, HC-12 RX Pin
void setup() {
Serial.begin(9600);
HC12.begin(9600);
}
void loop() {
while (HC12.available()) { // If HC-12 has data
Serial.write(HC12.read()); // Send the data to Serial monitor
}
while (Serial.available()) { // If Serial monitor has data
HC12.write(Serial.read()); // Send that data to HC-12
}
}
AT commands. The most important commands are (remember to use capital letters)
- AT – test command. It will return OK if AT interface is enabled
- AT+Bxxxx – set serial port baud rate. For example, AT+B57600 set baud rate to 57600bps, AT+B9600. Available baud rates: 1200 bps, 2400 bps, 4800 bps, 9600 bps, 19200 bps, 38400 bps, 57600 bps, and 115200 bps. Default: 9600 bps.
- AT+Cxxx – set radio channel. Channels start from 001 at 433,4MHz. Each next channel adds 400kHz. Channel 100 is 473,0MHz. AT+C002 will set frequency to 433,8MHz. Two HC-12 devices that creates a wireless link have to operate on the same frequency
- AT+FUx – set device mode: FU1, FU2, FU3 or FU4. Two HC-12 devices that creates a wireless link have to use the same mode
- AT+Px – set device transmitting power. For example AT+P2 sets power to 2dBm (1.6mW)
- -1dBm (0.8mW)
- 2dBm (1.6mW)
- 5dBm (3.2mw)
- 8dBm (6.3mW)
- 11dBm (12mW)
- 14dBm (25mW)
- 17dBm (50mW)
- 20dBm (100mW)
- AT+RX – retrieve all parameters: mode, channel, baud rate, power
- AT+V – retrieve module version
- AT+DEFAULT – reset module parameters to default settings