Arduino Crane With Emergency Lights

by Nimai122 in Circuits > Arduino

23 Views, 0 Favorites, 0 Comments

Arduino Crane With Emergency Lights

Screenshot 2024-06-18 at 7.52.44 AM.png

⁤I was able to construct an Arduino-controlled crane for this project, and I was able to build this by using a slide switch to turn on the whole component, two servo motors, a joystick, an LCD screen, a 555 timer circuit for panic mode, and a killer button to completely stop after the panic mode is activated. ⁤⁤The slide switch will be used to turn on and off the crane, and a joystick will used for precise movement control. ⁤⁤Real-time status updates will also be displayed on the LCD panel. ⁤⁤In addition, by turning on a slide-switch pin which is connected to the 555 timer circuit, it will act as a panic button, which can let the operator signal people around to move away from the crane and a certain button near the crane can be used to completely stop the crane from moving. ⁤⁤This project creates a flexible and interactive robotic crane by combining a variety of electronic components with coding knowledge. ⁤

Supplies

Click on the names to open the link for the following supplies:-

2 Servo Motors

LCD Display

Arduino

Jumper Wires

Joystick

555 Timer

LEDs

Capacitor

Resistors

BreadBoard

Basic Setup

First, before we start building our components let's make it so that we have all the things ready and organized, after we have done that we will set up basic supplies such as connecting the Arduino Ground(GND) and Power(5V) to the breadboard ground and power port.

For now, let's keep the power port unplugged as we don't want to be shocked or make our circuit spark up while we are building our crane.

Slide Switch (On/Off) and Killer Switch

Screenshot 2024-06-18 at 1.33.07 AM.png
Screenshot 2024-06-18 at 1.31.52 AM.png

Slide Switch

This slide switch will act as an ON/Off switch for the whole Arduino circuit, and the connections are;

  • The middle pin will connect to Pin 3.
  • Any of the other sides can be connected to power(PWR) and ground(GND).


Killer Switch

Since we need a button to be pressed so that the whole crane stops functioning we will be using a pushbutton that will work as a killer switch, the wiring for the following project would be as follows;

  • One leg of the button will be connected to the GND
  • Opposite of that leg of the button will be connected to Pin 9 on the Arduino

10k Ohm resistor if necessary will be connected between the button leg connected to the digital pin and 5V (pull-up configuration) or GND (if using a pull-down configuration).


Just in case you don't have an idea of what a pull-up or pull-down configuration refers to, it's basically a method of connecting a resistor to ensure a known voltage level at a digital input pin when no active signal is present. These configurations prevent floating inputs, which can cause unpredictable behaviour in digital circuits.

Setup the LCD Display

Screenshot 2024-06-18 at 1.35.42 AM.png
Screenshot 2024-06-18 at 1.35.04 AM.png

The LCD we will be connecting has 4 pins and we will be connecting it;

  • VCC to 5V on the Arduino (Red Wire)
  • GND to GND on the Arduino (Black Wire)
  • SDA to A4 on the Arduino (White Wire)
  • SCL to A5 on the Arduino (Brown Wire)

Set Up the Joystick

Screenshot 2024-06-18 at 1.39.13 AM.png
Screenshot 2024-06-18 at 1.39.55 AM.png

As we can now begin setting our actual parts, let's begin by configuring the joystick. The 5-pin joystick I'll be using has the following pin locations: X, Y, Bt, VCC, and GND. To make it easier for you all, I will be pinning it in this manner:

  • VCC (Red Wire): to 5V on the Arduino
  • GND (Black Wire): to GND on the Arduino
  • X (Brown Wire): to A0 on the Arduino
  • Y (Yellow Wire): to A1 on the Arduino
  • Bt (White Wire): to Pin 2 on the Arduino

Setup Both the Servo Motors

Screenshot 2024-06-18 at 1.44.15 AM.png
Screenshot 2024-06-18 at 1.44.55 AM.png
Screenshot 2024-06-18 at 1.45.41 AM.png

The 2 servo motors we are provided have wires brown, orange and red which isn't that hard to wire as it is a bit straightforward with the colours the wires have:

Red Wire on both the servo connects to Power(5V) on the Arduino

