Capacitors: are not they an element of the analogue world? What is their use in digital computers?
Well, there are at least three applications for capacitors in computers:
- They might be used to generate the clock cycles driving the CPU
- They support a stable supply voltage
- Inside dynamic memories they can be used for storing data at least for a very short time after which they have to be refreshed.
To have some fun in exploring the process of discharging, we use some wrapper of sweets which contain a thin sheet of metal, most probably it will be aluminium.
A short warning before you begin: avoid to make any short cuts. Strictly keep the Arduino off the metal sheet. I won't be responsible for any damages caused by your mishandling.
Actually, we need a pair of them. Gently open the wrapper and carefully make it plane. We also need an isolator; a sheet of paper will do, but much better is some greaseproof paper. Even better: cut a square piece of a plastic garbage bag. The whole thing actually forms a capacitor. Of course, we need two cables to connect both of the wrappers to two pins of the Arduino. In Order to get the wrappers close to each other we need a plane object, for instance a pane of glass to press things together.
Make sure both of the wrappers do not get in touch with one another. Now use some wires to connect them to the Arduino pins. Unfortunately, you cannot solder copper wires to the aluminium sheets.
Though the code is very short some lines should be explained.
As the capacity of our capacitor is very low, it will charge and discharge quite fast. That is why we need to speed up the analogue-to-digital converter by setting its prescaler select bits to 011 giving a factor of 8.
The charging pin has to be configured as output. To avoid using a separate resistor we configure the input pin as INPUT_PULLUP which connects an internal resistor to Vcc.
Measuring has to be done as fast as possible. Immediately printing the values would cause unnecessary delays. That is why two separate loops are needed. The line c=1204-b[i] inverts the graphic and makes it look like a normal discharge process.
The times for the loop can be obtained by inserting t=micros(). This gives us the possibility to evaluate the graph shown in the Serial Plotter. Now we have to do some math:
Indicated in the graph is the moment when the voltage drops to the half of its initial value U0.
Using the ln function we find that R*C = 0.00004328 seconds.
As the ATMEL data sheets give a value of approximately 20 kOhms for the internal resistor we find that our self made capacitor will have a capacity of about 2 nF.
/*
Watch charging/discharging a small capacitor
made of two "golden" wrappers of chocolate sweets.
Hardware:
Connect one sheet to outPin.
Connect the other sheet to inPin.
You need thin wires to make the contacts.
Between the sheets there should be some paper,
greaseproof paper or thin plastc is the best.
Press it all together and watch the output
using the Serial Plotter.
*/
const byte outPin = 3;
const byte inPin = A0;
void setup() {
Serial.begin(115200);
// enable this line to get a much
// better timing resolution:
ADCSRA = B11000011;
pinMode(outPin, OUTPUT);
// enable the internal pullup resistor
// (otherwise you need to install
// an external one of your choice)
pinMode(A0, INPUT_PULLUP);
}
void loop() {
const int N = 100;
int b[N];
long t1 = micros();
digitalWrite(outPin,HIGH);
digitalWrite(outPin,LOW);
for (int i = 0; i < N; i++)
b[i] = analogRead(inPin);
long t2 = micros();
// enable this to read the time for sampling N values
// Serial.println(t2 - t1); return;
for (int i = 0; i < N; i++) {
// this line converts charging into discharging:
int c = 1024 - b[i];
Serial.println(c);
}
// have a chance to watch results:
delay(500);
}
Comments