DEV Community

Cover image for Powered Smart Detection System Using KiwisIoT
S. Nishanth
S. Nishanth

Posted on Edited on

Powered Smart Detection System Using KiwisIoT

How It Started

I wanted to try something interesting with IoT, so I decided to build a simple object detection system using an IR sensor and an ESP8266 NodeMCU.

My idea was simple: instead of checking the sensor output only through the Serial Monitor, I wanted to monitor object detection remotely using a live dashboard.

That's how I started my project!

Building the Project

I used an ESP8266 NodeMCU, an IR obstacle sensor, jumper wires, and a USB cable.

circuit diagram

The connections were simple:

VCC → 3V3

GND → GND

OUT → D7

After completing the connections, I started programming the ESP8266 using Arduino IDE.

coding

#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

The sensor detects objects using infrared light. When an object is detected, its output becomes LOW. Otherwise, it remains HIGH.

I programmed the ESP8266 to read the sensor every two seconds and send the status to the KiwisIoT dashboard through Wi-Fi.

Connecting to the Dashboard

This was my favourite part of the project!

I connected the ESP8266 to Wi-Fi and configured the KiwisIoT dashboard. Whenever the sensor detected an object, the dashboard displayed DETECTED. When no object was present, it displayed NOT DETECTED.

dashboard connection

Seeing the sensor status update live on the dashboard was really exciting!

Problems I Faced

During development, I faced two errors:

COM Port Access Denied: I solved this by closing the Serial Monitor and reconnecting the board.

Invalid Head of Packet (0x00): I corrected the board selection and changed to a proper USB data cable.

These issues helped me learn basic hardware troubleshooting.

Final Result

Finally, my project worked successfully! I could detect objects using the IR sensor and monitor their status remotely through the KiwisIoT dashboard.

output

Through this project, I learned about ESP8266 programming, sensor interfacing, Wi-Fi communication, and IoT dashboards.

What's Next?

I would like to improve this project by adding a buzzer alert, an object detection counter, and a graph to display detection history.

It was a small project, but a great learning experience. I'm looking forward to building more interesting IoT projects!

KiwisIoT Official github Project link:https://github.com/Kiwistron/KiwisIoT-Projects/tree/main/esp8266

Have you built any projects using ESP8266? Share your experience in the comments!

Top comments (0)