Skip to content

Instantly share code, notes, and snippets.

@kretes
Last active December 6, 2016 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kretes/59957c4d9d7f7650792890b5b0a77800 to your computer and use it in GitHub Desktop.
Save kretes/59957c4d9d7f7650792890b5b0a77800 to your computer and use it in GitHub Desktop.
christmas lights scheduler on particle

I used particle core http://particle.io and a relay module http://allegro.pl/show_item.php?item=6573707747 to turn the lights on/off. Relay is needed because you cannot get more than 3,3V from particle core pin and you shouldn't puch much current through it anyway.

The module has a bit surprising API, but thanks to https://community.particle.io/t/switch-relay-by-connecting-pin-to-ground/9077/27 I could use it succesfully.

Christmas lights (in my case 4,5V) are wired to the relay, relay IN is connected to pin D6 on particle and that's it.

void relayOn() {
pinMode(D6, OUTPUT);
digitalWrite(D6, LOW);
Particle.publish("on");
}
void relayOff() {
pinMode(D6, INPUT);
Particle.publish("off");
}
void setup() {
relayOn();
Time.zone(1);
Particle.publish("time", Time.timeStr());
Particle.publish("hour", String(Time.hour()));
}
int hourOn_1 = 5;
int hourOff_1 = 8;
int hourOn_2 = 15;
int hourOff_2 = 22;
int previous_hour=0;
void loop() {
int current_hour = Time.hour();
if (current_hour != previous_hour) {
Particle.publish("hour", current_hour);
previous_hour = current_hour;
if (current_hour == hourOn_1 || current_hour == hourOn_2) {
relayOn();
}
if (current_hour == hourOff_1 || current_hour == hourOff_2) {
relayOff();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment