Dem Weihnachtsmann auf der Spur - Sensoren für die Überwachung des Kaminzimmers

On Wikipedia you can find this information: A sensor, also referred to as a detector, (measured variable or measuring) transducer or (measurement) sensor, is a technical component that determined physical or chemical properties (physically z. B. amount of heat, temperature, moisture, pressure, sound field sizes, Brightness, acceleration or chemical z. As pH, ionic strength, electrochemical potential) and / or the material nature of its environment can be qualitatively or quantitatively detected as a measured variable. These sizes are detected by physical, chemical or biological effects and transformed into a further processable electrical signal.

By the way, there are the products to the blog on the second Advent 55% cheaper in bundleBeing! Nobody still caught Santa Claus😉

For us, it is important to question which sensors for our purpose to capture Santa Claus, and in whatever form they send an electrical signal. Mostly, the sensors are easiest to detect, which send a digital signal. The query in the program then takes place as you check if a button has been pressed. If the sensor delivers analog values, we must measure on the analog input and - important! - Set a threshold value in which the alarm is triggered. And there are complex sensors that send their data via an interface (e.g., I2C) to the Micro Controller. Helpful are program libraries, which is included at the beginning of the sketch.


Required material:

👉 to the project setand save 55%!

1- 2 

Micro Controller

1

Motion detector HC-SR501

1

Rangefinder HC-SR04

alternative

VL53L0X Time-of Flight (TOF) Laser Distance Sensor

1

Temperature sensor, e.g. DHT11 Breakout module

2

NRF24L01 2.4 GHz Wireless Module and optional NRF24L01 Breadboard Adapter

1

Or the same that 35 in 1 sensor kit?

1

Prototyping Shield with Mini Breadboard for UNO R3

1

LCD1602 Display Keypad Shield


Enough the preface. To the factory. We start with the Motion detector (PIR = passive infrared) HC-SR501: The connection is in principle very simple: Power supply to 5V and GND, signal line to a digital PIN (in the PIN 2 circuit diagram). The good at the HC-SR501 is that the signal has only 3.3V and thus can be used on all Micro controllers and Raspberry PIs.

Sketch to Download:

 / * Pir Sensor Tester
  * The Circuit:
  * HC-SR501 Connect to Vcc = 5V, GND, signal pin to D2
  * USE LED_BUILTIN = D13 * /
 
 int Ledpin = 13;                // Choose the PIN for the LED
 int InputPin = 2;               // CHOOSE THE INPUT PIN (for PIR Sensor)
 int pirstate = Low;         // we start, assuming no motion detected
 int Val = 0;                       // variable for reading the pin status
 
 void set up() {
   Serial.Begin(9600);                 // use Serial Monitor for Messages
   pinmode(Ledpin, OUTPUT);    // Declare LED AS output
   pinmode(InputPin, Input);     // DECLARE SENSOR AS INPUT
 }
 
 void loop(){
   Val = digitalRead(InputPin);    // Read Input Value
   IF (Val == HIGH) {                    // Check if the input is high
     digitalWrite(Ledpin, HIGH);   // TURN LED ON
     IF (pirstate == Low) {
       // WE HAVE Just Turned on
       Serial.Println("Motion Detected!");
       pirstate = HIGH;
    }
  } else {
     digitalwrite(ledPin, Low);  // turn LED OFF
     IF (pirstate == HIGH){
       // we have just turned of
       Serial.Println("Motion ended!");
       pirstate = Low;
    }
  }
 }

In front of a small case, I want to warn: Due to different manufacturers may cause confusion of the connections even with three pins at PIR. If necessary, the lettering on the top surface of the cap.

On the same principle as well as the work Vibration / Shock Sensor:

and the Vibration • / shake sensor:

To recognize so steps or other shocks, you can exchange the PIR by these sensors, and to supplement the sketch.

Distance sensor

The two possible distance sensors I had in Halloween Blog presented. The ultrasonic sensor range finder HC-SR04 measures distances up to 3 m, the VL53L0X Time-of Flight (TOF) Laser Distance Sensor measures to 4 m. Changes to the measured distance, so there is someone within the evaluation length.

