Remote access to 4-20ma signals

Thread Starter

Wellarmedlamb

Joined Apr 16, 2016
16
Hello,

I recently stumbled upon the world of arduino and raspberry pi while researching tech for my truck.

I see many uses for these systems in my professional life.

I operate a small population / large geographical area rural drinking water system.

I would like to implement remote sensor viewing but the system has next to no budget to work with.

-I have a flow rate meter with digital display. The meter outputs a 4-20ma signal which is utilized by a flow-pace chemical injection pump. This signal would need to be converted to gallons per minute.

-I will be implementing a constant chemical saturation analyzer which outputs a 4-20ma signal. This signal would need to be converted to parts per million.

-I would like to implement a 4-20ma pressure sensor (for reading storage tank level) and a method of viewing the pressure. This signal would need to be converted to feet of water (2.31 feet is 1psi)

I would like to utilize arduino or a similar system to upload this information continuously and use a site like plot.ly to graph and track the data remotely. I would also need a small screen to view the pressure signal.

A streaming webcam would be nice too.

Thank you in advance for any advice.
Jesse
 

Picbuster

Joined Dec 2, 2013
1,047
first of all you have to identify the 4-20mA loop of each sensor.
the questions passive 2 wire active 3 or 4 wire, common GND or galvanic separated.
At two wire active; the sensor get his power from the 4-20mA loop.

