DIY Resistor Color Code Scanner with ESP32-CAM

DIY Resistor Color Code Scanner with ESP32-CAM & TFT Display – Kids Robotics Project | MakeMindz

🔍 DIY Resistor Color Code Scanner

Show a resistor to a tiny camera and watch a colorful screen tell you its value! A fun ESP32-CAM robotics mini project for young makers.

🌈 What Does It Do?

Resistors are tiny parts that control electricity. Instead of numbers, they wear colored stripes (bands). Each color means a number. This scanner uses a camera to look at the stripes, works out the number, and shows the answer on a TFT screen.

📷 Camera sees bands→🧠 ESP32 decodes colors→🖥️ Screen shows ohms

Level: MediumTime: 90 minAge: 10+ with adult help

💡 You will learn: how cameras see colors, how resistor codes work, how a microcontroller makes decisions, and how to draw on a display.

🧰 Parts You Need

  • ESP32-CAM (AI-Thinker) with OV2640 camera module
  • 1.8 inch ST7735 SPI TFT display (the red PCB kind)
  • FTDI USB-to-serial programmer (the ESP32-CAM has no USB port)
  • Breadboard and jumper wires, 2 alligator clips or a small stand to hold the camera
  • 5V power supply (USB power bank or 5V 2A adapter)
  • Resistors to test (4-band, gold on the right)
  • A plain white sheet of paper as the background

⚠️ Adult help tip: Never connect the board to anything above 5V, and unplug power before changing wires.

🔌 Circuit Connections

The screen uses 6 wires. We keep it simple: RESET and the backlight go straight to 3.3V.

TFT display pinESP32-CAM pin
VCC3V3
GNDGND
SCK / CLKGPIO 14
SDA / MOSIGPIO 13
CSGPIO 15
A0 / DCGPIO 2
RESET3V3
LED / BL (backlight)3V3
FTDI programmerESP32-CAM
5V5V
GNDGND
TXU0R
RXU0T
For uploading only: connect GPIO 0 to GND. Remove it and press RESET to run.

💡 Many 1.8" displays have two silkscreen names per pin. If yours says SCL/SDA, they mean SCK/MOSI.

🛠️ Step-by-Step Build

  1. Place the parts. Put the ESP32-CAM on the breadboard and the TFT screen beside it.
  2. Wire the screen using the first table. Double-check every wire before power.
  3. Mount the camera. Hold it with an alligator clip about 8–10 cm above the table, pointing down at a white paper.
  4. Install the software. In Arduino IDE open Preferences and add the ESP32 board package URL, then install "esp32" in Boards Manager. Install the libraries Adafruit GFX and Adafruit ST7735.
  5. Choose the board: Tools → Board → AI Thinker ESP32-CAM.
  6. Upload. Connect GPIO 0 to GND, press RESET, click Upload, then remove the GPIO 0 wire and press RESET again.
  7. Scan! Lay a resistor flat across the middle of the paper with the gold band on the right. Nudge it until the colored boxes on screen match your resistor.

💻 The Code

The camera takes a picture, then the code looks along a thin line through the middle. It finds colored stripes, turns each into a number, and calculates the resistance.

#include "esp_camera.h"
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>

// TFT: CS=15, DC=2, MOSI=13, SCK=14, RST not used
Adafruit_ST7735 tft(15, 2, 13, 14, -1);

// Camera pins for AI-Thinker ESP32-CAM
#define PWDN 32
#define XCLK 0
#define SIOD 26
#define SIOC 27
#define VSYNC 25
#define HREF 23
#define PCLK 22

const char* names[10]={"Black","Brown","Red","Orange","Yellow","Green","Blue","Violet","Grey","White"};
const uint8_t pal[10][3]={{0,0,0},{120,60,20},{220,30,30},{255,140,0},{240,220,0},{0,160,60},{30,80,220},{150,50,200},{130,130,130},{255,255,255}};

bool startCamera(){
  camera_config_t c = {};
  c.ledc_channel=LEDC_CHANNEL_0; c.ledc_timer=LEDC_TIMER_0;
  c.pin_d0=5; c.pin_d1=18; c.pin_d2=19; c.pin_d3=21;
  c.pin_d4=36; c.pin_d5=39; c.pin_d6=34; c.pin_d7=35;
  c.pin_xclk=XCLK; c.pin_pclk=PCLK; c.pin_vsync=VSYNC; c.pin_href=HREF;
  c.pin_sccb_sda=SIOD; c.pin_sccb_scl=SIOC;
  c.pin_pwdn=PWDN; c.pin_reset=-1;
  c.xclk_freq_hz=20000000;
  c.pixel_format=PIXFORMAT_RGB565;
  c.frame_size=FRAMESIZE_QVGA;      // 320 x 240
  c.jpeg_quality=12; c.fb_count=1;
  return esp_camera_init(&c)==ESP_OK;
}

// Turn one pixel color into a band number (-1 = not a band)
int classify(int r,int g,int b){
  int mx=max(r,max(g,b)), mn=min(r,min(g,b));
  float v=mx/255.0, s=mx? (mx-mn)/(float)mx : 0;
  if(v<0.20) return 0;              // black
  if(s<0.45) return -1;             // paper or resistor body
  float h;
  if(mx==r)      h=60.0*(g-b)/(mx-mn);
  else if(mx==g) h=60.0*(2+(float)(b-r)/(mx-mn));
  else           h=60.0*(4+(float)(r-g)/(mx-mn));
  if(h<0) h+=360;
  if(h<12 || h>=345) return v<0.50 ? 1 : 2;   // brown / red
  if(h<38)  return v<0.55 ? 1 : 3;              // brown / orange
  if(h<70)  return 4;                           // yellow
  if(h<170) return 5;                           // green
  if(h<260) return 6;                           // blue
  if(h<330) return 7;                           // violet
  return 2;
}

void setup(){
  tft.initR(INITR_BLACKTAB);
  tft.setRotation(1);
  tft.fillScreen(ST77XX_WHITE);
  tft.setTextColor(ST77XX_BLACK); tft.setTextSize(2);
  tft.setCursor(8,50); tft.print("Starting...");
  if(!startCamera()){ tft.fillScreen(ST77XX_RED); tft.setCursor(8,50); tft.print("Camera error"); while(1); }
}

void loop(){
  camera_fb_t* fb=esp_camera_fb_get();
  if(!fb){ delay(100); return; }

  int bands[8], n=0, cur=-2, run=0;
  for(int x=0;x<320;x++){
    long R=0,G=0,B=0;
    for(int y=116;y<=124;y++){            // average 9 rows in the middle
      int i=(y*320+x)*2;
      uint16_t p=(fb->buf[i]<<8)|fb->buf[i+1];
      R+=((p>>11)&31)*255/31; G+=((p>>5)&63)*255/63; B+=(p&31)*255/31;
    }
    int k=classify(R/9,G/9,B/9);
    if(k==cur) run++;
    else{
      if(cur>=0 && run>=5 && n<8) bands[n++]=cur;   // stripe must be 5+ pixels wide
      cur=k; run=1;
    }
  }
  esp_camera_fb_return(fb);

  tft.fillScreen(ST77XX_WHITE);
  tft.setTextSize(1); tft.setTextColor(ST77XX_BLUE);
  tft.setCursor(6,4); tft.print("RESISTOR SCANNER");

  if(n<3){
    tft.setTextSize(2); tft.setTextColor(ST77XX_RED);
    tft.setCursor(6,50); tft.print("Place resistor");
  } else {
    for(int i=0;i<min(n,4);i++){        // show colored boxes
      tft.fillRect(8+i*36,20,30,30,tft.color565(pal[bands[i]][0],pal[bands[i]][1],pal[bands[i]][2]));
      tft.drawRect(8+i*36,20,30,30,ST77XX_BLACK);
    }
    float ohms=(bands[0]*10+bands[1]);
    for(int m=0;m<bands[2];m++) ohms*=10;
    tft.setTextColor(ST77XX_BLACK); tft.setTextSize(2); tft.setCursor(8,66);
    if(ohms>=1000000) { tft.print(ohms/1000000.0,1); tft.print(" M"); }
    else if(ohms>=1000) { tft.print(ohms/1000.0,1); tft.print(" k"); }
    else { tft.print((int)ohms); tft.print(" "); }
    tft.print((char)0xF4);              // ohm-like symbol; may show differently
    tft.setTextSize(1); tft.setCursor(8,95);
    tft.print(names[bands[0]]); tft.print(" ");
    tft.print(names[bands[1]]); tft.print(" ");
    tft.print(names[bands[2]]);
  }
  delay(700);
}

💡 Tuning tip: If brown looks red or orange looks yellow, change the v<0.50 and h<38 numbers a little. Every room light is different!

🎨 Resistor Color Code Cheat Sheet

ColorDigitMultiplier
Black0×1
Brown1×10
Red2×100
Orange3×1,000
Yellow4×10,000
Green5×100,000
Blue6×1,000,000
Violet7×10,000,000
Grey8×100,000,000
White9×1,000,000,000
Gold±5% tolerance (always on the right end)

Example: Red – Violet – Orange – Gold = 2, 7, ×1,000 = 27,000 Ω = 27 kΩ.

❓ Troubleshooting & FAQ

Screen is white or blank? Check 3V3, GND, and that RESET and LED are both on 3V3. If your display is ILI9341 instead of ST7735, swap the library and constructor.

"Camera error" appears? Reseat the camera ribbon cable, and use a good 5V supply (weak USB ports cause errors).

Wrong colors? Use bright, even light with no shadows, a white paper background, and keep the resistor sharp and centered. This scanner works best on 4-band resistors, with gold on the right.

Upload fails? Make sure GPIO 0 is connected to GND while uploading, and press RESET right before it starts.

🚀 Challenges: show the tolerance too, add a buzzer that beeps when a resistor is found, or draw the live camera picture on the screen.

© MakeMindz – Learn, Build, Innovate. Made for young makers 🌟

Comments

Product Cards
Buddy Bot eBook
⭐ New 2026 Release
Build Your
Own Robot!
3D design, wiring &
Arduino coding.
★★★★★ Young inventors love it!
🖨️
3D Print
All parts
⚡
Wire it
Circuit guide
💻
Code it
Arduino IDE
🤖
Watch it
Walk & react
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Website Offer
₹499 ₹300
🌍 International: $5 USD
One-time · Instant digital delivery
🔒 Secured by Razorpay · Your data is safe
📄 Download Free Sample Copy
🔒 Secured by Razorpay · Your data is safe
🍓
Raspberry Pi Pico Mastery
21 Projects
⚡ Launch Price — 80% OFF
Learn Pico
Build 21 Projects!
MicroPython · Wokwi
IoT · Certificate
★★★★★ Perfect for beginners!
🖥️
Wokwi
No hardware
🐍
MicroPy
From zero
🔨
21 Projects
IoT + sensors
📄
Certificate
Verified cert
📋 Your Details
Enter your name
Valid 10-digit no.
Enter a valid email
Special Launch Offer
₹999 ₹200 80% OFF
🌍 International: $5 USD
One-time · Lifetime access · No subscription
🔒 Secured by Razorpay · UPI · Cards · NetBanking
🎉

You're in!

Payment successful! Your Buddy Bot eBook is ready. Time to build!

📖 Access Your eBook Now
🎉

Enrolled!

Payment successful! Lifetime access to all 21 Pico Projects is yours!

🍓 Go to My Course