Hello, I'm working on my first bigger project. I want to control pressure in system with potentiometer. Value from potentiometer is converted to 0-100 [%] and it should be equal to cca 0-30000 [Pa] pressure in system. I have small compressor, pressure sensor, lcd and air valve (all supplied by DC power externaly). The initialization and calibration of air in the system should start only when value on potentiometer will change. I'm not sure what I'm doing wrong but it everytime stuck on "while" contition.
I'll be glad for any idea, how to solve it. Thank you in advance.
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
// Potenciometr
int analogInput_0 = A0; // Potentiometer at Analog 0
int potRaw; // Potentimeter value (0-1023)
int potPercent; // Potentimeter value (0-100)
int lastPotPercent=0; // Potentimeter value from previous step
// Senzor tlaku
int analogInput_1 = A1; // Pressure sensor at Analog 1
int pressureRaw; // Pressure value (0-1023)
float pressure; // Pressure value (0-400000 [Pa])
int pressurePercent; // Pressure percentage (30000 Pa = 100%) - it is the limit I want to reach
// Motor and valves
int digitalOutput_4 = 4; // Compressor for inflating
int digitalOutput_5 = 5; // Valve for air bleed
int value;
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the I2C bus address for an unmodified backpack
void setup()
{
Serial.begin(9600);
pinMode (analogInput_0, INPUT);
pinMode (digitalOutput_4, OUTPUT);
pinMode (digitalOutput_5, OUTPUT);
// actiavtion of LCD
lcd.begin (16,2); // pro 16 x 2 LCD display
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
pinMode(analogInput_1, INPUT);
}
void loop()
{
potRaw = analogRead(analogInput_0);
pressureRaw = analogRead(analogInput_1);
pressure = abs(map(pressureRaw, 0, 1023, 0, 400000));
pressurePercent = pressure/300;
potPercent = abs(map(potRaw, 0, 1023, 0, 100));
if (potPercent != lastPotPercent)
{
value = min(pressurePercent, potPercent);
// Turn on compressor
if (value = pressurePercent)
while (pressurePercent < potPercent)
{
digitalWrite(4, HIGH);
}
else
{
digitalWrite(4, LOW);
}
// Turn on valve for air bleed
while (pressurePercent > potPercent)
if (value = potPercent)
{
digitalWrite(5, HIGH);
}
else
{
digitalWrite(5, LOW);
}
}
lastPotPercent = potPercent;
lcd.home ();
lcd.print(pressurePercent, 1);
lcd.print(" % Press");
lcd.setCursor (0,1);
lcd.print(potPercent, 1);
lcd.print(" % Pot");
delay(50);
}