#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
// I2C LCD configuration
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Servo motor configuration
Servo servo1;
Servo servo2;
// Relay pin
const int relayPin = 9;
// Analog input pins
const int key = A0;
const int sw = A1;
void setup() {
// Initialize LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Safety Helmet");
delay(5000);
// Attach servo motors to pins
servo1.attach(6);
servo2.attach(7);
// Set relay pin as output
pinMode(relayPin, OUTPUT);
// Set up analog input pins
pinMode(sw, INPUT);
pinMode(key, INPUT);
}
void loop() {
// Display starting message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Ready to Start");
// Check for inputs
if (digitalRead(sw) == HIGH && digitalRead(key) == HIGH) {
lcd.clear();
lcd.print("Helmet Status OK");
digitalWrite(relayPin, HIGH); // Turn on relay
// Move servo motors from 0 to 90 degrees
for (int angle = 45; angle <= 180; angle++) {
servo1.write(angle);
servo2.write(angle);
delay(15);
}
lcd.clear();
lcd.print("Fuel On");
lcd.setCursor(0, 1);
lcd.print("Engine On");
}
else if (digitalRead(sw) == HIGH && digitalRead(key) == LOW) {
lcd.clear();
lcd.print("Helmet Status OK");
digitalWrite(relayPin, LOW); // Turn on relay
lcd.setCursor(0, 1);
lcd.print("Ready To start");
delay(500);
servo1.write(45);
servo2.write(45);
}
else if (digitalRead(sw) == LOW && digitalRead(key) == HIGH) {
lcd.clear();
lcd.print("Please");
digitalWrite(relayPin, HIGH); // Turn on relay
lcd.setCursor(0, 1);
lcd.print("Wear Helmet");
delay(500);
servo1.write(45);
servo2.write(45);
}
else {
lcd.clear();
lcd.print("Fuel Off");
lcd.setCursor(0, 1);
lcd.print("Engine Off");
digitalWrite(relayPin, LOW); // Turn off relay
// Return servo motors to initial position
servo1.write(0);
servo2.write(0);
delay(15);
}
delay(1000);
}