How to use multiple Me Ultrasonic Sensor with Arduino


#1

I want to use three Me Ultrasonic Sensors with Arduino. But I don’t know how to select port and how to use distanceCm() for three sensors. Thank you so much.


#2

Hi,

The ME UltraSonic Sensor can be connected to ports 3, 4, 6, 7 or 8 (according to http://learn.makeblock.com/en/me-ultrasonic-sensor/).

For each sensor you just need to create an instance:

MeUltrasonicSensor ultraSensor_1(<port x>);
MeUltrasonicSensor ultraSensor_2(<port y>);
MeUltrasonicSensor ultraSensor_3(<port z>);

Then use the distanceCm() function for each instance:

ultraSensor_1.distanceCm() // read value for first sensor
ultraSensor_2.distanceCm() // read value for second sensor
ultraSensor_3.distanceCm() // read value for third sensor

Cheers
Antoine


#3