Square and Sine Wave Oscillators

Exploring these essential building blocks

Daniel Koch

Issue 71, June 2023

In Classroom Issue 59, we looked deeply at sine waves and some different circuits for generating them. This month, however, we have decided to look at all sorts of different oscillators. They are essential building blocks in electronics and have a huge variety of uses. However, as a Fundamentals, we do not necessarily go into the same depth, like explaining the maths behind a sine wave and what defines it. Instead, you'll find a collection of different circuits to generate different waves for different purposes that you can keep in your inventory. We will concentrate on fixed square and sine wave oscillators this month. In the next instalment of the topic, we'll discuss getting rectangular, triangle, and sawtooth waves, plus some variable circuits as well. There is one exception, the UJT oscillator which produces sawtooth waves.

Note that we are not covering all types of oscillators here, just a healthy selection that we think will cover most makers' needs, in the current context of component availability and general end-use trends. So, while there are valve enthusiasts still out there (and we think valves are awesome in their own way), most makers won't be using a vacuum-tube varactor oscillator any time soon.

Therefore, we have not described them or anything similarly 'off the beaten path'. Likewise, magnetrons can be used for a great high-frequency oscillator, but again, very few people will build one in the maker world today even if the parts can be obtained.


There are some things that are useful to define before launching into the different circuits, some things to be careful of, and some principles to explain. Definitions differ between sources on some points, and some, like the harmonic oscillator, need to be summarised and simplified to have any real value to someone from a general background and who isn't already knowledgeable on electronics.

Harmonic Oscillator

An oscillator based on the swinging of a signal above and below a middle equilibrium point, just like a pendulum. They are often resonant, having current move from one storage device like a capacitor, into another storage device like an inductor, at a resonant frequency. Also called a 'linear oscillator', they are generally sine wave generators.

Relaxation Oscillator

An oscillator based on the charging and discharging of a storage device like a capacitor or inductor, and the use of a switch with an upper and lower threshold. These produce square, triangle, sawtooth, and sometimes trapezoidal waves, but never sine waves unless there is some extra shaping circuitry added. Even the waves other than square usually require some extra components.

Delay Line Oscillator

An oscillator built using some sort of propagation delay, which is the time it takes a current to pass through some conductor or component, as opposed to charging time of a reactive element. This can be the turn on/turn off delay of a logic gate, or even a really long piece of wire.

Reactive Element

In this case, a capacitor or inductor. These store an electrical charge by different means, the charging and discharging of which is used in different ways in different oscillators.


Having two thresholds, an upper and a lower, instead of one. This way, the voltage has to rise above the upper threshold to cause a change in the circuit, then fall below the lower threshold to cause change again. This is good for noise immunity but also useful in some timing circuits. The following diagram illustrates this.


In this context, feedback means sending the output of a circuit element, usually but not always an amplifier, back to the input. This often works in conjunction with frequency-selective filters and tuned circuits, so that only the desired frequency is amplified, but is also used in other formats. It also generally involves a resistor, and often a reactive element to introduce a delay to the effect of the feedback from output to input.

Astable And Monostable Multivibrator

The term multivibrator means a circuit whose output changes between two states. Monostable has one stable state, and only changes into the other when triggered. Astable has two stable states and self-triggers between them, with a set time period for both states. Some sources define a monostable multivibrator as an oscillator, as it changes state then changes back again. Other sources consider them to be a category of their own and do not class them as oscillators. We will not call them oscillators here, because we anticipate most users to want a constantly repeating signal such as a clock signal. Therefore, we will only mention astable circuits, which all oscillators mentioned are.

Comparators Vs Op Amps

Operational Amplifiers (op Amps) are common electronic building blocks, and amplify the difference between their two inputs, whether it is negative or positive. The output is proportional to the difference in the inputs. A comparator is built using an op amp, and has one input tied to a reference while the output changes to high or low depending on whether the input signal is above or below the reference. However, in some cases, we specify a dedicated comparator. These ICs are designed so that their timing and threshold characteristics are very stable across the supply voltage range, while an op amp turned into a comparator with external components often lacks this and so accuracy of the calculated frequency may change if voltage changes.

Square and Rectangular Waves and Duty Cycle

A square wave is an on/off wave with no slope in it, meaning there is no rise or fall. It is either all upper voltage, or all lower voltage. The on time may or may not be the same as the off time. Often, rectangular waves are referred to as square waves. This is because the edges are squared, with no curves or slopes. For this article, we distinguish to make it easier for those less familiar with wave generators. A Square wave has equal on and off time, while a rectangular wave has different on and off times. That brings us to duty cycle, which is the amount of off time versus on time in one cycle of a wave. This usually refers to square waves, almost never to sine waves, and rarely to triangle, sawtooth, or other waves. It is expressed as a percentage, meaning the percentage of the whole time period that the wave is high. So, a square wave with a 30% duty cycle is on for 30% of the cycle then off for the remaining 70%.

Single Supply Versus Dual Supply

Many digital makers are unfamiliar with these terms, as they don't crop up in digital circuits or even many DC. The most familiar electronic circuit the average maker is familiar with is a single rail supply. It has a ground, or 0V, and a voltage rail of some higher voltage. There is a positive potential difference between the two. A Dual rail supply has three rails. It has a positive voltage rail, a ground in the middle, and a negative rail. The ground or 0V rail is still at 0V, it's just that the negative rail has a deficiency of charge, so the rail is actually at a negative potential than the ground. This is used a lot in amplifiers.


Some circuits or individual components have a maximum frequency at which they can operate. This is dictated, in the case of integrated circuits, by how fast the internal circuitry can switch and how fast the rise and fall times are. For example, an op amp may have a reasonably short delay where nothing is happening, but a longer rise or fall time for the voltage to rise from low to high or fall again. The datasheets of all ICs provide delays, rise and fall times, or sometimes a maximum switching rate including these and other factors. Always check if your device is up to the task when designing an oscillator for a given frequency.


The charging and discharging of a capacitor is central to many of the oscillator circuits presented. Sometimes, it is part of the timing section of a relaxation oscillator, while at other times it is part of the frequency filter for a harmonic oscillator. A capacitor consists of two plates on which opposite charges build up. If one plate is connected to ground, the other plate can be connected to a voltage and it will become charged. The rate at which it does so is called the RC time constant, and it is not a straight-line slope.

On the graph, you can see that as the voltage rises, the current falls. One time constant is the time it takes to charge the capacitor to 63.2% of the applied voltage. The graph is curved, and it takes five constants to get to 99.3% of the applied voltage. Even an ideal capacitor would never reach the supply voltage, as each time constant falls short, however, after seven or eight time constants, you would need some pretty good equipment to even measure the difference. Real capacitors have some losses so the difference is more pronounced but still negligible for practical purposes.

The time constant for a plain capacitor is based on the fact that there is inherent resistance in the capacitor, meaning current will not flow instantly. This comes from material impurity as well as the fact that even a pure metal in, say, the plates or leads, is not a perfect conductor. However, if a resistor is deliberately added in series, the overall relationship of the curve remains, but the x-axis, the time scale, stretches. So, one time constant takes more time to occur. This is very useful for us to create timing circuits based on capacitors, because we can control their behaviour. The same can be said of filters for AC waves, as adding resistors changes the charge and discharge time and therefore the frequency that can be handled.

Calculating the RC time constant involves scaling the component values into who units. So, microfarads, nanofarads, or picofarads have to become Farards, while kilohms and megohms need to become Ohms. Ohms are easier, because most people know kilo is an extra three zeros and mega is an extra six, but many people find the divisors harder. Remembering how far to move the decimal point which way confuses some people who don't do it often, even if they do more complex things on a regular basis. So, if that's you, check out our guide in Kids' Basics 43. The formula is: F = RC where F is the time of one RC constant in seconds; R is the series resistance in Ohms, and C is the capacitance in Farads. It should be noted that the internal resistance of a capacitor, called equivalent series resistance or ESR, is small enough to be ignorable for our purposes. However, at very high frequencies or in some situations, it is very, very important. We are not covering any of those situations in this article, but you may encounter them yourself. Finding the ESR of a capacitor requires an accurate datasheet for the capacitors you have (not just one of the same general type, as not all are equal), or a dedicated test instrument.

Another parameter that is related to the time constant is the cutoff frequency, Fc, which is the maximum frequency at which a resistor and capacitor combination can be used. This is very important for filter design, but also for higher-frequency relaxation oscillators, where the wrong combination may satisfy the time constant you need but still not perform. Here are both of the equations:


Many simple calculators from office suppliers and the like are meant for simple adding and subtracting and we have come across quite a few which do not perform order of operations properly. This can cause quite the headache when calculating some of the equations shown in these pages. The problem is not limited to physical calculators, either. Many default mobile phone calculator apps have issues in the way order of operations is performed, too. While many get the principle of performing multiplication and division before addition and subtraction, we have encountered problems with the way some apps treat indices, powers, exponents, and anything else out of the four basic operations. Therefore, you will see in some places that we have added brackets where you might not normally put them. This ensures that the calculator gets things right because generally, even the poorly-coded calculator apps and physical calculators perform brackets before anything else, and do so from the inside out.


One of the simplest (to build) and most popular oscillators is the Schmitt trigger relaxation oscillator, producing a square wave output. This uses a single Schmitt-triggered active element, one resistor, and one capacitor, and exploits the hysteresis that is part of what defines a Schmitt-gated element. There are different ways to make a Schmitt trigger, including from discrete transistors, but the most common is to use an inverter, buffer, or an op amp with external components. ICs are available as either buffers or inverters, with inputs already configured as Schmitt triggers. Buffers will not work as oscillators as the output follows the input. Inverters will work, although the data sheet would need to be consulted to find the thresholds. We will show one based on a dedicated Schmitt-trigger inverter, the 40106.

The 40106 hex inverter is an IC in the 4000 series with six Schmitt-gated inverters in one 14-pin package. At 5V supply, the typical hysteresis value is 0.8V to 0.9V depending on the model and manufacturer. That increases as supply voltage does, but its relationship as a percentage of the supply voltage remains roughly the same. The outputs of most CMOS ICs, and the 40106 is no exception, can output around 10mA. However, drawing any current from the output will affect the feedback circuit and is often responsible for variations from the calculated frequency. In practice the output of the oscillator would be fed to the input of another inverter, to serve as a buffer. The inputs have very high impedance and so will not load the circuit and change the characteristics, and the buffer output can be used to drive whatever it is you want the oscillator to drive. Therefore, while the schematic shows the building block, and the inverter follow-on stage. The oscillator itself only depends on IC1a to function, with IC1b being the isolating buffer.

