Smart-Dustbin
using Arduino
Circuit Board
Connect signals to
sensors / digital pins
Digital Input / Output
Read analog
sensor
Wire Connection
Ultra-sonic Sensor:
VCC to 5V
GND to GND
Trig to Pin 5
Echo to Pin 6
Servo Motor:
VCC to 5V
GND to GND
Signal to Pin 7
Code Explaination
Introduction
Object-Oriented Programming language
contains library, and
predefined functions
function starts and end with ‘ {} ‘ each line ends with ‘ ; ’
Introduction
Data type (int, str, dbl, bool)
variable = space to stores one data
Introduction
Function = a set of instructions to execute a specific task
Let’s Start
Variable Declaration
servo: Declares a Servo object.
trigPin and echoPin: Pins used for ultrasonic sensor connections.
servoPin: Pin connected to the servo motor.
minDistance: Minimum distance at which the lid should open (adjustable).
Setup Function
[Link](9600): Initializes serial communication at a baud rate of 9600.
[Link](servoPin): Attaches the servo to the designated pin.
Configures trigPin as an output and echoPin as an input.
Sets the servo to a closed position and then detaches it.
Measure Distance Function
This function calculates the distance measured by
the ultrasonic sensor.
It sends a short pulse to the sensor, measures the
duration of the echo, and calculates the distance
based on the speed of sound.
Open Cap Function
This function opens the dustbin's cap by rotating the servo motor.
It attaches the servo, sets the angle to open the cap, waits for a
moment, then closes the cap slightly.
Loop Function
This function continuously
loops.
It takes multiple distance
readings, averages them, and
checks if the average distance
is less than the minimum
distance.
If the condition is met, it opens
the cap.
It also prints the average
distance to the serial monitor
for debugging purposes.
Happy Coding!