I2c Ezb Arduino1 Sensor

Luis Vazquez

Skip to comments

Hello all,

I wail back I posted some information on using an Arduino as a I2C Sensor controller to use with the EZB3&4

I will post this in 3 stages ..

Stage one.. right here right now.

In this video you can see how im using the arduino to read the ultrasonic sensor . that in turn is being read by the EZB board via I2C.

This is the only code needed to read the ping for the EzBuilder script


print(I2CRead(0, 2,6 ))

The code for the Arduino is



void setup()

void loop()

void requestEvent()

long duration, inches, cm;
pinMode(9, OUTPUT);// attach pin 3 to Trig
digitalWrite(9, LOW);
digitalWrite(9, HIGH);
digitalWrite(9, LOW);

pinMode (8, INPUT);//attach pin 4 to Echo
duration = pulseIn(8, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

String outtoezb;

outtoezb += "D1=";
outtoezb += inches;
outtoezb += ":";

char tempout[outtoezb.length() + 1];
outtoezb.toCharArray(tempout,outtoezb.length() + 1);

long microsecondsToInches(long microseconds)

return microseconds / 74 / 2;

long microsecondsToCentimeters(long microseconds)

return microseconds / 29 / 2;

Phase two will be adding the 3 other ping sensors and a temp sensor to the arduino .
I hope to have it all encased together will plugs and off the project board.

I will follow up on this thread as the next phase is done I will provide the code for EzBuilder as well as the arduino code.

Hope yall can use it.

By — Last update
Sorry to see you go, but will look for you post as you progress! Enjoyed you tutorials:)
Shoot me your email, if you wouldn't mind

I have learned much from your posts.
Please stay in touch, I think all of us are OPEN to learn more.
EZ Robot is the best I have found since getting back into robotics.
Best wishes,
Steve S
Hi Luis.

Thank you so much for this great tutorial! Is there any way I can send commands from the EZ-Builder / Script to an Arduino by using the I2C interface?

I already tried lots of things, including this EZ-B script:


I2CWrite(0, 2, 128)
With this Arduino code I wrote:


#include "Wire.h"

void setup() {

void loop() {
while(Wire.available()) {
char c = Wire.read();
But I don't get any characters on the Arduino and EZ-B script engine does not show any error. 

Any help would be highly appreciated!

Thank you!
You have to put the arduino in SLAVE i2c mode, not master. Slave mode uses events when data is transmitted. i2c does not work liek Serial, with an input buffer, etc... It's a totally different protocol.
Any updates for using more then 1 ping sensor?
This is a very old deprecated thread. You can use as many ping sensors as the hardware supports. The EZ-Builder software supports arduino connections directly. Check the getting started guide (link on top of this website) for information.