Adjust the brightness of an LED with the potentiometer threshold.
Equipment:
•1 x Arduino Uno
•1 x Breadboard
•6 x Wire
•1 x Potentiometer 10k Ohm
•1 x 560 Ohm Resistor
•1 x LED
Reference:
http://www.oomlout.com/a/products/ardx/circ-08
Program Details:
No new concepts in the code for this lab.
Time to Complete:
15 minutes
Results:
No problems with this lab, the brightness of the LED increases when the potentiometer is turned clockwise.
Photos of Project:
Tips:
Make sure the potentiometer is in the right way. If nothing is happening, flip it 180 degrees.
Further Work:
Make the LED to turn off after a certain degree on the potentiometer.
Program Modifications:
The program is exactly the one from http://www.oomlout.com/a/products/ardx/circ-08
Program:
int sensorPin = 0; // the pin the sensor is connected to
int ledPin = 13; // the pin the LED is connected to
int sensorValue = 0; // a variable to hold the state of the sensor
int ledPin = 13; // the pin the LED is connected to
int sensorValue = 0; // a variable to hold the state of the sensor
void setup()
{
pinMode(ledPin, OUTPUT); //initialize pin 13 as an output
}
pinMode(ledPin, OUTPUT); //initialize pin 13 as an output
}
void loop()
{
//reads the value from the sensor and sets it to sensorValue
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH); //sets the state of ledPin to high(on)
delay(sensorValue); //delay equal to the value of sensorValue
digitalWrite(ledPin, LOW); //sets the state of ledPin to low(off)
delay(sensorValue); //delay equal to the value of sensorValue
}
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH); //sets the state of ledPin to high(on)
delay(sensorValue); //delay equal to the value of sensorValue
digitalWrite(ledPin, LOW); //sets the state of ledPin to low(off)
delay(sensorValue); //delay equal to the value of sensorValue
}
No comments:
Post a Comment