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
8

8200

@8200
About
Posts
4
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Trouble combining sketches for temp and motion control
    8 8200

    I am gratefull ;)

    I will try to compare the sketches.

    Troubleshooting

  • Trouble combining sketches for temp and motion control
    8 8200

    @hek But I was hoping to use the DS18b20?

    Troubleshooting

  • Trouble combining sketches for temp and motion control
    8 8200

    @hek Wow - thanks for a fast reply

    I have used a some what similar sketch as a basis and I guess I go wrong when adapting the sketch to the Dallas sensor which I presume is needed?

    Troubleshooting

  • Trouble combining sketches for temp and motion control
    8 8200

    Hi,

    So I am new to building sensors.

    I have managed to build a ethernet gateway and have this connect to my Vera2.

    Furthermore I have succeeded in building temperature and motion sensors.

    So far so good.

    Now I want to combine the sensors in a new sensor - a 230V powered motion and temp sensor (based on a Nano-clone)

    I have search the forum to see if anyone else has made this kind of sensor (for me to copy the sketch) but with no luck.

    I have the tried to combine the temp sketch and the motion sketch from the build-page, into the below sketch but the sketch wont compile. I have no experience in this so my combination is mostly based on gut-feeling :)

    Is there any one who can have a look at the sketch and explain where I go wrong or even better - are there anyone with a similar sensor and working sketch that I can use?

    #include <MySensor.h>
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>

    #define CHILD_ID_MOT 2 // Id of the sensor child
    #define ONE_WIRE_BUS 4 // Pin where dallase sensor is connected

    #define MAX_ATTACHED_DS18B20 16
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);

    #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)

    MySensor gw;
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    boolean receivedConfig = false;
    boolean metric = true;
    // Initialize temperature message
    MyMessage msg(0,V_TEMP);

    // Initialize motion message
    MyMessage msgMot(CHILD_ID_MOT, V_TRIPPED);

    void setup()
    {
    sensors.begin();

    gw.begin();

    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("Motion Sensor", "1.0");

    numSensors = sensors.getDeviceCount();

    for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
    gw.present(i, S_TEMP);

    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)
    gw.present(CHILD_ID_MOT, S_MOTION);

    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("Temperature Sensor", "1.0");

    // Fetch the number of attached temperature sensors
    numSensors = sensors.getDeviceCount();

    // Present all sensors to controller
    for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
    gw.present(i, S_TEMP);
    }
    }

    void loop()
    {

    // Read digital motion value
    boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;

    Serial.println(tripped);
    gw.send(msg.set(tripped?"1":"0")); // Send tripped value to gw

    {
    // Process incoming messages (like config from server)
    gw.process();

    // Fetch temperatures from Dallas sensors
    sensors.requestTemperatures();

    // Read temperatures and send them to controller
    for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {

    // Fetch and round temperature to one decimal
    float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
    
    // Only send data if temperature has changed and no error
    if (lastTemperature[i] != temperature && temperature != -127.00) {
    
      // Send in the new temperature
      gw.send(msg.setSensor(i).set(temperature,1));
      lastTemperature[i]=temperature;
    }
    

    }

    // Sleep until interrupt comes in on motion sensor. Send update every two minute.
    gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
    }
    }

    Thanks!

    Troubleshooting
  • Login

  • Don't have an account? Register

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