HOW TO CONTROL LAMP

hi guys, I am a novice user arduino, here I want to make a light control program. I have to get the program, but only one that could be controlled, how to continue the program? there is another solution?
:relaxed:

char INBYTE;
int LAMP1 = 10; // Pin PB2 = Pin 10 = LAMP 1
int LAMP2 = 11; // Pin PB3 = Pin 11 = LAMP 2
int LAMP3 = 12; // Pin PB4 = Pin 12 = LAMP 3
void setup() {
Serial.begin(9600);
pinMode(LAMP1, OUTPUT);
}

void loop() {
Serial.println("Press 1 or 0 to turn on / off lights");
while (!Serial.available()); // stay here so long as COM port is empty
INBYTE = Serial.read(); // read next available byte
if( INBYTE == '0' ) digitalWrite(LAMP1, LOW);
if( INBYTE == '1' ) digitalWrite(LAMP1, HIGH);
delay(50);
}

kaitokun:
I have to get the program

What program?

but only one that could be controlled

Only one what? Be controlled to do what?

how to continue the program?

What do you mean by “continue” the program?

there is another solution?

To what?

char INBYTE;
int LAMP1 = 10; // Pin PB2 = Pin 10 = LAMP 1
int LAMP2 = 11; // Pin PB3 = Pin 11 = LAMP 2
int LAMP3 = 12; // Pin PB4 = Pin 12 = LAMP 3
void setup() {
Serial.begin(9600); 
pinMode(LAMP1, OUTPUT);
}

void loop() {
Serial.println("Press 1 or 0 to turn on / off lights");
while (!Serial.available()); // stay here so long as COM port is empty 
INBYTE = Serial.read(); // read next available byte
if( INBYTE == '0' ) digitalWrite(LAMP1, LOW); 
if( INBYTE == '1' ) digitalWrite(LAMP1, HIGH); 
delay(50);
}

What does this code do that you don’t want it to do? What does it not do that you want it to do? You’re going to have to give a much better explanation on your problem if you’re looking for help. Also, post code using CODE tags as I have done.

Arrch:

kaitokun:
I have to get the program

What program?

but only one that could be controlled

Only one what? Be controlled to do what?

how to continue the program?

What do you mean by "continue" the program?

there is another solution?

To what?

What does this code do that you don't want it to do? What does it not do that you want it to do? You're going to have to give a much better explanation on your problem if you're looking for help. Also, post code using CODE tags as I have done.

i just say a big sorry,

  1. I get a program from the internet on the LED control with android
  2. of the program, can only control 1 LED
  3. intent of the meaning of "continue", I want to make a control program 3 lights from android, using a 5 volt relay as its switch, from the LED, I assume it was a relay.

so the outline of the question, what you could continue my program to be able to control 3 lights, with the equation, lights = relay 5 volt
4) meaning of the solution, I hope anyone can answer or complete the program I expected (completed)

Sorry, but your posts aren't very easy to understand. You're trying to take the code you have, which gets an input from the Serial monitor and turns an LED on/off based on the input, to be able to control 3 LEDs/relays? If that's the case you'll have to define the protocol. Should the user first enter which device to power on, then enter which state to set it to? In that case, you'll need a state machine. You could define the protocol to accept a number between 0 and 5 which you when then be used like this:

0 - LED1 ON
1 - LED1 OFF
2 - LED2 ON
3 - LED2 OFF
4 - LED3 ON
5 - LED3 OFF

If I'm completely off base in what you are trying to, then perhaps try Google translate or the sub-forum (if it exists) for your native language.

I use google translate,

yes, you are right
0 - LED1 ON
1 - LED1 OFF
2 - LED2 ON
3 - LED2 OFF
4 - LED3 ON
5 - LED3 OFF

i use Bluetooth HC-05 . so the program ? i'm so confused Arrch :drooling_face: :drooling_face:

if( INBYTE == '0' ) digitalWrite(LAMP1, LOW); 
if( INBYTE == '1' ) digitalWrite(LAMP1, HIGH);

This is the relevant portion of the code that needs to be expanded.

so , like this ?

char INBYTE;
int LAMP1 = 10; // Pin PB2 = Pin 10 = LAMP 1
int LAMP2 = 11; // Pin PB3 = Pin 11 = LAMP 2
int LAMP3 = 12; // Pin PB4 = Pin 12 = LAMP 3
void setup() {
Serial.begin(9600); 
pinMode(LAMP1, OUTPUT);
pinMode(LAMP2, OUTPUT);
pinMode(LAMP3, OUTPUT);
}

void loop() {
Serial.println("Press 1 or 0 to turn on / off lights");
while (!Serial.available()); // stay here so long as COM port is empty 
INBYTE = Serial.read(); // read next available byte
if( INBYTE == '0' ) digitalWrite(LAMP1, LOW); 
if( INBYTE == '1' ) digitalWrite(LAMP1, HIGH); 
if( INBYTE == '2' ) digitalWrite(LAMP2, LOW); 
if( INBYTE == '3' ) digitalWrite(LAMP2, HIGH); 
if( INBYTE == '4' ) digitalWrite(LAMP3, LOW); 
if( INBYTE == '5' ) digitalWrite(LAMP4, HIGH); 

delay(50);
}
if( INBYTE == '5' ) digitalWrite(LAMP4, HIGH);

How many lamps do you have?

Arrch:

if( INBYTE == '5' ) digitalWrite(LAMP4, HIGH);

How many lamps do you have?

I was wrong to write

char INBYTE;
int LAMP1 = 10; // Pin PB2 = Pin 10 = LAMP 1
int LAMP2 = 11; // Pin PB3 = Pin 11 = LAMP 2
int LAMP3 = 12; // Pin PB4 = Pin 12 = LAMP 3
void setup() {
Serial.begin(9600); 
pinMode(LAMP1, OUTPUT);
pinMode(LAMP2, OUTPUT);
pinMode(LAMP3, OUTPUT);
}

void loop() {
Serial.println("Press 1 or 0 to turn on / off lights");
while (!Serial.available()); // stay here so long as COM port is empty 
INBYTE = Serial.read(); // read next available byte
if( INBYTE == '0' ) digitalWrite(LAMP1, LOW); 
if( INBYTE == '1' ) digitalWrite(LAMP1, HIGH); 
if( INBYTE == '2' ) digitalWrite(LAMP2, LOW); 
if( INBYTE == '3' ) digitalWrite(LAMP2, HIGH); 
if( INBYTE == '4' ) digitalWrite(LAMP3, LOW); 
if( INBYTE == '5' ) digitalWrite(LAMP3, HIGH); 

delay(50);
}

is it true ?

Simple serial delimited (using a comma ,) test code that can be expanded to control a lot of output pins high/low.

//zoomkat 3-5-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
// CR/LF could also be a delimiter
//send on, or off, from the serial monitor to operate LED

int ledPin = 13;
String readString;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT); 
  Serial.println("serial LED on/off test with , delimiter"); // so I can keep track
}

void loop() {

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      Serial.println(readString); //prints string to serial port out
      //do stuff with the captured readString
      if(readString.indexOf("on") >=0)
      {
        digitalWrite(ledPin, HIGH);
        Serial.println("LED ON");
      }
      if(readString.indexOf("off") >=0)
      {
        digitalWrite(ledPin, LOW);
        Serial.println("LED OFF");
      }       
      readString=""; //clears variable for new input
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

kaitokun:
is it true ?

You tell me. You got the hardware. Does it work as you expect?