element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino Tutorials
  • Products
  • Arduino
  • Arduino Tutorials
  • More
  • Cancel
Arduino Tutorials
Blog The RC circuit
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino Tutorials to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: organtin
  • Date Created: 4 Mar 2016 9:21 AM Date Created
  • Views 16446 views
  • Likes 12 likes
  • Comments 13 comments
  • capacitor
  • rc
  • resistor
  • arduino
  • physics
Related
Recommended

The RC circuit

organtin
organtin
4 Mar 2016

This time I am going to share with you an amazingly simple experience that is made possible using just an Arduino UNO board, a resistor and a capacitor. The RC circuit is a classic circuit in physics teaching and is composed by just a resistor R and a capacitor C in series. For details you can look at the Charging a Capacitor page of the HyperPhysics pages. Pupils study the charging and discharging of the capacitor when the circuit is connected to a battery. A rather simple mathematics gives the laws governing the process. It is easy to show that the voltage across the capacitor VC is a function of the time t: when the capacitor is not charged and is connected to a voltage V0 through the resistor, one gets

VC(t)=V0(1−e−tθ )

Here  θ is a parameter having the dimensions of a time called the time constant of the circuit and is given by the product RC. When the capacitor is at its full charge and the two leads of the circuit are short circuited, the voltage across the capacitor drops with time with an exponential law whose time constant is still given by RC.

 

In the past, making the experience in a physics laboratory, was not so easy for students. The time constants that one can get using easily available components are short. For R of the order of few tens of kΩ and C of the order of few μF, the time constant is of the order of 10×103×10-6≈10-2s, i.e. a hundredth of a second. In order to measure the voltage across the capacitor as a function of time you need to connect the leads of a multimeter to the capacitor and read its value as a function of time, so you need time constants of the order, at least, of few seconds. That requires extremely large values of C (and R) that, of course, are not impossible to obtain, but are not so easy to find. Even in this case you can only collect few values.

 

With an Arduino board the job is greatly simplified and, needless to say, the precision you can attain with it is impressive.

 

The circuit, shown in the picture below (made with Fritzing), is easily realised connecting one of the leads of the resistor to the 5V pin of Arduino; the resistor is mounted in series with the capacitor that, in turn, has its second lead to the ground (GND). In order to measure the voltage across the capacitor, we connect the first lead of the capacitor to one of the Arduino analog inputs (A5).

 

image

Initially, the red wire is not connected to the 5V pin and the capacitor is not charged. Using the new Arduino IDE one can plot the values written to the Serial monitor as a function of time (in fact as a function of the reading). Consider the following code:

   void loop() {
    while (fabs(analogRead(A5)*5/1024. - lastReading) < 0.1) {
      // do nothing
    }
    for (int i = 0; i < 480; i++) {
      float currentReading = analogRead(A5)*5/1024.;
      Serial.println(currentReading);
    }
    while (1) {
      // do nothing
    }
}

The first loop just waits until the current reading of the A5 pin (analogRead(A5)) differs from the value of lastReading for more than one tenth of a volt. The fabs function returns the absolute value of its argument. The reading of the analog input can be an integer number between 0 and 1024 representing a voltage ranging from 0 to 5 V. Multiplying the reading by 5 and dividing it by 1024 we then get the value of the voltage across the capacitor in Volts. Note the dot after 1024 that is needed to make the value a floating point number. If the dot is missing, both 5 and 1024 are represented as integers in the Arduino memory, as well as the value returned by analogRead(A5). This can lead to important consequences. Suppose, for example, that the analogRead(A5) function returns 123. Once multiplied by 5, we get 615 that, divided by 1024 gives just zero! In fact, 615/1024 is a ratio between two integers and the result is interpreted as an integer, too. Writing 615/1024. (with the dot after 1024) forces the CPU to represent the number 1024 as a floating point number and any operation made using an integer (615) and a floating point number (1024.) is a floating point number (about 0.6).

 

The value of lastReading must be set in the setup() of the Arduino sketch, in which we also initialise the Serial monitor with

Serial.begin(9600);

The first loop, then, is needed to start the program as well as the Serial plotter, having the time to connect the red wire to the 5V pin. Only when such a wire is connected to that pin the capacitor starts charging and the voltage across its leads starts raising. At this point we just read a fixed number of values of such a voltage (480 in our case) and write them on the Serial monitor. Each value written to the Serial monitor is shown on the Serial plotter versus time (in fact each value written to the Serial monitor is plotted against a sequential number, but in our case the readings are made at almost constant intervals of time, hence the horizontal axis values are proportional to time).

 

Once we read all the values we just stop doing anything with the last loop. The result is shown below.

 

image

Such a very nice curve is exactly what we expected. You can even measure the discharge curve just repeating the experience in the following way: once charged, the capacitor remains charged until it is short circuited on the resistor. So, just disconnect the red wire from the 5V pin, restart the program and the Serial plotter, and connect the free lead of the red wire to the ground. The capacitor starts discharging on the resistor and the voltage across it changes. Soon after, the program makes 480 readings of the voltage and plot them, as can be seen below.

 

image

You can even be more quantitative with a slight change into the Arduino sketch. Consider the following:

 

   float lastReading;
   unsigned long time;
   void setup() {
     Serial.begin(9600);
     lastReading = analogRead(A5)*5/1024.;
   }
    void loop() {
    while (fabs(analogRead(A5)*5/1024. - lastReading) < 0.1) {
      time = micros();
    }
    for (int i = 0; i < 480; i++) {
      unsigned long now = micros();
      Serial.print(now - time);
      Serial.print(" ");
      float currentReading = analogRead(A5)*5/1024.;
      Serial.println(currentReading);
    }
    while (1) {
      // do nothing
    }
  }

At the beginning of the loop we still wait for a change in the voltage, but in this case we collect the current time in the time variable. The current time is given by the micros() function returning the number of microseconds elapsed since the start of the sketch. As soon as the voltage changes we start measuring the voltages across the capacitor, but in this case we also get the time of each measurement and send to the Serial monitor both the time elapsed since the start of the measurements and the measurement values.

 

We write those two numbers to the Serial monitor, then copy and paste them into a text file for subsequent analysis. The picture below shows the data collected by us, during the charge:

 

image

Times are in microseconds and you can see how rapid is the process. The capacitor is almost at its full charge already after 2 seconds. We used a resistor whose resistance was R=9.94 kΩ. We can then get the value of the capacitor from these measurements. With some mathematics one obtains a time constant θ of 0.53 s, from which we can derive C as θ/R≈54 μF. The nominal value of the capacitor we used is 47 μF. The error in the determination of it is then less than 15%.

  • Sign in to reply

Top Comments

  • DAB
    DAB over 9 years ago +3
    Nice post. Takes me back to my Tech school days when we went through RC circuits and plotted them by hand. I hope the newbies reading this post take a good look at the actions of just simple components…
  • D_Hersey
    D_Hersey over 9 years ago +3
    If you google 'capacitance multiplier' you will find circuits that use an op-amp to make a capacitor (that has one side attached to the supply) look bigger. You can easily get, say, a 10^4 apparent increase…
  • jw0752
    jw0752 over 9 years ago +2
    Hi Giovanni, I really like to see this type of presentation on the Forum. It reminds me of just how much fun one can have exploring electronics. It combines theory, the use of an MPU, and a basic electronic…
  • rscasny
    rscasny over 9 years ago

    Giovanni,

     

    A great getting-back-to-basics lesson with an Arduino twist, so to speak.

     

    You did this one on RC circuits. Do you have plans or interest in doing a project on LR circuits, or another version, an LC /tank circuit?

     

    Randy Scasny

    element14

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • kas.lewis
    kas.lewis over 9 years ago

    Pretty cool teaching tool, image thanks for sharing

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago

    This will work for non-electrolytic capacitors, but the leakage of some electrolytic capacitors will give a very inaccurate result.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dougw
    dougw over 9 years ago

    Nicely done. There is enough data to get a pretty precise value for the capacitor, assuming you can measure the resistor accurately.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • D_Hersey
    D_Hersey over 9 years ago

    Instead of an exponential curve, you would get a linear ramp, the slope of which would be proportional to the value of the current source.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube