Need help with dimmer project arduino uno , wemos d1 mini

Here is the slightly modified sketch… I changed the timing to every second and the increments from 10 to 100 to avoid sending too much data during diagnosis. Once it is working, you can remove the Serial.print() lines and adjust the timing and increments.

Otherwise I only had to correct a value from 1025 to 1023 in a couple of lines. ALSO I set it to print the brightness data output all the time, in the button void, not just when they are pressed (just to keep it to a single instance of print).

Now, I can NOT test this… it will not even compile on my setup, so hopefully there are no syntax errors.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

char auth[] = "xxx"; //WeMos D1 Mini
char ssid[] = "xxx";
char password[] = "xxx";

IPAddress server_ip (192, 168, 1, 154);

// Mac address should be different for each device in your LAN
IPAddress arduino_ip ( 192,   168,   1,  154);
IPAddress dns_ip     (  8,   8,   8,   8);
IPAddress gateway_ip ( 192,   168,   1,   1);
IPAddress subnet_mask(255, 255, 255,   0);

SimpleTimer timer;
#define UPButton D5  // Set increment button pin.
#define DNButton D6 // Set decrement button pin.
#define WLED D7  // Set LED (or mosfet) pin.
int brightness = 0;  // Start on with LED OFF.
SimpleTimer timerBUTTONS;  // Setup timerBUTTONS to check buttons.
/////////////////////////////////////////////////

void setup()
{
  pinMode(UPButton, INPUT_PULLUP);  // Set increment button pin to INPUT - Add _PULLUP if not already set in hardware.
  pinMode(DNButton, INPUT_PULLUP);  // Set decrement button pin to INPUT - Add _PULLUP if not already set in hardware.

  Serial.begin(115200);
  Serial.println();
  WiFi.config(arduino_ip, gateway_ip, subnet_mask);
  WiFi.begin(ssid, password);
  Blynk.config(auth);
  while (Blynk.connect(1000) == false) {
  }


  timerBUTTONS.setInterval(1000L, whiteLED);  // Timer to run whiteLED function every second.
}

////////////////////////////////////////////////

BLYNK_WRITE(V0) // Slider Widget Function - runs every-time slider widget is physically moved.
{
  brightness = param.asInt();  // Get slider value.
  analogWrite(WLED, brightness);  // Send slider value to LED or mosfet
  Serial.print("Slider: ");
  Serial.println(brightness);
}


/////////////////////////////////////////////////

void whiteLED() // This function checks buttons status and updates White LED and slider (frequency dependent on timer).
{
  // Check increment button and respond.
  if (digitalRead(UPButton) == LOW and brightness < 1023) {  // Only do something if button pressed and brightness counter in range.
    brightness += 100;  // Increment counter by 100
    Blynk.virtualWrite(V0, constrain(brightness, 0, 1023));  // Send feedback to Slider Widget - but keep within 0-1023
    analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-1023
  }
  // Check decrement button and respond..
  else if (digitalRead(DNButton) == LOW and brightness > 0) {  // Only do something if button pressed and brightness counter in range.
    brightness -= 100;  // Decrement counter by 100
    Blynk.virtualWrite(V0, constrain(brightness, 0, 1023));  // Send feedback to Slider Widget - but keep within 0-1023
    analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-1023
  }
  else { // nothing happening here... move along :)
  }
    Serial.print("Button: ");
    Serial.println(brightness);
}

/////////////////////////////////////////////////
/////////////////////////////////////////////////

void loop()
{
  Blynk.run();  // Runs usual Blynk routine.
  timerBUTTONS.run();  // Checks timer and runs whiteLED function.
}

Nope, bad idea as it will show slider changes as well since it is the same variable, brightness, but seem like it is because of button changes.

use this void whiteLED() instead

void whiteLED() // This function checks buttons status and updates White LED and slider (frequency dependent on timer).
{
  // Check increment button and respond.
  if (digitalRead(UPButton) == LOW and brightness < 1023) {  // Only do something if button pressed and brightness counter in range.
    brightness += 100;  // Increment counter by 100
    Blynk.virtualWrite(V0, constrain(brightness, 0, 1023));  // Send feedback to Slider Widget - but keep within 0-1023
    analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-1023
    Serial.print("Button: ");
    Serial.println(brightness);
  }
  // Check decrement button and respond..
  else if (digitalRead(DNButton) == LOW and brightness > 0) {  // Only do something if button pressed and brightness counter in range.
    brightness -= 100;  // Decrement counter by 100
    Blynk.virtualWrite(V0, constrain(brightness, 0, 1023));  // Send feedback to Slider Widget - but keep within 0-1023
    analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-1023
    Serial.print("Button: ");
    Serial.println(brightness);
  }
  else { // nothing happening here... move along :)
  }
}

