// Understanding Arduino if statements
// Control Led Using Potentiometer
int mypin = A3;
int readVal;
float V2;
int dt = 250;
int redPin = 9;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(mypin, INPUT);
pinMode(redPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
readVal = analogRead(mypin);
V2 = (5. / 1023.) * readVal;
Serial.print("Potentiometer voltage is ");
Serial.println(V2);
// if(V2==5.0)
if (V2 > 2 && V2 < 3)
{
digitalWrite(redPin, HIGH);
}
// if(V2!=5.0)
if (V2 < 2 || V2 > 3)
{
digitalWrite(redPin, LOW);
}
delay(dt);
// Make this using three leds green , blue , yellow and make them on and off at differnet voltages
}