how to connect ldr with arduino

i want to connect my LDR with the arduino without using any resistor or other things as shown in the figure, i just want to use hook-up wires and breadboard.
can any one help me doing this?
i also want a code with it library to test my ldr .

No.

356a244bde91460d4aa2a09b3b5903b2ae41e856.png

Well that diagram does not show an LDR, so I am not sure how it helps.

However, connecting the LDR is simple - just connect it between an analog input pin - any from A0 to A3 - and ground.

Use it in code like this:

#define LDR1 A0

int ldrval;

void setup() {
  // Your other setup code
  pinMode(LDR1, INPUT_PULLUP);
}

void loop() {
  // previous loop code
  ldrval = analogRead(LDR1);
  // following loop code
}

The resistor on the right is for the LED backlight, if you do not need a backlight (illuminated display) then you can omit that.

The LCD contrast pin is trickier to eliminate as a bias voltage is needed between 0V and 5V to set the contrast and this is normally set by a potentiometer (pot) or one/two resistors. Some success has been achieved using a PWM pin.

It might also be possible to use the Arduino UNO AREF pin as bias source since the voltage on this pin can be set by changing the reference, eg:

analogReference(INTERNAL1V1);

But the that pin is not really designed to sink even a small current, the contrast might not be ideal and it will mess up the analogue measurements!

Some LCDs are readable with the contrast pin connected to 0V, others like a bias level of about 0.5V.

Caveat: I have not tried any of this myself. Pots (or a single "select on test" bias resistor to 0V) are cheap and is the correct solution so why not use one!

Ah!

There's another slant on the question - a LCD, not a LDR!

Well, that's easy.

Check that Resistor R8 on the LCD is labelled "101". That means that you can connect pin 15 directly to +5 V, the resistor shown is superfluous.

Connect pin 3 to ground. The LCD should be legible, but may not be fully clear. Try resistors 100 to 330 Ohms between pin 3 and ground if and when you have them to find the best legibility; the potentiometer is not really necessary.


ayshaalrayes: i also want a code with it library to test my ldr .

It's on the page you found that terrible diagram!

Hi everyone

i am using an LCD that is connected to an arduino, and i am using this diagram as a reference

when i run LiquidCrystal Library - Hello World nothing is shown on the LCD

can u please help me

Arduino LCD_bb.jpg

a5f29706dc6d3512749311acdbc4ac0d4d4402c1.jpg

Did you not like the previous answers?

What does “nothing is shown on the LCD” actually mean?

i used another diagram to connect the LCD with the arduino that does not include resistor, but it also des not work.

nothing is showing on the LCD means that the code i have apload it on my arduino does not show a hello world on my LCD screen.

ayshaalrayes: I used another diagram to connect the LCD with the Arduino that does not include resistor, but it also does not work.

Let me explain how using this forum works.

You are given an explanation of what to do to correct the problem that you describe. You follow the instructions given; (there may be alternate things suggested by different people, in which case you should perhaps try one suggestion, then try another but) in each case you must describe what happens when you follow those instructions. If you do not do this, then it is impossible to assist you.

Unfortunately, sometimes apparently well-meaning suggestions given here will be wrong and actually make the problem more diffcult. :roll_eyes:

In the case of the instructions I gave, did you determine what is written on the resistor "R8" on the back of the LCD module? Did you then make the connection I instructed?

Did you connect pin 3 of the LCD to ground? What showed on the display?

ayshaalrayes: Nothing is showing on the LCD means that the code I have upload it on my Arduino does not show a hello world on my LCD screen.

Perhaps not, but in order to determine what is the problem, you must tell what it does show.

This means, does the backlight light up?

Does it show any form of dark "blocks" on the screen?

Does it show one line of blocks, or two?

Are there any visible characters in those blocks?

If the alterations to the first circuit that I described do not work, then the second circuit will definitely not function as it completely relies on the code (which you have not given to us) working correctly.

