Search code examples
carduinoioadctinkercad

How to create IO Bargraph in Arduino?


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


Solution

  • 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.