#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int speedSensorPin = A0; // Analog pin for speed sensor
const int ledBulbPin = 13; // Digital pin for LED bulb
const int buzzerPin = 9; // Digital pin for buzzer
const int speedThreshold = 700; // Threshold for over-speeding detection
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// put your setup code here, to run once:
pinMode(speedSensorPin, INPUT);
pinMode(ledBulbPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
lcd.begin(16, 2);
lcd.print("Speed Monitor");
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int speed = readSpeed(); // Read speed from the sensor
if (isOverSpeeding(speed)) {
indicateOverSpeeding();
} else {
clearIndication();
}
updateLCD(speed);
delay(1000); // Simulate a delay between readings
}
int readSpeed() {
// Simulate reading speed from the sensor
return analogRead(speedSensorPin);
}
bool isOverSpeeding(int speed) {
return speed > speedThreshold;
}
void indicateOverSpeeding() {
digitalWrite(ledBulbPin, HIGH);
tone(buzzerPin, 1000, 500); // Play a tone on the buzzer
Serial.println("Over-speeding detected!");
}
void clearIndication() {
digitalWrite(ledBulbPin, LOW);
}
void updateLCD(int speed) {
lcd.setCursor(0, 1);
lcd.print("Speed: " + String(speed) + " "); // Clear the line and print new speed
}