Anthony Nicolasjoseph harding
Published © GPL3+

Fill the Dog Bowl with a Single Click!

A simple Particle Photon project to fill a small dish up with water for a dog (or any animal that likes water).

BeginnerFull instructions provided10 hours585
Fill the Dog Bowl with a Single Click!

Things used in this project

Hardware components

Photon
Particle Photon
×2
Any 1 Gallon Tank
×1
Any bowl for filling
×1
7/16th Inch Tubing (24 inches long)
×1

Hand tools and fabrication machines

Digital Loggers AC/DC Control Relay
HG16 Submersible Pump

Story

Read more

Schematics

Schematic

A simple circuit diagram created using Fritzing to represent the particle photon plugged into the simple switch relay, which power the water pump.

Code

Pump On Code

PHP
This code recognizes when Joey publishes a code by activating D7 on his phone through the Particle Application, which activates the D7 LED on my Photon, activating the pump for 8 seconds to fill a water bowl with 2 cups of water. Then, this code publishes an event which Joey's Photon recognizes to turn the D7 LED off of his Photon.
int led=D7;

void setup() {

pinMode(led,OUTPUT);
digitalWrite(led, LOW);
    Particle.subscribe("WaterForDog", myHandler, "33004e000651353530373132");
}


void myHandler(const char *event, const char *data)
{
  digitalWrite(led, HIGH);
  delay(8000);
  digitalWrite(led, LOW);

}


void loop() {
    delay(100);
if(digitalRead(led)==HIGH){
Particle.publish("TurnLEDOff", "turning D7 to low", PUBLIC);
}
}

photon publish code for the activation photon

PHP
This code is a tinker used to publish an event to turn on the D7 led of the other photon
int tinkerDigitalRead(String pin);
int tinkerDigitalWrite(String command);
int tinkerAnalogRead(String pin);
int tinkerAnalogWrite(String command);
int Led = D7;
void setup()
{
	Particle.function("digitalread", tinkerDigitalRead);
	Particle.function("digitalwrite", tinkerDigitalWrite);
	Particle.function("analogread", tinkerAnalogRead);
	Particle.function("analogwrite", tinkerAnalogWrite);
    pinMode(Led, OUTPUT);
    Particle.subscribe("TurnLEDOff", myHandler, "2b0043000c47363339343638");
}





void loop()
{
    delay(10);
    if(digitalRead(Led) ==HIGH){
        Particle.publish("WaterForDog", "giving the dog some water", PUBLIC);
        delay(3000);
        digitalWrite(Led, LOW);
    }
}
void myHandler(const char *event, const char *data){
    digitalWrite(Led, LOW);
}
int tinkerDigitalRead(String pin)
{
	int pinNumber = pin.charAt(1) - '0';
	
	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;
}

int tinkerDigitalWrite(String command)
{
	bool value = 0;
	int pinNumber = command.charAt(1) - '0';
	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;
}
int tinkerAnalogRead(String pin)
{

	int pinNumber = pin.charAt(1) - '0';
	
	if (pinNumber< 0 || pinNumber >7) return -1;

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

int tinkerAnalogWrite(String command)
{
	int pinNumber = command.charAt(1) - '0';
	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

Anthony Nicolas

Anthony Nicolas

1 project • 0 followers
joseph harding

joseph harding

1 project • 0 followers

Comments

Add projectSign up / Login