Chapter 6:

Hello again with a new chapter of Domotics. This will be very brief in order to finish the idea of how to clone and prepare to send signals between Arduino boards. Please check the previous publication:

Normalize and Compress IR Signals

In this case, we are not going to normalize the signal since our previous cloning work did that somehow. Please check that publication to get an idea.

I will be working with Java since is the language a know best. Please if you have come across similar codes in other languages please let me know will be more than happy to link it here.

So here we go...

## Step 1: Compress 1

Here we have the original signal:

2,5,2,2,5,6,2,5,2,3,5,5,2,6,2,5,2,3,5,5,2,6,1,6,2,108,2,6,1,3,5,5,2,6,2,2,5,6,2,5,2,6,2,2,5,6,2,5,2,6,2,108,2,6,2,2,5,6,2,5,2,3,5,6,1,6,2,6,1,3,5,6,1,6,2,6,2,108,2,6,2,2,5,6,2,5,2,3,5,6,1,6,2,6,1,3,5,6,2,5,2,6,2,109,2,5,2,3,4,6,2,6,2,2,5,6,2,6,1,6,2,2,5,6,2,6,2,5,2,109,2,6,2,2,5,6,2,5,2,3,5,6,1,6,2,6,1,3,5,6,2,6,1,6,2,109,2,6,1,3,5,6,2,5,2,3,5,6,1,6,2,6,1,3,5,6,2,6,1,6,2,109,2,6,2,2,5,6,2,5,2,3,5,6,2,5,2,6,2,2,5,6,2,6,2,5,2,0

In order to compress the signal, first we will have to remove the commas to send the signal as if it is composed of a state represented by one character. By doing that we will have to remove the large numbers (108). And place them in sequence in a header, so we can, later, revert the process.

108L108L108L109L109L109L109L

## Step 2: Compress 2

If you analyze the signal for a while, you will find out that have a considerable amount of numbers repeated throughout the signal several times. So we can use that to compress a little bit more. We will accomplish that easily with regular expressions.

This pattern "(.+?)\\1+", will find several groups of repeated sequences and basically, we will have to find the best one, that is the largest sequence repeated more times. And we will replace that number with a single character. Remember that we have to send a single character this is important.

108L108L108L109L109L109L109L26225625R

## Step 3: Reverting the Process.

In this step, we will be checking if we can revert safely the compression. Sow we will have to read the header to obtain the repeated sequence and the large numbers. Read the signal body one by one (in the same fashion as we will do in the Arduino board), and again replace one by one what has to be replaced. If we found an 'L' character we place the large number that we have in the large numbers sequence, if we found an R we will place the repeated sequence that we store in the header.

## Step 4: Compete Compiling Code.

This is the complete Java code to compress and decompress the signal. In the coming chapters, I will go deeper on how to accomplish the decompression task in the Arduino board. Do not get anxious, we still have a lot ahead to go.

You can run it here: run Java online

## Step 5: What Is Next?

The next chapter will be more fun definitively. We will learn how to send information to your Arduino board from your computer via USB. Once you have control of the board from your computer, you will be able to send signals to other Arduino boards using radios like NRF24L01 cheapest yet most powerful radio transceiver. Or the mighty hc-12 radio transceiver, very powerful yet a little bit expensive. Tested those and I could send information two blocks (streets) apart from the sender. They deserve a special chapter of Instructables. Here you have a nice youtube intro for those: h12 by Tom Heylen.

Or even with an extremely cheap infrared receiver and emitter. They don't have a big range, but since you are saving money on the receiver you can try buying an ir laser to achieve long distances. Haven't tried that yet though.

And remember if you can centralize domotics in your computer with an internet connection, you can have control of your house/building/company from everywhere in the world. And more interesting, you can use every tool that your computer or phone already has... like for example a speech recognition system.

Till the next chapter.