int rV; //value from potentiometer (0 - 1023)
float V; //actual value in volts
int lV; //value to led (0 - 255)
int led=3; //setting LED out as digital pin 3
int pot=A0; //setting potentiometer input as A0
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT); //estabishing digital pin 3 as PWM output
pinMode(pot, INPUT); //establishing A0 as analog input
Serial.begin(9600); //serial comm. established with baud rate 9600
}
void loop() {
// put your main code here, to run repeatedly:
rV=analogRead(pot); //reading from A0 (value b/w 0 - 1023)
V=(5.0/1023.0)*rV; //converting the value received in A0 to volatge b/w 0 -5V
lV=(255.0/1023.0)*rV; //converting the value in rV to PWM range of 0-255 to be used in D3
analogWrite(led,lV); //sending the value to D3 to switch ON the LED
Serial.print("Potentiometer voltage = ");
Serial.println(V); //dispalys the actual voltage (0-5V)
Serial.print("Pot value = ");
Serial.println(rV); //dispalys the A0 value (o-1023)
Serial.print("LED value = ");
Serial.println(lV); //dispalys the D3 PWM value (0-255)
delay(1000); // provides a delay of 1s (1000ms) to the next cycle
}