Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Reaction Testing Game using Interrupts and Arduino

By Nischay Malhan July 6, 2015

The interrupts provided by the AVR microcontroller can be used for various purposes.  Many applications can be made by using the ISR. 

Prototype of Arduino based Reaction Time Game

Fig. 1: Prototype of Arduino based Reaction Time Game

This feature of the AVR microcontroller will be used to make an LED following game which will test a user’s reaction time. There will be 4  LEDs and 4 corresponding buttons for each. After the game begins, a timer will start and a random  LED will glow. The user will then have to press the button corresponding to that  LED to turn it off. If the correct button is pressed, another  LED will glow-up but if the wrong button is pressed, a penalty will be added and the same  LED will continue to glow till the correct button is pressed. This will be repeated for a total of 5 turns. Player one will complete his turn and his time will be displayed and the second player will play.. At the end of  the game,  player with minimum time will be declared as the winner.  

Description:
 
16X2 LCD is used in 4 bit mode to provide the user interface. The upper 4 bits are first sent to the LCD  followed by the lower 4 bits and the final result will be printed There will be 5 buttons –  one for starting the game, and the other four for connecting LEDs.
 
The basic idea is that whenever the TCNT of the AVR microcontroller reaches a certain number, an interrupt will be generated. The max TCNT value can be modified to change the time after which the ISR runs and checks for the interrupt condition.
 
Now that the microcontroller is set for external interrupts,  pressing any button will generate one. That interrupt will then be looked for in the vector table of the microcontroller.
 
Time of the players will be counted using CTC mode setting WGM12 in TCCR. F_CPU = 16000000 so set OCR1A = 16000 and prescaler = 1.  Every time the TCNT reaches 16000, 1ms has passed and TCNT is reset. So, interrupt   takes place every 1ms and player time increases every millisecond.
 
To tackle button debouncing, give a delay using _delay_ms() function. Button debouncing is the hardware issue in the state of switching from one state to the other. This may cause interrupts to be executed even when they are not programmed to. Debouncing can be tackled by giving a 10ms delay.

Pin Connections:

Port B and D of the Arduino are used to connect the LCD. Port B is used for connecting the EN and RS and Port D for connecting the 4 data bits.

LCD Pin Connections will be as follows:

(LCD Pin – Arduino Pin)

1) RS – PB2

2) EN – PB3

3) Vcc – 5v

4) Vee – Gnd

5) Vss – Gnd

6) DB4 – PD4

7) DB5 – PD5

8) DB6 – PD6

9) DB7 – PD7

Button Connections:

All the five external interrupts – PCINT0, PCINT1, PCINT2, INT0, INT1 will be used since there are 5 buttons and an independent interrupt needs to be generated for all the five buttons. The 5 buttons (push/switch) will then be connected to the following 5 pins of the Arduino as per following diagram.

>        PD0 or PCINT16

>        PB0 or  PCINT0

>        PD2 or INT0

>        PD3 or INT1

>        PC4 or PCINT12 (for start)

 

Pin Diagram of Arduino Uno

Fig. 2: Pin Diagram of Arduino Uno

Code:
 
The code does all the following:
 
1) GiveCommand() function is used to send command to the LCD and GiveData() for sending  data to the LCD. For example to send a clear LCD command 0x01 is sent using the GiveCommand() function.
 
2) The Init function is used to set all the pre-requisites such as :
 
– Setting the prescaler equal to 1 by enabling WGM (wave generation mode) and CS10 by writing (1<< WGM12)|(1 << CS10)
 
–  Initializing the LCD in 4 bit mode
 
–  Enabling all bits required to enable the interrupt service.
 
3) The SendString() function simply tells what message needs to be printed.
 
4) The Instruction() and Data() functions tell whether the LCD is working in instruction mode or data mode.
 
5) Itoa() function will be used to convert an integer to a string.
 
6) clk() function provides the clock required using enable (EN) high or low.
 
7) The ISR() function is to specify what needs to be done when  an interrupt condition is true.
 
– PCINT0_vect, PCINT1_vect, PCINT2_vect, INT0_vect are arguments corresponding to the buttons chosen above. These tell the microcontroller where to find a certain interrupt in the vector table.

Filed Under: Electronic Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Monte-Carlo simulation error on ADE-XL
  • Identification of a 6 pin smd chip (sto-23-6) marked E2
  • Dynacord enter protect
  • IGBTs without negative gate drive
  • Need suggestions in task NI6363 retrigger (analog trigger)

RSS Electro-Tech-Online.com Discussions

  • Fun with AI and swordfish basic
  • using a RTC in SF basic
  • Does US electric code allow branching ?
  • Faulty heat air gun (dc motor) - problem to locate fault due to Intermittent fault
  • Sump pit water alarm - Kicad 9

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe