In this project my relays will open as per the input voltage. In place of relay i am using leds. This is code for any input, led connected to pin 38 is high. All other leds are not getting on with increase in voltage. My connection to leds is correct because i have used http://www.arduino.cc/en/Tutorial/KnightRiderknight rider code to check connection
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the
int pinArray[] = {38, 39, 40, 41};
int count = 0;
void setup(){
// we make all the declarations at once
for (count=0;count<4;count++) {
pinMode(pinArray[count], OUTPUT);
digitalWrite(pinArray[count], LOW);
}
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 125);
// change the analog out value:
if(sensorValue = 1)
{ digitalWrite(38, HIGH);
digitalWrite(39, LOW);
digitalWrite(40, LOW);
digitalWrite(41, LOW);
}
else if(sensorValue = 2)
{
digitalWrite(38, HIGH);
digitalWrite(39, HIGH);
digitalWrite(40, LOW);
digitalWrite(41, LOW);
}
else if(sensorValue = 3)
{ digitalWrite(38, HIGH);
digitalWrite(39, HIGH);
digitalWrite(40, HIGH);
digitalWrite(41, LOW);
}
else if(sensorValue = 4)
{ digitalWrite(38, HIGH);
digitalWrite(39, HIGH);
digitalWrite(40, HIGH);
digitalWrite(41, HIGH);
}
delay(2);
}