CircuitGizmos

Electronic Products for Creative Minds

  • Home
  • Gizmo Store/Products
  • Documentation/Datasheets
  • Projects/Libraries
  • GizmoBlog
  • Services/Contact
    • Design
    • Contact Gizmo!
  • Your Gizmo Cart
    • Your Account
You are here: Home / GizmoBlog / MMBasic Language / Input and Output / Measuring Humidity and Temperature

Measuring Humidity and Temperature

The MMBasic 5.0 HUMID command will read the humidity and temperature from a DHT22 humidity/temperature sensor.

The DHT22 can be powered from 3.3V or 5V (5V is recommended) and it should have a pullup resistor (4.7 kohm) on the data line. This is suitable for long cable runs (up to 20 meters) but for short runs the resistor can be omitted as the CGMICROMITE2 (CGMICROKIT) or CGMICROBOARD also provides an internal weak pullup.

To get the temperature or humidity you use the HUMID command with three arguments as follows:


HUMID pin, tVar, hVar


Where:

‘pin’ is the I/O pin to which the sensor is connected. You can use any I/O pin but if the DHT22 is powered from 5V it must be 5V capable. The I/O pin will be automatically configured by MMBasic.

‘tVar’ is a floating point variable in which the temperature is returned

‘hVar’ is a second variable for the humidity.

The temperature is returned as degrees C with a resolution of one decimal place (eg, 23.4) and the humidity is returned as a percentage relative humidity (eg, 54.3). If there is an error (eg, the sensor is not connected or communicating correctly) the command will return 1000 for both the temperature and humidity.

For example:


HUMID pin, temp, humid
PRINT "The temperature is" temp " and the humidity is" humid


The datasheet recommends a one second delay after power up before the first reading is made and a two second interval between each measurement.

A Ton of Documentation

Open all | Close all

Projects made by Gizmo, Friends, and Members

open all | close all

Recent GizmoBlog Musings

  • Altair 8800 using a ColorMax!
  • Re-energizing the ColorMax, Pt. 3

Visit us!

  • Facebook

Electronic Products for Creative Minds

CircuitGizmos is your source for electronic products that help you create your embedded projects. Here at CircuitGizmos.com you will find a friendly store filled with creative products and all of the documentation that you need to use these gizmos.

We create devices that we believe make electronics fun, but we also know that our products are used for professional designs. For decades we have designed products for commercial, military, and medical industries. Our gizmos here are great for engineers and hobbyists alike.

Copyright © 2008+ CircuitGizmos, L.L.C. All rights reserved

Image already added

Recently Viewed Products

Copyright © 2025 · Generate Pro Theme on Genesis Framework · WordPress · Log in