Skip to main content

Project 6: Smart Curtain (60 points)

Task Description​

Design a smart curtain system using a motor, driver module, and multiple sensors (buttons, remote control, voice, etc.). Includes three sub-tasks:

  1. Button Control: Press buttons to control forward/reverse rotation for 1 second
  2. Remote Control: Long-press remote buttons for forward/reverse (stop when released)
  3. Voice Control: Voice commands control forward/reverse rotation for 1 second

Encourage implementing multiple tasks with a single program.

Core Concepts: Motor forward/reverse control, and diverse human-computer interaction through different sensors (digital input, analog remote signals, voice recognition) for the same controlled object (motor).

Required Hardware​

  • Steamania JoyKit V2 (Main Controller)
  • DC Motor Module
  • Motor Driver Module (L298N or similar)
  • Push Button Module (2 buttons: forward/reverse)
  • IR Remote Control Module
  • Voice Recognition Module (optional)

Core Tasks​

Task 1: Button Control (20 points)​

  • Press forward button → motor rotates forward for 1 second
  • Press reverse button → motor rotates reverse for 1 second

Task 2: Remote Control (20 points)​

  • Long-press remote forward button → motor rotates forward (stop when released)
  • Long-press remote reverse button → motor rotates reverse (stop when released)

Task 3: Voice Control (20 points)​

  • Say "Open Curtain" → motor rotates forward for 1 second
  • Say "Close Curtain" → motor rotates reverse for 1 second

Reference Solution​

Program Code​

; Smart Curtain Program
; Implements button, remote, and voice control for motor

; Initialization - Lines 000-005
000 C1 0001 0000 ; Enable button input
001 C2 0001 0000 ; Enable IR remote control
002 C4 0001 0000 ; Enable voice recognition (optional)
003 C9 0001 0000 ; Enable motor control
004 0E 0000 0010 ; Jump to main loop at line 010

; Main Loop - Check All Inputs - Lines 010-03F
010 04 0001 0020 ; If button pressed (R01 > 0), jump to button control
011 04 0002 0030 ; If remote pressed (R02 > 0), jump to remote control
012 04 0003 0040 ; If voice detected (R03 > 0), jump to voice control
013 D9 0000 0000 ; Stop motor (no input)
014 0E 0000 0010 ; Jump back to line 010 (continue monitoring)

; Button Control - Lines 020-02F
020 04 0064 0024 ; If R01 > 100 (forward button), jump to forward
021 04 00C8 0028 ; If R01 > 200 (reverse button), jump to reverse
022 0E 0000 0010 ; No valid button, return to main loop

024 D9 0001 0000 ; Motor forward
025 02 03E8 0000 ; Delay 1000ms (1 second)
026 D9 0000 0000 ; Stop motor
027 0E 0000 0010 ; Return to main loop

028 D9 0002 0000 ; Motor reverse
029 02 03E8 0000 ; Delay 1000ms (1 second)
02A D9 0000 0000 ; Stop motor
02B 0E 0000 0010 ; Return to main loop

; Remote Control - Lines 030-03F
030 04 000A 0034 ; If R02 == 10 (remote button A), forward
031 04 0014 0038 ; If R02 == 20 (remote button B), reverse
032 0E 0000 0010 ; No valid remote, return to main loop

034 D9 0001 0000 ; Motor forward (while button held)
035 04 000A 0034 ; Check if button still pressed
036 02 0064 0000 ; Delay 100ms
037 0E 0000 0034 ; Continue holding

038 D9 0002 0000 ; Motor reverse (while button held)
039 04 0014 0038 ; Check if button still pressed
03A 02 0064 0000 ; Delay 100ms
03B 0E 0000 0038 ; Continue holding

; Voice Control - Lines 040-04F
040 04 0001 0044 ; If R03 == 1 (voice "Open"), forward
041 04 0002 0048 ; If R03 == 2 (voice "Close"), reverse
042 0E 0000 0010 ; No voice command, return to main loop

044 D9 0001 0000 ; Motor forward
045 02 03E8 0000 ; Delay 1000ms (1 second)
046 D9 0000 0000 ; Stop motor
047 0E 0000 0010 ; Return to main loop

048 D9 0002 0000 ; Motor reverse
049 02 03E8 0000 ; Delay 1000ms (1 second)
04A D9 0000 0000 ; Stop motor
04B 0E 0000 0010 ; Return to main loop

Detailed Explanation​

Initialization (Lines 000-005)​

