LEVEL INDICATOR WITH 74HC4067

level 74hc4067

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/74HC4067%20LEVEL%20IND.zip

#include “MUX74HC4067.h”

MUX74HC4067 mux(7, 8, 9, 10, 11);
const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 1020;

void setup()

{
Serial.begin(9600);

// Configures how the SIG pin will be interfaced

// e.g. The SIG pin connects to PIN 3 on the Arduino,

// and PIN 3 is a Digital Output

mux.signalPin(3, OUTPUT, DIGITAL);

}

void loop()

{
int sensorReading = analogRead(A0);
// map the sensor range to a range of four options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 16);
Serial.println(sensorReading);
switch (range) {
case 0:
mux.write(0, LOW);
mux.write(1, LOW);
mux.write(2, LOW);
mux.write(3, LOW);
mux.write(4, LOW);
mux.write(5, LOW);
mux.write(6, LOW);
mux.write(7, LOW);
mux.write(8, LOW);
mux.write(9, LOW);
mux.write(10, LOW);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 1:
mux.write(0, HIGH);
mux.write(1, LOW);
mux.write(2, LOW);
mux.write(3, LOW);
mux.write(4, LOW);
mux.write(5, LOW);
mux.write(6, LOW);
mux.write(7, LOW);
mux.write(8, LOW);
mux.write(9, LOW);
mux.write(10, LOW);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 2:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, LOW);
mux.write(3, LOW);
mux.write(4, LOW);
mux.write(5, LOW);
mux.write(6, LOW);
mux.write(7, LOW);
mux.write(8, LOW);
mux.write(9, LOW);
mux.write(10, LOW);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 3:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, LOW);
mux.write(4, LOW);
mux.write(5, LOW);
mux.write(6, LOW);
mux.write(7, LOW);
mux.write(8, LOW);
mux.write(9, LOW);
mux.write(10, LOW);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 4:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, LOW);
mux.write(5, LOW);
mux.write(6, LOW);
mux.write(7, LOW);
mux.write(8, LOW);
mux.write(9, LOW);
mux.write(10, LOW);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 5:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, LOW);
mux.write(6, LOW);
mux.write(7, LOW);
mux.write(8, LOW);
mux.write(9, LOW);
mux.write(10, LOW);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 6:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, HIGH);
mux.write(6, LOW);
mux.write(7, LOW);
mux.write(8, LOW);
mux.write(9, LOW);
mux.write(10, LOW);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 7:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, HIGH);
mux.write(6, HIGH);
mux.write(7, LOW);
mux.write(8, LOW);
mux.write(9, LOW);
mux.write(10, LOW);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 8:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, HIGH);
mux.write(6, HIGH);
mux.write(7, HIGH);
mux.write(8, LOW);
mux.write(9, LOW);
mux.write(10, LOW);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 9:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, HIGH);
mux.write(6, HIGH);
mux.write(7, HIGH);
mux.write(8, HIGH);
mux.write(9, LOW);
mux.write(10, LOW);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 10:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, HIGH);
mux.write(6, HIGH);
mux.write(7, HIGH);
mux.write(8, HIGH);
mux.write(9, HIGH);
mux.write(10, LOW);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 11:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, HIGH);
mux.write(6, HIGH);
mux.write(7, HIGH);
mux.write(8, HIGH);
mux.write(9, HIGH);
mux.write(10, HIGH);
mux.write(11, LOW);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 12:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, HIGH);
mux.write(6, HIGH);
mux.write(7, HIGH);
mux.write(8, HIGH);
mux.write(9, HIGH);
mux.write(10, HIGH);
mux.write(11, HIGH);
mux.write(12, LOW);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 13:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, HIGH);
mux.write(6, HIGH);
mux.write(7, HIGH);
mux.write(8, HIGH);
mux.write(9, HIGH);
mux.write(10, HIGH);
mux.write(11, HIGH);
mux.write(12, HIGH);
mux.write(13, LOW);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 14:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, HIGH);
mux.write(6, HIGH);
mux.write(7, HIGH);
mux.write(8, HIGH);
mux.write(9, HIGH);
mux.write(10, HIGH);
mux.write(11, HIGH);
mux.write(12, HIGH);
mux.write(13, HIGH);
mux.write(14, LOW);
mux.write(15, LOW);
break;
case 15:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, HIGH);
mux.write(6, HIGH);
mux.write(7, HIGH);
mux.write(8, HIGH);
mux.write(9, HIGH);
mux.write(10, HIGH);
mux.write(11, HIGH);
mux.write(12, HIGH);
mux.write(13, HIGH);
mux.write(14, HIGH);
mux.write(15, LOW);
break;
case 16:
mux.write(0, HIGH);
mux.write(1, HIGH);
mux.write(2, HIGH);
mux.write(3, HIGH);
mux.write(4, HIGH);
mux.write(5, HIGH);
mux.write(6, HIGH);
mux.write(7, HIGH);
mux.write(8, HIGH);
mux.write(9, HIGH);
mux.write(10, HIGH);
mux.write(11, HIGH);
mux.write(12, HIGH);
mux.write(13, HIGH);
mux.write(14, HIGH);
mux.write(15, HIGH);
break;

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s