Controlling Light & Fan Using Arduino Mega 2560

Introduction
  • In this article I will explain how to control Light/Fan using Arduino Mega 2560. Light and fan will be controlled by the potentiometer.
  • We can adjust the potentiometer and light and fan will be controlled by us.
Parts Of List
  • Arduino Mega 2560
  • Potentiometer
  • LED
  • Bread board
  • Hookup wires
Potentiometer:
  • It has three terminals.
  • It has a sliding or rotating contact that forms a adjustable voltage divider.
  • It act as a variable resistor (or) rheostat.


    Figure 1: potentiometer 
Connection:

Step 1: Potentiometer to ArduinoMega2560

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 LED To Arduino Mega 2560

Postive pin    =     06
Negative pin =     Gnd
 
Programming
  1. const byte POTENTIOMETER = 0;  
  2. const byte CONTROL = 6;  
  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:
  • Through this we can control Light /fan using potentiometer.
  • If we adjust the potentiometer on the decreasing side the light brightness decreases.
  • Also the fan speed also decreases.
  • If we adjust the potentiometer on the increasing side the light brightness increases.
  • Also the fan speed increased. 
Output:


                                Figure 2: Output
 
Read more articles on Arduino:

Up Next
    Ebook Download
    View all
    Learn
    View all