The LM358 op-amp, running in a simulator
Intermediate
Or see every lesson.
- 455parts on the bench
- 43boards running now
- 1.00xreal time, on every board
The LM358 is two op-amps in one 8-pin chip, and it is the op-amp in most Arduino kits because it runs on a single 5 V supply. Its output can go all the way down to ground, but it stops about 1.5 V short of the supply, so on 5 V the highest it can reach is about 3.5 V.
The circuit above is an LM358 wired as a non-inverting amplifier. A function generator puts a 100 Hz sine from 0.2 V to 1.0 V into pin 3. The resistors set a gain of 3.2, and the scope shows the output on its second channel going from 0.64 V to 3.20 V: the same wave, 3.2 times taller and the right way up.
What you need
- An LM358 (LM358N or LM358P) in a DIP-8 package
- A 22 k and a 10 k resistor
- A 5 V supply
- A signal: a function generator, or a sensor
- An oscilloscope or a multimeter to see the output
- A breadboard and jumper wires
Wiring
| Part and pin | Goes to | Note |
|---|---|---|
| LM358 pin 8 (VCC) | 5 V | One supply is all it needs |
| LM358 pin 4 (GND) | GND | The bottom rail the output can reach |
| LM358 pin 3 (1IN+) | The signal | The input of amplifier 1 |
| 22 k | Pin 1 (1OUT) to pin 2 (1IN-) | Rf, the feedback resistor |
| 10 k | Pin 2 (1IN-) to GND | Rg: gain = 1 + Rf / Rg = 3.2 |
| Pins 5, 6 and 7 | Pin 5 to GND, pin 7 to pin 6 | Parks the unused amplifier 2 |
The LM358 pinout
Hold the chip with its notch on the left. Pin 1 is at the bottom left, and the numbers go along the bottom to pin 4, then back along the top from pin 5 to pin 8. Amplifier 1 is pins 1 to 3: 1OUT on pin 1, 1IN- on pin 2 and 1IN+ on pin 3. Pin 4 is GND. Amplifier 2 is pins 5 to 7: 2IN+ on pin 5, 2IN- on pin 6 and 2OUT on pin 7. Pin 8 is VCC.
The LM324 is four of the same amplifiers in a 14-pin chip. Its supply is not on the corners: VCC is pin 4 and GND is pin 11. The TL072 has the LM358’s pinout exactly, with VCC- on pin 4 and VCC+ on pin 8. The 741 does not. It has one amplifier, with IN- on pin 2, IN+ on pin 3, V- on pin 4, OUT on pin 6 and V+ on pin 7. Pins 1 and 5 are for an offset trimmer and pin 8 is not connected.
Working out the gain
A non-inverting amplifier feeds part of its own output back to its - input. The op-amp then does whatever it takes to make its two inputs equal. With 22 k from the output to pin 2 and 10 k from pin 2 to ground, pin 2 sees 10 / 32 of the output, so the output has to be 32 / 10 = 3.2 times the input. That is the formula: gain = 1 + Rf / Rg = 1 + 22 k / 10 k = 3.2.
So 0.2 V in gives 0.64 V out, and 1.0 V in gives 3.20 V out, which is what the scope shows. Swap Rf for 47 k and the gain is 5.7. The chip’s own gain does not appear in the formula: it is 100 000 with nothing around it, so big that only the resistors matter.
Why it clips at 3.5 V, not 5 V
Turn the generator’s amplitude up to 0.6 V and its offset to 0.7 V. Now the input goes from 0.1 V to 1.3 V, and 3.2 times that would be 0.32 V to 4.16 V. The bottom reaches 0.32 V. The top flattens at 3.49 V. An LM358’s output stage cannot get closer than about 1.5 V to its supply, and the datasheet says so. The 0.01 V under 3.5 V is the chip’s 100 ohm output resistance driving the 32 k of feedback.
The bottom is the LM358’s strong side. Its output gets to within a few millivolts of ground, so a small signal near 0 V, like 20 mV from a sensor, still comes out amplified. That is what single supply means on a datasheet, and it is the reason to pick this chip for a 5 V Arduino project.
The LM358 as a comparator
Take the feedback away and the gain is the whole 100 000. Then the output can only be at one rail or the other: high when + is above -, and low when it is below. That is a comparator. The LM358 dark switch project wires an LDR and a 10 k resistor as a divider into pin 3, and a knob into pin 2 as the threshold, set to 2.50 V. The output drives an LED through 470 ohm and goes to pin 2 of an Uno, and the Uno reads both voltages on A0 and A1.
Drag the LDR darker. At 20 lux the divider is at 2.49 V, just under the threshold, the output sits at 0.005 V and the Uno prints "light: comparator LOW, lamp off". At 19 lux the divider is at 2.53 V, the output jumps to 3.15 V, the LED lights and the Uno prints "dark: comparator HIGH, lamp on".
Look at that 3.15 V. An Uno is only sure of a HIGH above 3.0 V, so there is not much to spare. With a 220 ohm resistor on the LED instead of 470, the LED pulls the output down to 2.9 V, below that line. That is a real LM358 trap, and it is why a comparator output that feeds a pin should not also light a bright LED.
LM358 vs 741 on 5 V
The 741 is the op-amp in most textbooks, and it is the wrong chip for a 5 V circuit. The 741 vs LM358 project puts both on one 5 V supply as followers of the same knob, with a meter on each. A follower should copy its input. In the middle both do: 2.50 V in, 2.50 V out of each. With the knob at 5 V, both stop at 3.50 V. With the knob at 0 V, the LM358 gives 0.005 V and the 741 gives 1.50 V.
The 741 is a split-supply part. It is made for +12 V and -12 V, and its output stops 1.5 V short of both rails. On 5 V that leaves it only the band from 1.5 V to 3.5 V. Wire its V- pin to a real negative supply and it works the way the textbook draws it: an inverting amplifier with 10 k in and 47 k of feedback, on +-12 V, turns 1 V into -4.7 V. The TL072 is the same kind of part, a faster split-supply op-amp with JFET inputs.
The numbers the simulator uses
The LM358 and LM324 here have the typical numbers from TI’s datasheet: an open-loop gain of 100 000, a gain-bandwidth product of 0.7 MHz, a slew rate of 0.3 V per microsecond, an output from 5 mV above ground to 1.5 V under the supply, and a 40 mA output limit. The 741 has a gain of 200 000, 1 MHz and 0.5 V per microsecond, and the TL072 200 000, 3 MHz and 13 V per microsecond, both 1.5 V from each rail.
The gain-bandwidth product is what limits a fast signal. Divide it by the gain to get the bandwidth: 0.7 MHz / 3.2 is 219 kHz for this amplifier, and at a gain of 100 it would be 7 kHz. Run the Analysis tool’s AC sweep on the amplifier and the gain is 10.1 dB (3.2 times) at the low end and 3 dB down at 219 kHz.
What the simulation leaves out
The inputs draw no current at all, so the TL072’s JFET inputs, the reason people buy it, look the same as the LM358’s. There is no input common-mode range: a real LM358’s inputs stop working within 1.5 V of its supply, and here they work anywhere. Each chip’s input offset is zero unless you set the offset property, where a real one is a few millivolts either way. The 741’s offset pins are not connected, so a trimmer on them does nothing. The swing does not shrink as the load current grows, and there is no supply current.
Common mistakes
Using a 741 on a 5 V Arduino circuit. Its output never goes below 1.5 V there. Use an LM358.
Expecting the output to reach 5 V. An LM358 on 5 V stops at about 3.5 V. If you need the full swing, use a rail-to-rail op-amp.
Mixing up the pinouts. The LM358 and the 741 are both DIP-8 chips, but the 741’s output is pin 6 and its supply is pins 7 and 4. Check the pinout before you swap one for the other.
Leaving the second amplifier floating. On a real chip it can oscillate and warm the package. Tie its + input to ground and its output to its - input.
Forgetting the supply pins. An op-amp chip does nothing without VCC and GND, and they are not drawn on most schematics.
Questions
What is the LM358 pinout?
Pin 1 is 1OUT, pin 2 is 1IN-, pin 3 is 1IN+, pin 4 is GND, pin 5 is 2IN+, pin 6 is 2IN-, pin 7 is 2OUT and pin 8 is VCC. Pin 1 is next to the notch.
Can the LM358 run on a single 5 V supply?
Yes, that is what it is made for. Its output reaches ground and goes up to about 3.5 V on a 5 V supply.
Why does my LM358 output stop at 3.5 V?
Its output stage cannot get closer than about 1.5 V to the supply. On 5 V that is 3.5 V. A rail-to-rail op-amp gets closer.
Can I use a 741 instead of an LM358?
Not on 5 V. A 741 stays 1.5 V from both rails, so on 5 V its output only moves between 1.5 V and 3.5 V, and the pinout is different too. On a split supply like +-12 V a 741 works well.
How do I use an LM358 as a comparator?
Use no feedback. Put the signal on one input and a reference, like a knob’s wiper, on the other. The output goes high when + is above - and low when it is below.
Keep going
Build this for real
Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.