0
#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.

  • 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? – per1234 Jan 3 at 4:20
  • thanks so much this seems to have worked for me – PHANTOM NightCore Jan 3 at 4:41
  • 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 Jan 3 at 5:01
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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.