Saturday 6 April 2024

Arduino and LDR module Interfacing

Interfacing Arduino with LDR module to activate servo motor


Circuit: (Arduino with LDR as input and servo motor as output)

Arduino Code:

#include <Servo.h> 

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

const int LDRpin = 4;

void setup() { 
   myservo.attach(5); // pin 5 of Arduino with servo motor
   pinMode(LDRpin, INPUT);
   myservo.write(0);
   delay(500);
   myservo.write(90);
}

void loop() { 
  if(digitalRead(LDRpin)==0)
     myservo.write(0); // tell servo to go to a particular angle
  else
    myservo.write(90);
}


Video:







No comments:

Post a Comment