Archive for March, 2012

Music shield triggered by PIR sensor

March 17, 2012

I recently got a Seeeduino music shield, and I spent last night and a bit today trying to get it to be triggered by a PIR sensor, so that the music would turn on when there’s movement and turn off when there’s not been movement for 5 seconds.

It took a bit of tinkering and studying. Initially, I could just get it to turn on with movement and then run through a full song. But today I was finally able to get it to work.

The music shield library has rather ugly code with a lot of extraneous commented-out lines and little documentation. But it is rather easy to follow and to get working. Most importantly, it was quite easy to do the modifications to handle the PIR sensor information. I did need to make a change to the actual library, which is less than ideal, but it was only a couple of lines.

The file player.cpp contains a function AvailableProcessorTime() that gets called repeatedly in order to handle user interface events. Then there’s a global variable playStop that indicates whether the player should be playing (playStop == 1) or stopped (playStop == 0). So I just needed to add a line to check the sensor and change playStop accordingly.

What I did was create a generic user-defined function,

void userInterruptFunction(void) { /* ... */ }

that gets called within AvailableProcessorTime(). The user would need to be sure to define that function, but it could be left empty, or it could be used (as with my code) to check a sensor and then change a setting.

The code for my project is at my github page.

Boty Bot: Batteries

March 16, 2012

The DFRobot platform that I used for Boty Bot has the batteries placed inside the bottom compartment, near the motors. It would be a real hassle to exchange batteries, as you’d have to take the whole thing apart. And the kit does come with a DC power jack plus a hole for it in the back, next to another hole for a SPDT switch.

So it was obvious to me from the start that I’d want a rechargeable battery. And I was quite proud of myself for working out the following wiring diagram for the battery.

When the switch is in the up position, the battery is connected to the motor shield, and the motors receive power. When the switch is in the down position, the battery is connected to the DC power jack and can be charged. I guess the scheme is pretty obvious, but I was still pleased with myself.

After a bit of searching, I chose a 6V 2000 mAh NiMH battery pack that is like 5 AAs shrink-wrapped together, plus a related charger. I considered a more expensive universal charger, but decided to just get this cheaper one, as I didn’t think I’d be using lots of different kinds of batteries, and I’ve been spending too much money on this hobby.

The 6V battery worked great. But then a day after putting the robot together, the robot started acting crazy: going backwards and not responding to the remote, giving crazy Ping distance measurements, etc. I finally concluded that it was the 9V battery driving the arduino, ping sensor and servo: the battery was running low, but rather than stopping working completely, the robot was just stopping working properly.

So, I got a second rechargeable battery to drive the arduino, ping and servo (i.e., everything but the motors): a 7.2V 2000 mAh NiMH battery pack just like the 6V one driving the motors, but with 6 AAs shrink-wrapped together rather than just 5.

I soldered a 2.1mm male plug onto the 7.2V pack, then realized I’d forgotten to thread the plastic sleeve onto the wires first, and so had to cut them, desolder, and solder again. That won’t be the last time I screw up in that way, I’m sure.

I then made a couple of adapters for the charger, since one battery is connected to a 2.1mm female jack and the other to a 2.1mm male plug.

The robot has been working well since I got the 7.2V battery pack.

I also got a mini volt meter so I can monitor the battery charge. I’m not sure whether I should monitor the power to the arduino (the Vin pin) or the regulated power (the 5V pin). Currently, I’m monitoring the Vin pin.

Boty Bot: Overview

March 15, 2012

I learned quite a number of things in the process of creating my arduino robot, Boty Bot. (I initially called it “Boxy Bot”, but my son changed it to “Boty Bot”.) I’ll explain various things over the next several posts, separately considering the batteries, the motors, the Apple remote, etc. (The code is at github.)

A robot seemed a fun way to start with Arduino: something that drives around, to please the kids, and an opportunity to play with different sensors. I started with the adafruit motor party pack: the adafruit motor shield plus several motors to play with. I destroyed the DC motor by tearing off one of the soldering tabs (those things are delicate!); more on that later.

It seemed the easiest way to make a robot would be with a kit; after a bit of searching I decided on the DFRobot 4WD platform: simple and relatively inexpensive. I also got the Ping sensor and mounting bracket, a sonar sensor that looks like a pair of eyes, with a servo motor so the “head” can scan back and forth.

There is quite a bit of information online about this DFRobot kit:

It went together quite easily. There were a number of snags, but in the end I’m happy with it. The wheels are a bit cheap and wobbly, but overall it is good.

The highlights of what I learned:

  • It would be a hassle to change the motor batteries, as you’d have to take the whole thing apart. Rechargeable batteries and a power jack are critical.
  • A 9V battery to run the arduino plus the Ping sensor is not enough. I needed a second rechargeable battery for the controller. A mini volt meter is nice for keeping track of the battery charge.
  • Fancy jumper cables fall out too easily; it’s better to use hand trimmed wires. Even better would be screw terminals, like on a screw shield.
  • The soldering tabs on DC motors can be quite delicate, and if you break one, you pretty much ruin the motor. The best advice I’ve seen on soldering DC motors was in the instructions for the Makey Robot; see step 15.
  • I’ve had trouble with the Ping sensor giving sporadic 0s. I haven’t figured out why, but just ignoring strict 0s seems to work.

Improved robot

March 13, 2012

I’ve made some progress on the robot; I’ll provide details later. For now, here’s a video.

First projects

March 7, 2012

Here’s a brief run-down on some initial electronics projects.

Cigar box

My first electronics project was from Chapter 2 of the book Snip, Burn, Solder, Shred: a cigar box with LEDs, switches, a pushbutton, and a buzzer.

I should add a photo of the interior. It’s a mess of wires with considerable opportunity for short circuits. If I were to do it again, I’d cover the wire junctions and the leads to the LEDs and resistors with heat shrink tubing.

Intrusion alarm

My first “fancy” project was the intrusion alarm from Make: Electronics (Experiment 11).

The red and black connectors on the front are to be attached to magnetic sensors on doors/windows, for detecting intruders. I should show the interior of this one, too. The layout of the speaker holes on the front were done in R.

I learned a great deal from this, but there were disappointing aspects:

  • It’s hard to be line up holes precisely using a hand drill.
  • ABS plastic scratches easily. Note the scratches in the picture above, from my attempts to scrape off some burrs.
  • The circuit that controls the siren sound doesn’t work properly. It worked on the breadboard. It worked initially after I’d soldered it onto perf board. But after I screwed the perf board to the inside of the box, it stopped working properly. I suspect that I screwed it in too tightly, but I don’t really understand what’s going wrong.

It took a long time to complete the project, because I was waiting on the necessary DPDT on-(on) pushbutton (such buttons are hard to find). My Make: Electronics Components Pack 2 had two DC power jacks but no pushbutton. I contacted MakerShed, but they sent me an SPST pushbutton by mistake. I contacted them again, and I finally got the pushbutton. But they sent me a great notebook for my troubles. I love the notebook.


My latest project is to make an Arduino robot. I started with the DFRobot 4WD platform, an adafruit motor shield, and a Ping sensor and mounting bracket (from Parallax).

I’ll say more later. Here are a couple of pictures, including one of the single-digit LED display (using two Arduino digital pins and a 4026 decade counter) that indicates the distance measure from the Ping (sonar) sensor.


March 6, 2012

A new blog, to document (to some extent) my exploration of the arduino microcontroller and electronics more generally.

I’ll be posting arduino-related code to my github page and listing them here.