Controlling LED Using Arduino Mega 2560

Introduction

 
In this article, I have explained about controlling LED using Arduino Mega 2560. Also, controlling the brightness of LED using Arduino Mega 2560 will be described.
 
Parts
  • Arduino Mega 2560
  • Potentiometer
  • BreadBoard
  • LED
Connection
 
Step 1:
Connection from Potentiometer to Arduino Mega 2560:
  • The first pin of the potentiometer can be connected to the Gnd of the Arduino Mega 2560.
  • The second pin of the potentiometer can be connected to the Analog pin A0 of the Arduino Mega 2560.
  • The third pin of the potentiometer can be connected to the 5V of the Arduino Mega 2560.
Step 2: Connection From Potentiometer To Arduino Mega 2560:
  • Positive pin = 09
  • Negative pin = Gnd
Programming
  1. const byte POTENTIOMETER = 0;  
  2. const byte CONTROL = 9;  
  3. int reading;  
  4. int value;  
  5. void setup()  
  6. {  
  7.     pinMode(CONTROL, OUTPUT);  
  8. }  
  9. void loop()  
  10. {  
  11.     reading = analogRead(POTENTIOMETER);  
  12.     value = map(reading, 0, 1024, 0, 255);  
  13.     analogWrite(CONTROL, value);  
  14. }  
Explanation
  • When the potentiometer is adjusted the LED can be low to high
  • In the potentiometer we can see the brightness of the LED.
Output
 
 
Figure 1: Output
 
Read more articles on Arduino: