Me Ultrasonic Sensor and HC-SR04 Sonar Sensor can be used together?


#1

I have Ultimate 2 kit. I built the Robotic Arm Tank and I mounted on it 2 motorized ultrasonic sensors HC-SR04 and 1 Me Ultrasonic Sensor. After finishing the mechanical work I started to learn and understand how to program it. From the start I have a problem.
It is said that if I use NewPing Library for HC-SR04 that is possible to conect together “transmit” and “receive” pins of the sensor and to use, in this way, only one signal pin from MegaPi board (1 pin per sensor) beside the +5V and GND pins.
The problem is that when I tried to include NewPing Library in Arduino IDE I got a compilation error. See the image below.

Is any possibility to solve this problem?
I am very in the beginning with my programming skills.
Thanks.


#2

I found a very good description and solutions for this problem here
I hope that it is useful.


#3

I tried to read the signal from HC-SR04 sensor with 4 pins connected on MegaPi on pin number 13 (Send and Receive pins were connected together to MegaPi pin number 13).
For this I used the below code taken from here:


#include <NewPing.h>
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <MeMegaPi.h>

//this is a code for using a 4 pin hc sr04 sensor as a 3 pin ping sensor By robobot3112

#define PING_PIN 13 // Arduino pin for both trig and echo
NewPing sonar(PING_PIN, PING_PIN );

void setup() {
Serial.begin(115200);
}

void loop() {
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM); // convert time into distance
Serial.println(“cm”); }


But I am receiving only 0 cm.
What I am missing?


#4

I succeed to find myself the resolution.
Instead of “PING_PIN 13” must be “PING_PIN A13”.
This was my mistake.
Now is working like a charm.
So, the answer to my question is YES, is possible to use Me Ultrasonic Sensor and HC-SR04 Sonar Sensor in the same project.


#5