Skip to content

Instantly share code, notes, and snippets.

@lancehudson
Created October 9, 2016 02:49
Show Gist options
  • Save lancehudson/fa1480407d67444a6012457a7593d454 to your computer and use it in GitHub Desktop.
Save lancehudson/fa1480407d67444a6012457a7593d454 to your computer and use it in GitHub Desktop.
Steam Car Pump Controller
const int RelayPin = 4;
const int WaterSensorPin = A0;
const int SensorWet = 100;
const int MinimumRunTime = 2000;
const int MinimumWaitTime = 2000;
const bool RelayOn = LOW;
const bool RelayOff = HIGH;
bool relayState = false;
void setup()
{
Serial.begin(9600);
digitalWrite(RelayPin, RelayOff); // Turn off relay
Serial.println(F("RelayOff"));
pinMode(RelayPin, OUTPUT); // Set RelayPin as output
}
void loop()
{
int sensorValue = analogRead(WaterSensorPin);
Serial.println(sensorValue);
bool sensorState = sensorValue >= SensorWet;
if(sensorState != relayState) {
relayState = sensorState;
if(relayState) {
digitalWrite(RelayPin, RelayOn); // Turn on relay
Serial.println(F("RelayOn"));
delay(MinimumRunTime);
} else {
digitalWrite(RelayPin, RelayOff); // Turn off relay
Serial.println(F("RelayOff"));
delay(MinimumWaitTime);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment