I tried to fix this problem the whole weekend but, after no success I decided to post it here. I would really appreciate any help.
The problem
The Wi-Fi module activates the DC motor and lets it run for 3 seconds, but when the DC motor stops after that 3 seconds, the Wi-Fi module and display don't respond anymore. It only works once. (After I push the reset button the same thing happens.)
Question
What causes this disturbance? Any advice on my circuit? (I included a Fritzing Diagram because I am bad at drawing schematics)
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
SoftwareSerial ESP8266(9, 8); // RX = 8 en TX = 9
#define DEBUG true
boolean FAIL_8266 = false;
int LED = 13; // led op 13
int secondeAan = 3000;
String my_AP_SSID = "myID";
String my_AP_Pass = "myPass";
void setup()
{
// -- stel led in --
pinMode(LED, OUTPUT);
// -- lcd scherm --
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 1);
do {
ESP8266.begin(115200); // start communicatie met esp8266
//Wait Serial Monitor to start
while (!Serial);
lcd.clear();
lcd.print("--- Start ---");
ESP8266.print("AT\r\n");
delay(500);
if (ESP8266.find("OK"))
{
FAIL_8266 = false;
sendData("AT+RST\r\n", 4000, DEBUG);
sendData("AT+CWMODE=3\r\n", 2000, DEBUG);
sendData("AT+CWJAP=\"" + my_AP_SSID + "\",\"" + my_AP_Pass + "\",9,4\r\n", 2000, DEBUG);
sendData("AT+CIFSR\r\n", 2000, DEBUG);
sendData("AT+CIPMUX=1\r\n", 2000, DEBUG);
sendData("AT+CIPSERVER=1,80\r\n", 2000, DEBUG);
} else {
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Module have no response.");
delay(500);
FAIL_8266 = true;
}
} while (FAIL_8266);
}
void loop()
{
// Get the number of bytes (characters) available for reading from the serial port
if (ESP8266.find("+IPD,"))
{
lcd.clear();
lcd.print("Nieuwe connectie");
// -- sluit connectie --
motorToggle();
sendData("AT+CIPCLOSE=0\r\n", 100, DEBUG);
sendData("AT+CIPCLOSE=1\r\n", 100, DEBUG);
sendData("AT+CIPCLOSE=2\r\n", 100, DEBUG);
}
}
void motorToggle () {
digitalWrite(LED, HIGH);
lcd.clear();
lcd.print("eten gegeven");
delay(secondeAan);
digitalWrite(LED, LOW);
delay(200);
}
String sendData(String command, const int timeout, boolean debug)
{
String response = "";
ESP8266.print(command); // send the read character to the esp8266
long int time = millis();
while ( (time + timeout) > millis())
{
while (ESP8266.available())
{
char c = ESP8266.read();
response += c;
}
}
if (debug)
{ lcd.clear();
lcd.print(response);
}
return response;
}

