CONTROLLING SPEED OF LED USING POTENTIOMETER
In this tutorial we will teach you how to control speed of led with Arduino UNO / Nano
COMPONENT Used :
SR NO | COMPONENT NAME | QUANTITY |
1 | Arduino Board(Uno or Nano) | 1 |
2 | Bread Board | 1 |
3 | LED’S | 8 |
4 | Resistor(220ohm)- | 8 |
5 | Jumper Wire(Male to Male) | 1 set |
6 | Potentiometer | 1 |
Schematic Diagram :
Source Code :
#define MAXLED 8
#define pot1 A0
#define pot2 A1
int led[MAXLED] = {2,3,4,5,6,7,8,9};
void setup()
{
for (int i=0; i<MAXLED; i++)
{
pinMode(led[i], OUTPUT);
}
pinMode(pot1, INPUT);
pinMode(pot1, INPUT);
}
void loop()
{
for (int i=0; i<=MAXLED; i++)
{
int on = analogRead(pot1);
int t1=map(on, 0, 1023, 0, 1000);
int off = analogRead(pot2);
int t2=map(off, 0, 1023, 0, 1000);
prender(led[i],t1);
apagar(led[i],t2);
}
for (int i=6; i>0; i–)
{
int on = analogRead(pot1);
int t1=map(on, 0, 1023, 0, 1000);
int off = analogRead(pot2);
int t2=map(off, 0, 1023, 0, 1000);
prender(led[i],t1);
apagar(led[i],t2);
}
}
void prender(int i, int t)
{
digitalWrite(i, HIGH);
delay(t);
}
void apagar(int i, int t)
{
digitalWrite(i, LOW);
delay(t);
}
Video :
Maverick den wants to build the bridge between the learning and doing.
We aspire to provide a R&D environment to kindle the innovation within them.