I can't find any results to my searches but I'm sure this is a common thing.
I have 4-20mA coming from a flowmeter and need to operate a device which expects to see a pulsed input (5-15V, >200mS pulses). The pulse frequency would be proportional to the 4-20. So I'd like to use an arduino to output pulses like that (not sure yet if transistor output is sufficient - may have to drive a relay output). Is there a project someone can point me toward to start with?
So you have 4 to 20 mA which is proportional to a rate of flow? If you take your 4 to 20 mA range and drive it through a precision 500 Ohm resistor you now have your flow range proportional to 1.0 to 5.0 Volts which on an Arduino Uno powered by 5 Volts using an analog to digital reference of 5.0 volts tells you that 0 to 5 volts will give you 0 to 1023 bits (2^10). That's about 205 bits/volt. So you start with 205 bits through 1023 bits is 1 to 5 volts input.
Your post is vague in that you do not mention a lower and upper frequency limit for your range? Like 0 GPM or LPM to upper limit GPM or LPM flow rates? Anyway what you want is a voltage to frequency transducer or converter. Not knowing the lower or upper frequency limits I have no idea if an Arduino will fit your needs. With the Arduino one approach might be use it as a V to F (Voltage to Frequency) converter using a map function. As to the 5-15 Volts you can worry about that later using a simple transistor scheme but now you need to better define your project in some detail.
I have no clue what the pulsed relay reference thing is about?
Thanks for the quick reply! Yes, getting the 4-20 into the arduino by dropping it through a resistor is fine.
The pulse output would be a flow volume. So for a certain time at a certain current (voltage), we would integrate that current, and eventually output a pulse. As the current rises we get more pulses. So what I'm imagining is:
-read analog input value
-add it to "volume totalizer"
-when "volume totalizer" is > than a trigger value (the pulse volume), output a pulse and reset " volume totalizer"
-time delay so all the above happens once per second (say)
-go to start
What I meant by "may have to drive a relay output" is that I'm not sure how much pulse current there has to be. If it's more than the arduino can provide, I'll have to drive a relay with the arduino and use the relay to provide the current. What, you couldn't read my mind?
Not so sure how to code this... Would you mind pointing me toward a reference I can start from?
Do you have a link to the flow meter you are using? This would have gone better if the plow meter had a pulse output rather than a 4 to 20 mA current loop. So you are not really concerned with the rate of flow as the volume over a period of time or as you said a totalizer function.
The 4 to 20 mA is what you have and we need to get that to what you want which is pulses. Flowmeters have a K factor which will come down to how many pulses per unit of measure, be they Gallons or Liters. "The K-factor is the frequency divided by the flow rate => [1/s] / [g/s] = 1/g. Knowing the K-factor for each calibration point, the factory determines the best fitting K-factor for that particular flowmeter . They do that for instance by averaging all K-factors, or use another appropriate mathematical method".
I would take the 4 to 20 mA and derive a voltage as I mentioned earlier and then do V to F and then once you derive a K factor count pulses.
Running a voltage into an Arduino Analog In you can MAP the input and get a frequency. Then count the pulses (totalize). A given number of pulses will be proportional to a given volume of liquid measure. This would have gone much easier with a flowmeter that had a pulse out making it more suitable for a totalize function.
To clarify, I have almost no Arduino programming experience...
Unfortunately this flowmeter does not have a pulse output. No, it's not looking for PWM. Pulses have to be 5-15V, minimum 100ms I think. Thanks Ron for all the description. I'm almost there with the concept; less so with the coding. So here's where I'm at:
For the sake of argument, let's say 4mA = 0 l/s and 20mA = 100 l/s for the flowmeter.
I have an external counter is expecting one pulse (of 200ms at 9V) every say 1000L.
So if the flowmeter is putting out 20mA, the counter would get one 200ms pulse every 10 seconds
If the flowmeter is putting out 12mA, the counter would get one 200ms pulse every 20 seconds
and so on
I understand the the current to voltage conversion by using a resistor and reading that value in the arduino
I'm writing a program where I have a 1000ms delay between reads - that's close enough and I can fine tune it if necessary. So I think I can just use the sum of the voltage readings, and once I get to a particular sum I can fire the pulse. Then I'd have to reset the voltage sum to zero, and start again.
I'd be grateful for help with coding that part of the work.
I told you you want a V to F (voltage to frequency). The frequency is pulses in this case. Every so many pulses is proportional to a unit of volume. That is the K factor. At a pre determined volume you want something to happen be it send a 200 mSec pulse to another instrument but something happens. Counting the pulses increment the count is a totalizer.
So break it down. You want a Voltage to Frequency (pulses) and you want to count the pulses. After a preset number of pulses do something and reset or stop or whatever. About all you have shared is when you get where you are going you want a 200 mSec pulse between 5 and 15 volts in amplitude which I assume is going somewhere like a PLC?
Ron_Blain:
So you have 4 to 20 mA which is proportional to a rate of flow? If you take your 4 to 20 mA range and drive it through a precision 500 Ohm resistor you now have your flow range proportional to 1.0 to 5.0 Volts
You got your maths wrong, and besides the best way to do this is using a 51 Ω resistor and measuring the voltage using the Arduino's 1.1V internal reference. Much more stable than the default Vcc reference (which is usually somewhere between 4.5 and 5.2V depending on the power supply used).
xtabe:
I'm not sure how much pulse current there has to be.
More than an Arduino can supply - but most relay modules have a driver built in, so can be controlled directly from the Arduino and a 5V power source - which may of course be the same power source that powers the Arduino, but don't use the Arduino to power the relay instead.
That said, relays are slow and unsuitable for variable-length pulse outputs where you want to create a pulse every second. A more sensible on/off time for a relay is several seconds at a minimum.
You'd better explain a lot more of what you're trying to do, as it has the hallmarks of an XY problem..
My bad, too many years of using 2-10 volts (500 Ohm) and 1-5 volts (250 Ohm) and even then I posted it wrong. Before Arduino was part of my life. Thank you for pointing that out.
Anyway I have no clue where the thread starter is looking to go with any of this and information is slow in coming.
Sorry for the slow replies. We are living in interesting and changing times, as you know.
Ron,
Thanks for the link to the flow sensor pulse reading post - interesting reading.
Wvmarle,
Good point on the relay on time. I'll see if I can make it work with the arduino's output.
Here's my (very simple) code so far:
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
float voltsum = 0; //create variable & initial value
}
// the loop function runs over and over again forever
void loop() {
float voltsum = 0;
while (voltsum < 20) {
// one second delay
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(900); // wait
int sensorValue = analogRead(A0); // read the input on analog pin 0
float voltage = sensorValue * (5.0 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V)
voltsum = voltsum + voltage;
Serial.print ("Voltage "); // prints the word
Serial.println (voltage); // print out the value you read and go to next line
Serial.print ("Sum ");
Serial.println (voltsum);}