Pavithren(Viren)Kenneth Lim
Published © GPL3+

Ring a Light

A visual doorbell for the deaf and hard of hearing which provides visual and audio (for hearing) notifications.

IntermediateFull instructions provided3 hours863
Ring a Light

Things used in this project

Hardware components

Photon
Particle Photon
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Hue service
IFTTT Hue service
Particle Pi
Particle Pi

Story

Read more

Schematics

Circuit Schematics

Wiring between the Particle, MK Chime and the button.

Code

Particle

Arduino
SYSTEM_MODE(SEMI_AUTOMATIC);

// --- USER VARIABLES --- //


//for setting up Philips Hue Integration refer to github project at link below

// https://github.com/fsyth/hue-photon

// Optionally change these lines to enable compact wiring layout,
// manual wifi mode, reversed potentiometer voltages, and cloud
// debugging.
#define COMPACT true
#define MANUAL_WIFI false
#define REVERSE_VOLTAGES false
#define CLOUD_ENABLED false


// Hue Bridge API parameters. These can be obtained manually. Use this addon to get the values: https://chrome.google.com/webstore/detail/hue-light-controller/okogmhcbjehmmfmhmolkbpbhbnmmcgnd
const byte ip[] = { 192, 168, 1, x}; // replace with ip address of Hue bridge
const String id = "x";//replace with developer id using chrome extension above

// The rooms or individual lights to be controlled. Trial and error is
// simplest for finding these values.
// Set room numbers to control all lights in that room.
const int rooms[] = { 2 };
// Additional individual lights that are not already controlled as part
// of a room. There is no need to double up on sending requests.
const int lights[] = {};


// Declare a JSON formatted string to be sent to the Hue Bridge
String json;

// Create a TCPClient that will send on the JSON data
TCPClient client;

#if MANUAL_WIFI
// The wifi module should be turned off after a number of loops to save power
const int offAfter = 60e3 / loopInterval;

// Keep count of the number of loops that have been processed.
// If a number of loops pass without change, the wifi module can be turned off
// to conserve battery life.
int counter = 0;
bool wifiEnabled = true;
#endif


// --- END OF USER VARIABLES --- //


// These variables are derived from the Hue parameters specified above
const int lightCount = sizeof(lights) > 0 ? sizeof(lights) / sizeof(lights[0]) : 0;
const int roomCount  = sizeof(rooms)  > 0 ? sizeof(rooms)  / sizeof(rooms[0])  : 0;




// First, let's create our "shorthand" for the pins
// Same as in the Blink an LED example:
// led1 is D0, led2 is D7

int button = D0;
int ledPin = D7;
int val=0;
unsigned long old_time = millis();
uint8_t retry_count = 0;


// Last time, we only needed to declare pins in the setup function.
// This time, we are also going to register our Particle function


// Turns the LED on for time t, and then off for time t.
void ledFlash(int t) {
    // Turn the LED on for time t before turning off for time t.
    digitalWrite(ledPin, HIGH);
    delay(t);
    digitalWrite(ledPin, LOW);
    delay(t);
}


// Sends the string data stored in the json variable to the Hue Bridge.
// It also re-enables the wifi module if it was previously disabled and
// resets the counter for loops without changes occurring.
void sendJSON() {
    #if MANUAL_WIFI
    // Turn the wifi module on if it was previously disabled
    if (!wifiEnabled) {
        wifiEnabled = true;
        WiFi.on();

        // Wait until the wifi module is ready before proceeding.
        while (!WiFi.ready()) Particle.process();

        // Reset counter
        counter = 0;
    }
    #endif

    // Sending JSON led flash start
    digitalWrite(ledPin, HIGH);
    
    
    //json="{\"on\":true,\"hue\":12750,\"alert\":\"select\"}";//yellow blink
    json="{\"on\":true,\"alert\":\"select\"}";//blink

    for(int loopCount=0;loopCount<5;loopCount++){
         for (int i = 0; i < roomCount; i++) {
            if (client.connect(ip, 80)) {
                client.print("PUT /api/");
                client.print(id);
                client.print("/groups/0");
                client.println("/action HTTP/1.0");
                client.print("Content-Length: ");
                client.println(json.length());
                client.println();
                client.println(json);
            }
        }
         delay(1600);
    }
    

    // Sending JSON led flash end
    digitalWrite(ledPin, LOW);
}


void setup()
{
	WiFi.on();

   // Here's the pin configuration, same as last time
   pinMode(button, INPUT_PULLDOWN);
   pinMode(ledPin, OUTPUT);

   digitalWrite(ledPin, LOW);
   Particle.function("f", cloudFunction);
   
   
   // Setup the server, and wait until it's ready
    if (client.connect(ip, 80)) {
        // Flash the onboard LED to show connected
        ledFlash(200);
        ledFlash(200);
        client.stop();
    }

}

//visit https://console.particle.io/devices and immediately enter "sm" when the particle is switch on. This will put the particle into safe mode.
int cloudFunction(String command)
{
	if(command == "sm") {
	 System.enterSafeMode();
	 return 2;
	}
	else return -1;
}


// Last time, we wanted to continously blink the LED on and off
// Since we're waiting for input through the cloud this time,
// we don't actually need to put anything in the loop

void loop()
{
	if(millis() - old_time >= 2000) {
	 if(retry_count < 5){
	  if(!WiFi.ready()){
	   WiFi.connect();
	   retry_count++;
	  }
	  else if (!Particle.connected()){
	   Particle.connect();
	   retry_count++;
	  }
	  else {
	    sendJSON();//
        delay(8000);//to ensure that i can update firmware
        System.sleep(SLEEP_MODE_DEEP);
	  }
	 }//if less than 2 seconds between button press,
	 else{
	     WiFi.off();
	     retry_count = 0;
	     System.sleep(SLEEP_MODE_DEEP);
	 }
	 old_time = millis();
	}
	
   
}

Credits

Pavithren(Viren)

Pavithren(Viren)

1 project • 0 followers
Experienced in networking, electronic prototyping, programming, design thinking and using ground-up approach to solving everyday problems.
Kenneth Lim

Kenneth Lim

0 projects • 0 followers
Thanks to fsyth.

Comments

Add projectSign up / Login