Zero crossing detection

Hi guys , im using this ssr
i need to make a project in arduino for zero crossing detection... can anyone help me with the code and scheme .
Also an optocoupler ( H11AA1 ) may be needed. I would really appreciate all help provided.

Hello robertbr15,

Welcome to the Arduino fora. I and the other people here want to help you but to do that we need certain bits of information. Without the correct information it is difficult or impossible to give you the help and advice you need. To help us to help you please read General guidance andHow to use this forum and provide the information asked for. Being new here you might think this is asking too much or having rules for the sake of rules, that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of message while we try to get you to tell us what we need in order to help you, this is frustrating for you and frustrating for us.

Common mistakes for people posting here the first time:
Code problems:
Not posting any code while expecting us to work out what is wrong with your code; we are not telepathic and can only find problems in code we can see.
Posting a snippet of code in the belief that the problem is in the code snippet. It is almost always the case that the problem is not where you think it is but elsewhere in the code, hence we need all the code.
Not correctly formatting code. Before posting code use Tools / auto format at the top of the IDE, or use control T. Once you’ve done that use edit / copy for forum.
Posting code without code tags (</>), these are explained in the instructions linked to above. Using code tags makes the code easier to read. Not using code tags means some of the code gets interpreted as HTML with the result that it is displayed with smiley faces and other stuff that should not be there.
Posting an image of code instead of the code itself, or an image of error messages instead of the error messages themselves.
Not being clear about what is expected from code or what happened instead. Code ALWAYS works, that is the nature of code. Whether it does what you expect is a different thing altogether. We need to know what you expected the code to do and what happened instead.
Asking for complete code; we are not here to write code for you, we are here to help you if you get stuck writing code yourself. If you really want someone to write code for you please click on ‘report to moderator’ and ask them to move this to ‘Gigs and Collaborations’ and indicate how much you are willing to pay.

The language of electronics is a schematic or circuit diagram. Long descriptions of what is connected to what are generally useless. A schematic is a drawing of what connects to what, please make one and photograph it. We don’t mind if it’s hand drawn, scruffy and does not use the correct symbols. We do mind if you don’t at least try to post a schematic. Please read How to post an image

Posting links to other sites where code or photos or schematics are hosted. Most of us will not follow such links, partly because of the risk that they hold malware or other unwanted content, partly to maintain everything on this site for the benefit of future users looking for an answer to a similar question and partly because we feel that if you want our help you should provide everything we need on this site not expect us to go hunting elsewhere for it.

Not being clear about what is being asked, for example not asking a question at all or asking a vague question like ‘please help’ or ‘it doesn’t work’ or some such thing.

About us:
Those of us answering questions have a wide variety of backgrounds and electronics knowledge, some though working in electronics, some through electronics as a hobby, some both. Most of us are not trained as teachers so probably miss the finer points of how to teach and explain things effectively. We are not, with the odd exception, employees or representatives of Arduino.
Please also remember we are volunteers doing this for free in our spare time and are more inclined to help people who make it easy for us to provide help by providing the information we ask for.

About you:
We only know about you what you tell us; we need to know your level of experience with electronics or microcontrollers, if we don’t know then we can’t tailor our answer to your level of knowledge. We also don’t know if you have problems with English or language or communications in general unless you tell us. We can be sympathetic about problems we know about, but if you don’t tell us we don’t know.

Thank you.

I assume you're trying to build a light dimmer?

Just a couple of "hints" -

The zero crossing must be isolated from the power line. It can be done with an opto-isolator or with a transformer.

The relay provides isolation on the output so there should be no direct connection between the Arduino and the power line. The SSR must NOT be the zero-crossing type if you are making a dimmer.

Either way, you are usually detecting near zero crossing, and a transformer may introduce a phase shift.

If you are building your own power supply with a transformer it's handy to use the (unrectified) transformer output. (with a voltage divider or an over-voltage protection circuit for the Arduino). Otherwise, optical isolation is probably better.

Make sure to calculate the power dissipation for the opto-isolator's current limiting resistors. Generally you need 2W resistors.

OP probably left but for others:

I don’t see any reason the ZC circuit must be isolated. Of course it is somewhat safer/easier if done correctly. But using the optocoupler incorrectly (connecting grounds is a common mistake) will provide no protection, only dangerous illusion of safety.

Included is an app note describing a dangerous non-isolated but very simple ZC.

AVR182 Zero Cross Detector.pdf (230 KB)