Arduino Forum

Using Arduino => Programming Questions => Topic started by: Adam212 on Nov 01, 2014, 08:56 pm

Title: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: Adam212 on Nov 01, 2014, 08:56 pm
i'm new with Arduino ,may anyone help me to know  how can i read pulse ,or  4-20 mA output? 
i have this sensor (micronics flow meters U1000) , it's working fine, but i don't know how to read the output from Arduino.
here is the manual of flow meters sensor:
http://www.micronicsflowmeters.com/newestpdfs/Micronics-U1000-Issue2-1.pdf
Thanks in advance
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: larryd on Nov 01, 2014, 09:15 pm
Quote
how can i read pulse
Use the pulseIn() function
http://arduino.cc/en/Reference/pulseIn (http://arduino.cc/en/Reference/pulseIn)

Quote
4-20 mA output
Use a 250 ohm resistor with an analog input. Gives 1-5volts
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: KenF on Nov 01, 2014, 09:21 pm
Read down further.  It can produce a pulse.  THIS is the ideal interface for the arduino.  This can easily be used to drive an opto issolator that can then be read by one of the digital input pins.  Timing the pulses can then give a flow rate.

The device is even configurable for what flow is represented by each pulse.

Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: Adam212 on Nov 02, 2014, 10:08 am
Thanks LarryD
Thanks KenF
i already tried pulseIn() function ,but its not working i got only 0 value in the result ,may be i did something wrong with he connection.

The polarity of the wires is as follows:
Brown wire: 24V Input
Blue wire: 24V Return
white wire: Pulse Output
Green wire: Pulse Return
Red wire: 4-20mA Output (+)
Black wire: 4-20mA Return (-)

i connected white wire(Pulse Output) to pin number (2) and Green wire(Pulse Return) to Arduino GND between pin 13 and AREF , but i got only 0 as a result.

here is a sample code:

int pin = 2;
unsigned long duration;

void setup()
{
  pinMode(pin, INPUT);
  Serial.begin(9600);
  Serial.println("Started");
}

void loop()
{
  duration = pulseIn(pin, HIGH);
  Serial.println(duration, DEC);
}

but i got only 0 as a result in my hyper-terminal, so may you help me to get the correct pulse?
and how can i get pulse count from the duration ?

once again thanks in advance.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: KenF on Nov 02, 2014, 12:40 pm
I never mentioned the pulsein function.  I was talking about the pulse signal on your device. 
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: Adam212 on Nov 02, 2014, 12:59 pm
Thanks Kenf , yes so sorry i miss understood , i already set the configuration of (Micronics flow meters U1000) to give me pulse output , and it's working fine , and i can see the water level in the display , but when i try to use  pulseIn() with pin 2 like this code i got only 0

unsigned long duration;

void setup()
{
  pinMode(pin, INPUT);
  Serial.begin(9600);
  Serial.println("Started");
}

void loop()
{
  duration = pulseIn(pin, HIGH);
  Serial.println(duration, DEC);
}
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: robtillaart on Nov 02, 2014, 01:04 pm
moderator: cross-post in sensors deleted. 
Please keep your questions in one thread, saves time for everybody.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: Adam212 on Nov 02, 2014, 01:19 pm
Sorry robtillaart ,I'm new and i don't know which thread i need to put my question , because it's programming and sensor issues , that is why i put my question in both of programming and sensor thread.
once again , I'm sorry.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: KenF on Nov 02, 2014, 01:56 pm
Looking at the diagram on page 9 of the datasheet shows the "pulse" connections as the grey and green wires.  (not the red and black)

Grey is "pulse output" whereas Green= "pulse return"

Then on page 21 we have a rather useful looking table that tells us that the "pulse output" is "Opto-isolated MOSFET volt free normally open contact"

So what we have is a pair of wires that are connected to the mosfet side of an opto issolator.  It will not have any signal on it unless your circuit provides the power.

What I think you need to do is provide 5v from your arduino to the silver wire via a a suitable resistor (say 4.7K) and connect the green wire to your arduino GND.  You can then take your reading from the silver wire (at it's junction with the resistor)

Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: Adam212 on Nov 02, 2014, 02:19 pm
Thanks KenF , i will test it and comeback to you.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: dlloyd on Nov 02, 2014, 02:28 pm
Quote
... but when i try to use  pulseIn() with pin 2 like this code i got only 0
The pulseIn() is a blocking function and is not required for this very capable and accurate instrument, as your U1000 has both analog and pulse outputs.

The output is a MOSFET relay type and the electronic normlly-opened contacts are "dry" (high impedance) when open. At the Arduino end, I would connect one end of a 1K resistor to the white wire and the other end to GND. Also, the green wire needs to be connected to GND. You should now get pulses 0-5V on pin 2. EDIT: (as per KenF diagram) These pulses are ideal for totalizing (counting) to record accumulated volume.

The isolated 4-20mA signal can be monitored by using one of the analog inputs of the Arduino. This signal will provide the same information as the digital signal, however you can get accurate and near instantaneous readings which is ideal for monitoring flow rate, data logging, creating flow profiles, etc.
To connect to the Arduino, connect a good quality (temp stable) 250Ω resistor across the red and black wires. Connect the red wire to an analog input and the black wire to GND of the Arduino. This will give a 1-5 volt signal.

Disclaimer: I have never used this device.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: Adam212 on Nov 02, 2014, 02:50 pm
Thanks a lot dlloyd, i will test it and comeback to you.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: Adam212 on Nov 03, 2014, 01:03 pm
Thanks guys ,i tested but still not working. how i can take the reading of U1000  pulse? or in current loop 4 to 20mA? the u1000 is being powered but unfortunately i can't obtain any reading of both output.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: UKHeliBob on Nov 03, 2014, 01:31 pm
Can you please post a schematic of how the device and the Arduino are wired.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: Adam212 on Nov 03, 2014, 02:25 pm
Thanks UKHeliBob,

find below the schematic  image :

http://s23.postimg.org/ylht43xjf/schematic.jpg


and here is the sample code:

int pin = 2;
unsigned long duration;

void setup()
{
 pinMode(pin, INPUT);
 Serial.begin(9600);
 Serial.println("Started");
}

void loop()
{
 duration = pulseIn(pin, HIGH);
 Serial.println(duration, DEC);
}

Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: dlloyd on Nov 03, 2014, 02:33 pm
It looks like in the manual, the outputs can be configured and they also can be turned on or off.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: Adam212 on Nov 03, 2014, 03:07 pm
i already configured  to give me pulse ,and 4-20 mA output , and i can see the result in the device screen.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: dlloyd on Nov 03, 2014, 03:51 pm
Example of connections:

(http://i.imgur.com/Hjicmmz.jpg)

EDIT: You could use a stronger pull-up if needed, i.e. 470 Ω and still be well within the output's max current limit of 500mA.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: dlloyd on Nov 03, 2014, 04:51 pm
You could try something like this to test the digital input:

Code: [Select]
// constants
int pin = 2;  // digital input pin

// variables
unsigned long pulseCount = 0;
boolean inputStatus = LOW;
boolean inputStatusPrevious = LOW;

void setup() {
  pinMode(pin, INPUT);
  Serial.begin(115200);        //115200 for faster response
  Serial.println("Started");
  Serial.println("Pulse Count:");
  Serial.println(pulseCount);
}

void loop()
{
  inputStatus = digitalRead(pin);

  if (inputStatus == HIGH && inputStatusPrevious == LOW) {  //rising edge
    pulseCount++;
    Serial.println(pulseCount);
  }
  inputStatusPrevious = inputStatus;
}
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: Adam212 on Nov 03, 2014, 05:50 pm
Thanks alot for your kind replay , i will check it and come back to you.
once again , Thank you.
Title: Re: How can i read pulse ,or 4-20 mA output from Arduino?
Post by: Adam212 on Nov 06, 2014, 09:10 pm
thanks a lot dlloyd , it's working now , i appreciate your help.
once again thank you dlloyd.