Unfortunatly the sensor stopped working last night. I have ordered a relais board with opto coupler....
I will keep in touch
Posts made by Naitsirhc
-
RE: Pump + Relais + Decoupling
-
RE: Pump + Relais + Decoupling
Again, thanks all for answering
Until now its working 2 days flawlessly.
-
RE: Pump + Relais + Decoupling
Going bonkers is probably not the right word. I actually meant that the owner, and especialy his wife, are going bonkers
What I meant is:
When I connect the led: (red = D5, Green = D6 and the ground is connected through a resistor of 1K.) When I turn on the relay it's answering for aprox. 5 minutes and than it crashes.
I can only reanimate it by turning off the power -
RE: Pump + Relais + Decoupling
Thanks for your quick reply.
The led is indicating one colour at the same time. Green for open and red for close.
I can give it a try to have more resistors connected... -
RE: Pump + Relais + Decoupling
Hi,
I promised to keep in touch....
I have disconnected the radio from the Arduino, so the radio is fed through a seperate stable 5V.
And also the relais board is fed seperately.
It runs for a cuple of days and it seems to work well. Time to move on.
To see if the magnet is working or not, I decided to connect a RGB led. When I connect the led, the board is going bonkers. The led is connected on D5 and D6 and the other side to ground (via a resistor)Anybody a clue?
-
RE: Pump + Relais + Decoupling
To all,
Thanks for your answers. Unfortunatly I didn't have time to check your answers. I will keep in touch
-
Pump + Relais + Decoupling
Hi,
Picked up the hobby again
I would like to build an irregation system with a pump, 4 valves and a sensor to easure the total amount of water in a tank.
I have found some sketches to help me with the problem. So I hope this would not be the problem.
I now have tried the relais sketch on my doormagnet (other project), and after a while it will fail (probably noise causes the problem)
My system is:
Arduino nano
radio NRF2401 PA/LNA
NRF24L01+ Socket Adapter Board
relais board
All of this are connected with jumper wires and the arduino + radio are fed seperatly with a charger.Before I try to build the irregation system I would like to know if there is a good method to calcuate the size of the decoupling capacitor. And where do I have to put it. Do I have to put it on the 230V side, or also on the 5V (on the relais board)
Hope too get some aswers here, thanks in advance
-
RE: New scketch for water level + control valves
update:
Adapted the old distance sensor sketch to the 2.0 library and upladed it and connected to my PC. Also connected the gateway 2.0 to raspberry (Domoticz).....
Allright it works....I do get distance in my serial monitor and in domoticz.Now try to upload the basement alarm sketch...See what happens...
-
RE: New scketch for water level + control valves
Hi
First of all, thanks for all the answers.
Started from skratch again. Downloaded the new arduino IDE.Some Libraries (NewPing and Mysensors) and finaly the sketch compiled
I uploaded it to the Nano and then expected to see something on the serial monitor....Too bad...Oh right. removed slashes for MyDebug and MyDebug_Verbose...
Presto.
Unfortunatly I see in serial monitor:
Starting sensor (RNNNA-, 2.0.0) TSM:INIT TSM:RADIO:OK TSP:ASSIGNID:OK (ID=32) TSM:FPAR TSP:MSG:SEND 32-32-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: TSM:FPAR TSP:MSG:SEND 32-32-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: TSM:FPAR TSP:MSG:SEND 32-32-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: TSM:FPAR TSP:MSG:SEND 32-32-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: !TSM:FPAR:FAIL !TSM:FAILURE TSM:PDT TSM:INIT
Too bad. What have I done wrong? Is it possible to see the distance in serial monitor and to see if a relay turned on or off?
EDIT:
Upgraded my Gateway also to 2.0Stil no succes
Output from Gateway:
0;255;3;0;9;Starting gateway (RNNGA-, 2.0.0) 0;255;3;0;9;TSM:INIT 0;255;3;0;9;TSM:RADIO:OK 0;255;3;0;9;TSM:GW MODE 0;255;3;0;9;TSM:READY 0;255;3;0;14;Gateway startup complete. 0;255;0;0;18;2.0.0 0;255;3;0;11;GateWay 0;255;3;0;12;1.0 0;255;3;0;9;No registration required 0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1 0;255;3;0;9;TSP:SANCHK:OK 0;255;3;0;9;TSP:SANCHK:OK 0;255;3;0;9;TSP:SANCHK:OK 0;255;3;0;9;TSP:SANCHK:OK 0;255;3;0;9;TSP:SANCHK:OK
-
RE: New scketch for water level + control valves
Did a check with my other sketches a adapted the basement fooding alarm sketch:
/* Ultrasonic Sensor - based on a MySensors example (actuator) modified 30 august 2016 version 1.2 by Gert Sanders Uses 2.0.0-dev version of the library */ // Enable debug prints to serial monitor //#define MY_DEBUG //#define MY_DEBUG_VERBOSE //#define MY_NODE_ID 123 #define MY_NODE_ID 32 // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // possible values: RF24_PA_LOW (is default on gateway), RF24_PA_MED, RF24_PA_HIGH, RF24_PA_MAX (is default on nodes) #define MY_RF24_PA_LEVEL RF24_PA_MAX // RF channel for the sensor net, 0-127 #define MY_RF24_CHANNEL 80 // just my choice //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps #define MY_RF24_DATARATE RF24_250KBPS // defines for sensors #define PUMP 1 #define WATERLEVEL 2 // Enable repeater functionality for this node //#define MY_REPEATER_FEATURE // All includes #include <MySensor.h> #include <NewPing.h> #include <SPI.h> // Pin definitions and other defines #define TRIGGER_PIN 5 // Arduino pin tied to trigger pin on the ultrasonic sensor. #define ECHO_PIN 6 // Arduino pin tied to echo pin on the ultrasonic sensor. #define RELAYPIN 7 //#define LEDPIN 8 #define PumpOFFLimit 2 #define PumpONLimit 12 #define MAX_DISTANCE 255 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm. #define NUMBEROFSAMPLES 100 // constants // variables boolean PumpStatus = false; boolean oldPumpStatus = false; unsigned int uS = 0; byte Distance = 0; byte LastMeasuredDistance = 0; byte MaxMeasuredDistance = 0; // Instantiate objects MySensor gw; NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance. MyMessage PumpMsg(PUMP, V_LIGHT); MyMessage DistanceMsg(WATERLEVEL, V_DISTANCE); void presentation() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("BasementAlarmUltrasonic", "1.1"); gw.wait(500); // delay needed by Raspi/domotics gw.present(PUMP, S_LIGHT); gw.wait(500); // delay needed by Raspi/domotics gw.present(WATERLEVEL, S_DISTANCE); gw.wait(500); // delay needed by Raspi/domotics } // supporting functions. //void blipled() //{ // digitalWrite(LEDPIN, !PumpStatus); // turn the LED on (HIGH is the voltage level) // wait(50); // wait for a bit // digitalWrite(LEDPIN, PumpStatus); // turn the LED off by making the voltage HIGH // wait(150); // wait for a bit // digitalWrite(LEDPIN, !PumpStatus); // turn the LED on (HIGH is the voltage level) // wait(50); // wait for a bit // digitalWrite(LEDPIN, PumpStatus); // turn the LED off by making the voltage HIGH //} void receive(const MyMessage & message) { #ifdef MY_DEBUG // Write some debug info Serial.print(F("Incoming change for sensor:")); Serial.print(message.sensor); #endif if (message.type == V_LIGHT) { // Change relay state oldPumpStatus = PumpStatus; PumpStatus = message.getBool(); digitalWrite(RELAYPIN, PumpStatus ? HIGH : LOW); // Store state in eeprom saveState(PUMP, PumpStatus); #ifdef MY_DEBUG Serial.print(F("Changing PUMP status to : ")); Serial.println(PumpStatus); #endif } } ///////////////////////////////////////////////////////////////////////// // the setup function runs once when you press reset or power the board ///////////////////////////////////////////////////////////////////////// void setup() { PumpStatus = false; oldPumpStatus = false; // initialize digital LEDpin as an output. // pinMode(LEDPIN, OUTPUT); //digitalWrite(LEDPIN, HIGH); // turn the LED on by making the voltage HIGH // initialize digital Pumppin as an output. pinMode(RELAYPIN, OUTPUT); digitalWrite(RELAYPIN, LOW); // turn the LED off by making the voltage LOW PumpStatus = loadState(PUMP); digitalWrite(RELAYPIN, PumpStatus); send(PumpMsg.set(PumpStatus == true ? 1 : 0)); wait(500); MaxMeasuredDistance = loadState(WATERLEVEL); // digitalWrite(LEDPIN, LOW); // turn the LED off by making the voltage LOW } /////////////////////////////////////////////////////// // the loop function runs over and over again forever /////////////////////////////////////////////////////// void loop() { blipled(); uS = sonar.ping_median(NUMBEROFSAMPLES); // Send ping, get ping time in microseconds (uS). Distance = uS / US_ROUNDTRIP_CM; if (Distance >= MaxMeasuredDistance) { MaxMeasuredDistance = Distance; if (Distance >= loadState(WATERLEVEL)) { saveState(WATERLEVEL, Distance); } } if (Distance != LastMeasuredDistance) { if (send(DistanceMsg.set((MaxMeasuredDistance - Distance), 0))) { LastMeasuredDistance = Distance; wait(500); } } #ifdef MY_DEBUG Serial.print("Ping: "); Serial.print(Distance); // Convert ping time to distance in cm and print result (0 = outside set distance range) Serial.print("cm"); Serial.print(" Max: "); Serial.print(MaxMeasuredDistance); // Convert ping time to distance in cm and print result (0 = outside set distance range) Serial.println("cm"); #endif if ((MaxMeasuredDistance - Distance) >= PumpONLimit) { SetPumpOn(); } if ((MaxMeasuredDistance - Distance) <= PumpOFFLimit) { SetPumpOff(); } if (oldPumpStatus != PumpStatus) { if (send(PumpMsg.set(PumpStatus == true ? 1 : 0))) { oldPumpStatus = PumpStatus; wait(500); // delay needed by Raspi/domotics } } } void SetPumpOn() { digitalWrite(RELAYPIN, HIGH); oldPumpStatus = PumpStatus; PumpStatus = true; saveState(PUMP, PumpStatus); } void SetPumpOff() { digitalWrite(RELAYPIN, LOW); oldPumpStatus = PumpStatus; PumpStatus = false; saveState(PUMP, PumpStatus); }
I turned of the LED pin (I don't need it)
The compiler does his job till the last line:
saveState(PUMP, PumpStatus);which returns:
exit status 1
'saveState' was not declared in this scopeWhat can I do to make this error disappear
Thanks in advance
-
RE: New scketch for water level + control valves
Hi back again,
Tried to upload the sketch. unfortunatly the copiler returns an error:
'sendSketchInfo' was not declared in this scope
Googled for an answer. And found an solution, for installing a new library.
I installed:
MySensors 2.0.0
Mysensors_development
But it doesn't work.Can you help me please
-
RE: New scketch for water level + control valves
Thank You all,
I will try the sketch (and try to understand it....LOL)
I need only need to measure the water level once or twice a day. So I will figure it out how it has to be done.Thanks again
-
New scketch for water level + control valves
Hi,
As the title already mentioned, I would like to build a sensor which will measure the waterlevel and send it to my gateway. If the waterlevel is sufficient, my gateway has to send the signal to open the valve and start the pump.
I would like to use a combination of 2 scripts (Relay and distance sensor)I have tested the sketch, but it only returns a distance when I press a button in Domoticz.
The sketch I've used:
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Example sketch showing how to control physical relays. * This example will remember relay state after power failure. * http://www.mysensors.org/build/relay */ #include <MySigningNone.h> #include <MyTransportNRF24.h> #include <MyTransportRFM69.h> #include <MyHwATMega328.h> #include <MySensor.h> #include <SPI.h> #include <NewPing.h> #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 4 // Total number of attached relays #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 #define CHILD_ID 1 #define TRIGGER_PIN 8 // Arduino pin tied to trigger pin on the ultrasonic sensor. #define ECHO_PIN 7 // Arduino pin tied to echo pin on the ultrasonic sensor. #define MAX_DISTANCE 300 // Maximum distance we want to ping unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds) // NRFRF24L01 radio driver (set low transmit power by default) MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW); //MyTransportRFM69 radio; // Message signing driver (none default) //MySigningNone signer; // Select AtMega328 hardware profile MyHwATMega328 hw; // Construct MySensors library MySensor gw(radio, hw); NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); MyMessage msg(CHILD_ID, V_DISTANCE); int lastDist; boolean metric = true; void setup() { // Initialize library and add callback for incoming messages gw.begin(incomingMessage, AUTO, true); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Relay", "1.0"); // Fetch relay status for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) gw.present(sensor, S_LIGHT); gw.present(CHILD_ID, S_DISTANCE); boolean metric = gw.getConfig().isMetric; // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF); } } void loop() { // Alway process incoming messages whenever possible 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 Serial.println(metric?" cm":" in"); if (dist != lastDist) { gw.send(msg.set(dist)); lastDist = dist; } 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(message.sensor-1+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()); } gw.sleep(SLEEP_TIME); }
Please could you help me, to combine the sketches and help me with my learnig curve
-
RE: [SOLVED] Combine sketches for Relay + status (RGB)LED
You're brilliant.
It works like you said.... Red if the door is closed and green when it is opened
therefore I have adapted the code a littlebit:
if (message.getBool()== true)
is now:
if (message.getBool()== false)Thank you very much
-
[SOLVED] Combine sketches for Relay + status (RGB)LED
Hello,
First of all I would like to thank you for the good work you all are doing.
Since I have been attended to this site, I am thinking of making a relay board with a status signal.
What do I mean:
I have a magnet which is working on 12V. I have this magnet installed to my door, so it is possible for me to close the door by magnet.
From the site I have downloaded the sketch for operate a relay board, so it is possible for me to operate the magnet (with a relay) from Domoticz. It is already up and running.
Unfortunately the magnet doesn’t have a status led, so it isn’t possible to see if this magnet is working or not.
When I’m searching on the internet, I see several sketches to operate a led via some pins on the Arduino.
My question is:
Is it possible to integrate some code in the relay sketch to operate the LED.
For your info, I have a RGB LED which only have to work with the colors green and red.I have done some fiddling with the code, but it doesn’t work I think:
- modify it under the terms of the GNU General Public License
- version 2 as published by the Free Software Foundation.
- REVISION HISTORY
- Version 1.0 - Henrik Ekblad
- DESCRIPTION
- Example sketch showing how to control physical relays.
- This example will remember relay state after power failure.
- http://www.mysensors.org/build/relay
*/
#include <MySigningNone.h>
#include <MyTransportNRF24.h>
#include <MyTransportRFM69.h>
#include <MyHwATMega328.h>
#include <MySensor.h>
#include <SPI.h>#define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 1 // Total number of attached relays
#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
#define redPin = 5
#define greenPin = 6// NRFRF24L01 radio driver (set low transmit power by default)
MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
//MyTransportRFM69 radio;
// Message signing driver (none default)
//MySigningNone signer;
// Select AtMega328 hardware profile
MyHwATMega328 hw;
// Construct MySensors library
MySensor gw(radio, hw);void setup()
{
// Initialize library and add callback for incoming messages
gw.begin(incomingMessage, AUTO, true);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("RelayLED", "1.0");// Fetch relay status
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
// Register all sensors to gw (they will be created as child devices)
gw.present(sensor, S_LIGHT);
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);// Set relay to last known state (using eeprom storage) digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
}
}void loop()
{
// Alway process incoming messages whenever possible
gw.process();
setColor(255, 0, 0); // red
setColor(0, 255, 0); // green
}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(message.sensor-1+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());
}void setColor(int red, int green, int blue){
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
}
}I do know I have to combine the analogWrite command with the state of the relay, but I don know if this is possible….
Can you help me please?
Kind regards and thanks in advance….
italicised textitalicised textitalicised text