#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD Configuration
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set I2C address to 0x27 for 16x2 LCD
const int analog = 5;
const int Green = 17;
const int Yellow = 18;
const int Red = 19;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(Green, OUTPUT);
pinMode(Yellow, OUTPUT);
pinMode(Red, OUTPUT);
// Initialize LCD
Wire.begin(); // Initialize I2C
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on backlight
// Display initial message
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("System Ready");
lcd.setCursor(0, 1);
lcd.print("to test POT");
digitalWrite(Green, LOW);
digitalWrite(Yellow, LOW);
digitalWrite(Red, LOW);
delay(100);
}
void loop() {
// put your main code here, to run repeatedly:
float value = analogRead(analog);
float voltage = (value/8191)*3.3; //Dmax = single read mode (12 bits)
Serial.print("Analog value: "); Serial.print(value);
Serial.print("\tVoltage: "); Serial.print(voltage);
Serial.println();
delay(10);
lcd.setCursor(0, 0);
lcd.print("Voltage: ");
lcd.print(voltage);
lcd.print(" V");
delay(10);
if(voltage >=0.1 && voltage <=1.3){
digitalWrite(Green, HIGH);
digitalWrite(Yellow, LOW);
digitalWrite(Red, LOW);
delay(10);
lcd.setCursor(0,1);
lcd.print("GREEN TRIG ");
delay(10);
}
else if(voltage >1.3 && voltage <=2.3){
digitalWrite(Yellow, HIGH);
digitalWrite(Green, LOW);
digitalWrite(Red, LOW);
delay(10);
lcd.setCursor(0,1);
lcd.print("YELLOW TRIG ");
delay(10);
}
else if(voltage >2.3){
digitalWrite(Red, HIGH);
digitalWrite(Green, LOW);
digitalWrite(Yellow, LOW);
delay(10);
lcd.setCursor(0,1);
lcd.print("RED TRIG ");
delay(10);
}
else{
digitalWrite(Green, LOW);
digitalWrite(Yellow, LOW);
digitalWrite(Red, LOW);
delay(10);
lcd.setCursor(0,1);
lcd.print("ALL OFF ");
delay(10);
}
delay(10); // this speeds up the simulation
}