Thermoelectric Generator Logger on Raspberry Pi 5 - Proteus Simulation: the Raspberry Pi 5, the TEG module, the INA219, the relay module and the two power resistors

Thermoelectric Generator Logger on Raspberry Pi 5 - Proteus Simulation

40
700
60
25
60
PCBWay

Hello friends, I hope you all are doing great. Today, I am going to share the Thermoelectric Generator Logger on Raspberry Pi 5 - Proteus Simulation, the seventieth project of our IoT Projects series. If you have searched for a thermoelectric generator (TEG) project, the internal resistance of a Peltier module, maximum power transfer with a Raspberry Pi, or a Proteus simulation of a TEG with its load, here is a complete one. A TEG module on a stove or a heat pipe gives electricity from a temperature difference, but how much it can give depends on the heat, on the cooling and on the load. This Raspberry Pi 5 measures all of it: every 5 seconds it switches a small bank of resistors, fits a straight line through the readings, and finds the module's open-circuit voltage, its internal resistance and the most power any load could take.

Electrically a TEG behaves like a battery with a large internal resistance, and both its voltage and its resistance change with the heat. That makes it a perfect subject for one of the most useful ideas in electronics, the Thevenin model, and for the maximum power transfer theorem that follows from it. In this tutorial, we will go through the circuit, see why a TEG makes a voltage, measure its Thevenin model with four loads and a least-squares line, work out the best load, read the temperature difference from the voltage alone, and see how a TEG's cooling decides its output. Then we run the simulation at 100 and 150 C, switch the fan off and on again. At the end, you can download the project with the program and every library file.

NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the thermoelectric generator logger on Raspberry Pi 5 in Proteus simulation:

Thermoelectric Generator Logger on Raspberry Pi 5 - Proteus Simulation: the Raspberry Pi 5, the TEG module, the INA219, the relay module and the two power resistors
Figure: The TEG logger in a Proteus simulation: the Raspberry Pi 5 measuring the module.
Thermoelectric Generator Logger on Raspberry Pi 5: the working Proteus simulation, an animated view of the project's main steps
Figure: The project working in the Proteus simulation (an animation of the main steps).

What Does This TEG Logger Do?

  • Measures the module: an INA219 in the TEG's + lead reads its voltage and current; the Raspberry Pi 5 reads it over I2C.
  • Sweeps four loads every 5 s: a 2-channel relay module switches a 4.7 ohm and a 10 ohm cement resistor: open, 10, 4.7 and both together, 3.2 ohm.
  • Finds the module's Thevenin model: a least-squares line through the four points gives the open-circuit voltage and the internal resistance.
  • Predicts the best: the most power any load could take, and the load that would take it.
  • Uses the best load: between the sweeps, the bank's load closest to the internal resistance stays on and its power is logged as energy.
  • Reads the temperature from the voltage: the module's own table turns the open-circuit voltage into the difference between its faces.
  • Rejects bad sweeps and warns: a sweep taken while the heat changed is thrown out, and DIFFERENCE FALLING says when the cooling fails.

It is a great project for learning a TEG's physics and two of the most useful ideas in electronics in one go. In the simulation, the TEG's pop-up shows the whole heat path, from the heat source through the module and its heatsink to the room, with every temperature, and draws the module's load line with the matched point marked, so each of the Pi's numbers has an independent judge.

Components Used in the Proteus Simulation

All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file and the TEP Pi runtime.

The parts of the TEG logger and their library posts
PartProteus deviceLibrary postConnection
Raspberry Pi 5RASPBERRY PI 5Raspberry Pi 5 Library for ProteusPI1, teg_logger.py, Ethernet 192.168.1.51
SP1848 thermoelectric generatorTEGSP1848TEPThermoelectric Generator Library for ProteusTEG1: + to VIN+ of U1, - to GND
INA219 current sensorINA219ADVTEPINA219 Current Sensor Library for ProteusU1, I2C1 at 0x40: VIN+ the TEG, VIN- the bank
2-channel relay moduleRELAY2ADVTEPRelay Module Library for ProteusRLY1: IN1 GPIO17 (pin 11), IN2 GPIO27 (pin 13)
4.7 ohm and 10 ohm 5 W resistorsRESISTORPOWER5WTEPPower Resistor Library for ProteusR1, R2 from NO1, NO2 to GND
SSD1306 OLED 0.96" 128x64OLED12864WHITEADVTEPOLED SSD1306 Library for ProteusOLED1, I2C1 at 0x3C
Laptop WiFi MonitorLAPTOP WIFI MONITORLaptop WiFi MonitorPC1
Mobile WiFi MonitorMOBILE WIFI MONITORMobile WiFi MonitorMOB1

Proteus Simulation of the TEG Logger: the Circuit

TEG logger Proteus simulation circuit: Raspberry Pi 5, an SP1848 TEG, an INA219, a 2-channel relay module and two power resistors
Figure: The complete circuit of the TEG logger on an A3 Proteus sheet.
The connections of the TEG logger
PartPinsRaspberry Pi 5 / supply
TEG1+ / -the net TEG / GND
U1 INA219VIN+ / VIN-TEG / LOAD
U1 INA219SDA / SCL / VCCGPIO2 (pin 3) / GPIO3 (pin 5) / +3.3V
RLY1 relaysIN1 / IN2GPIO17 (pin 11) / GPIO27 (pin 13), LOW = on
RLY1 relaysVCC / JD-VCC+5V
RLY1 relaysCOM1, COM2 / NO1 / NO2LOAD / R1 4.7 ohm / R2 10 ohm, both to GND
OLED1SDA / SCL / VCCGPIO2 / GPIO3 / +3.3V

The power path runs from the TEG's + through the INA219's 0.1 ohm shunt to both relay contacts, and from each normally-open contact through its resistor to ground; the TEG's - goes straight to ground. The two resistors sit in parallel, so any combination of the relays is safe: none, either, or both together for 3.2 ohm. The relay module's VCC and JD-VCC need a real 5 V supply for the coils. The power is small, under half a watt, but 5 W cement resistors cost little and never get warm. The INA219 and the OLED share the I2C bus. The TEG runs with SPEED 20, a property of the model: each simulated second is twenty seconds of heating, so the temperatures settle in a few simulated seconds instead of minutes.

How the TEG Logger Works

Why a TEG Makes a Voltage

A thermoelectric module is a sandwich of many small pellets of two kinds of semiconductor, n-type and p-type, wired in series electrically and in parallel thermally between two ceramic plates. Heat one plate and cool the other, and the charge carriers drift from hot to cold, building a voltage across each pellet: the Seebeck effect. The voltage is proportional to the temperature difference between the faces. The SP1848's table gives 0.97 V at 20 C of difference, 1.8 V at 40 C, 2.4 V at 60 C, 3.6 V at 80 C and 4.8 V at 100 C, about 45 to 48 mV per degree for the whole module. The same pellets also have resistance, 4.3 to 7.2 ohm for this module, so the voltage at the terminals falls as the current rises.

The Thevenin Model: a Battery with a Resistor

Any source made of voltages and resistances behaves, at its two terminals, like one voltage Voc in series with one resistance Rint: the Thevenin model. Its terminal voltage is V = Voc - I x Rint, a straight line on a graph of V against I. Two points would fix the line; the program measures four and fits them by least squares, which averages out the noise and shows whether the points really lie on a line. Worked example from the run at 100 C: open, 1.848 V at 0 mA; 10 ohm, 1.244 V at 122 mA; 4.7 ohm, 0.911 V at 188 mA; 3.2 ohm, 0.742 V at 222 mA. From the open point to the 3.2 ohm point the slope is (1.848 - 0.742) / 0.222 = 4.98 ohm, and the least-squares line gives the same 4.98 ohm.

