|

楼主 |
发表于 2019-8-25 21:29
|
显示全部楼层
[mw_shl_code=arduino,true]/*
【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
实验三:多普勒微波雷达感应开关模块
GND – [connects to ground]
OUT -[connects to digital input]
VIN – [connects to 5v]
*/
#include <VirtualWire.h>
#define PIN_RADAR 2
#define PIN_TX 9
#define PIN_LED 13
void setup() {
Serial.begin(9600);
pinMode(PIN_LED, OUTPUT);
vw_set_tx_pin(PIN_TX); // Arduino pin to connect the receiver data pin
vw_setup(6000); // bps connection speed
}
int rv = -1;
void loop() {
digitalWrite(PIN_LED, HIGH);
int v = digitalRead(PIN_RADAR);
if (v != rv) {
rv = v;
char msg[20];
sprintf(msg, "R %lu %d", millis() / 1000, v);
vw_send((uint8_t *)msg, strlen(msg));
Serial.println(msg);
vw_wait_tx(); // Wait to finish sending the message
}
digitalWrite(PIN_LED, LOW);
delay(100);
}[/mw_shl_code]
|
|