Skip to content

9. Input Devices

Individual Assignment

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

I tried three types of input this week: Step response, HW-139 touch sensor, and a Standalone 5-Pad Capacitive Touch Sensor Breakout - AT42QT1070

I will likely use the 5-Pad capacitive touch sensor for my final project because, since I need so many touch points, this sensor allows me to recieve signals for 5 pads at a time.

Step Response

The first sensor I tried to use was step response. Step response is Neil’s favorite form of input and Mr. Dubick recommended giving it a try, so I did. I was very confused by this sensor and spent hours trying to understand it, but I eventually decided that it would be worth looking for another sensor for my final project since step response code is so complicated. Because I already have prior coding knowledge, I chose a software-heavy final project, but the step response would be difficult to integrate into the project as a whole. To see my full PCB designing process, visit my Electronics Production page.

This is my final milled and soldered step response PCB:

HW-139 Touch Sensor

I decided to try the HW-139 touch sensor next just to get a better idea of how touch sensors work. This sensor worked very well, but it seems unpractical for my final project, so I did not end up designing and milling a PCB for this sensor. However, I did several tests with breadboards and ended up using this sensor for machine week, so ultimately, I was glad that I learned how to use this sensor this week.

This is the wiring I used for one touch sensor:

This is the code I used to read one touch sensor:

#define BUTTON_PIN D0

struct Touch {
    byte wasPressed = LOW;
    byte isPressed = LOW;
};

Touch touch;

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

void loop() {
    touch.isPressed = isTouchPressed(BUTTON_PIN);

    if (touch.wasPressed != touch.isPressed) {
        Serial.println("Touch pressed");
    }

    touch.wasPressed = touch.isPressed;
}

bool isTouchPressed(int pin) {
    return digitalRead(pin) == HIGH;
}

Here is one touch sensor working:

I decided to add another of the same touch sensor in case this was something I decided to use for my final project.

I made the touch sensors light up 2 different colored LEDs, and ChatGPT helped me with this code just to speed up the process. To see my full conversation with Chat, a pdf is linked at the bottom of this page.

One thing that was cool about this sensor is that it is able to take input even through a material as thick as cardboard.

Here is a video of me testing this:

Standalone 5-Pad Capacitive Touch Sensor Breakout - AT42QT1070

Next, I found a Standalone 5-Pad Capacitive Touch Sensor Breakout - AT42QT1070 in the lab and decided to use that. I really enjoyed this sensor and will definitely be doing more work with it in the future for my final project. Milling the board for this was definitely tedious because I kept ripping traces and running into other issues. If I end up using this sensor for my final project, which I plan to do, I will have to remill the PCB I designed, and I will probably make it double sided.

Without any code connected to it, the touch sensor lights up each of its built-in LEDs when the corresponding pad is touched. All it needs is a connection to power and ground. I used a Xiao RP2040 to program it.

I started out trying to program the touch sensor to just be able to recieve signal from one of the pads. My first big mistake was that I connected the wires on the wrong side of the sensor. I tried to connect the touch pads of the sensor to the Xiao RP2040 instead of the side with the built-in LEDs so one pad was just always being touched, which is not helpful.

Once I figured out this issue, the wiring came very easily.

This is the wiring I used:

Here is Touch Pad 4 working correctly:

I realized when I tried to read multiple of the touch pads that only certain RP2040 pins worked, and I never figured out why, even after I studied the pinout and consulted with ChatGPT. Only d5, d8, d4, d9, and d10 were able to read signal from the touch sensor, which was frustrating.

Here is the code reading the signal, but the numbers were out of order. After some trial and error, I got the order to be how I wanted it to be:

Here is the code I used:

const int touchPins[] = {2, 3, 4, 5, 6, 7, 8};  // RP2040 GPIOs for OUT0 - OUT6
bool lastState[7] = {0};

void setup() {
    Serial.begin(115200);
    for (int i = 0; i < 7; i++) {
        pinMode(touchPins[i], INPUT);
    }
}

void loop() {
    for (int i = 0; i < 7; i++) {
        bool state = digitalRead(touchPins[i]);  // Read touch state
        if (state != lastState[i]) {  // Detect state change
            if (state == LOW) {  // Active-low means touched
                Serial.print("Touch pad ");
                Serial.print(i);
                Serial.println(" touched!");
            } else {
                Serial.print("Touch pad ");
                Serial.print(i);
                Serial.println(" released!");
            }
            lastState[i] = state;  // Update last state
        }
    }
    delay(50);  // Small debounce
}

ChatGPT helped me write the code, but it accomplishes something very simple. First, it sets up the Serial Monitor and sets each of the touch pads as input. Then, in the loop section, it displays a message in the Serial Monitor when the pad is touched and released. I was initally very confused about why the code was not working, but I figured out that it was the pins on the Xiao RP2040, not the code, I’m pretty sure.

Once I got the code working, I moved on to designing and milling the PCB.

To make the PCB for this sensor, I had to measure the size of the sensor using a caliper because it was not a built-in KiCad component, and it was not in the Fab Lab library I downloaded in the Electronics Design week.

This is my PCB design that I made slight altercations to every time I milled it:

Here is a video of the PCB being milled:

I tore a trace on the first one I milled because the traces with thin. I tore the power trace, so I was forced to remill. Then, I milled the same PCB again, and when I was vacuuming the milling machine, I tore a trace again. I went back to KiCad and made the traces bigger, so I would not make the same mistake again. I thought the lab was running out of one-sided copper boards, so I tried using a double-sided board and just peeling the copper off one of the sides. This was not successful, and Mr. Dubick showed me where I could find single-sided copper.

Another issue I ran into was the z-height on the milling machine. I used 0.something instead of just 0. Here is the machine milling at the wrong height:

Here is the final PCB being milled:

Here is the final PCB soldered:

I was not very proud of my soldering job this time, and I was shocked when it worked.

Group Assignment

Our group assignment for this week was to probe an input device’s analog levels and digital signals. I worked with Wilson Zheng and Elle Hahn. [Here] is a link to our group page for this week.

Reflection

This week was pretty rough. The hardest part was definitely trying to figure out step response and coding the capacitive touch sensor since I ran into so many issues. Hopefully, when I remill my PCB again, I will be able to use it in my final project.

Fab Academy Examples

AI Help

Here are all my ChatGPT searches from Week 9: PDF

Files

KiCad design I used for my Step Response PCB

KiCad design I used for my Capacitive Touch Sensor PCB


Last update: April 21, 2025