Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user

I have a small project and I have some problems while working on that. The idea of the project is the followingas below: I have an LED which is commandedoperated by two "buttons". The buttons are basically 1/0takes two values (1 or0) which I have to send from Serial Monitorserial monitor. One button command ais for LDR sensor, which lights up the LED when its value is below 300 (in my code). The other button just lights the LED (Value 1) or turns it off (Value 0). The buttons are working together, so I have to consider both of them in my statements. The problem is that I cannot play with the Serial Monitor to let me input the values for the two buttons separately,serial monitor it's just looping forevercontinuously and I cant type anything as input.

Can anybody, please,anyone help me with this to find a solution to be able to input values for both buttons?

const int analogInPin = A0; //LDR PIN
const int digitalOutPin = 13; // LED PIN
int outputValue;

int sensorValue = 0; //

char Buton1; //LDR button
char Buton2; //Blutooth button


void setup()
{
  Serial.begin(9600);
}

void loop()
{
  while (Serial.available())
  {
    Serial.println("Button1 value: ");
    Buton1 = Serial.read();
    if (Buton1 == '1')
    {
      Buton2 = Serial.read();
      Serial.println("Button2 value: ");
      Buton2 = Serial.read();
      if (Buton1 == '1' and Buton2 == '0')
      {
        sensorValue = analogRead(analogInPin);
        outputValue = map(sensorValue, 0, 1023, 0, 255);
        Serial.print ("Sensor: ");
        Serial.println(sensorValue);
        if (sensorValue < 300);
        {
          digitalWrite(digitalOutPin, 255);
        }
      }
      else if (Buton1 == '1' and Buton2 == '1')
      {
        digitalWrite(digitalOutPin, 255);
        Serial.print("Both buttons are ON ! !");
      }
    }
    else if (Buton1 == '0')
    {
      Serial.println("Button2 value: ");
      Buton2 = Serial.read();
    }
    if (Buton1 == '0' and Buton2 == '1')
    {
      digitalWrite(digitalOutPin, 255);
    }
    else if (Buton1 == '0' and Buton2 == '0')
    {
      Serial.println("Both buttons are inactive ! Please reset");
      break;
    }
  }
}

I have a small project and I have some problems. The idea of the project is the following: I have an LED which is commanded by two "buttons". The buttons are basically 1/0 values which I have to send from Serial Monitor. One button command a LDR sensor, which lights up the LED when its value is below 300 (in my code). The other button just lights the LED (Value 1) or turns it off (Value 0). The buttons are working together, so I have to consider both of them in my statements. The problem is that I cannot play with the Serial Monitor to let me input the values for the two buttons separately, it's just looping forever.

Can anybody, please, help me to find a solution to be able to input values for both buttons?

const int analogInPin = A0; //LDR PIN
const int digitalOutPin = 13; // LED PIN
int outputValue;

int sensorValue = 0; //

char Buton1; //LDR button
char Buton2; //Blutooth button


void setup()
{
  Serial.begin(9600);
}

void loop()
{
  while (Serial.available())
  {
    Serial.println("Button1 value: ");
    Buton1 = Serial.read();
    if (Buton1 == '1')
    {
      Serial.println("Button2 value: ");
      Buton2 = Serial.read();
      if (Buton1 == '1' and Buton2 == '0')
      {
        sensorValue = analogRead(analogInPin);
        outputValue = map(sensorValue, 0, 1023, 0, 255);
        Serial.print ("Sensor: ");
        Serial.println(sensorValue);
        if (sensorValue < 300);
        {
          digitalWrite(digitalOutPin, 255);
        }
      }
      else if (Buton1 == '1' and Buton2 == '1')
      {
        digitalWrite(digitalOutPin, 255);
        Serial.print("Both buttons are ON ! !");
      }
    }
    else if (Buton1 == '0')
    {
      Serial.println("Button2 value: ");
      Buton2 = Serial.read();
    }
    if (Buton1 == '0' and Buton2 == '1')
    {
      digitalWrite(digitalOutPin, 255);
    }
    else if (Buton1 == '0' and Buton2 == '0')
    {
      Serial.println("Both buttons are inactive ! Please reset");
      break;
    }
  }
}

I have a small project and I have some problems while working on that. The idea of the project is as below: I have an LED which is operated by two "buttons". The buttons takes two values (1 or0) which I have to send from serial monitor. One button is for LDR sensor, which lights up the LED when its value is below 300 (in my code). The other button turns it off (Value 0). The buttons are working together, so I have to consider both of them in my statements. The problem is that I cannot play with the serial monitor it's just looping continuously and I cant type anything as input.

