How to make Automated Dino game using Arduino




Materials:- 


Diagram:-






Connections:-
LDR Sensor Module to Arduino
  • LDR Sensor Module VCC = Arduino 5V
  • LDR Sensor Module GND = Arduino GND
  • LDR Sensor Module DO = Arduino D7
Servo Motor to Arduino
  • Servo Motor VCC = Arduino 5V
  • Servo Motor GND = Arduino GND
  • Servo Motor PWM = Arduino D6

Code


#include <Servo.h>
Servo myservo;
const int ldr = 7;


void setup() {
  pinMode(ldr,INPUT);//define pin as input sensor
  myservo.attach(6);

}

void loop() {
int y =digitalRead(ldr);//read the sensor
if (y==1){
myservo.write(36);
}else{
myservo.write(0);;
}
delay(50);

}