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

Picture of 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

Picture of 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

Picture of 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

Picture of 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.


Comments

tndog (author)2016-07-26

Nice work.


I used one of these GoPro motion detector sensors from CamDo which uses X-band microwave range waves and the doppler effect. Range is decent and goes through a plastic box so can be mounted in a protective enclosure. More reliable than PIR for my application and you can turn sensitivity up/down.

kelvinator11 (author)2015-08-19

please help me with the code if i want to add a buzzer and an LED

seaf20 (author)2014-01-11

question... how do I go about changing some parameters like... instead of meassuring in cm i'd like the sensor to read in ft

animes25 (author)seaf202014-01-13

ft = cm * 0.032808

I guess you have to change the serial print lines to:

Serial.print(distance*0.32808);
Serial.println(" ft");

please tell me if it works :D

About This Instructable

31,126views

82favorites

License:

More by animes25:Arduino Portable Weather Monitor, altimeter, temperature, humidity, using DHT11 and BMP85 with LCD using only 3 pinsGoPro Ultrasonic Motion Sensor HC-SR04 controled by arduinoFull Color electroluminescent decals with El Panel
Add instructable to: