meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
ixc2025:team_1:start [2025/05/15 16:23] ilmariixc2025:team_1:start [2025/05/15 16:29] (current) karppi
Line 43: Line 43:
  
  
 +=== 6. Future Improvements ===
    
  
-=== 5Power meter measurements ===+Ad-Hoc Sensor Networks for Neighborhood Safety:​ 
 +Emergency Alerts: Nearby homes can communicate to share data about fire, smoke, gas leaks, or intrusions.​ 
 +Collective Security: Use mesh networks to create a neighborhood-wide alarm system for better safety.​ 
 +Predictive Maintenance and Analytics:​ 
 +AI-Based Predictions: Use machine learning to predict appliance failures and optimize maintenance schedules.​ 
 +Usage Analytics: Provide insights on energy usage to promote more sustainable habits.​ 
 +​ 
 +​ 
 +Renewable Energy Integration:​ 
 +Solar and Battery Integration: Smart control for charging and discharging based on real-time energy prices.​ 
 +Electric Vehicle (EV) Charging Management: Coordinate EV charging when electricity is cheapest.​ 
 +Waste and Water Management:​ 
 +Smart Water Meters: Detect leaks and optimize water usage.​ 
 +Compost and Recycling Guidance: Use sensors to assist in proper waste segregation.
  
-=== 6. Future Improvements === 
- 
- 
- 
-=== 8. Final Code === 
  
  
Line 59: Line 67:
  
  
 +===notes===
 Day 1: We gathered our team members according to our interests and built our smart home. Then we tested a few existing codes. Day 1: We gathered our team members according to our interests and built our smart home. Then we tested a few existing codes.
 We brainstormed with each other and finally agreed about the main points that we are all going to build for our sustainable home. We brainstormed with each other and finally agreed about the main points that we are all going to build for our sustainable home.
Line 96: Line 105:
  
 {{:ixc2025:team_1:screenshot_from_2025-05-15_15-06-43.png?600|}} {{:ixc2025:team_1:screenshot_from_2025-05-15_15-06-43.png?600|}}
 +{{:ixc2025:team_1:result_data.png?400|}}
  
  
