Temperature sensor: Difference between revisions

From Sensors in Schools
Jump to navigation Jump to search
Line 99: Line 99:


machine.main('main.py')
machine.main('main.py')
</syntaxhighlight>
=== main.py ===
<syntaxhighlight lang="python">
</syntaxhighlight>
=== pymakr.conf ===
<syntaxhighlight lang="python">
</syntaxhighlight>
=== config.py ===
<syntaxhighlight lang="python">
</syntaxhighlight>
=== dth.py ===
<syntaxhighlight lang="python">
</syntaxhighlight>
=== lora.py ===
<syntaxhighlight lang="python">
</syntaxhighlight>
=== onewire.py ===
<syntaxhighlight lang="python">
</syntaxhighlight>
</syntaxhighlight>



Revision as of 19:32, 1 January 2022

Temperature sensor

Applications

Temperature is one of the easiest sensor projects to start with. Applications include:

  • Monitoring the temperature of a smart bee hive, rabbit hutch, chick coop, compost heap, worm farm, aquarium or wetland.
  • Experimenting with concepts related to energy efficient building construction.
  • Temperature compensation for other sensors (sensor values may change with changes in temperature).
  • Making a weather station.

Types of temperature sensors

The are two common temperature sensors that are used.

  • An internal temperature and humidity sensor is the DHT22. This is included in all sensor project to monitor temperature and humidity conditions within the sensor housing. If the temperature gets too hot or too cold within the sensor housing this may shorten the life of the equipment and the batteries.
  • An external temperatures sensor is the DS18B20. External sensors are typically water proof and have a longer cable. They can be used to monitor a range of interesting discovery learning projects.

DHT22 Internal temperature sensor

DS18B20 External temperature sensor

Software installation requirements

Parts list

Item description Number Supplier URL Cost Notes
10K resistor 2 Core Electronics TBA $10 Get pack of 10
10K resistor 2 Core Electronics TBA $10 Get pack of 10
10K resistor 2 Core Electronics TBA $10 Get pack of 10

Electronic circuit construction

  • Atom with Pymakr package installed

MicroPython code for Pycom LoPy4 microcontroller

  • There are several different code segments used on the Pycom LoPy4 microcontroller to monitor temperature.
    • boot.py - bootstrap program that runs first.
    • main.py - main program where program code is contained
    • pymakr.conf - configuration file for Atom and Pymakr package
    • lib - directory that contains additional library files
      • config.py - list of static variables
      • dth.py - library for DHT22 internal temperature sensor
      • lora.py - library for LoRa. Contains private keys
      • onewire.py - onewire library to communicate with DS18B20 external temperature sensor

boot.py

# boot.py -- run on boot-up

import pycom
from machine import UART
import machine
import os
from network import Bluetooth
from network import WLAN

if pycom.heartbeat() == True:
    pycom.heartbeat(False)

if pycom.wifi_on_boot() == True:
  pycom.wifi_on_boot(False)

#wlan = WLAN()
#wlan.deinit()

bluetooth = Bluetooth()
bluetooth.deinit()

uart = UART(0, baudrate=115200)
os.dupterm(uart)

machine.main('main.py')

main.py

pymakr.conf

config.py

dth.py

lora.py

onewire.py

Trouble shooting

Housing construction

Registering to The Things Network

Video tutorials