Suche

Recycling Smart

KI Illu Kapitel 3

Overview

Secondary School

Nature and Technology, Computer Science

Artificial Intelligence, Machine Learning, Coding, Robotics, Sustainability

English

Overview

Keywords: AI, machine learning, recycling, object recognition, sustainability
Subjects: Computer science, engineering
Other disciplines: Environmental sciences
Age group: 14–18
Required knowledge/skills: Basic coding skills (Python), basic robotics skills, AI literacy
Time frame: 4 x 2 hours
Cooperation partners: Software companies, waste management companies, schools

Required materials/hardware/software:

  • Physical hardware: Raspberry Pi, webcam, servo motors (4), jumpers, Coral USB Accelerator
  • Cardboard boxes (4)
  • Laptop
  • Raspberry Pi Operating System

Authors: Dr Selçuk Yusuf Arslan, Timur Gündoğan (Türkiye)
Co-authors: Abdüssamed Kuru, Cafer Berat Gülsoy, Melissa Asya Yıldırım (Türkiye)

  

Content

Introduction to the project
Instructions for teachers
Step-by-step instructions
Further ideas
Career orientation
Conclusion and outlook

A list of all links and materials mentioned below can be found in Material & References.

Summary

Recycling is of great importance in achieving a sustainable world. However, recycling rates vary considerably between countries. Türkiye, where this project was developed, lags behind many countries in recycling. While the recycling rate is 46 percent in Europe, it is only 13 percent in Türkiye[1].
The Recycling Smart project combines the capabilities of machine learning with object detection technology to facilitate and encourage recycling. When wastes such as glass, plastic, or organic are shown to a simple webcam, the object is recognised and the corresponding box in a set of recycling bins opens. In this way, recycling becomes easier and more fun[2]

ki_projekt_teaser-illustrationen_kapitel-3

Recycling is an important practice with environmental, economic, and social benefits and should be supported both on an individual and societal level. Encouraging and teaching recycling to students in schools not only creates environmental awareness, but also enables future generations to grow up as individuals who are more sensitive to their society, responsible and able to contribute to a sustainable future. In addition to raising recycling awareness in society, technology can also be utilised to make recycling easier and more fun. Acquiring knowledge in AI-related subjects can enhance the creativity of students and boost their capacity to devise innovative solutions for the challenges they will encounter in the future.

This teaching material focuses on facilitating recycling with artificial intelligence and machine learning based-object recognition. Designing a smart recycling system increases students’ awareness and develops their artificial intelligence and robotics skills. It is based on a project carried out to encourage students of a VET school to recycle. It was prepared within the scope of the elective course Artificial Intelligence and Machine Learning and won the first prize in its category in the competition organised at Atatürk Mesleki ve Teknik Anadolu Lisesi, Ankara, Türkiye, as well as the first prize in the STEM Alliance – Lenovo Competition 2023: Turning Waste into Educational Wonder.

Recycling is a practice that has many important benefits such as protecting natural resources, saving energy, reducing the amount of waste, protecting the environment, creating employment opportunities and supporting the principle of sustainability. Thanks to recycling, the consumption of natural resources is reduced and raw materials are reused, which allows us to use natural resources in a more sustainable way, making them transferable to future generations and maintaining the ecological balance. Reducing the amount of waste eliminates the need to expand landfills or open new areas. This reduces environmental pollution and waste management problems. Finally, the recycling sector also creates employment opportunities, thus contributing to economic growth.

Video by the UN Environment Programme: #ZeroWasteDay: An opportunity to address the global waste crisis

To protect your personal data, the connection to YouTube has been blocked.
By clicking on the button you can unblock the connection. YouTube/Google will receive personal data about your access to the website.

Play video

Instructions for teachers

Before the implementation, students are asked to research sample projects carried out with artificial intelligence and object recognition and present them in the classroom. In this way, it is ensured that students learn the basic concepts of AI.

To start off, the operating system must be installed on Raspberry Pi. After the operating system is installed, the necessary libraries should be shared so that students can set them up. The required libraries, sample source code and machine learning model file are given below and can be downloaded from this folder. Students are expected to write the code themselves; depending on the coding skills of the students, the teacher can decide which parts of the code will be shared with the students. To facilitate the implementation of this project, a fully trained object recognition model is supplied; however, creating a model with Google’s Teachable Machine by training it yourself can be integrated into the process as detailed below.