Can anyone help me with this to find a solution to be able to input values for both buttons?

const int analogInPin = A0; //LDR PIN
const int digitalOutPin = 13; // LED PIN
int outputValue;

int sensorValue = 0; //

char Buton1; //LDR button
char Buton2; //Blutooth button


void setup()
{
  Serial.begin(9600);
}

void loop()
{
  while (Serial.available())
  {
    Serial.println("Button1 value: ");
    Buton1 = Serial.read();
    if (Buton1 == '1')
    {
      Buton2 = Serial.read();
      Serial.println("Button2 value: ");      
      if (Buton1 == '1' and Buton2 == '0')
      {
        sensorValue = analogRead(analogInPin);
        outputValue = map(sensorValue, 0, 1023, 0, 255);
        Serial.print ("Sensor: ");
        Serial.println(sensorValue);
        if (sensorValue < 300);
        {
          digitalWrite(digitalOutPin, 255);
        }
      }
      else if (Buton1 == '1' and Buton2 == '1')
      {
        digitalWrite(digitalOutPin, 255);
        Serial.print("Both buttons are ON ! !");
      }
    }
    else if (Buton1 == '0')
    {
      Serial.println("Button2 value: ");
      Buton2 = Serial.read();
    }
    if (Buton1 == '0' and Buton2 == '1')
    {
      digitalWrite(digitalOutPin, 255);
    }
    else if (Buton1 == '0' and Buton2 == '0')
    {
      Serial.println("Both buttons are inactive ! Please reset");
      break;
    }
  }
}
Format code, fix typos
Source Link
per1234
  • 4.3k
  • 2
  • 24
  • 44

Serial monitorMonitor "button" implementation

I have a small project and I have some problems. The ideeaidea of the project is the following: I have an LED which is commanded by two "buttons". The buttons are basically 1/0 values which I have to send from serial monitorSerial Monitor. One button command a LDR sensor, which lights up the LED when it'sits value is below 300 (in my code). The other button just lights the ledLED (Value 1) or turnturns it off (Value 0). The buttons are working together, so I have to consider both of them in my statements. The problem is that I cannot play with the serial monitorSerial Monitor to let me input the values for the two buttons separately, he'sit's just looping forever.

const int analogInPin = A0; //LDR PIN
const int digitalOutPin = 13; // LED PIN
int outputValue;

int sensorValue = 0; //

char Buton1; //LDR button
char Buton2; //Blutooth button


void setup() {
  Serial.begin(9600);
}

void loop() {
 while (Serial.available())
  {
    Serial.println("Button1 value: ");
    Buton1=Serial.read();
      if (Buton1 == '1')
        {
          Serial.println("Button2 value: ");
          Buton2=Serial.read();
            if (Buton1 == '1' and Buton2 == '0')
              {
                sensorValue = analogRead(analogInPin);
                outputValue = map(sensorValue, 0, 1023, 0, 255);
                Serial.print ("Sensor: ");
                Serial.println(sensorValue);
                  if (sensorValue<300);
                    {
                      digitalWrite(digitalOutPin, 255);
                    }
              }
              else if (Buton1 == '1' and Buton2 == '1')
                {
                  digitalWrite(digitalOutPin, 255);
                  Serial.print("Both buttons are ON ! !");
                  
                }
        }
      else if (Buton1 == '0')
        {
          Serial.println("Button2 value: ");
          Buton2=Serial.read();
        }
          if (Buton1 == '0' and Buton2 =='1')
            {
              digitalWrite(digitalOutPin, 255);     
            }
            else if (Buton1 == '0' and Buton2 == '0')
              {
                Serial.println("Both buttons are inactive ! Please reset");
                break;
              }
  }
}
const int analogInPin = A0; //LDR PIN
const int digitalOutPin = 13; // LED PIN
int outputValue;

int sensorValue = 0; //

char Buton1; //LDR button
char Buton2; //Blutooth button


void setup()
{
  Serial.begin(9600);
}

void loop()
{
  while (Serial.available())
  {
    Serial.println("Button1 value: ");
    Buton1 = Serial.read();
    if (Buton1 == '1')
    {
      Serial.println("Button2 value: ");
      Buton2 = Serial.read();
      if (Buton1 == '1' and Buton2 == '0')
      {
        sensorValue = analogRead(analogInPin);
        outputValue = map(sensorValue, 0, 1023, 0, 255);
        Serial.print ("Sensor: ");
        Serial.println(sensorValue);
        if (sensorValue < 300);
        {
          digitalWrite(digitalOutPin, 255);
        }
      }
      else if (Buton1 == '1' and Buton2 == '1')
      {
        digitalWrite(digitalOutPin, 255);
        Serial.print("Both buttons are ON ! !");
      }
    }
    else if (Buton1 == '0')
    {
      Serial.println("Button2 value: ");
      Buton2 = Serial.read();
    }
    if (Buton1 == '0' and Buton2 == '1')
    {
      digitalWrite(digitalOutPin, 255);
    }
    else if (Buton1 == '0' and Buton2 == '0')
    {
      Serial.println("Both buttons are inactive ! Please reset");
      break;
    }
  }
}

