Go Down

Topic: Help with multiplexing HC-SR04 Ultrasonic Sensors with 74LS153N MUX Chip (Read 164 times) previous topic - next topic

josedlr00

Basically what I'm trying to do is Multiplex ultrasonic Sensors, but I'm not able to obtain data from the sensors once I wire everything. In the code below I'm only utilizing only one Ultrasonic Sensor and the 74LS153N MUX chip, but when I run the code no data is being display in the serial monitor.

Code: [Select]
// Multiplex input
#define EN 7 // Latch enable
#define A 6 // S0
#define B 8 // S1
// PING sensor interface Pins
#define SEN_IN 2 // Za
#define TRIGGER 9

// Data variables
int inDist = 0, cmDist = 0;
int sensorData[] = {0,0,0,0};

// Function prototype for reading Data
void usReadData(int sensor); //Reads sensor data Value

void setup() {
  Serial.begin(9600); //Initialization serial output
  pinMode (EN, OUTPUT); // Latch Enable interface
  pinMode(TRIGGER, OUTPUT); // PING Trig interface
  pinMode(SEN_IN, INPUT_PULLUP); // INput for the PING Echo
  digitalWrite(EN, HIGH); // Disable Mux
}

// Main execution of Arduino Code
 void loop()
{
  usReadSen(); // Read raw Distance value
  cmDist = ((sensorData[0] / 29) / 2); // Distance in CM
  inDist = ((sensorData[0] / 74) / 2); // Distance in inches
 
  Serial.print("Sensor: "); // Sensor #1
  Serial.print(inDist, DEC); // Distance in inches
  Serial.print("inches, \t"); // Units
  Serial.print(cmDist, DEC); // Distance in cm
  Serial.print("cm \n"); // Units
}

// Reads sensor data Value
void usReadSen()
{     
      // Trigger a pulse on PING Sensor
      digitalWrite(TRIGGER, LOW); // Ensure Trigger is LOW
      delay(30); // Short delay
      digitalWrite(TRIGGER, HIGH); // Trigger PING
      delay(150); // Wait for trigger
      digitalWrite(TRIGGER, LOW); // Trigger back to LOW

      // Listen for the Echo, save value in array
      sensorData[0] = pulseIn(SEN_IN, HIGH, 200);
      Serial.println(sensorData[0]);
 
}


The only part of the ultrasensor that I'm trying to Multiplex are the ECHO pins, in this case it will be only one ECHO pin when using the code above.

As you can see in the code above I'm defining everything properly: EN (Enabler), S0, S1, Za(Output from the chip), Trigger pin (Arduino).

I'm connecting the ECHO directly into the chip on the I0a pin in the MUX. The values of the ECHO are being store in a array sensorData[0]. But i still not able to get any  data in the serial monitor.

terryking228

Hi,

If you are triggering all the units, you will be getting lots of different incoherent echos.

Does it work with only one sensor connected?
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

josedlr00

Yes, I am only using one sensor, and the code attached is the code that I am using for it, but I still aren't able to obtain any data displayed in the Serial Monitor.

Go Up