Navigation

    • Register
    • Login
    • Search
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Nicklas Starkel
    3. Topics
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Topics created by Nicklas Starkel

    • Nicklas Starkel

      Watering flowers on the balcony + LED illumination
      My Project • • Nicklas Starkel  

      3
      1
      Votes
      3
      Posts
      1344
      Views

      Tmaster

      Nice. i`m building an version that control just 2 selenoids valvs 24v AC controlled by 5-12v DC . i will post it when its ready.stills testing the humidity sensor .. i build it from scratch because i change all the smart features to the sensors instead of depending from the gw. one of selenoids work all days ,the other just day yes ,day not.
    • Nicklas Starkel

      delay different functions in loop
      Troubleshooting • • Nicklas Starkel  

      2
      0
      Votes
      2
      Posts
      1172
      Views

      Nicklas Starkel

      After some hours of sleep and refactoring everything, now I think I've managed to get everything working. I have some problem wrapping my head around "forceTransmit" command and how it works. Also, millis() is also something I have to learn Here is the code if anyone finds it interesting. What it does is measure soil moisture every hour and sends info (normal forkthingie). Also reading every 30 seconds for temperature and humidity (si7021) If humidity changes by 1 or temperature by 0.2 it will send info. If no info has been sent it will force send info every 20 minutes. 3 Relays are there to power water pumps and a LED strip. i have now semi-learned the use of functions, which is fun cheers! /** * 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 * Example sketch showing how to control physical relays. * This example will remember relay state after power failure. * http://www.mysensors.org/build/relay */ // Enable debug prints to serial monitor #define MY_DEBUG //Network #define MY_NODE_ID 62 #define MY_PARENT_NODE_ID 0 #define MY_PARENT_NODE_IS_STATIC #define MY_RADIO_NRF24 //Includes #include <SPI.h> #include <MySensors.h> #include <SI7021.h> #include <RunningAverage.h> //Define Relay #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define RELAY_2 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define RELAY_3 5 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 3 // Total number of attached relays #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay #define RELEASE "1.4" //Define Moisture things #define AVERAGES 2 // Child sensor ID's #define CHILD_ID_TEMP 5 #define CHILD_ID_HUM 6 #define CHILD_ID_MOISTURE 7 // How many milli seconds between each measurement of temp and humidity #define MEASURE_INTERVAL 30000 // FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller #define FORCE_TRANSMIT_INTERVAL 2000 // 20minutes // HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with // TEMP_TRANSMIT_THRESHOLD for temperature threshold. #define HUMI_TRANSMIT_THRESHOLD 1.0 #define TEMP_TRANSMIT_THRESHOLD 0.2 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #define N_ELEMENTS(array) (sizeof(array)/sizeof((array)[0])) #define STABILIZATION_TIME 1000 // Let the sensor stabilize before reading SI7021 humiditySensor; // Sensor messages MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgMoist(CHILD_ID_MOISTURE, V_HUM); MyMessage msgR1(RELAY_1, V_STATUS); MyMessage msgR2(RELAY_2, V_STATUS); // Global settings const unsigned long tUpdateTemp = 5000; // update interval unsigned long t0; const unsigned long tUpdateMoist = 360000; // update interval unsigned long t1; int measureCount = 0; boolean isMetric = true; boolean highfreq = true; boolean transmission_occured = false; // Storage of old measurements float lastTemperature = -100; int lastHumidity = -100; int oldMoistureLevel = -1; //Change direction on moisture byte direction = 0; //Moisture sensor pins RunningAverage raHum(AVERAGES); const int SENSOR_ANALOG_PINS[] = {A0, A1}; // Sensor is connected to these two pins. Avoid A3 if using ATSHA204. A6 and A7 cannot be used because they don't have pullups. void before() { for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } } void setup() { Serial.begin(115200); humiditySensor.begin(); isMetric = getControllerConfig().isMetric; Serial.print(F("isMetric: ")); Serial.println(isMetric); raHum.clear(); t0=millis(); t1=millis(); //sendTempHumidityMeasurements(true); //sendMoistureMeasurements(); delay(250); for (int i = 0; i < N_ELEMENTS(SENSOR_ANALOG_PINS); i++) { pinMode(SENSOR_ANALOG_PINS[i], OUTPUT); digitalWrite(SENSOR_ANALOG_PINS[i], LOW); } } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("RelayTempHumMoist", "1.0"); for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY,"Relays"); } present(CHILD_ID_TEMP,S_TEMP,"Temperature"); present(CHILD_ID_HUM,S_HUM,"Humidity"); present(CHILD_ID_MOISTURE, S_HUM,"Moisture"); } void loop() { measureCount ++; bool forceTransmit = false; transmission_occured = false; if (measureCount > FORCE_TRANSMIT_INTERVAL) { forceTransmit = true; measureCount = 0; Serial.print(F("inne i loopen :")); } if ((millis() - t1) > tUpdateMoist) sendMoistureMeasurements(); sendTempHumidityMeasurements(forceTransmit); } void sendTempHumidityMeasurements(bool force) { wait(MEASURE_INTERVAL); bool tx = force; si7021_env data = humiditySensor.getHumidityAndTemperature(); raHum.addValue(data.humidityPercent); float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100.0); float diffHum = abs(lastHumidity - raHum.getAverage()); Serial.print(F("TempDiff :"));Serial.println(diffTemp); Serial.print(F("HumDiff :"));Serial.println(diffHum); t0 = millis(); if (isnan(diffHum)) tx = true; if (diffTemp > TEMP_TRANSMIT_THRESHOLD) tx = true; if (diffHum > HUMI_TRANSMIT_THRESHOLD) tx = true; if (tx) { measureCount = 0; float temperature = (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0; int humidity = data.humidityPercent; Serial.print("T: ");Serial.println(temperature); Serial.print("H: ");Serial.println(humidity); send(msgTemp.set(temperature,1)); send(msgHum.set(humidity)); lastTemperature = temperature; lastHumidity = humidity; transmission_occured = true; } } void sendMoistureMeasurements() { pinMode(SENSOR_ANALOG_PINS[direction], INPUT_PULLUP); // Power on the sensor analogRead(SENSOR_ANALOG_PINS[direction]);// Read once to let the ADC capacitor start charging sleep(STABILIZATION_TIME); int moistureLevel = (1023 - analogRead(SENSOR_ANALOG_PINS[direction])); // Turn off the sensor to conserve battery and minimize corrosion pinMode(SENSOR_ANALOG_PINS[direction], OUTPUT); digitalWrite(SENSOR_ANALOG_PINS[direction], LOW); direction = (direction + 1) % 2; // Make direction alternate between 0 and 1 to reverse polarity which reduces corrosion // Always send moisture information so the controller sees that the node is alive // Send rolling average of 2 samples to get rid of the "ripple" produced by different resistance in the internal pull-up resistors // See http://forum.mysensors.org/topic/2147/office-plant-monitoring/55 for more information if (oldMoistureLevel == -1) { // First reading, save value oldMoistureLevel = moistureLevel; } send(msgMoist.set((moistureLevel + oldMoistureLevel + 0.5) / 2 / 10.23, 1)); oldMoistureLevel = moistureLevel; t1 = millis(); } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_STATUS) { // Change relay state digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom 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()); } }```
    • Nicklas Starkel

      [SOLVED] After upgrade to mysensors 2.1 problems with radio module might manifest itself more.
      Troubleshooting • • Nicklas Starkel  

      23
      0
      Votes
      23
      Posts
      6449
      Views

      Anticimex

      @Nicklas-Starkel nice to hear! We are constantly trying to improve the performance in various aspects. I think it is @tekka that deserves the credit for increased rf performance as he has done a tremendous work with the drivers.
    • Nicklas Starkel

      Sleep time is not actual sleep time
      Troubleshooting • • Nicklas Starkel  

      4
      0
      Votes
      4
      Posts
      1322
      Views

      Nicklas Starkel

      @Yveaux and @mfalkvidd thanks! It's not important for me, just curious to know why
    • Nicklas Starkel

      Forced transmit by threshold is not working
      Troubleshooting • • Nicklas Starkel  

      3
      0
      Votes
      3
      Posts
      765
      Views

      Nicklas Starkel

      @mfalkvidd thanks! I actually found the problem while messing around with different settings. I changed 'uint16_t' to regular 'int' and it started working! Now, both should have worked (I guess by doing a quick google on uint16_t). So as to why how what.. im perplexed. Thanks for looking at the code