I saw somewhere on here (cant remember exactly where) that someone had set up a photo resistor to measure amibent light and dim the LCD's back light accordingly.
I really like this idea and I would like to try it out.
I use LCD's in parallel mode (not yet tried a serial one). I guess the code should be pretty simple - analogue read on the photo resistor, and set it to vary the voltage on a analogue output pin?
I'm unsure on the coding and what type (and where to look) photo-resistor to use?
just looking at the above, I guess the resistance swing would be from 1m ohm to 2-4k ohm, what would be the best way to use that? or are there more suitable ranges? Would I set it up as a voltage divider or directly to one of the analogue inputs?
thanks for the link, which bit do you suggest looking at?
the only relevent bit that I can see is 'Theremin – Use a photocell & piezo as a theremin' but I have no idea what that is doing, or what a theremin is?
Don't power your LCD back light directly with an arduino pin. You need a transistor to drive the current running through the back light, which is too much for the arduino pin to handle directly.
They are essentially electrically controlled open-close switches. You just need to hook the gate to arduino PWM pin and source to ground, drain to back light's current limiting resistor. The turn on and turn off times of this switch are around tens of nano seconds, fast enough for the PWM.
dtokez:
Thanks liudr thats a good point. Just looking at the datasheet for my screens and I think they draw 120mA at max!
Any recommendations on a transistor? I guess it would have to be a fast one if I am to use PWM?
Thanks
Almost any NPN small signal transistor capable of switching 120mA will do the job, e.g. BC337, with a 1K resistor between its base and the Arduino pin. It doesn't need to be a fast transistor because the pwm frequency is low. The 2n7000 mosfet already suggested will also do, however unless you connect a pulldown resistor between the gate and source, then its on/off state won't be well-defined until the Arduino finishes its initialization and sets the mode of the pin driving it.
dtokez:
just looking at the above, I guess the resistance swing would be from 1m ohm to 2-4k ohm, what would be the best way to use that? or are there more suitable ranges? Would I set it up as a voltage divider or directly to one of the analogue inputs?
@dc42 - why do you need to use a 1K resistor? and how did you come to this value? I'm not questioning your intelligence in any shape or form I just like to learn
excellent I will set it up as a divider then
Because the resistance swing is so great, how would I calculate the value of the other resistor in the divider?
dtokez: @dc42 - why do you need to use a 1K resistor? and how did you come to this value? I'm not questioning your intelligence in any shape or form I just like to learn
When driving a transistor used as a switch from an Arduino pin, you need to use a resistor in series with the base to limit the current. The current needs to be enough to make the transistor saturate, so you want somewhat more than Ic/hfe where Ic is the collector current (which you said was 120mA max) and hfe is the transistor gain at the collector current. The minimum hfe for a BC337 at 120mA is around 100, so the base current needs to be more than 1.2mA. A 1K resistor gives about 4.3mA, which means the transistor will be sufficiently overdriven to put it well into saturation.
dtokez:
Because the resistance swing is so great, how would I calculate the value of the other resistor in the divider?
You can't really calculate it. You could measure the resistance of the LDR at the minimum required light level and use than; or just experiment with different resistors, perhaps starting at a value around the geometric mean of its maximum and minimum values.
If you use a 2N7000, you don't need a "base resistor" since the gate (in place of base on the BC337) is not conducting direct current. You use voltage (0v/5V) to close or open the transistor for the back light. In case of BC337, you use current (0mA/4.3mA) to close or open the transistor for the back light.
@dc42, I only used 2N3904 for this type of application. Is BC337 just better in current and voltage specs or is there anything else that makes it your preferred NPN BJT? Just curious to learn here.
liudr: @dc42, I only used 2N3904 for this type of application. Is BC337 just better in current and voltage specs or is there anything else that makes it your preferred NPN BJT? Just curious to learn here.
2n3904 is OK for switching small currents (hfe = 100 minimum at 10mA) but its hfe drops off at higher currents (hfe = 30 minimum at 100mA). BC337 provides good hfe at higher currents (e.g. 100 minimum at 100mA, 60 minimum at 300mA), which is exactly when you need it (to keep the base drive current drawn from the Arduino pin reasonable). So BC337 is more versatile because it is suitable for switching a wider range of current. That's why I keep BC337/BC327 in preference to 2n3904/2n3906. Others on this forum have previously pointed out that there are other low-cost transistors available that can switch an even wider range of current.
Thanks dc42. I'll get some BC337 then. My attitude towards back light is: enough is enough, no need to make it into a light source. On the other hand, a glowing back light does offer a visual appeal, especially with RGB back light, color could mean different situations.
liudr:
Thanks dc42. I'll get some BC337 then. My attitude towards back light is: enough is enough, no need to make it into a light source. On the other hand, a glowing back light does offer a visual appeal, especially with RGB back light, color could mean different situations.
Agreed. I have a couple of RGB backlight LCD displays I recently bought from eBay, and since the RGB leds need 100 and 150 ohm series resistors, they can be driven directly from Arduino pins. Setting the backlight red and flashing it is very attention getting!
Yes. The value of the resistor you need for the other half of the voltage divider depends on what LDR you use, but that LDR looks fairly typical, so somewhere in the range 10K to 100K should be about right.