Hi mates,
please help me,
I have a project to make a small charger with arduino,
im just read analog voltage from analog pin, and I print the sensor value, and compare with 3 batterys.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
lcd.setCursor(0,0); // set kursor ke kolom 1, baris 1
lcd.print("Reading voltage"); //print read voltage
lcd.setCursor(0,1); // set kursor ke kolom 1, baris 1
lcd.print("v = "); //print v
lcd.setCursor(11,1); // set kursor ke kolom 1, baris 10
lcd.print(" volt"); // print volt
}
void loop()
{
int sensorValue = analogRead(A1);
float voltage = sensorValue * (5.0 / 1023.0);
lcd.setCursor(5,1);
lcd.print(voltage);
delay(500);
}
an error during test is, the voltage was incorrect
when I chek with print the sensor value
lcd.print(sensorValue);
sensor value alway keep the 3 last digit to last value
example :
read ADC is = 1023
i disconnect the battrey lcd still 0023
when 2nd battrey conect ADC read = 5902
then i disconnect the battrey lcd still 0902
3th battrey conneted ADC read = 7402
then i disconnect the battrey lcd say 0402
when i print
lcd.print(voltage);
only the first reading was correct, and another not
please help me
any help will be much appreciated in advance
Thanks guys
Without knowing how you wired the circuit, I can only ask.
The voltage that you apply to the pin never exceeds 5.5 V?
The voltage that you apply to the pin also has a wire to a resistor 10 K or more and then to ground?
Because without flow, voltage builds as the capacity of the wire itself fills and the read will be high.
But 1023 is the highest analog read so perhaps you are reading an added total or your Arduino is a Due
or Yun? I am pretty sure that the Due has 12 or 13 bit ADC(s).
Hi, the problem is when you print the sensorvalue on the LCD you are overwriting the previous value you have loaded to it, so if you have a three digit number displayed and then you overwrite a two digit, the digit not overwritten stays on the display.
The simplest solution is on the line immediately before you print the new value, you print a group of spaces to blank out the old digit.
Tom.......
You do have other problems, but not enough time tonight to help I'm afraid.
try
float voltage = ( float sensorValue * 5.0 )/ 1023.0;
GoForSmoke:
Without knowing how you wired the circuit, I can only ask.
The voltage that you apply to the pin never exceeds 5.5 V?
The voltage that you apply to the pin also has a wire to a resistor 10 K or more and then to ground?
Because without flow, voltage builds as the capacity of the wire itself fills and the read will be high.
But 1023 is the highest analog read so perhaps you are reading an added total or your Arduino is a Due
or Yun? I am pretty sure that the Due has 12 or 13 bit ADC(s).
Yes I have to read 9 volt battery with arduio that have maximum voltage to measure is 5 V, so i use voltage divider with 2 resistor that have same resistant, so I will have half voltage to measure.
so, how can I read 9 volt with arduino?
Thanks for helping me
If your reading is less than 1000, print a leading space, if your reading is less than 100 print a leading space and if your reading is less than ten . . . is left as an exercise for the reader.
To read 9v you need a resistor divider (2 resistors) which lowers the voltage.
Yes sure. But it's not work and I do it from the first time. The sensor was give me incorrect measure that I described in the first post. That's why I ask another way..
so, how can I read 9 volt with arduino?
Thanks for helping me
Put two 10K resistors, in series across the 9 volt battery. Then route the junction of the resistors to an analog pin.
Connect the - battery terminal to Arduino Ground.
That will give you 4.5 volts at the pin, give or take a few 1/10ths.
To read 9v you need a resistor divider (2 resistors) which lowers the voltage.
Yes sure. But it's not work and I do it from the first time. The sensor was give me incorrect measure that I described in the first post. That's why I ask another way..
What you described in the first post didn't look to me like a bad reading, just a bad presentation of a valid reading.
See my earlier post.
but when i connect the 1st battrey its get 1023
the 2nd battrey was 5878
then 3rd battrey was 9688
and then i connect 2nd battrey first it get 685 (correct measure)
then i connect 1st batrey i et 6890
the second measurement always incorrect due to 3 digit not change in the ADC
not the displaying problem, like print some blank words to avoid it.
but incorrect 2nd measurement due to incorrect ADC last digit not change.
May be a clue?
The arduino only has one ADC and if you're reading two analog pins back to back the reading from one can influence the other. One way to deal with this is to read each pin twice but ignore the first value you get.