How to connect ultrasonic sensor to mbot ranger


#1

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.


#2

Please send me a picture of the ultrasonic sensor.


#3

@dai5_jp


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.


#4

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.


#5

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.


#6

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
output.dWrite1(LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
output.dWrite1(HIGH);
delayMicroseconds(10);
output.dWrite1(LOW);
// 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: ");
Serial.println(distance);
}


#7

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)


#8

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


#9

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.


#10

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


#11

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?