3

I'm making a low energy consumption device so I'd like to turn off all the led when I'm idle.

Unfortunately the nodemcu turn on a blue led while I'm idle (during delay(ms))

Here is my code:

#define LED    16

void setup() {
  initialSetup();
  //Turn off the built-in led
  digitalWrite(LED, HIGH);
}

void loop() {
  //Here I do everything
  doStuff();
  //GO TO SLEEP
  delay(3600000);
}

The led that turn on during delay is the one near to D0 pin.

The led that I can control and so turn off (pin #16 -> D0) is near the 5v pin.

It's possible to completely turn off all led to consume less?

enter image description here

2

See this link which shows your second LED exactly (the image is for v1.0, I have v0.9 and the code below works just the same in this situation):

'Onboard LEDs? NodeMCU's got two!':

https://lowvoltage.github.io/2017/07/09/Onboard-LEDs-NodeMCU-Got-Two

Quote:

ESP-12 LED Blink:

 void setup() {
        pinMode(2, OUTPUT);     //Initialize GPIO2 pin as an output
 }

 void loop() {
   digitalWrite(2, LOW);   // Turn the LED on by making the voltage LOW   
   delay(1000);            // Wait for a second
   digitalWrite(2, HIGH);  // Turn the LED off by making the voltage HIGH 
   delay(2000);            // Wait for two seconds
 }

Or write it like this (ie. using 'D4' rather than '2'):

ESP-12 LED Blink:

 void setup() {
        pinMode(**D4**, OUTPUT);     //Initialize GPIO2 pin as an output
 }

 void loop() {
   digitalWrite(**D4**, LOW);   // Turn the LED on by making the voltage LOW   
   delay(1000);            // Wait for a second
   digitalWrite(**D4**, HIGH);  // Turn the LED off by making the voltage HIGH 
   delay(2000);            // Wait for two seconds
 }

Regards, Geoff

  • Thank you, I've already read that link and it talks about nodemcu 1.0, mine is nodemcu 0.9 and pin #2 correspond to port D4 and does NOT turn off any led – Timmy Mar 18 '18 at 18:07
  • I have a NodeMCU v0.9 and have just tested it. Referring to the pin as '2' or 'D4' both cause the LED you describe to flash... – Geoff Mar 18 '18 at 18:42
  • Oh sorry, you are right! I used that port also for another sensor so it remains always on. Now I wired the sensor to port D5 and I've no problem! Thank you, you have the best answer! – Timmy Mar 18 '18 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.