@BulldogLowell said:
are examples on the forum on multiple relays on one MCU... try searching the forum.
yes i see but with dth 22 it's difficult
i use simpletimer.h with this
@BulldogLowell said:
are examples on the forum on multiple relays on one MCU... try searching the forum.
yes i see but with dth 22 it's difficult
i use simpletimer.h with this
Hello
i have a sketch with dth22 motion and relay
it's not optimal but it works
i want to add another relay but it doesn't work have you a soluce
thanks
#include <MySensor.h>
#include <DHT.h>
#include <SimpleTimer.h>
#define CHILD_ID_HUM 1
#define CHILD_ID_TEMP 2
#define CHILD_ID_MOTION 3
#define CHILD_ID_RELAY 4
#define MOTION_SENSOR_DIGITAL_PIN 3
#define HUMIDITY_SENSOR_DIGITAL_PIN 4
#define INTERRUPT MOTION_SENSOR_DIGITAL_PIN-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
#define RELAY 5// Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define RELAY_ON 0 // GPIO value to write to turn on attached relay
#define RELAY_OFF 1 // GPIO value to write to turn off attached relay
unsigned long SLEEP_TIME = 600000; // Sleep time between reads (in milliseconds) - 10mins
DHT dht;
SimpleTimer timer;
float lastTemp;
float lastHum;
boolean lastTripped;
boolean metric = true;
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
MyMessage msg(CHILD_ID_MOTION, V_TRIPPED);
MySensor gw;
void setup()
{
// Initialize library and add callback for incoming messages
gw.begin(incomingMessage, AUTO, true);
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
// Send the Sketch Version Information to the Gateway
gw.sendSketchInfo("HumTempRelayMotion", "1.0");
// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_HUM, S_HUM);
gw.present(CHILD_ID_TEMP, S_TEMP);
gw.present(CHILD_ID_MOTION, S_MOTION);
gw.present(CHILD_ID_RELAY, S_LIGHT);
pinMode(RELAY, OUTPUT);
digitalWrite(RELAY, gw.loadState(RELAY)?RELAY_OFF:RELAY_ON);
//Serial.begin(9600);
timer.setInterval(30000, getMeasure);
metric = gw.getConfig().isMetric;
}
void loop()
{
// Alway process incoming messages whenever possible
gw.process();
timer.run();
boolean tripped = digitalRead(MOTION_SENSOR_DIGITAL_PIN) == HIGH;
if (tripped != lastTripped) {
lastTripped = tripped;
Serial.print("M: ");
Serial.println(tripped);
gw.send(msg.set(tripped?"1":"0")); // Send tripped value to gw
}
}
void incomingMessage(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_LIGHT) {
// Change relay state
digitalWrite(message.sensor-CHILD_ID_RELAY+RELAY, message.getBool()?RELAY_ON:RELAY_OFF);
// Store state in eeprom
gw.saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}
void getMeasure() {
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);
}
gw.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;
gw.send(msgHum.set(humidity, 1));
Serial.print("H: ");
Serial.println(humidity);
}
}```
Hello
i want to make a water level sensor for my pool
i have a sensor
it's this
but i don't find a sketch for this
it's analog imput
thanks to share if you have
best regards
@Dalhoj i use this and it's working fine
i want to include another relay and it's ok for me
#include <SPI.h>
#include <MySensor.h>
#include <Wire.h>
#include <DHT.h>
#include <SimpleTimer.h>
#define CHILD_ID_HUM 1
#define CHILD_ID_TEMP 2
#define CHILD_ID_MOTION 3
#define CHILD_ID_RELAY 4
#define HUMIDITY_SENSOR_DIGITAL_PIN 19
#define MOTION_SENSOR_DIGITAL_PIN 3
#define INTERRUPT MOTION_SENSOR_DIGITAL_PIN-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
#define RELAY 8 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define RELAY_ON 0 // GPIO value to write to turn on attached relay
#define RELAY_OFF 1 // GPIO value to write to turn off attached relay
unsigned long SLEEP_TIME = 600000; // Sleep time between reads (in milliseconds) - 10mins
MySensor gw;
DHT dht;
SimpleTimer timer;
float lastTemp;
float lastHum;
boolean lastTripped;
boolean metric = true;
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
MyMessage msg(CHILD_ID_MOTION, V_TRIPPED);
void setup()
{
// Initialize library and add callback for incoming messages
gw.begin(incomingMessage, AUTO, true);
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
// Send the Sketch Version Information to the Gateway
gw.sendSketchInfo("HumTempRelayMotion", "1.0");
// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_HUM, S_HUM);
gw.present(CHILD_ID_TEMP, S_TEMP);
gw.present(CHILD_ID_MOTION, S_MOTION);
gw.present(CHILD_ID_RELAY, S_LIGHT);
pinMode(RELAY, OUTPUT);
digitalWrite(RELAY, gw.loadState(RELAY)?RELAY_OFF:RELAY_ON);
//Serial.begin(9600);
timer.setInterval(30000, getMeasure);
metric = gw.getConfig().isMetric;
}
void loop()
{
// Alway process incoming messages whenever possible
gw.process();
timer.run();
boolean tripped = digitalRead(MOTION_SENSOR_DIGITAL_PIN) == HIGH;
if (tripped != lastTripped) {
lastTripped = tripped;
Serial.print("M: ");
Serial.println(tripped);
gw.send(msg.set(tripped?"1":"0")); // Send tripped value to gw
}
}
void incomingMessage(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_LIGHT) {
// Change relay state
digitalWrite(message.sensor-CHILD_ID_RELAY+RELAY, message.getBool()?RELAY_ON:RELAY_OFF);
// Store state in eeprom
gw.saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}
void getMeasure() {
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);
}
gw.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;
gw.send(msgHum.set(humidity, 1));
Serial.print("H: ");
Serial.println(humidity);
}
}
Hello
i want to make a similar project but i want to add a dht22 with this sketch
have you a sketch with a dht because i have a problem with mine
thanks