AC Power Control Issue

Hi

I recently purchased an AC dimmer module from bangood.com

I’m using it to control the temperature of my saltwater aquarium.

I’m using an interupt for zero cross detection

The relevant code being;

#include <TimerOne.h>

volatile int idim=0; // Variable to use as a counter
volatile boolean zero_cross=0; // Boolean to store a “switch” to tell us if we have crossed zero
int AC_pin = 37; // Output to Opto Triac
int dim = 128; // Dimming level (0-128) 0 = on, 128 = 0ff

int freqStep = 75; // This is the delay-per-brightness step in microseconds for 50Hz (change the value in 65 for 60Hz) 78

pinMode(AC_pin, OUTPUT); // Set the Triac pin as output
attachInterrupt(0, zero_cross_detect, RISING); // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
Timer1.initialize(freqStep); // Initialize TimerOne library for the freq we need
Timer1.attachInterrupt(dim_check, freqStep);
// Use the TimerOne Library to attach an interrupt

}

void zero_cross_detect() {
zero_cross = true; // set the boolean to true to tell our dimming function that a zero cross has occured
idim=0;
digitalWrite(AC_pin, LOW);
}

// Turn on the TRIAC at the appropriate time
void dim_check() {
if(zero_cross == true) {
if(idim>=dim) {
digitalWrite(AC_pin, HIGH); // turn on light
idim=0; // reset time step counter
zero_cross=false; // reset zero cross detection
}
else {
idim++; // increment time step counter
}
}
}

By changing the value of dim in the main loop of my sketch I can control the power of the heater.
I have tested on a lamp first and then the heater in the aquarium and all works well :slight_smile:

The problem I have is that when the power is anything other than 0% or 100% my PH gauge gets upset and gives spurious readings.

I have an off the shelf product that does the same job (dimming power to heater) and it doesn’t interfere with the PH gauge!

I’m reasonably confident that it’s not a coding issue, and think maybe the module I’m using which is quite cheap could be the cause and maybe needs some extra bits and pieces to isolate or suppress interference.

My programming knowledge is quite decent but my electronic knowledge is still a bit lacking!

Any help would be greatly appreciated!

Sounds like you’ve picked up a lot of EMI via the heater capacitively coupling to the tank.

Using slow PWM (15 seconds, a minute, that sort of rate) via a zero-crossing SSR would
avoid the transients of per-cycle triac switching.

For tank heating PWM can be very slow due to the high thermal inertia. If not using a PID loop
just use simple bang-bang control with hysteresis.

Sounds like you've picked up a lot of EMI via the heater capacitively coupling to the tank.

Thanks very much:

This makes sense as the PH gauge has a fluctuation which it recovers from whenever the heater is first plugged in!

The main benefit I successfully achieved is a very consistent temperature, the temperature sensor feeds back and the power to the heater is adjusted to maintain temperature to an exact value (most click on/off heaters allow a variance of over a degree, mine tends to keep it to within 0.1 and the power output normally settles down to around 40%.

Dimming the heater in this way gives me all the benefits I want apart from the interference!

Are you saying a constant slow pulsing on and off of the ssr would be the answer?

I'm sorry some of your terminology went a little over my head even after googling!

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

jamathon:
Thanks very much:

This makes sense as the PH gauge has a fluctuation which it recovers from whenever the heater is first plugged in!

The main benefit I successfully achieved is a very consistent temperature, the temperature sensor feeds back and the power to the heater is adjusted to maintain temperature to an exact value (most click on/off heaters allow a variance of over a degree, mine tends to keep it to within 0.1 and the power output normally settles down to around 40%.

Dimming the heater in this way gives me all the benefits I want apart from the interference!

Are you saying a constant slow pulsing on and off of the ssr would be the answer?

I'm sorry some of your terminology went a little over my head even after googling!

PWM = pulse width modulation (actually it means duty-cycle modulation, but hey). The per-cycle
switching in the triac circuit is a form of PWM running at 100 or 120 Hz, but the worse way possible for
interference.

Using a lower frequency of switching (such as once per 15 seconds) will work just as well given the
thermal time constants involved (hours probably), and generate less interference - especially if you
use an SSR that switches at the zero crossing (less interference as high currents are not involved at
the switching point).

Slow PWM needs to be software driven as the hardware PWM units in the microcontroller have a lower
frequency of operation as well as an upper one.