Now you may be wanting to turn your robot on and off with the push of a button. The Arduino itself will run code in an endless loop until you unplug it, which can be quite frustrating when you plug in your robot on the table and it starts running away from you! Integrating the button is a great step in this process because you'll also learn how to use buttons for other things, like creating a bumper to detect when the robot hits a wall.



As a note, you'll notice I removed the servos from the solderless breadboard for most of my pictures. This just helps make the image more clear when I'm showing different steps.



1. To begin, disconnect power from the servo motors before doing any more work. Remember to do this every time you add something to this project.



2. Now you may want to be able to turn your robot on and off as opposed to having the robot immediately start moving when you connect the power.



3. Identify a strip on the opposite side of the solderless breadboard to be power for on/off button (and later the sensors).



4. Using a long jumper wire connect the power (+5V) from the Arduino to the strip you just identified.



5. Connect two jumper wires to the momentary switch and plug one end into the (+5V) power



6. Plug the other end of the momentary switch into a smaller strip in the middle of the solderless breadboard.



7. From that same strip connect a 10K ohm resistor to the strip and the other end into ground



8. Finally, connect a wire from the strip with the switch and the resistor on one end and place the other end in digital input 7 on the Arduino.



9. Now, with the code you should be able to use the button to turn on and off the robot. If you use the code with the LED (digital output 13) you will see the on-board LED turn on and off with the robot. This is a great way to test the Arduino code if you have the power to the motors disconnected.