We built and programmed a robotic arm. It worked by rotating 3 different motors in response to the buttons being pushed on the lego brick. So the operator would push the left button and the arm would rotate to the left and so forth for right, up, down etc.
Here is the code involved. The commented code is for rotating the robot arm to the left, rotating the robot arm to the right is very similar it only changes the direction of the motor and waits for commands from a different button. This is a very good example of students learning how to use WAIT blocks. In effect they are “Do Until” commands.
This is a program that randomly produces a number and then this number is entered into the robot by clicking a button the appropriate number of times for each digit. If the code is entered correctly then the safe door is opened, if not then the safe stays closed. Some of the concepts that are covered in this lesson are random number generators, variables, wait blocks, loop interrupts, math blocks, comparison blocks and switch statements. The code could be modified to use a hard-coded secret code that is not displayed, so only the person that knows the code could open the safe. The code is quite extensive, so I split it into 3 parts that follow sequentially.
I’ve been trying to come up with a design for a walking robot that is relatively easy to build and modify for some time. This is the result. The code for this is very straight forward, basically just a loop with a move steering block.
Remote Control Robots
We constructed some remote control cars and engaged in some robot battles. The code consisted of two components a sender module and a receiver module. The sender robot would send a message to the receiver robot which would interpret the message and perform the appropriate action. The robots used Bluetooth as a communications protocol.
As you can tell from the name, this week we built a useless machine. It doesn’t do an aweful lot, but the code and build are surprisingly complicated. The machine is a switch that when the user tries to flick it, then the robot automatically returns it back to the original position. You can download the building plans from here.