Week 9: Input Devices
Group assignment
Week 9Introduction
Input devices are hardware components that allow users to enter data, send commands, and interact with a computer system. They convert physical actions—like typing, clicking, or speaking—into digital signals for processing. Common examples include keyboards, mice, touchscreens, microphones, cameras, and scanners.
This week I’ll design a PCB with all the XIAO’s inputs and outputs, because I didn’t include them on last week’s board. For the inputs, I’ll use two different sensors: a step response sensor and a Sharp IR sensor. I’m interested in the step response sensor for a potential application in my final project.
Types of signals
Digital Signals: A digital signal is a type of signal that represents data as a sequence of discrete, distinct values—typically binary 0s and 1s—rather than a continuous waveform. These signals are implemented as fixed-width electrical or light pulses (0V or 5V), creating a square wave pattern that offers high noise immunity and better data integrity than analog signals.
Analog Signals: An analog signal is a continuous, time-varying electrical, mechanical, or physical signal that represents information by varying its amplitude, frequency, or phase. Unlike digital signals, which use discrete binary values (0s and 1s), analog signals can take on an infinite range of values, making them ideal for representing natural phenomena like sound, temperature, and light.
Type of communications
These methods define rules for data exchange and are designed for reliable communication between multiple devices:
I²C (Inter-Integrated Circuit)
Two-wire protocol (SDA, SCL) that allows multiple devices using addressing.
- One main device + multiple peripherals
SPI (Serial Peripheral Interface)
High-speed communication with dedicated lines (MOSI, MISO, SCK, CS).
- One main device + multiple peripherals (each with select line)
UART (Serial Communication)
Asynchronous communication using TX/RX.
- Point-to-point (main ↔ peripheral)
PCB
Schematic
XIAO INPUTS AND OUTPUTS. For the Xiao, I'll just add pins for its inputs and outputs, and I'll also add pins for external power supply (3.3V, 5V, and GND).
NeoPixels. I connected them to D3 on my Xiao using a resistor and a label, then connected the LEDs in series and the first power pin to a capacitor of 100 nF for component safety. Finally, I left some holes so that more LEDs could be added if desired.
Display. For the display output I just added the corresponding pins to connect it later and a decoupling capacitor to 3.3V.
PCB design
1. Then I went to the PCB editor and with the Route single track I connected every component.
Calculator tool. Before defining the size, it is important to calculate it using the calculator tool given by KiCad. To do that we first have to go to the start menu and open the Calculator tool.Then add the Current (I) and the Temperature rise we are expecting our PCB to have and look fo the result the calculator will give back to us in the right top side. The calculator works by using a formula explained at the bottom.
Track thickness. To change the track thickness we must go to the top tool section and click on Track use netclass width. Subsequently, select Edit Pre-defined Sizes.
Inside that section we can add tracks sizes by clicking the + symbol located at the bottom of the window, and in the width section we can change the width of the new track we added. Then we'll just have to click Ok.
MODS
This are the parameters for each process in Mods. If you want to learn more go to Week 8.
Parameters.• The outline width is 2 mm and its layer is Edge.Cuts.• The track’s width is 0.8 mm- 2 mm and its layer is F.Cu.• The Holes layer is User.1.
Drilling - MODS.
• Tool width. 0.8 mm• Speed. 0.5 mm/s• Origin (x,y,z). (0,0,0)• Offset number. 1
Cutting - MODS.
• Tool width. 0.39 mm• Speed. 4 mm/s• Origin (x,y,z). (0,0,0)•Offset number. 3
Outline - MODS.
• Tool width. 2 mm• Speed. 4 mm/s• Origin (x,y,z). (0,0,0)• Offset number. 1
Results
VPANEL
VPanel for the Roland DG Corporation SRM-20 is the dedicated, user-friendly computer software interface used to operate, control, and monitor the desktop milling machine. It acts as a virtual on-screen panel, enabling users to set the milling origin (XYZ base point), adjust feed rates and spindle speeds, and pause/resume jobs.
Before Cutting
1. First, we have to paste the tape in the back of the copper board.
2. Then, we have to paste the copper board to the Sacrifice Bed.
Materials:
Copper Board.
double-sided tape.
Sacrifice Bed. Is an MDF board designed to prevent the SMR-20 from being damaged in the event that the tool drills too deep.
Before Cutting
3. Subsequently, we have to place the bed inside the SMR-20. In my case, in my lab, our SMR-20 has a fitting to secure the sacrifice table with screws.
Before Cutting
4. Having secured the bed inside the SMR-20, we have to select the tool for each milling process (Holes, Tracks and Borders).
Drilling Tool. This tool is specifically for perforations because of its shape and width. To use it, we must set the speed between 0.1 and 0.5 in order to don't damage it.
Cutting tool. This tool is specifically designed for traces, as its point is sharp and very thin. The Speed of use can be higher but we must be careful about its deep.
Border tool. This tool is can be used for the border cutting because of its width, it can also be used for perforation, but the diameter of them will be bigger.
Cutting
1. We have to connect our computer to the SMR-20 and open VPANEL.
VPANEL.
X-Y Controls. Move the tool in the X-Y axis.
Z Controls.Move the tool in the Z axis.
Cursor Step and Shortcuts. The Step Cursor determines the speed at which the tool moves along all axes; Continue is the smoothest and x1 is the slowest setting, since each click corresponds to a single motor movement. The Shortcuts are to automatically move to an already saved point (Origin Point).
Speed and Spindle. Is to set the speed and to turn on or turn off the the spin of the tool.
Set Coordinates (Origin Point). By clicking the XY or the Z button we can set the Origin Point.
Process Controls. Cut is for adding our code and start the process. Pause, this allows you to pause the process and resume it from where it left off. Stop, stops the process.
Cutting
2. Then we have to click on Cut. A window will open, and we should click Add to add our milling code.
3. Finally we have to click Output and the machine will automatically start to cut.
Cutting
Soldering
1. To solder, we first need to set up our workspace and gather the necessary tools.
Necessary tools
- Soldering station
- Flux
- Soldering Tin
- Desoldering mesh
- Silicone Tablecloth
Components
- Pinheaders
- 1 Jumper
- 2 smd WS2812B
Soldering
2. First, we need to apply flux to our PCB so that the solder adheres better. I placed the Xiao over the pins so it would stand upright.
Soldering
3.Then, we have to turn on the soldering station and set the temperature. To solder tin it is recomendable to place the temperature above 300 °C (572 °F). I will use 375 °C (710 °F) because that works good with my materials.
4.To solder, we have to place the soldering iron over the copper board and heat it up, then we have to place the Tin on the surface and wait until it melts. It is important to place the Tin on the copper surfance and not on the soldering iron because the melted Tin flows toward hot surfaces, if we place it on the soldering iron, it won't adhere easily to the copper surface because it will be cooler.
Results
Note.During the design of the PCB, I forgot to connect my neopixels to voltage, so I solved it using a little cable and soldering it to one 3.3V pin. Then I had some trouble with the alimentaton because I forgot that the neopixels requiere more than 3.3V to perform properly.
Step Response Sensor
Schematic
I made this sensor with the help of Adrian Torres documentation, Neil Gershenfeld's examples and Robert Hart's page.
What this sensor does is that its reading increases when we bring the plates closer together, since the distance between the two copper pieces decreases, causing a change in capacitance. The closer the plates are, the greater the capacitance.
Step Response. This board only has the pins needed to connect the step-response sensor to the microcontroller. It consists of two analog pins; one is connected to GND and the other to 3.3V via two 1-megohm resistors. After that, I simply added pins for power.
PCB design
1. Then I went to the PCB editor and with the Route single track I connected every component.
Calculator tool. Before defining the size, it is important to calculate it using the calculator tool given by KiCad. To do that we first have to go to the start menu and open the Calculator tool.Then add the Current (I) and the Temperature rise we are expecting our PCB to have and look fo the result the calculator will give back to us in the right top side. The calculator works by using a formula explained at the bottom.
Track thickness. To change the track thickness we must go to the top tool section and click on Track use netclass width. Subsequently, select Edit Pre-defined Sizes.
Inside that section we can add tracks sizes by clicking the + symbol located at the bottom of the window, and in the width section we can change the width of the new track we added. Then we'll just have to click Ok.
MODS
This are the parameters for each process in Mods. If you want to learn more go to Week 8.
Parameters.• The outline width is 2 mm and its layer is Edge.Cuts.• The track’s width is 0.8 mm- 2 mm and its layer is F.Cu.• The Holes layer is User.1.
Drilling - MODS.
• Tool width. 0.8 mm• Speed. 0.5 mm/s• Origin (x,y,z). (0,0,0)• Offset number. 1
Cutting - MODS.
• Tool width. 0.39 mm• Speed. 4 mm/s• Origin (x,y,z). (0,0,0)•Offset number. 3
Outline - MODS.
• Tool width. 2 mm• Speed. 4 mm/s• Origin (x,y,z). (0,0,0)• Offset number. 1
3D view
How to make the sensor
1. First I gathered all the materials.
Necessary materials
- Non-conductive material
- Copper tape
- Scissors
- Wire or Jumpers
How to make the sensor
2. Then we have to cut the Non-conductive material in the shape we desire.
How to make the sensor
3. Then we have to cut the Copper tape and paste it over the other material.
How to make the sensor
4. Then we have to connect it. To connect the board with the sensor we must conect one layer to a digital pin and the other layer to the Step response board analog pin and the other analog pin to one microcontrollers analog pin. then connect the power supply pins to power.
XIAO ESP32-C6 - Capacitive Sensing & NeoPixel Control
~ Method: Step response capacitive sensing (TX: D10, RX: A2).
~ Output: Dual WS2812B visual feedback via Pin D3.
~ Logic: Signal mapping and range filtering for proximity detection.
#include <Adafruit_NeoPixel.h>
// -------- CONFIGURACIÓN --------
#define PIN_NEO 3
#define NUM_PIXELS 2
Adafruit_NeoPixel pixels(NUM_PIXELS, PIN_NEO, NEO_GRB + NEO_KHZ800);
long result;
int analog_pin = A2;
int tx_pin = D10;
void setup() {
pinMode(tx_pin, OUTPUT);
Serial.begin(115200);
pixels.begin();
pixels.clear();
pixels.show();
}
long tx_rx() {
int read_high, read_low, diff;
long sum = 0;
for (int i = 0; i < 100; i++) {
digitalWrite(tx_pin, HIGH);
read_high = analogRead(analog_pin);
delayMicroseconds(100);
digitalWrite(tx_pin, LOW);
read_low = analogRead(analog_pin);
diff = read_high - read_low;
sum += diff;
}
return sum;
}
void loop() {
result = tx_rx();
long mapped_result = map(result, 15000, 25000, 0, 1024);
if (mapped_result >= 30000 && mapped_result <= 35000) {
for(int i=0; i < NUM_PIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(255, 0, 0));
}
pixels.show();
} else {
pixels.clear();
pixels.show();
}
delay(50);
}
CODE - EXPLANATION
This code implements a capacitive sensing system (specifically a transmit-receive method) using NeoPixel LEDs as visual indicators. The logic revolves around sending an electrical pulse, measuring the differential response to detect proximity or touch, and triggering a specific color on the LEDs if the value falls within a programmed range.
~ Library Configuration and Hardware Mapping:
The program begins by including the Adafruit_NeoPixel.h library to control addressable LEDs. The constants PIN_NEO (Pin 3) and NUM_PIXELS (2) define the hardware connection and the number of LEDs in the strip. The pixels object is then initialized using the NEO_GRB protocol. For the sensor portion, analog_pin (A2) is set to read the incoming signal, while tx_pin (D10) is used to transmit the pulse. The global variable result is declared to store the final processed sensor value.
~ Initialization and Setup:
In the void setup() function, the code prepares the pins and communication protocols. The tx_pin is configured as an OUTPUT, and the serial communication is opened at 115200 baud to allow for real-time data monitoring on a computer. The NeoPixel object is started via pixels.begin(), and the code immediately calls pixels.clear() and pixels.show() to ensure the LEDs are off at startup. A one-second delay(1000) is included to ensure the hardware stabilizes before the first reading.
~ The Sensing Mechanism: tx_rx Function:
The long tx_rx() function is the "heart" of the sensor. It uses a sampling technique to filter out electrical noise by taking 100 measurements (N_samples). In each iteration of the for loop, it sets the tx_pin to HIGH, reads the voltage at analog_pin (read_high), waits 100 microseconds, and then sets the tx_pin to LOW to read the voltage again (read_low). The difference between these two states is stored in diff and added to a cumulative sum. This differential measurement helps isolate the change in capacitance caused by a nearby object or finger.
~ Data Processing and Mapping:
Inside the void loop(), the variable result is updated by calling the tx_rx() function. The code then uses the map() function to convert this raw sum into a more manageable scale. The variable mapped_result scales the input range (15,000 to 25,000) to a new range of 0 to 1,024. Both the raw and mapped values are printed to the Serial Monitor, which is essential for calibrating the sensor and seeing how the environment affects the readings.
~ LED Feedback Logic:
The final section of the code handles the visual feedback. It uses an if statement to check if mapped_result falls between 30,000 and 35,000. If this condition is met, a for loop iterates through the LEDs and sets them to red using pixels.setPixelColor(i, pixels.Color(255, 0, 0)). If the value is outside this range, the else block executes pixels.clear(), turning the lights off. Note that there is a logical discrepancy in the code: the map function outputs a maximum of 1,024, but the if statement looks for values over 30,000, meaning the LEDs will likely remain off unless the mapping parameters are adjusted.
Results
How does it work?
1. I made this sensor with the help of Adrian Torres' documentation and Neil Gershenfeld's examples.
2. Then, we have to paste the copper board to the Sacrifice Bed.
Materials:
Copper Board.
double-sided tape.
Sacrifice Bed. Is an MDF board designed to prevent the SMR-20 from being damaged in the event that the tool drills too deep.
Before Cutting
3. Subsequently, we have to place the bed inside the SMR-20. In my case, in my lab, our SMR-20 has a fitting to secure the sacrifice table with screws.
Before Cutting
4. Having secured the bed inside the SMR-20, we have to select the tool for each milling process (Holes, Tracks and Borders).
Drilling Tool. This tool is specifically for perforations because of its shape and width. To use it, we must set the speed between 0.1 and 0.5 in order to don't damage it.
Cutting tool. This tool is specifically designed for traces, as its point is sharp and very thin. The Speed of use can be higher but we must be careful about its deep.
Border tool. This tool is can be used for the border cutting because of its width, it can also be used for perforation, but the diameter of them will be bigger.
Cutting
1. We have to connect our computer to the SMR-20 and open VPANEL.
VPANEL.
X-Y Controls. Move the tool in the X-Y axis.
Z Controls.Move the tool in the Z axis.
Cursor Step and Shortcuts. The Step Cursor determines the speed at which the tool moves along all axes; Continue is the smoothest and x1 is the slowest setting, since each click corresponds to a single motor movement. The Shortcuts are to automatically move to an already saved point (Origin Point).
Speed and Spindle. Is to set the speed and to turn on or turn off the the spin of the tool.
Set Coordinates (Origin Point). By clicking the XY or the Z button we can set the Origin Point.
Process Controls. Cut is for adding our code and start the process. Pause, this allows you to pause the process and resume it from where it left off. Stop, stops the process.
Cutting
2. Then we have to click on Cut. A window will open, and we should click Add to add our milling code.
3. Finally we have to click Output and the machine will automatically start to cut.
Cutting
Sharp IR Distance
Sensor
is a distance measuring sensor unit, composed of an integrated combination of PSD (position sensitive detector) , IR-LED (infrared emitting diode) and signal processing circuit. The variety of the reflectivity of the object, the environmental temperature and the operating duration are not influenced easily to the distance detection because of adopting the triangulation method. This device outputs the voltage corresponding to the detection distance. So this sensor can also be used as a proximity sensor.
Datasheet: Sharp IR Distance
How to connect.To connect it, simply connect the red wire to 5V, the black wire to GND, and the yellow wire to any analog pin on the microcontroller.
XIAO RP2350 - Sharp Distance Sensor & Visual Feedback
~ Hardware: Sharp GP2Y0A41SK0F (Analog) & 2x WS2812B LEDs.
~ Resolution: 12-bit ADC configuration for Raspberry Pi Silicon.
~ Threshold: Binary color feedback (Red ≤ 10cm, Blue > 10cm).
#include <Adafruit_NeoPixel.h>
const int PIN_SHARP = A2;
const int PIN_NEO = D3;
const int NUM_LEDS = 2;
Adafruit_NeoPixel strip(NUM_LEDS, PIN_NEO, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
strip.begin();
strip.setBrightness(50);
strip.show();
analogReadResolution(12);
Serial.println("--- SISTEMA DE PROXIMIDAD LISTO ---");
}
void loop() {
int lectura = analogRead(PIN_SHARP);
float voltaje = lectura * (3.3 / 4095.0);
float distancia_cm = 0;
if (voltaje > 0.4) {
distancia_cm = 13.0 / (voltaje - 0.1);
}
if (distancia_cm > 0 && distancia_cm <= 10) {
strip.setPixelColor(0, strip.Color(255, 0, 0));
strip.setPixelColor(1, strip.Color(255, 0, 0));
} else {
strip.setPixelColor(0, strip.Color(0, 0, 255));
strip.setPixelColor(1, strip.Color(0, 0, 255));
}
strip.show();
delay(50);
}
CODE - EXPLANATION
This code establishes a proximity-sensing system using an infrared (IR) distance sensor and NeoPixel LEDs. It is specifically configured for the XIAO RP2350 microcontroller, providing real-time visual feedback by changing the LED colors based on how close an object is to the sensor.
~ Hardware Configuration and Variable Definitions:
The program begins by including the Adafruit_NeoPixel.h library to manage the addressable LEDs. It defines three main constants for hardware mapping: PIN_SHARP (A2) for the sensor input, PIN_NEO (D3) for the LED data line, and NUM_LEDS (2) for the quantity of LEDs. An object named strip is created to control the NeoPixels using the NEO_GRB protocol. These variables ensure the code knows exactly where the sensor is sending data and where the light signals are being sent.
~ System Initialization (Setup):
In the void setup() function, the code prepares the hardware for operation. It initializes serial communication at 115200 baud for debugging purposes. The strip.begin() and strip.show() commands ensure the LEDs start in an "off" state, while strip.setBrightness(50) limits the intensity to roughly 20% to save power and protect the eyes. Crucially, the function analogReadResolution(12) is called to set the Analog-to-Digital Converter (ADC) to 12-bit mode, allowing the microcontroller to read the sensor with a high precision range of 0 to 4095.
~ Data Acquisition and Voltage Conversion:
The void loop() starts by taking a raw reading from the sensor using analogRead(PIN_SHARP), storing it in the integer variable lectura. Because the microcontroller operates on 3.3V logic and the ADC is set to 12-bit, the code calculates the variable voltaje using the formula lectura * (3.3 / 4095.0). This converts the raw digital number back into a meaningful voltage level, which is necessary to calculate the physical distance.
~ Distance Calculation Formula:
The code converts the voltage into a distance measurement in centimeters, stored in the variable distancia_cm. Sharp IR sensors like the GP2Y0A41SK0F have a non-linear output, so the code uses a specific linearization formula: 13.0 / (voltaje - 0.1). An if (voltaje > 0.4) condition is used to ensure the sensor is within its reliable operating range before performing the math; if the voltage is too low, the distance remains at zero to avoid mathematical errors or "ghost" readings.
~ Logic and Visual Feedback:
After calculating the distance, the code uses an if-else structure to provide visual feedback. If distancia_cm is between 0 and 10 cm, the code calls strip.setPixelColor to turn both LEDs RED (255, 0, 0), signaling that an object is very close. If the distance is greater than 10 cm or no object is detected, the LEDs are set to BLUE (0, 0, 255). The strip.show() function is then called to push these color changes to the physical LEDs.
~ Debugging and Timing:
To help the user monitor the system, Serial.print and Serial.println are used to output the distancia_cm value to the Serial Monitor in real-time. Finally, a delay(50) is included at the end of the loop. This short 50-millisecond pause ensures the system remains highly responsive to movement while preventing the Serial Monitor from being flooded with data too quickly, striking a balance between performance and readability.
Results
How does it work?
1. I made this sensor with the help of Adrian Torres' documentation and Neil Gershenfeld's examples.
2. Then, we have to paste the copper board to the Sacrifice Bed.
Materials:
Copper Board.
double-sided tape.
Sacrifice Bed. Is an MDF board designed to prevent the SMR-20 from being damaged in the event that the tool drills too deep.
Before Cutting
3. Subsequently, we have to place the bed inside the SMR-20. In my case, in my lab, our SMR-20 has a fitting to secure the sacrifice table with screws.
Before Cutting
4. Having secured the bed inside the SMR-20, we have to select the tool for each milling process (Holes, Tracks and Borders).
Drilling Tool. This tool is specifically for perforations because of its shape and width. To use it, we must set the speed between 0.1 and 0.5 in order to don't damage it.
Cutting tool. This tool is specifically designed for traces, as its point is sharp and very thin. The Speed of use can be higher but we must be careful about its deep.
Border tool. This tool is can be used for the border cutting because of its width, it can also be used for perforation, but the diameter of them will be bigger.
Cutting
1. We have to connect our computer to the SMR-20 and open VPANEL.
VPANEL.
X-Y Controls. Move the tool in the X-Y axis.
Z Controls.Move the tool in the Z axis.
Cursor Step and Shortcuts. The Step Cursor determines the speed at which the tool moves along all axes; Continue is the smoothest and x1 is the slowest setting, since each click corresponds to a single motor movement. The Shortcuts are to automatically move to an already saved point (Origin Point).
Speed and Spindle. Is to set the speed and to turn on or turn off the the spin of the tool.
Set Coordinates (Origin Point). By clicking the XY or the Z button we can set the Origin Point.
Process Controls. Cut is for adding our code and start the process. Pause, this allows you to pause the process and resume it from where it left off. Stop, stops the process.
Cutting
2. Then we have to click on Cut. A window will open, and we should click Add to add our milling code.
3. Finally we have to click Output and the machine will automatically start to cut.
Cutting
Learning outcomes
This week I learned how to build capacitive sensors and how they work. I also came to understand how useful this type of sensor is for my final project, which involves detecting impacts and measuring reaction times. In addition, I learned how proximity sensors work and how to program them.