Please Help on Serial Program Code

Hello all, very new to Arduino here.

Here I have a simple serial program which is intended to display "the lights are off" when 0 is input into the serial monitor, and "the lights are on" when 1 is input. However, the program simply jumps to the else case when i run this. No matter how much I tweak it.

My only guess is that it's something to do with bytes and the type of input the Serial Monitor accepts???

Code listed below. If you find any errors, I'd appreciate it enormously if you'd also go to the liberty to describe why the correct statement(s) needs to be implemented.

void setup() {
 pinMode(13, OUTPUT);
// the loop function runs over and over again forever
void loop() {
     while(Serial.available() > 0){ 
       int lightControl =;
       if(lightControl == 0)
         digitalWrite(13, LOW);
         Serial.println("Light is off fam");
       else if(lightControl == 1)
         digitalWrite(13, HIGH);
         Serial.println("THE LIGHTS ARE ON ");
         Serial.println("stop writing random numbers pls");

Moderator edit: [code]

[/code] tags added.

You really should have read How to use this forum before posting.

ie Your code and any error messages should always be placed between [code]code tags[/code]. Posting it inline as you have done makes it much harder to read or copy and paste for diagnosis.

It's still not too late to edit your post and do this. You'll make potential helpers much happier. :)

Hah, I’m so stupid to forget Serial only accepts ASCII chars.

Problem resolved!

Thanks to all who took the liberty to read this and not respond.

I've been working over half an hour on this...

Your amount of cuss is incongruous to effort exerted. Post censored.

DrakeHands: Thanks to all who took the liberty to read this and not respond.

Sounds like a back-handed thank you.

I had actually typed a reply telling you what was wrong, including a 'fixed' version of your code, when you posted reply #2, so I aborted.

And, in any case, what is wrong with reading a post and not responding?

It's not as if the OP is paying for his dinner and being ignored by the waiter :)