Week 12 - Light Sensor and Servo
- John Strough - DIY Animatronics and other work
- Animatronic Eye Parts and Code: https://www.johnstrope.com/post/eyemech
- NEW PARTS
- Sensors and Serial Communication
- NFT Workshop wth the McCoys
- From last class, we should still have our potentiometer hooked up into Analog Input 0 (A0) on the arduino.
- Load the AnalogReadSerial sketch (Examples->01.Basics->AnalogReadSerial) to the arduino.
- Open the serial monitor:
- Look at how moving the potentiometer changes the value of analogRead().
- Activity: Use
map() to scale those analog values to 0-255, and use that to fade a jumbo LED (
- We can use
serial.write() to communicate with p5, or processing, or maxMSP or any other program that can read from a serial port.
- Use a multimeter to see how the resistance changes with the photoresistor.
- (this does not need a circuit. connect the red lead to one side of the photoresister, and the black lead to the other)
- We can put a photoresistor in series with a resistor to make a voltage divider. This is similar to how a potentiometer works. As the resistance of the photoresistor changes (the light changes), the output voltage will change.
- Hook up the circuit in the picture above with a resistor, photoresistor, and wires to ground, 5V, and A0.
- Use AnalogReadSerial from the section above, and use the serial port monitor to see what the range of output voltages is.
- Activity: Use the photoresistor to control the servo from last class, in place of the potentiometer
- Use the serial port to debug the range of analog values coming in from the photo-resistor/resistor voltage divider.
map() to scale those analog values to 0 -> 180 degrees (the full range of the servo)
- Interact with the photoresistor and see the motor move.
- Extension: Instead of directly mapping sensor values to servo position, use the sensor values to trigger specific motions. For instance, have if statements that move it to different positions depending on how much light it sees.
- Immediately after class.
- or, contact me online