Widget led

Hello, please help with arduino 101 (connect with usb). I have a project, the code is attached below. When the temperature or the gas sensor is raised, a light is activated on my circuit. How to make it so that the application on the android also turned on and off the light bulb. I can not do it at all.

#define GAS A0
#define TEMP A1 

// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX

#include <BlynkSimpleStream.h>

char auth[] = "46ac3f79b916492cab3a9ef85a3f4f33";
WidgetLED led1(V1);
int LED_GAS = 12; 
int LED_TEMP = 11; 

void setup()
{
  SwSerial.begin(9600);
  Serial.begin(9600);
  // Debug console

  // Blynk will work through Serial
  // Do not read or write this serial manually in your sketch
  Blynk.begin(Serial, auth);
 
  pinMode(TEMP, INPUT);
  pinMode(GAS, INPUT);
  pinMode(LED_GAS,OUTPUT);
  pinMode(LED_TEMP,OUTPUT);
}

void loop()
{
  Blynk.run();
  gas();
  temp(); 
}
void gas()
{
  float GAS0 = analogRead(GAS);
  int result_gas = GAS0;
  delay(50);
  Serial.print("Gas ratio: ");
  Serial.print(GAS0);
  if (result_gas >= 30) 
  {
    led1.on();
    tone(10, 3000, 25);
    digitalWrite(LED_GAS,LOW);
    delay(25);
    digitalWrite(LED_GAS,HIGH);
  }
  else
  {
    digitalWrite(LED_GAS,LOW);
    noTone(10);
  }
}

void temp()
{
  float t = analogRead(TEMP);
  int result_t = t;
  Serial.print("Temp: ");
  Serial.print(result_t);
  delay(50);
  if (t >= 750) 
  {
    tone(10, 1000, 25);
    digitalWrite(LED_TEMP,LOW);
    delay(25);
    digitalWrite(LED_TEMP,HIGH);
  } 
  else 
  {
    digitalWrite(LED_TEMP,LOW); 
    noTone(10);
  }
}

so do I understand it correctly:
IF the gas or temp physical LED (on board) is activated THEN you also want a virtual LED (blynk app) activated??

Yes.

z.B
WidgetLED led0(V1);
WidgetLED led2(V2);

that comes in your program void gas void temp led0.on ();
led2.off (); or led0.off ();
led2.on ();

@tu_4ka Virtual LEDs can be controlled in two ways…

As noted above… with led2.on() or led2.off() commands.

Or, as you are doing, with virtualWrite()… However, then they accept a PWM like range of 0-255. So setting it HIGH is actually only giving it a 1, which is interpreted as just a tiny step above totally OFF… so use 0 instead of LOW and 255 instead of HIGH… anything in between will change the apparent “intensity” of the vLED

Thank you very much. And could you still prompt after which line to insert WidgetLED led0 (V1);
WidgetLED led2 (V2);
I after what in void gas led0.on (); led2.off ();

Hello
Widget LED led0 (V1); Widget LED led2 (V2); under char auth [] = “46ac3f79b916492cab3a9ef85a3f4f33”; insert
for example in the sketch at void temp after if led0.on (); or led2.off (); and after else led0.on (); or
led2.off (); insert so have pointed and then still with blynk app the LED select and then still the LED color

Thank you, very much.

hi tu_4ka can u share your code here as a references for me cause i also having the same problem with activate the led widget in blynk app, thanks

@Oh_Jia_Ming you seem to be taking a scattergun approach to asking for help with your university project. @PhilipNgu also appears to have the same project (not surprising as you both attend the same university).

Blynk regulars tend to get a little tired of students wanting free programming lessons, especially when you haven’t spent much time researching or taking onboard advice that’s given.

Pete.

3 Likes