Tutorial: NXT Segway with NXT-G

This tutorial will show you how to use and modify a standard NXT-G program to create a working LEGO NXT Segway balancing robot that you can customize as you like. I am assuming you will use the ‘Anyway’ platform. Once everything is up and running, you’re free to customize this one and create your own Segway.

The Anyway (click to build)


0. Quick start (if you don’t like to read)

Tutorials are fun, but of course you’re eager to get that robot to balance. If you want to figure it out on your own, just download and run the programs. If you’re stuck you can always return here.

If you’re more comfortable with step-by-step guidance, just follow the steps in order.

1. Requirements and preparation:

2. Understanding the Segway program basics

Before moving on to programming the Segway, let’s have a brief look at one example program for the Segway. All example programs have the same basic structure consisting of three components:

  • Start up (dark blue): This configures your Segway and calibrates sensors if needed.
  • Balancing task (light blue): This task does all the balancing work for you. You don’t have to do anything with these blocks.
  • Your control task (green): This is where you can customize your Segway actions. You’ll learn all about that in a minute.

3. Creating an extra profile for your Segway programs (Optional)

The program you’ll soon open contains a lot of My Blocks. Nothing special here, but it can make your collection of My Blocks a little unorganized. You can create an additional ‘user profile’ in your programming environment by following the steps below. That way, your Segway programs will be kept separate from your other files. Next time you start the software to work on the Segway, only follow step 3 again. Note that creating a user profile is totally optional, but recommended.

4. Getting started: Balancing for the first time (and just stand still)

  • Launch the NXT-G 2.0 software.
  • Open “AnywayHT-Basic(ContainsMyBlocks).rbtx”.
  • Select the “StartUp” My Block. A configuration panel shows up as shown below. In the “Wheel Diameter (mm)” box, enter the diameter of the wheels of your robot, measured in milimeters. It is 42 mm for standard NXT 2.0 and 54 mm for standard NXT 1.0 wheels. Use only one of these two wheel types for now! Once everything else works, try other wheels if you like.
  • Ignore the other settings for now!
Enter the wheel diameter, measured in milimeters. (1 inch = 25.4 mm)
  • Download the program to your robot and run (Yes, it was that simple!)
  • Follow the on screen instructions. Once it says <<Enter>>, you should hold it upright with its wheels touching the ground. Press the orange enter button and let go!
    • Your Segway may drift a little backwards or forwards and then come to stand still. That’s okay.
    • You shouldn’t try to hold the Segway, unless it is about to fall, of course. Holding it makes it unstable!
    • Triple check you’ve put the cables right!
    • (I’ll add more possible problems to this list when you find any, so let me know!)

5. Skipping Calibration

Calibration of the HiTechnic sensor is actually just finding the average sensor value. This average is different for every sensor but also depends on your NXT, the sensor port, and temperature. But once you find the value for your sensor, there’s no need to calibrate next time you start the Segway. To learn how to skip calibration, follow these steps:

  • When you ran the program in step 4, the NXT screen displayed something like: Average: 593.82 — with a different value, of course. That value is unique to my sensor. If you forgot what it was, just run the program and write it down somewhere.
  • Look again at the ‘StartUp’ block. Enter the average value you found in the “Average Gyro Value” box.
  • Delete the Calibrate Block. Your program should now look like the one shown below.
  • Save and run the program again. It should do exactly the same as before, but skip calibration. So hold it up right with the wheels touching the floor, press enter and let go.
Enter your average sensor value (not the one you see here, but the one found in step 3) in the highlighted box, and delete the Calibrate Block.

6. Moving, using other sensors, and avoiding objects

