Cant control LEDs individually

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:

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 {
  if (analogValue > threshold1) {
    digitalWrite(ledPin1, HIGH);
  else {
    if (analogValue > threshold2) {
    digitalWrite(ledPin2, HIGH);
  else {
    digitalWrite(ledPin2 ,LOW); 
  // print the analog value:
  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).



What does your serial output look like? Add a Serial.print() statement in setup() to confirm that you are not causing a reset. That some of the time the pins become dimmer is a suggestion of a wiring issue.

You may not be able to create a schematic, but you can take a picture, can't you?

Pretty sure it's not the coding. I loaded it, and it works perfectly. Your wires are probably connected so the lights power supply are shared with each other

Here are some pic,hope it helps =)

here’s another one

yay!! i solved the problem, turns out i connected in a very bad manner,fortunately nthn bad happend =)

turns out i connected in a very bad manner

Yes you shorted all three outputs together. This is for others looking at this post.

While it might seem like you did not do any damage, you did, and the Arduino is likely to have a shorter life than it should have.