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

Arduino UNO Controlled Flame-Sensing Robot with L298N Motor Driver and Servo Actuation

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Flame-Sensing Robot with L298N Motor Driver and Servo Actuation

Circuit Documentation

Summary

The circuit in question appears to be designed for a robotic application that involves motor control, air pumping, flame sensing, and audible signaling. An Arduino UNO microcontroller serves as the central processing unit, interfacing with various sensors, actuators, and a motor driver. The circuit includes flame sensors for detecting fire, a DC motor driver for controlling motors, a servo motor for precise angular movement, a mini air pump, a buzzer for audio feedback, and a power supply provided by a 9V battery. The circuit is designed to react to flame detection with specific movements and actions, including motor speed adjustments and air pump activation.

Component List

Wiring Details

Motor Amarillo Motorreductor Hobby

L298N DC Motor Driver

Mini Air Pump

Sensor SHT113 Flame

Arduino UNO

9V Battery

Ceramic Capacitor

Rocker Switch

Resistor

Servomotor MG90S

LED (Red)

Buzzer

Documented Code

#define enA 10    // Enable1 L298 Pin enA (Motor1 Speed Control)
#define in1 9     // Motor1 L298 Pin in1 (Motor1 Forward)
#define in2 8     // Motor1 L298 Pin in2 (Motor1 Backward)
#define in3 7     // Motor2 L298 Pin in3 (Motor2 Forward)
#define in4 6     // Motor2 L298 Pin in4 (Motor2 Backward)
#define enB 5     // Enable2 L298 Pin enB (Motor2 Speed Control)
#define ir_R A0   // Right Infrared sensor
#define ir_F A1   // Front Infrared sensor
#define ir_L A2   // Left Infrared sensor
#define servo A4  // Servo Motor pin
#define pump A5   // Pump control pin

int Speed = 160;  // Duty Cycle (0 to 255) for motor speed control
int s1, s2, s3;   // Variables to store sensor readings

void setup() {
  Serial.begin(9600);            // Start serial communication at 9600 bps
  pinMode(ir_R, INPUT);          // Set right sensor as input
  pinMode(ir_F, INPUT);          // Set front sensor as input
  pinMode(ir_L, INPUT);          // Set left sensor as input
  pinMode(enA, OUTPUT);          // Motor1 speed control
  pinMode(in1, OUTPUT);          // Motor1 forward
  pinMode(in2, OUTPUT);          // Motor1 backward
  pinMode(in3, OUTPUT);          // Motor2 forward
  pinMode(in4, OUTPUT);          // Motor2 backward
  pinMode(enB, OUTPUT);          // Motor2 speed control
  pinMode(servo, OUTPUT);        // Servo motor control
  pinMode(pump, OUTPUT);         // Pump control

  // Initial servo movements
  for (int angle = 90; angle <= 140; angle += 5) {
    servoPulse(servo, angle); 
  }
  for (int angle = 140; angle >= 40; angle -= 5) {
    servoPulse(servo, angle); 
  }
  for (int angle = 40; angle <= 95; angle += 5) {
    servoPulse(servo, angle); 
  }
  
  // Set initial motor speeds
  analogWrite(enA, Speed);  // Set Motor1 speed
  analogWrite(enB, Speed);  // Set Motor2 speed
  delay(500);
}

void loop() {
  s1 = analogRead(ir_R);  // Read right sensor
  s2 = analogRead(ir_F);  // Read front sensor
  s3 = analogRead(ir_L);  // Read left sensor

  // Display sensor readings on the serial monitor
  Serial.print(s1); Serial.print("\t");
  Serial.print(s2); Serial.print("\t");
  Serial.println(s3);
  delay(50);

  // Automated control based on sensor input
  if (s1 < 250) {
    Stop();
    digitalWrite(pump, 1);
    for (int angle = 90; angle >= 40; angle -= 3) {
      servoPulse(servo, angle);
    }
    for (int angle = 40; angle <= 90; angle += 3) {
      servoPulse(servo, angle);
    }
  }
  else if (s2 < 350) {
    Stop();
    digitalWrite(pump, 1);
    for (int angle = 90; angle <= 140; angle += 3) {
      servoPulse(servo, angle);
    }
    for (int angle = 140; angle >= 40; angle -= 3) {
      servoPulse(servo, angle);
    }
    for (int angle = 40; angle <= 90; angle += 3) {
      servoPulse(servo, angle);
    }
  }
  else if (s3 < 250) {
    Stop();
    digitalWrite(pump, 1);
    for (int angle = 90; angle <= 140; angle += 3) {
      servoPulse(servo, angle);
    }
    for (int angle = 140; angle >= 90; angle -= 3) {
      servoPulse(servo, angle);
    }
  }
  else if (s1 >= 251 && s1 <= 700) {
    digitalWrite(pump, 0);
    backword();
    delay(100);
    turnRight();
    delay(200);
  }
  else if (s2 >= 251 && s2 <= 800) {