# ac dimmer circuit

Hi
Im looking to integrate the ac dimmer circuit with a tmp36 temperature sensor. What im looking to do is dim the load based on the input temperature.
My circuit and code is based on http://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/
I still cannot get it to work so went about trying to understand the code given but for the life of me cannot understand it. I know from reading the temperature sensor and input and output example code, i may need to map the values given from my input and then use a similar code based on this instructables page...
Just to give you an idea the project is for controlling temperature in a vivarium.

Thanks

Here’s the code, in case anyone was wondering.

``````/*

AC Voltage dimmer with Zero cross detection
Attach the Zero cross pin of the module to Arduino External Interrupt pin
Select the correct Interrupt # from the below table (the Pin numbers are digital pins, NOT physical pins: digital pin 2 [INT0]=physical pin 4 and digital pin 3 [INT1]= physical pin 5)

Pin    |  Interrrupt # | Arduino Platform
---------------------------------------
2      |  0            |  All
3      |  1            |  All
18     |  5            |  Arduino Mega Only
19     |  4            |  Arduino Mega Only
20     |  3            |  Arduino Mega Only
21     |  2            |  Arduino Mega Only

In the program pin 2 is chosen
*/
int AC_LOAD = 3;    // Output to Opto Triac pin
int dimming = 128;  // Dimming level (0-128)  0 = ON, 128 = OFF

void setup()
{
attachInterrupt(0, zero_crosss_int, RISING);  // Choose the zero cross interrupt # from the table above
}

// the interrupt function must take no parameters and return nothing
void zero_crosss_int()  // function to be fired at the zero crossing to dim the light
{
// Firing angle calculation : 1 full 50Hz wave =1/50=20ms
// Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) For 60Hz => 8.33ms (10.000/120)
// 10ms=10000us
// (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65

int dimtime = (75*dimming);    // For 60Hz =>65
delayMicroseconds(dimtime);    // Off cycle
delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
}

void loop()  {
for (int i=5; i <= 128; i++){
dimming=i;
delay(10);
}
}
``````

Does the code work as is (without trying to modify it for temperature)? If not, you have a hardware problem. If it does, then the modifications you made, which are not going to be on the site you linked, are the problem.

As soon as i made the post i got the circuit working and the load does dim with the above code.... still need to integrate the temperature code though, i think i have an idea of how to do this now, although any hints/help would be brilliant

still need to integrate the temperature code

You haven't posted "the temperature code"

apoligies, im actually at work at the moment, they have blocked sites for 'shopping' ha,
the code is from this website anyways

i can post the code properly later....

//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures

/*

• setup() - this function runs once when you turn your Arduino on
• We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
}

void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor

// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;

// print out the voltage
Serial.print(voltage); Serial.println(" volts");

// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degrees C");

// now convert to Fahrenheight
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(" degrees F");

delay(1000); //waiting a second
}