Introduction: Servo PIR First Project


So... This is my first project. I've ordered leds, resistors and more from ebay, but so far only a PIR sensor and a servo motor came ( except the board ). So, I started looking online for a good explanation on what to do, and some worked for me, while others not.

All I could find are pretty long codes, so I've decided to write my own instructable, hoping it would help arduino-noobs like me ( I do have programming experience with other languages ).

And without further ado here it is:

Step 1: Components

  • An arduino uno - including power supply and usb cable to connect to computer.
  • PIR motion sensor - I've used HC-SR501 (as mentioned from ebay)
  • Servo motor - I've used "Servo SG90 Mini Gear Micro 9g" by Tower-Pro
  • Jumper wires
  • Breadboard ( optional - you can connect the cables directly, but breadboards are just so convenient )

Step 2: Assembly

I'll upload the photos tomorrow. For today I think this illustration, is as good as photos, or even more. Basically I've connected the 5V from the board to Servo 5V, and the PIR motion ensor 5V. Same about the ground. As for the input pin on the servo I've connected it to some digital pin on the Arduino ( mine was pin 7 ), and the PIR motion sensor data output to another digital pin on the Arduino ( mine was pin 2 ).

Step 3: Programming

So basically the code is very easy. Two code examples that helped me were:

And here is the code. I've over commented in order to help beginners like me.

I've attached the file.

Step 4: Congrats!

If it's your first project and it's working - Congrats!

If it's not, you can ask in the comments, and I hope I'll be able to help you.

Have fun building stuff!