Colecago’s Blog » Arduino, Microprocessor, Project, Tech

Robot Luggage- My Ben Heck Experience

Back in November I won a hat from Ben Heck, the host of the Ben Heck show produced by Newark Element14 http://www.newark.com/ and http://canada.newark.com/

I went and picked the hat up in person and talked to him and his assistant Alyson, they were finishing up the latest episode of the Ben Heck show.  See here for more info

http://colecago.org/blog/?p=38

 

During the visit, it was brought up that I might be able to help on a future episode.  Well that day came February 4th.  The project was robot luggage.  We started out by brainstorming over Skype.  I had thought about this prior and this is what we decided on:

2 Ultrasonic sensors (receivers) on the luggage, 1 Ultrasonic sensor (transmitter) on the person (the target), 1 Wireless transmitter/receiver on each.  The wireless is used to initiate the remote ultrasonic ping on the target.  I thought this was the better route than using wireless RSSI on the transceivers for a few reasons;

–  We don’t know what frequencies are in use in an airport and don’t want to be interfered with

– Wireless bounces a lot and is strange sometimes how it is affected by humidity, near ground effects, etc

–  If not using RSSI and instead using Time of Flight, you’d need a very fast micro to record the distance, Ultrasonic sound travels much slower and its easier to discern a distance

 

I went to the shop the next day to do the recording.  It was a little bit weird being on camera as you can tell I didn’t do the best acting in the beginning.  It became easier and more comfortable later on.  The recording day was all rehashing the design for the camera.  We went over why we chose what parts, the mechanical design of the device, dimensional analysis for the speed and many other things.  It was about 4 hours of work for 8 minutes of video.

 

Our next recording date was several weeks later as we needed to get the parts in.  That day consisted of more of the mechanical work and testing out all the electrical components.  Ben made a preliminary wheel, we soldered wires to all of our electronics and mounted them and added batteries.  I had a lot of trouble working with the motor drives because everything needed to be sent in hex and it’s hard to find a good terminal program in windows7 that lets you do that, had I brought a windows xp computer, I could have used realterm, which is my go to terminal.  I ended up using XCTU which is digi’s terminal program, originally meant to configure the xbee chips.  It was not supported on win7 but it worked.

Also, a note on UART dyslexia, if you are designing anything with a UART interface, please, please, mark your terminals in some manner like TXOut, RXIn so we know what direction the traffic should be.  Most things are marked TX and RX but they don’t indicate if its the TX of that device or the one connecting to it, I’ve seen it both ways on modules that use UART. Here is the best quote I’ve seen on this

Before purchasing this part you need to know if you have a condition called UART dyslexia. This is a neurological disorder that will render you incapable of properly wireing this device no matter how my times you triple check the the wiring. I have this disorder and I have only found three possible solutions:
1) Find someone else without UART dyslexia to wire it up for you
2) When you get the board, immediatly scratch out the silk screen for the TX and RX pins. You will have a better chance attaching the wires at random than attemping to determine the proper connections in your screwed up head. Test the device and if it doesn’t work swap the lines. The advantage of this approach is that you didn’t spend hours trying to figure out the wrong way to wire the connections.
3) Try to figure out the proper connections and do the opposite of what you think is correct. I have had some success with this approach. -MotiveForce sparkfun comment

I got some wheels spinning and we got the wireless generically working, and that was about it for the day.  One big comment about the transistor inverter-

Originally I wanted to do a NPN inverter but I wanted the signal pulled low so it was always low if the input was floating, this required me to change to the pnp approach, I switched the arrow, but did not switch the pins of the device.  Emitter should have went to VCC and collector to the signal out/pulldown resistor.  That is why it did not work.  The arrow represents the internal diode (because of PN junctions) of the device and you can think of it as the direction the current will flow, so of course current cannot flow backwards through it and the device didn’t work.  That was a fundamental mistake on my part, not much to blame it on but nerves and working on the fly on camera.

InverterPing

(Supposedly the ping has an internal pulldown, if that is the case you should be able to remove the pulldown off the pnp transistor)

I was supposed to come up the next Saturday and Sunday, but I got pretty sick, so I sat alone in my lab all day Saturday working on code

Let me say this, I hate programming for Arduino.  It’s a great platform for hobbyists and gets people into electronics and programming.  There are a ton of boards out there and quite the following.  Most Arduinos are based on AVRs which I use all the time at work.  I figured I’d do it as an Arduino this time, and I did not enjoy it.  This is how I expected the program to work

Decide to take a reading, send out a serial wireless command to do a ping, count on a uS timer until both left and right ping received, the distance is the turn value

I couldn’t find uS timers, so I tried the next approach

Decide to take a reading, send out a serial wireless command to do a ping, do pulsein to record time for one receiver, repeat for second receiver

This didn’t work as the serial library is so bloated that variable lag was causing my values to be off 50-150uS whereas the difference values I was looking for many times were less than that. I hooked up a scope and the end point of the value was bouncing but not the difference, it must be from inconsistent serial lag to the remote sensor. Basically I had to read them both on the same wireless ping to get accurate results.

Use interrupts, I set both ping sensors on an interrupt so when they changed state, I’d check the second sensor to see if it triggered, detatch the interrupt so it doesn’t happen again before I’m ready and then when I receive the next interrupt that is my distance.

Well, that didn’t work either, I think either the arduino doesn’t like detaching an interrupt within that interrupt or just how long it takes to do a digital read (which I didn’t know yet) was causing grief.

Next try, sit in a loop that’s doing uS delays and counting up (with a timeout) and polling the pins to see when they change (because they received the ping back), then receive that, set some flags so you know which one went first and wait for the second one, then do the difference value etc.

This didn’t work either, I think because digital read takes a very long time (longer than it should). Once I changed it to read directly from the port (PINB & 0xyadayada) that approach worked.

The whole project I was struggling with arduino based problems, if I had better access to the lower level parts of the AVR, especially timing interrupts, I would have been fine. Once I got the error values working correctly, the project worked great. Next time I skip the arduino and go avr studio and straight c.  Once I got the terminal result below, I went to bed

 

Error: -26
Direction: Left
Error Sum: -262
Error Correction -9.12

Error: -17
Direction: Left
Error Sum: -490
Error Correction -9.15

Error: -13
Direction: Left
Error Sum: -503
Error Correction -8.28

Error: -10
Direction: Left
Error Sum: -513
Error Correction -7.63

Error: -2
Direction: Left
Error Sum: -558
Error Correction -6.08

Error: 1
Direction: Right
Error Sum: 1
Error Correction 0.26

Error: 5
Direction: Right
Error Sum: 10
Error Correction 1.35

Error: 9
Direction: Right
Error Sum: 19
Error Correction 2.44

Error: 18
Direction: Right
Error Sum: 90
Error Correction 5.40

Error: 23
Direction: Right
Error Sum: 113
Error Correction 6.88

Error: 28
Direction: Right
Error Sum: 141
Error Correction 8.41

I was moving the target from left to right in front of the receivers, Error was the difference between the left and right times, Direction was which direction to turn, Error sum is basically the integral term before weighting, correction was what to add to the turn value.

The next day I showed up with my own box of kleenex, hand sanitizer, and trash bag as to not infect Ben and we went to work.  We got everything installed, Ben finished the 3rd leg and handle and I changed the code so it would send the turn value to the motor controllers.  Off the bat, it worked pretty well, had to do tweaking but I was surprised at how well it worked increasing and decreasing the separate wheel speeds based on location of the target.  I added a distance timeout for too close and too far, tweaked the P and I weights, and added flashing lights for status.  We tried a smaller battery pack but it died pretty short into it so we went back to the huge lead-acid batteries.  We got it following well and then I left.  Ben and Alyson finished closing up the front, added some decoration, and finished the taping.  All and all, it was an awesome experience, I had followed Ben’s work on HaD and it was a once in a lifetime experience to work with him, I hope I get to work with him more in the future.

Watch the full video below

 

 

Here is a little bit longer explanation of the program flow

Functions:
Setup()
Loop()
doPingDiff()
setToZero()
updateDrives()

Powerup
Setup-
Set up the 3 serial ports
Serial is for debug at 9600
Serial1 is for motor control at 38400 and 2 stop bits!
Serial2 is for zigbee for remote ping
Set up leds
Send some commands to motor control

Main
Loop-
Clear out important variables like difference and distance
See if handle switch is in disabled position
Flash status LED
If Not Disabled;        Do 4 pings and average difference result and distance result
If too close to person (based on distance); disable
If Difference looks good and not disabled; update the drives and
clear timeout; else increase timeout
If timeout counter is too high, disable
If disabled; set the drives to zero and blink lights

doPingDiff-
Do the high low thing to start both receivers
Send Zigbee start command
Wait for either left or right sensor to go to zero or timeout; record
that setpoint
Wait for second sensor to go to zero or timeout; record that setpoint
and break loop
Calculate the difference by subtracting
Calculate the distance by adding both values and dividing by 10 (for
scaling speed)
Return the difference (which is our error)

updateDrives-
Calculate the direction of the error (basically left or right turn)
If direction has changed, clear out the error sum (integral part of PI Loop)
Add Error to the Error Sum
Calculate turn value by doing Kp*error + Ki*errorSum where Kp and Ki
are set to 0.5 and 0.25 respectively and then add to 128 which is our
Zero
Calculate the speed by taking our above distance divided by two, then
subtract from 128 because forward is 0-128 (with 0 being max allowed)
Make sure turn isn’t greater than 250 or less than 5 (preventing
overflow or underflow)
Make sure speed isn’t less than 5 (preventing an underflow)
If Debug is set output all of these numbers through the Serial port as well

setToZero-
Set speed and turn to 128 (bidirectional data around 128, 0 is max
one way 255 is max other way

I’ve also attached the code for download.  I’ts a .c file, but is actually the .ino, wordpress doesn’t like .ino files so just rename it to something.ino

Robot C Code

 

I don’t have the dimensions of the luggage, but here is a build list of the electronics:

Motors and controller- http://www.robotshop.com/drive-system-12-volt.html

Microprocessor board (brains)- http://www.sparkfun.com/products/10744

Ultrasonic Sensors (x3)- http://www.parallax.com/tabid/768/ProductID/92/Default.aspx

Wireless Boards (x2) – http://www.sparkfun.com/products/10414

Power Convertor – Don’t remember, it was some off the shelf Buck Switch Mode powersupply with 5V output

238 thoughts on “Robot Luggage- My Ben Heck Experience

  1. Good Day,
    Thank you so much for posting this project, I’m working on a similar system that works with the same concept. I’m fixing up a golf cart to follow me around the golf course. I have all the electronics(motor controller, batteries, ping sensors, xbee’s and arduino) ready to go. I’m having one hurtle I was hoping you could shed some light on. I’ve tried using some of your code you posted but I’m a little confused with the serial1 and serial2, are these strictly for motor control and xbee trigger? and if so how do I use just the serial2 for the xbee trigger? I’ve tried compiling the code and get this error I’ve pasted below.

    [ Robo_luggage.ino: In function ‘void setup()’:
    Robo_luggage:74: error: ‘Serial1’ was not declared in this scope
    Robo_luggage:75: error: ‘Serial2’ was not declared in this scope
    Robo_luggage.ino: In function ‘long int doPingDiff()’:
    Robo_luggage:182: error: ‘Serial2’ was not declared in this scope
    Robo_luggage:212: error: ‘PINE’ was not declared in this scope
    Robo_luggage:216: error: ‘PINE’ was not declared in this scope
    Robo_luggage.ino: In function ‘void setToZero()’:
    Robo_luggage:234: error: ‘Serial1’ was not declared in this scope
    Robo_luggage.ino: In function ‘void updateDrives(long int, long int)’:
    Robo_luggage:272: error: ‘Serial1’ was not declared in this scope]

    Could you please shed some light on this and maybe explain what I might be able to do to get the code to compile as well as use the serial2 function?

    Thank you in advance for your time and considertion
    Dave Pina

    • My guess is that you aren’t using the same Arduino. We used the Mega Pro 3.3V. It had 3-4 serial ports and a IO’s on PORTE. Serial was the computer port (for debugging and programming), Serial1 was the motor control board and Serial2 was the Zigbee.

    • Hi Dave,

      Your project sounds interesting to me. I am retired now, though I was major in digital electronics. Yet 30 years in management distant me from toying with them. I would love to put this pet project into my garage.

      If you were successful into getting this done, can you shoot me your parts list, and schematics?

      Really appreciated.

      • Ben’s show is more about proof of concepts, never full production ready ideas. We did make this and it worked pretty well. If I would do it again I’d probably go completely wireless, I was worried about interference and such but I think it would be less of an issue than I thought.

        No schematics, it was a short time build and we don’t really make schematics for the show. A partial parts list is at the bottom of the post.

        • Thank you for your reply. What do you mean by “go with completely wireless”? Which technology will you implement? Also my question is if there are two such luggage next to each other, how will the robot know which one to follow? Perhaps that’s the other reason that you were thinking of changing the hand shaking technology?

          • Currently the luggage sends out a wireless signal to tell the target to start an ultrasonic ping, then it listens for pings and figures out which ear received it first to determine a left or right correction, also because it initiated the ping it knows approximately the distance away. In the future I might build one with 3 antennas and maybe use RSSI to track, I’m not sure how well that will work though. I could do time of flight but that would require a much faster control loop because the radio waves propagate much faster than sound.

            Right now there is no way for it to discern one target from another, it just follows the ultrasonic signal. This was a proof of concept for Ben’s show only and never meant to turn into a real product.

  2. Hi there,
    I would like to get further explanation from you on how to make the 2 ping sensors communicate with each other. For now, we managed to transmit pulses from one ping sensor (A) but the other ping sensor (B) isn’t able to receive the pulses from sensor (A). Hope to get a reply from you soon. Thank you.

    • You need to enable them around the same time. Basically I sent a wireless signal telling Sensor A to start its Ping, then I toggled the line for Sensor B to start it’s ping and made sure that the Ping Sensor B saw was the Ping from Sensor A. They both need their sensor lines toggled around the same time to begin the Ping sequence.

      • Hi, thanks for the reply. From your explanation, that means ping sensor A and ping sensor B are sending out pulses at the same time pulsing each other? Or can I make it in such a way that Ping sensor A is programmed just to transmit and ping sensor B is programmed just to receive pulses from ping sensor B? Thank you.

        • You can start the PING process, but I don’t think you can stop them from sending and receiving without removing their sending and receiving cones. That’s the good part about the PING sensors, they have definitive send and receive pieces so you can remove send on the receiver and receive on the sender, though the receive on the sender isn’t really a big deal. Also it might not matter much to remove the sender on the receiver, because the first PING it receives back are likely from the target and not its own reflected PINGS, meaning it will ignore its own returning PINGs in favor of the first responses it gets from the target.

  3. Hi, I intend to built a luggage robot for a higher weight (up to 50 kg). What components (motor, motor control etc.) would you suggest for this application?

    • Not really sure, maybe look into electric wheelchair motors? As for control, you might be able to use the controller on board with those, otherwise look for motor drives, hopefully with encoder feedback, that can handle the load of those motors.

  4. Good Day!!
    You folks gave me some great info. a few months ago and since then I’ve been working on a robo caddy that can follow me around the golf course. So far so good, how ever there is one obstacle I need to over come. This is the drive motors, I understand you used motors with feedback encoder. I assume the encoder on the drive motors is required in order to work properly. I’m implementing much larger motors to drive the robo caddy around the golf course. Would it be wise to use an encoder with these larger motors or can the code work without an encoder? I’m currently using a Sabertooth 2×25 motor driver that communicates via serial or PWM. Is it possible to use this motor driver without an encoder or am I chasing the impossible?

    Thank you again for your time!!
    Dave Pina

    • The PI loop is created with the dual drive motors in mind. If you were going to go encoderless you run the risk of not actually knowing how fast your drive tires are and drifting left or right or not being able to steer properly. If you had to go encoderless you are probably better off losing tank-like two drive wheel system and do something more like a separate drive system and steer system (like traditional vehicles use).

  5. Hello,
    I am trying to build a robot follower with the sensing part based on the idea you guys were doing here. I have a question about removing the emitter cones on the Ping attached to the robot. How did you do it? Did you just simply cut the cones out of the sensor?
    Thank you,

  6. hello^^
    im korean, can i request to you difficult one thing
    at first i should say to you sorry
    i am a student in south korea
    i go to university also i have so many classes
    but one of them is to make wheelcheir that can follow a service dog
    so i wanna know how could you make this luggage
    so could i see your programming source?
    i will never use for anything except for my class
    thank you

  7. hi… im currently doing my undergrad. design,, pertaining to human following cart,. i just want to know the connection of your xbee to arduino and the connection of xbee in the transmitter side..

    can u send me the schematic diagram of your circuit???

    tnx in advance..

    • I don’t have a schematic sorry. Zigbee transmitter was powered from 3.3V and just the Tx of the Arduino was tied to the input of the Zigbee. On the receiver side the Zigbee was again powered from 3.3V and the output line was put through an inverter before going to the Ping sensor.

  8. tnx so much for the reply sir.. is the schematic of the inverter,, above is correct? then wat kind of transistor did you use for the inverter??

    and one more thing that i just want to confirm is,… did you used arduino on the transmitter side? i mean,, the ping sensor that will put to the user??

    may i ask to you to provide me just a sketch on how did you connect the xbee to the pin of the ping sensor?

  9. pls… give me some light sir on the connection… i need to finish may design this coming march,,, and your project is the one that i used for the guide on building my prototype…

    i really need your help sir…..

    your information that you will give to me will be appreciated…

  10. thank you very much for the quick responce sir… i will visit now the site yoy gave,,, and i’ll come back here if there something need to confirm to you… thanks again sir… 🙂

  11. hi sir,, im here again,,, i just wanna ask if what is the configuration of xbee..? did you configure it using XCTU software?? sorry im juzt a newbie in xbee…

  12. gud day sir,, is there any way to communicate the ultrasonic reciever and transmitter with out using xbee?

    there is a xbee here in my country but but the price is too expensive..

    can i use the circuit of ultrasonic beacon instead?

    • Yeah looking back on it, I could have done it better in a few ways. In the end all that matters is the difference in times, so you could set up the target to just auto beacon and then listen with the other two and just use the difference between them. In the end that’s all I ended up using, I just knew when to start listening because I initiated the sequence with the wireless. You will have to work out sync issues, and the pings timeout after a bit, but it can be done without any wireless at all. Heck you could time them by just turning them on at the same time or maybe an output on the robot you plug into to tell the target to start and then they just stay in sync after that. Lots of possibilities.

  13. sir,, what if i use another arduino board on the transmitter side the program the ping sensor to initialize or trigger if there is an ultrasonic sound recieve from the reciever side? is it possible? what do you think sir?

    • Yeah, its like I was saying. One side, the target we’ll call it, just sends out pings at regular intervals. You can do this with an Arduino on that side, or you could use a 555 timer. On the robot you still have the 2 ears and an Arduino to decode the times between interrupts. The only problem you’ll run into is syncing up, the pings have a time out period, so maybe you get clever with the start up routines on both ends to get into sync.

  14. Great job!I am planning to doing this for my final year project.
    But i have a question here,i dun want to use the handle as a switch,(a lot of mechanical work to complete that handle)so what can i use?

  15. I would like to do this project with much lower level skill. I just want to make a model of what a real one might look like. Therefore, I am using cheaper parts such as simple DC motors and off brand Ping sensors(4 pin with an echo and trig). I am also trying to make the code very simple. My setup is 2 Ping sensors, 2 motors, and an Arduino on the luggage part and 1 Ping sensor with an Arduino on what the human would wear.
    My Luggage Code:

    const int motorPin1 = 9;
    const int motorPin2 = 10;
    const int echoPin1 = 11;
    const int echoPin2 = 12;

    void setup(){
    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(echoPin1, INPUT);
    pinMode(echoPin2, INPUT);
    }

    void loop(){

    long duration1, duration2, cm1, cm2;

    duration1 = pulseIn(echoPin1, HIGH);
    duration2 = pulseIn(echoPin2, HIGH);

    cm1 = microsecondsToCentimeters(duration1);
    cm2 = microsecondsToCentimeters(duration2);

    if (cm1 < cm2)
    {
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
    }

    if (cm2 < cm1)
    {
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin1, HIGH);
    }

    if (cm1 == cm2)
    {
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, HIGH);
    }

    delay(100);
    }

    long microsecondsToCentimeters(long microseconds)
    {
    return microseconds / 29;
    }
    My Transmitter Code:

    const int trigPin = 12;

    void setup(){
    pinMode(trigPin, OUTPUT);
    }

    void loop(){
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(5);
    digitalWrite(trigPin, LOW);
    delay(100);
    }
    As you can see they are very simple and since I do not have all the parts yet, I just want to know if my code will work. Thanks in advance!

    • I don’t think this will work well for a few reasons, you aren’t synced with your transmitter and using PulseIN which is a blocking command, thus the ear for distance2 won’t be heard until distance1 is finished, thus sometimes distance2 will be the difference between distance1 and distance2 and sometimes it will be the echo of a second ping if it was ignored because it happened during distance1. That’s why I couldn’t use those in my code, I did try them. You an go with can unsynced transmitter, but you will have to be listening to both ears at the same time like I did.

      Also, you aren’t using any analog control, basically you are full on or full off with your motors, so you go ahead full speed forward, if one distance is greater you stop and go full on with one motor but not the other until they are equal. When you get code that gives you good distances, the motor control will basically make your robot oscillate back and forth pretty heavily. I would do some type of PWM motor control, so analogwrite instead of digitalwrite. Your turn values are way too aggressive, I would do some scaling based off of how different the left and right ears are similar to what I did.

      Good Luck!

      • So to fix the first problem you mentioned, what can I use instead of pulseIn. I looked through your code but could not find the solution.

        To fix the second problem, you suggest that I do softer turns such as analogWrite(motorPin1, 255) analogWrite(motorPin2, 150) for example to not be so abrupt. Also, you say to only make it turn if there is a major difference between the 2 sensors. How would I go about doing this.

        By the way, I am very impressed that you still help people months after the Ben heck episode. Thank you so much!

        • If you look through my code at pingdiff that basically finds the difference between them by listening to both of them, here is the pseudo code

          doPingDiff-
          Do the high low thing to start both receivers
          Send Zigbee start command
          Wait for either left or right sensor to go to zero or timeout; record
          that setpoint
          Wait for second sensor to go to zero or timeout; record that setpoint
          and break loop
          Calculate the difference by subtracting
          Calculate the distance by adding both values and dividing by 10 (for
          scaling speed)
          Return the difference (which is our error)

          Not sure how well this will work with your setup, but its worth a try.

          You can either use a set turn value like you said with 255 and 150, play with the values for stability, or you can base it off of the difference. Like analogwrite(255-difference/5) type of thing.

          Also, make sure to use a transistor on the output of the arduino, don’t run the motor directly from it. I recommend a MOSFET with a pulldown resistor, also make sure to use a flyback diode, a setup like this
          http://www.nerdkits.com/videos/motors_and_microcontrollers_101/

          Or use this kit like I used on the glue gun episode (I did the hardware and software for that)
          https://www.sparkfun.com/products/315

          Still use your pull-down resistors on the control lines.

          • I am using the transistors, diodes, and resistors for both motors so that is taken care of.

            In your actual code under doPingDiff you have:
            pinMode(pingPin1, OUTPUT);
            pinMode(pingPin2, OUTPUT);
            digitalWrite(pingPin1, LOW);
            digitalWrite(pingPin2, LOW);
            delayMicroseconds(2);
            digitalWrite(pingPin1, HIGH);
            digitalWrite(pingPin2, HIGH);
            delayMicroseconds(5);
            digitalWrite(pingPin1, LOW);
            digitalWrite(pingPin2, LOW);
            Isn’t this the code used to send out a Ping? I do not understand the use of this because the actual luggage does not transmit at all. Once you set the Pings back as in INPUT, I still do not see any code that will actually receive an ultrasonic pulse.

            Also, your (PINE & 0x10) == 0) and (PINE & 0x20) == 0) are giving me a bunch of errors.

            Hopefully this is my last comment. I am sorry for bothering you on a Sunday.

          • My sensor uses the same pins to send and receive so I had to start a ping sequence for it to get into receiving mode where it stayed high until receiving an echo, the part you will need is more this part

            // The same pin is used to read the signal from the PING))): a HIGH
            // pulse whose duration is the time (in microseconds) from the sending
            // of the ping to the reception of its echo off of an object.
            pinMode(pingPin1, INPUT);
            pinMode(pingPin2, INPUT);

            delayMicroseconds(900);

            oneFire = false;
            twoFire = false;
            finished = false;
            setPoint1 = 0;
            setPoint2 = 0;
            difference = 0;

            while ((oneFire == 0) || (twoFire == 0)){
            if (((PINE & 0x10) == 0) && !oneFire){
            oneFire = true;
            setPoint1 = timeout;
            }
            if (((PINE & 0x20) == 0) && !twoFire){
            twoFire = true;
            setPoint2 = timeout;
            }
            delayMicroseconds(1);
            timeout++;
            if (timeout > 19000)
            break;
            }

            difference = setPoint1 - setPoint2;
            distance = (setPoint1 + setPoint2)/10;

            digitalWrite(13, LOW);
            return difference;
            }

            Your Arduino probably doesn’t have a PORTE, I was using an Arduino Mega

  16. One last thing. You say that I can use an unsynced transmitter. Does this affect any of my code or when I turn on the units? Meaning, do I have to turn both units on at the same time or does that matter?

    • Possibly. It depends on how your sensors work. The ones I used you did a sequence and then it started and would time out after a time. If yours do the same you could get out of sync. You might want to do a delay of some type on your readings so after a reading you don’t read for x mS so you aren’t just idling in your listening loop because you got out of sync of your transmitter.

      • I have been experimenting for a while now and have not found a solution. By now I have stopped trying with the motors and am focusing on the sensors. I still have not been able to have the transmitter be detected by the receivers. I have tried using the NewPing library and that has not worked. I posted on the Arduino Forums asking how to receive a ping on the hc-sr04 without pulseIn and all I got was “The PulseIn is blocking, it polls until line is changed.
        you should think of a rewrite of pulseIn() using pinchange interrupts.
        Not trivial but doable.” Any idea what this means or any further advice?

        • Did you try this code, replacing the PINE stuff with the echo pins of your sensors?
          oneFire = false;
          twoFire = false;
          finished = false;
          setPoint1 = 0;
          setPoint2 = 0;
          difference = 0;

          while ((oneFire == 0) || (twoFire == 0)){
          if (((PINE & 0x10) == 0) && !oneFire){
          oneFire = true;
          setPoint1 = timeout;
          }
          if (((PINE & 0x20) == 0) && !twoFire){
          twoFire = true;
          setPoint2 = timeout;
          }
          delayMicroseconds(1);
          timeout++;
          if (timeout > 19000)
          break;
          }

          difference = setPoint1 - setPoint2;

  17. I replaced the PINE & 0x10 with my echoPin1 (7) and PINE & 0x10 with my echoPin2 (6) and nothing else. Just to troubleshoot I had Serial.println(difference); and all I got was 0 when I pointed the transmitter at it. I feel like I am missing something. Was I not supposed to replace those with echoPin1 and echoPin2? As you can tell I am very inexperienced and would like to thank you again for helping me.

    • I have done some researching on port manipulation and have found that I can use it on an Arduino Uno. I just have to use PINB instead of PINE because my sensors are plugged into 6 and 7. When I replace your PINE with PIND I get no errors but still do not get any results. I think this is because of it not being synchronized. So unless you think otherwise my main problem now is a way to synchronize. Instead of using Xbee, couldn’t I just have an infrared led on the robot and an infrared sensor on the human that could communicate. Therefore I could be synchronized better. I have both of these parts available to me and it would not be that hard to get it to work I don’t think

      • Yeah, that would be a start. Maybe you should just try a singe sensor with limited code just to see how it works. I’m guessing that you need to start a ping for it to get into receive mode, so you are getting nothing because you are never in receive mode to receive a ping. Then after you are getting good results from a single one reflecting, remove its transmitter can and use a second sensor to see if you can hear the second sensor’s pings (you still need to initiate a ping with the first sensor). Watch in the video and that is what we do. One step at a time.

          • I don’t understand the question. Are you talking about the Zigbees? Or just the ultrasonic sensors in general? I always suggest look up the example for the ping sensors and start with just that to make sure both sides are working and without the wireless link, then work your way up in the design.

  18. In your PINE & 0x10 and PINE & 0x20 I know that PIN is a way of quickly reading the state of a pin. I also looked up that 0x10 = 16 and 0x20 = 32. Could you explain to me what these do. My setup is obviously different than yours so if I knew what they did, then I could probably figure out how to modify them for my setup. Also, I got 2 sensors to actually talk to each other so that is good. But that was using pulseIn which will not work in the final product so I need to learn how to use PIN.

    • Yeah, I’m going to write a post about that soon but haven’t gotten around to it yet, I’ll give you the short version. I frequently break out in hex, if you write that number in binary it will line up with certain bits with the port, its called masking. Instead of doing that, you can try putting this at the top of your Arduino file

      #define BIT(x) (1 < < (x)) /* How to Use PORTA |= BIT(0); //ON PORTA &= ~BIT(0); //OFF PORTA ^= BIT(0); //TOGGLE if (PORTA & BIT(0)) //Read pin 0 */ #define SETBIT(p,b) (p) |= BIT(b) #define CLRBIT(p,b) (p) &= ~BIT(b) #define TGLBIT(p,b) (p) ^= BIT(b) /* How to Use SETBIT(PORTA,0); CLRBIT(PORTA,0); TGLBIT(PORTA,0); */

      Remember Arduino doesn't mark its pins by the bit number, they number them 1-20 or whatever, you will need to look at the schematic to see what pin of the port it actually is.

      *Note, you might need to use
      if (PINA & BIT(0))
      not sure if PORTA works there because its using as an input, try both ways, I think I've used PORTA when reading before and it worked but don't remember.

    • No, you are interested in the PD6 and PD7, those are bits 6 and 7 of PORTD. Just like Arduino output 9 is actually PORTB bit 1.

      So to read 6 you would do
      if (PORTD & BIT(6)){
      //code here
      }

      Make sure to put that code I have in the previous post (with the #defines) at the top of your file. Also if it doesn’t work for some reason, try PIND instead of PORTD . PIND denotes input but I think it will work with PORT as well in that code.

  19. For troubleshooting purposes I put:
    if (PORTD & BIT(5)){
    Serial.println(“5 pin received”);
    }
    if (PORTD & BIT(6)){
    Serial.println(“6 pin received”);
    }
    and got this error for both lines of the if statements: “expected primary-expression before ‘<' token."
    I did put the #define stuff at the top of the page so that is not the problem. Also, in you doPingDiff receiving code, can I just replace PINE & 0x10 with PORTD & BIT(5) and PINE & 0x20 with PORTD & BIT(6) for example?

  20. Not sure what your error is, I don’t even see a ‘< ' character in there. I did notice when I copied and pasted your code, it didn't work, gave me some other error though, the problem lied in the quotes, they didn't copy over correctly, they were a different character that looked very similar, strange. Maybe your problem is arriving from a similar situation and copying my code from above. I'll upload a text file with my header up there. As for replacing the code, yeah you should be able to, and I just checked, PORTD & BIT(5) does work, it doesn't have to be PIND. You might also want to replace my digital writes with SETBIT(PORTD,5) and CLRBIT(PORTD,5) instead as it is faster and should allow for less inherent difference when you start the ping process. Alternatively if you want to blow your mind, you can do both at once with PORTD |= 0x60; to set them and PORTD &= ~0x60; to clear them (bit header in txt file) http://colecago.org/blog/?attachment_id=341

  21. Thanks you so much! I am actually getting results and the whole project is semi functional. When I have the transmitter on the right side of the receivers, it gives me a negative number and on the left side gives me a positive number although there are many 0’s in between. I added this and quickly got the motors moving how I wanted them to:
    if (difference 0){
    right();
    }
    But when I add this:
    if (difference == 0){
    halt();
    }
    The motors get all choppy(on and off continuously). My goal is just to have the motors not move when the receivers are not receiving a ping. Any ideas? Also, I noticed that when the sensors are basically pointing at each other exactly straight, I get numbers close to 0 such as -4 and 4. Is there any way to have an if statement that will use this data to make the luggage go forward?

    • You should try and write your code to tell the difference between 0 difference and a timeout, then increment a counter or something for number of timeouts and after a specific amount, stop moving, but if you get a good signal, reset the counter. As for motor code, just for something simple, you can try


      Max = 255;
      if (difference >= 10){
      motorRight = Max - 25;
      motorLeft = Max;
      }
      else if (difference < = -10){ motorRight = Max; motorLeft = Max - 25; } else{ motorRight = Max; motorLeft = Max; } if (timedOut){ motorRight = 0; motorLeft = 0; }

      Just an architecture, modify it to match your code and play with values, also not sure how well the Arduino compiler compares negative numbers. In the end, it would be better to have something like a PI loop, or even just a proportional difference in your motor adjustments, something like motorRight = Max - difference/10; but that is a little more advanced as it might need dampening, could be prone to oscillation, etc.

    • Hi Frank, It seems that I am having the same issue as yours. What is your final code which syncs up the emitter and the receiver? Thank you.

  22. For timeout code, I thought this would be easy and work well:
    if (difference == 0){
    counter++;
    }
    if (counter == 10){
    halt();
    }
    Every time difference was equal to 0, 1 would be added to counter and when there were ten 0’s in row the motors would shut off. I also set in all my other if statements that if difference isn’t equal to 0, then counter would be reset to 0. I have done some researching and can not figure out why this does not work. Once this is done, all the programming will be finished.

    • I don’t think I would use the difference of 0 to calculate timeout, if both ears hear it at the exact same time, then it will result in a difference of 0. I don’t know how your sensors work, but mine had a max number they would just return after even with no signal. I think I had timeout close to that, I had that counter going in the loop and if I counted up high enough I just said there was a timeout and broke out of the loop. Try something similar.

  23. Can anyone of you give me a parts list for the Xbee inverter. I have been away from digital electronics for too long.

    Much obliged with thanks.

    • The inverter in the show we used was a standard 74HC04 series inverter. We could have used a PNP transistor, but I had drawn it up wrong on camera, I have a correct drawing of it in the post. The Zigbee is in the parts list at the bottom of the post.

  24. Hi there
    I was thinking of using a RF receiver to trigger a 555 timer which will then trigger the ping sensor, I see the hc-sro4 sensor needs 10us to trigger it, does that have to be exact timing or can it be a little more or less?

    Thanks

      • I wanted to add it because I wasnt getting any readings when the rf was connected straight to the sensor with the echo and trig pin bridged , but today i got readings when i only connected the rf straight to the trig pin on the sensor but now its giving 1 reading of 330cm even if I pull the trig sensor further away or closer, but if i point the trig sensor away from the receiver it gives readings of 6987cm and if I point it at the receiver again it goes back to 330cm, any ideas?

        Thanks

  25. Dude,
    I am starting to build this project and I ordered the arduino mega board (3.3volt), 2 wireless XBee devices (3.3v), 3 ultrasonic devices (5v).

    The Arduino Mega board will have a XBee for transmitting a wireless ping to the hand held board. It will have two ultrasonic receivers for receiving the signal from the handhel remote.

    The handheld remote will have a XBee receiver and a ultrasontic transmitter.

    The operation will be:
    1. The Arduino will send a signal to Transmit Xbee which will send a signal to the Rx Xbee on the handheld.
    2. The Rx Xbee on the handheld will tell the ultrasonic transmitter on the handheld to send a ping out will send a ping response
    3. The ultrasonic receiver on the mother board will receive the ping on both ultrasonic receivers and calculate which came first.

    Questions:
    1. Does the handheld require a micro to take the output of the XBee Receiver and create a pulse for the Ultrasonic Transmitter? If not what is the glue logic between the XBee Receiver and the Ultrasonic Transmitter on the handheld board?
    2. Using your code I am trying to trace the software controls to the actual arduino pins. However some of your pin numbers in your code do not seem to match the hardware is this the latest working code?
    thanks

    • Yeah, didn’t notice the comments didn’t match, probably wrote the comments before the code was finished while I was trying to get interrupts and stuff to work. Just go by what the code says for IO assignments unless you run into problems.

      As for the transmitter, I discussed it a little bit in the episode and the post, we used an inverter from the dataout pin of xbee to trigger the ultrasonic target. I think you can get away with using a pnp logic inverter as shown in the schematic near the top of the post.

      Good Luck!

      • Thanks for getting back to me. I think its great that you are taking the time to following up with peoples questions regarding this project. Very few people would take the time to do it and I know that we appreciate it! Thank you

  26. I want to use the Devantech motor driver with my own motors without the encoder wires hookup. Would your codes still work?

    I prefer to use the sabertooth motor drivers. Can you or anyone please convert those devantech turn commands into those analog write commands? Thank you Colecago and everyone.

    • The only problem with using encoderless drives is you can’t control the inherit drift that can be caused by slightly different speeds causing drift, which isn’t that big of an issue I guess because this is supposed to correct itself based on what its following.

      For using analog drives you can do something like
      analogWrite(pin1, speed + turn/2);
      analogWrite(pin2, speed – turn/2);

      Now you’ll have to do some bound checking to make sure you aren’t overflowing or underflowing the value. There are better ways, like if you would overflow instead subtracting the extra amount from the other wheel, and doing something similar with underflow, but the above code is pretty basic and is a good start.

      • I did not see that you used the motor encoder commands, 0x23 and 0x24, in your codes so are you using the encoders in your Devantech motors in your setup? Thank you for the quick response.

  27. Hi there,

    I am really new at using xbees. Which configuration did you use for xbees. Can you explain clearly please. (AT, API, router, coordinator settings etc)

  28. Hello,thank you for this post! My question: can I use Arduino uno instead of Mega pro and use US-020 or HC-SR04 instead of Ping))), is it possible?

  29. Hello Innovator,

    Does cutting the cap of HC-SR04 will improve the sense angle of UltraSonic sensor?
    Is it possible to remove the cap of ultrasonic receiver carried by the target person, coz as u mentioned in the video that it will block some waves.
    Doesn’t it get harm?

    Kindly resolve my doubt 🙂

    • Yes you can, make sure to do the transmitter can on the target as the receiver doesn’t do anything. I think it will work better because it will see the target better, also it might be less likely to follow bounce signals if a signal shooting out the side gets to it instead. Let me know how it works for you.

      • Hello after long time,

        Yup it works great. But the problem is that ultrasonic sensor (HCSR04) is printing garbage values even the receiver didn’t receive any ping from transmitter.

        Kindly hep me out.

        • I’m not familiar with that exact sensor. My advice to look up example sketches with just that sensor and get the sensor working well before you move on to the whole system.

          • hi, how do you fix your problem with the 2 ultrasonic receivers? Because I’m having the same trouble as you are.

            Thanks

        • hi, how do you fix your problem with the 2 ultrasonic receivers? Because I’m having the same trouble as you are.

          When I tried to read the measurement from 1 ultrasonic receiver, the result is very good. But when I try to read 2 ultrasonic receivers at the same time, everything is messed up.

          Thanks

          • You have to listen for both at the same time, which doesn’t allow you to use things like PulseIN, see the code explanation above and the code provided.

    • The code is linked at the bottom of the post. It was written for a Mega but you should be able to convert it to work with an Uno just fine. Look at some of the comments above where someone was converting to an Uno.

      • Im new in arduino and im confused how to convert it in uno . and also confuse what pin im really use for the sensor, motor and xbee

        sorry for my english

        • If you look in the code at the top I give the different pins used for the sensors and the controls.

          /*******************************************
          Robot Luggage First Attempt
          IO List:
          Signal – Arduino Pin
          Ping Sensor 1
          +5V – Vin
          Sig – Pin7
          GND – GND
          Ping Sensor 2
          +5V – Vin
          Sig – Pin4
          GND – GND
          ZBee
          3.3V – 3.3V
          RX – RX2 (optional)
          TX – TX2
          GND – GND
          Motor Control
          RX – RX1
          TX – TX1
          GND – GND
          Prog/Debug
          RX – RX0
          TX – TX0
          StatusLED – Pin13
          ******************************************/

          It’s not a great project for someone new to this kinda thing as besides the normal Arduino stuff I also do some low level port manipulation like ((PINE & 0x20) == 0) to check the sensor pins. Besides adjusting the pins here

          const int pingPin1 = 2;
          const int pingPin2 = 3;
          const int ledPin = 4;
          const int switchPin = 5;

          You’ll have to adjust the lines that say PINE with the port and pins you are using because I don’t think the Uno has a port E on it. Also it doesn’t have 3 serial ports so you’d have to adjust the serial ports for whatever ones you decide to use. I highly recommend you get some more experience in Arduino before diving into this project.

    • Thanks for the update! With all the people that have contacted me through the website or email, you are the first to post actually finishing a project based on Robot Luggage. Congrats on the hard work and success!

  30. Hi! Great project and loving the results!

    Can you tell me the meaning of this from your code? I can’t seem to find proper explanation from the pseudocode nor googling.

    ” Serial1.write(null0);
    Serial1.write(0x33);
    Serial1.write(3);
    delay(10);

    Serial1.write(null0);
    Serial1.write(0x34);
    Serial1.write(0x02);
    delay(10);

    Serial1.write(null0);
    Serial1.write(0x32);
    Serial1.write(turn);
    delay(10);

    Serial1.write(null0);
    Serial1.write(0x31);
    Serial1.write(newSpeed); ”

    Can you tell me what does it mean?

    Thank’s a lot!

    • Hmm, it’s been awhile.

      It looks like I was setting the acceleration to 3, then setting the mode to 2 which is speed/turn, then setting the turn value and the overall speed values. Looking back on it, I could have just sent the acceleration and mode at the beginning and not done it every time I sent a new speed and turn. Not sure what I was thinking at the time, it was a quick project so its possible it was needed at some point and the code that it was offsetting was removed. I’m sure the first two serial blocks there could be added to a startup and then never sent again.

  31. Hi,

    I understand that this project was a fair while ago now, but do you have any tips on working with these motor drives? I’m building a version of this luggage for a college project and I’m not too great with hex!

    Also, is that a basic FTDI breakout board you used to control the motor drives in the video?

    Thanks,

    Matt

  32. Two xBee series1 on 2 different Explorers are talking to each other while running X-CTU.

    When I exit X-CTU on one of them, it doesn’t receive and only the power led and the RSSI led are on. The xBee still running X-CTU can still transmit confirmed by the led blinking.

    When I mounted the xBee on to the luggage side, it can also transmit but the xBee on the receiver (on the Ping transmitter side) is not receiving. I double checked everything and even switched all those xBee configurations and xBees, and realized that the receiving xBee will only receive if I connected to the pc and running X-CTU.

    My switchPin is wired correctly btw. When I wave my hand over the Ping sensors on the luggage, the RSSI led on the xBee sitting on the Explorer not running X-CTU blinks in accordance to the waving. I had left the Ping transmitter cones on luggage side for testing purposes).

    My belt clip transmitter circuit has the Ping sensor led off because the xBee is waiting for signal to come from the xBee the DO. I double checked my circuits and think that it is either
    a) the xBee configurations or b) the Arduino codes ( had changed the series2 baud rate to 57600).

    Current hw: Mega 2560, xBee series1, Parallax Pings, correct voltage supplies and logic inverter, and the xBees in AT mode and working under X-CTU. Please help anyone? Thanks again.

  33. Hello Mr. Colecago and Mr. Heck again,
    pinMode(13, 1); 1?
    digitalWrite(13, 1);
    digitalWrite(13, 0); 0?
    pinMode(13, OUTPUT);

    if (disabled){
    //digitalWrite(ledPin,HIGH);
    blinkTimer++;

    //if (blinkTimer < 10000)
    //digitalWrite(ledPin,LOW);
    Should I uncomment those code lines? I do not think that these caused my xBee TX RX problems mentioned before. Thanks again.

  34. My error stating the led on Parallax Ping sensor on my belt clip circuit is off. In fact it is on all the time and not blinking. Waving my hand over on the luggage Ping sensors made no changes to the belt clip Ping led. Those Ping sensors on the luggage are blinking and the xBee are transmitting confirmed by serial2 activity led. Also above I mentioned series 2 AT mode. I meant Serial2 AT mode (using xBee Series 1 units). Is the problem on TX or RX side? No UART dyslexia here. I know how to wire up the Serial2 on the luggage side and the DO going to the inverter on the belt clip side. Please help. Thanks again. I had searched exhaustedly on the internet before coming here. Above I had mentioned the RSSI blinking in response to hand waving over the luggage side Ping sensors

    • I would go without the wireless right now to see if the link is the issue. Hook up the target via wire to the unit and verify its function between the multiple ping sensors. Just add it in with this code and run the wire, make sure you have the grounds connected as well between the two boards so it knows the reference for the signal

      pinMode(pingPin1, OUTPUT);
      pinMode(pingPin2, OUTPUT);
      //pinMode(pingPin3, OUTPUT);

      digitalWrite(pingPin1, LOW);
      digitalWrite(pingPin2, LOW);
      //digitalWrite(pingPin3, LOW);

      delayMicroseconds(2);
      digitalWrite(pingPin1, HIGH);
      digitalWrite(pingPin2, HIGH);
      //digitalWrite(pingPin3, HIGH);

      delayMicroseconds(5);
      digitalWrite(pingPin1, LOW);
      digitalWrite(pingPin2, LOW);
      //digitalWrite(pingPin3, LOW);

      Don’t worry about reading pingpin3, just doing this to verify that the pings are working correctly, then you know its something with either Zigbees or the connection from them to the ping sensor (Are you sending the correct value of null0?)

      By the fact that you said you don’t get the receive light on the target Zigbee makes me think its the wireless link. We used those in master/slave configuration and basically as serial bridges.

      • Are you saying to wire the luggage serial2 TX that used to go to the DI xBee directly to the belt-clip Parallax signal pin? or the Base pin of the inverter transistor?

        • Not until you test it with a direct pin from the board to rule out the inverter and serial stuff, just drive it the same way the you are driving the other sensors in the same block to verify.

      • Wired directly and now my belt-clip Ping led is flashing so it has to my xBees configurations. I setup the xBees as AT mode and did the flip flop on the MY and the DL and they are working under X-CTU so maybe there are other settings. I had already lowered the baud rate and made the change in the codes. Please help. I am almost finished with this project.

        • Ok. The direct pin method is done and it is the wireless problem. I am suspecting the xBee breakout board on my belt-clip circuit. I didn’t want to solder on to the xBee pins so I removed all the smd and switches on the explorer and use it as a breakout board. Maybe I missed something while setting up the xBees under X-CTU.

          • I don’t think I’ve used much zigbee since this project, I’d look around on the Xbee forums for how to use these in a transparent serial link (bridge) mode. We used a master/slave kind of set up. I would think AT mode would mean it’s expecting AT commands and it responds to those instead of just spitting out whatever data that comes into one out the other. You should be able to still do it, you could probably even toggle a digital IO on the zigbee versus using the serial out pin, but I can’t really assist with any of that.

          • My xBee is not receiving outside of X-CTU. My inverter circuit sh be ok. I confirmed by the direct pin connection test. I even tried with two other new xBees. They only receive under X-CTU. I have searched exhaustedly and there other people had the same problem. Talking under X-CTU but not receiving with the arduono or a stand alone alone. Please help.

      • AT mode I was referring to is your transparent serial bridge. I understand your null0 question now. Under X-CTU I could see my remote xBee (belt-clip side) receiving 00’s constantly. I supposed that meant the luggage xBee was transmitting ok. You had mentioned using master/slave mode but your codes supported transparent mode with the serial2 lines. I did not try the API mode because the codes required packet infos and all that. I’m a newbie.

        I looked into why I cannot use witeless. I had skipped the Explorer which I converted to a breakout board. I even tried using a new Explorer using its pin outs taking advantage of its level shifting. I got the belt-clip Ping led “on” constantly even if I disconnect the 3.3v supply to the xBee. I thought then it has to be the PNP but it can’t be because when I did the direct pin test I got the LED blinking when I connected directly to the resistor before the base pin of the PNP. Please help. Thanks again.

        • Direct pin method worked pointed to a level shift problem don’t you think do? I don’t understand why when using the belt-clip xBee I got a constantly lid LED on the Ping. It is on constantly even when I removed the 3.3v supply to the xBee.

          • Looking back on the design, because of the mixed voltage, that transistor probably never fully turns off. I looked around a bit, and some people can get it to work on 3.3V level input, you could try putting the emitter to 3.3V and see if that works. Otherwise I can’t seem to think of an elegant level translator + inverter with a single transistor with the internal pulldown that’s in the ping sensor , multiples yes, but then it gets complicated. If you can’t get the above idea to work, you can just get an inverter chip and power it via 5, 3.3 would be enough to turn it on and the output would be 5.
            8 Pin Dip Inverter

          • You could also try hooking up the TXOut from the Xbee through a serial resistor (try a 330 maybe) to the ping pin directly, turn down the baud rate to maybe 9600 and sending 0x1C which would be 00111000 which might be enough of a pulse to start the ping.

          • Hi Mr Colecago again,
            I did more test and my inverter circuit is alright. The receiving xBee whether hooked up to the belt-clip circuit or power alone by usb cable or 3.3v supply, it doesn’t receive. I even tried 3 other different xBees and everytime I notices when running X-CTU and chose “open serial connection with the radio module” icon under the WORKING CONSOLE MODE where I could see the null0 values showing RX bytes increasing BUT as soon as I disconnect the serial connection or exit the X-CTU, the led on the Explores shows my TX led on that xBee stop flashing. So in the xBee configution I must need to trigger my xBee to start receiving as soon as it gets power. “+++”??? Other people did not get answers elsewhere so I think that you have a better idea. Thanks.

          • Unfortunately I do not have any xbee’s at my disposal. Maybe look into flow control? You might have to do something with the RTS and CTS lines to get it to receive correctly? Try turning off any flow control options that are available.

          • Hi Mr. Colecago and Mr. Heck,
            I have tried different settings including the RTS and the CTS settings in X-CTU and my receiving xbee (the belt-clip xbee) is still only receiving while I am running X-CTU and connecting in the AT command console. Once I disconnect, the led on the xBee indicates that it stopped receiving wirelessly. Thank you in advance.

          • I’d ask on the Digi forums. I haven’t done much with Zigbee since that episode so I don’t have any recent experience, also I don’t even have any to play around with to test.

            Good luck, hope they help you out there.

  35. Thank you Mr. Colecago for the quick response.
    I had the original code line Serial2.writenull0; so I am not sure what you are saying about sending the correct value. You also that the motors code lines Serial1.write(null0); Serial1.write(0x38); commented out. RIght before that you did the null0 line and set the motors to mode 2. I thought null was just reseting something to zero before setting a mode. Please expand on this. I would love to know so I can answer your question.

    BTW after I fixed the belt-clip circuit now having the inverter collector going to the Ping signal pin before the pull down resistor. I also experiment with the 1K and 10K resistor. Now it is not Pinging. It just sit there with the Ping led on constantly. I will try the direct connection now. thanks again. I am using the Parallax 3 pins Ping sensors.

    • Talking about this line in the void loop()

      digitalWrite(13, HIGH);

      Serial2.write(null0);
      delayMicroseconds(500);

      Yeah, it looks like Serial2 is the Zigbee, I chose what I sent to have the digital out to mimic the pulse the ping sensors need (except inverted), hence the inverter. In the show Ben ended up using a logic chip inverter instead because I messed up the design on the show (hence trying to fix it in the post). You can also try an npn inverter, signal through a resistor to the base, emitter to ground, pull-up resistor to the supply (I think the ping and zigbee had different voltage levels) and then the collector output to the ping sensor.

      As for the motors, you don’t really need to set the acceleration and mode every time like I did in that loop, if you do this in setup

      Serial1.write(null0);
      Serial1.write(0x33);
      Serial1.write(3);
      delay(10);

      Serial1.write(null0);
      Serial1.write(0x34);
      Serial1.write(0x02);
      delay(10);

      Then you could remove that from UpdateDrives() I believe. It’s been awhile since I’ve worked on or seen this code, and it was written pretty hastily for the show so its hard to know what I was thinking at the time, and I was sick, hence the box of kleenexes I brought to the second part of the episode 🙂

  36. After you set the motors to mode 2, you commented out the acceleration mode codes. Should I uncomment the null0 and 0x38 code lines?

    • I think your talking about this in the setup

      //Serial1.write(null0);
      //Serial1.write(0x38);

      I think that disables the timeout, I don’t think its the acceleration mode, that’s 0x33.

      • Yes I am talking about the serial2 null0 for the xBee but I just wanted to ask you should I uncomment the part where you commented out the 0x38 for the motors.

        • I just checked the Devantech reference and I just called it wrong. You are right I meant 0x38 for disabling timeout. Maybe that is the problem. Leave it commented? Also Im not sure how to tell you the null value you asked. I just double checked using the X-CTU and my xbees are relays between the twos.

          • Try a direct connection to rule out the wireless link and inverter, if it works and you think your wireless link is good, then either you aren’t sending a null0 or the inverter setup is wrong from the zigbee. Also remember that the zigbee and ping sensors run on different voltage, the transistor did more than invert, it level shifted the output to 5v.

          • Yes I have the correct voltage to the xBee and the Ping sensor. The Ping is transmitter now with the direct connection to the luggage Mega. The logic inverter and pull down resistor and hook up write. Not sure why the xBee is not receiving on the belt clip. I had told you the xBee on the luggage is transmitting confirmed by the led activity. Can I assume correctly that the xBees should be in AT mode? A lot of examples on the internet are written for the older X-CTU and they mentioned setting one xBee as a coordinator and the other one as a receiver; but that is for API mode so I don’t think I need to find that with the new X-CTU.

  37. Hi Colecago,

    Thanks for the nice project. I am building something similar with my line follower. The ultrasonic sensor I use are the cheap SR04. I’ve actually configured the belt clip BT module as master and the one on the line follower as slave, so that I can send more commands than simple ping start commands.

    Now the problem, the system works as long as I use wire to sync them up. But when I try the delay, I get erratic readings from ping receivers on the vehicle.

    From your code, it appears that you are triggering the remote first and wait 500 us before triggering the receiving side with additional 900 us before reading them.

    What would be the ideal delay between the transmitter and receiver sides ? My remote is connected over BT module at 57600 baud and I tried between 500 – 1800 us without success. I do get readings but they are not consistent.

    Appreciate any help to sync them up correctly.

    Thanks
    Kannan

  38. The serial port on the Arduino is notoriously not consistent, though my first though would be checking that the serial bridge is actually working and you are not instead reading the bounce back from your “ears”. I’d verify that the serial is working correctly, and then I’d make sure to remove the transmitting side of the sensor on both of the “ears”. I’m not sure how I came about those exact delay number, I remember though when I tried to do the readings separately (one “ear” at a time) I was getting really bad results because the serial had a non consistent delay between the serial.write and it actually happening.

    In the end the delay isn’t super important except to get the distance, as long as you are reading both “ears” at once, the time between them is what you are looking for.

  39. Thanks for the detailed reply, good to know you are responding to questions even after 3 yrs.

    Back to the problem, I am sure it is not receivers own signal since I shut the transmitting cones with insulation tape. The receivers are from this site http://www.rhydolabz.com/index.php?main_page=product_info&cPath=137_144&products_id=1696 and it has analog output besides pwm and serial. I choose analog since the product claims it has a latching facility of the last reading. Also it can be manually triggered by like SR04. So I thought after receiving the command from the remote, I can trigger the receiver and analogRead() the inputs. Initially I thought it is the sequential reading causing the inconsistencies, but even a single receiver is giving the same problem.

    Let me do some more digging on serial side.

    Thanks
    Kannan

      • I am splitting my hair about how to sync them up reliably. Did some timing check on the serial link over Bluetooth. A single character ‘t’ is sent from transmitter to the receiver every 20ms.I tried measuring the time between each trigger and it varies from 10 ms to 26ms and mostly stays around 18-21 ms. So every 5 or 6 readings I may get a genuinely synced reading. Double syncing back to the transmitter will only aggravate the issue.

        Anyways thanks for listening 🙂

        • So you are saying when you send a serial character, the delay between print or serial out and receiving it is 10-26mS? Hmm, will your sensor automatically timeout in that time period? If not, you can try increasing the timeout in the breakout section of code. If your sensor will timeout itself (I know they have a max time), then you could set an LED one before doing delayMicroseconds(time) to see what time period that is, and try setting it to whatever 10mS is, then do the serial send, then delay, then start your read? That still puts your delay between 10-26mS though.

          You could look for more reliable and lower level serial drivers for the Arduino, I heard that the library and calls are pretty bloated and I definitely noticed that when I was trying each receiver separately and using PULSEIN. Also could be the bluetooth sender/receiver, maybe they have longer handshaking, maybe try a zigbee.

          • Transmitter code as follows

            void loop(){
            mySerial.write(‘t’);
            mySerial.flush();

            delay(20);
            }

            and the receiver as

            int now,then = 0;
            void loop(){
            if(mySerial.available() > 0){
            now = millis();
            Serial.println(now – then);
            mySerial.read(); // just to empty the buffer
            }
            }

            mmm…forgot to mention, the Bluetooth module is connected via SoftwareSerial on pin 5,6.

            Could it be the culprit ?

            Thanks

          • Well I certainly trust the software serial for reliability less than the hardware serial. Also I’ve never had much luck with serial.flush, it’s acted strange for me. I would do the serial write and then use an OScope on the receive of the receiver to see if the packets are consistently timed. Also did you get this working without using the serial yet? That’s the first step, just use a long wire for the “target” to start its ping and see if the rest of the code is working, then use the serial to start the ping.

          • …after some more testing with hardware serial, I found no difference between them. They are varying almost 10-15 ms from the set delay. So, I figured I could send more ping to cover the delay and hitting at least once with the following code on the transmitter.

            void loop(){
            mySerial.write(‘t’);
            for(int i = 0;i < 10;i++){
            ping();
            }

            delay(20);
            }

            and what ? I am getting consistent differential readings. So, with some added checks for threshold clippings and such, it can be really useful.

            For lack of suitable name, the above can be called as 'Bad Marksman Algorithm' hereafter. Of course patent pending as always.:)

            Thanks

          • Consistent differentials are all you really need, the main part of the algorithm is the PI loop based on the difference between the sensors. The distance to target was nice, but not really necessary, it could be done other ways.

  40. I am having problem sync up the emitter and the receiver. I used two RFM69 to transmit the emitting request, then I delay the trigger for 0~2 milliseconds. It never sync up using Arduino code for SR-04 ultrasonic module. I read your post several times, trying figure out the following:

    “This didn’t work either, I think because digital read takes a very long time (longer than it should). Once I changed it to read directly from the port (PINB & 0xyadayada) that approach worked.”

    In your code, your were doing pinMode(pingPin1, INPUT); right after digitalWrite(pingPin2,LOW) there were no delay at all.

    But my receiver just never find the emitter.

    Can you help?

  41. One more comment, both sensors works fine individually. When I cut off the echo from one and the trigger from the other is when they don’t sync up.

  42. After reading through many of the comments, I have learned that my problem maybe caused by the pulseIn() command that I use.

    Please tell me what does “PINE & 0x10” and “PINE & 0x20” mean. Can not find it in Arduino code.

    • I couldn’t use pulsein because it’s a blocking command so you can only read one sensor at a time with that, I tried originally to trigger, listen on one, trigger, listen on second, but the Arduino serial library has non-deterministic delays sometimes larger than the signal you are listening for so it resulted in garbage data between the two sensors. PINE & etc is called direct port manipulation, using digital read and digital write was too slow, at least for the reading part, so I use that code to read bits from the port.
      https://www.arduino.cc/en/Reference/PortManipulation

  43. Hi Jessi,
    Thank you for your quick and detailed response. A bow to you.
    One last question, Since I am using 328 pin A0&A1 therefore, am I correct that I should code as “(PINC & 0x00)” “(PINC & 0x01)”
    Please

  44. Implemented the following code, tried delayMicroseconds(500~1500), still exits when timeout >=19000. Can you advise?

    while ((oneFire == 0) || (twoFire == 0)) {
    if (((PINC & 0x00) == 0) && !oneFire) {
    oneFire = true;
    setPoint1 = timeout;
    }
    if (((PINC & (1 < 19000)
    break;
    }

    Much obliged..

  45. Sorry, somehow copy and paste wrong:
    while ((oneFire == 0) || (twoFire == 0)) {
    if (((PINC & 0x00) == 0) && !oneFire) {
    oneFire = true;
    setPoint1 = timeout;
    }
    if (((PINC & (1 < 19000)
    break;
    }

  46. hmm, somehow after I click on “Post Comment”, my paste was chopped up. I hope you get the point. It is your exact code, other than the PINC & (1<<PC1)

  47. I think I am having the exact same issue with Frank Johnson. I read through the log and tried also PORTC & BIT(0) & PORTC & BIT(1). But no success.

    • One bite at a time, first get it working with no wireless, I recommend something like this, slightly modified for your sensor and arduino

      //pinMode(pingPin1, OUTPUT); this can be done in the setup and not repeated
      //pinMode(pingPin2, OUTPUT); this can be done in the setup and not repeated

      digitalWrite(trigPin1, LOW);
      digitalWrite(trigPin2, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin1, HIGH);
      digitalWrite(trigPin2, HIGH);
      delayMicroseconds(5);
      digitalWrite(pingPin1, LOW);
      digitalWrite(pingPin2, LOW);

      // The same pin is used to read the signal from the PING))): a HIGH
      // pulse whose duration is the time (in microseconds) from the sending
      // of the ping to the reception of its echo off of an object.
      //pinMode(rxPin1, INPUT); can be done in setup and not repeated
      //pinMode(rxPin2, INPUT); can be done in setup and not repeated

      delayMicroseconds(900);

      timeout = 0;
      oneFire = false;
      twoFire = false;
      finished = false;
      setPoint1 = 0;
      setPoint2 = 0;
      difference = 0;

      while ((oneFire == 0) || (twoFire == 0)){
      if (((PINC & 0x01) == 0) && !oneFire){
      oneFire = true;
      setPoint1 = timeout;
      }
      if (((PINC & 0x02) == 0) && !twoFire){
      twoFire = true;
      setPoint2 = timeout;
      }
      delayMicroseconds(1);
      timeout++;
      if (timeout > 19000)
      break;
      }

        • Really thank you Jessi for your kindness. Below is the complete code that is running.
          [code]#define trigPin A0
          #define echoPin A1
          #define trigPin2 A2
          #define echoPin2 A3

          void setup() {
          Serial.begin (115200);
          pinMode(trigPin, OUTPUT);
          pinMode(echoPin, INPUT);
          pinMode(trigPin2, OUTPUT);
          pinMode(echoPin2, INPUT);
          }

          void loop() {
          long distance = 0;
          sendTrigger(trigPin,trigPin2);
          getDistance(echoPin,echoPin2);
          delayMicroseconds(900);
          getDifference();
          delay(250);
          }

          long getDifference() {
          unsigned long difference = 0, timeout = 0, distance = 0;
          boolean oneFire = false;
          boolean twoFire = false;
          long setPoint1 = 0;
          long setPoint2 = 0;

          while ((oneFire == 0) || (twoFire ==0)) {
          if (((PINC & 0x01) == 0) && !oneFire) {
          oneFire = true;
          setPoint1 = timeout;
          }
          if (((PINC & 0x03) == 0) && !twoFire) {
          twoFire = true;
          setPoint2 = timeout;
          }

          delayMicroseconds(1);
          timeout++;
          if (timeout > 19000)
          break;
          }

          difference = setPoint1 – setPoint2;
          distance = (setPoint1 + setPoint2)/10;

          Serial.print(“setPoint1:”);
          Serial.print(setPoint1);
          Serial.print(” setPoint2:”);
          Serial.print(setPoint2);
          Serial.print(” Timeout:”);
          Serial.print(timeout);
          Serial.print(” Difference:”);
          Serial.print(difference);
          Serial.print(” Distance:”);
          Serial.println(distance);
          return (difference);
          }

          void sendTrigger(int trigger, int trigger2) {
          digitalWrite(trigger, LOW);
          delayMicroseconds(2);
          digitalWrite(trigger, HIGH);
          delayMicroseconds(5);
          digitalWrite(trigger, LOW);
          digitalWrite(trigger2, LOW);
          delayMicroseconds(2);
          digitalWrite(trigger2, HIGH);
          delayMicroseconds(5);
          digitalWrite(trigger2, LOW);

          }

          long getDistance(int echo, int echo2)
          {
          long duration, duration2, distance,distance2, diff;
          int trigger2=trigPin2;
          duration = pulseIn(echo, HIGH);
          distance = (duration / 2) / 29.1;
          duration2 = pulseIn(echo2, HIGH);
          distance2 = (duration2 / 2) / 29.1;
          diff = distance – distance2;
          Serial.print(distance);
          Serial.print(” – “);
          Serial.print(distance2);
          Serial.print(” cm = “);
          Serial.print(diff);
          Serial.println(” cm”);
          return diff;
          }[/code]

          And this is the result of the SerialPrint:
          [code]
          When //getDistance(echoPin,echoPin2); is not active

          setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0
          setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0
          setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0
          setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0
          setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0
          setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0
          setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0

          When getDistance(echoPin,echoPin2); is active.

          6 – 46 cm = -40 cm
          setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0
          6 – 45 cm = -39 cm
          setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0
          6 – 47 cm = -41 cm
          setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0
          6 – 47 cm = -41 cm
          setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0
          6 – 46 cm = -40 cm[/code]

          I can not figure out why both setPoints are 0(zero).

  48. OK, back to basics. I trigger on the same module and echo tested. Now, instead of pulseIn(), I used the following code…

    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    data2 = (PIND & BIT(4));

    data2 is always 0(zero) whether there is trigger or no trigger. What result do I suppose to get and if not, what’s wrong.

  49. I am sorry, the code that I just posted works fine.

    I am embarrassed to inform you that I placed the ultrasonic sensors right next to my keyboard, that’s why it continues to show 0.

    By accident, I tilted to the ceiling, the numbers began to show.

    • I’m glad you are working it out, I’m a pretty lousy teacher and remote troubleshooter and I’m glad to see you making progress as I’m away at work. Keep at it, after you get the three sensors working together by wire, then you can try and add the wireless trigger.

  50. Thank you, Jessi, for your kind support. You lift my spirit.

    What I really wanted to do is to try to figure out the timing difference between two RFM69, Instead of using RSSI signal strength, the timing difference will be more accurate.

    Unfortunately, I based these working code on the two interrupt pins. And I changed the delay upto 10 milliseconds, still no go.

    Any advise?

    • Are you trying to use time of flight of wireless modules versus using the time of flight of the ultrasonic sensors? I don’t think you will be able to do that on Arduino. The speed of the wireless signals are just too fast and the interrupt capabilities of the basic Arduino aren’t very good.

  51. Arriving at last step of my ultrasonic venture. First or second receiver works perfectly with remote triggered emitter. Delay works from 700~2700 microseconds.

    setPoint1:697 setPoint2:0 Timeout:698 Difference:697 Distance:69
    setPoint1:0 setPoint2:700 Timeout:701 Difference:700 Distance:70

    But when I insert both receivers, both failed as follows:

    setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0
    setPoint1:0 setPoint2:0 Timeout:1 Difference:0 Distance:0

    Please note timeout=0. Scratch my head and can not figure it the problem.

    Please advise.

  52. Greetings,
    My name is levi Hiti and I’m studying Mechanical Engineering College, Sammi Shimon in Israel. to my final degree project I am building a wagon (which is very similar suitcase) that will follow its owner. I will be happy if you could answer me a few questions:
    1. how you linked the Xbee to the sensors systems?
    2. Can we please send me the wiring diagram of the all system?
    2. The controller you’ve used (PID) was on speed or position? How does it work?

    I’d be happy to fast reply
    Thanks in advance!
    Levi

    • 1) The luggage had a zigbee on it, we sent a serial command and used the receive pin on the target to start the ultrasonic ping that the luggage would listen to.

      2) We don’t really have one

      3) Speed based, I use the time distance between the received ultrasonic pings be my error value that I’m trying to reduce to zero

        • Near the bottom of the page, above the parts list

          I’ve also attached the code for download. I’ts a .c file, but is actually the .ino, wordpress doesn’t like .ino files so just rename it to something.ino

          Robot C Code

  53. Hey I was wondering how you were able to sync the times of the transmitter ultrasonic and the receiver ultrasonics while they were on two different boards.

    Also, currently I am using an SRF-02 sensor as a receiver and as a transmitter, but my issue has been syncing them using UART.

    • My sensor doesn’t have a communication trigger, it has a digital input that is uses for trigger as well as detect. I send a specific command over wireless which through a not gate is used to trigger the transmitter, then I trigger the receivers to listen. I suspect that if you have sensors that use UART to initiate that you’ll have problems because of the non predictable/repeatable nature of UART in Arduino.

      • Thanks for the swift response. I read you’re code a couple times and noticed that you send a message from the Tx xbee on the luggage to the Rx xbee on the user to initiate the ping process.

        What is the pin setup on the transmitting beacon and how can I trigger the ping to go off upon receiving a notice from the xbee?

        Also, will an S1 differ from S2 xbee?

        • Not sure of the difference between the S1 and S2. As for using the receiving Zigbee to initiate a ping, if the initiation process is the same to the sensors we were using, you should be able to run the rx pin though an inverter to the ping pin.

      • OK, so i’m going to opt to use the parallax ping sensors because that single I/O pin is way too convenient. How would I model the code on the Rx Xbee that is transmitting the ping?

        I’m thinking some type of logic that says.

        When byte is sent
        do this.

        but how would i phrase that in arduino?

        • Also, for your motor code, what do 0x31..34 and 0x38 do. Also 0x2 and I’m assuming the values 128 and 3 are duty cycle values, is that correct?

        • We don’t have an Arduino on the receiving end, we just have the RX pin of the zigbee control the ping sensor through an inverter directly. If you wanted to use an Arduino, you could set up a serial interrupt and use this code in it

          pinMode(pingPin1, OUTPUT);
          digitalWrite(pingPin1, LOW);
          delayMicroseconds(2);
          digitalWrite(pingPin1, HIGH);
          delayMicroseconds(5);
          digitalWrite(pingPin1, LOW);

          pinMode(pingPin1, INPUT);

  54. HI,
    How to implement this project with HC-SRO4 ultrasonic sensor?
    How to use HC-SR04 either as a transmitter or receiver separately and to measure received signal strength of ultrasonic signal with HC-SRO4 in arduino?
    Thank you.

    • There are several comments on here about using that sensor, basically you just have to split the trigger and receive pins a part, shouldn’t be much different beyond that. To make one send and not receive or the opposite, remove the transmit or receive CAN from it. You can’t measure signal strength on these modules.

      • Why shall we remove a CAN rather than without connecting it? I mean, not connecting echo or trigger to arduino so that can we skip away echo or trigger?

      • Do we have to just remove the CAN’s or can we make those trigger or echo pins to ground?
        what’s the difference?
        Thanks in advance

        • I’ve never used that specific part, but I imagine that it won’t go into listen mode unless its been triggered using the trigger pin, so you have to stop it from actually transmitting on the listener ones despite being triggered, you could probably remove some inline resistors and whatnot, but we just took the transmitting CANs off.

  55. Hi,
    can you please explain what is the method you’ve developed on the detection(frequency measuring) the transmitter pulse at the two receivers without using any functions like pulseIn() or arduino interrupts ?
    Thanks,
    Goutham

    • I explain it a little bit in the post, basically I’m looping through waiting for either of the sensors to go to receive, then I record when it did, then I wait for the second one, and the difference is my error value.

      doPingDiff-
      Do the high low thing to start both receivers
      Send Zigbee start command
      Wait for either left or right sensor to go to zero or timeout; record
      that setpoint
      Wait for second sensor to go to zero or timeout; record that setpoint
      and break loop
      Calculate the difference by subtracting
      Calculate the distance by adding both values and dividing by 10 (for
      scaling speed)
      Return the difference (which is our error)

      Look at long doPingDiff() in the Robot C code near the bottom of the post

      • What about the transmitter , why can’t we use random square pulse generators? Are you sure this project can be made with hc-sr04 ultrasonic sensors instead of ping sensors?

        • You could go without a wireless transmitter, I’ve talked briefly about this in some of the comments on this page. It might make the code more complex because with the timeouts of the sensors you might be searching a bit before you sync onto the targets signal, also you’ll have no information about distance, only orientation from the TOF difference between the ears. It’s doable I’m sure, I’ve just never tried it, we had a couple of weekends to get this project working and I haven’t gone back to it since besides answering questions. I think 2-3 people have made working versions based on this design and code so far.

  56. Can i use a different type of motors like this one : 70:1 Metal Gearmotor 37Dx70L mm with 64 CPR Encoder

    12V brushed DC motor with a 70:1 metal gearbox and an integrated quadrature encoder that provides a resolution of 64 counts per revolution of the motor shaft, which corresponds to 4480 counts per revolution of the gearbox’s output shaft. These units have a 0.61″-long, 6 mm-diameter D-shaped output shaft

    https://www.pololu.com/product/2825

    • You should be able to. We had the benefit of a closed loop speed controller with our system so we sent speed commands and the controller took care of the encoder feedback and voltage control. If your motors are well balanced you might not need closed-loop speed control, voltage control may be good enough, I mean the system is correcting itself anyways as you walk so if one is spinning faster the PI loop for the ultrasonic signal will be adjusting the motors left/right. Make sure you figure out your wheel and use that to figure out the max speed of your robot based on the motor RPM.

  57. Hey Colecago,

    I’ve been thinking about working on a robot that is similar to this design. Instead of following, I simply want it to locate it’s home base (kind of like the vacuum bots when they go home to charge). I tried looking at your code, but its seems like the arduino file is not available anymore. Would you be willing to share this with me? Thanks!

  58. helloo … can u tell me the the wiring of switch pin to arduino .. ?

    and does it mean this one : const int switchPin = 5; the number five ?? what is this .. is this the pin number on arduino mega pro .. ? or a value ?

  59. i’m trying to do your project …., but i can’t get it work
    i don’t know why i think my wiring

    can i send you a picture of my project … ?

    • It’s a pretty advanced project, I recommend starting a piece at a time. Get the ultrasonic working, get the wireless working, get the motors working, then altogether.

    • Doesn’t matter if its pull up or pull down, just need to adjust the logic in the code to know which position the button is in. Follow the tutorial I posted on the Arduino site. I recommend you go through some of these before attempting this project, it’s pretty advanced and a bunch of the documentation is lacking, if you don’t have a good base in Arduino, this project will be very difficult. I think only 2-3 people have successfully replicated this project that I’ve seen.

  60. Hello.. I did the switch pin and i make the xbee communication xbee1 coordinate AT mode and xbee2 router AT mode.. nd they can chat now… Now how do i test the ping sensors.. which is the code do u use to test i have arduino uno.. and the maga pro 3.3v .. Can u give a way to make the motors move back and forth to test the controller.. Please help me i have a graduate on 15/4/3016 i fon’t have time please! and i use q pnp transistor bc558 for the handheld.

  61. hello …. can u tell me what is the code did u use to send ping request through Xbee’s to the target ( handheld ) to start ping))) i see in your code that’s serial2 is for Xbee’s and there’s no commnad just this one

    Serial2.write(null0);

    and you define a null0 — const unsigned char null0 = 0;

    i don’t know how to send a ping request ?

    • That is the line, when you send that value over the serial port, and the other side of the wireless signal is put through an inverter, that is the correct pulse sequence to start an ultrasonic ping.

    • You need an inverter because serial is normally high and goes low for the pulse.

      I don’t have any Ping sensors anymore, supposedly they have an internal pulldown, so this circuit should work with an PNP transistor.
      Inverter

  62. i got this result on serial monitor ..
    when i put my hand on ping sensor the motors movers to left …

    on luggage – xbee Rx pin – arduino Tx2 pin
    on target – xbee Tx pin – to inverter then to ping)))
    ??? that’s right?

    RF data on target Xbee receive FF in HEX ??

    Error: -41
    Direction: Left
    Error Sum: -41
    Error Correction -21.52
    Distance Correction 2242
    Speed Correction 5
    Turn Correction 106
    Turn Direction 0

    Error: -52
    Direction: Left
    Error Sum: -93
    Error Correction -28.32
    Distance Correction 4411
    Speed Correction 5
    Turn Correction 99
    Turn Direction 0

    Error: -40
    Direction: Left
    Error Sum: -133
    Error Correction -23.32
    Distance Correction 2236
    Speed Correction 5
    Turn Correction 104
    Turn Direction 0

    Error: -40
    Direction: Left
    Error Sum: -173
    Error Correction -24.32
    Distance Correction 1151
    Speed Correction 5
    Turn Correction 103
    Turn Direction 0

    Error: -44
    Direction: Left
    Error Sum: -217
    Error Correction -27.42
    Distance Correction 1514
    Speed Correction 5
    Turn Correction 100
    Turn Direction 0

    Error: -36
    Direction: Left
    Error Sum: -253
    Error Correction -24.32
    Distance Correction 4415
    Speed Correction 5
    Turn Correction 103
    Turn Direction 0

    Error: -48
    Direction: Left
    Error Sum: -301
    Error Correction -31.52
    Distance Correction 2236
    Speed Correction 5
    Turn Correction 96
    Turn Direction 0

    Error: -44
    Direction: Left
    Error Sum: -345
    Error Correction -30.62
    Distance Correction 4415
    Speed Correction 5
    Turn Correction 97
    Turn Direction 0

    Error: -43
    Direction: Left
    Error Sum: -388
    Error Correction -31.20
    Distance Correction 1151
    Speed Correction 5
    Turn Correction 96
    Turn Direction 0

    Error: -50
    Direction: Left
    Error Sum: -438
    Error Correction -35.95
    Distance Correction 2236
    Speed Correction 5
    Turn Correction 92
    Turn Direction 0

    Error: -44
    Direction: Left
    Error Sum: -482
    Error Correction -34.05
    Distance Correction 1513
    Speed Correction 5
    Turn Correction 93
    Turn Direction 0

    Error: -49
    Direction: Left
    Error Sum: -531
    Error Correction -37.78
    Distance Correction 2236
    Speed Correction 5
    Turn Correction 90
    Turn Direction 0

    Error: -49
    Direction: Left
    Error Sum: -580
    Error Correction -39.00
    Distance Correction 2239
    Speed Correction 5
    Turn Correction 89
    Turn Direction 0

    Error: -45
    Direction: Left
    Error Sum: -625
    Error Correction -38.13
    Distance Correction 2237
    Speed Correction 5
    Turn Correction 89
    Turn Direction 0

    Error: -76
    Direction: Left
    Error Sum: -701
    Error Correction -55.53
    Distance Correction 1524
    Speed Correction 5
    Turn Correction 72
    Turn Direction 0

    Error: -62
    Direction: Left
    Error Sum: -763
    Error Correction -50.08
    Distance Correction 4629
    Speed Correction 5
    Turn Correction 77
    Turn Direction 0

    Error: -60
    Direction: Left
    Error Sum: -823
    Error Correction -50.58
    Distance Correction 1515
    Speed Correction 5
    Turn Correction 77
    Turn Direction 0

    Error: -71
    Direction: Left
    Error Sum: -894
    Error Correction -57.85
    Distance Correction 2240
    Speed Correction 5
    Turn Correction 70
    Turn Direction 0

    Error: -62
    Direction: Left
    Error Sum: -956
    Error Correction -54.90
    Distance Correction 1514
    Speed Correction 5
    Turn Correction 73
    Turn Direction 0

    Error: -62
    Direction: Left
    Error Sum: -1018
    Error Correction -56.45
    Distance Correction 3033
    Speed Correction 5
    Turn Correction 71
    Turn Direction 0

    • I think you have some things wrong, RX should go to the inverter to start the target’s pin sequence. Here is how it is supposed to work.
      Luggage starts the ping sequence on both of its sensors to put them into listening mode
      Luggage sends out a wireless transmission to start the target into transmitting mode
      Luggage starts listening and counting, waiting for a signal or timeout

      Target receives the wireless packet which automatically starts the transmitting mode of the ping sensor

  63. can i make alarm if someone pass through or if it’s out of range ‘?….

    with buzzer or Alarm sound … i think it’s possible with some codes … i’m not good with codes can u write a code to do this thing …
    for example :
    int alarm = 7;
    ……………………..???

    • The luggage stops moving if it gets too many timeouts. Timeouts happen when it doesn’t receive a signal which could be from being too far away, something blocking the luggage, or the angle is too extreme for the luggage to see the target.

  64. Thanks Colecago for your Support .
    The Project almost working … now i’m making the design when i finish the project i will upload a video sooon … 🙂 🙂

    Thnx . 😉

  65. why the motors moves when i push the switch pin without using the sensor on handheld ?? i remove the Tx on two sensors on luggage
    that’s the only problem i have . maybe u left something in code that cause the problem .

    • I would think that the timeout would take care of that if its not receiving signal. The code I have attached is the code we used in the show, so not sure what the difference between our stuff and your stuff is.

  66. i checked everything .. i can’t fine the problem .!!

    when i push the switch button the motor moves to left without any transmitter .. and when the luggage is in disabled mode the receivers start blinking …and when i power the transmitter it moves fine .. but when i power off the transmitter it keeps moving … i think the problem is with the timeout .. where is the code that tell the motors to stop if there’s to many time out . and the move of motors is slow !!!????!
    please help me 🙁
    components :

    Arduino Mega 2560
    2x – xbee s2
    3x – Ping))) ultrasonic sensor
    md25 motor controller
    motors : 70:1 Metal Gearmotor 37Dx70L mm with 64 CPR Encoder https://www.pololu.com/product/2825

  67. Here’s the Result of Debug Serial Monitor i added the Difference and Distance ….
    Without using Transmitter just the two RX sensors on Luggage it’s still moving and when i replace the sensors pins the direction changed to Right
    i checked the Jumpers on MD25 and it’s on 38,4K Baud
    i can’t find the problem … 🙁 🙁 🙁
    Error: -26
    Direction: Left
    Error Sum: -4217
    Error Correction -118.43
    Distance Correction 1487
    Speed Correction 5
    Turn Correction 9
    Turn Direction 0
    Distance 1486
    Difference -27

    Error: -27
    Direction: Left
    Error Sum: -4244
    Error Correction -119.60
    Distance Correction 1508
    Speed Correction 5
    Turn Correction 8
    Turn Direction 0
    Distance 1514
    Difference -27

    Error: -27
    Direction: Left
    Error Sum: -4271
    Error Correction -120.27
    Distance Correction 1494
    Speed Correction 5
    Turn Correction 7
    Turn Direction 0
    Distance 1516
    Difference -26

    Error: -28
    Direction: Left
    Error Sum: -4299
    Error Correction -121.47
    Distance Correction 1507
    Speed Correction 5
    Turn Correction 6
    Turn Direction 0
    Distance 1515
    Difference -28

    Error: -27
    Direction: Left
    Error Sum: -4326
    Error Correction -121.65
    Distance Correction 1508
    Speed Correction 5
    Turn Correction 6
    Turn Direction 0
    Distance 1515
    Difference -27

    • Hmm, I think I have another idea, did you happen to change the pins that the ultrasonic receivers are on? Because you can’t only change the ping1Pin, ping2Pin etc, I have some hardcoded digital reads in there because the Arduino library takes too long to do that, this is the code I’m referring to

      while ((oneFire == 0) || (twoFire == 0)){
      if (((PINE & 0x10) == 0) && !oneFire){
      oneFire = true;
      setPoint1 = timeout;
      }

      If you moved the pins those are on, I’d have to adjust the lines (PINE & 0x10) and the other one. Let me know what pins those are on and I can give you those updated lines, which may help the situation.

  68. i changed the pins to this …

    while ((oneFire == 0) || (twoFire == 0)){ // PORTH define pin 7 faster than Digital input
    if (((PINH & 0x10) == 0) && !oneFire){
    oneFire = true;
    setPoint1 = timeout;
    }
    if (((PINH & 0x20) == 0) && !twoFire){ // PORTH define pin 8
    twoFire = true;
    setPoint2 = timeout;

    it’s now on PORTH
    PINH & 0x10 >>>> pin 7
    PINH & 0x20 >>>> pin 8
    Same Problem .. still moving without transmitter or signal .!!!!!!!!!!!!!!!!!!! :@ 🙁

    • It looks like pin 7 and 8 line up on the same port pins as 2/3 (which is 4/5) so the code you have should work. Not sure why it doesn’t. I recommend like before you get every piece working alone before you try and put it together, right now I think the problem is in the Ping sensors, you should get nothing if you have nothing hooked up.

  69. Hi Colecago,

    May i ask you to explain to me how you disabled the transmitter/receiver from the 28015 ping))) sensor?

      • Hi Colcago,
        Thanks for replying to my previous question!
        I removed the transmitter on one of the ping sensors and connected them in the same arduino board for testing. However, i cannot seem to get a reading from the receiver, it kept saying 0cm. Any possible causes for this?

          • No problem, I don’t often get to these comments very quickly and often times people have solved their own problems like this!

          • Hi colcago,

            Sorry but i had another problem with the receivers..
            Can I know how you enable the 2 receivers to be able to receive the same pulse from the transmitter? I can’t seem to get both my receivers to receive, it’s always the receiver of the first pulseIn that receives the signal. I’m guessing that my first pulseIn is blocking my second pulseIn, but i can’t seem to get around it.

            Code:
            pinMode(pingPin, INPUT);
            pinMode(pingPin1, INPUT);
            duration = pulseIn(pingPin, HIGH);
            duration1 = pulseIn(pingPin1, HIGH);

          • Yeah I explain this issue in the post, pulsein is a blocking command so you can only do one at a time. I ended up having to put them both into receive mode and then loop and poll the receive pins until they changed or timed out. See the code and explanation in the post.

  70. Hi Colecago,

    Do we really need to use xbee for this project? Can I just use another arduino for the transmitter in the handheld device?

    Thank you for your great project.

    • Look at some of the comments for this discussion. Basically you could do it without a wireless link, but it makes the code easier if you have one because then you don’t have to worry about losing sync with the transmitter. You can only listen for a limited time period so it’s possible the sensors time out before you get a chance to go back into listen mode. With a wireless link the receivers know when to start listening as they initiated the ping.

  71. Oh! I think i got it!
    One more thing, correct me if i’m wrong, the receiver sends a ping to the transmitter through the xbee which acts as the “activation” signal for the transmitter hence no program is needed for the transmitter right?
    So how did you connect up the transmitter and the xbee? Did you solder the pins directly? also which pins should i use to connect the xbee to the ping sensor?

    • In the post I talk about this, I wanted to use a transistor invertor but we miswired it on the show and Ben used a standard logic inverter. I have a schematic on the post on how it should be wired.

Leave a Reply

Your email address will not be published. Required fields are marked *