Devices & Components
Arduino Uno Rev3
IR proximity sensor
Male/Female Jumper Wires
USB-A to Mini-USB Cable
Software & Tools
Arduino IDE
Python 3
Project description
Code
Arduino_Dino_Game_101
arduino
This is the code you need to upload to Arduino board.
1//code by YaSh36. 2 3int IRsensor = A1; 4void setup() 5{ 6 Serial.begin(9600);// Making serial monitor ready to be used by python3 7 pinMode( LED_BUILTIN, OUTPUT); 8 pinMode(A1, INPUT); // IR sensor is connected to analog pin A1. 9} 10 11void loop() 12{ 13 if(analogRead(IRsensor )>500) 14 { 15 digitalWrite(LED_BUILTIN ,LOW ); 16 } 17 else 18 { 19 digitalWrite(LED_BUILTIN ,HIGH ); // Otherwise Turn led ON and Sent "up" command to python3 Thats all ! 20 Serial.println("up"); 21 delay(250); 22 } 23 24}
Python_Dino_Game_101
python
This the code to be used in Python. Make sure you have installed "pyautogui" and "pyserial" prior to execution. Also plaease make sure the 'COM_port' is correctly selected. Mine was COM 4. So, I have written COM4.
1#Code by @yash36(Yash Kumar) 2 3import serial 4import pyautogui 5 6arduino=serial.Serial('COM4', 9600) 7 8while 1: 9 incoming_Data=arduino.readline() 10 if 'up' in incoming_Data.decode('utf-8'): 11 pyautogui.press('up') 12 incoming_Data=""
Arduino_Dino_Game_101
arduino
This is the code you need to upload to Arduino board.
1//code by YaSh36. 2 3int IRsensor = A1; 4void setup() 5{ 6 Serial.begin(9600);// 7 Making serial monitor ready to be used by python3 8 pinMode( LED_BUILTIN, OUTPUT); 9 10 pinMode(A1, INPUT); // IR sensor is connected to analog pin A1. 11} 12 13void 14 loop() 15{ 16 if(analogRead(IRsensor )>500) 17 { 18 digitalWrite(LED_BUILTIN 19 ,LOW ); 20 } 21 else 22 { 23 digitalWrite(LED_BUILTIN ,HIGH ); // Otherwise 24 Turn led ON and Sent "up" command to python3 Thats all ! 25 Serial.println("up"); 26 27 delay(250); 28 } 29 30}
Python_Dino_Game_101
python
This the code to be used in Python. Make sure you have installed "pyautogui" and "pyserial" prior to execution. Also plaease make sure the 'COM_port' is correctly selected. Mine was COM 4. So, I have written COM4.
1#Code by @yash36(Yash Kumar) 2 3import serial 4import pyautogui 5 6arduino=serial.Serial('COM4', 9600) 7 8while 1: 9 incoming_Data=arduino.readline() 10 if 'up' in incoming_Data.decode('utf-8'): 11 pyautogui.press('up') 12 incoming_Data=""
Downloadable files
Dino_Game_Circuit.
Circuit Schematic for connecting IR sensor to Arduino
Dino_Game_Circuit.
Comments
Only logged in users can leave comments