3

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 Answers3

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.

Coder_fox
  • 686
  • 7
  • 14
2

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.

0

After four months of searching - Just use 3.3 V with 1.5 or 2 A and everything will work correctly.

Greenonline
  • 3,152
  • 7
  • 36
  • 48