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
  1. Home
  2. Hardware
  3. multiple distance sensor ?

multiple distance sensor ?

Scheduled Pinned Locked Moved Hardware
4 Posts 3 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fred97
    wrote on last edited by
    #1

    hello everybody ,

    i wan to plug 4 sensor level , is for water level of rain water tank .

    i have found this code for distance sensor :+1:

    
    #include <SPI.h>
    #include <MySensor.h>
    #include <NewPing.h>
     
    #define CHILD_ID 1
    #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
    #define ECHO_PIN     5  // Arduino pin tied to echo pin on the ultrasonic sensor.
    #define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
    unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds)
     
    MySensor gw;
    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
    MyMessage msg(CHILD_ID, V_DISTANCE);
    int lastDist;
    boolean metric = true; 
     
    void setup()
    {
      gw.begin();
     
      gw.sendSketchInfo("Distance Sensor", "1.0");
     
      gw.present(CHILD_ID, S_DISTANCE);
      boolean metric = gw.getConfig().isMetric;
    }
     
    void loop()
    {
      int dist = metric?sonar.ping_cm():sonar.ping_in();
     
      if (dist != lastDist) {
          gw.send(msg.set(dist));
          lastDist = dist;
      }
     
      gw.sleep(SLEEP_TIME);
    
    

    So for 4 sensor i need to definite more like this

    #define CHILD_ID1 1
    #define TRIGGER_PIN1 6
    #define ECHO_PIN1 8
    #define MAX_DISTANCE1 300

    #define CHILD_ID2 2
    #define TRIGGER_PIN2 5
    #define ECHO_PIN2 9
    #define MAX_DISTANCE2 300

    and i need change this gw.present(CHILD_ID, S_DISTANCE); by gw.present(CHILD_ID, S_DISTANCE1, S_DISTANCE2, XXXX);

    so i need change other thing inside ?

    thanks you

    1 Reply Last reply
    0
    • DNKROZD Offline
      DNKROZD Offline
      DNKROZ
      wrote on last edited by
      #2

      Hi.

      I recommend you to check the relay example, the sketch includes support for multiple relays and you'll understand what do do in that scenario, but answering you initial question, no, I'm afraid you can't do gw.present(CHILD_ID, S_DISTANCE1, S_DISTANCE2, XXXX); but you can do gw.present(CHILD_ID1, S_DISTANCE); and gw.present(CHILD_ID2, S_DISTANCE); after that one... and... so on, you'll see better reading the relay sketch.

      Regards.

      M 1 Reply Last reply
      0
      • F Offline
        F Offline
        fred97
        wrote on last edited by
        #3

        thanks you for help , i will try and if is work i will share the code , is not very difficult but for me it is , is use a unix command since 2 week hahahah

        1 Reply Last reply
        0
        • DNKROZD DNKROZ

          Hi.

          I recommend you to check the relay example, the sketch includes support for multiple relays and you'll understand what do do in that scenario, but answering you initial question, no, I'm afraid you can't do gw.present(CHILD_ID, S_DISTANCE1, S_DISTANCE2, XXXX); but you can do gw.present(CHILD_ID1, S_DISTANCE); and gw.present(CHILD_ID2, S_DISTANCE); after that one... and... so on, you'll see better reading the relay sketch.

          Regards.

          M Offline
          M Offline
          moffen666
          wrote on last edited by
          #4

          @DNKROZ said:

          Hi.

          I recommend you to check the relay example, the sketch includes support for multiple relays and you'll understand what do do in that scenario, but answering you initial question, no, I'm afraid you can't do gw.present(CHILD_ID, S_DISTANCE1, S_DISTANCE2, XXXX); but you can do gw.present(CHILD_ID1, S_DISTANCE); and gw.present(CHILD_ID2, S_DISTANCE); after that one... and... so on, you'll see better reading the relay sketch.

          Interesting, where is this Relay sketch?

          Regards

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          20

          Online

          11.7k

          Users

          11.2k

          Topics

          113.1k

          Posts


          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
          • Login

          • Don't have an account? Register

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