Jay K
Published © GPL3+

Make Your Light Smart Using Amazon Alexa

This project will teach you to make your light a smart device using Amazon Alexa, Particle Photon and free IFTTT service.

IntermediateShowcase (no instructions)4 hours2,589
Make Your Light Smart Using Amazon Alexa

Things used in this project

Story

Read more

Schematics

Video - Working model

Code

Code to control Relay Shield for Particle Photon I²C 2-Channel DPDT 5-Amp with WiFi and USB

Arduino
#if PLATFORM_ID == 6
//Photon code here

    #define MY_FUNCTION(cloudFunctionID,localFunctionName)   Particle.function(cloudFunctionID,localFunctionName) 
    #define MY_VARIABLE(cloudVariableID,localVariableName)   Particle.variable(cloudVariableID,localVariableName) 
    
    // This #include statement was automatically added by the Particle IDE.
    #include "NCD2Relay/NCD2Relay.h"
    
    /*For relay control*/
    NCD2Relay relayController;
    
   
    /*Relay number*/
    int relayNumber = 1;
    
    /*Relay status*/
    int rStatus = 0;
    /***********************************Relay END**************************************/
    
    int commandSent = 255;
 
    void setup() 
    {
        setupFunctions();
        setupRelay();
    }
    
    void loop() 
    {
       
    }
    
    void setupFunctions()
    {
        MY_FUNCTION("Relay#",setRelayNumber);
        MY_FUNCTION("RelayAction",setResetRelay);  
    }
    
    void setupVariables()
    {
    }
    
    void setupRelay()
    {
        Serial.begin(9600);
        relayController.setAddress(0,0,0);
    }
    

    
    int setRelayNumber(String command)
    {
        if (command.length() != 1) 
            return -1;
    
        relayNumber = atoi(command);
                
    }
    
    int setResetRelay(String command)
    {
        if (command.length() != 1) 
            return -1;
        
        commandSent = atoi(command);

        if (commandSent==1) 
        {
            rStatus = relayController.readRelayStatus(relayNumber);
            
            if(rStatus==0)
            {
              relayController.turnOnRelay(relayNumber);  
            }

            return rStatus;
        }
        else if(commandSent==0)
        {
            rStatus = relayController.readRelayStatus(relayNumber);
            
            if(rStatus==1)
            {
                relayController.turnOffRelay(relayNumber);
            }
            

            return rStatus; 
        }
    }


#else
    #error "*** PLATFORM_ID not supported by this library. PLATFORM should be Core or Photon ***"
#endif

Credits

Jay K

Jay K

1 project • 0 followers
HMI Architect - Automotive domain

Comments