int potPin = A0;
int ledPin = 9;
int brightness = 0;
int dt = 500;
void setup(){
Serial.begin(9600);
pinMode(potPin , INPUT);
pinMode(ledPin , OUTPUT);
}
void loop(){
int potValue = analogRead(potPin);
// COnversion of analog value which is between 0 to 1023 into analog voltage
float voltage = (potValue * 5.0) / 1023.0;
brightness = map(potValue , 0 , 1023 , 0 , 255);
analogWrite(ledPin , brightness);
Serial.print("Potentiometer value = ");
Serial.print(potValue );
Serial.print(" ; ");
Serial.print("Analog Voltage Reading = ");
Serial.print(voltage);
Serial.print("V");
Serial.print(" ; ");
Serial.print(" Brightness = ");
Serial.println(brightness);
delay(dt);
}
//potentiometer is a displacement sensor
//X axis - potValue(0 to 1023) and Y axis - brightness(0 to 255)
//brightness = (255/1023) * potValue
//map(input , range)