Pflanzenbewässerung mit ESP32 in MicroPython - Teil 4 - Ein Peltierelement gegen kalte Tage - AZ-Delivery

This episode is also as PDF document available.

In addition to light and water, plants also need a certain temperature. Especially in the time when you would like to raise from seed plants, it can still be quite cool on the windowsill, especially at night. At the moment, heat pumps are in great demand due to the gas and oil shortage. The devices usually work with a compressor. I chose a heat pump without moving parts. You can cool with pelt animal elements and if you reverse the direction of the current, also heat. The positive aspect is that you get more heat energy into the seed box than you have to use electrical energy. However, you have to permanently monitor the hot side so that on the one hand the plastic of the box does not melt and, above all, the maximum operating temperature of the pelt animal element is not exceeded. The melting or softening temperature is significantly lower and is therefore crucial for us. Come along, on a discovery tour through a new episode of

Micropython on the ESP32 and ESP8266


Part 4 - a pelting element against cold days

Some theory to warm up

A thermoelectric converter consists of two different metals, the ends of which are welded or soldered. One of the ladder is separated. Depending on the further circuit, two operating modes are possible.

The thermoelectric or Seaside-Plower is that a hike of electrons takes place at the contact points of two different metals. If you heat or cool the contact points, this leads to an electrical voltage at the point where one of the two ladder is separated due to the different speed of the electrons at the contact points. Because the element itself acts as a voltage source, the technical current direction within the element is from the minus to the positive pole, because the voltmeter flows the current from plus to minus.

Figure 1: Seebeck effect

Figure 1: Seebeck effect

If you swap the cause and effect, then this results in the Pelting-Effect. This means that a current flow through the element results in a temperature difference at the contact points. With the same current direction, the contact point cools down that would have to be heated in the Seebeck effect.

Figure 2: Peltier effect

Figure 2: Peltier effect

In principle, this also works with iron and copper. However, similar to the Seebeck effect, the Peltier effect is significantly increased if you use semiconductor material instead of the metals. With our pelting elements, the positively and negatively endowed bismuth-stelluride is. 127 small cuboids made of this material are connected in series and strung together between two ceramic plates. The PN transitions are thus parallel to the one plate (above), the NP contacts on the other. This adds up the effects of the pelting effect on the panels that cool one side while the other is heated.

Figure 3: Peltier element schematic

Figure 3: Peltier element schematic

This is what the pelting element used here looks like. It has the dimensions 40mm x 40 mm x 3.6mm.

Figure 4: Peltier element or thermoelectric converter

Figure 4: Peltier element or thermoelectric converter


As a controller, I chose an ESP32 because it can come up with sufficient freely selectable GPIO connections, we need 10 pieces up when fully removed.

The ESP32 models in the partial list are all useful. Only with the ESP32-Lolin-Board must be taken for the I2C connection SDA instead of GPIO21 of the GPIO25 PIN.


ESP32 Dev Kit C unpleasant or

ESP32 Dev Kit C V4 unplacerated or

ESP32 NODEMCU Module WiFi Development Board with CP2102 or

Nodemcu-ESP-32S kit or

ESP32 Lolin Lolin32 WiFi Bluetooth Dev Kit


0.91 inch OLED I2C Display 128 x 32 pixels


AHT10 moist and temperature sensor or

AHT10 moist and temperature sensor


Tec1-12706 thermoelectic converter - Peltier element


Resistance 10K


Resistance 1K


NPN transistor BC548 or similar


1M cable DS18B20 Digital stainless steel temperature sensor


DS18B20 Digital temperature sensor To92


1-relay 5V KY-019 module high-level trigger


MB-102 Breadboard Pug with 830 contacts


Jumper Wire cable 3 x 40 pcs. 20 cm M2M / F2M / F2F each possibly too

65stk. Jumper wire cable plug -in bridges for Breadboard


Power supply 5V / 3A


Logic Analyzer

The software

For flashing and the programming of the ESP32:

Thonny or


Used firmware for the ESP32:

V1.19.1 (2022-06-18).

The micropython programs for the project:

SSD1306.PY Hardware driver for the OLED display API for the OLED display The program for light control API for the AHT10 climate sensor

Micropython - Language - Modules and Programs

To install Thonny you will find one here Detailed instructions (English version). There is also a description of how that Micropython firmware (As of 18.06.2022) on the ESP chip burned becomes.

Micropython is an interpreter language. The main difference to the Arduino IDE, where you always flash entire programs, is that you only have to flash the Micropython firmware once on the ESP32 so that the controller understands micropython instructions. You can use Thonny, µpycraft or ESPTOOL.PY. For Thonny I have the process here described.

As soon as the firmware has flashed, you can easily talk to your controller in a dialogue, test individual commands and see the answer immediately without having to compile and transmit an entire program beforehand. That is exactly what bothers me on the Arduino IDE. You simply save an enormous time if you can check simple tests of the syntax and hardware to trying out and refining functions and entire program parts via the command line before knitting a program from it. For this purpose, I always like to create small test programs. As a kind of macro, they summarize recurring commands. Whole applications then develop from such program fragments.


