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.
