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

ESP32-Controlled Robot with L298N Motor Drivers and Flame Detection

View and Edit Project In Cirkit DesignerImage of ESP32-Controlled Robot with L298N Motor Drivers and Flame Detection

Circuit Documentation

Summary

This circuit is designed to control a set of DC motors using an L298N DC motor driver, interfaced with an ESP32 microcontroller. The circuit includes servomotors for precise movement control, heat flame sensors for detecting fire or high temperatures, and a Lipo battery for power supply. A rocker switch is used to control the power flow to the circuit. The ESP32 microcontroller is programmed to read inputs from the heat flame sensors and control the motors and servomotor accordingly.

Component List

Lipo Battery

Rocker Switch

L298N DC Motor Driver

Servomotor SG90

DC Motor

Heat Flame Sensor

ESP32 38 PINS

Wiring Details

Lipo Battery

Rocker Switch

L298N DC Motor Driver (First Instance)

L298N DC Motor Driver (Second Instance)

Servomotor SG90

DC Motor

Heat Flame Sensor

ESP32 38 PINS

Documented Code

// ESP32 Microcontroller Code
bool forward = 0, backward = 0, right = 0, left = 0;
#include <Servo_ESP32.h>

Servo_ESP32 myservo;
int temp1 = 32;
int temp2 = 33;
int temp3 = 26;
int temp4 = 25;
int a = temp1;
int b = temp2;
int c = temp3;
int d = temp4;
int pos = 0;

void setup()
{
  // directions
  pinMode(7, INPUT);
  pinMode(8, INPUT);
  pinMode(12, INPUT);
  pinMode(11, INPUT);
  // flame sensor pins 
  pinMode(a, INPUT);
  pinMode(b, INPUT);
  pinMode(c, INPUT);
  pinMode(d, INPUT);
  myservo.attach(27);
  // Outputs
  pinMode(3, OUTPUT); 
  pinMode(5, OUTPUT); 
  pinMode(6, OUTPUT);  
  pinMode(9, OUTPUT);
  digitalWrite(3, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(9, LOW);
}

void loop()
{
  forward = digitalRead(12);
  right = digitalRead(7);
  left = digitalRead(11);
  backward = digitalRead(8);
  
  digitalWrite(3, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(9, LOW);

  if (right == 0)
  {
    digitalWrite(3, HIGH);
  }
  if (forward == 0)
  {
    digitalWrite(3, HIGH);
    digitalWrite(5, HIGH);
  }
  if (left == 0)
  {
    digitalWrite(5, HIGH);
  }
  if (backward == 0)
  {
    digitalWrite(6, HIGH);
    digitalWrite(9, HIGH);
  }

  // Read sensor values
  int a = analogRead(temp1);
  int b = analogRead(temp2);
  int c = analogRead(temp3);
  int d = analogRead(temp4);

  // Determine servo position based on sensor values
  if (a >= b && a >= c && a >= d) {
    pos = 0;
  }
  else if (b >= a && b >= c && b >= d) {
    pos = 90;
  }
  else if (c >= a && c >= b && c >= d) {
    pos = 180;
  }
  else if (d >= a && d >= b && d >= c) {
    pos = 260;
  }
  else {
    pos = 0;
  }
  myservo.write(pos);
}

This code is responsible for reading the inputs from the direction pins and flame sensor pins, controlling the DC motors through the L298N motor drivers, and adjusting the position of the servomotor based on the readings from the flame sensors. The code uses the Servo_ESP32 library to control the servomotor.