9 - Input Devices

Summary
This week was all about input devices, getting more familiar with them and adding one to our own PCB's.
Approach
My focus this week was on input devices that could work for my final project and getting more practice with the PCB production process.
Assignment
- group assignment:
- probe an input device's analog levels and digital signals
- individual assignment:
- measure something: add a sensor to a microcontroller board that you have designed and read it
Group assignment
For our group assignment this week with the help of Henk and Erwin we played around with a bunch of different sensors, both from the Waag inventory and an Arduino kit that Christian brought. We analyzed how these sensors work by using multimeters, logic analyzers and an oscilloscope just like in week 6 Christian did a really good job at documenting our group assignment, below I summarize what I learned from each sensor.

Water sensor
Unfortunately the datasheet for Christian's Arduino kit doesn't give us much information about the water sensor we tested with the multimeter, but it tells us it's a “Circuit board with a switching transistor” (Platine mit Schalttransistor). From this and some explanation by Erwin we can understand how this sensor works.
A water sensor like this uses a conductive plate and a small circuit to detect liquid by measuring voltage. The plate has exposed metal traces that are normally not connected, so the measured voltage is low. When water touches the plate, it creates a conductive path between the traces, allowing current to flow. This changes the voltage at the output, typically increasing it, which the circuit (with a transistor) passes on as a signal that a microcontroller can read to detect the presence of water.
The transistor on this kind of water sensor acts as a switch or amplifier for the signal coming from the plate. The small current that flows when water connects the traces is often too weak or unstable to use directly, so the transistor uses that tiny input at its base to control a larger, more stable current between its collector and emitter. This turns the weak change caused by the water into a clear on/off (digital) signal that a microcontroller can reliably read.
Temperature and Humidity
Next up we analyzed a DHT11 humidity and temperature digital sensor with a logic analyzer.
The DHT11 is a simple digital sensor that measures temperature and humidity using two internal components. For humidity, it uses a moisture-sensitive material whose electrical resistance changes depending on how much water vapor is in the air. For temperature, it uses a thermistor, which changes resistance based on temperature. An internal chip reads these changes, converts them into digital values, and sends the data to a microcontroller over a single-wire serial signal.
Real Time Clock
The DS1302 is a real-time clock (RTC) chip that keeps track of time and date. It has an internal clock that counts seconds, minutes, hours, days, months, and years, and it can run continuously using a small backup battery even when the main power is off. The chip communicates with a microcontroller through a three-wire interface (clock, data, and reset), sending time data in a digital format.
We had some issues working with this one, getting scrambled data back for quite a while. We disconnected it from power by disconnecting it from the Arduino and taking the battery out, but apparently not for long enough; due to the capacitor on the RTC's PCB. Due to time constraints we gave up on analyzing this sensor with the logic analyzer and moved on to the next one.
Distance sensor
Henk wanted to show us to study the workings of a sensor he analyzed during his time at Fab Academy. It's an Ultrasonic Ranging Module HC-SR04 which measures distance using sound waves. It sends out a short ultrasonic pulse (a burst of sound at a frequency too high for humans to hear) and then listens for the echo that bounces back from an object. By measuring how long it takes for the echo to return, the sensor can calculate the distance using the speed of sound. The microcontroller triggers the pulse and then reads the duration of the returned signal to determine how far away an object is.
To help us get started we look at Henk's documentation and see it uses an amplifier component which has four internal amplifiers. These four amplifiers aren't internally connected, so you use them either parallel or in series to amplify the signal four times. It's impossible to see on the PCB how the traces are connected, so we tried to analyze this with the oscilloscope, but this was a bit tricky. With the help of Henk we did in the end see some results.
Individual assignment
Magnetic field sensor
For my final project I'm trying to make an interactive bead curtain, so this week I was looking for input devices that could be useful there. I was thinking of using a 6-axis accelerometer+gyroscope, but talking to Henk and my classmates it become clear quickly this is complex; this components need to be attached to a PCB via reflow, each bead would require it's own PCB which would be coming a wiring and coding nightmare and they're not exactly cheap compared to other sensors. Henk suggests to add a row of magnetic field sensors behind a row of beads just below the top of the curtain, these magnetic sensors could detect whether and how the strands are moving. I like this idea so Henk orders me a sensor, unfortunately it gets delayed in the mail and I haven't been able to play around with it this week.

Motion sensor
Since the magnetic field sensor didn't arrive on time I think of other sensors that could add interesting interactions to the bead curtain. Two things come to mine, one being distance, the curtain could pulsate or change color the closer you get, the other motion, where motion within the curtain could wake it up from stand-by mode. Since there's no time to order anything else for this week I have to choose from the sensors that are available at Waag, which leaves me with one option for both, a sonar (HC-SR04) for distance and a pyroelectric (HC-SR501) one for motion. The datasheet for the sonar sensor states that it has a 15 degree angle, the motion sensor on the other hand has a 100 degree angle. I whip up a sketch in Freecad to see what this means.

This quickly shows that the distance sensor only works for things that are basically directly in front of it, adding multiple sensors to my final project design would be extra complexity I'm not really looking for right now, so for this week I decide to stick with the motion sensor. The HC-SR501 is a PIR (passive infrared) motion sensor that detects movement by sensing changes in infrared radiation. All warm objects, like people, emit infrared energy, and the sensor has two small sensing elements that monitor this radiation in its field of view. When something moves, the infrared levels change between these two elements, and the sensor detects this difference. The module includes a lens (the white dome) that helps focus and spread the detection area, and a small circuit that processes the signal. When motion is detected, the sensor outputs a HIGH signal; otherwise, it stays LOW. There are multiple datasheets around for this little sensor, but there's one that is very extensive and even has a little code demo.

It also does a good job at explaining the three different configurations on the sensor. There are two potentiometers, one for the distance which ranges from 3 to 7 meters, and one for the delay after motion is detected. There's also a jumper with a jumper cap that you use to set whether you want the sensor to start the time delay after the first motion is detected or to reset for every motion. Henk hands me the sensor and I start by testing it in my Arduino setup.

It's fairly easy to setup and control. Next up I move to KiCad and design a little PCB which does the same as the Arduino setup, but with a Xiao microcontroller. The sensor has three pins, power ground and output, so I add a three pin header on the side of my board.

Next up I move over to the mill we also used last week, this week luckily everything goes a lot more smoothly and it doesn't take long to mill the board.

I solder on all the components and hook it up to my computer, first I nuke the microcontroller and install MicroPython like we did in week 4. Then I load the code example from the datasheet and it works beautifully. To make sure I fully understand them I play around with the configurations on the sensor.

Flex sensor
Speaking with my classmate Christian he suggests an idea I've also thought about: what if you add a sensor that can measure flexing and bending to the strand of the bead curtain? Luckily in my ten year old Arduino kit there's a flex sensor. The example in the Arduino guide book uses a little servo motor as output, so I decide to first build this setup and test if the sensor is working at all, which it does.
A flex sensor is a plastic strip with a conductive coating. When the strip is straight, the coating will be a certain resistance.When the strip is bent, the particles in the coating get further apart, increasing the resistance.
From the Arduino code example by SparkFun
I change the setup to remove the motor and write the values from the flex sensor to the serial monitor. It give me values from about 750 till 1000, depending on the bend.

Shape sensor
It would be really cool to have a sensor that can measure bends both ways and describe the curves of a strand. Talking to Henk he mentions a paper that does exactly that. I found a video on Youtube by one of the authors that does a good job of explaining the sensor. Below I quote the most relevant parts of the paper.
ShArc: A Geometric Technique for Multi-Bend/Shape Sensing - Fereshteh Shahmiri, Georgia Institute of Technology, Paul H. Dietz, Tactual Labs

Figure 1: a. A capacitive ShArc sensor uses a series of flexible strips that are joined together at one end. The outer electrode strips are held a constant distance apart via an elastic sleeve which compresses them against a series of spacers. A circuit measures the relative shift between the electrode layers as the strips are formed into the curves. b. When the strips are bent, the ends no longer align due to the varying radii of curvature. c and d. Interacting with the prototype and real-time reconstruction of dynamic bends.

Figure 7: The relationship between the relative shift and differential capacitance. a. Transmit electrodes are centered between two receive electrodes when sensor is laying flat, giving zero differential capacitance. b. When sensor is bent, the transmit electrodes overlap one receive electrode more than the other, creating a non-zero differential capacitance. The change in capacitance indicates the degree of shift. C. A top and side view of the overlap between transmit and receive electrodes when the differential capacitance is minimum and maximum.

They now also have a commercial version of this sensor available, at 16cm in length with 16 segments, for $350.00. This pricing and the complexity of the sensor suggests it is not realistic to make two meter long ones for my bead curtain, but it would be really cool to see if we can replicate the behavior in a Fab Lab.
What would i do differently
My LED is kind of under the sensor on the board, next time I should think more carefully about the 3D aspects of my board, especially when working with header pins. They were also so close to together on this board that it became a bit hard to solder.
Files & resources
Leftovers previous week
- week 8 documentation
Further exploration
- magnetic field sensor
- flex sensor with multiple bends and/or both directions