Devices & Components
Arduino Uno Rev3
NPN Transistor
Resistor 150 Ohm ¼ w
Wires
Led RGB
Temperature Sensor - TMP36
Small DC Motor
10kohm Potentiometer
LCD 16X2
Resistor 1k Ohm
pushbutton (generic)
Breadboard
Software & Tools
Tinkercad
Project description
Code
FinalProjectCode
cpp
Code that runs the fan and LCD logic.
1#include <LiquidCrystal.h> 2 3//motor 4const int DC_MOTOR = 3; 5 6//LCD 7const int RS = 4; 8const int E = 5; 9const int DB4 = 6; 10const int DB5 = 7; 11const int DB6 = 8; 12const int DB7 = 9; 13 14//temp sensor 15const int TEMP_SENSOR = A0; 16 17//LED 18const int RED_LED = 10; 19const int BLUE_LED = 11; 20const int GREEN_LED = 12; 21 22//degree character 23const char DEGREE = (char) 178; 24 25//initialize LCD 26LiquidCrystal lcd(RS, E, DB4, DB5, DB6, DB7); 27int tempC; 28 29void setup() 30{ 31 pinMode(DC_MOTOR, OUTPUT); //motor 32 lcd.begin(16, 2); //lcd 33 pinMode(TEMP_SENSOR, INPUT); //temp sensor 34 for (int i = RED_LED; i <= GREEN_LED; i++) //LEDs 35 pinMode(i, OUTPUT); 36 37 //print never-changing text to LCD 38 lcd.print("TEMP: "); 39} 40 41void loop() 42{ 43 //read sensor value 20-358 44 int tempSensorValue = analogRead(TEMP_SENSOR); 45 // map sensor value 20-358 to -40 to 125 46 tempC = map(tempSensorValue, 20, 358, -40, 125); 47 48 49 //if-else chain to decide color, LCD screen, and fan speed 50 if (tempC <= 20) { 51 writeToLCD(tempC, "COLD! "); 52 analogWrite(DC_MOTOR, 0); 53 digitalWrite(RED_LED, LOW); 54 digitalWrite(BLUE_LED, HIGH); 55 digitalWrite(GREEN_LED, HIGH); 56 } else if (tempC <= 25) { 57 writeToLCD(tempC, "SEMI-WARM "); 58 analogWrite(DC_MOTOR, .25 * 255); 59 digitalWrite(RED_LED, LOW); 60 digitalWrite(BLUE_LED, HIGH); 61 digitalWrite(GREEN_LED, LOW); 62 } else if (tempC <= 32) { 63 writeToLCD(tempC, "WARM "); 64 analogWrite(DC_MOTOR, .50 * 255); 65 digitalWrite(RED_LED, LOW); 66 digitalWrite(BLUE_LED, LOW); 67 digitalWrite(GREEN_LED, HIGH); 68 } else if (tempC <= 38) { 69 writeToLCD(tempC, "HOT "); 70 analogWrite(DC_MOTOR, .75 * 255); 71 digitalWrite(RED_LED, HIGH); 72 digitalWrite(BLUE_LED, HIGH); 73 digitalWrite(GREEN_LED, LOW); 74 } else { 75 writeToLCD(tempC, "EXTREME "); 76 analogWrite(DC_MOTOR, 255); 77 digitalWrite(RED_LED, HIGH); 78 digitalWrite(BLUE_LED, LOW); 79 digitalWrite(GREEN_LED, LOW); 80 } 81 82} 83 84//function to write text to the LCD since the location never changes 85void writeToLCD(int temp, String tempDesc) { 86 lcd.setCursor(6, 0); 87 lcd.print(temp); 88 lcd.print(DEGREE); 89 lcd.print("C "); 90 lcd.setCursor(0, 1); 91 lcd.print(tempDesc); 92}
Documentation
Final Project Documentation
Guide on building and programming project
Documentation.pdf
Comments
Only logged in users can leave comments