Garrett LoweEthan BuchananRiddick White
Published

MEGR 3171 Laundry Sensing

A new way to control your laundry cycles!

IntermediateFull instructions provided5 hours136
MEGR 3171 Laundry Sensing

Things used in this project

Hardware components

Argon
Particle Argon
×3
Rotary Encoder with Push-Button
Rotary Encoder with Push-Button
×1
SparkFun Triple Axis Accelerometer Breakout - ADXL335
SparkFun Triple Axis Accelerometer Breakout - ADXL335
×1
Photo resistor
Photo resistor
×1
Breadboard (generic)
Breadboard (generic)
×3
Jumper wires (generic)
Jumper wires (generic)
×3
Slide Switch
Slide Switch
×1
Buzzer
Buzzer
×1

Software apps and online services

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

Story

Read more

Schematics

Accelerometer

Accelerometer

Buzzer

Buzzer

Timer

Timer

Code

Accelerometer

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

int switchInput = D2;
int ymotion = A2;
int led = D7;
int IntData = 0;

TCPClient client;

unsigned long myChannelNumber = 1932107;	
const char * myWriteAPIKey = "19BLLFDNPCEXMWU7"; 

void setup() {
    pinMode(switchInput,INPUT);
    pinMode(ymotion,INPUT);
    pinMode(led,OUTPUT);
    ThingSpeak.begin(client);
    Serial.begin(9600);
    Particle.subscribe("toggle-led", toggleLed);
}
void loop() {
    while (digitalRead(switchInput) == HIGH) {
      int a = analogRead(ymotion);
      delay(5000);
      int b = analogRead(ymotion);
      if (abs(b-a) < 20) {
          Particle.publish("Motion",String(0), PUBLIC );
          ThingSpeak.writeField(myChannelNumber, 1, String(0), myWriteAPIKey);
      }else{
          Particle.publish("Motion",String(analogRead(ymotion)), PUBLIC );
          ThingSpeak.writeField(myChannelNumber, 1, String(analogRead(ymotion)), myWriteAPIKey);
      }
    }   
}

void toggleLed(const char *event, const char *data) {
    String myData = data;
    IntData = myData.toInt();
    
    if (IntData == 1){
        digitalWrite(led, HIGH);
    }
    else if (IntData == -1){
        digitalWrite(led, LOW);
    }

}

Buzzer

C/C++
int photoresistor = A2;
int IntData = 0;
int buz = D2;
int led= D7;

void setup() {
    pinMode(buz,OUTPUT);
    pinMode(led,OUTPUT);
    pinMode(photoresistor,INPUT);
    Particle.subscribe("time", buzzer);
    Particle.subscribe("Motion", motion);
}

void loop() {
    if (analogRead(photoresistor)<2500){
        Particle.publish("toggle-led", "1", PUBLIC); 
        delay(5000);
    }else if(analogRead(photoresistor)>2500){
        Particle.publish("toggle-led", "-1", PUBLIC); 
        delay(5000);
    }
}

void buzzer(const char *event, const char *data){
    String myData = data;
    IntData = myData.toInt();
    IntData = IntData *1000*60;
    delay(IntData);
    
    if (analogRead(photoresistor)<2500){
        analogWrite(buz,135);
        digitalWrite(led,HIGH);
        delay(3000);
        analogWrite(buz,0);
    }
}

void motion(const char *event, const char *data) {
    String myData = data;
    IntData = myData.toInt();
    
    if (IntData > 0){
        digitalWrite(led, LOW);
    }
    else if (IntData < 1){
        digitalWrite(led, HIGH);
    }

}

Timer

C/C++
void doEncoderA();
void doEncoderB();

int encoderA = D2;
int encoderB = D3;
int led = D7;


volatile bool A_set = false;
volatile bool B_set = false;
volatile int encoderPos = 0;

// variables will change:
int prevPos = 0;
int value = 0;
int switchVal;
int IntData = 0;
int oldVal = LOW;


void setup() {
    pinMode(encoderA, INPUT_PULLUP);
    pinMode(encoderB, INPUT_PULLUP);
    pinMode(led, OUTPUT);
    attachInterrupt(encoderA, doEncoderA, CHANGE);
    attachInterrupt(encoderB, doEncoderB, CHANGE);
    Particle.subscribe("toggle-led", toggleLed);
}

void loop() {
    if (prevPos != encoderPos) {
        prevPos = encoderPos;
        delay(5000);
        Particle.publish("time", String(encoderPos), PUBLIC); 
        delay(encoderPos*1000*60);
    }
    encoderPos = 0;
}

//----------------------------------------------------------------
void doEncoderA(){
    if( digitalRead(encoderA) != A_set ) {  // debounce once more
        A_set = !A_set;
        // adjust counter + if A leads B
        if ( A_set && !B_set ) 
            if (encoderPos < (60))
            {
                encoderPos += 1;
        }
    }
}

// Interrupt on B changing state, same as A above
void doEncoderB(){
   if( digitalRead(encoderB) != B_set ) {
    B_set = !B_set;
    //  adjust counter - 1 if B leads A
    if( B_set && !A_set ) 
        if (encoderPos > 0)
        {
            encoderPos -= 1;
        }
  }
}

void toggleLed(const char *event, const char *data) {
    String myData = data;
    IntData = myData.toInt();
    
    if (IntData == 1){
        digitalWrite(led, HIGH);
    }
    else if (IntData == -1){
        digitalWrite(led, LOW);
    }

}

Credits

Garrett Lowe

Garrett Lowe

1 project • 0 followers
Ethan Buchanan

Ethan Buchanan

1 project • 0 followers
Riddick White

Riddick White

1 project • 0 followers

Comments

Add projectSign up / Login