Announcing the "ST_Anything" Arduino/ThingShield Project

Right. He was hoping not to use a breadboard. I think it would be great to see your circuit.

Thanks.

Luke,

It looks like you have a pretty solid plan. Yes, using ST_Anything_Doors_Windows should provide you with an excellent starting point. Be sure to get everything up and running in your lab before trying to integrate with the existing alarm system.

Some basic ST_Anything guidelines:

  • 99.99% of your Arduino code modifications should be within the ST_Anything_Doors_Windows.ino sketch. You should not need to modify any of the library files (there are many!) One exception to this rule is the “Constants.h” file which has user tweakable settings.

  • Please read the comments at the top of the IS_Contact.h file, found within the ST_Anything library. This will explain what all of the arguments are that you can modify within your Arduino sketch’s setup() routine when the various doors and windows objects are defined. Of particular note are the options to Invert Logic and whether or not to use the Internal Pullup resistor. Here is a sample of the comments:

    // st::IS_Contact() constructor requires the following arguments
    // - String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
    // - byte pin - REQUIRED - the Arduino Pin to be used as a digital input
    // - bool iState - REQUIRED - LOW or HIGH - determines which value indicates the interrupt is true
    // - bool internalPullup - OPTIONAL - true == INTERNAL_PULLUP
    // - long numReqCounts - OPTIONAL - number of counts before changing state of input (prevent false alarms)

  • Do NOT use the internal pullup resistor feature if you want to run both the old alarm system and the new one in parallel. The internal pullup resistor feature is designed to supply +5 volts on the digital input pin, thus allow a very simple wiring circuit (i.e. Arduino pin --> Reed Switch --> Arduino Gnd.) When running two systems in parallel, the Arduino will be trying to force its +5V on the old alarm system’s inputs. This is a bad idea.

Hopefully Ken Washington’s (@kewashi) wiring diagram will help to explain some of the wiring circuitry. If you’re not familiar with the wiring, it may be best to try to find a buddy who is good with TTL level circuits to help out. You’re going to need to figure out what voltage the old alarm system is using. If it happens to be 5 volts DC (TTL) then you’re in luck! If not, you’ve going to have to build voltage level shifting circuitry, which is what Ken has done.

If the old alarm does use 5vdc wiring, you then need to figure out which side of the existing reed switch wiring you need to tap into before connecting it to the Arduino Digital Input pin. You’re also going to have to figure out how to get both the old alarm system and the new Arduino to have the same reference voltage. Usually, this is done by tying the Arduino ground to the old alarm system’s ground. Do NOT also tie the Arduino +5 to the old Alarm panel’s +5. That would be a very bad idea!

This can be tricky, which is why having someone around which circuits experience in your house to help figure this out, is really the best way to determine your wiring strategy.

Dan

Got a quick look at the security board tonight. It looks like its 12v throughout so me and ken are going to be good buddies.

The Atmel Mega2560 data sheet shows the I/O pin current limit is 40mA. I believe this is true for all the Atmel microcontrollers. The I/O pins have internal protection diodes rated for 40mA. It only takes .6 x Vcc (5v) = 3v @ 10uA to see a logic HIGH.

I have used 10K resistors with 12V systems for years without any issues. 12v/10K= 1.2mA. It will actually be less, more like (12v-5.5)/10K=.65mA or 650uA.

Just one resistor in series to limit the current is needed. No voltage divider or transistor needed.

Here is the link to the Atmel app note…

http://www.atmel.com/dyn/resources/prod_documents/doc2508.pdf

Dan,

I’ve had great fun as a newbie experimenting with your work, and I have some questions about ‘RCSwitch’. Is this sketch/smartapp/device type for the purpose of controlling multiple outputs, such as relays, with an Arduino SmartThings Shield? The .ino file wouldn’t compile for me until I inserted a value in the constructor for ‘unsigned int pulseLength’. Not knowing what that represents I arbitrarily put a value of 25. So should I define outputs for my relay pins, or am I off-base in my understanding of what this code is for?

Thanks

Hate to answer myself but in reading more I think I have got the picture now…

Betty,

