How do you plan to solve it?
Read the potentiometer on A0 with default reference:
A0 Potentiometer reading 0..1023 maps to 0 ..100% .
Control brightness by pwm : duty cycle 0 .. 255 maps to brightness 0 to 100%
Potentiometer reading=x
I did this in EXCEL sheet:
Percentage-wise:
potentiometer | LED0 | LED1 | LED2 | LED3 | LED4 | |
slope, a | 1 | 0.5 | 0 | -0.5 | -1 | |
intercept, b | 0 | 25 | 50 | 75 | 100 | |
potentiometer, x | percentage, x | y=ax+b | y=ax+b | y=ax+b | y=ax+b | y=ax+b |
0 | 0 | 25 | 50 | 75 | 100 | |
25 | 25 | 37.5 | 50 | 62.5 | 75 | |
50 | 50 | 50 | 50 | 50 | 50 | |
75 | 75 | 62.5 | 50 | 37.5 | 25 | |
100 | 100 | 75 | 50 | 25 | 0 |
using raw measurements, potentometer range 0 to 1023.
Controlling brightness by pwm:
0 % maps to 0 on the pwm pin
25% maps to 63 analogWrite on th epwm pin
50 % map sto 127
75% maps to 191
100% maps to 255
potentiometer, x | raw, x | LED0 | LED1 | LED2 | LED3 | LED4 |
0 | 0 | 63 | 127 | 191 | 255 | |
256 | 63 | 95 | 127 | 159 | 191 | |
512 | 127 | 127 | 127 | 127 | 127 | |
768 | 191 | 159 | 127 | 95 | 63 | |
1023 | 255 | 191 | 127 | 63 | 0 |
using 330Ohm resistors and 10K pot.
/*Paste your code here*/
int potPin = 0;
int pwmPin[5] = {10, 9, 6, 5, 3};
int pot;
int poti;
void setup()
{
int i;
poti=1023;
for (i=0; i < 5; i++) {
pinMode(pwmPin[i], OUTPUT);
}
Serial.begin(9600);
}
void loop()
{
int brightness[5];
int i;
pot = analogRead(potPin);
// print only if potentiometer is moved
if (pot != poti) {
Serial.print("Potentiometer: ");
Serial.println(pot);
brightness[0] = map(pot, 0, 1023, 0, 255) ;
brightness[1] = map(pot, 0, 1023, 63, 191) ;
brightness[2] = 127;
brightness[3] = map(pot, 0, 1023, 191, 63) ;
brightness[4] = map(pot, 0, 1023, 255, 0) ;
for (i=0; i < 5; i++) {
analogWrite(pwmPin[i], brightness[i]);
Serial.print(brightness[i]);
Serial.print(" ");
}
Serial.println("");
poti=pot;
}
delay(100);
}
Add video of output (know more)
Add a photo of your hardware showing the output.