diff --git a/diy_relay_module.png b/_wiring/diy_relay_module.png similarity index 100% rename from diy_relay_module.png rename to _wiring/diy_relay_module.png diff --git a/_wiring/wiring.fzz b/_wiring/wiring.fzz new file mode 100644 index 0000000..f5b8970 Binary files /dev/null and b/_wiring/wiring.fzz differ diff --git a/_wiring/wiring_basic.png b/_wiring/wiring_basic.png new file mode 100644 index 0000000..483ea6e Binary files /dev/null and b/_wiring/wiring_basic.png differ diff --git a/_wiring/wiring_touchless_power_switch_with_display.png b/_wiring/wiring_touchless_power_switch_with_display.png new file mode 100644 index 0000000..73f6a88 Binary files /dev/null and b/_wiring/wiring_touchless_power_switch_with_display.png differ diff --git a/touchless_power_switch_with_display/touchless_power_switch_with_display.ino b/touchless_power_switch_with_display/touchless_power_switch_with_display.ino new file mode 100644 index 0000000..96b3ba7 --- /dev/null +++ b/touchless_power_switch_with_display/touchless_power_switch_with_display.ino @@ -0,0 +1,76 @@ +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; +bool newAction; + +#include +LiquidCrystal lcd(12,11,5,4,3,2); + +void setup() { + Serial.begin (9600); //Allows serial output to serial monitor + pinMode(relayPin, OUTPUT); + digitalWrite(relayPin, HIGH); // Default relay should be OFF! + + lcd.begin(16,2); //Say what format of LCD we are using. + lcd.clear(); + lcd.setCursor(0,0); //Goto line 0 char 0 + lcd.print("RC Solutions"); + lcd.setCursor(0,1); //Goto second line + lcd.print("touchless v1"); + delay(1500); + lcd.clear(); + lcd.setCursor(0,0); //Goto line 0 char 0 + + lcd.print("Power Status:"); + lcd.setCursor(0,1); //Goto second line + lcd.print("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) { + + if (newAction) { + valRelay = digitalRead(relayPin); // read the status of input pin + if (valRelay) { + relayAction = LOW; + lcd.clear(); + lcd.print("Power Status:"); + lcd.setCursor(0,1); //Goto second line + lcd.print("ON"); + } else { + relayAction = HIGH; + lcd.clear(); + lcd.print("Power Status:"); + lcd.setCursor(0,1); //Goto second line + lcd.print("OFF"); + } + + digitalWrite(relayPin, relayAction); // Switch Ralay ON or OFF + newAction = false; + } + //lcd.print(newAction); + delay(1000); // Miliseconds which it waits before does any action again + + } else { + newAction = true; + //lcd.print(newAction); + } +} + +long microsecondsToCentimeters(long microseconds) { + return microseconds / 29 / 2; +}