SSR flickering problem


I am trying to run below code for AC circuit using SSR but AC powered halogen light bulbs flickers.

some people in the forums say that special arduino code or 555 timer or 741 coupler need to be used for zero crossing voltage...

please advise how to solve this problem.

Thank you.

Parts available in the attached photo;

MOC3020 (according to play ground tutorial)
H11aa1m (according to play ground tutorial)
lots of mosfets, resistors etc..

const int led = 9; // the pin that the LED is attached to
const int sensor1 = A1;
const int sensor2 = A2;
int brightness = 250; // how bright the LED is
int lightgoal = 0;
int maxbrightness =252;
const int upfadeAmount = 5; // how many points to fade the LED by
const int dnfadeAmount = 3; // how many points to fade the LED by
int timer = 1000;
// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
  pinMode(sensor1, INPUT); // declare sensorpins as inputs
  pinMode(sensor2, INPUT);
// the loop routine runs over and over again forever:
void loop() {
  if (digitalRead(sensor1) == HIGH || digitalRead(sensor2) == HIGH) { // detect if either sensor triggered
    timer = 15; // every increment adds about a tenth of a second
    lightgoal = maxbrightness; // set lights to turn on
    //if (brightness == 0){ brightness = 1;}
  /// light brightness / fading section
  if(brightness == lightgoal){ // is the brightness where we want it?
    if (timer == 0){
      lightgoal = 0;
    delay(100); // finctioning delay in timer, not very percise
    timer = timer - 1; //countdown the timer with every loop
    if(brightness < lightgoal){ // is the brightness too low?
      // raise the brightness
      brightness = brightness + upfadeAmount;
    else { // if the light isn't too low, it's too high
      // lower the brightness
      brightness = brightness - dnfadeAmount;
    // set the brightness (pwm duty cycle) of led
    analogWrite(led, brightness);
    // wait for 30 milliseconds to see the dimming effect

  1. Those pictures are way too big.
  2. Can you post a schematic?
  3. analogWrite(led, brightness) - you can not apply PWM to an SSR it simply will not work. This is because once triggered the SSR will stay on until the next half cycle. The result is that it will beat and yes cause flickering.
  4. why delay(100) ?

First there are two types of SSR

  • With Zero crossing detector. These cannot be used for dimming but they are great for turning loads with long time constants (heaters) on and of
  • Without zero crossing detection, these can used for dimming,. But in order to acheive a dimming function you must establish phase angle control by synchronizing with the zero crossing of the mains voltage