Always wanted to create your own sensors and actuators? With MySensors you can. Create your own PIR’s, detect the light level, Control LED strips or hack other dumb hardware and make it ‘smart’!
What is MySensors
MySensors is software to control arduino’s wirelessly. This software is open source and can be found at GitHub. To transmit data between arduino’s you need a NRF24L01+ or the RFM69 transceivers. More detailed info can be found here.
Where do i start?
To program the arduino’s you need the MySensors library for the Arduino IDE. You can download the latest stable version here Copy all those files to /Documents/Arduino/
Gateway
Video: https://youtu.be/TBvGrB094Co
The heart of the MySensors network is the Gateway, this gateway is connected to your pimatic installation. Like the Homeduino gateway. For the gateway you need:
You connect the radio like this:
Mak sure you connect the VCC of the NRF to the 3.3v output of the arduino
After connecting the NRF to the arduino open the Arduino IDE on your computer and upload the gateway sketch. This can be found in the examples in the arduino IDE. File > Examples > MySensors > SerialGateway
. Upload this sketch to the arduino nano and wait till its finished. After its finished open the serial monitor and look for the startup messages. If its says Gateway startup complete
your good to go. If it says, Check Wiring
you have to check if the wires of the NRF are connected correctly.
Setup pimatic
If the gateway is working you have to connect it to the raspberry where pimatic is installed. Open the terminal and check where your arduino is.
ls -l /dev/ttyUSB*
You should see something like:
crw-rw---- 1 root dialout 188, 0 Apr 12 00:01 /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 1 Apr 11 23:30 /dev/ttyUSB1
In this case I have 2 arduino’s connected. the USB0 is homeduino and USB1 is the MySensors gateway.
Now install pimatic-mysensors and add this to the plugin section (where serialDevice is your arduino we found in the terminal):
{
"plugin": "mysensors",
"driver": "serialport",
"protocols": "1.5.1",
"driverOptions": {
"serialDevice": "/dev/ttyUSB1",
"baudrate": 115200
}
},
We also add this device for testing our sensor (add it to the device section of the pimatic config), this is a simple contact sensor for something like a door:
{
"id": "Door",
"name": "Door",
"class": "MySensorsButton",
"nodeid": 1,
"sensorid": 1
},
Now restart pimatic and your good to go. Now lets create your first sensor.
Sensor node
Video: https://youtu.be/2bc27dpof04
Lets create a simple contact sensor so we can test if everything is working. For this sensor you need:
- Arduino Nano or Pro Mini 3.3V BUY
- NRF24l01+ BUY
- If using the pro mini you also need a programmer BUY
Now lets connect the radio the same way you did with the gateway and connect the arduino to your computer and upload this test sketch with the Arduino IDE.
This sketch sends an open/close signal every 10 seconds.
#include <MySensor.h>
#include <SPI.h>
#define NODE_ID 1
#define CHILD_ID 1
MySensor gw;
MyMessage msg(CHILD_ID, V_TRIPPED);
void setup()
{
gw.begin(NULL, NODE_ID, false);
gw.present(CHILD_ID, S_DOOR);
}
void loop()
{
gw.send(msg.set(1));
gw.sleep(10000);
gw.send(msg.set(0));
gw.sleep(10000);
}
After uploading open the serial monitor and check if everything works. If a message contains fail than the sensor can’t reach the gateway. If you get messages with OK and the end, then everything is working. Now check pimatic, and see if the contact device changes every 10 seconds. If this is working you have created your first sensor
Example sensors
In the MySensors library there are a lot of examples how to use sensors and actuators. check File > Examples > MySensors
. Device examples for pimatic can be found here
Troubleshooting
I get the message Check Wiring
This means your sensor is not connected correctly. If you’re sure it is, maybe your NRF is broken.
I get a lot of fail messages
This means the sensor or gateway can’t find each other. Move them closer and see if it works then. You can add a capacitor to the NRF for a more stable voltage. Connect a 10uF between the GND and VCC of the NRF. You can also add a repeater and place it somewhere in between.
What is my nodeid?
Most example sketches ask for a id from pimatic. after uploading the sketch and letting the sensor startup check the serial monitor on the Arduino IDE. You should see something like Sensor started with id x
where x is your nodeid.
Some useful videos:
Creating the gateway: https://youtu.be/TBvGrB094Co
Creating a motion sensor: https://youtu.be/2bc27dpof04
Troubleshooting: https://youtu.be/vehinrWbxpw