Wemos Mini and PIR sensor example

In this example we connect a PIR module to a Wemos Mini. A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view.

This is from Wikipedia and sums up the operation of a PIR nicely

An individual PIR sensor detects changes in the amount of infrared radiation impinging upon it, which varies depending on the temperature and surface characteristics of the objects in front of the sensor. When an object, such as a human, passes in front of the background, such as a wall, the temperature at that point in the sensor’s field of view will rise from room temperature to body temperature, and then back again. The sensor converts the resulting change in the incoming infrared radiation into a change in the output voltage, and this triggers the detection. Objects of similar temperature but different surface characteristics may also have a different infrared emission pattern, and thus moving them with respect to the background may trigger the detector as well.[4]

PIRs come in many configurations for a wide variety of applications. The most common models have numerous Fresnel lenses or mirror segments, an effective range of about ten meters (thirty feet), and a field of view less than 180 degrees. Models with wider fields of view, including 360 degrees, are available—typically designed to mount on a ceiling. Some larger PIRs are made with single segment mirrors and can sense changes in infrared energy over one hundred feet away from the PIR. There are also PIRs designed with reversible orientation mirrors which allow either broad coverage (110° wide) or very narrow “curtain” coverage, or with individually selectable segments to “shape” the coverage.

This is a typical module which is commonly used by hobbyists

SR501 HC-SR501 Adjust IR Pyroelectric Infrared PIR module Motion Sensor Detector Module



wemos and PIR
wemos and PIR


[codesyntax lang=”cpp”]

int pirPin = D7;
int val;

void setup()

void loop()
val = digitalRead(pirPin);
//low = no motion, high = motion
if (val == LOW)
  Serial.println("No motion");
  Serial.println("Motion detected  ALARM");




Open the serial monitor window in the Arduino IDE and unblock and block the sensor, you should see something like this

wemos and PIR output
wemos and PIR output


HC-SR501 Human Body Infrared Pyroelectric Infrared Sensor Module


  1. I’m trying to get this working myself, i got a Wemos D1 Wifi Uno and the HC-SR501 sensor, and used your code … and all i seem to be getting is Motion detected ALARM, why would this be? Would it be because of the Wemos D1 Wifi Uno differing to the Wemos Mini or something else?

  2. The modules I just bought have the 5V and ground the other way round to the way its shown in your diagram. Mine didn’t work but swapping them over sorted it out.

  3. I think someone is using these devices to monitor movement in my home. is there a way to find these with a detector? or render them useless without finding them?


Please enter your comment!
Please enter your name here