Monday, March 7, 2016

Scratch for Arduino (S4A) Project - A Food Detector

Here is a project to design a Food Detector - an interactive game that tries to identify the type of food among a few given food items.  It uses the Arduino's analog inputs to measure the resistance offered by different food items. I designed this lesson for our Grade 5 students, and taught it last week at school. The inspiration for this lesson came from the Pixelate game, that I found on the Arduino site. The class went really well, and the kids had fun playing detective with different fruits & vegetables.

Below is the formal lesson plan:


Different food items have different resistance/ conductance to electricity. Learn to use the analog sensors in the Arduino to identify different food items, with S4A (Scratch for Arduino) as the software development environment.


Build upon the students’ learning from Grade 4 that different materials have different amounts of resistance to electricity. Use a few food items with a range of resistance values. The students look at the sensor values to compare and identify the food items from a given list. The students use their knowledge of comparators and conditionals from the previous classes to design the game.

Computer Science Concepts

  • Design interactive programs
  • Use of sensors
  • Conditionals
  • Comparators
  • Logic - AND
  • Variables

Common Core Standards

Math Standards:
  • Variables
  • Comparing values
  • Electric circuits
  • Resistance & conductance


  • Software Development Environment: S4A (Scratch for Arduino)
  • Arduino Uno
  • USB cable to connect the Arduino to the laptop
  • Breadboard
  • Jumper wires
  • Resistor
  • A few pieces of fruits & vegetables


  • 1-1.5 hrs

Lesson Plan

Several fruits and vegetables act as conductors of electricity because the juices in them are mild acids, and the acids can conduct electricity just like in a voltaic battery. The level of conductivity depends on the water content and the amount of other chemicals in the fruit. The more water and chemicals there is in the fruit, the more amount of electrical energy it will allow to pass through. Acidic fruits, like lemon, are usually good conductors of electricity.

In this assignment, we shall design a game that uses a very simple version of an ohm-meter, built using the Arduino. We will examine the readings of an Analog pin (A0) on the Arduino and compare the values generated by different fruits and vegetables. The fruit/veg is of unknown resistance, and we use the Analog pin (A0 ) to measure the voltage drop across this resistor (the fruit/veg piece). The larger the reading obtained, the lesser the resistance offered by the food item, and the more its conductance. Here are a couple of links with info on how to build an ohmmeter using the Arduino:

Note: We shall use the value of A0 just to identify the food items. To keep it simple for the kids, we shall not delve into the math that uses the voltage drop to calculate the resistance associated with the food items. We shall simply look at the reading of A0 and identify the associated food item in our game.

Image Source:

We shall work with a pre-decided set of food items. Choose 4-5 different types of fruits and vegetables. We shall build a circuit similar to the schematic above and examine the readings of Analog pin A0, for different food items.



Experiment with a variety of foods to see what values are generated by them. The monitor that appears on screen along with the Arduino sprite can be used to see the readings for A0. Here are a few sample values for A0 that I obtained with the following fruits & vegetables:

  • red grape - 19
  • cherry tomato - 35
  • apple  4-8
  • yellow squash - 14
  • carrot top - 15
  • dried orange - 0
  • dried fig -  0
  • Other options to try -> lemons, berries, kiwis, melons, etc.

As you can see, some of the values are pretty close, while some are far apart. I also used a couple of dry fruits in the experiments, to check whether the lack of juices/water in the fruit would amount to no current flow. In the game, you want to try and use food items which have A0 values far apart, so that they can be distinctly and easily identified. Our program shall examine the value of A0, and compare it with some pre-set values or ranges to determine the type of food item.

On the day of the programming class, bring in several pieces of 4-5 different kinds of fruits and vegetables. The fruit/vegetable pieces shall act as the unknown resistor in the circuit above, and will be attached to the board via jumper wires. Allow the kids to experiment and note down the values of A0 in each case, and then use the values to design the game.

Once the A0 values are determined, the programming can begin. Details of the program are included in the slides. We shall use comparators and conditionals to check the range of the A0 values, and use it to identify the food item.

After the program is made, the kids can set up a cardboard piece or so, to act as a screen behind which the food items are placed. The jumper wires to connect to the food should stick through the cardboard to the other side, so that they can be connected to the food pieces. One player connects the food to the wires, while the other person runs the S4A program and sees whether the food is identified correctly.


A discussion of the science behind the game could be used to wrap up the class. Here is a link with some questions related to the conductance of electricity through fruit:

No comments:

Post a Comment