Brown Wire on both the servo connects to the ground(GND) on the Arduino

Servo 1 orange pin to Pin 10 on the Arduino

Servo 2 orange pin to Pin 11 on the Arduino

Setup the 555 Timer Circuit

Screenshot 2024-06-18 at 1.07.15 AM.png

The 555 timers we will be using won't be required to work on code, so as it on manual we will just wire it, just so you have an idea, we will be using them as emergency lights, which is to let any workers below to press a button that will turn off the whole crane


The components we will need are:-

  • 555 timer
  • Jumper Cable
  • Capacitor
  • x3 Resistors
  • LED
  • SlideSwitch


Copy the wiring in the tinkercad image

Arduino Code

Before using the code make sure you have the Libraries downloaded for certain components, such as in this case it would be LCD.

#include <Servo.h>
#include <LiquidCrystal_I2C.h>

// Define pins for joystick
const int joystickXPin = A0;
const int joystickYPin = A1;
const int joystickButtonPin = 2; // Optional, if you want to use the button

// Define pins for servos
const int servo1Pin = 11;
const int servo2Pin = 10;

// Define pin for the Killer switch
const int killerSwitchPin = 9;

// Define pin for the slide switch
const int slideSwitchPin = 3; // Example pin for slide switch

// Initialize the servo objects
Servo servo1;
Servo servo2;

// Variables to store joystick positions
int joystickX;
int joystickY;

bool craneOn = false;
bool systemOff = false; // Variable to track system state

// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the address if needed

// Variables to store the current servo positions
int currentServo1Pos = 90; // Start at the middle position
int currentServo2Pos = 90; // Start at the middle position

// Servo speed adjustment
const int servoSpeed = 2; // Adjust this value to change the speed (1 is slow, higher values are faster)

void setup() {
// Start serial communication
Serial.begin(9600);

// Attach the servos to their pins
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);

// LCD initialization
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Crane OFF");

// Set joystick button pin as input (optional)
pinMode(joystickButtonPin, INPUT_PULLUP);

// Set the killer switch pin as input with pull-up resistor
pinMode(killerSwitchPin, INPUT_PULLUP);

// Set the slide switch pin as input with pull-up resistor
pinMode(slideSwitchPin, INPUT_PULLUP);

// Initialize servos to the middle position
servo1.write(currentServo1Pos);
servo2.write(currentServo2Pos);
}

void loop() {
// Check if the Killer switch is pressed
if (digitalRead(killerSwitchPin) == LOW) {
systemOff = true; // Turn off the system
craneOn = false; // Ensure crane is off
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("System OFF");
}

// Check if the slide switch is toggled
if (digitalRead(slideSwitchPin) == LOW) {
systemOff = false; // System is on
craneOn = !craneOn; // Toggle crane state
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(craneOn ? "Crane ON " : "Crane OFF");
delay(500); // Debounce delay
}

// If the system is off, do nothing
if (systemOff) {
return;
}

// If crane is ON, control the servos with the joystick
if (craneOn) {
joystickX = analogRead(joystickXPin);
joystickY = analogRead(joystickYPin);

// Map the joystick values to servo positions
int targetServo1Pos = map(joystickX, 0, 1023, 0, 180);
int targetServo2Pos = map(joystickY, 0, 1023, 0, 180);

// Gradually move servo 1 to the target position
if (currentServo1Pos < targetServo1Pos) {
currentServo1Pos += min(servoSpeed, targetServo1Pos - currentServo1Pos);
} else if (currentServo1Pos > targetServo1Pos) {
currentServo1Pos -= min(servoSpeed, currentServo1Pos - targetServo1Pos);
}

// Gradually move servo 2 to the target position
if (currentServo2Pos < targetServo2Pos) {
currentServo2Pos += min(servoSpeed, targetServo2Pos - currentServo2Pos);
} else if (currentServo2Pos > targetServo2Pos) {
currentServo2Pos -= min(servoSpeed, currentServo2Pos - targetServo2Pos);
}

// Write the new positions to the servos
servo1.write(currentServo1Pos);
servo2.write(currentServo2Pos);
}

// Add a small delay to improve stability
delay(20);
}

Video of It Working

This is a small clip on how its supposed to look and work like.

Downloads