How to turn LED on after a certain anolog signal is reached

No, it will be fine :slight_smile: Besides, you can’t break anything with this sort of code. It’ll work or not and if it doesn’t work you probably did something wrong, nothing to worry about :slight_smile:

BLYNK_READ(V6)//pressure reading
{
  int val = analogRead(0);
  val = map(val, 210, 1080, 0, 145);
  Blynk.virtualWrite(6, val); 

//GREEN LED
 if (val > 100)//If val = greater than 100, LED turns on
    led1.on();//LED On
  } else {//If val = less than 100 LED turns off
    led1.off();//LED Off
  }
  
  //RED LED
 if (val < 100)//If val = less than 100, LED turns on
    led1.on();//LED On
  } else {//If val = greater than 100 LED turns off
    led1.off();//LED Off
  }
}

In saying that, would this work? 2 in the one? and still use the frequency from the gauge to act as the timer?
Cheers.

Actually it has error:

Systems_Button.ino:93:5: error: expected unqualified-id before ‘else’
Systems_Button.ino:98:2: error: expected unqualified-id before ‘if’
Systems_Button.ino:100:3: error: expected declaration before ‘}’ token
Error compiling.

Yes, you are missing one “{” after the if(vla<100) :wink:

But in essence, you are correct this should work.

Thanks a bunch Lichtsignaal! really do appreciate it! If you don’t mind one last question, how could you get one LED to change colour? that’d really be the icing to the cake on my project.By the way this is my school project so should get a top notch mark!

Nice :slight_smile:

You can use this:

Blynk.setProperty(V0, “color”, “#D3435C”);

To change the color of the LED (V0 being the pin the LED is attached to of course).

Something like this?

//GREEN LED
 if (val > 100){//If val = greater than 100, LED turns on
    led1.on();//LED On
    Blynk.setProperty(V0, "green", "#23C48E");
  } else {//If val = less than 100 LED turns off
    led1.off();//LED Off
  }
  
  //RED LED
 if (val < 100){//If val = less than 100, LED turns on
     Blynk.setProperty(V0, "red", "#D3435C");    
     led2.on();//LED On
  } else {//If val = greater than 100 LED turns off
    led2.off();//LED Off
  }
}

I think the “color” part is just that, it indicates which property you want to adjust. the #xxxxxx is the hexadecimal color code, so you should change that to the appropriate color.

do you just put it on the line before led1.on? and would it change if i put it before both scenarios, so depending what scenario its on will automatically change colour?

oh and now it comes with errors:

Systems_Button.ino: In function ‘void BlynkWidgetRead6(BlynkReq&)’:
Systems_Button.ino:90:11: error: ‘class BlynkEthernet’ has no member named ‘setProperty’
Systems_Button.ino:98:12: error: ‘class BlynkEthernet’ has no member named ‘setProperty’
Error compiling.

Yes, you can do it however you want. I’d keep it simple with just 1 LED and do something like:

if (val > 100){//If val = greater than 100, LED turns green
    Blynk.setProperty(V0, "color", "#33cc33");    
    led1.on();//LED On
  } else {//If val = less than 100 LED turns off
    Blynk.setProperty(V0, "color", "#ff0033");
    led1.on();//LED On

  }

still get “error compiling”

Systems_Button.ino: In function ‘void BlynkWidgetRead6(BlynkReq&)’:
Systems_Button.ino:90:11: error: ‘class BlynkEthernet’ has no member named ‘setProperty’
Systems_Button.ino:93:11: error: ‘class BlynkEthernet’ has no member named ‘setProperty’

Did you update to the latest library? This function is pretty new I think.

of course. Thanks for your help! youre a wiz, I can only test this on monday but will be sure too! thanks again