Manchester Code Library for Arduino

Introduction: Manchester Code Library for Arduino

I made wireless motion dectors (see and I spent some time to search for a good library to avoid me to code too much.

I found some, and some have worked but when I opened the code, oh dear i has been flooded with a lot of blabla, multiples functions, Arduino stuff to be compatible with a lot of board...

So I decided to code a library myself, not the best, but the simpliest, readable and understandable.


Step 1: About the Manchester Code

I won't explain the manchester code in details hereby, there is a lot of publication on internet that will do it better than me.

But just to resume :

A 0 bit is coded with a rising edge.

A 1 bit is coded with a falling edge.

This code is supposed to be more resistant to noise. That is why I've choosen it.

Step 2: About ASK and RF Modules

No ASK is not a bad word, it means : Amplitude Shift Keying.

And so what ?

It is a complicated acronym for something so simple :

  • If I want to transmit 1, I emitt a signal.
  • If I want to transmit 0, I stop to emitt the signal.

But before doing this, I need to tell to my receiver : hey it's me, I am about to send you a message !!

To do that, I will send it a suite of 1 0 1 0 1 0 ... the receiver will sense the signal, a regular signal : so it is not a noise but someting is talking to me, and measure the amplitude to make it a reference.

This is the purpose of the send_sync() in manchester_tx.h :

void Sender::send_sync()
/*send 32 HIGH LOW edges to synchronize with the receptor*/


/sending a sync signal

for (byte i=0;i<32;i++)





delayMicroseconds(T); }




-> 32 is arbitrary, you can try to send less and see if it still works...

From then we can talk ...

Step 3: Sending a Byte

To make understand the receiver we are sending data and not sync signal as in the previous step, let send a start byte.

Then the receiver will now that the following byte is the data.

void Sender::send_load(byte start[],boolean state)

-> call the function twice, one time to send the start byte and oner time to send the data byte

void Sender::send_byte(byte car)

-> use previous function to send start byte + data byte, this is the one you should use in your skectch

Step 4: Let Deal With the Receiver

void Receiver::seek_start()

-> loop indefinitly until a start byte is received

This is a blocking function, I may improve it ...

byte Receiver::read_signal()

-> read a byte

This is also a blocking funciton, but there is a timeout, so if the signal is not received within few ms it returns 3

Step 5: No Blabla, Let Make It Work

I count on you to buy a pair of RF emitter/receiver...

Plug the emitter data pin on pin 9 of an Arduino. The receiver is on pin 11 of a another Arduino.

Install my library and check the examples.

Be the First to Share


    • Jewelry Challenge

      Jewelry Challenge
    • One Board Contest

      One Board Contest
    • Photography Challenge

      Photography Challenge