-
Notifications
You must be signed in to change notification settings - Fork 1
Multiplexeur
augustinsoul edited this page Feb 5, 2020
·
1 revision
Implement an Arduino code in order to handle several ultrasonic sensors HC-SR04 (max 8).
- a multiplexer CD74HC4067
- an Arduino board
- 2-8 ultrasonic sensors HC -SR04
- Build the circuit with the Arduino, the multiplexer and the ultrasonic sensors.
Multiplexer/Arduino connections :
SIG on 2
s3 on 3
s2 on 4
s1 on 5
s0 on 6
Sensors/Multiplexer connections:
Sensor1:
pin trigg on C0
pin echo on C1
Sensor2:
pin trigg on C2
pin echo on C3
- Initialize the pins of the multiplexer
const int SIG = 2;
const int s0 = 6;
const int s1 = 5;
const int s2 = 4;
const int s3 = 3;
void setup() {
pinMode(SIG, INPUT);
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
Serial.begin(9600);
}
- To access to the channels of the multiplexer you have to send a number on 4 bits to the multiplexer.
For example, if you want to access to the channel C0, you have to send 0, which is "0000" in binary, so s0=LOW, s1=LOW, s2=LOW, s3=LOW, if you want to access to the channel 4, you have to send 4 to the multiplexer, whixh is "0100" in binary, so s0=LOW, s1=LOW, s2=HIGH, s3=LOW;
(LOW = 0, HIGH = 1).
Example with 2 ultrasonic sensors using channels C0,C1,C2,C3 :
void loop() {
//sensor1
long duration1, distance1;
digitalWrite(s0, HIGH);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(2);
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(10);
digitalWrite(s0, HIGH);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
duration1 = pulseIn(SIG, HIGH);
distance1 = (duration1/2) / 29.1;
Serial.print("Sensor_1");
Serial.print(distance1);
Serial.println("cm");
delay(500);
//sensor 2
long duration2, distance2;
digitalWrite(s0, HIGH);
digitalWrite(s1, HIGH);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(2);
digitalWrite(s0, LOW);
digitalWrite(s1, HIGH);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(10);
digitalWrite(s0, HIGH);
digitalWrite(s1, HIGH);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
duration2 = pulseIn(SIG, HIGH);
distance2 = (duration2/2) / 29.1;
Serial.print("Sensor_2 : ");
Serial.print(distance2);
Serial.println("cm");
delay(500);
}
Make sur that all your sensors and connections are functionals. (lol)
-
[Tutorials]
- [MECA]
- [Wheelbase]
- [CAD Model]
- [CODE]
- Ubuntu 18 on raspi 4
- [ROS 101]
- Master-Slave ROS
- Camera ROS
- Lidar gmapping and nav stack
- [Add points to virtual map]
- Simulate mapping
- Set up TF environment
- Using-yolo-v3
- [Weed recognition]
- [Embedded Inference]
- [ELEC]
- [Hardware]
- Ultrasound Sensors
- Multiplexer
- [Alimentation]
- [MAKE]
- 3D Modeling
- Laser cutting
- 3D Printing
- CNC Extrusion
- [Tools 101]
- [MECA]
-
[Subprojects]
-
[Articles]
- [Type of sensors]
- [Choice of microcontroller]
-
[Ressources]
- [Cloud]
- [Other Repositories]
- [Papers]
- [Youtube Channels]
-
[Miscellaneous]