Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
Noah W.
Published © CC0

AI-Powered Trash Can

This is a trash can that can sort between trash and recyclable items

IntermediateWork in progress4 hours680
AI-Powered Trash Can

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Trash Can
×1
Camera
×1

Software apps and online services

Arduino IDE
Arduino IDE
python
OpenCV
OpenCV

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Circuit

Structure

Attach the camera using a stick above the trash can. Make sure it can see the surface of the board, nothing but the board. Put the board and servo motors across the opening of the trash can. Attach the Arduino on the side. Plug everything into your computer, or an external battery source. If needed refer to the attached picture.

Code

Python Code

Python
Take a bunch of pictures of trash and recyclable items. Using Google's teachable machine or Cascade Trainer, sort these items into groups and export the file into your Python code.
import cv2

import cvzone

from cvzone.ClassificationModule import Classifier

import serial

import time

data = serial.Serial('com4', baudrate = 9600)



cap = cv2.VideoCapture(1)



classifier = Classifier('rec/keras_model.h5','rec/labels.txt')



while True:

  _, img = cap.read()

  pred, index = classifier.getPrediction(img)

  print(pred, index)



  cv2.imshow("img",img)

  cv2.waitKey(1)

  if (index == 0):

    recycle = 1

  if (index == 1):

    recycle = 1

  if (index == 2):

    recycle = 1

  if (index == 3):

    recycle = 1

  if (index == 4):

    recycle  = 1

  if (index == 5):

    recycle = 1

  if (index == 6):

    recycle = 1

  if (index == 7):

    recycle = 3

  if (index == 8):

    recycle = 3

  if (index == 9):

    recycle = 2

  def recy():

    data.write(b'1')

  def neu():

    data.write(b'2')

  def tra():

    data.write(b'3')

  t=0

  while(t<2000):

    if(t % 10 == 0):

      print(t)

    t+=1

  if(recycle == 1):

    recy()



  if(recycle == 2):

    neu()



  if(recycle == 3):

    tra()

Arduino Code

Arduino
#include <Servo.h>

Servo motor;

Servo motorb;



char serialData;



int n = 7;

int m = 7;

int p = 7;



void setup() {

Serial.begin(9600);

motor.attach(10);

motorb.attach(3);

}



void loop() {

if(Serial.available() > 0){

serialData = Serial.read();

Serial.print(serialData);

}

if(serialData == '1'){

n = n+1;

}

if(serialData == '2'){

p = p+1;

}

if(n == 8){

 motor.write(360);

  motorb.write(0);

  delay(300);

   motor.write(90);

   motorb.write(90);

      delay(1700);





 n=n-1;

}

if(serialData == '3'){

m = m+1;



}

if(m == 8){

 motor.write(0);

   motorb.write(360);

 delay(300);

   motor.write(90);

   motorb.write(90);

      delay(1700);



 m=m-1;

}

if(p == 8){

 motor.write(90);

   motorb.write(90);

 delay(300);

   motor.write(90);

   motorb.write(90);

   delay(1700);

 p=p-1;

}

}

Credits

Noah W.

Noah W.

2 projects • 0 followers
High School student making stuff

Comments