Picture Source: cuidevices
The aim of this project is to develop a prototype that opens the trash can lid contactlessly using various tools. Detailed explanations are explained in order. The program was simulated through the Tinkercad program and then applied in practice.
- 1 Arduino UNO
- 1 USB 2.0 to USB B Cable
- 4 Male to Female Jumper Cable
- 4 Female to Female Jumper Cable (Optional, depends on distance between Arduino to bin!)
- 1 Servomotor
- 1 HC-SR06 Distance Sensor
- 1 Bin
- 1 Stick or piece of wood (for Servomotor)
The following simulation was created via Tinkercad.
After the model is created, there is the coding part next.
Pin numbers and libraries are specified:
#include <Servo.h>
Servo motor;
#define echo 5
#define trig 6
void setup() {
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
motor.attach(8);
Serial.begin(9600);
}
Within a quarter of a second, the ultrasonic sensor scanned whether there was any object close to the sensor. This sensor reads from 2cm to 400cm (0.8inch to 157inch) with an accuracy of 0.3cm (0.1inches), which is good for most hobbyist projects. The distance (in cm) was calculated according to the sound velocity and the distance was calculated over the time variable.
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(2);
digitalWrite(trig, LOW);
float time = pulseIn(echo, HIGH);
float cm = time/58.2;
delay(250);
<p>If the object brought closer to the ultrasonic sensor is closer than <i>10 centimeters</i>, the motor will move at an angle of <i>90 degrees</i>. Then it will wait for <i>5</i> seconds and the servo motor will return to its original state.</p>
if (cm < 10){
motor.write(90);
delay(5000);
motor.write(0);
}
If you have something to say to me please contact me:
- Twitter: Doguilmak
- Mail address: doguilmak@gmail.com