Arduino-Controlled Street Sweeper with Ultrasonic Fullness Detection and Motor Driver
View and Edit Project In Cirkit Designer
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
- Description: A motor that converts DC electrical energy into mechanical energy.
- Purpose: Drives the street sweeper mechanism.
L298N DC Motor Driver
- Description: An integrated circuit that allows for controlling the direction and speed of a DC motor.
- Purpose: Interfaces between the Arduino and the DC motor to control the motor's operation.
HC-SR04 Ultrasonic Sensor
- Description: A sensor that uses ultrasonic waves to measure distance.
- Purpose: Detects the level of trash in the bin to signal when it is full.
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Purpose: Acts as the central controller for the street sweeper system, processing inputs and controlling outputs.
12V Battery (mini)
- Description: A power source providing 12 volts.
- Purpose: Supplies power to the motor driver and, indirectly, the DC motor.
Pushbutton STOP
- Description: A normally closed pushbutton switch.
- Purpose: Stops the motor when pressed.
Pushbutton START
- Description: A normally open pushbutton switch.
- Purpose: Starts the motor when pressed.
Pilot Lamp Red
- Description: An indicator light that illuminates when powered.
- Purpose: Indicates when the trash bin is full.
Resistor (200 Ohms)
- Description: A passive two-terminal electrical component that implements electrical resistance.
- Purpose: Used for current limiting or voltage dropping as needed in the circuit.
Resistor (220 Ohms)
- Description: Similar to the 200 Ohms resistor, with slightly higher resistance.
- Purpose: Used for current limiting or voltage dropping as needed in the circuit.
Wiring Details
DC Motor
- OUT1 from L298N to pin 1
- OUT2 from L298N to pin 2
L298N DC Motor Driver
- 12V to "+" of 12V Battery
- GND to "-" of 12V Battery and GND of Arduino UNO
- 5V to 5V of Arduino UNO
- ENA to D5 of Arduino UNO
- IN1 to D2 of Arduino UNO
- IN2 to D3 of Arduino UNO
HC-SR04 Ultrasonic Sensor
- VCC to 5V of Arduino UNO
- GND to GND of Arduino UNO
- TRIG to D9 of Arduino UNO
- ECHO to D10 of Arduino UNO
Arduino UNO
- GND to NC of Pushbutton STOP and NO of Pushbutton START
- D8 to X1 of Pilot Lamp Red
- D7 to NC of Pushbutton STOP
- D6 to NO of Pushbutton START
Pushbutton STOP
- NC to GND of Arduino UNO
- NC to D7 of Arduino UNO
Pushbutton START
- NO to GND of Arduino UNO
- NO to D6 of Arduino UNO
Pilot Lamp Red
- X1 to D8 of Arduino UNO
- X2 to pin1 of 220 Ohms Resistor
Resistor (220 Ohms)
- pin1 to X2 of Pilot Lamp Red
- pin2 to GND of Arduino UNO
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.