Here, the adjusted Sketch for the HC-SR04 without Adding a library to the Download:

 const int trigPin = 2;
 const int echoPin = 3;
 long duration;
 int distance1 = 100;
 int distance2;
 int led = LED_BUILTIN;
 
 void set up() {
   pinmode(trigPin, OUTPUT);
   pinmode(echoPin, Input);
   pinmode(led, OUTPUT);
   Serial.Begin(9600);
 }
 void loop() {
   digitalwrite(trigPin, Low);
   delay microseconds(2);
   digitalwrite(trigPin, HIGH);
   delay microseconds(10);
   digitalwrite(trigPin, Low);
   duration = pulseIn(echoPin, HIGH);
   distance2 = duration * 0.034 / 2;
   Serial.print("Distance");
   Serial.Println(distance2);
   IF (Section(distance2 - distance1) >10) {
     digitalwrite(led,HIGH);
     Serial.Println("Alarm!");
     distance1 = distance2;
    }
   delay(1000);
   digitalwrite(led,Low);
 }

If the distance changes by more than 10 cm, the alarm is triggered. After switching on a test alarm, wherein at the same time, the comparison value is determined is carried out.

It is connected to VCC = 5V and GND as well as two digital pins (here D2 and D3). Here, the trigger pin necessarily needs 5V, 3.3V, unfortunately, not enough. And the echo pin also provides 5V, so too much for Raspberry Pi and some microcontrollers. That is why we provide a remedy with an NPN transistor or a voltage divider for the cases in which supply the digital pins only 3.3V or tolerated.

temperature sensor

When Santa comes straight from the North Pole, he brings determined cold air into our home. Usually the temperatures are in the living room 12 to 28 ° C. If the measured temperature is colder, someone has come in from outside. And if it gets warmer than 28 ° C, not only burn the candles. In both cases, careful, something is wrong here.

The range of temperature sensors is large. I decide exemplary of the DHT11Where the required pull-up resistor is already present on the break-out board. So VCC to 5V, GND to GND and the signal line to a digital pin, in the example pin. 7

Here is the sample-to Sketch Download:

 // Modified Example sketch for DHT11 temperature sensor by ladyada, public domain
 // REQUIRES the Following Arduino libraries:
 // - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
 // - Adafruit Unified sensor Lib: https://github.com/adafruit/Adafruit_Sensor
 
 #include "DHT.h"
 #define DHTPIN 7 // digital pin connected to the DHT sensor
 #define DHTTYPE DHT11 // DHT 11
 DHT dht(DHTPIN, DHTTYPE);
 
 void set up() {
   Serial.Begin(9600);
   Serial.Println(F("DHT11 test!"));
   dht.Begin();
 }
 
 void loop() {
   // Wait a few seconds between measurements.
   delay(2000);
   // Read temperature as Celsius (the default)
   float t = dht.read temperature();
   // Check if any reads failed and exit early (to try again).
   IF (isnan(t)) {
     Serial.Println(F("Failed to read from DHT sensor!"));
     return;
  }
   Serial.print(F("Temperature:"));
   Serial.print(t);
   Serial.Println(F("° C"));
   IF (t<12 || t>28)   {
     Serial.Println("Alarm");
  }
 }

Alternatively to the DHT11 you can also DHT22 use:

How to connect him and program the right sketch, you can here Read.

Another possibility would be one GY-BME280 Barometric sensor:

Also, you will find a detailed description and the sketch and circuit diagram in this post.

Local display of the sensor data

Who does not want to do without a local display of the sensor data and the alarm, to be for the micro controllers in the design of the UNO (ie ours Microcontroller Board Atmega328 or D1 NODEMCU with ESP8266) The so-called LCD-keypad shield with a small modification recommended. This shield is equipped with an LCD1602 without the I2C interface. Instead, the digital pins D4 to D9 are used by the display - next to the power supply. This will be the library Liquidcrystal.h installed and included in the sketch. As a modification, I propose the soldering of three spring strips (on the picture on the top and bottom), so that you can achieve the remaining pins well.

