Working on a doorbell receiver in C

less than 1 minute read

I want to receive an email whenever someone rings the doorbell. To do this, I’m using an RTL-SDR USB dongle from Nooelec hooked up a to Pi.

My doorbell sends a signal 3 times in pulse width modulation on every press. The signal doesn’t change and it’s unique. Good start!

Carrier signal:

raw signal graph

Steps

  1. Balance the signal by removing the DC bias. Use averaging.
  2. Abs() all values in the signal. I want everything on one side of the X-axis for later on.
  3. Smooth out the amplitude ripples. Use even more averaging for this.

Demodulated:

demodulated graph

Output using a test file:

example output from console

The C program is straightforward. Each pulse/gap has a duration. Just keep track of the current duration of the pulse/gap and progress or reset if the duration is wrong. To do this I iterate through the below array where each element is the next bit of the doorbell signal.

ook_modulation protocol[] = {
    short_pulse,
    sync_gap,
    long_pulse,
    long_gap,
    short_pulse,
    long_gap,
    short_pulse,
    short_gap,
    long_pulse,
    short_gap,
    long_pulse,
    short_gap,
    long_pulse,
    short_gap,
    long_pulse,
    short_gap,
    long_pulse,
    long_gap,
    ...
}

Updated: