Hello,
I just opened my brand new Arduino UNO R3 yesterday. I was able to get the "Hello World!" blinking light sketch to run right away and then decided to try something a little more sophisticated. I wanted to build the 'Capacitance Meter' exactly as described on this page:
http://arduino.cc/en/Tutorial/CapacitanceMeterI copied the code almost entirely and configured my board with a 220 ohm resistor between the charge pin and the rest of the circuit as well as a 220 ohm resistor between the circuit and the discharge pin as described in the schematic. I used a 100uF capacitor as a test. When I ran the sketch, no capacitance values were printed on the serial monitor.
To troubleshoot, I began sending messages to the screen to indicate where in the program it was breaking down and what I determined was that it got caught up in a while loop because the analogPin never reached 63.2% of the maximum voltage. I modified the code to give me a reading of the chargePin just before it entered the while loop and found that the chargePin was only putting out approximately 2-2.5 V instead of the expected 5V.
Here is the code that I used. You can see that the chargePin is set as output and set to HIGH and still doesn't put out 5V
#define analogPin 0 // analog pin for measuring capacitor voltage
#define chargePin 13 // pin to charge the capacitor - connected to one end of the charging resistor
#define dischargePin 11 // pin to discharge the capacitor
#define resistorValue 220.0F // change this to whatever resistor value you are using
// F formatter tells compliler it's a floating point value
unsigned long startTime;
unsigned long elapsedTime;
float microFarads; // floating point variable to preserve precision, make calculations
float nanoFarads;
void setup(){
pinMode(chargePin, OUTPUT); // set chargePin to output
digitalWrite(chargePin, LOW);
Serial.begin(9600); // initialize serial transmission for debugging
}
void loop(){
digitalWrite(chargePin, HIGH); // set chargePin HIGH and capacitor charging
int chargeValue = analogRead(chargePin);
Serial.print("Charge pin is: ");
Serial.println(chargeValue); // chargePin gives result that corresponds to ~2.5 volts instead of 5V
int analogValue = analogRead(analogPin);
Serial.print("Analog pin is: ");
Serial.println(analogValue);
startTime = millis();
Serial.println(millis());
while(analogRead(analogPin) < 648){ // 647 is 63.2% of 1023, which corresponds to full-scale voltage
Serial.println(analogValue); //analogPin never gets above 2.5V meaning it will never reach the desired 63.2% and will stay in this loop forever
}
I really didn't do anything crazy with the board yet...I've only had it a day! So I can't imagine that I'd have fried a pin already?? If you have any suggestions or need clarification, let me know. Thanks!