Introduction: Arduino Alarm - Cat Proof
Cats can be great. They can be so unbelievably snuggly, fuzzy and fun. However, when they start on a project, they can be incredibly hard to deter. What better way to deter a cat than a motion sensitive light and sound?
In this lesson you will learn how to set up and code an Arduino to detect motion near it. When motion occurs, it will deter the creature with both LED light, and sound.
Some basic experience with circuitry and programming is helpful but not required.
1 Arduino Uno
2 330Ω Resistor
1 RGB LED
10 Jumper Cables
1 9V1A Adapter (for setting up and plugging in)
Step 1: Step 1: Assembling Ultra Sonic Sensor
Begin assembling your breadboard.
Attach the Ultra Sonic sensor as shown above. Take note of the four different pins (labeled) VCC, Trig, Echo, and Gnd. Be sure the VCC is going to the 5V power source, and the GND is going to the Ground.
Trig should go to Pin 2, and Echo should go to Pin 3.
Step 2: Step 2: Attach the Buzzer
Again, follow along with the breadboard above to attach the buzzer. Be sure that the + terminal of the buzzer is attached to pin 7, and use a 330Ω resistor to attach the - terminal to ground.
Step 3: Step 3: Attach the LED
Attach the RGB LED as shown in the diagram. The Red should attach to pin 9, the Green should attach to pin 10, and the blue to pin 11. The last (and longest) pin should attach to the ground, with a 330Ω Resistor.
Step 4: Step 4: Coding Time
It's now time to add the code. Using the Arduino editor, the following code will cause your LED to light up and buzzer to make noise depending on the distance away that the UltraSonic Sensor detects an object.
If you got creative with any of your Pin numbers, know that you may need to change them to get the code to work.
Step 5: Step 5: Time to Stop the Cat.
Set up your arrangement wherever you want to prevent your cat from going places. I am trying to stop him from walking across the floor in my basement, where there is no door to prevent this. When he walks in front of the sensor, it goes off. He's easily scared by noise and lights so it doesn't take too much to deter him.
Step 6: Step 6: Play With the Settings
Some of the things you can adjust or tweak depending on your needs:
- What "distanceInCM" causes things to happen. Do you want it to be when it detects something super close, or only when it's further away? If you adjust this to be too far away, you may need to get a better Ultrasonic sensor that is more sensitive.
- What color range do you want to use? With the RGB LED, its choosing random values between 0 and 100, or 0 and 255 (in the red when something is close) to give a bigger warning.
- The frequency of the buzzer can be adjusted. Lower frequencies are lower notes, higher frequencies are higher notes.