Introduction: GoPro Ultrasonic Motion Sensor HC-SR04 Controled by Arduino

Gopro activated by movement, the ultrasonic sensor move the servo when something appears close to the sensor, it can be programed to take pictures or video, and also it can be programed to stop taking pictures when there is no movement in the sensor.
Advantages over normal infrared motion sensors a.k.a. PIR, is that it can sense reptiles and insects, it can also log the distance of the object, and it haves a range of 4 meters.

Step 1: Get the Parts

Materials:

1 Arduino
1 Gopro or any other camera
1 Ultrasonic Motion Sensor HC-SR04
1 Servo
1 100uF/25V capacitor
1 breadboard
lots of rubberbands



Step 2: Build the Circuit

1 .- Attach the HC-SR04 to Arduino:
Arduino 5v Pin to Vcc Pin on HC-SR04
Arduino Pin 2 to Pin Echo on HC-SR04
Arduino Pin 3 to Pin Trig on HC-SR04
Arduino GND to Pin GND on HC-SR04

2.- Attach the Servo to Arduino:
Arduino 5v Pin to Servo Red Wire
Arduino GND to Servo Black Wire
Arduino Pin 9 to Servo Yellow(data) Wire
100uF/25V capacitor is optional, Attach one between the power and ground of your project to ensure smooth power delivery, remember that the colored line must be in the negative wire

3.- Attach the Servo to the GoPro
You can use as many rubberbands as necessary, the tip of the servo arm must touch the center of the GoPro Button, you can also construct your own attachment with wood, sintra, acrylic or metal once you tested everything.



Step 3: Upload the Code to Your Arduino

The code is simple if something is 50 cm near the sensor, it will activate the Servo, you can change it to a far or close distance as you wish, check also the angle of the servo, in this example the arm of the servo will move in a 40 Degree angle, you have to change it if you need more force to be applied to the GoPro camera button.

Code:

#include <Servo.h>
Servo myservo;
#define trigPin 3
#define echoPin 2

void setup(){
  myservo.attach(9);
  myservo.write(0);
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop(){
  int duration, distance;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(100);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  Serial.print(distance);
  Serial.println(" cm");
  int thisPitch = map(distance, 0, 200, 2093, 22);
  tone(4, thisPitch);
  delay(50);
  noTone(4);
  if (distance < 50) {    //Distance in cm
  myservo.write(40);       // angle of the servo arm
  delay (700);
  myservo.write(0);
  delay (2000);
  }
}

Step 4: Conclusion

Hope you like it, you can suggest better ways to attach the servo to the GoPro or improve the program.
Now you just need to go outdoors and take great wildlife videos or photos or capture at last what kind of critter is stealing the dog food in your backyard.