Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
zrom69Z

zrom69

@zrom69
About
Posts
23
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • 💬 Building a wired RS485 sensor network
    zrom69Z zrom69

    @dzjr
    thank you for your reply
    at least 10 children in node and 30 nodes
    @dzjr

    Announcements

  • 💬 Building a wired RS485 sensor network
    zrom69Z zrom69

    thank you for your reply
    at least 10 children in node and 30 nodes

    Announcements

  • 💬 Building a wired RS485 sensor network
    zrom69Z zrom69

    and it can have blockages if there are sensors that function or even time
    thanks

    Announcements

  • 💬 Building a wired RS485 sensor network
    zrom69Z zrom69

    Hi,
    in a node how many children can put rs-485
    thanks good work

    Announcements

  • What did you build today (Pictures) ?
    zrom69Z zrom69

    @mfalkvidd good job

    General Discussion

  • Clock with temperature, humidity and CO2 level sensors
    zrom69Z zrom69

    hi
    I have this error
    'class SensorMQ' has no member named 'setCurveScalingFactor'

    My Project

  • relay as a switch not as a button (domoticz)
    zrom69Z zrom69

    thanks for the work you did
    i add the motion sensor and light level sensor its not working well
    you can help me thank you

    /*
    Relay with toggle switch sketch
    modified to work with no uplink
    to gateway
    Toggle switch connected between pin3 and ground.
    */

    #define MY_DEBUG // Enable debug prints to serial monitor

    #define MY_RADIO_NRF24 // Enable and select radio type attached

    #define MY_TRANSPORT_WAIT_READY_MS 5000 //set how long to wait for transport ready in milliseconds

    #include <MySensors.h>
    #include <Bounce2.h>

    #define CHILD_ID_LEVEL A0
    #define RELAY_PIN 5 // Arduino Digital I/O pin number for relay
    #define SWITCH_PIN 4 // Arduino Digital I/O pin number for switch
    #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)

    #define CHILD_ID 1 // Id of the sensor child
    #define CHILD_ID_MOT 2 //motion sensor
    #define CHILD_ID_LEVEL 3
    #define RELAY_ON 1
    #define RELAY_OFF 0

    Bounce debouncer = Bounce();
    int oldswitchState = 0;
    bool state = false;
    bool firstStart = true;
    int photocellPin = 0; // The photoresistor and resistance 10 / 12KOhms connected on the pin / analog pin A0
    int photocellReading;

    unsigned long interval= 6000;//dht.getMinimumSamplingPeriod(); // the time we need to wait
    unsigned long previousMillis=0; // millis() returns an unsigned long.
    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)

    MyMessage msg(CHILD_ID, V_STATUS);
    MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);
    MyMessage msgLight(CHILD_ID_LEVEL, V_LIGHT_LEVEL);

    void setup(){
    pinMode(SWITCH_PIN, INPUT_PULLUP); // Setup the button pin, Activate internal pull-up
    debouncer.attach(SWITCH_PIN); // After setting up the button, setup debouncer
    debouncer.interval(5);

    pinMode(RELAY_PIN, OUTPUT); // set relay pin in output mode
    digitalWrite(RELAY_PIN, RELAY_OFF); // Make sure relay is off when starting up
    }

    void presentation() {
    // Send the sketch version information to the gateway and Controller
    sendSketchInfo("Relay & Toggle", "1.0");

    // Register all sensors to gw (they will be created as child devices)
    present(CHILD_ID, S_BINARY);
    present(CHILD_ID_LEVEL, S_LIGHT_LEVEL);
    present(CHILD_ID_MOT, V_TRIPPED); //me
    }

    void loop(){

    if (firstStart) { // this code is only run once at startup
    debouncer.update();
    oldswitchState = debouncer.read(); // set oldswitchState to the current toggle switch state
    send(msg.set(false), false); // notify controller of current state no ack
    firstStart = false; // set firstStart flag false to prevent code from running again
    }
    debouncer.update();
    int switchState = debouncer.read(); // Get the update value
    if (switchState != oldswitchState) { // check for new throw of toggle switch
    state = !state; // Toggle the state
    digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF); // switch the relay to the new state
    send(msg.set(state), false); // notify controller of current state no ack
    oldswitchState = switchState;
    }
    // Read digital motion value
    boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;

    // only run loop if time has passed.
    unsigned long currentMillis = millis(); // grab current time

    // check if "interval" time has passed
    if ((unsigned long)(currentMillis - previousMillis) >= interval) {

    send(msgMot.set(tripped?"1":"0"));

    photocellReading = analogRead(photocellPin)/10; // Conversion en 100% (approximatif)
    // Valeur de la photorésistance avec lampe torche devant = ~1000
    Serial.print("Luminosité : ");
    Serial.println(photocellReading);
    send(msgLight.set(photocellReading, 1));

          if(tripped == 1 && photocellReading < 30)           // Si la luminosité est inférieure à 30%
    

    #ifdef MY_DEBUG
    Serial.print("Motion: ");
    Serial.println(tripped);
    #endif
    }
    }
    /-------------------start of functions--------------------------/

    void receive(const MyMessage &message) {
    if (message.type == V_STATUS) { // check to see if incoming message is for a switch
    state = message.getBool(); // get the new state
    digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF); // switch relay to new state

        /*---- Write some debug info----*/
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getBool());         
    

    }
    }

    Domoticz

  • I'm not good at programming
    zrom69Z zrom69

    in domoticz he sends his state of light
    it is he and turn on or off

    Troubleshooting

  • I'm not good at programming
    zrom69Z zrom69

    thank you for your response
    light with classic toggle switch
    and i have add pir sensor
    for what I ask to correct
      I have to thank you

    Troubleshooting

  • I'm not good at programming
    zrom69Z zrom69

    Hello I'm not good at programming I mix two motion light my times his block is what a he can look at thank

    #define MY_DEBUG

    #define MY_RF24_CE_PIN A0
    #define MY_RADIO_NRF24
    #define MY_REPEATER_FEATURE

    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>

    #define MOTION_PIN 4
    #define RELAY_ON 1
    #define RELAY_OFF 0

    #define SSR_A_ID 1 // Id of the sensor child
    #define MOTION_ID 2

    // Sleep time between reads (in milliseconds)
    unsigned long SLEEP_TIME = 100000;

    unsigned long T = 1;

    const int buttonPinA = 3;
    const int relayPinA = 5;
    int oldValueA = 0;
    bool stateA = false;
    bool lastMotion;

    Bounce debouncerA = Bounce();

    MyMessage msgA(SSR_A_ID, V_STATUS);
    MyMessage motion_msg(MOTION_ID, V_TRIPPED);

    void setup()
    {

    pinMode(buttonPinA, INPUT_PULLUP); // Setup the button Activate internal pull-up
    // Then set relay pins in output mode
    pinMode(relayPinA, OUTPUT);

    // After setting up the buttons, setup debouncer
    debouncerA.attach(buttonPinA);
    debouncerA.interval(5);

    // Make sure relays are off when starting up
    digitalWrite(relayPinA, RELAY_OFF);

    // Define the motion sensor pin for digital input
    pinMode(MOTION_PIN, INPUT);

    /*--------------------- Added these lines for toggle switch-------------------------*/
    

    oldValueA = digitalRead(buttonPinA); // set oldValueA to the current status of the toggle switch
    send(msgA.set(false)); // Send off state for relayA to ensure controller knows the switch is off

    }

    void presentation() {
    // Send the sketch version information to the gateway and Controller
    sendSketchInfo("Mains Controller", "1.0");

    // Register all sensors to gw (they will be created as child devices)
    present(SSR_A_ID, S_LIGHT);

    // Register the motion sensor to the gateway
    present(MOTION_ID, S_MOTION);
    }

    /*
    Example on how to asynchronously check for new messages from gw
    */
    void loop()
    {
    debouncerA.update();
    // Get the update value
    int valueA = debouncerA.read();
    if (valueA != oldValueA) {
    send(msgA.set(stateA ? false : true), true); // Send new state and request ack back
    oldValueA = valueA;
    }
    // Read digital motion value
    bool motion = digitalRead(MOTION_PIN) == HIGH;

    if (motion != lastMotion) {
    // Send tripped value to gw
    send(motion_msg.set(motion ? "1" : "0"));
    lastMotion = motion;
    }
    T++;
    if (T > SLEEP_TIME) {
    T = 1;
    Serial.print("Motion: ");
    Serial.println(motion);

    }
    

    }

    void receive(const MyMessage &message) {
    // We only expect one type of message from controller. But we better check anyway.
    if (message.type == V_STATUS) {

    switch (message.sensor) {
      case 1:
        stateA = message.getBool();
        digitalWrite(message.sensor + 4, stateA ? RELAY_ON : RELAY_OFF);
        
        break;
      
    }
    
      // Write some debug info
    Serial.print("Incoming change for sensor:");
    Serial.println(message.sensor);
    Serial.print("from node:");
    Serial.println(message.sender);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
    

    }
    }

    Troubleshooting

  • Multiple switch inputs
    zrom69Z zrom69

    yes you can change
    you go on switch press edit after a window that opens
    you go to Switch Type and you find motion
    safeguard

    Hardware

  • Multiple switch inputs
    zrom69Z zrom69

    it's normal with domoticz same motion you can do it off
    you have to protect how it works you can not operate it anymore

    Hardware

  • What did you build today (Pictures) ?
    zrom69Z zrom69

    and that's a TV box turn into a mini pc more powerful than raspberry pi 3
    and I installed linux with domoticez and imperihome EMMC Flash is fluid and fast
    and toutsca works well

    8 x CPU: Amlogic S912 Octa core ARM Cortex-A53 CPU jusqu'à 2GHz (DVFS)
    GPU: 750MHz + ARM Mali-820MP3 GPU Processeur
    RAM: 3Go DDR3
    ROM: 32Go EMMC Flash
    Système d'exploitation: Android 6.0
    Ethernet: 100M/1000M
    WIFI: 2.4GHZ / 5.8GHZ 802.11a / b / g / n / Ac
    Bluetooth: BT4.1
    0_1521059381799_^C93E5C8C7E6C5F03C9EEEBA000E69D846D47F6D85F5CFA84D6^pimgpsh_fullsize_distr.jpg

    General Discussion

  • What did you build today (Pictures) ?
    zrom69Z zrom69

    here is photo my usb gateway with STM32 power
    it's a big difference with arduino nano0_1521058384234_^80B8C6188DE448790B3E345195F473A2EDB5AA9D57B09A0C13^pimgpsh_fullsize_distr.jpg

    General Discussion

  • help to pass version 2 mysensors
    zrom69Z zrom69

    @gohan

    you can check i add module rain

    // Example sketch för a "light switch" where you can control light or something 
    // else from both vera and a local physical button (connected between digital
    // pin 3 and GND).
    // This node also works as a repeader for other nodes
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_NODE_ID 2
    #define MY_PARENT_NODE_ID  0
    #define MY_PARENT_NODE_IS_STATIC
    #include <MySensors.h>
    #include <SPI.h>
    #include <DHT.h> 
    
    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    
    //pin sensori
    #define PIR_PIN 6                   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define HUMIDITY_TEMPERATURE_PIN 3  // sensore temperatura umidita
    #define RELAY_PIN  4   // relay pin
    #define DIGITAL_INPUT_RAIN_SENSOR 5
    int BATTERY_SENSE_PIN = A1;         // Pin carica batteria o pannello solare
    int FOTORESIST_SENSE_PIN = A2;      // Pin fotoresistenza
    
    //interupt per sleep arduino
    #define INTERRUPT PIR_PIN-6 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define INTERRUPT DIGITAL_INPUT_RAIN_SENSOR-2
    
    //id per vera
    #define CHILD_ID_RELE 1   // Id relay
    #define CHILD_ID_HUM 2    // id temperatura
    #define CHILD_ID_TEMP 3   // id umidita
    #define CHILD_ID_PIR 4    // Id pir
    #define CHILD_ID_LIGHT 5  // Id luminosita (fotoresistenza)
    #define CHILD_ID_RAIN 6
    
    //definizione per nodo vera
    #define NODE_ID 10
    #define SN "meteo station"
    #define SV "1.4"
    
    //variabili
    bool state_relay;                 //stato relay
    float batt_valore;                //dichiaro la variabile valore che memorizzerà il valore della batteria dal pin analogico
    float batt_volt;                  //volt batteria
    float batt_charged_percent;       //percentuale carica batteria
    float last_batt_charged_percent;  //percentuale carica batteria precedente
    float batt_min_voltage = 0.5;     //tensione minima batteria
    float batt_max_voltage = 5;       //tensione massima batteria
    float fotoresistenza_valore;      //dichiaro la variabile valore che memorizzerà il valore della fotoresistenza dal pin analogico
    float last_fotoresistenza_valore; //dichiaro la variabile valore precedente
    int lastRainValue = -1;
    int nRainVal;
    boolean bIsRaining = false;
    String strRaining = "NO";
    int lux_vera;                      //valore luminosita da inviare a vera
    
    
    
    // sensore temperatura umidita
    DHT dht_int;
    float lastTemp_int = -1;
    float lastHum_int = -1;
    
    boolean metric = true; 
    
    MyMessage msgRelay(CHILD_ID_RELE,V_LIGHT);
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgPir(CHILD_ID_PIR, V_TRIPPED);
    MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    MyMessage msgRain(CHILD_ID_RAIN, V_TRIPPED);
    
    void setup()  
    {  
     metric = getControllerConfig().isMetric;
      // Then set relay pins in output mode
      pinMode(RELAY_PIN, OUTPUT);
    
      pinMode(DIGITAL_INPUT_RAIN_SENSOR, INPUT);
      
      //PIR
      pinMode(PIR_PIN, INPUT);
      
      state_relay = 0;  
      //GestisciRelay();
      digitalWrite(RELAY_PIN, LOW);
      send(msgRelay.set(state_relay)); 
         
    }
    
    
    void presentation() 
    {
          
      
      sendSketchInfo(SN, SV); 
    
      //Sensore umidita temperatura
      dht_int.setup(HUMIDITY_TEMPERATURE_PIN);
      
      present(CHILD_ID_RELE, S_LIGHT);       //light vera
      present(CHILD_ID_HUM, S_HUM);          //umidity vera
      present(CHILD_ID_TEMP, S_TEMP);           // temp vera
      present(CHILD_ID_PIR, S_MOTION);          // motion vera
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);  //light level (fotoresistenza)
      present(CHILD_ID_RAIN, S_MOTION, "WS Rain");
    
    }
    void loop() 
    { 
        
      
        //sensore temperatura umidita
        delay(dht_int.getMinimumSamplingPeriod());
    
        float temperature_int = dht_int.getTemperature();
        if (isnan(temperature_int)) 
        {
            lastTemp_int = -1;
            Serial.println("Failed reading temperature from DHT");
        } 
        else if (temperature_int != lastTemp_int) 
        {
          lastTemp_int = temperature_int;
          if (!metric) 
          {
            temperature_int = dht_int.toFahrenheit(temperature_int);
          }
          send(msgTemp.set(temperature_int, 1));
          Serial.print("T int: ");
          Serial.println(temperature_int);
        }
      
        float humidity_int = dht_int.getHumidity();
        if (isnan(humidity_int)) 
        {
            lastHum_int = -1;
            Serial.println("Failed reading humidity from DHT");
        } 
        else if (humidity_int != lastHum_int) 
        {
            lastHum_int = humidity_int;
            send(msgHum.set(humidity_int, 1));
            Serial.print("H int: ");
            Serial.println(humidity_int);
        }
        //sensore temperatura umidita
        
        //fotoresistenza    
        for(int i=0;i<150;i++)
        {
          fotoresistenza_valore += analogRead(FOTORESIST_SENSE_PIN);  //read the input voltage from battery or solar panel      
          delay(2);
        }
        fotoresistenza_valore = fotoresistenza_valore / 150;    
               
        Serial.print ("fotoresistenza: ");
        Serial.println(fotoresistenza_valore); 
    
        if (fotoresistenza_valore != last_fotoresistenza_valore) 
        {
          lux_vera = (int) fotoresistenza_valore;
          send(msgLux.set(lux_vera));
          last_fotoresistenza_valore = fotoresistenza_valore;
        }    
        //fotoresistenza
        
        //pir relay
        // Read digital motion value
        boolean tripped = digitalRead(PIR_PIN) == HIGH; 
        Serial.println("pir:");      
        Serial.println(tripped);
        send(msgPir.set(tripped?"1":"0"));  // Send tripped value to gw 
        
        //accende la luce con il buio
        if (fotoresistenza_valore < 200)  //poca luce
        {
          if (tripped == 1) 
          {
             state_relay = 1;     
          }
          else
          {
             state_relay = 0;     
          }
        }
        //accende la luce con il buio
        
        GestisciRelay();
        //pir relay
        
        //battery    
        for(int i=0;i<150;i++)
        {
          batt_valore += analogRead(BATTERY_SENSE_PIN);  //read the input voltage from battery or solar panel      
          delay(2);
        }
        batt_valore = batt_valore / 150;    
               
        Serial.print ("batt_valore: ");
        Serial.println(batt_valore);
        
        batt_volt = (batt_valore / 1024) * batt_max_voltage;
        Serial.print ("batt_volt: ");
        Serial.println(batt_volt);
        
        ////////////////////////////////////////////////
       //The map() function uses integer math so will not generate fractions
       // so I multiply battery voltage with 10 to convert float into a intiger value
       // when battery voltage is 6.0volt it is totally discharged ( 6*10 =60)
       // when battery voltage is 7.2volt it is fully charged (7.2*10=72)
       // 6.0v =0% and 7.2v =100%
       //batt_charged_percent = batt_volt*10;   
       //batt_charged_percent = map(batt_volt*10, 60 , 72, 0, 100);
        batt_charged_percent = batt_volt * 10;   
        batt_charged_percent = map(batt_volt * 10, batt_min_voltage * 10 , batt_max_voltage * 10, 0, 100);
        //batt_charged_percent = (batt_volt / batt_max_voltage) * 100;
        Serial.print ("batt_charged_percent: ");
        Serial.println(batt_charged_percent);
           
        if (last_batt_charged_percent != batt_charged_percent) 
        {
            sendBatteryLevel(batt_charged_percent);
            last_batt_charged_percent = batt_charged_percent;        
        }
        
        bIsRaining = !(digitalRead(DIGITAL_INPUT_RAIN_SENSOR));
          if(bIsRaining){
              strRaining = "YES";
          }
          else{
              strRaining = "NO";
          }
      
          //Serial.print("Raining?: ");
          //Serial.print(strRaining);  
          //Serial.print("\t Moisture Level: ");
          //Serial.println(nRainVal);
          //http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-rain-sensor-module-guide-and-tutorial/
    
          send(msgRain.set(bIsRaining, 1));
        
        //battery
        
        delay(50);
        
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.   
        sleep(INTERRUPT, CHANGE, SLEEP_TIME);
        
        
    } 
     
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_LIGHT) {
         // Change relay state_relay
         state_relay = message.getBool();
         GestisciRelay();
        
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
       
      
    }
    
    
    
    void GestisciRelay()
    {
        //Serial.print(" GestisciRelay state_relay:");
        //Serial.println(state_relay);
      
        if (state_relay == 0)
        {
          digitalWrite(RELAY_PIN, LOW);
          send(msgRelay.set(state_relay));
          //Serial.println("SPENTO RELAY");
        }
        else 
       {
          digitalWrite(RELAY_PIN, HIGH);
          send(msgRelay.set(state_relay));
          //Serial.println("ACCESO RELAY");
       } 
    
      
    }
    
    Development

  • help to pass version 2 mysensors
    zrom69Z zrom69

    @zrom69 said in help to pass version 2 mysensors:

    Hello
    I am a beginner in programming and excuse me
    my english
    i tried to go to v 2 his function not these you can m help thank you in advance[0_1514023990085_sketch_dec23b.ino](Envoi en cours 100%)

    // Example sketch för a "light switch" where you can control light or something 
    // else from both vera and a local physical button (connected between digital
    // pin 3 and GND).
    // This node also works as a repeader for other nodes
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <DHT.h> 
    
    unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
    
    //pin sensori
    #define PIR_PIN 2                   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
    #define HUMIDITY_TEMPERATURE_PIN 3  // sensore temperatura umidita
    #define RELAY_PIN  4                // relay pin
    int BATTERY_SENSE_PIN = A1;         // Pin carica batteria o pannello solare
    int FOTORESIST_SENSE_PIN = A2;      // Pin fotoresistenza
    
    //interupt per sleep arduino
    #define INTERRUPT PIR_PIN-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    
    //id per vera
    #define CHILD_ID_RELE 1   // Id relay
    #define CHILD_ID_HUM 2    // id temperatura
    #define CHILD_ID_TEMP 3   // id umidita
    #define CHILD_ID_PIR 4    // Id pir
    #define CHILD_ID_LIGHT 5  // Id luminosita (fotoresistenza)
    
    //definizione per nodo vera
    #define NODE_ID 10
    #define SN "meteo station"
    #define SV "1.4"
    
    //variabili
    bool state_relay;                 //stato relay
    float batt_valore;                //dichiaro la variabile valore che memorizzerà il valore della batteria dal pin analogico
    float batt_volt;                  //volt batteria
    float batt_charged_percent;       //percentuale carica batteria
    float last_batt_charged_percent;  //percentuale carica batteria precedente
    float batt_min_voltage = 0.5;     //tensione minima batteria
    float batt_max_voltage = 5;       //tensione massima batteria
    float fotoresistenza_valore;      //dichiaro la variabile valore che memorizzerà il valore della fotoresistenza dal pin analogico
    float last_fotoresistenza_valore; //dichiaro la variabile valore precedente
    
    int lux_vera;                      //valore luminosita da inviare a vera
    
    MySensor gw;
    
    // sensore temperatura umidita
    DHT dht_int;
    float lastTemp_int = -1;
    float lastHum_int = -1;
    
    boolean metric = true; 
    
    MyMessage msgRelay(CHILD_ID_RELE,V_LIGHT);
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msgPir(CHILD_ID_PIR, V_TRIPPED);
    MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    
    void setup()  
    {  
      gw.begin(incomingMessage, NODE_ID, false);    
      
      gw.sendSketchInfo(SN, SV); 
    
      //Sensore umidita temperatura
      dht_int.setup(HUMIDITY_TEMPERATURE_PIN);
      
      gw.present(CHILD_ID_RELE, S_LIGHT);       //light vera
      gw.present(CHILD_ID_HUM, S_HUM);          //umidity vera
      gw.present(CHILD_ID_TEMP, S_TEMP);           // temp vera
      gw.present(CHILD_ID_PIR, S_MOTION);          // motion vera
      gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);  //light level (fotoresistenza)
      
      metric = gw.getConfig().isMetric;
      
      // Then set relay pins in output mode
      pinMode(RELAY_PIN, OUTPUT);   
      
      //PIR
      pinMode(PIR_PIN, INPUT);
      
      state_relay = 0;  
      //GestisciRelay();
      digitalWrite(RELAY_PIN, LOW);
      gw.send(msgRelay.set(state_relay)); 
         
    }
    
    void loop() 
    { 
        gw.process();
      
        //sensore temperatura umidita
        delay(dht_int.getMinimumSamplingPeriod());
    
        float temperature_int = dht_int.getTemperature();
        if (isnan(temperature_int)) 
        {
            lastTemp_int = -1;
            Serial.println("Failed reading temperature from DHT");
        } 
        else if (temperature_int != lastTemp_int) 
        {
          lastTemp_int = temperature_int;
          if (!metric) 
          {
            temperature_int = dht_int.toFahrenheit(temperature_int);
          }
          gw.send(msgTemp.set(temperature_int, 1));
          Serial.print("T int: ");
          Serial.println(temperature_int);
        }
      
        float humidity_int = dht_int.getHumidity();
        if (isnan(humidity_int)) 
        {
            lastHum_int = -1;
            Serial.println("Failed reading humidity from DHT");
        } 
        else if (humidity_int != lastHum_int) 
        {
            lastHum_int = humidity_int;
            gw.send(msgHum.set(humidity_int, 1));
            Serial.print("H int: ");
            Serial.println(humidity_int);
        }
        //sensore temperatura umidita
        
        //fotoresistenza    
        for(int i=0;i<150;i++)
        {
          fotoresistenza_valore += analogRead(FOTORESIST_SENSE_PIN);  //read the input voltage from battery or solar panel      
          delay(2);
        }
        fotoresistenza_valore = fotoresistenza_valore / 150;    
               
        Serial.print ("fotoresistenza: ");
        Serial.println(fotoresistenza_valore); 
    
        if (fotoresistenza_valore != last_fotoresistenza_valore) 
        {
          lux_vera = (int) fotoresistenza_valore;
          gw.send(msgLux.set(lux_vera));
          last_fotoresistenza_valore = fotoresistenza_valore;
        }    
        //fotoresistenza
        
        //pir relay
        // Read digital motion value
        boolean tripped = digitalRead(PIR_PIN) == HIGH; 
        Serial.println("pir:");      
        Serial.println(tripped);
        gw.send(msgPir.set(tripped?"1":"0"));  // Send tripped value to gw 
        
        //accende la luce con il buio
        if (fotoresistenza_valore < 200)  //poca luce
        {
          if (tripped == 1) 
          {
             state_relay = 1;     
          }
          else
          {
             state_relay = 0;     
          }
        }
        //accende la luce con il buio
        
        GestisciRelay();
        //pir relay
        
        //battery    
        for(int i=0;i<150;i++)
        {
          batt_valore += analogRead(BATTERY_SENSE_PIN);  //read the input voltage from battery or solar panel      
          delay(2);
        }
        batt_valore = batt_valore / 150;    
               
        Serial.print ("batt_valore: ");
        Serial.println(batt_valore);
        
        batt_volt = (batt_valore / 1024) * batt_max_voltage;
        Serial.print ("batt_volt: ");
        Serial.println(batt_volt);
        
        ////////////////////////////////////////////////
       //The map() function uses integer math so will not generate fractions
       // so I multiply battery voltage with 10 to convert float into a intiger value
       // when battery voltage is 6.0volt it is totally discharged ( 6*10 =60)
       // when battery voltage is 7.2volt it is fully charged (7.2*10=72)
       // 6.0v =0% and 7.2v =100%
       //batt_charged_percent = batt_volt*10;   
       //batt_charged_percent = map(batt_volt*10, 60 , 72, 0, 100);
        batt_charged_percent = batt_volt * 10;   
        batt_charged_percent = map(batt_volt * 10, batt_min_voltage * 10 , batt_max_voltage * 10, 0, 100);
        //batt_charged_percent = (batt_volt / batt_max_voltage) * 100;
        Serial.print ("batt_charged_percent: ");
        Serial.println(batt_charged_percent);
           
        if (last_batt_charged_percent != batt_charged_percent) 
        {
            gw.sendBatteryLevel(batt_charged_percent);
            last_batt_charged_percent = batt_charged_percent;        
        }
        //battery
        
        delay(50);
        
        // Sleep until interrupt comes in on motion sensor. Send update every two minute.   
        gw.sleep(INTERRUPT, CHANGE, SLEEP_TIME);
        
        
    } 
     
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_LIGHT) {
         // Change relay state_relay
         state_relay = message.getBool();
         GestisciRelay();
        
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
       
      
    }
    
    
    
    void GestisciRelay()
    {
        //Serial.print(" GestisciRelay state_relay:");
        //Serial.println(state_relay);
      
        if (state_relay == 0)
        {
          digitalWrite(RELAY_PIN, LOW);
          gw.send(msgRelay.set(state_relay));
          //Serial.println("SPENTO RELAY");
        }
        else 
       {
          digitalWrite(RELAY_PIN, HIGH);
          gw.send(msgRelay.set(state_relay));
          //Serial.println("ACCESO RELAY");
       } 
    
      
    }
    
    Development

  • help to pass version 2 mysensors
    zrom69Z zrom69

    Hello
    I am a beginner in programming and excuse me
    my english
    i tried to go to v 2 his function not these you can m help thank you in advance[0_1514023990085_sketch_dec23b.ino](Envoi en cours 100%)

    Development

  • Problem with multiple relays and delays
    zrom69Z zrom69

    Hi friends
    thank you for your help I have try the code on Arduino pro mini touts the relay they work or even monument must change something in the code Arduino
    I am newbie in Arduino
    there is detection of door opening
    thanks for the help

    Development

  • Problem with multiple relays and delays
    zrom69Z zrom69

    I'm sorry for my English, I'm French
    I try to control node 3 and motorized shutters which card must be used aduino thank you
    :smiley:

    Development
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular