@Grumpy_Mike - I am not sure what exactly you mean by only use if statements. I am including code here. If you can elaborate and maybe show me an example as to how to simplify then I'd be glad to try it.
@aarg - Hydraulic vehicle lifts have no down button. Down is controlled manually by a bleed valve that uses gravity to lower the vehicle back to the ground.
#include "Ultrasonic.h"
#include <LiquidCrystal.h>
int clearance; //remaning distance from top of vehicle to top of lift
//Inputs
int upButton = 1; //Input 1 - Digital:Up Button
int bypassButton = 6; //Input 2 - Digital: Bypass Button)
int doorSensor = 9; //Input 3 - Digital: Overhead Door Prox Sensor
int heightLimitSensor = 10; //Input 4 - Digital: Overheight Prox Sensor
Ultrasonic ultrasonic(7,8); //Input 5 - Analog: Lift height Measurement via Ultrasonic Distance Measurement Sensor
//Outputs
int upRelay = 13; //Output 1 - Digital: Lift relay to send power to the lift to raise it
int goodLed = 14; //Output 2 - Digital: All Systems Good led
int faultLed = 15; //Output 3 - Digital: Fault Light
int bypassLed = 16; //Output 4 - Digital: Bypass Active Light
int faultBuzzer = 17; //Output 5 - Digital: Fault Buzzer
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Output 6 - Digital: Dot Matrix Screen
void setup() {
//Inputs
pinMode(upButton, INPUT);
pinMode(bypassButton, INPUT);
pinMode(doorSensor, INPUT);
pinMode(heightLimitSensor, INPUT);
pinMode(heightMeasurementSensor, INPUT);
//Outputs
pinMode(upRelay, OUTPUT);
pinMode(goodLed, OUTPUT);
pinMode(faultLed, OUTPUT);
pinMode(bypassLed, OUTPUT);
pinMode(faultBuzzer, OUTPUT);
pinMode(clearanceDisplay, OUTPUT);
//Initialize LCD
lcd.begin(16, 2);
lcd.print("Starting...");
}
void loop()
{
//Lcd Range Write
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Pearsall Lift");
lcd.setCursor(0, 1);
lcd.print("Distance: ");
lcd.print(ultrasonic.Ranging(CM));
lcd.print("cm");
//16 Cases for combinations of sensors and buttons
if ( upButton && bypassButton && doorSensor && heightLimitSensor ) //Case 1
{
digitalWrite(upRelay, HIGH);
digitalWrite(goodLed, HIGH);
digitalWrite(faultLed, LOW);
digitalWrite(bypassLed, HIGH);
noTone(faultBuzzer);
}
else if ( upButton && bypassButton && doorSensor && !heightLimitSensor ) //Case 2
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, HIGH);
tone(faultBuzzer, 30000);
}
else if ( upButton && bypassButton && !doorSensor && heightLimitSensor ) //Case 3
{
digitalWrite(upRelay, HIGH);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, HIGH);
tone(faultBuzzer, 30000);
}
else if ( upButton && bypassButton && !doorSensor && !heightLimitSensor ) //Case 4
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, HIGH);
tone(faultBuzzer, 30000);
}
else if ( upButton && !bypassButton && doorSensor && heightLimitSensor ) //Case 5
{
digitalWrite(upRelay, HIGH);
digitalWrite(goodLed, HIGH);
digitalWrite(faultLed, LOW);
digitalWrite(bypassLed, LOW);
noTone(faultBuzzer);
}
else if ( upButton && !bypassButton && doorSensor && !heightLimitSensor ) //Case 6
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, LOW);
tone(faultBuzzer, 30000);
}
else if ( upButton && !bypassButton && !doorSensor && heightLimitSensor ) //Case 7
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, LOW);
tone(faultBuzzer, 30000);
}
else if ( upButton && !bypassButton && !doorSensor && !heightLimitSensor ) //Case 8
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, LOW);
tone(faultBuzzer, 30000);
}
else if ( !upButton && bypassButton && doorSensor && heightLimitSensor ) //Case 9
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, HIGH);
digitalWrite(faultLed, LOW);
digitalWrite(bypassLed, HIGH);
noTone(faultBuzzer);
}
else if ( !upButton && bypassButton && doorSensor && !heightLimitSensor ) //Case 10
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, HIGH);
noTone(faultBuzzer);
}
else if ( !upButton && bypassButton && !doorSensor && heightLimitSensor ) //Case 11
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, HIGH);
noTone(faultBuzzer);
}
else if ( !upButton && bypassButton && !doorSensor && !heightLimitSensor ) //Case 12
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, HIGH);
noTone(faultBuzzer);
}
else if ( !upButton && !bypassButton && doorSensor && heightLimitSensor ) //Case 13
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, HIGH);
digitalWrite(faultLed, LOW);
digitalWrite(bypassLed, LOW);
noTone(faultBuzzer);
}
else if ( !upButton && !bypassButton && doorSensor && !heightLimitSensor ) //Case 14
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, LOW);
noTone(faultBuzzer);
}
else if ( !upButton && !bypassButton && !doorSensor && heightLimitSensor ) //Case 15
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, LOW);
noTone(faultBuzzer);
}
else //Case 16
{
digitalWrite(upRelay, LOW);
digitalWrite(goodLed, LOW);
digitalWrite(faultLed, HIGH);
digitalWrite(bypassLed, LOW);
noTone(faultBuzzer);
}
}