You may or may not have hardware problems, but that second program probably won’t work as desired. If Serial.available() is < 1, then there are no characters to read. I’d use:```
while (Serial.available() > 0) {…}
The led is shiny bright when I cover the LDR with my hand(serial monitor show ‘2’). But I got a problem with using serial command, as below.
int lead=9;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (Serial.available() >0)
{
char c=Serial.read();
if (c==‘o’)
{
digitalWrite(lead, HIGH);
}
else if(c==‘c’)
{
digitalWrite(lead, LOW);
}
else Serial.println(“Others”);
}
}
When I sent other character not ‘o’ and ‘c’, the serial monitor respond as I desired(“Others”).
When I sent ‘o’, the lead is not absolutely dead, I notice little light that is not bright like in the working program.
That means, the lead in the same pin is bright that is trigger by UNO’s IO (in my sketch LDR) and not(not bright like previous) bright that is trigger by serial command.
In the second sketch, you forgot to set the pin as an output. Therefore, instead of setting it high, you are turning on the pullup, which barely lets through enough current to light the LED.