Lennart Heimbs 2019-03-08 10:38:05 +01:00
commit 4a1c1bfe92
5 changed files with 174 additions and 1 deletions

View File

@ -1,7 +1,7 @@
# Smart-Home am Beispiel der Präsenzerkennung im Raum
## Einführung
Johannes hat auch angefangen
## Schluss
Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Dr. Oliver Hofmann
SS2019

View File

@ -0,0 +1,36 @@
//HC-SR501 als Bewegungsmelder, vergleicht alten PIR-wert mit neuem PIR-wert und lässt bei HIGH Phase LED leuchten
//Einstellung *repeatable Trigger||single Trigger* hier egal
//Single Trigger:Bei Bewegung läuft ein festgelegtes Zeitfenster HIGH ab (LINKER POTI, 3sec bis 5min)
//Repeatable Trigger: Bei Bewegung läuft HIGH Zeitfester ab, wenn darin wieder Bewegung erkannt wird, wird das zeitfenster wieder neu gestartet und verlängert.
//Nach diesen HIGH signal folgt in beiden fällen ein 3 sekündiges LOW Fenster, hier wird keine bewegung erkannt
int ledPin = D1; // LED on Pin 13 of Arduino
int pirPin = D0; // Input for HC-S501
int pirValueNeu; // Place to read PIR Value
int pirValueAlt = 0; //Place to store read PIR Value
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
digitalWrite(ledPin, LOW);
}
void loop() {
pirValueNeu = digitalRead(pirPin);
if(pirValueNeu != pirValueAlt){
if(pirValueNeu==1){
Serial.println("Motion! Level:HIGH");
}
else{
//Serial.println("Ruhemodus 3 Sekunden! Level:LOW");
//delay(3000);
Serial.println("No motion so far! Level:LOW");
}
}
digitalWrite(ledPin, pirValueNeu);
pirValueAlt=pirValueNeu;
}

View File

@ -0,0 +1,21 @@
//analoger ausgang gibt nur den aktuellen wert des potis aus, also nur zum genauen poti einstellen geeignet! ansonsten nutzlos
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = D0; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup()
{
pinMode(ledPin,OUTPUT);
Serial.begin(9600);
}
void loop(){
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH);
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue);
Serial.println(sensorValue, DEC);
}

View File

@ -0,0 +1,53 @@
//www.elegoo.com
//2016.06.13
//digitaler ausgang soundmodul
int Led=D0;//define LED port
int buttonpin=D5; //define switch port
int val;//define digital variable val
int anzahl_loop=0;
int anzahl_high=1;
int anzahl_low=1;
double high_anteil;
void setup()
{
Serial.begin(9600);
pinMode(Led,OUTPUT);//define LED as a output port
pinMode(buttonpin,INPUT);//define switch as a output port
}
void loop()
{ anzahl_loop++;//anzahl der loopdurchlaeufe
val=digitalRead(buttonpin);//read the value of the digital interface 3 assigned to val
if(val==HIGH)//when the switch sensor have signal, LED blink
{
digitalWrite(Led,HIGH);
//Serial.println("HIGH");
anzahl_high++;
}
else
{
digitalWrite(Led,LOW);
//Serial.println(val);
anzahl_low++;
}
if(anzahl_loop==1000){ //100 loops auswerten und den high anteil ermitteln
high_anteil=((double)anzahl_high/(double)anzahl_loop);
if(high_anteil>=0.10){
Serial.println(high_anteil);
}
anzahl_high=1;
anzahl_low=1;
anzahl_loop=0;
}
}

View File

@ -0,0 +1,63 @@
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
const char* SSID = "smartroom";
const char* PSK = "smarthome";
const char* MQTT_BROKER = "192.168.4.1";
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
void setup() {
Serial.begin(115200);
setup_wifi();
client.setServer(MQTT_BROKER, 1883);
}
void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connecting to ");
Serial.println(SSID);
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PSK);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void reconnect() {
while (!client.connected()) {
Serial.print("Reconnecting...");
if (!client.connect("ESP8266Client")) {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" retrying in 5 seconds");
delay(5000);
}
}
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
snprintf (msg, 50, "Alive since %ld milliseconds", millis());
Serial.print("Publish message: ");
Serial.println(msg);
client.publish("/home/data", "Hello asdf World");
delay(5000);
}