If your school does not use Raspberry Pi and students are not proficient in text-based coding, you can make a simpler version of this project using Arduino and block-based coding. Inspiration on how to proceed can be found online, for example in this instructable "AI Auto-Classify Trash Can". For primary school students, our teaching unit "EcoKids Teach AI" offers detailed ideas and instructions for working with coding robots and block-based coding in a recycling-themed learning environment.

Step A: Setting up libraries

The students type the necessary commands in the Raspberry terminal and install the appropriate libraries.

sudo apt-get update

sudo apt-get upgrade

pip install tensorflow

pip install opencv-python

pip install numpy

pip install keras

pip install pigpio

pip install time

sudo apt-get update && sudo apt-get install python3-rpi.gpio

sudo apt-get update && sudo apt-get install python3-pigpio

sudo pigpiod

https://forums.raspberrypi.com/viewtopic.php?t=340847

CORAL USB:

echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

sudo apt-get update

sudo apt-get install libedgetpu1-std

sudo apt-get install libedgetpu1-max

##sudo pigpiod this command must be run again every time the raspberry pi is rebooted to activate the engines 

Step B: Writing the code

The students are expected to write the code themselves. To help and guide them through the process, you can share the following coding examples and explanations.

import os  # import libraries
import cv2
from pycoral.utils.dataset import read_label_file
from pycoral.utils.edgetpu import make_interpreter
from pycoral.adapters import common
from pycoral.adapters import classify
import pigpio
import time
import RPi.GPIO as GPIO
import numpy as np

# Define the path to the TFLite model converted for use with Edge TPU
modelPath = '/home/admin/Desktop/TF/model_edgetpu.tflite'

# Define the path to the labels file that was downloaded with the model
labelPath = '/home/admin/Desktop/TF/labels.txt'

# Define GPIO pins for servos
servo1 = 23
servo2 = 24
servo3 = 25
servo4 = 21

# Initialize PWM (Pulse Width Modulation) for servo control using pigpio library
pwm = pigpio.pi()
pwm.set_mode(servo1, pigpio.OUTPUT)
pwm.set_mode(servo2, pigpio.OUTPUT)
pwm.set_mode(servo3, pigpio.OUTPUT)
pwm.set_mode(servo4, pigpio.OUTPUT)

# Set PWM frequency for servos
pwm.set_PWM_frequency(servo1, 50)
pwm.set_PWM_frequency(servo2, 50)
pwm.set_PWM_frequency(servo3, 50)
pwm.set_PWM_frequency(servo4, 50)

# Set initial servo positions
pwm.set_servo_pulsewidth(servo1, 500)
time.sleep(1)
pwm.set_servo_pulsewidth(servo2, 500)
time.sleep(1)
pwm.set_servo_pulsewidth(servo3, 500)
time.sleep(1)
pwm.set_servo_pulsewidth(servo4, 500)
time.sleep(1)

# Function to classify an image using the provided TFLite interpreter
def classifyImage(interpreter, image):
    size = common.input_size(interpreter)
    common.set_input(interpreter, cv2.resize(image, size, fx=0, fy=0, interpolation=cv2.INTER_CUBIC))
    interpreter.invoke()
    return classify.get_classes(interpreter)

def main():
    # Load the model onto the TF Lite Interpreter
    interpreter = make_interpreter(modelPath)
    interpreter.allocate_tensors()
    labels = read_label_file(labelPath)

    # Open the video capture device
    cap = cv2.VideoCapture(0)
    last_detection_cam = 0 #"cam" stands for "glass"
    last_detection_metal = 0
    last_detection_plastik = 0 #"plastik" stands for "plastics"
    last_detection_kompost = 0 #"kompost" stands for "organic waste"

    while cap.isOpened():
        # Read a frame from the video capture device
        ret, frame = cap.read()
        if not ret:
            break

        # Flip the image horizontally
        frame = cv2.flip(frame, 1)

        # Classify and display the image
        results = classifyImage(interpreter, frame)
        cv2.imshow('frame', frame)

        # Extract information about the detected object
        detected_label = labels[results[0].id]
        confidence_score = results[0].score
        print(f'Detected Label: {detected_label}, Score: {confidence_score}')

        # Control the servos based on the detected object and confidence score
        if detected_label == 'cam' and confidence_score > 0.9:
            pwm.set_servo_pulsewidth(servo1, 1700)
            last_detection_cam = time.time()
        elif detected_label == 'metal' and confidence_score > 0.9:
            pwm.set_servo_pulsewidth(servo2, 1700)
            last_detection_metal = time.time()
        elif detected_label == 'kompost' and confidence_score > 0.9:
            pwm.set_servo_pulsewidth(servo3, 1700)
            last_detection_kompost = time.time()
        elif detected_label == 'plastik' and confidence_score > 0.9:
            pwm.set_servo_pulsewidth(servo4, 1700)
            last_detection_plastik = time.time()

        # Reset servo positions after a certain duration if no detection
        if time.time() - last_detection_cam > 4:
            pwm.set_servo_pulsewidth(servo1, 500)
        if time.time() - last_detection_metal > 4:
            pwm.set_servo_pulsewidth(servo2, 500)
        if time.time() - last_detection_kompost > 4:
            pwm.set_servo_pulsewidth(servo3, 500)
        if time.time() - last_detection_plastik > 4:
            pwm.set_servo_pulsewidth(servo4, 500)

        # Check for the 'q' key press to exit the loop
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # Release the video capture device and close all OpenCV windows
    cap.release()
    cv2.destroyAllWindows()

