Help with blynk slider to turn on/off digital pin

he i wont turn on/off digital pin 6 with slider ( when its of = pin6 off ; when i move the slider its turn on from value1 the pin to high ) its for multi ( relay on/off and dimmer with same slider)

wats e good code for it .

thanks

i now i most do it with virtual pin . i struccel with the arduino code . for button i now i dont now for slider.

example slider code:

BLYNK_WRITE(V2) // tray warning temp (LOW)  slider
{
  setTrayLowerTemp = param.asInt();
  {
    setTrayLowerAlarmTemp = setTrayLowerTemp - 5; //sets alarm temp at 5 (or whatever) degrees lower than the warning temp
    readDS18BFunction(); //runs the tray temp function again
  }
}
BLYNK_WRITE(V0)
{
  dimmerValue = param.asInt();
  if(dimmer > 1)
  {
     digitalWrite(relayPin, HIGH);
     analogWrite(someAnalogPin, dimmerValue);
  }
  else
  {
     digitalWrite(relayPin, LOW);
     analogWrite(someAnalogPin, dimmerValue);
}

This will turn on the relay and set the dimmer level in one go. There are variations and maybe it can be written shorter, but this is more readable :slight_smile:

i gave on error ( ‘dimmerValue’ was not declared in this scope

it’s a variable name, you have to declare variables or at least type them, try it like so:

int dimmerValue = param.asInt()

if you want to use the variable locally change

dimmerValue = param.asInt();

to

int dimmerValue = param.asInt();

if you need the variable to be global keep:

dimmerValue = param.asInt();

and add the following after your libraries:

int dimmerValue;

1 Like

thanks it works now

the realy works , now i test the dime and its not work i take pmw uitgang

So your relay works but your dimmer doesn’t, correct?

Paste a link to your dimmer and your current sketch.

its work now thanks

BLYNK_WRITE(6)
{

dimmerValue = param.asInt(); // assigning incoming value from pin V6 to a variable

dimmerValue = (255./1023.) * param.asInt();

if(dimmerValue < 1)
{
digitalWrite(6 , HIGH);
analogWrite(5, dimmerValue);
}
else
{
digitalWrite(6, LOW);
analogWrite(5, dimmerValue);

}
}

void loop()
{
Blynk.run();

}

this work well