Serial monitor "button" implementation

I have a small project and I have some problems. The ideea of the project is the following: I have an LED which is commanded by two "buttons". The buttons are basically 1/0 values which I have to send from serial monitor. One button command a LDR sensor, which lights up the LED when it's value is below 300 (in my code). The other button just lights the led (Value 1) or turn it off (Value 0). The buttons are working together, so I have to consider both of them in my statements. The problem is that I cannot play with the serial monitor to let me input the values for the two buttons separately, he's just looping forever.

const int analogInPin = A0; //LDR PIN
const int digitalOutPin = 13; // LED PIN
int outputValue;

int sensorValue = 0; //

char Buton1; //LDR button
char Buton2; //Blutooth button


void setup() {
  Serial.begin(9600);
}

void loop() {
 while (Serial.available())
  {
    Serial.println("Button1 value: ");
    Buton1=Serial.read();
      if (Buton1 == '1')
        {
          Serial.println("Button2 value: ");
          Buton2=Serial.read();
            if (Buton1 == '1' and Buton2 == '0')
              {
                sensorValue = analogRead(analogInPin);
                outputValue = map(sensorValue, 0, 1023, 0, 255);
                Serial.print ("Sensor: ");
                Serial.println(sensorValue);
                  if (sensorValue<300);
                    {
                      digitalWrite(digitalOutPin, 255);
                    }
              }
              else if (Buton1 == '1' and Buton2 == '1')
                {
                  digitalWrite(digitalOutPin, 255);
                  Serial.print("Both buttons are ON ! !");
                  
                }
        }
      else if (Buton1 == '0')
        {
          Serial.println("Button2 value: ");
          Buton2=Serial.read();
        }
          if (Buton1 == '0' and Buton2 =='1')
            {
              digitalWrite(digitalOutPin, 255);     
            }
            else if (Buton1 == '0' and Buton2 == '0')
              {
                Serial.println("Both buttons are inactive ! Please reset");
                break;
              }
  }
}

Serial Monitor "button" implementation

I have a small project and I have some problems. The idea of the project is the following: I have an LED which is commanded by two "buttons". The buttons are basically 1/0 values which I have to send from Serial Monitor. One button command a LDR sensor, which lights up the LED when its value is below 300 (in my code). The other button just lights the LED (Value 1) or turns it off (Value 0). The buttons are working together, so I have to consider both of them in my statements. The problem is that I cannot play with the Serial Monitor to let me input the values for the two buttons separately, it's just looping forever.

const int analogInPin = A0; //LDR PIN
const int digitalOutPin = 13; // LED PIN
int outputValue;

int sensorValue = 0; //

char Buton1; //LDR button
char Buton2; //Blutooth button


void setup()
{
  Serial.begin(9600);
}

void loop()
{
  while (Serial.available())
  {
    Serial.println("Button1 value: ");
    Buton1 = Serial.read();
    if (Buton1 == '1')
    {
      Serial.println("Button2 value: ");
      Buton2 = Serial.read();
      if (Buton1 == '1' and Buton2 == '0')
      {
        sensorValue = analogRead(analogInPin);
        outputValue = map(sensorValue, 0, 1023, 0, 255);
        Serial.print ("Sensor: ");
        Serial.println(sensorValue);
        if (sensorValue < 300);
        {
          digitalWrite(digitalOutPin, 255);
        }
      }
      else if (Buton1 == '1' and Buton2 == '1')
      {
        digitalWrite(digitalOutPin, 255);
        Serial.print("Both buttons are ON ! !");
      }
    }
    else if (Buton1 == '0')
    {
      Serial.println("Button2 value: ");
      Buton2 = Serial.read();
    }
    if (Buton1 == '0' and Buton2 == '1')
    {
      digitalWrite(digitalOutPin, 255);
    }
    else if (Buton1 == '0' and Buton2 == '0')
    {
      Serial.println("Both buttons are inactive ! Please reset");
      break;
    }
  }
}
Bumped by Community user
edited tags
Link
user31481
user31481
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Source Link
Loading