Lab 3: Potentiometers
Description
The objective of the lab was to control the blinking and fading of 3 LED's with 2 potentiometers. Unfortunately I ran out of time and could only solder one potentiometer, so I've made 3 LEDs blink with only one potentiometer.
Components Used
1- Arduino Uno
1- Breadboard
3- LED (R,G,B)
3- 220Ω Resistor
1- cutton
1-diffuser
1- rubberband
1- potentiometer
several cables
Code
/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on
the value obtained by analogRead().
The circuit:
* Potentiometer attached to analog input 0
* center pin of the potentiometer to the analog pin
* one side pin (either one) to ground
* the other side pin to +5V
* LED anode (long leg) attached to digital output 13
* LED cathode (short leg) attached to ground
* Note: because most Arduinos have a built-in LED attached
to pin 13 on the board, the LED is optional.
Created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/AnalogInput
*/
int sensorPin = A0; // select the input pin for the potentiometer
int ledRed = 9;
int ledBlue = 10;
int ledGreen = 11;// select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
pinMode(ledRed, OUTPUT);
pinMode(ledBlue, OUTPUT);
pinMode(ledGreen, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledRed, HIGH);
digitalWrite(ledBlue, HIGH);
digitalWrite (ledGreen, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledRed, LOW);
digitalWrite(ledBlue, LOW);
digitalWrite(ledGreen, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
sensorValue = analogRead(sensorPin);
}
- Login to post comments
Drupal theme by Kiwi Themes.