Adani, I need to tell you I’m not an expert programmer and I’m not the best person to help you with the nitty-gritty details of your program. I’ve done lots of programming over the years in several different programming languages and I’ve even written some programs for work. But, I have to constantly refer to my programming books and I write my code in little bits at a time.

Now… Let’s back-up a bit… **What kind of information are you trying to get from the sound?** I’m getting the impression that you are trying to get two states:

1 - Sound is above the threshold.

2 - Sound is below the threshold or silent.

I suppose I should have started counting with “state 0”, since we are in the digital/programming world.

Then, you want to collect this information, put it into an array, and use it later to control a couple of servos?

So now, I am not sure what that binary is. Maybe is just a binary translation of the decimal value that I get from the analogue signal? (i.e, if the signal I get is 100,259,129 ETC… I get the binary conversion of these values.)

So… Let’s convert these example numbers to binary to see if that gives you anything useful… (I’m using the Windows calculator in programming view).

100 decimal = 1100100 binary

259 decimal = 100000011 binary

129 decimal = 10000001 binary

Or, if we have a type *int* and we look at all 16-bits, we’d get this:*

0000 0000 0110 0100

0000 0001 0000 0011

0000 0000 1000 0001

**Are those numbers (or patterns/sequences) helpful for what you’re trying to do?**

Note that bit zero (the rightmost bit) corresponds to odd & even. If you bitRead bit zero from those three numbers and stuff it into an array (left to right), you’ll get 110.

**Is that array at all helpful for what you’re trying to do?**

```
//iterate for the size of array and put all the values in the array
for (int i=0;i<=arraySize;i++)
{
myBinary[count] = bitVal ; //add the sensorvalue to the array
count++;
Serial.println(myBinary[count]);
// Serial.println(bitvalue);
// Serial.println(sensorvalue);
}
```

So… Although I’m still not sure what you’re *trying* to do, I can tell you what you’re doing wrong.

Before going into your for-loop, you read bitVal **once.** That’s going to be 1 or 0, depending on if sensorvalue is odd or even.

Then, your for-loop writes that **same bitVal** into your array 40 times.

```
i<=arraySize;
```

That looks like a small error too… Your 40 element array is counted 0-39 (not 0-40), so I think that should be *i < arraySize*.

*** Totally off-topic:**

It’s traditional to break binary numbers into 4-bit “nybbles” because it makes it easier to read and it’s easier to convert to hexadecimal. It’s also very common to use hex when working with binary numbers/patterns because it’s a LOT easier to read & write than binary.

It’s easy to convert between hex and binary (a LOT easier than converting between decimal and binary) because each group of 4 bytes represents exactly one hex digit.

That means you only have to memorize 16 conversions and you can convert numbers of any size between hex and binary in your head!

You actually only need to memorize 14, since 0 and 1 are the same in hex, decimal, and binary. And some are easy to remember… (such as F = 1111, 5 = 0101, A = 1010, etc.)