Manish Kumar Yadav
Published

Controlling Servo motor using LDR

Controlling the position of servo motor using LDR. As the value of LDR increases the position of servo motor increases.

BeginnerProtip24,511
Controlling Servo motor using LDR

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
LDR, 5 Mohm
LDR, 5 Mohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

controlling servo motor position using LDR

Code

controlling servo motor position using LDR.

Arduino
/*project by Manish kumar yadav*/
#include<Servo.h>
int lightval;
int lightpin=A0;
int tm=100;
int servopin=3;
Servo myservo;
int angle;
void setup() {
  Serial.begin(9600);
  pinMode(lightpin,INPUT);
 myservo.attach(servopin);
 pinMode(servopin,OUTPUT);
}

void loop() {
  lightval=analogRead(lightpin);
  Serial.println(lightval);
  delay(tm);
  
  angle= lightval/5;
  myservo.write(angle);
  Serial.println("anlge is");
  Serial.println(angle);

}

Credits

Manish Kumar Yadav

Manish Kumar Yadav

11 projects • 16 followers
Highly skilled Electronics and Communication Engineer, adept Programmer, and creative PCB Designer.

Comments