Introduction
Human usually go to work on weekday, and stay at home or go to other places on weekend. Therefore, smart devices should be able to switch their task basing on this human behavior. For examples, traffic light system should act differently between weekday and weekend. RFID-based door in workplace may need to be activated only on weekday.
In this article, I am going to show you how to switch Arduino Uno-based IoT device’s tasks basing on day of week.
Things Used In This Project
- Arduino Uno
- USB cable for Arduino
- PHPoC Shield for Arduino or PHPoC Wi-Fi Shield for Arduino
PHPoC Shield not only provide the internet connection for IoT devices but also provide the real-time clock (RTC) which is useful for scheduling.
Steps
- Stack PHPoC Shield on Arduino
- Install Arduino library and examples for PHPoC Shield:
- On Arduino IDE, Goto Sketch -> Include Library -> Manage Libraries.
- Type “PHPoC” on search box.
- Click on PHPoC row and click “Install” button.
- Or you can get .zip file here: https://github.com/phpoc/arduino
- Run the following code
Code:
#include <SPI.h> #include <Phpoc.h> enum day { FAILURE, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }; enum day today; void weekdayTask() { Serial.println("This is weekday task"); //TODO } void weekendTask() { Serial.println("This is weekend task"); //TODO: } PhpocDateTime datetime; void setup() { Serial.begin(9600); while (!Serial) ; Phpoc.begin(); Serial.println("Weekly Scheduling"); datetime.date("Y-m-d D H:i:s"); Serial.println(datetime.date()); } void loop() { today = datetime.dayofWeek(); if (today == FAILURE) Serial.println("System Error!"); else if ( today >= MONDAY && today <= FRIDAY) weekdayTask(); //Program for weekday else weekendTask(); //Program for weekkend }
- Modify two functions: weekdayTask() and weekendTask() according to your need.
Note that you can do much with Arduino when combining with PHPoC shield because this shield has many powerful features such as IPv4/IPv6, TCP/UDP, SSL, ESMTP…
For more information, visit http://www.phpoc.com/phpoc_shield_for_arduino.php and https://www.phpoc.com/support/manual...8_user_manual/
If you have any questions or something to discuss, don’t hesitate to leave a comment!