Things used in this project

Hardware components:
Photon new
Particle Photon
×1
Ardgen mega
Arduino Mega 2560 & Genuino Mega 2560
×1
Pi 3 02
Raspberry Pi 3 Model B
×1
Adafruit industries ada1314 image
Speaker: 3W, 4 ohms
×1
Aiy projects 4 bgsoumwo5r
Google AIY Projects Kit
×1
Voice HAT for Raspberry Pi
×1
Mic Array
×1
Arcade Button and Micro Switch
×1
Servo (Continuous Rotation)
×1
11026 02
Jumper wires (generic)
×1
Te connectivity 4 103741 0 image 75px
Male Header 40 Position 1 Row (0.1")
×1
Pppc081lfbn rc sml
Female Header 8 Position 1 Row (0.1")
×1
SparkFun APDS-9960
×1
181 02
Adafruit Standard LCD - 16x2 White on Blue
×1
Omron b3f 1000 image 75px
SparkFun Pushbutton switch 12mm
×2
Software apps and online services:
Ide web
Arduino IDE
IFTTT Assistant Service
Particle Photon Build IDE
Logo assistant kvfq4j72g6 yciz8pmvwr
Google Assistant SDK
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)
3drag
3D Printer (generic)

Custom parts and enclosures

This is from Thingiverse for the Automated Cat Feeder: http://www.thingiverse.com/thing:27854 You will need a 1.5" T-joint PVC pipe as well.
Button Holder
This holds the actual button in place.
Button
This slides into the button holder piece. It is what the user presses. Make sure it can slide freely.
Switch Holder
It attaches on the side of the button holder and the tact switch is mounted on it.

Schematics

Schematic
Connect as-is. Sorry if it's messy.
Schematic bb 2ok5rjtgon

Code

Arduino Mega CodeC/C++
Copy and Paste for the Arduino Mega.
#include <Wire.h>
#include <SparkFun_APDS9960.h>
#include <LiquidCrystal.h>
#include <Servo.h>

#define LARGE_AMOUNT 4000 //time to dispense candy in ms
#define SMALL_AMOUNT 2500

LiquidCrystal lcd(12,11,5,4,3,2);

Servo auger;

SparkFun_APDS9960 apds = SparkFun_APDS9960();

uint8_t proximity_data = 0;
int LB = 6;
int RB = 7;
bool LBS = false;
bool RBS = false;
int candy_amount = 0;

void setup(){
	if ( apds.init() ) {
    Serial.println(F("APDS-9960 initialization complete"));
  } else {
    Serial.println(F("Something went wrong during APDS-9960 init!"));
  }
  if ( !apds.setProximityGain(PGAIN_2X) ) {
    Serial.println(F("Something went wrong trying to set PGAIN"));
  }
  if ( apds.enableProximitySensor(false) ) {
    Serial.println(F("Proximity sensor is now running"));
  } else {
    Serial.println(F("Something went wrong during sensor init!"));
  }
  lcd.begin(16,2);
  lcd_reset();
  lcd.print("Initializing");
  auger.attach(9);
  pinMode(LB, INPUT);
  pinMode(RB, INPUT);
  Serial.begin(9600);
  delay(5000);
  lcd_reset();
  lcd.print("Running");
  delay(4000);
  lcd_reset();
	lcd.print("Google Powered");
  lcd.setCursor(0,1);
  lcd.print("Candy Dispenser");
  auger.write(90);
  auger.detach();
}

void loop(){
  int state = analogRead(A0);
  LBS = digitalRead(LB);
  RBS = digitalRead(RB);
  
	if (state > 60 || LBS == true || RBS == true){
  Serial.println("active");
  Serial.print(LBS);
  Serial.print(",");
  Serial.println(RBS);
  LBS = false;
  RBS = false;
  delay(1000);
  lcd_reset();
    lcd.print("How much candy?");
    lcd.setCursor(0,1);
    lcd.print("A Little   A LOT");
    while(LBS == false && RBS == false){
      LBS = digitalRead(LB);
      RBS = digitalRead(RB);
    }
    if(LBS){
      candy_amount = SMALL_AMOUNT;
    }
    else if(RBS){
      candy_amount = LARGE_AMOUNT;
    }
  while(proximity_data != 255){
  if ( !apds.readProximity(proximity_data) ) {
    Serial.println("Error reading proximity value");
  } else {
    
    lcd_reset();
    lcd.print("Waiting for cup");
    lcd.setCursor(0,1);
    lcd.print("Distance: ");
    lcd.print(proximity_data);
  }
  delay(400);
  }
  lcd_reset();
  lcd.print("Cup found!");
  delay(1000);
  
  for(int x=5;x>0;x--){
    if ( !apds.readProximity(proximity_data) ) {
    Serial.println("Error reading proximity value");
  } else {}
    if(proximity_data != 255){
      lcd_reset();
      lcd.print("Please replace");
      lcd.setCursor(0,1);
      lcd.print("the cup");
      delay(2000);
      while(proximity_data != 255){
  if ( !apds.readProximity(proximity_data) ) {
    Serial.println("Error reading proximity value");
  } else {
    
    lcd_reset();
    lcd.print("Waiting for cup");
    lcd.setCursor(0,1);
    lcd.print("Distance: ");
    lcd.print(proximity_data);
  }
  delay(400);
  }
  lcd_reset();
  lcd.print("Thanks for");
  lcd.setCursor(0,1);
  lcd.print("replacing it");
  delay(1000);
    }
    else{
    lcd_reset();
  lcd.print("Pouring in: ");
  lcd.print(x);
  delay(1000);
    }
  }
  lcd_reset();
  lcd.print("Pouring candy...");
    delay(1000);
    auger.attach(9);
		auger.write(20);
		delay(candy_amount);
		auger.write(90);
    auger.detach();
		
   lcd_reset();
   lcd.print("Enjoy!");
   delay(4000);
   lcd_reset();
 lcd.print("Google Powered");
  lcd.setCursor(0,1);
  lcd.print("Candy Dispenser");
  proximity_data = 8;
	}
}

void lcd_reset(){
	lcd.clear();
	lcd.setCursor(0,0);
}
Particle Photon CodeC/C++
Copy and Paste
#include "application.h""

int pin = 7;
char charBuf[50];
int out_pin = 5;

void setup() {
    pinMode(out_pin,OUTPUT);
    pinMode(pin, OUTPUT);
    Particle.function("give_candy", candy);
    Serial.begin(9600);
}

void loop() {

}

int candy(String command){
    command.toCharArray(charBuf, 49);
    char number[6];
    sprintf(number, "%c" "%c" "%c", charBuf[0],charBuf[1],charBuf[2]);
    int length1 = (int)number[0] - 48;
    int length2 = (int)number[1] - 48;
    int length3 = (int)number[2] - 48;
    
    int length = length1 * 100 + length2 * 10 + length3;
    digitalWrite(out_pin,HIGH);
    delay(100);
    digitalWrite(out_pin,LOW);
    
    for(int x=0; x<5; x++){
        digitalWrite(pin,HIGH);
        delay(length);
        digitalWrite(pin, LOW);
        delay(length);
    }
    return 0;
}

Credits

Download
Arduino “having11” Guy

I love creating cloud solutions that can interact with hardware along with using Arduino boards and Raspberry Pis to create new projects.

Contact

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

Arduino on Internal Oscillator Crystal as Clock Source
Intermediate
  • 670
  • 46

Protip

Want to make an Arduino having only an ATmega328 chip and nothing else? Not even the crystal oscillator!

Reducing Arduino Power Consumption
Intermediate
  • 1,097
  • 74

Protip

One the most important feature of portable electronics should be long battery life. We can reduce the current drawn by several ways.

Wireless Sensor Node
Intermediate
  • 14
  • 2

Work in progress

This project is a compact wireless sensor node that connects directly to a smart phone or tablet to display data from connected sensors.

CNC Controller in Python
Intermediate
  • 509
  • 8

Full instructions

First ever CNC machine controller implementation in pure Python.

Distance Measurement Vehicle via Websocket
Intermediate
  • 2,676
  • 21

Full instructions

A vehicle measures distance with an encoder on its wheel. It is remotely controlled and transmits the distance via Websocket.

Pi Zero Speaker - DIY Audio HAT and Audio Player
Intermediate
  • 385
  • 6

Work in progress

Convert an old speaker into something cool powered by Pi Zero.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login