Line 102: Line 112:
 final ppt final ppt
 {{ :ixc2025:team_1:greenguard_smart_home_presentation_final_day.pptx |}} {{ :ixc2025:team_1:greenguard_smart_home_presentation_final_day.pptx |}}
 +
 +
 +=== 8. Final Code ===
 +
 +
 +#include <WiFi.h> 
 +#include <HTTPClient.h> 
 +#include <Wire.h> 
 +#include <LiquidCrystal_I2C.h> 
 +#include <DHT.h> 
 +#include <DHT_U.h> 
 +#include <FastLED.h> 
 + 
 + 
 +// WiFi 
 +const char* ssid = "Phone"; 
 +const char* password = "12345678"; 
 + 
 + 
 +// Tilamuuttujat 
 +int screenstate = 0; 
 +float price = 0; 
 +float temperature; 
 +float last_temperature; 
 +float humidity; 
 +float last_humidity; 
 +bool alertcheck = true; 
 + 
 + 
 +// Rajat 
 +#define PRICE_ALERT_THRESHOLD 20.0 // c/kWh 
 + 
 + 
 +// Pinimääritykset 
 +#define LED_PIN 26 
 +#define BUTTON_LEFT_PIN 16 
 +#define BUTTON_RIGHT_PIN 27 
 +#define BUZZER_PIN 25 
 +#define NUM_LEDS 4 
 +#define DHT_PIN 17 
 +#define DHT_TYPE DHT11 
 + 
 + 
 +// Näyttötilat 
 +#define price_display 0 
 +#define temperature_display 1 
 + 
 + 
 +// Muut globaalit 
 +CRGB leds[NUM_LEDS]; 
 +boolean alertStatus = false; 
 +int display_state = 0; 
 +LiquidCrystal_I2C lcd(0x27, 16, 2); 
 +DHT dht(DHT_PIN, DHT_TYPE); 
 + 
 + 
 +// Ajastin hintapäivitykselle 
 +unsigned long lastPriceUpdate = 0; 
 +const unsigned long priceInterval = 0.5 * 60 * 1000; // 30 sec 
 + 
 + 
 +// WiFi-yhteys 
 +void connectwifi() { 
 +WiFi.begin(ssid, password); 
 +Serial.println("Yhdistetään WiFi-verkkoon..."); 
 + 
 + 
 +while (WiFi.status() != WL_CONNECTED) { 
 +delay(500); 
 +Serial.print("."); 
 +
 + 
 + 
 +Serial.println("\nWiFi-yhteys muodostettu!"); 
 +
 + 
 + 
 +// Piippaus 
 +void beepBuzzer() { 
 +tone(BUZZER_PIN, 440, 250); 
 +noTone(BUZZER_PIN); 
 +
 + 
 + 
 +// Hälytys 
 +void alert(String warningMessage, int freq) { 
 +lcd.clear(); 
 +lcd.setCursor(0, 0); 
 +lcd.print(warningMessage); 
 + 
 + 
 +while (alertStatus) { 
 +beepBuzzer(); 
 +for (int i = 0; i < NUM_LEDS; i++) { 
 +leds[i] = CRGB::Red; 
 +
 +FastLED.show(); 
 +delay(1000 / freq); 
 + 
 + 
 +if (digitalRead(BUTTON_LEFT_PIN) == LOW) { 
 +delay(50); // debounce 
 +alertStatus = false; 
 +clearAlert(); 
 +
 + 
 + 
 +for (int i = 0; i < NUM_LEDS; i++) { 
 +leds[i] = CRGB::Black; 
 +
 +FastLED.show(); 
 +delay(1000 / freq); 
 +
 +
 + 
 + 
 +// Hälytyksen poisto 
 +void clearAlert() { 
 +alertStatus = false; 
 +lcd.clear(); 
 +for (int i = 0; i < NUM_LEDS; i++) { 
 +leds[i] = CRGB::Black; 
 +
 +FastLED.show(); 
 +alertcheck = false; 
 +
 + 
 + 
 +// Oikean napin painallus 
 +int r_buttonPress() { 
 +if (digitalRead(BUTTON_RIGHT_PIN) == LOW) { 
 +delay(100); // debounce 
 +return 1; 
 +
 +return 0; 
 +
 + 
 + 
 +// Näytön päivitys 
 +void screen(int state) { 
 +lcd.clear(); 
 +if (state == temperature_display) { 
 +lcd.setCursor(0, 0); 
 +lcd.print("Temp: "); 
 +lcd.print(temperature); 
 +lcd.print(" C"); 
 +lcd.setCursor(0, 1); 
 +lcd.print("Hum: "); 
 +lcd.print(humidity); 
 +lcd.print(" %"); 
 +} else if (state == price_display) { 
 +lcd.setCursor(0, 0); 
 +lcd.print("Price: "); 
 +lcd.print(price); 
 +lcd.print("c/kWh"); 
 +
 +
 +//randomhinta 
 +float changePrice() {  
 + 
 + 
 +float newPrice = random(18, 30); // Generoi uusi hinta  
 + 
 + 
 +if (newPrice > 0.5 || newPrice < -0.05) {  
 + 
 + 
 +//newPrice = 0.05; // Palauta hinta, jos se karkaa käsistä  
 + 
 + 
 +}  
 + 
 + 
 +return newPrice; // Palauta uusi hinta  
 + 
 + 
 +}  
 +// Hintahaku 
 +float curPrice() { 
 +String priceStr = "0"; 
 +if (WiFi.status() == WL_CONNECTED) { 
 +HTTPClient http; 
 + 
 + 
 +String date = "2024-05-14"; 
 +int hour = 14; 
 + 
 + 
 +String url = "https://api.porssisahko.net/v1/price.json?date=" + date + "&hour=" + String(hour); 
 +http.begin(url); 
 +int httpResponseCode = http.GET(); 
 + 
 + 
 +if (httpResponseCode > 0) { 
 +String payload = http.getString(); 
 +int priceIndex = payload.indexOf("\"price\":"); 
 +if (priceIndex != -1) { 
 +int start = payload.indexOf(":", priceIndex) + 1; 
 +int end = payload.indexOf("}", start); 
 +priceStr = payload.substring(start, end); 
 +priceStr.trim(); 
 +
 +} else { 
 +Serial.print("HTTP-virhe: "); 
 +Serial.println(httpResponseCode); 
 +
 + 
 + 
 +http.end(); 
 +
 +return priceStr.toFloat(); 
 +
 + 
 + 
 +// Alustus 
 +void setup() { 
 +randomSeed(71137); 
 +Serial.begin(115200); 
 +//connectwifi(); 
 + 
 + 
 +lcd.init(); 
 +lcd.backlight(); 
 +dht.begin(); 
 + 
 + 
 +pinMode(BUZZER_PIN, OUTPUT); 
 +digitalWrite(BUZZER_PIN, LOW); 
 + 
 + 
 +FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS); 
 +FastLED.setBrightness(50); 
 + 
 + 
 +pinMode(BUTTON_LEFT_PIN, INPUT_PULLUP); 
 +pinMode(BUTTON_RIGHT_PIN, INPUT_PULLUP); 
 + 
 + 
 +screen(display_state); 
 +
 + 
 + 
 +// Pääsilmukka 
 +void loop() { 
 +if (millis() - lastPriceUpdate > priceInterval || price == 0) { 
 +price = changePrice(); 
 +lastPriceUpdate = millis(); 
 +alertcheck = true; 
 +
 + 
 + 
 +temperature = dht.readTemperature(); 
 +humidity = dht.readHumidity(); 
 + 
 + 
 +if (r_buttonPress() == 1) { 
 +delay(50); 
 +display_state = !display_state; 
 +screen(display_state); 
 +
 + 
 + 
 +if (alertcheck && price > PRICE_ALERT_THRESHOLD) { 
 +alertStatus = true; 
 +alert("Price is high", 5); 
 + 
 + 
 +screen(display_state); 
 +
 + 
 + 
 +if ((last_humidity != humidity || last_temperature != temperature)/* && display_state == temperature_display*/) { 
 +if (humidity <= 100) { 
 +screen(display_state); 
 +
 +
 + 
 + 
 +last_temperature = temperature; 
 +last_humidity = humidity; 
 +
 +