Hi,
i have 2 pressure sensors, whenever the pressure rises like above the value of 2 i want to count that.
my sketch is working perfectly fine, but that counting part is not working at all.
i thought it would be as simple as this:
int Senscount0 = 0;
if (Druck0 >0.01){
Senscount0=Senscount0+1; //or Senscount0++;
}
else{}
but it seems not to be.
When pressure is like below my threshold (here 0.01) it shows me 1 in the display, and if i go to a negative value with the pressure it shows 0 on my display. Going above 0.01 doesnt change the 1.
Could you help me please?
This is my code:
#define Drucksensor0PIN 0 // Analog Pin 0
#define Drucksensor1PIN 1 // Analog Pin 1
#include <math.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h> // F Malpartida's NewLiquidCrystal library
#define I2C_ADDR 0x27 // Define PCF8574A's I2C Address
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define LED_OFF 0
#define LED_ON 1
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
float vcc = 5;
float SpannungSens0;
float Drucksensor0(int ADC0) {
SpannungSens0 = ((ADC0*vcc)/1024.0);
Serial.print(" ");
Serial.print(ADC0);
Serial.print(" ");
return SpannungSens0;
}
float SpannungSens1;
float Drucksensor1(int ADC1) {
SpannungSens1 = ((ADC1*vcc)/1024.0);
Serial.print(" ");
Serial.print(ADC1);
Serial.print(" ");
return SpannungSens1;
}
void setup() {
Serial.begin(9600);
lcd.begin (20,4);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(LED_ON);
}
void loop() {
float SpannungSens0;
float Druck0;
float SpannungSens1;
float Druck1;
int Senscount0 = 0;
SpannungSens0=Drucksensor0(analogRead(Drucksensor0PIN));
SpannungSens1=Drucksensor1(analogRead(Drucksensor1PIN));
lcd.setCursor(5, 1);
Druck0=((((SpannungSens0/5.0)-0.04)/0.09));
Druck1=((((SpannungSens1/5.0)-0.5)/0.2));
lcd.print("p0: ");
lcd.print(10 * Druck0,2);
lcd.print("mbar ");
lcd.setCursor(5, 2);
lcd.print("p1: ");
lcd.print(10 * Druck1,2);
lcd.print("mbar ");
lcd.print (Senscount0);
Serial.print(Druck0 * 10,1);
Serial.print("mbar");
if (Druck0 >0.01){
Senscount0=Senscount0+1;
}
else{}
lcd.setCursor(0, 0);
lcd.print (Senscount0);
Serial.print(Senscount0);
Serial.println("");
delay(2000);
}