Lesson 6: Potentionmeter & LED
This lesson is about a Controlled LED brightness using Potentiometer. In our model, the brightness of the LED will depend on the rotation of the potentiometer knob. This is also one of the basic schemes.Link to original lesson: http://edurobots.ru/2014/04/arduino-potenciometr/
- Arduino board
- Breadboard
- LED
- 220 Ohm resistor
- Jumpers (wires)
- Potentiometer
Scheme on breadboard:
Program code for this project:
#define pot A0
void setup(){
pinMode(led, OUTPUT);
pinMode(pot, INPUT);
Serial.begin(9600);
}
void loop(){
int x;
// read value of Potentiometer
// as you remember A0-A5 pins working in range of 0-1023
// but analog INPUT/OUTPUT pins range is 0-255
// to get correct result we will divide result to 4
x = analogRead(pot) / 4;
Serial.print("X=");
Serial.println(x);
// show result on LED
analogWrite(led, x);
}
Task for Advanced students: Give 2 more LEDs and resistors. Task is to connect 3 LEDs in total, and control brightness. When 1st LED at full brightness, next LED must turn on, and so on.
kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - kayseri escort - gaziantep escort
ReplyDelete