PComp Lab 5: Serial communicator
Though simple, this lab was my favorite so far. Finally I’m beginning to see how we take input from the real world and make it do fun digital things. It gave me lots of ideas, principal among them this: what if you wired a handheld fan in such a way that when someone held it next to a screen leaves/dots/pinwheels on the screen responded accordingly? You could sense distance and direction. I really want to try that. Anyway, it was a great joy to finally arrange a liaison between Arduino and oh so coy Processing.
I set up the lab looking only at the schematic (I’m trying to get better at reading diagrams), which wasn’t particularly challenging given the simplicity of this particular wiring. I did manage to wire my potentiometer so that the readings increased when it was turned counterclockwise and decreased when it was turned clockwise. Switching the power and ground connections fixed that.
I got the expected gobbledygook on the serial monitor.
And then I wrote up the graphing app in Processing, which outputted the following when I turned the potentiometer knob back and forth:
But that didn’t look so interesting, so by altering the Ardiuno code to
I got a more colorful graph:
I tried a photo sensor:
And a force sensor
The force sensor’s range seemed too narrow, so I mapped its maximum and minimum values to 255 and 0
analogValue = map(analogValue, 0, 50, 0, 255);
and got a much noisier graph:
To do: I’m going to get the values to display as numbers every so often on the graph and I’d really like to rewrite the code so that the screen scrolls rather than the graph (possibly by storing each value in an array and then shifting all the values over each time a new value is read, at least that’s what I’m thinking now). Also, I really should have tried to get a video screenshot of the graph moving rather than the various stills.