Chapter 6:

Hello again with a new chapter of domotics. This will be very brief in order to finish the idea on how to clone and prepare to send signals between arduinos. 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 some how. Please check that publication to get a the idea.

I will be working with java since is the language a know best. Please if you came across similar codes in other languages please let me know will be more that 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 comas to send the signal as if it is composed as a states 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 wile , you will find out that have a considerable amount of numbers repeated through out the signal several times. So we can use that to compress little 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 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 have to be replaced. If we found a 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 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 in here: run java online

## Step 5: What Is Next?

Next chapter will be more fun definitively. We will learning 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 another arduinos using radios like NRF24L01 cheapest yet powerful radio transceiver. Or the mighty hc-12 radio transceiver, very powerful yet 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 nice youtube intro for those: h12 by Tom Heylen.

OOOOr even with extremely cheap infra red receiver and emitter. They don't have a big range, but since you are saving mony in the receiver you can try buying a 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 you computer or phone already has... like for example a speech recognition system.

Till next chapter.