multiple distance sensor ?
-
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
#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 300and 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
-
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.
-
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
-
@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