Another challenge is that the thresholds, both in their absolute value, and their separation, mean that the RC time constant needs further calculation to determine frequency. Both upper and lower thresholds are well away from the top and bottom of the capacitor charge curve, so we cannot rely on the RC time constant as it is. Instead, the datasheets for the 40106 provide this formula for Astable operation:

The Texas Instruments datasheet in particular uses a symbol that looks like a cursive lower-case 'L' that we did not recognise, but given the context, suspected to represent natural logarithm. Sometimes, such characters are used to avoid looking too similar to other characters, like 'In', as in for input is scattered all throughout a datasheet. We checked Mexperia's datasheet but it doesn't have the formula at all, but found the STMicroelectronics to use 'ln', being a lower case 'L' and 'N' for natural logarithm. So, the correct way to calculate the oscillator frequency is to first calculate the inner brackets. The first is the positive threshold voltage divided by the negative threshold voltage, while the second bracket is the supply voltage minus the negative threshold voltage, divided by the supply voltage minus the positive threshold voltage. Once solved, the two products are multiplied because both sets of brackets are next to each other inside square brackets. Then, you take the natural logarithm of that result, and multiply that by the time constant.

That gives the time period for one whole cycle, from which you can calculate the frequency. Take note, however, that the datasheet includes component value upper and lower limits. For resistors, the value is 50kΩ to 1MΩ inclusive, and the capacitor must be between 100pF and 1µF, inclusive. The datasheets give no reason as to these limits but it is a fair assumption that neither performance nor stability are guaranteed outside those values. Note that this information applies to the 40106, and other formulas are commonly suggested that apply to other ICs. Be careful if you are doing your own further reading.

In the schematic, you can see that if the starting state of the oscillator is a low input on power on, then the output is high. Current flows through the feedback resistor R1 to charge capacitor C1 connected to the input. When the capacitor voltage rises above the upper threshold of the Schmitt trigger, the inverter's output goes low. C1 now discharges through R1 into the low output, until the voltage across it falls below the lower threshold of the Schmitt trigger.

This is why connecting anything like a base drive resistor for a bipolar junction transistor to the output affects timing: any alternative current path between the output and C1 changes the charge time of C1. A buffer should always be used, or at least something with a very high impedance.


This circuit is a delay line oscillator producing a square wave output. It uses inverters connected in series, and makes use of the inherent delay, called a propagation delay, between when a signal arrives at the input of an inverter, and when the internal circuitry has done its thing and changed the output. This delay is usually in the nanosecond range, and is always defined in the datasheets. Different technologies have different delays, too, with TTL (Transistor-Transistor Logic) being much slower than CMOS (Complementary Metal Oxide Semiconductor) logic. So, a 4000-series IC will be much faster than, say, a 74LS-series chip, with 74HC being a bit better but still slower than the 4000s.

The ring oscillator consists of an odd number of inverters connected in series, with the output of the last one connected to the input of the first one. If the first inverter's input is low, its output is high, which is presented to the input of the second inverter, whose output is therefore low. This is why the number of inverters must always be odd. The low output from the second inverter causes the output from the third inverter to be high, which is linked back to the first inverter's input, pushing it high and changing its state, which flows back along the chain to repeat the process. Three counters is a minimum, and generally more would be used. This counter produces relatively fast oscillations suitable for clock signals.

Once the propagation delay is obtained from the datasheet of your chosen IC, then calculating the frequency is straightforward. In the formula above, Tp is the propagation delay, while n is the number of inverters. Note that even with a relatively slow delay, the frequency is well into the Megahertz range. You will never be building an LED flasher from a ring oscillator unless you're going to set the Guiness World Record for the longest ring oscillator chain. Also, ring oscillators are not exactly precise. Propagation delay is usually a range for most ICs, and it can be quite broad. In addition, it is specified at 25°C but elsewhere in the datasheet, you will normally find a graph showing the delay as a function of temperature and supply voltage, both of which have a significant effect. However, there are still plenty of situations where the ring counter is good enough for the job.

It is also possible to create a ring oscillator with RC stages in between the inverters. In this case, the inverter chosen must have an output that can both source and sink current, otherwise the capacitor will not discharge between cycles. Some have this, some do not. We are only giving a general circuit here. Values of the RC network are only part of the story. The thresholds at the inputs of each inverter are also at play, and vary from device to device.

Check the datasheets for your chosen device. Then, calculate the RC time constant for your RC network. It is unlikely that a whole time constant will be used, because the threshold is usually somewhere around half the supply voltage, while one time constant is the time taken to reach 63.2% of the supply voltage. Therefore, the delay is not simply the RC time constant at each point.


A relaxation oscillator producing a square wave can be constructed from an op amp. It is not as effective as a dedicated comparator (next example) but it works, and if you have an op amp in the parts box but not a comparator, it will do most jobs asked of it. With an op amp, the output waveform is generally a rough-edged square wave with a bit of noise on it, but this is still ok for some situations like driving a decade counter-based light chaser, for example.

Most op amps have what is known as a 'push-pull' output, allowing them to both source and sink current. That is because op amps are generally used as some sort of amplifier, requiring the output to swing above and below the centre by a given number of times the difference between the inputs, be it positive or negative. A comparator, on the other hand, is designed to simply be all the way high or low depending on whether the difference between the inputs is positive or negative.

Therefore, many comparators have open-collector transistor outputs, or some other form of load driver. Others have an internal driver arrangement that works rail-to-rail (to the supply voltage or ground). Most op amps, by contrast, have outputs that cannot get quite all the way to the rails and definitely cannot be externally connected like an open-collector transistor can. Some cannot even get close to the supply rails. All of that means the relaxation oscillator circuits for the two are a little different.

This circuit is for a dual rail supply. The output of most op amps does not quite get to the supply rails, often being around 0.5V away. Some are better, some are worse, but just remember that when we say high and low. Because any circuit like this has some noise and natural signal flowing around, we can make certain assumptions about its starting point because the op amp will start in either of the conditions described, be that with a positive or negative difference between the two inputs.

This stabilises in a matter of nanoseconds into one of the output cycles described. So, we will assume the op amp has started with a high output. Resistors R2 and R3 set the reference voltage at the non-inverting input (+).

With the output high, current flows through R2 and R3 to ground, setting up a positive voltage reference for the non-inverting input. Current also flows through R1 to charge the capacitor. As it charges, the voltage at the inverting input (-) rises until it exceeds the voltage at the non-inverting input. The output now swings low.

When it does, the R2/R3 voltage divider is now connected between the output at nearly the negative voltage, and ground, meaning current flows from ground to the current-sinking output. This gives a negative voltage on the non-inverting input, changing the threshold. The capacitor also discharges into the output. When its voltage drops to below the new reference at the non-inverting input, the output switches back.

This has created hysteresis, essential for oscillation. There is a formula for calculating the frequency based on the RC time constant. However, by a quirk of maths, it can be simplified a lot if you keep to a certain relationship for the ratio of R3 to R2. If R3 is 0.462 of the total of R2 and R3 combined, then the frequency of the oscillator is:

The ideal values of R2 and R3 will have to be a little off standard values, or use a potentiometer. The standard values that get us the closest are R2 = 3.6kΩ and R3 = 3kΩ, or multiples thereof (30kΩ and 36kΩ, 300kΩ and 360kΩ). 36kΩ and 30kΩ are a good balance between the need to not load the output too highly, and being immune from stray capacitance, temperature, and so on. Keep in mind that the values should be higher than R1 so that the voltage divider does not load the feedback path to the capacitor. In other words, if 50kΩ suits the RC time constant that you want, use the 300kΩ/360kΩ divider.

However, you can control the behaviour of the oscillator by changing the relationship of R2 and R3. You can make the hysteresis larger or smaller by doing so, but the relationship to the RC time constant becomes more complex and the maths to go with it is a little harder to explain. So, for most makers, it is really easier to just stick to the suggestions above.

For fun, the formula is here, with natural logarithm being represented by the somewhat ambiguous 'ln' which is a lower case 'L' but also looks like 'In' for input with a capital 'I'. Note that the calculation is the natural logarithm of what is in the brackets, then it's 2 x R x C x product of ln(). Order of Operations!


The circuit above is a good building block but not many regular maker projects have a dual supply available. Furthermore, if all you want is a clock pulse, the rest of your circuit is probably not dual-supply either. So, with a little rearranging, we can make an op amp work as an oscillator on a single rail supply. It is still a relaxation oscillator producing a square wave output. The change is really the addition of R2, but the diagram has been rearranged for clarity compared to the dual-rail version so R4 in this diagram is equivalent to R2 in the previous one, R3 is still R3, and R2 is new. R1 is the feedback resistor in both.

The voltage divider arrangement works a bit differently now. When the output is high, the voltage at the non-inverting input is set by the two connections to V+, R2 and R4, and one to ground, R3. When the output is low, there is one connection to V+, R2, and two to ground: R3 and R4.

Therefore, the threshold at the non-inverting input is two thirds V+ when the output is high, and one third V+ when the output is low. That is, if the three resistors are equal. You can tweak this circuit to expand or contract the hysteresis. However, if you do keep them equal, the output frequency is approximately given by:


Op amps are an acceptable way to build an oscillator. However, if you do have a comparator or are planning a build and can buy the parts you need, the oscillator performs far better with a dedicated comparator. With a comparator, the output is cleaner and the frequency results are more consistent over temperature and supply voltage range. Noise immunity is also better. Some comparators have their own output driver networks, and you can use them directly in place of the op amp in the single supply op amp example, with the same calculations. However, many comparators have open outputs. Some have open collectors, some have open emitters, and some have both. One of the more common ones on the retail market is the LM311N, which has both open collector and emitter at its output.

This necessitates a small change to the circuit. We have to provide our own ground and supply voltage connections, unlike the single output pin of an op amp. The emitter at pin 1 is directly grounded, while the collector at pin 7 is tied to the supply voltage through a 470Ω resistor. This limits the current through the output transistor, which has a maximum capability of 50mA but should not be maxed out continuously. Across the whole supply range, 470Ω will provide enough current to ensure it does not play a part in the calculations, but not enough to overload the output transistor. Other than that, the circuit is fairly similar to the single supply op amp version. Even the calculations are the same.


