Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Arduino Capacitance Meter Code
- //Measuring Range: from 100pF to 1µF
- //A1 is the positive probe
- //For testing the capacitors connect to A1 and GND
- #define analogPin 1 //common point for connecting the resistors and positive probe
- #define chargePin 2 //connect to the end of resistor of 10MΩ
- #define dischargePin 3 //connect to the end of resistor of 220Ω
- #define R_Value 10000000.0F //resistor of 10MΩ
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- unsigned long startTime;
- unsigned long elapsedTime;
- float microFarads;
- float nanoFarads;
- float picoFarads;
- void setup() {
- }
- void loop() {
- pinMode(chargePin, OUTPUT);
- digitalWrite(chargePin, LOW);
- lcd.begin(16, 2);
- digitalWrite(chargePin, HIGH);
- startTime = millis();
- while(analogRead(A1) < 648){
- }
- elapsedTime= millis() - startTime;
- microFarads = ((float)elapsedTime / R_Value) * 1000;
- lcd.print(elapsedTime);
- lcd.print(" mS");
- delay(2000);
- lcd.clear();
- delay(500);
- if (microFarads > 1){
- lcd.print(microFarads);
- lcd.print(" uF");
- delay(2000);
- lcd.clear();
- delay(500);
- }
- if (nanoFarads = microFarads * 1000.0){
- lcd.print(nanoFarads);
- lcd.print(" nF");
- delay(2000);
- lcd.clear();
- delay(500);
- }
- if (picoFarads = nanoFarads * 1000.0){
- lcd.print(picoFarads);
- lcd.print(" pF");
- delay(2000);
- lcd.clear();
- delay(500);
- }
- lcd.clear();
- digitalWrite(chargePin, LOW);
- pinMode(dischargePin, OUTPUT);
- digitalWrite(dischargePin, LOW);
- while(analogRead(A1) > 0){
- }
- pinMode(dischargePin, INPUT);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement