LAB: Smart mini-fan with STM32-duino
LAB: Smart mini-fan with STM32-duino
I. Introduction
In this lab, you are required to create a simple program that uses arduino IDE for implementing a simple embedded digital application. Refer to online arduino references for the full list of APIs.
Hardware
NUCLEO -F401RE or NUCLEO -F411RE
Ultrasonic distance sensor(HC-SR04), DC motor (RK-280RA)
Software
Arduino IDE
II. Procedure
The program needs to run the Fan only when the distance of an object is within a certain value.
Example: An automatic mini-fan that runs only when the face is near the fan. Otherwise turns off.
As the button B1 is pressed, change the fan velocity. The MODE(states) are
MODE(state): OFF(0%), MID(50%), HIGH(100%)
When the object(face) is detected about 50 mm away, then it automatically pauses the fan temporarily.
Even the fan is temporarily paused, the MODE should be changed whenever the button B1 is pressed
When the object(face) is detected within 50mm, then it automatically runs the fan
It must run at the speed of the current MODE
LED(LED1): Turned OFF when MODE=OFF. Otherwise, blink the LED with 1 sec period (1s ON, 1s OFF)
Print the distance and PWM duty ratio in Tera-Term console (every 1 sec).
Must use Mealy FSM to control the mini-fan
Draw a FSM(finite-state-machine) table and state diagram
Example Table. See below for example codes
III. Configuration
Ultrasonic distance sensor
Trigger:
Generate a trigger pulse as PWM to the sensor
Pin: D10 (TIM4 CH1)
PWM out: 50ms period, 10us pulse-width
Echo:
Receive echo pulses from the ultrasonic sensor
Pin: D7 (Timer1 CH1)
Input Capture: Input mode
Measure the distance by calculating pulse-width of the echo pulse.
USART
Display measured distance in [cm] on serial monitor of Tera-Term.
Baudrate 9600
DC Motor
PWM: PWM1, set 10ms of period by default
Pin: D11 (Timer1 CH1N)
IV. Report & Score
You are required to write a concise lab report in 'md' format. On-Line submission.
Lab Report:
Write Lab Title, Date, Your name
Introduction
Draw State Table and State Diagram to explain your logic [30%]
Explain your source code with necessary comments [30%]
External circuit diagram that connects MCU pins to peripherals(sensor/actuator) [10%]
Demonstration Video. Include the link in the report [30%]
Submit in both PDF and original file (*.md etc)
FSM Examples
Example 1
INPUT:
X: Button Pressed {0, 1}
OUTPUT:
LED {ON, OFF}
STATE:
S0: FAN OFF State
S1: FAN ON State
Moore FSM Table
Mealy FSM Table
Example Code
Example 2
INPUT:
X: Button Pressed {0, 1}
OUTPUT:
VEL {0%, 100%}
LED {ON, OFF}
STATE:
S0: FAN OFF State
S1: FAN ON State
Mealy FSM Table
Moore FSM Table
Example Code
FSM Example 3
INPUT:
X: Button Pressed {0, 1}
Y: Object Detected {0, 1}
OUTPUT:
VEL {0%, 50% 100%}
LED {ON, OFF}
STATE:
S0: FAN OFF State
S1: FAN MID State
S2: FAN HIGH State
P_50: FAN 50% PAUSE State
P_100: FAN 100% PAUSE State
Mealy FSM Table
EXERCISE
Moore FSM Table
Example Code
Last updated