Fruit ripeness colour checker
Build it step by step
0 of 7 doneBuild the tube
Line a black tube so the sensor sits at one end.
Wire the sensor
Connect I2C and the LED pin.
Print raw values
Read r, g, b for a sample fruit.
Collect ten fruits of each stage
Note the red-to-green ratios on the serial monitor.
Set the thresholds
Place them between the groups.
Add the grade LEDs
Wire the three LEDs.
Test with new fruit
Check it grades them as you would.
How do you build a fruit ripeness colour checker?
A TCS34725 colour sensor in a dark tube grades tomatoes or bananas as unripe, turning or ripe by their colour. You need Arduino Nano, TCS34725 colour sensor, SSD1306 OLED Display, LED 5 mm green, LED 5 mm yellow, LED 5 mm red and Resistor 220 Ω × 3. It takes 7 steps and about 90 minutes.
- Level
- Intermediate
- Time
- About 90 min
- Parts
- 7
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- DisplaysBuy
- SemiconductorsBuyLED 5 mm green × 1
- SemiconductorsBuyLED 5 mm yellow × 1
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 3
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| TCS34725 VIN | Nano 5V | Power |
| TCS34725 GND | Nano GND | Ground |
| TCS34725 SDA | Nano A4 | I2C data |
| TCS34725 SCL | Nano A5 | I2C clock |
| TCS34725 LED | Nano D7 | On-board white LED control, high is on |
| OLED VCC and GND | Nano 5V and GND | Power |
| OLED SDA and SCL | Nano A4 and A5 | I2C |
| Green LED and 220 Ω resistor | Nano D3 through the resistor, LED to GND | Unripe |
| Yellow LED and 220 Ω resistor | Nano D4 through the resistor, LED to GND | Turning |
| Red LED and 220 Ω resistor | Nano D5 through the resistor, LED to GND | Ripe |
Code
Put the sensor and its white LED at the bottom of a black tube and rest the fruit on the open end, so that the same light and distance are used every time; outside light would ruin the readings. For tomatoes the red-to-green ratio rises as the fruit ripens from green through orange to red. The two thresholds in the code are only starting guesses: measure ten fruits of each stage that you have judged by eye, note the red-to-green ratios on the serial monitor, and put each threshold between neighbouring groups. Bananas need a different rule, such as the yellow level against green. The result is a grade to help sort, not a food safety check. Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Libraries: Adafruit TCS34725, Adafruit SSD1306 and GFX. Tomato example.
#include <Wire.h>
#include <Adafruit_TCS34725.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_TCS34725 tcs(TCS34725_INTEGRATIONTIME_154MS, TCS34725_GAIN_4X);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const byte LED_PIN = 7, G = 3, Y = 4, R = 5;
// Red-to-green ratio thresholds. Replace with values from your own ten fruits of each kind.
const float UNRIPE_BELOW = 0.9, TURNING_BELOW = 1.6;
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, HIGH); // controlled light inside the tube
pinMode(G, OUTPUT); pinMode(Y, OUTPUT); pinMode(R, OUTPUT);
tcs.begin();
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(WHITE);
}
void loop() {
uint16_t r, g, b, c;
tcs.getRawData(&r, &g, &b, &c);
if (c < 50) { oled.clearDisplay(); oled.setCursor(0, 20); oled.print("Place fruit"); oled.display(); delay(500); return; }
float ratio = (float)r / (float)g;
const char *grade; byte pin;
if (ratio < UNRIPE_BELOW) { grade = "UNRIPE"; pin = G; }
else if (ratio < TURNING_BELOW) { grade = "TURNING"; pin = Y; }
else { grade = "RIPE"; pin = R; }
digitalWrite(G, pin == G); digitalWrite(Y, pin == Y); digitalWrite(R, pin == R);
oled.clearDisplay();
oled.setTextSize(1); oled.setCursor(0, 0);
oled.print("R "); oled.print(r); oled.print(" G "); oled.print(g); oled.print(" B "); oled.print(b);
oled.setCursor(0, 12); oled.print("R/G "); oled.print(ratio, 2);
oled.setTextSize(2); oled.setCursor(0, 32); oled.print(grade);
oled.display();
Serial.print(r); Serial.print(","); Serial.print(g); Serial.print(","); Serial.print(b); Serial.print(","); Serial.println(ratio);
delay(500);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Green tomato | UNRIPE and the green LED |
| Orange tomato | TURNING and the yellow LED |
| Red tomato | RIPE and the red LED |
| No fruit on the tube | Place fruit message |
If it does not work
Readings change with daylight
Close the tube so only the LED lights the fruit.
Wrong grades
Recalibrate the thresholds from your own fruit.
Sensor not found
Check I2C wiring and the 0x29 address.
LED stays off
Check the resistor and the pin numbers.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the fruit ripeness colour checker?
Arduino Nano, TCS34725 colour sensor, SSD1306 OLED Display, LED 5 mm green, LED 5 mm yellow, LED 5 mm red and Resistor 220 Ω × 3.
How long does the fruit ripeness colour checker take to build?
About 90 minutes for a intermediate maker, in 7 steps.
How do I know the fruit ripeness colour checker works?
Green tomato: UNRIPE and the green LED. Orange tomato: TURNING and the yellow LED. Red tomato: RIPE and the red LED.
Readings change with daylight: what should I check?
Close the tube so only the LED lights the fruit.
Wrong grades: what should I check?
Recalibrate the thresholds from your own fruit.
Sensor not found: what should I check?
Check I2C wiring and the 0x29 address.
LED stays off: what should I check?
Check the resistor and the pin numbers.
