Advertisement
Electgpl

ARDUINO - Capacimetro pF

Feb 3rd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. //Capacimetro Digital para pF
  2. const int OUT_PIN = A4;
  3. const int IN_PIN = A0;
  4. long int acumulado=0;
  5. void setup(){
  6.    pinMode(OUT_PIN, OUTPUT);
  7.    pinMode(IN_PIN, OUTPUT);
  8.    Serial.begin(9600);
  9. }
  10. void loop(){
  11.    for(int i=0; i<150; i++){
  12.       pinMode(IN_PIN, INPUT);
  13.       digitalWrite(OUT_PIN, HIGH);
  14.       int val = analogRead(IN_PIN);
  15.       digitalWrite(OUT_PIN, LOW);
  16.       pinMode(IN_PIN, OUTPUT);
  17.       float capacitancia = (float)val * 24.5 / (float)(1023 - val);
  18.       acumulado = capacitancia + acumulado;
  19.    }  
  20.    Serial.print("Capacitor = ");
  21.    Serial.print(acumulado/150);
  22.    Serial.println("pF ");
  23.    acumulado = 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement