Quail Monitor
A real-time embedded monitoring system for small-bird habitats. Tracks temperature and water levels, drives an automatic cooling fan, and delivers visual alerts through a 16×2 LCD and a 32-pixel NeoPixel array - all on a single Arduino UNO.
Devices & Components
1
Arduino Uno Rev3
1
PART 16X2 LCD
1
Moisture Sensor
1
Potentiometer with Built In Knob
1
NPN Transistor (BJT)
1
TMP36 ANALOG TEMPERATURE SENSOR
4
NeoPixel Strip
1
Breadboard & Jumper Wires
1
DC Fan Motor
2
Resistor 1K OHM
Software & Tools
Arduino IDE
Project description
Code
C++ code
cpp
Quail Monitor C++ Code
1#include <LiquidCrystal.h> 2#include <Adafruit_NeoPixel.h> 3// C++ code 4// 5 6// LCD Constants 7const int RS = 2; 8const int E = 3; 9const int DB4 = 4; 10const int DB5 = 5; 11const int DB6 = 6; 12const int DB7 = 7; 13const int DC_MOTOR = 9; 14 15// DC MOTOR Constants 16const int OFF_SPEED = 0; 17const int LOW_SPEED = 64; 18const int MED_SPEED = 128; 19const int HIGH_SPEED = 255; 20 21// Thresholds 22const int TEMP_LOW_THRESHOLD = 65; 23const int TEMP_HIGH_THRESHOLD = 80; 24const int FAN_LOW_THRESHOLD = 80; 25const int FAN_MED_THRESHOLD = 90; 26const int FAN_HIGH_THRESHOLD = 100; 27const int WATER_LOW_THRESHOLD = 300; 28 29// Create LCD object 30LiquidCrystal lcd(RS, E, DB4, DB5, DB6, DB7); 31 32// Soil moisture sensor 33const int MOISTURE_SENSOR = A0; 34 35// TMP36 temperature sensor 36const int TEMP_SENSOR = A1; 37 38// NeoPixel PIN 39const int PIXEL_PIN = 8; 40 41// Pixel Count 42const int PIXEL_COUNT = 32; 43 44 45// Create NeoPixel strip object 46Adafruit_NeoPixel strip( 47 PIXEL_COUNT, 48 PIXEL_PIN, 49 NEO_GRB + NEO_KHZ800 50); 51 52// Colors 53const uint32_t RED = strip.Color(255, 0, 0); 54const uint32_t GREEN = strip.Color(0, 255, 0); 55const uint32_t OFF = strip.Color(0, 0, 0); 56 57// Variables 58int moistureValue = 0; 59int tempSensorValue = 0; 60int tempC = 0; 61int tempF = 0; 62 63 64void setup() 65{ 66 // Temp Sensor 67 pinMode(TEMP_SENSOR, INPUT); 68 Serial.begin(9600); 69 70 // Initialize LCD 71 lcd.begin(16, 2); 72 73 // Initialize NeoPixels 74 strip.begin(); 75 strip.show(); 76 77 // DC_MOTOR 78 pinMode(DC_MOTOR, OUTPUT); 79 80 // Startup message 81 lcd.setCursor(0, 0); 82 lcd.print("Quail Monitor"); 83 delay(1500); 84} 85 86void loop() 87{ 88 // Read the sensor value (analog) 89 tempSensorValue = analogRead(TEMP_SENSOR); 90 91 // Map sensor value (20 to 358) to celsius temp (-40 to 125) 92 tempC = map(tempSensorValue, 20, 358, -40, 125); 93 94 // Calculate the temp in Fahrenheit 95 tempF = 9 * tempC / 5 + 32; 96 Serial.print("Temp Value: "); 97 Serial.println(tempF); 98 99 // Read moisture sensor 100 moistureValue = analogRead(MOISTURE_SENSOR); 101 Serial.print("Moisture Value: "); 102 Serial.println(moistureValue); 103 104 // Determine warning states 105 bool tempLow = tempF < TEMP_LOW_THRESHOLD; 106 bool tempHigh = tempF >= TEMP_HIGH_THRESHOLD; 107 bool waterLow = moistureValue < WATER_LOW_THRESHOLD; 108 109 // Determine overall system status 110 bool systemSafe = !tempLow && !tempHigh && !waterLow; 111 112 // Updating NeoPixel to reflect status 113 if (systemSafe) { 114 setNeoColor(GREEN); 115 } 116 else { 117 setNeoColor(RED); 118 } 119 120 // Update fan speed 121 updateFanSpeed(); 122 123 // Always show temperature first 124 showTemperature(); 125 delay(2000); 126 127 // Rotate warning messages 128 if (tempLow) { 129 showWarning("TEMP LOW"); 130 delay(2000); 131 } 132 133 if (tempHigh) { 134 showWarning("TEMP HIGH"); 135 delay(2000); 136 } 137 138 if (waterLow) { 139 showWarning("WATER LOW"); 140 delay(2000); 141 } 142 143 // If safe, show SAFE message 144 if (systemSafe) { 145 showSafe(); 146 delay(2000); 147 } 148 149} 150 151// Helper functions 152void setNeoColor(uint32_t color){ 153 for (int i = 0; i < PIXEL_COUNT; i++) { 154 strip.setPixelColor(i, color); 155 } 156 strip.show(); 157} 158 159void showTemperature() { 160 clearLCDRows(); 161 lcd.setCursor(0, 0); 162 lcd.print("Temperature:"); 163 lcd.setCursor(0, 1); 164 lcd.print(tempF); 165 lcd.print(" F"); 166} 167 168void showWarning(String message) { 169 clearLCDRows(); 170 lcd.setCursor(0, 0); 171 lcd.print("WARNING:"); 172 lcd.setCursor(0, 1); 173 lcd.print(message); 174} 175 176void showSafe() { 177 clearLCDRows(); 178 lcd.setCursor(0, 0); 179 lcd.print("System Status"); 180 lcd.setCursor(0, 1); 181 lcd.print("ALL GOOD"); 182} 183 184void clearLCDRows() { 185 lcd.setCursor(0, 0); 186 lcd.print(" "); 187 lcd.setCursor(0, 1); 188 lcd.print(" "); 189} 190 191void updateFanSpeed() { 192 if (tempF >= FAN_HIGH_THRESHOLD) { 193 // Very hot 194 analogWrite(DC_MOTOR, HIGH_SPEED); 195 } 196 else if (tempF >= FAN_MED_THRESHOLD) { 197 // Hot 198 analogWrite(DC_MOTOR, MED_SPEED); 199 } 200 else if (tempF >= FAN_LOW_THRESHOLD) { 201 // Warm 202 analogWrite(DC_MOTOR, LOW_SPEED); 203 } 204 else { 205 // Safe 206 analogWrite(DC_MOTOR, OFF_SPEED); 207 } 208}
Comments
Only logged in users can leave comments