How to Use Ultrasonic Sensors with the Arduino

I’ve made my first video tutorial! I obtained some SR-04 ultrasonic sensors quite cheaply, and I’ve been learning how to use them with the Arduino, with good results. I’ve created a tutorial covering how to get the proper libraries and how to use the basic functions in the Arduino IDE to interface with the sensor.

Here’s the steps¬†(covered in the video) on how to get NewPing, a library created for controlling ultrasonic sensors, up and running with the Arduino IDE:

  1. Use this link to download the NewPing Library: https://bitbucket.org/teckel12/arduino-new-ping/downloads.
  2. Click “Download NewPink v1.7” and save the .zip file.
  3. Open the Arduino IDE, and go to ‘Sketch>Include Library>Add .ZIP Library’ and then navigate to where you saved the .zip download, and click ‘open.’
  4. Go to ‘Sketch>Include Library’ again and scroll all the way down to the bottom and select NewPing.
  5. The NewPing library will now be included in your sketch.
  6. For some sample sketches and documentation of NewPing, look here: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home#!syntax.

For code sample written in the tutorial, click here.

P.S. – Yesterday was the first anniversary of this blog (this is my 48th post)! ūüėÄ

ultrasonic sensor schematic

Mouse Emulation With an Analog Joystick and Arduino

another view of arduino joystick circuitMy latest mini-project has been hooking an analog joystick up to an Arduino to make my own joystick computer mouse…plus I have some news…¬†my soldering iron

I got a soldering iron for Christmas! YAY! I desoldered an analog joystick from an old PlayStation 2 controller (see my Tear Down from a while back), and bought a joystick breakout board from SparkFun so I could fit the joystick into a breadboard. I originally made my own breakout board using a PCB etching kit, but it just got messy and I decided to save myself the hassle and just buy one.

This is the breakout board I was making for the joystick. It didn't come out too good.
This is the breakout board I was making for the joystick. It didn’t come out too good, as I drilled the holes too big and the solder ran through.

I practiced using my soldering iron quite a bit over the holidays and I feel like I’m finally getting the hang of it! I soldered the joystick along with some old headers from a furnace board without a hitch!

arduino joystick breakout with controller pad
This is the finished analog joystick soldered to the breakout board.

I then wired it up on the breadboard, along with my Arduino Micro (which can emulate a mouse and keyboard, unlike most of the other Arduino boards), an LED indicator light, a toggle switch, and two pushbuttons to act as right and left click mouse buttons. The toggle switch shuts the mouse on and off, and the LED indicates if it’s on or off. I tested it out on my laptop and my Raspberry Pi, and it works great! Certainly it’s more interesting to use a joystick than a regular mouse!

arduino joystick mouse final circuit
This is the finished circuit.

Check out the software on GitHub Gist here. I had some help from the Arduino website, as well as from Jeremy Blum’s excellent book Exploring Arduino.

analog_joystick_bb
Breadboard schematic of circuit.

Designing a Helicopter

Helicopter 2050_459 AeroFish_Image 1_Hand Drawing_Amanda C
My technical drawing of the helicopter design.

Okay,¬† okay, so this is kind of an off-topic post. But it does involve engineering design and materials engineering, so I thought I’d share it.

A couple of months ago, I entered a national competition to design an eco-friendly helicopter of the future. I didn’t win, but I wanted to share what I came up with! I had a lot of fun coming up with ideas, and I learned quite a bit about the physics and jargon of helicopters.

I designed my helicopter to be ultralight, entirely self-powered, and sensor-integrated to increase safety and efficiency. I named it the 459 AeroFish because it’s all-terrain and can easily float on water. The 459 part is completely arbitrary though, it was a random number that I thought sounded good.

The best part of my helicopter is that it’s made of aerogel, a super lightweight gel that’s made of 98% air and is one of the world’s best thermal insulators.

Image of Aerogel from Wikipedia

The 459 AeroFish is powered in two different ways. During startup and sustained lengths of travel, the helicopter uses hydrogen fuel, which is zero emissions and can be derived from the environment. Current methods of mining liquid hydrogen are extremely expensive both monetarily and energy-wise, but in the future hydrogen could be easier to obtain as the collection methods improve.Helicopter 2050_459 AeroFish_Image 2_Elevation Views_Amanda C

