Abstract
Do you have a garden or houseplants? What about living on or a near a farm? How often do you check your plants' leaves for discoloration? What if you could build a robot to check for you, and warn you if your plants are getting sick? In this project you will learn to use a color sensor to identify different colors on leaves, which can give you a warning about problems like pests, diseases, or nutrient deficiency. Get ready to automate your gardening!
Summary
Previous experience with Arduino is recommended before you try this project. See our How to Use an Arduino page.
A kit is available from our partner Home Science Tools®. See the Materials section for details.
No issues
Objective
Build a color sensor circuit to detect different color leaves.
Introduction
The appearance of a plant's leaves can tell you a lot about the plant's health. Discolored leaves can be a sign of an underlying issue like nutrient deficiency, over/under-watering, too much (or too little) exposure to sunlight, pests, or fungus. The type of discoloration can vary depending on the plant and underlying problem. Discoloration can come in multiple forms, including changes in color, location, size, and shape of spots. For example, there can be a single, large spot (Figure 1) or numerous small spots (Figure 2). Monitoring the leaves for any issues can help you identify the cause of the problem and, if necessary, isolate it from other plants or treat it before there is further damage to the plant.

If you have a small garden or a couple of house plants, taking a quick glance at the leaves every day might not be a big problem. But what if you have a huge backyard garden or even a farm? You might not have time to walk around and look at every single plant every day. What if you could build a robot to monitor your plants' health for you? In this project you will use a color sensor to detect different color leaves. The color sensor responds to different wavelengths of visible light. Just like our eyes, it specifically responds to red, green, and blue light, which can be mixed to form other colors like yellow and brown. As explained in the following video, you will need to calibrate the sensor to identify the leaves.
In this project, you will need to pick plants to work with. You can then calibrate the sensor to identify healthy green leaves and discolored leaves and alert the user (you!) using something like an LED or buzzer when an unhealthy leaf is detected. You can look up what the specific type of discoloration means for your plants and how to treat it (some references in the Bibliography can help with this). Optionally, you can mount your color sensor on a robotic arm or a mobile robot (see the Variations section).
Terms and Concepts
- Color sensor
- Wavelength
- Visible light
- Calibrate
Questions
- What are some reasons that a plant's leaves may be discolored?
- How does a color sensor work?
Bibliography
- Science Buddies Staff (n.d.). Engineering Design Process. Science Buddies. Retrieved May 20th, 2024
- Finio, B. (n.d.). How to Use an Arduino. Science Buddies. Retrieved May 20th, 2024
- PennState Extension (2024, January 10). Your Plants Look Sick? Now What? Retrieved May 20th, 2024
- PennState Extension (n.d.). Plant Disease Identification and Control. Retrieved May 20th, 2024
Materials and Equipment 
Recommended Project Supplies
-
Electronics Kit for Arduino, available from our partner Home Science Tools®.
The kit includes the following parts that you need for this project:
- Arduino-compatible microcontroller board
- Note: This project will work with the Arduino UNO R3, UNO R4 Minima, UNO R4 WiFi, and compatible third-party boards.
- USB cable
- Breadboard
- Jumper wires
- LEDs
- Resistors
- Arduino-compatible microcontroller board
- TCS3200 color sensor
- Additional male-female jumper wires
- Windows or Mac computer. See this page if you have a Chromebook. Your computer will need:
- Access to the Arduino IDE, either installed local version or web-based editor. Watch this video for a comparison of the two options.
- USB port. The Science Buddies kit comes with a USB-A to C cable. The "C" end plugs into the Arduino, and the "A" end plugs into your computer. You will need an adapter or different cable if your computer only has USB-C ports. Watch this video to learn about the different types of cables and adapters.
- Access to plants or leaves you can test. If you do not have access to any plants with discolored leaves, you can search for leaves on the ground, or pick some leaves off a plant and place them in the sun until they start to change color. Note that the color sensor will work best with large discolored patches (like Figure 1 in the Introduction), not small spots (like Figure 2).
Disclaimer: Science Buddies participates in affiliate programs with Home Science Tools®, Amazon.com, Carolina Biological, and Jameco Electronics. Proceeds from the affiliate programs help support Science Buddies, a 501(c)(3) public charity, and keep our resources free for everyone. Our top priority is student learning. If you have any comments (positive or negative) related to purchases you've made for science projects from recommendations on our site, please let us know. Write to us at [email protected].
Experimental Procedure

