TURN ON A LED WITH ARDUINO WITH A "1" AND SHUT OFF WITH A "0"

0

I have problems to turn on a led with arduino, you have to turn on the led when the user enters a "1" and show a legend that says "led on from the computer" and it has to be turned off when the user enters a " 0 "and show a legend that says" led off from computer ", also must turn on with bluethooth from the mobile. Could you please help me?

#include <SoftwareSerial.h>

SoftwareSerial BT1(2,3);
int myLed= 12;
char s ='0';
int g = 0;

void setup() {
  Serial.println("LISTO :)");
  BT1.begin(9600);
  pinMode(myLed,OUTPUT);

}

void loop() {
   if(BT1.available()){
    Serial.println("SI ESTA LISTO");
    g=BT1.read();
    Serial.println(g);
    }
  if(g==49){
    digitalWrite(myLed,HIGH);
    Serial.println("led enciende desde celular");
    g=50;
  }
   if(g==48){
    digitalWrite(myLed,LOW);
    Serial.println("led apaga desde celular");
    g=47;
  }

  if(s=='1'){
    digitalWrite(myLed,HIGH);
    Serial.println("led enciende desde computadora");
  }

}
    
asked by Edgar Gamero 23.03.2018 в 01:15
source

1 answer

0

It seems that the problem is that you read the Bluetooth in the variable g, but your if valid with s.

Change

If(s=='1')

By

If(g=='1')

or else, what you need is to add the reading of the sensor S in the bluetooth:

s=BT1.read();

Remember that in your code you also do not have the option 0 message added:

  if(s=='0'){
    digitalWrite(myLed,HIGH);
    Serial.println("led apagado desde computadora");
  }
    
answered by 23.03.2018 в 09:48