Skip to content

Update HeaterService.h#124

Open
robrozo wants to merge 1 commit intouncodead:masterfrom
robrozo:patch-1
Open

Update HeaterService.h#124
robrozo wants to merge 1 commit intouncodead:masterfrom
robrozo:patch-1

Conversation

@robrozo
Copy link
Copy Markdown

@robrozo robrozo commented Mar 10, 2026

For heating control, using fast PWM via analogWrite() is not ideal. In thermal systems, the most effective approach is Time Proportional Control, where the heater is driven based on an on/off time window.

The code has been updated to use a 10-second time window, allowing the heater to be controlled by the proportion of ON/OFF time within that window. This reduces unnecessary switching and improves overall temperature control stability.

For heating control, using fast PWM via analogWrite() is not ideal. In thermal systems, the most effective approach is Time Proportional Control, where the heater is driven based on an on/off time window.

The code has been updated to use a 10-second time window, allowing the heater to be controlled by the proportion of ON/OFF time within that window. This reduces unnecessary switching and improves overall temperature control stability.
@uncodead
Copy link
Copy Markdown
Owner

Olá, @robrozo! Tudo bem?

Você utiliza Relé de Estado Sólido (SSR)? Os SSRs operam de forma muito mais eficiente com ciclos de chaveamento controlados (PWM/Proporcional de Tempo) em comparação aos relés mecânicos. Quando aliamos isso ao controle PID, o sistema se torna ainda mais preciso e eficiente na manutenção da temperatura.

Hi @robrozo! Hope you're doing well.

Are you using a Solid State Relay (SSR)? SSRs are much more efficient when handling controlled switching cycles (PWM/Time Proportional) compared to mechanical ones. When this is integrated with PID control, the system becomes significantly more precise and stable for heating.

@robrozo
Copy link
Copy Markdown
Author

robrozo commented Mar 20, 2026

Olá @uncodead , tudo bem? Espero que sim!

Sim, estou utilizando SSR.

A questão do uso do analogWrite() nesse caso está relacionada à frequência de operação. O analogWrite() trabalha com PWM em torno de ~1 kHz (no ESP8266), enquanto a rede elétrica aqui no Brasil opera a 60 Hz.

Como o SSR (especialmente os do tipo zero-cross) chaveia sincronizado com a senoide da rede, esse PWM de alta frequência acaba não sendo eficaz para controle de potência — ele não consegue modular corretamente a energia entregue ao aquecedor.

Por isso, a abordagem mais adequada é o Time Proportional Control, utilizando uma janela de tempo (por exemplo, 10 segundos), onde controlamos a proporção de tempo ligado/desligado dentro dessa janela.

Isso equivale, na prática, a uma frequência de controle de aproximadamente 0,1 Hz, muito mais compatível com sistemas térmicos e com o comportamento do SSR.

Além disso, essa estratégia reduz chaveamentos desnecessários e melhora a estabilidade do controle de temperatura.

Hi @uncodead , hope you're doing well!

Yes, I’m using an SSR.

The issue with using analogWrite() in this case is related to frequency. The analogWrite() function operates at around ~1 kHz PWM (on ESP8266), while the mains frequency here in Brazil is 60 Hz.

Since SSRs (especially zero-cross types) switch in sync with the AC sine wave, this high-frequency PWM is not effective for power control — it cannot properly modulate the energy delivered to the heater.

That’s why the most appropriate approach is Time Proportional Control, using a time window (for example, 10 seconds), where we control the ON/OFF ratio within that window.

In practice, this corresponds to a control frequency of about 0.1 Hz, which is much more suitable for thermal systems and aligns better with SSR behavior.

Additionally, this approach reduces unnecessary switching and improves overall temperature control stability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants