0% found this document useful (0 votes)
8 views2 pages

Arduino Servo Control with LDR Sensors

The document contains an Arduino sketch that controls a servo motor based on the readings from three LDR (Light Dependent Resistor) sensors. It initializes the servo and LDR pins, reads their states, and adjusts the servo position depending on whether light is detected by the LDRs. The code also includes debugging information to display the states of the LDRs in the serial monitor.

Uploaded by

Ganesh Wajantri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Arduino Servo Control with LDR Sensors

The document contains an Arduino sketch that controls a servo motor based on the readings from three LDR (Light Dependent Resistor) sensors. It initializes the servo and LDR pins, reads their states, and adjusts the servo position depending on whether light is detected by the LDRs. The code also includes debugging information to display the states of the LDRs in the serial monitor.

Uploaded by

Ganesh Wajantri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <Servo.

h>

// Define components

Servo servo1;

// LDR Sensor Module Pins (Digital Pins)

Const int ldr1 = 2; // Digital output of LDR 1

Const int ldr2 = 3; // Digital output of LDR 2

Const int ldr3 = 4; // Digital output of LDR 3

Void setup() {

// Attach servo

[Link](9);

// Initialize LDR sensor module pins

pinMode(ldr1, INPUT);

pinMode(ldr2, INPUT);

pinMode(ldr3, INPUT);

// Initialize servo

[Link](0);

[Link](9600);

Void loop() {

// Read LDR sensor module digital outputs (HIGH or LOW)


Int ldr1State = digitalRead(ldr1); // LOW = light detected

Int ldr2State = digitalRead(ldr2); // LOW = light detected

Int ldr3State = digitalRead(ldr3); // LOW = light detected

// Check the states of LDRs and adjust the servo dynamically

If (ldr1State == LOW && ldr2State == LOW && ldr3State == LOW) {

[Link](60); // All three lasers on

} else if (ldr1State == LOW && ldr2State == LOW) {

[Link](40); // Laser on LDR 1 and LDR 2

} else if (ldr1State == LOW) {

[Link](20); // Laser on LDR 1 only

} else {

[Link](0); // No lasers detected

// Debugging

[Link](“LDR States: “);

[Link](ldr1State == LOW ? “Light “ : “No Light “);

[Link](ldr2State == LOW ? “Light “ : “No Light “);

[Link](ldr3State == LOW ? “Light “ : “No Light “);

[Link]();

Delay(100); // Add delay for stability

You might also like