Different Modes and Arduino?


I had a question. 

I want to have like 5 buttons and every time I press one button it runs a certain block of code over and over until I press another button. This way I can have different modes etc. mode 1, mode 2. . .
Can somebody help me with the code please?


sort by: active | newest | oldest
1-10 of 20Next »
robobot311222 days ago

You could possible make a principle code and use the IF statement for example-

void setup(){

enter all constants, variables and stuff here (for all the codes)


void loop(){

IF (condition button press 1){

your code


ELSE IF (condition button press 2){

your code


and so on

the only disadvantage i see is that it takes too much space, but it is possible

Nic-SMD1 month ago


I need to make a project but my zero knowledge in programming does not allow me to go far.. For someone with the knowledge and experience may be a code for children :)

My code needs to have three different modes just to activate two relays in a different way at each mode.

Can anyone help please?? I will send a brief description of what I need.


So, let me get this straight:

You want three modes(inputs) to control two relays. Right?

I can help. Let me know a little more about the input mode. Is it a pushbutton? Also what output(Result) you want for each input.


Thanks a lot for offering to help me on that. I can send you a brief description via email if you like to take a full view off what I need.

Alright go ahead.

You can send me the details through personal message on my instructables account.

take a look at this


Hi Anshu,

Any news? Do you think that you can figure out something of this?


Sorry that setup turned out to be lot complicated (for me)

I can write a program to perform a simpler function.

The main obstacle is that the Arduino needs to store some data on which button was pressed earlier.

Apart from this everything is cool.

I can code for a setup that turns on or off the relays and even display the outputs and inputs on the LCD.

But, nothing that complex. Sorry! :(

First of all I am really appreciate your time.

What I have seen so far is that many use multiple void () functions or what they call them. So 3 different void(), one for each mode. And then you call the in void loop() or in a main void(). And I think a counter function to count the times that the button has pressed.

Why Arduino has to know what button has pressed earlier? I am asking because after you select and finish a mode it has to go back in the beginning and can select any mode you want, even the same as previews.

1-10 of 20Next »