Create relay free potential free switch.



  • Hi there,

    i need some help with an idea i need...
    I looking far a way to control a potential free contact to control an water lock, but without using a relay. if my water lock sees 10K on its connection it keeps it closed so no watering, if it sees 0 ohm it will have permission to water. my plants
    .
    i was thinking to use an opto coupler but those i now need a voltage going tru on the output... or am i wrong.

    or maybe some kind of hal sensor with internal coil controlled by an arduino


  • Mod

    I didn't get what's the problem with the relay



  • battery powered project....


  • Mod

    Transistor? Latching relay? I am just throwing ideas since I haven't fully understood your project.


  • Hardware Contributor

    @Rene046 said in Create relay free potential free switch.:

    battery powered project....

    Why not just use a latching relay ?



  • because i dont want the water lock stay open after power lost.



  • Ok i explain.

    i have and Gardena Watering computer, here i want to connect a controller on battery to
    All this controller has to do via Mysensors is open or close a an switch (the 2 wires of this switch go inside the gardena computer that is looking for an 10k resistance to stop watering the plants, and an open switch 0 ohm to water the plants.

    Some distance further i have an other node that's measuring soil moisture,

    I have this now running by using normal relays, but using 2 of them (2 garden computers ) they use allot of battery power while watering so i was hoping there are some more better options.


  • Mod

    If you are afraid of wasting too much water, just run a command in setup function that checks the status of latching relay and turns it off. In addition there are many arduino projects for watering plants you can look for inspiration


  • Hardware Contributor

    And there are also some latching relays with 2 latches, one to switch on, one to switch off.
    You can just switch off at the beginning of your sketch.
    It's even possible to do that with hardware, to send a pulse to the "switch off" latch when the system is started. So even if your sketch fails to start, your relay will be off.



  • will give it a try.

    this is the sketch i want to implement this in:
    It will be a repeater node,
    I would like to have 2 Relays on pins D3,D4
    And a temperature sensor on D5 (DS1820)
    Eventually an voltage sense pin A3

    /*
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * http://www.mysensors.org/build/relay
     */
    
    // 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_RF24_PA_LEVEL RF24_PA_MAX
    
    // Enabled repeater feature for this node
    #define MY_REPEATER_FEATURE
    #define MY_NODE_ID 1
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
    
    #define RELAY_PIN1  3  // Arduino Digital I/O pin number for relay
    #define BUTTON_PIN  7  // dont need this one remove
    #define CHILD_ID 1
    #define RELAY_ON 1
    #define RELAY_OFF 0
    
    Bounce debouncer = Bounce();
    bool state = false;
    bool initialValueSent = false;
    
    MyMessage msg(CHILD_ID, V_STATUS);
    
    void setup()
    {
      // Setup the button
      //pinMode(BUTTON_PIN, INPUT_PULLUP);
    
      // After setting up the button, setup debouncer
      //debouncer.attach(BUTTON_PIN);
      //debouncer.interval(10);
    
      // Make sure relays are off when starting up
      digitalWrite(RELAY_PIN1, RELAY_OFF);
      // Then set relay pins in output mode
      pinMode(RELAY_PIN1, OUTPUT);
    
      // Set relay to last known state (using eeprom storage)
      state = loadState(CHILD_ID);
      digitalWrite(RELAY_PIN1, state?RELAY_ON:RELAY_OFF);
    }
    
    void presentation()  {
      // Startup initialize MySensors library. Set callback for incoming messages. 
       
      
      sendSketchInfo("Lamp", "1.0");
      present(CHILD_ID, S_BINARY);
      
    }
    
    void loop()
    {
      if (!initialValueSent) {
        Serial.println("Sending initial value");
        send(msg.set(state?RELAY_ON:RELAY_OFF));
        Serial.println("Requesting initial value from controller");
        request(CHILD_ID, V_STATUS);
        wait(2000, C_SET, V_STATUS);
      }
      if (debouncer.update()) {
        if (debouncer.read()==LOW) {
          state = !state;
          send(msg.set(state?RELAY_ON:RELAY_OFF), true); // Send new state and request ack back
        }
      }
     }
    
    void receive(const MyMessage &message) {
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_STATUS) {
        if (!initialValueSent) {
          Serial.println("Receiving initial value from controller");
          initialValueSent = true;
        }
        // Change relay state
    
        state = (bool)message.getInt();
        digitalWrite(RELAY_PIN1, state?RELAY_ON:RELAY_OFF);
        send(msg.set(state?RELAY_ON:RELAY_OFF));
        // Store state in eeprom
        saveState(CHILD_ID, state);
    
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.print(message.sensor);
        Serial.print(", New status: ");
        Serial.println(message.getInt());
      }
    }```


  • So far 1 relay works perfect adding a second one will be a bid harder because the sketch samples i found use more than 2 i would like to know how to add just a second one.
    also in this sketch in need to find out hoe to remove the button function.
    Adding the temperature sensor seems for me very hard, because i would like to call it every 5 minutes without interrupting the repeater. (No Sleep can be used).
    if i know how to call every 5 minutes the temperature, i think i'll be able to add the also the adc code.

    I someone could point me to some code sample i would be very happy...


  • Mod

    Just use wait() instead of sleep



  • Thanks Gohan,

    Will the repeater function keep working...... ? more like an interrupt when something is seen ?


  • Mod

    The wait is specific for keeping the communications going while pausing the loop


 

498
Online

7.7k
Users

8.6k
Topics

92.3k
Posts