Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:iot-open:remotelab:sut:generalpurpose2:b8 [2020/04/29 23:28] – created pczekalskien: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>Relation between rotation speed and PWM duty cycle is non-linear, thus i.e. switching duty cycle from 200 to 400 does not bring you twice the rotation speed of the fan, as well as won't generate twice as much airflow nor pressure inside air chamber.</note> 
 +
 +=== 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 "analogue" output. There is no need to include any library to operate the fan.
 +
 +=== 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 <Arduino.h>
 +...
 +#define PWMFanPin D8
 +</code>
 +
 +== Step 2 ==
 +In the ''setup()'' section of the code, define GPIO D8 as output and define PWM frequency. It is also a good idea to stop the fan at the beginning of your code. Also, give some time for the BMP sensor (once initialised) to let it relax in current pressure and stabilise readings. At least 10s delay is suggested.
 +<code c>
 +  ...
 +  pinMode(PWMFanPin,OUTPUT);
 +  analogWriteFreq(250);
 +  ...
 +  analogWrite(PWMFanPin,0); //stop FAN
 +  ...
 +  delay(10000);
 +</code>
 +
 +== Step 3 ==
 +Change the fan rotation speed using ''analogWrite(pin, value)'' and keep delays between consecutive changes to let the BMP280 sensor go along with new air pressure in the air chamber:
 +<code c>
 +  ...
 +  analogWrite(PWMFanPin,500);
 +  delay(5000);
 +  ...
 +  //here read air pressure
 +  delay(5000);
 +  ... 
 +  // next rotation speed
 +</code>
 +
 +== Step 4 ==
 +<note warning>Once you're done with your lab, please execute following code to stop the fan. Thank you!</note>
 +Once finished your experiments, please execute the following code, to stop fan:
 +<code c>
 +#include <Arduino.h>
 +#define PWMFanPin D8
 +
 +void setup()
 +{
 +  pinMode(PWMFanPin,OUTPUT);
 +  analogWriteFreq(250);
 +  analogWrite(PWMFanPin,0); //stop FAN
 +}
 +void loop()
 +{
 +  //This section was intentionally left blank
 +}
 +</code>
 +
 +=== 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>Remeber to execute fan stopping code once all your experimentation is finished.</note>
  
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0