Automatic Lid

by thalesalmagro in Circuits > Arduino

176 Views, 0 Favorites, 0 Comments

Automatic Lid

thumbnail_image0.jpg

This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)

Material

thumbnail_image0-1.jpg

Creating this project, it was required a servo, a proximity sensor, an Arduino board, and some wires for the connections. To create the model, I used Solidworks but the design does not need to remain the same.

The servo model used is the SG90 and the proximity sensor is the HC-SRO4. The Arduino board used is the Arduino Uno.

Model

thumbnail_image0-2.jpg

Prepare your model. For my model I used the software solidworks and 3D printed it.

Wiring the Circuit

Screen Shot 2022-05-02 at 20.07.04.png

Wire the proximity sensor to the Arduino and keep in mind the ports that you are using. Same for the Servo.

Note that the sensor has a echo and a trig pin, if you follow the script in the next step, wire the echo to pin 10 of the Arduino board and the trig pin to pin 11 in the Arduino board. The Vcc needs to be wired to 5 Vdc and the ground to ground, also in the Arduino board.

The servo's red wire needs to be connected to 5 Vdc, the brown to ground and the yellow to the Arduino board, I used pin 8 in the Arduino board.

Prepare the Code

Screen Shot 2022-05-02 at 20.07.16.png

the code I used is the following:

#include
#define echoPin 10 //assign the arduino pins to the sensor #define triggerPin 11 //assign the arduino pins to the sensor #define servopin 8 //assign the arduino pins to the servo Servo myservo; // call the servo

void setup() { Serial.begin(9600); //start the arduino board pinMode(echoPin, INPUT); // assign the sensor ports pinMode(triggerPin, OUTPUT); // assign the sensor ports myservo.attach(servopin); // assign the servo port

}

void loop() { Serial.print("The distance is: "); digitalWrite(triggerPin, HIGH); delayMicroseconds(10); digitalWrite(triggerPin, LOW); //this lines were used to see what would be a good distance to trigger the sensor

int distance = pulseIn(echoPin, HIGH); //assign the distance a variable

int actual_distance = distance/58; // translate the variable to cm

Serial.print(actual_distance); Serial.println(" cm"); //read the variable delay(500); if (actual_distance>0 && actual_distance<7){ //When the distance to the sensor is smaller than 7 cm myservo.write(0); // openning the lid with the servo to the angle 0 delay(5000); // after 5 seconds myservo.write(90); // close the lid } }

Use Your Automatic Lid!

Deliverable 7 Automatic Lid

More information can be seen in the video posted.