Maximum Power Transfer

Into a load R, the source gives P = Voc squared x R / (R + Rint) squared. Too small a load and most of the voltage is lost inside the module; too big and little current flows. The power is greatest when R = Rint, and then P = Voc squared / (4 Rint), with exactly half the power lost inside. Worked example at 100 C: 1.848 squared / (4 x 4.98) = 171 mW. The bank's three loads give 0.911 x 0.188 = 171 mW into 4.7 ohm, 1.244 x 0.122 = 152 mW into 10 ohm and 0.742 x 0.222 = 165 mW into 3.2 ohm, so 4.7 ohm, the closest to Rint, takes all but a fraction of the maximum. The efficiency is tiny: the TEG's pop-up shows 25 W of heat flowing through the module for those 170 mW, 0.7 %, which is typical of a TEG.

The Temperature from the Voltage

Since the open-circuit voltage follows the difference between the faces, the module is its own thermometer. The program reads the difference back from the table with a straight line between its points. Worked example: 1.848 V lies between 1.8 V (40 C) and 2.4 V (60 C), so the difference is 40 + 20 x (1.848 - 1.8) / (2.4 - 1.8) = 41.6 C; the TEG's pop-up showed 41 C. The open point is a little warmer than a loaded one, because a current carries heat through the module too (the Peltier effect) and narrows the difference; with no current there is none of that.

The Cooling Decides the Output

A TEG does not make power from heat; it makes power from heat flowing through it, and the heat must leave through the cold face. A good heatsink with a fan keeps the cold face near the room's temperature, so the whole difference between the source and the room appears across the module. Without the fan, or without a heatsink at all, the cold face warms until little difference is left, and the output collapses even though the heat source is as hot as before. The program watches for that: when the difference falls a third under its best of the last 30 s, it says DIFFERENCE FALLING.

A Sweep That Missed the Line

The first final run showed why the least-squares fit needs a check. One sweep happened just as the heat source went from 100 to 150 C; its four points were taken at four different temperatures and did not lie on any line, and the fit claimed an internal resistance of 1.34 ohm and 512 mW. So the program now measures how far the points miss their own line: more than 30 mV, and the sweep is rejected, the last good model is kept, and only the open-circuit reading is used, for the temperature.

The Python Code Explained

The program is teg_logger.py, plain Python 3 with lgpio for the I2C bus and the relays, threading, and http.server for the dashboard. It runs the same way on a real Raspberry Pi 5. The module's table and the four loads:

TABLE = [(0, 0.0), (20, 0.97), (40, 1.8), (60, 2.4), (80, 3.6), (100, 4.8)]   # the module's open-circuit volts by the difference
LOADS = [(None, False, False), (R2, False, True), (R1, True, False), (R1 * R2 / (R1 + R2), True, True)]   # open, 10, 4.7, 3.2

The relays: LOW switches a resistor on:

    lgpio.gpio_write(chip, IN1, 0 if a else 1); lgpio.gpio_write(chip, IN2, 0 if b else 1)

The INA219: the bus register read unsigned, and the module's own voltage is the bus plus the shunt's drop:

        bus = (self.read(0x02) >> 3) * 0.004                    # BUS VOLTAGE (VIN- to ground): 4 mV a step
        return max(bus + shunt, 0.0), max(amps, 0.0)            # (the module's own volts: the load's plus the shunt's drop)

The least-squares line through the points: its slope is minus Rint, its intercept Voc:

    b = (n * sxy - sx * sy) / den
    return (sy - b * sx) / n, -b

How far the points miss their line:

    worst = max(abs(v - (voc - i * rint)) for _, v, i in pts)

The temperature difference from the open point:

    dt = diff_of(pts[0][1])                                     # (the open point: I = 0, the module's own volts)
            return d0 + (d1 - d0) * max(voc - v0, 0) / (v1 - v0)

