Software
Programming of GARB
Sensing
We opted to use an Ultrasonic sensor to determine when GARB was full. The detection was done by finding the average fullness across one second (20 samples) and comparing it to the threshold that we set. Alternatively, it would also exit the loop if the lid button is pressed.
Code
# Trash can Dimensions
bin_height = 76 # Height from Lid to Bottom of Trash (cm)
trigger_height = 61 # Height from Bottom of Trash to Trigger Point (cm)
# Ultrasonic Sensor Settings
close_enuf = bin_height - trigger_height # Calibrate
avg_distance = 76
# Fullness Detection Loop
print("Detecting Height and Button Press")
while avg_distance >= close_enuf:
distances = []
d_sum = 0
for k in range(20):
# open_close = lid_button.value()
open_close = 1
time.sleep(0.05)
if open_close == 1:
distance = sensor.distance_cm()
else:
distance = bin_height
if distance > bin_height:
distance = bin_height
distances.append(distance)
d_sum += distances[k]
avg_distance = round(d_sum/20, 1)
print(avg_distance)
status = user_button.value()
if status == 1:
avg_distance = close_enuf - 1Actuation and Communication
Once the sensors determined that GARB was full, we would move on to the sealing procedure.
Actuation
GARB has two main actuation operations: Tightening and Releasing. Both of these involve the use of the servo.
Communication
Upon the tightening finishing up on GARB, it sends a text to the owner via MQTT. Although MQTT is slow and not as secure as other communication methods, it is more than enough for a product like GARB. Other communication methods like Bluetooth also require the owner to be nearby.
Code
# Servo Tightening Procedure
print("Begin Twisting Procedure")
S.duty(counter_clockwise)
# Can ramp the duty between the time frames to get a more smooth rotation
time.sleep(5) # Let the Servo Fully Twist
S.duty(rest) # Stop Servo
# Completion
# mqtt.publish(feedName_done, sendDone)
print("Waiting for Button Press")
status = user_button.value()
while status == 0:
status = user_button.value()
print("Button has Been Pressed")
# Reverse Servo
S.duty(clockwise)
time.sleep(5) # Need to calibrate
S.duty(rest)
status = 0
avg_distance = 76Full Code
Last updated