Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Light-Tracking Servo System with Dual Photocells

View and Edit Project In Cirkit DesignerImage of Arduino UNO Light-Tracking Servo System with Dual Photocells

Circuit Documentation

Summary

This circuit is designed to control a servo motor based on the readings from two Light Dependent Resistors (LDRs). The Arduino UNO microcontroller reads the analog values from the LDRs and adjusts the position of the servo motor accordingly. The circuit includes power connections, ground connections, and signal connections to ensure proper functionality.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Servo

    • Description: A servo motor used for precise control of angular position.
    • Pins: gnd, vcc, pulse
  3. Photocell (LDR)

    • Description: A light-dependent resistor used to measure light intensity.
    • Pins: pin 0, pin 1
  4. Photocell (LDR)

    • Description: A light-dependent resistor used to measure light intensity.
    • Pins: pin 0, pin 1
  5. Resistor (10k Ohms)

    • Description: A resistor with a resistance of 10k Ohms.
    • Pins: pin1, pin2
  6. Resistor (10k Ohms)

    • Description: A resistor with a resistance of 10k Ohms.
    • Pins: pin1, pin2

Wiring Details

Arduino UNO

Servo

Photocell (LDR) 1

Photocell (LDR) 2

Resistor 1 (10k Ohms)

Resistor 2 (10k Ohms)

Code Documentation

#include <Servo.h>

// Define the LDR sensor pins
#define LDR1 A0
#define LDR2 A1

// Define the error value. You can change it as you like
#define error 10

// Starting point of the servo motor
int Spoint =  90;

// Create an object for the servo motor
Servo servo;

void setup() {
  // Include servo motor PWM pin
  servo.attach(11);
  // Set the starting point of the servo
  servo.write(Spoint);
  delay(1000);
}

void loop() {
  // Get the LDR sensor value
  int ldr1 = analogRead(LDR1);
  // Get the LDR sensor value
  int ldr2 = analogRead(LDR2);

  // Get the difference of these values
  int value1 = abs(ldr1 - ldr2);
  int value2 = abs(ldr2 - ldr1);

  // Check these values using a IF condition
  if ((value1 <= error) || (value2 <= error)) {

  } else {
    if (ldr1 > ldr2) {
      Spoint = --Spoint;
    }
    if (ldr1 < ldr2) {
      Spoint = ++Spoint;
    }
  }
  // Write values on the servo motor
  servo.write(Spoint);
  delay(80);
}

This code reads the values from two LDR sensors connected to analog pins A0 and A1 of the Arduino UNO. It then compares the values and adjusts the position of the servo motor connected to digital pin 11 based on the difference between the two LDR readings. The servo motor's position is updated in small increments to ensure smooth movement.