PAGE 08 PAGE 10
WEEK #09

INPUT DEVICES

Giving senses to the machine! Measuring distance with IR and pressure with custom e-textiles.

ALL ACCESS MISSION FILES (GITLAB REPO)

MISSION BRIEFING

This week's directive is to add sensors to a microcontroller board that I have designed and read them. I decided to tackle two different types of inputs for my custom XIAO RP2350 board: a Sharp GP2Y0A41SK0F Infrared Distance Sensor and a custom-made piezoresistive fabric sensor using Velostat.

01. GROUP ASSIGNMENT

For the group assignment, we probed the analog levels and digital signals of an input device using an oscilloscope and a multimeter.

📂 OPEN GROUP ASSIGNMENT

02. PREPARING ARDUINO IDE (XIAO CORE)

Since the Seeed Studio XIAO RP2350 is a very new microcontroller, the Arduino IDE does not recognize it by default. Before writing any code, I had to install the specific Board Manager Core. Here are the 7 steps I followed:

03. THE HARDWARE BASE (PCB V2.0)

For this assignment, I am using the custom PCB I designed and milled myself. At its core is the Seeed Studio XIAO RP2350. Previously, I had already routed and soldered an external LED to pin D0 and a tactile button to pin D1. Since my design exposed 7 additional free pins via male headers, I had plenty of options. For these analog sensors, I decided to use the analog pin D2 (A2) to read the data, tapping into the available 5V and GND pads to power the modules.

Custom PCB V2.0 Setup
My custom V2.0 board. Ready to receive analog signals.

04. TROUBLESHOOTING THE COM PORT

Before I could upload any code to read the sensors, I ran into a major roadblock: the Arduino IDE was not detecting the COM port of my XIAO RP2350. The board was powered on, but the computer couldn't communicate with it to upload the sketch. After some research, I found out this is a common issue with new RP2040/RP2350 chips.

The solution involved manually compiling the code and flashing a binary file to upload the code to the Xiao without Arduino. Here is the step-by-step fix:

05. SENSOR 1: SHARP IR DISTANCE

I tested the Sharp GP2Y0A41SK0F. The sensor needs 5V to power on, but its output signal peaks at ~3.1V, which connects directly to the XIAO's 3.3V logic perfectly!

Sharp Sensor connected to XIAO
Hero Test: The Serial Monitor displaying accurate distance in centimeters!

05. THE PIEZORESISTIVE FORCE (HOW IT WORKS)

Before diving into programming, the mission required understanding the secret energy behind Velostat. The diagram below (from the excellent Fab Lab León documentation) decrypts the data.

Our sewn t-shirt sensor operates on this exact principle. When pressure is applied to the Velostat layer between the conductive threads, the resistance between the conductors drops, allowing more voltage to pass to our analog input pin D2 (A2), which the machine converts into data.

06. SENSOR 2: VELOSTAT FABRIC SENSOR

For my second input, I designed an e-textile sensor using faux leather and Velostat. Velostat is a piezoresistive material whose electrical resistance decreases when compressed. I built a "shirt" structure with sewn contacts to create a complete circuit loop.

To connect this soft sensor to my rigid PCB, I used a modular approach: alligator clips paired with jumper wires. I clamped one alligator clip to the copper contact pad on the sensor and plugged its jumper end into the analog pin D2 (A2) on my board. The second alligator clip was attached to the conductive thread on the opposite side of the sensor, with its jumper connected to a GND pin.

By utilizing the XIAO's internal pull-up resistor (INPUT_PULLUP) in my code, I created a voltage divider without needing to solder any external resistors to my PCB. As pressure increases on the fabric, the resistance drops, and the analog value read by the ADC goes down.

Custom Velostat Leather Sensor
Hero Test: Plotter visualizing pressure waves!

07. THE CODE VAULT

// CODE 1: SHARP IR

const int PIN_SHARP = A2; 
const int LED_PLACA = D0; 

void setup() {
  Serial.begin(115200); 
  analogReadResolution(12); 
  pinMode(LED_PLACA, OUTPUT);
}

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); 
  }

  Serial.println(distancia_cm);

  if (distancia_cm > 4 && distancia_cm < 10) { 
    digitalWrite(LED_PLACA, HIGH);
  } else {
    digitalWrite(LED_PLACA, LOW);
  }
  delay(100); 
}

// CODE 2: VELOSTAT

const int PIN_CAMISA = A2; 
const int LED_PLACA = D0; 

void setup() {
  Serial.begin(115200); 
  pinMode(LED_PLACA, OUTPUT);
  pinMode(PIN_CAMISA, INPUT_PULLUP); 
}

void loop() {
  int presion = analogRead(PIN_CAMISA);
  Serial.println(presion);

  if (presion < 2000) { 
    digitalWrite(LED_PLACA, HIGH);
  } else {
    digitalWrite(LED_PLACA, LOW);
  }
  delay(50); 
}