How to appropriately connect the FS1012-1002-C01-LQ to a Opamp and to the arduino?

Hello, I recently acquired the FS1012-1002-C01-LQ flow rate sensors for my thesis experimentation setup and I have been having troubles with the output voltage readings in my Arduino. I was wondering if I could be helped with this. I will provide more information. My experimental setup consists on 2 12V DC water pumps and the 2 flow rate sensors to monitor the flow rate these pumps are supplying and I plan to create a simple P-controller using the information of the sensors on flow rate to control the speed of the motor through voltage. In my circuit I have two things going on. The first part of the circuit, consists on having a N-type MOSFET transistor that is used to control the amount of voltage i am supplying to the 12V DC motors and I am using PWM to control the gate of the transistor. The second part of my circuit I have these FS1012-1002-C01-LQ flow rate sensors connected to an Opamp named Opa244 and I am using the single ended circuit (using the non inverting configuration) with the TP2 since I only want to measure fluid. Here I share my circuit configuration.

The problem that I am having is the following:

1. The arduino is reading nonsense values when reading the voltage at the Opamp output but when I disconnect the ground of the arduino that is connected to the transistor circuit, the voltage values that the arduino is reading gets "fixed" and reads a constant value. What is even more strange is that if i send a signal to the gate of the transistor, the voltage readings of the sensor lowers as if there is flow passing by but because the ground is disconnected from the arduino to the transistor circuit the motors do not activate therefore no flow is actually. happening.

2. In the diagram, I use 2 1K ohm resistors for the Opamp circuit but it is just an illustration. I am wondering what is the best way to set the Gain if the behavior of the sensor is not fully linear as from 0 to 0.1 SLPM it has a different slope than from 0.1 to 1 SLMP. Initially I set a gain of 50x because the range that I will be operating is from 0 to 0.1 SLPM but any tips on how to appropriately find the correct gain is also much appreciated. 

I tried connected a grounding cable to both the transistor circuit and Opamp and I still get the same result of nonsense voltage readings. I also tried using a different power source than the arduino 5V to power both the sensor and Opamp and still the same.

This is my first time using Opamps so I am still learning how to use them. In theory it seems simple enough but I am having these issues that I do not know how to solve. If more information is needed please let me know.

Here is my code and the spreadsheet of the Opamp.

//Motor 1 digtal pins

int motor1_Controlpin = 3;

//Motor 2 digtal pins

int motor2_Controlpin = 5;

//pulsation delay
int Motor_1_delayTime = 25;
int Motor_2_delayTime = 25;


//Voltage reading
int readPin = A0;
int readBits1;
float Volt1 = 0;
int PrintdelayTime = 50;


void setup() {
  // put your setup code here, to run once:

  pinMode(readPin, INPUT);
  Serial.begin(9600);

  pinMode(motor1_Controlpin, OUTPUT);
 
  pinMode(motor2_Controlpin, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  readBits1 = analogRead(readPin);
  Volt1 = (5./1023.) * readBits1;
  Serial.println(Volt1);
  delay(PrintdelayTime);
  
  analogWrite(motor1_Controlpin, 70); // analogWrite (pin, 0) = 0V i.o.w off! 
  delay(Motor_1_delayTime);
  analogWrite(motor1_Controlpin, 0); // analogWrite (pin, 0) = 0V i.o.w off! 
  delay(Motor_1_delayTime);// analogWrite (pin, 255) = 12V i.o.w max speed!

  analogWrite(motor2_Controlpin, 90); // analogWrite (pin, 0) = 0V i.o.w off! 
  delay(Motor_2_delayTime);
  analogWrite(motor2_Controlpin, 0); // analogWrite (pin, 0) = 0V i.o.w off! 
  delay(Motor_2_delayTime);// analogWrite (pin, 255) = 12V i.o.w max speed!
  
  
}

 

  • Hi KO!

    Thank you for the request. Your request in our Renesas Flow sensor is very valuable to us. We have acknowledged your request; we are working on that and very soon we will give you update regarding this.

    Regards:

    Raja.

  • Hi,

    I have gone through your circuit schematic, and I have marked some changes in your schematic please do that changes and share the latest results with us so that I could better understand sensor behaviors in more detail and one more thing I observed that you told initially you set the gain 50, Can you please tell me how you can set the gain 50 using same resistance value that you have used in opamp?

    The FS1012 requires a full amplification circuit and microcontroller for most applications. Depending on your flow range, you will need to set the amplification properly, scaling the FS1012 output to your full flow range. Apart from that, you can also conduct another setup without using the opamp and observed the reading and after you connect opamp and measured those reading and also share those reading with us so that I would understand the sensor behavior in better way.

     

    Regards:

    Raja.

  • Greetings Raja, 

    Thank you for the reply. I made a mistake when making the circuit schematic, I indeed connected the arduino 5V into the circuit just like you mentioned. I tried connecting the extra ground just as you mentioned and I still get the same uncontrolled readings. I will show you what happens when I connect the ground of the arduino to the circuit.

    When I turn on the motor to push the fluid, the readings do not change and stays doing this. What is more strange is that when I use a multimeter to measure the voltages, the multimeter outputs 4.30 when there is no flow and around 3.8V when there is flow. 

    In regards to the gain. In the circuit diagram I placed two of the same resistors but it was just to illustrate how I am setting up the circuit. The way I am setting a gain of 50 is by placing resistors in series that connect from the Vout of the Opamp. Since the gain in the non inverse Opamp is measured by 1+R1/R2. In this case R1 would be the one connected directly to the Vout. I set a gain of 50 because the range that I want to use from to sensor is 0 to 0.1SLMP. I wanted to set that at 0.1SLPM the arduino would read 5V minus the 0.70V that the sensor takes. 

    Kind Regards,

  • Hi,

    Thank you for the response. I am working on your issue just give some time, meanwhile I have attached application notes please go through that and check your Arduino codes with the reference one and please let me know if the problem persists.

    /cfs-file/__key/communityserver-discussions-components-files/291/Application-Note_5F00_User-Guide-for-FS1012-Flow-Sensor-with-Arduino-Uno.docx

    Regards:

    raja.

  • Hi Raja,

    I was able to find out what was the issue with my readings. in Page 4 of the Word document that you shared it mentions that the sensor (-TP2) need to be connected to a separate ground and not connect it to the ground of the Opamp circuit. I did that and the values steadied and afterwards I used the code that is in the word document to better the resolution and I got the following results.

    After "fixing this" I went Ahead and tried to find the appropriate gain for the non inverting Opamp. I did this by trial and error until I got close to 5V when there is no flow. The result of doing this is what you can see in the video. What is strange is that one sensor at no flow and without the amplification of the Opamp has a reading of 106mV and the other of 129mV. This made the gains to be completely different. The one with 106mV has a gain of 15.17 and the one with 129mV has a gain of 9.46. At first I didnt think much of it because both sensors with these gains have a reading close to 5V. When I tried to calibrate these sensors I found out that there is something very wrong. Here is the result of the flow rate Vs voltage reading with the gains.

    the flow rate range in which i want to operate is from 0 to 0.1SLPM. (let me remark that the graph is on mL/s). The result is clearly not usable. Is there any advice which could help me solve this issue?

    Kind Regards, 

  • Hi,

    Thank you for the response. Can you share the discrete data of Flow rate and corresponding output voltage without amplification and with amplification? Try to plot output voltage (y axis) vs flow rate (x axis) for better visualization of the graph with the reference and also tell me the opamp gain (like 20 or 30..) that you have used in your experiments. you can also change the supply voltage to 3.3v and see the deviation with reference (given in the data sheet) under no flow condition.

    Regards:

    Raja.

  • Hi,

    The flow sensor measures the following readings without the gain sensor 1: 102mV and sensor 2: 127mV.  The Gain of sensor 1 is of 15.14 and the gain of sensor 2 is 9.46. The gain was set until the voltage reading in the arduino measured approx 5V. A power supply of 6 Volts was used but I used a voltage divider to lower the Voltage to 5.7. I choose 5.7 because the sensors takes away 0.7V. 

    I noticed the following when using different power sources. I measured the No flow voltage of the sensors without the gain using 3.3V, 5V, 5.55V, and 5.8V. The result is the following:

    At 3.3V no flow, no gain: 

    Sensor 1: 34mV

    Sensor 2: 43mV

    At 5V no flow, no gain: 

    Sensor 1: 78mV

    Sensor 2: 100mV

    At 5.55V no flow, no gain: 

    Sensor 1: 95mV

    Sensor 2:117mV

    At 5.8V no flow, no gain: 

    Sensor 1: 100mV

    Sensor 2: 124mV

    I did not use the 3.3V voltage input because I would need a higher resolution so I used 5V. I wanted to obtain the equation calibrated curve to use it to control the motor speeds. 

    I changed the graph as you suggested and I will include the discrete data with the Gain. 

    Sensor 1 Results (with Gain) Sensor 2 Results (with Gain)
    Avg Voltage Flow Rate [mL/s] Avg Voltage Flow Rate [mL/s]
    4.132 0 4.467428571 0
    3.519428571 0.00700106 4.498 0
    3.201428571 0.07486848 4.455142857 0
    2.951142857 0.160167111 4.12 0.017002575
    3.294285714 0.524365118 3.741714286 0.0983006
    3.359428571 0.714679651 3.548285714 0.161024384
    3.458857143 0.901707973 3.468571429 0.211031956
    3.658857143 1.15474629 3.404 0.283900133
    3.699428571 1.38406673 3.290285714 0.355339523
    3.700285714 1.59467005 3.174571429 0.422921185
    3.423142857 1.755694434 3.338 0.510648755
    3.272857143 1.936578968 3.273428571 0.626094809
    3.330571429 2.085030019 3.295428571 1.02258342
    3.162 2.472660146 3.036 1.148602503
    3.165428571 2.714411039 2.681714286 1.617673533
    3.118 3.121615559 2.598571429 1.871712002
    3.242285714 3.330647212 2.588285714 2.124464562
    3.037714286 3.522533412 2.368857143 2.418794846
    3.16 3.70884734 2.313428571 2.849431485
    3.139142857 4.029895956 2.173142857 3.26778055
    3.168571429 4.919316354 2.154571429 4.864879539

    The reason Why i did not include the No gain data is because the arduino reads the following 

    This is very odd. as the multimeter reads 0.1 V and 0.127 V not 0.40V. I used the code that was provided in the word document. the only thing I added was just turning the byts readings to Voltage. The sensor readings code starts at line 137.

    //Desired Flow Rate Determination
      float Desired_VFR = 1e-6; // [m^3/s] CI
    
    // Control Variables
      float PWM_1;
      float PWM_2;
      float Cal_PWM = 50; // This is used ONLY FOR CALIBRATION
      float error_1 = 0;
      float error_2 = 0;
      float PWM_error_1 = 0;
      float PWM_error_2 = 0;
      float Output_VFR_1 = 0; 
      float Output_VFR_2 = 0;
    
      //P-Controller Gain
        float K_Gain_1 = 1; //CI
        float K_Gain_2 = 1; //CI
    
    //Time
      float CurrentTime = 0;
    
    //Motor Information
      //Motor 1 digtal pins
        const int motor1_Controlpin = 3;
    
      //Motor 2 digtal pins
        const int motor2_Controlpin = 5;
    
      //pulsation delays
        int Motor_1_delayTime = 25; //CI
        int Motor_2_delayTime = 25; //CI
    
    
    //Voltage reading flow sensors
    
     //====Flow Sensor 1 to Motor 1 ============
      const int sensor_1_readPin = A0;
      //int readBits1;
      float Volt1 = 0;
    
      // Variables for Motor 1
          int sensorValue_1 = 0;               // value read from the flow sensor
          float sensorAverage_1 = 0.0;         // average sensor value
    
    
       //====Flow Sensor 2 to Motor 2 ===========
        const int sensor_2_readPin = A1;
        //int readBits2;
        float Volt2 = 0;
    
       // Variables for Motor 2
        int sensorValue_2 = 0;               // value read from the flow sensor
        float sensorAverage_2 = 0.0;         // average sensor value
    
    // Data Sampling Configuration for flow sensors
      const int sampleAverage = 20;  //CI    // number of sensor samples to average    
      const int serialRateOutput = 100;  //CI // sample output rate in ms
      const int analogSampleDelay = 2;   //CI // sample delay for analog sampling in ms
    
    // Button To start Program
      /*int ButtonPin = 1;
      int ButtonNew;
      int ButtonOld = 0;*/
      int StopSystem = 20; // seconds to let the system run
    
    void setup() {
      // put your setup code here, to run once:  
    
      // initialize serial communications at 9600 bps:
        Serial.begin(9600);
    
      //Button read
        //pinMode(ButtonPin, INPUT);
    
      // Recieve bits analog values of Sensor
        pinMode(sensor_1_readPin, INPUT);
        pinMode(sensor_2_readPin, INPUT);
    
      // set internal analog reference to 1.1V
        analogReference(INTERNAL);
    
      // Configure Digital Pins
        pinMode(motor1_Controlpin, OUTPUT);
        pinMode(motor2_Controlpin, OUTPUT);
    
      // print the results to the serial monitor:
        Serial.print("\n");
        Serial.print("Time:" );
        Serial.print("\t");
        Serial.print("\t");
        Serial.print("\t");
        
        Serial.print("Flow Sensor 1:" ); 
        Serial.print("\t");
        Serial.print("\t");
    
        Serial.println("Flow Sensor 2:" );
        //Serial.print("\t");
        //Serial.print("\t");
    
        /*Serial.print("Flow Rate 1:" ); 
        Serial.print("\t");
        Serial.print("\t");
    
        Serial.println("Flow Rate 2:" );*/
     
      //Calculation of PWM with desired Flow Rated
    
      PWM_1 = Cal_PWM;
      PWM_2 = Cal_PWM;
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
       
        while (CurrentTime/1000 < StopSystem){
    
          CurrentTime = millis();
    
          Serial.print(CurrentTime/1000);
          Serial.print("\t");
          Serial.print("\t");  
          Serial.print("\t"); 
          //========================================= Motor Parameters ==========================================
    
          analogWrite(motor1_Controlpin, PWM_1); // analogWrite (pin, 0) = 0V i.o.w off! 
          delay(Motor_1_delayTime);
          analogWrite(motor1_Controlpin, 0); // analogWrite (pin, 0) = 0V i.o.w off! 
          delay(Motor_1_delayTime);// analogWrite (pin, 255) = 12V i.o.w max speed!
    
          analogWrite(motor2_Controlpin, PWM_2); // analogWrite (pin, 0) = 0V i.o.w off! 
          delay(Motor_2_delayTime);
          analogWrite(motor2_Controlpin, 0); // analogWrite (pin, 0) = 0V i.o.w off!
          delay(Motor_2_delayTime);// analogWrite (pin, 255) = 12V i.o.w max speed!
    
          //========================================= Sensor Readings ==========================================
    
            /*readBits1 = analogRead(sensor_2_readPin);
            Volt1 = (5./1023.) * readBits1;
            Serial.println(Volt1);
            delay(PrintdelayTime);*/
    
            // initialize average sensor value
            sensorAverage_1 = 0.0;
            sensorAverage_2 = 0.0;
    
            // read and accumulate sensor measurements
            for(int i = 0; i < sampleAverage; i++)
            {
              // read the analog in value:
              sensorValue_1 = analogRead(sensor_1_readPin);
              sensorValue_2 = analogRead(sensor_2_readPin);
    
              // wait for the analog-to-digital converter 
              // to settle after the last reading:
              delay(analogSampleDelay);
              
              // accumulate sensor data
              sensorAverage_1 = sensorAverage_1 + sensorValue_1;
              sensorAverage_2 = sensorAverage_2 + sensorValue_2;
    
            }  
    
            // calculate sensor average
            sensorAverage_1 = sensorAverage_1 / sampleAverage;
            sensorAverage_2 = sensorAverage_2 / sampleAverage;
    
            // Convert Bits to Voltage Readings
            Volt1 = (5./1023.) * sensorAverage_1;
            Volt2 = (5./1023.) * sensorAverage_2;
    
            // Convert Voltage reading into Flow Rate Readiing
    
            Output_VFR_1 = 0;
            Output_VFR_2 = 0;
    
    
            // print the results to the serial monitor:
          
            Serial.print(Volt1);
            Serial.print("\t");
            Serial.print("\t");  
            Serial.print("\t");     
            
            Serial.println(Volt2);
            /*Serial.print("\t");
            Serial.print("\t");  
            Serial.print("\t");
    
            Serial.print(Output_VFR_1);
            Serial.print("\t");
            Serial.print("\t");  
            Serial.print("\t");      
    
            Serial.println(Output_VFR_2);*/
    
            // wait to ensure at least 100ms between each serial print
            delay(serialRateOutput - (sampleAverage * analogSampleDelay));         
    
    
          //========================================= Motor Control ==========================================
            
            //P-Controller
    
            //error_1 = Desired_VFR - Output_VFR_1;
            //error_2 = Desired_VFR - Output_VFR_2;
    
            //PWM_error_1 = error_1 * ;
            //PWM_error_2 = error_2 * ;
    
            // PWM_1 = PWM_1 + K_Gain_1 * PWM_error_1;
            // PWM_2 = PWM_2 + K_Gain_2 * PWM_error_2;
        }
    
    }