Glad you’re having fun. The RCSwitch example is to be used specifically with a 433MHz transmitter to control Radio Control (RC) devices. If you are just trying to control relays from the Arduino, via SmartThings, please refer to my ST_Anything_Relays example code. Please read the ReadMe on the GitHub repository for basic setup instructions. You’ll also need to use the corresponding Groovy code for the Arduino “Device Handler”, the Multiplexer “Smart App”, and my virtual switch “Device Handler”. Together, they make a matched set of code.

Please read through this discussion where I helped a user by creating the ST_Anything_Relays example:

Also. here is the discussion I posted about the ST_Anything_RCSwitch project you mentioned, in case you’re curious.

Dan

@ogiewon Are you aware of any character limits on messages sent to SmartThings via the smartthing.send() method? I ask because I noticed that messages of length 55 characters are received OK, but I had one sent that was 59 characters and it was never received by SmartThings.

Long story short, I am passing along a JSON string (via ArduinoJSON) from my Arduino to SmartThings and sometimes the string is longer than other times.

I am just trying to figure out if I am missing something or if others have experienced this as well.

Thanks!

@ritchierich

Yes, there is a limited string length by design in the ST_Anything library. If using a MEGA, it defaults to 200 bytes. This can be adjusted very easily by modifying Constants.h. Simply increase the MAX_SENSOR_COUNT and/or MAX_EXECUTOR_COUNT in the following section. You’ll see, in the last line below, how these constants adjust the size of the RETURN_STRING_RESERVE. The ST_Anything library has been optimized to minimize dynamic string allocations to prevent heap memory fragmentation. This was done due to numerous memory management issues we encountered during initial development on the Arduino UNO R3 due to its 2K SRAM limitation. The MEGA 2560 has 8K SRAM so you can make it larger.

Curious, what is the project you’re working on?

		#if defined(BOARD_MEGA)
			//Maximum number of SENSOR objects
			static const byte MAX_SENSOR_COUNT=20;					//Used to limit the number of sensor devices allowed.  Be careful on Arduino UNO due to 2K SRAM limitation 
			//Maximum number of EXECUTOR objects
			static const byte MAX_EXECUTOR_COUNT=20;				//Used to limit the number of executor devices allowed.  Be careful on Arduino UNO due to 2K SRAM limitation 
		#else
			//Maximum number of SENSOR objects
			static const byte MAX_SENSOR_COUNT = 10;				//Used to limit the number of sensor devices allowed.  Be careful on Arduino UNO due to 2K SRAM limitation 
			//Maximum number of EXECUTOR objects
			static const byte MAX_EXECUTOR_COUNT = 10;				//Used to limit the number of executor devices allowed.  Be careful on Arduino UNO due to 2K SRAM limitation 
		#endif
		//Size of reserved return string
		static const byte RETURN_STRING_RESERVE = (MAX_SENSOR_COUNT + MAX_EXECUTOR_COUNT) * 5;	//Do not make too large due to UNO's 2K SRAM limitation

This project is awesome! Thanks for sharing it.

I was able to get 3 contact sensors and 2 motion sensors that were hardwired into my house as part of an old alarm system to work with smart things.

I didn’t see any code for a virtual motion sensor, but I attempted to modify the virtual contact sensor included in the ST_Anything files. It seems to work, so I figured I would share it in case anyone else wanted multiple motion sensors. This is my first time working with groovy, so I tried to change as little as possible so as not to screw it up.

Thanks again!

@nerfnerfnerf

Thanks for the kind words and for writing the Virtual Motion Sensor. I have added a slightly modified version of your groovy code to my GitHub Repository. The only real change I made was to rename the two “commands” to match what I found in the SmartThing Public repository for their “Simulated Motion Sensor” device handler. This will help others regardless of which version they choose to use. So, “motion_active” became “active” and “motion_inactive” became “inactive”.

No need to change what you have as it is already working for you.

Again, thank you for your contribution back to the community!

Dan

Hey Dan @ogiewon and Luke @SkyJedi - Thought I would update you and your followers on my project. I couldn’t find an easy way to draw up the circuit nicely so I just took a picture. One day I will have to learn how to use Eagle I suppose or find some nice circuit brushes for Photoshop. Anyway, here it is. This is a typical voltage splitter that cuts the input by 10 thus reducing my closed voltage to under the transistor 0.7 threshold. The simple equations are shown in the image.


The 6V and 12V shown just depict the two possible states for the tap into each alarm zone. The 5V is where you plug in the leads to the Arduino that are pulled high.Just about any NPN transistor will work. I built 5 of these circuits in parallel. The only questionable part was sharing a ground among all the zones since my alarm treats them all separate for some reason. This seemed to work. Here is the prototype all wired up.

After installing the virtual drivers and virtual devices and the multiplexer I have five door sensors working like a charm with my alarm system still fully operational. The transistors are needed to avoid mucking up the operational alarm voltages. The only goofy part is it turned out that the low voltage condition for NPN off is for closed doors and the logic of your anything code is the opposite. I just hacked the device driver groovy code to swap open/close in the parse routine, and it worked fine. This was easier than reversing the voltage logic or diving into your core code.

Here’s the code snippet to stick in the parse routine of the device driver to swap open and close. I know it isn’t groovy compliant but hey it works.Would love to see how a groovy code slinger would do this more efficiently.

if ( name in ["frontDoor","kitchenDoor","garageDoor","bedroomDoor","froomDoor"] ) {
    if (value=="closed") {
        value = "open"
    } else if (value== "open") {
        value = "closed"
    }
}

Thanks a billion Dan. I could never have done this without your excellent library and sample code.

Ken,

Thanks for sharing the circuit. The quick and easy way to reverse your contact sensor logic is done in the Arduino sketch. We have an optional field in the contact sensor constructor to allow you to select either High or Low logic.

Check out th comments at the top of the IS_Contact.h or .cpp file. It describes all of the parameters you can specify to make the code work properly for your specific circuitry.

Dan

Okay cool… I rely on the pin being high so when the transistor switches it gets pulled low. Will that change? I’m assuming no- that the code just swaps the logic around.

@kewashi

Ken,

Correct, just the logic in the Arduino changes. Here is the comment section that describes the arguments that are used within the sketch’s setup() routine to create each of the constact sensors.

//			  st::IS_Contact() constructor requires the following arguments
//				- String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
//				- byte pin - REQUIRED - the Arduino Pin to be used as a digital input
//				- bool iState - REQUIRED - LOW or HIGH - determines which value indicates the interrupt is true
//				- bool internalPullup - OPTIONAL - true == INTERNAL_PULLUP (defaults to FALSE if not specified)
//				- long numReqCounts - OPTIONAL - number of counts before changing state of input (prevent false alarms)  (defaults to 0 if not specified)

Been doing a lot of reading tonight and this has me intrigued, i’m getting ready to pull the trigger on buying an arduino and shield but I have 2 questions:

  1. Is the consensus to just splurge for the Mega? I have 6 doors and 4 windows that I plan on using from an old alarm system. Also thinking about adding in a siren later on if this all works. Will that work on the Uno or do I just go big?
  2. I’ve noticed that everything connected to the Arduino is seen as a single object to SmartThings with multiple personalities. So two parts. A) will any door sensor trigger an alert to Smart Home Monitor? B) is there a way to see in the app which exact location was the culprit? Like see a push notification that says “front door has been opened”. Thanks!

@kacole2

Kendrick,

  1. Yes, just go for a MEGA 2560. Having the extra RAM is really nice and gives you lots of flexibility. You can get a clone via eBay (shipped from the USA) for <$15.

  2. Yes, you can use one of my MULTIPLEXER SmartApps, along with virtual devices, to be able to expose each and every sensor independently to the rest of SmartThings. Read through some of the earlier posts for directions.

Based on your usage scenario, you should start with my ST_Anything_Doors_Windows example sketch (.ino) and Multiplexer SmartApp, along with my Virtual Contact Sensor Device Handler.

Dan

Ken, did you read the app note from Atmel? Maybe the Atmel Arduino connection wasn’t made. The Arduino Mega 2560 uses the Atmel Mega 2560 microcontroller. Like the app note states, all you need is a series resistor to limit current. One resistor to handle 5v to 240v.