0

Hello this is my code in Tinkercad. I created schema for Bargraph with LED. Two LED (Yellow and Orange) not work correctly.

My code is below:

int sensorValue = 0;
int outputValue = 0;
void setup()
{
    pinMode(A0, INPUT); 
    
    
    pinMode(1, OUTPUT);
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
}

void loop()
{
  
  sensorValue = analogRead(A0);
  
  outputValue = map(sensorValue, 0, 1023, 0, 100);
  
  if (outputValue > 11) {     
    digitalWrite(3, HIGH); 
  } else {
    digitalWrite(3, LOW); 
  }
    if (outputValue > 51) {     
    digitalWrite(2, HIGH);
  } else {
    digitalWrite(2, LOW); 
  }
    if (outputValue > 91) {     
    digitalWrite(1, HIGH); 
  } else {
    digitalWrite(1, LOW); 
  }
  
  delay(2);
}

This is my schema which I created. This is my schema which I created

kaluaaa
  • 47
  • 5
  • It is a hardware issue rather than a software issue and therefore belongs on https://electronics.stackexchange.com/, however you have simply omitted to connect the cathodes of two of the LEDs to GND - only the red cathode is connected. – Clifford Jan 09 '21 at 11:23
  • Note that Arduino sketches are compiled as C++, so strictly the C tag is incorrect. But that is a pedantic point in this case. Also almost all Arduino examples positively reinforce bad practice; declare `sensorValue` and `outputValue` `static` in `loop()` rather then making them unnecessarily global - https://www.embedded.com/a-pox-on-globals/ – Clifford Jan 09 '21 at 11:38

1 Answers1

0

Not really an SO question since the issue is not with the code, but that is not perhaps for you to know so:

enter image description here

to connect the cathodes to GND.

Clifford
  • 88,407
  • 13
  • 85
  • 165