SmartThings Community

CreeRelays Project (part Cree bulb, part Arduino)

project_misc

(Dan) #1

All,

I was inspired by the work of @drbudro which can be found here…

I decided to see if I could possibly build a generic DeviceType and Arduino Sketch that could make use of the Cree Connected Bulb’s easy-to-extract Zigbee module. By reading the dim level values into the Arduino , I was able to accurately obtain 100 discrete dim level values. These can be used by the Arduino to perform any action desired. This example implements an 8 relay controller. The Groovy Device Type code works, but does not expose all 8 relays as separate virtual devices (which is always the 1st question people love to ask! :slight_smile: ). Also, this is essentially a one-way communication device. SmartThings can command any one of the relays to be on at any given time, but the Arduino cannot send any data back to SmartThings. This may limit the value of this design, but it is a very inexpensive solution at about $20 ($15 for the bulb + $5 for the Arduino Nano clone.)

You can download all of the code from my “CreeRelays” GitHub repository at https://github.com/ogiewon/CreeRelays

------ReadMe From GitHub Follows---------

CreeRelays
SmartThings + Cree Connected LED Bulb Zigbee board + Arduino Nano = Cheap Home Automation Potential!

Please note that this project results in a device that is essentially a one way device. SmartThings sends commands to the Arduino via a scavenged Cree Connected LED bulb’s Zigbee board. There is no way for the Zigbee board to send updates to SmartThings, unless a REFRESH command is sent from ST. The Arduino has no way to tell the Zigbee board the status of anything! The Zigbee board is capable of sending two signals to the Arduino:
•An On/Off signal (i.e. bulb on or off)
•A PWM Signal (i.e. bulb dim level)

The Cree bulb can be bought at Home Depot for about $15. The Arduino Nano clone that I used was bought on ebay for less than $5 (and a few weeks shipping time!)

Overview
CreeRelays consists of two parts:
•The CreeRelays.ino Arduino sketch
•The CreeRelays.device.groovy SmarThings Device Type

Hardware Requirements
CreeRelays requires:
•Arduino Nano, UNO, or similar ($5 and up)
•Cree Connected LED Bulb’s Zigbee Communication Board ($15)

Hardware Setup Instructions
•Join your Cree Connected Bulb to your hub using your phone’s SmartThings App BEFORE disassembling the bulb!!!
•After removing the Zigbee board from the Cree Connected bulb, attach it to the Arduino as follows

◦Zigbee Board Pin 1 to Arduino GND
◦Zigbee Board Pin 2 to Arduino 3.3V
◦Zigbee Board Pin 3 to Arduino Pin 11 (PWM)
◦Zigbee Board Pin 3 to Arduino Pin 12 (On/Off)
◦Arduino Pin 2 to Relay #1 (or an LED as I did for testing!)
◦Arduino Pin 3 to Relay #2
◦Arduino Pin 4 to Relay #3
◦Arduino Pin 5 to Relay #4
◦Arduino Pin 6 to Relay #5
◦Arduino Pin 7 to Relay #6
◦Arduino Pin 8 to Relay #7
◦Arduino Pin 9 to Relay #8

CreeRelays Arduino Setup Instructions
•Join your Cree Connected Bulb to your hub using your phone’s SmartThings App BEFORE disassembling the bulb!!!
•Download the CreeRelays repository.
•This folder structure should mirror that of your local Arduino directory.

◦On Mac, it’s located in ~/Documents/Arduino/ .
◦On Windows, it’s located in C:\My Documents\Arduino .

•Look inside the Arduino/Sketches folder of the repo.
•Copy and paste the CreeRelays sketch folder into your local Arduino sketches directory. If you haven’t created any sketches, you may not see the folder. In this case, feel free to create it.

CreeRelays SmartThings Device Type Installation Instructions
•Join your Cree Connected Bulb to your hub using your phone’s SmartThings App BEFORE disassembling the bulb!!!
•Create an account and/or log into the SmartThings Developers Web IDE.
•Click on My Device Types from the navigation menu.
•Click on + New SmartDevice button.
•Fill in the Name field as CreeRelays and click on the Create button. Don’t worry about filling out everything else.
•Paste the code from the CreeRelays.device.groovy file from this repo.
•Click on Save in the IDE.
•Click on Publish -> For Me in the IDE.
•Click on My Devices from navigation menu
•Select your “Arduino ThingShield” device from the list
•Click the Edit button at the bottom of the screen
•Change the Type to “CreeRelays”
•Click the Update button at the bottom of the screen
•On your phone, log out of SmartThings in the app, and then log back into SmartThings to refresh its settings
•Your CreeRelays Device Tile should now look like the image above in this ReadMe

