Raghavendra Ponuganti
Published © GPL3+

My style of welcome to my wife

Romantic and Technical welcome to my wife powered by Particle Core.

IntermediateShowcase (no instructions)2,176
My style of welcome to my wife

Things used in this project

Hardware components

Spark Core
Particle Spark Core
×1
DC motor (generic)
×1
Relay (generic)
×1
ULN2803
To drive RGB LED strip. One channel used to drive DC Motor.
×1

Software apps and online services

Tasker
AutoVoice
RESTask for Tasker

Story

Read more

Code

Code to control Motor and Relay

C/C++
// This #include statement was automatically added by the Particle IDE.

int RELAY_1     = D2;
int RELAY_2     = D3;

int MOTOR       = A1;

int motorDrivingTime;
int motorDrivingPWM;
unsigned long motorStartTime;

unsigned long currentTime;



void setup() {
    pinMode(RELAY_1,    OUTPUT);
    pinMode(RELAY_2,    OUTPUT);
    pinMode(MOTOR,      OUTPUT);
    
    motorDrivingTime = 0;
    motorDrivingPWM = 0;
    motorStartTime = 0;
    currentTime = 0;
    
    Spark.function("startMotor",    controlMotor);
    Spark.function("startRelay1",   controlRelay1);
    Spark.function("startRelay2",   controlRelay2);
    
}

void loop() {
    
    currentTime = millis();
    
    if((currentTime - motorStartTime) > (motorDrivingTime*1000))
    {
        analogWrite(MOTOR, 0);
    }
}

/* Called from external world*/
/* Driving Motor */
int controlMotor(String command)
{
    // Example TIME(00),PWM(000)
    
    motorDrivingTime = command.substring(5,7).toInt();
    motorDrivingPWM  = command.substring(13,16).toInt();
    
    motorStartTime = millis();
    
    analogWrite(MOTOR,  motorDrivingPWM);
    
    return 1;
}

/* Called from external world*/
/* Drive Relay 1 */
int controlRelay1(String command)
{
    // Example ON or OFF
    if(command == "ON")
    {
        digitalWrite(RELAY_1, 1);
    }else
    {
        digitalWrite(RELAY_1, 0);
    }
    
    return 1;
}


/* Called from external world*/
/* Drive Relay 1 */
int controlRelay2(String command)
{
    // Example ON or OFF
    if(command == "ON")
    {
        digitalWrite(RELAY_2, 1);
    }else
    {
        digitalWrite(RELAY_2, 0);
    }
    
    return 1;
}


/* Called from external world*/
/* Stop everything connected */
int stopAllActions(String command)
{
    controlMotor("TIME(00),PWM(000)");
    controlRelay1("OFF");
    controlRelay2("OFF");
    return 1;
}

Credits

Raghavendra Ponuganti

Raghavendra Ponuganti

3 projects • 11 followers

Comments