Skip to main content

Rather than continuing on in the other threads where this has been being discussed I thought it might be worthwhile to start a new topic specific to using Arduino for panel meters.

The premise here is to use an Arduino micro-controller, LED/LCD displays, and Hall-Effect current sensing modules to build a set of highly accurate panel meters to monitor the voltage and current of each output on a transformer.  I'm planing on 4 channels at this time, but the design is expandable for many more if needed.  

I'm also planning to add some extra features, some of which are quite useful, and others that ate neat, but not really so useful.  The primary added feature is high speed, programable circuit protection.  Because we already will have a micro-controller monitoring both instantaneous current and voltage, as well as RMS current and voltage, it should be fairly simple to use that information to shut off track power if current rises too high.  What this current limit is could be adjustable by the user, and could also be programed in steps, allowing say 1 amp over current for 10 seconds, 2 amps over for 5 seconds, 3 amps over for 2 seconds, etc until at maybe 5 amps over the set level power would be instantly shut off.

As a clarification of terms, when I use the term instant here, I mean within the realm of the limitations of the speed of the electronics and the mechanical limitations of whatever device is used to disrupt the flow of power.  In effect this is likely to be in the realm of 15-30 milliseconds, competitive with the fastest acting breakers on the market today for electric trains.  When I have a working prototype I'll have to test to see just how fast the device responds.  

At this point key features I'm planing on are:

True RMS voltage displays with 1/20th volt resolution (0.05V).(edited typo here)

True RMS Current (Amps) displays with 1/20th Amp resolution (0.05A).

At least 1/10th second refresh times on the displays, with a user adjustment for preferred refresh speed.  (ex. some folks may not like seeing the numbers jumping about so quickly and may prefer slower changes. )

Programable, adjustable electronic circuit breakers for each channel.

