The Raspberry Pi is an extremely useful mini computer. The one I have (The Raspberry Pi 3 Model B) has 4 USB ports, an ethernet port, built in wifi, and HDMI out. It may not be the fastest computer around, but it’s definitely small and versatile. Today, I’ll show you how to use a cheap Raspberry Pi as a simple desktop computer to program an Arduino for robotics and other tech projects!
4. Plug in the power adapter and the chip will start up.
5. To program an Arduino with the Raspberry Pi, you will need to download the Arduino IDE so you can upload code to the Arduino. Read this article to learn in-depth how to install Arduino IDE on raspberry pi and connecting various arduino devices to it.
6. Click the terminal button to open the terminal. This is where you will type in the commands for downloading and installing the Arduino IDE.
7. Type “sudo apt-get install arduino” and press enter. Eventually, you will need to learn the commands used in the Terminal.
[vc_row][td_block_ad_box spot_id=”custom_ad_1″ spot_title=”- Advertisement -“][/vc_row]
8. Type “y” and then hit enter. You have plenty of space on the Raspberry Pi right now so this isn’t something you need to worry about yet.
9. Once that finishes, you are ready to upload code to the Arduino! Connect the Arduino and the Raspberry Pi together with the USB “A” to “B” cable.
10. Open Menu -> Programming -> Arduino IDE
11. Once the program has opened, go to Tools -> Serial Port -> and select what is there. There should be only one option right now. If there are multiple options, trial and error is ok.
Wouldn’t it be cool to have a house with futuristic technology, where everything is automated or computer controlled? Well, here’s a couple ways to rig up a little tech and coolness into your life! For both versions of this project, the same Arduino controlled light switch will be used, so let’s make that first.
The ultrasonic sensor’s trig pin is connected to pin 2 on the Romeo board, and the echo pin is connected to pin 3 on the board. Vcc goes to the 5v pin on the board, and Gnd goes to Gnd.
The motor is connected to M2, which means it is controlled by digital pins 6 and 7 on the board.
Building The Frame
You will need to build some kind of frame to mount everything on. I used lumber because it’s easy to work with and I had some lying around. It doesn’t have to be perfect unless you want a professional look, so just put something together and don’t worry.
As long as the center of the wheel is at the same height as the center of the switch, and the switch is between the wheel spokes, it will work fine.
Wiring The Switch
I used a regular lightswitch and just wired it into the hot wire of an old lamp. The hot wire is the narrower prong on the plug. Just cut the hot wire and strip the ends. Do not cut the neutral wire (The wide prong on the plug). On the switch I used, the wire coming from the wall connects to the bottom screw on the switch and the wire going to the lamp connects to the top screw.
DO NOT WIRE THE SWITCH WITH THE CORD PLUGGED INTO THE WALL OR ANY OTHER POWER SOURCE!!! I AM NOT RESPONSIBLE FOR YOU BEING AN IDIOT!!! THE AMOUNT OF ELECTRICITY COMING FROM A WALL OUTLET CAN KILL YOU!!!
If you want to make the Touchless Switch, you are done building! This version is cool because all you have to do is wave your hand in front of the sensor to turn the switch on or off. Plus, think about all the germs not being spread! Time to upload the code and test it all!
Uploading The Code
Uploading code to the board is easy!
1. Download and install the Arduino IDE on your computer.
2. Plug in the board to the computer.
3. Select “Arduino Uno” from the Tools -> Board menu, if you are using the DFRobot Romeo board I recommended.
4. Copy and paste the code from this page into the IDE.
Another option for building the switch is to use magnets to control the switch. This is more for adding that “cool factor” to the project than function.
A Shoe Box
String or Wire
Building The Frame
Attach your magnets to your string or wire. I used wire because I didn’t have any string lying around. Poke a hole in the top and the bottom of the shoe box so you can run the strings or wires through. Tie them off on the outside of the box.
Make sure the magnets aren’t too far apart. If the magnets are too close, all you have to do is tie knots onto the string or wire on the inside of the box to pull the magnets further apart.
Once the magnets are attached to the box properly, stand the box up and hang the bottom magnet from the top one. Poke a hole in the side of the box at about the height of the top magnet. Run the wires for the ultrasonic object detector through this hole and then attach the sensor to the wires. Position the sensor so it is aiming at the bottom magnet.
Afterwards, follow the steps above to upload code to the board, but use this code instead:
The most crucial part of any mobile robot is the ability to avoid obstacles. What good is a robot that just runs into everything? Thankfully, object avoidance is an easy goal to achieve. With just a few parts and less than 100 lines of code, anyone can build a basic object avoiding robot!
You’ll need to assemble the frame and figure out a way to mount the board, sensors, and battery. I used cardboard and electrical tape… So unless you’re going for a professional appearance, don’t worry about how it’s put together. However you want to do it is perfectly fine. It doesn’t have to be perfect! We’re just having fun, anyways!
I used a small cardboard box that one of the sensors came in to raise the Romeo board above the wheels, then just electrical taped it to the frame. After that, I made a sensor mount using some taped together pieces of cardboard. The HC-SR04 sensors were also mounted with electrical tape, and I angled them slightly outwards to have more directional sensing. I ended up removing the rear swivel wheel and just letting the rear end slide around. The swivel wheel didn’t swivel very well, so it would get stuck facing one direction and make the robot turn unnecessarily.
Connecting Everything Together
I wired the left sensor’s trigger pin to digital pin 2 on the Romeo, and the echo pin to digital pin 3. The right sensor’s trigger pin goes to digital pin 8, and the echo pin goes to digital pin 9. The Vcc wires coming from the sensors need to be spliced together into one wire and then that wire goes to 5v on the board. The Gnd wires from the sensors also need to be spliced together into one wire that connects to Gnd on the board. The motors just need to be hooked up to the green motor terminals on the Romeo. Left motor to M2 and right motor to M1.
Once, the robot has been assembled, the code can be uploaded and you can test it out!