Help with sending serial text string

Hello! I finally got this to send serial strings, but something is not right. The problem is that when I push a button, it sends the string "MODEL 1" continuously and does not stop, it also seems to always send "MODEL 1" even if i push the other buttons.

What I want to do with this is to send simple commands to a rc transmitter that has 9 stored models that I can select via serial command like this.

What have I done wrong here?

int button1 = 1;
int button2 = 2;
int button3 = 3;
int button4 = 4;
int button5 = 5;
int button6 = 6;
int button7 = 7;
int button8 = 8;
int button9 = 9;

void setup(){
Serial.begin(9600);

pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
pinMode(button5, INPUT);
pinMode(button6, INPUT);
pinMode(button7, INPUT);
pinMode(button8, INPUT);
pinMode(button9, INPUT);

digitalWrite(button1, HIGH); 
digitalWrite(button2, HIGH); 
digitalWrite(button3, HIGH); 
digitalWrite(button4, HIGH); 
digitalWrite(button5, HIGH); 
digitalWrite(button6, HIGH); 
digitalWrite(button7, HIGH); 
digitalWrite(button8, HIGH); 
digitalWrite(button9, HIGH); 

}

void loop(){
if(!digitalRead(button1)){
   Serial.print("MODEL 1");
}

if(!digitalRead(button2)){
   Serial.print("MODEL 2");
}

if(!digitalRead(button3)){
   Serial.print("MODEL 3");
}

if(!digitalRead(button4)){
   Serial.print("MODEL 4");
}

if(!digitalRead(button5)){
   Serial.print("MODEL 5");
   }

if(!digitalRead(button6)){
   Serial.print("MODEL 6");
   }

if(!digitalRead(button7)){
   Serial.print("MODEL 7");
   }

if(!digitalRead(button8)){
   Serial.print("MODEL 8");
   }

if(!digitalRead(button9)){
   Serial.print("MODEL 9");
}
}

Make sure your button wiring is correct. If you press a button, does the input go HIGH or LOW. Do some debugging with the serial monitor to find out.

You need to sense a transition on each button to trigger an action - currently you are looping as fast as possible doing the action for the whole duration of the button push.u

You are using pin 1 which is the TX pin as well - probably a good idea not to.

You'll find other threads about sensing button transitions, you need a state variable to do this that records the last value you read for the button, you test for a change, not a steady state, by comparing current state to previous.

Not using pin 1 made things a lot better, thanks :) :blush: Now the correct model appears and stops looping when I release the buttons.

Now, if I want to halt or delay everything while I hold a button, how do I do this?

I tried this:

if(!digitalRead(button2)){
   Serial.print("MODEL 2");
   delay(2000);
}

It works, but I feel that this is the stupid way to do it. EDIT: Typo. I changed to use the "Serial.println" instead, so I got the carriage return, or whatever it is called. I have this running on an Atmega 8 - 16 PU, using the internal oscillator at 8 mhz. I tried searching but I could not really find anything that I understood on this. However I found some examples that was installed with my Arduino software that it looks like I maybe can learn something from. For example the Debounce and State change detection. Thank you for your help.