Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Patrick Jackson
Published © GPL3+

Automated Bird Feeder

Feeds and records local bird populations.

BeginnerWork in progress5 hours72
Automated Bird Feeder

Things used in this project

Hardware components

SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Photon
Particle Photon
×1
S40 ST High Accuracy Thin Kraftsensor Pressure Sensor Pad Film Pressure Sensor Force Sensor for Intelligent High End Seat
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Alligator Clips
Alligator Clips
×1
Resistor 1k ohm
Resistor 1k ohm
×1

Software apps and online services

Google Sheets
Google Sheets
Particle Build Web IDE
Particle Build Web IDE
Serial Monitor

Story

Read more

Schematics

Force Sensor Circuit

For taking input from the force sensor.

Final Circuit

Controls Servo motor in addition to taking sensor input.

Code

Spreadsheet Test

JavaScript
Formats the data in a google sheet.
  function test() {
  var e = {};
  e.parameter = {};
  e.parameter.event = 'sheetTest1';
  e.parameter.data = '[1,1234]';
  e.parameter.coreid = '1f0030001647ffffffffffff';
  e.parameter.published_at = new Date().toISOString();
  doPost(e);
}

function doPost(e) {
  // e.parameter.event
  // e.parameter.data
  // e.parameter.coreid
  // e.parameter.published_at "2016-04-16T13:37:08.728Z"

  var publishedAt = new Date(e.parameter.published_at);

  var dataArray = [];
  try {
    dataArray = JSON.parse(e.parameter.data);
  }
  catch(e) {
  }

  var sheet = SpreadsheetApp.getActiveSheet();

  var row = [e.parameter.coreid, publishedAt];

  row = row.concat(dataArray);

  sheet.appendRow(row);

  var result = {};
  result.ok = true;

  return ContentService.createTextOutput(JSON.stringify(result))
    .setMimeType(ContentService.MimeType.JSON);
}

Main Program

C/C++
This includes the code for each of the functions which trigger the webhooks. It also includes the main program which is responsible for controlling the function of the bird feeder.
// This #include statement was automatically added by the Particle IDE.

#include "Particle.h"

SYSTEM_THREAD(ENABLED);

SerialLogHandler logHandler;


Servo myServo; //declares servo object

// How often to publish a value
const std::chrono::milliseconds publishPeriod = 30s;

// The event name to publish with
const char *eventName = "sheetTest1";



unsigned long lastPublish; 

int squirrel = 0; // Initial population of squirrels, cardinals, and sparrows
int cardinal = 0;
int sparrow = 0;
int fsrPin = A1; // Designates which pin reads the force sensor's output
int fsrReading; // The value which is output by the force sensor
int servoPosI = 90; // Initial position of the servo
int servoPosF = 45; // Final position of the servo

void publishTest(); //These methods trigger the webhooks
void publishTest1();
void publishTest2();

void setup() {
     Serial.begin(9600); //Initializes Serial Monitor 
   
    pinMode(fsrPin,INPUT); // Designates fsrPin as an INPUT
   
    myServo.attach(1); // Connects the servo to the Pulse with Modulation Pin located at Pin 1
    myServo.write(servoPosI); // Sets Servo to its initial position
    
    
}

void loop() {
    
     fsrReading = analogRead(fsrPin); 
     
     Serial.println("Analog reading = " + String(fsrReading));
        delay(1000); // Prints sensor reading to serial monitor 
     

              if(fsrReading>50){ // Condition for when a squirrel or animal larger than a squirrel or sparrow steps on the sensor 
                publishTest();
                delay(3000);
              }
                
              if(fsrReading>40 && fsrReading<=50){ // Condition for when a cardinal steps on the sensor 
                publishTest1();
                     myServo.write(servoPosI);
                delay(1000);
                     myServo.write(servoPosF);
                delay(3000);
              }
              
            if(fsrReading>35 && fsrReading<=40){ // Condition for when a sparrow steps on the sensor 
                publishTest2();
                    myServo.write(servoPosI);
                delay(1000);
                    myServo.write(servoPosF);
                delay(3000);
              }
 
}

void publishTest() { // publishes the value [squirrel,103] to the spreadsheet, recording a squirrel or larger mammal
    char buf[128];

    snprintf(buf, sizeof(buf), "[%d,%d]", ++squirrel, 103);

    Particle.publish(eventName, buf, PRIVATE);
    Log.info("published: %s", buf);
}  

void publishTest1(){ // publishes the value [cardinal,102] to the spreadsheet, recording a cardinal 
        char buf[128];

    snprintf(buf, sizeof(buf), "[%d,%d]", ++cardinal, 102);

    Particle.publish(eventName, buf, PRIVATE);
    Log.info("published: %s", buf);
    
}

void publishTest2(){ // publishes the value [sparrow,101] to the spreadsheet, recording a sparrow
         char buf[128];

    snprintf(buf, sizeof(buf), "[%d,%d]", ++sparrow, 101);

    Particle.publish(eventName, buf, PRIVATE);
    Log.info("published: %s", buf);   
}

Credits

Patrick Jackson
2 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.