Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Capacitance Meter, AutoRanging, with OLED Display.

Mounted in an Altoid Box. Run by 9VDC battery. Code Updated 05Feb2021.


File Download: https://durhamwilly.ca/capacitance-meter-autoranging/
Circuit adapted from one created by Mirko Pavleski:
https://create.arduino.cc/projecthub/mircemk/diy-simple-autorange-capacitance-meter-10pf-10000microf-e6e797

GND VCC SCK SDA


0.91 Inch OLED Display Module
with I2C Interface.
SSD1306 Compatible with
Arduino Driver DC 3-5V
Brand: GoldenMorning, Amazon.ca

1K

Capacitor
Under Test
(Polarity
Insensitive) 1Meg

D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 GND RST RX0 TX1


GND Reset

NANO
Mini USB

Reset
MOSI SCK
PIN11 PIN13

VCC MISO
PIN5V PIN12
Spi

D13 3V3 REF A0 A1 A2 A3 A4 A5 A6 A7 5V RST GND VIN

10K

Notes:
1.) Each time the meter is turned on, a calibration occurs, so it's important that you do
not have a capacitor connected to the test leads when turning the unit on. This
calibration only needs to take place once, so if you are testing a few capacitors, you
are fine after allowing the initial calibration on start-up. On-Off
Switch

2.) You must also discharge capacitors before testing.

3.) When testing, smaller value capacitors readings happen quickly. Large capacity
ones make the top part of the OLED appear to go blank, until the capacitor has
+ -
charged sufficiently to give you a reading.
9VDC
4.) When making your circuit, use the most accurate tolerance resistors you have! I
used Gold - 5%

5.) Your power supply can be anything from 5V to 9V, and the accuracy seems to be
just fine.. Code on Page 2

SSD1306 OLED

Raised Plastic
square to wrap
test leads around
for storage

This file created by DurhamWilly@gmail.com


https://durhamwilly.ca/capacitance-meter-autoranging/
Code ..... Copy code out of this PDF file into a blank
// Autoranging Capacitance Meter ... adapted from: arduino sketch. Code adapted from
// https://create.arduino.cc/projecthub/mircemk/diy-simple-autorange-capacitance-
meter-10pf-10000microf-e6e797
project created by Mirko Pavleski
// I'm not using the same display, so display code changed up..... Also added other stuff
such as screen
// printing of nF readings into mfd readings, cleaned up variables, and try to make this
meter a bit more
// user friendly on-screen! ......... Durhamwilly. This project's code and schematic resides time0=100000000;
as a pdf for download at: break;
// https://durhamwilly.ca/capacitance-meter-autoranging/ }
}
////////////////////////////////////////// Usage Notes: //////////////////////////////////////////////
// 1.) Each time the meter is turned on, a calibration occurs, so it's important that you do time1=micros()-time0;
not
// have a capacitor connected to the test leads when turning the unit on. while(analogRead(A0)>0){
// This calibration only needs to take place once, so if you are testing a few pinMode(7,OUTPUT);
capacitors, pinMode(8,OUTPUT);
// you are fine after allowing the initial calibration on start-up. digitalWrite(7,LOW);
// 2.) You must also discharge capacitors before testing. digitalWrite(8,LOW);
// 3.) When testing, smaller value capacitors readings happen quickly. }
// Large capacity ones make the top part of the OLED appear to go blank, until the
capacitor has if(mk==1&&time1<1000){
// charged sufficiently to give you a reading. mk=0;
// 4.) When making your circuit, use the most accurate tolerance resistors you have! I }
used Gold - 5%
// 5.) Your power supply can be anything from 5V to 9V, and the accuracy seems to be capacitance=time1;
just fine.. capacitance=capacitance/1000;
// 6.) Meter is NOT polarity sensitive when testing capacitors
///////////////////////////////////////////////////////////////////////////////////////////////////// if(time1>=10000000){

// Wiring of "test lead" Pins (but see schematic!): ////////// u8g2.setFont(u8g2_font_6x12_tf); // set font
// A0 to capacitor probe 1 via a 10K resistor. // cursor position (L to R, Row)
// D7 to capacitor probe 1 via a 1K resistor. u8g2.setCursor(3,30);
// D8 to capacitor probe 1 via a 1Meg resistor. u8g2.print("~ CAPACITOR READING ~"); // write to the internal
// GRN to capacitor probe 2 memory
u8g2.sendBuffer(); // transfer internal memory to the display
// Display Pins SSD1306: /////////////// }
// Arduino A4 to SDA on SSD1306 else{
// Arduino A5 to SCK on SSD1306
// Arduino GND Pin to GND on SSD1306 /////////// screen printout //////////////////
// Arduino 5V Pin to VCC on SSD1306 u8g2.setFont(u8g2_font_6x12_tf); // set font
u8g2.setCursor(3,30);
// Arduino Board Power: ////////////// u8g2.print("~ CAPACITOR READING ~"); // write to the internal
// Arduino GND pin to - 9VDC memory
// Arduino VIN pin to + 9VDC .... I used a standard 9V battery for power. u8g2.sendBuffer(); // transfer internal memory to the display
// You can also power this with the Mini USB cable, ///////////////////////////////////////////////////////////
// which you obviously will need to do in order to upload this code!
if(mk==0){
#include <Arduino.h>
#include <U8g2lib.h> u8g2.setFont(u8g2_font_ncenB10_tr); // set font
#include <SPI.h> // cursor position (L to R, Row)
#include <Wire.h> u8g2.setCursor(0,15); // set cursor position
if(capacitance>.5){ // only display if capacitor is under test.
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0); // set up the u8g2.print(capacitance); // print value with decimal places, as
SSD1306 OLED display capacitance variable is a float, not an int.
u8g2.print(" nF / ");
void setup(){ }
pinMode(A0,INPUT); else{
Serial.begin(9600); u8g2.setFont(u8g2_font_ncenB10_tr); // set font
u8g2.begin(); u8g2.print("Insert Capacitor ");
} }

unsigned long time0,time1,time2; u8g2.setFont(u8g2_font_ncenB10_tr); // set font


float capacitance; // now also display the nF reading in mfd’s for us old guys
byte kn,mk,i; u8g2.print(capacitance/1000); // ( microfarads = nanofarads ÷
1,000 )
void loop(){ u8g2.print(" uF");
u8g2.sendBuffer(); // transfer internal memory to the display
if(mk==0){ delay(2000);
pinMode(8,OUTPUT); u8g2.clearBuffer(); // clear the internal memory
pinMode(7,INPUT); }
digitalWrite(8,HIGH); if(mk==1){
} u8g2.setFont(u8g2_font_ncenB10_tr); // set font
u8g2.setCursor(30,15); // set cursor position
if(mk==1){ u8g2.print(capacitance); // print capacitance value
pinMode(7,OUTPUT); u8g2.print(" uF ");
pinMode(8,INPUT); u8g2.sendBuffer(); // transfer internal memory to the display
digitalWrite(7,HIGH); delay(2000);
} u8g2.clearBuffer(); // clear the internal memory

time0=micros(); }
while(analogRead(A0)<644){ }
time2=micros()-time0; }
if(time2>=1000000 && mk==0){
mk=1;

You might also like