DEV Community

Cover image for ESP8266 IR Sensor IoT Project with KiwisIoT
manikanda balamurugan S
manikanda balamurugan S

Posted on Edited on

ESP8266 IR Sensor IoT Project with KiwisIoT

Introduction

This project uses an ESP8266 NodeMCU and an IR sensor to detect objects in real time. The detection status is sent to the KiwisIoT dashboard through Wi-Fi.

Components Required

  • ESP8266 NodeMCU
  • IR sensor module
  • Jumper wires
  • USB cable
  • Computer

Software Requirements

  • Arduino IDE
  • ESP8266 board package
  • KiwisIoT Arduino library
  • KiwisIoT account
  • Wi-Fi connection

CIRCUIT DIAGRAM

How It Works

  1. The IR sensor detects whether an object is present.
  2. The ESP8266 reads the sensor's digital output.
  3. The system identifies the status as DETECTED or NOT DETECTED.
  4. The ESP8266 sends the status to KiwisIoT over Wi-Fi.
  5. The dashboard displays the detection status for remote monitoring.

In this project, a LOW signal indicates that an object has been detected, while a HIGH signal indicates that no object is detected.

ARDUINO CODE:

#include <ESP8266WiFi.h>
#include <KiwisIoT.h>

const char* ssid = "YOUR_WIFI_NAME";
const char* pass = "YOUR_WIFI_PASSWORD";

const char* topic = "YOUR_DASHBOARD_TOPIC_ID";

#define IR_PIN D7

KiwisIoT kiwisiot(ssid, pass, topic);

void sendObjectStatus() {
  int irState = digitalRead(IR_PIN);
  String objectStatus;

  if (irState == LOW) {
    objectStatus = "DETECTED";
  } else {
    objectStatus = "NOT DETECTED";
  }

  Serial.println();
  Serial.println("---------- IR MONITORING ----------");

  Serial.print("IR Sensor Value: ");
  Serial.println(irState);

  Serial.print("Object Status: ");
  Serial.println(objectStatus);

  kiwisiot.send("0", objectStatus);

  Serial.print("Sent to KiwisIoT Channel 0: ");
  Serial.println(objectStatus);
}

void setup() {
  Serial.begin(115200);

  Serial.println();
  Serial.println("     IR OBJECT MONITORING     ");

  pinMode(IR_PIN, INPUT);

  Serial.println("IR sensor initialized");
  Serial.println("Connecting to KiwisIoT...");

  kiwisiot.begin();

  Serial.println("KiwisIoT initialized");
  Serial.println("Starting object monitoring...");
}

void loop() {
  kiwisiot.run();

  static unsigned long lastSend = 0;

  if (millis() - lastSend >= 2000) {
    lastSend = millis();
    sendObjectStatus();
  }

  delay(100);
}
Enter fullscreen mode Exit fullscreen mode

Applications

  • Object detection
  • Entry monitoring
  • Smart parking concepts
  • Obstacle detection
  • Automation projects
  • IoT monitoring systems

What I Learned

Through this project, I learned how to connect an IR sensor to an ESP8266, read digital sensor values, and send sensor data to an IoT dashboard.

I used the reference to understand the concept and implement the project.

GitHub Reference:https://github.com/Kiwistron/KiwisIoT-Projects/tree/main/esp8266/002-ir-kiwisiot

My GitHub Repository: https://github.com/bala02102008/IR-Sensor-IoT-Project-using-KiwisIoT-

Conclusion

This project demonstrates how basic sensors and Wi-Fi connectivity can be combined with an IoT platform for real-time object monitoring.

I hope this project helps beginners explore IoT and embedded systems.

Top comments (0)