When all are using common gnd you can put a 50 Ohm resistor in the gnd loop and feed the voltage over that resistor into the analogue inputs of a MPU. But this I a bit tricky and could introduce gnd loops (errors). It is always better to create galvanic separation.
From MPU via GPRS or short haul modems to a receiver.( that's the simple part).
I prepare to help you. just ask.
Picbuster
 

Thread Starter

Wellarmedlamb

Joined Apr 16, 2016
16
Thank you for starting to help! Of the 3 proposed sensors, only one is already in place. The flow rate meter which has a controller which outputs the 4-20 signal. I will contact the manufacturer tomorrow to find out the type of loop being utilized.

The next priority will be the pressure sensor which has not yet been purchased so I'll be able to get whatever type is suggested here.

I would like to get started on a platform with something in hand upon which to start learning.

Arduino, raspberry pi, Intel, something else altogether?

I'm starting mostly in the dark here so I certainly appreciate any and all help!
 

Thread Starter

Wellarmedlamb

Joined Apr 16, 2016
16
The flow meter outputs a signal to a digital display and totalizer called an Act-Pac. The Act-Pac outputs a powered, 2-wire, 4-20ma signal covering a range of 0-400 gallons per minute, which in this case is utilized by a flow-paced chemical injection pump to regulate injection.

The pressure sensor I will be using requires a powered, 2-wire, 4-20ma signal covering a range of 0-100 psi. I would like to have a display panel for this pressure reading. If possible I would like this display to show the reading in feet (1 psi = 2.31 feet).

I will need capability for expansion into a third powered 2-wire, 4-20ma signal for the chlorine analyzer (the analyzer puts out a powered signal) but that won't be implemented anytime soon.

As a side note, an ambient air temperature sensor and a webcam would be nice for remote conditions viewing. These items are not immediately necessary though.
 

Thread Starter

Wellarmedlamb

Joined Apr 16, 2016
16
So based on what I've been reading:

My flow rate meter output is active 2-wire (type 2). In which 4ma = 0.00gpm & 20ma = 400.00gpm.

My pressure transducer is passive 2-wire (type 2). In which 4ma = 0.00psi & 20ma = 100.00psi

My future Chlorine analyzer output will be active 2-wire (type 2). In which 4ma = 0.00ppm & 20ma = 5.00ppm.

I found a 4-20ma shield made by libelium. This appears, to my untrained eye, to be what I need.

https://www.cooking-hacks.com/4-20-...shield-for-arduino-raspberri-pi-intel-galileo

I'm considering getting an arduino starter kit just to start learning.
 

mcgyvr

Joined Oct 15, 2009
5,394
I'm considering getting an arduino starter kit just to start learning.
Yep.. What you want is simple for anyone with the knowledge.. and a fairly simple project for a "beginner".. Take each chunk of the project one at a time..research (aka google) and go for it..
If you get stuck post back here for help/direction..

Simply google "arduino 4-20ma" and you should get all the info/videos/tutorials,etc.. you need..
Then slap on a display..

Its all just read the 4-20ma inputs and scale accordingly to your desired output.. Pretty darn simple..
 

Thread Starter

Wellarmedlamb

Joined Apr 16, 2016
16
Thanks for the confirmation! I thought it sounded pretty simple too but then was afraid I might be overlooking something. Sounds similar to the data logging I've put together for 0-5v analog automotive sensors. Now to pick a starter kit.

On a side note, it looks like I'm not going to be able to place my pressure sensor in close proximity to my flow rate meter (inside my treatment plant). I'm going to have to install my pressure sensor at my storage tanks (due to needing high accuracy) which are 0.7 Miles away. There is no hardwired solution for getting the signal from the tanks to the treatment plant. The only solutions I can think of are having a second arduino with it's own SIM card uploading data or an xbee pro type solution to wirelessly communicate to the Uno in the treatment plant. There is no clear line of sight (the tanks are about 50 feet higher in elevation through 0.7 Miles of forest and rolling hills) than the treatment plan so I'm not sure if wireless communication would work.
 

mcgyvr

Joined Oct 15, 2009
5,394
Thanks for the confirmation! I thought it sounded pretty simple too but then was afraid I might be overlooking something. Sounds similar to the data logging I've put together for 0-5v analog automotive sensors. Now to pick a starter kit.

On a side note, it looks like I'm not going to be able to place my pressure sensor in close proximity to my flow rate meter (inside my treatment plant). I'm going to have to install my pressure sensor at my storage tanks (due to needing high accuracy) which are 0.7 Miles away. There is no hardwired solution for getting the signal from the tanks to the treatment plant. The only solutions I can think of are having a second arduino with it's own SIM card uploading data or an xbee pro type solution to wirelessly communicate to the Uno in the treatment plant. There is no clear line of sight (the tanks are about 50 feet higher in elevation through 0.7 Miles of forest and rolling hills) than the treatment plan so I'm not sure if wireless communication would work.
Got internet at both locations?
You can pick up some super cheap "WIFI" enabled boards now and just post the data somewhere..aka the cloud (lots of free services if you don't have your own server) and read it from the remote location..
I've been using the ESP8266 based micros lately.. The Adafruit Feather ESP8266 variant is a great alternative to an Uno and has built in wifi.. usb to serial chip..usb..lipo battery jack with build in charger.. Sparkfun has one too and more.. And I believe both have their own cloud datalogging service you can use too..
Oh did I mention you can just program them right from the Arduino IDE using the same simple "arduino" language

here.. quite a few choices if one fits your needs..
https://www.adafruit.com/category/851
There is an arm micro with wifi too I believe.. Really no need for the UNO anymore now that these types of things are so accessible and Arduino compatible..

even some "long range" radio ones..
 

Thread Starter

Wellarmedlamb

Joined Apr 16, 2016
16
Unfortunately, no internet access as of yet at either location. I am waiting for the internet provider to get back to me as to availability of internet at either location. If there's no availability I will have to use a mobile network data connection.

Also, management would not be willing to pay for more than one internet connection.


I will absolutely look into the other versions of the uno!
 
Last edited:

Thread Starter

Wellarmedlamb

Joined Apr 16, 2016
16
Update: I received my starter kit last week and commenced teaching myself Arduino based on the tutorial. I also received my 4-20 ma Shield and at this point have the Arduino temporarily set up reading my pre-existing flowmeter to check accuracy. Having simply built upon and worked backwards from a few of the tutorial code examples , I'm sure my current code is a bit clumsy but it functions.

I do have a couple of coding questions:

-Can I cause the arduino to do a 5 second average then show that average? Right now it just takes and displays a spot reading every five seconds. The spot reading fluctuates greatly.

-If I have a button hooked up to reset the reading, can I cause the arduino to display a running average since last button push?

Final question:

In setting another arduino to read the water level in a 25 foot tall tank. Dan at maxbotix has helped me make it down to a particular rangefinder which has output options as follows:ensors in this line provide the following output options: "analog voltage, pulse-width, and serial data (RS232 or TTL depending on the sensor)."

The sensor will be 50+ feet away from the arduino. What is the best output for this application?

Thanks
Jesse
 

mcgyvr

Joined Oct 15, 2009
5,394
-Can I cause the arduino to do a 5 second average then show that average? Right now it just takes and displays a spot reading every five seconds. The spot reading fluctuates greatly.
yes
You need to read the sensor and store that value, then read again, then add that to the previous, then read again, then add,etc... then divide by 5 and display.
You would do this with a for loop.. something like this.. (very basic example)
Code:
int sumval=0; //create sumval variable
for (int i=0; i = 4; i++){ //repeat this code 5 times
val =digitalRead(SensorPin);// read the sensor pin
sumval = val + sumval; //add read value to sum
delay(1000); //1 second delay
}
int myaverage; //create myaverage variable
myaverage = sumval/5; //divide sum by 5
Serial.print("My average is: "); //print out results
Serial.println(myaverage);
-If I have a button hooked up to reset the reading, can I cause the arduino to display a running average since last button push?
yes
Just need another variable thats the running average..
and a value of total number of reads to use for division..


In setting another arduino to read the water level in a 25 foot tall tank. Dan at maxbotix has helped me make it down to a particular rangefinder which has output options as follows:ensors in this line provide the following output options: "analog voltage, pulse-width, and serial data (RS232 or TTL depending on the sensor)."

The sensor will be 50+ feet away from the arduino. What is the best output for this application?

RS232 due to distance..
 
Last edited:

Thread Starter

Wellarmedlamb

Joined Apr 16, 2016
16
I got the "smoothed flow rate" working. Thanks!

In terms of a running "flow rate average" which only gets reset upon button push...i can't seem to figure out how to get the total number of reads by which to divide.

I'd also like a third line on my screen giving a total usage which I imagine could just come from the the "flow rate average" times the number of minutes of uptime? Also to be reset upon button push.

I ordered a beginners guide to coding arduino because I'm flying blind on anything outside of the starter kit lessons.
 

Thread Starter

Wellarmedlamb

Joined Apr 16, 2016
16
To get a link to your remote tank location would be easy with a radio data transmission system.
This company has a good solution under $500
http://www.radiolabs.com/products/wireless/900-mhz-wireless-bridge-link.php
Thank you for that. I'm still researching the best method of communication. I could use the cellular network in both locations or a long range radio type device as you suggestes, if possible. It's only a distance of 0.7 miles but has a hill in the way which I'm afraid is too thick a land mass to penetrate.
 

mcgyvr

Joined Oct 15, 2009
5,394
In terms of a running "flow rate average" which only gets reset upon button push...i can't seem to figure out how to get the total number of reads by which to divide.
Just a variable that starts at zero and is never reset (until power is lost)..

Basic example.. you can load this on your arduino and view the serial monitor to see the output..
Code:
int totalreads = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Started");

}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("I'm reading the sensor now");

//code for reading the sensor goes here..

  delay(1000);
  totalreads++; //add 1 to the total reads each time we get to this point
  Serial.print("I've read the sensor ");
  Serial.print(totalreads);
  Serial.println(" times");

}
 

