Play Dino On chrome with Arduino

Everyone plays Dinosaur on chrome when there is no internet. One trending project on social media was using an arduino with sensors to jump across the cactus.

Demo of playing the Dino

Components Needed

  • Arduino UNO
  • light-dependent resistor (LDR)
  • Servo
  • stickers to tape the sensors on the laptop

Circuit Diagram and Wiring

Wiring Servo:
– Connect the ground to GND
– Connect the v to +5v
– Connect the s to PIN 9

Wiring the Photoresistor
– Connect the ground to GND
– Connect the +ve to PIN A5

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

#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);
}

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 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

Next step is to improve the code and setup to allow the dinosaur to dodge when there are birds 😀