Akshayan Sinha
Published © MIT

Bird Feeder using IoT alert

Be it Bird or your pet, automate their meal time according to proper routine. And receive an alert whenever you need to refill the meal.

BeginnerFull instructions provided8 hours1,979
Bird Feeder using IoT alert

Things used in this project

Story

Read more

Schematics

Circuit Diagram

Code

BirdFeeder

Arduino
#include <Servo.h>

Servo servo;
int pos = 30;
int door, food;
int open = 0;
int val;

void setup() {
  pinMode(13, INPUT);
  
  servo.attach(9);
  Serial.begin(9600);
}

void exit(){
  int ret = 1;
  while (ret >=1){
    ret++;
  }
}

void loop() {
  door = digitalRead(13);
 
  servo.write(30);
 // Serial.println(door); 
    
  if (door == HIGH){
    for (pos = 30; pos >= 0; pos -= 2) 
    { 
      servo.write(pos); 
     // Serial.println(pos);               
      delay(15);                       
    }
    open++; 
    
    Serial.println(open);
    
    delay(500);
    for (pos = 0; pos <= 30; pos += 2) 
    { 
      servo.write(pos);  
     // Serial.println(pos);            
      delay(15);                       
    }
   // Serial.println(food);
    delay(5000);
  }
  
  
  if (open >= 15){
    exit();
    //Serial.println("detected");
    if (Serial.available()){
      Serial.println(open);
      //Serial.println("RF");
      exit();
    }
  }
}

Python Code for Wifi

Python
import sms_conf, bolt_conf
from boltiot import Sms, Bolt
import json, time, requests

mybolt = Bolt(bolt_conf.API_KEY, bolt_conf.DEVICE_ID)
sms = Sms(sms_conf.SID, sms_conf.AUTH_TOKEN, sms_conf.TO_NUMBER, sms_conf.FROM_NUMBER)

limit = 15

print ("...............")

print ("Bird-Feeder On")

print ("...............")
print(".")
print(".")
print("The door will open " +str(limit) + " times before sending Refill Alert")

responseA = mybolt.serialBegin('9600')

while True: 
    
    
    responseB = mybolt.serialRead('10') 
    dataB = json.loads(responseB) 

 #   print("Sensor value is: " + str(data['value']))
    try: 
        error = str(dataB['value'])
        

        if error != 'Command timed out' and len(error) != 0:
            door = int(dataB['value'])
            
            print(door)
            print(".")
            print(".")

            if door >= limit:
                    
                print("Time to Refill the Food")
                print(".")
                print(".")
                print("Total no. of openings = " + str(door))

                response_sms = sms.send_sms("Refill Bird Feeder Box !!  Total times opened - " + str(door))
                print("Response received from Twilio is: " + str(response_sms))
                print("Status of SMS at Twilio is :" + str(response_sms.status))

    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)        
    time.sleep(5)    

Credits

Akshayan Sinha

Akshayan Sinha

28 projects • 26 followers
Robotics Software Engineer with a makermind.

Comments