LCD Brighntess

My LCD works fine and so does my program..but it is not that bright and I can barely see it. Can you please help me change the brightness from the code. (Using a potientmter would not be my first choice to control the brightness..I would rather it stay at one brightness level.)

Here is my code:

#include <Servo.h>

const int trigPin = 9;
const int echoPin = 10;


 static unsigned long timer = 0;
  unsigned long interval = 1000;
  static int seconds = 0;

#define LCD_Backlight 9

  
int x = 0;
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

float duration, distance;

//this is the threshold where the sensor will trigger the 
//countdown. If you are getting extra countdowns or the 
//countdown won't start, you may need to adjust this for your sink
int threshold = 20;
Servo countServo;




void setup() {

  Serial.begin(9600);
    lcd.begin();
 
  // Turn on the blacklight and print a message.
  lcd.backlight();

   
  //attach pin 7 to servo and sweep it to indicate that the timer is on
  countServo.attach(7);
  countServo.write(180);
  delay(700);
  countServo.write(0);
  delay(700);
  countServo.write(180);
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600);
}

void loop() {





  
  
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = duration * .0343/ 2;
  Serial.println(distance);

  if (distance < threshold) {
    countdownServo();
    Serial.println("Working");
    
  }
  delay(100);
}



//this moves the servo 4.5 degrees every half second
//to smooth out the movemnt (vs 9 degrees every second)
//for 20 seconds.
void countdownServo() {
  Serial.println("Counting down");

  //start of loop Robojax code for LCD with I2C
  
  lcd.setCursor (0,1); // go to start of 2nd line
 lcd.print("Hello World!");
  //lcd.print(millis() / 1000);
  delay(500);
 //end of loopcode Robojax code for LCD with I2C
  int halfseconds = 19;

  for (int i = halfseconds; i >= 0; i--) {

    countServo.write((int)(i * 4.5));
    delay(500);

    //start of loop Robojax code for LCD with I2C
  lcd.clear();
  
  
   if(millis() - timer >= interval)
  {
    timer = millis();
    seconds++;
    Serial.print("seconds elapsed = ");
    Serial.println(seconds);

  }

  
  lcd.print(seconds);
  lcd.setCursor (0,1); // go to start of 2nd line
 lcd.print("");
  //lcd.print(millis() / 1000);
  delay(500);
 //end of loopcode Robojax code for LCD with I2C
  }

  //reset the servo, clear the queue
  countServo.write(180);

  seconds = 0; 
  lcd.print("You finished!");
  delay(700);
}

Are you referring to the backlight brightness or the contrast adjustment?

The black light brightness and contrast. My background is black and my letters are somehwat grey. I guess its both.

Did you mean "black light" (aka UV) or "back light"?

I meant backlight. Oops.

Please respond guys I need to fix this in the next hour or so.

Normally the backlight is ran at full by a strap bringing Vcc == 5 volt. Contrast is a setting done from a pot, once.

But can you please help me change the brightness and contrast of my LCD in the code?

No. Backligt maye but I never used it, contrast… never heard of. Why do that? Adjust it and that's it.

All I want to do is change the backlight to a lighter color. Its black right now. Please help me do that in my code I posted.

Backlight always has a strap that must be in place. There is no code in the world that can affect the backlight if it is missing, which looks very likeöly to me.
Start looking in the data sheets for the display and check the display library,LiquidCrystal_I2C.h, for useful functions.

engineer123498:
Please respond guys I need to fix this in the next hour or so.

Remember that those responding in this forum are volunteers.

I dont expect anyone can give you an authorative answer, you dont seem to have provided any information on the 'LCD' you are using.

Ok...here is the lcd: 5V Blue Backlight LCD Display Module LCD1602A 16X2 HD44780 for Arduino AVR PIC - Newegg.com

srnet:
...you dont seem to have provided any information on the 'LCD' you are using.

No information about which Arduino is used and how it is powered either.
And no connection diagram/picture.
Leo..

PS code uses I2C, but the LCD in the link does not have an I2C backpack.
It doesn't even have a backlight LED fitted.

I don't see any code telling what pins should be used for the LCD. In Your code pin 9 is assigned to the back light. Check that! But nowhere it's told about the data pins, enable pin etc.

I'm pretty sure that pin 15 on the display needs +5 volt. Look at the pictures of the back side of the display. You can se some pads and the signs "K" (cathode== GND) and "A" (Anode == +5 volt). I'm sure that's the backlight connected there. Check Your wiring!

@Wawa
No backlight? I think I see clear signs of a backlight. An LCD without backlight… Never heard of or seen such a one. A reflective type? It says "Backlight" in the link.

Text says 'blue backlight', but there is no LED soldered to the vias of the board.
I assume the Amazon picture is wrong/misleading.

It also says 'IIC/I2C Serial Interface Adapter is not included'.
But OP is trying to use I2C.

Must see real pictures of the setup.
Leo..

@Wava
Look at the leftmost picture out of those 4. Look at the right side of the LCD. There You see a white tag emerging from under the display. I interpret that as the backlight. My LCD looks like that. I'm sure You know that backlight has nothing to do with I2C or ni I2C.
The vias I also noted. Often there is a strap invold in the neighbourhead.

Railroader:
Never heard of or seen such a one. A reflective type? It says "Backlight" in the link.

I use the 'transflective' LCDs, very good.

They are highly visible in the strongest of direct sunlight and with the backlight on highly visible in dark or dim conditions. As they mostly dont need the backlight on to see them, they are low power too.

Not sure why you would want to use the other types really, unless you are peversly keen on blue displays.

@srnet
What would "transreflective" be? Both reflective and using trans-light, light from behind?
Reflective LCD calls for light from outside. In darkness You would see nothing. Out the 20 LCD I've bought from Ebay they all have the backlight, but not always the needed strap to make it shine…..