From 7da2236af4bf287bab716ed2f012f7400e7a8939 Mon Sep 17 00:00:00 2001 From: bernd2k <36308246+bernd2k@users.noreply.github.com> Date: Sat, 30 Nov 2019 17:42:36 +0100 Subject: [PATCH] added arduino code and moved raspbi code added arduino code is the read out of the sensor via an arduino. the raspicode is moved to its own section. --- arduino/door_status.ino | 66 +++++++++++++++++++++++++ LICENSE => raspberry_pi/LICENSE | 0 README.md => raspberry_pi/README.md | 0 config.json => raspberry_pi/config.json | 0 main.py => raspberry_pi/main.py | 0 status.json => raspberry_pi/status.json | 0 6 files changed, 66 insertions(+) create mode 100644 arduino/door_status.ino rename LICENSE => raspberry_pi/LICENSE (100%) rename README.md => raspberry_pi/README.md (100%) rename config.json => raspberry_pi/config.json (100%) rename main.py => raspberry_pi/main.py (100%) rename status.json => raspberry_pi/status.json (100%) diff --git a/arduino/door_status.ino b/arduino/door_status.ino new file mode 100644 index 0000000..805043f --- /dev/null +++ b/arduino/door_status.ino @@ -0,0 +1,66 @@ +# arduino Duemilanove +#define IR_INPUT_PIN A0 +#define IR_LED_PIN 13 + +#define status_red_PIN 12 +#define status_yellow_PIN 11 +#define status_green_PIN 10 + + + +void setup(){ + Serial.begin(9600); + pinMode(IR_INPUT_PIN, INPUT); + pinMode(IR_LED_PIN, OUTPUT); + + pinMode(status_red_PIN, OUTPUT); + pinMode(status_yellow_PIN, OUTPUT); + pinMode(status_green_PIN, OUTPUT); +} + + +int threshold = 900; +int value_b4 = 900; + +int value = 0; + +void loop(){ + int ambient = 0; + int lit = 0; + + + digitalWrite(IR_LED_PIN, LOW); + delay(5); //To give ADC and LED transition time + ambient = analogRead(IR_INPUT_PIN); + + digitalWrite(IR_LED_PIN, HIGH); + delay(5); + lit = analogRead(IR_INPUT_PIN); + + value = ((lit - ambient) + value_b4) / 2; // small filter + + Serial.print(value); + Serial.print(" "); + Serial.println(ambient); + delay(500); + + if (value >= threshold) { + digitalWrite(status_red_PIN, HIGH); + digitalWrite(status_yellow_PIN, LOW); + digitalWrite(status_green_PIN, LOW); + } + + //if (value < 977 && value >= 964) { + // digitalWrite(status_red_PIN, LOW); + // digitalWrite(status_yellow_PIN, HIGH); + // digitalWrite(status_green_PIN, LOW); + //} + + if (value < threshold) { + digitalWrite(status_red_PIN, LOW); + digitalWrite(status_yellow_PIN, LOW); + digitalWrite(status_green_PIN, HIGH); + } + + value_b4 = value; +} diff --git a/LICENSE b/raspberry_pi/LICENSE similarity index 100% rename from LICENSE rename to raspberry_pi/LICENSE diff --git a/README.md b/raspberry_pi/README.md similarity index 100% rename from README.md rename to raspberry_pi/README.md diff --git a/config.json b/raspberry_pi/config.json similarity index 100% rename from config.json rename to raspberry_pi/config.json diff --git a/main.py b/raspberry_pi/main.py similarity index 100% rename from main.py rename to raspberry_pi/main.py diff --git a/status.json b/raspberry_pi/status.json similarity index 100% rename from status.json rename to raspberry_pi/status.json