ESP32-Powered Waterway Trash Collector with Ultrasonic Monitoring and DC Motors
View and Edit Project In Cirkit Designer
Waterway Trash Collector with Monitoring
Summary
This project involves a waterway trash collector system that uses an ESP32 microcontroller to control three DC motors for movement and one DC motor for a conveyor. An ultrasonic sensor is used to detect the trash level. The system is powered by two 18650 Li-ion batteries. The ESP32 microcontroller interfaces with two L298N DC motor drivers to control the motors, and an HC-SR04 ultrasonic sensor to monitor the trash level.
Component List
ESP32 - 38 pins
- Description: A powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities.
- Pins: 3V3, EN, SP, SN, G34, G35, G32, G33, G25, G26, G27, G14, G12, GND, G13, SD2, SD3, CMD, 5V, G23, G22, TXD, RXD, G21, G19, G18, G5, G17, G16, G4, G0, G2, G15, SD1, SD0, CLK
L298N DC Motor Driver (2 units)
- Description: A dual H-bridge motor driver that allows control of the speed and direction of two DC motors.
- Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
DC Motor (4 units)
- Description: Standard DC motors used for movement and conveyor operations.
- Pins: pin 1, pin 2
18650 Li-ion Battery x 2
- Description: Rechargeable lithium-ion batteries used to power the system.
- Pins: +, -
HC-SR04 Ultrasonic Sensor
- Description: An ultrasonic sensor used to measure distance to detect the trash level.
- Pins: VCC, TRIG, ECHO, GND
AMB82-Mini IoT AI Camera
- Description: An AI camera module for potential future enhancements.
- Pins: PF6, PF7, PF8, PF11, PF12, PF13, AOUT, GND, CHIP_EN, V_USB, VDD33, PF15, PF14, PF5, PA3, PA2, PD14, PF2, PF1, PF0, PE4, PE3, PE2, PE1, PD18, PD17, PD16, PD15
Wiring Details
ESP32 - 38 pins
- G34 connected to ENB of L298N DC motor driver
- G35 connected to IN4 of L298N DC motor driver
- G32 connected to IN3 of L298N DC motor driver
- G33 connected to IN2 of L298N DC motor driver
- G25 connected to IN1 of L298N DC motor driver
- G26 connected to ENA of L298N DC motor driver
- GND connected to GND of HC-SR04 Ultrasonic Sensor, GND of L298N DC motor driver, and - of 18650 Li-ion Battery
- 5V connected to VCC of HC-SR04 Ultrasonic Sensor and 5V of L298N DC motor driver
- G23 connected to ENA of L298N DC motor driver
- G22 connected to IN1 of L298N DC motor driver
- G21 connected to IN2 of L298N DC motor driver
- G19 connected to IN3 of L298N DC motor driver
- G18 connected to IN4 of L298N DC motor driver
- G5 connected to ENB of L298N DC motor driver
- G17 connected to TRIG of HC-SR04 Ultrasonic Sensor
- G16 connected to ECHO of HC-SR04 Ultrasonic Sensor
L298N DC Motor Driver (1st unit)
- ENB connected to G34 of ESP32
- IN4 connected to G35 of ESP32
- IN3 connected to G32 of ESP32
- IN2 connected to G33 of ESP32
- IN1 connected to G25 of ESP32
- ENA connected to G26 of ESP32
- GND connected to GND of HC-SR04 Ultrasonic Sensor, GND of ESP32, and - of 18650 Li-ion Battery
- 5V connected to VCC of HC-SR04 Ultrasonic Sensor and 5V of ESP32
- OUT1 connected to pin 2 of DC Motor
- OUT2 connected to pin 1 of DC Motor
- 12V connected to + of 18650 Li-ion Battery
L298N DC Motor Driver (2nd unit)
- ENA connected to G23 of ESP32
- IN1 connected to G22 of ESP32
- IN2 connected to G21 of ESP32
- IN3 connected to G19 of ESP32
- IN4 connected to G18 of ESP32
- ENB connected to G5 of ESP32
- GND connected to GND of HC-SR04 Ultrasonic Sensor, GND of ESP32, and - of 18650 Li-ion Battery
- OUT1 connected to pin 2 of DC Motor
- OUT2 connected to pin 1 of DC Motor
- OUT3 connected to pin 2 of DC Motor
- OUT4 connected to pin 1 of DC Motor
- 12V connected to + of 18650 Li-ion Battery
DC Motor (1st unit)
- pin 2 connected to OUT1 of L298N DC motor driver
- pin 1 connected to OUT2 of L298N DC motor driver
DC Motor (2nd unit)
- pin 2 connected to OUT3 of L298N DC motor driver
- pin 1 connected to OUT4 of L298N DC motor driver
DC Motor (3rd unit)
- pin 2 connected to OUT1 of L298N DC motor driver
- pin 1 connected to OUT2 of L298N DC motor driver
DC Motor (4th unit)
- pin 2 connected to OUT3 of L298N DC motor driver
- pin 1 connected to OUT4 of L298N DC motor driver
18650 Li-ion Battery x 2
- + connected to 12V of L298N DC motor driver
- - connected to GND of L298N DC motor driver, GND of ESP32, and GND of HC-SR04 Ultrasonic Sensor
HC-SR04 Ultrasonic Sensor
- VCC connected to 5V of L298N DC motor driver and 5V of ESP32
- TRIG connected to G17 of ESP32
- ECHO connected to G16 of ESP32
- GND connected to GND of L298N DC motor driver, GND of ESP32, and - of 18650 Li-ion Battery
Code Documentation
/*
* Waterway Trash Collector with Monitoring
* This code controls three DC motors for movement and one DC motor for a conveyor
* using an ESP32 microcontroller. An ultrasonic sensor is used to detect the trash
* level.
*/
// Motor driver pins
const int motor1_ENA = 26;
const int motor1_IN1 = 25;
const int motor1_IN2 = 33;
const int motor2_ENB = 34;
const int motor2_IN3 = 32;
const int motor2_IN4 = 35;
const int motor3_ENA = 23;
const int motor3_IN1 = 22;
const int motor3_IN2 = 21;
const int motor3_IN3 = 19;
const int motor3_IN4 = 18;
const int motor4_ENB = 5;
// Ultrasonic sensor pins
const int trigPin = 17;
const int echoPin = 16;
void setup() {
Serial.begin(115200);
// Motor pins setup
pinMode(motor1_ENA, OUTPUT);
pinMode(motor1_IN1, OUTPUT);
pinMode(motor1_IN2, OUTPUT);
pinMode(motor2_ENB, OUTPUT);
pinMode(motor2_IN3