The 459 AeroFish’s prime power source, though, comes from millions of microscopic nanogenerators embedded in the aerogel skin of the helicopter. These nanogenerators are capable of converting the vibrative energy of wind turbulence into an electric charge that can power the helicopter’s engine. By reducing the aerodynamic drag on the helicopter, the overall energy required to power the helicopter decreases!

The helicopter has an inflatable pontoon, which can be used to land in water. It also has landing struts that can fold in like an airplane’s to further reduce drag during flight.

The following is a detail drawing I did of my helicopter, including a close-up of the nanogenerators.  This and the elevation image above were created using Adobe Photoshop Elements based off of my original hand drawing.

Helicopter 2050_459 AeroFish_Image 3_Multiple views and nanogenerators_Amanda CBelow is the abstract I wrote about the helicopter if you want to read about the details.

The 459 AeroFish is an extremely lightweight aircraft that is able to sustain its own energy source through the use of piezoelectric nanogenerators and hydrogen fuel cells. Intended for human search and rescue, wildlife conservation, and scientific research, especially in aqueous environments, the 459 AeroFish can land competently on both land and water. It has an extremely large non-stop flying range (approx. 1100 km) and it can dock safely in bodies of water for long periods of time with the help of its inflatable pontoons. Scientists can use the helicopter to conduct oceanic and biological research far out on the open sea, as well as in isolated biomes such as wetlands, islands, marshes, and the arctic. The long range also helps first-responders and military units in major disaster areas carry out sustained search and rescue operations.

The 459 AeroFish is constructed out of organic aerogel (an extremely low density substance made of over 99% air), carbon nanotubes, and six composite rotor blades. The 459 AeroFish’s small form factor, lightweight construction, and turbulence reduction due to the nanogenerators make it as aerodynamic as possible. The AeroFish is also equipped with sophisticated sensor integration and an internet-connected computer information system. Sensors located in the front of the body, in the aerogel exterior, and within the moving parts provide information such as the amount of energy being gathered by the nanogenerators, the stress on the rotor blades, and the condition of the engine parts and electrical system. This data, which is projected in 3D on the helicopter’s windshield, helps the pilot (or autopilot) steer the aircraft more efficiently, budget energy, and determine if parts are in need of repair or replacement before they become a problem.

The 459 AeroFish is entirely self-powered. Piezoelectric nanogenerators provide the main source of energy during the flight dynamic. Millions of tiny nanogenerators are embedded into the surface of the aerogel skin of the helicopter, and they convert the mechanical energy of wind turbulence into electrical potential. Because of its conductive properties, the aerogel is able to store the generated electricity. The nanogenerators not only generate electricity, they also reduce the force of wind turbulence on the helicopter, converting kinetic energy into electric potential.

In order to start up and sustain its power over long periods of flight, the 459 AeroFish also is powered by liquid hydrogen fuel. This fuel is stored within the carbon nanotubule hexagonal exoskeleton, so it does not take up space within the helicopter’s engine or main motor system. Alkaline fuel cells located in the rear of the helicopter’s body generate electricity by converting hydrogen and oxygen into pure water. The water can then be dispelled out of the helicopter, used as drinking water by passengers, or be electrolyzed to form more liquid hydrogen fuel.

Besides its sustainable energy system, the 459 AeroFish’s entire outside surface is made from an inexpensive biodegradable substance called safe emulsion agar gel (SEAgel), a type of organic aerogel. This ultra-light material, with a density less than that of air, consists of air-dried agar, a natural material derived from sea algae. SEAgel is even edible, and is easily replaced should the helicopter be surface damaged. The SEAgel aerogel on the AeroFish contains the nanogenerators and stores their electricity. In addition, due to its heat insulative properties, also keeps the temperature inside the helicopter comfortable for the passengers.

