Back to Weekly Assignments

Week 9:Input Devices

Assignments

Group Work : Probe an input device(s)'s analog levels and digital signals (As a minimum, you should demonstrate the use of a multimeter and an oscilloscope.) Document the work on the group work page and reflect on your individual page what you learned

individual assignments:Measure something: add a sensor to a microcontroller board that you have designed and read it.

Group Work Assignment Reflection

Summary Table: Multimeter vs. Oscilloscope

Feature Multimeter Oscilloscope
Potentiometer Shows exact steady voltage (e.g., 2.34V). Shows smooth, continuous voltage ramp over time.
Push Button Shows 0V or 5V (static, ideal state). Shows switch bounce (multiple voltage spikes) during the first ~5ms of contact.
Best for… Measuring absolute resistance, average voltage, continuity. Visualizing signal shape, timing, glitches, and transitions.

Conclusion

Use a multimeter to verify the DC operating point of a sensor (e.g., "Is my potentiometer outputting 1.5V?"). Use an oscilloscope to verify the integrity and timing of a digital signal (e.g., "Does my button bounce? Is my serial data line clean?").

Individual Assignments

Sensor & Microcontroller Introduction

TCS3472 — The RGB Color Sensor

What Is An RGB Sensor?

RGB stands for Red, Green, and Blue. An RGB sensor can independently detect the color intensity of red, green, and blue colors. It can also measure brightness. The color sensor achieves this by using an RGB color filter at its input. The red color filter allows only the red color to pass through it. The light falls on the photodiode, whose current will vary depending on the amount of incident light. The current will be converted to a voltage using a signal conditioner which can be read using an ADC.

Description of image

Block Diagram

Here is the block diagram of the TCS34725 sensor. The IR block filter in the TCS34725 helps in sensing ambient light. Ambient light sensing is used in your phones when you set the brightness level to Auto. You can also find applications in TCs and Screens whose brightness will adapt automatically to their ambient. The TCS34725 has an I2C interface (SDA and SCL) that connects to the Arduino Board. The IC also has an optional interrupt output pin which can be used to interrupt Arduino. An example application is a fruit sorting machine. The color will be different if a fruit is not ripened. The Arduino can use this interrupt to trigger a solenoid to let the unripened fruit into another conveyor.

Description of image

Pinout of TCS34725

The below table gives the pin description of the color sensor IC – TCS34725.

Description of image

Description of image

XIAO ESP32-C3 — The Microcontroller

The XIAO ESP32-C3 is an ultra‑compact development board built around the Espressif ESP32‑C3 chip (RISC‑V, 160 MHz). It features 11 digital I/O pins, 4 analog inputs, and supports I²C, SPI, UART, I²S, Wi‑Fi, and Bluetoot

Description of image

Description of image

Description of image

Circuit Design & Wiring

TCS3472 Pin XIAO ESP32-C3 Pin Function
VCC (3.3V–5V) 3V3 Power supply
GND GND Common ground
SDA D4 (GPIO6) I²C Serial Data
SCL D5 (GPIO7) I²C Clock signal

Wiring diagram (ASCII):

Description of image

Description of image

Note: The XIAO ESP32-C3 runs at 3.3V logic. The TCS3472 module accepts both 3.3V and 5V, so direct connection is safe. If using a bare TCS3472 chip, ensure VCC is 3.3V only.

Code Implementation

Adafruit_TCS34725 — Install via Arduino Library Manager (search “Adafruit TCS34725”)

Description of image

Complete Arduino Sketch

ArduinoC++
/*
    Fab Academy 2026 – Individual Assignment: Input Devices
    Board: XIAO ESP32-C3
    Sensor: TCS3472 RGB Color Sensor
    Date: May 15, 2026
*/

#include <Wire.h>
#include "Adafruit_TCS34725.h"

// Create TCS34725 object with default I2C address 0x29
// Parameter values: Integration time (2.4ms) and gain (1x)
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_2_4MS,
                                           TCS34725_GAIN_1X);

void setup() {
  Serial.begin(115200);
  Serial.println("\n\n=== TCS3472 Color Sensor Test on XIAO ESP32-C3 ===");

  // Initialize I2C with specific pins on XIAO ESP32-C3
  // GPIO6 = SDA, GPIO7 = SCL
  Wire.begin(6, 7);  // SDA, SCL

  // Check if sensor is connected
  if (!tcs.begin()) {
    Serial.println("ERROR: TCS3472 sensor not found!");
    Serial.println("Check wiring: VCC -> 3.3V, GND -> GND, SDA -> GPIO6, SCL -> GPIO7");
    while (1) delay(1000);
  }
  Serial.println("TCS3472 sensor detected successfully!");

  // Optional: increase gain for low-light conditions
  // tcs.setGain(TCS34725_GAIN_16X);
  // tcs.setIntegrationTime(TCS34725_INTEGRATIONTIME_50MS);
}

void loop() {
  uint16_t r, g, b, c;  // 16-bit raw values (0-65535)

  // Get raw sensor data
  tcs.getRawData(&r, &g, &b, &c);

  // Calculate color temperature and lux (optional)
  uint16_t colorTemp = tcs.calculateColorTemperature(r, g, b);
  uint32_t lux = tcs.calculateLux(r, g, b);

  // Print to Serial Monitor
  Serial.println("========== SENSOR READINGS ==========");
  Serial.print("Red   (R): ");   Serial.print(r);   Serial.print("\t");
  Serial.print("Green (G): ");   Serial.print(g);   Serial.print("\t");
  Serial.print("Blue  (B): ");   Serial.print(b);   Serial.print("\t");
  Serial.print("Clear (C): ");   Serial.println(c);
  Serial.print("Color Temperature: "); Serial.print(colorTemp); Serial.println(" K");
  Serial.print("Lux (Illuminance): "); Serial.print(lux); Serial.println(" lx");
  Serial.println();

  delay(1000);  // Update once per second
}

Code Walkthrough

Description of image

Problems Encountered & Solutions

Problem 1: Sensor not responding

The Serial Monitor showed No I2C devices Not Found

Description of image

Solution: Check I²C connections and verify sensor is properly powered (3.3V).

Problem 2: Inaccurate color readings under indoor lighting

Symptom: The RGB values did not change significantly when different colored objects were placed in front of the sensor.

Cause: The default integration time (2.4 ms) and gain (1×) were too low, and there was insufficient ambient light.

Solution: Increased the gain to 16× and integration time to 50 ms by uncommenting the two lines in

Gallery

Description of image

Source file (Arduino sketch): TCS3472_XIAO_week09.ino — XIAO ESP32-C3 + TCS3472 color sensor (same code as on this page).