HC-12 433 MHz Mailbox and Gate Alert with ESP32 - Proteus Simulation: the gate ESP32 with its HC-12, the PIR and the mailbox switches, and the house ESP32 with its HC-12, the OLED and the MAIL lamp

HC-12 433 MHz Mailbox and Gate Alert with ESP32 - Proteus Simulation

40
700
60
25
60
PCBWay

Hello friends, I hope you all are doing great. Today, I am going to share the HC-12 433 MHz Mailbox and Gate Alert with ESP32 - Proteus Simulation, the sixty-seventh project of our IoT Projects series. If you have searched for an HC-12 ESP32 project, a 433 MHz mailbox alert, a wireless gate sensor, or a Proteus simulation of a long-range radio link, here is a complete one. A garden gate and its mailbox sit far from the house. At the gate, an ESP32 with a PIR sensor and two switches notices a visitor, the post arriving and the post being collected, and tells the house over an HC-12 radio. In the house, a second ESP32 answers every message, lights a MAIL lamp, shows the news on an OLED and serves a dashboard to a laptop and a phone.

A one-way radio alert has a weakness: when a message is lost, nobody knows. This project fixes that in three ways. Every message is answered, so the gate knows whether it got through. A heartbeat every 5 seconds lets the house notice when the gate has gone quiet. And the gate finds the least transmit power that still reaches the house, because a battery-powered radio that shouts at 100 mW to cover 50 metres wastes most of its energy. In this tutorial, we will go through the circuit, see how the HC-12 works and how far its signal goes with a simple link budget, design the answered messages, the power steps and the AT commands that change the power while the link runs, walk through both Arduino sketches, and then run the simulation: the gate comes online, a visitor walks in, the post arrives, the gate moves away to 250 m and to 1 km, and comes back. At the end, you can download the project with both sketches and every library file.

NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the HC-12 mailbox and gate alert with ESP32 in Proteus simulation:

HC-12 433 MHz Mailbox and Gate Alert with ESP32 - Proteus Simulation: the gate ESP32 with its HC-12, the PIR and the mailbox switches, and the house ESP32 with its HC-12, the OLED and the MAIL lamp
Figure: The gate and mailbox alert in a Proteus simulation: mail delivered, the MAIL lamp lit.
HC-12 433 MHz Mailbox and Gate Alert with ESP32: the working Proteus simulation, an animated view of the project's main steps
Figure: The project working in the Proteus simulation (an animation of the main steps).

What Does This Mailbox and Gate Alert Do?

  • Watches the path: an HC-SR501 PIR sensor at the gate notices a person walking in and the gate ESP32 reports a visitor.
  • Feels the post: a switch under the mailbox flap reports mail delivered, a switch on the mailbox door reports mail collected.
  • Sends over 433 MHz: two HC-12 radios carry short text messages between the gate and the house, like a serial cable through the air.
  • Answers every message: the house replies to each message at once; no reply means no delivery, and the gate tries again.
  • Finds the least power: the gate starts at the HC-12's lowest power, climbs only when the house does not answer, and steps down again when the link is easy.
  • Notices a silent gate: a heartbeat every 5 seconds; when 16 seconds pass with nothing, the house says GATE SILENT.
  • Tells the family: an amber MAIL lamp while post waits in the box, a 0.91" OLED with the news, and a dashboard on a laptop or a phone.

It is a great project for learning how a real radio link behaves: it has a range, it loses messages, and its power costs energy. In the simulation, each HC-12's pop-up shows what it sends and hears, the signal level at the receiver against the sensitivity it needs, and DISTANCE buttons that move the two radios apart, from 10 m to 2 km. The PIR's pop-up lets a person walk in, stand still or walk out, and the push buttons stand in for the mailbox switches.

Components Used in the Proteus Simulation

All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file.

