Task: In my Introduction to Engineering Principles and Practices class, I was tasked with designing a system that would theoretically open and close a door at a grocery store. The goal is to program an ultrasonic sensor to detect a person at a certain distance, activate a servo motor to rotate from 0 degrees to 180 degrees, delay 2 seconds, and then allow the servo to return back to 0 degrees if it no longer detects a person. 

Ultrasonic Sensor and Servomotor Description: An ultrasonic sensor sends out a sound wave that will bounce off an object within the range of the sensor. After the pulse bounces off the object, the echo will bounce back and be received by the sensor. A servomotor (simply called a servo) uses feedback to rotate a certain number of degrees. The servo used in this project can rotate 180 degrees in both directions. A photo of each device can be seen below:

Setting up the System: To create a system that would allow the ultrasonic sensor and the servo motor to interact, I used my Arduino and my breadboard to connect both devices together with the same power source and ground. I have included a photo below:

Programming the System: By taking two separate codes that work to communicate between the Arduino and the servo/ultrasonic sensor, I combined the codes to ensure that both the servo and the ultrasonic sensor would be defined. To complete the task, I used an if else statement. The condition stated that if the ultrasonic sensor detects an object in range of the sensor (in this case I used 6 inches), the servo would rotate 180 degrees for 2000 milliseconds. Otherwise (else), the servo would stay at 0 degrees. If the sensor continues to detect an object, it will remain at 180 degrees for longer than 2 seconds.

Final Result: The Youtube video below demonstrates how the system I created functions:

https://youtu.be/MZ2NvjDxLlM?feature=shared