Real time line frequency adaptability.  (See Note #1 below for why and how this matters, in a huge block of useless text) In effect this will provide extremely accurate readings from the meters as well as the ability for the meters to operate on any power grid or source, as well as being operational with DC power.

LED and/or LCD displays for RMS voltage and RMS current, peak voltage and peak current( over, say, the last 30 seconds?), possibly an indication of any DC offset on the signal, and if I can figure out how to do so, a warning that a high voltage spike has been detected.  

I'd like to hear what other features might be desired in this project from other folks so I can see if they could be worked in.  Also, do folks prefer simple on/off circuit breakers that could be handled with a relay, or would it be worthwhile to investigate designing a fold-back system that will lower voltage to limit current?  

 

The actual parts I'm planning on using are all fairly inexpensive and readily available shipped from China.  ACS712 Hall effect modules will be used for current sensing.  These will provide 1/20th Amp sensitivity up to 30 amps, and should not be damaged by less than 50 amps. For voltage measurement I'm planning on using a bridge rectifier to feed a voltage divider made of two resistors.  This will convert the AC track voltages into a 0 - 5 VDC level that can be read by an Arduino.  If my math is correct we should be able to read RMS pure sine wave voltages up to about 36 volts with 1/20th volt resolution.  I plan on using a zener diode to clamp excess voltage from damaging the Arduino.  

To provide the most accurate measurements, it may be that I will have to use several Arduinos linked together.  Once I have parts I'll be able to test things to see if a single processor will be fast enough to take all the measurements and process data for the displays.  if it is not, I plan to use a separate processor for each channel that will report data to a master controller.  This method costs less but is more complex than the alternative, which is to use something like an Arduino Due which has an 84MHz CPU, as opposed to the 16MHz found on the less expensive boards.  The Due has it's own issues, the biggest one for me being that it requires 3.3V logic levels as opposed to the 5v logic used on other boards.  Another option may be to use Raspberry Pi instead of Arduino, but I have only a limited understanding of RPi.  

In the end, mu goal is to use the most cost effective route that will provide exceptionally accurate results.  I think there are already plenty of great products out there for mediocre accuracy, and don't see much point in reinventing the wheel if it will not bring something better to the table.  Here in the planning stage it looks like I'll be needing around $30 in parts to provide the desired features, however if a single, faster microprocessor ends up being needed it will quickly double that price.  This also does not include a case of any sort or fuses/holders that I'd like to install as a fail-safe.  

 

Anyway, lets see what we can come up with here, let the comments commence!

JGL

 

Note #1:  When measuring for True RMS the frequency of the AC matters.  in the US we typically have a 60Hz line frequency, however in other parts of the world 50Hz is standard.  Further more, there are slight fluctuations in this frequency throughout the day, often being fractionally less than 60Hz at peak power consumption times of the day and fractionally above 60Hz through the night when there is less power consumed from the grid.  Power grids in the US follow a rule that they must average out the number of cycles in a full day, but do not care about the exact line frequency in any given second or minute.  While there have been some tests to see what effect it will have by changing, at the moment, the US power grid provides exactly 5.184,000 cycles every day.  This is done so that devices such as clocks and timers that depend on line frequency will keep accurate time.  

In the case of measuring for true RMS to get a truly accurate reading you need to measure an absolutely exact amount of time equal one full wave period, or a multiple there of, ex: 2 waves, or 5, or 10.  Because of this I'm planning on  measuring the frequency of current so that accurate measurements can be taken.  I do not know if this level of accuracy has any need for layout meters, but the difficulty in programing will be similar just to allow for automatic adjustment for 50Hz or 60Hz grids, so I may as well see how it works in real time.  I think that it may prove too taxing on the processor to check frequency too often, but it should be little trouble to update every 60 seconds or so.  If that doesn't work out I'll simply have a single check at start up.  

 

Last edited by JohnGaltLine
Original Post

Replies sorted oldest to newest

JGL, 

First off thanks for creating this thread and I look forward to learning and sharing ideas. I have read your above post, but I think I will have to read it again to try to understand the electrical portion. 

I would like to add the following to what you said. You mentioned a larger microprocessor as needed or the Raspberry PI. Why not use an Arduino Mega if you need to go larger? Also, I think that you can use a Raspberry PI as needed too and would be very easy to learn in my opinion. A lot of people typically program in python for Raspberry PI, but you can also use C to match the Arduino if you are sending data back and forth. Check out wiring pi, which is the wire library used on Arduino for Raspberry Pi. Here is the website, http://wiringpi.com/. Raspberry PI can also be setup for I2C. 

This also maybe a dumb question, but why not use a voltage sensor in lieu of the divider? I have seen the voltage sensor on-line today. Maybe it is me because I'm just learning the in depth electrical stuff, but I find that it would be neater to have the voltage divider on a PCB board. 

Chris 

Crood58, What i mean by larger is not the typical problem with needing more I/O pins, but that the processor may be too slow to keep up with reading all the sensors, do floating point math, and keep the displays updated.    All of the common Arduinos (Uno, Nano, Mega2560, 5v ProMini) have 16MHz processors.  Now this really is very fast, but a number of libraries place a high overhead on the processor, so I'm going to have to test things.  One of the biggest CPU hogs I've run into is the serial library, which really sucks when trying to debug code.  

As for the voltage modules, the one's i've seen don't really look like a good deal to me, and they don't offer any over-voltage protection for the Arduino.  With the ACS712 modules, the modules cost less than $2 each and an actual ACS712 chip alone costs over $4.  Chinese economics at work.  For the voltage sensors you're paying 75 cents for a penny worth of resistors, and still need to add the clamping diode to protect the arduino,and a rectifier to convert the AC to DC.  

I'm expecting that I'll have to put together some sort of 'mother board' to connect everything together where I can install various modules and discrete components.  For folks that may be adverse to soldering, I've also had good luck in the past using solder-less breadboards, then pouring wax over the breadboard to hold everything in place when finished.  With as cheap as breadboards have gotten this may be the way to go.  

JGL

Short answer:  

ToTrainYard, I actually do appreciate the caution, and expect that a full battery of testing will be in order to insure everything works as expected, however when it comes to component level electronics and mass produced modules,  you can take the quote from the movie Armageddon to heart:  

Lev Andropov:  "It's stuck, yes? "
Watts:  "Back off! You don't know the components! "
Lev Andropov: [annoyed] "Components. American components, Russian Components, ALL MADE IN TAIWAN!"

Long answer:  

To date I have never had counterfeit parts shipped, however there have been reports of such things happening.  From what I can tell these counterfeit parts tend to be duds right out of the package.  On occasion similar parts from different manufactures are shipped, but these often say as much in the listings.  Such similar parts are usually interchangeable.    Listings show part numbers and data sheets are available for those exact parts so that you can see what differences exist between one manufacturer and another.  

All in all I'm unsure what parts there is concern over here.  The various chips at use in arduino boards are proven reliable, whether based on the ATmega2560, ATmega328, or the old stand-by ATmega168.  The ACS712 is the industry standard hall effect current sensor, and all else that has been discussed are basic components that are the same everywhere and in everything.  The only part I'd have any concern over is a relay used for disconnecting track power.  This will take some research to find out if the sort used on the relay modules have any sort of issues with contact welding or arcing under currents below their max ratings.  

In general parts meet the specs given.  They can often out-perform those ratings, but it is not usually the case that they under-perform.  I did mention, as well, the intention to use glass fuses in the event of a catastrophic failure of the electronics.  I expect these fuses to never blow, however as the processor would report a failure of any crucial part and go into a fail-safe mode, refusing to apply power to the track.  

In all honestly I have no concern about the quality of the parts, or at least no more concern than with the parts in any other electronic device.  I would take it as a prerequisite that anyone following along would know enough of what they are doing not to blow anything up, and not to power an expensive train until they are sure it works, but I just don't really see a cause for concern with this project, or with anyone experimenting and designing their own circuits.  

JGL

I'm very interested in over current protection, as I have damaged my fair share of electronics. I'm currently using polyfuses, but I think they're too slow to cut power. I would love to see a fairly inexpensive way sense over current and simply drop out a relay, much the way the old TMCC lockon did. I need quantity, something like 70 units.

totrainyard posted:

Remember a chain is only as strong as it's weakest link.

Bargain parts from Asia and home made circuits are not the best protection for expensive model trains.

I have destroyed many toys with bargain parts.

Sometimes it pays to pay "retail".

I have 40 years of making, fixing and breaking electronics.

No offense, but all your fancy electronic trains are using parts from China, where they are also made!  Most of your other consumer electronics are also using parts from China, and probably made there as well.

As far as "home made" circuits, what makes you think you can't engineer something at home to the same level as stuff made in some "factory".  In many cases, the corners cut to save a component or two, or to shave the price a few cents on production, results in an inferior product.

I spent over 40 years designing electronics, including many products used in high-reliability applications.  Much of my career was in Aerospace designing cockpit instrumentation and fuel systems for commercial and military aircraft.  I think I have a pretty good handle on how the stuff on the other side of the wall is designed and built.

This is truly a non-issue.

John, one option that might be interesting is an analog display with the digital display below it.  You'd have to reconsider the display technology, but in many cases the analog response to change is a lot more useful.  Many displays in cockpits are displayed in analog fashion for that reason.  Many multi-meters have the analog display bar at the bottom so you can see what's happening when the digital display is changing too fast to read.

I know, I'm making it complicated!

The inexpensive relay modules that are available in everything from one channel to sixteen channels would be a good match for this project.  Here's a four channel one with optical isolation and 10 amp relays for $2.69 shipped free, there are many more examples.

Attachments

Images (1)
  • blobid0

True RMS voltage displays with 1/20th volt resolution (0.05A).

This is a bit more complex than it appears if you are also looking for that order of accuracy.

Depending on how you rectify the AC, you will have a fixed voltage drop due to the rectifiers, which will need to be part of the RMS calculation. Not insurmountable, but if you start with a 1.2 volt drop on a 12 volt signal.... Unfortunately, in the true RMS world, you can't just add the offset at the end. There are ways to allow for it, but in any case you lose all the voltage data below the level of the diode drop, compromising accuracy.

You could design a perfect rectifier using an op amp with a diode in the feedback loop; this is quite well documented in the literature. A quad op amp of almost any sort would probably do. Or, you could use low-drop diodes of some type, or forward-bias plain old silicon.

To your credit, you are learning why low-cost readouts, free multimeters and model train transformer displays seldom agree. They just ignore all the fine points and wing it!

Last edited by PLCProf

Gentlemen,

   IMO you are trying to over Engineer this safety problem for you train layouts.  I have never damaged any of my P2 or Legacy Engines when using the 7-10 Amps Scott type Breakers and the TVS in the DCS-TIU.  So far they have provided me with all the safety required on my layouts.  Now the newer LC & LC+ I am going to use the 5 Amp Breakers on, however this might be slightly over safety protected we will see.

PCRR/Dave

PLCProf posted:

You could design a perfect rectifier using an op amp with a diode in the feedback loop; this is quite well documented in the literature. A quad op amp of almost any sort would probably do. Or, you could use low-drop diodes of some type, or forward-bias plain old silicon.

I was going to comment on the same thing, the diodes are going to be a problem.  I like the idea of the active circuit solution.

Eliot,  I think if you eliminate the display portion and are only concerned with the circuit breaker portion, you could build banks of 8 breakers for about $25.  This would assume that each one is set to trip at the same level, and a max instant cut off less than 10 Amps.  Still need to wait for parts to get here and do some tests, but it seems workable at this point.  

GRJ, Complicated is good!  At this stage I think it is advantageous to dump every possible idea in the mix, then see if anything has to be scratched off the list later. I like the idea of a visual, non-numeric display to show quickly changing readings.  It may be that instead of a simple LED or character LCD that a dot-matrix LCD would be in order that would allow for 'graphics'.  I've never worked with one of those, however, so will need to learn what is involved.  Another option might be a simple bar-graph LED.  

The relay module you posted is exactly what I had in mind at the start, but for main track power I don't think 10 Amp rated contacts will be enough.  I need to do my homework here, but I think I'm going to look into a 30-50 amp relay.  

PLCPROF, good thinking here.  My brain works in the world of DC, and didn't really think this one through.  I suppose I could limit the problem a bit by using schottky diodes, but it still wouldn't be entirely accurate .  Going to have to look into the Op-Amp method or see what else exists if we want truly accurate readings.  

Dave, I understand the idea of over thinking it.  The thing is the circuit breakers here are an afterthought.  The idea is for volt and amp meters, and it just so happens that once that part is built, you may as well add circuit breakers that should be competitive with anything else on the market for speed, for the cost of a relay (and transistor and opto-coupler, etc.).  

JGL

The relay modules are so cheap that you can pick on to your specifications.  Personally, I think 10A is all I'd ever want, I don't believe in putting more than 10A on the tracks.  For the relay option, I'd just provide logic outputs that would hold the relays energized and release them for over-current.  This allows you to hang whatever capacity relay you think you need to do the switching.

You could also use something like this, I have a few of these in my parts drawers.  They handle 25 amps and would certainly be fast switching.  They switched 18V just fine, there's about a 1V drop through the switch, not too significant.  $2.88 on eBay: 331822808867

New-SSR-25-DA-Solid-State-Relay-Input-3-32V-DC-Output-25A-24V-380V-AC-Switching

Last edited by gunrunnerjohn
JohnGaltLine posted:

 

The relay module you posted is exactly what I had in mind at the start, but for main track power I don't think 10 Amp rated contacts will be enough.  I need to do my homework here, but I think I'm going to look into a 30-50 amp relay.  

 

I wouldn't hesitate at all to use a 10 amp relay module. Look at the relay in the highly-praised PH-180, it is certainly no better than the typical Chinese module relay. If you still feel the need to go bigger, use two module relays in parallel, that will definitely switch faster than a 30 or 50 ampere relay. An 8 channel module would give you four 20 amp circuits!

 

GRJ, I'm not picking on those relay modules, I think they are absolutely fantastic!  The thing with current is that if i'm looking to match what I think of as the industry standard, the PH180, I need to handle 10 amps all day long, and have a sliding scale up to about 17 amps for instant cut off.  

Ad a note, just looking at the picture, that SSrelay is only rated for DC, which I think is the case for many of them.  If I do the solid state route, I think I'll opt for a triac or FET.

PLCPROF, I hope the relay in the PH180 is rated for more than 10 amps.  Am I remembering correctly that you tested the breaker on one to determine the sliding scale they use?  

As for putting two in parallel, I thought of this, but it has the problem that the relays may not break contact at the exact same instant, and if they do not, one relay is carrying the full load for a fraction of a second still.  If I could find a module with double pole relays this would be more of a solution.  

 

At this point I think I'm going to go forward with the cheap relay modules and a 10 amp maximum peak rating on the device, and perhaps leave connection points for a larger relay for those that need one.  

JGL

JohnGaltLine posted:

Ad a note, just looking at the picture, that SSrelay is only rated for DC, which I think is the case for many of them.  If I do the solid state route, I think I'll opt for a triac or FET.

HUH?  How do you figure that?  It worked fine being powered with a PH180 brick, pretty sure that's A/C.   In truth, many of the solid state relays handle AC, including this one.

Attachments

Images (1)
  • blobid0

Derp.  I need to learn to read.  AC it is.  

Anyway, here's the datasheet for the module relays.  5mS break time.   much faster than I expected. as well as a much better life expectancy that I figured they would have.    http://datasheetcafe.databank....C-SL-C-Datasheet.pdf

Anyway, keep up the ideas, I have to hit the road from Detroit to Rockford, IL with a couple stops on the way, so I'll be away for the next 8 hours or so.  

Thanks everyone for the input so far.  

JGL

gunrunnerjohn posted:

The Millionspot H200S09 relay in the PH180 is a 15A relay.

I stand corrected.

I thought I remembered a thread here a while back where someone was going on and on about how unsuitable it was for the purpose. 

Chalk me up for qty (1) Factual Boo-Boo! I won't try to pass it off as a Senior Moment....

I would be happy with just the volt amp meter part of the project, but you have gone way beyond that with a lot more nice features. For circuit protection here, I have some PSX-AC's, which might be something I could give a shot at comparing to the circuit protection you end up with here, if you want. You might have to help me along a little with the proper way to compare them though. You guys are all way ahead of me so I will just follow along and try to keep up...

rtr12 posted:

I would be happy with just the volt amp meter part of the project...

I agree with this sentiment.  Yes, for discussion or forum purposes it's fun to blue-sky ideas, but my interpretation of your basic premise is to leverage the relatively recent availability of attractively priced digital processing, instrumentation, and display modules and apply it to train power measurement.  IMO if you can teach an Arduino to provide both digital and analog (emulate a dot/bar graph) display, even a single-channel volt amp meter would be a contribution to the hobby.  I'm assuming you're thinking of something that could be easily replicated by other OGR members.  The reality is that like soldering and dealing with tiny electronic components the Arduino is not in most guys' comfort zone.  The vast majority of OGR readers (from what I can tell) would just as soon buy a ready-to-run solution.  To that end, simple considerations such as a bezeled display that easily drops into a control panel cut-out is a big win...in my opinion.

display

Or if you "solve" the recurring question of whether or not and what kind of isolated DC power module you need to operate those eBay digital panel meters then that would be a contribution.

So if this is really in the "planning" stage (as opposed to the implementation stage) I suggest more discussion of WHAT it is rather than HOW it is done.  Arduino vs. RaspPi is HOW.  Electro-mechanical vs. solid-state relay is HOW.  Voltage sensor vs. resistor divider is HOW.   Bridge-rectifier vs. op-amp rectifier is HOW. 

That is, I'm bogged down by your initial statement, the meters to operate on any power grid or source, as well as being operational with DC power.

Are you saying you want to (accurately) measure true RMS voltage and current for chopped-sine supplies?  How about DC supplies?  DCC supplies?

Or your statement, provide exceptionally accurate results.

You say 0.05V and 0.05A resolution but generally speaking, resolution is easy.  Accuracy is hard.  And exceptional accuracy is exceptionally hard!  IMO I don't think you need exceptional accuracy.  That goes to WHAT...which is my point.  Once the horse is before the cart, I would claim the accuracy of the intrinsic Arduino measurement system is not exceptional.

Very interesting ideas.  A gold star for your inspiration and willingness to go before the peanut gallery!

gold-star

 

Attachments

Images (2)
  • display
  • gold-star
Last edited by stan2004
stan2004 posted:
  I'm assuming you're thinking of something that could be easily replicated by other OGR members.  The reality is that like soldering and dealing with tiny electronic components the Arduino is not in most guys' comfort zone. 

 

Oh, I don't know how important that is to the project. The OGR forum is positively overflowing with scenery and super-detailing and realism that I personally couldn't duplicate for any amount of money, let alone easily! Nothing wrong with working on a project for the Arduino guys!

I suspect we are at the reality check stage, where the practicalities of the HOW are pushing back against the dreams of the WHAT. Or, to put it in terms dear to my heart, Engineering is pushing back on Marketing. 

Last edited by PLCProf

LOL.  Well, yes and no.  IMO your projects are (generally ) problems looking for a solution.  In this case it's arguably leaning toward a solution (Arduino, inexpensive Hall current sensors, etc.) looking for a problem.  For a forum and beer-drinking conversation there's nothing wrong with the latter and it's an interesting topic.  But as I'm sure your industry experience has shown, the "everything but the kitchen sink" approach to product definition is a recipe for disaster.

Lets see where we are…  (this is a long one... sorry, brain going in too many directions all at once.)

RTR12, once we have something that works, I'd really like to run some tests head to head with other products that are considered top of the line.  I think the Arduino will keep up with the best of them, but I don't know this as a fact just yet.  I'll have to build an adjustable load bank for testing, or come up with a simple load solution for others to test with.  I have some ideas here, but I don't quite think we're at that stage yet.  

As mentioned before the circuit breaker part is sort of an add on to the meters.  it's not needed, but only adds the cost of the relays to the project as we already have the Arduino monitoring the current.  It shouldn't take much to say "if current is over X, turn off the relay."  Just slightly more complex to add a sliding scale as discussed above.  It may be that if this ever turns into a marketable product, or a 'how-to' instruction guide that it will have the circuit breaker portion as an add on to the basic meters.  

As far as trying to keep up, please ask any questions you may have.  I'm certain there are things I'm overlooking in this project and there are things for everyone to learn.  Arduino is fairly simple to learn, but the best way is to start building something!

 

Stan, thanks for the star.  At this point i'm looking for everything, including the kitchen sink.  there are no stupid ideas, just ones that will turn out to be unworkable for some reason or another.  

If this works out and proves to be something that is as good or better than other options on the market, I wouldn't mind trying to produce a ready to use device that doesn't require any specialized skills or knowledge to use.  Another option might be to offer a standardized motherboard that would allow folks to buy their own parts and simply plug everything together. At some future date I'd like to offer some products and services for sale, but that is not today.  

For me, form follows function…but, it makes sense to make sure that whatever is used can be made to look good.  

I've never been one to care much about having a 'finished look' but understand that this will be important to many folks.  I have access to a lot of useful tools and such both of my own and through my company's print shop.  While injection molded plastic is currently not on the menu, almost everything else is.  I'm thinking of using acrylic plastic with dye-sublimation printing to make a panel that could be dropped into a control panel.  

 

You can see the sort of display I was originally looking at by typing "8 digit LED Arduino" into the auction site. I like these because they use only 3 I/O pins for 8 digits and probably less than that as at least one pin can be shared between displays.  

I'm not sure if these will be optimal now and am going to look at some other display options.  by the time you have the LEDs, for primary displays, LCD for additional data, and a bar-graph for detail of fluctuating readings I think everything is going to be quite cluttered.  May be better off using a single dot-matrix display, or even scraping the Arduino and using a Raspberry Pi with it's native support for HDMI video output.  May be overkill but with folks wanting nice large meter displays, you could pick up a $129 32" TV and clearly see the readouts from the neighbor's house.  I'm going to kick this idea around a bit more, buy it will require me to brush up on my python skills.  Going with a RPi would eliminate any concerns for CPU speed as the current $35 model has a 1.2GHz quad core processor.  The down side is that the RPI does not have native support for analog inputs, so an AtoD chip will have to be used… or an arduino go between… more ideas happening as I type… Stupid ideas getting in the way of things!

 

On a couple of your comments, Stan, I do intend to measure true RMS for any supply connected, no matter what the waveform looks like.  I honestly do not know enough about DCC to know what is needed, and am unsure if it will be possible.  I am imagining that the meter would be in place on the input side on a DCC or DCS setup, such that we don't have to worry about signal issues.  If it is the case that the meter needs to be made compatible with the DCS signal, that is something that I'll have to do homework on.  

As for exceptionally accurate readings, I suppose we need a definition of terms.  I suppose what I mean is 'better than anything I am aware of in current production for model trains.  The voltage meter end of the design is currently up in the air, so I don't know what we will end up with, but the current sensors, at least according to the datasheet, read in 1/20th of an Amp increments.  I suspect the over all accuracy then will be with in 50mA of what it reports.  Testing will be in order to see if these sensors actually report accurate measurements or not, but the information I have on them suggests that they do.  Perhaps installing a load resistor in the device so that it can self calibrate for variations between sensors would be an option, or in the vein of KISS, simply forming a calibration procedure for new units.  

EDIT:  (for preceding and following paragraphs) still some good info here on ADCs and such, and it may be useful for the volt meter portion, but upon further reading of the datasheet for the ACS712, it seems this device, in the 20A version, is only accurate to a tenth of an amp this may require some rethinking on my part, or it may be that 0.1 amp is good enough for people

While the Arduino's 10 bit ADC is not fantastic, it is exactly enough for 1/20th Amp resolution with the 20 Amp version of the ACS712 module.  Seems I forgot that spec, so with the 30 Amp version we'd go down to 1/13 amp resolution.  I think, however that even a reading to the tenth's of an Amp is better than most of what is out there right now for trains, and even more so if we know that the reading is an accurate, true RMS measurement.   if a RPI ends up being the micro-controller of choice, however, it's need for an external ADC opens the door for a much higher resolution.  There are also very inexpensive I2C interface 16 bit ADC's from chin that might be just the ticket if the 10bit ADC on the arduino proves insufficient.  With 16 bits we go from 1024 desecrate values (1/20th A on 20A sensor) to 65.536 increments, (about 1/1300th amp, better than 1 milliamp resolution.)  I'm unsure if the module outputs sensitivity that low, but if it does, I may go the 16 bit route just for fun.  

 

I agree that the solution here is far in excess of the problem, but there is a problem none the less.  For me the problem is that I'm unaware of even a reasonably accurate panel meter solution that is also reasonably cost effective.  I'm also unaware of a cost effective electronic circuit breaker.  All of these things do exist, I just think that throwing it all in one box and using off the shelf parts wherever possible will provide a better quality product than anything currently offered, AND cost less than these other options.   I'm not a genius with figuring our MSRP but if we go the most expensive route for everything thus far discussed, a nice looking box and a 7 inch touch screen display we're still only looking at about $100 in parts for a 4 channel unit.  Even at $200 retail for a finished product the cost is less than just that of 4 of the high speed electronic circuit breakers.  Going with a simple, dumbed down version with just simple 7 segment Volt and Amp displays and nothing else, we're looking at maybe $ 60 retail, which doesn't seem bad at all for true RMS panel meters.  

 

So, As I've been typing thoughts out here it occurred to me that the best solution that would make the most people happy might be a modular design.  You have voltage and current sensor modules that provide serial, I2C, or SPI data  output as one module.  You could then add circuit breaker modules, which would be little more than relay boards, really.  Then last could be a user choice of various display modules. Perhaps a 'basic' version that uses the simple LED 7 segment displays and only reports the current RMS voltage and Amps in typical panel meter fashion and which would be rather inexpensive.  then you could have the choice of a more complex display, utilizing a 7" or 10" color LCD touch screen that will display all the little quirks of information that the sensors can provide.  

 

Sorry if I babble too much.  I tend to do that when brainstorming ideas.  Please, toss the kitchen sink in the mix as well, you know there are some really neat water-level sensors for Arduino?

JGL

 

JGL,

I will be following along. Probably won't be able to offer much technical assistance though.  

Also if you happen to have a Micro Center in your area they have the Inland brand Arduino Mega 2560's (SMT chip version) on sale for $9.99 each, so I now have an Arduino Mega. Maybe more costly than the Asian suppliers on ebay (haven't compared them), not a bad price and I was right there in the store already... They also had sale prices on Arduino Pro mini's ($3.99) and Raspberry Pi 3 Model B's ($29.99). I don't know if those are good prices compared to ebay or not, but if you have a Micro Center nearby, it's handy and much quicker.

