Seeeduino XIAO und das 16 in 1 Sensor Kit - Teil 3 - AZ-Delivery

In Part 1 We had set up the Seeduino Xiao this series and made it ready for operation. In part 2 we then used 8 of the 16 sensors from the 16-in-1 sensor cite and created two mini projects. Now we will use the remaining sensors and create two more mini projects with some of the sensors.

DS1302 real-time clock module

This is a real -time module and is used when we have to keep the date and the time in a project. The CR2032 battery must be installed so that the configuration is not lost, because if the module is separated from the power supply, this data will be deleted and must be reconsidered before use. To use this module with the Seeduino Xiao microcontroller, we can virtuabotixrtc.h Use library. Download the files as a zip and install them via the library management. The following code is used to configure the day and the time. It is only carried out once. To use it in the projects, the line must myrtc.setds1302Time (XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX) Comment or deleted as soon as the day and the time have been set.

(You can also try out other libraries and their examples. If you are looking for "DS1302" in the library administration, then the following code must be re -adjusted.)

#include <Virtuabotixrtc.h>                   // Library use

// Wiring SCLK -> 3, I/O -> 2, CE -> 1
// or clk -> 3, dat -> 2, reset -> 1

// if you change the Wiring Change the pins here
Virtuabotixrtc myrtc(3, 2, 1); 

void set up() {
    Serial.Begin(9600);

     // Set the current date, and time in the following format:
     // seconds, minutes, hours, day of the Week, Day of the Month, Month, Year.

     myrtc.Setds1302Time(00, 26, 10, 3, 1, 5, 2024);

     // here you write your actual time/date as shown above but  
     // "Comment/remove" this function once you're Done
     // The Setup is Done only one time and the module will Continue.
     // Counting it automatically
}

void loop() {
  
    // This allows for the update of variables for time or 
    // Accessing the individual elements.
    Myrtc.update();                                 

    // Start Printing Elements as individuals.
    Serial.print("Current Date / Time:");
    // You can switch between and month if you're USING American System.
    Serial.print(myrtc.Dayofmonth);                     
    Serial.print("/");
    Serial.print(myrtc.Month);
    Serial.print("/");
    Serial.print(myrtc.year);
    Serial.print(" ");
    Serial.print(myrtc.Hours);
    Serial.print(":");
    Serial.print(myrtc.minute);
    Serial.print(":");
    Serial.print(myrtc.seconds);

    // Delay So The Program Doesn't Print non-stop
    delay(1000);
}

Sensor for obstacle recognition

This module uses an infrared stem and recipient. The transmitter sends this infrared light, which is reflected by the object in front of it. The light returns to the module and is recorded by the recipient sensor. The standard measurement circuit with the LM393 compartment of the module receives the digital measurement value and changes the condition of the signal pin that is connected to a PIN of the microcontroller. A campaign programmed by us can then be carried out. The distance to the object should be between 5 mm and 20 mm for optimal reading. An example of the use of this module along with an RTC (Real Time Clock) module can be found in the article about the electronic money box.

(The RTC module is not the one contained in this kit, so that the code would have to be adjusted.)

intimately obstacle_avoid_sensor = 1;
intimately Val;

void set up() { 
      pin mode(obstacle_avoid_sensor,Input);
      Serial.Begin(9600);
}

void loop() { 

      Val=digital read(obstacle_avoid_sensor);

      IF(Val==HIGH) {
            Serial.print("HIGH!");
      } Else { 
            Serial.print("Low!");
      } 
} 


Rain sensor

With the rain sensor of this kit, water drops can be recognized on the sensor plate. The kit consists of two parts: the first is the MD RH plate with printed copper railways on the surface. It behaves like a variable resistance, the value of which changes depending on the amount of water on the surface. The more water hits the measuring plate, the lower the measured resistance. The second part is a measurement module that houses an LM393 compartment and a potentiometer for sensitivity setting. The company works digitally or analogously. The following sketch uses both the digital value (does not rain/rain) and the analog value to display the amount of water in percent.

#define Digital_pin 3
#define Analog_pin 1
#define Sensor_power 2

uint16_t rainval;
Boolean Israining = false;
String raining;

void set up() {
      Serial.Begin(9600);
      pin mode(Digital_pin, Input);
      pin mode(Sensor_power, OUTPUT);
      digital(Sensor_power, Low);
}

void loop() {
      digital(Sensor_power, HIGH);
      delay(10);
      rainval = analogead(Analog_pin);
      Israining = digital read(Digital_pin);
      digital(Sensor_power, Low);
      IF (Israining) {
            raining = "No";
      } Else {
            raining = "Yes";
      }
      rainval = map(rainval, 0, 1023, 100, 0);
      Serial.print("Raining:");
      Serial.print(raining);
      Serial.print("Moisture:");
      Serial.print(rainval);
      Serial.print("%\ n");
      delay(1000);
}

Moisture and temperature sensor DHT11

With the DHT11 sensor we can determine the temperature and the relative humidity with just one port of any microcontroller. You can e.g. DHT Sensor Library Use that is installed via the library manager. Only one PIN is needed to read both values. The sensor is well suited for projects in which the measurements do not have to be very accurate. There is an example of use in the project Matrix display, servos and climate sensors. The following example sketch shows the ambient temperature and humidity in the serial monitor of the Arduino IDE.

#include "DHT.H"
#define Dhtpin 2
#define Dhtype DHT11

Dht dht(Dhtpin, Dhtype);

void set up() {
    Serial.Begin(9600);
    Serial.print(F("DHTXX test!"));

    dht.Begin();
}

void loop() {
 
    delay(2000);
    float h = dht.readhumidity();
    float T = dht.Reading temperature();
    float F = dht.Reading temperature(true);


    IF (Isnan(h) || Isnan(T) || Isnan(F)) {
        Serial.print(F("Failed to Read from DHT Sensor!"));
        return;
    }

    Serial.print(F("Humidity:"));
    Serial.print(h);
    Serial.print(F("% Temperature:"));
    Serial.print(T);
    Serial.print(F("° C"));
    Serial.print(F);
}

Flamet registration sensor

The flaming deformity module also contains an LM393 compartment and a potentiometer to adjust the sensitivity to the sensitivity. The most important component of this module is the infrared receiver sensor that recognizes a flame. Fire generates energy in the form of heat and light, the light spectrum of which extends from ultraviolet to infrared. The latter can be detected with the sensor. We will connect the D0 output signal of the module to PIN 6 of our microcontroller.

intimately flame_sensor = 6;
intimately  Val;

void  set up() {
      pin mode(Led_builtin, OUTPUT);
      pin mode(flame_sensor, Input);
      Serial.Begin(9600);
}

void  loop() {
      Val = digital read(flame_sensor);
      IF(Val==HIGH) {
            digital(Led_builtin,HIGH);
            Serial.print("Fire Not Detected");   
      } Else {
            digital(Led_builtin,Low);
            Serial.print("Fire Detected !!!!");
      }
}


Cycle Sor MQ-2

This sensor serves to detect smoke and flammable gases. Gas concentrations of 300 to 10,000 ppm can be measured.

MQ-alleys use a small heater with an electrochemical sensor that changes its resistance depending on the gas concentration in the air. The supply voltage of the module must be 5 VDC so that the heating works properly. An external power source should be used for sufficient electricity. This sensor is used indoors at room temperature. It has a digital and an analog output.

The MQ-2 gas module is able to track down LPG, I-Buutan, Propan, Methan, Alcohol, Hydrogen and Room, which can be useful in detection of gas leaks and smoke recognition.

intimately Smokea2 = A2;
intimately sensor throat = 400;

void set up() {
      pin mode(Smokea2, Input);
      Serial.Begin(9600);
}

void loop() {
      intimately analog sensor = analogead(Smokea2);

      Serial.print("PIN A2:");
      Serial.print(analog sensor);

      IF (analog sensor > sensor throat) {
            Serial.print("Gas Detected");
      } Else {
            Serial.print("No Gas Detected");
      }
      delay(100);
}

Barometric sensor GY-68 BMP180

This is a small sensor with low power consumption, good stability and high accuracy. It is often used to calculate the air pressure and with the help of compensation of the temperature the flight height of drones, the altitude of weather stations or for navigation. A piezo-resistant technology is used. The module communicates via the I2C interface.

It can be supplied with a voltage of 5V or 3.3V. In the case of Seeduino Xiao, we connect the module with the 3.3 VDC output, the SCL line with PIN 5 and the SDA line with PIN 4. We install the BMP180 library for Arduino from Adafruit in the library administrator and use sketch below . After compiling and uploading, the data is displayed in the serial monitor of the Arduino IDE.

#include <Wire.h>
#include <BMP180.h>

BMP180 BMP180;

void set up() {
      BMP180.init();
      Serial.Begin(9600);
      Serial.print("BMP180 demo");
      IF (!BMP180.hasvalidide()) {
            Serial.print("Error - Please Check the BMP180 Board!");
      }
}

void loop() {
      Serial.print("Temperature:");
      Serial.print(BMP180.getting temperature());
      Serial.print("C");
  
      Serial.print("Pressure:");
      Serial.print(BMP180.gutpressure());
      Serial.print("HPA");
  
      Serial.print();
      delay(2000);
}

Soil moisture sensor

The soil moisture sensor of this kit consists of a probe with two electrodes, which is inserted into the ground to measure the moisture and the comparat module LM393 in order to obtain both analog and digital measurement values ​​here. This module also has a potentiometer to regulate sensitivity.

The digital output of the compatator module two states. In our example we will use it to message "Dry"(dry) or"Wet"(wet). The analog output provides a voltage between 0V and the supply voltage of the module depending on the conductivity of the soil through the soil moisture and converts it into a corresponding number between 0 and 1023. In the case of dry soil, the value is 1023 Soaked soil the value is 0. This value can then be converted into percent as in the following sketch.

#define Digital_pin 3
#define Analog_pin 1

uint16_t humidity_val;
Boolean Iswet = false;
String Wet_soil;

void set up() {
      Serial.Begin(9600);
      pin mode(Digital_pin, Input);
}

void loop() {
      humidity_val = analogead(Analog_pin);
      Iswet = digital read(Digital_pin);
      IF (Iswet) {
            Wet_soil = "Dry";
      } Else {
            Wet_soil = "Wet";
      }
      humidity_val = map(humidity_val, 0, 1023, 100, 0);
      Serial.print("How is the Soil?");
      Serial.print(Wet_soil);
      Serial.print("Moisture:");
      Serial.print(humidity_val);
      Serial.print("%\ n");
      delay(1000);
}

Mini projects part 2

On this occasion we will again create two basic projects with the modules just described. One will be a simple weather station mini project and the other is a fire and gas alarm.

Simple weather station

For this project we will use the DHT11 sensor, the GY-68 BMP180 sensor and the soil moisture sensor. With the DHT11 sensor we will measure the outside temperature and the humidity. The GY-68 BMP180 sensor gives us temperature and atmospheric pressure. On the occasion we will compare the difference in the temperature values ​​of the two sensors. The soil moisture sensor is usually used to measure the degree of moisture in the bottom of a plant. In this case we put it in a glass, the volume of which we know. This enables us to calculate quantity.

It is a handicraft project and will not provide us with such exact data as in a professional weather station. The sketch (Download) is explained by the comments it contains.

Simple fire and gas reporting system

This is a very simple structure of a fire and gas registration alarm. In addition to the MQ-2 and the flame sensor, we need that MB102 power supply With 3.3 VDC and 5 VDC outputs, one bidirectional level converter and that Passive summer module KY-006. We use the level converter because the MQ-2 module 5V needs to heat up and delivers voltages from 0V to 5V at the data output. However, the pins of the Seeeduino Xiao need 3.3V. Therefore we have to adjust this voltage.

If the continuously carried out measurements exceed the specified alarm threshold, the buzzer sounds with a frequency of 700 Hz. If the flame detector determines that it burns, the alarm also sounds until the microcontroller is reset. In the video you can see how it works. This sketch (tooDownload) is explained by the comments.


(If the videos are not displayed, please check the cookie settings of your browser)

We hope that this blog series has aroused its interest and that the examples of the mini projects have suggested their curiosity to implement other projects with the sensors of the 16-in-1 ceiling scorch.

Für arduinoProjekte für anfängerSensoren

Lascia un commento

Tutti i commenti vengono moderati prima della pubblicazione