This week for Physical Computing we had to complete two labs: first Arduino program (with digital in & out) and analog in. In addition, I was selected to present a creative project which gives context to the lab concepts.
The LEDs toggle when you press and de-press the button.
For the first Arduino program lab we setup the breadboard with two LEDs and a pushbutton and then wired the breadboard to the Arduino. Since the pushbutton is a digital input (it’s either on or off), both the input and output were connected to the digital row of pins on the Arduino. Then we programed the Arduino to turn on one LED at a time — one is on when the button is not pressed, the other when the button is pressed. The final result is LEDs that toggle when you press the button over and over. This lab helped me to understand the basic setup of input and output, the functions digitalRead and digitalWrite, and the arguments high and low. I’ll put a video here but beware, it’s not really in focus: TwoLEDsAndButton
The second lab focused on analog input. First, we setup the breadboard with a potentiometer and an LED. Then we connected the breadboard to the Arduino using an analog pin for the potentiometer and a digital pin for the LED. The Arduino programming became a little more complicated in this lab: we had to establish variables and translate the analog output of the potentiometer (which ranges from 0 to 1023) into the analog input of the LED (which ranges from 0 to 255). We also used Serial.println() to monitor the potentiometer output. The final result was an LED that grows brighter and fades as you turn the potentiometer. Again, an out of focus video:PotentiometerAndLED
This lab had two parts. In the second part, we used force sensing resistors as the analog input which controlled the brightness of two LEDs. Here’s a video of those sensors in action: touch-sensor-lab-wk2. As you can see, the sensors and LEDs respond fairly well to the variation in pressure.
In addition to the labs, I was selected to present a creative project in class. Since day one at ITP, I’ve heard a lot about the integral part that failure plays in learning and creativity. With that in mind, much of the remainder of this post will be about failure and confusion.
I decided to work with analog input for my creative project — the sensors were a lot of fun to work with, they make you feel like you have control over what’s happening with those little LEDs. Along the lines of the “love-o-meter” challenge, I decided to create a “frugality-o-meter” to measure the very sexy trait of money management by measuring how tightly you can pinch two pennies together. I thought I’d use a flex sensor and build it into some type of contraption which adds in physical resistance (so it becomes a little difficult to bring the two ends together). Based on the analog in lab, and some additional resources, I cobbled together some Arduino code that would make one LED light up with a little flex, a second LED light up with more, and a third LED light up if those pennies were really pinched. When I built my breadboard and connected it to the Arduino, all three LEDs just lit up – not what’s supposed to happen. I’d put in my code a Serial.println() for the sensor input and on the serial monitor there was a fairly steady read of 1023 even when the sensor was totally flat and the read didn’t change much when I bent it. Here’s a picture of the serial monitor:
What’s wrong with this picture?
So, OK, plenty of things could have gone wrong. Is there a problem with my code? Maybe I need to do some math someplace or something? Am I just using the sensor incorrectly? Or is the whole setup totally wrong? I try rearranging things and looking over my work as best I can. Nothing changes. The long story short is that I couldn’t figure out what I was doing wrong, so I decided to give the whole thing a try with the force-sensing resistor. Since I used the FSR in the lab, I feel like I know how to handle this sensor a little better and maybe I can figure out a way to use it in the frugality-o-meter instead.
I disconnect the flex sensor and replace it with the FSR. All the LEDs light up. What? I feel so sad — the good old FSR, after all we went through figuring out part two of the lab, is now betraying me. I open up the serial monitor and the read is changing as I put pressure on the sensor, but it never goes below about 300, even when nothing is touching it at all. Here’s a picture of the serial monitor for the FSR:
Now it’s personal…
I go through all of the adjustments that I can, nothing I do seems to make much of a difference. And, really, the FSR is too sensitive for what I’m trying to accomplish. I could maybe build something around it that gets the job done, but at this point I’m basically doubting all of my skills. I’m unable to figure out what I’m doing wrong so I have to move on.
As a last-ditch effort to try and gain some understanding of where the problem is, I replace the sensor with the potentiometer. And, lo and behold, it works like a charm! Exactly what I want to happen, happens. When you twist the potentiometer a little bit, one LED comes on, a little more lights a second and when it’s cranked all the way all three LEDs are lit. My despair fades. Even if this isn’t what I was going for, at least something is working and making sense. I ditch the frugality-o-meter. I start thinking about a new context for my analog in and corresponding code. With some input, I land on a faucet. A faucet which drips LEDs when you turn the little knob. I add some code which makes the LEDs toggle when the knob is turned on all the way so it looks kind of like a drip. And, while I’m building the housing for the breadboard, I decide to turn the whole thing into a PSA for the DEP. Here’s a photo of the finished piece:
Leaky faucets waste money and resources.
I’ll include a video here too because, well, who knows if this is going to work this afternoon in class (LeakingFaucetAnalogIn). I’ll be honest, I had a hard time getting the breadboard and the Arduino into the housing. I had to add wires to the potentiometer legs so that it could be separated from the breadboard, it got kind of unruly. Also, it’s possible those LEDs will work themselves loose on the commute.
When I started the “get creative” part of the lab I was really nervous. And, as you can see, it wasn’t exactly smooth sailing. But I got something done and I feel good about that. Even if it’s not in direct response to the challenge, the faucet demonstrates a basic understanding and use of analog in. I think this is a great place to start and definitely leaves me a lot of room for improvement.