Introduction
A Light Follower Robot is an engaging project that demonstrates basic robotics and sensor integration. This robot is designed to follow the light source, making it a great introduction to concepts such as light sensing, motor control, and basic robotics. In this tutorial, we'll walk you through building a simple Light Follower Robot using TinkerCAD and Arduino.
Materials Needed
For this project, you will need:
Arduino Uno
Breadboard
2 DC Motors
L298N Motor Driver Module
2 LDR (Light Dependent Resistors) sensors
2 Resistors (10kΩ)
Jumper Wires
Battery pack (for power supply)
Chassis (can be simulated in TinkerCAD)
Step 1: Setting Up the Components
Arduino and Breadboard: Open TinkerCAD and create a new circuit project. Drag and drop an Arduino Uno and a breadboard onto the workspace.
LDR Sensors: These sensors will detect the light intensity. Connect them as follows:
Connect one LDR to the 5V pin on the Arduino and the other to GND.
Connect the middle pin of each LDR (the output) to analog pins A0 and A1 on the Arduino respectively.
Each LDR should have a 10kΩ resistor connected in series with it to create a voltage divider.
DC Motors: Connect the DC motors to the L298N motor driver module. The motor driver has the following pins:
Motor A: Connect the DC motor terminals to the output pins of the L298N module (OUT1 and OUT2).
Motor B: Connect the second DC motor terminals to the output pins of the L298N module (OUT3 and OUT4).
VCC: Connect to the 5V pin on the Arduino.
GND: Connect to GND on the Arduino.
IN1: Connect to digital pin 3 on Arduino.
IN2: Connect to digital pin 4 on Arduino.
IN3: Connect to digital pin 5 on Arduino.
IN4: Connect to digital pin 6 on Arduino.
ENA: Connect to digital pin 9 on Arduino (PWM for speed control).
ENB: Connect to digital pin 10 on Arduino (PWM for speed control).
Power Supply: Use a battery pack to power the motors, connected to the motor driver module.
Step 2: Wiring Diagram
Ensure your wiring looks like this:
LDR Sensors:
LDR1:
One pin → 5V
Other pin → Analog Pin A0
Series resistor → GND
LDR2:
One pin → 5V
Other pin → Analog Pin A1
Series resistor → GND
L298N Motor Driver:
VCC → 5V on Arduino
GND → GND on Arduino
IN1 → Digital Pin 3 on Arduino
IN2 → Digital Pin 4 on Arduino
IN3 → Digital Pin 5 on Arduino
IN4 → Digital Pin 6 on Arduino
ENA → Digital Pin 9 on Arduino (PWM for speed control)
ENB → Digital Pin 10 on Arduino (PWM for speed control)
OUT1 → Motor Terminal 1
OUT2 → Motor Terminal 2
OUT3 → Motor Terminal 3
OUT4 → Motor Terminal 4
Step 3: Writing the Code
With the components connected, let’s write the Arduino code to make the robot follow the light source.
const int ldrPin1 = A0; // LDR1 connected to analog pin A0
const int ldrPin2 = A1; // LDR2 connected to analog pin A1
const int motorPin1 = 3; // Motor driver input 1
const int motorPin2 = 4; // Motor driver input 2
const int motorPin3 = 5; // Motor driver input 3
const int motorPin4 = 6; // Motor driver input 4
const int speedPinA = 9; // Motor driver enable pin A (PWM)
const int speedPinB = 10; // Motor driver enable pin B (PWM)
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
pinMode(speedPinA, OUTPUT);
pinMode(speedPinB, OUTPUT);
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
int ldrValue1 = analogRead(ldrPin1); // Read value from LDR1
int ldrValue2 = analogRead(ldrPin2); // Read value from LDR2
if (ldrValue1 < ldrValue2) {
// Light is stronger on the right side
// Turn right
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
} else if (ldrValue1 > ldrValue2) {
// Light is stronger on the left side
// Turn left
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
} else {
// Light is centered or equal on both sides
// Move forward
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
}
// Debugging information
Serial.print("LDR1: ");
Serial.print(ldrValue1);
Serial.print(" LDR2: ");
Serial.println(ldrValue2);
delay(100); // Delay for stability
}
Step 4: Simulating the Circuit
After entering the code, click the "Start Simulation" button in TinkerCAD.
Adjust the light intensity around the LDR sensors to see how the robot responds. The robot should follow the light source by changing its direction based on which LDR detects more light.
Monitor the Serial Monitor to see the LDR values in real-time.
Step 5: Understanding the Code
LDR Reading: The analogRead() function reads the analog values from the LDRs, indicating light intensity.
Motor Control: Depending on which LDR detects more light, the robot turns left or right. If the light intensity is equal, the robot moves forward.
Serial Debugging: The Serial.print() and Serial.println() functions display LDR values on the Serial Monitor for debugging purposes.
Step 6: Enhancing the System
You can expand this basic Light Follower Robot with additional features:
Speed Control: Use PWM to control motor speed for smoother operation.
Obstacle Avoidance: Add ultrasonic sensors to avoid obstacles while following the light.
Battery Management: Implement a battery monitoring system to keep track of power levels.
Conclusion
You have successfully built a Light Follower Robot using TinkerCAD and Arduino. This project demonstrates basic robotics concepts, including sensor integration and motor control. By following this guide, you’ve gained valuable experience in building robots that interact with their environment based on sensor inputs.
Want us to guide you through your project or make the project for you ?
Create Various Projects
Check out our Free Arduino Projects Playlist - Arduino Projects
Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects
Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects
Check out our Free IoT Projects Playlist - IoT Projects
Check out our Free Home Automation Projects Playlist - Home Automation Projects
Check out our Free NodeMCu Projects Playlist - NodeMCu Projects
Comentários