Lab Experiment Manual Introduction to ESP NOW Communication (Lab Session 6)
Lab Experiment Manual Introduction to ESP NOW Communication (Lab Session 6)
Lab Session: 6
NAME: ______________________
ROLL NO.:__________________
Objective
Theory
1. What is ESP-NOW?
3. Working Principle
ESP-NOW works by using the MAC addresses of ESP devices for communication. Unlike
traditional networking, it does not use IP addresses or an internet connection.
Ⓒ UNIVERSITY of ENGINEERING & TECHNOLOGY
Dr. Faheem Gohar Awan
Mr. Muhammad Ali Musawir
Analog Digital Communication
Lab Session: 6
5. Applications of ESP-NOW
• Sender ESP: The device that transmits data (e.g., a button press).
• Receiver ESP: The device that receives data and performs an action (e.g.,
turning on an LED).
• MAC Address: A unique identifier (e.g., 24:0A:C4:8B:12:34) assigned to each ESP
module for communication.
• ESP-NOW Protocol: Handles secure, low-latency transmission between devices.
3. Communication Flow
The sender and receiver must be paired before exchanging data. The steps are:
• Each ESP has a unique MAC address that can be found using a simple program.
• The sender needs to store the MAC address of the receiver.
• Both ESPs must enable ESP-NOW mode and disable Wi-Fi networking.
• The sender registers the receiver’s MAC address to allow communication.
• The sender transmits a small data packet (e.g., 1 for ON, 0 for OFF).
• The receiver listens and processes the received data.
6. Security in ESP-NOW
Equipment Required
Theory
Each ESP module has a unique MAC address that is needed for ESP-NOW
communication.
#include <WiFi.h>
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
Serial.print("ESP MAC Address: ");
Serial.println(WiFi.macAddress());
}
void loop() {}
2. Initializing ESP-NOW
ESP-NOW requires both devices to be in Wi-Fi station mode but without connecting
to a network.
• Call WiFi.mode(WIFI_STA);
The sender must add the receiver’s MAC address to send data.
ESP-NOW transfers data in small packets (e.g., 1 for ON, 0 for OFF).
Circuit Diagram
#include <WiFi.h>
#include <esp_now.h>
int buttonState = 0;
Ⓒ UNIVERSITY of ENGINEERING & TECHNOLOGY
Dr. Faheem Gohar Awan
Mr. Muhammad Ali Musawir
Analog Digital Communication
Lab Session: 6
int buttonStatus;
} struct_message;
struct_message buttonData;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
return;
esp_now_peer_info_t peerInfo;
peerInfo.channel = 0;
peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
return;
pinMode(buttonPin, INPUT);
void loop() {
buttonState = digitalRead(buttonPin);
buttonData.buttonStatus = buttonState;
delay(100);
#include <WiFi.h>
#include <esp_now.h>
int buttonStatus;
} struct_message;
struct_message receivedData;
digitalWrite(ledPin, receivedData.buttonStatus);
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
return;
esp_now_register_recv_cb(onDataReceive);
pinMode(ledPin, OUTPUT);
void loop() {
Procedure
Conclusion