Wireless bell using ESP-01 Wi-Fi microcontroller
58 View(s)
0 Like(s)
2 Comment(s)
SO
Seun Omolayo
Author

Description
The wireless doorbell project aims to create a convenient and reliable system for receiving doorbell notifications. It consists of a wireless doorbell button and a receiver unit. The project will be implemented using two ESP-01 boards and ESP-NOW communication protocol, with a focus on power efficiency.
Project Documentation
The primary goal of the wireless doorbell project is to create an easy-to-use and reliable system that promptly notifies users when someone is at their door. The system comprises a wireless doorbell button, strategically placed near the entrance, and a wireless receiver unit that connects to the existing doorbell. Its versatile design allows it to be installed on any type of door, making it incredibly convenient.
Once the wireless doorbell button is pressed, signals are transmitted via a transmitter to the receiver unit, promptly triggering the doorbell to ring. This seamless process ensures that occupants are promptly alerted to visitors without the need for complicated wiring or installation procedures.
The wireless doorbell system finds practical applications in both homes and offices. It effectively notifies residents of visitors, providing a more comfortable and secure living environment. Similarly, in office settings, it proves invaluable in alerting employees or staff members that someone is waiting to enter, enhancing security and accessibility.
Components and suppliers
- ESP-01
- Relay
- Headers
- Resistor 10k x 2
- 1N4007 Diode
- Transistor BC547
- Vero Board
- Wires
- Doorbell switch
- Doorbell Gong
- Pattress box x 2
- 5volt SMPS module
- 3.7volt Lithium battery
- 3.7volt single battery rack
Apps and IDE
- Arduino IDE - The Arduino IDE (Integrated Development Environment) is a software application used to program and develop projects for Arduino microcontrollers. Arduino is an open-source electronics platform that provides a simple and user-friendly way to create interactive projects and prototypes.
- Proteus 8 - Proteus 8 is a popular electronic design automation (EDA) software package developed by Labcenter Electronics. It is widely used for simulating, designing, and testing electronic circuits and microcontroller-based projects. Proteus 8 offers an integrated solution for circuit design, PCB layout, and microcontroller simulation, making it a valuable tool for electronics engineers, hobbyists, and students.
Tools and machine
- 60-watt soldering iron and soldering lead
- Wire stripper
- Scissors
- Hot Glue Gum
- Multimeter
Hardware overview
Button Circuit
Schematic diagram of the doorbell button circuit (transmitter).
The bell button is connected between the RST pin and the GND pin of the ESP-01 module. To provide a pull-up functionality, a 10k resistor is connected between the VCC and RST pins. This setup enables the button circuit to utilize the deep sleep function, optimizing power consumption.
When the doorbell button is pressed, it pulls the RST pin low, which acts as an external interrupt, waking up the ESP-01 board from deep sleep mode. Upon awakening, the board promptly establishes a connection to the receiver and sends a message to indicate that the button has been pressed. Subsequently, the ESP-01 board goes back to sleep immediately, conserving power until the next button press event.
Bell Circuit
Schematic diagram of the doorbell circuit (receiver).
The receiver circuit remains constantly active, waiting to establish a connection with the transmitting board when it wakes up. The ESP board's GPIO2 pin is connected to the base of a transistor, and a 10k resistor is placed in parallel with it. The transistor's emitter is connected to the negative terminal of the 5V module, while its collector is linked to one of the relay's pins. To protect the circuit, a diode is connected across the relay's pins with the correct polarity to dissipate high voltage spikes when the relay turns off.
The other pin of the relay is connected to the positive terminal of the 5V module. The bell is connected to the Normally Open (NO) pin of the relay, with its other terminal going to the ground of the 220V AC power supply. Lastly, the common (COM) pin of the relay is connected to the live terminal of the AC power supply.
When a successful communication is established with the transmitter, and the receiver receives a valid message, the ESP-01 board immediately sets the GPIO2 pin to a high state. This action turns on the transistor, closing the relay's circuit, which subsequently activates the bell, resulting in it ringing.
- ESP-01
The ESP-01 is a Wi-Fi module with programmable capabilities that provides two GPIO pins, IO0 and IO2. In this project, we utilize the ESP-01 board in both the button and the bell circuits. The communication between these boards is facilitated using the ESP-NOW protocol, which operates on the 2.4GHz frequency and is specifically designed for ESP boards. ESP-NOW enables direct communication between ESP devices without the need for a Wi-Fi network.
To elaborate on the project's functionality, one ESP-01 board acts as the button device, equipped with a physical button connected to one of its GPIO pins. When the button is pressed, this ESP-01 board sends a signal or a specific message through ESP-NOW.
On the other hand, the second ESP-01 board serves as the bell device, controlling a bell or a notification mechanism. When the bell circuit's ESP-01 board receives the signal from the button device through ESP-NOW, it triggers the bell or notification mechanism to perform its intended action.
The project's success relies on properly configuring the ESP-01 modules and establishing the ESP-NOW communication between them.
- Relay
In this project, a relay is employed to control the doorbell's ON and OFF states. Relays function as electromagnetic switches that use a small current to manage the flow of a much larger current in a circuit. When the doorbell button is pressed, a small electrical signal is generated, which may not be sufficient to directly activate the doorbell mechanism. By utilizing the relay, the small signal can control the switching of the larger current required to activate the doorbell. This setup ensures the safe separation.
- Headers
These headers are connectors that will be soldered to the board to facilitate incoming connections.
- Resistor 10k x 2
Resistors are renowned for their capability to impede the flow of electric current within a circuit. In the project, a 10k resistor was utilized in two roles - as a pull-up resistor and as a base resistor.
- 1N4007 Diode
The 1N4007 Diode is a versatile and commonly used general-purpose diode. In this context, it is employed as a protection diode for the transistor, serving to mitigate the impact of high voltage spikes generated by the relay when it is switched OFF.
- Transistor BC547
To avoid unhealthy conditions when triggering the relay directly from the Esp board, a BC547 transistor is introduced to serve as an intermediary for relay activation.
- Vero Board
All the components will be arranged and soldered onto the Vero board.
- Wires
Wires are required to establish connections between the components.
- Doorbell switch
Any kind of doorbell switch is suited for this project.
- Doorbell Gong
The Door Gong functions by generating a sound when an electric current passes through it. Its primary purpose is to alert the residents in a building, notifying them of visitors at the front door.
- Pattress box x 2
It will act as an enclosure for our project.
- 5volt SMPS module
In order to power the receiver circuit and the relay, a 5V module is utilized. This 5V module is a Switch Mode Power Supply (SMPS) that performs the conversion from 220V to 5V, supplying power to the board.
- 3.7volt Lithium battery
The button circuit in the project is powered by a 3.7V battery, which supplies the required voltage for its operation.
- 3.7volt single battery rack
A single 3.7V battery rack hold and maintain the battery's connection to the circuit.
Software Overview
Before writing the main sketch, we need to obtain the MAC address of the receiving board. To achieve this, the provided sketch should be compiled and uploaded to the board.
You can download the project from GitHub.
#include <ESP8266WiFi.h>
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println();
Serial.print("MAC Address: ");
Serial.println(WiFi.macAddress());
}
void loop() {
}
Once you have successfully uploaded the sketch to the board, open the serial monitor and set its baud rate to 115200. Afterward, press the reset button on the board, and you should see the MAC address displayed in the serial monitor.
You can now copy the MAC address and paste it into the sketch for the transmitting circuit.
Sketch for the Button (Transmitting) Circuit
#include <ESP8266WiFi.h>
#include <espnow.h>
// Replace this with the mac address of the receiving EspO1 board
uint8_t broadcastAddress[] = { 0xFC, 0xF5, 0xC4, 0x96, 0xEC, 0x2B };
// create a structure must be thesame on both
// the sender and receiver
typedef struct struct_message {
bool state;
} struct_message;
struct_message data;
// Callback when data is sent
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
Serial.print("Last Packet Send Status: ");
if (sendStatus == 0) {
Serial.println("Delivery success");
} else {
Serial.println("Delivery fail");
}
}
void setup() {
// Init Serial MonitorSerial.begin(115200);
// Set device as a Wi-Fi StationWiFi.mode(WIFI_STA);
// Init ESP-NOWif (esp_now_init() != 0) {Serial.println("Error initializing ESP-NOW");return;
}
esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
esp_now_register_send_cb(OnDataSent);
// Register peeresp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
// rings bell from rest
rst_info *resetInfo = ESP.getResetInfoPtr();
if (resetInfo->reason == REASON_DEEP_SLEEP_AWAKE) {
data.state = true;
esp_now_send(broadcastAddress, (uint8_t *)&data, sizeof(data));
Serial.println("\\nrings bell");
}
delay(100);
Serial.println("Esp going to sleep...");
ESP.deepSleep(0);
}
void loop() {}
How the code works
First, include the ESP8266WiFi.h
and espnow.h
libraries.
#include <ESP8266WiFi.h>
#include <espnow.h>
Following that, you should insert the MAC address of the ESP-01 receiver in the next line.
uint8_t broadcastAddress[] = { 0xFC, 0xF5, 0xC4, 0x96, 0xEC, 0x2B };
In our case, the receiver MAC address is FC:F5:C4:96:EC:2B, but you should replace that variable with your specific MAC address.
Next, create a structure to hold the data that will be sent. In this example, we have declared a Boolean variable named 'data' to send a Boolean command.
// create a structure must be thesame on both
// the sender and receiver
typedef struct struct_message {
bool state;
} struct_message;
struct_message data;
After that, define the OnDataSent()
function. It serves as a callback function that will be executed when a message is successfully sent. In this project, the function was used primarily for debugging purposes.
// Callback when data is sent
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
Serial.print("Last Packet Send Status: ");
if (sendStatus == 0) {
Serial.println("Delivery success");
} else {
Serial.println("Delivery fail");
}
}
In the setup() function, initialize the serial monitor to enable debugging and facilitate communication for testing and debugging purposes.
Serial.begin(115200);
Set the device as a Wi-Fi station:
WiFi.mode(WIFI_STA);
Initialize ESP-NOW:
if (esp_now_init() != 0) {
Serial.println("Error initializing ESP-NOW");
return;
}
Set the ESP8266 role:
esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
Register the callback function:
esp_now_register_send_cb(OnDataSent);
Pair the board with another ESP-NOW device:
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
After the connection has been established this code section checks if the board is waking from a deep sleep.
// rings bell from rest
rst_info *resetInfo = ESP.getResetInfoPtr();
if (resetInfo->reason == REASON_DEEP_SLEEP_AWAKE) {
data.state = true;
esp_now_send(broadcastAddress, (uint8_t *)&data, sizeof(data));
Serial.println("\\nrings bell");
}
rst_info *resetInfo = ESP.getResetInfoPtr();
: This line declares a pointer named resetInfo
, which points to a data structure of type rst_info
. The function ESP.getResetInfoPtr()
retrieves a pointer to a structure containing information about the reason for the last reset of the ESP-01 board.
if (resetInfo->reason == REASON_DEEP_SLEEP_AWAKE)
: This if
statement checks if the reason for the last reset was due to waking up from deep sleep. if true then it means the button was pressed.
data.state = true;
sets data to true.
esp_now_send(broadcastAddress, (uint8_t *)&data, sizeof(data));
sends data using the ESP-NOW protocol.
delay(100);
waits for 100 milliseconds before setting the board to deep sleep.
ESP.deepSleep(0);
sets the board to deep sleep.
Sketch for the Bell (Receiving) Circuit.
#include <ESP8266WiFi.h>
#include <espnow.h>
#define trigger 2
typedef struct struct_message {
bool state;
} struct_message;
struct_message data;
// Callback function that will be executed when data is received
void OnDataRecv(uint8_t *mac, uint8_t *incomingData, uint8_t len) {
memcpy(&data, incomingData, sizeof(data));
if (data.state == true) {
digitalWrite(trigger, HIGH);
Serial.println("Received");
delay(200);
digitalWrite(trigger, LOW);
}
}
void setup() {
pinMode(trigger, OUTPUT);
// Initialize Serial MonitorSerial.begin(115200);
// Set device as a Wi-Fi StationWiFi.mode(WIFI_STA);
// Init ESP-NOWif (esp_now_init() != 0) {Serial.println("Error initializing ESP-NOW");return;
}
// Once ESPNow is successfully Init, we will register for recv CB to// get recv packer infoesp_now_set_self_role(ESP_NOW_ROLE_SLAVE);esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
}
How the code works
Define the pin trigger and set it to GPIO2.
#define trigger 2
A callback function named onDataRecv()
is to be implemented for the ESP-01 module, which will be automatically triggered when the module receives data through ESP-NOW communication. This function will accept multiple parameters to handle the received data effectively.
void OnDataRecv(uint8_t *mac, uint8_t *incomingData, uint8_t len) {
memcpy(&data, incomingData, sizeof(data));
if (data.state == 1) {
digitalWrite(trigger, HIGH);
Serial.println("Received");
delay(200);
digitalWrite(trigger, LOW);
}
}
memcpy(&data, incomingData, sizeof(data));
copies the incoming data into structure.
if (data.state == 1)
check the state variable in the data if it is equal 1 same as equal true.
digitalWrite(trigger, HIGH);
set GPIO2 to high.
delay(200);
wait for 200 milliseconds.
digitalWrite(trigger, LOW);
In the setup()
function.
pinMode(trigger, OUTPUT);
sets GPIO2 to output mode.
Conclusion
The wireless bell using the ESP-01 Wi-Fi microcontroller provides a convenient, cost-effective, and eco-friendly solution. With real-time notifications and easy customization, it enhances home security and communication while eliminating the need for physical wiring. Its compact size and low power consumption make it a reliable and versatile choice for modern doorbell systems.
NaN

Victor Obaro
2 years ago
Thanks, This project helped me, especially the way you explained the code.
0 Likes
·Reply
PO
Paul Onoma
2 years ago
Wow, this is an interesting project. I love this 🥹🥹
0 Likes
·Reply