Addison GallowayMitchell Meisenholder
Created April 22, 2022 © GPL3+

MEGR 3171- Straightener left on?

"Ever leave the house with your straightener accidentally left on?"

IntermediateFull instructions provided20 hours3
MEGR 3171- Straightener left on?

Things used in this project

Hardware components

Argon
Particle Argon
×2
current sensing switch
×1
Elegoo Digital Temperature
×1
6 foot extension cord
×1
Breadboard (generic)
Breadboard (generic)
The breadboard came inside the argon case.
×2
electrical tape
×1

Software apps and online services

ThingSpeak API
ThingSpeak API
Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

DIAGRAM SCHEMATICS

Code

Straightener Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include "Thingspeakappcode.h"

#include <math.h>

int Temp = A2;//TEMP PIN
float tempval = 0;//TEMP VALUE
int Current = D2;// CURRENT PIN
//int Power = A5;
int currentstate = 0;
int lastcurrentstate = 0;
int ledpin = D7 ;// LED PIN
int groundpin = D0 ;// GROUND
//int led =D4;

void setup() {

    Particle.variable("Temperature", Temp);
    Particle.variable("Current",  currentstate);
    pinMode(D5, INPUT_PULLUP);  //connects this pin with a real resistor to 3.3V by software *configurable hardware*  Switch inputs will be detected by sensing a low here.
    digitalWrite (ledpin, LOW);
    //Particle.subscribe("straightener-on", SUB_TEMP, "MY_DEVICES"); //when useless-on occurs in the cloud (viewable by console.particle.io) run the uselessfunc
    //MY_DEVICES limits the subscription such that only devices on your particle account will be listened to.

     Particle.subscribe("hook-response/thingSpeakWrite_", myHandler, MY_DEVICES);
}

void myHandler(const char *event, const char *data) {
  // Handle the integration response
//}
//void SUB_TEMP(const char *event, const char *data)
//{
    digitalWrite(ledpin,HIGH);
}


void loop() {
    lastcurrentstate = currentstate;  //copy the previous switch state to the last switch state
    currentstate = digitalRead(D1);  //read a new switch state.
    //begin switch input edge detection.  We want to trigger when the input goes from high to lo
    
    lastcurrentstate = currentstate;
    currentstate = digitalRead(D1);

    if ((currentstate == 1) && (lastcurrentstate ==1)){
    Particle.publish("straigtener-on1", PRIVATE);
    delay(10000);
    }
    
    tempval = analogRead(Temp);
    
    double tempK = log (10000.0 * ((1024.0 / tempval - 1)));
    tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK ); //Temp Kelvin
    float tempC = tempK - 273.15; // Convert Kelvin to Celcius
    float tempF = (tempC * 9.0)/ 5.0 + 32.0;
  
    

  
    if(tempval >=80.0)
    {
        // Get some data
        String data = String(tempF);
        // Trigger the integration
        Particle.publish("temperature_test", data, PRIVATE);
        // Wait 60 seconds
        delay(10000);
        //String Temperature = String(Temp);
    
        //Particle.publish("temp",Temperature, PRIVATE);
        //delay(50000);
    }    
    
    else
    {
        // DO NOTHING
    };
    
 
    
    
    

pinMode(ledpin, OUTPUT);
pinMode(groundpin, OUTPUT);
digitalWrite(groundpin,LOW); //blink the led for visual feedback 


}

//function that runs when you subscribe

Cloud Code

C/C++
int led = D7 ;

void setup() {
    pinMode(led, OUTPUT);  
    Particle.subscribe("searching", SUB_TEMP, "MY_DEVICES"); //when useless-on occurs in the cloud (viewable by console.particle.io) run the uselessfunc
//MY_DEVICES limits the subscription such that only devices on your particle account will be listened to.
}
void SUB_TEMP(const char *event, const char *data)
{
    digitalWrite(led,HIGH);
}

void loop() {

    digitalWrite(led,HIGH);
    
    Particle.publish("straigtener-on2", PRIVATE);
    delay(10000);
}

Credits

Addison Galloway

Addison Galloway

0 projects • 1 follower
Mitchell Meisenholder

Mitchell Meisenholder

0 projects • 1 follower

Comments

Add projectSign up / Login