need some guidance on codeing

I’m a complete novice at arduino micro controllers and I have been given and assignment were I have to write a code for a suspension system the requirements are below, I wrote the most basic code out to see could I get these parts to work before I add more variable but the code I have written is not operating the way I was expecting it to and I cannot figure out why any help would be appreciated. I will post code in the next post window

Software Requirements

  1. If the pot signal goes “out of range”, eg > 4.75V or <0.25V it is deemed
    to be faulty and the system should stop operating and both outputs should
    turn off.
  2. Ideally the system will try maintain the height of the vehicle
    approximately ½ way between min and max, typically a pot value of
    approx. 2.5V. If the voltage is less than this the compressor should turn
    on. If the voltage is greater than this the exhaust value should turn on.
  3. Hysteresis bands should be added either size of 2.5V to prevent the
    system switching rapidly.
  4. The compressor run time should be limited to 5 minutes, in the event of
    an air leak in the system the compressor should not run continuously

const int senosorPin = A0; // input pin that the pot sensor (pressure sensor) is attached to
int sensorValue = 0; //value read from pot sensor (pressure sensor)
const int compressor =13; //output run signal to compressor
const int exhaustValve= 12; //output run signal to exhaust valve
const int ECUFault = 11; //output fault signal to ECU

void setup() { // initialize the output pins
pinMode(A0, INPUT); //reads the pot value
pinMode(13, OUTPUT); //compressor run signal
pinMode(12, OUTPUT); //exhasut valve run/open signal
pinMode(11, OUTPUT); //Fault output to ECU
}

void loop() {

if(analogRead(A0 >= 4.75)){ //pot value over range; fault
digitalWrite(13,0); //compressor off
digitalWrite(12,0); //valve off
digitalWrite(11,1); //ECU fault on
}
if(analogRead(A0 <= 0.25)){ //pot value under range; fault
digitalWrite(13,0); //compressor off
digitalWrite(12,0); //valve off
digitalWrite(11,1); //ECU fault on
}
if(analogRead(A0 >= 2.01 && A0 <= 3.99)){ //pot value ok
digitalWrite(13,0); //compressor off
digitalWrite(12,0); //valve off
digitalWrite(11,0); // ECU fault off
}
if(analogRead(A0 >= 0.26 && A0 <= 2.0)){ //pot value too low
digitalWrite(13,1); //compressor on
digitalWrite(12,0); //valve off
digitalWrite(11,0); //ECU fault off
//timer required to count to 5min and then stop compressor
}
if(analogRead(A0 >= 4.0 && A0 <=4.74)){ //pot value too high
digitalWrite(13,0); //compressor off
digitalWrite(12,1); //valve on/open
digitalWrite(11,0); // ECU fault off
}
delay(500);
}

Rather than doing a new analogRead() for each test just read it at the start of loop() and save it to a variable. Then use the variable in the tests. That way all the tests use the same value

potVal = analogRead(potPin);

if (potVal > 972) {
   //etc
}

Also analogRead() returns an integer with a value between 0 (0v) and 1023 (5v). It does not produce voltage values. You could convert the number to a floating point voltage number but I suggest you just use the raw values and figure out the test values accordingly. 4.75 volts will be 972 (if my maths is correct).

Also, use variables (or constants) to hold the values of your pin numbers and give them meaningful names. It is easier to understand analogRead(potPin); than analogRead(A0), and much easier to use compressorPin rather than 13.

Finally, use the code button when posting code.

Have fun.

...R

thanks for the advice robin

(analogRead(A0 >= 4.75))

Is A0>=4.75 an analog input pin. Mind the parenthesis.

I had intended to include a link to planning and implementing a program.

...R