This is a basic motion activated servo that can be used in a wide variety of projects, and it is very simple and easy to make. If you use it creatively, you can do a lot of things with it. For example, I used mine to create a motion activated nerf gun.

Step 1: Materials

In order to make this, you will need:

An Arduino.
A PIR motion sensor.
A servo.
<p>I have had good luck with this setup using the HC-SR501 but found the HC-SR505 (the mini version) unreliable, either overactive or not working at all. I have tried multiple units and have not tried to modify the code/wiring. Someone PLEASE help me to use the mini!</p>
Just play around with the sensitivity and test the module to see if it is faulty. Also make sure you connect left to GND middle to OUT and right to VCC (look up a data sheet)<br>All the best,<br>Jacks How2s ( not author of this project!)
I love it
<p>thank you so much, u rock</p>
<p>i need help to code 4 servo motor sweep motion activated by PIR. The 1st motor will sweep and return to its original position when PIR detects motion followed by 2nd motor (sweep motion) , 3rd (sweep motion) and the 4th (sweep motion).</p>
<p>how to add LED and BUZZER. And what is the code and schematic diagram?</p><p>HELP.</p>
I would like to make a motion activated cat feeder...could this be used for this? We're my cat can paw at an area near feeder and 3-4 pixies of food drop out...
<p>Nice one,</p><p>You could use this free tool for quickly generate schematics and code snippets:</p><p><a href="http://www.circuito.io/" rel="nofollow">www.circuito.io</a></p>
<p>So thats actually pretty cool, I couldn't get the code to pull up. The schematic helps a lot though.</p>
<p>Hi nice project.. </p><p>Actually i have made similar project like this, but i used 2 PIR sensor. PIR1 i put at 0 degree and PIR2 put at 180 degree. so when movement detected, servo will move to source movement then SIM900A make call. i have done for it all and success for calling, but the problem is why my servo is vibrate and move by itself? if without SIM900A, servo and pir working normally. is it anything wrong? i used 9600 bps..</p>
<p>I have got it working, however only when plugged into the USB. How do I modify the circuit to get it working from a battery?</p>
<p>when I try to compile the code for arduino it says there is a compiling error. How can I fix this.</p>
<p>Hi</p><p>I can not transfer the info from PIR cencor to servo. I appreciate any help.</p><p>Thank you!</p>
I did everything dicribed but it seems to be not working?
Please help
<p>Hi!</p><p>What would you change in the code to make the servo only go 180 degrees and back once, when triggered by the sensor? I noticed it goes to 180 and back three times when triggered. Thanks!</p>
<p>Did you ever figure out why the servo loops three times? I'm having the same issue.</p>
<p>I'm experiencing this as well! If anyone could comment on this, it would be really helpful!</p>
<p>Found it. Edit delay in &quot;//waits for the servo to reach the position&quot; or use this simplified code :</p><p>#include &lt;Servo.h&gt;</p><p>Servo myservo; //creates a servo object</p><p> //a maximum of eight servo objects can be created</p><p>int pos = 0; //variable to store servo position</p><p>//amount of time we give the sensor to calibrate(10-60 secs according to the datasheet)</p><p>int calibrationTime = 30;</p><p>int pirPin = 12; //digital pin connected to the PIR's output</p><p>int pirPos = 13; //connects to the PIR's 5V pin</p><p>void setup(){</p><p> myservo.attach(4); //attaches servo to pin 4</p><p> Serial.begin(9600); //begins serial communication</p><p> pinMode(pirPin, INPUT);</p><p> pinMode(pirPos, OUTPUT);</p><p> digitalWrite(pirPos, HIGH);</p><p> //give the sensor time to calibrate</p><p> Serial.println(&quot;calibrating sensor &quot;);</p><p> for(int i = 0; i &lt; calibrationTime; i++){</p><p> Serial.print(calibrationTime - i);</p><p> Serial.print(&quot;-&quot;);</p><p> delay(1000);</p><p> }</p><p> Serial.println();</p><p> Serial.println(&quot;done&quot;);</p><p> while (digitalRead(pirPin) == HIGH) {</p><p> delay(500);</p><p> Serial.print(&quot;.&quot;); </p><p> }</p><p> Serial.print(&quot;SENSOR ACTIVE&quot;);</p><p>}</p><p>void loop(){</p><p> if(digitalRead(pirPin) == HIGH){ //if the PIR output is HIGH, turn servo</p><p> for(pos = 0; pos &lt; 170; pos += 1) //goes from 0 to 180 degrees</p><p> { //in steps of one degree</p><p> myservo.write(pos); //tells servo to go to position in variable &quot;pos&quot;</p><p> delay(50); //waits for the servo to reach the position</p><p> }</p><p> }</p><p> if(digitalRead(pirPin) == LOW){ </p><p> }</p><p>}</p>
<p>Very helpful.</p>
<p>HI Seraine,<br><br>I've follow your instructions and seem to be getting close to my desired intent. The problem I am running into is like in your video, the servo motor is constantly rotating and does not come to a complete stop before being triggered again by the motion sensor. Perhaps you can help me with this?<br><br>I am attempting to implement a kinetic skin system to my final architecture thesis project and would appreciate any help. Thanks!</p>
<p>Thanks so much for this, I couldn't work out how to combine the Servo code with the PIR code. All is now clear! I have made a useless object which moves kind of flower things when someone approaches.</p>
<p>Thank you for posting this! I am having one problem with it and I hope you can help me understand what I'm doing wrong. Everything starts fine, the sensor triggers the servo as it's supposed to, but the servo never stops. I have isolated the sensor so the motion of the servo isn't setting it off. Any ideas? Thanks again!</p>
<p>Made this for my Halloween owl amazing, I am trying to add led blinking program to it but keep running into problems says voids are wrong and loop is wrong. You are an amazing programmer can not wait to see what the future holds for you</p>
How do you want the led to blink? Do you want it to blink when the servo is moving, or something else? Could I see your code?
Seraine<br>After playing with your program I added the lights<br>Thank you for the reply tho
<p>Really nice tutorial. I have a problem because the PIR is too sensitive, do you have the same problem?</p>
<p>Nice tutorial!</p><p>You can get the hc-sr501 PIR motion sensor for cheap here: <a href="http://voltatek.com/en/sensors/69-motion-sensor-module-hc-sr501-pyroelectric-ir-infrared-adjustable.html" rel="nofollow">http://voltatek.com/en/sensors/69-motion-sensor-m...</a></p>
<p>How to connect it with servo ?</p>
Copy and pasted from step two: <br>The servo's red wire should be plugged into the Arduino's 5 volt pin, the black wire should be plugged into the Arduino's Ground pin, and the signal wire (it was white on my servo) should be plugged into the Arduino's digital pin 4.
cool bro !!! could you provide me a little i wanna light two bulbs on detecting motion could u plzz give me a code , i am a newbie <br>
Pretty cool man. Thanks for the 'ible.
Looking for some help with a project I am thinking of undertaking. I want to attempt this with a couple of mods - https://www.instructables.com/id/Squirt/step2/The-circuit/ (small pic only) but this one uses a 12v supply for the servo. Most servos I have seen are 5v. Am I correct in thinking I could move the servo power wire from the 12v as shown to the 5v on the board to power it and still maintain the functionality? <br> <br>Any help would be appreciated.
Most servos should be able to be powered by the 5v pin on the Arduino, so you should be fine. That's how mine was powered. However, if you connect multiple devices that draw as much current as a servo to your Arduino or if your servo uses an unusually high amount of current, you could potentially fry the Arduino, so beware of that. Also, you can't power a servo through a digital pin on the Arduino by turning the pin HIGH, as the pin can't give enough current. Other than that, I can't think of any problems.
Hi, how do I connect multiple servos, each triggered by individual sensors
I am assuming you want to have multiple servos, and each one controlled by its own individual sensor. I will address the electrical changes you need first, and then move onto programming. <br> <br> The positive pins of all of the PIR sensors will need to be connected together, and the negative pins of all of the PIR sensors will need to be connected together. Then connect the positive pins to the Arduino's 5V pin, and the negative pins to the Arduino's GND pin. Finally, connect the signal pin from each individual sensor to its own Arduino pin. For example, the pin from your first sensor will be connected to Arduino pin 11, the pin from the second to pin 12, etc. <br> <br> You will need to do something similar with the servos. However, you cannot connect the positive and negative pins to the Arduino's 5V and GND pins, because you will probably draw too much current and potentially fry the Arduino. Instead, you will need to connect the positive and negative pins to the positive and negative wires of a 5 volt power source (three AA batteries connected in series would probably work). Then connect the negative wire of the power source to the Arduino's GND pin. This is necessary because the electrical signal from the Arduino has to be able to return to the Arduino, and if they weren't connected, the signal wouldn't do anything. <br> <br> As far as programming goes, you will need to start by attaching more pins for the new sensors and servo. For example, this <br> <br>int pirPin = 12 <br>Servo myServo; <br> <br>void setup() { <br> <br>myServo.attach(4); <br>pinMode(pirPin, INPUT); <br> <br>} <br> <br> <br>would be become this <br> <br>int pir1 = 11; <br>int pir2 = 12; <br> <br>Servo servo1; <br>Servo servo2; <br> <br>void setup() { <br> <br>servo1.attach(4); <br>servo2.attach(5); <br> <br>pinMode(pir1, INPUT); <br>pinMode(pir2, INPUT); <br> <br>} <br> <br>You will also need to change the if loops. For example, this <br> <br> if(digitalRead(pirPin) == HIGH){ <br> for(pos = 0; pos &lt; 180; pos += 1) <br> { <br> myservo.write(pos); <br> delay(5); <br> } <br> for(pos = 180; pos&gt;=1; pos-=1) <br> { <br> myservo.write(pos); <br> delay(5); <br> } <br> if(lockLow){ <br> <br> lockLow = false; <br> Serial.println(&quot;---&quot;); <br> Serial.print(&quot;motion detected at &quot;); <br> Serial.print(millis()/1000); <br> Serial.println(&quot; sec&quot;); <br> delay(50); <br> } <br> <br> <br>Would have to become something like this <br> <br> if(digitalRead(pir1) == HIGH){ <br> <br> boolean pirState1 = true; <br> <br> if(lockLow){ <br> <br> lockLow = false; <br> Serial.println(&quot;---&quot;); <br> Serial.print(&quot;motion detected at &quot;); <br> Serial.print(millis()/1000); <br> Serial.println(&quot; sec&quot;); <br> delay(50); <br> } <br> takeLowTime1 = true; <br> } <br> <br> if(digitalRead(pir2) == HIGH){ <br> <br> boolean pirState2 = true; <br> <br> if(lockLow){ <br> <br> lockLow = false; <br> Serial.println(&quot;---&quot;); <br> Serial.print(&quot;motion detected at &quot;); <br> Serial.print(millis()/1000); <br> Serial.println(&quot; sec&quot;); <br> delay(50); <br> } <br> takeLowTime2 = true; <br> } <br> <br> if (pirState1 == true) { <br> for(pos = 0; pos &lt; 180; pos += 1) { <br> servo1.write(pos); <br> delay(5); <br> } <br> for(pos = 180; pos&gt;=1; pos-=1) { <br> servo1.write(pos); <br> delay(5); <br> } <br> } <br> if (pirState2 == true) { <br> for(pos = 0; pos &lt; 180; pos += 1) <br> { <br> servo2.write(pos); <br> delay(5); <br> } <br> for(pos = 180; pos&gt;=1; pos-=1) <br> { <br> servo2.write(pos); <br> delay(5); <br> } <br>} <br> <br>I hope this helps you with your design, but beware, you will probably need to modify the code to account for whatever I missed. If you need further help, feel free to ask.
I just realized that the loop code I wrote won't work very well. The problem with it is that it would sweep one servo, then sweep the next, etc. In order to have them all sweeping at the same time, it would have to look something like this. <br> <br>boolean pirState1 = false; <br>boolean pirState2 = false; <br> <br>if(digitalRead(pir1) == HIGH){ <br> <br>pirState1 = true; <br> <br>if(lockLow){ <br> <br>lockLow = false; <br>Serial.println(&quot;---&quot;); <br>Serial.print(&quot;motion detected at &quot;); <br>Serial.print(millis()/1000); <br>Serial.println(&quot; sec&quot;); <br>delay(50); <br>} <br>takeLowTime1 = true; <br>} <br> <br>if(digitalRead(pir2) == HIGH){ <br> <br>pirState2 = true; <br> <br>if(lockLow){ <br> <br>lockLow = false; <br>Serial.println(&quot;---&quot;); <br>Serial.print(&quot;motion detected at &quot;); <br>Serial.print(millis()/1000); <br>Serial.println(&quot; sec&quot;); <br>delay(50); <br>} <br>takeLowTime2 = true; <br>} <br> <br>if (pirState1 == true &amp;&amp; pirState2 == true) { <br>for(pos = 0; pos &lt; 180; pos += 1) { <br>servo1.write(pos); <br>servo2.write(pos); <br>delay(5); <br>} <br>for(pos = 180; pos&gt;=1; pos-=1) { <br>servo1.write(pos); <br>servo2.write(pos); <br>delay(5); <br>} else if (pirState1 == true) { <br>for(pos = 0; pos &lt; 180; pos += 1) { <br>servo1.write(pos); <br>delay(5); <br>} <br>for(pos = 180; pos&gt;=1; pos-=1) { <br>servo1.write(pos); <br>delay(5); <br>} else if (pirState2 == true) { <br> <br>for(pos = 0; pos &lt; 180; pos += 1) { <br>servo2.write(pos); <br>delay(5); <br>} <br>for(pos = 180; pos&gt;=1; pos-=1) { <br> <br>servo2.write(pos); <br>delay(5); <br> <br>} else { <br>} <br> <br> <br>This code is probably very inefficient, but it gives the gist of what I am thinking of.
thanks alot. I want to build an art installation that reacts when someone walks by, i'm thinking of using about 10 servos
This is nice and simple, yet effective. Your a very smart young man, and I wish I would have started my electronics hobby when I was your age. I didn't start until I turned 50, (now 53) and it amazes me at how smart some young inventors can be. Great job and keep up the good work, or should I say play :-)
You are welcome.

About This Instructable




Bio: I am 14 years old, and I'm interested in many different things - electronics, chemistry, robotics, basketball, chess and much, much more.
More by seraine:Arduino Ticking Time Bomb Motion Activated Servo Low Voltage Electrical Igniters 
Add instructable to: