- Physical Computing by Igoe & O’Sullivan (2004)
Ch 6. pgs 87-136 (for this week and next week)
Before the Lab
You should have already successfully built the 3 LED (RGB) circuit and gotten them to fade with various color combinations. Congratulations!
In Lab Exercise
In this lab, we explore analog input. Specifically, we’ll be looking at variable resistance devices known as potentiometers or “pots” for short. These are also known as “knobs” that you might be familiar with turning in other user interfaces, such as the volume knob on a radio. In exploring analog input, we will use Arduino to read pot values and control the LEDs based on those pot values. We’ll also be moving away from the more elementary circuit diagrams to the more advanced circuit schematic diagrams.
Part 1: Soldering
First we need to prepare the pot so that can easily connect it to our circuit. We do this by soldering wires to it.
1) Take 1 red, 1 black, 1 yellow wires, and 1 pot (One pot is in your kit).
Part 2: Controlling one LED from the one Pot
1) Extend your 3 LED circuit so that it includes a pot. Follow the circuit diagrammed below
You an see that the red wire goes to power, the black wire goes to ground, and the yellow wire goes to Pin A0 on the Arduino.
2) Use the potentiometer to control the blinking rate of the LEDs. On the Arduino website, there is some sample code which takes the pot value as input and uses it to control the blinking speed of an LED. You can also find the Arduino sketch here. https://www.arduino.cc/en/Tutorial/AnalogInput . You can ignore the stuff about photoresistors and just look at the stuff involving potentiometers and LEDs. MAKE SURE YOU DOUBLE CHECK THE PIN NUMBERS. Your should make sure that your pot is plugged in to pin A0 (A-Zero) so that it matches the pin in the arduino sketch. This is determined by this line in the arduino sketch:
in sensorPin = A0; // select the input pin for the potentiometer
Also, the arduino sketch linked to above controls an LED plugged into pin 13, but your LED is probably plugged in to a different pin. If your LEDs are plugged into different pins, change the line
int ledPin = 13; // select the pin for the LED
in the Arduino sketch to match the pin you are using. This sketch only makes one LED blink; see if you can modify the code to make all your LEDs blink. You can try adding other LEDs by adding lines of code like so:
int redledPin = 9; int blueledPin = 10; int greenledPin = 11;
3) At this tutorial, there is some sample code which takes the pot value as input and uses it to control the brightness level of an LED. http://owenmundy.com/blog/2010/05/fading-an-led-with-pwm-and-a-potentiometer/ . Again, make sure that you are using the right pins for your potentiometer and LED. This is good practice for when you find arduino sketches online and you have to modify it for what you want.
Part 3: Multiple Pots controlling multiple LEDs
1) There are two options for this part.