Besides detecting the signal with the "sniffer" sketch, this part took me the most time to figure out. It turns out that Twitter just recently decided that you can't use a HTTP GET command of the REST API v1.0 anymore. Developers must now use v1.1, which means you have to use OAuth even if you want to search for tweets. Since just recently, Twitter offers applications the ability to issue authenticated requests on behalf of the application itself (as opposed to on behalf of a specific user). This is called Application-only authentication, but the drawback of this is that you have to connect to the Twitter servers through SSL. Unfortunately, an Arduino isn't capable of doing this because it hasn't enough recources to do so.
With the Twitter library for Arduino from the Arduino Playground you can make it post a message to Twitter.
The following sketch prints a message to the serial output when it detects the doorbell signal.
I use the following sketch to test if the doorbell speaker reacts on the signal I found. It turned out that it works better when I adjusted the timings a little bit. That's why you won't find 520 microseconds, but 417 microseconds in line 29 of the code.
The first thing to do is detecting which signal is sent when pressing the doorbell button. For this purpose, we connect the RF receiver to the LINE IN connection of a PC and record the received signals with Audacity. This way, the PC acts like a kind of occiloscope, which I think is very cool. I was really suprised when it turned out that this really works!
First, build the following circuit:
You will need two resistors: 39 KOhm and 10 KOhm (which act as voltage dividers) and an audio cable with 3 segments on its plug. I stripped the 3 wires inside the cable and soldered it to 3 pins, so I could easily plug it into a breadboard. The power (5V) is supplied by the Arduino.
Now download and install Audacity. Audactity is a free to use audio editor. With this program, you can record the signal from the LINE IN input of your PC. While recording, press the doorbell button. The signal I recorded looks like this:
You can clearly see the moment on which I pressed the doorbell button.
Zooming in reveals that the same signal is repeated over and over again, with a long, low "sync" signal inbetween:
Zooming even further:
You can see that that this signal is built from just two different "building blocks":
- a long high pulse, followed by a short low pulse. We will encode this as a "1" in our Arduino sketch later on;
- a short high pulse, followed by a long low pulse. We will encode this as a "0" in our Arduino sketch.
This means that the code sent by the doorbell button is 0101 1111 0110 0010 0000 1000. The following question is: what is the duration of each pulse? When you zoom in even further, the sample points become visible as dots:
By counting the dots and noticing the sample rate at the lower left screen of the window, you can calculate the duration of the high and low pulses.
For example: when the recorded signal has a frequenct of 48000 Hz (samples per second) and you count 25 samples in the short signal, this signal has a duration of 25/48000 = (approximately) 520 microseconds.
Also notice that a long pulse is 3 times as long as a short pulse.