Project 3 Result!
Video:
Project Statement:
For this project, I was inspired by the inflatable tube guys, often seen in car lots. Since this was a project where we wanted to display an emotion when triggered by a sensor, I thought a good way to do this would be to have a stationary being that would show happiness when someone gets close. One way to do this would be to have a fan turn on, causing the inflatable tube to start billowing, but I did not want to introduce a fan or a sewing project into such a short project, so I thought servos could be used to emulate the motion by raising and waving the being's arms near its head when triggered by the proximity sensor. I had also planned to have a changing face, but based on the way I had already built the arms made me rethink its design from two faces that switch places to a happy mouth moving to cover a sad mouth when someone gets close. During the critique session, I was given the idea to have had the face rotate upright to switch the faces rather than on two ends of a longer stick switching places, which I had not thought of but think it is a great idea for a potential second iteration. The coding and construction itself was not too complicated, and I am very glad it went much better than past projects had. I like the simple, minimalistic style of my current iteration, but with more time I probably would have made a more attractive or neater robot, and covered up more of the mechanical components. Overall, I am happy with how my project turned out!
Code:
from machine import Pin
from servo import Servo
import utime
import time
trigger = Pin(27, Pin.OUT)
echo = Pin(28, Pin.IN)
servo1 = Servo(pin=26)
servo2 = Servo(pin=22)
servo3 = Servo(pin=21)
def ultra():
trigger.low()
utime.sleep_us(2)
trigger.high()
utime.sleep_us(5)
trigger.low()
while echo.value() == 0:
signaloff = utime.ticks_us()
while echo.value() == 1:
signalon = utime.ticks_us()
timepassed = signalon - signaloff
distance = (timepassed * 0.0343) / 2
print("The distance from object is ",distance,"cm")
return distance
while True:
#ultra()
servo1.move(135)
servo2.move(45)
servo3.move(45)
utime.sleep(1)
while ultra() <= 10:
servo3.move(12)
servo1.move(90) # turns the servo to 0°.
servo2.move(90)
time.sleep(.5)
servo1.move(0) # turns the servo to 90°.
servo2.move(180)
time.sleep(.5)
utime.sleep(1)
Comments
Post a Comment