I'm using a 16-channel MUX (CD74HC4067) to read high/low signals from 16 hall sensors. In this prototype, only one sensor will be activated at a time. I want to light a corresponding (one of 16) LED when a sensor is activated, and turn it off only when the sensor is deactivated.
Do I need an additional MUX to send a write signal to the corresponding LEDs?
For example, the hall sensor on channel 11 is activated. I want then to also light the LED for channel 11 until the channel is deactivated.
I am using this base code as a starting point
void loop()
{
byte data;
for (byte i = 0; i < 16; ++i)
{
// Reads from channel i and returns HIGH or LOW
data = mux.read(i);
Serial.print("Push button at channel ");
Serial.print(i);
Serial.print(" is ");
if ( data == HIGH ) Serial.println("not pressed");
else if ( data == LOW ) Serial.println("pressed");
else if (data == HIGH) {
digitalWrite(ledPin, LOW);
}
else {
digitalWrite(ledPin, HIGH);
delay(2500);
}
Serial.println();
delay(150);
}
}
Ideas and/or code snippets greatly appreciated.
You could use two shift registers, 74HC595 or TPIC6C595. Shift in a pattern corresponding to the LED you want turned on. Don't forget a current limit resistor for each LED if more than 1 can be on.
The mux would seem a bit overkill for LEDs. How about a 16-bit shift register like the 674 or a cascaded pair of 595s?
DKWatson:
The mux would seem a bit overkill for LEDs.
Not overkill but totally the wrong component. The problem with a multiplexer to drive LEDs is that you need to keep, scanning or refreshing as it is called, the state of the LEDs because only one LED can be on at one time.
I would use a port expander MCP23017 or an MCP23S17.
because only one LED can be on at one time.
If the LED reflects the channel that is open, and only one channel can be open at a time, what necessitates having more than one LED to be lit at one time?
The MCP23017 or MCP23S17 truly are overkill. Why would one implement a 16-bit bi-directional port expander and use the I2C or SPI pins to light a single LED?
I am opening to trying to use other components. I'm just a hobbyist here, with little education on all the different components.
This product, while likely overkill, seems like it might be the easiest solution for a noob like myself to get a working version of the full project, which actually requires a way to read 31 hall sensors and then output to a single corresponding LED:
Am I reading this correctly that I could use two rows for the 31 inputs, and then use the remain row to output to the LED? I'm assuming since I only need to light a single LED at a time, that I don't need 31 outputs, but that a single output will do.
thank you.
Where is the single light part is coming from? If two sensors are active, don't you want to have two leds on?
And for that, there are multiple solutions. A mux is one of the more pore solutions... A shift register like a 595 is better. TPIC6C595 if you want high currents but if you just want indication leds a HC595 with resistors limiting the current to +-2mA is fine as well.