Paired Devices - Blinking Lights

Made by Adwoa Asare

When one of us covers the light sensor, the other person's light will blink pink.

Created: December 5th, 2024

0

Intention

Our goal was to prototype a remake of the lover's cups project, where a photoresistor on a rim of a cup would detect a "kiss" and alert the other person's cup to blink pink. When not "kissing" the cup would remain blue indicating that the temperature sensor was cold. The devices communicated through Wi-Fi connection.

0

Context

This prototype was based on the Lover's Cups project which involved a couple that has wirelessly connected cups that indicate each other's status.

0

Process

At first, we tried to connect our devices while having our Photon 2 microcontrollers registered on separate accounts, but we could not find any way to do this. We did not want to use Webhooks, so we then moved our devices to be on the same account. When we did this, at first, we were unable to find a way to push code to the second device, but I found an old thread online about this issue and we used the info from it to troubleshoot our problem.

0
// 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/", 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);//cup2 for other cup
    
}

void handleKiss(const char *event, const char *data){
    kiss("");
}
Adwoa Asare (2024) Click to Expand
0

Outcome

    • Our devices blink when the other cup experiences a "kiss".
    • We can view each other's published events on the same console.

0
0

Reflection

I learned how to connect to Particle microcontrollers. I wish there was a way to connect microcontrollers that are on different accounts, and I would look more into this idea in the future.

x
Share this Project


Focused on
About

When one of us covers the light sensor, the other person's light will blink pink.