Anyway just as an FYI, they now have a pretty good selection of electronic parts, Arduinos and related items now, looks a lot better than Radio Shack to me. Seems like they have more and more electronic stuff every time I visit.

Forgot to add, it is pretty impressive that you have already received a gold star too, and so early in the project. That's a good sign!

Last edited by rtr12

RTR12, I own one each of the genuine Arduino Uno($25, paid $35 at RadioShack) and Mega($45), and a genuine SparkFun ProMini ($10).  I purchased these mostly because I believe in supporting the original designers work, but I can't afford these boards for actual projects.   That said, every other Arduino I currently have, about 20 boards all told, are the MicroCenter Inland brand.  At the sale prices, which have been about the same for the last 3 or 4 months, they are reasonable enough for me and I like the connivence of a 15 minute drive over waiting a couple weeks from China.  On the auction site, from China, Megas run about $8, Unos about $4, and Nanos and proMinis are about $2.  There's savings that will add up on large quantities, but for prototyping work, I'm very happy with MicroCenter.   As for the RPi, I don't currently own one but have messed around with a first generation board quite a bit several years ago.  

JGL

While it's fun to brainstorm and exercise the gray cells, you can't eat a pie-in-the-sky.

Pie-in-the-Sky

Here's WHAT I think would be a contribution to the hobby.  If the Arduino is the HOW then so be it.

