Will Blalockhunter carignan
Published

Smart Cooler

The Smart Cooler is your typical cooler, but it communicates with you and has automatic lights.

EasyFull instructions provided4 hours342
Smart Cooler

Things used in this project

Hardware components

Photon
Particle Photon
×2
Magnetic Reed Switch
×1
Waterproof LED Strip Lights
×1
Jumper wires (generic)
Jumper wires (generic)
×7
220 Ohm Resistor
×3
Breadboard (generic)
Breadboard (generic)
×2

Software apps and online services

build.particle
Maker service
IFTTT Maker service
ThingSpeak API
ThingSpeak API

Hand tools and fabrication machines

Heavy Duty Tape

Story

Read more

Schematics

Photon One: Magnetic Reed Switch

Reedswitch 9kj5isrwla

Photon 2: LED Strip Light

Screen shot 2018 04 17 at 11 35 55 am c6m8lbv8sv

Code

Photon 1: Magnetic Reed Switch

C/C++
int state; // For the loop portion of the code, state is used, which only allows a "publish" when the cooler state changes 

int lid=0; // Thinkspeak data, 0=closed lid, 1=opened lid

void setup() {
    
	pinMode(D7,OUTPUT);
	pinMode(D0,INPUT); // D0 is reading the input from the reed switch
    digitalWrite(D7,HIGH); // D7 is always outputting a high signal

}
void loop() {
	
   if (digitalRead(D0)==HIGH){//D0 will read HIGH when the reed switch is disconnected due to the cooler lid being opened
   
    	if(state != 0){
    	Particle.publish("cooler_status","Opened");// Publish "Opened" is sent to "cooler_status", which is the channel that the other photon is listening to initiating the lights to turn ON
    	state=0;
    	lid=1; //cooler lid defined as opened
    	Particle.publish("thingSpeakWrite_", "{ \"1\": \"" + String(lid) + "\", \"k\": \"URJNA1RRANEH72J7\" }", 60, PRIVATE); //value of "1" is sent to thinkspeak, idicating the lid is open
    	
    	}
	}
	else if (digitalRead(D0)==LOW){ //D0 will read LOW when the reed switch is connenected due to the cooler lid being closed
	
    	if (state !=1){
        Particle.publish("cooler_status","Closed");//Publish "Closed" is sent to "cooler_status", which is the channel that the other photon is listening to initiating the lights to turn OFF
    	state=1;
    	lid=0; //cooler lid defined as closed
    	//  delay(1000); was here but deleted for testing
    	Particle.publish("thingSpeakWrite_", "{ \"1\": \"" + String(lid) + "\", \"k\": \"URJNA1RRANEH72J7\" }", 60, PRIVATE);//value of "0" is sent to thinkspeak, idicating the lid is closed
    	
    	}
	}
}

Photon 2: LED Strip Light

C/C++
int state=0;

void setup() {
    
    pinMode(D0,OUTPUT); 
    digitalWrite(D0,LOW);
    Particle.subscribe("cooler_status", myHandler, "55004c000e51353532343635");
    
}

void loop() {
}
 
void myHandler(const char *event, const char *data) {

    if (strcmp(data,"Opened")) {//Code recieves message from photon one, indicating that the lid is OPENED, and to turn the lights ON
      digitalWrite(D0,HIGH);
      
}

    else if (strcmp(data,"Closed")) {//Code recieves message from photon one, indicating that the lid is CLOSED, and to turn the lights OFF
          digitalWrite(D0,LOW);
  }
}

Webhook

C/C++
{
    "event": "thingSpeakWrite_",
    "url": "https://api.thingspeak.com/update",
    "requestType": "POST",
    "form": {
        "api_key": "{{k}}",
        "field1": "{{1}}",
        "field2": "{{2}}",
        "field3": "{{3}}",
        "field4": "{{4}}",
        "field5": "{{5}}",
        "field6": "{{6}}",
        "field7": "{{7}}",
        "field8": "{{8}}",
        "lat": "{{a}}",
        "long": "{{o}}",
        "elevation": "{{e}}",
        "status": "{{s}}"
    },
    "mydevices": true,
    "noDefaults": true
}

Credits

Will Blalock

Will Blalock

1 project • 0 followers
Contact
hunter carignan

hunter carignan

1 project • 0 followers
Contact

Comments

Add projectSign up / Login