Phase control of mains voltage

rising_and_falling_edge_detection.ino (594 Bytes)
modified_rising_edge_detector.ino (1.1 KB)
I have made a very simple zero voltage crossing detector which gives a high pulse at zero crossing of the mains voltage. Schematic included. Then I used an Arduino sketch to use it in phase control. I used a random phase optocoupler and triac to vary the brightness of a mains filament globe.
The results are excellent. No flicker at all in the globe. Then I tried using it with a sketch that read an analog voltage which was supposed to vary the on/off points of the mains. This sketch failed but no error message in the coding itself.
I have uploaded both sketches. Can anybody point out what may be wrong in my extended sketch? And suggest something that will work.
Not sure if the sketches have been uploaded properly. Couldn't upload the schematic for the detector. Its an Ltspice simulation. Suggestions how to do this.

@petercl14, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project :wink: See About the Installation & Troubleshooting category.

Please insert your code in a post instead of attaching; some people use cell phones and can't read ino files and you miss out on their knowledge. Don't forget to use code tags (just in case).

There is no schematic.

Upload a screenshot of the schematic in spice.

Further to my recent topic on this subject here is a picture of my simple zero crossing circuit which I couldn't upload as a Ltspice schematic. Hope this works. It can be simulated in Ltspice.Processing: pulse edge detection picture.rtf...
Sorry still doesn't work. Trying to put it in pictures. Suggestion please as to how I can upload this. Tried print screen and saved in wordpad and then in documents. The upload here didn't accept this. Wrong file type.

Topics merged

Why did you create a new one instead of adding to teh existing one ?

Take a screenshot in Windows of the window with the schematic in and then paste the screenshot directly into a post

There is no need to use an intermediate program

didn't know how to do it. also don't know how to get screenshot of circuit onto the website.
Here I will try now. Control c and then control v for paste. Doesn't work for a screenshot. Would for text. Why does this website make things so difficult?

Has your keyboard got a Print Screen button ?

Sorry, but I find it very easy to copy screenshots, both full and partial, into posts here. I use WinKey+shift+s to activate the Windows snip tool then select the screen section that I want, which copies it to the clipboard, then simply Ctrl+V to paste it here

An example :
image

You registered over a year ago :wink: You probably never tried to upload an image in the old forum; this new forum is an aboslute pleasure when it comes to inserting images :smiley: Basically it's just drag-and-drop.

Doesn’t work for me. Yes I have a print screen button and I always save to wordpad. No snip tool.

Use <alt><printscreen> to copy the active window to the clipboard.
Open a reply in your topic, place the cursor in there and use <ctrl>V to paste.

As I said earlier

Got it.That works. This is a great zero crossing circuit. Much simpler than anything else I have seen. Try a simulation on Lt spice.

Where are you applying the AC? and how frequently are you measuring with the analog read?
Paul

The AC is applied to a random phase optocoupler connected to a triac. At the moment the triac is connected to a mains filament globe. It could be connected to any AC appliance with a suitable heat sink.
I think I see a problem now from your second point. While waiting for the high going pulse at zero crossing the analog voltage is being read continuously in the 'while' loop. It only needs to be read after the high going pulse is detected. I will try putting the analog read in the 'if' loop. If this doesn't work I will get the analog read say every 1 minute using the ms elapsed from the start of the program.
Thanks for your input Paul. I am Peter.

I was trying to make the point that your program may not be doing the analog often enough to catch the zero crossing point. You cannot know the low or the high point until it is one measurement past the point.

Hello Peter, welcome to the world of electronics and microcontrollers.
Paul

Hi Paul, I had the programming wrong. I had the read analog before the main ‘while’ loop. So while in the ‘while’ loop the program couldn’t get the analog read. So now I have the read analog after the zero crossing detection.Working much better now but still some problem at the extremities of the main ‘while’ loop.

This problem can probably be fixed by only getting the analog read every minute. It is a temperature reading and doesn’t change much over time. This way I will be getting a fixed temperature reading for a minute and then I wont get the annoying flashing of the globe at the extremities.

I may use an interrupt every minute using the millisecond recording of how long the program has been running.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.