Teach Your Machine to Think: Build a Smart Sorter

In this lesson, students step into the role of computer engineers as they explore the intersection of artificial intelligence, machine learning, and embedded systems. Using Google’s Teachable Machine, they train models to recognize objects, spoken phrases, and human motions, then apply those models to solve a real‑world motion‑classification problem. After training their models, teams integrate them with an Arduino, transforming a laptop into an intelligent sorting system. They test, refine, and retrain their classifiers to improve accuracy, experiencing the full mini‑cycle of machine‑learning development: data collection, training, hardware integration, testing, and iterative improvement.

Students will:

  • Develop and train a functional classification model using Teachable Machine, analyzing examples to understand how AI detects patterns.
  • Integrate their design with an Arduino to create an intelligent, automated sorting system that responds to real‑world inputs.
  • Evaluate and improve system performance using accuracy measures, observed misclassifications, and iterative engineering‑design refinements.
  • Materials & Preparation

    • Computer (shared by two students) – Download Arduino Software
    • Arduino Leonardo (Microcontroller)
    • Micro-USB Cable (Note: If your computer has a USB-C port, you’ll need an adapter.) 
    • Micro Servo (SG90)
    • Five jumper wires (Male to Male)
    • Two paper cups
    • Two different types of dry cereal
    • Cardboard or Card Stock
    • Tape
    • Scissors
    • Ruler
    • Optional: Other fun items to decorate sorting device like pipecleaners, markers, feathers, colored construction paper, etc.)

    **Note: Teacher Preparation for lesson: 

  • Your engineering team has been hired by a breakfast‑foods startup that wants to automate part of its packaging line. Your mission is to design a machine‑learning‑powered sorting system that can tell two types of dry cereal apart and automatically drop each one into the correct container using a simple Arduino‑controlled mechanism.

    Criteria:

    • The computer must be well-trained, or it will make errors
    • Cereal must be sorted correctly every time
    • Students can alter the design or the code if they have ideas for improvement

    Constraints:

    • Complete in the allotted time
    • Only use the materials provided
  • Teach Your Machine to Think: Build a Smart Sorter
    Step 1

    Step 1: Hook with AI Ebook

    Students, in teams of two, explore the AI Adventures: Exploring the World of Artificial Intelligence eBook. Have them read through the following sections: 

    Step 2

    Step 2: Hook with AI EbookPages 3-4

    Student do the reflection activity on page 4 of the ebook about AI in the real-world.

    Step 3

    Step 3: Teachable Machines:
    What is Machine Learning and the Teachable Machine?

    • Explain to students that they will use machine learning and the Teachable Machine to train their computer to distinguish between items. This platform allows students to test how machine learning works and see how to increase the odds of having the machine make correct choices.
    • Watch the Teachable Machine video
    • Students will hit the “Get Started” button and play with the three project options on the “New Project” page:
      • Image Project: Teach based on images
      • Audio Project: Teach based on sounds
      • Pose Project: Teach based on images

    Step 4

    Step 4. Sorting Machine: Define the Problem

    Review the challenge with students: Read the design challenge aloud:

    Your engineering team has been hired by a breakfast-foods startup that wants to automate part of its packaging line. Your mission is to design a machine-learning-powered sorting system that can tell two types of dry cereal apart and automatically drop each one into the correct container using a simple Arduino-controlled mechanism.

    • Criteria:
      • Cereal must be sorted correctly every time – 100% accuracy.
    • Constraints:
      • Complete in the allotted time.
      • Only use the materials provided.
    Step 5

    Step 5: Sorting Machine: Design Solution

    • Provide the student with the Student Handout to Brainstorm & Sketch Possible Solutions. Make sure to encourage originality, reminding students that there are multiple solutions to the problem.

    Direct them to sketch a diagram of their unique physical design. The design must plan the exact positions of the servo, the computer camera, and the collection cups to ensure the cereal is identified and sorted efficiently.

    Step 6

    Step 6: Sorting Machine: Build Prototype & Hardware Setup

    Students construct their physical machine based on their design sketch.

    • Assembly: Attach the micro servo (SG90) to the sorter structure.
    • Wiring: Carefully connect the micro servo to the Arduino using jumper wires, specifically to GND, connection #9, and 5V.TIny Sortter

    Tips for Assembly:

    • Be very careful to note which wire you are connecting to which connection on the Arduino. You will be looking for GND, connection #9, and 5V.
    • Don’t rush, and do this step carefully!

    Connection: Attach the Arduino to their computer using a micro USB cable and place the sorting machine over the camera on the laptop.

    Note: If the computer has a USB-C port, the student will need an adapter.

    Step 7

    Step 7: Arduino Software Set Up

    Follow the video’s steps for Arduino software here on https://experiments.withgoogle.com/tiny-sorter/view/

     

     

    Step 8

    Step 9: Machine Learning Training

    Students will train their computer to differentiate between two types of cereals using the 

    Teachable Machine.

    • Go to the Teachable Machine link: https://teachablemachine.withgoogle.com/train/image.
      Teachable Machine



    • Data Collection: Students can use their webcam to record video (lots of individual photos) or upload individual photos. Encourage a combination of both and sufficient data to cover:
      • Different angles of the cereal pieces.
      • Different lighting conditions (similar to the final testing environment).
    • Class Training: Students will fill three “classes” with image data and name them:
      • Class 1: Pictures of the first cereal.
      • Class 2: Pictures of the second cereal.
      • Class 3: Pictures of nothing in the container, named “empty.”
    • Training and Export:
      • Select “Training.”
      • When the system is accurately sorting, select Export and upload the Model, then copy the shareable link.

    Go back to the P5 sketch URL and paste the link to the model into the p5 sketch, then select “Load Model.”

    Step 9

    Step 9: Testing and Iteration

    This is the core phase for refining both the physical machine and the machine learning model.

    • Trial Testing: Students will test their sorting machines with several pieces of both types of cereal and see how well it works. The machine should sort at least 50 pieces of cereal in each trial. Students will need to count out the different cereal types before and after sorting.
    • Iteration: If the accuracy is less than 100%, encourage them to revise the system, which may include:
      • Adding more individual photos or completely retraining the computer (more images from many angles will boost accuracy).
      • Adjusting the physical design (e.g., changing the ramp’s curve, steepness, or width).
      • Changing the angle of the laptop cover to slow or speed up the cereal flow.

    Goal: At a real sorting facility, 100% accuracy is required. If a team reaches 100% accuracy on the first trial, have them complete at least two more trials to ensure consistent results.

  • What is Artificial Intelligence and Machine Learning?

    Artificial Intelligence (AI) aims to imitate human or “natural” intelligence by use of modern algorithms and datasets that imitate human learning. Practically, AI helps a machine to learn and perform actions on its own – and improve the accuracy of its recommendations and decisions over time.

    One familiar application of AI is a search engine, which recommends websites to users based on individual requests, and tracks how well the suggested sites meet the users’ needs.  For example, if you search for “history of chess” the underlying program will suggest websites whose contents match the searched phrase and its individual words. Furthermore, if many users with similar search terms click on the same website but click off again quickly, the algorithm will “learn” over time that the suggested site isn’t a good match for the search criteria, and will recommend it less frequently.

    Music streaming services also use AI algorithms to determine which song a subscriber might want to hear next.  In this case there may not be any explicit search criteria, and the service must learn your preferences from your actions on the platform and from any personal information it can access about you. Self-driving cars require AI algorithms to interpret the motion of other vehicles from real-time cameras, to read and understand road signs, and to make choices regarding steering, speed, and safety. AI is also well-established in gaming, where non-player characters (NPCs) and “bot” opponents must mimic human decision-making skills, often at a precisely chosen level of intelligence. Online advertising is personalized using data-driven AI, in which the search history, personal details, and social network of a user determine not only what advertisements they will receive, but when, where, and in what format they will receive them.

    Machine Learning

    Machine Learning (ML) is a widespread and influential variety of AI which enables machines to perform complex tasks without specific instructions or programming. This goal is achieved using statistical optimization, which sometimes incorporates feedback from the environment in which an algorithm operates, and is inspired by the immersive way that humans and other animals are able to learn. We will be working with several machine learning applications in this activity, all involving the identifications of similarities and differences among input data.

    ML algorithms can be thought of as intelligent strategies for pattern recognition. Two key categories are supervised learning, where an algorithm is “trained” on example data with known properties before being applied to unknown data, and unsupervised learning, where an algorithm searches for structure and similarity in an entirely unknown dataset. A simple example of supervised learning is “classification,” where each input datapoint is assigned to one of several categories.  For example, a car moving at 60 MPH on a highway might be labelled as “normal” while another moving at 90 MPH is labelled as “fast,” alerting a self-driving car to a potentially hazardous situation and triggering a reaction. Another example of supervised learning is “regression,” where an algorithm is trained to predict one or more continuous quantities, such as forecasting temperature, rainfall, and humidity at a given location using a combination of historical data and physical weather-modeling. Unsupervised learning includes “clustering” algorithms which identify natural subdivisions of a collection data, and is widely used in computational biology, market research, and the social sciences.

    Image recognition and searching for similar images (e.g. Google Lens) are successful arenas for supervised ML. If you upload a photo of a canoe, for example, many others have likely already done the same, so the algorithm will recognize your image as a canoe. This is possible either because prior users have labelled their canoe images with the word “canoe,” or because the algorithm has scraped contextual information from websites or social media posts where canoe images appear. Over time, as the algorithm absorbs more samples, the system will become more accurate and may learn to distinguish subcategories of canoe, such as styles or manufacturers. Note that the algorithm does not understand what a canoe is or how it works, but has learned to distinguish patterns of pixels which look like a canoe from those that do not. Applications of image recognition include facial or eye recognition in a security system, quality assurance in manufacturing settings, and automated diagnosis from medical scans.

    Computer vision more broadly describes applications where a machine tries to understand some environment through visual data. This often involves the use of multiple AI/ML algorithms in succession, such as unsupervised learning to identify unusual or interesting regions of an image, processing steps which filter unwanted noise or improve contrast, and supervised learning to label objects or behaviors contained in the processed image. Computer vision is used to inform autonomous vehicles about their surroundings, to perform face tagging online, and to automate military combat including missile guidance.

    Natural language processing (NLP) applies ML to recognize, analyze, and interpret human communication – whether in digital text, speech, or handwriting. Supervised learning is frequently used to digitize handwritten or spoken samples, using many training examples which have been tagged by a human or another algorithm. Applications of this technology include virtual assistants, transcriptions of books and letters, machine translation, and live captioning of TV shows or video meetings. Unsupervised learning is also valuable in modern linguistics, identifying patterns in language with greater speed or insight than possible for a human.

    Deep learning is an important class of ML inspired by the communication systems inside animal brains.  Deep neural networks include “hidden layers” of trained algorithms between input and output data, allowing for the modeling of more complex relationships, and have shown promise in computer vision, NLP, and drug development.

    Recently, ethical challenges have emerged related to AI and ML, including racial/gender biases in recognition/classification systems, safety risks from autonomous vehicles, the safety of weapons systems, and privacy concerns associated with personal data. In most cases, it is not the intelligent algorithm itself which leads to ethical issues, but instead the methods by which input data are obtained and results are interpreted or used.

    Find out more at IBM Machine Learning: www.ibm.com/cloud/learn/machine-learning

    • Accuracy: A metric for overall correctness, representing how often the model’s predictions are right (the challenge goal is 100% accuracy).
    • Algorithm: A set of instructions used by a computer to solve problems; AI programs use specific algorithms to enable them to learn and make decisions.2
    • Arduino: The microcontroller used to control the simple mechanism of the sorting device.
    • Classification: The specific type of supervised learning where the AI model learns to predict the category or class of an input (in this case, Cereal 1, Cereal 2, or “empty”).
    • Computer Vision: A field of AI that lets a computer program understand visual data from the world, such as the camera feed of the cereal pieces.
    • Deep Learning: A more advanced type of Machine Learning that uses a Neural Network with multiple layers to find patterns that are difficult to see initially. By processing through deep layers, it can understand complex decisions.
    • Microcontroller: A small computer device used to control the simple mechanism of the sorting machine (the Arduino).
    • Micro Servo: The specific hardware component connected to the Arduino that is used to automatically drop the cereal into the correct container.
    • Natural Language Processing (NLP): A field of AI focused on helping computers understand and work with human language. This allows anyone to talk to an AI program, and the AI will understand what they want it to do.
    • Neural Network: A method in machine learning that uses layers of nodes that communicate to process information, mimicking the way the human brain operates.
    • Supervised Learning: A Machine Learning method that uses examples with the correct answers attached to help train the AI. This helps the AI learn to recognize patterns and make predictions on new data it has never encountered.
    • Teachable Machine: The platform used to train the computer model to distinguish between items, sounds, or poses.
    • Testing Set: New, unseen samples used to check how well the model performs.
    • Training Set: The group of samples (images/video of the cereal) used to build or “teach” the machine learning model.
    • Unsupervised Learning: A Machine Learning method that uses examples without the right answers. The AI figures out its own patterns from the examples, which it can use on new data when it’s ready.
  • Explore the AI Adventures: Exploring the World of Artificial Intelligence eBook to get a full picture of what AI is all about. 

    Some of the  engagement activities described in the eBook include:

    • Neural Networks in Action: Play the AI Quick Draw game by Google and help teach the neural network by adding your drawings to the world’s largest doodling data set.
    • Generative AI Mission: Play with the Tool:
      • Pick a generative AI tool (like ChatGPT or Microsoft Copilot) and give it prompts, such as asking it to tell a story or request help with homework.
      • Observe and reflect on how the AI responds and why.
      • Experiment with different prompts to see how it handles various tasks (e.g., describing a historical event or creating a recipe).
      • Share your experience and reflect on AI’s capabilities
    • Deep Blue is a chess-playing AI developed by IBM that used a rule-based system instead of machine learning. It was incredibly fast, evaluating up to 200 million chess positions per second using a “giant cheat sheet” of moves. In 1997, it successfully beat the world chess champion, Garry Kasparov. Watch: Deep Blue Video 
    • Deepfake Mission: Detecting Deepfakes:
    • AI Ethics: The Debate:
      • Research the singularity and debate the ethical implications of using AI, with teams supporting and opposing its use.
      • Reflect on what was learned after the debate.
  • Student Handout
    Teach Your Machine to Think: Build a Smart Sorter

    Lesson Goal

    In this activity, you will explore artificial intelligence and machine learning by using the Teachable Machine to train your computer to differentiate between two types of dry cereal. You will build a machine-learning-powered sorting system using an Arduino and strive for 100% accuracy.

    Engineering Design Challenge

    Your engineering team has been hired by a breakfast-foods startup that wants to automate part of its packaging line. Your Mission: Design a machine-learning-powered sorting system that can tell two types of dry cereal apart and automatically drop each one into the correct container using a simple Arduino-controlled mechanism.

    Criteria:

    • The computer must be well-trained, or it will make errors.
    • Cereal must be sorted correctly every time (100% accuracy).
    • You can alter the design or the code if you have ideas for improvement.

    Constraints:

    • Complete in the allotted time.
    • Only use the materials provided.

    Activity Procedures: Building Your Smart Sorter (Part Three)

    1. Define the Problem
    • Review the Engineering Design Challenge, Criteria, and Constraints.
    1. Design Solution: Brainstorm & Sketch
    • Brainstorm and sketch possible solutions for your sorting machine.
    • Draw a diagram of your unique physical design. This sketch must plan the exact positions of the servo, the computer camera, and the collection cups to ensure the cereal is identified and sorted efficiently.
    1. Build Prototype & Hardware Setup
    • Assembly: Attach the micro servo (SG90) to the structure of your sorter.
    • Wiring: Carefully connect the micro servo to the Arduino using jumper wires, specifically to GND, connection #9, and 5V.
    • Connection: Attach the Arduino to your computer using a micro USB cable and place the sorting machine over the laptop camera.
    1. Arduino Software Set Up
    1. Open Arduino on your computer.
    2. Open “file” and “examples,” and select “servos” and “sweep” to test if your micro servo moves.
    3. Open the file: sorter_sketch.ino.
    4. Install the web USB library: Go to Sketch → Include Library → Add Zip Library, and then browsing to the WebUSB folder.
    5. Check that the board is correctly identified as Arduino Leonardo and the Port also points to Arduino Leonardo in the Tools menu.
    6. Run the Arduino sketch by clicking the arrow button.
    1. Connect to Browser
    1. Machine Learning Training
    • Go to the Teachable Machine link: https://teachablemachine.withgoogle.com/train/image.
    • Class Training: Create and fill three classes with image data:
      • Class 1: Pictures of the first cereal.
      • Class 2: Pictures of the second cereal.
      • Class 3: Pictures of nothing in the container, named “empty.”
    • Data Collection Tips: Use your webcam to record video (lots of individual photos) or upload individual photos. Ensure sufficient data that covers different angles of the cereal pieces and different lighting conditions.
    • Training and Export:
      • Select “Training.”
      • When the system is accurately sorting, select Export and upload the Model, then copy the shareable link.
      • Go back to the P5 sketch URL and paste the link to the model, then select “Load Model.”
    1. Testing and Iteration
    • Trial Testing: Test your sorting machine with at least 50 pieces of cereal in each trial. You must count the different cereal types before and after sorting.
    • Iteration: If the accuracy is less than 100%, revise your system. This may include:
      • Adding more individual photos or completely retraining the computer (more images from many angles will boost accuracy).
      • Adjusting the physical design (e.g., changing the ramp’s curve, steepness, or width).
      • Changing the angle of the laptop cover.
    • Goal: Reach 100% accuracy. Complete at least two more trials to ensure consistent results once you reach 100%.
    1. Analyze Results and Reflect
    • Document your results using the chart below. Note trends under “Trial Observations” and intended changes under “Planned Changes”.

     

    % Accuracy Trial Observations Planned Changes
    Trial 1
    Trial 2
    Trial 3
    Trial 4

     

  • Next Generation Science Standards (NGSS)

    • MS‑ETS1‑1 – Engineering Design:
      Students define the problem of creating an accurate machine‑learning‑powered sorting system and identify criteria (accuracy, speed, reliability) and constraints (servo range, camera angle, training data quality).
    • MS‑ETS1‑2 – Engineering Design:
      Students evaluate competing ML models and mechanical designs using evidence from accuracy tests, misclassification counts, and servo performance.
    • MS‑ETS1‑3 – Engineering Design:
      Students analyze test results from “at least 50 pieces of cereal per trial” to refine their model, improve training data, adjust lighting, or redesign the ramp mechanism.
    • MS‑ETS1‑4 – Engineering Design:
      Students develop and test a functional prototype sorter using Arduino + ML, iterating to improve accuracy and mechanical reliability.
    • MS‑LS1‑3 (Patterns):
      Students identify visual patterns in cereal images that help the ML model distinguish between classes.
    • MS‑LS4‑5 (Cause & Effect):
      Students explain how changes in training data (e.g., more images, better lighting) cause improvements in classification accuracy.

    ISTE Standards for Students

    • 1.1 Empowered Learner:
      Students take ownership of training, testing, and refining their ML model, adjusting data and design to improve performance.
    • 1.4 Innovative Designer:
      Students design, prototype, and optimize a machine‑learning‑powered sorting device that integrates hardware and software.
    • 1.5 Computational Thinker:
      Students break down the sorting challenge into components (data collection, model training, servo control, mechanical design) and apply algorithmic reasoning.
    • 1.6 Creative Communicator:
      Students communicate their model choices, explain misclassifications, and justify improvements using accuracy data and trial observations.
    • 1.7 Global Collaborator:
      Students work in teams to co‑design, test, and refine their ML sorter using shared datasets and collaborative decision‑making.

    UNESCO – Sustainable Development Goals (SDGs)

    • SDG 4.4 – Skills for Work:
      Students develop foundational AI literacy, coding skills, and engineering design experience relevant to future digital and technical careers.
    • SDG 4.7 – Global Citizenship & Digital Literacy:
      Students explore how intelligent systems make decisions, fostering responsible and informed engagement with AI technologies.
    • SDG 9.5 – Innovation & Research Skills:
      Students engage in a simplified but authentic AI development cycle—data collection, model training, testing, and optimization.

     

    UK National Curriculum

    • Computing – Algorithms & Programming:
      Students design and evaluate ML‑driven decision systems, applying logical reasoning to predict and test outcomes.
    • Computing – Data Representation:
      Students interpret structured datasets (image classes, accuracy metrics) and use patterns to inform model improvements.
    • Design & Technology – Iterative Design:
      Students prototype, test, and refine both the ML model and the mechanical sorting system following an engineering design cycle.
    • Science – Working Scientifically:
      Students analyze data patterns, form evidence‑based conclusions, and evaluate the reliability of their ML model using performance metrics.

    Australian Curriculum

    • Digital Technologies – ACTDIP039 (Years 7–8):
      Students analyze datasets (image sets, accuracy results) to identify patterns and develop algorithms that automate classification.
    • Digital Technologies – ACTDIP040 (Years 7–8):
      Students design and evaluate a digital‑physical solution (ML model + Arduino sorter) using structured logic and iterative refinement.
    • Science Inquiry Skills – ACSIS139:
      Students process and analyze trial data to identify relationships between training data quality and model performance.
    • Design & Technologies – ACTDEK034:
      Students apply engineering design principles to create, test, and optimize a functional machine‑learning‑powered sorting system.
.vc_tta-panels-container .vc_tta-panel, .vc_tta-panels-container .vc_tta-panel-body img , #engineering-design-process .vc_tta-panel-body .vc_row .wpb_column:first-child img{page-break-inside: avoid;position:relative !important; } .vc_tta-panels-container .vc_tta-panel#translations{display:none !important; } .article-text .vc_tta-title-text {font-size:1.75em; color:#00629B;} .article-text h4.vc_tta-panel-title {padding-top:2em;} .article-text .lessonPlan-downloads, .article-text .buttonsetc{display:none !important;}

Lesson Plan Download

Before downloading, please share with us some information.

Name(Required)
Are you a(n)(Required)