Bluetooth, and Picaxe Lightswitch

by chanks2 in Circuits > Remote Control

6299 Views, 26 Favorites, 0 Comments

Bluetooth, and Picaxe Lightswitch

20130807_014349.jpg
Drawing1_zps64a13397.png
20130807_014332.jpg
20130807_014357.jpg
20130807_014433.jpg
BYTERULE.COM BLUETOOTH LIGHTSWITCH
PROJECT SCOPE
August 6, 2013
OVERVIEW
1. Project Background and Description
This is the first project I am starting with in the realm of home automation and wireless connections.   I have limited use with Bluetooth and wanted to get more experience with the technology.   After looking around I saw one of these at Target or WM for about $99 (7/20/2013).
2. Project Scope
This project will include a electronic light switch that will accept input from either Bluetooth or a touch sensor  to then turn the light on and off.   This is version 1.0   I mention this as there are future versions that will be added in order to further the design later.   Project should cost as little as possible with the easiest use for non technical people.  (specifically family).
3. High-Level Requirements
• Blue tooth connectivity
• Local way to turn on an off the light with touch


4. Affected Parties
Family, friends, who ever happens to be in the house.


5. Specific Exclusions from Scope
Nothing at this time.
6. Implementation Plan
After looking online I plan to purchase the Bluetooth module, and a relay module that will reduce the amount of time required to develop this project.  Due to the voltage and current requirements it is possible to damage circuits and or ignite a fire with the cables involved.   I also plan to run this from a wall plugin and will need a solid permanent 5V power source for this project.
7. High-Level Timeline/Schedule
Purchase the online items
Look locally for remaining parts at a discount. 
Develop on a circuit board and transfer to a soldered circuit.
8. Parts
The online parts were found on very inexpensive sites. 
• Picaxe 18m2+   ($3.91) http://www.robotshop.com/picaxe-18m2-microcontroller-chip.html?utm_source=google&utm_medium=base&utm_campaign=jos
• Bluetooth transceiver  ($7) http://compare.ebay.com/like/290932857308?var=lv • 5V Relay Module for Arduino (Works with Official Arduino Boards) ($3)
http://dx.com/p/arduino-5v-relay-module-blue-black-121354?utm_source=GoogleShoppingUS&utm_medium=CPC&utm_content=121354&utm_campaign=436&gclid=CPWxmPC76rgCFazm7AodATcAUA
• Now save some money go get a 5V (1A-2A) power converter from the local Goodwill or similar second hand store. 
• Few resistors, wires, and circuit board of your choice.
9. The circuit
You will need to program the Picaxe chip however as this will not be part of the finished product it will not be included in the circuit.  We can program the chip on a solder less board and move it into the circuit laid out below.   To do this connect the chip per the Picaxe manual  which can be found (http://www.picaxe.com/docs/picaxe18m2.pdf ).  To make the circuit there is really only a few connections Power, Ground, Serial TX, RX, Touch, and Signal.  A total of 10 or less connections.   Below is the circuit laid out to use the Picaxe boot loader. 
http://i1331.photobucket.com/albums/w582/cody_byterule/Bluetooth%20lightswitch/Drawing1_zps64a13397.png                                                                                                                                                                                 https://plus.google.com/photos/106710414793493759480/albums/5909298573545462145?authkey=CLb-vanowvWQOA        

10.  Programing
The basic idea in program this project is read the blue tooth value if you get a specific pattern then go to turn the light on or off, or if you get a touch turn the light on or off… we don’t actually have to know if the light is on or off just that we changed it.
The code is really simple .
///////////////////////////////////////////////////////////////////// code ////////////////////////////////////////////////////////////////////////////////////////////////////////
; cody hanks
; 8/6/2013
; picaxe 18m2+ code for light switch
; input from bluetooth or a touch sensor 
; output to a relay for light on and off.
;reset the frequency to improve the resolution ( and increase the Bluetooth speed) 
SETFREQ m8     ; set the chip to 8 Mhz
hsersetup B9600_8, %00  ; set to Baud rate of 9600 with a frequency of 8Mhz
input C.1  ; setup the input for touch sensor
output C.0 ; setup output for signal wire to relay module

let b2=0

main: w1 = $FFFF  ' set up a non-valid value
; w1 is word one held in bytes 2 and 3
hserin w1  ' receive 1 byte into w1
if w1 <> $FFFF then ; if a byte was received check that its not the invalid byte
  ; Ascii 1 = dec 49  so this should check for a 1 sent
  ; over the bluetooth signal and will toggle the output
  if w1 = 49 then  
    toggle C.0
  end if
  ; send to the bluetooth so we can see what it recived
   hserout 0,("you pressed a button:",w1) ; echo it back out
end if

; this will read the touch value in 16 bits into the w0 memory
touch16 c.1,w0
; w0 is in bytes 0 and 1
; check for 0's on the touch sensor depending on connection and noise this
; could signl a touch
if w0 = 0 then goto interuptloop
; send the value out to bluetooth, this is so we can re program to the correct
; sensetivity at a later time.
hserout 0,("value:",#w0,13,10)
; the other value for my setup is if w0 >6000 then a touch
if w0 > 6000 then goto interuptloop



pause 5
; debug works on the programing serial port and will output values for all
; memory locations back to the programing editor
debug

goto main  ; loop


interuptloop:
pause 100 ; waid befor checking to see if its still being touched
touch16 c.1,w0 ; read
hserout 0,("value:",#w0,13,10) ; output to bluetooth to debug
; if it is still being touched do nothing and simply go to loop
if w0 = 0 then goto interuptloop
if w0 > 5400 then goto interuptloop
; once its no longer being touched then we change the light.
toggle C.0
; and loop
goto main
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11.  Problems
There is one major flaw in this design that causes a problem consistently.  A adc converter connected to un ungrounded plate that sits in open air IE the touch sensor is really unsecure. Version 2.0 – or later will use a better method for this … for now it’s simple to turn this off in the code