capacitor question im confused

the reading from the voltage meter is 4.62
and yes it was a > 4.8

wiring as follows

~82k resistor + 10k trimpot (calibration) in series from A1 to +batt/supply
10k resistor from A1 to ground
100n capacitor from A1 to ground for stable readings

 calibration a 9volt battery and a DMM, adjust trimpot to the same reading

i also tried the following

 unsigned long total_1;
unsigned long total_2;
//
void setup() {
  analogReference(INTERNAL); // use internal 1.1volt reference, change (INTERNAL) to (INTERNAL1V1) for a Mega
  Serial.begin(115200); // ---set serial monitor to this value---
}
//
void loop() {
  analogRead(1); // one unused reading to clear old sh#t
  for (int x = 0; x < 1000; x++) { // 1000 readings
    total_1 = total_1 + analogRead(1); // add each value
  }
  analogRead(2); // one unused reading to clear old sh#t
  for (int x = 0; x < 1000; x++) { // 1000 readings
    total_2 = total_2 + analogRead(2); // add each value
  }
  // print to serial monitor
  Serial.print("Raw average = ");
  Serial.print(total_1 * 0.001, 3); // 1000 readings /100, 2 decimal places
  Serial.print(" | ");
  Serial.print(total_2 * 0.001, 3); // 1000 readings /100, 2 decimal places
  Serial.print("   Input A1 = ");
  Serial.print(total_1 * 0.00001, 3); // convert milivolts to volts, display with 3 decimal places
  Serial.print(" volt");
  Serial.print("   Input A2 = ");
  Serial.print(total_2 * 0.00001, 3); // convert milivolts to volts, display with 3 decimal places
  Serial.println(" volt");
  //
  delay(1000); // optional readout delay
  total_1 = 0; // reset values
  total_2 = 0;
}

but the reading was as if there was nothing attached yes i do have a complete circuit and its been tested at both ends with a multimeter. this applies for all my available analog sockets
A0,A1, A3,A4 to the end

and the suggested code above just returns

5 Volt Supply = 4.80
5 Volt Supply = 4.80
5 Volt Supply = 4.80
5 Volt Supply = 4.80

no matter connected or disconnected from voltage.
i can't understand it .. it was working until i was told to put in the following wiring diagram
~82k resistor + 10k trimpot (calibration) in series from A1 to +batt/supply
10k resistor from A1 to ground
100n capacitor from A1 to ground for stable readings

now with or without it im getting nothing. but the rest of the system is working

Don't forget to change (INTERNAL) to (INTERNAL1V1) for your Mega.
Leo..

Threads merged.

UPDATE ALERT

i have tested the code on its own

void setup() {
  // put your setup code here, to run once:

  Serial.begin(115200);
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH); // turn on the radio
  pinMode(4, OUTPUT);    // switch on the radio
  digitalWrite(4, LOW); // ensure the radio is not sleeping
}

void loop() {
    // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (3.5 / 750);
  delay(1000);
  // print out the value you read:
  Serial.print("3 3Volt Supply = ");
  Serial.println(voltage);
delay(500);
      // read the input on analog pin 5:
  int sensorValueFive = analogRead(A5);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltageFive = sensorValueFive * (4.8 / 900);
  // print out the value you read:
  Serial.print("5 Volt Supply = ");
  Serial.println(voltageFive);
}

and this is working fine on both analog ports

but when i put it into a function in my code it stops working and just report 4.8 volts all the time

so its my code somewhere and there is 5 Tabs at about 1500 lines per tab

void VoltageCheck() {
    // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (3.5 / 750);
  delay(1000);
  // print out the value you read:
  Serial.print("3 3Volt Supply = ");
  Serial.println(voltage);
delay(500);
      // read the input on analog pin 5:
  int sensorValueFive = analogRead(A5);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltageFive = sensorValueFive * (4.8 / 900);
  // print out the value you read:
  Serial.print("5 Volt Supply = ");
  Serial.println(voltageFive);

}

main loop

