Project tutorial
Play Dinosaur Game Using Arduino and Python3

Play Dinosaur Game Using Arduino and Python3 © GPL3+

A great project for beginners! You can play Dinosaur game not by pressing any keyboard buttons but by motion of your hand.

  • 12 respects

Components and supplies

Apps and online services

About this project

Project Description:

Most of us have played dinosaur game by google when our internet was not working and if you have not played this game don't worry now can but not in a conventional way pressing buttons but by using motion of your hand. So in this project using hand motion photo resistor sends values to arduino and arduino sends it to python3 and by using famous library of python pyautogui we can perform "up" arrow function :)

How I decided to make this project ?

Recently I watched a video on youtube regarding project which was about Arduino based Hand Gesture Control of Computer and I really wanted to make that project but currently I don't have ultrasonic sensors which was required to make that project. So I read all the stuff how that project works ? and then I thought I can also do that kind of work by using photo resistor (LDR) sensor. And then I decided let's control "up arrow" key and use it in dinosaur game. Most importantly beginners can also try this project which can increase their interest level.

Below is a video I watched recently

Now let's start to make it:

Things required to make this project:

  • One Arduno UNO board
  • Breadboard
  • Photo Resistor also known as LDR
  • 10k ohm resistor
  • Jumper wires

Thats' all


Information Regarding python3:

Now to make this project you need to install python3 on your system for that I recently uploaded a project "Python3 and Arduino Communication" and there I have uploaded stuff regarding how to install python3. If you want to get familiar with python3 and arduino I recommend you to check that project :)

Below is a link of "Python3 and Arduino Communication"

Last Step is to install library pyautogui :

Now you need to install python library pyautogui which will perform "up arrow" function.

After you have succesfully install python3 on your system:

Follow these steps:

  • open command prompt by clicking run as administrator and write

cd C:\Python37

  • Now you need to write below command

python -m pip install --upgrade pip

  • Now this is last command you need to write

pip install pyautogui

Demonstration Video


Arduino CodeArduino
Download the file and paste in your sketch
  This Program is about connecting arduino and python3 for playing google dinosaur game.
  In this sketch simply from using readings of ldr "up" command is sent to python3 which is use by pyautogui library to control 
  up arrow function.

  Note: You may have to change below threshold value based on the light intensity of your room. 
        Also value in delay() function
  By Jalal Mansoori
int ldrValue=0;
int threshold=400; // Your threshold value may be different 
void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);// Getting our serial monitor ready to be use by python3
  pinMode( LED_BUILTIN, OUTPUT); // LED_BUILTIN means led on board connected with digital pin 13
  pinMode(A1, INPUT); //  ldr sensor is connected to analog pin A1

void loop() {
  // put your main code here, to run repeatedly:
  ldrValue=analogRead(A1); // Takes values from ldr sensor
 // Serial.println(ldrValue); // To check which value fits best depending on room light intensity you use this function by uncommenting it
  if(ldrValue> threshold)
    digitalWrite(LED_BUILTIN ,LOW ); // So if ldrValue is greater than 400 threshold then do nothing led will be off
     digitalWrite(LED_BUILTIN ,HIGH ); // Otherwise Turn led ON and Sent "up" command to python3 Thats all !
     delay(500);// you may have to change this value because delay was use to sent only one "up" command otherwise it will send multiple commands. 
Python3 CodePython
Download the file and paste in your python3 file
# Serial library use to connect python3 and arduino
import serial

# pyautogui library will be use to perform "up" arrow function
import pyautogui

#Creates object of Serial class. You may need to change port name
#Check your ardunio sketch in tools section to know port name
arduino=serial.Serial('COM1', 9600)

while 1:

    incoming_Data=arduino.readline() #readline() function will get data from serial monitor line by line
    if 'up' in incoming_Data.decode('utf-8'): #In python3 data needs to convert into byte so decode function is use for that'up')# function to perform up arrow functionality

    incoming_Data="" # reinitialing incoming_Data to empty


Circuit Diagram to make this project
Additional Jumper wires were use to give space for hand motion



Jalal mansoori
Jalal Mansoori
  • 5 projects

Additional contributors

  • Made project tutorial on : arduino based hand gesture control of your computer by RAVI

Published on

January 27, 2019

Members who respect this project

Avatar fofgrbxpczAdambenzPhotoSaulofilhoDefault

and 7 others

See similar projects
you might like

Similar projects you might like

Chrome Dinosaur Game Controlled in Real Life

Project tutorial by Ryan Chan

  • 84 respects

Arduino LCD Video Game

Project tutorial by tylerpeppy

  • 33 respects

A Simple Reflex Game

Project tutorial by rowan07

  • 8 respects

LCD Game

Project showcase by Team Iron_SalsaStudio

  • 44 respects

Chrome Dino Game "Revamped" with arduino and python

Project tutorial by yashastronomy

  • 1 comment
  • 7 respects

Breadboard to PCB Part 1 - Making the Simon Says Game

Project tutorial by Katie Kristoff and Monica Houston

  • 34 respects
Add projectSign up / Login