| 1 | |
| 2 | == Materials Needed\\ |
| 3 | |
| 4 | a. For this project you will need to use the TinkerCAD software as the PIR sensor is not included in the Arduino kit that you have physically.\\ |
| 5 | |
| 6 | b. You will need a PIR sensor, an Arduino, an LED, and a resistor.\\ |
| 7 | |
| 8 | == Steps\\ |
| 9 | |
| 10 | [[Image()]] |
| 11 | |
| 12 | a. Let’s start with an LED, and connect the anode side of the LED to a resistor, typically with a resistance of 370 to 500 ohms.\\ |
| 13 | |
| 14 | b. Connect the resistor to digital pin 13.\\ |
| 15 | |
| 16 | c. Connect the cathode side of the LED to the GND of the Arduino.\\ |
| 17 | |
| 18 | d. Then, take out a PIR sensor, and connect the left pin (signal pin) to digital pin 2.\\ |
| 19 | |
| 20 | e. Then, connect the middle pin (power pin) to the 5v pin on the Arduino.\\ |
| 21 | |
| 22 | f. Next, connect the right pin (ground pin) to the GND of the Arduino.\\ |
| 23 | |
| 24 | g. Lastly, copy and paste this code into the code section with the blocks option changed to text.\\ |
| 25 | |
| 26 | h. You can then run the simulation, press the PIR sensor, and move the circle around to see what happens.\\ |
| 27 | |
| 28 | Code:\\ |
| 29 | |
| 30 | const int LED1=13;\\ |
| 31 | |
| 32 | const int PIRinput=2;\\ |
| 33 | |
| 34 | void setup()\\ |
| 35 | |
| 36 | {\\ |
| 37 | |
| 38 | pinMode(LED1, OUTPUT);\\ |
| 39 | |
| 40 | pinMode(PIRinput,INPUT);\\ |
| 41 | |
| 42 | Serial.begin(9600);\\ |
| 43 | |
| 44 | }\\ |
| 45 | |
| 46 | |
| 47 | void loop()\\ |
| 48 | |
| 49 | {\\ |
| 50 | |
| 51 | Serial.println(digitalRead(PIRinput));\\ |
| 52 | |
| 53 | if (digitalRead(PIRinput) == 1){\\ |
| 54 | |
| 55 | digitalWrite(LED1,HIGH);\\ |
| 56 | |
| 57 | }\\ |
| 58 | |
| 59 | if (digitalRead(PIRinput) == 0){\\ |
| 60 | |
| 61 | digitalWrite(LED1,LOW);\\ |
| 62 | |
| 63 | }\\ |
| 64 | |
| 65 | }\\ |
| 66 | |
| 67 | |
| 68 | == Explanation of how it works\\ |
| 69 | |
| 70 | a. The LED is used to indicate when the ball (which represents an object) moves.\\ |
| 71 | |
| 72 | b. The Arduino knows when to turn on the LED because of the PIR sensor that detects motion.\\ |
| 73 | |
| 74 | c. The PIR sensor sends a signal through the signal pin to the Arduino, which makes the Arduino know that the PIR sensor saw something move.\\ |
| 75 | |
| 76 | d. The Arduino then uses that information to turn on the LED.\\ |
| 77 | |
| 78 | e. You will find that many sensors are wired in a similar fashion, with 2 pins dedicated for power (5v and GND/ground), and the other pins are used for transmitting information between the sensor and the Arduino. An example of a sensor that is wired similarly to the PIR sensor is the ultrasonic sensor, which you will get to work with during the electrical meets as a project. |