Fish tank cooling system


As the title says, i am working on a small project for my fish-tank which intends to provide and automate cooling during the summer months. Basically the concept is that if the temperature raises above a certain value the fan will turn on and again, if it falls below a certain value it will stop. In this post, i would like to show you where i am and ask for support from someone more experienced than i am in the wiring. So, before i reach to the wiring, let me give you a part list:


  • NodeMCU, ESP8266 is the brains of the operation.
  • DS18B20 Underwater temperature sensor
  • 12V DC, IP68 Fan
  • LM2596 Stepdown converter
  • SRD-05VDC-SL-C Relay

For the software i am going to use ESPHome. The logic of the project is, that the NodeMCU will be powered by the 12V AC-DC 2A adapter using the stepdown converter. The rest of the parts will be powered directly from the NodeMCU except of course for the 12V fan that is connected on the relay. Since this this the first time i try to build such a thing i would like a confirmation that i do everything correctly on the wiring.

To Power the NodeMCU have pinned the jack to the upper power rails of the breadboard providing 12V power to all pins. From the left side of the rail, i feed 12V the step-down converter in the in+ and in- and i have adjusted the output to 5V (is this correct). Then the output of the step-down converted will be connected to VIN and G pin on the NodeMCU (currently is not yet connected). I hope that with this connection i will be able to power the NodeMCU and all the parts connected to it. In case my logic here is not correct please let me know.

The DS18B20 is connected to one of the 3v3 pins, to a ground, and for data i use pin D7, also programmed in the code. This is tested with USB power and it works.

The relay is connected with the NodeMCU as such:

  • VCC to 3v3
  • Ground to Ground
  • In to D6 also programmed in the code

The 12V fan is a 2 pin fan and i connected it to the relay as follows:

  • Power from the rail + goes to the COM of the relay (red wire)
  • Power from the NO of the relay goes to the fan (red wire)
  • Black wire from the fan is directly connected to the negative rail of the breadboard.

This way, i believe that the relay closes the circuit of the red wires and the fan should spin.

So to sum up my questions:

  1. Is the 5V output of the step-down converter correct? Will it be enough to power the NodeMCU?
  2. Is the wiring logic correct or as soon as i am gonna plug it in it’s gonna blow up?

Thanks very much for support here. Wiring is not my forte!!

Sounds about right, but the relay may expect 5V, not 3v3, so you might want to confirm that (its name suggests that it wants 5), and connect its Vcc to the Vin line (same place you get power from the step-down).
FWIW, the above is based on the notion that the 3v3 line on the NodeMCU is provided by the NodeMCU’s onboard 5v-3v regulator, but the relay may draw more current than that regulator can supply (which would be in addition to the current it’s already supplying for the 3v3 on which the ESP runs).

Hi glyndon,

Yes you are correct. The Relay is a 5V relay… I missed that, because i was following the below schematic:


It has the exact same relay (part number is the same) and connects this to the first 3v3 pin. The only difference is that on the above picture the NodeMCU is powered by a USB.

Currently i have the relay connected and the entity is exposed to home assistant and i can switch it on and off.

Do you think it is safe to pin it on the VIN and Ground that the NodeMCU will get power?

Sorry for the newbie questions, we all start like this!!! :slight_smile:

The blue box is the actual relay, which is lasbeled SRD-05VDC-SL-C.
The circuit board on which it’s mounted will have its own name/model, and is importand to know since it will have its own signal levels, input voltage/current requirements.
Can you provide that model #? It will let me confirm what its proper input voltage is.

Unfortunately it doesn’t have anything written on the PCB neither under it. If it helps, i bought it from this link: Sorry it is in slovak but even on the title it says 5V.

I will try it with 3V first and if it doesn’t work i will switch it to 5v

I should rephrase my recommendation:
If its datasheet says it expects 5V, you should supply that, not 3v3.
It will probably appear to work if supplied 3v3, but that might be right at the edge of not being enough, and one day it won’t move the relay contact. Using 3v3 from the ESP’s board also puts additional strain on the onboard regulator, meaning that your ESP may also not get enough current to operate reliably.
You don’t want to risk either of those things happening, and you don’t want to overload/damage the onboard 3v3 regulator.
Thus I’d power the relay module from the 5V converter, not the 3v3 from the ESP.
I also noticed on the webpage that they offer a 3V version, further supporting the reason for supplying this on with 5.
As an aside: The control pin will still get only a 3v3 signal from the ESP’s GPIO, but that should be high enough to satisfy the logic on the relay board and activate it reliably. The relay’s support circuit will act on the 3v3 signal, and then draws power from its 5V Vcc line to move the relay armature.

At first, i had it on the 3v3 and it was working normally. I moved it to the output of the converter (5V) and now when i switch it on or off it doesn’t make any difference… The relay outputs 12.10V regardless if i turn it on or off… Should i switch it back to 3v3?

I disconnected it from power until we figure it out

The only thing to put on 5v is the relay’s Vcc line.
If that’s what you did, then it may be that the 3v3 logic signal isn’t high enough to trigger it when Vcc is at 5. So, if the above is what you did, and it only works at 3v3, just go with that.

Yeah returning back to the 3V3 makes it operational again… I am thinking to buy the 3v version of the relay on my next purchase from that store… For now I will switch it on 3 volts

Thanks very much… It’s a simple project but if you are not familiar with these things it can be stressful

Thanks for the help!

You’re welcome!
As you said, we all start out as new. It’s all about questions, answers, learning, sharing and helping each other.
Hope it does what you want it to and the fish stay happy!

What’s the actual part number on the relay, see pic?



The part number of the relay is: SRD-05VDC-SL-C. I am pretty sure that it is 5v relay… My problem is that when connecting it to 5V on VCC the relay doesn’t close the circuit by providing 3v on the “IN”.

The likely reason for that has nothing to do with the [blue] relay itself, but with the logic circuit that’s on the board holding the relay.
A bare relay’s coil needs more current than the GPIO signal can provide, so most hobbyist relays now come with a driver board attached, which accepts logic-level control signals (e.g. from GPIO) to control the full-current Vcc source through the relay’s coil.
Some control logic will, if powered at 5v, still accept 3.3v as a logical “on” or “high” signal.
But, some require the input signal to be closer to the Vcc voltage before considering it to indicate “on”.
This device seems to behave in the latter manner.

Exactly that, as the esp pin is only outputting 3.3v when pulled high, that’s why I requested the exact part number, the link provided in the OP shows two different relay boards.

You can also try using 5v but set the esp to trigger pin to pull low.


And how exactly do I do I set it to pull low?

Where you define the ‘output’, you can add ‘inverted: true’ to that block. It makes the GPIO signal go low for ‘on’ and high for ‘off’.

Assuming you’re using the following config

  - platform: gpio
      number: XX
      inverted: true

Hello guys,

Thanks for the code… It seems that i need to do my homework one more time… Here is the code i have for the switch:

  - platform: gpio
    pin: D6
    name: "Aquarium Fan"
    inverted: true
    restore_mode: RESTORE_DEFAULT_OFF

Initially i did not have the “inverted: true” in the code but what was happening was that the polarity of the switch was opposite. When the switch was on in Home Assistant i was measuring 0.06v on the pins of the fan. When i “turned it off” i was measuring 12.46v on the pins. So i added the “inverted: true” which fixed this problem. That made me believe that the inverted: true defines the polarity and not the voltage of the D6 Pin.

Today with your help, i connected again the relay to 5V and i tried both with “inverted: true” or without and unfortunately the relay stays on all the time, giving 12v on the fan pins.

I moved it back to the 3v3 and for now i will keep it there as nothing makes sense…
Thank you very much both for your help, i wouldn’t be able to reach to the stage that i am now without your support.

Now that i am thinking about it perhaps i could do the following:

  • Connect the relay to 5V
  • Keep the “inverted: true” in the code so it is on low
  • Connect the positive pin of the fan to NC instead of NO (this might fix the polarity issue)

Is the above correct?

Kind Regards

Not ideal, as the relay will be constantly energized.

Which esp8266 are you using?

Could you try “D8 GPIO15” which is normally pulled low (to gnd)?

The article linked below should clarify everything a little further.