So I have a pressure sensor measuring the pressure of a small tank, when the pressure gets too low it turns on compressor and turns it off after it gets to the required pressure.
that system works fine no issues, its only when there is a quick and dramatic change in pressure that there is a problem.
The quick change in pressure is a pneumatic piston firing, the serial print reads steady when the piston fires out it is still steady. when it goes back in/ fires the other way the serial print reads
"395.⸮404.00" instead of "404.00" , this makes the compressor relay switch and messes with everything.
what makes it read with the reverse question mark and how can i stop it?
thanks
You're getting buffer overrun. It starts to send the one value, a rapid change hits and the sensor changes its mind mid update. The inverted ? is the overlap. Read it again until you get a clean reading.
Up the baud rate if you can.
Could be electrical noise from the compressor motor, appearing in the sensor connections.
That was also my first thought.
The compressor is off when this is happening it comes on when the pressure is too low or when this issue happens and it thinks it needs to turn on again.
Thanks I'll give it a go tomorrow
I've never seen code that allows a new sensor reading to be reported before the current or last one has been reported. So normally this couldn't happen...
how do i post my code ive never used this before.
Upper right corner of the IDE, or in the menu "copy for forum"
const int compressor = 11;
const int piston = 12;
const int pressureIn = A1;
const int button = 2;
const int testlight = 13;
int buttonstate ;
float Pressure = 0;
// pressure scan timer
const unsigned long period = 1000;
unsigned long previousTime = 0;
void setup() {
// put your setup code here, to run once:
pinMode (compressor,OUTPUT);
pinMode (piston,OUTPUT);
pinMode (button, INPUT);
pinMode (pressureIn, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
buttonstate = digitalRead ( button);
if (buttonstate == HIGH){
digitalWrite (testlight, HIGH);
digitalWrite (piston, LOW);
}
else if (buttonstate == LOW){
digitalWrite (testlight, LOW);
digitalWrite (piston, HIGH);
}
// timed pressure reading
unsigned long currentTime = millis();
if (currentTime - previousTime >= period){
Pressure = analogRead (pressureIn);
Serial.println (Pressure);
}
if (Pressure < 300){
digitalWrite (test , HIGH);
}
if (Pressure > 600){
digitalWrite (test , LOW);
}
}
I have added the timed reading with out testing idk if it will fix it. im hoping with this timer it wont catch the dodgy reading. I am a big noob with this if you couldnt tell. will this timed reading only update the "pressure" every second?
Where is the variable 'test' defined? It looks like you didn't post compilable code...
that should be compressor sorry i meant to change that before i sent
The serial buffer is still transmitting when you switch the compressor... if you want to wait for it to be fully sent, you have to use flush().
It wouldn't be consistent if it was noise. If the last couple of digits are consistently dropped it's being overrun.
Show me where the code problem is then.
Please post the actual code that produces the flaw, in a new message, just to keep things on track. Also try running the problem code with the compressor disconnected.
const int compressor = 11;
const int piston = 12;
const int pressureIn = A1;
const int button = 2;
const int testlight = 13;
int buttonstate ;
float Pressure = 0;
void setup() {
// put your setup code here, to run once:
pinMode (compressor,OUTPUT);
pinMode (piston,OUTPUT);
pinMode (button, INPUT);
pinMode (pressureIn, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
buttonstate = digitalRead ( button);
if (buttonstate == HIGH){
digitalWrite (testlight, HIGH);
digitalWrite (piston, LOW);
}
else if (buttonstate == LOW){
digitalWrite (testlight, LOW);
digitalWrite (piston, HIGH);
}
Pressure = analogRead (pressureIn);
Serial.println (Pressure);
delay(1000)
}
if (Pressure < 300){
digitalWrite (compressor , HIGH);
}
if (Pressure > 600){
digitalWrite (compressor , LOW);
}
}
The compressor relay disconnected if there is one, not just the compressor...