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
Suggested Topics
-
Over the air updates
General Discussion • 23 Mar 2014, 21:38 • ToSa 1 Mar 2015, 11:21 -
"Remote Irrigation with LoRaWAN: LM27313 Challenges and PCB Design"
Hardware • 24 Jan 2024, 23:06 • wrendral 3 Feb 2024, 07:13 -
Best time of year to buy higher quality small project solar panels?
Hardware • 10 Jun 2021, 19:19 • NeverDie 30 Aug 2024, 14:01 -
Sensor to detect marijuana vape/smoke
Hardware • 21 Jan 2025, 06:36 • Hellmark 25 Feb 2025, 20:56 -
Does MySensors require Arduino Timer 2?
Hardware • 6 Jan 2024, 19:39 • OldSurferDude 11 Jan 2024, 04:39 -
Newbie questions
Hardware • 14 Feb 2025, 20:03 • magwas 14 Feb 2025, 20:03