Devices & Components
Engineering Kit Motors Backup
Arduino Plug and Make Kit
1 relay module 5 Vdc 10A (assembled)
Jumper Wire Female to Male
12V Power Supply
Female 12V DC Power Connector
Hardware & Tools
Screwdriver (Phillips)
Hot Glue Gun
Super glue
Wire cutter
Software & Tools
Arduino IDE
Project description
Code
PLACITECH Smart Fan
cpp
Arduino Code
1/* Author: PLACITECH 2 * 3 * YouTube: PLACITECH 4 * Instagram: @placitech_ 5 * Tiktok: @placitech 6 * 7 * Use this code to create a Smart Fan that turns on 8 * whenever the temperature of your room gets too hot. 9 * This project was built using the Arduino Plug and Make Kit 10 * and the Modulinos that come with it! 11 * 12 * Have fun! :) 13*/ 14 15//// LIBRARIES. Make sure to have them installed! 16#include "Modulino.h" 17#include "ArduinoGraphics.h" 18#include "Arduino_LED_Matrix.h" 19 20 21//// INSTANCES (Components we will control) 22 23// Modulinos 24ModulinoThermo thermo; 25ModulinoBuzzer buzzer; 26ModulinoPixels leds; 27 28// Arduino UNO built-in LED Matrix 29ArduinoLEDMatrix matrix; 30 31 32//// PINS 33 34// For this project, we'll only use one pin to control the relay that turns on/off the fan 35#define relay 7 36 37 38//// VARIABLES 39 40int temperature; // Stores the current temperature (in degrees Celsius) 41 42// The temperature threshold that triggers the fan (in degrees Celsius) 43// Feel free to change this to what you find too hot! 44int start_temp = 27; 45 46int freq = 1000; // Frequency of the buzzer sound (in Hertz) 47int dur = 250; // Duration of the beep (in milliseconds) 48 49 50//// FUNCTIONS 51 52// Turn the LEDs red (used for alerting high temperature) 53void leds_red(){ 54 for (int i = 0; i < 8; i++) { 55 leds.set(i, RED, 25); 56 leds.show(); 57 } 58} 59 60// Turn the LEDs green (used for signaling normal temperature) 61void leds_green(){ 62 for (int i = 0; i < 8; i++) { 63 leds.set(i, GREEN, 25); 64 leds.show(); 65 } 66} 67 68// Get the room's temperature and show it on the Arduino UNO built-in LED Matrix 69void get_temp(){ 70 temperature = thermo.getTemperature(); // Read the temperature from the sensor 71 Serial.println("Temp = " + String(temperature) + "°C"); // Print it to the Serial Monitor 72 73 // Display temperature starting from the 1st column and 1st row of the LED Matrix 74 matrix.beginText(1, 1, 0xFFFFFF); 75 matrix.println(temperature); 76 matrix.endText(); 77} 78 79 80 81void setup(){ 82 // Start serial monitor 83 Serial.begin(9600); 84 85 // Set the relay pin as an output (to control the fan) 86 pinMode(relay, OUTPUT); 87 digitalWrite(relay, LOW); // Ensure the fan starts off 88 89 // Initialize all connected Modulinos and the built-in matrix 90 Modulino.begin(); 91 thermo.begin(); 92 buzzer.begin(); 93 leds.begin(); 94 matrix.begin(); 95 96 // Set the font size for text displayed on the matrix 97 matrix.textFont(Font_5x7); 98 99 delay(100); // Small startup delay 100} 101 102 103 104void loop(){ 105 // Read temperature every 5 seconds until it reaches the threshold 106 while (temperature < start_temp){ 107 delay(5000); 108 get_temp(); 109 } 110 111 // Alert the user that the threshold was reached using the Serial Monitor 112 Serial.println(); 113 Serial.println("High temperature detected!"); 114 Serial.println("Turning on fan!"); 115 Serial.println(); 116 117 // Alert the user that threshold was reached using the Pixels (LEDs) and Buzzer Modulinos 118 for (int i = 0; i < 3; i++){ 119 buzzer.tone(freq, dur); // Make a beep 120 leds_red(); // Turn LEDs red 121 delay(250); 122 buzzer.tone(0, dur); // Stop the sound 123 leds.clear(); // Turn off LEDs 124 leds.show(); 125 delay(250); 126 } 127 128 // Turn on fan 129 digitalWrite(relay, HIGH); 130 131 // Continue monitoring temperature every 5 seconds 132 // The fan will stay on until the temperature is 1 degree below the threshold 133 // This avoids turning the fan on/off frequently due to minor fluctuations 134 while (temperature >= start_temp - 1){ 135 delay(5000); 136 get_temp(); 137 } 138 139 140 // Alert the user that the temperature is OK using the Serial Monitor 141 Serial.println(); 142 Serial.println("Temperature OK."); 143 Serial.println("Turning off fan."); 144 Serial.println(); 145 146 147 // Alert the user that the temperature is OK using the Pixels (LEDs) and Buzzer Modulinos 148 for (int i = 0; i < 3; i++){ 149 buzzer.tone(freq, dur); 150 leds_green(); 151 delay(250); 152 buzzer.tone(0, dur); 153 leds.clear(); 154 leds.show(); 155 delay(250); 156 } 157 158 // Turn off fan 159 digitalWrite(relay, LOW); 160}
Downloadable files
Fan Blades
3D Model
file.None
Base Supports
3D Model. Remember to print four (4) of these
file.None
DC Motor Fitting
3D Model
file.None
Fan Base
3D Model
file.None
Comments
Only logged in users can leave comments