user39505: I am making use of the code below to control the speed of an AC fan and the intensity of an AC Lamp with an Uno.
The problem I am having is that, when I set the lamp intensity to low or medium, the fan turns on at a very low speed as well, and I cannot turn it off even when setting the fan to off. 
Also if I turn the lamp on and then off, the fan (which is still set as off), will spin slowly for a second or two in random intervals.
For troubleshooting purposes, I did separate this program into two programs, controlling each device and its circuit separately, and it works perfectly, but when I combine them, I get the above problem.
Any assistance in troubleshooting or ideas to solve this would be appreciated.
Haven't attempted AC control before.
int PWM = 3;
int FAN = 4;
int dimming;

void setup()
{
  Serial.begin(9600);
  Serial.println("Serial connection started, waiting for instructions…n0 =     Offn1 = 25%n2 =50%n3 = 75%n4 = 100%");
  pinMode(PWM, OUTPUT);
  pinMode(FAN, OUTPUT);

  attachInterrupt(0, zero_crosss_int, RISING);
}

void zero_crosss_int()
// function to be fired at the zero crossing to dim the light
{
  int dimtime = (75 * dimming);  // For 60Hz =>65
  delayMicroseconds(dimtime);    // Off cycle
  digitalWrite(FAN, HIGH);   // triac firing
  delayMicroseconds(10);         // triac On propogation delay
  //(for 60Hz use 8.33)
  digitalWrite(FAN, LOW);    // triac Off
}


void loop ()
{
  if (Serial.available()) {
    char ser = Serial.read(); //read serial as a character


    switch (ser)
{

  /* Lamp Control  */

  case '0':
    analogWrite(PWM, 0);  //lamp Off
    break;
  case '1':
    analogWrite(PWM, 50);  //lamp low
    break;

  case '2':
    analogWrite(PWM, 130); //lamp medium
    break;

  case '3':
    analogWrite(PWM, 255); //lamp high
    break;

  /* Fan Control  */


  case '4':
    dimming = 128;  //fan off
    break;

  case '5':
    dimming = 90; //fan low
    break;

  case '6':
    dimming = 65; //fan medium
    break;

  case '7':
    dimming = 35; //fan high
    break;

  default:
    Serial.println("Invalid entry");

    }
  }
}

The circuits it controls is based on these :
Lamp

Fan

Also, these circuits and code are based on these post, if it may interest you:
Lamp
PWM AC Lamp
Fan
Dimmer AC Fan

user39551: The design of the zero_crosss_int() ISR is unreliable. After each interrupt it unconditionally turns on the triac, even in the OFF position. Since the dimming value in that case is close to the AC cycle duration, it may miss the current cycle and turn on early in the next cycle. This may happen e.g. due to noise in zero crossing input.
75 us * 128 = 9.6 ms. Assuming 50 Hz AC, cycle duration is 1000 ms / 100 = 10 ms. You only have 4% margin.
You need to avoid turning on the triac close to the end of the AC cycle. Limit the maximum value of dimming variable to, say, 75% of the AC cycle. This will impose a lower limit on the output power. However, you want to do this anyway because motors need a minimum power to start rotating. Adjust the ISR so that in the OFF position it does not send a positive pulse at all.
ADDED: so you just need to add an if statement to you ISR code:
void zero_crosss_int()
// function to be fired at the zero crossing to dim the light
{
  if (dimming > 96) // choose this value experimentally, adding some margin
    return;
  ... everything else goes here ...
}

ADDED2: Blocking for extended duration in the ISR is not a good idea in general. If you happen to need to do anything else in addition to 'dimming' a fan, you will almost certainly need to get rid of this. You could start a timer in the ISR and send the output pulse in the timer ISR, making sure that the timer ISR does not get executed after the next zero-crossing ISR...

user39652: Imraan, you have most definitely NOT build your circuit safely as to do so is impossible on a 'breadboard' when using 220 VAC.  The contacts on these boards are extremely poor not to mention that the separation between the metal contacts is inadequate.  Please read up on track separation for mains voltages on PCB's to get an idea of what is required.
The commonly used 0.1" pitch strip board is also unsuitable for mains voltages.

39505: <p>I am making use of the code below to control the speed of an AC fan and the intensity of an AC Lamp with an Uno.</p>

<p>The problem I am having is that, when I set the lamp intensity to low or medium, the fan turns on at a very low speed as well, and I cannot turn it off even when setting the fan to off. </p>

<p>Also if I turn the lamp on and then off, the fan (which is still set as off), will spin slowly for a second or two in random intervals.</p>