Build Your Circuit
Assemble your circuit as shown in Figures 3 and 4. Important: depending on where you bought your breadboard, the left-right orientation of the power and ground buses may be reversed.
- Connect red, yellow, and green LEDs to Arduino pins 8, 9, and 10 respectively. Use 220Ω current-limiting resistors for the Arduino UNO R3 and 470Ω resistors for the UNO R4.
- Connect the color sensor pins as follows. Use male-female jumper wires to connect the color sensor pins to your breadboard. Important: depending on where you bought your sensor, the physical order of the pins on your sensor board might not match Figures 3 and 4. Make sure you read the labels on your sensor and connect the pins accordingly.
- VCC pin to 5V (your sensor may have more than one VCC pin).
- GND pin to GND (your sensor may have more than one GND pin).
- S0 to Arduino pin 2
- S1 to Arduino pin 3
- S2 to Arduino pin 4
- S3 to Arduino pin 5
- LED to 5V
- OUT to Arduino pin 6


Test the Code
- Download color_sensor_LEDs.ino.
- Read through the commented code so you understand how it works.
- Upload the code to your Arduino.
- Open the serial monitor (Tools→Serial monitor).
- Look at the red, green, and blue (RGB) values printed out on the serial monitor.
- If you have not already, make sure you watch the tutorial video about the color sensor in the introduction. Remember that a smaller number (the pulse width measured by the
pulseInfunction) means more of that color light. If you find this confusing, you can uncomment the lines of code that use the Arduinomapfunction. You can use this function to convert the light readings to a range where a bigger number means more light. - Experiment with holding the color sensor over different color surfaces and at different distances and watch how the RGB values change.
Calibrate Your Sensor
- Gather the leaves that you plan to use for your experiment. Make sure you have several samples each of at least two different colors (healthy and unhealthy).
- Using the resources in the Bibliography, or other resources that you find online, try to figure out what the discoloration means for your specific plant species. What are some possible underlying causes? How are they treated?
- Make a data table like Table 1. Add rows as needed.
- For each leaf, fill in the actual color that you see with your eyes in the data table (green, yellow, brown, etc.).
- Hold the color sensor directly over the leaf at a constant distance, and watch the RGB values in the serial monitor. They will fluctuate slightly even if you hold the sensor perfectly still. Write down typical or average values for the red, green, and blue readings.
- Repeat this process for each one of your leaves. If your leaves are large enough, you can even take readings at different locations on each leaf.
| Leaf number | Actual Color | Red Value | Green Value | Blue Value |
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| ... |
Table 1. Example data table.
- Based on the values you recorded in Table 1, now you will need to add conditions to the
ifstatements in the code to detect certain colors. For example, the condition(red > 40 && green < 20 && blue > 30)will be true if the red value is greater than 40, the green value is less than 20, and the blue value is greater than 30. This means that there is more green light and less red or blue light (assuming you are not using the map function to change the values so that a bigger number means more light, in which case you would need to reverse the greater than and less than signs). You can read more about if statements, logical operators, and comparison operators in the Structure section of the Arduino language reference. - Enter conditions you developed in the previous step in the code where it says "FILL IN YOUR CONDITIONS HERE" and uncomment the
if/elsestatements. Re-upload the code to your Arduino and try holding the sensor over different leaves. Do the red, yellow, or green LEDs light up appropriately? If not, watch the RGB values in the serial monitor. How do they compare to the values you entered in yourifstatement conditions? You may need to leave a slight buffer or margin for error in your values. For example, if you typically read a green value of 20 on a green leaf, you could set the condition forgreen<25. - Continue iteratively testing your leaves and adjusting the conditions for your
ifstatements. Document your conditions for each iteration in your lab notebook. Can you adjust your code so you avoid false positives (detecting a healthy leaf as unhealthy) or false negatives (detecting an unhealthy leaf as healthy)? - What other changes or improvements could you make to your code? See the Variations section for more ideas.
- Going forward, how could you use your color sensor to monitor plant health? What would your treatment plan be when you detect unhealthy leaves?
Ask an Expert
Global Goals
The United Nations Sustainable Development Goals (UNSDGs) are a blueprint to achieve a better and more sustainable future for all.
Variations
- Can you mount a color sensor on a mobile robot? What about a robotic arm? You could even combine the two, and put a robotic arm on a mobile robot! This would allow your robot to drive around and check different plants.
- Can you use a buzzer as an alarm when you detect a discolored leaf?
Careers
If you like this project, you might enjoy exploring these related careers:
Contact Us
Our kits are developed in partnership with Home Science Tools®. If you have purchased a kit for this project, Home Science Tools® is pleased to answer any questions.In your email, please follow these instructions:
- Include your Home Science Tools® order number.
- Please describe how you need help as thoroughly as possible:
Examples
Good Question I'm trying to do Experimental Procedure step #5, "Scrape the insulation from the wire. . ." How do I know when I've scraped enough?
Good Question I'm at Experimental Procedure step #7, "Move the magnet back and forth . . ." and the LED is not lighting up.
Bad Question I don't understand the instructions. Help!
Good Question I am purchasing my materials. Can I substitute a 1N34 diode for the 1N25 diode called for in the material list?
Bad Question Can I use a different part?
Contact Support











