python code for automate dino game using arduino IDE

In this article we are going to see One another interesting project Topic python code for automate dino game using arduino IDE. 

Mostly Everyone played this Dino game in google chrome in your free time But, what to do if Dino game gets boring too.

So friends let’s  see automate Dino game using python code (Arduino IDE)

Python Code For Automate Dino Game Using Arduino IDE
Python Code For Automate Dino Game Using Arduino IDE

Step 1: Pre- Requirement 

  1. Arduino UNO
  2. Arduino IDE 
  3. Python 3.7
  4. LDR (light dependent resistor)

Step 2 : Procedure:

  • Connect Arduino UNO with LDR  (light dependent resistor) (Note : If you don’t know how they are connect then refer Arduino official site or see on youtube it is very simple process)
  • Then write code for python and arduino 
  •  upload code to analog Read LDR value.
  • Also run python code in python 3.7 as possible

Step 3: Arduino code for automate dino game using arduino IDE

int sensorPin = A0;    //Connect LDR on A0 on arduino UNO 

int sensorValue = 0;  // set variable to store the value coming from LDR

int thresholdValue = 45; //this one depend on your trial and error method. 

void setup() {



void loop() {

  // read the value from the sensor:

  sensorValue = analogRead(sensorPin); //read sensor data 

  //Serial.println(sensorValue);  //uncomment this while first use and take your thresholdValue and set. 


  if(sensorValue <= thresholdValue){   //if condition to detect obstacle.

    Serial.println(1);                 // printing if condition it  is true. 


  delay(30);                         //delay 30ms


How to work LDR for this project python code for automate dino game using arduino IDE :

Place  LDR position on the monitor then read analogValues when an obstacle is present it automatically set that value as thresholdValue and change if condition. 

We need to add a servo motor to press ‘Space bar’ to make Dino jump. But this is quarantine time So, here we are used python code to do this task.

Step 4: python code for automate dino game using arduino IDE

//you fist need to import required library 

import subprocess   

import time

import pyautogui

import serial[r'C:\Program Files\Mozilla Firefox\Firefox.exe',  

    '-new-tab', ''])  

					# Here Add google chrome path for chrome users to open browser and open Dino game. 

time.sleep(6)                 	#give a short time to open and setup all.

print("All sett :)")

ser = serial.Serial('COM4')		#Update with your arduino [port COM4]

ser.baudrate = '9600'			

while True:						# looping. 

  h1=ser.readline() 			#reading serial data. 

  if h1:

   ss = int(h1.decode('utf-8')) # decode and make a int value

   if ss== 1:					# true while obstacle. 

   	print("Oh :< Jump!! ")'up') 		#Auto press [UP] key

And then Run this python code on 3.7 version at that time and fit LDR in appropriate place by trial and error method.

Automated Dino game is ready.Summary : In this project we saw python code for automate dino game using arduino IDE, if any problem about this project then free to ask me
BEST OF LUCK !!!Resource : Arduino official site

Also see following posts

how to conda create with python version 03.10

how to fastly check python version in linux macos windows

which is major new features of the python 3.10 series

python 3-10-0a2 is finally available for testing

python 3-8-6 positional only parameters

I am the founder of Pythonslearning, a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Leave a Comment