The parts of the mailbox and gate alert and their library posts
PartProteus deviceLibrary postConnection
ESP32 DevKit V1 (x2)ESP32 DEVKIT V1ESP32 DevKit V1 Library for ProteusU1 the house (TEP-WiFi 192.168.1.101), U3 the gate
HC-12 433 MHz radio (x2)HC12ADVTEPHC-12 Library for ProteusU2 the house, U4 the gate: TXD to RX2, RXD from TX2
HC-SR501 PIR sensorHCSR501ADVTEPPIR Sensor Library for ProteusU5, OUT to D27 of the gate
Push buttons (x2)BUTTONGREENTEPPush Button LibrarySW1 the flap on D25, SW2 the door on D26 of the gate
SMD LED amberLEDSMDAMBERTEPSMD LED LibraryD1, the MAIL lamp, on D4 of the house
SMD resistorsRESISTORSMD1206TEPSMD Resistor LibraryR1 220 ohm for the lamp, R2 / R3 10k pull-downs
SSD1306 OLED 0.91" 128x32OLED12832WHITEADVTEPOLED 128x32 Library for ProteusOLED1, I2C at 0x3C on the house
Laptop WiFi MonitorLAPTOP WIFI MONITORLaptop WiFi MonitorPC1
Mobile WiFi MonitorMOBILE WIFI MONITORMobile WiFi MonitorMOB1

Proteus Simulation of the Gate Alert: the Circuit

Gate alert Proteus simulation circuit: two ESP32 DevKit V1 boards, two HC-12 radios, an HC-SR501 PIR, two switches, an OLED and an LED
Figure: The complete circuit of the gate alert on an A3 Proteus sheet.
The connections of the mailbox and gate alert
PartPinsESP32 / supply
U2 HC-12 (house)TXD / RXD / SETRX2 GPIO16 / TX2 GPIO17 / open (its own pull-up)
U4 HC-12 (gate)TXD / RXD / SETRX2 GPIO16 / TX2 GPIO17 / D4
U2, U4VCC / GNDthe 5 V rail / GND
U5 PIROUT / VCCD27 of the gate / the 5 V rail
SW1 flap, SW2 door1 / 2the gate's 3.3 V / D25, D26 with R2, R3 10k to GND
OLED1SDA / SCL / VCCD21 / D22 of the house / +3.3V
D1 MAILanodeD4 of the house through R1 220 ohm

The sheet holds two separate nodes that share nothing but the air: the house on the left and the gate on the right. Each HC-12 sits on its ESP32's second UART, Serial2, on GPIO16 and GPIO17, which leaves the first UART free for the serial monitor. The HC-12's pins are on its bottom edge, so each one goes down to a label. The gate's SET pin goes to D4, because the gate changes its own transmit power with AT commands; the house's SET pin is left open, and the module's own pull-up keeps it in normal mode. Both radios and the PIR run from the 5 V rail: the HC-12 takes 3.2 to 5.5 V and draws up to 100 mA while it transmits at full power. The two switches pull their inputs up to the gate's 3.3 V when pressed, and 10k resistors hold the inputs low otherwise. On the house, the OLED shares the I2C bus on D21 and D22, and the amber lamp has its own 220 ohm resistor on D4.

How the HC-12 Gate Alert Works

The HC-12: a Serial Cable Through the Air

The HC-12 is a 433 MHz transceiver with a microcontroller of its own. Whatever bytes arrive on its RXD pin go out over the air, and whatever another HC-12 on the same channel hears comes out on its TXD pin, so for the ESP32 the radio looks like a serial cable. The factory settings are 9600 baud, channel 1 (433.4 MHz), mode FU3 and the full 20 dBm. In FU3, the air data rate follows the serial baud rate: at 9600 baud the radio sends at 15,000 bits per second, and the manual gives the receiver a sensitivity of -112 dBm at that rate. Lower air rates reach further, because a slower signal can be heard under more noise: at 2400 baud the sensitivity improves to -117 dBm. This project keeps the defaults on both radios and changes only the power.

The Link Budget: How Far Does 433 MHz Go?

A receiver hears a message when the signal reaching it is at least its sensitivity. The signal is the transmit power minus the path loss, and in free space the path loss grows by 20 dB for every tenfold distance: 20 log10(4 pi f / c) + 20 log10(d). At 433.4 MHz, the first term is 25.2 dB. The HC-12 library adds 51 dB for the small spring antennas, the ground and a fade margin, which makes the ranges match the manual's own table. Worked example at 100 m: the loss is 25.2 + 40 + 51 = 116.2 dB, so the transmitter needs at least 116.2 - 112 = 4.2 dBm. The HC-12's eight power levels P1 to P8 are -1, 2, 5, 8, 11, 14, 17 and 20 dBm, so P3 (5 dBm) is the first that reaches, with 0.8 dB to spare. At 250 m, the loss is 124.1 dB and the need 12.1 dBm: P6. At 500 m, 18.2 dBm: P8 with 1.8 dB to spare. At 1 km, 24.2 dBm: more than the HC-12 can give. The full range at P8 and 9600 baud is about 620 m, and every 6 dB less power halves it, just as the manual says.

Answered Messages: No Answer, No Delivery

A message from the gate is a short line of text: "G,12,M,3" means message number 12, type M (mail), sent at power P3. The types are V for a visitor, M for mail delivered, C for mail collected and H for a heartbeat. The house replies at once with "A,12", and the gate waits up to 400 ms for that reply. 400 ms is enough: the message and the reply are about 14 bytes together, about 15 ms on the serial lines at 9600 baud, plus the HC-12's own delay, which the manual puts at 4 to 80 ms in FU3, once for the message and once for the reply. If no reply comes, the gate sends the same message again with the same number. That creates a subtle problem: when the house heard the message but its reply was lost, the house gets the message twice. So the house remembers the last number it saw: a repeat is answered again, because the gate needs the reply, but counted only once, so one letter is never counted as two.

Adaptive Transmit Power: the Least That Reaches

The gate starts at P1, -1 dBm, less than a milliwatt. A message that gets no answer is sent twice at each power level, then the power goes up one level and the message goes again, until the house answers. If even P8 fails, the event is kept and sent with the next heartbeat. Climbing is only half of the job: if the gate moves closer, or the weather clears, the power should come down again. After 3 messages in a row answered at the first try, the gate steps down one level, and the next message tests the lower level. If the lower level does not reach, the gate goes back up, and it waits twice as long before it tests again: 6 answers, then 12, then 24, up to 48. Without that doubling, a link right at the edge between two levels would test the lower one every 15 seconds forever, and each failed test costs two lost tries. When the link changes for real, a message lost at the level that worked before, the wait goes back to 3. This is the same idea as the exponential back-off that Ethernet and Wi-Fi use when a channel is busy. Only the gate adapts: the house runs from the mains, so it answers at the HC-12's factory P8, and its answers arrive with a wide margin.

Changing the Power with AT Commands

The HC-12 takes AT commands while its SET pin is low. The gate pulls SET low, waits 60 ms, sends "AT+P3", and the module replies "OK+P3". When SET goes high again, the module switches to the new setting within 80 ms, so the gate waits 100 ms before it sends anything. While SET is low the radio does not transmit, so a power change costs about a fifth of a second; with a step every few messages at most, that is nothing. The setting is also stored in the module, which is why the README lists "P8 stored": an HC-12 fresh from the factory starts at full power, and the gate sets P1 as the first thing it does.

Noticing a Silent Gate

An event can happen once a day, so the house cannot judge the link by events alone. The gate sends a heartbeat every 5 seconds, and the house notes the time of every message it hears. When 16 seconds pass with nothing, three heartbeats missed plus a margin, the house shows GATE SILENT on the OLED and the dashboard. The heartbeats do a second job too: they keep the power control working while nothing happens, and they carry any event that could not get through at the time it happened.

The PIR and the Mailbox Switches

The HC-SR501 drives its OUT pin high while it sees a moving warm body, and the gate counts a visitor on the rising edge. The flap and door switches are pressed by the post and by the hand that collects it. A real switch bounces for a few milliseconds when it closes, and a fast loop would see that as several presses; so the gate counts an edge only when the input has been steady for 300 ms. The same rule keeps a person who stands still and then moves again from counting twice in a moment.

The Arduino Code Explained

The project has two sketches, both written in the Arduino IDE for the ESP32 DevKit V1: ESP32_Gate_Node.ino for the gate and ESP32_Gate_House.ino for the house. The gate needs no extra library; the house uses WiFi and WebServer for the dashboard and Adafruit SSD1306 for the OLED. The gate's pins, its timing and the power table in dBm:

