/Dino On chrome with Arduino

Dino On chrome with Arduino

Bored at home during confinement? Well to keep myself entertained, I’ve tried to let my laptop play Dino on chrome on its own  (well it happens sometimes power goes off  at my place)

                                                           Demo of playing the Dino

Components Needed

  • Arduino UNO Board
  • light-dependent resistor (LDR) / Photoresistor
  • Servo
  • stickers to tape the sensors on the laptop
  • USB cable to connect Arduino UNO to Laptop

Circuit Diagram and Wiring

Wiring Servo:

  • Connect the ground to GND on Arduino
  • Connect the vcc to +5v on Arduino
  • Connect the s to PIN 9 on Arduino

Wiring the Photoresistor Sensor (LDR)

  • Connect the ground to GND on Arduino
  • Connect the +ve to PIN A5 on Arduino

Software Needed

  • Arduino IDE (https://www.arduino.cc/en/main/software)

Coding the board

  • The Value of the Sensor trigger needs to be verified and depends on the light intensity value from the screen.
    With the serial Monitor, you can verify the value
  • Add the following codes on Arduino Software
#include <Servo.h>
Servo myservo;
int sensorPin = A5;
int sensorValue = 0;
int val;
void setup() {
  // put your setup code here, to run once:
  myservo.attach(9);
  Serial.begin(9600);
  myservo.write(80);
}
void loop() {
  // put your main code here, to run repeatedly:
  sensorValue = (analogRead(sensorPin));
  if (sensorValue < 230) {
    // cactus 
    val = 45;
  }
  else {
    //no cactus
    val = -10                                                                    ;
    myservo.write(val);
    delay(5);
  }
  Serial.println(sensorValue); //debug
  myservo.write(val);
  //delay(15);
}
  • Ensure the programmer is set to “AVR ISP” and the Board is “Arduino UNO”

  • Upload the codes to the Arduino UNO board.

How It works

  • The photo resistor sensor will get the value of light intensity on the screen
  • when a cactus is found on the screen the value of the intensity will be low.
  • Once the value is lower than a predefined value, move the servo to 45degrees to press the spacebar and
  • afterwards move 45 degrees back to release the spacebar.

Testing

To view the dino, check the URL chrome://dino on a chrome browser even if there is no internet

Tadaaa!! Let it play on and relax. 🙂

TAGS: