Industrial Fuel Flex Sensor

Hiya! Its been 3 days with Arduino & C++ and first post here so excuse me please for any non-sense. thankkss!

I'm trying to read the ethanol sensor values on my OLED screen but no go.

  • The sensor outputs 0-5v which means %0 alcohol for 0.1 volts and %100 alcohol for 5.0 volts.

  • The sensor also sends PWM signals(over same output) which means 1 hertz 1 Celsius degree and 100 hertz means 100 Celsius degree.

So I put this into 2 stage. First reading voltage. Second, reading in hertz.
After experimenting with some libraries I came to here;Failed in both!

The problem is here, I start experimenting with a rotary switch and now I can't translate it to 0-5v and tearing up my hairs.

Here is the code;

#include "U8glib.h"

U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9, 8);  // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9

#define VOL  A0
#define VMAX 1023
int vol_val = 0;
 
 
void setup() {
  pinMode(VOL, INPUT);
  u8g.setColorIndex(1);
  
}

 
void loop() {
 
  vol_val = 0.9 * vol_val + 0.1 * analogRead(VOL);
  //vol_val = 5.0 / 1023.0 * (analogRead (VOL) + 0.5) ;
  byte val = map(vol_val, 0, VMAX, 0, 127);
  //vol_val = map(vol_val, 0, 1023, 0, 255);

 
  u8g.firstPage();
  do {
 
    //u8g.drawBox(0, 60, val, 3);
    u8g.drawBox(26,4,8,34); // This is for big E
    u8g.drawBox(32,4,15,6); // yatay 1
    u8g.drawBox(32,18,15,6); // yatay 2
    u8g.drawBox(32,32,15,6); // yatay 3
    u8g.drawBox(0, 44, val, 22);           // draw gauge
    


 
  } while (u8g.nextPage());
}

The problem here if i modify the code;

vol_val = 5.0 / 1023.0 * (analogRead (VOL) + 0.5) ;

the
u8g.drawBox(0, 44, val, 22);

turns with nothing. The gauge bar doesn't work. I'm also checking val over the serial port screen and it reads 0 or absurd values.(checking with aa size battery)

Could someone guide me to solve the problem.

#include "U8glib.h"

U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9, 8);  // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9

#define VOL  A0
#define VMAX 1024


int val = 0;
const float RefVolts = 5.0; // the default reference on a 5-volt board
const int PilPin = 0; // battery is connected to analog pin 0 
 
void setup() {
  pinMode(VOL, INPUT);
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_unifont);    // choose font
}

/*void draw(void) 
{
  u8g.setFont(u8g_font_profont17r);        // select font
  u8g.drawStr(18, 12, "VOLTAGE"); 
  u8g.setPrintPos(33,40);
  u8g.drawRFrame(15, 20, 100, 30, 10);     // draws frame with rounded edges
  u8g.println(vin);                        //Prints the voltage
  u8g.println("V");
}
*/
 
 
void loop() {
 
 //int val = analogRead(PilPin); // read the value from the sensor
 //float volts = (val / 1023.0) * RefVolts; // calculate the ratio
 float volts = 5.0 / 1024.0 * (analogRead (PilPin) + 0.5) ;
 byte volts = map(val, 0, VMAX, 0, 127);

 //volts = volts*10;

  //vol_val = 0.9 * vol_val + 0.1 * analogRead(VOL);
  //byte val = map(vol_val, 0, VMAX, 0, 127);
 
  u8g.firstPage();
  do {

    u8g.drawBox(0, 44, volts, 22);
    u8g.setPrintPos(100,64);
    u8g.print(volts);
   
 
  } while (u8g.nextPage());
}

I tried this way as well.

i don't see any place in your code where you tried to debug the problem by using Serial.println, etc.

Paul

Okay I missed the whole idea and reworked on the code.
The sensor outputs frequency 50hz to 150hz to show ethanol content %0 to %100.(not voltage)

It works!

Here is the code for whom want to build their own gauge for their cars.
Now I need to calculate the duty cycle since the duty cycle shows the fuel temperature . The code below only shows ethanol percentage.

#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9, 8);

int Sensorpin = 2;  
float pulsetime = 0;
int hertz = 0;



void setup() {
 u8g.setColorIndex(1);             // piksel
 u8g.setFont(u8g_font_fub35n);    // font sec
 
         
  u8g.firstPage();  
 do {
   draw();
   } while( u8g.nextPage() );
 
 // logo suresi
 delay(3000);

}

void loop() {

 pulsetime = pulseIn(Sensorpin, HIGH) + pulseIn(Sensorpin, LOW);
 hertz = int((1000000 / pulsetime) - 51);

 u8g.firstPage();
 do
 {
     
   // Buyuk E harfi icin kutu 
   u8g.drawBox(25,4,8,34); 
   u8g.drawBox(31,4,15,6); 
   u8g.drawBox(31,18,15,6); 
   u8g.drawBox(31,32,15,6); 
   u8g.setPrintPos(49, 39);
   u8g.print(hertz);
   u8g.drawFrame(1, 40, 127, 24);
   u8g.drawBox(2, 41, hertz / 100.0 * 126, 22);       // bar skala    

   
 } while (u8g.nextPage());
 delay(900);
}

Anyone have any idea how can i add a digit to my code?

54 hz for E4
55 hz for E5

so 54.3 hz should be E4.3

Can I do that?

cheers