Ultrasonic Sensor+1 Relay node does not work
-
Hi,
I am trying to build a node with Ultrasonic sensor and 1 relay. I used the sample code and tried to build one. I am facing issues. The Domoticz will detect the ultrasonic sensor using the provided example code but when I merge them it gives error and does not detect. My sketch is as below:
#include <SPI.h> #include <MySensor.h> #include <NewPing.h> #define CHILD_ID_DISTANCE 1 #define CHILD_ID_RELAY 10 #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. #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #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 MySensor gw; NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance. MyMessage msg(CHILD_ID_DISTANCE, V_DISTANCE); int lastDist; boolean metric = true; void setup() { gw.begin(incomingMessage, AUTO,false); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Distance Sensor", "1.0"); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_DISTANCE, S_DISTANCE); boolean metric = gw.getConfig().isMetric; gw.sendSketchInfo("Relay", "1.0"); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_RELAY, S_LIGHT); // Then set relay pins in output mode pinMode(RELAY_1, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(RELAY_1, gw.loadState(CHILD_ID_RELAY)?RELAY_ON:RELAY_OFF); } void loop() { gw.process(); int dist = metric?sonar.ping_cm():sonar.ping_in(); Serial.print("Ping: "); Serial.print(dist); // Convert ping time to distance in cm and print result (0 = outside set distance range) Serial.println(metric?" cm":" in"); if (dist != lastDist) { gw.send(msg.set(dist)); lastDist = dist; } //gw.sleep(SLEEP_TIME); } void incomingMessage(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_LIGHT) { // Change relay state digitalWrite(RELAY_1, 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()); } }
I am unable to figure out why it is not working.
The log file from Domoticz shows the below:
2015-05-26 07:05:52.585 MySensors: Using serial port: /dev/ttyUSB0 2015-05-26 07:05:57.410 Error: MySensors: Unhandled sensor (sub-type=13), please report with log! 2015-05-26 07:05:57.429 Error: MySensors: Unhandled sensor (sub-type=13), please report with log! 2015-05-26 07:05:57.440 Error: MySensors: Unhandled sensor (sub-type=13), please report with log!
and it keeps on going.
Below is the output when Node is connected to serial port.Ping: 11 cm send: 5-5-0-0 s=1,c=1,t=13,pt=2,l=2,st=ok:11 read: 5-1-0 s=10,c=0,t=3,pt=0,l=5:1.4.1 Ping: 9 cm send: 5-5-0-0 s=1,c=1,t=13,pt=2,l=2,st=ok:9 read: 5-1-0 s=10,c=0,t=3,pt=0,l=5:1.4.1 Ping: 9 cm Ping: 11 cm send: 5-5-0-0 s=1,c=1,t=13,pt=2,l=2,st=ok:11 read: 5-1-0 s=10,c=0,t=3,pt=0,l=5:1.4.1
I am using Raspberry pi as gateway with Arduino Uno. Arduino Mini Pro as node.
Please help me figure out what could be the issue. Any help is really appreciated. Thanks.!
-
The distance sensor is supported in the beta version of Domoticz
2 out of 2
Suggested Topics
-
Domoticz Temperature display on sensor node
Development • 27 Sept 2015, 20:20 • coppo23 16 Oct 2015, 18:39 -
No ID assigned by gateway.
My Project • 15 Nov 2016, 11:02 • Suresh Mali 21 Nov 2016, 04:25 -
💬 Universal Inputs Modbus Module
OpenHardware.io • 23 Feb 2021, 00:30 • openhardware.io 23 Feb 2021, 13:51 -
Sensor for pellet burner
General Discussion • 9 Mar 2017, 22:47 • pugho 10 Mar 2017, 10:55 -
RelayWithButtonActuator Example with touch sensor
Troubleshooting • 19 Dec 2014, 18:54 • C.r.a.z.y. 20 Dec 2014, 22:09 -
Sensor reading incorrect data from the controller
Bug Reports • 27 Feb 2016, 10:07 • Brian Fernando 27 Feb 2016, 10:07 -
💬 NModule
OpenHardware.io • 23 May 2017, 14:38 • openhardware.io 10 May 2020, 05:43 -
Itead RBoard and RMini Example Sketch
Development • 21 Nov 2015, 13:08 • Alphalove 21 Nov 2015, 15:03