learn to post code using </>
int value;
int led=13;
int in=3;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(in, INPUT);
}
void loop() {
value=Serial.read();
if(value=='1' and digitalRead(in) == HIGH){
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
i see several problems with the above code
-
not sure what "in" is. should it be configured as INPUT_PULLUP? (is there a switch connected between it and ground)
-
there's no check using
Serial.available()before reading a value from the serial port -
i hopes it's clearn that the built-in led on pin 13 is active LOW. if a value of 1 is expected to turn it on, it should be set LOW
-
there's a missing closing brace at the end of loop()