const int PIR = 27, FLAP = 25, DOOR = 26, SET_PIN = 4;
const unsigned long BEAT_MS = 5000, ACK_MS = 400;
const int TRIES = 2, DOWN_AFTER = 3;
const int DBM[9] = {0, -1, 2, 5, 8, 11, 14, 17, 20};

The HC-12 on the second UART, 9600 baud on GPIO16 and GPIO17:

  Serial2.begin(9600, SERIAL_8N1, 16, 17);

A power change: SET low, the command, and SET high again with time for the module to switch:

  digitalWrite(SET_PIN, LOW); delay(60);
  while (Serial2.available()) Serial2.read();
  Serial2.print(F("AT+P")); Serial2.print(p);
  digitalWrite(SET_PIN, HIGH); delay(100);

Every message carries its number, its type and the power it was sent at:

      Serial2.print(F("G,")); Serial2.print(s); Serial2.print(','); Serial2.print(type); Serial2.print(','); Serial2.print(power); Serial2.print('\n');

The gate accepts only the answer with the same number:

        if (line[0] == 'A' && line[1] == ',' && atoi(line + 2) == s) return true;

Three answers at the first try, and the gate tests one level lower:

        if (tries == 1 && ++firstTryRun >= downAfter && power > 1) { firstTryRun = 0; probing = true; setPower(power - 1); }   // try less

A failed test goes back up and doubles the wait; a real loss resets it:

      wasProbe = false; downAfter = min(downAfter * 2, 48);
    } else downAfter = DOWN_AFTER;                                  // (a real loss: the link changed - probe down soon again)

An edge counts only after 300 ms of a steady input:

  if (flap && !flapWas && now - flapT > 300) { flapT = now; event('M'); }

The heartbeat, which also carries an event that did not get through:

    char t = pending ? pending : 'H';
    if (send(t)) pending = 0;

On the house, the answer goes out first, before anything else, because the gate is waiting for it:

  Serial2.print(F("A,")); Serial2.print(s); Serial2.print('\n');  // the answer first: the gate waits 400 ms for it

A repeated number is answered but counted once:

  if (s == lastSeq) { repeats++; return; }                         // (a repeat: the gate missed our answer - answered, counted once)

The MAIL lamp follows the count of letters waiting:

  digitalWrite(MAIL_LED, mail ? HIGH : LOW);

