Playing with a flex sensor
Concept explored: Voltage dividers, analog I/O, programming with Arduino
Materials used: Breadboard, wires, LED, Arduino micro controller, glove, flex sensor, (lotsa) tape, 100 Kohm resistor and 330 ohm resistor
The idea
Expressing emotions with body movements.
How do body movements change when you feel an emotion? A very happy person may have a different walking rhythm than a person who’s not feeling that great. And so I decided to take up one such emotion: anger. I wanted to explore the relationship of one’s body movements with the intensity of an emotion.
How the idea is meant to work
When a person clenches his fists with anger, an LED would increase or decrease in brightness depending on the bend of the flex sensor, i.e it would show the gradual progress of one’s anger when going from relaxed hands to clenched fists.
How I set things up
Hooking up the circuit:
First, connected the LED and a 330 ohm resistor to 5V (found out that 330 ohm would work)
Defined the output for the LED by connecting it to 13 on the micro controller
Connected the LED circuit to 5V and GRD on the micro controller so it’s powered
Next, attached the flex sensor to a glove and connected it to the breadboard
Connected the flex sensor to a resistor on the breadboard and connected another wire in between the resistors to read the difference in voltage which would act as the analog input.Connected that wire to A0 on the micro controller.
Mistakes happened. And learnings too.
Lesson #1: The flex sensor is always attached in a way that the ink is exposed on the outside when bending. Did it the wrong way first.
Lesson #2: Don’t try connecting the flex sensor to wires with tape, solder it. I still haven’t managed to and so the circuit is too delicate and unreliable.
Went up to the VFL lap, were an assistant taught me a bunch of things including soldering which was very helpful. Outcome: A stronger (and neater) connection.
Lesson #3: Don’t solder onto the flex sensor directly. It’ll burn the plastic.
Lesson #4: Use a stranded wire instead of a single one when longer lengths are required so the wires inside don’t brake.
Lesson #5: Insulate the wires using the rubber things + heat.
Writing the code in Arduino:
As my starting point, I referred to the photocell code and tried to use the same logic to brighten/dim the LED. I failed. After doing some research, I found out to make the LED bright and dim, we had to convert the range into 0-255 from 0-1023. So I used some of the code and wrote some, and it looked something like this:
Result: Nothing happened, it did not work : /
Attempt 2: Sat with Eric to troubleshoot and realised, the min and max values in the code (0-1023) were actually not my sensors min and max values. We read the min and max value of the flex sensor based on the resistor I used and changed it accordingly.
Lesson#6: Use a resistor that allows maximum range of sensitivity. Right now, my range is narrow which is why the brightness increase/decrease is over a less range of motion.
Revised code:
Voila! It worked! The LED changed its brightness based on how much a bent my finger.
Here’s how it looked.
Schematic diagram
Concept video