Arduino sketch sharing, discussion and support

I thought maybe this topic could be used for people to share sketch files or generally discuss sketch files or seek support in creating your own sketch files.

I would like to share one sketch that I have managed to put together with some help from hek and twistedsanity.

I would be happy if people would like to give me feedback on the sketch and give me pointers about things that could be handled better (I don?t have that much coding experience so be patient).

The sketch basically contains 2 garage door controllers.

The hardware needed is one relay per garage door and one reed switch + pull-down resistor per garage door (see picture how to connect the reed switch).
TOTAL DEVICE PRICE (for me): $1,6 + $0,92 (arduino + radio) + $1,75 (relay module) + $0,30 (pulldown resistors) + $1,2 (socket adapter for radio) + $10 (reed switches) = $15.77

That would make a GREAT commercial product.
I would imagine that 1 and 2 door garages would cover the majority of garages.

Thanks RTS it also seems to work great with your garage door plugin! (at least on the table, have not yet set it up in the garage.)

Nice korttoma, I can add new example sketches to the git-repo as well when you have had time to test it “in production”.

Getting ready to order some Arduino parts and ran across this post. I take it the relays are for opening and closing the garage door correct?

Yes the relays are for giving an open or close command to the garage door motors. They will show as light switches in vera and when you turn them on they will be on for 300ms and then turn back off. Feel free to change it according to your needs.

Note: I have not yet tested it on my garage door but I don’t see why it should not work. I have Liftmaster garagedoor motors.

Ok Thanks, just getting the build list for detecting my doorbell then I will be ordering everything. I think my garage doors is also a liftmaster belt drive.

The relay should be wired in parallel to the push button if you have one.
If you do not have this option it is also possible to “hack” in to a remote and “make the relay push the button of the remote”.

Thanks for the diagram, it confirms what I was thinking. I am going to put the device I think up by the motor and for ease of wiring into the wall mounted switch and positioning the open/close sensor. Just need to figure out a place to grab power from since I don’t want to use battery.

Should we use this post to discuss support for building a different sensors and asking for help? Or create a new one for each “type” of sensor?

It is fine To diskuss any sensor or any sketch in this thread.

Ok :slight_smile:

So I am working on a sensor that will have this for temp and humidity: http://www.ebay.com/itm/261070585099

I also need to be able to provide 1.5V out for X seconds but also reverse the polarity. It will be operating a DC motor and I just need to be able to change directions.

I am thinking about using 5V Two 2 Channel Relay Module With optocoupler For PIC AVR DSP ARM Arduino | eBay

Errrr and now I just thought I might need a reed sensor too, to sensor if open or closed… but it will probably never be operated manually so I might skip that part for now.

Any other suggestions?

Just for general 120/240V switching and for those who aren’t confident with their electronic skills. You may want to check out this device:

http://www.powerswitchtail.com/Pages/PSTKKit.aspx

https://www.sparkfun.com/products/10747

Certainly more expensive than the eBay switches but may suit some users. My only criticism is that there appears to be no strain relief on the mains cables. However plain grommets are shown in the kit photo but the built units are using a different arrangement.

Relays need to be derated when using inductive loads such as motors:
http://cp.literature.agilent.com/litweb/pdf/5988-6917EN.pdf

Has anyone tried a solid state relay like this?
http://www.ebay.com/itm/NEW-Solid-State-Relay-SSR-40DA-40A-250V-3-32VDC-/110954690054?pt=LH_DefaultDomain_0&hash=item19d56a3606

I suspect one of my fibaro relays soon will give up due to welding (it has stuck two times). It turns on/off two 500W transformers for my RGBW controlled led list around the house.

My idea is to use a SS-relay controlled by Arduino instead.

[quote=“hek, post:14, topic:178741”]Has anyone tried a solid state relay like this?
http://www.ebay.com/itm/NEW-Solid-State-Relay-SSR-40DA-40A-250V-3-32VDC-/110954690054?pt=LH_DefaultDomain_0&hash=item19d56a3606[/quote]

Should work fine. Well not from an Arduino…I’ve used them before driving them directly from digital logic. The input uses an opto-coupler.

Here’s a link that refers to the Arduino.

[url=http://imall.iteadstudio.com/im121228003.html]http://imall.iteadstudio.com/im121228003.html[/url]

I can confirm that. I?ve got 3 of these. Works fine connected directly to a ProMini.
I have them just on my test board so far. Don?t know how reliable they are.

@gibby
To change directions of a DC motor you will probably need more than one relay.

I found some good examples here → http://www.robmeyerproductions.com/bows.html

Then for the actual sketch I would suggest you start from the DHT22 sketch from here → HumiditySensor – Arduino Sensor Plugin
Then just add the relay and reed sensor related code.

Hi there,

I’ve successfully implemented my ducted air conditioning dry contact control with the Vera using Henk’s relay actuator sketch and opto-couplers to handle the switching.

Thanks again Henk for creating such an interesting project.

I’ve been testing the “Relay Actuator with a button” and from my testing the local push button updates the state of the switch in Vera but does not toggle the local relay output? I’ve successfully modified the code to toggle the local relay (I’m new to coding) and it’s working as per my requirement. I’m looking at a cheap alternative to a commercial ZWave relay module.

The only issue I can find with this modification is that there is no verification with Vera to ensure the gw.sendVariable was successfully received. If I unplug power to the RF24 radio module on the local sensor the relay toggles but the Vera does not receive the update and we have a sync issue between the Vera device state and the local relay.

I’ve read through the sensors.h and tried to use “message_s getMessage” to check for a response from the Vera but I just don’t understand the code to make it work.

Here is the loop section from the sketch which includes an extra digitalWrite(RELAY_PIN, state==1?0:1);

I’ve added a comment at the point where the verification step is needed.

I’d appreciate any help at all. I’ll upload this sketch once complete.

void loop()
{
if (gw.messageAvailable()) {
// got new messsage from gw
message_s message = gw.getMessage();
setRelayStatus(message);
}

buttVal = digitalRead(BUTTON_PIN); // read input value and store it in val

if (buttVal == HIGH && previousVal == LOW) {
// Start counter from when button was pressed
pressTime = millis();
switched = 0;
}

if (buttVal == HIGH && switched == 0 && millis() - pressTime > debounce) {
// Switch state if button pressed more than debounce msec
state = state==1?0:1;

 // Debug the action of the switch
 Serial.println("Button pressed");
 
 gw.sendVariable(CHILD_ID, V_LIGHT, state); // We will receive an ack message
 switched = 1; // No more switches until button is released

/* ##############################################################################
Insert a verification check with the Vera to ensure the message was received and the sensor state updated
so we can then change the state of the local relay.
##############################################################################
*/
}
// Added this line to change the state of the local relay
digitalWrite(RELAY_PIN, state==1?0:1);
}
previousVal = buttVal;

}

@bluman
Hi,
I think what you need to achieve this is in the road map for the 1.4 version

Quote from readmap:
Planned features 1.4

New option to enable “ack” when sending message between and from sensor to gateway. Actuators need this to confirm that messages has been delivered.
end quote

I think this is planed to be released in the next 2 months (please hek correct me if I’m wrong)

@ bluman thanks, that was the same problem I had with the relay with button sketch and now the button triggers the relay and Vera.