Hooray! If you’ve made it up here then you’re probably good to go ahead. This step will show you how to control your Segway to move about.

  • Take another look at the overal program structure at the top of this page. Notice that in the basic program you just ran, there wasn’t a lot going on in your custom control task.
  • For instant fun, run the “AnywayHT-Avoidance” program that you downloaded previously.
  • You control the Segway by setting values for the ‘steering’ and ‘speed’ variables. The avoidance program illustrates this.
    • Recommended speed is between -30 and 30. Negative numbers mean you go backwards. It will stand still on 0, and go forwards on positive speeds.
    • Recommended steering is between -5 and 5, where negative numbers indicate a right turn, 0 is straight ahead and positive numbers are left turns.

  • Important limitations:
    • You must not use regular Wait for Sensor blocks! They consume too much CPU power and your Segway becomes unstable. Instead, use a Loop Block configured as a sensor with a normal Wait Block in it. This is shown in the example.
    • Do not use Motor Blocks or Move Blocks to control motors B and C. You can use the Rotation Sensor Blocks, however you shouldn’t use its reset function.
    • Always leave at least one Wait Block in the main Loop Block as you’ve seen in the basic example program.
  • Come up with something creative. Make a Segway that follows lines, delivers drinks, picks up the mail, does your homework… And let me know!

The following video shows the Anyway in action. (The program on this robot is slightly different and it is using a different sensor, but overall the behavior is the same.)


If you find any mistakes (even typos!) on this page let me know in the comments so this page can be made as clear as possible. Feel free to ask for help too, or share your own discoveries. I’ll add some of your questions to the troubleshooting section. If you help answer other people’s questions, you’ll make my day!

About the author

138 Responses
  1. james

    i have a problem, after following the intruction the NXT robot dont work properly, all i can see is just the two wheels keeping turning again and again. what is the solution?

    1. James,

      Can you specify your problem? Are you using the HiTechnic sensor? Are you having problems in step 4? Carefully follow these steps. Holding it up right when you start is important.

      “Follow the on screen instructions. Once it says < >, you should hold it upright with its wheels touching the ground. Press the orange enter button and let go!”


      1. james

        i use the hi technic accel sensor. The problem is that after press the orange button, i can see ” what will you make” and then the wheels start to run in the back direction during few segond, and then everything stop and i can see a sad face on the screen of the robot

          1. james

            laurens can you help me, i would like to unederstand the logo nxt program, have you got a document or someting, a document witch could help me to understand it in details? thank you in advance

          2. James,

            You can’t use that acceleration sensor if that’s what you’re trying. To better understand the program, I recommend that you read the C version of the code, located here.


  2. james

    Laurents thanks for all your help. i followed the instruction for the robot and when i turn it on he is just going back and set the “crash exit” page, iam using the hi technic compass sensor, do you have a idea?

  3. Ernesto

    i use the Hi Technic Gyro sensor. The problem is that after press the orange button, i can see ” what will you make” and then the wheels start to run in the back direction during few segond, and then everything stop and i can see a sad face on the screen of the robot.

      1. Ernesto

        Hello Laurens. Thanks for your answer. Finaly a find the problem: the Gyro sensor must be instalet in 90º position in order to mesure as “horizontal” angle the vertical angle from de robot. Now it works well ! Thank you very much.
        I think this is te same problem from other people that explain the same symptoms.
        ¿You know if there is in the market some other sensor with 3 axis instead this from HiTechnic that use only one?

        1. Ernesto,

          Glad to hear you figured it out.

          The instructions do say that (“Once it says < >, you should hold it upright with its wheels touching the ground”), but I agree with you that this is not entirely clear. I think I’ll add a picture some time soon.

          Thanks for the input!

          The Dexter Industries Gyro supports three axes.


      2. Paul

        Hello laurens
        i have the same problem, but after i press the orange button i can see ” what will you make” and then only one left wheel start to run forward in during few second, and then everything stop and i can see a sad face. i tried to mount a gyrosensor parallel to and perpendicular to a longitudinal axis of the robot but its not balancing

        my average Gyro value is 620,4 all cables connected correctly

        Best regards.

        1. Hi Paul,

          I hate to say it, but a single motor moving does seem to indicate a problem with the cables. So check these, and try running some other program to test your motors (B and C), to see if the motors are not broken.


          1. Paul

            Hello Laurens
            Thanks for answer. The problem was that the cable was damaged and now all is working perfectly. Thanx for great project!

            Best regards, Paul.

  4. Bob-2

    Hello Ernesto and Laurens!
    I faced a similar problem – the robot movement is only to back and refuse balancing. Please specify as it is necessary to mount a gyrosensor: parallel to or perpendicular to a longitudinal axis of the robot? In other words, how it is necessary to change the sensor position, which is shown on the first image on page http://robotsquare.com/2012/02/12/tutorial-building-segway/?

  5. Ernesto

    Hello Bob-2. I solve the problem mounting the gyro sensor with the white part 90º to one or other face (is the same), not in up or down position, paralel to the flour.
    You can see my robot in facebok. Search for Lego MindStorms.
    Best regards.

  6. james

    hello laurens
    thanks for all your help. I would like to know if it’s possible to translate a nxt program file into a 3dxml file to make it work into “catia v6”.
    and do you know if there a web site where i could find some 3dxml robot program file, juste the program file to know how the 3dxml work. thanks for your informations.

  7. Martin Buhelt

    Hi Laurens

    Great project – thanks!

    I do however have a problem with the programming. I have installed the Gyro Sensor Block from HiTechnic and I have created a new profile – Segway – and proceded to section 4 in the description above. When I open the “AnywayHT-Basic(ContainsMyBlocks).rbtx” I get the error “LEGO MINDSTORMS NXT encountered an error opening the program file at “C:Documents and SettingsMartinMy DocumentsLEGO CreationsMINDSTORMS ProjectsProfilesSegwayAnywayHT-Basic.rbt”.”.

    Please advise!


    1. Martin Buhelt

      Further info:

      It seems that some of the “My Blocks” does not get installed correct. For example I can not place a Calibrate, PID, ReadEncoders or SetPosition block on the Sequence Beam.


      1. Hi Martin,

        Do you have the NXT 2.0 software? Try deleting all programs related to this project and try opening the rbtx again.

        Also, you can only add these blocks when you go to your newly made profile. You have to go there each time you launch the software.


        1. Martin Buhelt

          Hi Laurens

          I tried to use HiTechnics version of the software and this also failed. Then I installed the NXT 2.0 software on another machine, and everything went well. I haven’t investigated further.

          I am now finally having fun with your machine, thank you!


        2. Chuck

          I get the same error message as above but it continues to load but I see what I assume are broken blocks – http://screencast.com/t/AywjayyBzD . I am not sure what you mean by deleting all programs – does that mean the program I just tried to load? That is the only rbtx file in the Mindstroms projects structure? This is my first attempt at loading this code. I created the Anyway profile as suggested, then I open the AnywayHT-Basic(ContainsMyBlocks)file and I get the error message. WHat else can I try?

          1. Hi Chuck,

            Yes, they are broken blocks.

            RBTX files are what you get when you make a program with multiple My Blocks, and you click Tools/’Create Pack and Go’. That creates a file with everything in it, making it easy to share.

            Just opening the RBTX with the LEGO software should put every sub file in the right place. The problem is that some browsers recognize RBTX as a zip package. Save the RBTX to your computer first, and open it with the LEGO Software. This usually resolves the problem.


    2. P8r

      I had the same problem. In my case McAfee All Access Total Protection was the cause. It somehow interfered with the Mindstorms program. Switching of the virus scanner helped, but is not a good idea. I added ‘MINDSTORMSNXT.EXE’ to the list of files not to be scanned on access. This, for me, resolved the matter. (with a lot of help from Mindstorms Support Europe).



  8. Zo

    My lecturer at university has asked if I can build and program one of these to show the earlier years some robotics and get them interested in the course. Unfortunately we use LABView with the NXT plugin, and it doesn’t recognise rbt or rbtx files, only vi’s. Would anybody have the code in vi format or even some sort of pseudo code so that I can try and rewrite it?


    1. Hi Zo,

      You may want to check out the C-like version of the code which is much easier to read than these NXT-G programs. See here.

      That you can read as the pseudo code. That was how I developed and debugged it until it worked. Only then I translated it to this graphical language. (It’s a real pain to make and test large programs in the standard software, so this was more effective).

      If you rewrite the code in Labview, please let me know if you want to share it on this blog.



  9. will

    trying to use link for dimu program and it took me here and the program wont work, i read everything but it still wont work, what do i do for dimu anyway program!?!?!?!?

    1. James Summers

      What to you mean by “wont work”? Does it not download to the NXT? Will the robot not stand? Will it not stand still? Does it not drive?

      Clarification is needed. Please be specific about what does not work.

      1. Will

        The robot will not stand because when I am starting the program it just makes the motors go backwards instead of balancing
        Take note: I am using dexter industries dimu gyro sensor
        Please help!!!

  10. Bert Lindeman

    Hi Laurens, real fun this anyway, thanks for that.
    Your NXT-G programs work at once. Great.
    Have been fiddling with it and got a working version that’s controlled via the HT-Infrared receiver.
    Looking at the myblocks “Calibrate” and “Gyro read” the gyro-sensor looks like a touch-sensor with one extra output. I swapped “your” gyro-sensor with the one from HiTechnic.
    I used the “raw-value” output from the HT-block. The average reported by the Calibrate block is negative? e.g. -2.02….
    After that I could not get the anyway in balance. *Is* your gyro-sensor block meant to be different from HT’s? In short I do not understand. Regards, Bert

    1. Hi Bert,

      Thanks, that’s great to hear.

      The Touch Sensor and the HiTechnic Gyro are analog sensors. This means that the NXT reads a value between 0 and 1023, depending on the sensor value. All Analog Sensors are read in the same way.

      This is opposed to digital sensors, which actually communicate with the NXT with digital messages (I2C) like the UltraSonic Sensor.

      Now, the HT Gyro reports a value around 600. If 600 is the average measurement, 601 would mean a falling rate of rougly 1 degrees/sececond backward. 594 would be 6 deg/sec backward, or -6.

      Since all analog sensors are read the same way, you can just read the Raw Touch Sensor value, which is that value between 0 and 1023. I did not use the HiTechnic block to make it easier for users to quickly use this program. Also, I wanted the real value from the sensor so it would behave the same as my older Segway programs. The HT block appears to do some pre-processing. Maybe it subtracts that average reading for you already.

      Hope this clears things up.

      Best regards,


  11. didier


    I am french

    very good idea this blog


    please , I buit and try it ; OK ;
    but it goes always slowy ( speed 5 ?? ) towards until I put my hand in front ; then it goes forward then toward , etc …

    and after whitout my hand in front it goes always forward slowy ( about speed 5 ?? )

    it is strange ? I thought it had to stay at the same place ( about ) ???

    thanks for your help to understand what is wrong ?



    1. didier


      So Sorry

      everything good
      it works like the program is built ;

      I put speed 0 at the beginning of the back loop
      and the robot stay on the same place ;


      please , did you tried to do a motor bike ?



      1. Bon Jour Didier!

        Great job that you solved your problem. I haven’t tried a motor bike yet. There’s so many cool things to build, but not enough time! 🙂

  12. lacourt

    hello, i’m french user of NXT,

    when i have open your nxt programm an error message is Appeared.

    I haven’t all the blocks who are used in this program.

    Could you help me?


    1. Franz-Josef

      hello lacourt.

      Obviously, I have just had the same problem like Martin Buhelt above and you.
      First, I created the new profile “Anyway” in my NXT 2.0 software. Laurens delivered the Anyway Basic and Anyway Avoidance programs.
      I extracted it in an separate download folder.
      I first opened under my profile tghe program “Anyway Basic”. NXT software seems to copy the main Basic .rbt into the directory C:User\DocumentsLEGO CreationsMINDSTORMS ProjectsProfileAnyway and also extracs the subroutine blocks (my blocks) in the same directory as *.rbt.

      When I opened the second program “Anyway-Avoidance” from the separate diretory the subroutine blocks were show broken. I think the NXT software has a bug when opening a new program in the same profile and the subroutine blocks are already extracted in the profile directory (in my case from the “Anyway Basic” program), then it show these blocks broken.

      I found a workaround:
      Just copy the (second) main rbt-program file directly to the above profile directory and open it via the NXT software from this location. So that the software already finds the main rbt-program an all subroutine blocks (from earlier opened program) in the same directory. Maybe it was a bit complicated, but it seems to work 🙂

      Btw. thank you very much, Laurens, for your great work.
      I will try to add bluetooth control to the control thread.


      1. Hi Franz-Josef,

        Great to hear you got it working.

        It was my understanding that opening the avoidance program *after* you open the one with My Blocks should work, but apparently that’s not the case for all installations. Thanks for informing me about that.


  13. biomedical degree

    I will right away take hold of your rss feed as I can’t to find your e-mail subscription link or newsletter service. Do you’ve any? Kindly allow me recognise in order that I may just subscribe. Thanks.

  14. Henk

    Hallo Laurens,

    Fraai stukje werk deze segway. Goede instructie ook, had em binnen de kortste keren werkend. Doe als docent natuurkunde af en toe binnen nask of techniek wat eenvoudige robotprojectjes met de kids. Voorbeeld software is daarbij een enorm hulpmiddel. Heb echter wat moeite de segway software te ‘lezen’. Met name de ‘straight-steer’ module kom ik niet goed uit. Ik neem aan dat hier de instructie voor een kwart slag draaien ook wordt verwerkt. Zie alleen niet precies hoe.
    Heb je toevallig uitleg beschikbaar over het lezen/begrijpen van je programma’s?


    1. Henk,

      Bedankt. Fijn om te horen dat het meteen werkte.

      Ik raad je aan deze code te raadplegen. Dit is als het ware het origineel (klik). De NXT-G versie op deze pagina heb ik gemaakt op basis van mijn eerder gemaakte RobotC code. De RobotC versie is wat makkelijker te lezen.

      Als de Segway balanceert draaien beide motoren met een snelheid x, in principe dus even snel. Door de ene nu op x+5 snelheid te laten draaien, en de andere op x-5, stuurt de Segway. Het aardige is dat dit geen invloed heeft op de balans.

      Bij vooruit rijden, draaien de motoren niet altijd even snel doordat de ene soms meer wrijving heeft dan de andere. Dat is goed te zien in delen van deze video, waarbij de straight steer module nog ontbrak.

      Als de robot vooruit gaat, gaan de motoren in de praktijk dus niet even snel. Hij gebruikt dan het principe van sturen om dit te corrigeren. Dat doet de straight steer module.

      Zodra de gebruiker aangeeft rechtuit te willen rijden, worden de huidige waarde van de encoders onthouden. Vanaf die waardes, moet de afgelegde weg van beide motoren gelijk zijn. Als dat niet zo is, wordt dat gecorrigeerd door te sturen.

      Het sturen zelf is puur het bovenstaande x-stuur en x+stuur verhaal. Hierbij wordt niet naar de encoders gekeken.

      Ik hoop dat je hier verder mee kunt.



      1. Henk


        Bedankt voor je duidelijke antwoord. Ik zal me eens verdiepen in de robotC code. Ongetwijfeld kom ik dan een stuk verder.
        Het lastige zit em denk ik ook in het feit dat de motor zowel motor als rotatiesensor is.


  15. jeb

    When ever I try to open the myblock files as you specify, I get an error. Saying it can’t open the file. I am running the NXT-G education version 2.1

    1. jeb

      Got it, had to create a profile and put them in the MyDocumentsLEGO CreationsMINDSTORMS ProjectsProfiles
      before I could do anything with them. Normally I can open programs from the desktop no problem

  16. Adam Pinter

    I’m impressed with your work, and the robot is awesome! I downloaded your program, and it works fine. But i’m new with the nxt programming, and i don’t clearly understand everything inside the program. Especially the balancing task. Could you please write some deeper specifics about what each block does? It would really help me understand the program.
    Thank you very much!

  17. David Green

    WOW! Thank you thank you thank you so much for sharing this project with the world!

    And bless you for being patient enough to code this in NXT-G! I enjoy your PID implementation 😉

  18. Matt

    I’m student from Poland and i really need your help. I have to create a Robot Soccer program in NXT-G. It has to work with IR Ball and turn in to right direction using compass sensor. First wheh it detect the ball with IR Sensor he go to the ball and stop when he is in front of it ( using ultrasonic) then it has to turn using commpas and go forward to the goal. Please help me!

  19. DrDevinci

    Got some stability problems.
    Download and compilation OK. Robot does balance but is extremely sensitive to perturbations, much more so than what’s shown on the video. What gives here?


    Running NXT 2.0

  20. Dimi

    Dag Laurens,

    Ik zou graag een segway maken om het principe van een PID regelaar mee uit te leggen in klas. Ik heb een Dexter DIMU en een Mindsensors IMU-ACG ter beschikking, maar geen Hitec gyro sensor.

    Is er een NXT-G programma ter beschikking? Werkt NXT-G niet goed met deze sensoren? Of kan ik mits enkele kleine aanpassingen toch uw NXT_G programma gebruiken?

    (Ik heb geen robotC software, ik kan wel de 30 dagen proef downloaden, maar m’n studenten zullen te veel afgeschrikt worden door de c code vrees ik. De NXT-G code zal voor hen overzichtelijker zijn. (Als ik niet te diep in de my blocks ga))

    Alvast bedankt voor uw mooi werk op deze site,

    1. Ik kreeg de NXT-G versie helaas niet aan het werk met de dIMU sensor. Het NXT-G block gemaakt door Dexter Industries is niet snel genoeg, en het geeft foutieve sensorwaarden.

        1. Ja, maar tevens alleen met RobotC. Ik heb ondersteuning voor die sensor toegevoegd in de laatste versie.

          De code in NXT-G is in weze hetzelfde opgebouwd als de RobotC code. Je kunt de NXT-G versie misschien laten zien in de klas, en de RobotC versie gebruiken voor de echte Segway.

  21. Haroun

    Hello Laurens,
    I’m a french student and I’m working on the segway. The problematic of my project is “How does the segway balance despite it gots only 2 wheels ? ”
    The program is working very well thanks to your tutorial, but my teacher ask me to give more details of the important blocks in my report. The program is very difficult to understand even to my teacher so if you can help me it would be very nice.

  22. david

    hi Laurens
    I made your segway and it works very well,
    thank you. I took it a step further and
    used the HT IR receiver with the 8885 remote.
    It works nicely and the program overides the
    remote if nesesary. Once again thank you for the
    ANYWAY. Please write back,

  23. Jordi Alonso

    Hi Laurens,
    Thank you very much. We,ve learned a lot with these pages. Finally I bought a mindsensor IMU ( 3 axes -gyro ,acc, & Compass) for my kid ( Marti – 11 years old – he isn´t bad although PID control & gyro is complex for him ). We are just a little bit disappointed because we can´t work with your program. We put the IMU in diferent possitions but it can´t balance the robot. In my opinion is because the mindsensor IMU has a large resolution ( I guess is 200º/seg from factory ) and the filter is in position 4 not 7 ( maximun filter).
    What is your opinion ?. When we calibrate in the first step the average gyro value is erratic ( -24,…, -45,5) although we let the robot horizontal without touching it.

    Some ideas?.

    Thanks a lot.

    Jordi & Marti

    1. Well, the program on this page is for the HiTechnic sensor only. To use the other sensors, follow the RobotC segway tutorial. (Tutorials > Programming > RobotC)

  24. Dimi

    Hi Laurens,

    Thanks to your tutorials, I was able to make a cool ir-remote controlled NXT Segway. I made a short movie on youtube: http://www.youtube.com/watch?v=GVB77-A_q58&feature=youtu.be

    If you are intersted to share my slightly adjusted RobotC program on your site, let me know. (I added the ir-remote control and used the lightsensor to signal the way the robot is moving. He also tells where he is going to.)

    Thanks for the help,

  25. quinten

    we don’t have a gyroscope from nxt. but we do have a light sensor does the program work with that or can you tell me how we can make it work with a light sensor

  26. Tom

    Hi Laurens,

    I have built the Gyro Bot and downloaded the Anyway HT program. After I have entered in the Gyro Avg of 1023 (does that even sound right?), and deleted the calibrate block. Once I run the program I get this message: ” what will you make” and then the wheels start to run endlessly. Any tips on what I may be doing wrong.



      1. Tom

        Thanks, Laurens. I did that, re-entered the new avg Gyro Value, and completed the download. Now the robot wheels just spin continuously (while I hold the bot upright). If I tilt the bot to far one way the wheels stop, then I get a sad face. Not sure what I am doing wrong.

        Again, Thanks for you help.

        1. Tom

          Hi Laurens,

          I am still having the same problem with the bot’s tires continuously. The Bot will not stand tall on its own. Any help troubleshooting what might be going wrong?



  27. adrian

    Where I can find any explanations about the equations used ?
    How you deduce all those parameters ?
    Is there any mathematical, phisical thinking in background or is an intuitive way?

  28. stelthy cat 129

    does the robot degsin have to be the same I used a different one and it didn’t work

    ///p.s. call me stealthy

    1. It doesn’t have to be exactly the same, but I recommend that you start with the exact design first. When you get everything to work, start making modifications as you like, remembering to test every time you change something important.

  29. Peter Nuessmann

    I built it the exact same way as the instructions say but I cant get it to stay

    ///ps how many mm are the motor scycle tires

  30. oliver cozens

    Hi Laurens,
    Your Segway works beautifully.
    I would like to control it remotely with the Lego endorsed Minddroid Android smartphone. It seems that the gyro sensor somehow interferes or competes with controls. Is there anything I can add to the basic NXTG program to combat this?
    Many thanks

    1. Hi Oliver,

      They key is that you should not control the motors directly, because the program is actively controlling the motors to balance.

      Instead, you can drive by modifying the values in the steering and speed variables, as described in section “6. Moving, using other sensors, and avoiding objects”

      So you’ll have to find an app that sends values to the program rather than direct motor control signals. Then in your program, use those control signals to modify the speed and steering variables.



      1. oliver cozens

        Thanks Laurens. Rather than reinvent the wheel, I don’t suppose your know of an Android app that already exists that will do this?

  31. NXT Segway

    Hi Laurens,

    the Balancing work perfect, but i would like to control it with the light sensor. The SW should drive on a black Line. But when I manipulated the speed and steering variable nothing chanched? Can you give me some tipps?

  32. huant

    Why is in the calibrate block aswell as in the gyroreadblock not the gyrosensor but the touchsensor at input 2?

    got it in your answer 7. August 2012
    ps that pid in next-G is awsome

  33. Ian

    Well Laurens this is amazing, worked right away with no problems. Was a little stumped by the touch senor block but read why you had done it this way so I think I understand. I have different design I found several years ago and it works well with your program. There was another person asking about Android wireless control this can be found here. It works well on my phone and mu version of the segway


    If this fails then try and google this.

    HiTechnic Segway Remote – Android apps on google play

    Laurens you are also talked about here.


  34. Jimmy

    Your code worked perfectly, many thanks!!!
    I saw a video of a robot riding a segway simulating turn left and right, but I lost the link and can’t find it anywhere.

    Thanks again!


  35. Niklas

    Hi Laurens,
    I would like to program a Segway, but I have not the HiTechnic gyroscope but the gyroscope of the MIND SENSORS (Absulute IMU ACG). I also have no RobotC otherwise I would use this. So I ask you could you help me?

  36. Ajay Chitnis

    I wanted to add a braitenberg vehicle #2b type program in parallel with the segway program (using HiTechnic sensor) and the avoidance program. Is this too ambitious using Nxt-G.
    I would love some guidance on this.

  37. Ian McKay

    Has anyone developed the NXT-G code to work with the DIMU sensor yet? I have been trying but no success so far. It would be great if someone could share this.

    1. I couldn’t get proper sensor values from this sensor in NXT-G. It would randomly jump between 0 and 4. The sensor works fine in RobotC, so I think that the NXT-G block developed by Dexter Industries has some problems.

  38. Nxt7

    Hello. First of all, I followed the steps on HiTechnic’s website to download the block for the gyro sensor, that didn’t work. I also extracted the files in the sample programs folder, and opened the program with the myblocks, like the instuctions, yet then NXT-G says:

    LEGO MINDSTORMS NXT encountered an
    error opening the programs at “C:
    UsersInsertNameHereDocumentsLEGO Creations
    MINDSTORMS ProjectsProfilesDefaultAnywayHT-Basic.rbt”.

    It says that, even though I did extract them. I have Vista, there is no “unzip folder” option, just View, Open, and Extract.

    I just do not understand what the problem is.

    1. Hi Nxt7,

      You don’t need to download and install the Gyro block from HiTechnic.

      First download and open AnywayHT.zip. You should see three files (AnywayHT-Avoidance.rbt, AnywayHT-Basic(ContainsMyBlocks).rbtx, README.txt). Just drag these files to a place like your Desktop. This is the same as extracting or unzip.

      Then open AnywayHT-Basic(ContainsMyBlocks).rbtx with the NXT software. This will automatically install the My Blocks in the right location.

      Let me know if that helps. The problem is sometimes that Windows confuses the *.rbtx file to be another zip archive, and then it goes wrong.


      1. dibor32

        Now it works. It seems to be a problem of the version of the Lego software. The software, I downloaded from the Lego Homepage, didn’t open the AnywayHT-Basic(ContainsMyBlocks).rbtx. Then I tried an older version (the origanal one of the Mindstorms box and it works.

        1. Cristhian

          Marissa MacLeod : Great job! Katie looked so betuuifal and you really captured it so well! Can’t wait to blog about these and add them to the real weddings section on the Solutions web site!

  39. Asim


    I am having a problem to get the program to work.

    I followed all the instructions, ran calibration got value of 600.44, entered it manually and deleted the calibrate block.

    re compiled the program and downloaded tot he brick. Now when I run the program, both wheels are just turning non stop. They never stop!!!

    The only thing I can do is to hit the enter key and stop the program.

    No idea whats going on.

    Please advise.


  40. Geert-Jan

    Bought a HT-Gyro from eBay, downloaded your program, build the AnyWay bot, pressed run and ……. happy!!!

  41. Frederik

    Hello Laurens,
    We downloaded your programm and start it, but then we have got a problem. When our NXT fall down, the motors begins to run, but they doesn’t stop before it show a sad smiley and stop everything (programm is done).
    Please advise.

    Your sincely

  42. Mauricio


    When I tried to follow the instructions kindly provided by Laurens, the system displayed the error “LEGO MINDSTORMS NXT encountered an error opening the program file at “C:Documents and Settings…My DocumentsLEGO CreationsMINDSTORMS ProjectsProfilesSegwayAnywayHT-Basic.rbt”.

    Notice that I’m running the app under Windows 7, 64 bits. By the way the installation was carried out by using the standard CD provided with my the set 8547. Installed NXT version: 2.0.

    After spending some time researching on the web with very little success, I found out that by changing the running parameters of the file MINDSTORMSNXT.EXE it worked perfectly.

    What I did (apologize for the lack of accuracy in terms ’cause my system is displayed in a language package different than English)

    1. Go to C:Program Files (x86)LEGO SoftwareLEGO MINDSTORMS NXT
    2. Right click on MINDSTORMSNXT & select Properties
    3. Select tab “Compatibility”
    4. Press the button at the bottom (Change settings for all users…)
    5. In combo box “Compatibility mode”, select Windows 7
    6. Click on check “run as administrator”
    7. Click “Ok” twice

    Now my programs are running smoothly.
    Hope it helps.

    Best regards,

  43. Sebastian

    It’s a shame you didn’t say anything about the controlling cycles of the balancing part. Is it just a fine-tuned PID or more?

  44. David Nicolson

    after extracting the AnywayHT-Basic(ContainsMyBlocks).rbtx file and adding it to my blocks it says there is a problem opening the file because of some missing files. also if I just bouble click the file opening nxt-g all the my blocks open in the programe but are broken.
    can you please help me get them loaded correctly.
    thank you in advance for your help,

  45. FineWhine_

    I got a few questions, hope you can answer me I need it for school :/. Why do you divide the diameter of the wheel by 84? And what does your OwnBlock VarWait? Does it just wait until the time of dt is fully used?

  46. Brad

    Hi Lauren. Thanks for your video! I helps me a lot.
    But Unfortunately, We don`t have gyro sensor, so we are using light sensor instead, and it works. Anyway we want to make our nxt robot go straight, and we tried many times but it doesn`t work. When i added the function that robot goes, it stopped self-balancing and it falled down. Do you know how to make it go straight while self – balancing?? Thanks a lot

Leave a Reply


EV3 Discovery

Discover the many features of the EV3 set, and learn to build and program your own robots! Learn more

Start Building Robots


Website Maintenance

Robotsquare is currently being updated, which means that it may look a little different (and not very polished) for a while. All the content and pages should still be there, though. It should be back and fully operational soon. Thanks for your patience!