ESP8266 IR Sensor Counter with Wi-Fi Logging, MAX7219 Display & Data History Graphs (Complete IoT Project Guide)
🔎 Introduction
IoT projects using ESP8266 are one of the best ways to learn embedded systems, networking, and real-time monitoring. In this project, we build a smart object counter system using an IR Sensor (Flying Fish v1.1), ESP8266 microcontroller, and MAX7219 LED display.
The system connects to home Wi-Fi (Router Mode) and logs sensor activity to create data history and graphical analytics.
This project is useful for:
- Visitor counting systems
- Production line monitoring
- Smart attendance tracking
- Inventory automation
- Entry/Exit monitoring systems
⚙️ Components Used
# MAX7219 LED Display Module - MAX7219 4-in-1 Display Dot Matrix Module is an integrated serial input/output common-cathode display driver, it connects the microprocessor 7-segment digital LED display with 8 digits, you can also connect a bar graph display or 64 independent
# 10K Resistor - A 10K resistor is mainly used for signal stability and protection in electronics. In your ESP8266 / sensor projects, common uses are:
# Push Buttons - Ensures reliable ON/OFF detection
# Breadboard – Used to connect components without soldering. Helpful for quick prototyping.
👉 Note: 3-Digit 7-Segment Display is optional because MAX7219 handles digital output more efficiently.
Why Use IR Sensor Instead of MH Flying Fish Sensors?
Currently, IR Sensor is preferred because:
👉 Use MH sensors later for:
- Gas detection
- Flame detection
- Sound detection
- Environmental monitoring
🔌 Hardware Connections
Sensor NodeMCU 8266 ESP
- VCC -> 3V3
- GND -> GND
- D0 -> D2
switch
- OFF -> GND
- ON(I) -> D1
MAX7219 NodeMU 8266 ESP
- VCC -> VIN
- GND -> GND
- DIN -> D7
- CS -> D8
- CLK -> D5
This Exact Setup:
Code
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define DIN_PIN D7
#define CLK_PIN D5
#define CS_PIN D8
#define IR_PIN D2
#define SWITCH_PIN D1
MD_Parola display = MD_Parola(HARDWARE_TYPE, DIN_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
ESP8266WebServer server(80);
volatile int count = 0;
bool lastIRState = HIGH;
/* ---------- Wi-Fi credentials ---------- */
const char* ssid = "Airtel_ajay_4747";
const char* password = "air83128";
/* ---------- Web page ---------- */
void handleRoot() {
String page =
"<!DOCTYPE html><html><head>"
"<meta name='viewport' content='width=device-width, initial-scale=1'>"
"<meta http-equiv='refresh' content='2'>"
"<title>ESP8266 Counter</title></head><body>"
"<h2>Live Counter - Hackingtruth.in | .org </h2>"
"<h1>" + String(count) + "</h1>"
"<a href='/reset'><button>Reset</button></a>"
"</body></html>";
server.send(200, "text/html", page);
}
void handleReset() {
count = 0;
server.sendHeader("Location", "/");
server.send(303);
}
void setup() {
pinMode(IR_PIN, INPUT);
pinMode(SWITCH_PIN, INPUT_PULLUP);
display.begin();
display.setIntensity(5);
display.displayClear();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
server.on("/", handleRoot);
server.on("/reset", handleReset);
server.begin();
}
void loop() {
server.handleClient();
bool currentIRState = digitalRead(IR_PIN);
if (lastIRState == HIGH && currentIRState == LOW) {
count++;
if (count > 999) count = 0;
delay(300);
}
lastIRState = currentIRState;
if (digitalRead(SWITCH_PIN) == LOW) {
count = 0;
}
char buf[4];
sprintf(buf, "%03d", count);
display.displayText(buf, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
display.displayAnimate();
}
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("ESP8266 IP Address: ");
Serial.println(WiFi.localIP());
- Hold FLASH button
- Click Upload
- Release FLASH when uploading starts
How to Check:
- # Look at the top-right corner of the Arduino IDE.
- # If the Serial Monitor is open, you’ll see a window titled “Serial Monitor” (it looks like a terminal).
- # Simply close that window by clicking the X at the top-right of it.
Why it matters:
Disclaimer
All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.











