Things used in this project

Hardware components:
Photon new
Particle Photon
×1
Mfr 25fbf52 221r sml
Resistor 221 ohm
While I used a 220 Ohms resistor, you can use any resistor for this; a larger resistor (like 10K Ohms) will give you a wider range of values whereas a smaller resistor (like 220 Ohms) will give you a lower range of values.
×1
Adafruit industries ada161 image 75px
Photo resistor
×1

Schematics

The Circuit Diagram
Build the circuit like the one given in the scheme diagram.
Photon photores only fritzing k5kwlnscu9

Code

Untitled fileArduino
This is the code for the photon you have to flash through build.particle.io to your device. Tweak around with delays for leds and intervals between each mails. You can even use an external LED instead of the inbuilt LED at D7. Also play around with the if condition for analog-value according to the safe limit you want to set.
int led = D7; // This is where your can use can plug in a different LED. The other side should go to a resistor connected to GND.

int photoresistor = A0; // This is where your photoresistor is plugged in. The other side goes to the "power" pin (refer to diagram).

int power = A5; // This is the other end of your photoresistor. The other side is plugged into the "photoresistor" pin (above).
// The reason we have plugged one side into an analog pin instead of to "power" is because we want a very steady voltage to be sent to the photoresistor.
// That way, when we read the value from the other side of the photoresistor, we can accurately calculate a voltage drop.

int analogvalue; // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the photoresistor.

void setup() {

    // First, declare all of our pins. This lets our device know which ones will be used for outputting voltage, and which ones will read incoming voltage.
    pinMode(led,OUTPUT); // Our LED pin is output (lighting up the LED)
    pinMode(photoresistor,INPUT);  // Our photoresistor pin is input (reading the photoresistor)
    pinMode(power,OUTPUT); // The pin powering the photoresistor is output (sending out consistent power)

    // Next, write one pin of the photoresistor to be the maximum possible, so that we can use this for power.
    digitalWrite(power,HIGH);

    // We are going to declare a Particle.variable() here so that we can access the value of the photoresistor from the cloud.
    Particle.variable("analogvalue", &analogvalue, INT);
    // This is saying that when we ask the cloud for "analogvalue", this will reference the variable analogvalue in this app, which is an integer variable.

}

void loop() {

    // check to see what the value of the photoresistor is and store it in the int variable analogvalue
    analogvalue = analogRead(photoresistor);
    delay(100);
    
    if(analogvalue>=250){
        digitalWrite(led, HIGH);
        Spark.publish("Light_limit","Exceeded",60,PRIVATE);
        delay(5000); //delay for LED
        digitalWrite(led, LOW);
        delay(10000); //10 second gap for each observation
        // Add a delay to prevent getting tons of emails from IFTTT
    }
}

Credits

Img 20170408 074825 veqr15pqtp
Yatin Agarwal

Founder at selfcure.co and cofounder at drair.in. A coding, chess, math, physics, animation, music, cooking, and graphic design enthusiast.

Contact

Replications

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

Comments

Similar projects you might like

WiFi Strength Meter
Easy
  • 561
  • 9

A meter that indicates the Wi-Fi signal strength in an intuitive way, using the parts I had on hand.

E-Paper Weather Display with Photon and IFTTT
Easy
  • 4,338
  • 21

Full instructions

Create a beautiful medium for weather information using Particle's cloud services and IFTTT.

2-Way Particle Photon Communication
Easy
  • 199
  • 4

Make two Particle Photons "talk" via the usage of webhooks!

IFTTT - Enabled Sensors with Particle Photon
Easy
  • 734
  • 11

Full instructions

Connect any sensor to Particle Photon and use it to trigger an IFTTT action with just a few lines of code.

Internet-Connected Popcorn Popper
Easy
  • 169
  • 1

Full instructions

A hot air popcorn popper triggered via the Internet! (Built for the Bellingham Codes May event.)

MyReed-Switch Controlled by Particle Electron
Easy
  • 51
  • 0

Full instructions

Magnetism in a simple door monitoring.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog