Once again, the dream team of Bruna, Ryan and I reunited to play with more serial outputs. Bruna put together the video below that documents just what we did:
Once again, the dream team of Bruna, Ryan and I reunited to play with more serial outputs. Bruna put together the video below that documents just what we did:
This lab was a little weird for me. I collaborated (once again) with Alessandra and our main issue was that we couldn’t get our values to map correctly. You’ll see in the code below that we could only get the photoresistors to go from about 400 to 600. Our melody sounded a bit….off, and I think that our odd mapping may have had something to do with it.
Here’s a picture of our board with the speaker and the photoresistors.
And this was when we first hooked things up so that different tones would get played as light was added and taken away from the photocells. The sound coming from them is the annoying squealy one, not the stuff that makes it sound like I filmed in a room full of people because I was too lazy to find another room.
And here’s the video where we programmed it to play a little melody. It’s a little hard to hear, but exciting nonetheless.
I’d like to mess around with this lab some more. The first thing I’ll do is try and see if I can get the proper values to map. And the second thing will be to figure out how to program my Arduino to play this. Once again, stay tuned, guys.
CODE:
This post documents my first foray into the world of using Arduino for more than blinking LEDs! We’re finally getting into the art of making things move, and this week we focused on motors. Servomotors, to be more specific. The beauty of servos is that they can be positioned into specific angular positions; all you have to do is send the servo a signal through a variable resistor (I used a potentiometer, just to break up the FSR rut that my Stupid Pet Trick plunged me into).
I decided to actually provide some good documentation this week, so I grabbed a Panasonic LX5 from the ER and even (gasp!) a tripod. But even though I recorded some nice video, my devices revolted and refused to read any of the stuff that I shot. The best that I could do was one screenshot.
You can see in this one how the servomotor and potentiometer are connected to output and input pins (respectively). The white tip on the servomotor would move (up to 280 degrees) according to how I adjusted the potentiometer, and when I moved the potentiometer up to its highest 1023 setting, the servo started to buz and shake.
See, even when I try to set things up all nicely, the end result is still a blurry photo. Sigh.
Here’s the code (in italics) to make up for the lack of video documentation and prove that I did it:
#include <Servo.h>
int analogValue = 0;
Servo servoMotor;
int servoPin = 2;
void setup() {
//pinMode(A0, INPUT);
Serial.begin(9600);
servoMotor.attach(servoPin);
}
void loop() {
analogValue = analogRead(A0);
Serial.println(analogValue);
int servoAngle = map(analogValue, 0, 1023,0,179);
servoMotor.write(servoAngle);
}