I´m using a Wemos D1 mini board to control a RGB LED Strip and programmed a simple code with the Arduino IDE. The Wemos conects to my Internet just fine and with the IP adress I can change the RGB values of the Strip. Everything works but after a few minutes the board freezes and nothing works. After a reset it works again.

I also conected a simple circuit to the board just to controle a RGB-LED Strip with a few transistors nothing that should cause an issue and also if i conect nothing to the board the problem occurs.

I also tested a example from the Wemos Library but there is the same problem. Here is my code I used (And sorry if the code isn´t that well programmed I´m a beginner ;)):

#include <ESP8266WiFi.h>

const char* ssid = "my SSID"; 
const char* pass = "my password"; 

void setup() {
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D5, OUTPUT);

  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) delay(500);

void setColor(String rgb)
  String rgb_val = rgb.substring(4, rgb.lastIndexOf('H'));
  String red_val = rgb_val.substring(1,rgb_val.indexOf(':'));
  String green_val = rgb_val.substring(rgb_val.indexOf(':') + 1,rgb_val.indexOf(':',rgb_val.indexOf(':') + 1));
  String blue_val = rgb_val.substring(rgb_val.lastIndexOf(':') + 1);
  int redval = red_val.toInt();
  int greenval = green_val.toInt();
  int blueval = blue_val.toInt();
  analogWrite(D5, redval);
  analogWrite(D2, greenval);
  analogWrite(D1, blueval);

  redval = redval >= 1023 ? 1023 : redval <= 0 ? 0 : redval;
  if (redval == 0)
    analogWrite(D5, 0);

  greenval = greenval >= 1023 ? 1023 : greenval <= 0 ? 0 : greenval;
  if (greenval == 0)
    analogWrite(D1, 0);

  blueval = blueval >= 1023 ? 1023 : blueval <= 0 ? 0 : blueval;
  if (blueval == 0)
    analogWrite(D2, 0);


void loop() {
  //delay(50) //just a test if there are not so many updates
  WiFiClient client = server.available();
  if (!client) return;

  while (!client.available()) delay(1);

  String request = client.readStringUntil('\r');


  client.print("HTTP/1.1 200 OK\r\n");

Is there someone who know what I have done wrong?

  • Are you certain that is the actual code you are using? It doesn't compile because you call server.begin(), but haven't declared server. Aug 15 '17 at 14:21
  • 2
    First you stop the client, then you continue writing to it. I have no idea how exactly the client is implemented, but you can imagine how this could lead to memory problems.
    – tttapa
    Sep 16 '17 at 15:28

I doubt this is the problem, but this code looks wrong.

  int redval = red_val.toInt();
  analogWrite(D5, redval);
  redval = redval >= 1023 ? 1023 : redval <= 0 ? 0 : redval;
  if (redval == 0)
    analogWrite(D5, 0);

I think it should be more like this:

  int redval = red_val.toInt();
  if (redval > 1023)  // If its =1023 you do need to set it to 1023.
    redval= 1023;
  else if (redval < 0)
    redval = 0;
  analogWrite(D5, redval);

The inline if statement is too ugly and doesn't really add anything.

To be honest I would look at pulling this code into functions to make it easier to read and I suspect you will find the problem.

When these microprocessors stop after a while its usually memory, heat or electrical. If you have checked the electrics and its stopping quite quickly its probably a memory leak. So refactoring your code might help people spot the problem easier.

You might want to replace you call to setColour() with a call to Serial.println() and see if that cure the problem. If it doesn't then your problem is with the way you are calling client.

  • 2
    Ok I just edited the code like you said and also replaced the call function with the Serial.println() but the issue occured after a few seconds again
    – rlcmtzc
    Aug 15 '17 at 13:26

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