The 459 AeroFish is radically different compared to today’s helicopters. It is designed to be extremely lightweight and therefore require less energy overall. Instead of being made from aluminum alloys and steel, the copter consists mainly of aerogel and carbon nanotubes, making it up to six times lighter than contemporary helicopters of a similar size. The extractable landing struts as well as its overall aerodynamic smooth shape reduce in-flight drag even more.  

The biggest advantage of the 459 AeroFish over the conventional helicopters of today is its combination of a few small improvements that make a vast difference in performance. The helicopter’s energy efficiency and energy sustainability make it emissions safe and zero cost to power. The inflatable pontoon and landing strut combination turn it into a versatile land or water aircraft. It’s computer information system and sensor integration make piloting easier, safer, and more efficient.

Drum Set with Raspberry Pi – Part 1

This is my prelimnary sketch of the drum kit. It's seriously sloppy.
This is my prelimnary sketch of the drum kit! It’s kind of sloppy.

I like music. I like tapping on things with either my fingers or random objects to get a rhythm stuck in my head out in the world. Since my incessant tapping seems to annoy everyone around me, I’ve decided to make my own fake drum set with the Raspberry Pi! I’ll be able to bang on it as much as I want, and maybe it’ll sound more musical than finger-tapping!

I was inspired to make a drum set after seeing some old large cans after my mom had cleaned up the basement a bit, and I figured they could double as drums. I also figured that I could rig my Pi to play audio whenever each ‘drum’ is hit.

I’ve already made a breadboard prototype with all the components, and I have written software in Python 3 that will likely drive the finished project. Since the software is mostly done, now I’m mainly concerned with building the physical project.

This is the prototype breadboard circuit for the drum set. Each button and LED corresponds with a drum.
This is the prototype breadboard circuit for the drum set. Each button and LED corresponds with a drum.

Here’s some details and components about my drum set:

  • Raspberry Pi: Since this project doesn’t require much processing power and I need at least 20 GPIO, I’m most likely going to use my B+ unless I can obtain a Pi Zero soon.
  • Four RGB LEDs: These will be placed inside each drum and will be constantly lit when the kit is in use, and will change color every time the drum is hit. The RGBs hog up the GPIO pins (12 total) and I could just use two single color LEDs in each drum to reduce the total GPIO pins used down to an amount where I could use the Model B Raspberry Pi as opposed to the B+.
  • The ‚ÄúDrums‚ÄĚ: AKA the peanut canisters, will be lined up in a row and wired to four digital inputs.
These are the four cans I found, with a Raspberry Pi to scale.
These are the four cans I found, with a Raspberry Pi to scale.
  • Drumsticks: These will probably be makeshift dowels with a padded metallic tip wired up the shaft of the drumstick and connected to ground. Every time the drumstick touches the top of the drum, the pull-up resistor will connect to ground and therefore read low. That’s the simplest way I can think of to sensor read when the drum is tapped, although the idea of each drumstick being physically wired to the unit is cumbersome. I could use some sort of capacitive sensing, but I’m not sure how to do that digitally or easily with the Pi and I would need to do some research and experimentation. It would also be kind of neat to make the drums sensitive to hand-taps.
  • Speakers: The Pi will be wired to one or two speakers via the audio jack that will play a drum sound effect every time the drum is hit. I have a of couple options with the physical speaker: I can make homemade speakers to embed in the drums, attach an old external speaker, or just leave the Pi’s audio output jack accessible from the outside so that the audio output can be decided at the user’s discretion, whether it be headphones or speakers. However, each option has disadvantages; homemade speakers are cheap, simple, and embed-able, but have an extremely low volume level certainly unsuitable for hard core drumming. Standard external speakers, while nice and loud, are either clunky or require external battery power, which makes them hard to embed. Finally, leaving the audio jack open to the user might reduce the drum set‚Äôs portability.
  • Audio: The drum sounds effects themselves are actually .wav sound files played by the software. I decided to use the sample drum effects files used in Sonic Pi since there is a good variety. Because every Pi running Raspbian has Sonic Pi installed, the software will transport across any image of Raspbian, forgoing the need to download any .wav or .mp3 files along the code. I might in the future compile my own set of drum sound effects, but for now Sonic Pi provides plenty of variety.
  • Volume Buttons: The drum kit will have two buttons to control volume up and down.
  • Software: I wrote code in Python 3 using the RasPi.GPIO module.
  • ‘Soundschemes’ and ‘Colorschemes’: Since I’m using RGB LEDs and an audio mixer, there are an infinite amount of colors and sounds that can be produced. I’m adding a button to the drum kit that changes the ‘soundscheme’ or the drum tones that are played. Each soundscheme contains four related drum tones. For now, I just picked random Sonic Pi .wav files to make three mock soundschemes. I also added ‘colorschemes’ where a button can change the LED colors of each drum. This function might be removed in the future.

It might be a few weeks before I finish this. Stay tuned for part 2!

Reflections on Raspberry Pi Zero

If you’re into Raspberry Pi, then by now you’ve probably heard of the recent announcement and release of the newest RasPi model: the Raspberry Pi Zero, which costs a mere $5. Even better, the Zero is included with every printed copy of this month’s issue of the Magpi, making it the first computer ever to come free with a magazine! I think I’ve managed to convince my mom to bring me to Barnes & Noble to get a copy of the magazine when it hits the States in a few weeks.

Anyway, I wanted to write a reflection on how the Pi Zero could become a technological and educational game-changer even more so than the original Raspberry Pi models have been. It might sound kind of nostalgic and dramatic, but hey… I gotta say what I gotta say.

When the original Raspberry Pi model came out in 2012, the world got a cheap computer that would help educate kids in computing and making. Since then, the Raspberry Pi has become one of the ultimate tools of the maker, and its found its way into both proprietary applications and the hands of young kids who learn Scratch. The Raspberry Pi’s popularity derives from both its cost and versatility. And now, not long after the second generation Pi 2 was released, the miniaturized Pi Zero enters the scene at the same price as two cups of coffee. As far as computers that anyone can use, the Zero is by far the cheapest.

The most obvious of the Zero’s features is its cost. It’s a computer¬† that only costs $5, so anyone can have one to use. It costs less than even the nano versions of standard maker microcontrollers like the Arduino. It’s certainly no longer too expensive to give every child in the world (including kids in third-world countries) a computer to learn on.

Another more subtle impact of the Pi Zero is how it transforms the computer from, well, a computer into a component. Makers and proprietary prototypers alike will reach for the Pi Zero in the way they reach for wires, breadboards, and LEDs. The Pi Zero turns the computer into a mainstream building material. Certainly if we can make a $5 computer, we can also make a new plethora of other cheap technology building component staples.

In my opinion, the Raspberry Pi Zero is going to end up being a critical point in the development of primary education, the power of makers, and computing-for-everything. Going from a $20 computer (model A+) down to a $5 computer, even if it’s a minimalistic computer in some respects, is a giant leap. At the very least the Pi Zero is a testament to the rapidly improving cost-optimization in electronics production and design.

Homemade Raspberry Pi Case

pi case by itself raspberry pi model b

So a while back I was thinking of making a new case for my Raspberry Pi and now I’ve finally gotten around to finishing one!

Items I used:

  • White cardboard box that my RPi Model B came in, so it was already sized to shape
  • 1/4 ” thick anti-static foam salvaged from the hard drive section of an old computer tower
  • Four rubber end caps from a Meccano Erector set to use as rubber feet for the case
  • Silver spray paint
  • Red spray paint
Parts used to make the case.
Parts used to make the case.

This was a make-it-up-as-you-go kind of project for me. I first cut all the peripheral holes one at a time, starting with the USB and Ethernet ports. Then I cut the foam to size and cut a big ventilation hole in the bottom of the case directly underneath the Broadcom chip.

The artistic part came next. I spray-painted the entire case silver to give it a metallic look and used black paint and a crumpled paper towel to give it a sponged, scratched-up look around the sides. I also added the visage of the Raspberry Pi logo using red spray paint and a 3D printed template of the logo. It didn’t come out too good maybe because I jiggled it a bit during spray-painting and didn’t block it properly. It goes with the sturdy-used-tech theme of the case I think though.

 The bottom of the case, with the big ventilation hole and the rubber feet.
The bottom of the case, with the big ventilation hole and the rubber feet.

The last step was adding the rubber feet and putting it into action! The only problem I noticed is that it does get a little warm in the case. I probably should’ve added more ventilation holes in the bottom since the anti-static foam traps the heat. This isn’t really an issue for me, though, because I don’t run my Pi for very long periods of time.

raspberry pi case in action model b
The case in action.

My First PCB: Air Conditioning Fan

green light and fan pcb plugged in

As you may know, I enjoy making various personal air conditioning systems using old computer fans and the Arduino. In order to try making my first printed circuit board (PCB), I designed a personal air conditioning fan system that plugs into any standard USB port, and can be powered via computer USB or 5V wall adapter. Except for the printed circuit board etching kit my dad gave me for Christmas, pretty much every component I used was salvaged from old electronics (this is seriously low budget!).

usb fan circuit_schem

Basically, a fan is connected to and on-off switch to act as air conditioning. An RGB LED can be lit either green or blue, and a slide potentiometer both changes the color and adjusts the brightness.

parts to fan light circuit pcb copy
The parts used for the circuit.

Here’s the components I used, plus their sources:

  • Standard DC toy motor, from an old electric toothbrush
  • CA RGB LED, an old one that I had burnt the red lead out, so only the green and blue diodes worked
  • Black LED collar, from an indicator LED on an old computer tower (doesn’t do anything, just makes the RGB look cool)
  • 3-pin slide switch, from a broken ‘build your own plastic mechanical spider’ kit that my brother had
  • 3-pin slide 250K Ohm slide potentiometer, from an old space-age toy gun
  • 470 ohm resistor
  • USB-Type A to USB-Mini cable, from some old LeapFrog toy (I cut off one end and left only the Vcc and GND lines of the remaining wire)
  • 3D printed fan blades (I tested two different ones, and I’m working on designing my own)
My initial sketches for the layout of the board.
My initial sketches for the layout of the board.

I prototyped the circuit with a breadboard first, and then designed the PCB layout on paper, making it as space efficient as possible. Then I cut a 1×1 inch square (5×5 cm) from a larger piece of copper board, added the ‘wires’, or the black rub-on stickers that prevent parts of the copper surface of the board from being removed.

Partially etched PCB.
Partially etched PCB.

Next was to actually etch the board by putting into a solution. After doing some research, I found that you can use a mixture of vinegar, hydrogen peroxide, and salt, instead of the standard ferric chloride etching solution. Household chemicals are safer to use and won’t burn your skin if you spill it! I added equal parts vinegar and hydrogen peroxide, placed the board in the solution, and then sprinkled coarse salt on top.

Overall, it took about eight hours for all the excess copper to dissolve. I changed the solution twice, as the reaction slowed down as the solution dissolved the copper. The second time I added a higher concentration of vinegar, because it seemed to speed up the reaction more than the hydrogen peroxide or salt.

Some of the tools I used.
Some of the tools I used.

With the board etched, I used my dad’s drill press to drill holes for the components, and some steel wool to remove the black etching lines. Using my dad’s improvised soldering iron (a woodburning tool, a little high temp, but worked okay), I had my first experience soldering components to a board! The end result was decent, though it took me a long time to do it.

The two fan blades I tested out.
The two fan blades I tested out.

The last step was getting a fan blade for the DC motor. I printed two different fan models to test, and I’m working on my own right now. The green one below looks much fancier, but it moves significantly less air than the blue fan. It also has sharp edges, and I cut my fingers on the spinning blades more than once. I may print a scaled up version of the blue fan when I get the chance.

Prototype of my fan blade design made in Tinkercad.
Prototype of my fan blade design made in Tinkercad.
The finished circuit laid out.
The finished circuit board laid out.

Since the circuitry and parts have been gathered and put together, I now have to make some kind of case for the whole thing. Right now, the fan is practically unusable because the motor can’t stay upright. I could 3D design a case, make some kind of insulated wire stand, or make something with wood and cardboard.