Motion light
A PIR module, a transistor and a lamp, no board. Click the dome and the light holds for two seconds after the movement stops. There is no microcontroller in it: the simulator solves the 5 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
Teaching? Assign it to your class in one click.
Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $5.30. On Mokxi they're free.
Step by step, with the wiring and the common mistakes: PIR Motion Sensor: How It Works, With an Arduino
What you'll learn
- A PIR sensor gives a clean digital output
- A transistor works as a switch
- A base resistor limits current
- Hold time and retrigger on a PIR module
- Difficulty: Beginner
- Time: About 15 minutes
- Parts: 7
How it works
This circuit has no board and no code. A PIR motion module watches for movement. Its OUT pin goes high when it sees something and stays high for a short hold time after.
That output goes through a 1k resistor into the base of a transistor. The transistor switches a yellow LED on its collector, with a 220 ohm resistor to 5 V. The PIR's output is about 3.3 V, which is plenty to turn the transistor on.
Click the dome in the simulator and the lamp holds for about two seconds after the movement stops. The module then ignores new movement for a short while.
Parts list
7 parts, plus the jumper wires. They retail for about $5.30; on Mokxi they're free.
- 1 × Half breadboard
- 1 × Power, 5 V
- 1 × Motion sensorIn Halloween Prop Kit.
- 1 × Transistor (NPN or PNP)In LED Cube Kit.
- 1 × Resistor, 1k ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × LED, yellowIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × Resistor, 220 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
Kits that can build it
These 7 starter kits have every part in the circuit. Each kit's page lists what else it can build.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Motion sensor pin VCC | 5 V |
| Resistor, 220 Ω pin 2 | 5 V |
| Motion sensor pin GND | Ground |
| Transistor (NPN or PNP) pin E | Ground |
| Resistor, 1k Ω pin 1 | Motion sensor pin OUT |
| Resistor, 1k Ω pin 2 | Transistor (NPN or PNP) pin B |
| LED, yellow pin C | Transistor (NPN or PNP) pin C |
| Resistor, 220 Ω pin 1 | LED, yellow pin A |
The notes that come with it
There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.
// A motion light with no board: a PIR, a transistor and a lamp.
//
// Nothing here is programmed. The HC-SR501 module has its own chip on it, and
// what comes out of OUT is already a clean digital signal: high while it can
// see movement, and for the hold time afterwards.
//
// PIR VCC -> 5 V, GND -> ground
// PIR OUT -> 1 k -> the base of a 2N2222
// emitter -> ground, collector -> the lamp -> 220 ohm -> 5 V
//
// The output is 3.3 V and not 5, whatever the module is powered from, because
// the regulator on the board feeds its logic. Through 1 k into a base that is
// a good two and a half milliamps, and a 2N2222 with a gain of a hundred will
// pass far more than the lamp's twelve.
//
// Things to try. Click the dome, then click it again and count: the lamp holds
// for two seconds. Now click again right away: nothing, for another two
// and a half, because the module ignores everything after a pulse. Then open
// the PIR's properties and set retrigger to single: now holding the movement
// on gives one pulse and no more.
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The lamp never lights This project
Check the transistor emitter goes to ground and the PIR has 5 V and ground. - It turns off even while there is movement This project
The module holds for only a couple of seconds and then pauses. Try the retrigger setting in its properties. - The sensor reads high for ages after power up. Motion sensor
A real PIR needs 30 to 60 seconds to settle. Ignore its output during that time, and keep still in front of it until the delay passes. - Wrong output or it never triggers. Motion sensor
Power it from 5 V, join GND, and read OUT as a digital input (3.3 V logic high). Check the trimmers for delay and sensitivity. - The load never turns on, or is always on, because the legs are in the wrong order. Transistor (NPN or PNP)
Check the pinout in the datasheet for your part. A 2N2222 or BC547 can have emitter, base, collector in a different order. Flat side orientation is easy to get wrong. - The base is wired straight to the pin with no resistor, or the motor has no flyback diode. Transistor (NPN or PNP)
Put about 1k between the pin and the base. For motors and relays, add a diode across the coil with the stripe toward the positive side. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.