1
#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); 
int greenLedPin = 12;
int blueLedPin = 11;
int redLedPin = 8;
int yellowLEdPin = 9;
int lightSensorPin = A0;
int analogValue = 0;
void setup() {
 // put your setup code here, to run once:
 lcd.begin(16, 2); 
 pinMode(greenLedPin, OUTPUT);
 pinMode(blueLedPin, OUTPUT);
 pinMode(redLedPin, OUTPUT);
 pinMode(yellowLEdPin, OUTPUT);
 Serial.begin(9600);
 while (! Serial);
}
void loop() {
 // put your main code here, to run repeatedly:
 Serial.println(analogRead(lightSensorPin));
 analogValue = analogRead(lightSensorPin);
 if (analogValue < 50) {
digitalWrite(redLedPin, HIGH);
 }
 else if (analogValue >= 50 && analogValue <= 99) {
 digitalWrite(yellowLEdPin, HIGH);
 }
 else if (analogValue >= 100 && analogValue <= 300) {
 digitalWrite(blueLedPin, HIGH);
 lcd.print("its bright");
 }
 else {
 digitalWrite(greenLedPin, HIGH);
 lcd.print("its bright");
 }
 delay(3000);
 digitalWrite(greenLedPin, LOW);
 digitalWrite(blueLedPin, LOW);
 digitalWrite(redLedPin, LOW);
 digitalWrite(yellowLEdPin, LOW);
 lcd.clear();
}

I'm very new to this so sorry if its a dumb mistake and I know my LCD is working right, since I have tested it so all the pins are good.

Michel Keijzers
13k7 gold badges41 silver badges58 bronze badges
asked Jan 3, 2019 at 3:54
2
  • 1
    On the Uno, pin 0 and 1 are used for Serial. You can't use pin 1 for Serial in addition to the LCD. What happens if you change the wiring to use a different pin and update the code accordingly? Commented Jan 3, 2019 at 4:20
  • You're welcome. I'm very glad to hear that! I have written a formal answer so that this question can be considered answered by the Stack Exchange system. If you consider it the correct answer, you can "accept" it. Commented Jan 3, 2019 at 5:01

1 Answer 1

1

On the Uno, pin 0 and 1 are used for Serial. You can't use pin 1 for Serial in addition to the LCD. In general, it's best to avoid using pins 0 and 1.

You need to change the LCD wiring to use a different pin and update the code accordingly. For example, if you moved the LCD's RS pin connection from pin 1 on your Arduino to pin 13, you would update this line from:

LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

to:

LiquidCrystal lcd(13, 2, 4, 5, 6, 7);

After that, your LCD should work correctly.

answered Jan 3, 2019 at 4:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.