LED dimming affects sensor data

Hello,

I've just started playing around with my brand new Arduino Mega 2560 and - after some success - run into a problem I do not understand. Before I explain it I should mention that I'm absolutely new to Arduino, working with micro controllers and electrics in general so no background about volts/watts/amps/... is available, just starting from scratch... :wink: I've got a ITDB02-3.2s LCD screen with touch pad connected to my Arduino board without any shield -> first success :wink: Then I got a DHT11 temperature/humidity sensor connected, too -> second success. Finally I got the data from the sensor to be shown on the LCD -> third success :wink:

Ok, here's my problem. I control the LCD with the UTFT library and figured out that turning the lcd on and off in the code did not work. Searching the net I found a sollution and it also lead me to the idea to control the brightness of the background lights - LEDs - by connecting the LED pin of the screen to an transistor which I control over Arduino's PWM port 8. Running this setup I'm able to dim the LCD's background light. So far so good but I had to figure out that the results of the measurements through the DHT11 sensor are getting affected by the puls (correct term?) I set at the PWM port. An example would be:

  • Having defined an output of 255 on the pin, the sensor reports: Temperature: 24 | Humidity: 34
  • Having defined an output of e.g. 115, the sensor reports: Temperature: 26-27 | Humidity 36-37

I did several test runs so I can confirm that the different setting on the PWM port affects the data comming from the sensor.

Here's my question: What's going on? :wink: I have no glue why the settings on the PWM port affects the readings from the sensor. Could somebody please help me figuring out what's happening and how to prevent this? I would be highly thankfull.

Greez,

dialsc

Please post your schematic so we can see how everything is wired up.

dialsc:
Here's my question: What's going on? :wink: I have no glue why the settings on the PWM port affects the readings from the sensor. Could somebody please help me figuring out what's happening and how to prevent this? I would be highly thankfull.

Most likely a decoupling problem.

Try putting a big ceramic capacitor across the wires that power the sensor (+5V and GND). Maybe another one between the screen LED's anode and ground.

Hello,

First of all, thank you very much for your very fast answer. majenko asked me to post my schematic but I cannot right now. Currently I'm fighting with getting the basic knowledge of how to do all those things, e.g. creating such a schematic file... :wink: What I can do right now is making some images and attache them.

The tip of using ceramic capacitor is what I did already for the sensor. According to the data sheet of the sensor I used a 100 Nanofarads capacitor. The power for the sensor is taken from Ardunio's 5V pin.

Does the images help you to get an idea of what I did? There are four images I took but I have to upload them in three more iterrations as the file sice is too big.

Greez,

dialsc

BTW: Is there a good tool to create such schematic files? One that doesn't kost that much?

Image #2

Image #3

Image #4

The digital signal from the sensor consists of long (70uS) and short (28uS) pulses. Timing is critical, so interrupts are disabled by the library (you are using the DHT library, yes?).

Also, noise could be an issue with that protocol. You have a low for a period, then a high for a period - the period of that high, up until it goes low, is what determines if it's a 0 or a 1. If you get a bit of noise, that period could be measured wrongly.

If it is the PWM signal inducing noise, you could try to counter it by reducing the pull-up resistor on the data line to say 4.7K?. You could also try ensuring that your PWM signal is as far away from the data line as practicable.

I tried now with a 4.7K? pull-up resistor but without success. Then I took the data line cable and changed its pin from 7 to 13 on the Arduino board. Unfortunately this did not solve the problem. Do you see anything else I could try?

  1. Decoupling capacitors should be connected as close to the device they are decoupling as possible. Plug that 100nF capacitor directly into the same 2 breadboard rows that the DHT11 is plugged into.

  2. Use one ground pin on fhe Mega to connect just the DHT11 and its decoupling capacitor. Use a different one to connect the backlight or the transistor controlling the backlight. Similarly for the +5V supply.

The above changes will reduce the extent to which the switched backlight current induces noise on the DHT22 power and ground lines, which may be what is causing the problem.

Oh, and for schematics... There is a free version of Eagle for more "normal" schematic capture, or for basic stuff, there is Fritzing which is very Arduino friendly (it's what does those breadboard schematic pictures you often see).

fungus:

dialsc:
Here's my question: What's going on? :wink: I have no glue why the settings on the PWM port affects the readings from the sensor. Could somebody please help me figuring out what's happening and how to prevent this? I would be highly thankfull.

Most likely a decoupling problem.

Try putting a big ceramic capacitor across the wires that power the sensor (+5V and GND).

Not too bad an idea, but the source of the noise should be tackled first, the LED backlight.

Maybe another one between the screen LED's anode and ground.

You decouple the supply, not the switching voltage - so this is only appropriate if the LED is being switched on the low-side - do we know that? In fact something big like 220uF really close to the transistor that's
switching the PWM to the backlight - across the supply, not the LED! The idea is to soak up the heavy current pulses at source and not export them to the rest of the supply rails on other boards.

dialsc:
BTW: Is there a good tool to create such schematic files? One that doesn't kost that much?

If you have a PC, ExpressSCH is easy to use (and free):

http://www.expresspcb.com/expresspcbhtm/Free_schematic_software.htm

Okay, I moved the ceramic capacitor directly infront of the DHT11 sensor. I also tried to use as few as possible cables. The sensor was already conected to a dedicated ground pin on the Arduino board. Things look like getting better now. Instead of having temperature and humidity data with a difference of 2-3 when dimming the back light it's now only the humidity that has a difference of something betwenn 0.5 and 1. It's kind of hard to know as the sensor's resolution is 1.0.

Think we got near the sollution :wink: Anything else someone could think of what I also could try? Maybe another capacitor or something like that? Sorry for the dump question but in fact I even do not know what this little thing made of ceramic is actually doing there... :wink:

Oh, and thanks for the info about the software for the schematics. I'll take a look to each one and check if I will be able to cope with one of them.

Greez,

dialsc

Hello,

I started playing with Fritzing and attached you'll find the circuit I've created using breadboards. I hope it's okay, it's my first one... :wink:

Does anybody see the problem this way? I still get different values when changing the PWM signal to dimm the LCD's back light LEDs.

Disconnect the red 5V wire that connects the two breadboards. Your sensor and led breadboards should make separate ground and 5V connections to the Arduino.

Hi,

I did so, at least I think. Please see the updated layout image. The ground for the two is allready seperated, isn't it.

Unfortunately this made things even worse. The temp is now fluctuating more as well as the humidity is. The data retrieved from the sensor now looks more instable.