Eunice_Paired Device

Made by yuany4

The project objective is to pair my particle with my teammate's particle, so our devices can communicate with each other.

Created: December 4th, 2024

0

Intention

The project objective is to pair my particle with my teammate's particle, so our devices can communicate with each other and change the LED color when certain actions were triggered. 

0

Context

We tried to remake the lover's cups with our IoT prototype. The most difficult part is not make the LED shine, but also make the device work with the sensors on the other breadboard. Therefore, we utilized the Particle publish and subscribe to make it work.

0

Process

We named the devices by cup1 and cup2. In my code, my device is the cup2. My LED will change into when the cup1 board detected data from its photoresistor. We tried to connect our devices through public cloud on Particle initially, but it didn't work. Therefore, we moved two device under the same account, and it worked eventually. 

0

Outcome

    • When the the photoresistor has lower value of brightness, meaning 'kiss' in our setting, the LED will change into pink on the other device. 
    • Therefore, the user2 can know user1 is drinking by the paired cup. 

0

Reflection

The pairing process is much more difficult than wiring the circuit on the device, it took us almost three hours to solve the problem. 

0
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

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

// Include Particle Device OS APIs
#include "Particle.h"
#include <neopixel.h>

#define PIXEL_PIN SPI // plug into pin MO
#define PIXEL_COUNT 12 // 0 addressed
//#define PIXEL_TYPE SK6812RGBW
#define PIXEL_TYPE WS2812

// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);

// Show system, cloud connectivity, and application logs over USB
// View logs with CLI using 'particle serial monitor --follow'
SerialLogHandler logHandler(LOG_LEVEL_INFO);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

static int photoPin = A0;
static int tempPin = A1;


uint32_t w = strip.Color(0, 0, 0, 255); // Pure white
uint32_t blue = strip.Color(0, 0, 255); // Blue
uint32_t green = strip.Color(0, 255, 0); // Green
uint32_t purple = strip.Color(100, 0, 100); // Purple
uint32_t red = strip.Color(255, 0, 0); // Red

uint32_t c1 = green; 
uint32_t c2 = purple; 

int photoReading = 0;
int tempReading = 0;
int tempOut =0;
int photoOut = 0;
// setup() runs once, when the device is first turned on
void setup() {
    Particle.function("kiss", kiss);
    Particle.function("ambient", ambient);
    
    Particle.variable("Brightness", photoReading);
    Particle.variable("Temperature", tempReading);
    strip.begin();
    ambient("");
   
   //Particle.subscribe("diot/love-cup-kiss/cup1/", handleKiss); //cup1 for other cup
   Particle.subscribe("diot/love-cup-kiss/", handleKiss);

}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
    photoReading = analogRead(photoPin);
    tempReading = analogRead(tempPin);
    
  
    
    
    delay(100);
    
    if (photoReading < 2500){
       // Particle.publish();
        publishKiss();
    }
    else{
        ambient("");
    }
    if(tempReading > 650){
        c1 = red;
    }
    else{
        c1 = blue;
    }
    delay (1000);
}

int ambient(String Command){
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c1); // set a color 
        strip.show();
        delay( 100 );
    }
    return 1;
}

int kiss(String Command){
     
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c1); // set a color 
        strip.show();
        delay( 100 );
    }
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c2); // set a color 
        strip.show();
        delay( 100 );
    }
    return 1;
}

void publishKiss(){
    String eventName = "diot/love-cup-kiss/" + System.deviceID();
    Particle.publish(eventName, NULL, 30, PUBLIC);//cup2 for other cup
    //String eventName = "love-cup/kiss/0a10aced202194944a05990c";
    //Particle.publish(eventName, NULL, 30, PUBLIC);
}

void handleKiss(const char *event, const char *data){
    kiss("");
}
Click to Expand
x
Share this Project


About

The project objective is to pair my particle with my teammate's particle, so our devices can communicate with each other.