if __name__ == '__main__':
    main()

Step C: Robotic design

Coral USB, which can accelerate machine learning, can be connected to any USB port on Raspberry Pi. Similarly, the webcam is connected to the USB port. The servo motors are connected to Raspberry Pi as follows: The black cables of the servo motors are connected to GND on the Raspberry Pi, the yellow cables are connected to the GPIO pins (23, 24, 25 and 21) specified on the servo motor, and the red cables are connected to 5V. 

Circuit Recycling Smart
© Selçuk Yusuf Arslan/Science on Stage
The circuit from Step C: Robotic design

Step D: Preparing the boxes

The students make cardboard boxes that are labeled and/or colour-coded to the type of recyclables they are intended for. In line with the theme of sustainability, it is recommended to make the boxes from recyclable materials. The servo motors are connected to the box lids so that the boxes can be opened and closed.

Reycyling Smart - Step D
© Selçuk Yusuf Arslan/Science on Stage
Preparing the boxes

Step E: Testing and development

Download the model file and extract the folder. After all the processes are completed, the project is finalised by checking whether the project works correctly and making the necessary improvements.

Note: With paper, plastic, metal and organic waste samples that the students have collected themselves, students can create their own models trained with about 500 photographs taken in studio light on the Teachable Machine website.

Further ideas

Once the students have finalised the system, they can place their smart recycling bins in a suitable area in the school so that the entire school community benefits from the project. You could get feedback from other students by adding a QR code for an online evaluation. Questions could include:

  • To what extent does this project facilitate recycling?
  • What did you like about this project?
  • What would you like to improve in this project?

This could be enhanced with a quiz consisting of multiple choice questions devised by the project group, such as:

  • In which colour bins are plastic and glass wastes placed, respectively?
  • Which of the following materials are generally recyclable?
  • Why is recycling important?

To develop the project further, teachers and students applying this teaching material can also add other waste bins. In addition, with a distance sensor added inside the box, a warning can be given with LEDs and the box can be prevented from opening once it is full. Moreover, when the box is full, the system can inform the waste collection centres by sending an e-mail.

The project can also be taken beyond the school. Students could present and/or implement their smart recycling system in local facilities such as retirement homes or kindergartens, helping the elderly or young kids with separating waste correctly.

Career orientation

Artificial intelligence stands out as a field that encourages new ideas and innovation. Students' learning about AI-related topics can contribute to developing their creativity and increasing their ability to find innovative solutions. As a result, AI for students should be an important focus not only for those interested in technology, but also for general career development. Further information and resources for career orientation in the context of AI, including the topic of AI and sustainability, can be found on our career orientation page.

Conclusion

The smart recycling system was tested in three schools in Türkiye. The schools were given five days to implement the project. The wastes shown to the webcam were recognised with approximately 95 percent accuracy. Teachers observed the students during this process and the opinions of the students using the system were also taken. Students described the project as easy, encouraging, fun and timesaving. Teachers emphasised its ease of use and easy adaptability. In addition, the project was improved according to the feedback received and invited to the final of Science on Stage’s Future League competition organised in 2023. The improved version includes glass, paper, plastic, organic waste, battery and metal bins.

Watch the Future League project video here:

 

To protect your personal data, the connection to YouTube has been blocked.
By clicking on the button you can unblock the connection. YouTube/Google will receive personal data about your access to the website.

Play video
Close search