Douglas Jude PatzJavair RatliffGeva Patz
Published

Trashmatic

An automated trash sorter which can also decide when it must be emptied.

542
Trashmatic

Things used in this project

Hardware components

SparkFun capacitive touch sensor
×1
Grove starter kit plus for Intel Edison
Seeed Studio Grove starter kit plus for Intel Edison
×1

Software apps and online services

AWS IoT
Amazon Web Services AWS IoT

Story

Read more

Code

trashmatic.py

Python
Script which handles trashmatic on Edison. Servo connects to D5. Capacitive touch connects to D7. RGB/Prox sensor connects to I2C slot. Run on Edison, and it handles the rest.
from upm import pyupm_servo as servo
import time
from upm import pyupm_grove as grove
from upm import pyupm_i2clcd as lcd
from HTU21D_Ed import HTU21D as RGB
from subprocess import call
from upm import pyupm_i2clcd as lcd

#myLcd = lcd.Jhd1313m1(0, 0x3E, 0x62)

recycle = 0
trash = 0
rgb = RGB(6)
touch = grove.GroveButton(7)
gServo = servo.ES08A(5)
opped = False

thingname = "edison-lightbulb"



def sendAWSData():
	payload = "\"{\\\"state\\\":{\\\"reported\\\":{\\\"recyclable\\\": " + str(recycle) + ", \\\"trash\\\": " + str(trash) + ", \\\"trashed\\\": " + str(trash + recycle) + "}}}\""
	
	shadow_command = "iot-data update-thing-shadow --thing-name " + thingname + " --payload " + payload + " output.txt"
	call("aws " + shadow_command, shell=True)

def recycleItem(recycle):
    recycle += 1
    gServo.setAngle(0)
#    myLcd.setColor(0,255,0)
    time.sleep(1)

def trashItem(trash):
    trash += 1
    gServo.setAngle(110)
#    myLcd.setColor(255,0,0)
    time.sleep(1)

rgb.initSensor()
gServo.setAngle(58)

while 1:
#        myLcd.setColor(0,0,255)
	if rgb.readUReg(0x9C) > 200:
		print("Something's in the bin!")
		time.sleep(2)
		if touch.value() == 1:
			print("Conductive material")
                        recycleItem(recycle)
                        opped = True
		a,r,g,b = rgb.color() # Checks data from sensor. a = ambient light
                if (a+r+g+b) > 2000:
                    print()
                    print("Paper!")
                    recycleItem(recycle)
                    opped = True

                if opped == False:
                    trashItem(trash)
		gServo.setAngle(58)

                opped = False

		sendAWSData()

Credits

Douglas Jude Patz

Douglas Jude Patz

1 project • 2 followers
I am a young aspiring hacker who is very into game development.
Javair Ratliff

Javair Ratliff

4 projects • 2 followers
Geva Patz

Geva Patz

1 project • 2 followers

Comments