Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP8266-Based Obstacle Detection and Alert System with IR Sensor, Buzzer, and Relay-Controlled Motor

View and Edit Project In Cirkit DesignerImage of ESP8266-Based Obstacle Detection and Alert System with IR Sensor, Buzzer, and Relay-Controlled Motor

Circuit Documentation

Summary

This circuit is designed to detect obstacles using an IR sensor and respond by cutting off power to a motor, activating a buzzer, and lighting up an LED. The control logic is implemented using an ESP8266 NodeMCU microcontroller. The circuit also includes a 5V relay to control the motor and a 9V battery as the power source.

Component List

ESP8266 NodeMCU

IR Sensor

LED: Two Pin (red)

Buzzer

5V Relay

9V Battery

Motor and Wheels

Wire Connector

Wiring Details

ESP8266 NodeMCU

IR Sensor

LED: Two Pin (red)

Buzzer

5V Relay

9V Battery

Motor and Wheels

Wire Connector

Code Documentation

// Include necessary libraries

// Define pin numbers for components
#define IR_PIN D1        // IR sensor input pin
#define RELAY_PIN D7     // Relay control pin
#define BUZZER_PIN D3    // Buzzer output pin
#define LED_PIN D6       // LED output pin

void setup() {
  // Start serial communication for debugging
  Serial.begin(115200);    

  // Set pin modes for input and output
  pinMode(IR_PIN, INPUT);        // IR sensor pin as input
  pinMode(RELAY_PIN, OUTPUT);    // Relay control pin as output
  pinMode(BUZZER_PIN, OUTPUT);   // Buzzer pin as output
  pinMode(LED_PIN, OUTPUT);      // LED pin as output

  // Set initial states for the components
  digitalWrite(RELAY_PIN, HIGH);  // Initially, power is supplied to the motor (relay off)
  digitalWrite(BUZZER_PIN, LOW);  // Buzzer off
  digitalWrite(LED_PIN, LOW);     // LED off
}

void loop() {
  // Read the IR sensor value to detect obstacles
  int irValue = digitalRead(IR_PIN);  

  // If an obstacle is detected (IR sensor value LOW), cut off the power supply
  if (irValue == LOW) {   
    digitalWrite(RELAY_PIN, LOW);  // Relay cuts off power supply
    digitalWrite(BUZZER_PIN, HIGH); // Turn on buzzer to alert the user
    digitalWrite(LED_PIN, HIGH);    // Turn on LED to indicate braking mode
    Serial.println("Obstacle detected, power supply cut off...");

  } else {
    digitalWrite(RELAY_PIN, HIGH);   // Relay supplies power to the motor (no obstacle)
    digitalWrite(BUZZER_PIN, LOW);   // Turn off buzzer
    digitalWrite(LED_PIN, LOW);      // Turn off LED
    Serial.println("No obstacle detected, normal operation...");
  }

  delay(100); // Short delay for stable operation
}

This code initializes the pins for the IR sensor, relay, buzzer, and LED. It continuously reads the IR sensor value to detect obstacles. If an obstacle is detected, it cuts off the power supply to the motor, turns on the buzzer, and lights up the LED. If no obstacle is detected, it supplies power to the motor, turns off the buzzer, and turns off the LED.