Ifm flowsensor to arduino

Hello all ,
i am new in this all arduino , code or in electricals things .

basically i need guidence related to code. i am using SM7050 flow sensor with arduino uno .
SM7050 - Magnetic-inductive flow meter - ifm

// Define the analog input pin (for sensor's voltage output)
const int sensorPin = A0;  // Connect the sensor output to A0

// Flow rate parameters for SM7050 (4-20mA to 0.2-50 LPM conversion)
const float minVoltage = 0.88;  // Voltage corresponding to 0.2 LPM
const float maxVoltage = 4.4;   // Voltage corresponding to 50 LPM
const float minFlow = 0.2;      // Minimum flow rate in LPM
const float maxFlow = 50.0;     // Maximum flow rate in LPM

void setup() {
  // Initialize Serial Monitor for debugging
  Serial.begin(9600);
  Serial.println("Starting flow rate measurement...");
}

void loop() {
  // Read the analog value from the sensor
  int sensorValue = analogRead(sensorPin);
  
  // Convert the sensor value (0-1023) to a voltage (0-5V)
  float voltage = sensorValue * (5.0 / 1023.0);
  
  // Map the voltage to a flow rate (LPM)
  // The voltage from the sensor is between 0.88V (0.2 LPM) and 4.4V (50 LPM)
  float flowRateLPM = map(voltage, minVoltage, maxVoltage, minFlow, maxFlow);
  
  // Convert flow rate from LPM (liters per minute) to mL/s (milliliters per second)
  float flowRateMLsec = flowRateLPM * 1000.0 / 60.0;  // 1 LPM = 1000 mL / 60 seconds
  
  // Print the flow rate in mL/s to the Serial Monitor
  Serial.print("Flow Rate: ");
  Serial.print(flowRateMLsec);
  Serial.println(" mL/s");
  
  // Add a small delay for readability (1 second)
  delay(1000);  // Update every 1 second
}
```
 this is my code and i am aiming to get data of flow rate in mls 
this make sense ?

Welcome, and thanks for posting using code tags :+1:

Is this the correct datasheet for your sensor: SM7050-02_EN-GB.pdf (289.0 KB)

It looks like it has 2 ways of communicating the readings - via a 4-20mA output or a serial link called IO-Link.

You can't read a 4-20mA output directly using an Arduino analogue input pin. Have a look at this discussion for a simple solution:

Also, there is an Arduino IO-Link library here which may be useful:
https://docs.arduino.cc/libraries/lwiolink/
There may be other IO-Link libraries for Arduino as well.

2 Likes

Hi, @js13ropa
Welcome to the forum.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks... Tom.... :smiley: :+1: :coffee: :australia:

1 Like

thanks for the reply ,
i am attaching pic of circut here

here i have took 24 volt dc power supply so + and - of power supply i connected to bread board then sensor has + and - so this i have connected to +- on breadboard . then output is 4-20 ma so i connected to 220 ohm resistor and second leg of resistor to the - rail . then - rail to the gnd on arduino uno then junction of output from sensor end first leg of resistor to the A0 pin on arduino .

where in circuit from sensor blue is - , brawn is + and green is output (4-20ma)

Hi, @js13ropa

Can you see the voltage across the 220R resistor change with flow rate, using a DMM?

Tom.... :smiley: :+1: :coffee: :australia:

Yes

However you have it connected wrong and may have damaged the Uno

i havent built it physical circuit . before that i want to be sure so nothing happen wrong.

thanks

Hi
you mean my conections in circuit ? if yes then please correct me .

thanks

Connect the Brown wire to +24V.
Connect the Blue wire to -24V and as shown below

hi sorry but i am not able to understand this stuff . but again i am trying to describing my circuit. as you can seen in circuit there is three wire from sensor blue , green , brown and at bottom left side 24 volt power supply ( red is + and black is - ) where as sensor need this to power on .

so blue wire which is negative (- ) of sensor and brown is positive (+) of sensor and green is output 4-20ma .

so what i did in circuit connect +- of power supply to +- of bread board then +- of sensor to the +- rail of breadboard . output of sensor connect to 220 ohm resistor leg and another leg to the - rail on bread board then this - rail to the GND on arduino uno . at last junction at first leg connected to the A0 pin on arduino uno.

at last it will be easy to follow your instruction if you explain me in reference of my pic .

thanks

OK give me a few minutes but you will need the following parts
220 resistor
1K resistor
Two 1N5819 diodes

hi thank

as you told me this circuit is okay ? . why i did this because just to confirm here - of power supply connected to - rail then - rail to end of 220 ohm resistor and there is also connect - of sensor .

and could you let me know why you gave me advice to use 220 , 1k , and diode ?.

why as i used earlier only one 220 ohm is not okay ?

why here we have to connect 5v to the cathode of diode ?

also help me in code

thanks a lot

The 220 converts the 4-20mA current to voltage 0.88 to 4.4V as described in your code.
The diodes and 1K resistor are there to protect the Uno from overvoltages and negative voltages, don't leave them out.

By connecting the cathode of the one diode to 5V it will clamp the voltage on A0 to 5V in case you have an overvoltage.
The other diode protects against negative voltages.

As I already stated, your code is OK

Thank you so much for clarification at last please let me know this in circuit which i uploaded,
here - of power supply connected to - rail then - rail to end of 220 ohm resistor and there is also connect - of sensor . this is not an issue right .

thanks

For prototyping and testing it's OK but I would not use solderless breadboards for a permanent installation. They can be very unreliable.

1 Like


here i am using ADS1115 then my connection are okay .
one more question i am using 24 volt dc , 4 ampere power source for sensor and currently i am using arduino to my laptop for uploading code and see how its work ( i mean by usb cable ) , is this okay ?

What is the reason for using the ADS1115?
You changed the 1K resistor to 220. It should be 1K

i am using 24 volt dc , 4 ampere power

The sensor only use 95mA so you could use a much smaller supply.

sensor is power up with this 24 volt dc and 4 a . i have checked across resistor it will give me 0.878 volt and 4 ma from white wire . but when during flowing for 3 to 4 second i can notice voltage go till 0.895 volt but flow rate shoing 0 and it may be reason of flow is below 0.2 lpm or something else while from manufacturer they told me yes you can measure flow for 3 sec cycle 10 ml to 2500 ml , for 6 second cycle can measure 20 to 5000 ml , but showing me 0 flow rate while using mentioned previous post code , so i thought asd115 for better resolution but i getting nothing .

at last i didnt replaced 1k resistor its there in circuit have one 220 ohm and one 1k ohm.

Instead of using map, use this function to compute flow
float flowRateLPM = (14.148 * voltage) - 12.25;

It's the equation of the flow vs voltage