| HomeTurtlegraficsGPanelRoboticsGameGrid WebTigerPython |
| Python - Online |
![]()
YOU LEARN HERE... |
how to connect high-precision sensors to the micro:bit via the I2C interface and use them to measure air quality, temperature and humidity. |
SGP30 AIR QUALITY SENSOR |
The SGP30 air quality sensor provides highly accurate measurements of the CO2concentration in the air. When the CO2 concentration increases, the air in a room is no longer fresh, which can cause tiredness and increase the risk of virus transmission. |
|
|||||||
To place an order, send an email to the following address: |
EXAMPLES |
Program: from microbit import * # sgp--------------------- raw = [0, 0] buf = [0,0,0,0,0,0] i2c.write(0x58, bytearray([0x20,0x03])) sleep(1500) def getValues(a=0x58): i2c.write(0x58, bytearray([0x20,0x08])) sleep(600) block = i2c.read(0x58, 6) buf = [0,0,0,0,0,0] for i in range(0,6): buf[i]=block[i] for i in range(0,2): raw[i]= buf[i*3] raw[i]<<=8 raw[i]|=buf[i*3+1] return (raw[0], raw[1]) #------------------------------ while True: co2, voc = getValues() print ("CO2 = ", co2, " TVOC = ", voc) sleep(500) |
Program: from microbit import * # sht------------------------- def getValues(a = 0x44): i2c.write(a, b'\x2c\x06') raw = i2c.read(a, 6) t, h = (raw[0] << 8) + raw[1], (raw[3] << 8) + raw[4] return -45 + (175 * (t / 65535)), 100 * (h / 65535) #----------------------------- while True: temp, humi = getValues() print(temp, humi) sleep(500) |
REMEMBER... |
The SGP30 sensor provides CO2-equivalent (eCO2) values in ppm (parts per million), ranging from 400 to 60,000. Values below 1000 indicate good air quality, while values above 1400 suggest that the room should be ventilated immediately. Poor ventilation can increase the risk of airborne virus transmission. The SHT85 sensor measures temperature in °C and relative humidity in %, returning values with four decimal places. Since these external sensors are not directly supported by the microbit module, you need to include the corresponding program block #sgp-------- or #sht------- in each application. The sensors are connected to the micro:bit via a hub with several I2C connectors. The mbHub and SensorLink are designed so that they can also be used to connect additional I2C sensors and electronic components. |
EXERCISES |
|
![]()