TinkerCAD

How to Use PIR Sensor with Arduino in Tinkercad?

Understanding PIR Sensors

Passive Infrared (PIR) sensors are widely utilized in various applications for detecting motion. These sensors can identify changes in the infrared radiation emitted by objects, particularly warm bodies like humans. The basic principle relies on two pyroelectric sensors that detect temperature differences in their environment. When a person moves across the sensor, it registers a variation in heat, triggering a response.

Components Required

Before starting, gather the following components:

  • Arduino board (e.g., Arduino Uno)
  • PIR motion sensor module
  • LED
  • Resistor (220 ohm for the LED)
  • Breadboard and jumper wires

Connecting the PIR Sensor to Arduino

  1. Wiring the PIR Sensor: The PIR sensor features three pins:

    • Vcc: Connect this pin to the +5V output on the Arduino.
    • GND: Connect this pin to the ground (GND) on the Arduino.
    • OUT: Link this pin to a digital pin on the Arduino (for example, pin 2).
  2. LED Circuit: To visualize the motion detection:
    • Connect the LED to one of the digital pins (e.g., pin 13) on the Arduino.
    • Use a resistor and connect the other end of the LED to the ground.

Setting Up Tinkercad

  1. Start a New Project: Go to Tinkercad, create a new circuit project, and include the Arduino and PIR sensor in the design.

  2. Place the Components: Arrange the Arduino, PIR sensor, and LED on the breadboard layout as per the wiring instructions.

  3. Code Editor: Click on the "Code" button to enter the coding interface. Select the block coding option for a more visual programming approach.

Writing the Code

  1. Define the Variables: Create a variable named sensorState to store the state of the PIR sensor. This will help determine if motion is detected.

  2. Setup Function: Use the setup function to initialize the serial communication and set the mode of the LED pin as an output. Additionally, set the PIR sensor pin as an input.

    void setup() {
       Serial.begin(9600);
       pinMode(LED_PIN, OUTPUT);
       pinMode(PIR_PIN, INPUT);
    }
  3. Loop Function: In the loop function, continually read the PIR sensor’s output. If the sensor is activated (output high), turn the LED on and print the state to the serial monitor. If it is not activated, turn off the LED.

    void loop() {
       sensorState = digitalRead(PIR_PIN);
       if (sensorState == HIGH) {
           digitalWrite(LED_PIN, HIGH);
           Serial.println("Motion Detected");
       } else {
           digitalWrite(LED_PIN, LOW);
       }
       delay(500);
    }

Testing the Circuit

Once your circuit is wired and the code is uploaded, simulate motion in front of the PIR sensor. The LED should illuminate each time movement is detected. Adjust the sensitivity and delay settings on the PIR module, if necessary, to fine-tune its response.

Frequently Asked Questions

  1. What range does a PIR sensor cover?
    The detection range of a PIR sensor typically varies from 5 to 12 meters, depending on its model and mounting angle.

  2. Can I use multiple PIR sensors with one Arduino?
    Yes, multiple PIR sensors can be connected to different digital pins on the Arduino. Just ensure each sensor has its own unique pin assignment in the code.

  3. What might cause false triggers in a PIR sensor?
    Factors like moving curtains, pets, or sudden changes in temperature can trigger false readings. Proper placement and adjusting sensitivity can minimize these effects.

About the author

Wei Zhang

Wei Zhang

Wei Zhang is a renowned figure in the CAD (Computer-Aided Design) industry in Canada, with over 30 years of experience spanning his native China and Canada. As the founder of a CAD training center, Wei has been instrumental in shaping the skills of hundreds of technicians and engineers in technical drawing and CAD software applications. He is a certified developer with Autodesk, demonstrating his deep expertise and commitment to staying at the forefront of CAD technology. Wei’s passion for education and technology has not only made him a respected educator but also a key player in advancing CAD methodologies in various engineering sectors. His contributions have significantly impacted the way CAD is taught and applied in the professional world, bridging the gap between traditional drafting techniques and modern digital solutions.