Implementing the first story
By Irving on Thursday, March 19 2020, 19:24 - Charge Monitor - Permalink
We flesh out the first story and choose some practical quick n dirty solutions to try out.
Lets remind ourselves of the first story:
- As a user I want to measure the battery terminal voltage at 1 sec intervals and store the tuple (time, voltage) on a PC for later processing.
So simply by inspection of the story we know we need some way to measure the voltage at a given time interval and transmit that value, and a count representing the number of time intervals that have passed, to a PC. Measuring the voltage requires an analog to digital converter (ADC). Most analog to digital converters have a limited voltage range at the input, typically 1, 3, or 5 volts. As our battery is nominally 24v and the charging volts could be as high as 28v we need some voltage division at the front end.

Transmitting the voltage reading to the PC most conveniently would be done, these days, by a USB connection. So we need a USB connected ADC, and unsurprisingly such things exist. An example being this one (left). Despite its attractive low price (£6 from China) this solution isn't really viable as it doesn't have any on-board firmware which will allow it to be programmed from the Arduino programming environment (and all the software supplied appears to have a Chinese user interface). Another option is this one (right), which is marketed as a PC oscilloscope for around £20 - 25. It has an extensive suite of software written in Visual Basic, the source code of which is available on request. I quite like this one. Its based on a Microchip PIC microcontroller, is available in both 10 (5v in 5mV steps) and 12 bit (5v in 1mV steps) resolution and has 6 ADC channels. I'll get one ordered very soon. But for now, and for simplicity and speed of creation, I'm going to go with our old friend, the Arduino Uno, which has a built-in 6-channel 10bit ADC with a 5v input.
For those that haven't met the Arduino before, I suggest you scurry over to the Arduino website and have a look at the tutorials. For now I'm going to assume you have some knowledge about the Arduino and programming in general. I'm also going to assume a little knowledge of electronics, at least the basics of voltage, current and resistance.
So here is the diagram of our first trial. It can easily be set-up on a breadboard, some stripboard (Veroboard) or just a free space rats nest. We'll use the Arduino's ADC on channel 0 (hence the connection to the A0 pin).
The core of the front end is the voltage divider comprising resistors R1 - R3. These create a voltage divider with a division ratio between 0.1636 and 0.1695 depending on the actual values of the resistors, the actual ratio required being 0.1666:1. Since the maximum input voltage to the Arduino is 5 volts, this allows for a maximum battery voltage of 5/0.1666 = 30v. The exact division value isn't critical because we will run a calibration procedure as described later, but it needs to be close to get the best result. Too low a ratio and the reading will be off the scale, too high and you lose dynamic range (the abiity to differentiate between two readings). The Arduino ADC, by default, uses its 5v supply as the reference, so ADC readings are returned as relative to the supply voltage. You must use an external power supply and not rely on the USB supply if you want the ADC reading to be remotely accurate as the supply voltage on USB power can be as low as 4.7V and not stable giving inconsistent results.
There are two other components shown, capacitor C1 and diode D1. These are optional but represent good design practice. The connection from our test module to the battery is a length of wire probably at least a metre long. Even if twisted pair is used this will still pick up noise, mains hum and other unwanted signals on top off the ripple and switching spikes from the charger. C1 in conjunction with the resistor network act like a low pass filter. It has little effect on the DC voltage we are measuring but will significantly reduce signals above 10Hz. Diode D1 serves to protect the Arduino against voltage spikes that could come from the charger or the wheelchair. Any voltage arriving at the Arduino will be clamped to the 5v supply, limiting the input voltage at analogue input A0 to a safe 5.6v.
The code for the Arduino couldn't be simpler:
/**************
*
* Simple logging voltmeter. Averages 10 readings and sends the result once per second over USB to PC.
*
* Capture to file on PC using putty, then import into Excel to graph.
*
* Version 1.01 30-03-2020
*
***************/
#define CALIBRATION_FACTOR 30.0
#define SENDS_PER_SEC 1
#define SEND_INTERVAL 1000/SENDS_PER_SEC
#define READS_PER_SEND 10
#define READ_INTERVAL SEND_INTERVAL/READS_PER_SEND
int voltagePin = A0; // select the input pin for the voltage measurement
long timeValue = 0; // variable to store the time count
float voltageValue = 0; // variable to store the battery voltage
int analogValue = 0; // raw ADC reading
int loopCount = 0; // counter for averages
long timeNow = 0; //time counters
long timeLastRead = 0;
long timeLastSent = 0;
void setup() {
Serial.begin(115200);
while (!Serial); // wait for the serial port
timeLastRead = millis(); // start timing
timeLastSent = timeLastRead;
}
void loop() {
timeNow = millis();
if( timeNow = timeLastRead + READ_INTERVAL) {
timeLastRead = timeNow;
// acquire the voltage
analogValue += analogRead(voltagePin); // read the ADC and accumulate
loopCount += 1; // increment count of reads. added 30/03/20
}
if( timeNow = timeLastSent + SEND_INTERVAL) {
timeLastSent = timeNow;
voltageValue = (analogValue * CALIBRATION_FACTOR)/(1024.0 * loopCount); // convert to average volts. modified to use loopCount 30/03/20
// print time & voltage tuple as "[ time, voltage ]
Serial.print("[ "); Serial.print(timeValue);
Serial.print(", "); Serial.print(voltageValue); Serial.println(" ]");
analogValue = 0; // reset accumulator
loopCount = 0; // reset loopCount. added 30/03/20
timeValue += SEND_INTERVAL; // increment time counter
}
}
The calibration procedure is very simple too. The purpose here is to adjust the calibration constant to take account of errors in the voltage divider and the actual ADC reference voltage. Connect up the battery and measure the voltage between R1 & ground (ideally with a good 4-digit, 6000 count multimeter), and call this v1. Now run the program, open the serial monitor, and see what voltage is reported. This is averaged over 10 reads so should be reasonably stable, but if it varies take a further average, and call this v2. Divide v2/v1 and multiply by 30. The result is the calibration constant to use in place of the value 30.0 in the program, so adjust the line containing "#define CALIBRATION_CONSTANT" to suit.
In the next blog I'll deal with Story 2, measuring the current.
Comments
I'd like to thank you for the efforts you've put in writing this site. I am hoping to view the same high-grade content from you later on as well. In truth, your creative writing abilities has motivated me to get my own website now ;)|
It is not my first time to pay a visit this website, i am browsing this web page dailly and take pleasant information from here daily.|
Hi there, I discovered your blog via Google even as searching for a similar matter, your website got here up, it appears to be like great. I've bookmarked it in my google bookmarks.
There's definately a lot to learn about this issue. I like all the points you have made.|
Hello, I enjoy reading through your article. I wanted to write a little comment to support you.|
I am no longer positive the place you are getting your info, however great topic. I needs to spend some time studying much more or working out more. Thanks for magnificent information I was in search of this information for my mission.|
I always spent my half an hour to read this blog's articles or reviews all the time along with a cup of coffee.|
I am now not sure where you're getting your info, however great topic. I needs to spend a while learning much more or understanding more. Thank you for fantastic info I was searching for this info for my mission.|
Every weekend i used to go to see this web page, for the reason that i wish for enjoyment, as this this web site conations genuinely nice funny information too.|
Magnificent beat ! I wish to apprentice even as you amend your site, how can i subscribe for a weblog website? The account helped me a appropriate deal. I had been a little bit acquainted of this your broadcast offered brilliant transparent concept|
I'm amazed, I have to admit. Rarely do I encounter a blog that's equally educative and amusing, and without a doubt, you've hit the nail on the head. The problem is something not enough men and women are speaking intelligently about. I'm very happy I found this in my hunt for something regarding this.|
Pretty great post. I just stumbled upon your weblog and wished to mention that I have really enjoyed surfing around your weblog posts. In any case I will be subscribing on your feed and I'm hoping you write once more very soon!|
Thanks for sharing your thoughts on artikel.
Regards
https://paitohkwarna.com/
I want to to thank you for this fantastic read!!
I definitely enjoyed every little bit of it.
I have got you bookmarked to look at new stuff you post…
https://paitosydneywarna.com/
Howdy I am so grateful I found your weblog, I really found you by accident, while I
was browsing on Google for something else, Nonetheless I am
here now and would just like to say kudos for a remarkable post and a all round thrilling blog (I also love the theme/design), I don't have time to read through it all
at the minute but I have book-marked it and also added your RSS feeds, so when I have time I will be back
to read a great deal more, Please do keep up the superb work.
Do you have a spam problem on this website; I also am a blogger, and I was curious about your situation; we have developed some nice procedures
and we are looking to swap techniques with other folks, why not shoot me an email if interested.
It's nearly impossible to find educated people on this topic, but you
sound like you know what you're talking about!
Thanks
https://smkmuh1-lamongan.sch.id
https://duamata.com
https://berita.unisla.ac.id
https://unisla.ac.id
Ι'm not sure why but thiѕ weƅlog is lⲟading very slow for me.
Is anyone else having this problem or is it a issue on my end?
I'll check back later and see if the problem stiⅼl exists.
Ꮃhen some one searches for һis necessary thing, thus
he/ѕhe wants to be ɑvailable that in detɑil, therefore that
thing is maintained over here.
Normally I do not read article on blogs, but I wish to say that this write-up very
compelled me to check out and do so! Your writing style has been amazed me.
Thanks, quite nice post.
obviously like your web-site however you need to
test the spelling on quite a few of your posts.
A number of them are rife with spelling issues
and I to find it very troublesome to inform the reality on the other hand I will
definitely come back again.
https://quickcliplink.com/go/paitos...
Hmm it looks like your blog ate my first comment
(it was extremely long) so I guess I'll just sum it up
what I wrote and say, I'm thoroughly enjoying your blog. I as well am an aspiring blog blogger but I'm still new to everything.
Do you have any recommendations for inexperienced blog writers?
I'd definitely appreciate it.
This post ρrovides clear idea for the new people of blogging, that actually how to do running a
blog.
Hі there Deaг, are you really visiting this web site
daily, if so after that you will absolutely get nice knoѡledge.
Aw, this was a very nice post. In concept I wish to put in writing like this additionally – taking time and precise effort to make an excellent article… but what can I say… I procrastinate alot and not at all appear to get something done.
Wonderful beat ! I wish to apprentice whilst you amend your site, how can i subscribe for a blog website?
The account helped me a acceptable deal. I were tiny bit
familiar of this your broadcast offered vibrant transparent concept
Hiya very nice site!! Guy .. Beautiful .. Amazing .. I will bookmark your site and take the feeds also…I'm happy to seek out numerous useful information right here in the post, we need work out extra strategies in this regard, thank you for sharing. . . . . .
Spot on with this write-up, I actually assume this website needs rather more consideration. I’ll in all probability be once more to read far more, thanks for that info.
Good post. I learn something more challenging on totally different blogs everyday. It can always be stimulating to read content from other writers and observe somewhat something from their store. I’d choose to make use of some with the content on my weblog whether or not you don’t mind. Natually I’ll provide you with a link in your net blog. Thanks for sharing.
Rattling instructive and great anatomical structure of content material, now that's user friendly (:.
Hello, i feel that i noticed you visited my blog thus i
got here to return the choose?.I'm attempting to find issues to improve my web site!I suppose its good enough to use
some of your ideas!!
Hi there all, here every one is sharing such knowledge, thus it's pleasant to read this blog, and I used to pay a
quick visit this website everyday.
I want studying and I think this website got some truly useful stuff on it! .
What's up to all, it's really a fastidious
for me to pay a quick visit this web site, it consists of helpful Information.
I like this site its a master peace ! .
I believe this site has got very fantastic composed content material blog posts.
Asҝing questions are actually good thing if you
are not understanding anything completely, except this piece of
ѡriting gives pleasant understanding yet.
Hello, i believe that i saw you visited my site so i came to return the favor?.I am trying to find things to enhance my web site!I suppose its good enough
to use some of your concepts!!
Ιt's really a cool and usefuⅼ pіece of info. І am happy that you just shared this useful info
with us. Please stay us up to date like this. Thanks
for sharing.
I love what you guys are usually up too. This kind of
clever work and exposure! Keep up the terrific works guys I've included you guys to blogroll.
Hi there it's me, I am also visiting this site daily, this site is truly fastidious
and the people are really sharing pleasant thoughts.
Hey there would you mind sharing which blog platform you're working with?
I'm planning to start my own blog soon but I'm having a difficult time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
The reason I ask is because your layout seems different then most blogs and I'm looking for
something completely unique. P.S Apologies
for getting off-topic but I had to ask!
Hi, I think your website might be having browser compatibility issues.
When I look at your website in Safari, it looks fine but when opening in Internet Explorer, it has
some overlapping. I just wanted to give you a
quick heads up! Other then that, great blog!
This is very interesting, You're a very skilled blogger.
I've joined your rss feed and look forward to seeking more of your magnificent post.
Also, I've shared your website in my social networks!
It's going to be finish of mine day, except before end I am
reading this great paragraph to increase my knowledge.
Hello would you mind stating which blog platform you're using?
I'm looking to start my own blog in the near future but I'm having a hard time making
a decision between BlogEngine/Wordpress/B2evolution and Drupal.
The reason I ask is because your layout seems different then most blogs and I'm looking for something completely
unique. P.S My apologies for getting off-topic
but I had to ask!
Your style is really unique in comparison to other
people I've read stuff from. Many thanks for posting when you have the opportunity,
Guess I'll just book mark this web site.