Week 12 - Sensors and Sensations
Tuesday
Agenda
Artist of the Day
John Strope - DIY Animatronics and other work
Analog Serial
<img = “https://www.arduino.cc/wiki/static/7dbfb4b4c090ba1bc52c2a779822b8f9/29007/analoginoutserial1_bb.png” width=800>
https://docs.arduino.cc/built-in-examples/basics/AnalogReadSerial
- 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 (analogWrite()
)
- We can use
serial.write()
to communicate with p5, or processing, or maxMSP or any other program that can read from a serial port.
Photoresistor
https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput
- 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.
- Use
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.
Homework
Office Hours
Thursday
Agenda
Artist of the Day 2
Inmi Lee
Thermistors
LED Outputs
Activity
Using multiple LEDs, build a bar-graph that displays the temperature (e.g. more lights for higher temp)
Homework 2
Finish up the class activities.
References