I'm new to arduino and I was hoping if anybody can show me how to code a multiplexer (CD4051BE) for 64 IR-sensors? Really need it!

Okay, To be more direct the problem is a software and not a hardware one. That I can do but the coding part is where I'm stuck.

THX in advance

  • 1
    I'm not sure if you really know what you are asking for. A multiplexer allows you to chose one IR-receiver at a given time. So while listening to one IR-receiver, the signals of all the other receivers is just lost. What are you trying to accomplish? Are you using 64 different kind of receivers (different wavelength and/or modulation) or are the receivers spread across an area with no line of sight for every single one? If you are trying to receive IR signals from 64 different sources with line of sight, then you usually need one, two or maybe three receivers at most. – Kwasmich May 16 '19 at 11:17
  • Please show us the code you have written so far. – VE7JRO May 21 '19 at 22:18

Instead of writing the program (we do not offer a coding service), what you should do is:

  1. Find out how to write (and maybe read) a pin (digitalWrite).
  2. Obtain a datasheet for the CD4051.
  3. Create on paper a simple diagram/scheme in what order you want to do what (how to set each pin in what order) and verify if this does what you want.
  4. Coding what you created.

The third action might look like:

FOR each sensor (one out of 64)
   Write the bits to define the output (Input A, B, C), using `digitalWrite`)
   Read the sensor (not sure how your sensor work, probably with `analogRead`).
   Calculate the IR value.
   Process/store the value

Actually I think only 8 are possible per CD4051, so you need more of them, in that case, use a second for loop to set the second CD4051 in the correct way.

| improve this answer | |

This is both a hardware problem and a software problem. I'll focus on the hardware part, and also talk briefly about how to select one of your IR sensors once you've built the hardware.

Assuming the CD4051 only multiplexes 8 channels you'll need to build a 2-level multiplexer in order to be able to select one of 64 IR sensors.

You would attach the output of a top-level CD4051 to your Arudino. Then you'd attach each of the inputs from that first CD4051 to the output of another CD4051. You'll need a total of 9 CD4051's. You'd use a 3-bit input to the top-level CD4051 to select one of the 8 second-level multiplexers. You could then tie the 3 channel selector lines of each 2nd level CD4051 together. (You'd tie the Channel select pin As of all 2nd level CD4051s together, all channel select pin Bs together, and all channel Cs together).

The 3 control pins from the top level CD4051 and the 3 control pins from the 2nd level CD4051s would be connected to 6 digital outputs of the Arudino and serve as a 6 bit channel selector. which would select one of the 64 input pins on the 2nd level CD4051s.

To select 1 of 64 inputs you'd set the 3 bits to the top-level CD4051, which would select one of it's 8 input pins, which is in turn connected to one of the 8 second-level CD4051's. The 3 control bits to the 2nd level CD4051 would select one of the inputs to the active 2nd level CD4051. (It would select one of the inputs on ALL the 2nd level CD4051s, but only the selected 2nd level CD4051's output would be fed to the top-level CD4051, and forwarded to the Arduino.)

Once you've rigged your 9 CD4051s this way, the 3 bits from the top-level CD4051 and the 3 bits from the 2nd level CD4051 would serve as a 6-bit address of one of 64 inputs. You'd then wire your 64 IR sensors to all 64 inputs of the 2nd level CD4051s, and write Arduino software to use the 6 digital outputs pins to output the 6-bit address of the desired IR sensors into the CD4051 multiplexer array.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.