Are you a competitive person? Then here is the perfect mini game for you. With this project you can challenge your friends to see who is faster at pressing a button many times.
READY. SET. GO. THE RACE STARTS NOW.
Table of contents
Explanation and gameplay
The game is very simple. You have to press a button many times until an LED turns on. The challenge is to light your LED before your opponent does. The program is designed so that the first player to press the button 10 times lights their LED and wins.
That is not all. You can also play by yourself by timing how long it takes you to light the LED and trying to improve your result. You can even press each button with a different hand and see which one lights up first.
Overall, this is a very interesting Arduino project for anyone who wants to understand how a button works and how to count button presses with Arduino.
Materials used in the project
The materials used in this project are very simple and should be easy to find. To make things easier, here is a list of all the components.
Below you can find a list of purchase links.
If you have any questions about the materials used in this project, feel free to leave a comment and we will reply as soon as possible.






WE DEVELOP YOUR IDEA
Need help with a project?
- Prototyping and MVPs
- Arduino and ESP32
- PCB design
- 3D part design
- Bluetooth connectivity
- Feasibility study
- Cost optimization
- Technical consulting
- Internet of Things
- Patent support
Step-by-step project video
If you want a more detailed walkthrough of how to build this project from start to finish, including a code explanation, the video below covers everything in a more visual and easier-to-follow way. And if you enjoy this kind of content, do not forget to subscribe.
Arduino wiring diagram for this project
To make the assembly easier, here is the wiring diagram. All the connections shown here match the code placed just below, so make sure your wiring is exactly as shown in the image.
Arduino code for the project
Below you can find the Arduino code developed specifically for this project. The pins used in the code are the same ones shown in the wiring diagram above.
If you want a more detailed explanation of the different parts of the code and how the project works, we recommend watching the video above.
Using this code is very simple. You just need to copy it and paste it into your Arduino compiler, for example the Arduino IDE. If you do not have it installed yet, here is our guide on how to install it for free.
If you have any questions, leave a comment on this page and we will reply as soon as possible.
//Canal de YouTube -> RobotUNO
//Carrera con leds
#define button1 8
#define button2 4
#define led1 9
#define led2 5
int goal = 10, win=0, flag1=0, flag2=0;
int state1 = 0;
int state2 = 0;
int contador1 = 0;
int contador2 = 0;
void setup(){
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop(){
state1 = digitalRead(button1);
state2 = digitalRead(button2);
if(state1 == HIGH && flag1==0){
contador1++;
flag1=1;
}
if(state1==LOW && flag1==1){
flag1=0;
}
if(state2==HIGH && flag2==0){
contador2++;
flag2=1;
}
if(state2==LOW && flag2==1){
flag2=0;
}
if(contador1 == goal && win==0){
for(int i=0;i<10;i++){
digitalWrite(led1,HIGH);
delay(50);
digitalWrite(led1,LOW);
delay(50);
}
digitalWrite(led1,HIGH);
win=1;
}
if(contador2 == goal && win==0){
for(int i=0;i<10;i++){
digitalWrite(led2,HIGH);
delay(50);
digitalWrite(led2,LOW);
delay(50);
}
digitalWrite(led2,HIGH);
win=1;
}
}






