Need help with dimmer project arduino uno , wemos d1 mini

The Wemos has 3v logic ports whereas te Arduino has 5v logic. So you need to either change the mosfet to a logic level on (which will work at 3v fully open). You could also use the map() function to map values from 0-255 to 0-1023.

can you give me some examples?

@jack

This is just a shot in the dark, as I am unfamiliar with the Wemos, and I couldn’t find the resolution info on-line… but if the Wemos digital pins are 10bit resolution, as your slider values seem to indicate (my Arduino based sliders only show 0-255), then simply change the ranges in the sketch that relates to the pin you are controlling: i.e. instead of 0-255 use 0-1023, also modify the same values in the constraint().

Already tried that and it doesn’t work, 0-1023 works with simple slider sketch and it gives me 3.3v

@jack

So…

{
  brightness = param.asInt();
  analogWrite(WLED, brightness);
}

and…

analogWrite(WLED, constrain(brightness, 0, 1023));

…give different results?? Very strange… since both the slider and physical buttons output to the same physical pin ( as defined by WLED).

EDIT: OH, Wait! Also change this range setting (for both buttons) as that will also limit the values.

if (digitalRead(UPButton) == LOW and brightness < 1023) { // Only do something if button pressed and brightness counter in range.

it’s pulling slider to zero by itself and nothing works

check my edit… there are multiple areas that limited the button range of 0-255… all need to be changed to 0-1023.

@jack

it is this line that is causing the slider to move back…

Blynk.virtualWrite(V4, constrain(brightness, 0, 255))

Basically, change all references of 255 in the sketch to 1023 instead.

i tried that before too . for some reason it doesn’t work

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

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 += 20;  // Increment counter by 50
    Blynk.virtualWrite(V0, constrain(brightness, 0, 1023));  // Send feedback to Slider Widget - but keep within 0-255
    analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-255
  }
  // 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 -= 20;  // Decrement counter by 50
    Blynk.virtualWrite(V0, constrain(brightness, 0, 1023));  // Send feedback to Slider Widget - but keep within 0-255
    analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-255
  }
  else { // nothing happening here... move along :)
  }
}

OK, show the sketch as you have it now and I will take a look. Also let me know if the slider is currently referencing a virtual pin or digital, and which pin number.

pin V0

#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 D6  // Set increment button pin.
#define DNButton D7 // Set decrement button pin.
#define WLED D8  // Set LED pin.
int brightness = 255;  // Start on with LED on.
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(100L, whiteLED);  // Timer to run whiteLED function every half 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
}

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

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 += 20;  // Increment counter by 50
    Blynk.virtualWrite(V0, constrain(brightness, 0, 1023));  // Send feedback to Slider Widget - but keep within 0-255
    analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-255
  }
  // 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 -= 20;  // Decrement counter by 50
    Blynk.virtualWrite(V0, constrain(brightness, 0, 1023));  // Send feedback to Slider Widget - but keep within 0-255
    analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-255
  }
  else { // nothing happening here... move along :)
  }
}

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

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

Everything looks OK… but this INT line will set the pin to a really low, but not off, state (based on 10bit ranges) every-time the board resets, so change that as well to avoid unforeseen issues.

i think those pins need to be mapped just like Lichtsignaal wrote but my coding skills aren’t there im lost

Mapping is like a way of taking data from an input with a set range, then converting it to match an output that has a larger or smaller range. However, the pin controlling the mosfet obviously has the full range capabilities of the slider (0-1023), so there is no reason to use mapping for the button output, as it’s range is only limited to what you tell it to be.

You could try to add serial.print(brightness); to send the actual data to the IDE monitor, after every instance of action… just to confirm the values being sent via slider vs button.

i.e.

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
Serial.print("Slider: ");
Serial.println(brightness);
}

and…

analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-255
Serial.print("Button: ");
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 += 80;  // Increment counter by 50
    Blynk.virtualWrite(V0, constrain(brightness, 0, 255));  // Send feedback to Slider Widget - but keep within 0-255
    analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-255
    Serial.print(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 -= 80;  // Decrement counter by 50
    Blynk.virtualWrite(V0, constrain(brightness, 0, 255));  // Send feedback to Slider Widget - but keep within 0-255
    analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-255
    Serial.print(brightness);
  }
  else { // nothing happening here... move along :)
  }
}

ok so after these changes it gives me 0-1023 range (3.3v out) using slider and phisical switches but it doesn’t sync with app slider

Well, that’s some progress I guess :slight_smile:

Don’t forget to change that INT line and, I guess, reboot server, app and coffee maker just to be safe.

Ahh… this line (and one other, just like it) still needs to be changed. And it is the line that would sync the slider.

Just change everything in the sketch from 255 to 1023 (including the comments, to keep from later confusion).

when i do that it stops working
heres what i get from serial monitor

Button: 10
10Button: 20
20Button: 30
30Button: 40
40Button: 50
50Button: 60
60Button: 70
70Button: 80
80Button: 90
90Button: 100
100Button: 110
110Button: 120
120Button: 130
130Button: 140
140Button: 150
150Button: 160
160Button: 170
170Button: 180
180Button: 190
190Button: 200
200Button: 210
210Button: 220
220Button: 230
230Button: 240
240Button: 250
250Button: 260
260Button: 270
270Button: 280
280Button: 290
290Button: 300
300Button: 310
310Button: 320
320Button: 330
330Button: 340
340Button: 350
350Button: 360
360Button: 370
370Button: 380
380Button: 390
390Button: 400
400Button: 410
410
ets Jan 8 2013,rst cause:4, boot mode:(1,6)

wdt reset

and it wont do anything untill i press reset

sounds like something is overloading…

Send me the whole darn current sketch again, please :slight_smile:

#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 pin.
int brightness = 0;  // Start on with LED on.
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(100L, whiteLED);  // Timer to run whiteLED function every half 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
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 += 10;  // Increment counter by 50
    Blynk.virtualWrite(V0, constrain(brightness, 0, 1023));  // Send feedback to Slider Widget - but keep within 0-255
   analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-255
Serial.print("Button: ");
Serial.println(brightness);
    Serial.print(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 -= 10;  // Decrement counter by 50
    Blynk.virtualWrite(V0, constrain(brightness, 0, 1023));  // Send feedback to Slider Widget - but keep within 0-255
   analogWrite(WLED, constrain(brightness, 0, 1023));  // Send data to LED - but keep within 0-255
Serial.print("Button: ");
Serial.println(brightness);
    Serial.print(brightness);
  }
  else { // nothing happening here... move along :)
  }
}

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

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