Line 000: C1 0001 0000

  • Enable button input module
  • Required for physical button control

Line 001: C2 0001 0000

  • Enable IR remote control module
  • Required for remote control operation

Line 002: C4 0001 0000

  • Enable voice recognition module
  • Optional for voice command control

Line 003: C9 0001 0000

  • Enable motor control module
  • Required for motor operation

Line 004: 0E 0000 0010

  • Jump to main loop at line 010

Main Loop - Input Monitoring (Lines 010-014)​

Line 010: 04 0001 0020

  • Conditional Jump: If button pressed (R01 > 0), go to button control

Line 011: 04 0002 0030

  • Conditional Jump: If remote pressed (R02 > 0), go to remote control

Line 012: 04 0003 0040

  • Conditional Jump: If voice detected (R03 > 0), go to voice control

Line 013: D9 0000 0000

  • Stop motor (no active input)

Line 014: 0E 0000 0010

  • Continue monitoring loop

Task 1: Button Control (Lines 020-02B)​

Line 020: 04 0064 0024

  • Conditional Jump: If R01 > 100 (forward button threshold)
  • Button value > 100 indicates forward button pressed

Line 021: 04 00C8 0028

  • Conditional Jump: If R01 > 200 (reverse button threshold)
  • Button value > 200 indicates reverse button pressed

Line 024: D9 0001 0000

  • Motor forward rotation
  • Instruction 0xD9 controls motor direction

Line 025: 02 03E8 0000

  • Delay 1000ms (1 second)
  • Fixed duration for button control

Line 026: D9 0000 0000

  • Stop motor

Task 2: Remote Control (Lines 030-03B)​

Line 030: 04 000A 0034

  • Conditional Jump: If R02 == 10 (remote button A code)
  • Remote sends specific codes for each button

Line 031: 04 0014 0038

  • Conditional Jump: If R02 == 20 (remote button B code)

Line 034: D9 0001 0000

  • Motor forward while button held

Line 035: 04 000A 0034

  • Check if button still pressed

Line 036: 02 0064 0000

  • Delay 100ms

Line 037: 0E 0000 0034

  • Continue holding if button pressed

Key Difference: Remote control uses "press and hold" logic - motor runs only while button is pressed.

Task 3: Voice Control (Lines 040-04B)​

Line 040: 04 0001 0044

  • Conditional Jump: If R03 == 1 (voice command "Open")
  • Voice module maps commands to register values

Line 041: 04 0002 0048

  • Conditional Jump: If R03 == 2 (voice command "Close")

Line 044: D9 0001 0000

  • Motor forward for 1 second

Line 045: 02 03E8 0000

  • Delay 1000ms

Line 046: D9 0000 0000

  • Stop motor

Key Concepts​

1. Motor Control​

Use instruction 0xD9 for motor control:

  • D9 0001 0000 = Forward rotation
  • D9 0002 0000 = Reverse rotation
  • D9 0000 0000 = Stop

2. Input Priority​

The program checks inputs in order:

  1. Button control (highest priority)
  2. Remote control
  3. Voice control (lowest priority)

3. Control Modes​

  • Button Mode: Fixed 1-second duration
  • Remote Mode: Continuous while held (momentary)
  • Voice Mode: Fixed 1-second duration

4. Sensor Integration​

Multiple sensors can control the same actuator:

  • Buttons: Digital input (R01)
  • Remote: Analog/digital input (R02)
  • Voice: Digital input (R03)

Assessment Rubric​

CriteriaExcellent (5)Good (4)Satisfactory (3)Needs Improvement (2)
Button ControlReliable button operationMinor issuesWorks with delaysButtons not working
Remote ControlSmooth press-and-holdMinor lagWorks inconsistentlyRemote not functioning
Voice ControlAccurate voice recognitionOccasional errorsLimited recognitionVoice not working
Motor ControlSmooth forward/reverseMinor issuesRough operationMotor not working properly
IntegrationAll 3 modes work seamlesslyMinor integration issuesModes work separatelyIntegration fails
Code QualityClean, modular codeGood structureCode works but messyCode doesn't work

Extension Challenges​

  1. Position Sensing: Add limit switches to detect fully open/closed positions
  2. Auto-Close: Automatically close curtain at sunset using light sensor
  3. Obstacle Detection: Stop motor if obstacle detected (current sensing)
  4. Scheduling: Program curtain to open/close at specific times
  5. App Control: Add Bluetooth/WiFi for smartphone control