Switches on a relay when an authorized BLE device is in range. You get to specify the BLE device(s) you want to activate the switch– I'll show you how in the Code Setup instructions.
This could be used to turn lights/audio/heaters/whatever on and off based on the presence of people's devices. For example, I could add the device IDs for the smartphones of everyone in my office, and have the office turn on when the first one of us arrives in the morning, and off when everyone has left.
- Bluetooth Low Energy Module
- Relay Module
- Something to plug into the relay that you want switched on or off.
- One or more BLE devices that can advertise– I used a Myo; you could use a smartphone, another Tessel BLE module, or any number of other cool BLE devices.
- Always unplug power (including USB power) before you do anything involving wires.
- I'm assuming you're starting with a simple two-wire plug, like the one for a cheap desk lamp or space heater. Cut through one side of the cord. Be careful not to cut the other side of the cord; that insulation is important!
- Use wire strippers or scissors to expose the wires within the cut side of the cord. You want about a centimeter exposed.
- Using a screwdriver or a pen to press down on the tabs, insert both exposed copper ends into the two sides of Relay 1 on the Relay Module.
- Plug in the Relay Module to Port B and the BLE Module to port A.
- You may now plug in power for the relay-switched thing and USB power to your computer for the Tessel.
- Clone this repo.
- From inside your local copy of the repo,
npm installto install dependencies.
tessel run index.jsto run the code.
- Set a BLE device to advertising– say, a Myo, an August lock, a Fitbit, or your (fairly new) BLE-enabled laptop or smartphone.
- Check the console– it's scanning for your device! If it sees it, it should print out a message that it has discovered an unauthorized device, and the ID of that device. Copy the device ID into the
acceptedDeviceslist in index.js to authorize that device.
- Stop the code and run it again. Now, your device is authorized, and its presence will switch the relay on! Stop your device from advertising or move it out of range to switch the relay off.
- Feel free to add as many authorized devices as you want to the acceptedDevices array in index.js.
- I have this polling every five seconds, because reactions that fast look great in a demo setting. But if you wanted to deploy this in real life, you would probably want to make the polling time quite a bit longer to save power.
- If you want to use this long-term, you can run it from a battery, wall power, a solar charger, etc. according to this doc.
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!