Automatic parking area lighting system

Joined
Apr 22, 2023
Messages
4
Reaction score
0
Hi, can have a question about my code. I have written a code for the lighting system (if Day the led light will turn off, the LCD will show the day led turned off, and when dark the led will turn on, and the LCD will show the night led turned on). Then I need to add a notification if there is a led faulty the red led will turn on and show which led is faulty (in this part I already wrote in the code but it is not working). Can you help me to check thank you very much.

#include <LiquidCrystal.h>
// include liquid crystal library
const int rs = 12, e = 11, db4 = 5, db5 = 4, db6 = 3, db7 = 2;
LiquidCrystal lcd(rs, e, db4, db5, db6, db7);
//LCD Pins connection
int ldrPin = A0;
int ledPin1 = 6;
int ledPin2 = 7;
int ledPin3 = 8;
int ledFaulty = 9; // Pin for LED faulty status

void setup()
{
lcd.begin(16, 2); // Set lcd number of row and column
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledFaulty, INPUT_PULLUP); // Set pin for LED faulty status as input with internal pull-up resistor
pinMode(ldrPin, INPUT);
}
void loop()
{
int ldrStatus = analogRead(ldrPin);

bool led1Faulty = digitalRead(ledFaulty); // Read the status of ledPin1
bool led2Faulty = digitalRead(ledFaulty); // Read the status of ledPin2
bool led3Faulty = digitalRead(ledFaulty); // Read the status of ledPin3

// Turn off the red LED and display error message on the LCD if any of the LED pins is faulty
if (led1Faulty || led2Faulty || led3Faulty)
{
digitalWrite(ledFaulty,HIGH);
lcd.setCursor(1, 0); // Set lcd cursor to the second row and first column
lcd.print("LED"); // Display the message "LED" on the LCD
if (led1Faulty)
{
lcd.print("1"); // Display "1" on the LCD if ledPin1 is faulty
}
if (led2Faulty)
{
lcd.print("2"); // Display "2" on the LCD if ledPin2 is faulty
}
if (led3Faulty)
{
lcd.print("3"); // Display "3" on the LCD if ledPin3 is faulty
}
lcd.print(" faulty"); // Display "faulty" on the LCD
}
else
{
digitalWrite(ledFaulty, LOW); // Turn off the red LED if none of the LED pins is faulty
if (ldrStatus <= 200)
{
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
Serial.print("It's BRIGHT, LED turn off : ");
Serial.println(ldrStatus);
lcd.setCursor(1, 0); // Set lcd cursor to the second row and first column
lcd.print("DAY !"); // First line message
lcd.setCursor(1, 1); // Set lcd cursor to the second row and second column
lcd.print("LED turn off "); // Second row message
}
else
{
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
Serial.print("It's DARK, LED turn on : ");
Serial.println(ldrStatus);
lcd.setCursor(1, 0); // Set lcd cursor to the second row and first column
lcd.print("NIGHT!"); // First row message
lcd.setCursor(1, 1); // Set lcd cursor to the second row and second column
lcd.print("LED turn on "); // Second row message
}
}
}
 
Joined
Apr 6, 2023
Messages
21
Reaction score
0
While checking if any led pin is faulty, we can pass ledPin1, ledPin2, ledPin3 in the digital Read method.
Code:
bool led1Faulty = digitalRead(ledPin1); // Read the status of ledPin1
bool led2Faulty = digitalRead(ledPin2); // Read the status of ledPin2
bool led3Faulty = digitalRead(ledPin3); // Read the status of ledPin3
 
Joined
Apr 22, 2023
Messages
4
Reaction score
0
16821622802844506921330482824738.jpg

This is the first pic means day
16821623211267414260853174843023.jpg

If night the lcd has problem
 

Attachments

  • 16821621615921486087022560742925.jpg
    16821621615921486087022560742925.jpg
    166.3 KB · Views: 6
  • 16821621885228440645593396339644.jpg
    16821621885228440645593396339644.jpg
    158.1 KB · Views: 6
  • 16821622120356056827099414160360.jpg
    16821622120356056827099414160360.jpg
    141.1 KB · Views: 6
  • 16821623820886072053096847453363.jpg
    16821623820886072053096847453363.jpg
    173.7 KB · Views: 6

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top