Things used in this project

Hardware components:
3 Pin Fan
×1
100k Thermistor
×1
09590 01
LED (generic)
Included with particle
×1
Adafruit industries ada161 image 75px
Photo resistor
Included with particle
×1
Relay (generic)
SPDT 1A, 5V Relay
×1
Mfr 25frf52 10k sml
Resistor 10k ohm
×1
Mfr 25fbf52 221r sml
Resistor 221 ohm
×1
Photon new
Particle Photon
×1
Software apps and online services:
Particle
Particle.io

Custom parts and enclosures

CREO Files for project
Here are the creo files for the hard components of the project.
DUq5jkRciArbjwUKZK92.zip

Schematics

Circuit Diagram
Wire the components accordingly
Mdjsfwvcgpge07aendbq

Code

FanC/C++
The fan code triggers fan on and records fan speed
int counter = D0; //yellow wire from 3 pin fan
int period;
int frequency;
int rpm;
int power = D1;
int power2 = D2;


void setup()
{
    
    pinMode(counter,INPUT_PULLDOWN); // counter needs 3.3v pulldown
    pinMode(power, OUTPUT); // 5v relay needs 2 sources to power it on. power and power2
    pinMode(power2, OUTPUT);
    Particle.subscribe("tjohn212LidStatus", myHandler); // using the unique name from lidsensor, subscribe to the event. Assign myHandler code below
    delay(2000);
    
}


void loop()
{
    
    period = (pulseIn(D0, HIGH))/3600; // the PWM provides a period, or duration between pulses
    frequency = (10 / period); // must take the inverse of period to get frequency
    rpm = (frequency*60); // and finally convert frequency to RPM
    Particle.publish("rpm", String(rpm)); // publish final value to console
    delay(1000);
}


void myHandler(const char *event, const char *data) // here is were you assign myHandler task
{
  
  if (strcmp(data,"ON")==0) // we have to convert the incoming data using strcmp() which compares two chars.
  {
    digitalWrite(power,HIGH); // if the lid is on from the other photon, turn fan on
    digitalWrite(power2,HIGH);
    delay(500);
  }
  else if (strcmp(data,"OFF")==0)
  {
    digitalWrite(power,LOW); // if the lid is off turn fan off
    digitalWrite(power2,LOW);
    delay(500);
  }
}
Lid SensorC/C++
The lid code turns on LED based on whether or not the lid is on or not
int lidon;
int lidoff;
int led = D0; // Where LED is plugged into. The other side goes to a resistor connected to GND.
int photoresistor = A0; // Where photoresistor is plugged into. The other side goes to the "power" pin (below).
int power = A5; // Other end of your photoresistor. The other side is plugged into the "photoresistor" pin (above).
int analogvalue; // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the photoresistor.
bool lid = false;


void setup()
{

    pinMode(led,OUTPUT); // LED pin is output
    pinMode(photoresistor,INPUT);  // input reading from photoresistor
    pinMode(power,OUTPUT); // pin powering photoresistor
    digitalWrite(power,HIGH); // write the photoresistor to max power
}


void loop()
{

    analogvalue = analogRead(photoresistor); // reads value from photoresistor 
    delay(10);
    if (analogvalue < 5) //if value above is less than, turn ON LED
    {    
        digitalWrite(led,HIGH);
        if (lid==true)
        {
            Particle.publish("tjohn212LidStatus","ON"); // using unique event name, publish to console so other photon can subscribe
            delay(1000);
            lid=false;
        }
    }
    else
    {
        digitalWrite(led,LOW); // any other value not less than, turn OFF LED
        if (lid==false)
        {
            Particle.publish("tjohn212LidStatus","OFF");
            delay(1000);
            lid=true;
        }
    }
}
ThermistorC/C++
Thermistor code publishes temperature readings to console
#include <math.h>
const int pullup_res = 10000; // ( 10kOm )
const double beta = 4390; // in K for Semitec 104 GTA-2
const double thermistor_res = 100000; // 100kOm thermistor
const double thermistor_nom_temp = 77; // Nominal Farenheit

void setup()
{
}


void loop()
{
 thermistor_temp(analogRead(4));
 delay(1000);
}


void thermistor_temp(int aval)
{
 double R, T;
R = (double) pullup_res / ( (4095 / (double) aval ) - 1 );
 
 T = 1 / ( ( 1 / (thermistor_nom_temp + 241.15 )) + ( ( 1 / beta) * log ( R / thermistor_res ) ) );
 
 T -= 241.15; // convert K to F
 
 // return degrees F
 Particle.publish("Temperature", String(T) + " °F"); // publishes temp to console every 2 seconds
 delay(2000);
}

Credits

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

Particle Photon Doorbell
Intermediate
  • 611
  • 9

Full instructions

Get notified when the doorbell is pressed for about 1/6 the price of the RING doorbell!

DIYSprinkler Controller
Intermediate
  • 420
  • 3

Full instructions

Make your own sprinkler controller and I have the software to control it. Must have an existing sprinkler system or you could make your own

DIYSprinkler Controller

Team dougefresh89

Magic Eyeball
Intermediate
  • 781
  • 7

Full instructions

It's like a magic eight ball. But with Alexa, and two eyeballs.

Spoil your Valentine with Particle + Spoil + AWS
Intermediate
  • 475
  • 3

Full instructions

Instead of giving a box of chocolates this Valentines Day, keep the chocolates. Lets give a smart self-gifting box instead!

Pebble + Photon = IoT Watch Switch
Intermediate
  • 47
  • 1

Full instructions

When I arrive in my house I switch on the light with my Pebble Watch! The procedure to make this is very simple.

Automated Cat Feeder with Particle Photon
Intermediate
  • 1,543
  • 19

Work in progress

The goal was to make it possible to feed my cats when I'm not at home.

Add projectSign up / Login
Respect project