No Oscilloscope? Try an Arduino!

by JD_K in Circuits > Arduino

704 Views, 9 Favorites, 0 Comments

No Oscilloscope? Try an Arduino!

1630977786054.jpg
IMG_20210904_183915.jpg
Capacitors.jpg

I had a need to measure the timing of the output of a 555 chip. I could have just connected it up to a LED and timed it with a stopwatch, but I wanted a better way to quantify the timing and to see if this timing drifts over time. Of course, the best thing would be to connect it to an oscilloscope, but I don’t have one of those. So, in this Instructable I will show how I used an interrupt function on an Arduino to measure.

As a bonus, this set-up can show how resistors, and capacitors each work when connected in series or in parallel. I find it interesting that they “behave” in opposite ways. And finally, I used the Arduino to show the tracing of the output, and of the capacitor, similar to what you would see on an oscilloscope screen.

Supplies

Parts

  • Arduino Uno
  • 555 Timer integrated chip
  • Jumper wires
  • Resistors, two or more, any values between 1kOhm to 1MOhm will do
  • Electrolytic capacitor, one or more, 10 uF but any value would do
  • Solderless breadboard, 140-point size or bigger
  • Proto Shield for Arduino (optional)

A Word About Electrolytic Capacitors

Likely if you are trying out this project, you are somewhat new to electronics. Electrolytic capacitors are polarized, meaning it is important which electrode is connected to the positive voltage and which is connected to ground. On these capacitors the longer electrode is the “anode” and should be connected to the positive voltage. The shorter electrode is the “cathode” and should be connected to the zero volts (ground). The aluminum can that holds the capacitor together will have a large stripe on the cathode side. And this stripe usually has large minus signs. In the picture, you can see three capacitors, one with the large white stripe. If you connect the capacitor in backwards, or you connect a larger voltage than the rating for that capacitor, then there is a good chance it will “pop” like a firecracker. In fact, if you look at the top (not shown, sorry), there are often “x” shaped grooves where the capacitor has been designed to break in such a situation.

Connections

Pinout 555.jpg
Circuit Astable.png
2 Vcc GND.jpg
3 Resistors.jpg
20210904_145602-0.jpg
7 Output to Arduino D2.jpg
No Oscilloscope? Try an Arduino (Part 1)

There is a YouTube video (Part 1) that is an overview of this project (link)

For this project I made all the connections with a proto shield and a small breadboard, but the shield is optional. In the first picture, you can see the drawing of a 555 Timer with the names of the pins and their numbering. The important thing here is to note that there is a round notch on the chip between pins 1 and 8. The next pictures show a drawing of the wiring, and then one-by-one the connections I made:

Image 1: The 555 Timer pinout
Image 2: The connections to the 555 for the Astable Operation
Image 3: Connecting Ground (GND) and 5Volts of the Arduino to pins 1, 4 and 8 of the 555
Image 4: Adding Resistors A and B
Image 5: Adding the capacitor and its 3 connections: anode to pins 2 & 6, cathode to GND
Image 6: Connecting the output pin, pin 3, to the digital pin 2 (D2) of the Arduino

How It Works

When the Arduino is powered up, current passes from its 5 Volt source through both resistors to charge up the capacitor. This takes time depending on the size of the resistors and the capacitor. When the charge on the capacitor reaches 2/3 of the 5Volt source, the output pin of the 555 timer will go low, meaning it will be at 0 volts. And at this point the capacitor will start draining current through resistor B. Again, this takes time depending on the capacitor and resistor B. When the voltage has reduced to 1/3 of 5 Volts, the output pin will switch to 5 Volts (high), and cycle will begin again with charging up the capacitor. The result should be a regular repeating High-Low signal from this chip which can be used in electronics when a timing signal is needed.

Displaying the Values on the Arduino

SerialMonitor2.png

To be able to see the effects of different combinations of resistors and capacitors, I used the Arduino to display the timing on my computer. This function in the Arduino IDE software is called the Serial Monitor (see picture with all the numbers), and is a way to communicate between the Arduino and the computer when the Arduino is running.

In the code below, I start by declaring some variables. The first two are Boolean variables, which mean they can only be zero or one, which are synonymous in this situation with low or high, which is synonymous with 0 volts or 5 volts. I called these two variables “state” and “lastState” and use them to keep track of when the output pin changes. Similarly, there are two variables used to keep track of the time, called “currentTime” and “lastTime”. And finally, another variable is used to store the time duration. This variable is called “timeDifference” as it will be the difference between currentTime and lastTime. This is a “float” type of variable, which means it can keep track of decimals.

Basically, how the code works, is that if the output pin of the 555 Timer changes, from low to high, or high to low, a function, named “timeStamp”, is activated. This is a type of function called an “interrupt service routine” because, regardless of where the Arduino is in its code, the timeStamp function will run, then the Arduino will go back to where it was in its code. During timeStamp, the Arduino will update the “state” variable to match whether the output pin is high or low, and it will update the “currentTime” variable with a function called “micros”. This is a built-in function of the Arduino software which returns the number of microseconds since the Arduino last turned on or reset. Now that “state” and “currentTime” are updated, the Arduino will calculate the time difference and print that on the Serial Monitor of the computer. Then it updates makes “lastState” and “lastTime” to match “state” and “currentTime”, respectively so that they are ready for the next time the output pin changes.

Predicting the Results

There are calculations you can do to predict what the number of seconds for the timing. These are useful if you have specific timing in mind and you want to know where to start. The formula is for calculating the HIGH period, the amount of time the output pin is high (5 volts). This formula is:

HIGH period = 0.7 * (Resistor A + Resistor B) * Capacitor

The other formula is for calculating the LOW period, when the output in is low (0 volts). This does not use resistor A at all, and is calculated:

LOW period: = 0.7 * (Resistor B) * (Capacitor)

For these equations to work the units must be in Ohms for resistance, and Farads for the capacitor. So, for example, 10 kilohms and 10 microFarads (uF), will be 10 000 ohms and 0.00001 Farads. So, the example with the two 10 kilohm resistors and the 10 uF capacitor, the HIGH period should be 0.14 seconds, and the LOW should be 0.07 seconds.

Experimenting Time!

No Oscilloscope? Try an Arduino (Part 2)

Now that everything is set up, then you can experiment with different resistors and capacitors so see if the measured timing is what you predict!

... For the rest of this Instructable, there is a Part 2 video on YouTube video (link)

Also, an interesting thing about this circuit is you can see the effect of putting multiple resistors or capacitors for either Resistor A or B, or the capacitor. You can connect components in either series (end to end) or parallel (side-by-side) and see how capacitors “behave” opposite to resistors. In the part 2 video, you can see what I mean.

Visualizing the Voltage Level With the Arduino

22uF square.png
Sawtooth (2).png
Sawtooth2.png

I demonstrate this at the end of the part 2 video in the previous step. Since we are using the Arduino IDE, we can also take advantage of its Serial Plotter. This is a basic graphing function of the software and can show you how the voltage changes over time. By using the small code below, you can graph the voltage of the output pin by connecting it to the A0 pin of the Arduino, and see how the output changes in a stepwise fashion (first picture). The other interesting pin to see is the charging and discharging of the capacitor (two picture examples). The voltage here changes exponentially, where it changes quickly at first but the slows its rate of change as the capacitor charges or discharges. For that connect the anode of the capacitor (which is connected to pin 6 of the 555) to the Arduino A0 pin and see the classic “saw tooth” pattern that is characteristic of capacitors. Then to open the Serial Plotter, go to “Tools” and click Serial Plotter. A window will open, and you should see the voltage change on the graph.

That’s it for now. I hope you found this project interesting. This was a useful circuit to test out the 555 Timer and to determine the right resistors and capacitors I needed. And it confirmed what I had learned about capacitors and how they work.