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

Arduino-Controlled Street Sweeper with Ultrasonic Fullness Detection and Motor Driver

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Street Sweeper with Ultrasonic Fullness Detection and Motor Driver

Street Sweeper System Circuit Documentation

Summary

The circuit is designed to control a DC motor for a street sweeper system using an L298N motor driver. It features an HC-SR04 ultrasonic sensor to detect if the trash bin is full and a red pilot lamp to indicate the full status. The system is controlled by an Arduino UNO, which manages the motor operation through pushbuttons for start and stop functions. A 12V battery powers the motor driver, while the Arduino and sensor are powered by the Arduino's onboard voltage regulator.

Component List

DC Motor

L298N DC Motor Driver

HC-SR04 Ultrasonic Sensor

Arduino UNO

12V Battery (mini)

Pushbutton STOP

Pushbutton START

Pilot Lamp Red

Resistor (200 Ohms)

Resistor (220 Ohms)

Wiring Details

DC Motor

L298N DC Motor Driver

HC-SR04 Ultrasonic Sensor

Arduino UNO

Pushbutton STOP

Pushbutton START

Pilot Lamp Red

Resistor (220 Ohms)

Documented Code

/*
 * Arduino Sketch for Street Sweeper System
 * This code controls a DC motor for a street sweeper using an L298N driver.
 * An ultrasonic sensor (HC-SR04) detects if the trash bin is full.
 * A red pilot lamp indicates when the trash bin is full.
 * Pushbuttons are used to start and stop the motor.
 */

// Pin definitions
const int motorIn1 = 2;
const int motorIn2 = 3;
const int motorEnA = 5;
const int trigPin = 9;
const int echoPin = 10;
const int startButton = 6;
const int stopButton = 7;
const int lampPin = 8;

// Variables
long duration;
int distance;

void setup() {
  // Initialize motor control pins
  pinMode(motorIn1, OUTPUT);
  pinMode(motorIn2, OUTPUT);
  pinMode(motorEnA, OUTPUT);
  // Initialize ultrasonic sensor pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  // Initialize pushbutton pins
  pinMode(startButton, INPUT_PULLUP);
  pinMode(stopButton, INPUT_PULLUP);
  // Initialize lamp pin
  pinMode(lampPin, OUTPUT);
  // Start serial communication
  Serial.begin(9600);
}

void loop() {
  // Check if start button is pressed
  if (digitalRead(startButton) == LOW) {
    startMotor();
  }
  // Check if stop button is pressed
  if (digitalRead(stopButton) == LOW) {
    stopMotor();
  }
  // Measure distance using ultrasonic sensor
  distance = measureDistance();
  // Check if trash bin is full
  if (distance < 10) { // Adjust threshold as needed
    digitalWrite(lampPin, HIGH); // Turn on lamp
  } else {
    digitalWrite(lampPin, LOW); // Turn off lamp
  }
  delay(100);
}

void startMotor() {
  digitalWrite(motorIn1, HIGH);
  digitalWrite(motorIn2, LOW);
  analogWrite(motorEnA, 255); // Full speed
}

void stopMotor() {
  digitalWrite(motorIn1, LOW);
  digitalWrite(motorIn2, LOW);
  analogWrite(motorEnA, 0); // Stop motor
}

int measureDistance() {
  // Clear the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Set the trigPin on HIGH state for 10 microseconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Read the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculate the distance
  distance = duration * 0.034 / 2; // Speed of sound wave divided by 2
  return distance;
}

This code is responsible for controlling the street sweeper system. It initializes the necessary pins, reads the state of the pushbuttons, controls the motor, and reads the ultrasonic sensor to determine the fullness of the trash bin. The red pilot lamp is controlled based on the distance measured by the sensor.