// Final Project /// This IoT project is designed to monitor and control the environment of your home for the wellbeing of your dog. /// The project uses a DHT22 sensor to measure temperature and a water sensor to gauge the water level in the dog’s bowl. /// The data is displayed on the Blynk app, accessible via Wi-Fi, allowing remote monitoring. /// Additionally, the system features an LED strip that can be controlled remotely, and a servo motor to operate a food /// dispenser, both of which can be activated through the web interface. /// The web interface provides intuitive controls to turn the LED strip on or off and to dispense food for the dog, /// making it a comprehensive solution for ensuring your dog’s comfort and well-being. /// Components used: Air Temperature and Humidity Sensor, Water Sensor, Servo Motor, LED Strip /// Video link: https://youtu.be/pQtGN3XxCzE ///Created by: /// Student1_Ido_Shenbach 318653789 /// Student2_Tamar_Assabi 318604329 #define BLYNK_TEMPLATE_ID "[INSERT YOUR TEMPLATE_ID]" // TODO: Replace with your Template ID #define BLYNK_TEMPLATE_NAME "[INSERT YOUR TEMPLATE_NAME]" // TODO: Replace with your Template Name #define BLYNK_AUTH_TOKEN "[INSERT YOUR AUTH_TOKEN]" // TODO: Replace with your Auth Token #define BLYNK_PRINT Serial #include #include #include #include #include #include #include // Define pin connections and types #define DHTPIN 4 // Digital pin connected to the DHT sensor #define DHTTYPE DHT22 // DHT 22 (AM2302) #define LED_PIN 15 // Digital pin connected to the NeoPixels #define LED_COUNT 12 // Number of NeoPixels #define WATER_SENSOR_PIN 35 // Analog pin connected to the water sensor #define SERVO_PIN 22 // Digital pin connected to the servo // Variables to deal with temperature float temperature; // Variable to hold the temperature value char tempString[10]; // Buffer to hold the converted string // Variables to deal with water level int waterLevel; // Variable to hold the water level value String waterLevelStr = ""; // Variable to hold the water level string Servo myservo; // create servo object to control a servo Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); // Create a NeoPixel object // Initialize DHT sensor for normal 16mhz Arduino DHT dht(DHTPIN, DHTTYPE); char ssid[] = "[INSERT YOUR SSID]"; // TODO: Replace with your SSID char pass[] = "[INSERT YOUR PASSWORD]"; // TODO: Replace with your Password unsigned long lastUpdated = 0; // Variable to hold last updated time void setup() { Serial.begin(115200); // Start the Serial Monitor Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // Connect to Blynk dht.begin(); // Initialize DHT sensor myservo.setPeriodHertz(50); // standard 50 hz servo myservo.attach(SERVO_PIN, 500, 2500); // attaches the servo onto pin strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) strip.show(); // Initialize all pixels to 'off' strip.setBrightness(150); // Set brightness to about 150 (max = 255) } void loop() { Blynk.run(); if (millis() - lastUpdated > 3000) // Update every 3 seconds { temperature = dht.readTemperature(); // Read temperature as Celsius waterLevel = analogRead(WATER_SENSOR_PIN); // Read water level Serial.print("Water Level:"); Serial.println(waterLevel); if (waterLevel == 0) // Check if the water level is empty { waterLevelStr = "Empty"; report(0); } else if (waterLevel < 1200) // Check if the water level is low { waterLevelStr = "Low"; } else if (waterLevel < 1600) // Check if the water level is moderate { waterLevelStr = "Moderate"; } else // Check if the water level is full { waterLevelStr = "Full"; } Blynk.virtualWrite(V1, temperature); // Send temperature to Blynk app Blynk.virtualWrite(V4, waterLevelStr); // Send water level to Blynk app lastUpdated = millis(); // Update last updated time } } bool isOn = false; // Variable to hold the state of the LED bool isOpen = false; // Variable to hold the state of the servo BLYNK_WRITE(V2) // Button Widget is writing to pin V2 { long color = strip.Color(255, 0, 255); if (isOn) { for (int i = 0; i < LED_COUNT; i++) // Turn off all LEDs { strip.setPixelColor(i, 0); strip.show(); delay(100); } } else { for (int i = 0; i < LED_COUNT; i++) // Turn on all LEDs { strip.setPixelColor(i, color); strip.show(); delay(100); } } isOn = !isOn; // Toggle the state of the LED } BLYNK_WRITE(V0) // Button Widget is writing to pin V0 { int angle = 0; if (!isOpen) { angle = 180; // turn the motor, open food dispensor myservo.write(angle); delay(100); } else { angle = 0; // turn the motor, close food dispensor myservo.write(angle); delay(100); } isOpen = !isOpen; // Toggle the state of the servo } // Function to report the status of the water level void report(int reportKind) { WiFiClientSecure *client = new WiFiClientSecure; // Create a new client if (client) // Check if the client was created { client->setInsecure(); { HTTPClient https; // Create a new HTTPClient Serial.print("[HTTPS] begin...\n"); if (https.begin(*client, String("[ENTER YOUR WEBHOOK URL]"))) // TODO: Replace with your own URL { int httpCode = https.GET(); // Send the GET request if (httpCode > 0) // Check the returning code { if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) // Check if the response is OK { String payload = https.getString(); // Get the request response payload } } else { Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str()); } https.end(); // Close the connection } else { Serial.printf("[HTTPS] Unable to connect\n"); } } delete client; // Delete the client } else { Serial.println("Unable to create client"); } Serial.println(); }