The occupancy of the first spring strip below the operating voltage pins is as usual. The analog pins gives access to the analog inputs A1 to A5.

In memory of: These pins can also be used as digital pins D15 to D19 and as the I2C interface (A4 = SDA and A5 = SCL). The analog input A0 is not available, since the buttons are connected via a voltage divider. To find out how it works, I recommend you to write a short sketch that runs the PIN in a loop with analogread (A0). If you then press the buttons, you will see the changed values ​​of the ADC. This can then be opened on how to query the buttons to realize projects, or they look into the blog post A robust robot car with remote control.

Important:

The executed digital pins on the shield (upper spring strip) is not intuitive. Here you get from right to left access to the digital pins D0 = RX, D1 = TX, D2 and D3, and D11 = MOSI, D12 = MISO and D13 = SCK, ie the permanent pins of the SPI interface. The other digital pins are evidenced by the display as described above and not accessible.

Small tip at first commissioning: In the top left picture, the blue potentiometer for the contrast can be seen. I had to turn the small screw many times to the right until the font became visible. And barely visible: Above the display is a small protective film.

To the Download follow the essential lines for the initialization of the display. These program parts can be integrated into the sketches for the sensors.

 /*
 LCD-Keypad-Shield
 */
 
 // The LCD has no I2C adapter
 // The data is transmitted via the pins D4 to D7
 #include
 // LCD Pin to Arduino
 constant int pin_en = 9;
 constant int pin_rs = 8;
 constant int pin_d4 = 4;
 constant int pin_d5 = 5;
 constant int pin_d6 = 6;
 constant int pin_d7 = 7;  
 Liquidcrystal LCD( pin_rs,  pin_en,  pin_d4,  pin_d5,  pin_d6,  pin_d7);
 
 
 void set up() {
 // Initialization of the built-in LCD
   LCD.Begin(16, 2);       // LCD1602 with 16 characters and 2 lines
   LCD.setcursor(0,0);     // Count starts at zero, first sign, then line
   LCD.print("Az-delivery.com");
   LCD.setcursor(0,1);     // 0 = First sign, 1 = second line
   LCD.print("Christmas 2021");
  }
 
 void loop() {
 
 }

For use with the D1-8266-Board I refer to my blog of November 2020.

We now add the components to a construction:

Download the sketch with

  • HC-SR04 to D2 and D3
  • PIR to D15 = A1
  • DHT11 to D16 = A2


Remote display of the sensor data

My blogger colleague Andreas Wolter has even expanded the project and built a Santa Detector with radio transmission:

Since we secretly want to catch Santa, we transfer the sensor data to outside the fireplace room, e.g. in the nursery. We therefore separate the structure and take two atmega328 microcontrollers. On the one we plug the display shield, on the other a prototyping shield and connect the sensors there. Both get an NRF24L01 2.4 GHz radio module. In this way, we can transfer data between both devices. We use the enclosed mini breadboard for the first test to connect the sensors. That looks like this:

Construction with two microcontrollers

For the PIR sensor I soldered legs from wire to a three-pole spring solder and put it there.

Microcontroller with sensors

Follow schematic schedules and pinout:

Switching diagram microcontroller with display shield

Display shield on the microcontroller

NRF24L01 Radio module

GND

GND

3.3V

Vcc

D2

CE

D3

CSN

D11

Mosi

D12

Miso

D13

Sck


The pins numbers for the sensors I have changed for this structure:

Switching diagram microcontroller with sensors

Microcontroller

NRF24L01 Radio module

GND

GND

3.3V

Vcc

D9

CE

D10

CSN

D11

Mosi

D12

Miso

D13

Sck


DHT11 temperature sensor

D8

S (Ignal) / DAT

5V

Vcc

GND

GND


HC-SR04 ultrasonic sensor

GND

GND

D6

Trigger

D7