The best load of the bank, and the most power:

            k_now = min(range(1, 4), key=lambda j: abs(LOADS[j][0] - rint))   # the bank's load closest to Rint
            s.update(voc=voc, rint=rint, pmax=voc * voc / (4 * rint), dt=dt, load=LOADS[k_now][0])

The warning:

            if top > 10 and dt < (1 - FALL) * top and not falling:

Between the sweeps the program reads the module every quarter second into the matched load, adds up the energy, and redraws the OLED: the state, the difference, Voc, Rint, the most power, the load and the power now. The pages are / (the dashboard), /line.bmp (the last sweep's four points and their line as a picture) and /data (JSON).

How to Run the Proteus Simulation

  1. Download the project zip below and install the library files and the TEPPi folder (the steps are under the download button).
  2. Open Pi-5-TEG-Logger.pdsprj from the Proteus Simulation folder. Keep teg_logger.py and the DLL files next to it.
  3. Press Play. The heat source is at 100 C with a fan on the heatsink; the first sweep comes at once.
  4. Click TEG1 for its pop-up and press 150; then No heatsink, and Fan again.
  5. Open the Laptop or the Mobile WiFi Monitor and press Go for the dashboard.

Simulation Results: the TEG Logger in Proteus

Here is the run that made the screenshots of this tutorial, 101 seconds of simulation, about half an hour of heating on the model's SPEED 20 clock. The times are the program's own, as it printed them in the Raspberry Pi's terminal; the TEG's pop-up shows the module's own temperatures and its own Thevenin numbers for comparison.

100 C with a Fan

From 11.5 s the sweeps repeat to the millivolt: "open 1.848 V; 10 ohm 1.240 V 122 mA, 5 ohm 0.911 V 188 mA, 3 ohm 0.742 V 222 mA - Voc 1.848 V, Rint 4.98 ohm, 171 mW at most into 5.0 ohm; the difference 41.6 C". The matched load, 4.7 ohm, takes 0.907 V at 187 mA, 170 mW, all but 1 mW of the maximum. The TEG's pop-up says the same in its own words: 96 C on the hot face, 55 C on the cold face, 41 C between them, 1.82 V open, 4.9 ohm inside, 170 mW at most, 25 W of heat through the module and 0.7 % of it as electricity. The program's Voc is 1.5 % higher than the pop-up's because its open point carries no Peltier current and runs a little warmer, as explained above.

The TEG logger Proteus simulation at 100 C: the Raspberry Pi 5, the TEG, the INA219 and the relay with the 4.7 ohm load on
Figure: At 100 C: the 4.7 ohm load on.
Thermoelectric generator pop-up in the Proteus simulation: 100 C, 41 C between the faces, 170 mW, the load line
Figure: The TEG at 100 C.
OLED pop-up in the Proteus simulation: TEG GENERATING, DT 41.6 C, VOC 1.849 V, RINT 4.99 OHM, PMAX 171 MW, LOAD 4.7 OHM
Figure: The OLED at 100 C.
INA219 pop-up in the Proteus simulation: 0.888 V on the bus and 187.6 mA from the TEG
Figure: The INA219 at 100 C.
Laptop WiFi Monitor in the Proteus simulation: the TEG logger dashboard, 171 mW, and the sweep's four points on a line
Figure: The dashboard: the four points and their line.

150 C: a Rejected Sweep, Then More Power

150 C at 26.6 s, and that sweep caught the change: "SWEEP REJECTED - the points miss a straight line by up to 207 mV: the heat changed during it". The last good model stays, and five seconds later the first clean sweep at the new heat arrives. Then they settle: "Voc 2.976 V, Rint 5.93 ohm, 373 mW at most into 5.9 ohm; the difference 69.6 C". The internal resistance has grown with the temperature, from 4.98 to 5.93 ohm, and 4.7 ohm is still the closest the bank offers: 1.331 V at 274 mA, 365 mW. The pop-up: 144 C and 75 C on the faces, 68 C between them, 2.91 V open, 5.7 ohm, 368 mW at most, 42 W of heat, 0.9 %. Twice the difference has given more than twice the power, because the power grows with the square of the voltage.

The TEG logger Proteus simulation at 150 C: the module making 365 mW into the 4.7 ohm load
Figure: At 150 C.
Thermoelectric generator pop-up in the Proteus simulation: 150 C, hot face 144 C, cold face 75 C, 368 mW at 5.7 ohm
Figure: The TEG at 150 C.
OLED pop-up in the Proteus simulation: the TEG at 150 C, Voc about 2.98 V and Rint about 5.9 ohm
Figure: The OLED at 150 C.
Relay module pop-up in the Proteus simulation: K1 on, the 4.7 ohm matched load carrying 274 mA
Figure: The relay module: the matched load on.
Laptop dashboard in the Proteus simulation at 150 C: Voc 2.976 V, Rint 5.93 ohm, 373 mW at most
Figure: The dashboard at 150 C.

The Fan Off: the Difference Collapses

No heatsink at 58.6 s, the fan and the fins taken away. The heat source is still at 150 C, but the cold face has nowhere to send its heat. Four seconds later: "open 0.240 V ... Voc 0.241 V, Rint 4.80 ohm, 3 mW at most; the difference 4.9 C", and at once "DIFFERENCE FALLING - 4.9 C, a third under the best 69.7 C of the last 30 s: check the heat and the cooling". The pop-up shows why: the hot face at 150 C and the cold face at 145 C, only 3 W of heat getting through, 3 mW of electricity. The module is as hot as ever and almost useless.

The TEG logger Proteus simulation with no heatsink: the OLED showing TEG FALLING
Figure: No heatsink: TEG FALLING.
Thermoelectric generator pop-up in the Proteus simulation: no heatsink, the cold face at 145 C, 5 C between the faces
Figure: The TEG without a heatsink.
OLED pop-up in the Proteus simulation: TEG FALLING, DT 5.0 C, VOC 0.247 V, PMAX 3 MW
Figure: The OLED: the difference gone.
Laptop dashboard in the Proteus simulation: FALLING, 3 mW at 0.122 V, the difference 5.0 C
Figure: The dashboard: FALLING.

The Fan Back

The fan again at 75 s. The next sweep catches the cold face cooling down, 61.3 C of difference, and at 83.3 s: "the difference back: 69.3 C", with 371 mW at most. The energy counter shows how little a TEG makes: 0.007 Wh in the whole run.

The TEG logger Proteus simulation with the fan back: the difference back near 70 C
Figure: The fan back.
Thermoelectric generator pop-up in the Proteus simulation: the fan back, the faces apart again
Figure: The TEG with the fan back.
Laptop dashboard in the Proteus simulation at the end: 373 mW at most, 0.007 Wh
Figure: The dashboard at the end.
Mobile WiFi Monitor in the Proteus simulation: the TEG logger dashboard with the sweep's line
Figure: The phone.
Raspberry Pi 5 terminal in the Proteus simulation: every sweep, the rejected one, the warning and the recovery
Figure: The terminal: every sweep of the run.
The results of the TEG logger simulation
MomentVocRintMost powerThe differenceThe pop-up
100 C, fan1.848 V4.98 ohm171 mW41.6 C1.82 V, 4.9 ohm, 170 mW, 41 C
150 C, fan2.976 V5.93 ohm373 mW69.6 C2.91 V, 5.7 ohm, 368 mW, 68 C
150 C, no heatsink0.241 V4.80 ohm3 mW4.9 C0.22 V, 4.3 ohm, 3 mW, 5 C
150 C, fan back2.974 V5.93 ohm373 mW69.5 C-

Download the Project Files

Click the button below to download Thermoelectric-Generator-Logger-Raspberry-Pi-5-Proteus-Simulation-v1.0.zip (about 14.5 MB, without the source code of the models):

Thermoelectric Generator Logger on Raspberry Pi 5 - Proteus Simulation V1.0
  • Proteus Simulation: Pi-5-TEG-Logger.pdsprj, teg_logger.py and copies of the models.
  • Python Code: teg_logger.py, the program.
  • Proteus Library Files: the LIB files of the Raspberry Pi 5, the TEG, the INA219, the relay module, the power resistor, the OLED and the two WiFi Monitors.
  • Proteus Model Files: the DLL models and the TEPPi folder (Python and the TEP Pi runtime).
  • README.txt: the installation steps, the properties, the test results and the links to every library post.

No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.

How to Install the Project Files

  1. Close Proteus and extract the whole zip file, for example to your Desktop.
  2. Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
  3. Copy everything in Proteus Model Files, the DLL files and the TEPPi folder, into the MODELS folder.
  4. Start Proteus and open the project from the Proteus Simulation folder.

Changing the Code

Edit teg_logger.py beside the project; PI1 runs the file named in its PROGRAM property, so a change takes effect at the next Play. The resistor values, the sweep interval, the point time, the module's table and the warning's threshold are at the top. In TEG1's properties, SOURCE sets the heat, HEATSINK the cooling, AMBIENT the room and SPEED the thermal clock.

Ideas to Extend the Project

  • Replace the relays with a MOSFET and PWM for a load that matches Rint exactly, and compare the energy.
  • Charge a supercapacitor through a boost converter, the usual way to make a TEG's low voltage useful.
  • Add a thermocouple on the hot face and compare its reading with the difference worked out from the voltage.
  • Log a whole evening of a stove: power, difference and energy, and find the best fire for electricity.
  • Use two modules in series and see how Voc and Rint add up.
  • Make the sweep adaptive: more often while the heat changes, rarely when it is steady.

From Simulation to Real Hardware

  • Mount the module well: thermal paste on both faces and even pressure; a poor contact wastes more temperature difference than anything else.
  • Mind the hot face: the SP1848 takes 150 C at most on its hot face; a stove top can be much hotter, so use a spreader plate.
  • The cooling is half the design: a heatsink with a fan, or water, keeps the cold face cool; a passive heatsink soon warms up.
  • Small signals: the volts and amps are small, so keep the wiring short and the INA219 close to the module.
  • Relays use power: a coil takes about 70 mA at 5 V, far more than the TEG gives; on a self-powered logger, use MOSFETs.

Troubleshooting

  • The relays never click: their VCC and JD-VCC need a real 5 V supply (+5V), not a net label.
  • Voc and Rint read 0: the TEG's + must go through the INA219 (VIN+ to VIN-) to the relays' COM pins.
  • Many sweeps rejected: the heat is changing fast; a slower thermal clock (SPEED) or shorter points help.
  • The OLED stays blank: SDA / SCL on GPIO2 / GPIO3, address 0x3C, VCC on 3.3 V.
  • Python does not start: the TEPPi folder must be in the MODELS folder.

Limitations of the Simulation

  • The TEG is the library's model: the module's published table with straight lines between its points, a lumped heat path from the source to the room, and the Peltier effect of the current.
  • SPEED 20 makes each simulated second twenty seconds of heating, so the module warms twenty times faster during a sweep than it would in real time.
  • The network to the laptop and the phone is simulated inside Proteus.
  • Raspberry Pi is a trademark of Raspberry Pi Ltd; this project is not made or endorsed by them or by Labcenter.

So, that was all about the Thermoelectric Generator Logger on Raspberry Pi 5 - Proteus Simulation. I hope it helps you understand why a TEG makes a voltage, how four loads and a straight line reveal its Thevenin model, why the best load equals the internal resistance, how the voltage tells the temperature, and why the cooling matters as much as the heat, all tested in a simulation before you put a module on a stove. More IoT projects with the ESP32 and the Raspberry Pi 5 are coming in this series. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!


Comments

0

Join the conversation