Sprinklino

Posts Tagged ‘multiplexer’

Multiplexer Test

So tested out the CD4051B 8 Channel Multiplexer today and everything worked as expected. I’m using a multiplexer so that I can use more sensors than I have digital i/o pins.

It’s very simple to use, you send the chip a 3 bit address, and that is the pin that is connected to the output.

To get the Arduino to select each input in turn I did a loop and wrote value directly to the port data register PORTD


void loop() // run over and over again
{
for(int i = 0 ; i <= 16 ; i++)
{
byte b = (byte)i << 2; // Shift to the left so that I don't mess with pins 1 & 2
PORTD = b; // Write bits to the i/o pins
delay(50);
}
}

I have my LED resistor connected to the common pin so that I only need to use one, and LEDs connected to all the output pins, et voila disco lights :)

Although you can’t see it in this pic the leds are being lit one after another. You can also see the RX4 ASK receiver in this pic but it isn’t hooked up yet as I’m waiting on the TTL/RS232 converter to arrive to program my other Arduino which will control the transmitter.