WonEunghoChoi jiwonChoi jaeyoungkanginsu1
Created July 13, 2018

Kicking out annoying birds!

This program protect crops from annoying birds. Detect using ultrasonic, kick out using siren.

78
Kicking out annoying birds!

Things used in this project

Hardware components

WIZ750SR
WIZnet WIZ750SR
×1
WIZwiki-W7500
WIZnet WIZwiki-W7500
×1
Arduino Mega 2560
Arduino Mega 2560
×1
Servo Module (Generic)
×1
Buzzer
Buzzer
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Code

code for wiznet

C/C++
this code for wiznet. it get data from arduino, and send data to mqttbroker
#include "mbed.h"
#include "SPI.h"
#include "MQTTEthernet.h"
#include "MQTTClient.h"

#define ECHO_SERVER_PORT   7
 
Serial pc(USBTX, USBRX);   //Enabling the Serial transmission between WIZ750SR and PC.
Serial serial(D1,D0);      // Enabling Serial transmission betwenn Wiz750SR and W7500. 
char c[100]="";
char *temp="hi";
 
int main(void) {
    printf("Wait a second...\r\n");
//    char* topic = "Vending machine";
    MQTTEthernet ipstack = MQTTEthernet();
    
    MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack);
    
    char* hostname = "172.16.73.4";   //Give the IP Address of the MQTT Broker.
    int port = 1883;                  // Port number of the MQTT broker.  
    
 
    int rc = ipstack.connect(hostname, port);
    if (rc != 0)
        printf("rc from TCP connect is %d\n", rc);
 //   printf("Topic: %s\r\n",topic);
    
    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;       
    data.MQTTVersion = 3;
    data.clientID.cstring = "parents";

    if ((rc = client.connect(data)) == 0)
        printf("rc from MQTT connect is %d\n", rc);
 
   while (true) {
    if (serial.readable()) // if anything available/ readable in Serial port 
    {
        int i;
        c[i]=0;
        for(i=0;i<=1;i++){
        char c1 =serial.getc();
        c[i] = c1;
        i++; 
        } 
        pc.printf("The value returned is %s ",c);
     MQTT::Message message;
     char buf[100];
     //strcpy(c,);
     sprintf(buf, "%s", c);
     message.qos = MQTT::QOS0;
     message.retained = false;
     message.dup = false;

     message.payload = (void*)c;
     message.payloadlen = strlen(c);

     rc = client.publish("/cdilab/sensors/temperature", message);
   
     pc.printf("Rc result: %c \n ",rc);
     client.yield(60);
             }
}
}

code for arduino

Arduino
this detect birds using ultrasonic radar. And if detect, it send signal to wiznet
#include <SoftwareSerial.h>
#include <Servo.h>  
#define TRIG 2    
#define ECHO 3   
#define SERV 9
Servo servo;
int k=0;
SoftwareSerial mySerial(10, 11); // RX, TX
int oldD[180];
int newD[180];
int count,detect=0; 
int servoDirection = 1, rad = 0; 
int speakerpin = 12; //digital pin for buzzer
int birds=0;
void setup() {
  Serial.begin(9600);
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
  servo.attach(SERV); //pin for servo
  mySerial.begin(9600);
  pinMode(8,OUTPUT);
}
int compare(int oldD[],int newD[]){
    count=0;
    for(int i=0;i<180;i++){
      if(abs(oldD[i]-newD[i])>10)
        count++;
    }
    if(count>10)
      return 1;
      
     else
      return 0;
      
}
void alert(){
  digitalWrite(8,HIGH);
  delay(1000);
  digitalWrite(8,LOW);
}

void loop() {
//  Serial.print(size
  digitalWrite(TRIG, LOW);
  delayMicroseconds(2);  //stop for 2uS 
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);  //operate for 10uS
  digitalWrite(TRIG, LOW);
 
  
  long distance = pulseIn(ECHO, HIGH, 5800) / 58; 
  Serial.print("r");
  Serial.print(rad);
  Serial.print("d");
 Serial.println(distance);
 newD[rad]=distance;
 
  rad += servoDirection;
  if (rad > 180) {
    rad = 179;
    servoDirection = -1;
  }
  else if (rad < 0) {
    rad = 1;
    servoDirection = 1;
  }
  
  if((rad==1)&&(servoDirection==-1)){//every one cycle
     
      detect=compare(oldD,newD);
      
      
      if(detect==1){       
        if(birds!=0){
          Serial.println("bird");   
          mySerial.println(birds);     
          Serial.println(birds);
         
        }
      }
      
    
       for(int i=0;i<180;i++)
    Serial.print(oldD[i]);
  Serial.println(" ");
  for(int i=0;i<180;i++)
    Serial.print(newD[i]);
      memcpy(oldD,newD,sizeof(oldD));
  }
    
  servo.write(rad);
  delay(20); //delay for survo

  if(birds==0)
    birds++;
  if(detect==1){
  alert();
  }
  detect=0;
 
  
    
 }
 

code for openhab

Java
configure folder
No preview (download only).

Credits

WonEungho

WonEungho

1 project • 0 followers
Choi jiwon

Choi jiwon

0 projects • 0 followers
Choi jaeyoung

Choi jaeyoung

1 project • 0 followers
kanginsu1

kanginsu1

0 projects • 0 followers
Thanks to namgoocha.

Comments