4.5 Testing It Out
Place the PIR sensor at a convenient location to test motion detection, download the sketch, and open the Arduino IDE’s serial window.
Trigger the PIR sensor by waving your hand in front
of it. Your guard dog should react with a random audio clip and
servo motion. If you want the servo motor to rotate differently,
modify theservo.write()
method calls
with values ranging from 1000 to 2200. This is because the
ServoTimer2 library uses microseconds instead of the angle of
degrees used by the original Servo library to measure pulse widths.
As a result, you may need to experiment to find the right degree of
movement. After getting the hang of the timing based on the size of
the servo you are using, determining the ideal values to elicit the
desired amount of rotation will become second nature.
Now that you have tested and tweaked the servo timing synchronized with the appropriate audio clip, it’s time to put the finishing touches on the final placement of the hardware.