I have a simple NODEMCU I want to setup at a remote location and be powered by batteries. I have it working 100% and deep sleeping just fine when it is connected to my laptop USB port, I am using an inline USB current monitor (FNB48S) and in deep sleep it's about 500uA, when I power it from a USB block it idles at 8mA and never goes below. I have tried various USB power sources and batteries powering Vin, it only sleeps when connected to my laptop. I'm stumped. I am not using any serial print functions in the code, although I have a suspicion it might be related to the CP2102, but don't know why the differences in power source would make a difference.
Anyone else run into this and have a solution?
Thank you
Paul
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
float distance;
float duration;
float input_volt;
float temp;
float r1=42400; //r1 value
float r2=18000; //r2 value
SoftwareSerial HC12(D1, D2); // HC-12 TX Pin, HC-12 RX Pin
void setup() {
//Serial.begin(9600); // Serial port to computer
HC12.begin(1200); // Serial port to HC12 ****THIS HAS TO BE THE SAME AS "AT+BXXXX"
pinMode(D5, OUTPUT); // Set pin HC12
pinMode(D6, OUTPUT); // Power ENABLE 2N3906 base pin JSN-SRO4
pinMode(D7, OUTPUT); // Trigger pin JSN-SRO4
pinMode(D8, INPUT); // Echo pin JSN-SRO4
digitalWrite(D6, LOW); // Keep JSN-SR04 off until needed
}
void hc_12_sleep() {
delay(150);
digitalWrite(D5, LOW);
delay(150);
HC12.println("AT+SLEEP");
delay(150);
digitalWrite(D5, HIGH);
}
void hc_12_wakeup() {
digitalWrite(D5, LOW);
delay(150);
digitalWrite(D5 , HIGH);
delay(150);
}
void hc12_loop() {
hc_12_wakeup();
temp = (analogRead(A0) * 3.3) / 1024.0; // FORMULA USED TO CONVERT THE VOLTAGE
input_volt = temp / (r2/(r1+r2));
if (distance < 100) HC12.print('0');
if (distance < 10) HC12.print('0');
//Serial.print("Tank Level ");
// Serial.println(distance);
// Serial.print("Voltage ");
// Serial.println(input_volt);
HC12.print(distance);
HC12.print(",");
HC12.print(input_volt);
HC12.println("");
}
void getSensordata(){
digitalWrite(D6, HIGH);
delay(100);
digitalWrite(D7, LOW);
delayMicroseconds(10);
digitalWrite(D7, HIGH);
delayMicroseconds(1100);
digitalWrite(D7, LOW);
duration = pulseIn(D8, HIGH);
distance = duration * .034 / 2;
digitalWrite(D6, LOW);
}
void loop() {
getSensordata();
hc12_loop();
hc_12_sleep();
ESP.deepSleep(58.7e6, WAKE_RF_DISABLED);
delay(100);
}
NodeMCU won't sleep when externally powered, works fine on USB laptop power
-
- Posts: 200
- Joined: Sun Jun 23, 2024 6:18 pm
Re: NodeMCU won't sleep when externally powered, works fine on USB laptop power
Monitor the voltage at the Vin pin when the device attempts to enter deep sleep. A significant drop may indicate that the power source isn't providing sufficient current.
Re: NodeMCU won't sleep when externally powered, works fine on USB laptop power
Thank you for the help. That actually was a problem about a month ago in early development but I sorted that out.
This morning I found the problem/answer...the board I am using has a CP2102 UART and my laptop was setup to allow the COM port to sleep which it did when the MCU went to sleep, thus giving the illusion it was sleeping, which it really was but was actually drawing more current than I thought it would, 8mA from an external USB power block, the port shutting down fooled me.
So long story shortened, I removed the AMS1117 regulator and feed the 3v3 pins with an external regulator which has 18uA quiescent current. The entire module now sleeps at 200uA, way better than the 8mA previously with the stock setup. The other version of NODEMCU which uses the CH340 won't allow my computer port to sleep but it has only 2mA draw when sleeping. Replacing the AMS1117 should help reduce that as well.
Thanks again.
This morning I found the problem/answer...the board I am using has a CP2102 UART and my laptop was setup to allow the COM port to sleep which it did when the MCU went to sleep, thus giving the illusion it was sleeping, which it really was but was actually drawing more current than I thought it would, 8mA from an external USB power block, the port shutting down fooled me.
So long story shortened, I removed the AMS1117 regulator and feed the 3v3 pins with an external regulator which has 18uA quiescent current. The entire module now sleeps at 200uA, way better than the 8mA previously with the stock setup. The other version of NODEMCU which uses the CH340 won't allow my computer port to sleep but it has only 2mA draw when sleeping. Replacing the AMS1117 should help reduce that as well.
Thanks again.
Who is online
Users browsing this forum: Bing [Bot] and 101 guests