This lab worked off the original 3 LED circuit built in the previous lab, and introduced the concept of potentiometers to allow physical manipulation of the behavior of the circuit. Potentiometers are an Analog electrical component meaning they have values on a continuous scale. Potentiometers are variable value resistors that can change their resistance based on the physical arrangement of their components. Typically this is done by a wiper which changes the amount of resistive material the current has to flow through. Longer distances correlate to higher resistances.
From the perspective of the Arduino Uno microcontroller, this change in resistance can create a voltage drop from the 5V input. This change in voltage is converted into a digital number which is created by the analogRead() command. The Arduino Uno has 6 Analog in pins which are able to do this, allowing for up to 6 independent analog inputs (ex: 6 trim pots) to provide inputs to the code being run on the microcontroller. The analog system in the Arduino has a resolution of 210 bits, meaning that over a total voltage drop 1024 unique values can be created. Analog is unique to the serial input used in the last lab because the analog inputs are effect real time change whereas the serial needed to be “entered” and were not read until specifically sent to the Arduino.
This lab also introduced the technique of soldering. Soldering used a very hot heating element (iron) and solder, a fusible metal alloy, to join to metal components together with a strong physical and electrical connection. To use the potentiometers provided three wires were stripped and soldered to the three pins of the potentiometer (high voltage, signal wire, and ground).
Homework:
I extended the original circuit to include three potentiometers. The 5V and ground pins of all three are connected in parallel with the signal wire connected to the analog input pins. Using the provided code “2a_Control3LEDsWith3Pots.txt” each LED’s brightness was able to be controlled by adjusting a unique potentiometer.
For the optional assignment I decided to have three potentiometers. The first (input 0) controls the brightness of all 3 LEDs. The second (input 1) controls how fast the each LED is on before moving onto the next LED in a blue, green, cycle. The last potentiometer (input 2) controlled the delay between each cycle.
Using the analogRead() command, all three values from the potentiometers are converted to discrete values. The first value is divided by 4 to allow it a max value of 256 because it will be used for the brightness in the analogWrite() command. The second value was read in and multiplied by an extender value (declared as a variable before the void setup()) to make the for loops long enough to provide visual difference between the max and min states of the potentiometer. The last value was used in the delay() function to provide a pause between each cycle of the loop.
Components
1- Arduino Uno Microcontroller
1- Breadboard
3- 220ΩResistors
3- Light Emitting Diodes (LEDs) (Red, Green, Blue)
1- USB Cable
1- Computer (Windows)
1- Soldering Iron
Solder
1- Wire Cutter/Stripper
3- Potentiometers
Wires
Code
/*
Kevin Lessard
TUI Lab 3 Potentiometers
9/26
*/
int potpin1 = 0; //input pin for pot 1
int potpin2 = 1; //input pin for pot 2
int potpin3 = 2; //input pin for pot 3
int ledpin1 = 9; //pins for the LEDs
int ledpin2 = 10;
int ledpin3 = 11;
int potval1 = 0; //variable to store the analog pot values
int potval2 = 0;
int potval3 = 0;
int bright = 0; //variable for brightness
int relayspd = 0; //the speed of the relay (inverse relationship)
int i = 0; //for loop counter
int extender = 5; //arbitrary multiplier to extend the value of the pot 1 (see relayspd
void setup() {
pinMode(ledpin1, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(ledpin2, OUTPUT); // declare the led2Pin as an OUTPUT
pinMode(ledpin3, OUTPUT); // declare the led3Pin as an OUTPUT
}
void loop() {
potval1 = analogRead(potpin1); //read values from each pot
potval2 = analogRead(potpin2);
potval3 = analogRead(potpin3);
bright = potval1/4; //max value of 256
if(bright == 256){
bright = bright-1;
}
relayspd = potval2*extender; //the number of iterations each loop will go for
for(i=0; i<relayspd; i++){ //green on, blue and red off
analogWrite(ledpin1, bright);
analogWrite(ledpin2, 0);
analogWrite(ledpin3, 0);
}
for(i=0; i<relayspd; i++){ //blue on, red and green off
analogWrite(ledpin1, 0);
analogWrite(ledpin2, bright);
analogWrite(ledpin3, 0);
}
for(i=0; i<relayspd; i++){ //red on, blue and green off
analogWrite(ledpin1, 0);
analogWrite(ledpin2, 0);
analogWrite(ledpin3, bright);
}
for(i=0; i<relayspd; i++){ //all off
analogWrite(ledpin1, 0);
analogWrite(ledpin2, 0);
analogWrite(ledpin3, 0);
}
delay(potval3); //delay between loops
}
- Login to post comments