Jak postavit modul s teplotním vlhkostním světelným a pohybovým senzorem Mysensors a připojit k Openhabu
Tento návod popisuje, jak vytvořit senzor a jak ho připojit k Openhabu.
Budete muset mít nainstalovanou bránu Mysensors. Podívejte se na můj tutoriál o tom, jak vytvořit bránu Mysensors.
Co potřebujeme:
Light Sensor BH1750 nebo
Light sensor LM393
Humidity/Temperature sensor
Arduino Pro Mini 3.3V (Můžete také použít verzi 5V. Nezapomeňte Radio modul je pouze na 3.3V vstup.)
Radio module
Dupont cable
Capacitor 47uF
USB module
Motion sensor
Jak připojit moduly k Arduinu:
Connecting radio module
Connecting dht22 sensor
Connecting light sensor BH1750 nebo
Connecting light sensor LM393
Connecting motion sensor
Připojení k USB je jednoduché kromě jedné věci. USB modul dává 5V, což není dobré pro rádiový modul. Musíte dát VCC z USB modulu na RAW Arduina namísto VCC, pokud používáte 3.3V arduino bez regulátoru na rádiovém modulu.
Zde je kód pro arduino:
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * */ #define MY_DEBUG #define MY_RADIO_NRF24 #define MY_NODE_ID 4 #include <SPI.h> #include <MySensors.h> #include <DHT.h> #include <BH1750.h> #include <OneWire.h> #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_MOTION 2 #define CHILD_ID_LIGHT 3 #define HUMIDITY_SENSOR_DIGITAL_PIN 4 #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) DHT dht; BH1750 lightSensor; uint16_t lastlux; float lastTemp; float lastHum; boolean metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL); MyMessage msgMotion(CHILD_ID_MOTION, V_TRIPPED); void setup() { dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the Sketch Version Information to the Gateway sendSketchInfo("MotionTemperature", "1.0"); pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_MOTION, S_MOTION); present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); lightSensor.begin(); metric = getControllerConfig().isMetric; } void loop() { //DHT Humidity Temperature sensor //delay(dht.getMinimumSamplingPeriod()); float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT"); } else if (temperature != lastTemp) { lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } send(msgTemp.set(temperature, 1)); Serial.print("T: "); Serial.println(temperature); } float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum) { lastHum = humidity; send(msgHum.set(humidity, 1)); Serial.print("H: "); Serial.println(humidity); } //BHT1750 light sensor uint16_t lux = lightSensor.readLightLevel();// Get Lux value Serial.print("Light: "); Serial.println(lux); if (lux != lastlux) { send(msgLight.set(lux)); lastlux = lux; } // Read digital motion value boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; Serial.println(tripped); send(msgMotion.set(tripped?"1":"0")); // Send tripped value to gw // Sleep until interrupt comes in on motion sensor. Send update every two minute. sleep(INTERRUPT,CHANGE, SLEEP_TIME); }
Po zapnutí senzoru byste jej měli jednoduše přidat do PaperUI v openhabu.
Nastavení položek v aplikaci Openhab.
Pak přiřadíte položky k objeveným věcem v OpenHab PaperUI.
Group MySen2 "Sensor2" Number MySen2_Humidity "Humidity [%.1f %%]" (MySen2) Number MySen2_Temperature "Temperature [%.1f C]" (MySen2) [ "CurrentTemperature" ] Number MySen2_Light "Light [%s]" (MySen2) Contact MySen2_TrippedStatus "Motion [%s]" (MySen2) DateTime MySen2_Update "Updated [%1$td.%1$tm. %1$tH:%1$tM]" (MySen2)
zde je můj design PCB můžete okopírovat, pokud chcete. funguje dobře pro krabičku kterou používám.
MotionTemperature_etch_silk_top
MotionTemperature_etch_copper_bottom