Ping Sensor

I've been sitting around the house sick with a cold. I haven't had the energy to do any serious projects but I threw together a little gadget to make people leave me alone.

It started out with a ping sensor. I mounted it on a Make protoshield I had and connected the on board LEDs to a couple pins. Then I figured it wouldn't take much to add a piezo buzzer I had.

What I ended up with is a ping sensor that turns on the green LED if you get within 12 inches and the red LED if you get within 6 inches. It also starts to play a tone if you're within 24 inches and increases the pitch as you get closer.

It's an easy little project to help you understand how the ping sensor, map function, if else function and tone library work.


Material:

1 x Arduino UNO
1 x ProtoShield (I used the Maker's Shield)
1 x Piezo Buzzer
1 x Ping Sensor (I used the Parallax one)
Several Jumper Wires

The Circuit:

It's a pretty simple circuit. Just connect power to the ping sensor. Connect the output from the ping sensor to pin 7. Connect the green LED to pin 5 and the red LED to pin 6. Connect the ground of the piezo to ground and the positive to pin 9.

The Code:

The code is pretty simple and I tried to leave it commented enough so you'll understand a little of what it's doing. It includes some serial commands for debugging or if you want to see what distance the ping sensor is reading. 



Now just plop down on the couch and leave this on the coffee table and if anyone comes over to bother you they'll be turned away by blinking lights and an annoying tone.

Comments

Popular Posts