#include <LiquidCrystal.h>
// Pin definitions
const int throttlePin = A0; // Throttle potentiometer connected to analog pin A0
const int brakePin = A1; // Brake sensor connected to analog pin A1
const int ledPin = 9; // LED connected to digital pin 9 (PWM)
const int tempPin = A2; // Temperature sensor connected to analog pin A2
const int buzzerPin = 8; // Buzzer for warnings
// LCD pin definitions
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Variables to store sensor values
int throttleValue = 0;
int brakeValue = 0;
int ledBrightness = 0;
int tempValue = 0;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize LED pin as output
pinMode(ledPin, OUTPUT);
// Initialize buzzer pin as output
pinMode(buzzerPin, OUTPUT);
// Initialize LCD
lcd.begin(16, 2);
lcd.print("VCU Starting...");
delay(2000);
lcd.clear();
}
void loop() {
// Read the throttle and brake values
throttleValue = analogRead(throttlePin);
brakeValue = analogRead(brakePin);
tempValue = analogRead(tempPin);
// Convert the throttle value to LED brightness (0-255)
ledBrightness = map(throttleValue, 0, 1023, 0, 255);
// Apply brake logic: if brake is applied, reduce LED brightness
if (brakeValue > 500) { // Assuming a threshold value for the brake sensor
ledBrightness = 0;
}
// Monitor temperature and activate buzzer if temperature is too high
float temperature = tempValue * (5.0 / 1023.0) * 100; // Example conversion
if (temperature > 60.0) { // Example threshold for overheating
digitalWrite(buzzerPin, HIGH);
ledBrightness = 0; // Turn off the LED for safety
lcd.setCursor(0, 1);
lcd.print("OVERHEATING!");
} else {
digitalWrite(buzzerPin, LOW);
}
// Write the brightness to the LED
analogWrite(ledPin, ledBrightness);
// Display values on the LCD
lcd.setCursor(0, 0);
lcd.print("Throttle:");
lcd.print(throttleValue);
lcd.setCursor(0, 1);
lcd.print("Brake:");
lcd.print(brakeValue);
lcd.setCursor(8, 1);
lcd.print("Temp:");
lcd.print(temperature);
// Print values to the serial monitor for debugging
Serial.print("Throttle: ");
Serial.print(throttleValue);
Serial.print(" Brake: ");
Serial.print(brakeValue);
Serial.print(" LED Brightness: ");
Serial.print(ledBrightness);
Serial.print(" Temp: ");
Serial.println(temperature);
// Small delay for stability
delay(100);
}
Loading
ds18b20
ds18b20