Raspberry Pi + DHT22’s + Relays = Problems

Hi guys,

I have a few questions to ask and I’m hoping there’s someone here who can help me out.

So basically, me and my friend we decided to make a controller that controls the temperature and humidity of room.

At the moment I’m using the official Raspberry power supply for the Raspbery. Then, we have a 12v5a power supply which is connected to a step-down (LM2596) that now converts it to 5v and it connects to a breadboard. This breadboard then supplies the 8 relay board and the three DHT22.

So all the coding is done in node-red and when we testing all seemed fine. I left it on for a few days and it was all good. Then we tried to connect a few lamps to see if the relays were doing its job properly. And everything worked out fine.

When we tried to do the final test, connecting lamps, humidifier, dehumidifier, heater, fans and ventilation system, was when all the system collapsed. For 2 weeks we’ve been testing one by one and try to understand where the problem resides. We found (at least we think we did)! So basically everytime the relay board lets any of the equipment with a motor work, when the relay stop the equipment there’s some sort of spike and messes the communication between the DHT22 and the Pi.

So we decided to buy another power supply 5v2a to make and independent power supply for the relay board. We tested it and we thought we solve the problem. The sad reality is, now it doesn’t freeze the readings straight after the relay shuts the equipment with a motor. Instead it works for about 5 to 10 minutes and then freezes the readings.

After this last test we realized this is not a problem from the code but from power supply/interference.

We’ve been melting our brains for over 6 months and I don’t know what to do anymore. Should I use the power supply from the breadboard and then create an independent power supply for the sensors? Should I have an independent power supply for the Pi, another one for the relay board and another one for the sensors? Does anyone experienced the same problem? All the help is welcome and you guys are my last resort.

Thank you in advance and happy electronics for everyone!

Are the relays opto-isolated from their inputs?

Hi, and welcome to the forum.

You will hear a lot of options and so I am going to throw my thoughts in on this.

1 - Use either FET or OPTO isolators from the RasPI GPIO pins.
Transistors will work, but there are problems with biasing their inputs and if they aren't turned on all the way they get hot - waste power / make heat for no reason.

2 - you may need isolating capacitors on the power supply.
Sorry I can't give you specific values - been too long.
They are small ceramic disc capacitors (light brown from memory abut 3mm diameter)

3 - put fly back protection around/across the relay coil.
ie: a reverse biased diode in parallel with the coil.

4 - Yes, a separate supply would be advised. And if you use the FET or OPTO isolator idea, you can have that at 12v rather than 5v - if you are using a 12v supply. It seems silly dropping 12v to 5v only to power things.
Though..... If things need 5v, you don't have much say.
(Maybe get a 5v supply?)

Depending on how long your wires are you may need filters at both ends of the wire

From what I just serached, I don’t think so. They’re normal relays

Like these:

Sorry but my electronics knowledge is almost zero. My friend has better understanding of this matter. Basically I idealised what I wanted the controller to do and then tried to start assembling. After a few tries and a few euros I realised I couldn’t do all by myself, it was very overwhelming. That’s where my friend stepped in. But now he is very busy with his work and I want to solve this as soon as possible, as I’ve dedicated the last 6 months to this and now I’m so close to finish.

So I don’t want to upset anyone or making it seen that I’m very lazy. But if you guys could explain to me like you explain to baby (or a dummy, which I am in this matter) what I need to buy and to do. I would really appreciate

DHT22 (1) - 30cm (12inches)
DHT22 (2) - 150cm (50inches)
DHT22 (3) - 180cm (70inches)

They look as though they are opto-isolated.
The main interference occurs in the relay power side, you need to separate that power supply from the supply for the RasPi + DHT22's.
The separation is also made by the opto-isolators.

One way you could get around the relay problem is to buy a USB controlled relay.

It is a board with relay/s on it (only 1 or 2) and you plug it into the USB port.

Then you send it commands (from node-red) and all should be good.

I think that is what I did. I’ve put the Pi running with official Pi Power supply. Then I have a 12v5a power supply stepped down to 5v supplying the DHT’s and the relay communication with the Pi. Then have a separate 5v2a power supply for the main supply of the relay board.

I agree with @Paul-Reed , the relays look opto isolated. It looks very similar to boards I've used. If that is the case then the relay board is probably not the major problem. Still need to look at filtering the wires though.
[Edit] and possibly some very serious filters on the power supply plus make sure the supply is way over rated for the current draw
[Edit edit] you may want to double check your connections also consider shielded wire or twisted pairs

Have you made sure that the opto isolators on the relay board are powered from the Pi and the relays are powered from your separate PSU?

Your relay board should have a connector/jumper like the one in the top right of this one.


This one shows the jumper fitted, which, if I remember correctly, drives everything off the 5V supplied by the Pi, which is ok for me. To power them separately then I think you have to remove the jumper and separately connect the PSU to the board. You will need to check the data sheet for your board to make sure you get it right.

You can check whether you have it right, because, with the PSU disconnected, the LEDs should light when you attempt to drive the relays, but they will not click. When you connect the PSU then the relays should work.

I personally would remove that power supply, and power those components from the Raspberry Pi supply. The DHT22's only consume 1.5mA each when reading data (and 50uA when standby), and the opto-coupler consume even less current, so make use of the 3.3V Raspberry Pi stabilised supply (or even the 5V, if 3.3V is insufficient voltage for your application).

As Colin has also said, make sure that the opto-isolator supply is also not shared by the supply to the relays (to test, unplug the [separate 5v2a power supply for the main supply of the relay board] and see if the relays still actuate by using the [12v5a power supply stepped down to 5v supplying the DHT’s and the relay communication with the Pi] supply.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.