The classic two-transistor multivibrator circuit that so many people learn as one of their earliest electronics builds can do much more than flash LEDs. This circuit is a basic oscillator and even has the ability to be variable, and have a rectangular output. It is a form of relaxation oscillator, and as presented first, has a square wave output. The circuit functions not on a regular charging and discharging of a capacitor connected on one side to a switching element, but on the reversal of polarity of the capacitor. This explanation does not simplify easily, but here goes!

We know that capacitors store a charge by having one plate more charged than the other. In operation, we often connect one side to ground. The other side can charge with a voltage, relative to ground. However, if the polarity of a charged capacitor is revered, then the voltage is instantly transferred to the other side. At first, Q1 is on and conducting. Q2 is off. Current is flowing through R4 to charge the positive side of C2. The values of R1 and R4 are often reasonably low, so C2 charges quickly. The other side of C2, its negative, is connected to the base of Q1, so its negative side is at ground, plus the 0.7V or so of base-emitter voltage drop. Q1 is held on by R3.

Current is flowing through R1 to the positive side of C1 but it will not charge because Q1 is conducting to ground. The negative side of C1 is connected to the base of Q2, which is currently off, but there is current coming through R2. This charges C1 despite the fact that it is reverse-polarised. When the voltage has risen far enough to turn on the base of Q2, it conducts. This has the effect of grounding the positive side of C2, which was charged. A capacitor's charge is the difference between its plates. The positive side was

charged to near the supply rail but the negative side was at 0.7V, charged by R3 to the threshold of Q1's base-emitter junction. So, it is not fully at the supply rail voltage.

When the positive side of C2 is grounded, it does not discharge straight away. Instead, the negative side is suddenly at -8.3V assuming a supply voltage of 9V. This negative voltage pulls down the base-emitter junction of Q1, turning it off. Now, C1 charges again via R1 on the positive side, with the negative side held at 0.7V by R2 feeding the base of Q2, which is on, repeating the cycle.

That's an overly compressed explanation so for more details and a coloured circuit diagram, see Kids' Basics Issue 55.

To use this circuit as an oscillator to generate a usable wave, without altering its timing characteristics, it is best to use another switching element to avoid loading the circuit. That does not apply if you are feeding a very high-impedance input like many logic IC gates (the clock input of a 4017 decade counter, for example). It does apply if the circuit is something with an RC filter in it, or anything else that will draw any appreciable current. You could use a buffer IC or just another transistor. Here, we have used a Darlington transistor (Q3) and a 470kΩ resistor (R5) for the purpose.

Timing calculations again use natural logarithm. The circuit can be calculated to give specific time periods for each side of the circuit. Not that R5 and Q3 could easily be placed at the junction of C1 and R1 instead. The duty cycle desired at a nominal frequency can be backwards-calculated to reveal individual timings for each half of the circuit.

Then, using natural logarithm rather than 'In' for input, the formula is:

The frequency can be calculated by the first line in the following equation which again uses natural logarithm ln. Remember order of operations! R2xC1 and R3xC2 are each solved first, then added together. In the second equation, the frequency is easier to calculate when the duty cycle is 50% and both halves of the circuit are the same.


The good old NE555! Many makers use this IC so much the legs fall off, literally. Hated by engineers but loved by everyone else, it does many jobs quite well. More than well enough for most makers, but not as well as a dedicated circuit or device for each specific use, which is why engineers often loathe it. The NE555 timer IC makes a great oscillator, and it can be configured several ways to have very close to a square wave, or far from it at a very narrow-pulsed rectangular wave. Of all the circuits presented so far, this one most easily adapts to having a variable frequency but we'll still leave that for the next instalment.

We could write a whole article on this IC, and in fact we have, so this one will not be exhaustive. We covered the NE555 in deep detail in Classroom Issue 58, and a bit more basically (but still deep enough) in Kids' Basics Issues 47, 54, and 57. You might like to check any or all of those out.

In the first example, we have set up the NE555 to produce a rectangular wave of 1000 Hz at a duty cycle of 25%. When the circuit is first powered up, pin 3 is high and the capacitor connected between pin 2 and ground is discharged. The NE555 has an internal transistor connected between pin 7, the discharge pin, and internal ground, but when the output is high, this transistor is off. Therefore, current flows through the 15kΩ resistor R1, and the 6.2kΩ resistor R2 to the capacitor C1, which charges with this current. When the capacitor is charged to two thirds of the supply voltage, the internal comparator monitoring pins 2 (trigger) and 6 (threshold) changes state.

The output goes low, and the transistor on pin 7, the discharge pin, is activated. This allows the capacitor to discharge through R2 only, through pin 7 to ground. Because of the ground connection, the current from R1 flows through here too and no longer plays a part. As the voltage across the capacitor falls, it reaches one third of the supply voltage. The internal comparator changes state again, sending the output at pin 3 high, and turning off the discharge transistor so the capacitor charges again.

To gain the component values above, we first determined our time periods from our target frequency. We wanted a 1kHz signal, so we used the frequency to time period formula to yield a total time period of 0.001 seconds. That means T = 0.001 seconds, the total time period. However, it is made up of T1 and T2, the on and off times. Note that with an astable NE555, T1 is always longer than T2, so for short output pulses, the output can be inverted. Next, we can choose a capacitor value for C1, then try values for R1 and R2 until we get what we want. Knowing that T is made up of R1 + 2 x R2, we can guess the ratio anyway, and the calculate specific values until we're sure. Note that standard component values mean we may not get exactly what we want. In this example, C1 of 56nF, R1 of 15kΩ and R2 of 6.2kΩ gives 940Hz at a duty cycle of 77.4%. Moving just a little aside, C1 of 56nF, R1 of 12kΩ and R2 of 5.6k would give a frequency of 1111Hz, further away, but at 75.86% duty cycle.

Importantly, if you really hate the maths, there are online calculators to help. We have listed our favourites in the 'Reading and Resources' section at the end.

There are two advantages to this circuit compared to many of the others described. The first is that the NE555's timing characteristics vary only minimally across its voltage supply range: The calculations are as valid at 5V as they are at 15V. Compare that to a Schmitt Trigger Inverter IC, which has a hysteresis of around 0.8V at 5V supply, but nearly 2V at 15V supply. The delay for a ring counter is also supply voltage dependent. The other, and possibly more significant, advantage is the output pin 3. It is fully independent of the timing circuit (at least in this configuration), so changes in output load will not change the timing characteristics. Further, the output can both source or sink 200mA of current, so it can directly drive significant loads. In addition, the source and sink capability make it easy to gain a desired duty cycle: In this case, if you need a 25% duty cycle, then the low period of the current circuit can be used. Using a PNP transistor would enable driving a load at 25% duty cycle if the load required high-side power switching, or if low side switching is suitable, it can directly be driven by the low periods of the circuit as-is.

It is also possible to make a good square wave generator out of the NE555 with a different circuit arrangement. It is not exactly 50% duty cycle, but is very close. The facts that the output at pin 3 is high when the circuit is powered up, and that it both sources and sinks current, are useful to us. With only one charging and discharging resistor connected to pins 2 and 6 and the timing capacitor C1, we can ensure that the charge and discharge times are the same. To eliminate the other resistor and the discharge pin 7, we take the resistor from the output. When powered on, pin 3 goes high and begins charging C1 until the voltage across it reaches two thirds of the supply voltage.

The internal comparator switches state, sending the output low and enabling the capacitor to discharge back through R1 to ground via pin 3s ground path. When the capacitor voltage falls to one third of the supply voltage, the comparator switches state again and the process repeats.

The main difference to consider with this circuit is that output loads may change the timing characteristics. If the load is very low impedance and the timing resistor quite large, current will favour the load path and not charge the capacitor as expected. However, with a 200mA load limit, low-impedance loads with no current limiting will damage the IC anyway. It's something to think about and make sure of, though.

The NE555 lends itself very well to some variable circuits that we will cover in the next instalment of this topic. It is possible to vary the duty cycle while keeping the frequency the same (sort of), and to vary the frequency while keeping the duty cycle the same.


One component we no longer see much of in the maker world is the unijunction transistor, or UJT. Most readers are quite familiar with the ubiquitous BJT, or bipolar junction transistor, in which three pieces of doped silicon are combined in an NPN or PNP arrangement. However, the UJT has only one PN junction, with a heavily doped P-type piece of material bonded to a longer slice of N-type material with contacts at each end. The ends of the N-type material are known as bases, and the P-type terminal is the emitter. As such, the UJT is sometimes called a 'double base diode' even though it is not a diode. It is worth noting that the P-type material is not usually located centrally, but closer to base 1 than base 2. The fact that the device is asymmetrical is important in some applications and when installing the component, pin order matters.

There is always a small current flowing between the bases of a UJT. When a sufficient voltage, the 'trigger voltage' is applied to the emitter, a much larger current flows from emitter to base 2. They are negative resistance devices, where the more current that flows, the lower the resistance between the emitter and base 2. The ratio of resistance between base 1 and emitter, and emitter and base 2, is called the 'intrinsic stand-off ratio' and is given by the Greek letter Eta, η.They are not linear amplifiers but rather switches. There is also a complimentary UJT, which sees the P- and N-type materials swap roles. Both are largely obsolete now but some are still around and there is also a 'Programmable Unijunction Transistor' which is a more modern multilayered device.

The UJT was a common active device in oscillators before modern ICs like op amps, inverters and timers became readily and economically available. When discrete components were the mainstream, the UJT was the go-to for oscillator circuits. The 2N2646 is one of the few left commonly available, and even that is discontinued at Jaycar, so we will use this but if you want to build one, stock may become exhausted. They are still available from online wholesalers, as are a handful of others.

In normal operation, a UJT is connected with base 2 connected to the supply voltage and base 1 connected to ground. We're ignoring loads and limiting resistors to explain the function of the device itself. There is also an applied voltage to the emitter. This might be from a charging capacitor, a potentiometer, or anything else. For now, it's just a nominal voltage. This voltage is rising until it reaches a critical point called the peak voltage, or VP. When this point is reached, there is a breakdown between the emitter and base 1, causing a current path to ground. This is where the negative resistance aspect of the device comes in. As more current flows, the resistance between the emitter and base 1 decreases. Current is added to that flowing from base 2. As the voltage falls, this lower resistance means that the threshold to turn off has moved. It is called the Valley Voltage, VV, and when it is reached, the UJT turns off.

An oscillator is quite easy to build with a UJT, but some extra components will be required to actually use it. We'll show the base circuit first, then a usable one. There are three resistors, one capacitor, and the UJT. That's about as simple as it gets, but the oscillator produces a sawtooth wave in addition to two pulsed outputs. In the diagram, the pulses are shown where they are obtained, but not to scale. The pulse at B2 is actually quite small in amplitude, and would not be easy to see if drawn to scale.

Resistors R2 and R3 limit current, while R1 is the one used for the RC timing constant. The capacitor charges through R1 until the peak voltage is reached, at which point the UJT switches on and the capacitor discharges through R3. Therefore, R3's value may be used to slightly change the shape of the waveform by increasing the discharge time, but it cannot be a large value without affecting the circuit operation. Typical values are shown. R1 must be large enough that the voltage after the capacitor discharges is not enough to keep the UJT switched on.

To calculate the frequency of operation, we need the standoff ratio, 𝜼, to insert into this formula. Look carefully, because our friend Natural Logarithm is involved, as is Eta, the standoff ratio. Unfortunately in many fonts, the symbols can look similar. Using the component values we chose, our oscillator calculates at 968Hz.

To gain a reasonable output, however, we need a high-impedance buffer. Note that because the output has been added at the left of the diagram, the component designations have changed but the core UJT circuit remains the same. The 15kΩ resistor R2 connects to the junction of the RC element, and to the base of an NPN bipolar transistor Q1, a BC547. This is connected as an emitter follower, where the voltage at the emitter follows that at the base. The 1kΩ resistor R1 is the current-limiting resistor and could be a higher value, too. The junction between Q1's emitter and R1 is where the usable voltage output is taken from.

That's to keep it simple and stay in the vein of the era when the UJT dominated. If a UJT oscillator suited your needs now, it would be better to use an op amp buffer for the highest practical impedance so as not to change the RC characteristics at all, and for maximum isolation. If the op amp were to be configured as a comparator, or even a dedicated comparator used, then this circuit could generate square or rectangular waves.


Quartz or Piezo crystal oscillators are another item that could have a whole topic written about them. In fact, perhaps we should! In short, the piezo effect describes a small sliver of quartz crystal sandwiched between two electrodes. Mechanical deformation of the crystal, by pressure or vibration, causes an electrical current to be generated. An applied electrical current causes mechanical deformation. That deformation has a resonant frequency that is extremely precise, so crystals are used in high-precision oscillators as part of a resonant circuit with capacitors, inductors, or both as the other resonant elements.

Many makers are familiar with crystals. The circuit symbol is shown above. You may have never built a circuit with one, however. They were the little thing you plugged in and out of old-school 27MHz radio control equipment, but they are ubiquitous today as the clock generator on the vast majority of microprocessors. There is one on every Arduino board. They generally come in some form of metal can package and have the frequency printed on the top.

One of the most common crystal oscillators is the Colpitts oscillator. We chose this one because it uses standard workbench components while some other options use inductors which either have to be sourced or even hand-wound. Yes, some makers will have them, but they're not quite the standard that ceramic capacitors and regular resistors are.

In addition, we chose the BC337 transistor. Although the currents involved are low, the BC337 has a maximum switching speed of around 100MHz, while the more common BC547 and cousins max out around 30MHz.

The crystal X1 and capacitor C1 form a tank (resonant) circuit with R2, which is as high as it can be to help prevent loading and limit the current in the fragile crystal part of the circuit. R1 provides supply voltage but R1 and R2 together also bias the base of the transistor Q1.

C2 and C3 reduce the feedback from the emitter output of the circuit, which keeps power consumption under control.

Q1 is set up as an emitter follower amplifier but C2 and C3 keep the gain low so that it really is just a voltage follower, or current buffer.

R4 sets the current through the transistor but R3 is also needed because there is a pathway to the output that R4 has no influence on.

The value of X1 can be any of the available values on the retail market, which are typically between 1MHz and 40MHz, with C1 adjusted until oscillation is achieved. C1 is an 8.5pF to 100pF trimmer.

The Schmitt inverter IC can also be used as a crystal oscillator. The 74LS and 74HC series will likely not be fast enough but the 4000 CMOS series is. Component count is even lower, requiring only two resistors, one crystal, two capacitors, and two of the inverters out of the six found in most inverter IC packages. The output is a very clean square wave, and because of the use of the buffer, nothing will change the timings as the load changes. Capacitor and resistor values for 5MHz increments are given in the table, but you might have to adjust by experimentation if your desired frequency is in between.

Crystal Freq. (MHz)

C1/C2 (pF)

R2 (Ω)














A variation of the ring inverter circuit from earlier is another good circuit for the workbench as many makers who use logic devices had a quad NAND gate IC on hand. The circuit has a slightly different operating principle, however, to the ring oscillator. Both inputs are tied together to create an inverter, but instead of either the propagation delay only, or RC networks at each stage, the NAND version uses one capacitor and two resistors spread along the inverter. Because of this, only three inverters are needed and adding more will generate only a minimal change. Non-Schmitt gates work, but Schmitt-gates NANDs work better. Both of the following oscillators produce square waves.

