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
H

Hausner

@Hausner
About
Posts
48
Topics
13
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • 230V power supply to Arduino
    H Hausner

    I have with succes used these:

    http://www.aliexpress.com/item/Travel-Convenient-EU-Plug-Wall-USB-Charger-Adapter-For-Samsung-Galaxy-S5-S4-S3-Note-3/32220133044.html

    They are really easy to dismatle, and the result is this - https://www.dropbox.com/s/ep43uyve5v0msv6/20141206_214210.jpg?dl=0

    At $1.10 I didn't even think about making my own PSU :)

    Hardware

  • Motion (PIR), actuator and Temp sensor
    H Hausner

    Ok, finally got it to work with this:

    // Example sketch showing how to control physical relays. 
    // This example will remember relay state even after power failure.
    
    #include <MySensor.h>
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
    #define MAX_ATTACHED_DS18B20 16
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    //boolean receivedConfig = false;
    boolean metric = true;
    #define RELAY_1 5  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define RELAY_2 6
    #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
    
    // Motion sensor defs
    unsigned long SLEEP_TIME = 10000; // Sleep time between reports (in milliseconds)
    #define DIGITAL_INPUT_SENSOR 4   // 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)
    #define CHILD_ID 3   // Id of the sensor child
    
    boolean lastTrippedState;
    
    MySensor gw;
    //
    MyMessage msgTemp(0, V_TEMP);
    MyMessage msgRelay2(2, V_LIGHT);
    MyMessage msgMotion(3, V_TRIPPED);
    
    void setup()  
    {   
      gw.begin(incomingMessage, AUTO, true);
      gw.sendSketchInfo("Temp/Relay/Motion Sensor", "1.0");
      //
      gw.present(1, S_LIGHT);
      pinMode(RELAY_1, OUTPUT);
      //
      gw.present(2, S_LIGHT);
      pinMode(RELAY_2, OUTPUT);
      digitalWrite(RELAY_1, gw.loadState(1)? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_2, gw.loadState(1)? RELAY_ON : RELAY_OFF);
      pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
      //
      gw.present(CHILD_ID, S_MOTION);
      
      // 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(0, S_TEMP);
      //}
    }
    //
    void loop() 
    {
      gw.process();
      boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
      if (tripped != lastTrippedState)
      {  
        Serial.println(tripped? "tripped" : "not tripped");
        gw.send(msgMotion.set(tripped?"1":"0"));  // Send tripped value to gw//
        //digitalWrite(RELAY_1, tripped? 1 : 0);
      }
      lastTrippedState = tripped;
      
      // 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(0):sensors.getTempFByIndex(0)) * 10.)) / 10.;
    
        // Only send data if temperature has changed more then 1 degC and no error
        if (int(lastTemperature[0]) != int(temperature) && temperature != -127.00) { //added integer
    
          // Send in the new temperature
          gw.send(msgTemp.setSensor(0).set(temperature,1));
          lastTemperature[0]=temperature;
        }
       //}
    }
    
    void incomingMessage(const MyMessage &message) {
      // 
      if (message.type==V_LIGHT && message.sensor == 2) 
      {
        // Change relay state
        digitalWrite(RELAY_2, 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());
      }
    }
    
    Hardware
  • Login

  • Don't have an account? Register

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