// 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 ?
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.
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 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 .
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 ?
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.
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 .
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 ?
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.