Skip to content

9. Input Devices


Weekly Assignment:

Group assignment:

  • Probe an input device(s)'s analog levels and digital signals
  • Document your work on the group work page and reflect on your individual page what you learned

Individual assignment:

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

Breadbaord

I started by wiring on the breadboard.

I first tried to make a leap of faith by uploading the final code that includes the touch sensor and LED part together, but it didn't work, as to be expected.

Even so, this was the code.

#define LED_PIN 5
#define TOUCH_PIN 4
#define TOUCH_THRESHOLD 40  // You may need to adjust this depending on your setup

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(115200);
  delay(1000); // Wait for serial monitor to start
}

void loop() {
  int touchValue = touchRead(TOUCH_PIN);
  Serial.println(touchValue);

  if (touchValue < TOUCH_THRESHOLD) {
    digitalWrite(LED_PIN, HIGH);  // Turn on LED
  } else {
    digitalWrite(LED_PIN, LOW);   // Turn off LED
  }

  delay(100);  // Small delay for stability
}

So, I did them by part. First was making sure the LED was working and could be coded by the ESP32C3 to light up. This is the code I ended up using.

#define LED_PIN 6      // GPIO6 (D6) for LED


void setup() {
  pinMode(LED_PIN, OUTPUT);  // Set GPIO6 as output for the LED
}


void loop() {
  digitalWrite(LED_PIN, HIGH);  // Turn LED on
  delay(1000);                  // Wait for 1 second
  digitalWrite(LED_PIN, LOW);   // Turn LED off
  delay(1000);                  // Wait for 1 second
}

Here is a video of the LED blinking on command.

Then, I moved onto the touch sensor. I coded it so that when the touch sensor was touched, there would be an indication on serial monitor. This is the code I ended up using.

#define TOUCH_PIN 5     // GPIO4 for touch sensor


void setup() {
  Serial.begin(115200);
  pinMode(TOUCH_PIN, INPUT);
}


void loop() {
  int touchValue = digitalRead(TOUCH_PIN);  // Read sensor value
  Serial.println(touchValue);  // Print it to Serial Monitor
  delay(100);  // Delay for a moment
}

This is a video of the touch sensor working and serial monitor outputting what the code says. When the touch sensor senses touch, 1 shows up on serial monitor. If not, it keeps outputting 0.

Finally, I used the code from before that incorporates them both. And it worked! Instead of 0 and 1, I changed it to No Touch Sensed and Touch Sensed


PCB

Design

This was the schematic design for my board. I double grounded (something I learned I could do from production week) because I wanted to use the GND pin on the edges and not the random pin 21 thats in the middle of the microcontroller board.

Then I creaded my PCB design and checked if it looked the way I wanted it to in 3D viewer. It seemed fine, so I went on and printed it.

But this is how the design came out.

Because of how small the traces were, the one connecting the resistor to ground and touch sensor pin to the microcontroller both broke off right after milling. Granted, I wasn't extremely careful or delicate in handling them, but I did not expect them to be that fragile. Unfortunately, they broke off on BOTH of the boards I milled, which made all the extra work really counterproductive. I did try salvaging them by creating a solder bridge between them (sounds wrong but it might have actually worked). Only, it was really hard to manipulate the solder because it kept sliding around and balling up.

I ended up just redesigning my board, making sure I would not have the same issue with traces.


Soldering

The board came out much better than before.

I could solder all the components without having to worry about the trace issue or having to create my own traces.

And finally, since my ESP32C3 already had the code uploaded, all I had to do was power it. And it worked!


Overview

This week was another nice opportunity to incorporate what I learned from previous PCB weeks. It was also nice to get a start on familiarizing myself with parts that will end up on my final project. I'm considering potentially using this touch sensor to turn my machine on, but even if I don't I feel like this week was still productive. I'm much more comfortable designing, milling, stuffing, and troubleshooting PCB boards now and that's really useful throughout fab.

On the group assignment side,


Files

Design:

Print:



Last update: May 7, 2025