Hello all,
Me and a group of friends decided to enter the field of EVs, so we started off with the battery pack.
I've used Arduino before and applied the digital pins and PWM as well into my small projects. But challenges kept appearing every time I used the analog pins.
I need your help measuring Voltage. I'm basically trying to charge just one 18650 Li-ION cell, through the CC-CV method.
First, I took the Arduino Mega and wrote this:
x = analogRead(2) ;
Serial.println(x);
I got vague values as expected, since the pin value floats around thanks to the noise and everything else it picks up.
To solve this I connected a resistor of 10k to ground to the pin. This pulled the pin down and the result I got was a constant 0.
Then I connected an PWM pin 9 to the analog Pin. This code was added to it:
x = analogRead(2) ;
Serial.println(x);
analogWrite(9,255);
At 255 I measured using a voltmeter, a voltage of 4.98V, which I assume the Mega uses as a reference voltage. At the same time, the analog pin was giving out 1021 to 1022 as a readout.
Then I changed the above code to:
x = analogRead(2) ;
Serial.println(x);
analogWrite(9,150);
At 150, the voltmeter on pin 9 measured 2.88, which was the expected value. But the analog Pin, showed 980 to 984 on the readout.
Calculating that, I'm not getting the right value which is around 592 to 595.
How can one calculate the accurate Voltage value. Any ideas peeps ?
Can you draw a schematic of what you tried to do?
I notice you made no mention of gnd connections.
If you want to measure voltages and output control voltages you must use gnd as reference.
Hello,
Thanks Tom & Bill for helping.
Well Tom, I'm only connecting my PWM pin to an analog pin on the board and trying to read my PWM voltage on the analog pin. This returned vague values, hence the doubt.
Bill, I now know that the capacitor basically filters the peaks, so that I have a smoother wave form. My question now is, this PWM signal will be input to a BD139 transistor to control higher voltages and currents. Will the RC filter make a significant difference of voltage through the transistor ?. Since I'm charging the 18650, I'll require quite a precise voltage output ?
vikramnayak:
I'm only connecting my PWM pin to an analog pin on the board and trying to read my PWM voltage on the analog pin.
PWM is NOT a voltage. It's a digital signal (on/off, 0volt/5volt).
The on/off times are varied.
A DMM averages, so it appears to be constant.
The analogue input takes short samples.
It might be during a high or during a low, so you will get random values.
The circuit that BillHo posted smooths the PWM into a fairly constant voltage.
That can be measured by the analogue input.
Any cap (1-10uF) can be used.
It might not be a wise to use this voltage and a BD139 to charge a LiPo battery.
There are special chips to do this safely.
Leo..