Things used in this project

Hardware components:
Photon new
Particle Photon
×1
Software apps and online services:
Particle IDE
Twilio
Heroku

Code

Twilio-AlertsArduino
This is a modified version of the Tinker.ino by Particle. It will publish an event when pin D7's state switches.
/* Function prototypes -------------------------------------------------------*/
int tinkerDigitalRead(String pin);
int tinkerDigitalWrite(String command);
int tinkerAnalogRead(String pin);
int tinkerAnalogWrite(String command);
int previousState = 0;
/* This function is called once at start up ----------------------------------*/
void setup()
{
	//Setup the Tinker application here

	//Register all the Tinker functions
	Particle.function("digitalread", tinkerDigitalRead);
	Particle.function("digitalwrite", tinkerDigitalWrite);
	Particle.function("analogread", tinkerAnalogRead);
	Particle.function("analogwrite", tinkerAnalogWrite);

}

/* This function loops forever --------------------------------------------*/
void loop()
{
	// Read the current state of D7 Pin.
	int currentState = digitalRead(D7);
	// Check if current state of D7 is different than previous state
	if (currentState != previousState){
	    if(currentState){
	        // State is HIGH
	        Particle.publish("Twilio-SMS/{YOUR_PHONE_NUMBER_HERE}","The blue LED is now ON!", PRIVATE);
	    } else {
	        // State is LOW
	        Particle.publish("Twilio-SMS/{YOUR_PHONE_NUMBER_HERE}","The blue LED is now OFF!", PRIVATE);
	    }
	    // Update previousState variable
	    previousState = currentState;
	}
}

/*******************************************************************************
 * Function Name  : tinkerDigitalRead
 * Description    : Reads the digital value of a given pin
 * Input          : Pin
 * Output         : None.
 * Return         : Value of the pin (0 or 1) in INT type
                    Returns a negative number on failure
 *******************************************************************************/
int tinkerDigitalRead(String pin)
{
	//convert ascii to integer
	int pinNumber = pin.charAt(1) - '0';
	//Sanity check to see if the pin numbers are within limits
	if (pinNumber< 0 || pinNumber >7) return -1;

	if(pin.startsWith("D"))
	{
		pinMode(pinNumber, INPUT_PULLDOWN);
		return digitalRead(pinNumber);
	}
	else if (pin.startsWith("A"))
	{
		pinMode(pinNumber+10, INPUT_PULLDOWN);
		return digitalRead(pinNumber+10);
	}
	return -2;
}

/*******************************************************************************
 * Function Name  : tinkerDigitalWrite
 * Description    : Sets the specified pin HIGH or LOW
 * Input          : Pin and value
 * Output         : None.
 * Return         : 1 on success and a negative number on failure
 *******************************************************************************/
int tinkerDigitalWrite(String command)
{
	bool value = 0;
	//convert ascii to integer
	int pinNumber = command.charAt(1) - '0';
	//Sanity check to see if the pin numbers are within limits
	if (pinNumber< 0 || pinNumber >7) return -1;

	if(command.substring(3,7) == "HIGH") value = 1;
	else if(command.substring(3,6) == "LOW") value = 0;
	else return -2;

	if(command.startsWith("D"))
	{
		pinMode(pinNumber, OUTPUT);
		digitalWrite(pinNumber, value);
		return 1;
	}
	else if(command.startsWith("A"))
	{
		pinMode(pinNumber+10, OUTPUT);
		digitalWrite(pinNumber+10, value);
		return 1;
	}
	else return -3;
}

/*******************************************************************************
 * Function Name  : tinkerAnalogRead
 * Description    : Reads the analog value of a pin
 * Input          : Pin
 * Output         : None.
 * Return         : Returns the analog value in INT type (0 to 4095)
                    Returns a negative number on failure
 *******************************************************************************/
int tinkerAnalogRead(String pin)
{
	//convert ascii to integer
	int pinNumber = pin.charAt(1) - '0';
	//Sanity check to see if the pin numbers are within limits
	if (pinNumber< 0 || pinNumber >7) return -1;

	if(pin.startsWith("D"))
	{
		return -3;
	}
	else if (pin.startsWith("A"))
	{
		return analogRead(pinNumber+10);
	}
	return -2;
}

/*******************************************************************************
 * Function Name  : tinkerAnalogWrite
 * Description    : Writes an analog value (PWM) to the specified pin
 * Input          : Pin and Value (0 to 255)
 * Output         : None.
 * Return         : 1 on success and a negative number on failure
 *******************************************************************************/
int tinkerAnalogWrite(String command)
{
	//convert ascii to integer
	int pinNumber = command.charAt(1) - '0';
	//Sanity check to see if the pin numbers are within limits
	if (pinNumber< 0 || pinNumber >7) return -1;

	String value = command.substring(3);

	if(command.startsWith("D"))
	{
		pinMode(pinNumber, OUTPUT);
		analogWrite(pinNumber, value.toInt());
		return 1;
	}
	else if(command.startsWith("A"))
	{
		pinMode(pinNumber+10, OUTPUT);
		analogWrite(pinNumber+10, value.toInt());
		return 1;
	}
	else return -2;
}

Credits

15284163 10101162552377826 2155907735284080982 n
Sean Marraffa

I am a Systems Integration Specialist for Sebastian Technologies. When I'm not building custom solutions for work I enjoy making fun home automation projects.

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

IoT Drone - Part 1 - Motor Control
Intermediate
  • 1,363
  • 27

Work in progress

After flying a friends drone I was hooked. However, I wanted to build my own, so this is part one of my drone project - motor control.

Bike Swarm
Intermediate
  • 608
  • 13

Work in progress

Cyclists will be able to connect seamlessly to form a synchronized swarm of riders to reduce traffic congestion and improving safety.

Bike Swarm

Team Bright Water Bottle

Smart Maid
Intermediate
  • 1,308
  • 21

Full instructions

Hack your existing iRobot Create with Particle and control it through Alexa.

Smart Maid

Team Yosnalab

"Internet-controlled" Nespresso Machine
Intermediate
  • 2,618
  • 8

Using a chatbot and a Nespresso machine to make coffee remotely.

IoT Smart Desk Drawer with Amazon DRS
Intermediate
  • 461
  • 4

Never run out of office supplies again. PostIt notes, stamps, paperclips, tape and paper replenished from the cloud.

Home Theater Accent Lights
Intermediate
  • 307
  • 1

Full instructions

Particle Photon and SmartThings controlled WS2812B.

Add projectSign up / Login
Respect project