I bought Makeblock Ultimate 2 robot. I built Robotic Arm Tank. I installed on it 2 ultrasonic sensors HC-SR04 but I can not make them work.
Here is my test code:
#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 TRIGER_PIN 10 // Arduino pin for both trig and echo
#define ECHO_PIN 11
NewPing sonar(TRIGER_PIN, ECHO_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 dist = sonar.ping_cm(); // Send ping, get distance in whole centimeters.
Serial.print("Ping: ");
Serial.print(sonar.ping_cm()); // distance in whole centimeters
Serial.println("cm"); }
I connected the sensor also with a bread-board and DuPont wires to be sure that all the 4 pins are connected where they have to be.
But I get only "0 cm".
In the final I have to make HC-SR04 to work only with 3 pins (trigger pin and echo pin connected together).
Please help me to discover what I am missing.
The robot is intended to be a Christmas gift for my grand son and Christmas is already next corner and I am a little desperate.
Thanks.