This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:iot-open:remotelab:sut:generalpurpose2:b8 [2020/04/29 23:28] – created pczekalski | en:iot-open:remotelab:sut:generalpurpose2:b8 [2020/07/20 12:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ==== B8: Controlling fan using PWM ==== | ||
| + | In this scenario, you will control a fan using PWM.\\ | ||
| + | The fan pushes air into the air chamber so you may expect air pressure readings provided via integrated BMP280 pressure sensor to increase a bit. Changes should reflect fan rotation speed (non-linear way, as noted below).\\ | ||
| + | Servo is connected to the GPIO D8. | ||
| + | |||
| + | <note tip> | ||
| + | |||
| + | === Target group === | ||
| + | Beginners | ||
| + | |||
| + | === Prerequisites === | ||
| + | Students should get familiar with BMP pressure readings and presenting their value on the LCD display. | ||
| + | |||
| + | he fan is controlled raw PWM signal generated as " | ||
| + | |||
| + | === Scenario === | ||
| + | In this scenario, you will start rotating fan (0 means fan is stopped) and observe air pressure change on the LCD display. | ||
| + | Keep periodical changes of the fan rotation (i.e. every 10s) and experiment with different speeds. The valid range is between 0 and 1023. | ||
| + | |||
| + | === Result === | ||
| + | You should see the fan rotating in the camera. Note, it will be hard to observe rotation speed via camera, so you can observe result indirectly via observing pressure changes on the LCD display. | ||
| + | |||
| + | === Start === | ||
| + | There are no special steps to be performed. | ||
| + | |||
| + | === Steps === | ||
| + | |||
| + | == Step 1 == | ||
| + | Include LCD driver library as presented in scenarios B1 and B2. You need to include a generic Arduino library to control PWM frequency. No other libraries are necessary but for convenience and programming purity, you may define the pin that controls the fan: | ||
| + | <code c> | ||
| + | #include < | ||
| + | ... | ||
| + | #define PWMFanPin D8 | ||
| + | </ | ||
| + | |||
| + | == Step 2 == | ||
| + | In the '' | ||
| + | <code c> | ||
| + | ... | ||
| + | pinMode(PWMFanPin, | ||
| + | analogWriteFreq(250); | ||
| + | ... | ||
| + | analogWrite(PWMFanPin, | ||
| + | ... | ||
| + | delay(10000); | ||
| + | </ | ||
| + | |||
| + | == Step 3 == | ||
| + | Change the fan rotation speed using '' | ||
| + | <code c> | ||
| + | ... | ||
| + | analogWrite(PWMFanPin, | ||
| + | delay(5000); | ||
| + | ... | ||
| + | //here read air pressure | ||
| + | delay(5000); | ||
| + | ... | ||
| + | // next rotation speed | ||
| + | </ | ||
| + | |||
| + | == Step 4 == | ||
| + | <note warning> | ||
| + | Once finished your experiments, | ||
| + | <code c> | ||
| + | #include < | ||
| + | #define PWMFanPin D8 | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | pinMode(PWMFanPin, | ||
| + | analogWriteFreq(250); | ||
| + | analogWrite(PWMFanPin, | ||
| + | } | ||
| + | void loop() | ||
| + | { | ||
| + | //This section was intentionally left blank | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Result validation === | ||
| + | Observe air pressure changes on the LCD. Try to evaluate minimum and maximum values (related to the fan stopped and operating on max rpm. | ||
| + | <note warning> | ||