HC-12
HC-12
The HC-12 is a low-cost, low-power, and high-performance wireless serial communication module that operates at a frequency of 433.92 MHz. It is a popular and widely used IoT component for wireless communication between microcontrollers, computers, or other devices.
The HC-12 module is designed to provide wireless serial communication between devices. It can be used to transmit and receive data wirelessly between two devices, allowing for wireless communication over distances of up to 1000 meters (3280 feet) in open areas. The module operates in half-duplex mode, meaning it can either transmit or receive data at a time, but not both simultaneously.
By providing a detailed description of the HC-12 module's functionality and key features, developers can effectively integrate this component into their IoT projects, ensuring reliable and efficient wireless communication between devices.
HC-12 Wireless Serial Communication Module DocumentationOverviewThe HC-12 is a popular and cost-effective wireless serial communication module, widely used in IoT projects, robotics, and wireless communication systems. It offers a reliable and efficient way to transmit data wirelessly between two devices. This documentation provides a comprehensive overview of the HC-12 module, including its features, pinout, and code examples for various contexts.FeaturesWireless serial communication module
Operating frequency: 433.4-473.0 MHz
Transmission distance: up to 1000 meters (line of sight)
Baud rate: 1200-115200 bps
Power consumption: 3.3V - 5V DC
Small size: 27x13x3 mmPinout| Pin | Function |
| --- | --- |
| VCC | Power supply (3.3V - 5V) |
| GND | Ground |
| TXD | Transmit data |
| RXD | Receive data |
| SET | Module setup (high: setup mode, low: normal mode) |Code Examples### Example 1: Basic Wireless Communication using ArduinoIn this example, we will demonstrate how to use two HC-12 modules to establish wireless communication between two Arduino boards.Transmitter Code (Arduino Board 1)
```c
#include <SoftwareSerial.h>SoftwareSerial HC12(2, 3); // TX, RX pinsvoid setup() {
HC12.begin(9600); // Initialize HC12 module at 9600 bps
}void loop() {
HC12.print("Hello, World!"); // Send data to receiver
delay(1000);
}
```Receiver Code (Arduino Board 2)
```c
#include <SoftwareSerial.h>SoftwareSerial HC12(2, 3); // TX, RX pinsvoid setup() {
HC12.begin(9600); // Initialize HC12 module at 9600 bps
Serial.begin(9600); // Initialize serial monitor
}void loop() {
if (HC12.available()) {
String receivedData = HC12.readStringUntil('
');
Serial.println(receivedData); // Print received data to serial monitor
}
}
```### Example 2: Wireless Sensor Node using ESP8266 and HC-12In this example, we will demonstrate how to use the HC-12 module with an ESP8266 board to create a wireless sensor node.ESP8266 Code
```c
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>SoftwareSerial HC12(D1, D2); // TX, RX pins
const char ssid = "your_wifi_ssid";
const char password = "your_wifi_password";void setup() {
Serial.begin(115200);
HC12.begin(9600); // Initialize HC12 module at 9600 bps
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}void loop() {
int sensorValue = analogRead(A0); // Read sensor value
HC12.print("Sensor Value: ");
HC12.println(sensorValue); // Send sensor data to receiver
delay(1000);
}
```In this example, the ESP8266 board reads sensor data from an analog input and transmits it wirelessly to a receiver using the HC-12 module.Note: These code examples are just a starting point, and you may need to modify them based on your specific use case and requirements.