Components and supplies
Arduino Uno Rev 3
Arduino Sensor Kit - Bundle
Arduino Motor Shield Rev3
Apps and platforms
Arduino IDE 2.0 (beta)
Project description
Code
Arduino code for The Blowhard
cpp
Code written in Arduino .ino, a superset of C++.
1// The Blowhard code - Steven Lightfoot - Version 2024-06-08 PUBLIC 2 3//*****************************oled************************************ 4#include <Arduino.h> 5#include <U8g2lib.h> 6 7#ifdef U8X8_HAVE_HW_SPI 8#include <SPI.h> 9#endif 10#ifdef U8X8_HAVE_HW_I2C 11#include <Wire.h> 12#endif 13 14U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // High speed I2C 15 // THis is the oled Constructor, with some parms to modify incl: U8G2_R2 for screen rotation 180 deg 16 // Note: This is the HW I2C contructor 17 18 // Info from U8G2 on Constructors: 19 // https://github.com/olikraus/u8g2/wiki/u8g2setupcpp#using-dynamically-allocated-page-buffers 20 21//*******************************oled*********************************** 22 23//*******************************DHT20********************************** 24#include "DHT20.h" 25DHT20 DHT; 26//********************************DHT20********************************** 27 28//*******************************BMP280********************************** 29#include "Seeed_BMP280.h" 30#include <Wire.h> 31 32BMP280 bmp280; 33 34// #include "DHT20.h" 35// DHT20 DHT; 36//********************************BMP280********************************** 37 38 39 40// -------------------------------/ 41// --------> global defines and constants 42const int dirPinA = 12; // Arduino motor shield settings 43const int pwmPinA = 3; 44const int brakePinA = 9; 45const int dirPinB = 13; 46const int pwmPinB = 11; 47const int brakePinB = 8; 48// -------------------------------/ 49 50 51 52// --------> global variables including objects 53// int button_state = 0; // Not used in this version of The Blowhard code 54unsigned long count = 0; // uint8_t count = 0; 55unsigned long previousTime_1 = 0; // For Millis() timing 56const long eventTime_1_TC = 10000; //in ms, interval for measuring Temp in C 57unsigned long previousTime_2 = 0; // For Millis() timing 58const long eventTime_2_WS = 60000; //in ms, interval for measuring data from WeatherStation (Rh and Baro) 59float temptest = 0.0; // For Rate of Rise comparator 60// --------------------------/ 61 62 63 64// --------> user defined function proottypes 65void StartWarning(); 66void WeatherStation(); 67void RampTestA(); 68void RampTestB(); 69// --------------------------------------------------------------------------------------------------------------------------------------/ 70 71 72 73 74// ******************* SETUP START ************************* 75void setup() { 76 77 // pinMode(6, OUTPUT); // LED initialize, in case it is used - not used in this code 78 pinMode(5, OUTPUT); // Start warning tones 79 // pinMode(4, INPUT); // Start button - not used in this code 80 81 pinMode(dirPinA, OUTPUT); // Arduino motor shield parms 82 pinMode(pwmPinA, OUTPUT); 83 pinMode(brakePinA, OUTPUT); 84 85 pinMode(dirPinB, OUTPUT); 86 pinMode(pwmPinB, OUTPUT); 87 pinMode(brakePinB, OUTPUT); 88 89 // pinMode(A0, INPUT); // For Arduino Motor Shield Current Sending, Not used in this code 90 // pinMode(A1, INPUT); // For Arduino Motor Shield Current Sending, Not used in this code 91 92 Serial.begin(9600); 93 94 //**************BMP280*************** 95// if(!bmp280.init()){ 96// Serial.println("Device error!"); 97 98 bmp280.init(); // inserted this on speculation, and it seemd to have initialized and started data flowing 99 100 Wire.begin(); // this begin may be redundant 101// DHT.begin(); // ESP32 default pins 21 22 102//**************BMP280*************** 103 104//**************oled**************** 105 u8g2.begin(); 106 u8g2.enableUTF8Print(); // enable UTF8 support for the Arduino print() function 107//**************oled**************** 108 109//**************DHT20*************** 110 Wire.begin(); 111 DHT.begin(); // ESP32 default pins 21 22 112//**************DHT20*************** 113 114 } 115// ******************** SETUP END ************************** 116 117 118 119// ********************************************* MAIN START **************************************************************** 120void loop() { 121 122 unsigned long currentTime = millis(); 123 124 if ( currentTime - previousTime_1 >= eventTime_1_TC) // Check and display temp every 10 secs and do Rate-of-Rise check 125 126 { count++; 127 128 // ********DHT20 related code ************** 129 int status = DHT.read(); 130 float T = DHT.getTemperature(); 131 // ********DHT20 related code ************** 132 133 //***********oled relate code ************* 134 u8g2.firstPage(); 135 do { u8g2.setFont(u8g2_font_spleen32x64_mr); 136 u8g2.setFontDirection(0); 137 u8g2.drawStr(0,52,"Tc"); 138 u8g2.setCursor(64, 52); 139 u8g2.print(T, 0); 140 u8g2.sendBuffer(); 141 u8g2.clearBuffer(); 142 delay(1000); 143 } while ( u8g2.nextPage() ); 144 u8g2.clearBuffer(); 145 u8g2.sendBuffer(); 146 //***********oled relate code ************* 147 148 previousTime_1 = currentTime; 149 150 if ( T - temptest > 2.0 && count >1 ) // Rate-of-Rise check - count variable ensures if statement is false on first iteration 151 152 { StartWarning(); RampTestA(); RampTestB(); RampTestA(); RampTestB(); RampTestA(); RampTestB(); } 153 154 temptest = T; 155 156 } 157 158 159 if ( currentTime - previousTime_2 >= eventTime_2_WS) // Run Weather Station fuction every 60 secs (ie display Rh and Baro) 160 161 { 162 163 WeatherStation(); 164 165 previousTime_2 = currentTime; 166 167 } 168} 169 170// ********************************************** MAIN END ****************************************************************** 171 172 173 174// ** begin *********************** RampTestA ************************************ 175void RampTestA() 176{ digitalWrite(dirPinA, HIGH); // Set direction pin HIGH to establish which direction this is in real life (counter-clockwise Pilot View) 177 digitalWrite(brakePinA, LOW); // confirm motorbrake is OFF 178 analogWrite(pwmPinA, 60); delay(3000); // Start run 179 for (int i = 60; i < 120; i++) { analogWrite(pwmPinA, i); delay(75); } // Accelerate forward 180 delay(14000); 181 for (int i = 120; i >= 30; i--) { analogWrite(pwmPinA, i); delay(75); } // Decelerate forward 182 delay(2000); 183 analogWrite(pwmPinA, 0); } 184// *** end ************************ RampTestA ************************************ 185 186 187 188// ** begin *********************** RampTestB ************************************ 189void RampTestB() 190{ digitalWrite(dirPinB, HIGH); // Set direction pin HIGH to establish which direction this is in real life (counter-clockwise Pilot View) 191 digitalWrite(brakePinB, LOW); // confirm motorbrake is OFF 192 analogWrite(pwmPinB, 60); delay(3000); 193 for (int i = 60; i < 120; i++) { analogWrite(pwmPinB, i); delay(75); } // Accelerate forward 194 delay(14000); 195 for (int i = 120; i >= 30; i--) { analogWrite(pwmPinB, i); delay(75); } // Decelerate forward 196 delay(2000); 197 analogWrite(pwmPinB, 0); } 198// *** end ************************ RampTestB ************************************ 199 200 201 202// ** begin *********************** Function StartWarning ************************************ 203 204void StartWarning() 205 206{ 207 tone(5, 175); //Set the voltage to high and makes a noise 208 delay(800);//Waits for 1000 milliseconds 209 210 tone(5, 494); //Set the voltage to high and makes a noise 211 delay(800);//Waits for 1000 milliseconds 212 213 tone(5, 740); //Set the voltage to high and makes a noise 214 delay(800);//Waits for 1000 milliseconds 215 noTone(5);//Sets the voltage to low and makes no noise 216 } 217// *** end ************************ Function StartWarning ************************************ 218 219 220 221// ** begin *********************** Function WeatherStation ********************************** 222 223void WeatherStation() 224 225{ 226 227//********DHT20 related code ************** 228int status = DHT.read(); // A read has to be executed to get a reading, the variable status is filled but never used 229float RH = DHT.getHumidity(); // get RH 230float T = DHT.getTemperature(); // get T C 231//********DHT20 related code ************** 232 233//********BMP280 related code ************** 234 235// float temp = bmp280.getTemperature(); 236float pressure = bmp280.getPressure(); 237 238float PressCorrhPa = (pressure/100.) + 12.973; // 12.973 hPa is the Sea Level correction for 15 Goldridge at 107 MASL 239 // https://en-ca.topographic-map.com/map-p6dmt/Ottawa/ 240 // http://www.csgnetwork.com/barcorrecthcalc.html (I used this correction) 241 // another resource: https://www.engineeringtoolbox.com/barometers-elevation-compensation-d_1812.html 242 243 244//********BMP280 related code ************** 245 246//***********oled relate code ************* 247 u8g2.firstPage(); // https://github.com/olikraus/u8g2/wiki/u8g2reference#firstpage 248 249 do { 250 u8g2.setFont(u8g2_font_spleen32x64_mr); // 15 pixel height, letters and numbers - u8g2_font_ncenB14_tr - lucida 251 // 19 pixel height, letters and numbers - u8g2_font_luRS19_te - lucida 252 // 40 pixelheight, letters Ucase and Lcase and numbers - u8g2_font_spleen32x64_mr - spleen 253 254 u8g2.setFontDirection(0); // https://github.com/olikraus/u8g2/wiki/u8g2reference#setfontdirection 255 256 u8g2.drawStr(0,52,"Rh"); 257 u8g2.setCursor(64, 52); // set position x,y for print 258 u8g2.print(RH, 0); // print float with zero decimal places 259 260 u8g2.sendBuffer(); // send to screen 261 u8g2.clearBuffer(); 262 delay(2000); 263 264 u8g2.drawStr(0,52,"Baro"); 265 u8g2.sendBuffer(); // send to screen 266 u8g2.clearBuffer(); 267 delay(500); 268 269 u8g2.drawStr(0,52,"Corr"); 270 u8g2.sendBuffer(); // send to screen 271 u8g2.clearBuffer(); 272 delay(500); 273 274 u8g2.drawStr(0,52," hPa"); 275 276 u8g2.sendBuffer(); // send to screen 277 u8g2.clearBuffer(); 278 delay(500); 279 280 u8g2.setCursor(0, 52); // set position x,y for print 281 u8g2.print(PressCorrhPa, 0); // print float with zero decimal places 282 283 u8g2.sendBuffer(); // send to screen 284 u8g2.clearBuffer(); 285 delay(2000); 286 287 } while ( u8g2.nextPage() ); // https://github.com/olikraus/u8g2/wiki/u8g2reference#nextpage 288 289 u8g2.clearBuffer(); 290 u8g2.sendBuffer(); 291 //delay(1000); 292 293//***********oled relate code ************* 294 295} 296 297// ** end ****************************** Function WeatherStation **********************************
Documentation
EUDAX size 130 DC motors and fans
Eudax 130 DC motor and prop set.png
Power Supply used
Power supply Stated 6 VDC Actual 8 VDC 800 mA limit.png
The Blowhard closeup 1
The Blowhard closeup 1.png
The Blowhard closeup 2
The Blowhard closeup 2.png
The Blowhard closeup 3
The Blowhard closeup 3.png
The Blowhard iso view
The Blowhard iso view.png
The Blowhard oled SSD1315 U8g2 constructor information
The Blowhard oled SSD1315 U8g2 contructor information.png
The Blowhard overall view during fan-motor B testing
The Blowhard overall view during fan-motor B testing.png
Comments
Only logged in users can leave comments
The Blowhard - HVAC Circulation Blower Assist | Arduino Project Hub