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 I have explained 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.
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.
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
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:
Program Code for the above Arduino Sine Wave Inverter Circuit
// By Swagatam
void setup(){
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
void loop(){
digitalWrite(8, HIGH);
delayMicroseconds(500);
digitalWrite(8, LOW);
delayMicroseconds(500);
digitalWrite(8, HIGH);
delayMicroseconds(750);
digitalWrite(8, LOW);
delayMicroseconds(500);
digitalWrite(8, HIGH);
delayMicroseconds(1250);
digitalWrite(8, LOW);
delayMicroseconds(500);
digitalWrite(8, HIGH);
delayMicroseconds(2000);
digitalWrite(8, LOW);
delayMicroseconds(500);
digitalWrite(8, HIGH);
delayMicroseconds(1250);
digitalWrite(8, LOW);
delayMicroseconds(500);
digitalWrite(8, HIGH);
delayMicroseconds(750);
digitalWrite(8, LOW);
delayMicroseconds(500);
digitalWrite(8, HIGH);
delayMicroseconds(500);
digitalWrite(8, LOW);
//......
digitalWrite(9, HIGH);
delayMicroseconds(500);
digitalWrite(9, LOW);
delayMicroseconds(500);
digitalWrite(9, HIGH);
delayMicroseconds(750);
digitalWrite(9, LOW);
delayMicroseconds(500);
digitalWrite(9, HIGH);
delayMicroseconds(1250);
digitalWrite(9, LOW);
delayMicroseconds(500);
digitalWrite(9, HIGH);
delayMicroseconds(2000);
digitalWrite(9, LOW);
delayMicroseconds(500);
digitalWrite(9, HIGH);
delayMicroseconds(1250);
digitalWrite(9, LOW);
delayMicroseconds(500);
digitalWrite(9, HIGH);
delayMicroseconds(750);
digitalWrite(9, LOW);
delayMicroseconds(500);
digitalWrite(9, HIGH);
delayMicroseconds(500);
digitalWrite(9, LOW);
}
//-------------------------------------//
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.
A More Reliable Delay ON Timer
If you are not comfortable with the response of the above passive delay ON timer circuit, you can employ the following configuration using BJTs and a relay. This design is extremely reliable and will effectively protect your Arduino and the inverter from burning due to a malfunctioning delay effect.
Just add this to the above inverter configuration.
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.
For an isolated version of voltage correction circuit we can modify the above circuit with a transformer, as shown below:
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.
The Complete Circuit Diagram
The complete diagram using the automatic voltage regulator and the delay ON timer would look like this:
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
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:
Hillary says
Good day sir. can lm358 OpAmp be used for the feedback circuit?
Swagatam says
Hi Hillary, yes any standard opamp can be used.
Ainsworth Lynch says
Hey I built this circuit today after some years now, I keep getting one Fet blown, not sure if its because I am using Irfz44n Fets, I did not build the delay on circuit, Instead switched pin 9 and 10 to input on boot up and added a delay then switch them to output when the arduino is fully booted after 2 seconds but I still have the same fet shorting on each leg, the software method is a standard practice, I I still get output from the inverter with one fet blown 30v.
Would irf740 work better thats the only other thing I have.
Swagatam says
Hi, In my experiment I used IRF540 and did not have any such issues. But i don’t think the IRFZ44N can be the problem, unless the MOSFET has some internal defect. You can isolate the power supply input to the transformer center-tap and the Arduino, and then switch ON the Arduino first, and then after about 5 seconds switch ON the supply to the transformer and check the results.
irf740 may not be suitable because it is rated at 400V and your transformer may be rated at just 12-0-12V.
ainsworth lynch says
I added a software delay but when I read the article I realize the delay should just be for one Fet I delayed them both which is probably my issue.
also I used the modified spwm code that Mr Atton made im not sure if you tested that without issue also, if not I would just use your code.
Swagatam says
Please initially check with a manual delay, by isolating the transformer center tap and the Arduino, and please use only the code supplied by me, because it is the tested one.
Jonathan codjoe says
Hi swagatam. Trust you good?. I have designed the above circuit which is working perfectly fine. But my problem is the feedback circuit which I have designed just as it is but it is still not working. Please try and solve my problem for me. Thanks
Swagatam says
Thank you Jonathan,
I hope you have built and implemented the following feedback circuit:
https://www.homemade-circuits.com/wp-content/uploads/2019/03/Arduino-regulation.jpg
I would suggest you to test this circuit stage separately using a variac.
In this circuit, can you please test how much voltage do you get across the 10uF capacitor.
Remember, this DC voltage across the 10uF is the direct interpretation of the AC 220V that comes from the inverter output. When the inverter output voltage rises, this DCV also rises. As soon as this corresponding DC voltage at pin#3 of the 741 IC goes above the pin#2 zener vooltage, the output pin#6 of the IC turns high causing the BC547 to conduct and ground the MOSFET gates, shutting down the inverter.
So please verify the above stage separately and let me know.
Kerim Fahme says
Hi Swagatam,
As you know, sinewave PWM (SPWM) could be generated at different high frequencies (though much higher than 50 Hz). Since I don’t have Arduino board (though I design the hardware and firmware of my controllers using AVR MCUs, as ATmega8 and ATmega32) I wonder if you measured the PWM frequency which is generated by the offered Arduino firmware above. Thank you.
For instance, let us assume that the SPWM frequency is around 16 KHz. Naturally, it needs to be filtered to generate the 50Hz pure sinewave output at the transformer secondary. I read many articles on how to build a pure sinewave inverter, but none of them shows how the SPWM filtration is done. The only device which is supposed to do it in their circuits is the inverter power transformer since there is no explicit filter. But to let the transformer act as a filter, its mutual coupling coefficient (K) shouldn’t be made close 1 (as in mains stabilizers for example). The more K is made lower than 1, the higher the leakage inductance between the MOSFETs and the load is. And this leakage inductance does the filtering (shunted also by the iron losses at the high frequencies). But the more (K) is made lower than 1, the lower the transformer efficiency is. In practice, separating the coils of the primary and secondary, instead of winding them on the same coil, lowers (K). The optimum distance between the two coils is usually determined by trial and error. But if by adding a small capacitor (<1uF) at the transformer output (not loaded), the output voltage is acceptable (its high frequency ripple is hardly noticeable), the transformer is ok.
Swagatam says
Thank you Kerim, for the valuable information.
Each 50 Hz half cycle is chopped into 7 pillars, or 7 pieces, so each 20 millisecond cycle accompanies 14 PWM peaks.
I know this may look a little higher to handle for an iron core transformer, but in my experiment it worked perfectly well, without any buzzing or heating up of the transformer.
Yes, adding a high voltage capacitor at the output side of the transformer helps to smoothen the SPWM cycles into pure a sinewave like frequency.
Kerim Fahme says
If I understood you well, the PWM of the Arduino program (above) is 700 Hz only. At this relatively low frequency, I expect the ripple of the sinewave output is not small. So, I wonder how it looks on your scope screen in your experiment. Please let me know if the output ripple could be made small even at this very low PWM frequency and without an external LC filter. Thank you.
But, even with such a high ripple, the generated output is much better than of a square wave or quasi-sinewave.
For instance, among your many published articles about the pure sinewave inverters, which one its PWM frequency is highest?
Swagatam says
Thank you Kerim, for calculating the frequency.
According to my knowledge the only way to reduce the ripple is either by using a capacitor at the transformer output or by increasing the pwm frequency and using a ferrite core transformer.
In the above Arduino concept I used a 3uf capacitor at the output which produced a relatively good sinewave, however if this capacitor value is increased that might further help to improve the sine waveform quality and reduce the ripples proportionately, although that would also incur some power wastage. The above sinewave inverter project uses the maximum frequency for the pwm among all the published articles.
Kerim Fahme says
I asked about the SPWM frequency because lately I wrote a code for ATmega8 to generate the SPWM at 15.625 KHz (8000 KHz / 512). (For instance, since about 40 years ago, I used to write my CPU/MCU codes in assembly language only). This code can be used for a push-pull inverter which I designed its hardware too. Its push-pull transformer could be driven by two sets of N-MOSFET which, in turn, are driven by discrete circuits using BJT; NPN & PNP for fast turn on-off with dead time.
By simulating the code and its hardware, the results were as expected. I set K=0.99 in the transformer model. I hope soon I will have the time to test it in real.
In case we will find a way to let you receive files from me, I don’t mind sharing my design here (code and circuit).
Swagatam says
MCUs existed 40 years ago? I did not know that. Thanks for sharing the info.
Sure, please feel free to share the codes anyway you like, through email or directly through comments using online free upload sites.
I appreciate your kind efforts.
Kerim Fahme says
Sorry for not being clearer. You are right, 40 years ago, MCUs didn’t exist, only CPUs did (as Z80).
I had to say on my precious post:
“In the last 40 years, I used to write first my CPU codes (for Z80), then my MCU codes (for C51 and AVR families).in assembly language only”.
Swagatam says
OK, got it, thanks for the clarification.
Damir says
Few suggestions:
– Can the delay circuit be realized mainly in the software? I think the Arduino microcontroller ensures that on power on, all I/O pins are set to the input direction and in the high-Z mode by the microcontroller electronics. Software must explicitly configure pins for output or PWM. Suppose the Arduino pins that drive BC547 transistors are pulled to the ground with 100k or stronger resistors. Would it be enough to ensure that the MOSFET stages initiate with a delay during the Arduino booting or start-up? MOSFETS will be active once the Arduino application reconfigures the pins driving BC547 transistors.
– The automatic voltage regulator can be realized mostly in the software. Arduino has 6 ADC inputs and is capable of performing tens of thousands of ADC conversions a second. A simple voltage divider with a diode and capacitor as a half-wave rectifier can be connected to the Arduino ADC pin. Arduino ADC pins have about 100k input impedance, so a half-wave rectifier should be good enough. After every SPWM cycle, Arduino can read the output voltage and decide what to do next.
Swagatam says
Thank you for your valuable suggestions, it would be indeed very nice if the delay feature and the automatic voltage control are added within the Arduino. Please let us know if you have the necessary programming codes for that.
Yes, if the Arduino pins that drive BC547 transistors are pulled to the ground with 100k or stronger resistors, that would be enough to ensure that the MOSFET stages initiate with a delay during the Arduino booting or start-up.
Ainsworth Lynch says
Would I only need to pull one side to ground or both bc547
Swagatam says
both the BJTs….
Omar says
how can I make closed loop single phase inverter using Arduino
Swagatam says
Please go through the above article, everything is explained in it.
RK Seth says
Hello sir I want to control inverter out put by varying the the duty cycle values of arduino by push button from 0 to 100% duty cycle at increment or decrement by 1%.
I want to make 0 to 10 volt pure sinwave inverter at 400 Hz frequency and the ac voltage can be controlled by microcontroller at +/- 1% duty cycle variation so that 10 volt AC change accordingly.
Thanks and regards.
Please suggest me the code and circuit.
Swagatam says
Hello RK, I wish I could solve your query, however my Arduino coding skills are not good enough, therefore it can be difficult for me to help you with this question.
Rk seth says
thanks for reply.
Stan says
So the CMOS based circuit seams like an inherently better circuit as circuit loading does not affect the arduino outputs? however, I notice there is no feedback mechanism like it the upper circuit. Is it not possible or just not needed because of the buffer?
Swagatam says
There’s no loading with the transistorized circuit also due to the presence of the 10K resistors. 10K is quite a high value and will absolutely not cause any loading on the Arduino.
Yes, feedback might not be necessary since the Arduino generates a fixed PWM.
stan says
then which circuit would you choose? I am planning to build a low powered 12V, 500ma, to 120V variable frequency inverter.
Also, I have started trying to source components for the CMOS version but find that at Digikey many items are either obsolete or require purchasing large quantities, I’m not willing to pay $3000 to use only 2 transistors. Can you suggest alternate parts?
Swagatam says
The transistorized version of the above Arduino inverter is the most efficient one and is a tested design. I would recommened this design. The 10K resistor associated with the Arduino outputs can be even raised to 100K to reduce loading.
I did not quite understand what you meant by “I’m not willing to pay $3000 to use only 2 transistors. Can you suggest alternate parts?” Kindly elaborate
Stan says
BC547 is listed as obsolete on Digikey. https://www.digikey.com/en/products/detail/onsemi/BC547/976363#product-details-substitutes
BC548 is also obsolete in bulk, but i I buy 6662 of them they are only .05 each. ($333.10) , https://www.digikey.com/en/products/detail/rochester-electronics-llc/BC548/11545848
i forget which one only had a $3000 option. i’ll have to take better notes in my searching
Swagatam says
That’s super strange because BC547 is the most standard type of BJT and one of the most used general purpose transistor…. how on earth this transistor can become obsolete??
You can try 2N2222 or any other equivalent transistor, they all will work.
Stan says
couple more questions about the Voltage regulator circuit.
1) what is a 4V7 zener? 4V, 7V 4.7V? or other?
2) there are 2 led’s shown in series with the gates on BC547. are they required? this will be in a box and used remotely. do they have a troubleshooting purpose?
Swagatam says
1) 4V7 = 4.7V
2) Yes they are required, since the LEDs prevent the leakage or the offset voltage from 741 output to reach the base of the BC547 transistors, thus preventing false switching of the transistors..
Stan says
are they just standard 12V(forward Voltage) Red LED’s?
Swagatam says
They are standard 3.3 V, 20 mA LEDs.
Stan says
one more question about the voltage regulator, is this what you mean by IC741?
https://www.digikey.com/en/products/detail/texas-instruments/TPIC74100QPWPRQ1/1531097
if so, is there a through hole substitute?
Swagatam says
741 is an IC, not a voltage regulator, if you are not familiar with 741 IC then I am afraid you should not try this circuit, chances are you might not succeed.
https://www.homemade-circuits.com/wp-content/uploads/2021/08/IC-741-and-LM393-comparison-compressed.jpg
Stan says
Sorry, I did not recognize the Op-Amp symbol. The regulator I found is Also an IC. Searching on Both digikey and Mouser for IC741 resulted in nothing, so I went the hard way (drilling down) and had to choose a category. Voltage Regulator was just a guess. The wiring for the OP-Amp seams straight forward (other than the LED’s,) and i plan to use a socket so as to not damage the Chip when soldering, so i’ll take my chances. I’m just an electrician with electronics hobby experience not an electronics engineer. Sorry for the dumb questions, but I need this Arduino controlled inverter for one of my other hobbys (Astrophotography) .
Swagatam says
No problem, you can go ahead and build this project. The op amp output voltage control might not be necessary since the Arduino is generating a calculated fixed PWM, so the output voltage should be pretty constant.
aqil says
sir, how to construct a 450w 12vdc-230vac solar inverter?
Swagatam says
Aqil,
Please provide detailed information regarding the inverter and the load, if possible I will try to help.
Aqil says
A 12V solar panel and 12V battery supply to a 350W water filter. All i need is 500W (inverter sizing) inverter circuit diagram with code
Swagatam says
If you divide 350 by 12, it gives 30 amps, so your transformer must be rated at 6-0-6 30 amps or 32 amps. Please get this transformer then I will tell you how to proceed.
aqil says
i dont find for step up transformer. i just found for step down transformer…
Swagatam says
Step down transformer will do but it must rated at 6-0-6V 32 amps on one side and 220V on the other side.
Aqil says
Okay now proceed to the next step sir
Swagatam says
Did you get the transformer?
Aqil says
Yes
Swagatam says
Please build the circuit which is explained above using that transformer. You will also need a 12V 300 Ah battery for the 350 watt output
Emmanuel says
Hello sir, thank you for the Arduino sine wave circuit, can the circuit also be used for 24V DC?
Swagatam says
Thank you Emmanuel,
24 V can be also used. For that you will need a 12-0-12V transformer and the +24V will need to be fed on its center tap. The Arduino must be fed with 12 V through a 7812 IC.