If the program is to start autonomously by switching on the controller, copy the program text into a newly created blank tile. Save this file under in WorkSpace and upload it to the ESP chip. The program starts automatically the next time the reset or switching on.

Test programs

Programs from the current editor window in the Thonny-IDE are started manually via the F5 button. This can be done faster than the mouse click on the start button, or via the menu run. Only the modules used in the program must be in the flash of the ESP32.

In between, Arduino id again?

Should you later use the controller together with the Arduino IDE, just flash the program in the usual way. However, the ESP32/ESP8266 then forgot that it has ever spoken Micropython. Conversely, any espressif chip that contains a compiled program from the Arduino IDE or AT-Firmware or Lua or ... can be easily provided with the micropython firmware. The process is always like here described.

The circuit

The entire circuit for the project at an overview shows Figure 5. Parts from the previous blog sequences Let there be light and Water on are grayed out. The AHT10 module from the first episode AHT10 is used here again.

Figure 5: temperature control

Figure 5: temperature control

I enlarged the section at the top right again so that the small print is easier to read.

Figure 6: Temperature unit

Figure 6: Temperature unit

The module around the temperature measurement is based on the pelting element, a relay, a fan, two heat sinks, a buck converter, two DS18B20 Temepature sensors and the AHT10 module from the first post together.

Figure 7: entire electronics

Figure 7: entire electronics

One DS18B20 is connected to a piece of cable of one meter and, if you want it, can serve as an erdhermometer in one of the plant pots, or as a temperature sensor in the water tub, because it is waterproof in a stainless steel tube.

The other loose sensor is soldered at three cable pieces, secured with shrink hose sections and clamped between the cooling ribs of the heat sink on the warm side of the pelt animal element. It must reliably help the ESP32 to limit the temperature to approx. 50 ° C - 60 ° C so that the plastic does not melt away.

Figure 8: Heiz-cool combination

Figure 8: Heiz-cool combination

The Raspi fan, which is switched on and off via a transistor, is used to distribute the warm air. The 10kΩ resistor safely maintains the base of the transistor on GND potential, as long as the Tax PIN GPIO17 of the ESP32 is still switched as an entrance when booting. As soon as GPIO17 goes as an output by writing a 1 to 3.3V, the transistor switches through, a programmed 0 drops GPIO17 to 0V and the BC548 blocks. For fans with a higher power consumption (> 100mA), the BC548 must be replaced by a type with a higher collector permanent current. About a BC337 (up to 800mA) or a BC517 (up to 1.0a) would then be suitable.

For the assembly of the pelt animal element, a recess of 40mm x 40mm is cut or milled into the wall of the box. After inserting the element, the heat sinks are attached from the inside and outside. Please make sure that you have good flat contact with the pelt animal element.

Figure 9: Heiz-cool combination in the seed box cover

Figure 9: Heiz-cool combination in the seed box cover

The fan becomes quite loud when it is operated with 5V. That's why I installed a switchgear that allows it to optimize the noise and circulation of the air. With too much wind speed, the delicate plants would finally grow in the arch.

The pelt animal element must be installed in such a way that the printed side points outwards, because it becomes cold when the element is connected as in the switching sketch and we want the warm side inside. The element pulls about 1.5a at 5V. This is a little bit for a small switching transistor. That's why I decided to use a relay, as with the lighting LEDs. If you want more heating output, it is better to use a MOSFET-N-channel transistor together with a transistor preliminary stage as a driver and to place the pelt animal element on 12VDC. Then the performance of the element with a PWM output of the ESP32 can even be controlled via the duty ratio. The relay can then also be omitted. At 12V, however, the pelt animal element pulls about 3.5a top current.

Our pelt animal element can do two things that a simple heating spiral does not create. I have already mentioned above that more thermal energy comes out on the warm side of the element than we have to insert into heat on the ohmic resistance via the electrical power. The surplus joules come from the area. The air around our box is extracted on the cold side of its own thermal energy. Warm environmental air releases warmth on the colder heat sink. The element then pumps them down to the warm side due to the pelting effect. On the other hand, through the polarity of the power connection on the element, we can ensure that the inside gets cold. So we could cool the box on hot days. Then a fan must also be attached to the outside so that it does not overheat now.

The program

For the OLED display and the AHT10 we get the classes Softi2c and Pin code on the boat. The functions sleep and Sleep_ms enable the programming of waiting times. The class OLED Is the API for the display and sys delivers the function exit. With an object of the class OneWire we will create a DS18x20 instance. The topic of temperature also includes the recording of the air temperature, because we control the use of the heating. So we also need the class at the import business AHT10.

From machine import Softi2c, Pin code
From time import sleep, Sleep_ms
From OLED import OLED
import sys
From OneWire import OneWire
From DS18x20 import DS18x20
From AHT10 import AHT10

