I have found another UltraSonic with I2C here
The addresses are similar for the commanding the sensor to read.
Here is the same code for mine :
#include <Wire.h>
void setup() {
Serial.begin (9600);
Wire.begin();
Wire.setClock(400000L);
}
int Range=0;
void loop() {
// Step1: instruct sensor to read
Wire.beginTransmission(112);
Wire.write(byte(0x00)); // sets register pointer to the command register (0x00)
Wire.write(byte(0x51));
Wire.endTransmission(); // stop transmitting
// step2: for reading to happen
delay(200);
// step 3: instruct sensor to return a particular echo reading
Wire.beginTransmission(112); // transmit to device #112
Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02)
Wire.endTransmission(); // stop transmitting
// step 4: request reading from sensor
Wire.requestFrom(112, 2);
// step 5: receive reading from sensor
if (2 <= Wire.available()) { // if two bytes were received
Range = Wire.read(); // receive high byte (overwrites previous reading)
Range = Range << 8; // shift high byte to be high 8 bits
Range |= Wire.read(); // receive low byte as lower 8 bits
Serial.println(Range); // print the reading
}
delay(250);
}
}
Didn't change it, but my question is why he wrote the register pointers parts ?
These are my sensor commands ( try to open them on a new window for clearer image )

So, do I need to do the register parts ?
I haven't got the chance to test it. Can I improve the code? and how to write for it to measure real-time as it suggest above ?
