Physical Computing Lab-Analog Output
Servo and Sensor
Connecting a potentiometer or other analog sensor to the Arduino’s analog input pin 0, then connecting a servo motor to the Arduino’s digital pin 9.
The original code: mapped to the servo’s 180 degree range, but editing the map changes the range to another scale.
original code:
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
edited code:
val = map(val, 0, 1023, 0, 90); // scale it to use it with the servo (value between 0 and 90)
Speaker Setup
Connecting one lead from the speaker or headphone jack to ground, the other lead to a 1K resistor, and connect that resistor to digital pin 8. I didn’t set this up right at all and blew out my speaker :(
Fixed the wiring and made some noise! The 1K resistor was too much resistance, the sound was very faint. So I tried a 330 ohm resistor instead, and got better sound (listen closely).
Create Something Unique
Using a photoresistor and a force resistor, I set up an alarm clock that makes an annoying high-pitched beep when the light reaches a certain brightness.