#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.
-
1On 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?per1234– per12342019年01月03日 04:20:24 +00:00Commented 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.per1234– per12342019年01月03日 05:01:01 +00:00Commented Jan 3, 2019 at 5:01
1 Answer 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.