echo

5V

Vcc


Pir motion sensor

GND

GND

D5

OUT

5V

Vcc

You may use a DHT11 temperature sensor in another version. As can be seen in the circuit diagram, the S-PIN may then be outside. The variant above in the article, as you get it in the AZ shop, has the data spin in the middle. Therefore, make sure exactly on the label on the breakout board, or look into the data sheet.

The NRF24L01 works with an operating voltage of 3.3V. If you also use the optional NRF24L01 Breadboard module, you must supply it with 5V!

The two sketches follow now.

Transmitter module with sensors (Download the sketch)

 #include 
 #include "rf24.h"
 #include "dht.h"
 
 // DHT 11
 #define dhtpin 8
 #define DHTTYPE DHT11 // DHT 11
 
 // HC-SR04
 constant int trigpin = 6;
 constant int echo = 7;
 Dht dht(DHTPIN, DHTTYPE);
 
 // pir
 constant int pirpin = 5;
 
 // RF24 radio module
 RF24 radio(9, 10);   // CE, CS
 constant byte Address[6] = "Santa";
 Char SendValues[15] = {'s', "T ', "a ', "R ', "T ', '\0'};        // StartupCode
 int interval = 200;                                          // send interval
 
 // Read temperature and return
 // DHT11 does not issue any commas,
 // Therefore, the output can be shortened to two digits
 int temperature() {
   float t = dht.Read Temperature();
 
   IF (Isnan(t)) {
     Serial.Println(F("Failed to Read from DHT Sensor!"));
     return -1;
  }
   return (int)t;
 }
 
 // Distance measurement by HC-SR04 ultrasonic module
 // without library
 float distance() {
   unsigned long duration;
   float distance = 0;
 
   digitalwrite(trigpin, Low);
   Delaymicroseconds(2);
   digitalwrite(trigpin, HIGH);
   Delaymicroseconds(10);
   digitalwrite(trigpin, Low);
   duration = pulse(echo, HIGH);
   distance = duration * 0.034 / 2.0;
   return distance;
 }
 
 void set up() {
   Serial.Begin(115200);
   IF (!radio.Begin()) {
     Serial.Println(F("Failed to Read from RF24 Sensor!"));
     whiler (1) {}
  }
   // Start DHT11
   dht.Begin();
 
   // Initialize sensor pins
   pinmode(trigpin, OUTPUT);
   pinmode(echo, Input);
   pinmode(pirpin, Input);
 
   // initialize RF24
   radio.OpenwritingPipe(Address);
   
   // Palevel can be changed for higher Reicher
   // Electricity consumption increases
   radio.setpalevel(RF24_PA_MIN);
   radio.stoplistening();
 
   // Send start code
   radio.writing(&SendValues, sizeof(SendValues));
 }
 
 void loop() {
   // Save sensor values ​​as a string
   sprint(SendValues, "%d:%s:%i", temperature(), String(distance()).C_STR(), digitalRead(pirpin));
   Serial.println(sendValues);
 
   // Sensorwerte an Empfaenger senden
   radio.write(&sendValues, sizeof(sendValues));
 
   // Sendeintervall
   delay(intervall);
 }

Empfängermodul mit Display (Download des Sketches)

 #include 
 #include "RF24.h"
 #include
 
 // LCD Shield Pins
 const int pin_EN = 9;
 const int pin_RS = 8;
 const int pin_D4 = 4;
 const int pin_D5 = 5;
 const int pin_D6 = 6;
 const int pin_D7 = 7;
 LiquidCrystal lcd( pin_RS, pin_EN, pin_D4, pin_D5, pin_D6, pin_D7);
 
 unsigned long interval = 500;
 unsigned long currentMillis = 0;
 unsigned long previousMillis = 0;
 unsigned long blinkTimeout = 4000;
 unsigned long blinkStart = 0;
 int minTemp = 12;
 int maxTemp = 28;
 float startDist = 0.0;
 float maxDist = 10.0;
 bool firstStart = true;
 bool blinkmode = false;
 bool displayToggle = LOW;
 
 // eigene Zeichen für das Bewegungs-Symbol des PIR
 
 byte movement1[] = {
   B00011,
   B00111,
   B01111,
   B01111,
   B01111,
   B01111,
   B00111,
   B00011
 };
 
 byte movement2[] = {
   B00000,
   B10000,
   B10100,
   B10101,
   B10101,
   B10100,
   B10000,
   B00000
 };
 
 byte movement3[] = {
   B00000,
   B00001,
   B00101,
   B10101,
   B10101,
   B00101,
   B00001,
   B00000
 };
 
 byte movement4[] = {
   B11000,
   B11100,
   B11110,
   B11110,
   B11110,
   B11110,
   B11100,
   B11000
 };
 
 // RF24 Funkmodul
 RF24 radio(2, 3); // CE, CSN
 const byte address[6] = "SANTA";
 bool transConnected = false;
 bool started = false;
 char startcode[6] = "start";          // Programm startet, wenn Sendermodul diesen Code sendet
 char recValues[15] = "";
 char *recValuesTemp = NULL;
 int temperatur = 0;
 float dist = 0.0;
 int moving = 0;
 
 // Startprozedur mit Ausgabe auf dem Display
 // und Verbindungsaufbau zum Sender
 void startConnect() {
   lcd.clear();
   lcd.home();
   lcd.print("AZ-Delivery.com");
   lcd.setCursor(0,1);
   lcd.print(" Santa Detector ");
   if (!radio.begin()) {
     lcd.print(" RF24 Sensor is ");
     lcd.print("not responding!!");
     while (1) {}
  }
   radio.openReadingPipe(1, address);
   radio.setPALevel(RF24_PA_LOW);  // RF24_PA_MAX is default.
   radio.startListening();
   delay(2000);
   lcd.clear();
   lcd.home();
   lcd.print(" waiting for");
   lcd.setCursor(0,1);
   lcd.print(" Transmitter... ");
   while(!transConnected) {
     if (radio.available()) {
       radio.read(&recValues, sizeof(recValues));
       if (strstr(recValues, startcode)) {
         transConnected = true;
      }
    }
  }
   lcd.clear();
   lcd.home();
   lcd.print(" Transmitter");
   lcd.setCursor(0,1);
   lcd.print("   connected");
   delay(2000);
   lcd.clear();
   lcd.home();
   lcd.print("Temp Dist Move");
   lcd.setCursor(0,1);
 }
 
 // Sendermodul sendet einen String,
 // der zerlegt und in passende Datentypen
 // gewandelt wird
 // Inhalt: int:float:int
 // ':' als Delimiter
 // Reihenfolge ist Temperatur:Distanz:Bewegung
 void parseValues() {
   int counter = 0;
   recValuesTemp = strtok(recValues, ":");
   while(recValuesTemp != NULL) {
       switch(counter) {
         case 0: {
           temperatur = atoi(recValuesTemp);
           counter++;
        } break;
         case 1: {
           dist = atof(recValuesTemp);
           counter++;
        } break;
         case 2: {
           moving = atoi(recValuesTemp);
           counter++;
        } break;
         default: break;
      }
       recValuesTemp = strtok(NULL, ":");
  }
 }
 
 // Ausgabe der Werte auf dem LCD
 void printValues() {
   lcd.setCursor(0,1);
   lcd.print("               ");
   lcd.setCursor(0,1);
   lcd.print(temperatur);
   lcd.setCursor(2,1);
   lcd.print((char)223);
   lcd.setCursor(3,1);
   lcd.print("C");  
   lcd.setCursor(5,1);
   lcd.print(dist);
   if (moving) {
     lcd.setCursor(12,1);
     lcd.print("   ");
     lcd.setCursor(12,1);
     lcd.write(1);
     lcd.setCursor(13,1);
     lcd.write(2);
     lcd.setCursor(14,1);
     lcd.write(3);
     lcd.setCursor(15,1);
     lcd.write(4);
  }
   else {
     lcd.setCursor(12,1);
     lcd.print("   ");
  }
 }
 
 void setup() {
   lcd.begin(16, 2); // Start LCD
 
   // eigene Symbole initialisieren
   lcd.createChar(1, movement1);
   lcd.createChar(2, movement2);
   lcd.CreateChar(3, Movement3);
   LCD.CreateChar(4, Movement4);
 
   // start procedure start
   StartConnect();
 }
 
 void loop() {
   
   // screen is updated when new
   // received values
   // Interval is determined by the transmitter module
   IF (radio.Available()) {
     radio.reading(&recvalues, sizeof(recvalues));
     parsevalues();
 
     // Calibrate distance measurement
     IF (FirstStart) {
       startup = Dist;
       FirstStart = false;
    }
     PrintValues();
  }
   
   Currentmillis = millis();
   
   // Trigger alarm
   IF ((temperature < mintemp || temperature > MaxeMP || Section(Dist - startup) > maxdist || moving) && !blinking) {
     blinking = true;
     blink = millis();
  }
 
   // Blinking the interval after expiration
   IF (Currentmillis - blink >= blinking && blinking) {
     blinking = false;
     LCD.display();
  }
 
   // Non-blocking blinking of the display
   IF (Currentmillis - Previousmillis >= interval && blinking) {
     display = !display;
     IF (display) {
       LCD.display();  
    }
     else {
       LCD.nodisplay();
    }
     Previousmillis = Currentmillis;
  }    
 }

The transmitter module sends a start code after the start and then the sensor values ​​as a string with a colon as a separator between the sensor values. The interval time, how often data is to be sent, determines the transmitter. The first measured removal of the ultrasonic sensor is stored as a reference. It works quasi like a calibration.

The receiver is waiting for the start code from the transmitter after switching on. So you should first switch on the recipient, then place the transmitter and turn on (or restart).

In the receiver, the string is disassembled from sensor data and converted into suitable data types. The functions from the other sketches was adopted. The tolerated temperature is between 12 and 28 degrees Celcius. The measured distance must not be changed by more than 10 cm and a movement nearby is detected in the nearby, visible through an icon on the display that I have inserted as its own characters into the source code. If an alarm is triggered, the content of the display flashes for a few seconds.

Microcontroller with display

If the distance between transmitter and receiver be too large and no connection is made, you can change this line in both source codes:

 radio.setpalevel(RF24_PA_LOW);

For maximum power, change the transfer parameter in RF24_PA_MAX. But then more power is consumed. It is recommended to use an external voltage source.

To avoid the cable salad on the transmitter module, you can solder the sensors to the prototyping shield. I have soldered spring strips so I can swap the sensors should be a defect.

Sensorshield versed

Sensorshield lost from belowSensorshield soldered with sensors

Sender and receiver

That looks very compact and it can also be designed for this. If you now place the transmitter with the sensors and press your children the recipient in hand, you could possibly provide even more tension on Christmas Eve.

As a further suggestion, you could extend the function of the recipient and additionally bring the keys on the display shield into play.

Have fun checking and at this point I wish a nice Christmas.

Andreas Wolter


Forwarding the alarm in domestic Wi-Fi

For the forwarding of sensor data and possibly an alarm you need two network-enabled micro controllers, e.g. The MCUs with the ESP 8266 or ESP32. How does that work, I have in my blog "Garden houses with Micro Controller and Sensors monitor" - Part 1, Part 2 and part 3 described.

Last but not least

What happens if you get the Santa Claus bodily can not be predicted. Maybe he takes all the presents again? It's best, you spoil him with treats. If you believe the advertisement, you can taste it with red doses of a soft drink. However, if he is as old as I - supposedly he is even older - he certainly prefers a glass of sherry or port and a tablet with peppermint chocolate. And Mohrüben for Rudolf and the other reindeer should also be ready.

Who does not believe in Santa Claus, can tinker with the sensors an alarm system against unwanted visitors.

For arduinoProjects for beginnersSensors

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN