Pametna budilica
Osnovna škola ZametVideo snimka
Izrada projekta
Laserska dioda i foto otpornik. U trenutku prekida laserske zrake dolazi do promjene izlazne vrijednosti na foto otporniku. Posljedično, gasi se svjetlo pametne budilice.
Mobilna aplikacija
Shema projekta
Shema grafički prikazuje projekt pametne budilice.
Shemu ovoga projekta možete preuzeti ovdje.
Arduino program
#define BLYNK_PRINT SerialUSB #include #include #include #include #include // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = "b6866a82e925480db0520a53b9a5c3cb"; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "P2 Lite"; char pass[] = "12345678ab"; int fo = A0; int r = 3, b = 5, g = 4; int laser = 7; int alarm = 0; int hours, minutes, seconds, currTime; int diff; int brightness = 0; int last = 0; int cnt = 0; int changed = 0; bool radi = true; WidgetTerminal terminal(V1); WidgetRTC rtc; BLYNK_WRITE(V1) { String curr = param.asStr(); if (String("on") == param.asStr()) { //upali ledicu terminal.println("Palim svjetlo"); radi = true; } else if (String("off") == param.asStr()) { //ugasi ledicu terminal.println("Gasim svjetlo"); analogWrite(r, 0); analogWrite(g, 0); analogWrite(b, 0); radi = false; } else if (curr.length() > 12){ //postavi alarm za pametnu budilicu radi = true; String alarmStr = ""; for (int i = 13; i < curr.length(); ++i){ alarmStr += curr[i]; } int h = ((alarmStr[0] - '0') * 10) + (alarmStr[1] - '0'); int m = ((alarmStr[3] - '0') * 10) + (alarmStr[4] - '0'); alarm = h * 3600 + m*60; terminal.println("Your alarm is set to :" + alarmStr); last = 130; } terminal.flush(); } void changeBrightness(){ //ovo sluzi za mijenjanje boja dok pametna budilica radi hours = hour(); minutes = minute(); currTime = hours * 3600 + minutes * 60 + second(); diff = alarm - currTime; if (diff > 120 || diff < 0){ return; } if (diff < 120 && last != 120){ analogWrite(r, 150); analogWrite(g, 150); analogWrite(b, 0); } if (diff < 110 && last != 110){ analogWrite(r, 100); analogWrite(g, 100); analogWrite(b, 0); } if (diff < 100){ analogWrite(r, 150); analogWrite(g, 150); analogWrite(b, 0); } if (diff < 90 && last != 90){ analogWrite(r, 150); analogWrite(g, 100); analogWrite(b, 0); } if (diff < 80){ analogWrite(r, 100); analogWrite(g, 100); analogWrite(b, 0); } if (diff < 70){ analogWrite(r, 150); analogWrite(g, 100); analogWrite(b, 0); } if (diff < 60){ analogWrite(r, 200); analogWrite(g, 150); analogWrite(b, 0); } if (diff < 50){ analogWrite(r, 150); analogWrite(g, 150); analogWrite(b, 0); } if (diff < 40){ analogWrite(r, 200); analogWrite(g, 200); analogWrite(b, 0); } if (diff < 30){ analogWrite(r, 250); analogWrite(g, 200); analogWrite(b, 0); } if (diff < 20){ analogWrite(r, 200); analogWrite(g, 200); analogWrite(b, 0); } if (diff < 10){ analogWrite(r, 250); analogWrite(g, 200); analogWrite(b, 0); } } void saveEnergy(){ //ugasi svijetlo ako izadem iz sobe int val = analogRead(fo); if (val < 200 && changed == 0){ analogWrite(r, 0); analogWrite(b, 0); analogWrite(g, 0); changed = 1; } else if (val > 200){ changed = 0; r = 3; g = 4; b = 5; } } void cs(){ for (int i = 0; i <= 24; i++) { terminal.println(""); } terminal.flush(); } BLYNK_CONNECTED() { rtc.begin(); } void setup() { changed = 0; SerialUSB.begin(9600); Blynk.begin(auth, ssid, pass); cs(); pinMode(r, OUTPUT); pinMode(g, OUTPUT); pinMode(b, OUTPUT); pinMode(laser, OUTPUT); } void loop() { Serial.println(radi); Blynk.run(); if (radi){ //provjera dal radi digitalWrite(laser, HIGH); changeBrightness(); saveEnergy(); } else { analogWrite(r, 0); analogWrite(g, 0); analogWrite(b, 0); } }
Arduino program ovoga projekta možete preuzeti ovdje.
Autori
Projekt su izradili Filip Višnić i Boris Španić uz mentorstvo Dine Abrule iz OŠ Zamet.
Projekt je prijavljen na temu: Internet of Things: Pametna rasvjeta.