Skip to content

My Project

Show off and share your great projects here! We love pictures!
964 Topics 13.5k Posts
  • two energy meter

    4
    0 Votes
    4 Posts
    3k Views
    F
    I couldn't just lay down in the sofa so I started to test and now I got a code that seems to work. I have tested it for a few days and it seems to count correct. I made some changes so it will send data every minute and it will send Watt-value even if it is the same value since last time. I am using VAR2 for second energy meter since I don't know how to config Incomingmessage and seperate VAR1 from different Child_IDs. I change corrupted interrupts from 10000L to 40000L otherwise it reported interrupts twice. /** * 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. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * 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. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Use this sensor to measure kWh and Watt of your house meter * You need to set the correct pulsefactor of your meter (blinks per kWh). * The sensor starts by fetching current kWh value from gateway. * Reports both kWh and Watt back to gateway. * * Unfortunately millis() won't increment when the Arduino is in * sleepmode. So we cannot make this sensor sleep if we also want * to calculate/report watt-number. * http://www.mysensors.org/build/pulse_power */ #include <SPI.h> #include <MySensor.h> unsigned long SEND_FREQUENCY = 60000; // Minimum time between send (in milliseconds). We don't want to spam the gateway. #define SLEEP_MODE false // Watt-value can only be reported when sleep mode is false. //sensor 1 #define DIGITAL_INPUT_SENSOR_1 2 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!) #define PULSE_FACTOR_1 1000 // Number of blinks per KWH of your meeter #define MAX_WATT_1 10000 // Max watt value to report. This filters outliers. #define INTERRUPT_1 DIGITAL_INPUT_SENSOR_1-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define CHILD_ID_1 1 // Id of the sensor child //sensor 2 #define DIGITAL_INPUT_SENSOR_2 3 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!) #define PULSE_FACTOR_2 10000 // Number of blinks per KWH of your meeter #define MAX_WATT_2 10000 // Max watt value to report. This filters outliers. #define INTERRUPT_2 DIGITAL_INPUT_SENSOR_2-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define CHILD_ID_2 2 // Id of the sensor child MySensor gw; //sensor 1 double ppwh_1 = ((double)PULSE_FACTOR_1)/1000; // Pulses per watt hour boolean pcReceived_1 = false; volatile unsigned long pulseCount_1 = 0; volatile unsigned long lastBlink_1 = 0; volatile unsigned long watt_1 = 0; unsigned long oldPulseCount_1 = 0; unsigned long oldWatt_1 = 0; double oldKwh_1; unsigned long lastSend_1; //sensor 2 double ppwh_2 = ((double)PULSE_FACTOR_2)/1000; // Pulses per watt hour boolean pcReceived_2 = false; volatile unsigned long pulseCount_2 = 0; volatile unsigned long lastBlink_2 = 0; volatile unsigned long watt_2 = 0; unsigned long oldPulseCount_2 = 0; unsigned long oldWatt_2 = 0; double oldKwh_2; unsigned long lastSend_2; //sensor 1 MyMessage wattMsg_1(CHILD_ID_1,V_WATT); MyMessage kwhMsg_1(CHILD_ID_1,V_KWH); MyMessage pcMsg_1(CHILD_ID_1,V_VAR1); //sensor 2 MyMessage wattMsg_2(CHILD_ID_2,V_WATT); MyMessage kwhMsg_2(CHILD_ID_2,V_KWH); MyMessage pcMsg_2(CHILD_ID_2,V_VAR2); void setup() { gw.begin(incomingMessage); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Energy Double", "1.0"); // Register this device as power sensor //sensor 1 gw.present(CHILD_ID_1, S_POWER); //sensor 2 gw.present(CHILD_ID_2, S_POWER); //Send new VAR to Gateway //gw.send(pcMsg_1.set(xxxxxxxxx)); // Send pulse count value to gw //gw.send(pcMsg_2.set(1895931000)); // Send pulse count value to gw // Fetch last known pulse count value from gw //sensor 1 gw.request(CHILD_ID_1, V_VAR1); //sensor 2 gw.request(CHILD_ID_2, V_VAR2); //sensor 1 attachInterrupt(INTERRUPT_1, onPulse_1, RISING); //sensor 2 attachInterrupt(INTERRUPT_2, onPulse_2, RISING); lastSend_1=millis(); lastSend_2=millis(); } void loop() { gw.process(); //sensor 1 unsigned long now_1 = millis(); // Only send values at a maximum frequency or woken up from sleep bool sendTime_1 = now_1 - lastSend_1 > SEND_FREQUENCY; if (pcReceived_1 && (SLEEP_MODE || sendTime_1)) { // New watt value has been calculated //if (!SLEEP_MODE && watt_1 != oldWatt_1) { // Check that we dont get unresonable large watt value. // could hapen when long wraps or false interrupt triggered if (watt_1<((unsigned long)MAX_WATT_1)) { gw.send(wattMsg_1.set(watt_1)); // Send watt value to gw } Serial.print("Watt_1:"); Serial.println(watt_1); oldWatt_1 = watt_1; //} // Pulse cout has changed if (pulseCount_1 != oldPulseCount_1) { gw.send(pcMsg_1.set(pulseCount_1)); // Send pulse count value to gw double kwh_1 = ((double)pulseCount_1/((double)PULSE_FACTOR_1)); oldPulseCount_1 = pulseCount_1; //if (kwh_1 != oldKwh_1) { gw.send(kwhMsg_1.set(kwh_1, 4)); // Send kwh value to gw oldKwh_1 = kwh_1; //} } lastSend_1 = now_1; } else if (sendTime_1 && !pcReceived_1) { // No count received. Try requesting it again gw.request(CHILD_ID_1, V_VAR1); lastSend_1=now_1; } //sensor 2 unsigned long now_2 = millis(); // Only send values at a maximum frequency or woken up from sleep bool sendTime_2 = now_2 - lastSend_2 > SEND_FREQUENCY; if (pcReceived_2 && (SLEEP_MODE || sendTime_2)) { // New watt value has been calculated //if (!SLEEP_MODE && watt_2 != oldWatt_2) { // Check that we dont get unresonable large watt value. // could hapen when long wraps or false interrupt triggered if (watt_2<((unsigned long)MAX_WATT_2)) { gw.send(wattMsg_2.set(watt_2)); // Send watt value to gw } Serial.print("Watt_2:"); Serial.println(watt_2); oldWatt_2 = watt_2; //} // Pulse cout has changed if (pulseCount_2 != oldPulseCount_2) { gw.send(pcMsg_2.set(pulseCount_2)); // Send pulse count value to gw double kwh_2 = ((double)pulseCount_2/((double)PULSE_FACTOR_2)); oldPulseCount_2 = pulseCount_2; //if (kwh_2 != oldKwh_2) { gw.send(kwhMsg_2.set(kwh_2, 4)); // Send kwh value to gw oldKwh_2 = kwh_2; //} } lastSend_2 = now_2; } else if (sendTime_2 && !pcReceived_2) { // No count received. Try requesting it again gw.request(CHILD_ID_2, V_VAR2); lastSend_2=now_2; } if (SLEEP_MODE) { gw.sleep(SEND_FREQUENCY); } } void incomingMessage(const MyMessage &message) { if (message.type==V_VAR1) { pulseCount_1 = oldPulseCount_1 = message.getLong(); Serial.print("Received_1 last pulse count from gw:"); Serial.println(pulseCount_1); pcReceived_1 = true; } if (message.type==V_VAR2) { pulseCount_2 = oldPulseCount_2 = message.getLong(); Serial.print("Received_2 last pulse count from gw:"); Serial.println(pulseCount_2); pcReceived_2 = true; } } void onPulse_1() { if (!SLEEP_MODE) { unsigned long newBlink_1 = micros(); unsigned long interval_1 = newBlink_1-lastBlink_1; if (interval_1<40000L) { // Sometimes we get interrupt on RISING return; } watt_1 = (3600000000.0 /interval_1) / ppwh_1; lastBlink_1 = newBlink_1; } //Serial.println(pulseCount_1); pulseCount_1++; //Serial.println(pulseCount_1); } void onPulse_2() { if (!SLEEP_MODE) { unsigned long newBlink_2 = micros(); unsigned long interval_2 = newBlink_2-lastBlink_2; if (interval_2<40000L) { // Sometimes we get interrupt on RISING return; } watt_2 = (3600000000.0 /interval_2) / ppwh_2; lastBlink_2 = newBlink_2; } //Serial.println(pulseCount_2); pulseCount_2++; //Serial.println(pulseCount_2); }
  • LED Lamp

    7
    6 Votes
    7 Posts
    2k Views
    YveauxY
    @checkup if you add this project to openhardware.io including sources, schematics (if applicable) and some description we can import it to the build pages.
  • Outdoor fence gate access

    2
    0 Votes
    2 Posts
    1k Views
    C
    @clippermiami can you hit it from your house with a garage door opener? I haven't integrated mine into a HA controller yet, but for now I just have an RPi driving a relay board that is soldered into the guts from a garage door opener. Bonus there are three buttons so I can run both garage doors and the front gate from a web interface. I'm sure you could do the same with an arduino in place of the RPi.
  • This topic is deleted!

    1
    0 Votes
    1 Posts
    12 Views
    No one has replied
  • combining button with dht11 issue

    2
    0 Votes
    2 Posts
    1k Views
    el tigroE
    sorted works a treat now. My bad, used a sketch I had tinkered with in the past. sketches melded now. Finished sketch below for them that might need. The sketch is for domestic light swith. #define MY_NODE_ID 5 #define MY_DEBUG #define MY_RADIO_NRF24 #include <SPI.h> #include <MySensors.h> #include <Bounce2.h> #include <DHT.h> #define DHT_DATA_PIN 7 #define CHILD_ID 3 #define BUTTON_PIN 3 #define SENSOR_TEMP_OFFSET 0 #define CHILD_ID_TEMP 1 Bounce debouncer = Bounce(); static const uint64_t UPDATE_INTERVAL = 5000; static const uint8_t FORCE_UPDATE_N_READS = 2; float lastTemp; unsigned long interval = 5000; unsigned long previousMillis = 0; uint8_t nNoUpdatesTemp; int oldValue = -1; bool metric = true; MyMessage msg(CHILD_ID, V_LIGHT); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); DHT dht; void presentation() { sendSketchInfo("kitchen Lights", "1.1"); present(CHILD_ID, S_LIGHT); present(CHILD_ID_TEMP, S_TEMP); metric = getConfig().isMetric; } void setup() { pinMode(BUTTON_PIN, INPUT); digitalWrite(BUTTON_PIN, HIGH); debouncer.attach(BUTTON_PIN); debouncer.interval(5); dht.setup(DHT_DATA_PIN); if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } } void loop() { debouncer.update(); int value = debouncer.read(); if (value != oldValue) { send(msg.set(value == HIGH ? 1 : 0)); oldValue = value; } unsigned long currentMillis = millis(); if ((unsigned long)(currentMillis - previousMillis) >= interval) { dht.readSensor(true); float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } nNoUpdatesTemp = 0; temperature += SENSOR_TEMP_OFFSET; send(msgTemp.set(temperature, 1)); #ifdef MY_DEBUG Serial.print("T: "); Serial.println(temperature); #endif } else { nNoUpdatesTemp++; } previousMillis = millis(); } }
  • Schneider Electric WISERJLPM200

    2
    0 Votes
    2 Posts
    1k Views
    RedguyR
    I implemented this with a schneider PM9C using modbus which works fine Zigbee is just transport, shouldnt be to hard to translate.. You need the manual to see what data it provides, which i couldnt find online. The model you specified has been of the market for some years.
  • RS485 Stress test

    34
    7 Votes
    34 Posts
    14k Views
    R
    @AWI I have access to the necessary most modules and electronic components in my city . so if you have idea for this told me and i am ready to test .
  • My projects with mysensors on my house

    11
    5 Votes
    11 Posts
    5k Views
    L
    I have a 0.4mm nozzle. I can print with a 100 microns resolution with this one 😉
  • Ultrasonic essential Oil diffuser

    11
    7 Votes
    11 Posts
    9k Views
    fifipil909F
    Hi, It's hard to say right now. It can be interesting to know how do you control the On/Off. Those Ceramic caps don't like to be used without any liquid and can be damaged very quickly if there are dry. But normally there is a build in switch off circuit if no liquid is detected. Can you tell me more how to you modify the electronic to control it with Mysensors ?
  • IKEA Spöke/Spoke(ghost)

    3
    4 Votes
    3 Posts
    4k Views
    F
    @Yveaux Thanks. I used alcohol to put the silicone back. I have add that information in the post
  • Sensbender Micro BinaryDoorSensor

    3
    0 Votes
    3 Posts
    2k Views
    T
    The library for SI7021 is missing. You'll find it here: https://github.com/mysensors/MySensorsArduinoExamples
  • Module "Fil Pilote" for french heaters

    1
    0 Votes
    1 Posts
    736 Views
    No one has replied
  • Slim Node Si7021 sensor example

    137
    6 Votes
    137 Posts
    72k Views
    miljumeM
    @Eawo Domoticz groups sensors after the order you present them in, see: https://forum.mysensors.org/topic/5132/ds18b20-ans-sht31-d-show-up-as-combined-sensors-on-domoticz/15 I send every 5 minutes and check the value before so that I only send if the value has changed I have been running my sensor for nearly 2 months now and battery level has only decreased 1-2% Make sure you use 1 MHz bootloader
  • Rfm69 and that pesky antenna

    8
    0 Votes
    8 Posts
    6k Views
    rmtuckerR
    Thank you everyone for your input on this. Eventually i just used a piece of wire 82mm long and bent it over and stuck it out of one of the slots in the housing. Crude i know but the initial results are promising. The Gateway is in one corner of the house upstairs and i placed the sensor in the opposite diagonal corner downstairs in the house through a guess of 4 brick walls and the sensor is reporting an Rssi of -65db ti -70db. Shame Rssi can not be presented in Domoticz properly yet (Having to use a dummy sound sensor to visualise it) as mysensors has no way of handling it yet!. I will be conducting more range tests but the change from NRF24 was well worth it (No more deadspots in the house).
  • How to mill a PCB at Home!

    11
    6 Votes
    11 Posts
    8k Views
    Martin TellblomM
    Hi all, Just bought a little CNC + Laser engraver machine that I'm going to use for PCB milling and have some questians for the experienced users. @Frank-Herrmann will your Chillipeppr code work on all arduino/gcode based CNC routers? Any other free software like BamCam for use will small projects? What cutting bits are you using for PCB milling?
  • Measuring battery

    5
    0 Votes
    5 Posts
    3k Views
    meanmrgreenM
    @sundberg84 Will look into that, i have a UNO lying around aswell so prehaps ill experiment with the bootloader burning eventually.
  • My own board (50mm x 30mm)

    133
    1 Votes
    133 Posts
    100k Views
    GertSandersG
    @alexsh1 Indeed, there is a solderpad near to the D2 pin which needs to be closed (connected) to allow the IRQ signal to go to D2, so one can use the radio
  • LIVOLO alike switch mod

    3
    0 Votes
    3 Posts
    2k Views
    mfalkviddM
    https://forum.mysensors.org/topic/5719/livolo-eu-switch-mysensors-integration might be useful
  • RFID Garage door opener

    2
    0 Votes
    2 Posts
    1k Views
    mfalkviddM
    @vlad1 welcome to the MySensors community! Who are you asking? About which project are you asking? Can you post a link to it? If you mean this project, the code is right there in the first post.
  • ORP/PH Node

    1
    3 Votes
    1 Posts
    940 Views
    No one has replied

14

Online

11.8k

Users

11.2k

Topics

113.2k

Posts