diff --git a/README.md b/README.md index 6b1f26a..b124a27 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ -# arduino-touchless-projects +# Arduino touchless projects +### Versions + +- **touchless_basic**: Läuft so lange, wie man die Hand in Reichweite hält. +- **touchless_power_switch**: Ein und ausschalten von Geräten. +- **touchless_time_limited**: Läuft für eine angegebene Zeit und stoppt anschliessend. + + +#### Hardware + +* Arduino: - https://www.conrad.ch/de/p/arduino-ag-mikrocontroller-uno-rev3-smd-191789.html **23.-** +* Relay: - https://www.play-zone.ch/de/elektronik-kit-zubehoer/module-karten/relais/1-kanal-relais-modul-karte-5v-30vdc-mit-kabel.html **11.-** + +* Sensor: - https://www.pi-shop.ch/ultrasonic-range-sensor-hc-sr04 **7.-** + +* Pumpe: - https://www.conrad.ch/de/p/modelcraft-kraftstoff-getriebepumpe-benzinfest-foerdermenge-0-6-l-207894.html **13.-** +* Pumpe2: - https://www.brack.ch/velleman-wasserpumpe-871806 **15.-** diff --git a/diy_relay_module.png b/diy_relay_module.png new file mode 100644 index 0000000..175fcde Binary files /dev/null and b/diy_relay_module.png differ diff --git a/touchless_basic/touchless_basic.ino b/touchless_basic/touchless_basic.ino new file mode 100644 index 0000000..9c602f2 --- /dev/null +++ b/touchless_basic/touchless_basic.ino @@ -0,0 +1,52 @@ +const int US_sensorPin = 7; +const int relayPin = 10; +const int waveBackWait = 5000; //adjust this to set the min speed of wave gesture +const int range = 8; //Range of detection from the sensor in cm + + +void setup() { + pinMode(relayPin, OUTPUT); + digitalWrite(relayPin, HIGH); // Default relay should be OFF! +} + +void loop() { + long duration, cm; + pinMode(US_sensorPin, OUTPUT); + + digitalWrite(US_sensorPin, LOW); + delayMicroseconds(2); + digitalWrite(US_sensorPin, HIGH); + delayMicroseconds(5); + digitalWrite(US_sensorPin, LOW); + + pinMode(US_sensorPin, INPUT); + duration = pulseIn(US_sensorPin, HIGH); + + cm = microsecondsToCentimeters(duration); + + if (cm < range && cm > 1) { + for (int i = waveBackWait; i > 0; i--) { + long new_duration, new_cm; + pinMode(US_sensorPin, OUTPUT); + digitalWrite(US_sensorPin, LOW); + delayMicroseconds(2); + digitalWrite(US_sensorPin, HIGH); + delayMicroseconds(5); + digitalWrite(US_sensorPin, LOW); + pinMode(US_sensorPin, INPUT); + new_duration = pulseIn(US_sensorPin, HIGH); + + new_cm = microsecondsToCentimeters(new_duration); + if (new_cm < range && new_cm > 1) { + digitalWrite(relayPin, LOW); // Turn Ralay ON + delay(500); // Miliseconds which it waits before turn off again + digitalWrite(relayPin,HIGH); // Trun Ralay OFF + } + } + } +} +long microsecondsToCentimeters(long microseconds) { + return microseconds / 29 / 2; + + +} diff --git a/touchless_power_switch/touchless_power_switch.ino b/touchless_power_switch/touchless_power_switch.ino new file mode 100644 index 0000000..ab7af6c --- /dev/null +++ b/touchless_power_switch/touchless_power_switch.ino @@ -0,0 +1,56 @@ +const int US_sensorPin = 7; +const int relayPin = 10; +const int range = 8; //Range of detection from the sensor in cm +int valRelay = 0; // variable to store the read value +long relayAction; + +void setup() { + pinMode(relayPin, OUTPUT); + digitalWrite(relayPin, HIGH); // Default relay should be OFF! +} + +void loop() { + long duration, cm; + pinMode(US_sensorPin, OUTPUT); + + digitalWrite(US_sensorPin, LOW); + delayMicroseconds(2); + digitalWrite(US_sensorPin, HIGH); + delayMicroseconds(5); + digitalWrite(US_sensorPin, LOW); + + pinMode(US_sensorPin, INPUT); + duration = pulseIn(US_sensorPin, HIGH); + + cm = microsecondsToCentimeters(duration); + + if (cm < range && cm > 1) { + long new_duration, new_cm; + pinMode(US_sensorPin, OUTPUT); + digitalWrite(US_sensorPin, LOW); + delayMicroseconds(2); + digitalWrite(US_sensorPin, HIGH); + delayMicroseconds(5); + digitalWrite(US_sensorPin, LOW); + pinMode(US_sensorPin, INPUT); + new_duration = pulseIn(US_sensorPin, HIGH); + + new_cm = microsecondsToCentimeters(new_duration); + + valRelay = digitalRead(relayPin); // read the status of input pin + if (valRelay) { + relayAction = LOW; + } else { + relayAction = HIGH; + } + + if (new_cm < range && new_cm > 1) { + digitalWrite(relayPin, relayAction); // Switch Ralay ON or OFF + delay(1000); // Miliseconds which it waits before does any action again + } + } +} +long microsecondsToCentimeters(long microseconds) { + return microseconds / 29 / 2; + +} diff --git a/touchless_time_limited/touchless_time_limited.ino b/touchless_time_limited/touchless_time_limited.ino new file mode 100644 index 0000000..d361f78 --- /dev/null +++ b/touchless_time_limited/touchless_time_limited.ino @@ -0,0 +1,52 @@ +const int US_sensorPin = 7; +const int relayPin = 10; +const int range = 8; //Range of detection from the sensor in cm + +void setup() { + pinMode(relayPin, OUTPUT); + digitalWrite(relayPin, HIGH); // Default relay should be OFF! +} + +void loop() { + long duration, cm; + pinMode(US_sensorPin, OUTPUT); + + digitalWrite(US_sensorPin, LOW); + delayMicroseconds(2); + digitalWrite(US_sensorPin, HIGH); + delayMicroseconds(5); + digitalWrite(US_sensorPin, LOW); + + pinMode(US_sensorPin, INPUT); + duration = pulseIn(US_sensorPin, HIGH); + + cm = microsecondsToCentimeters(duration); + + if (cm < range && cm > 1) { + long new_duration, new_cm; + pinMode(US_sensorPin, OUTPUT); + digitalWrite(US_sensorPin, LOW); + delayMicroseconds(2); + digitalWrite(US_sensorPin, HIGH); + delayMicroseconds(5); + digitalWrite(US_sensorPin, LOW); + pinMode(US_sensorPin, INPUT); + new_duration = pulseIn(US_sensorPin, HIGH); + + new_cm = microsecondsToCentimeters(new_duration); + + if (new_cm < range && new_cm > 1) { + digitalWrite(relayPin, LOW); // Turn Ralay ON + delay(500); // Miliseconds which it waits before turn off again + digitalWrite(relayPin,HIGH); // Trun Ralay OFF + } + + if (new_cm < range && new_cm > 1) { + delay(3000); // Pauses the measure for 3 seconds.. so the liquid-flow stops after above time + } + } +} +long microsecondsToCentimeters(long microseconds) { + return microseconds / 29 / 2; + +}