Hey!!
I connected a potentiometer to my arduino uno board (Analog 0),and Wrote a sketch following a template (shown below),the purpose of what i am doing is to make 3 different LEDs light independently according to the reading from the potentiometer. But for some reason all the LEDs light up together and switch off together(sometimes they just become dimmer).Help anyone?
// These constants won't change:
const int analogPin = A0; // pin that the sensor is attached to
const int ledPin = 13;// pin that the LED is attached to
const int ledPin1 = 12;
const int ledPin2 = 11;
const int threshold = 1000; // an arbitrary threshold level that's in the range of the analog input
const int threshold1 = 500;
const int threshold2 = 250;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);
// if the analog value is high enough, turn on the LED:
if (analogValue > threshold) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin,LOW);
};
if (analogValue > threshold1) {
digitalWrite(ledPin1, HIGH);
}
else {
digitalWrite(ledPin1,LOW);
};
if (analogValue > threshold2) {
digitalWrite(ledPin2, HIGH);
}
else {
digitalWrite(ledPin2 ,LOW);
};
// print the analog value:
Serial.println(analogValue);
delay(1); // delay in between reads for stability
}
BTW sorry i couldnt make a schematic of the connections,but anyways Pin13,12,11 are used to connect the LEDs (yes,i used resistors) and i connected all 3 pins back to the same GND port/pin (the one next to pin 13).