Arduino Pure Sine Wave Inverter Circuit with Full Program Code
LAST UPDATED ON BY SWAGATAM 508 COMMENTS
This article explains a simple pure sine wave inverter circuit using Arduino, which could be upgraded to achieve any desired power output as per the user's preference
Circuit Operation
In the last article we learned how to generate sine wave pulse width modulation or SPWM though Arduino, we are going to use the same Arduino board to make the proposed simple pure sine wave inverter circuit.The design is actually extremely straightforward, as shown in the following figure.
You just have to program the arduino board with the SPWM code as explained in the previous article, and hook it up with some of the external devices.
![Arduino Pure Sine Wave Inverter Circuit](https://www.homemade-circuits.com/wp-content/uploads/2017/04/arduino-2.png)
Pin#8 and pin#9 generate the SPWMs alternately and switch the relevant mosfets with the same SPWM pattern.
The mosfst in turn induce the transformer with high current SPWM waveform using the battery power, causing the secondary of the trafo to generate an identical waveform but at the mains AC level.
The proposed Arduino inverter circuit could be upgraded to any preferred higher wattage level, simply by upgrading the mosfets and the trafo rating accordingly, alternatively you can also convert this into a full bridge or an H-bridge sine wave inverter
Powering the Arduino Board
In the diagram the Arduino board could be seen supplied from a 7812 IC circuit, this could be built by wiring a standard 7812 IC in the following manner. The IC will ensure that the input to the Arduino never exceeds the 12V mark, although this might not be absolutely critical, unless the battery is rated over 18V.
![](https://www.homemade-circuits.com/wp-content/uploads/2017/04/7805IC-1.png)
If you have any questions regarding the above SPWM inverter circuit using a programmed Arduino, please feel free to ask them through your valuable comments.
Waveform Images for Arduino SPWM
![Arduino Pure Sine Wave Inverter Circuit SPWM waveform](https://www.homemade-circuits.com/wp-content/uploads/2017/04/11931-1.jpg)
Image of SPWM waveform as obtained from the above Arduino inverter design (Tested and Submitted By Mr. Ainsworth Lynch)
UPDATE:
Using BJT Buffer Stage as Level Shifter
Since an Arduino board will produce a 5V output, it may not be an ideal value for driving mosfets directly.
Therefore an intermediate BJT level shifter stage may be required for raising the gate level to 12V so that the mosfets are able to operate correctly without causing unnecessary heating up of the devices,. The updated diagram (recommended) can be witnessed below:
![simple Arduino sinewave inverter circuit using SPWM](https://www.homemade-circuits.com/wp-content/uploads/2017/04/arduino.jpg)
For the full Program Code please visit the following link: Arduino SPWM Generator Circuit
Video Clip
Parts List
All resistors are 1/4 watt, 5% CFR
- 10K = 4
- 1K = 2
- BC547 = 4nos
- Mosfets IRF540 = 2nos
- Arduino UNO = 1
- Transformer = 9-0-9V/220V/120V current as per requirement.
- Battery = 12V, Ah value as per requirement
Delay Effect
To ensure that the mosfet stages initiate with a delay during the Arduino booting or start up, you may modify left side BC547 transistors into delay ON stages, as shown below. This will safeguard the mosfets and prevent them from burning during power switch ON Arduino booting.
![](https://www.homemade-circuits.com/wp-content/uploads/2021/09/Arduino-booting-delay-circuit.jpg)
FOR INCREASING THE DELAY YOU CAN INCREASE THE 10K VALUE TO 100K
Adding an Automatic Voltage Regulator
Just like any other inverter the output from this design can rise to unsafe limits when the battery is fully charged.
To control this an automatic voltage regulator could be employed as shown below.
The BC547 collectors should be connected to the bases of the left side BC547 pair, which are connected to the Arduino via 10K resistors.
![Arduino sinewave output correction automatic](https://www.homemade-circuits.com/wp-content/uploads/2019/03/Arduino-regulation.jpg)
For an isolated version of voltage correction circuit we can modify the above circuit with a transformer, as shown below:
![](https://www.homemade-circuits.com/wp-content/uploads/2019/04/isolated-voltage-correction.jpg)
How to Setup
To set up the automatic voltage correction circuit, feed a stable 230V or 110V as per your inverter specs to the input side of the circuit.
Next, adjust the 10k preset carefully such that the red LEDs just light up. That's all, seal the preset and connect the circuit with the above Arduino board for implementing the intended automatic output voltage regulation.
Using CMOS Buffer
Another design for the above Arduino sinewave inverter circuit can be seen below, the CMOS IC is used as an aided buffer for the BJT stage
![SPWM Arduino inverter](https://www.homemade-circuits.com/wp-content/uploads/2017/04/SPWM-Arduino-inverter.jpg)
Important:
In order to avoid an accidental switch ON prior to Arduino booting, a simple delay ON timer circuit may be included in the above design, as shown below:
![Arduino with switch ON delay](https://www.homemade-circuits.com/wp-content/uploads/2017/04/spwm-arduino.jpg)
You'll also like:
- 1. How to Build a 400 Watt High Power Inverter Circuit
- 2. Solid-State Inverter/Mains AC Changeover Circuits Using Triacs
- 3. Calculating Solar Panel, Inverter, Battery Charger
- 4. Designing a Grid-Tie Inverter Circuit
- 5. Arduino LCD KeyPad Shield (SKU: DFR0009) Datasheet
- 6. 7 Simple Inverter Circuits you can Build at Home
About Swagatam
I am an electronic engineer (dipIETE ), hobbyist, inventor, schematic/PCB designer, manufacturer. I am also the founder of the website: https://www.homemade-circuits.com/, where I love sharing my innovative circuit ideas and tutorials.
If you have any circuit related query, you may interact through comments, I'll be most happy to help!
Have Questions? Please Comment below to Solve your Queries! Comments must be Related to the above Topic!!
very interesting. can we convert DC to AC 11w tube using hybrid transformer?
expecting your valuable guidance.
Yes that’s possible. Yu can try the following circuit:
https://www.homemade-circuits.com/electronic-ballast-circuit-for-uv-germicidal-lamps/
Hi Swagatam
I am Designing the H bridge converter, I required Sinusoidal at high frequency (3kHz). Can you guide me on How should I change the Arduino code to obtain High Frequency at Output?
Regards
Hi Leo,
.webp
you can probably try the following circuit for the H bridge design, but make sure the battery and transformer are 12V rated.
Changing the code can be plenty of hard work and a lot of thinking. Basically you will have to replace each of the microsecond delays with smaller delays such that they together add up to produce 3000 Hz for each channel.
Hello Swagatam. You have great circuits and great explanations to teach folks about the circuits. Here’s my idea: 55 gal blue drum full of 400 pounds of water is my gravity battery. Pull it up to some height with a block and tackle. My goal is to run a 5000 btu ac for 1 hour. 5000btuas/3412btusper kw is about 1400 watts, and running this contraption would give some cool air for an hour. Then make someone else crank the drum back to to run it again. At first I looked into a 3phase PMA alternator that puts out 12V 3phase… Read more »
Thanks Bob! Your concept looks interesting.
If you are looking for a circuit to limit the speed and the voltage output of an alternator, then yes that can be done through a simple shunt regulator circuit. Is the alternator a 3 phase alternator or a single phase alternator?
Hello Swagatam.
I wish to thank you for all the circuits you make available for free on your site. They are very educational to a amateur radio operator like me. My call is KE4WCE.
My question is where in the code for the Arduino Pure Sine Wave Inverter Circuit would I need to change from 50Hz (cycles) to 60Hz and replace it with what number.
Or if you don’t mind me asking the math formula and a example so I may able to do it myself.
Thank You 73’s
Thank you very much Amos,
In the Arduino code explained above we have used the total delay on each channel as 10 ms, since each 50 Hz AC half cycle requires 10ms to complete. For a 60 Hz cycle the completion time of half cycle becomes 12 ms. So you will have to adjust the microsecond time (in brackets) on each channel of the code in such a way that it produces a delay of 12 ms or 12000 microseconds.
Thank you For the fast reply. I am going to have a go at it and see if I can duplicate your circuit. Again Thank you for your time and patience.
73’s
I am glad to help!
HI,
I Build the first most simple’s project on the page. After programming my arduino I founded that my irf540 is heating up and when i checked the frequency on my arduino ouput it was around 500 hz . I am most certain thats why the mosfets heat up. I cannot see what i am doing wrong. Advise please
Regards
Peter
MOSFETs can work with frequencies up to MHz and GHz, so frequency can never be a problem, I have tested the design thoroughly and had no such problems. My MOSFETs also heated up a a little but it was because of the 100 watt load at the output of the transformer. If your MOSFETs are heating up due to an output load then it is normal, simply put a heatsink on it.
And one more thing…. instead of using high voltage capacitors at transformer output for waveform smoothing. can we use low voltage capacitors at the transformer input??? voltage and power handling will be easier… what say??
I don’t think that might be possible, because at the input side everything is PWM based and digital which cannot be transformed into an analogue sine wave….the transformation may be possible only at the output side of the transformer.
Hiii Swagatam, The delay circuit is introduced as a safety. But What I say is instead of introducing a circuit why dont we use aurduino digital output signal to switch the DC supply to inverter circuit. mainly for three reasons, 1) Human error is eliminated. 2) circuit is simplified 3) Delay circuit malfunction hazard is also eliminated. Whats your say in this??
Thanks Vivek,
My Arduino knowledge is not good, so I won’t be able to suggest on this modification. If you think this is something feasible then surely it can be implemented and tried in this design.
Best Swagatam
I may be understanding the circuit diagram wrong but I simulated the circuit and it does not seem to work.
I don’t understand how the positive terminal can be connected directly to the base of the mosfet. What is the reason for the BJT level shifters? Also a positive voltage is applied again directly (resistor in series… so voltage division?) to the bjt. I would like to build this circuit but cannot seem to understand its working principle.
Would it be possible to communicate by email for me to better understand the circuit please?
Kindest Regards Christiaan
Christiaan, level shifters are necessary to enable the mosfets gates to get 12V supply so that they can conduct optimally. If we connect the mosfets directly with the Arduino, the gates will be be able to get only 5V which may not be sufficient for the mosfets to switch ON perfectly. The first BC547 inverts the Arduino PWM so it cannot be directly used with the mosfets otherwise the mosfets gates would be switched with inverse PWM signals. The second BC547 corrects this issue and makes the PWM same as the Arduino output, but at 12V level The circuit is… Read more »
Thank you for the response.
That makes sense but wont the voltage to the mosfet be 13.3V since this is more the operating voltage of a 12V battery? Is this still a suitable value?
Then lastly do you have a inverter circuit that does not use a transformer but still steps up from 12V to 230V?
Sincerely Christiaan
Most mosfet gates are designed to work with upto 20V, so 13V is quite OK.
Making an 12V to 230V inverter without a transformer is almost impossible, as far as I know.
Thanks for the replies Swagatam.
This is definitely one of the only sites where you get replies.
What is the wattage of this inberter?
It’s my pleasure Tiaan.
Hello
Can you show the charging circuit?
All the best
J K BARIK
Sure, you can get the desired battery charger circuit from these two articles:
Lead Acid Battery Charger Circuits
Op amp Battery Charger Circuit with Auto Cut Off
Hello sir , can you please tell me how the feedback circuit works and why you connect them in the gate of the Mosfet but not in the arduino .
Lalawmpuia, where do you think the feedback can be connected with the Arduino? It will require special coding for that. Connecting the feedback to MOSFET gates is an universal option which can configured easily without any coding by anybody and with any inverter.
Sir can you please explain how the BC547 collector is connected to the base/gate of the BJT/Mosfet . Since I have a hard time understanding that . Since the emmiter side is connected to ground and does that simply pull down ?
The BC547 collector will pull down the mosfet gate while it is ON, and when it is OFF the mosfet gate will get the switching voltage through the 1K resistor.
How does the feedback works? since the feedback ( bc547) emmiter is connected to the base of the bc547( arduino output ) will it just pull down from bc547 base to ground . Please explain the worling of this feedback . Also I tried your Circuit and code as well but I have burn out 10 mosfet ( 5 times irfz44n and 5 times irf3205 ) in just under 10 seconds . It was too hot to even touch .
When the input voltage to the op amp circuit exceeds the set limit the op amp output and the BC547 conduct and grounds the Arduino BC547 bases causing the mosfets to shut off. As soon as the mosfets are turned off the voltage begins to drop which reverts the opamp output causing the mosfets to switch ON again, and this process continues which keeps the output voltage within the desired range. Your mosfets may be burning due to some fault in your design, or may be the mosfets are not good quality. You can in the video the circuit works… Read more »
Thank you so much .
Hello sir , I have a question about the transformer , if I use a 6-0-6 transformer rated at 3A , at ideal mode , what will be the rated watt of the output ? Since 3A is the highest rated transformer I can buy from our state .
Hello Fanai, it will be 6 x 3 = 18 watts for each half cycle of AC output, that means for one full AC cycle it can be around 36 watts
Hello sir , how are you ?
I have one question regarding the feedback , my circuit is exactly same as your circuit , and the transformer I used is from an old ups , and the question is , the output Voltage decrease to 140V from 210V when connected a load . Will the feedback you posted work in this situation to give 220V constant even when connected to a load ( 60W incandescent lamb) ?
Hello Fanai, no, the feedback cannot boost a low voltage happening due to over load or low wattage transformer/battery, it can only prevent an over voltage. To correct the voltage drop you must ensure that the transformer, battery and the mosfets are appropriately rated as per the load requirement.
k. well the solution i have now will have to do till i have more time. seems the best way forward will be to build an inverter that doesnt have over voltage protection. when i have time i’ll pull the transformer out of the old inverter, check it to make sure it meets the specs of the Arduino. i’ll also grab the heat sinks for the mosfets. then i’ll have another 1000 questions for you. thank you for your help.
Sure, no problem, all the best to you!
this may be off topic, i’m looking at building this inverter but perhaps its better to tell you what my problem is first because you may have a better solution. i have a 300 watt inverter thats doing just fine. but its connected to lithium ion batterys instead of lead acid. the ion batterys are 4p so top voltage is 16.4. the inverter has i high voltage cut off at 15.5. i’m working around the problem by placing a buck inverter between the batterys and the inverter, the buck inverter is set to output at 14.9 volts. this works but… Read more »
Using a buck converter between the battery and the inverter can be indeed quite wasteful, but unfortunately there’s no other more efficient way than a buck converter, except if one Li-Ion cell is reduced, and a 3S combination is used with a 12.6V output supply. The transformer winding rating must match the PWM average of the Arduino in the above explained concept. The average voltage at the collector of the first BC547 transistor will be the value that must match the half winding specs of the transformer. So definitely you can salvage the transformer from your 3000 watt inverter but… Read more »
Hi Mr
i have built a small circuit using Bc547 & Bc557 as BJT Buffer stage to drive the Mosfets (i’m using IRFZ46)
when i check the ouput of the buffer stage connected to Arduino uploaded with Spwm Code
on DSO138 oscilloscope the output is same as the pattern of the wave in the picture on the page
But on the Drain of the Mosfet its square wave
Why?
My circuit using readymade oscillator SG3524 is working fine
But using the Arduino the output is connected to lamp & is flashing
any idea?
thanks for ur Help
I need another circuit which i didnt know how to contact the page
a small Solid state relay using mosfets which have Com positive or negative 12V
NC NO so i can select which source to use power of
2 12v dc inputs & 1 output \]
Thanks
You must do exactly as shown in the above schematics because it is a tested design, I cannot suggest about any other configuration.
if i connect the oscilloscope to the Drain of the Mosfet should i see the same signal as the arduino output ?
i will test it with 2 npn transistors instead of the buffer stage i have used
thanks for help
Drain waveform should be exactly as its gate waveform.
any suggestions why i get square waveform on the drain when the gate is the same as the waveform in ur pic ?
That is actually not possible. The ON/OFF switching of the drain is dependent on the ON/OFF switching of its gate, and has to be exactly similar. Not sure why it is not happening for your mosfet…
It’s interesting how people solve a problem based on their background. You designed a delay circuit to insure there are no shoot-through conditions at startup. Being a software engineer, I would have done this in software by driving the relay with transistor and an output from the Arduino :-).
Great article, thanks for publishing!
Thank you for the feedback, I completely agree, this could have been solved through a code modification also.
Hi swag, which pin of the arduino do I connect the delay generator to
Hi Nimel, the pin8 and pin9 go to the first BC547 via 10k, this BC547 base is configured with the delay timer network, so it is the pin8 nd pin9 which go to the delay network
Sir, can you please share the transformar specification, required for this project.
Thanks.
Partha, the transformer voltage can be 6-0-6V for a 12V battery. Transformer current will depend on the load wattage. If the load wattage is 200 watt then dividing this by 6 becomes 33 amps and so on.
Hello Sir,
Thanks for the article,i would love to know more on the programming aspect.Please can you explain in detail how the avr side of the above circuit works to protect the circuit,like when the LED lights up,what does it mean,and can i implement it on all other inverter circuit?
Hello Patrick, yes you can use the concept universally with any inverter circuit. More details can be learned from the following artcle:
https://www.homemade-circuits.com/load-independentoutput-corrected/
thanks for the good circuit .
Kindly tell if we want to vary the frequency or if we wants the the output at 1 kHz
Thank you for liking the post!
Yes you an change the frequency to any desired value, simply by altering the “microsecond” values in the code.
As you can see, the above applications works with 50 Hz frequency, therefore the microsecond delays in the code across both the channels are adjusted accordingly to a 20 ms value.
For 1kHz, this total delay for the entire code will need to be adjusted to 1 ms.
Hi,
If you are going to use 1kHz, then you will probably need to design or obtain a transformer suitable for the job.
The 50/60Hz transformers used here will not provide the performance at 1 kHz.
The impedance of the transformer is lower at 50/60Hz than at 1 kHz.
In fact it will be 1000/50 = 20 time higher.at 1 kHz.
https://en.wikipedia.org/wiki/Electrical_impedance
It’s around 700 Hz, which is not too bad for an iron core transformer according to me…in my experiment everything worked fine.
Excellent article.
What would need to change to cater for a 24v battery?
Thank you, no changes will be required, except the transformer and the battery. The transformer can be a 12-0-12V for the primary side
здравствуйте. а можно как-то реализовать между переходами мертвую точку или
dead line
dead time already introduced at the end of the codes for each channel
digitalWrite(8, LOW);
//……
digitalWrite(9, LOW);
}
//————————————-//
Thanks for quick reply on my previous comments. I want to know one more thing how output frequency calculated. For some spacial applicatoin i want to lower the frequency about 10Hz to 15Hz. Please help.
It will depend on the specific oscillator circuit, and the RC parts used in the oscillator. The frequency can be changed by changing the RC values of the oscillator.
Thanks for the reply, but think there is some confusion, The frequency shoud be depends on arduino code coz SPWM is generated by arduino itself…?
Yes, for the above Arduino, the frequency is dependent on the delay (microsecond) set for each of the PWM blocks. You can modify them accordingly to ensure the waveform delay coincides with the frequency timing or the Hz rate
Hi, Nice projects is this, I want to make this same project with 110V DC source, can i replace 12V DC source with 110V? Second thing in place of saperate Power On delay circuit, we can also use Arduino itself for the same.
Hi, thanks, for 110V DC input you will need a 110V transformer connected with the MOSFETs.
you can use the same power for the Arduino and the delay circuit