At first, inputs are low so all outputs are high. At some point, one of the gates will respond to noise first and active, but we have the RC network of R2 and C1. C1 holds the input of IC1c low, because the capacitor draws current. This persists long enough for the stable state to settle in where the output of IC1c is high, charging C1 through R2. R1 is ten times the value of R2, so the voltage at the input of IC1a is much lower at first while the capacitor charges. This ensures that its output is high, holding the input of IC1b high and its output low. The other side of C1 is grounded via the low output of IC1b and input of IC1c (which really has too much impedance to ground anything).

At some point, the voltage across capacitor C1 rises to above the threshold of the input of IC1a, which is now taken high. Its output therefore goes low, causing the output of IC1b to go high. This reverses the polarity of C1, and it discharges through R2. It also forces the output of IC1c low, giving the current through R2 somewhere to go. We have included a fourth gate, IC1d, as a buffer only so that any load on the output side will not affect R2. This is not really an issue if you are driving a high-impedance load like another logic input.

The frequency of this circuit can be determined by the formula:

Of course, that is one way of creating an oscillator with a NAND gate. It's quite stable and reasonable in its performance. However, sometimes you need something that is simpler, at the cost of precision. If all you want is a utilitarian clock signal, this might be ok. If you need such a signal and have one spare gate left in a quad NAND package for another circuit, then a single RC network and one gate can form a basic oscillator.

One side of the input is tied to the supply rail, keeping it high. Remembering that in a NAND gate, input A AND input B need to be high for the output to be low. In all other states, the output is high. It would work the same if the inputs were tied together. At the start, because one input is high but the other is low, the output is high. Current flows from the high output through R1 to charge capacitor C1. As the voltage rises, it will eventually reach the upper threshold of the input of IC1a, the NAND gate we are using. When it does, both inputs are high, so the output goes low. C1 now discharges through R1 until it reaches the lower threshold of the NAND gate's inputs. Once a low is registered, the output goes high again and the cycle repeats. That means both this and the previous NAND gate circuit are dependent on the thresholds of the IC involved.

In the schematic, the dotted line shows another NAND gate. This is used as a buffer if the output is to be taken to a lower-impedance load, such as the base of a transistor with a 1kΩ resistor, which would load the output. It is not needed if the output is to feed a high-impedance load such as a logic or op amp input. The formula for frequency is the same as for the other NAND circuit, except here R1 takes the place of R2 in the above calculation.


Which circuit is for you depends on a variety of factors including the precision required and the components available. When deriving a precise timing circuit for clocking a microprocessor, for example, no less than the crystal oscillator will really do the job. On the other hand, driving an LED light chaser based on a 4017 decade counter could be done with any of these circuits, even the unijunction sawtooth version.

We have only presented a selection of oscillators here and you may be very familiar with one we have not presented. Some were excluded because they are similar enough to others we did show, while some were excluded because they may be difficult to calculate or use parts that are no longer available. Still others are not here because there are more designs out there than we ourselves have ever seen!

When building an oscillator, always check the frequency limits of your design and make sure it matches what you want to do. Don't bang your head against a wall wondering why an oscillator is not clocking your circuit, only for the problem to be that it just cannot output anything at the frequency you need. Not all components are created equal. 4000 series CMOS ICs are much faster than 74LS series TTL, for example. Even bipolar transistors vary. Some of the circuits have limitations, like upper and lower values of resistor, outside of which the circuit may not work. We have mentioned this where we know about it and where it might be relevant. At other times however, it may be that we did not know. For example, a circuit regularly used for 1kHz signals may not work with a resistor low enough to generate a 1Hz signal, because it loads the circuit too much or some other factor. If something isn't working, first check connections but then, start researching for your specific needs.

We hope this circuit collection can serve as a ready reference for when you need a square wave oscillator. In the next instalment, which may not follow straight away depending on supplies and other factors, we will explore some variable oscillators and some ways to produce other waveforms.

Remember our favourite ancient philosopher, Mediocrates, who said: "Meh, good enough'.

Some of these circuits are far more precise than others. Some are easier to calculate than others. It pays to choose a circuit that's good enough for your needs rather than fighting to make the best one. We often have the mindset that our circuits need to follow the best engineering possible but that is not always the case.

Professional engineers often only do the minimum required, because anything else is a waste of time and money. Yes, things are over-engineered but that is usually safety margin or for eventualities which are unlikely but could happen. Putting surge protection in a power supply is an example. Power surges don't happen that often but when they do, they can be terminal. However, rarely would an engineer build a 500A power supply when a 1.5A supply is needed. Yes, it's the best power supply they can build, but what's the point?

The same applies to these circuits: Ring counters are not always precise but if all you need is a clock for a shift register driving a scoreboard display, then there is nothing to be gained from engineering something more precise or advanced. This may sound silly but it is so easy to lose sight of that when designing a project. We do it all the time! We often have to ask deliberate questions of ourselves to ensure this doesn't happen. So, remember, the best oscillator you can build is not necessarily the best oscillator for your needs.