If the variable debug on True is set, we get through the function climate() Information about the current state and the actions in the box during development. As a rule, there is usually no PC connected in production, then we set up the variable False.

# ************* Declarize objects *****************
# debug = true

The I2C object I2C Let's hand over the constructor of the display object D, Together with the display height in pixel. The I2C object also needs the constructor of class AHT10.

I2C=Softi2c(scl=Pin code(22),sda=Pin code(21))
To control the relay for the pelt animal element, we create the PIN object hater to GPIO13. GPIO17 controls the transistor that switches the fan. button is the digital input GPIO0 on which the flash button of the ESP32 is located.
hater=Pin code(13,Pin code.OUT, value=0)
vent=Pin code(17,Pin code.OUT, value=0)
button=Pin code(0,Pin code.IN,Pin code.Pull_up)

The two DS18B20 are on the OneWire bus, which we need at PIN 18 and need to produce the DS18x20 object.

dspin=Pin code(DS18)
DS = DS18x20(OneWire(dspin))
In order to be able to clearly assign the ROM codes, only one of the two DS18B20 is now connected, for example the Sensor on the heat sink. Then I start the program entered so far F5 and then give the instructions in the terminal area Ds.Scan() a. I receive the Rome code of this chips as the only element of the Rome code of this chips list.
AHT10 ready
>>> DS.scan()
[bytearar(B '(\ xffd \ x0ei \ x0f \ x01>)]
Now I connect the second DS18B20 in parallel to the first and enter the command again.
>>> DS.scan()
[bytearar(B '(\ xffd \ x0ei \ x0f \ x01>'), bytearar(b '(\ x12 \ xd3 \ Xe9 \ x1f \ x13 \ x01 \ x13')]
Ds.Scan() will always find the sensors in the same order. The list of the method scan() returns, I then unpack in the two variables Heatsink and EARTHTEMP. If the second element came first in the list, I would have to simply swap the order of the variables.
Heatsink,EARTHTEMP = DS.scan()
print("Chip-Rom codes:",EARTHTEMP,Heatsink)
The declarations of some functions follow.
def heating(Val=None):
   assert Val in (0,1,None)
   IF Val is need None:
       return state[hater.value()]
The optional parameter of the function heating() has the default value None. I call heating() without an argument, i.e. with empty brackets, the call returns the current status of the GPIO output. Otherwise, the outcome will be placed on the transferred value. With assert I check whether the content of Val corresponds to a permitted value. If that is not the case, it will be a Assertoreror Throwed up that the calling program should intercept so that the error does not stop.

The function Fan() works according to the same scheme.

def Fan(Val=None):
   assert Val in (0,1,None)
   IF Val is need None:
       return state[vent.value()]

The function temperature() as an argument takes one of the ROM codes in Heatsink or EARTHTEMP. First with convert() a measurement initiated. The result is available in both components 750 milliseconds later. To read out the method read_temp() the corresponding chip must be addressed. This happens by handing over the ROM code in C.

def temperature(C):
   return DS.read_temp(C)

The function climate() It's pretty complex, it has to cover all possible cases. In any case, we get the measured values ​​at the start. We spend the temperatures on the display and, if debug The value of true has the air temperature in the terminal. There we receive a protocol of the way of working through other IF constructs.

def climate():
   tempo=AHT.gettem temp()
   D.writer("Temp_air: {0:> 4.1f}*C".format(tempo),0,0)
   D.writer("Temp_KK: {0:> 4.1f}*C".format(tempkk),0,1)
   D.writer("Temp_sub: {0:> 4.1f} %".\
   IF debug: print("Air temperature: {: 0.2f}".format(tempo))

For the further course, the flow diagram says of the function climate() more than words.

Figure 10: Flow diagram of the climate function

Figure 10: Flow diagram of the climate function

    IF tempo >= 24:
       IF debug: print("Too hot, luefter on")
   elif tempo < 19: #
       IF debug: print("Too cool")
       IF debug: print("KK-Temp:",tempkk)
       IF tempkk <= 26:
           IF debug: print("KK Temp ok, heat")
           IF debug: print("KK too hot, just wound")
       IF debug: print("Temperature OK")
       IF tempkk >= 25:
           IF debug: print("Heating")
           IF debug: print("No Action Needed")
As usual, the main loop is very clear. I only call the function climate() and ask the flash button. If it is pressed, the message appears on the display Program Canceled, Heating and fan are switched off and the corresponding messages are shown on the display.

With this article we now have all assemblies for plant irrigation. In the next episode we put together the parts into a program. Because, like me, you certainly have no desire to always get around the display to be up to date, I made an Android app that shows me the status of the box. On request, you could even integrate a remote control of the actuators, for example heating on / off.

Have fun tinkering and programming.

Until then

Esp-32Projekte für anfängerSensorenSmart home

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. ESP32 jetzt über den Boardverwalter installieren - AZ-Delivery
  2. Internet-Radio mit dem ESP32 - UPDATE - AZ-Delivery
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1 - AZ-Delivery
  4. ESP32 - das Multitalent - AZ-Delivery