LED Lights/Function Issue

Hi,

I'm wondering if someone can make sense of some code and schematics regarding 2 LED lights in a circuit. I didn't create this code so I'm only trying to follow it.

The module i'm working on has 2 LEDs. One LED to represent power and the other LED to represent the system is ready. In the schematics its shows LED1 connected to 3.3v and the LED2 to D3. However, in the code it shows PinMode 2 & 3 as Output but only pin 3 as high. So correct me if i'm wrong, according to the schematics both LEDs would turn on? If so, would it be correct to put leds be on pin 2 and 3.

Also, assuming both LEDS turn on, would they just be doing the same function? As one of them is meant to indicate the system is ready.

Section of code for the LED

 pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);

  delay(500);

  digitalWrite(3, HIGH);

Full Code

SoftwareSerial mySerial(4, 5);
RF24 radio(7, 8);

DFRobot_TFmini TFmini;
uint16_t distance;
const byte addr[6] = "00001";

void setup(){
  Serial.begin(115200);
  
  TFmini.begin(mySerial);
  
  radio.begin();
  radio.openWritingPipe(addr);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
  
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);

  delay(500);

  digitalWrite(3, HIGH);
}

void loop(){
  if(TFmini.measure()){
    distance = TFmini.getDistance();

    if(distance < 20000 && distance > 0) {
      Serial.println(distance);
      radio.write(&distance, sizeof(distance));
    }
  }
}

pinMode(2, OUTPUT); // this is not needed

You could put a LED/resistor on pin 2 if you needed too.

It actually would be better to toggle the LED on pin 3 every so often from within loop ().
This would be similar to a heartbeat.

While I see D2 is defined as an output, there is nothing in the code controlling it and nothing on the schematic connected to it. I would expect to see one LED being on all the time, and the other also coming on a half-second later.

Ok, thanks for clearing this up for me

Ok, so according to the schematic, having one led on the 3.3v and one on the D3 pin that would be correct?

One LED is just connected to the 3.3v power circuit... if there is power it will turn on.

The other LED is connected to Digital Pin 3... this one is controlled from within the program.

Yes. D2 is essentially unused, and the statement allocating it as an output pin could be deleted (as suggested). Unless there are other parts of the code as yet unrevealed. :slight_smile:

Thanks, I removed the code for D2.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.