add arduino sketch and update readme

This commit is contained in:
2023-09-26 22:17:30 +02:00
parent 655276b454
commit e9e72d6d2c
2 changed files with 96 additions and 0 deletions

83
PumpStateMachine.ino Normal file
View File

@@ -0,0 +1,83 @@
#include <StateMachine.h>
const int lowTriggerPin = 2;
const int highTriggerPin = 3;
const int ledPin = 13; // the number of the LED pin
const int relay = 7;
StateMachine machine = StateMachine();
State* S0 = machine.addState(&state0); // Waiting for trigger
State* S1 = machine.addState(&state1); // Pump
State* S2 = machine.addState(&state2); // Stop Pump
void setup() {
Serial.begin(115200);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the waterlevel sensors pin as an input:
pinMode(lowTriggerPin, INPUT);
pinMode(highTriggerPin, INPUT);
// initialize the relay pin:
pinMode(relay, OUTPUT);
S0->addTransition(&transitionS0S1,S1); // S0 transition to S1
S1->addTransition(&transitionS1S2,S2); // S1 transition to S2
S2->addTransition(&transitionS2S0,S0); // S2 transition to S0
S2->addTransition(&transitionS2S1,S1); // S2 transition to S1
}
void loop() {
machine.run();
}
void state0(){
Serial.println("State 0");
Serial.println("waiting for trigger");
}
bool transitionS0S1(){
if(digitalRead(lowTriggerPin) == HIGH && digitalRead(highTriggerPin) == HIGH){
return true;
}
// Should never happen...
if(digitalRead(lowTriggerPin) == LOW && digitalRead(highTriggerPin) == HIGH){
return true;
}
return false;
}
void state1(){
Serial.println("State 1");
Serial.println("Start pumping...");
digitalWrite(ledPin, HIGH);
digitalWrite(relay, HIGH);
}
bool transitionS1S2(){
if(digitalRead(lowTriggerPin) == LOW && digitalRead(highTriggerPin) == LOW){
return true;
}
return false;
}
void state2(){
Serial.println("State 1");
Serial.println("Stop pumping...");
digitalWrite(ledPin, LOW);
digitalWrite(relay, LOW);
}
bool transitionS2S0(){
if(digitalRead(lowTriggerPin) == LOW && digitalRead(highTriggerPin) == LOW){
return true;
}
return false;
}
bool transitionS2S1(){
if(digitalRead(lowTriggerPin) == HIGH && digitalRead(highTriggerPin) == LOW){
return true;
}
return false;
}

View File

@@ -1,2 +1,15 @@
# PumpStateMachine
# DehumidifierPumpController
This is a little program written for an arduino to control a pump with two induction switches.
Used components:
- 2x [Induction Switch](https://www.aliexpress.com/item/32965219918.html?spm=a2g0o.order_list.order_list_main.5.21ef586aXBF9dz) or 1x [Float Switch](https://s.click.aliexpress.com/e/_DCIed4F)
- 1x [Water Pump](https://www.aliexpress.com/item/32859594599.html?spm=a2g0s.9042311.0.0.27424c4dypXzoO)
- 1x [5V Relay](https://www.aliexpress.com/item/32358134833.html?spm=a2g0s.9042311.0.0.27424c4dyynnLY)
- 1x [Arduino Uno R3](https://www.aliexpress.com/item/32831857482.html?spm=a2g0o.productlist.0.0.19f16140AZZgOJ&aem_p4p_detail=202107131539031573662234321060028453385)
- 1x [12v Powersupply](https://s.click.aliexpress.com/e/_AWcEVU)
- 1x [Female DC Jack](https://www.aliexpress.com/item/32815757637.html?spm=a2g0s.9042311.0.0.27424c4dMtkAO7)
- 1x [Box (example)](https://s.click.aliexpress.com/e/_A2Mksa)
- 1x [12v to 5v for the Arduino](https://s.click.aliexpress.com/e/_AtmkyE)
- 1x [Outside connector to connect pump and float switch](https://s.click.aliexpress.com/e/_AVMj3k)