Min menu

Pages

project 13 :LIGHT DIMMER

LIGHT DIMMER

IN THIS PROJECT, YOU’LL CREATE A DIMMER SWITCH BY ADDING A POTENTIOMETER TO CONTROL THE BRIGHTNESS OF AN LED.

PARTS REQUIRED
• Arduino board
• Breadboard
• Jumper wires
• LED
• 50k-ohm potentiometer
• 470-ohm resistor

The Sketch This sketch works by setting pin A0 as your potentiometer and pin 9 as an OUTPUT to power the LED. You then run a loop that continually reads the value from the potentiometer and sends that value as voltage to the LED. The voltage value is between 0–5 volts, and the brightness of the LED will vary accordingly. /* http://arduino.cc/en/Reference/AnalogWrite by Tom Igoe from http:itp.nyu.edu/physcomp/Labs/AnalogIn */ 


int potPin = A0; // Analog input pin connected to the potentiometer int potValue = 0; // Value that will be read from the potentiometer int led = 9; // Pin 9 (connected to the LED) is capable of PWM // Runs once at beginning of the program void setup() { pinMode(led, OUTPUT); // Set pin 9 to output } // Loops continuously void loop() { potValue = analogRead(potPin); // Read potentiometer value // from A0 pin analogWrite(led, potValue/4); // Send potentiometer value to LED // to control brightness with PWM delay(10); // Wait for 10 ms }
reaction: