Lesson 6: Potentionmeter & LED

This lesson is about a Controlled LED brightness using PotentiometerIn 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/


Hardware parts for this lesson:

  • Arduino board
  • Breadboard
  • LED
  • 220 Ohm resistor
  • Jumpers (wires)
  • Potentiometer
Scheme on breadboard:



Program code for this project:

#define led 9
#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.

Comments

Post a Comment

Popular posts from this blog

Lesson 10: Piezo Buzzer controlled with Potentiometer

Lesson 9: Piezo Buzzer

Lesson 3: Working with Buttons