* Single-channel isolated Voltmeter-Ammeter w/digital-readout

* 0-30 Volts, 0-15 Amps, true RMS

* Analog display dot/bar-graph for current

* AC or DC operation (select-able or auto-detecting)

* Powered by single DC wall-wart or by the voltage-channel input

* $20

Possible nice-ties:

* Output signal to control relay for over-current (settable threshold)

* Display of true power (in Watts)

* Settable functionality (display update time, bar-graph response time, detect of DC offset on AC)

To be clear, if the purpose of the discussion is to add to the (long) list of things an Arduino can do for trains, OK and I'll stop harassing you!  I'm simply reflecting on dozens of OGR threads on panel volt and current meters and the issues/problems in applying them.

Separately, in the solution-looking-for-a-problem category, just as the $2 Arduino causes one to ponder what else it could do, take a look at the $1 power-metering IC chips that integrate dual-channel A/D converters and computation of true-RMS with revenue-quality (power company meters) accuracy.  I think you will find a few tips on sampling frequency, calibration, accuracy, bandwidth, etc.. as it relates to the specific problem of measuring 50/60 Hz AC voltage and current.  For example, here's a block-diagram of the Atmel M90E26 available from DigiKey for $1.45 quantity 1.

m90e26

Similar chips are made by Microchip (of PIC fame) and many others.  For all I know there might be an eBay Arduino module that integrates one of these $1 IC chips (via SPI).  So this could eliminate the need to "reinvent the wheel" of true RMS calculation of AC voltage and current and all the attendant issues with A/D frequency, resolution, accuracy, etc.  OTOH, this HOW would not measure hi-frequency DCC voltage/current.

Attachments

Images (2)
  • Pie-in-the-Sky
  • m90e26

Well, JGL initially threw out $30 for a 4-channel system...

Because of low-volumes in hobby trains, and yet lower-volumes dealing with O-gauge AC, leveraging electronic modules meant for other high-volume applications seems like the only practical way forward.  And unfortunately the "glue" to put these modules together still requires, in many cases, soldering, wiring, messing with tiny components, and so on.

It is happening to some degree now but at some point sending data or software to other OGR members ought to make these projects easier.  That is, an Arduino-based widget could be updated by simply plugging into a USB port and it magically gets new features.  Or guys exchanging MP3 recordings of train sounds to play on their MP3 sound effect modules.  Or the 3-D printer data file to make a broken piece on an engine body.  Presently, the only member exchange that comes to mind is sending the data file to print out a tach timing tape for a DCS flywheel! 

In the mean time, it does seem that many projects like this devolve into one-off showpieces - I'm imagining JGL using a 32" flat-panel screen with HDMI interface to display the 4-channel voltage and current data!     Of course it is these one-off showpieces that serve as inspiration for the next great idea. 

On the one hand, this hobby is not about saving money. But on the other hand, a high price will prevent someone from getting something that would be nice, but not necessary.

So...it's appropriate to be frugal in the design (parts), but not at the expense of getting the design accomplished.

