Implementing the first story

We flesh out the first story and choose some practical quick n dirty solutions to try out.

Lets remind ourselves of the first story:

  1. 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.

stmadc.jpg, Mar 2020picadc.jpg, Mar 2020Transmitting 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). arduino voltmeter.JPG, Mar 2020

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

1. On Saturday, July 16 2022, 16:32 by Russel Yu

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 ;)|

2. On Monday, July 18 2022, 08:34 by Sergio Rutenbar

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.|

3. On Monday, July 18 2022, 18:52 by Joye Nop

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.

4. On Monday, July 18 2022, 20:14 by Isaura Godleski

There's definately a lot to learn about this issue. I like all the points you have made.|

5. On Thursday, July 21 2022, 15:36 by Thanh Toh

Hello, I enjoy reading through your article. I wanted to write a little comment to support you.|

6. On Thursday, July 21 2022, 16:14 by Mariel Dettorre

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.|

7. On Thursday, July 21 2022, 16:18 by Lawerence Lupacchino

I always spent my half an hour to read this blog's articles or reviews all the time along with a cup of coffee.|

8. On Sunday, July 24 2022, 14:36 by Keisha Rozzelle

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.|

9. On Sunday, July 24 2022, 15:16 by Karl Pennison

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.|

10. On Tuesday, July 26 2022, 18:47 by Adeline Hirko

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|

11. On Tuesday, July 26 2022, 19:25 by Emerson Boffa

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.|

12. On Thursday, July 28 2022, 20:46 by Marty

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!|

13. On Tuesday, November 5 2024, 12:20 by paito warna hk 2023

Thanks for sharing your thoughts on artikel.
Regards
https://paitohkwarna.com/

14. On Tuesday, November 5 2024, 13:33 by paito warna sydney

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/

15. On Wednesday, November 6 2024, 12:35 by click this

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.

16. On Sunday, November 10 2024, 22:13 by gksexdolls shop

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.

17. On Monday, November 11 2024, 07:19 by motivation

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

18. On Wednesday, November 13 2024, 17:46 by 7

Ι'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.

19. On Monday, November 18 2024, 05:48 by ดูหนัง av

Ꮃ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.

20. On Monday, November 18 2024, 16:43 by Nottingham escort

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.

21. On Thursday, November 21 2024, 15:21 by sgp paito 2024

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...

22. On Tuesday, November 26 2024, 02:48 by Home Page

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.

23. On Tuesday, November 26 2024, 04:48 by หนังอาร์ญี่ปุ่น

This post ρrovides clear idea for the new people of blogging, that actually how to do running a
blog.

24. On Tuesday, November 26 2024, 08:35 by หนังxxx

Hі there Deaг, are you really visiting this web site
daily, if so after that you will absolutely get nice knoѡledge.

25. On Tuesday, November 26 2024, 20:48 by Proxies For Instagram

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.

26. On Thursday, December 5 2024, 17:04 by Your Quality Pressure Washing Houston

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

27. On Friday, December 6 2024, 10:14 by Proxy Store

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. . . . . .

28. On Monday, December 9 2024, 07:03 by Buy 10000 Proxies

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.

29. On Monday, December 9 2024, 09:03 by 10000 Private Proxies

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.

30. On Saturday, December 14 2024, 22:50 by Buy 10000 Cheap Private Proxies

Rattling instructive and great anatomical structure of content material, now that's user friendly (:.

31. On Sunday, December 15 2024, 16:44 by www

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!!

32. On Tuesday, December 17 2024, 12:39 by here

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.

33. On Thursday, December 19 2024, 12:55 by Buy 10000 Proxies

I want studying and I think this website got some truly useful stuff on it! .

34. On Thursday, December 19 2024, 20:19 by Pressure washer nearby

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.

35. On Friday, December 20 2024, 10:19 by Buy 10000 Cheap Proxies

I like this site its a master peace ! .

36. On Saturday, December 21 2024, 11:39 by Buy 10000 Private Proxies

I believe this site has got very fantastic composed content material blog posts.

37. On Thursday, December 26 2024, 08:08 by หนังอาร์ญี่ปุ่น

Asҝing questions are actually good thing if you
are not understanding anything completely, except this piece of
ѡriting gives pleasant understanding yet.

38. On Friday, December 27 2024, 20:02 by source

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!!

39. On Sunday, January 19 2025, 20:51 by หี

Ι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.

40. On Sunday, March 23 2025, 14:24 by Gutter Installation concord

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.

41. On Tuesday, March 25 2025, 17:07 by Gutter Repair newark

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.

42. On Sunday, April 6 2025, 07:58 by car accident lawyer los angeles county

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!

43. On Thursday, April 10 2025, 15:25 by Chimney Repair harrys county

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!

44. On Thursday, April 10 2025, 16:18 by Car Key Replacement cook county

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!

45. On Saturday, May 10 2025, 08:09 by image editing services

It's going to be finish of mine day, except before end I am
reading this great paragraph to increase my knowledge.

46. On Monday, May 26 2025, 18:22 by clipping path service

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!

47. On Friday, September 19 2025, 23:38 by garage door repair services

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.

Add a comment

HTML code is displayed as text and web addresses are automatically converted.

They posted on the same topic

Trackback URL : https://kisolutionz.co.uk/blog/index.php?trackback/30

This post's comments feed