Neopixel using a button error

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "";
char ssid[] = "";
char pass[] = "";

int r;
int g;
int b;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, D6, NEO_GRB + NEO_KHZ800);

  r = param.asInt();
  g = param.asInt();
  b = param.asInt();

void setup() {
  Blynk.begin(auth, ssid, pass);

void loop() {;

  if (digitalRead(D1) == HIGH) { //on pin D1 is a Button!
    strip.setPixelColor(1, 255, 0, 0);; 
  } else {
    strip.setPixelColor(1, 0, 0, 0);; 

I would like to control my LEDs via smartphone. As a test I wrote this code. This should turn on a specific LED as soon as you press a button in the Blynk app. But every time I press the button, the ESP will simply disconect.

So can you guys find a mistake or helping me otherwise?


Wel, we are not a code mechanic shop here :wink:

But as I see, your Blynk related code is doing nothing but assigning a value to a variable (r, g & b) it then does nothing with those variables…

PS you might be better using MERGE mode like this…

BLYNK_WRITE(V1) // zeRGBa assigned to V1 
  r = param[0].asInt();
  g = param[1].asInt();
  b = param[2].asInt();

And this shouldn’t be in the void loop() since as soon as you press the physical button, that code tries to run thousands of times a second and can disconnect the device from the server…

Try running in a timed loop instead.

1 Like

I think the D6 here may be a problem. The Neopixel library may be treating this as GPIO6, which isn’t an available pin on the ESP8266.

Try changing this to 12 and keeping the Neopixel strip connected to D6 (Which is GPIO12) and see what happens.

If it’s not that, then it may be your cluttered void loop.


1 Like

ok guys it works now! just had to make a timed loop with a small delay. the connection is now fine!
Thank you!

1 Like