How's that for an Independent?

JGL,

I have been doing some more research on this and was wondering about the voltage diver to read the voltage. The divider would have a bridge rectifier that feed two resisters right? The resisters would knock down the voltage to 0-5 volts. What I'm not understanding is that the divider and Arduino board would have to share a common ground, correct? The ground from the Arduino would need to be connected to the ground from the voltage divider. Does this create any problems if the Arduino is wired to an ATX computer power supplie that is supplying other Arduinos or devices?

Chris 

Hey Chris,

I've kinda put this project on hold due to work keeping me very busy lately, but have done a bit more research.  At present I'm weighing the pros and cons of using various methods discussed above.  Primarily I'm undecided if it would be simpler to use a power metering chip that does everything internally, or to go with the separate current and voltage sensors.

I've found that the sensors I originally wanted to use are only good for 1/10th amp accuracy, and the onboard ADC of the typical Arduino will give at best 1/10th volt increments.  While this would be 'good enough' for track power monitoring, it is not nearly as accurate as I was hoping for... which has led me to looking for more accurate sensors.  


to measure true RMS of AC voltage we can't use the rectifier, as it will block any voltage under about 0.6 volts from being read.  The best solution I've found so far seems to be the method described by the open energy monitor project found HERE. 

The values of the resistors in use will have to be changed for track level as opposed to the mains levels the circuit is intended for, and the step down transformer is likely unneeded.  

