Make ultimate 2.0 work with microswitches


I cant seem to make the ultimate 2.0 with mega pi control board work with a makeblock microswitch. My idea is to play a game of tag in a closed arena. The robots have to push a microswitch on their opponents robot to tag them out. I want the tag to turn on the string of lef lights that came with the kit. I have the string of led lights and the microswitch plugged into slots 1 and 2 of the adapter board. Then i plugged the adapter board into slot 8 of the megapi.
Its the code im not sure of. I used a repeat until loop. The command line reads “repeat until limit switch port8 slot 1 =1”. The operator part of the command “=1” is in green. The “limit switch port8 slot1” is blue and nested within the green “=1” block and they’re both nested in the gold “repeat until” block. Within the repeat until loop are some motor speed commands. Below the loop are two “set encoder” commands that set the drive motor power to zero. Help

anyone! My kids cant start the competition until i figure this out!!!


Hi Moses,

Your program looks okay.
First, you may check the way how you connect the small wires to the micro switch.
If you connect like this way, the output is 0 when press the key and is 1 when unpressed.

If you connect like this way, the output is 1 when press the key and 0 when unpressed.

Secondly, check if you have connected the MegaPi to a battery and if the power switch on MegaPi is pulled to ON.

LED strips

I have a successful micro switch system setup as follows:

  • The aim of my setup is to know when the robot arm is at the top or the bottom
  • in the first image below I have shown the back of the robot (and micro switch slot 1 is circled in yellow)
  • For what it’s worth, I used Port 6
  • Like you, I also used slots 1 and 2 of the RJ25 adapter
  • My code is different to yours but it certainly works (see second image)
  • I use the “not” function but that’s simply because of the polarity of my wiring
  • Also, you will notice that I don’t equate my input to “1” … I worked for hours to get my code to work, starting with the same assumption that you did that the limit switch had to equal “1” or “0”. So see if my coding principle works for you too… let me know how you go!


any chance u could help me understand how to attach 3 limit switches to a megapi through the rj25 shield. im looking at having a limit switch on min and max XYZ


Hi, I could only get two limit switches per RJ25 shield, so you will need a second shield to get three (or four) limit switches


were you using micro switch A or B?
I am thinking it is only the bracket that is different.