Project 1: Indoor Temperature Monitoring System
🎯 Project Objectives
Build a temperature monitoring system that:
- Continuously monitors ambient temperature using BME280 sensor
- Changes LED color based on temperature (Green → Yellow → Red)
- Displays real-time temperature values on screen
📋 Required Hardware
| Component | Quantity | Connection |
|---|---|---|
| Steamania JoyKit V2 | 1 | Main Controller |
| BME280 Temperature Sensor | 1 | I2C Bus |
| WS2812B Full-Color LED | 1 | On-board or External |
🔧 Circuit Setup
- BME280 Sensor: Connect to I2C bus (SDA, SCL, VCC, GND)
- WS2812B LED: Use on-board LED or connect to dedicated PWM pin
💡 Core Tasks
Task 1: Enable Temperature Sensor
- Use opcode
0xC3to enable BME280 module - Temperature value will be automatically stored in register
R2E
Task 2: Read Temperature and Map to Color
- Read temperature from
R2E(value × 10, e.g., 25.3°C = 253) - Implement color mapping logic:
- Low Temp (< 20°C): Green (0x00FF00)
- Medium Temp (20-30°C): Yellow (0xFFFF00)
- High Temp (> 30°C): Red (0xFF0000)
Task 3: Control LED Color
- Use opcode
0xE4to set LED color - Update color in real-time as temperature changes
Task 4: Display Temperature
- Use opcode
0x55to display temperature on screen - Show value with one decimal place
📝 Reference Solution
Program Code
000 C3 0001 0000 ; Enable BME280 temperature sensor
001 C7 0001 0000 ; Enable WS2812B LED control
002 10 0028 FFFF ; Set foreground color to white (for text)
003 0E 0000 0010 ; Jump to main loop at line 010
; Main Loop - Start at line 010
010 11 0001 002E ; Copy R2E (temperature) to R01 for processing
011 04 00C8 0020 ; If R00 > 20.0°C (200), jump to check high temp
012 E4 00FF 0000 ; Set LED to GREEN (temp < 20°C)
013 0E 0000 0030 ; Jump to display update
020 04 012C 0028 ; If R00 > 30.0°C (300), jump to high temp
021 E4 00FF FF00 ; Set LED to YELLOW (20°C ≤ temp ≤ 30°C)
022 0E 0000 0030 ; Jump to display update
028 E4 00FF 0000 ; Set LED to RED (temp > 30°C)
; Display Update - Line 030
030 55 0000 0011 ; Display temperature at position (0,0)
031 02 03E8 0000 ; Delay 1000ms (1 second)
032 0E 0000 0010 ; Jump back to line 010 (loop)
Detailed Explanation
Initialization (Lines 000-003)
Line 000: C3 0001 0000
- Enable BME280 temperature and humidity sensor
- After enabling, temperature is automatically stored in
R2Eevery ~1 second
Line 001: C7 0001 0000
- Enable WS2812B full-color LED control
- Required before using opcode
0xE4
Line 002: 10 0028 FFFF
- Write
0xFFFFto registerR28 R28controls foreground color for drawing/text commands0xFFFF= White in RGB565 format
Line 003: 0E 0000 0010
- Unconditional jump to line
010 - Skips over the temperature checking logic to start the main loop
Temperature Checking Logic (Lines 010-028)
Line 010: 11 0001 002E
- Copy temperature value from
R2EtoR01 R00is used for comparisons, so we copy toR00first- Temperature in
R2Eis stored as value × 10 (e.g., 25.3°C = 253 = 0x00FD)
Line 011: 04 00C8 0020
- Conditional Jump: If
R00 > 200(20.0°C), jump to line020 00C8= 200 in decimal = 20.0°C- If temperature ≤ 20°C, continue to next line (set LED to green)
Line 012: E4 00FF 0000
- Set LED #0 to GREEN color
- Format:
E4 [LED_Index] [R][G] [B] 00FF 0000= Green in RGB format
Line 013: 0E 0000 0030
- Jump to line
030to update display and continue loop
Line 020: 04 012C 0028
- Conditional Jump: If
R00 > 300(30.0°C), jump to line028 012C= 300 in decimal = 30.0°C- If temperature ≤ 30°C, continue to next line (set LED to yellow)
Line 021: E4 00FF FF00
- Set LED #0 to YELLOW color
00FF FF00= Yellow in RGB format
Line 022: 0E 0000 0030
- Jump to line
030to update display and continue loop
Line 028: E4 00FF 0000
- Set LED #0 to RED color (temperature > 30°C)
00FF 0000= Red in RGB format- Falls through to line
030(no jump needed)
Display and Loop (Lines 030-032)
Line 030: 55 0000 0011
- Display temperature value at screen position (0, 0)
- Format:
55 [X:Y] [Value:Color] - Shows the value in
R01(which contains temperature fromR2E)
Line 031: 02 03E8 0000
- Delay for 1000 milliseconds (1 second)
03E8= 1000 in decimal0000= Milliseconds unit- Prevents too-fast updates and makes changes visible
Line 032: 0E 0000 0010
- Unconditional jump back to line
010 - Creates infinite loop for continuous monitoring
🎨 Color Mapping Table
| Temperature Range | LED Color | RGB Value | Hex Color |
|---|---|---|---|
| < 20°C | Green | (0, 255, 0) | 00FF00 |
| 20-30°C | Yellow | (255, 255, 0) | FFFF00 |
| > 30°C | Red | (255, 0, 0) | FF0000 |
🔍 Key Learning Points
- Sensor Integration: How to enable and read from I2C sensors
- Conditional Logic: Using comparison-based jumps for decision making
- Color Control: RGB color representation and LED control
- Program Flow: Creating main loops with initialization sections
- Data Representation: Understanding temperature scaling (×10)
🧪 Testing Checklist
- BME280 sensor is properly connected and enabled
- LED changes to green when temperature < 20°C
- LED changes to yellow when 20°C ≤ temperature ≤ 30°C
- LED changes to red when temperature > 30°C
- Temperature value displays correctly on screen
- Updates occur approximately once per second
💡 Extension Challenges
Try these modifications to deepen your understanding:
- Add More Color Levels: Add orange (25-30°C) and blue (< 15°C)
- Display Temperature Trend: Show if temperature is rising or falling
- Add Alarm: Flash LED red if temperature exceeds 35°C
- Log Maximum Temperature: Track and display the highest temperature reached
- Dual LED System: Use two LEDs with different colors for wider range
📚 Related Documentation
Instructions Used in This Project
| Opcode | Name | Description | Documentation Link |
|---|---|---|---|
0x02 | Delay | Set delay time in milliseconds | Delay |
0x04 | Greater Than Jump | Jump if R00 > immediate value | Conditional Jumps |
0x0E | Unconditional Jump | Jump to specified line | Unconditional Jump |
0x10 | Write Register | Write immediate value to register | Register Operations |
0x11 | Copy Register | Copy value from one register to another | Register Operations |
0x55 | Display Text | Display register value on screen | Text Output |
0xC3 | Enable BME280 | Enable temperature sensor module | External Devices |
0xCB | Enable WS2812B | Enable LED control module | External Devices |
0xE4 | Set LED Color | Set RGB color for specific LED | Lights & Music |
Additional Reference
- Register Map - Complete register documentation
- Instruction Set Summary - Full instruction set overview