CreeRelays Usage
•This is essentially a proof of concept example. You can control up to 8 relays with this example as-is. My intention was to share this project as an inspiration for others to kick-start any other efforts that desire a very low cost way to control real-world devices from SmartThings.
•Pressing any of the “Relay 1” through “Relay 8” tiles on your phone will "turn on the bulb and set the dim level to 1 through 8 respectively.
•Based on the dim level selected, the arduino sketch will turn on a corresponding digital output (which could be conncted to a relay.)
•Pressing a different “Relay n” tile will turn off the previous output, and turn on the new output
•Pressing the main “Lightbulb” tile will either turn on or turn off the output which corresponds to the current Dim Level
•Only Dim Levels 1 through 8 are currently being handled by the Arduino sketch. Using the slider control to set dim levels above 8 or below 1 will turn off all of the output pins. Note: All 100 dim levels are properly recognized in the Arduino Sketch, but I only have code in place for values 1 though 8 in this example.
•Only one digital output can be on at a time in the current example. For more complicated designs, the exercise is left up to the student!

Enjoy!
Dan


Zigbee/ZWave control for any battery powered device?
Announcing the "ST_Anything" Arduino/ThingShield Project
Neopixel projects
Battery Based Zwave FLiRS Relay/switch
Smartthings Cree PCM integrated Audio Volume Control
Local Control options for particle proton board?
$20 Door Chime
SHM or Home Mode Indicator lights
[RELEASE] ST_Anything v2.9.2 - Arduino/ESP8266/ESP32 to ST via ThingShield, Ethernet, or WiFi
Intergrating A Tv Bed Lift Mechanism
Status Indicator Light
My Home Automation Addiction
Announcing the "ST_Anything" Arduino/ThingShield Project
Thingshield dimmer?
(Scott G) #2

This is pretty cool! I wouldn’t know how to put this together even with your great instructions, but the zigbee module will actually accept “dim” values from 0-255 (00-fe in hex). All the ST device codes for zigbee bulbs do a conversion from 0-100 to the wider range because it’s a better UI. We could easily use a custom slider range to get the full spectrum though, which means even more possibilities.


(Dan) #3

Scott,

That’s an interesting idea, to use the full range of the zigbee module’s dim capability. The only issue I could foresee is that it was already very challenging to properly discern 100 unique PWM values on the Arduino. It required the use of the Arduino’s TIMER2 interrupt in order to have enough resolution and repeatability. It was a very fun way to learn a lot about Arduino Interrupts, as I believe their use is required to accomplish this. I discovered many examples from the Radio Control (RC) community where they face the same issue with trying to measure PWM signals. The one advantage the RC folks have is that they always have a valid PWM value to measure. With the zigbee module, a dim level of 0 results in a flat-lined signal LOW, while a dim level of 99 results in a flat lined signal HIGH. Dealing with a constant on, constant off, and a variable PWM signal was a little challenging.

Hopefully others will find this useful. I am still determining what are the best use cases for this. @drbudro’s door chime is an excellent use scenario. Perhaps others will “chime” in with some ideas? (Sorry for the pun! :slight_smile: )

Dan


(Devesh Batra) #4

could i use the CREE circuit along with an amplifier to drive LED Strips ?


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #5

Use the CREE circuit to drive a low voltage relay and you can control anything on / off. Most low voltage relays are 5vDC … I think Cree is 3.3vDC, right, so you’ll need a power regulator in the circuit. Not too complicated.

As for control – at most, you’re limited to dim level messages, I think … 0 to 100; so not great for color LED.


(Dan) #6

@BatraD

I’ve never used an LED light strip, so no 1st hand experience… However, you should be able to take my example, including the Arduino, and modify the Arduino code to drive the LED strip. You could create ~100 (i.e the number of dim levels) distinct LED lighting “scenes” that the Arduino could interpret into interesting lighting effects.

Here’s one quick example I found to use an Arduino with an LED strip - http://www.instructables.com/id/PWM-an-RGB-LED-Strip-with-Arduino/

SmartThings then becomes a means to remotely initiate the desired LED lighting “scene”. Just an idea.

Dan


(Daniel) #7

Hi dan
As always you come with more projects for this community, Thanks for that! !!.
I have two questions, First why we have to add the bulb before to take the circuit and second that means that you just can select one relay at the time?


(Dan) #8

It’s just easier to make sure your can pair the bulb to the ST hub and verify it works properly while it is still a complete light bulb package. As for the “1 switch on at a time” - that was simply a design decision on my part for the sample sketch. This was done as a proof of concept. Feel free to hack up the Arduino code to suit your needs as you see fit. It is essentially a simple way for ST to send a device up to 100 unique commands. You can do whatever you want with those “commands” in the Arduino sketch.


#9

Thanks for the effort with this project Dan,
I had the same idea a week ago and stumbled on this as I was getting started.
Great job. Works Great. Huge time saver!
Thanks again.
-Bill


(Dan) #10

Bill,

Glad to hear to you have found it useful. I’d love to know what your application is for this? I am sure others would also find it interesting as well.

Dan


#11

Dan, thanks for posting the instructions for this great proof of concept! I’m in the process of researching a way to create an interface to control my home sprinkler system with my Smartthings hub, and your information seems to be a great starting point. I just need a way to turn on several relays one at a time to control my sprinkler valves, and I think I can use your hack to do it.

One question: I understand it’s easier to pair the Zigbee chip with my ST hub while it’s still in the bulb. Do you know if it’s possible to to do the pairing if the Zigbee board is already pulled out of the bulb? I’m trying to think if I needed to do the pairing again for some reason after I pull the board out of the bulb, if it would still be possible.

Thanks.


(Dan) #12

It’s been a while, but I believe you can pair the Zigbee board after it has been removed. I had to do this when migrating from my v1 hub to my v2 hub.

Just power cycle the module in the same pattern as you would do if it was still in the bulb.


#13

Thanks for the response, Dan. What you said makes sense with the power cycling for repairing. Thanks again!


(Alan Penner) #14

I’ve been playing around with the Cree module, and wasn’t able to make this work reliably. For a few dim levels it’s reliable, but not for all of them. Sometimes, it fluctuates back and forth between levels when the bulb is constant. The PWM output isn’t perfectly linear, so the map function doesn’t do a great job of translating the PWM to a dimming level. I am trying to use all 99 dimming levels for my application.

A bigger problem, though, is that the timing is so sensitive that I can’t do anything else on the Arduino without throwing off the numbers. Certainly not anything that requires interrupts. I’ve taken it as inspiration to figure out a way to use the Cree board, though. To solve the main problem of letting the Arduino do other things, I’m using a Linear LTC2644 to convert the PWM to a fixed voltage. I’m then reading that voltage on an analog pin of the Arduino. I haven’t gotten all the voltages mapped to dimming levels yet, but it seems to be working, and completely offloads the hard stuff from the Arduino. http://www.linear.com/product/LTC2644

Thanks for the push to get me started!


(Alan Penner) #15

Update: It works! https://hackaday.io/project/19401-cree-dimming-level


(Dan) #16

Nice work and great writeup!


(Alan Penner) #17

Thank you! And thanks again for getting me started!


(Chris Hanson) #18

Dan,

I’ve now got a working garage door opener prototype. Thanks for the inspiration!

I used Arduino interrupts to get the PWM value and did some fuzzy math to get around the fluctuations. I figure the Arduino has little else to do.

Chris


(Ozzie Jacks) #19

Thanks to all the contributors. I used one of the Cree modules to directly control a 3V relay (no Arduino needed in this case) so that I can switch some fluorescent tube lights. I used a cut down Amazon kindle USB power supply and a 3V regulator to power it. The whole thing is small enough that I managed to fit it behind the regular light switch in the electrical box and wired it so that it is in between the light switch and the light. That way I can still use the regular light switch to override the relay if I want. Just make sure that you properly insulate everything so that you don’t electrocute someone. I used GE silicone II from Home Depot for that.

Does anyone know how to wire up the Cree light so that it becomes a dumb LED bulb after the module is removed? I was hoping that I could feed 3V to the PWM pin but that didn’t work.


#21

Ogiewon,
This project is way cool!
I wanted to see if the setup can be battery powered as opposed to having to plug in a wall wart to the wall. I know the ESP8266 can be battery powered. I wanted to see if the Cree parts you use can be as well.