Thread Starter

Wellarmedlamb

Joined Apr 16, 2016
16
I'm still struggling to get some of this figured out.

based on mcgyver's post I currently have the smoothed flow rate seemingly working properly. It wasn't working and I placed a "<" in line 10 and it began working. Feel free to critique this.
  1. // Get the sensor value corrected for flow in gpm
  2. // If 4mA = 0 gpm and 20mA = 400 gpm then float flow = (current - 4) * 25;
  3. float flow = (current - 4) * 25;
  4. Serial.print("Flow : ");
  5. Serial.print(flow);
  6. Serial.println("gpm");
  7. // Smoothed Flow Rate
  8. int sumval = 0.00; //create sumval variable
  9. for (int i=0; i <= 49; i++){ //repeat this code 50 times
  10. sumval = flow + sumval; //add read value to sum
  11. delay(100); //0.1 second delay
  12. }
  13. int smoothedflow = 0.00; //create smoothedflow variable
  14. smoothedflow = sumval/50; //divide sum by 50
  15. Serial.print("Smoothed flow is: "); //print out results
  16. Serial.println(smoothedflow);
The above sketch outputs the smoothed flow rate every 5 seconds. I've been trying to get the below necessities to also update every 5 seconds but can't seem to figure out how to make that happen based on the for loop above. I understand that the for loop is going to run for 5 seconds inside the main loop every time we get to this point. I can't figure out how to get totalreads to add up more quickly than once every 5 seconds, i believe because of the for loop(and my lack of understanding)

I would like a running average updated every 5 seconds. This average could potentially read and add the smoothed flow once per second divided by totalreads or once every 5 seconds divided by total reads to get a a running average for gallons per minute.

I would like a running total updated every 5 seconds. This total could potentially read and add the smoothed flow once per second divided by 60 or once every 5 seconds divided by 12(accuracy is important).

I've tried a number of different things but just don't understand enough yet to get this working. I've included in my sketch the library from this post but can't figure out how to use it.

also, assuming the above requirements can be worked out, am I going to run into memory constraints? This unit needs to be able to run unattended without having the total or average reset(once the code is worked out I'll add a reset button for the running average and total). The total may grow quite large (we run 80,000 gallons per day)
 

mcgyvr

Joined Oct 15, 2009
5,394
Remember that (for the most part) when the program is doing something or a delay is occurring nothing else can happen. Its basically can only do one thing at a time. With a delay its just sitting there counting the delay.. When a loop is running is just running that loop and can't do anything else. Now you can include your other code inside that loop or or whatever to have it happening while that loop is processing.

Also an int is only whole numbers so it can't include decimals.. Sorry if I used ints in my basic examples when I should have used floats.

As to memory.. You shouldn't have any issues.. You are just changing the value of a variable over and over again but not adding more and more variables.

Also the button to post "code" as I did is 3 over from the smiley face.. Looks like a piece of paper with a small I at the bottom..
Just makes code easier to read,etc..
 

Thread Starter

Wellarmedlamb

Joined Apr 16, 2016
16
As I'm learning this on the fly with no foundation in coding, i wasn't really aware of the chronological limitations until last night when i read one of the labels that said "//do this each time we reach this point.". Also, I discovered the loss of decimals today and switched the ints to float. Is there a way to limit to and require a minimum of 2 decimal points?

So I either need to have my methods of totalizing and averaging running later or place it in the pre-existing for loop.

The library I downloaded seems like a viable option but haven't had time to figure that out yet.

Haha okay, I wasn't sure how you did that with posting your code.

Thank you
 
Top