Things used in this project

Hardware components:
A000066 iso both
Arduino Arduino UNO & Genuino UNO
×1
13285 01
PIR Motion Sensor (generic)
×1
Esp01
Espressif ESP8266 ESP-01
×1
10722 01
Speaker: 0.25W, 8 ohms
×1
SparkFun Servo - Generic Metal Gear (Micro Size)
×1
Software apps and online services:
8ztngd 9
circuito.io
Use this magic link >>https://www.circuito.io/app?selectedComponentsIds=11021&selectedComponentsIds=9442&selectedComponentsIds=13678&selectedComponentsIds=197253&selectedComponentsIds=931983&selectedComponentsIds=10333

Custom parts and enclosures

speaker mount
servo mount
servo case
PIR case

Schematics

Pet Feeder Dashboard
Download this file to your computer and import it to Freeboard according to the steps in the "connectivity" section of the tutorial.
dashboard_RdzZcxLkpD.json

Code

Code for IoT pet feederArduino
Replace the sample code from the circuito reply with the code below.
Make sure to leave the //Include Libraries and //Pin Definitions at the top of the code, and also keep all the libraries that are on the original code from circuito.io.
const int ServoRestPosition   = 20;  //Starting position
const int ServoTargetPosition = 150; //Position when event is detected
unsigned int HoorayLength          = 6;                                                      // amount of notes in melody
unsigned int HoorayMelody[]        = {NOTE_C4, NOTE_E4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5}; // list of notes. List length must match HoorayLength!
unsigned int HoorayNoteDurations[] = {8      , 8      , 8      , 4      , 8      , 4      }; // note durations; 4 = quarter note, 8 = eighth note, etc. List length must match HoorayLength!

unsigned int comeLength          = 3;
unsigned int comeMelody[]        = {NOTE_C5, NOTE_G5, NOTE_C5};
unsigned int comeNoteDurations[] = {8      , 8      , 8};

ESP8266 wifi(WIFI_PIN_RXD,WIFI_PIN_TXD);
Servo servo;
PIR pir(PIR_PIN_SIG);
PiezoSpeaker piezoSpeaker(PIEZOSPEAKER_PIN_SIG);

int pirCounter = 0;
// ====================================================================
// vvvvvvvvvvvvvvvvvvvv ENTER YOUR WI-FI SETTINGS  vvvvvvvvvvvvvvvvvvvv
//
const char *SSID     = "YOURWIFI"; // Enter your Wi-Fi name 
const char *PASSWORD = "YOURPASSWORD" ; // Enter your Wi-Fi password
//
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ====================================================================


// These Dweet tokens have been auto generated for you.
char* const inputToken  = "YOURTOKEN_input";
char* const outputToken = "YOURTOKEN_output";

Dweet dweet( &wifi, inputToken, outputToken);

/* This code sets up the essentials for your circuit to work. It runs first every time your circuit is powered with electricity. */
void setup() {
    // Setup Serial which is useful for debugging
    // Use the Serial Monitor to view printed messages
    Serial.begin(9600);
    Serial.println("start");
    
    if (!wifi.init(SSID, PASSWORD))
    {
        Serial.println(F("Wifi Init failed. Check configuration."));
        while (true) ; // loop eternally
    }
    servo.attach(SERVO_PIN);
    servo.write(ServoRestPosition);
    delay(100);
    servo.detach();
}

