Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
An Tran
Published © MIT

Particle Photon Controls Grove Relay & Electromagnetic Lock

Connect a Grove Relay to a Particle Photon to control an electromagnetic lock.

BeginnerShowcase (no instructions)2 hours1,682
Particle Photon Controls Grove Relay & Electromagnetic Lock

Things used in this project

Story

Read more

Code

PhotonGroveRelay

Arduino
#define BUTTONPIN D2
#define LEDPIN D7
#define RELAYPIN D4

void setup() {
    pinMode(LEDPIN, OUTPUT);
    pinMode(BUTTONPIN, INPUT);

    pinMode(RELAYPIN, OUTPUT);
    digitalWrite(RELAYPIN, LOW);
}

void loop() {
    if (digitalRead(BUTTONPIN) == 1) {
        digitalWrite(LEDPIN, HIGH);
        digitalWrite(RELAYPIN, HIGH);
    } else {
        digitalWrite(LEDPIN, LOW);
        digitalWrite(RELAYPIN, LOW);
    }
}

PhotonGroveRelay

Credits

An Tran

An Tran

5 projects • 12 followers
tech, startup, web, mobile, iot, dev

Comments