Built-in project · Arduino Uno R3

Radar light on an Arduino Uno

An RCWL-0516 microwave motion sensor lights the Uno’s LED while something moves, and holds it two seconds after the movement stops. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner About 10 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $28. On Mokxi they're free.

Step by step, with the wiring and the common mistakes: Arduino RCWL-0516 Microwave Radar Sensor

The circuit runs here once the page has loaded.

What you'll learn

  • How a microwave motion sensor differs from a PIR
  • Reading a digital sensor output
  • Detecting a change of state, not just the state
  • Timing with millis
  • Difficulty: Beginner
  • Time: About 10 minutes
  • Board: Arduino Uno R3
  • Parts: 3

How it works

An RCWL-0516 sensor sends out a 3.2 GHz signal and listens for the echo. Anything that moves shifts the echo a little, and the chip on the board turns that into a digital output on OUT, wired to pin 2.

OUT goes high as soon as it sees movement and stays high for two seconds after the movement stops. The sketch copies that to the Uno's own LED on pin 13.

It also prints a message when the state changes. It prints "Movement" when the room turns busy, and "Clear after" with the number of milliseconds when it goes quiet. The output is 3.3 V, which the Uno reads as high with no level shifter.

Parts list

3 parts, plus the jumper wires. They retail for about $28; on Mokxi they're free.

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 pinConnects to
Microwave motion sensor pin GNDArduino Uno R3 pin GND
Microwave motion sensor pin OUTArduino Uno R3 pin 2
Microwave motion sensor pin VIN5 V

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Radar light: an RCWL-0516 microwave motion sensor lights the Uno's own LED
// while something moves, and prints when the room goes busy and quiet.
//
//   RCWL-0516  VIN -> 5V, GND -> GND, OUT -> pin 2
//
// The board sends out a 3.2 GHz signal and listens for the echo. Anything
// moving shifts the echo's frequency a little, and the chip on the board
// turns that into a plain digital output: OUT goes high, to 3.3 V, as soon as
// it sees movement and stays high for two seconds after the movement stops.
// 3.3 V is well over the Uno's input threshold, so it needs no level shifter.
//
// Unlike a PIR, it sees through plastic and thin walls and it has no dead
// time after a pulse, so movement right after OUT drops is seen at once.
//
// Things to try. Click the sensor to start something moving and click again
// to stop it, and count the two seconds. Then click it twice quickly.

const int SENSOR_PIN = 2;
const int LAMP_PIN = 13;

bool busy = false;
unsigned long since = 0;

void setup() {
  Serial.begin(9600);
  pinMode(SENSOR_PIN, INPUT);
  pinMode(LAMP_PIN, OUTPUT);
  Serial.println("Radar ready");
}

void loop() {
  bool seen = digitalRead(SENSOR_PIN) == HIGH;
  digitalWrite(LAMP_PIN, seen ? HIGH : LOW);
  if (seen != busy) {
    busy = seen;
    unsigned long now = millis();
    if (busy) {
      Serial.println("Movement");
    } else {
      Serial.print("Clear after ");
      Serial.print(now - since);
      Serial.println(" ms");
    }
    since = now;
  }
  delay(20);
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

It starts the serial port at 9600, sets the sensor pin as an input and the lamp pin as an output, and prints "Radar ready".

void setup() {
  Serial.begin(9600);
  pinMode(SENSOR_PIN, INPUT);
  pinMode(LAMP_PIN, OUTPUT);
  Serial.println("Radar ready");
}

loop sketch.ino

It reads the sensor and sets the LED on pin 13 to match. If the state differs from the last one, it prints a message. A new movement prints "Movement". When it ends, it prints how many milliseconds passed since the last change. It waits 20 ms each pass.

void loop() {
  bool seen = digitalRead(SENSOR_PIN) == HIGH;
  digitalWrite(LAMP_PIN, seen ? HIGH : LOW);
  if (seen != busy) {
    busy = seen;
    unsigned long now = millis();
    if (busy) {
      Serial.println("Movement");
    } else {
      Serial.print("Clear after ");
      Serial.print(now - since);
      Serial.println(" ms");
    }
    since = now;
  }
  delay(20);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The light stays on for a while after movement stops. This project
    That is normal. The sensor holds OUT high for about two seconds after the last movement.
  • Nothing ever lights. This project
    Check VIN is on 5V, GND is on GND and OUT goes to pin 2.
  • It triggers by itself or on a person behind a wall, and the output stays high. The microwave goes through thin walls and plastic, and it holds OUT for a few seconds. Microwave motion sensor
    Aim it away from fans, windows, and moving things. Wait for the output to drop. The hold time and range can be set with solder pads and resistors on the board.
  • The board is powered wrong and acts strange. It needs 4 to 28 V on VIN, and OUT is 3.3 V, so it is safe for 3.3 V and 5 V pins. Microwave motion sensor
    Feed VIN with 5 V. Keep the supply clean, since noise causes false triggers. Wait about a minute after power on before trusting the output.
  • Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
    Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected.
  • Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
    Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.