DESCRIPTION:
In this laboratory exercise we explored using analog inputs from potentiometers (pots) to change the blink speed and brightness of the LEDs. Pots provide variable resistance depending on the position of the rotating element, and in this exercise the pot adjusted the voltage input from 0V-5V. We used the Arduino Uno to read the pot values andcontrol the LEDs.
Another objective of the lab was to learn how to solder. We soldered a black (ground), yellow (analog), and red (5V) wires to our pot. After soldering the wires we connected them to the corresponding ports on the Arduino.
We used the provided sketches to control the blinking rate or the intensity level of an LED. For the homework assignment, I merged both examples and modified the code slightly in order to have 2 pots controlling the LEDs:
- Pot connected to analog pin 2 controled blinking
- Pot connected to analog pin 3 controled LED brightness
COMPONENTS:
1- Arduino Uno Microcontroller
1- Breadboard
3- 220Ω Resistors
3- Light Emitting Diodes (LEDs) (Red, Green, Blue)
1- USB Cable
1- Apple Laptop Computer (Mac OSX)
1- Soldering Iron
1- Solder
1- Wire Cutter/Stripper
2- Potentiometers
CODE:
/*
* a) Makes 3 LEDs blink at a certain rate depending on position of potPinBlink (connected to analog pin 2).
* b) Dims the light intensity of 3 LEDs depending on position of potPinDim (connected to analog pin 3)
* Sofia Solar Cafaggi
*/
int potPinBlink = 2; // select the input pin for the potentiometer
int potPinDim = 3; // select the input pin for the potentiometer
int ledPinB = 9; // select the pin for the blue LED
int ledPinG = 10; // select the pin for the green LED
int ledPinR = 11; // select the pin for the red LED
int valblink = 0; // variable to store the value coming from the sensor
int valdim = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPinB, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(ledPinG, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(ledPinR, OUTPUT); // declare the ledPin as an OUTPUT
Serial.begin(9600);
}
void loop() {
valblink = analogRead(potPinBlink); // read the value from the sensor
valdim = analogRead(potPinDim); // read the value from the sensor, between 0 - 1024
//Serial.println(val2);
analogWrite(ledPinB, valdim/4); // analogWrite can be between 0-255
analogWrite(ledPinG, valdim/4);
analogWrite(ledPinR, valdim/4);
delay(valblink); // stop the program for some time
digitalWrite(ledPinB, LOW); // turn the blue ledPin off
digitalWrite(ledPinG, LOW); // turn the green ledPin off
digitalWrite(ledPinR, LOW); // turn the red ledPin off
delay(valblink); // stop the program for some time
}
- Login to post comments