Newbie problem - why LED only flashes shortly and doen't stay on

Hello, I'm an absolute Newbie and just started to make my first steps with Arduino.
I tried to use the following sketch I found in a YT video:

char Incoming_value = 0;
                
void setup() 
{
  Serial.begin(9600);         

  
  pinMode(13, OUTPUT);       
}

void loop()
{
  if(Serial.available() > 0)  
  {
    Incoming_value = Serial.read();      
    Serial.print(Incoming_value);        
    Serial.print("\n");        
    if(Incoming_value == '1')             
      digitalWrite(13, HIGH);  
    else if(Incoming_value == '0')       
      digitalWrite(13, LOW);   
  }                            
} 

Problem is, when I push the button 1 the LED flashes just for a second, same when pushing button 2. In the YT video the LED stay on until the other button for off is pushed.

Can anybody help?

Thanks in advance
Mike

OOPs!

Please edit your post and apply code tags to your code using the </> button; next save your post.

Your topic has nothing to do with Avrdude, stk500 or Bootloader and hence has been moved to a more suitable location on the forum.

I have just tried your code on a Uno and it works OK for me.

Is it possible the code doesn't work properly on a Nano?
I've got a "real" Nano, not a clone.
Maybe the problem comes from the App I use on my mobile to controll the buttons?
I don't know how to post the code of app inventor. I only could show a screen shot.
But I guess this is a wrong topic here

Code for Nano and UNO would be identical, so what it does on one would be the same on the other.

To what "button" are you referring? This appears to be reading from the keyboard on the serial monitor, where you generally have to press "Enter" to get a response.

Seems like you have a problem that is kinda bigger than you thought...

How the information is transmitted from your mobile to the Nano?

Nano doesn´t have bluetooth/wi-fi capabilities unless you have a module to do so. Moreover, as @Paul_B stated, the code that you´ve provided is not prepared to receive information from your mobile, just from your keyboard.

Nothing in your code or description suggested a mobile phone or MIT app inventor. Your code works with the serial monitor, which is what the code you presented would appear to be for.

Please read How to get the best out of this forum and provide full information. You cannot expect helpful responses when the people trying to help you don't know what you actually have.

Maybe post the link to the youtube video so we can see what this is about. But I agree with the answers given above, that code will only work when the Arduino is connected to the computer via USB cable and the serial monitor is used to send the commands.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.