This circuit involves an Arduino Uno R3 microcontroller interfacing with various components including IR sensors, servos, a hobby gear motor, and a 16x2 I2C LCD. The circuit is powered by a 18650 Li-Ion battery. The Arduino controls the servos and motors based on input from the IR sensors and displays information on the LCD.
Arduino Uno R3
IR Sensor
Hobby Gearmotor with 48:1 Gearbox
Servo
16x2 I2C LCD
18650 Li-Ion Battery
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Pin Definitions
const int IR_SENSOR1_PIN = 12; // IR sensor 1 connected to pin 12
const int IR_SENSOR2_PIN = 13; // IR sensor 2 connected to pin 13
bool sensor1Enabled = true; // Variable to track if sensor 1 is enabled
bool sensor2Enabled = true; // Variable to track if sensor 2 is enabled
// Define the servo objects
Servo servo1; // Claw servo
Servo servo2; // Body servo
Servo servo3; // Base servo
// LCD Initialization (I2C address 0x27, 16 columns, 2 rows)
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Attach the servos to their respective pins
servo1.attach(9); // Attach servo1 (claw) to pin 9
servo2.attach(10); // Attach servo2 (body) to pin 10
servo3.attach(11); // Attach servo3 (base) to pin 11
// Set motor control pins as output
pinMode(2, OUTPUT); // Motor 1 direction pin
pinMode(5, OUTPUT); // Motor 1 speed pin
pinMode(4, OUTPUT); // Motor 2 direction pin
pinMode(6, OUTPUT); // Motor 2 speed pin
// Set the IR sensor pin mode to input
pinMode(IR_SENSOR1_PIN, INPUT);
pinMode(IR_SENSOR2_PIN, INPUT);
// Initialize LCD
lcd.init(); // Use init() instead of begin()
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0);
lcd.print("GROUP 7");
lcd.setCursor(0, 1);
lcd.print("FINAL PROJECT");
delay(5000); // Display welcome message for 5 seconds
lcd.clear();
// Initial servo movements with delays
moveServoSlowly(servo3, 80, 5); // Move base (servo3) to 80 degrees slowly
delay(3000); // Wait for 3 seconds before completing the setup
moveServoSlowly(servo1, 130, 20); // Move claw (servo1) to 130 degrees slowly
delay(3000); // Wait for 3 seconds before moving the next servo
moveServoSlowly(servo2, 30, 20); // Move body (servo2) to 40 degrees slowly
delay(3000); // Wait for 3 seconds before moving the next servo
// Continue with further movements
moveServoSlowly(servo3, 20, 5); // Move base (servo3) to 20 degrees slowly
delay(3000);
moveServoSlowly(servo2, 120, 20); // Move body (servo2) to 110 degrees slowly
delay(3000);
moveServoSlowly(servo1, 190, 20); // Move claw (servo1) to 190 degrees slowly
delay(3000);
moveServoSlowly(servo2, 30, 20); // Move body (servo2) back to 40 degrees slowly
delay(4000);
moveServoSlowly(servo3, 50, 5); // Move base (servo3) to 50 degrees slowly
delay(3000);
moveServoSlowly(servo2, 120, 20); // Move body (servo2) to 110 degrees slowly
delay(3000);
moveServoSlowly(servo1, 130, 20); // Move claw (servo1) back to 130 degrees slowly
delay(1000);
moveServoSlowly(servo2, 30, 20); // Move body (servo2) back to 40 degrees slowly
delay(3000);
moveServoSlowly(servo3, 80