keeps restarting

___  __          __

/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.4.2 on Arduino

[5001] Connecting to blynk-cloud.com:8442
[5047] Ready (ping: 1ms).
Button: 100

ets Jan 8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v3de0c112
~ld

[65]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.4.2 on Arduino

[5001] Connecting to blynk-cloud.com:8442
[5038] Ready (ping: 1ms).
Button: 100
Button: 200
Button: 300
Button: 400
Button: 500

ets Jan 8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v3de0c112
~ld

[65]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.4.2 on Arduino

[5001] Connecting to blynk-cloud.com:8442
[5029] Ready (ping: 1ms).

Change your timing to 2 seconds, or more, and possibly the increments to 200 (thus only about 5 button presses to reach full range) to keep from apparent overload or whatever the official Blynk terminology is… this is just for the diagnostics.

same thing - keeps restarting
[5114]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.4.2 on Arduino

[5115] Connecting to blynk-cloud.com:8442
[5992] Ready (ping: 3ms).
Button: 200

ets Jan 8 2013,rst cause:4, boot mode:(1,7)

wdt reset
rl

OK, I am guessing that it is only resetting when you are pressing (or holding) the buttons?? How about when only adjusting the slider (I would suggest setting the slider to “send on release” for this and moving the slider in about 1/4 or 1/3 increments)… what is the monitor printout for that?

app doesn’t send anything to serial monitor
phisical switch doesn’t sync with slider
slider works without problem up untill i press phisical button than it freezes

i think theres something with server code because ,
wemos can obviously range from 0-1023
everything is working when we using 0-255 value

what do you think ?

App doesn’t send to monitor, the print lines in this function do that:
BLYNK_WRITE(V0) // Slider Widget Function - runs every-time slider widget is physically moved. { brightness = param.asInt(); // Get slider value. analogWrite(WLED, brightness); // Send slider value to LED or mosfet Serial.print("Slider: "); Serial.println(brightness); }

This line (1 of 2 in void whiteLED() )should sync with slider as long as system is not too busy freezing up to pay attention.

Blynk.virtualWrite(V0, constrain(brightness, 0, 1023));  // Send feedback to Slider Widget - but keep within 0-1023

And the freezup is just likely all because of the fast timing… set things reeellly slow for diagnostics and only change one thing at a time.

And finally, set your int brightness = 1023; (to start at full brightness) and only hit the DOWN button a few times… the purpose of the print statements was to confirm the button function was sending the full 1023 range (and that the mosfet was taking the full 3.3v). If they are, then Great!! clear out all the print statements and focus on feedback to the slider or whatever the next issue might be… Once it is ALL working, then you can reset the timing and increment/decrement settings (although 100 milliseconds for the timing is a bit too quick, try around 250 - 500 at lowest, higher if still rebooting).

PS

The server doesn’t care about the range limits of the hardware, it is just shuttling the data back and forth… as long as you have confirmed that the hardware works withing a specific range, then the issue is in the code and the timing.

As for me… it is time to go and relax with a nice Christmas Classic movie… I am thinking Die Hard :smile:

Merry Christmas to you and I will check in on this thread another day to see if you made any progress.

Thanx a lot!
Merry Christmas!

Any sugestions? anybody?

Still have issues??

The LED control via slider/button code I had posted for you has been working great for my demo setup, as shown in my video I recently posted here. Including an added virtual LED in the app that dims along with the real one.

Last I recall, we resolved the range issue, and you had said the slider worked fine. Then the buttons “seemed” to work except for being too fast and causing flood disconnect.

So what have you tried since and what is the up to date status?

I just figured it out !
there was no problem with your code , the problem is that you need to add pullup resistors to the switcheses

pinMode(DNButton, INPUT_PULLUP); doesn’t work
and than change 255 to 1023 !

Gunner Thanx A LOT BRO!

1 Like