/* This code is the main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop. */
void loop() {

    bool pirVal = pir.read();
    
    //SET DWEETS
    dweet.setDweet("pir", pirVal );
    dweet.setDweet("pirCounter",  pirCounter);
    
    
    dweet.sendDweetKeys();
    
    
    if (pirVal)
    {
        pirCounter++;
        // The servo will rotate to target position and back to resting position with an interval of 500 milliseconds (0.5 seconds) 
        servo.attach(SERVO_PIN);         // 1. attach the servo to correct pin to control it.
        servo.write(ServoTargetPosition);  // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
        delay(500);                              // 3. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
        servo.write(ServoRestPosition);    // 4. turns servo back to rest position. Modify initial position by modifying the 'ServoRestPosition' definition above.
        delay(500);                              // 5. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
        servo.detach();                    // 6. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.
        
        // The Piezo Speaker light will play a beep for half a second, wait for another 500ms(half a second) and then play a tune
        piezoSpeaker.tone(400);                                                    // 1. plays a 400Hz beep. Change the value in the brackets (400) for a higher or lower beep.
        delay(500);                                                               // 2. keeps playing it for 500ms
        piezoSpeaker.off();                                                        // 3. stops the beep
        delay(500);                                                               // 4. waits 500ms                   
        piezoSpeaker.playMelody(HoorayLength, HoorayMelody, HoorayNoteDurations);  // 5. plays the Hurray melody. to play a different melody, modify HoorayLength, HoorayMelody and HoorayNoteDuration above.                    
        delay(500);                                                               // 4. waits 500ms
    }
    
    
    //GET DWEETS  
    dweet.receiveDweetEvents();
    
    
    if(strcmp(dweet.getValue() , "servo") == 0)
    {
        Serial.println(F("servo was pressed!"));
        // The servo will rotate to target position and back to resting position with an interval of 500 milliseconds (0.5 seconds) 
        servo.attach(SERVO_PIN);         // 1. attach the servo to correct pin to control it.
        servo.write(ServoTargetPosition);  // 2. turns servo to target position. Modify target position by modifying the 'ServoTargetPosition' definition above.
        delay(500);                              // 3. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
        servo.write(ServoRestPosition);    // 4. turns servo back to rest position. Modify initial position by modifying the 'ServoRestPosition' definition above.
        delay(500);                              // 5. waits 500 milliseconds (0.5 sec). change the value in the brackets (500) for a longer or shorter delay in milliseconds.
        servo.detach();                    // 6. release the servo to conserve power. When detached the servo will NOT hold it's position under stress.
    }
    else if(strcmp(dweet.getValue() , "piezoSpeaker") == 0)
    {
        Serial.println(F("piezoSpeaker was pressed!"));
        // The Piezo Speaker light will play a beep for half a second, wait for another 500ms(half a second) and then play a tune
        piezoSpeaker.tone(400);                                                    // 1. plays a 400Hz beep. Change the value in the brackets (400) for a higher or lower beep.
        delay(500);                                                               // 2. keeps playing it for 500ms
        piezoSpeaker.off();                                                        // 3. stops the beep
        delay(500);                                                               // 4. waits 500ms                   
        piezoSpeaker.playMelody(HoorayLength, HoorayMelody, HoorayNoteDurations);  // 5. plays the Hurray melody. to play a different melody, modify HoorayLength, HoorayMelody and HoorayNoteDuration above.                    
        delay(500);                                                               // 4. waits 500ms
    }
    else if(strcmp(dweet.getValue() , "playGame") == 0)
    {
        Serial.println(F("Playing Game!"));
        while (!pir.read())
        {
          piezoSpeaker.playMelody(comeLength, comeMelody, comeNoteDurations);
          delay(500);
        }
        
        servo.attach(SERVO_PIN);
        servo.write(ServoTargetPosition);
        delay(1000);
        servo.write(ServoRestPosition);
        delay(1000);
        servo.detach();
        
        piezoSpeaker.playMelody(HoorayLength, HoorayMelody, HoorayNoteDurations);  // 5. plays the Hurray melody. to play a different melody, modify HoorayLength, HoorayMelody and HoorayNoteDuration above.                    
        
        delay(100);
    }
}

Credits

Jzbvk4go5lw68vtvbfe4
circuito.io team

Circuito.io is an online platform that generates wiring and code for Arduino projects. Want to know more? Visit http://circuito.io

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

Sigfox Forest Fire Detector
Intermediate
  • 999
  • 9

Full instructions

How to prevent forest from burning? A small Sigfox signal can prevent natural disasters. We will use an Arduino MKRFOX + a flame detector

Using Common Cathode and Common Anode RGB LED with Arduino
Intermediate
  • 735
  • 14

Protip

Common Cathode and Common Anode RGB LEDs are two different kinds of RGB LEDs whose function is same but working is different.

Wall Mounted Textile MP3 Player
Intermediate
  • 59
  • 2

MP3 Player with fabric user interface using Arduino LilyPad.

Arduino Word Clock
Intermediate
  • 468
  • 8

Full instructions

A clock that let you read the time, for real!

ssd1306 oled for ESP32 with Micropython
Intermediate
  • 47
  • 1

Protip

Control your oled screen using micropython for your esp32 board

DIY Complete Philips Hue Home Automation
Intermediate
  • 340
  • 3

Full instructions

This project emulates a Philips Hue Bridge that is able to control multiple types of lights.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog