Week 09 – Input Devices

Hero shot of my input device board

This week is focused on Input Devices: understanding how to connect sensors to a microcontroller, how to probe analog levels and digital signals, and how to read and interpret real-world data from a device connected to a board that I designed.

On this page I document:

Assignment and Learning Outcomes

The weekly assignment is:

The learning outcomes are:

Checklist

In this page I answer the required questions:

You can see the group documentation here:

Group Assignment – Probing Analog Levels and Digital Signals

Hero shot of my input device board

For the group assignment we analyzed the output of one or more input devices and observed their behaviour using laboratory instruments. The goal was to understand how a sensor or input device behaves electrically, both in analog and digital form.

At minimum, we demonstrated the use of a multimeter we haven´t in Ponferrada osciloscope for try it maybe in the next weeks we will get One. We also reviewed the use of a logic analyzer for digital signals when applicable.

Equipment Used

What We Tested

Multimeter

First, we used the multimeter to identify the main electrical values present in the circuit: power supply voltage, continuity between lines, and the voltage changes produced by the sensor.

  1. Connect the multimeter ground reference to the board GND.
  2. Measure the board supply voltage.
  3. Probe the sensor output pin.
  4. Observe how the voltage changes when the physical condition changes.

Logic Analyzer

For digital signals, especially when using communication protocols, the logic analyzer is very useful because it allows us to inspect logic states, timing, and protocol decoding.

In our case, we also reviewed how the logic analyzer can help verify whether a sensor is sending correct digital information to the microcontroller.

What I Learned from the Group Assignment

This group assignment helped me understand that reading a sensor is not only about writing code. It is also about knowing what the signal looks like electrically and how the hardware behaves in real conditions.

Individual Assignment – Measure Something

individual

For the individual assignment I added a sensor to a microcontroller board that I had designed and I read the sensor values using code.

My goal this week was to connect a sensor that could also be useful for my final project, following the recommendation from the local instructors.

In this case I used a RGB Color sensor connected to a Seeed XIAO RP2040 . The sensor measures colors , and I read the values through the microcontroller using the Arduino environment.

Board Design and Fabrication

This week I followed a workflow similar to previous electronics weeks. I designed the board in KiCad, prepared the manufacturing files, milled the PCB, soldered the components, and tested the system.

If the board had already been designed in a previous week, this assignment builds on that base by adding the sensor and the necessary connections.

Design Workflow

  1. Design the sensor board or adapt a previous board in KiCad.
  2. Use the Fab Library for compatible symbols and footprints.
  3. Route the traces according to our milling constraints.
  4. Export the design files for fabrication.
  5. Convert Gerbers if needed and prepare the PNG files for Mods CE.
  6. Mill the board and solder the components.

Main Elements of the Board

For the fabrication process I used the same PCB production workflow as in the previous electronics assignment.

Fabrication and Soldering

After finishing the design, I fabricated the board using the in-house PCB milling workflow. Then I soldered the microcontroller connections, sensor, and the remaining components.

Fabrication Workflow

Interfacing the Sensor

The next step was to connect the sensor to the microcontroller and verify that the board could read the signal correctly.

Depending on the type of sensor, the signal can be:

Electrical Connection

In my case, the sensor output was connected to / SDA-SCL / and power . This allowed the microcontroller to read the physical variable and print the values through the Arduino Serial Monitor.

Code and Reading the RGB Sensor (TCS34725)

To test the RGB color sensor TCS34725, I wrote a program using the Arduino IDE. Unlike a simple analog sensor, this device communicates via I2C, allowing us to read precise values for red, green, blue, and overall light intensity.

How the Code Works

  1. The program includes the required libraries: Wire.h for I2C communication and Adafruit_TCS34725.h to control the sensor.
  2. An instance of the sensor is created with a specific integration time and gain to adjust sensitivity.
  3. In setup(), the serial communication is initialized and the sensor is started using tcs.begin().
  4. If the sensor is not detected, the program stops and displays an error message.
  5. In loop(), the sensor continuously reads raw color data: red (R), green (G), blue (B), and clear/light (C).
  6. The measured values are formatted and sent to the Serial Monitor for visualization.
  7. A short delay is added to make the readings easier to observe.

Example Code


    
Arduino color sensor XIAO-RP2040 Show code
		
#include <Wire.h>
#include "Adafruit_TCS34725.h"

// Sensor configuration (integration time and gain)
Adafruit_TCS34725 tcs = Adafruit_TCS34725(
  TCS34725_INTEGRATIONTIME_50MS,
  TCS34725_GAIN_4X
);

void setup() {
  Serial.begin(115200);
  delay(2000);

  // Initialize the sensor
  if (!tcs.begin()) {
    Serial.println("Error: TCS34725 not found");
    while (1);
  }

  Serial.println("Sensor initialized");
}

void loop() {
  uint16_t r, g, b, c;

  // Read raw RGB and clear light values
  tcs.getRawData(&r, &g, &b, &c);

  // Print formatted values
  Serial.print("Red: ");
  Serial.print(r);

  Serial.print(" , Green: ");
  Serial.print(g);

  Serial.print(" , Blue: ");
  Serial.print(b);

  Serial.print(" , Lumen: ");
  Serial.println(c);

  delay(500);
}
  

Understanding the Output

The sensor provides four values:

These values can be used to detect colors, measure ambient light, or trigger actions based on color conditions.

If the sensor was digital, the code changes depending on the protocol or data format. For example, some digital sensors require a dedicated library or communication through I2C, UART, or 1-wire.

Measured Results

Once the program was uploaded, I verified that the XIAO RP2040 was reading the TCS34725 RGB color sensor correctly through the serial monitor. The values of Red, Green, Blue, and brightness changed depending on the color or object placed in front of the sensor.

This confirmed that the board, the I2C communication, the wiring, and the Arduino code were all working correctly together.

  • When the observed color changed, the RGB values changed accordingly.
  • The serial output allowed me to monitor the sensor response in real time.
  • The measured values were consistent with the expected behaviour of the color sensor.
  • The clear channel value (brightness) also changed depending on the amount of reflected light.

In this way, I could directly observe the relationship between the color of the object and the digital values captured by the microcontroller.

For example, when a red object was placed in front of the sensor, the red channel showed a higher value than the green and blue channels. Similarly, different objects and lighting conditions produced different RGB and brightness readings.

Bonus Pack – Raspberry Pi Face Detection, PIR Presence Detection and MQTT Communication

Sensor connected to board

As a BONUS EXTENSION FOR MY FINAL PROYECT for this assignment, I decided to explore how different input devices and processing systems can work together in a more complete interactive setup.

In this extra experiment, I use a Raspberry Pi as the main processing unit. The Raspberry Pi performs face detection with a camera, while at the same time it uses its GPIO pins to read a PIR motion sensor for presence detection. Based on these inputs, the system sends commands through MQTT to several ESP32 boards, which then react and perform different actions.This is part of my final project: a robot that detects people and rewards them with a hug when they put trash in the box.

System Overview

Before getting started, it is necessary to install Node-RED on the Raspberry Pi in case it is not already installed. You can download it from https://nodered.org.

For MQTT communication, you will also need a broker such as Mosquitto, available at https://mosquitto.org.

Ensuring these components are properly installed is essential for everything to work correctly. However, this setup is not part of this assignment and will be documented in future work.

To work with Node-RED, open a web browser and navigate to http://localhost:1880. Full documentation is available at https://nodered.org/docs/getting-started/raspberrypi .

System Overview 2

  • Main controller: Raspberry Pi
  • Input 1: Face detection using a camera
  • Input 2: Presence detection using a PIR sensor connected to GPIO
  • Communication protocol: MQTT
  • Output devices: ESP32 boards receiving MQTT messages and acting accordingly

Software Used

I divided the project into two software environments depending on the task:

Python Libraries

  • cv2 (OpenCV) for image processing and face detection
  • paho.mqtt for publishing MQTT messages to the ESP32 devices

To create the code, I relied on my knowledge of Python and Node-RED, but I also used AI as support

Node-RED

For the PIR part, I use the standard nodes already included in the Node-RED installation for Raspberry Pi. These nodes allow me to read the GPIO state, process the motion detection event, and integrate it into the MQTT workflow.

How It Works

  1. The camera connected to the Raspberry Pi captures video frames.
  2. Python processes the frames using OpenCV (cv2) to detect faces.
  3. At the same time, a PIR sensor connected to the Raspberry Pi GPIO detects motion or presence.
  4. When a face or presence event is detected, the Raspberry Pi sends a message using MQTT.
  5. The ESP32 boards subscribed to the MQTT topics receive the message.
  6. The ESP32 devices then perform the programmed action, such as turning on outputs, activating responses, or interacting with the environment.

Why I Added This Bonus Pack?

I added this extra section because it connects the weekly topic of input devices with a more advanced real-world application. Instead of reading only one sensor from a microcontroller, this setup combines computer vision, presence sensing, GPIO input, and network communication with distributed embedded devices.

This is also directly related to my FINAL PROJECT , because it demonstrates how different sensing technologies can be integrated into one smart interactive system.

Problems and Fixes

Problems during sensor board development

Problem 1 – Wrong Sensor Connection

  • Problem: At first the sensor did not produce valid readings because one connection was incorrect.
  • Fix: I checked the wiring pin by pin, verified VCC and GND, and corrected the signal connection. I paint colors

Problem 2 – Unstable Readings

  • Problem: The measured values were noisy or unstable.
  • Fix: I checked grounding, improved the wiring, and verified the signal using the multimeter.

Problem 3 – Code or Pin Definition Error

  • Problem: The code was initially reading the wrong pin or using the wrong reading function.
  • Fix: I reviewed the code and corrected the pin definition and the read method.

These problems helped me better understand that successful sensor interfacing depends on both hardware debugging and software debugging.

Design Files, Source Code and Hero Shot

Design Files

Source Code

Summary and Reflection

Reflection on input devices week

This week helped me understand the complete workflow of input devices, from probing signals with lab equipment to connecting a sensor to a custom board and reading real data with code.

One of the most important things I learned is that sensor integration is not only about software. It also requires understanding the signal electrically: whether it is analog or digital, what voltage levels it produces, and how stable the signal is.

The use of the multimeter, oscilloscope, and logic analyzer helped me understand what was really happening between the sensor and the microcontroller.

In the individual assignment I completed the full process: board design, fabrication, sensor connection, code development, and testing. Seeing the measured values change in the serial monitor made it clear that the board was correctly interfacing with the physical world.

This assignment is especially useful for future work because input devices are essential for interactive systems and for my future final project development.