My system looks like this:
ESP8266 is connected to Arduino Uno (2, 3 pins) and a relay's data input to Arduino's pin 12 and power for relay is provided from another source.
Arduino gets data from server and switches on/off relay according to that signal. This system works perfectly for few hours and then suddenly crashes. In my WiFi console I have:
wlan0: STA 2c:3a:e8:4e:bf:70 WPA: pairwise key handshake completed (RSN) wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: disassociated wlan0: AP-STA-DISCONNECTED 2c:3a:e8:4e:bf:70 wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: disassociated wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: associated wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: disassociated wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: disassociated wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: associated wlan0: AP-STA-CONNECTED 2c:3a:e8:4e:bf:70
I have read this Arduino question, but circuit diagram similar to that one. I get power from my PC to run Arduino.
This is my Arduino code :
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2, 3); // RX, TX
#endif
char ssid[] = "RPi"; // your network SSID (name)
char pass[] = "raspberry"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "192.168.50.1";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds
int testLED = 12;
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
pinMode(testLED, OUTPUT);
// initialize serial for debugging
Serial.begin(9600);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Serial.println("You're connected to the network");
//printWifiStatus();
}
void loop()
{
// if there's incoming data from the net connection send it out the serial port
// this is for debugging purposes only
while (client.available()) {
char c = client.read();
//code to run relay
if (c == '#')
{
while (client.available() == 0) { } // Do nothing while we wait for the next value
// reading the second charactor
c = client.read();
if (c == '1') {
Serial.println("On");
digitalWrite(testLED, HIGH);
delay(600000);
}
else if (c == '0') {
Serial.println("Off");
digitalWrite(testLED, LOW);
delay(600000);
} //end of C cheking if-else
} //end of first charactor # if
//end of replay code
}
// if 10 seconds have passed since your last connection,
// then connect again and send data
if (millis() - lastConnectionTime > postingInterval) {
httpRequest();
}
}
// this method makes a HTTP connection to the server
void httpRequest()
{
Serial.println();
// close any connection before send a new request
// this will free the socket on the WiFi shield
client.stop();
// if there's a successful connection
if (client.connect(server, 80)) {
Serial.println("Connecting...");
// send the HTTP PUT request
client.println(F("GET /simple.txt HTTP/1.1"));
client.println(F("Host: localhost"));
client.println("Connection: close");
client.println();
// note the time that the connection was made
lastConnectionTime = millis();
}
else {
WiFi.begin(ssid, pass);
Serial.println("Reconnecting again");
}
}
3 Answers 3
As long as I know you need at least 170mA to power the esp8266 also you need 100-200mA for the arduino and 100mA for the relay so I recommend to use a 1A power supply and solder some capacitors on the 5V and 3.3V rails. Also if your Wi-Fi is giving a ip address that is limited for certain time for example 1-2 hours you need to expand that time for your needs.If it disconnects the esp will lose its IP address and try to recover for example on my NODE MCU it works well for weeks. It also depends on your library (I am using ESP8266WiFi.h). Anyway I recommend to try the WebServer example for testing if the issue is in your code.
-
solder capacitors to Arduino board? can you explain it ?Sachith Muhandiram– Sachith Muhandiram2018年01月18日 14:34:58 +00:00Commented Jan 18, 2018 at 14:34
-
1@Sachith instructables.com/id/NRF24L01-Fixing-Connection-IssuesCoder_fox– Coder_fox2018年01月18日 21:12:30 +00:00Commented Jan 18, 2018 at 21:12
-
you need 100-200mah for the arduino - 100 milliamp-hours? You mean 100-200mA don't you?2018年03月10日 06:47:08 +00:00Commented Mar 10, 2018 at 6:47
-
OP uses WiFiEsp library in Uno with AT firmware in esp82662018年03月10日 15:59:12 +00:00Commented Mar 10, 2018 at 15:59
-
1@Sachith, are you here? You offered a bounty. It will go to Coder_fox. Did this answer help? If yes accept it, if not, give feedback2018年03月11日 09:49:33 +00:00Commented Mar 11, 2018 at 9:49
After quite long research I found the solution for my problem.
I did some changed power connection to ESP-8266.
ESP 8266 --------- Arduino Uno
Vcc
---------> 3.3v
CH_PD
---------> 5v divided into 3.3v using resistors
RX
---------> PIN-2 via 3.3v regulator.
After this configuration, my system was working perfectly for days. Thanks for the all suggestions given.
-
powering CH_PD from 5V did the trick. I suspect it powers the WiFi part2018年03月11日 12:23:52 +00:00Commented Mar 11, 2018 at 12:23
-
@Juraj sorry, what do you mean? directly connect 5v to ESP's CH_PD port?Sachith Muhandiram– Sachith Muhandiram2018年03月12日 04:40:10 +00:00Commented Mar 12, 2018 at 4:40
-
no no, the regulator is ok. 3.3 V pin on Uno can provide only 50mA. normal is connecting Vcc and CH_PD together but the 3.3 V is not strong enough to power esp8266. I wonder that powering only CH_PD from stronger source helped.2018年03月12日 06:11:51 +00:00Commented Mar 12, 2018 at 6:11
-
@Juraj I tried to connect external voltage to Vcc, but it didn't work.Sachith Muhandiram– Sachith Muhandiram2018年03月12日 06:16:44 +00:00Commented Mar 12, 2018 at 6:16
-
I looked up the docs. Your esp8266 is now stable because the CH_PD (chip enable) pin has stable power not affected by power drops caused by WiFi. a stronger power supply would by a better solution2018年03月12日 12:48:02 +00:00Commented Mar 12, 2018 at 12:48
After four months of searching - Just use 3.3 V with 1.5 or 2 A and everything will work correctly.
-
1can you suggest full answer?Sachith Muhandiram– Sachith Muhandiram2018年09月29日 15:02:01 +00:00Commented Sep 29, 2018 at 15:02
Explore related questions
See similar questions with these tags.
I get power from my PC to run Arduino.