And the silent gate:

  if (heard && !silent && millis() - lastHeard > SILENT_MS) {

The house serves its pages from one handler that reads the address itself: each separate web.on() handler costs memory, and the dashboard needs only three pages, / (the dashboard), /reset (the counts) and /data (JSON). The OLED gets a new frame once a second, four lines of 21 letters: the mail and the visitors, the gate's power or GATE SILENT, the packets heard, and the last event. Both sketches print every event and every power change on the serial monitor with the time since the start.

How to Run the Proteus Simulation

  1. Download the project zip below and install the library files (the steps are under the download button).
  2. Open ESP32-HC12-Gate-Alert.pdsprj from the Proteus Simulation folder. Keep both HEX files and the DLL files next to it.
  3. Press Play. The gate's first heartbeat climbs from P1 until the house answers; the radios start 100 m apart.
  4. On the PIR's pop-up (U5) press Walk in: a visitor. Press SW1, the flap: mail, and the MAIL lamp lights.
  5. On the gate HC-12's pop-up (U4), press 250 m and watch the gate climb; press 1 km and the house reports GATE SILENT.
  6. Open the Laptop or the Mobile WiFi Monitor and press Go for the dashboard.

Simulation Results: the Gate Alert in Proteus

Here is the run that made the screenshots of this tutorial, 71 seconds of simulation. The times are the sketches' own clocks, as they printed them on the two serial monitors; the radio levels come from the HC-12 pop-ups, which judge every packet by the link budget above.

Online at 100 m: P3

The radios start 100 m apart. The gate sets P1 and sends its first heartbeat: no answer, twice. P2: no answer, twice. P3: at 3.4 s, "H #1 answered at P3 (5 dBm), try 5", and the house prints "the gate node online - P3 (5 dBm)". The gate HC-12's pop-up shows the reason in one line: "At 100 m: -111 dBm, needs -112 dBm, OK (+0.8 dB)", exactly the worked example above. Its traffic panel shows the last AT command, AT+P3 answered with OK+P3, and the house's answer A,1 heard at -96 dBm: the house answers at the factory P8, 15 dB stronger than the gate needs to be.

The HC-12 gate alert Proteus simulation: both ESP32 nodes running, the OLED showing GATE P3 5 DBM OK
Figure: The gate online at P3.
HC-12 pop-up in the Proteus simulation: the gate at P3, -111 dBm at 100 m against -112 dBm needed, OK by 0.8 dB
Figure: The gate's HC-12 at 100 m.
OLED pop-up in the Proteus simulation: NO MAIL, VISIT 0, GATE P3 5 DBM OK, GATE ONLINE
Figure: The house's OLED.
Laptop WiFi Monitor in the Proteus simulation: the gate alert dashboard, the gate OK at P3
Figure: The dashboard: the gate online.

A Visitor, Then the Post

Walk in on the PIR's pop-up, and the sensor sees a person 3.5 m away; its OUT pin goes high 0.10 s later. At 7.0 s the gate prints "a VISITOR at the gate (the PIR)", the house answers 0.1 s later and prints "a VISITOR at the gate (#3, P3)", and the OLED's last line says VISITOR AT THE GATE. At 9.1 s SW1, the flap: "MAIL delivered (#4, P3)", the amber MAIL lamp lights, and the OLED says YOU HAVE MAIL with MAIL x1 at the top. Each event took one try: at 100 m and P3 the link has 0.8 dB to spare.

The HC-12 gate alert Proteus simulation: the PIR sees a visitor, the OLED says VISITOR AT THE GATE
Figure: A visitor at the gate.
HC-SR501 pop-up in the Proteus simulation: a person walking in at 3.5 m, OUT HIGH 0.10 s after it was seen
Figure: The PIR sees the visitor.
OLED pop-up in the Proteus simulation: VISIT 1, GATE P3 5 DBM OK, PACKETS 3, VISITOR AT THE GATE
Figure: The OLED: a visitor.
The HC-12 gate alert Proteus simulation: mail delivered, the amber MAIL LED lit and the OLED saying YOU HAVE MAIL
Figure: Mail in the box: the MAIL lamp on.
OLED pop-up in the Proteus simulation: MAIL x1, VISIT 1, PACKETS 4, YOU HAVE MAIL
Figure: The OLED: you have mail.
Laptop dashboard in the Proteus simulation: MAIL waiting 1, visitors 1, the events with their numbers
Figure: The dashboard: mail waiting.

250 m: the Power Climbs to P6

Three answers at the first try in a row, so at 9.3 s the gate tests a lower level: "power P2 (2 dBm)". Then the gate HC-12 moves to 250 m. The next heartbeat goes out at P2 twice without an answer, and the gate prints "P2 too weak - back up; the next try lower after 6 answers". Back at P3 the heartbeat fails again, twice, because the link has changed; so this counts as a real loss, the wait goes back to 3, and the power climbs: P4, P5, P6. At 15.4 s, "H #5 answered at P6 (14 dBm), try 9". The pop-up agrees: "At 250 m: -110 dBm, needs -112 dBm, OK (+1.9 dB)", the range of these settings about 310 m. The house's HC-12 has counted every packet that arrived too weak, 12 in all, and the last one it heard came in at -110 dBm. The OLED and the dashboard now say P6, 14 dBm.

HC-12 pop-up in the Proteus simulation: the gate at 250 m on P6, -110 dBm against -112 dBm, OK by 1.9 dB
Figure: The gate's HC-12 at 250 m.
HC-12 pop-up in the Proteus simulation: the house radio, 12 packets too weak, the last one heard at -110 dBm
Figure: The house's HC-12 counts the weak packets.
Laptop dashboard in the Proteus simulation: the gate OK at power P6, 14 dBm
Figure: The dashboard: P6.

At 18.2 s SW2, the door: "the mail collected (#7, P6)", one try at the new level. The house sets the mail count to zero, the MAIL lamp goes out, and the OLED says MAIL COLLECTED.

OLED pop-up in the Proteus simulation: NO MAIL, GATE P6 14 DBM OK, PACKETS 7, MAIL COLLECTED
Figure: The OLED: the mail collected.

1 km: GATE SILENT

Now the gate moves to 1 km, beyond the 620 m that even P8 can reach. The next heartbeat climbs P6, P7, P8 and gives up: "H #8 - NO ANSWER even at P8 (+20 dBm) after 6 tries: the house is out of reach". The pop-up: "At 1 km: -116 dBm, needs -112 dBm, TOO WEAK (-4.2 dB)". Two more heartbeats fail at P8. The house has heard nothing since 18.3 s, and at 34.2 s, exactly 16 s later: "GATE SILENT - nothing for 16.0 s (3 heartbeats missed)". The OLED and the phone show it at once.

The HC-12 gate alert Proteus simulation at 1 km: the OLED showing GATE SILENT
Figure: GATE SILENT.
HC-12 pop-up in the Proteus simulation: the gate at 1 km on P8, -116 dBm against -112 dBm, TOO WEAK by 4.2 dB
Figure: The gate's HC-12 at 1 km: too weak even at P8.
OLED pop-up in the Proteus simulation: GATE SILENT on two lines, PACKETS 7
Figure: The OLED: the gate silent.
Mobile WiFi Monitor in the Proteus simulation: Gate SILENT, heard 17.2 s ago, the events
Figure: The phone: the gate silent.

Back in Range: the Power Steps Down

The gate HC-12 goes to 50 m. The next heartbeat, still at P8, is answered at the first try: at 36.4 s the house prints "the gate is back - P8 (20 dBm)". Now the power comes down one level after every 3 answers: P7 at 46.7 s and P6 at 61.7 s, each new level answered at the first try. One detail of the model shows here: the link uses the larger of the two radios' DISTANCE settings, and the house's radio still says 100 m. So the link is a 100 m link, the gate's pop-up line "At 50 m" is only its own half of the story, and the gate is on its way back down to P3, one level every 15 s. Once it gets there, the test of P2 will fail, and the wait doubles to 6 answers, then 12. The run ended there, after 71 seconds of simulation, with no repeated message all the way: every answer reached the gate.

The HC-12 gate alert Proteus simulation: the gate back in range, the OLED showing GATE P6 14 DBM OK and GATE BACK
Figure: The gate back, stepping down.
HC-12 pop-up in the Proteus simulation: the gate set to 50 m and back down to P6, the answers heard at -96 dBm
Figure: The gate's HC-12 back in range.
Laptop dashboard in the Proteus simulation: the gate back at P6, GATE SILENT and the gate is back in the events
Figure: The dashboard at the end.
Gate ESP32 serial monitor in the Proteus simulation: every message, every try and every power level
Figure: The gate's serial monitor: the whole run.
House ESP32 serial monitor in the Proteus simulation: online, the visitor, the mail, GATE SILENT, the gate back
Figure: The house's serial monitor.
The results of the gate alert simulation
MomentDistanceThe gateThe radio (pop-up)
Online (3.4 s)100 mP3 after P1 and P2, try 5-111 dBm, OK +0.8 dB
Visitor, mail (7.0 s, 9.1 s)100 mP3, try 1-
Climb (15.4 s)250 mP6, try 9-110 dBm, OK +1.9 dB
Mail collected (18.2 s)250 mP6, try 1-
GATE SILENT (34.2 s)1 kmno answer at P8-116 dBm, TOO WEAK -4.2 dB
Back (36.4 s)50 m (link 100 m)P8, then P7 at 46.7 s, P6 at 61.7 sanswers at -96 dBm
Simulation-71 s of simulation, 0 repeats-

Download the Project Files

Click the button below to download HC-12-433MHz-Mailbox-Gate-Alert-ESP32-Proteus-Simulation-v1.0.zip (about 4.8 MB, without the source code of the models):

HC-12 433 MHz Mailbox and Gate Alert with ESP32 - Proteus Simulation V1.0
  • Proteus Simulation: ESP32-HC12-Gate-Alert.pdsprj, ESP32_Gate_House.hex, ESP32_Gate_Node.hex and copies of the models.
  • Arduino Code: ESP32_Gate_House.ino and ESP32_Gate_Node.ino, the two sketches.
  • Proteus Library Files: the LIB files of the ESP32 DevKit V1, the HC-12, the PIR, the push button, the SMD LED and resistor, the OLED and the two WiFi Monitors.
  • Proteus Model Files: the DLL models.
  • README.txt: the installation steps, the properties, the test results and the links to every library post.

No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.

How to Install the Project Files

  1. Close Proteus and extract the whole zip file, for example to your Desktop.
  2. Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
  3. Copy the files from Proteus Model Files into the MODELS folder.
  4. Start Proteus and open the project from the Proteus Simulation folder.

Changing the Code

Open either sketch in the Arduino IDE with the TEP boards for Proteus installed, compile it, export the compiled binary and set U1's or U3's PROGRAM property to the new HEX file. The heartbeat, the answer timeout, the tries at each level and the answers before a step down are at the top of the gate's sketch; the silent time is at the top of the house's. Both HC-12s must stay on the same channel, mode and baud rate.

Ideas to Extend the Project

  • Put the gate ESP32 into deep sleep between heartbeats and wake it on the PIR and the switches, then compare the battery life at P1 and at P8.
  • Use the HC-12's FU2 mode, 80 microamps when idle, for a gate that must run for months on batteries.
  • Add a second gate or a garage door on the same channel, each with its own name in the message.
  • Log the power level over a day and see how the weather would move it on a real link.
  • Send a phone notification from the house when mail arrives, through a web service of your choice.
  • Add a checksum to each message, so a corrupted line is answered with a request to send again.

From Simulation to Real Hardware

  • Give the HC-12 a clean supply: it draws up to 100 mA while it transmits at 20 dBm; the manual asks for a supply that can give at least 200 mA and a reservoir capacitor of at least 22 uF, preferably 1000 uF, and for long transmissions above 4.5 V a 1N4007 diode in series.
  • Mind the antenna: the small spring antenna is the weak point of the link; a quarter-wave wire (about 17 cm at 433 MHz) or an external antenna adds many metres.
  • Logic levels: the HC-12's UART pins have 1k resistors inside the module; measure your module's TXD level before you join it to a 3.3 V ESP32 input, and never hang an LED on TXD, as the manual warns.
  • The real path: walls, trees and wet weather add their own loss; let the power control find the level, and keep a few dB of margin by stepping down only after more answers.
  • The law: 433 MHz is a licence-free band in many countries but with limits on power and duty cycle; check the rules where you live before you use 20 dBm.

Troubleshooting

  • Nothing gets through: both HC-12s on the same channel, mode and baud rate; check the DISTANCE on their pop-ups.
  • "NO REPLY from the HC-12" on the gate: SET must go to D4; in AT mode the module answers OK+Px.
  • The PIR never triggers: VCC on the 5 V rail; it sees only a moving warm body (Walk in, not Stand still).
  • One press counted twice: the button bounces; the gate counts an edge only 300 ms after the last one.
  • The OLED stays blank: SDA / SCL on D21 / D22, address 0x3C, VCC on 3.3 V.

Limitations of the Simulation

  • The radio link is the library's model: the free-space loss plus 51 dB, the manual's sensitivities, and a clean OK or TOO WEAK at each distance, without fading or interference.
  • The link uses the larger of the two radios' DISTANCE settings; moving one radio closer than the other's setting changes nothing.
  • The PIR sees what its pop-up says: a person walking in, standing still or walking out.
  • The network to the laptop and the phone is simulated inside Proteus.
  • ESP32 is a product of Espressif Systems; this project is not made or endorsed by them or by Labcenter.

So, that was all about the HC-12 433 MHz Mailbox and Gate Alert with ESP32 - Proteus Simulation. I hope it helps you understand how far a 433 MHz radio reaches and why, how answered messages and numbers make a lossy link reliable, how a heartbeat turns silence into news, and how a radio can find the least power it needs and save its battery, all tested in a simulation before you build the real gate. More IoT projects with the ESP32 and the Raspberry Pi 5 are coming in this series. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!


Comments

0

Join the conversation