Projects / Fruit ripeness colour checker

Fruit ripeness colour checker

Intermediate1.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO

    Build the tube

    Line a black tube so the sensor sits at one end.

  2. NANO8.2 mA

    Wire the sensor

    Connect I2C and the LED pin.

  3. NANO

    Print raw values

    Read r, g, b for a sample fruit.

  4. NANO

    Collect ten fruits of each stage

    Note the red-to-green ratios on the serial monitor.

  5. NANO

    Set the thresholds

    Place them between the groups.

  6. NANO8.3 mA

    Add the grade LEDs

    Wire the three LEDs.

  7. NANO

    Test with new fruit

    Check it grades them as you would.

In short

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

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
TCS34725 VINNano 5VPower
TCS34725 GNDNano GNDGround
TCS34725 SDANano A4I2C data
TCS34725 SCLNano A5I2C clock
TCS34725 LEDNano D7On-board white LED control, high is on
OLED VCC and GNDNano 5V and GNDPower
OLED SDA and SCLNano A4 and A5I2C
Green LED and 220 Ω resistorNano D3 through the resistor, LED to GNDUnripe
Yellow LED and 220 Ω resistorNano D4 through the resistor, LED to GNDTurning
Red LED and 220 Ω resistorNano D5 through the resistor, LED to GNDRipe

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.

CheckExpected
Green tomatoUNRIPE and the green LED
Orange tomatoTURNING and the yellow LED
Red tomatoRIPE and the red LED
No fruit on the tubePlace 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 →

Ask Lark AI

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.