<p>For troubleshooting purposes, I did separate this program into two programs, controlling each device and its circuit separately, and it works perfectly, but when I combine them, I get the above problem.</p>

<p>Any assistance in troubleshooting or ideas to solve this would be appreciated.
Haven't attempted AC control before.</p>

<pre><code>int PWM = 3;
int FAN = 4;
int dimming;

void setup()
{
  Serial.begin(9600);
  Serial.println("Serial connection started, waiting for instructions…n0 =     Offn1 = 25%n2 =50%n3 = 75%n4 = 100%");
  pinMode(PWM, OUTPUT);
  pinMode(FAN, OUTPUT);

  attachInterrupt(0, zero_crosss_int, RISING);
}

void zero_crosss_int()
// function to be fired at the zero crossing to dim the light
{
  int dimtime = (75 * dimming);  // For 60Hz =&gt;65
  delayMicroseconds(dimtime);    // Off cycle
  digitalWrite(FAN, HIGH);   // triac firing
  delayMicroseconds(10);         // triac On propogation delay
  //(for 60Hz use 8.33)
  digitalWrite(FAN, LOW);    // triac Off
}


void loop ()
{
  if (Serial.available()) {
    char ser = Serial.read(); //read serial as a character


    switch (ser)
{

  /* Lamp Control  */

  case '0':
    analogWrite(PWM, 0);  //lamp Off
    break;
  case '1':
    analogWrite(PWM, 50);  //lamp low
    break;

  case '2':
    analogWrite(PWM, 130); //lamp medium
    break;

  case '3':
    analogWrite(PWM, 255); //lamp high
    break;

  /* Fan Control  */


  case '4':
    dimming = 128;  //fan off
    break;

  case '5':
    dimming = 90; //fan low
    break;

  case '6':
    dimming = 65; //fan medium
    break;

  case '7':
    dimming = 35; //fan high
    break;

  default:
    Serial.println("Invalid entry");

    }
  }
}
</code></pre>

<p>The circuits it controls is based on these :</p>

<p>Lamp
<a href="https://i.stack.imgur.com/6Gavz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6Gavz.jpg" alt="PWM AC Lamp"></a></p>

<p>Fan
<a href="https://i.stack.imgur.com/95J35.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/95J35.jpg" alt="Dimmer AC Fan"></a></p>

<p>Also, these circuits and code are based on these post, if it may interest you:</p>

<p>Lamp
<a href="https://diyhacking.com/arduino-lamp-dimmer/" rel="nofollow noreferrer">PWM AC Lamp</a></p>

<p>Fan
<a href="https://arduinodiy.wordpress.com/2012/10/19/dimmer-arduino/" rel="nofollow noreferrer">Dimmer AC Fan</a></p>
 39551: <p>The design of the zero_crosss_int() ISR is unreliable. After each interrupt it unconditionally turns on the triac, even in the OFF position. Since the <code>dimming</code> value in that case is close to the AC cycle duration, it may miss the current cycle and turn on early in the next cycle. This may happen e.g. due to noise in zero crossing input.</p>

<p>75 us * 128 = 9.6 ms. Assuming 50 Hz AC, cycle duration is 1000 ms / 100 = 10 ms. You only have 4% margin.</p>

<p>You need to avoid turning on the triac close to the end of the AC cycle. Limit the maximum value of <code>dimming</code> variable to, say, 75% of the AC cycle. This will impose a lower limit on the output power. However, you want to do this anyway because motors need a minimum power to start rotating. Adjust the ISR so that in the OFF position it does not send a positive pulse at all.</p>

<p>ADDED: so you just need to add an <code>if</code> statement to you ISR code:</p>

<pre><code>void zero_crosss_int()
// function to be fired at the zero crossing to dim the light
{
  if (dimming &gt; 96) // choose this value experimentally, adding some margin
    return;
  ... everything else goes here ...
}
</code></pre>

<p>ADDED2: Blocking for extended duration in the ISR is not a good idea in general. If you happen to need to do anything else in addition to 'dimming' a fan, you will almost certainly need to get rid of this. You could start a timer in the ISR and send the output pulse in the timer ISR, making sure that the timer ISR does not get executed after the next zero-crossing ISR...</p>
 39652: <p>Imraan, you have most definitely NOT build your circuit safely as to do so is impossible on a 'breadboard' when using 220 VAC.  The contacts on these boards are extremely poor not to mention that the separation between the metal contacts is inadequate.  Please read up on track separation for mains voltages on PCB's to get an idea of what is required.
The commonly used 0.1" pitch strip board is also unsuitable for mains voltages.</p>