I believe, but need to confirm, that multiple arduinos and multiple meters can share a power supply, but the ground of that supply can not be connected to track/transformer common.  This is because the common of the transformer must also be put through a voltage divider to the ground of the arduino so that the arduino can read both the positive and negative parts of the wave, and so that the negative voltage will not damage the Arduino input.  

In addition to this I'm thinking of using an add on 16 bit ADC (analog digital converter) as opposed to the 10 bit on board one, which will increase resolution by more that 60 times. (theoretically giving about 1 mV resolution if my math is right here.)

Anyway, the short of it is, I think that one power supply could be used to run as many meters as you want (assuming the sources the meters are reading have commons connected together), but that power supply could not be used to power anything else sharing track power.  


I'm still kicking all of this around.  I've found a couple different current sensing methods that may be better than the modules I was first looking at as well, and with the addition of 16 bit ADCs should be able to get fairly good results.  I won't know what happens in the real world until I have time to hook parts together.  

JGL

JohnGaltLine posted:
 
...to measure true RMS of AC voltage we can't use the rectifier, as it will block any voltage under about 0.6 volts from being read.  The best solution I've found so far seems to be the method described by the open energy monitor project found HERE. 

The values of the resistors in use will have to be changed for track level as opposed to the mains levels the circuit is intended for, and the step down transformer is likely unneeded. 

