im trying to follow these instructions to the following code to keep a check on incoming voltages
and before i took delivery of my capacitor's i tried it without. And i was able to trim the voltage so i got a correct reading.
But with the capacitor now in the voltage stays the same no matter what i do the the trimpot. is this correct?
i was testing the output with a multimeter from the yellow middle cable
and what is the capacitor doing?
// displays the voltage of a battery/supply/USB/Vin/etc. on the serial monitor and/or LCD shield
// works with 3.3volt and 5volt Arduinos
// uses the internal 1.1volt reference > independent of supply fluctuations
// max readout is 10.230volt, 0.001volt resolution, last digit is averaged
//
// ~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: connect a 9volt battery and a DMM, adjust trimpot to the same reading
//
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // your LCD pins could be different
unsigned long total;
//
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---
lcd.begin(16,2); // shield with 2x16 characters
lcd.setCursor(0,0); // first row
lcd.print("Voltmeter"); //info text
lcd.setCursor(0,1); // second row
lcd.print("0-10.230 volt");
delay(2000); // info display time
lcd.clear(); // clear
lcd.setCursor(0,0);
lcd.print("Voltmeter 0-10V"); // print once
}
//
void loop() {
analogRead(1); // one unused reading to clear old sh#t
for (int x = 0; x < 1000; x++){ // 1000 readings
total = total + analogRead(1); // add each value
}
// print to LCD
lcd.setCursor(0,1);
if(total == 1023000){ // max A/D reading * 1000
lcd.print("----overflow----");
}
else{
lcd.print("A1= ");
lcd.print(total*0.00001, 3); // convert milivolts to volts, display with 3 decimal places
lcd.print("volt");
}
// print to serial monitor
Serial.print("Raw average = ");
Serial.print(total*0.001, 3); // 1000 readings /100, 2 decimal places
if(total == 1023000){
Serial.print(" ----overflow----");
}
else{
Serial.print(" Analogue input A1 = ");
Serial.print(total*0.00001, 3); // convert milivolts to volts, display with 3 decimal places
Serial.println(" volt");
}
delay(1000); // optional readout delay
total = 0; // reset value
}
The 10k resistor needs to go from A1 to ground and the capacitor needs to go from A1 to ground. That means the capacitor should be in parallel with the resistor, not in series.
i don't seem to be getting any readings from the analog inputs
(quick edit) im using an mega 2560
im trying
void VoltageCheck() {
// read the input on analog pin 1:
int sensorValue = analogRead(A1);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (4.8 / 1023);
if (voltage > 50.9) {
Serial.println("5v Too High");
Serial.print("5 Volt Supply = ");
Serial.println(voltage);
//digitalWrite(ledred, HIGH);
} else {
// print out the value you read:
Serial.print("5 Volt Supply = ");
Serial.println(voltage);
}
}
the code is just reading input values and i have tried inputting the board 3v and 5v and also an external 5V supply but ithe values do not change on A1
mikewitney:
i did think that but it didn't mean sense to me not being being an electronics expert.
but i will give it a go and see what i get
Capacitors do not conduct DC current, so if placed in series with a resistor there will be no DC current through the resistor.
I've just spotted in your photo that the other resistor looks like 820Ω, not 82kΩ.
Is the wiper of your trimpot potentiometer on the breadboard's row 9? The connection to Arduino's A1 input is supposed to be from one end of the 10kΩ resistor. From what I can work out from your photo: A1 should go to breadboard row 8 and a wire link should go from row 9 to row 10 to make the trimpot act as a variable resistor, not as a potentiometer (or just connect the 82kΩ resistor to the wiper).
Start with connecting two wires between Arduino and the breadboard.
Arduino ground to any pin on the -blue side rail.
And Arduino pin A1 to e.g. row 10 on the breadboard
Connect the 10k resistor from row 10 to the ground (blue) rail.
Also connect the cap from row 10 to the ground rail.
Plug the trimpot into 9, 10, 11
Connect a 82k resistor (grey, red, orange) from row 11 to the + (red) row.
Only two pins of the trimpot are used.
Now connect a wire between the +row and anything you want to measure.
e.g. the 3.3volt pin or the 5volt pin or the Vin pin.
Disconnect that last wire if you want to measure e.g. a 9volt battery.
Connect the battery to +rail and -rail of the breadboard
Leo..
How do you have the hardware hooked to the analog pin?
Using a VOM, what voltage do you read on that analog pin?
Did you mean "if (voltage > 50.9)" or did you mean "if (voltage > 4.7)"? Since I don't think your calculations can give a result over 4.8. I may have read that wrong.
Is your output saying "5 Volt Supply = 0.0" ?
In your script (for debugging) display the reading you get from the analog read (before any calculations).
jremington: if (voltage > 50.9)In the code you've posted, this can never be true.
In addition, you will damage the analog input if the voltage exceeds 5.0 V.
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
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);
}
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
"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.