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 ...

Get Programming Your Home now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.