Things used in this project

Hardware components:
Relay (generic)
Photon new
Particle Photon
Extension Cord
Mfr 25frf52 10k sml
Resistor 10k ohm
SparkFun Photocell
11026 02
Jumper wires (generic)
826 04
Male/Female Jumper Wires
Software apps and online services:
Blynk logo avatars
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)
Exacto Knife
Wire Cutter


Tinkercad's Relay
Screen shot 2018 02 28 at 12 13 05 pm du0jyrz4gk
This is the code to go with the Tinkercad Schematic
Screen shot 2018 02 27 at 12 14 54 pm v4s0t17uop


Project's codeJava
This code includes the relay as well as the photocell.
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
#define BLYNK_PRINT Serial
char auth[] = "YOUR_AUTH_CODE_HERE";

const float VCC = 4.98;
const float DARK_THRESHOLD = 1500; //If your photon reads less than this it should turn on.
const int LIGHT_PIN = A0;
float lightV;
int lightADC;
int pinValue;
 //NO -> LOW is on

void setup()
  Serial.begin(9600); //lets you check the voltage number
  pinMode(LIGHT_PIN, INPUT); //LIGHT_PIN is the photocell
  pinMode(D6, OUTPUT); //D6 is the relay
  digitalWrite(D6, HIGH); //D6 is automatically set to LOW, but this turns the relay on and we want the relay off at first.
  pinValue = 0; //Sets the VirtualPin to zero

BLYNK_WRITE(V0) // V0 is the number of Virtual Pin  
    pinValue = param.asInt(); //This grabs the value of the virtual pin

void loop()
    if(pinValue == 1 ) { //if the virtual pin is on
      lightADC = analogRead(LIGHT_PIN); //read the value the photocell is sending
      if (lightADC > 0)
        lightV = (lightADC * VCC / 1023.0)*100; //Calculates voltage, then multiples by 100 to make the # easier to read
        Serial.println("Voltage: " + String(lightV) + " V"); //Displays Voltage
            if ((lightV) <= DARK_THRESHOLD) //If its dark
                digitalWrite(D6, LOW); //turn the relay and therefore the extension cord on
            else //if its not dark
                digitalWrite(D6, HIGH); //turn the relay and extension cord off


Lilly Moore
1 project • 1 follower
Thanks to Ostin Jos.


Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback


Add projectSign up / Login