Megan PietJonathan Gaskins
Published

Sunrise Coffee Maker

If you wake up with the sun, then so should your coffee maker.

BeginnerFull instructions provided5 hours1,843
Sunrise Coffee Maker

Things used in this project

Hardware components

Photon
Particle Photon
×2
Photo resistor
Photo resistor
×1
Resistor 100 ohm
Resistor 100 ohm
×2
General Purpose Transistor PNP
General Purpose Transistor PNP
×1
Resistor 10k ohm
Resistor 10k ohm
×1
LED (generic)
LED (generic)
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2

Software apps and online services

ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Coffee Maker Circuit

This is the breadboard used to flip the transistor to turn on the coffee maker.

Photoresistor Circuit

This is the circuit diagram for the Photon with the photoresistor.

Code

Photocell Code

Arduino
This code goes to the particle connected to the photocell
#define publish_cycle 60000 // Only publish every 60 seconds
const String key = "<Your key here>"; // Change this to your Thingspeak api write key
int photoCell = A0;
int power = A5; // Photocell power.  An analog pin to gives a more steady voltage
int light; // Light
const int sleepytime = 43200; //seconds to sleep 3600=1hr; sleeps 12 hrs
unsigned int lastPublish = 0;
long waketime = 0;
void setup() {
    // Set Pin Modes
    pinMode(photoCell,INPUT);
    pinMode(power,OUTPUT);
    digitalWrite(power,HIGH); // Turn on power source for photoCell
    Particle.variable("light", &light, INT);
    Serial.begin(9600);
    delay(10000);
} //setup
void loop() {
  unsigned long now = millis();
  light = analogRead(photoCell);
  delay(100);  // is this needed?
  Serial.println();
  Serial.print(" light=" + String(light));
  delay(200);
  // Publish to thinkspeak
  if ((now - lastPublish) > publish_cycle) {
    Particle.publish("thingSpeakWrite_All", "{ \"1\": \"" + String(light) + "\"," +
      // "\"2\": \"" + String(tempC) + "\"," +
       // "\"3\": \"" + String(tempF) + "\"," +
      "\"4\": \"" + String(light) + "\"," +
       "\"k\": \"" + key + "\" }", 60, PRIVATE);
    lastPublish = now;
    Serial.println(" - Published!");
  } else {
      Serial.println();
  }
  if (light >= 150 && light < 155) {
  Particle.publish("Your event name here", String(light)); // create a unique event name to turn on your coffee maker
  delay(300000);
        waketime = millis();
        Particle.disconnect();
        System.sleep(photoCell,FALLING,sleepytime);
        Particle.connect(); //necessary when putting the Photon to sleep for a long time
        pinMode(photoCell,INPUT); // this may need resetting after sleep.
        waketime = millis();  //millis haults when sleeping.  find out the time on boot and compare from there.
  }
  delay(2000); // Wait 2 seconds before next loop
} // loop

Thingspeak Webhook

Arduino
{
  "api_key": "{{k}}",
  "field1": "{{1}}",
  "field2": "{{2}}",
  "field3": "{{3}}",
  "field4": "{{4}}",
  "field5": "{{5}}",
  "field6": "{{6}}",
  "field7": "{{7}}",
  "field8": "{{8}}",
  "lat": "{{a}}",
  "long": "{{o}}",
  "elevation": "{{e}}",
  "status": "{{s}}"
}
          

Coffee Maker Code

Arduino
This code received the event from the light photon and turned on the coffee maker and an LED.
int led = D0;

int transistor=D3;

void setup() {

   pinMode(led, OUTPUT);
   pinMode(transistor, OUTPUT);
   digitalWrite(led,HIGH);
   digitalWrite(transistor,LOW);
  pinMode(led,OUTPUT); 
  digitalWrite(led,LOW);
  Particle.function("ledfunc",ledfunc);


  Particle.subscribe("sunshine987_6543", myHandler);

  
}

void loop() {
 
}

int ledfunc(String command) {
    

    if (command=="on") {
        digitalWrite(transistor,HIGH);
        delay(500);
        digitalWrite(transistor,LOW);
        
        
        return 1;
    }
    else if (command=="off") {
        
        digitalWrite(transistor,HIGH);
        delay(500);
        digitalWrite(transistor,LOW);
        return 0;
    }
    else {
        return -1;
    }
}


void myHandler(const char *event, const char *data)
{

  digitalWrite(transistor,HIGH);
        delay(500);
        digitalWrite(transistor,LOW);
        
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000);
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000);
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000);
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000);
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000);
digitalWrite(led,HIGH);
delay(1000);
digitalWrite(led,LOW);
delay(1000);
digitalWrite(led,HIGH);
delay(1800000);

digitalWrite(transistor,HIGH);
        delay(500);
        digitalWrite(transistor,LOW);
}
 

Credits

Megan Piet

Megan Piet

1 project • 1 follower
Jonathan Gaskins

Jonathan Gaskins

1 project • 1 follower

Comments