Advertisement
Braulio777

Arduino Capacitance Meter

Jun 15th, 2015
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.80 KB | None | 0 0
  1. //Arduino Capacitance Meter Code
  2. //Measuring Range: from 100pF to 1µF
  3. //A1 is the positive probe
  4. //For testing the capacitors connect to A1 and GND
  5. #define analogPin 1          //common point for connecting the resistors and positive probe        
  6. #define chargePin 2          //connect to the end of resistor of 10MΩ      
  7. #define dischargePin 3       //connect to the end of resistor of 220Ω      
  8. #define R_Value 10000000.0F  //resistor of 10MΩ
  9.  
  10. #include <LiquidCrystal.h>
  11. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  12. unsigned long startTime;
  13. unsigned long elapsedTime;
  14. float microFarads;                
  15. float nanoFarads;
  16. float picoFarads;
  17.  
  18. void setup() {
  19. }
  20.   void loop() {  
  21.   pinMode(chargePin, OUTPUT);    
  22.   digitalWrite(chargePin, LOW);
  23.   lcd.begin(16, 2);
  24.   digitalWrite(chargePin, HIGH);  
  25.   startTime = millis();
  26.   while(analogRead(A1) < 648){      
  27.   }
  28.   elapsedTime= millis() - startTime;
  29.   microFarads = ((float)elapsedTime / R_Value) * 1000;
  30.   lcd.print(elapsedTime);      
  31.   lcd.print(" mS");
  32.   delay(2000);  
  33.   lcd.clear();
  34.   delay(500);
  35.  
  36.   if (microFarads > 1){
  37.     lcd.print(microFarads);      
  38.     lcd.print(" uF");  
  39.     delay(2000);
  40.     lcd.clear();
  41.     delay(500);
  42.   }
  43.    if (nanoFarads = microFarads * 1000.0){      
  44.     lcd.print(nanoFarads);        
  45.     lcd.print(" nF");          
  46.     delay(2000);
  47.     lcd.clear();
  48.     delay(500);
  49.   }
  50.    if (picoFarads = nanoFarads * 1000.0){      
  51.     lcd.print(picoFarads);        
  52.     lcd.print(" pF");          
  53.     delay(2000);
  54.     lcd.clear();
  55.     delay(500);
  56.   }
  57.  
  58.   lcd.clear();
  59.   digitalWrite(chargePin, LOW);            
  60.   pinMode(dischargePin, OUTPUT);            
  61.   digitalWrite(dischargePin, LOW);          
  62.   while(analogRead(A1) > 0){        
  63.   }
  64.   pinMode(dischargePin, INPUT);      
  65.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement