How to connect ultrasonic sensor to mbot ranger


Hello, I have recently purchased an RJ25 adaptor and RJ25 to dupont wires, but I was stuck on trying to code an ultrasonic sensor, as i don’t know how to connect to the sensor.


Please send me a picture of the ultrasonic sensor.



its this one
I know how to connect the ultrasonic but not sure how to code and config it using the dupont/RJ25 adaptor using the mbot ranger.


Sorry for the late reply.
Look at this picture.

This is an enlarged photo of a part of the rj25 adapter (hereinafter abbreviated as “adapter”).
S1 and S2 are also written on the opposite side, and they are connected. The value varies depending on which port the adapter is connected to.


For example, when an adapter is connected to port 6, s1 is connected to a10, and s2 is connected to a15. In the same way
In port 7, s1 is connected to a9, s2 is connected to a14.
When connecting to other ports, it will be as shown in the table below.


I have tried this code, to measure the distance of the ultrasonic, I have looked at the RJ25 example code and tried to adapt it. but it doesn’t work.

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <MeAuriga.h>

// defines variables
MePort output(PORT_6);
MePort input(PORT_6);
long duration;
int distance;
void setup() {
Serial.begin(9600); // Starts the serial communication
void loop() {
// Clears the trigPin
// Sets the trigPin on HIGH state for 10 micro seconds
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(input.dRead2(), HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");


I’m sorry! I forgot to tell you.
You cannot use the adapter without using auriga as arduino mega 2560. (As far as I know)


So, How would i connect it, as I have an arduino mega.


I’m sorry. Because I am translating sentences with automatic translation, I couldn’t convey the meaning well.
me auriga is based on arduino mega 2560.
So you can use me auriga as arduino mega 2560.


Code example (When an adapter is connected to port 6, trig of ultrasonic sensor is connected to s1, and echo is connected to s2) (599 Bytes)


You are amazing, the code works but I was wondering why did you put the trig and echo pins to 64 and 69? is their a pinout sheet which shows the pinouts for each port?


The arduino’s analog input pins (the pins that start with A) can also be used as digital input / output pins. In that case, you can use it as a digital pin by adding 54 to that number (example:
A0 = 54, A10 = 64).
However, after that, I found a better way.
Simply select A10, A15, etc.
pinMode (A10, OUTPUT);
DigitalWrite (A10, HIGH);


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.