Experiment No. 4

  • L4.1 Name

  • RPi - DS1820 sensor send mail
    ( Pi Day - March 14 Pi Zero 2 W )



  • L4.2 General presentation, purpose

  • The laboratory work aims to address the ways of achieving elements of the type Internet of Things (IOT) connected via the protocol SMTP .
    The DS1820 temperature sensor connected to the Rpi, the use of the 1 Wire protocol, Python, represent the proposed ingredients to be used.
    At the end of the laboratory, relevant information will be held about the Linux Kernel configuration possibilities for sensors that can be interrogated over the Internet or that can activate mail services. It is useful to explore the MIT Python course.



  • L4.3 Resources


  • Hardware: Raspberry Pi 0-4 platforms, DS1820 sensors, oscilloscope, router with Internet connection



  • L4.4 Example programs


  • External interrupt handling program in Python

    Temperature reading program from the DS1820 sensor
    Classic mail sending program
    Send mail sensor program
    -------- Video sequence


  • L4.5 Lab Progress/Tracking Mode

  • Python - GPIO Interrupts
    Python programs accept external interrupts generated via GPIO configured as an input port like this:

    > GPIO.setup(40,GPIO.IN, pull_up_down=GPIO.PUD_UP)
    or
    >GPIO.setup(40,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

    Usually an external event can cause the current program to be interrupted and jump to the execution of a handler if the following sequences have been executed:

    GPIO.add_event_detect(40,GPIO.FALLING, callback=fa_ceva, bouncetime=250)

    The program, usually called handler, is defined as a function as follows:

    def fa_ceva(channel):
    .........print("handler is running")
    .........instr1
    .........instr2


    DS1820
    Using Raspi-config, the 1-wire interface is activated as follows:


    In the /boot/config.txt file
    you can add the line:

    dtoverlay=w1-gpio

    like this:

    Its presence can be viewed as follows:
    > ls /sys/bus/w1/devices/
    which will return :


    Loading the driver for the 1 wire sensor is done as follows:

    > sudo modprobe w1-gpio
    > sudo modprobe w1-therm

    Configuring the kernel modules for the temperature sensor can also be done and by adding the following lines to the /etc/module file:
    w1-gpio
    w1-therm
    A directory with the sensor code is created in the /sys/bus/w1/devices/ directory. Here is the file w1_slave which is updated with the temperature data as follows:


    The content of the w1_slave file is:


    Installing the Python module for ds1820 is done as follows:

    > sudo apt-get install python-w1thermsensor
    Recent versions can be located with the command:
    >sudo pip install w1thermsensor
    The pip utility can be installed in the classic way with
    >sudo apt-get install pip.

    The DS1820 sensor connects to pin 7 of the Rpi's extension connector according to the figure below.


    Mail server
    Python has a set of classes from which instances can be created that allow messages to be transmitted using the SMTP protocol. To ensure a high level of security, it is necessary to have a email account set up with the possibility of accessing through 2 levels of passwords according to the specifications below:



    After activating this option, a 2nd password will be generated for accessing the client that will send mail. Programs that will access this client will use this new password which, as a rule, is 16 characters long ensuring an increased level of security.



  • L4.6 Proposed Problems

  • 1. Connect 2 temperature sensors and create a program sequence for reading the data;
    2. Replace the temperature sensor with the humidity sensor DHT11;
    3. Modify the prototype program to send email based on 2 temperatures;
    4. Develop a method to send email with the temperature in the lab. on March 23, 2021.;
    5. Create a program that will send an email with the processor temperature when a button is pressed.



  • L3.7 The experiment can be extended for:



  • - Creation of sensor networks capable of communicating on the Internet;
    - Creation of alarm and protection equipment;
    - Creation of systems for ambient monitoring;
    - Creation of smart homes;
    - Remote actuator activation using messages sent via SMTP.


  • L4.8 Collateral information

  • © 2010-2026 - Embedded Advanced Computer