void loop() {

//  //is the time up for this task?
//  if (millis() - lastMillis >= 1 * 30 * 1000UL)
//  {
//    lastMillis = millis();  //get ready for the next iteration
//    VoltageCheck();
//  }
//
  VoltageCheck(); // temp line for debug main code commented above
  delay(2000); // temp line for debug main code commented above



  blueledBlink();

  char command = Serial.read();
  if (command == ('a')) {

    emergency();
  }
  else {

    // Wait for a touch
    if (! ctp.touched()) {
      return;
    }

    // Retrieve a point
    TS_Point p = ctp.getPoint();

    // flip it around to match the screen.
    p.x = map(p.x, 240, 0, 240, 0);
    p.y = map(p.y, 320, 0, 0, 320);

    int a = page;
    switch (a) {

      // --------------check to see if screen 1 is loaded-----------------

      case 1: {  // Screen 1 Active As when screen 1 loads it chages the value of page to 1

          if ((p.x > 175 && p.x < 201) && (p.y > 280 && p.y < 320))
            setuser();

          else if ((p.x > 144 && p.x < 163) && (p.y > 280 && p.y < 320))
            systest();

          else if ((p.x > 104 && p.x < 116) && (p.y > 280 && p.y < 320))
            Serial.print("touch");


          else if ((p.x > 58 && p.x < 72) && (p.y > 280 && p.y < 320))
            Serial.print("option1.3");

          else if ((p.x > 5 && p.x < 39) && (p.y > 280 && p.y < 320))
           testfail();
          break;
        }

      // -----------------check to see if screen 2 is loaded------------------


      case 2: {  // Screen 1 Active As when screen 1 loads it chages the value of page to 1

          if ((p.x > 175 && p.x < 201) && (p.y > 280 && p.y < 320))
            volup();

          else if ((p.x > 144 && p.x < 163) && (p.y > 280 && p.y < 320))
            voldown();

          else if ((p.x > 104 && p.x < 116) && (p.y > 280 && p.y < 320))
            Serial.print("option1.2");

          else if ((p.x > 58 && p.x < 72) && (p.y > 280 && p.y < 320))
            Serial.print("option1.3");

          else if ((p.x > 5 && p.x < 39) && (p.y > 280 && p.y < 320))
            mainmenu();
          break;
        }

      // -----------------check to see if screen 3 is loaded------------------




      case 3: {  // Screen 1 Active As when screen 1 loads it chages the value of page to 1

          if ((p.x > 175 && p.x < 201) && (p.y > 280 && p.y < 320))
            Serial.println("one");

          else if ((p.x > 144 && p.x < 163) && (p.y > 280 && p.y < 320))
            setuser();

          else if ((p.x > 104 && p.x < 116) && (p.y > 280 && p.y < 320))
            Serial.print("option1.2");

          else if ((p.x > 58 && p.x < 72) && (p.y > 280 && p.y < 320))
            Serial.print("option1.3");

          else if ((p.x > 5 && p.x < 39) && (p.y > 280 && p.y < 320))
            Serial.print("option1.4");
          break;
        }

      // -----------------check to see if screen 4 is loaded------------------


      case 4: {  // Screen 1 Active As when screen 1 loads it chages the value of page to 1

          if ((p.x > 175 && p.x < 201) && (p.y > 280 && p.y < 320))
            Serial.println("one");

          else if ((p.x > 144 && p.x < 163) && (p.y > 280 && p.y < 320))
            setuser();

          else if ((p.x > 104 && p.x < 116) && (p.y > 280 && p.y < 320))
            Serial.print("option1.2");

          else if ((p.x > 58 && p.x < 72) && (p.y > 280 && p.y < 320))
            Serial.print("option1.3");

          else if ((p.x > 5 && p.x < 39) && (p.y > 280 && p.y < 320))
            Serial.print("option1.4");
          break;
        }


    }


  }
  // ---------------------End Screen check ------------------------------------


  // Print out raw data from screen touch controller for debug use only
  //
  //  Serial.print(" X "); Serial.print(p.x);
  //  Serial.print(" & Y "); Serial.print(p.y);
  //
  //  Serial.print("  Page Value= "); Serial.print(page);
  //  Serial.println();
  //  delay(500);


}

These post are now very confusing, because you have crossposted in two places.

Remember that you CAN'T measure the 5volt rail with the default 5volt Aref.

If you want to measure the 5volt rail, you MUST use another Aref.

The code I gave you uses (INTERNAL), but you HAVE to change that to (INTERNAL1V1) for a Mega.
Leo..

i am using it but after the capacitor was added it all stopped working
so i have just removed it. now its working

so i thought of going back to the basic of basics

i tried the setup on another board and it works Uno
using the basic code

i have a feeling the capacitive touch screen is causing problems
as this uses A2 and A3 for the capacitive touch

i have put a post of the touch screen maker's site to see if they can help

right im down to just the board Mega 2560 testing the voltage from a power converter outputting 5V via the capacitor and resistors as diagram top post

i am using the code

unsigned long total_1;

//
void setup() {
  analogReference(INTERNAL1V1); // use internal 1.1volt reference, change (INTERNAL) to (INTERNAL1V1) for a Mega
  Serial.begin(115200); // ---set serial monitor to this value---
}
//
void loop() {
  analogRead(1); // one unused reading to clear old sh#t
  for (int x = 0; x < 1000; x++) { // 1000 readings
    total_1 = total_1 + analogRead(0); // add each value
  }

  // print to serial monitor
  Serial.print("Raw average = ");
  Serial.print(total_1 * 0.001, 3); // 1000 readings /100, 2 decimal places
  Serial.print(" | ");
//  Serial.print(total_2 * 0.001, 3); // 1000 readings /100, 2 decimal places
  Serial.print("   Input A0 = ");
  Serial.print(total_1 * 0.00001, 3); // convert milivolts to volts, display with 3 decimal places
  Serial.println(" volt");

  //
  delay(1000); // optional readout delay
  total_1 = 0; // reset values
  
}

with no voltage on A0
i am getting

Raw average = 1004.327 | Input A0 = 10.043 volt
Raw average = 1003.484 | Input A0 = 10.035 volt
Raw average = 1003.967 | Input A0 = 10.040 volt
Raw average = 1002.310 | Input A0 = 10.023 volt

this is something i expect

but with a voltage attached

Raw average = 1023.000 | Input A0 = 10.230 volt
Raw average = 1023.000 | Input A0 = 10.230 volt
Raw average = 1023.000 | Input A0 = 10.230 volt
Raw average = 1023.000 | Input A0 = 10.230 volt
Raw average = 1023.000 | Input A0 = 10.230 volt
Raw average = 1023.000 | Input A0 = 10.230 volt

if i try to adjust the voltage the output does not change with any voltage i am getting the last readout constantly

Post a picture of your breadboard.
Leo..

"if i try to adjust the voltage the output does not change with any voltage i am getting the last readout constantly "

I suggest you take out "analogReference(INTERNAL1V1);", because you will get max reading until the voltage on the analog pin goes below 1v1. If you take out that script, it should show changes when your voltage on the analog pin goes below 4v7.

with your voltmeter, read the analog pin. Adjust your pot to 0.5 volts showing on the analog pin.

Now what result is your code showing, raw reading from analog pin (before any math)?

Make sure you are using the same analog pin for hardware, as software. I have seen in posts that you were using A1 for hardware, and I think you have used A0 in script.

CAUTION note: When using a voltage divider on an analog pin, it is good practice to make sure the resistor to ground is secure, before hooking up the one to the sample voltage. If the sample voltage is above 5 volts, it is critical to do this.

No,
OP wants to measure the 5volt rail, and you CAN'T measure that with 5volt Aref.
Sketch works 100%.
Wrote it myself, and tested it myself.
Running right now on the bench, showing 5.029volt on the LCD.
OP has modded the sketch, and has some mistakes in there, but it still should work.

He should check his voltage divider.
Last picture we saw was a voltage divider with a 820ohm resistor instead of a 82k resistor.
And the 10k resistor in series with the 100n cap.
The voltage divider indeed has to divide to 0.5volt.

We need to see a picture....
Leo..

"OP wants to measure the 5volt rail, and you CAN'T measure that with 5volt Aref."

I beg to differ. I have used a 5 volt reference (default) several times, to measure anywhere from 2 volts to 18 volts. I have to modify the voltage divider for the higher voltages (or add a zener diode).

If your voltage divider is 50 50, then the 5 volt from the rail will show up on the analog pin as half (2.5v). Readable if using 5v aref, but not readable if using 1.1 volt.

Yes, you can measure any OTHER voltage, but NOT it's own 5volt rail.

Assume you have a 1:1 voltage divider connected to Arduino's 5volt rail.
The regulator is exactly 5volt. Default Aref is also 5volt.
The divider output is 2.5volt, and the A/D converts it to 512 digital.
The code converts 512 to 5.0volt for the display.

If the regulator would drop to 4volt, then Aref would also be 4volt.
The A/D sees 2volts as half of the reference voltage, and converts it to digital 512.
The code converts 512 to 5volt.
Leo..

@Wawa, you are right. I stand corrected.

If the 5volt rail is all he is wanting to read, then you are right, it needs to have a vref lower (1v1 or 2v56).

"It turns out the Arduino 168 and 328 can measure their own voltage rail."

https://code.google.com/p/tinkerit/wiki/SecretVoltmeter

Yes, tried that.

I had to change "result = 1126400L" to "result = 1084800L" to display the right voltage on my UNO.

Problem is that you only can measure one voltage.
Leo..

LarryD:
"It turns out the Arduino 168 and 328 can measure their own voltage rail."

Google Code Archive - Long-term storage for Google Code Project Hosting.

Any Arduino with an internal reference can measure its own Vcc. Just select the internal reference, then use a voltage divider to divide Vcc down to the internal reference range. Some use 1.1V, some 2.56V, some have both and you must specify which one.

@PolyMorph,
Thanks, for confirming. Would you use the 1v1 or the 2v56 ?

I sometimes use the 1.1volt and sometimes the 2.56volt (Mega only).

Say you have to use an LM35 temp sensor.
An LM35 outputs 0-1volt between 0 and 100 degrees C.
Read that with 1.1Aref and you have a scale of ~0-100 with ~0.1 degree resolution.
The limit of the A/D is ~100C.
Use the 2.56Aref, and the limit is the IC's temp limit. But with 2.5x less resolution..

Replace it with a TMP36.
They already output 1volt at 50 degrees C.
Only the 2.56Aref can measure -50C to +200C
Leo..

yes removing the analogReference(INTERNAL1V1)
worked i am getting results that show ok. but the trimpot needs to be turned right down to 2v to show 4.7v

but now i have my readings. but by looking at the code i can't see a way of putting and if statement in as i don't have a value to hold it against
eg the voltage is outputted to the serial monitor
Serial.print(total_1 * 0.00001, 3);

how can i use this as a value to say if the value goes over 4.98v or in that range show an error

below is the working code

void VoltageCheck() {
  analogRead(1); // one unused reading to clear old sh#t
  for (int x = 0; x < 1000; x++) { // 1000 readings
    total_1 = total_1 + analogRead(0); // add each value
  }

  // print to serial monitor
  Serial.print("Raw average = ");
  Serial.print(total_1 * 0.001, 3); // 1000 readings /100, 2 decimal places
  Serial.print(" | ");
//  Serial.print(total_2 * 0.001, 3); // 1000 readings /100, 2 decimal places
  Serial.print("   Input A0 = ");
  Serial.print(total_1 * 0.00001, 3); // convert milivolts to volts, display with 3 decimal places
  Serial.println(" volt");

  //
  delay(1000); // optional readout delay

  
  total_1 = 0; // reset values
}

You should put (INTERNAL1V1) back in, and sort out your voltage divider.

There should be ~0.5volt on the analogue pin. 1/10 of the voltage you measure.

Second line should be "analogRead (0)" if you are using input 0

total_1 holds the voltage value, x10,000.
If you want to do something above 4.98volt, use:

if(total_1 > 498000){
do something
}

Leo..