How to automate the Chrome T-Rex game using Arduino

Arduino code

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int sensorPin = A0;
int sensorValue = 0;

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
}

void loop() {
  sensorValue = analogRead(sensorPin);
  Serial.print("value: ");
  Serial.println(sensorValue);

// compare according to threshld
  if (sensorValue < 200) {
    myservo.write(35); // change according to how much the servo needs to move
    delay(250);
    myservo.write(20); // same as above
  }
}

Or click here to download file with code

Connection diagram

Comments

comments

About Low End Guru 22 Articles
Life long technology enthusiast. Expert in software quality assurance, Fan of the maker movement.