...

In addition to stepping down the AC voltage, the transformer provides the more important function of floating (isolating) the measured voltage so that you can "force" one side of it to the 2.5V mid-point of the A/D.   Note that if you choose to support DC measurements...such as accurately measuring the track voltage when the Horn or Bell button is pressed, then using a transformer will not work since it does not pass DC.

The link you provided shows an "active" op-amp circuit to shift the mid-point.  For the application of shifting the mid-point level, the gain/amplification of an active circuit greatly reduces the burden on the measured voltage.  DC level-shifting circuits that use passive-only components can get tricky such as narrow range of resistor values that work without compromising accuracy.

If you're using an external A/D converter (instead of the internal Arduino A/D) they have bipolar input converters that operate on a +5V DC but have a bipolar input range of, say -x Volts to +x Volts.  In other words the level-shifting to the mid-point (i.e., an active circuit) and range scaling (i.e., precision resistor dividers) are built-in.  You will pay (dearly) for the convenience of having these functions integrated in the A/D chip!

As you study input methods note that an ideal voltage measurement instrument has an infinite input impedance so as to not burden the device being measured.  But if your voltmeter only needs to measure a train transformer output you get a lot of design flexibility.  So check the assumptions as you read how-to articles, application notes or whatever about designing a voltmeter.

Hey JGL,

I read your response and somewhat understand. I'm a little confused though. When I was talking about the ground I was trying to say that they should be separated correct? Meaning between the train/layout power and Arduino. You stated that ground from the Arduino needs to be connected to the divider. This wouldn't connect them? Would a voltage divider still need to be used if an ADC is? Would the ADC be just reading voltage and would a ASC current still needed? 

What do you think of this one, 16-bit ADC?

I apologize if I sound like a dummy, but I admit you are getting out of my league with electronics, but willing to learn. 

Chris

Add Reply

Post
×
×
×
×
Link copied to your clipboard.
×
×