Overview
We investigated the motion sensors on the market.
We will check the specifications of each sensor from the mechanism of the motion sensor, program it, and use it by electronic work.
When using the ESP32 for electronic work, we test in enviable environments such as cold objects, small objects, outdoors, and indoors, and evaluate which sensor is the easiest to use and has the best performance.
Video
Japanese【日本語】
English
Sensor List
PreTest for “sensor only” type
//*************************************************************************
// MotionSensor PreTest Ver2023.3.8
// Arduino board : ESP32(Arduino core for the ESP32) by Espressif Systems ver 2.0.7
// Written by IT-Taro
//***********************************************************************
#define LED_PIN 32
#define TEST_PIN 34
#define ARR_MAX 10
uint32_t pirArr[ARR_MAX];
int arrCount = 0;
unsigned long loopCount = 0;
void setup() {
// Serial monitor
Serial.begin(115200);
Serial.println();
// PIN Setting
pinMode(LED_PIN, OUTPUT);
pinMode(TEST_PIN, ANALOG);
// INIT ARREY
for(int i=0;i<ARR_MAX;i++){
pirArr[i]=0;
}
// Display Serial monitor
Serial.println("Setup completed!");
}
void loop() {
// Sleep[500 msec]
delay(500);
loopCount++;
// checkStatus
uint16_t analog1Adc = analogRead(TEST_PIN);
uint32_t analog1Mv = analogReadMilliVolts(TEST_PIN);
//Array average
uint32_t total = 0;
for(int i=0;i<ARR_MAX;i++){
total = total + pirArr[i];
}
uint32_t ave = total / ARR_MAX;
//Check Voltage
int diff = analog1Mv - ave;
if( diff >= 7 || diff <= -7 ){
digitalWrite(LED_PIN, HIGH);
Serial.printf("[%ld] Yes Detected ADC=%d, mV=%d[mV], ave=%d, diff=%d\n", loopCount, analog1Adc, analog1Mv, ave, diff);
} else {
digitalWrite(LED_PIN, LOW);
Serial.printf("[%ld] No Detected ADC=%d, mV=%d[mV], ave=%d, diff=%d\n", loopCount, analog1Adc, analog1Mv, ave, diff);
}
//Update Array
pirArr[arrCount]=analog1Mv;
arrCount++;
if( arrCount >= ARR_MAX ){
arrCount = 0;
}
}
Circuit
Program
//*************************************************************************
// MotionSensor1 Ver2023.3.11
// Arduino board : ESP32(Arduino core for the ESP32) by Espressif Systems ver 2.0.7
// Written by IT-Taro
//***********************************************************************
#define LED1_PIN 32
#define LED2_PIN 14
#define GROVE_PIN 2
#define M5STK_PIN 33
unsigned long loopCount = 0;
void setup() {
// Serial monitor
Serial.begin(115200);
Serial.println();
// PIN Setting
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
pinMode(GROVE_PIN, INPUT);
pinMode(M5STK_PIN, INPUT_PULLUP);
// Display Serial monitor
Serial.println("Setup completed!");
}
void loop() {
// Sleep[1 sec]
delay(1000);
loopCount++;
// checkStatus
int checkStatus = digitalRead(GROVE_PIN);
if( checkStatus ){
digitalWrite(LED1_PIN, HIGH);
Serial.printf("[%ld]GROVE Yes Detected checkStatus=%d\n", loopCount, checkStatus);
} else {
digitalWrite(LED1_PIN, LOW);
Serial.printf("[%ld]GROVE No Detected checkStatus=%d\n", loopCount, checkStatus);
}
checkStatus = digitalRead(M5STK_PIN);
if( checkStatus ){
digitalWrite(LED2_PIN, HIGH);
Serial.printf("[%ld]M5STK Yes Detected checkStatus=%d\n", loopCount, checkStatus);
} else {
digitalWrite(LED2_PIN, LOW);
Serial.printf("[%ld]M5STK No Detected checkStatus=%d\n", loopCount, checkStatus);
}
}
//*************************************************************************
// MotionSensor2 Ver2023.3.11
// Arduino board : ESP32(Arduino core for the ESP32) by Espressif Systems ver 2.0.7
// Written by IT-Taro
//***********************************************************************
#define LED1_PIN 33
#define LED2_PIN 32
#define LED3_PIN 14
#define PANA1_PIN 17
#define PANA2_PIN 19
#define SB412A_PIN 27
unsigned long loopCount = 0;
void setup() {
// Serial monitor
Serial.begin(115200);
Serial.println();
// PIN Setting
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
pinMode(LED3_PIN, OUTPUT);
pinMode(PANA1_PIN, INPUT);
pinMode(PANA2_PIN, INPUT);
pinMode(SB412A_PIN, INPUT);
// Display Serial monitor
Serial.println("Setup completed!");
}
void loop() {
// Sleep[1 sec]
delay(1000);
loopCount++;
// checkStatus
int checkStatus = digitalRead(PANA1_PIN);
if( checkStatus ){
digitalWrite(LED1_PIN, HIGH);
Serial.printf("[%ld]PANA1 Yes Detected checkStatus=%d\n", loopCount, checkStatus);
} else {
digitalWrite(LED1_PIN, LOW);
Serial.printf("[%ld]PANA1 No Detected checkStatus=%d\n", loopCount, checkStatus);
}
checkStatus = digitalRead(PANA2_PIN);
if( checkStatus ){
digitalWrite(LED2_PIN, HIGH);
Serial.printf("[%ld]PANA2 Yes Detected checkStatus=%d\n", loopCount, checkStatus);
} else {
digitalWrite(LED2_PIN, LOW);
Serial.printf("[%ld]PANA2 No Detected checkStatus=%d\n", loopCount, checkStatus);
}
checkStatus = digitalRead(SB412A_PIN);
if( checkStatus ){
digitalWrite(LED3_PIN, HIGH);
Serial.printf("[%ld]SB412A Yes Detected checkStatus=%d\n", loopCount, checkStatus);
} else {
digitalWrite(LED3_PIN, LOW);
Serial.printf("[%ld]SB412A No Detected checkStatus=%d\n", loopCount, checkStatus);
}
}
Measurement result
Document
Japanese【日本語】
English
Comments