Hey y'all. My project is coming along, but slower than I'd like. I'm to the point where I don't know how to go about this anymore. I am going to use a potentiometer to change the "pressure/weight" value so that I can bench test this system before testing on the machine. I will be able to change the pressure reading and see what the relays do. I am going to have two LCD readouts, a keypad or potentiometer to change the "desired" downforce. So in the code I will tell the system what I want and it will maintain the weight, when I change the pressure, I will do it, but I need to keep the system from chasing its tail. In other words, constantly raising or lowering the pressure to try to get the exact value. Would rounding the "pressure" reading in step values i.e. 10,20,30 psi be better than 20,21,22,23? And how would I do that? I'm getting the pressure reading, then calculating the downforce from there, and I will be telling the system what downforce to achieve.
So in all I have 4 questions:
-
If/Else commands - If the actual is more or less than desired, make the change, within 10lbs, then stop. - Am I close? Or no where near that?
-
If/Else commands - How would I put a buffer in to keep it from being over active i.e. desired is 200, it achieves 215 with the fill relay, then fires the exhaust relay to make it 200 and gets 185, then fires the fill solenoid on and on.
-
If the actual is "X" lbs higher or lower than desired turn pin 13 LOW(light up LED or sound buzzer) - Am I close there? Don't know what that should be yet, I don't want nuisance warnings.
-
How do I go about giving rounded readings? Example - Pressure sensor reads 42 psi, make it show 40 psi, or it reads 66 psi, make it round to 70 psi. I don't know the step value I want yet, but 5 or 10 psi would be fine, so 50,60,70, or 50,55,60,65.
#include <SPI.h>
#include <SoftwareSerial.h>
#include <ArduinoBlue.h>
#include <Wire.h>
int rawValue= 50; // A/D readings
int offset = 51; // zero pressure adjust
int fullScale = 1085; // max pressure (span) adjust
float pressure; // final pressure
float weight; // Actual added downforce
float setpoint;// Desired added downforce
#define BT_SERIAL_RX 11//software serialRX pin
#define BT_SERIAL_TX 10//Software serialTX pin
SoftwareSerial BluetoothSerial(BT_SERIAL_RX, BT_SERIAL_TX);
int Alarm = 13;// alarm control
#define ON 0
#define OFF 1
int IN1 = 6;// relay1(fill) control pin
int IN2 = 5;// relay2(exh) control pin
pinMode(IN1, OUTPUT)
pinMode(IN2, OUTPUT)
digitalWrite(IN1, status_1)
digitalWrite(IN2, status_2)
relay_SetStatus( unsigned char status_1, unsigned char status_2)
void setup() {
Serial.begin(9600);
BluetoothSerial.begin(9600);
relay_init();
pinMode(13, OUTPUT);
}
void loop() {
rawValue = analogRead(A0);// Press sensor signal in
pressure = (rawValue - offset) * 1.2 / (fullScale - offset)*139; // pressure conversion
weight = (pressure * 3.81)-7.15;// pressure to weight conversion
BluetoothSerial.print(pressure,0);// press readout
BluetoothSerial.print(weight,0);// weight readout
if (setpoint < weight){// Setpoint less than actual.... Need to limit it within ~15 lbs
relay_SetStatus(ON,OFF), delay(2000);//turn on RELAY_1(fill)
// Need a smoothing device or ON/OFF pulsing so the system doesnt constantly turn relays on and off/ or turn relay on for "X" milliseconds and check to see if its true or not.
}
else{ // Setpoint more than actual... Need to limit within ~ 15 lbs
relay_SetStatus(OFF, ON), delay(2000);//turn on RELAY_2 (exh)
//Need a smoothing device or ON/OFF pulsing so the system doesnt constantly turn relays on and off/ or turn relay on for "X" milliseconds and check to see if its true or not.
}
if ((weight < setpoint - 40)||(weight > setpoint + 40)){// Warning that actual is out of range
digitalWrite(13, LOW);// sounds alarm or lights up LED.
}
}