PWM contrast seems to work very well, so if you have the resistor that Paul mentioned fitted on the PCB then you can completely avoid other discrete components.

I used a Mega and just wired Arduino pin 7 direct to V0 (LCD pin 3) and then by experiment found a PWM value of 150 works well.

I tried pin 13 too as that runs at a higher PWM frequency but then I got display flicker, no doubt due to the aliasing between the segment drive waveform and the PWM frequency. Pin 7 showed no discernible flicker though.

This is the code based on the “Display” example:

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("PWM contrast");

  // Arduino pin 7 is wired direct to V0 (pin 3 of LCD)
  analogWrite(7, 150); // Set the contrast (150 looks good)
}

void loop() {
  // Turn on the display:
  lcd.display();
  while(1);
}

So the answer is “yes” you can avoid all discrete components.

Sorry for not understanding how does the forum works. i am only a beginner on arduino and this is my first time using it. yes i have tried what you said by grounding pin3. on the LCD i got a one row of blocks with no characters. so what are your suggestion ? thank you

ayshaalrayes:
I have tried what you said by grounding pin3.
on the LCD I got a one row of blocks with no characters.

So, we are actually getting somewhere now! :grinning:

I now presume you have in fact checked resistor R8, found it to indeed be “101” and connected pin 15 directly to Vcc, so you have the backlight working (otherwise it is very difficult to see the display).

The “row of blocks” tells us that the contrast (pin 3) is set more-or-less correctly and should be ready to display characters. The fact that it is there and on the first line only indicates that you are failing to communicate with the controller on the LCD module.

This means that either the connections are incorrect, or the code is incorrect or simply does not match the connections.

I now want you to do two things. I want you to tell me to which UNO pins each of the LCD pins 4, 6, 11, 12, 13 and 14 connect and confirm that pin 5 is connected to ground.

Then I want you to post the actual code you are trying to use by copying it from the IDE to inside a pair of code tags (using the “</>” icon above the reply window) in your reply.

OK?

i have connected the pins as following :

LCD pin 4 to digital pin 12
LCD pin 6 to digital pin 11
LCD pin 11 to digital pin 5
LCD pin 12 to digital pin 4
LCD pin 13 to digital pin 3
LCD pin 14 to digital pin 2

and i used this code " Hello World "

#include <LiquidCrystal.h>
#include <SPI.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
 // set up the LCD's number of columns and rows: 
 lcd.begin(16, 2);
 // Print a message to the LCD.
 lcd.print("hello, world!");
}

void loop() {
 // set the cursor to column 0, line 1
 // (note: line 1 is the second row, since counting begins with 0):
 lcd.setCursor(0, 1);
 // print the number of seconds since reset:
 lcd.print(millis()/1000);
}

Well, the code does seem to match the wiring though I am not sure how the “#include <SPI.h>” came to be in there as it is not relevant to this device.

There is a minor problem with that code, but it need not concern us now. There must be a problem with the connections, which leads me to two comments. One is that you should try a different set of jumper wires for connections to pins 4 to 14 of the LCD in case one of them is faulty.

The other however and perhaps more to the point, is to ask how you have the LCD module connected to the breadboard. To connect a module to the breadboard, it must have a set of pins soldered into the holes on the module. Can you confirm that your pins are actually soldered to the LCD board as it will quite certainly not work if they are not?

A perfectly focussed photograph of your whole assembly, photographed in good outdoor daylight (but not direct sun) might be useful to confirm the soldering of the pins.

First step code for testing:

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  /* // First test without loop code
    // Do not update the display too frequently
    delay(300);
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    // print the number of seconds since reset:
    lcd.print(millis() / 1000);
  */
}

This will print just the first line if connections are correct.

thankyou very much, it seems that the wire connection was not connected well. i tried it again and it worked perfectly

I think we figured that. You may now modify the title on your first post to add the word "(Solved!)". :grinning: