HTWay – Bluetooth Version

The HTWay programs, both the NXT-G and the NXC versions, are designed so that the control code and the balance code are separate. This makes it possible to modify the control code without effecting the balance code. Want to add different sensors such as a Light sensor for line tracking or Ultrasonic for obstacle avoidance, then you can do that in the control code without having to worry about the details needed to make the robot balance. This post will show you and example of how that can be done by creating a remote controlled Bluetooth version using a second NXT for the Bluetooth controller. This second NXT features active controls using the NXT motors that will self-center when you let go of them.

If you look at the NXT-G program for the HTWay it will see that it looks like this:

In the top part of the program you see the initialization and the balance code. This starts of with getting the wheel size from the user, then getting the initial gyro offset, and right before it starts to balance it plays the beep sequence. The loop here is the main balance code, you can leave that alone.

Below the main balance code you see another loop that starts of with the IR Receiver sensor block. This loop runs at the same time as the balance code and communicates with the balance code through two global variables: controlDrive and controlSteer. In this loop the IR Receiver block is used to read the values for the red and blue sub-channels for IR channel 1. Then these red and blue values are used to set the controlDrive and the controlSteer. Basically, the sum of the red and blue, times a constant, set the controlDrive and the difference of the red and blue set the controlSteer. If you want to make the robot do something else, all you have to do is replace this loop with your own code that sets the controlDrive and controlSteer variables.

The variables controlDrive and controlSteer and in the units degrees per second. For controlDrive, this is the sum of the motors and for controlSteer it is the difference between the motors (left-right). For example, if you set the controlDrive to 400 and then let it run for one second, then the sum of the two motors should change by 400. If you set controlSteer to 400 and let it run for one second, then the difference of left-right will change by 400. In other words, the robot will turn to the right. These values can both be set independently so the robot can drive and turn at the same time.

The first Bluetooth controlled HTWay

A young robot builder in Norway, Christian I., created a Bluetooth version of the HTWay. He used a second NXT with four touch sensors for his controller and programmed it to send BT messages to the HTWay which would then use the messages to drive the robot via the controlDrive and controlSteer variables. What to go, Christian! Nice job! Here are some photos he sent me as well as the youtube video:

Top View, left for steering, right for driving Bottom View, bottom of beam presses touch sensors.

Here is the video of Christian’s BT HTWay:

Official HiTechnic HTWay – Bluetooth Edition

Inspired by Christian’s fine work, here at the HiTechnic workshop we have developed an official HiTechnic version of the Bluetooth HTWay. It also uses a second NXT for the BT controller but instead of buttons, it uses two NXT motors. The controller can be built from either a LEGO Mindstorms 1.0 or 2.0 set, just note that the part colors and tires are different. The controller is programmed so that the motors are self-centering and have limited travel. If you push them all the way forwards, then they will send a 100 for that side, all the way back is -100. If you let go of the wheel, it will go back to the zero position.

PDF of Building Instructions for the HTWay
PDF of Building Instructions for the Bluetooth Remote
Zip file of NXT-G Controller and Receiver Programs for the HTWay-BT

Update(July 28, 2010):The NXT-G Program in the download above has been updated to use the new 2.0 Gyro sensor block available for download from the Downloads page. If you are using the original 1.0 Gyro sensor block, you must update it to the new 2.0 block for use with this program.

Currently the programs are only available in NXT-G for LEGO Mindstorms 2.0. Also included in the programs Zip file are the compiled .rxe files. If you don’t have LEGO Mindstorms 2.0, you can still download these files to the NXTs from the LEGO Mindstorms 1.0 software. Your NXTs will still need to have a firmware associated with LEGO Mindstorms 2.0 (firmware version 1.26 or greater) which you can download from this LEGO downloads page.


  1. Build the HTWay exactly like the original version except without the IR Receiver sensor. If you want, you can replace the L-Beam that is supposed to hold the IR Receiver with a 3 Beam. Like this:
  2. Build the Remote from the instructions with the link above. The remote is buildable from either a NXT 1.0 or 2.0 set though the program is designed for LEGO Mindstorms 2.0.
  3. If you have LEGO Mindstorms 2.0, I recommend that you create a new profile for the HTWay as there are a lot of MyBlocks that are specific to this project. In the new profile; open the two .rbtx files. Download the HTWayG-BT to the HTWay NXT and download HTWayG-BTRem to the controller NXT.

    If you have LEGO Mindstorms 1.0, you can download the .rxe files directly to the NXT. From the LEGO Mindstorms software; create or open a program and then click on the upper-left button in the group of 5 buttons on the lower-right corner of the window. Click on the Memory tab and then click Download. Download the HTWayG-BT.rxe to the HTWay NXT and HTWayG-BTRem.rxe to the controller NXT.

  4. Before you run the programs, you need to establish the Bluetooth connection between the NXT. First of all, turn on Bluetooth on both NXTs by selecting Bluetooth on the main NXT menu and then selecting On/Off, then On. From the Controller NXT, you now need to initiate the communication by first selecting Bluetooth on the main NXT menu, and then select Search. The NXT will now search for Bluetooth devices around. This may take a while. When it is done searching, select the NXT of the HTWay. Then select Connection 1. You will now need to accept the pass-key on both NXTs.
  5. You are now ready to run the programs. Like the original NXT, the HTWay will first ask you to select the wheel size. After the wheels size is selected, lay the robot down flat in order to give it a chance to get an initial Gyro offset value. As soon as the robot starts to beep, hold it up vertically as balanced as possible. On the long beep, let go.

That’s it! You should now be ready to drive the HTWay.

Here you can see this version in action:

Other possibilities

Just like Chistian’s version, only the control loop of the HTWay was modified. The Balance code is exactly like the original version. If you want to make the HTWay do different things, you can try changing the control code on your own to see what you can make it do. Try adding other sensors such as the Light sensor or Ultrasonic sensors.


Tags: , , , ,

17 Responses to “HTWay – Bluetooth Version”

  1. Brian says:

    Excellent. I have been waiting patiently (ok actually impatiently) for my new IR Receiver sensor to arrive. This will give me something to play with until it arrives. Great job. Please keep the new HTWay variants coming!!

  2. David says:

    need help with program download try o download out of memory and rebuil program have all the files do i need to rebuild have reinstalled it and deleted all files and still wont work this is for both htway programs bluetooth ang ir reciver pls help Best Regaurds David

  3. Gus says:

    David, make sure you have deleted sound and graphic (.ric) files from the NXT as well. These programs are not so big that you should have any major difficulty downloading them to the NXT. If you still have trouble email me at support at hithechnic dot com.

  4. n says:

    Are somebody have a NXC control code?

  5. [...] you feedback when you attempt to go beyond these values. This little trick was honestly stolen from Gus’ BT Remote for the HT Way. As they say in The Netherlands: “Beter goed gejat dan slecht bedacht.”, or in English, “It [...]

  6. indy says:

    i want it balanced for bluetooth from my laptop cause i dont have a ir sensor or second nxt

  7. Gus says:

    This is a little tricky because most NXT BT remote programs that run on a PC control the motors directly which does not work with the HTWay. Instead you need a remote program that will communicate with the HTWay program running on the NXT. If you know of a remote program that can be configured to talk to an NXT program instead of controlling the motors directly then let me know.

  8. Htway says:

    How to operate the Htway but with an accelerometer, it is mentioned that can be done with trigonometric functions, but need a little help, to make it work

  9. Z says:

    Can i build a program in vb, to control the nxt via bluetooth?. I have already paired my gamepad with vb. (Visual basic). All I need now is a method to communicate between the nxt and VB. Please, any help would be appreciated

  10. Arsalan says:

    Awesome work man i applied it and it worked just fine shine, gr8 effort i was really strugling to control the nxt two wheeled balancing robot by remote device n after months seeing this was very exciting, thou i was wondering if i can control it from pc? coz i borrowed remote nxt from a friend…it would be gr8 help if u can give an idea of controlling it by pc bluetooth….i had balancing code on robotc and also motor controlling code by joystick but when join the both codes it only balances n controlling code does not do anything any help???
    again gr8 work

  11. Gus says:

    Thanks! I am working on a PC remote version.

  12. Gus says:

    There should be a .net framework available that lets you communicate with the NXT from a VB or C# program. Sorry, can’t help you beyond that.

  13. [...] you feedback when you attempt to go beyond these values. This little trick was honestly stolen from Gus’ BT Remote for the HT Way. As they say in The Netherlands: “Beter goed gejat dan slecht bedacht.”, or in English, “It [...]

  14. [...] Segways (the one Laurens made and the HTWayby [...]

  15. Boy says:

    Is there any java code for htway?or can you give me link ??
    thanks a lot

  16. Gus says:

    I do not have Java code for it but I don’t think it would be all that difficult to port the NXC version to Java.

  17. DD GHEVARIYA says:

    very good….keep it up…

Leave a Reply