RCWL-0516 microwave proximity module


I’m new to coding and Blynk but I enjoy experimenting and learning as I go. So if you can see ways for me to improve the code or Blynk Widgets please let me know.

I purchased two RCWL-0516 off eBay(https://www.ebay.co.uk/itm/263104954328) and connected one up to my Wemos D1 Mini Pro. At first I had the RCWL-0516 on a breadboard right next to the Wemos D1 and had stability problems. After an hour or two of trying to figure out why I realised the the close proximity of the Wemos D1 to the RCWL-0516 was the cause. As you can see in the photo the RCWL-0516 now sits 240mm above the Wemos and the results about 10 seconds after start up are now stable. It easily detects the slightest movement in a 2 meter radius and will detect me walking over 5 meters away.

For those of you that are interested here’s the code:

#include <ESP8266WiFi.h>
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>

#define BLYNK_GREEN     "#23C48E"
#define BLYNK_RED       "#D3435C"

#define SensorPin D1

char auth[] = "";
char ssid[] = "";
char pass[] = "";

int SensorValue;
int motionDetected = 0;

WidgetLED led1(V2);

void setup()
{
  Serial.begin(115200);
  delay(10);
  Blynk.begin(auth, ssid, pass);
  pinMode(SensorPin, INPUT);
  led1.on();
}

void loop()
{
  getSensorValue();
  Blynk.run();
}

void getSensorValue(void)
{
  SensorValue = digitalRead(SensorPin);
  if (SensorValue)
  {
    led1.setColor(BLYNK_RED);
    Serial.println("LED: red");
  } else
  {
    led1.setColor(BLYNK_GREEN);
    Serial.println("LED: green");
  }

  Blynk.virtualWrite(V1, SensorValue);

  delay(1000);

}
1 Like

@Shadeyman switch to BlynkTimer at say 500ms intervals to call getSensorValue(), don’t call it in loop().

1 Like

Thanks @Costas . Hope it did it correctly?

#include <ESP8266WiFi.h>
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>

#define BLYNK_GREEN     "#23C48E"
#define BLYNK_RED       "#D3435C"

#define SensorPin D1

char auth[] = "";
char ssid[] = "";
char pass[] = "";

int SensorValue;
int motionDetected = 0;

WidgetLED led1(V2);

BlynkTimer timer;

void setup()
{
  Serial.begin(115200);
  delay(10);
  Blynk.begin(auth, ssid, pass);
  pinMode(SensorPin, INPUT);
  led1.on();

  timer.setInterval(500L, getSensorValue);
}

void getSensorValue(void)
{
  SensorValue = digitalRead(SensorPin);
  if (SensorValue)
  {
    led1.setColor(BLYNK_RED);
    Serial.println("LED: red");
  } else
  {
    led1.setColor(BLYNK_GREEN);
    Serial.println("LED: green");
  }

  Blynk.virtualWrite(V1, SensorValue);

}

void loop()
{
  Blynk.run();
  timer.run();
}
1 Like

Hi @Shadeyman, glad to see that you’ve not given up tinkering, and that you’ve actually found a use for those wooden kebab skewers that were kicking around in the kitchen drawer!

Take a look at this blog post from @scargill:

https://tech.scargill.net/category/rcwl-0516/

It’s worth reading all of the comments, as a few people were getting false triggers and people have tried a variety of ways of smoothing these out with varying success.
I used to love reading Peter Scargill’s tech blog, and his blog about his Spanish property (we also have a place in Spain, so it especially interesting for me). Unfortunately Peter suffered a stroke before Christmas and although he’s now replying to a few comments from time to time he’s focusing on his recovery rather than his blog posts. Hopefully he’ll be writing again soon, but there’s lots of useful techie info on his blog site that’s worth reading.

Pete.

2 Likes

Perfect.

1 Like

:grinning: :bowing_man:

I don’t have much spare time but when I do I try to increase the small amount of coding knowledge I have. Love Blynk, makes things so much easier visually for noobs like myself.

Weather is crap here(England) again, didn’t want to venture out so used what I had to hand, well spotted. :sweat_smile:

I have already skimmed over it, when I had false triggers I searched google, Scargill’s tech blog was the top result, I also found this(GitHub - jdesbonnet/RCWL-0516: Information about RCWL-0516 microwave proximity switch module (ICStation.com SKU 10630)). I’ve not tested it over long periods, don’t get chance. Children, Grandchildren, Animals, the Wife = no chance.
However, I shall now read everything thoroughly. :+1:
And I wish you a speedy recovery @scargill