Ultrasonic Reaction Time Game Using Arduino and OLED

by devkrishnavhora in Circuits > Arduino

47 Views, 0 Favorites, 0 Comments

Ultrasonic Reaction Time Game Using Arduino and OLED

The Ultrasonic Reaction Time Game is an interactive Arduino-based project that measures a player's reaction time using an ultrasonic sensor.

The player places their hand near the ultrasonic sensor. When the hand reaches a distance of 5 cm or less, the Arduino detects it and starts the reaction timer. When the player moves their hand away from the sensor, the Arduino calculates the time taken and displays the result on an OLED display.

The project is useful for learning about ultrasonic distance measurement, timers, OLED displays, conditional statements, and Arduino programming.

Supplies

Components Required

Deshbot shield

Arduino Uno

HC-SR04 Ultrasonic Sensor

0.96" OLED Display 128×64

Pin Connections


Ultrasonic Sensor

HC-SR04Arduino Uno

VCC - 5V

GND - GND

TRIG - A0

ECHO - D13

OLED Display

OLEDArduino Uno

VCC - 5V

GND - GND

SDA - A4

SCL - A5

Working Principle


The HC-SR04 ultrasonic sensor sends an ultrasonic pulse and measures the time taken for the echo to return.

The Arduino converts this time into distance.

When the measured distance becomes 5 cm or less, the Arduino starts the timer.

The OLED displays:

READY → GO → REACTION TIME

When the player's hand moves farther than 5 cm, the Arduino stops the timer and calculates the reaction time in milliseconds.

The best reaction time is also displayed on the OLED.

Game Flow

START
↓
OLED shows READY
↓
Hand comes within 5 cm
↓
Timer starts
↓
OLED shows "GO!"
↓
Hand moves away > 5 cm
↓
Timer stops
↓
Reaction time calculated
↓
OLED shows result
↓
Best time displayed
↓
PLAY AGAIN

Features

  1. Ultrasonic distance detection
  2. 5 cm detection point
  3. Reaction-time measurement
  4. OLED graphical display
  5. Reaction time displayed in milliseconds
  6. Best reaction time tracking
  7. Simple and interactive game
  8. No external buttons required

Programming Concepts Used

Ultrasonic Distance Measurement

The Arduino uses the HC-SR04 sensor to measure the distance of the player's hand.

micros()

The micros() function is used to measure very small time intervals accurately.

Conditional Statements

The program uses if conditions to determine whether the hand is within or outside the 5 cm detection range.

OLED Display

The OLED displays the current game status, reaction time, and best time.

Variables

Variables are used to store:

  1. Distance
  2. Start time
  3. End time
  4. Reaction time
  5. Best reaction time

Example OLED Output

Ready

READY!

Move hand to
5 cm

Game

GO!

REACTION...

Result

REACTION TIME

247 ms

BEST: 247 ms

Applications

This project can be used as:

  1. A reaction-time game
  2. A classroom electronics project
  3. An Arduino programming demonstration
  4. A STEM learning activity
  5. A demonstration of ultrasonic sensors
  6. A practical example of measuring time using Arduino


Downloads

Conclusion


The Ultrasonic Reaction Time Game combines an Arduino Uno, HC-SR04 ultrasonic sensor, and OLED display to create an interactive reaction-time measurement system.

The project demonstrates how a microcontroller can detect distance, measure time, process the result, and display information to the user. It is a simple project but introduces important concepts used in embedded systems and interactive electronics.