Created
December 7, 2019 09:11
-
-
Save Electronza/d3eb5fbda249347c6ed86cba52e9d68b to your computer and use it in GitHub Desktop.
Arduino code example for Mikroe C-meter click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://electronza.com/mikroe-2376-arduino-uno-capacitance/ | |
// C-meter click is installed in socket #1 | |
// of Arduino Uno click shield | |
// Pulses will be applied on pin D2 | |
int pin = 2; | |
// We compute on float | |
float period; | |
float Cx; | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(pin, INPUT); | |
} | |
void loop() | |
{ | |
period = 0; | |
// We compute the average of four measurements | |
// one of the reasons I choose float | |
Serial.println("Measurements"); | |
period += pulseIn(pin, HIGH); | |
period += pulseIn(pin, LOW); | |
period += pulseIn(pin, HIGH); | |
period += pulseIn(pin, LOW);; | |
period += pulseIn(pin, HIGH); | |
period += pulseIn(pin, LOW); | |
period += pulseIn(pin, HIGH); | |
period += pulseIn(pin, LOW); | |
// We divide only by four, as the above code measures | |
// Th and Tl separately | |
// and one period T = Th + Tl | |
period = period / 4; | |
Serial.print("Period is: "); | |
Serial.println(period*1000); | |
Serial.print("Frequency is: "); | |
Serial.print(1000000/period); | |
Serial.println("kHz"); | |
Serial.println(""); | |
Cx= period * 1000 / 77816; | |
Serial.print("Capacity is: "); | |
Serial.print(Cx); | |
Serial.println(" uF"); | |
Serial.println(""); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment