Labs / Bipes + MicroPython / 10 Comprehensive Case

10.5 Smart Classroom Environment Manager

Author: Li Zisheng · Source: FreakStudio open documentation · License: CC BY 4.0

Contents

Young makers, we have already learned how to use individual sensors and peripherals before, and today we are going to take on an extremely practical comprehensive project — the Classroom Environment Monitoring and Comfort Reminder System! Just like a little "environment steward" in the classroom, it can monitor temperature, humidity and light in real time, and once the data goes beyond the "comfort zone", it will use a buzzer and LED to remind everyone, making our classroom a comfortable place to stay forever~

1. Case Introduction

Modules used:

Creative Gameplay:

The system continuously monitors the environmental data of the classroom and displays it in real time on the OLED screen; we have preset a "comfort zone":

Core Learning Points (Essential for Beginners to Master)

  1. Learn multi-sensor collaborative acquisition (simultaneously read temperature, humidity and light intensity data);
  2. Master OLED screen data visualization (converting numerical data into intuitive text display);
  3. Understand the threshold judgment logic (using the conditional judgment "whether the data is within the comfort zone");
  4. Implement multi-peripheral linkage reminder (buzzer and LED trigger alarm simultaneously);
  5. Proficient in using loop monitoring + data refresh (to keep the system running continuously and update in real time).

2. Wiring Instructions

10.5 Smart Classroom Environment Manager

This case requires connecting 5 modules. Please connect them correctly according to the corresponding relationship below to ensure that the pins are not connected incorrectly:

2.1 Wiring of DHT11 Temperature and Humidity Sensor

We connect the DHT11 temperature and humidity sensor module to the development board, and the corresponding relationship is as follows:

Development Board Pins

Module Pins

Description

Pin 12 / GPIO9

DIO

1-Wire communication pin

2.2 Wiring of GL5516 Light Intensity Sensor

We connect the GL5516 light intensity sensor module to the AIN0 interface of the development board, and the corresponding relationship is as follows:

Development Board Pins

Module Pins

Description

GPIO26

AIN

Light intensity analog signal input pin, used to read the analog value of light intensity

GPIO19

NC

-

2.3 Wiring of SSD1306 OLED Display

We connect the SSD1306 OLED display module to the I2C0 interface of the development board, and the corresponding relationship is as follows:

Development Board Pins

Module Pins

Description

Pin 4

SDA

I2C data transmission line, corresponding to I2C0 's SDA

Pin 5

SCL

I2C clock signal line, corresponding to the I2C0 SCL

2.4 Wiring of Passive Buzzer Module

We connect the passive buzzer module to the DIO0 interface of the development board, and the corresponding relationship is as follows:

Development Board Pins

Module Pins

Description

GPIO7

DOUT

PWM output pins and high/low level output pins of MCU

GPIO8

NC

-

2.5 Piranha LED Module Wiring

We connect the Piranha LED light module to the DIO0 interface of the development board, and the corresponding relationship is as follows:

Development Board Pins

Module Pins

Description

GPIO3

DOUT

Level output/PWM output pins on MCU

GPIO2

NC

Do not use

📌 Wiring Tips

3. Program Description

10.5 Smart Classroom Environment Manager

The core of this case lies in the workflow of "real-time data collection → data display → threshold judgment → exception alarm". We break it down in the order of building block assembly, so even beginners can follow along step by step:

  1. Hardware Initialization Block (preliminary step, hidden but critical)
    • DHT11 Initialization: By default, Pin 12/GPIO9 is configured as input mode for reading temperature and humidity data;
    • OLED Initialization: Configure the I2C0 interface (SDA= Pin6, SCL= Pin7) and set the screen size (128×64);
    • Buzzer / LED Initialization: Set the corresponding pins to output mode to prepare for peripheral control.
  2. Infinite Loop Block (repeat while true)
    • Function: Keeps the logic of "collection → display → judgment → alarm" running continuously, with data refreshed once per second.
    • Location: All function blocks must be placed inside this loop.
  3. Data Acquisition Block
    • Read temperature and humidity: use the Read DHT11 Temperature and Read DHT11 Humidity blocks to obtain the current values;
    • Read light intensity: Use the Read RPI Pico ADC Input block to read the analog value of GL5516 (Pin31).
  4. OLED Display Building Block
    • Temperature Display: Display "T: XX℃" at the screen coordinate (20,0);
    • Display Humidity: Display "H: XX%" at coordinates (20,20);
    • Display light intensity: Display "L: XX" at coordinates (20,40);
    • Refresh the screen: Use the Clear OLED Display and Show OLED blocks to update data in real time.
  5. Threshold judgment block (if multi-condition judgment)
    • Configuration: Judge "Temperature < 20 OR Temperature > 28 OR Humidity < 40 OR Humidity > 60 OR Light Intensity < 50";
    • Function: An alarm operation will be triggered as long as any item goes beyond the comfort zone.
  6. Alarm trigger block (if within the branch)
    • Buzzer Beep: Use the PWM #6 block to output a 3000Hz PWM signal to make the buzzer emit a prompt tone;
    • LED blinking: Use the set output pin block to toggle the LED between on and off states;
    • Delay debounce: add a delay of 200 milliseconds to avoid frequent alarm triggering.
  7. Normal state block (else branch, optional)
    • If the environment is within the comfort zone, you can add set output pin to keep the LED on steadily and stop the buzzer from sounding.

Program running effect:

10.5 Smart Classroom Environment Manager

Directly importable building blocks:

Smart classroom environment little steward.xml 24 KB

A Beginner's Guide to Avoiding Common Pitfalls

  1. OLED screen not displaying?
    • Check whether the SDA/SCL pins are connected correctly (Pin6/Pin7) and whether the I2C library is installed properly;
    • Confirm that the screen is properly powered, and you can try restarting the development board before testing again.
  2. Sensor data abnormal / not moving?
    • The DHT11 requires a 2-second warm-up time, remember to add it in the program delay 2 seconds as the initialization delay;
    • GL5516 is an analog sensor whose value changes with light intensity; if the value remains unchanged, check whether the wiring is loose.
  3. Alarm not triggered / Abnormal triggering?
    • Check whether the threshold condition is written incorrectly (for example, writing "AND" instead of "OR");
    • Check whether the pins of the buzzer / LED match the configuration in the program.

✨ Interactive Mini Quiz

  1. Think about it: If we want to change the "comfort zone" to "temperature 18~26℃, humidity 30~70%", which block in the program needs to be modified?
  2. Try it out: Add a "normal status indicator" to the system — when the ambient conditions are within the comfortable range, the LED stays on steadily, and when they go beyond the range, it blinks. Can you incorporate this logic into the code?