Skip to main content

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​

ComponentQuantityConnection
Steamania JoyKit V21Main Controller
BME280 Temperature Sensor1I2C Bus
WS2812B Full-Color LED1On-board or External

🔧 Circuit Setup​

  1. BME280 Sensor: Connect to I2C bus (SDA, SCL, VCC, GND)
  2. WS2812B LED: Use on-board LED or connect to dedicated PWM pin

💡 Core Tasks​

Task 1: Enable Temperature Sensor​

  • Use opcode 0xC3 to 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 0xE4 to set LED color
  • Update color in real-time as temperature changes

Task 4: Display Temperature​

  • Use opcode 0x55 to 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 R2E every ~1 second

Line 001: C7 0001 0000

  • Enable WS2812B full-color LED control
  • Required before using opcode 0xE4

Line 002: 10 0028 FFFF

  • Write 0xFFFF to register R28
  • R28 controls foreground color for drawing/text commands
  • 0xFFFF = 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 R2E to R01
  • R00 is used for comparisons, so we copy to R00 first
  • Temperature in R2E is 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 line 020
  • 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 030 to update display and continue loop

Line 020: 04 012C 0028

  • Conditional Jump: If R00 > 300 (30.0°C), jump to line 028
  • 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 030 to 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 from R2E)

Line 031: 02 03E8 0000

  • Delay for 1000 milliseconds (1 second)
  • 03E8 = 1000 in decimal
  • 0000 = 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 RangeLED ColorRGB ValueHex Color
< 20°CGreen(0, 255, 0)00FF00
20-30°CYellow(255, 255, 0)FFFF00
> 30°CRed(255, 0, 0)FF0000

🔍 Key Learning Points​

  1. Sensor Integration: How to enable and read from I2C sensors
  2. Conditional Logic: Using comparison-based jumps for decision making
  3. Color Control: RGB color representation and LED control
  4. Program Flow: Creating main loops with initialization sections
  5. 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:

  1. Add More Color Levels: Add orange (25-30°C) and blue (< 15°C)
  2. Display Temperature Trend: Show if temperature is rising or falling
  3. Add Alarm: Flash LED red if temperature exceeds 35°C
  4. Log Maximum Temperature: Track and display the highest temperature reached
  5. Dual LED System: Use two LEDs with different colors for wider range

Instructions Used in This Project​

OpcodeNameDescriptionDocumentation Link
0x02DelaySet delay time in millisecondsDelay
0x04Greater Than JumpJump if R00 > immediate valueConditional Jumps
0x0EUnconditional JumpJump to specified lineUnconditional Jump
0x10Write RegisterWrite immediate value to registerRegister Operations
0x11Copy RegisterCopy value from one register to anotherRegister Operations
0x55Display TextDisplay register value on screenText Output
0xC3Enable BME280Enable temperature sensor moduleExternal Devices
0xCBEnable WS2812BEnable LED control moduleExternal Devices
0xE4Set LED ColorSet RGB color for specific LEDLights & Music

Additional Reference​