Skip to content

Instantly share code, notes, and snippets.

@dattasaurabh82
Created January 27, 2015 11:24
Show Gist options
  • Save dattasaurabh82/8b96640f9dac206b16f0 to your computer and use it in GitHub Desktop.
Save dattasaurabh82/8b96640f9dac206b16f0 to your computer and use it in GitHub Desktop.
Simple code (untested ver) for the camera mount control
/*
This code will enable auto claibration of light sensors.
After uploading the code when you switch on the Arduino, within 10 seconds:
For the base senosr:
Bgring the sensor to a hole , so that it can see the light followed by covering it so that it can see dark. Do it couple of times with in 10 secs
so that the microcontroller knows and what is the value to reffer to when it sees light and adrk again .
For the falsh sensor, do the same:
With in the same 10 sec time frame, flash few times the goPro so that the sensor knows what the value should be for flashing and would use it later
Also keep them without flashing so that the sensor knows what is the value for dark..
*/
#include <Servo.h>
Servo myservo;
int servoPin = 3;
//cross check with the sensor Pin values
//by simple analog read example
int baseSensor = A4;
int flashSensor = A5;
int baseSensorVal, flashSensorVal;
//Basic initial value setting for calibrartion
//I set it up based on what value I saw through
//the simple analog REad example
// you might need to chnge these value(and you need
//to only once) after you set up there on spot
int baseSenosrMin = 1200;
int baseSenosrMax = 0;
int flashSensorMin = 1200;
int flashSenosrMax = 0;
void setup()
{
Serial.begin(9600);
//claibration setup at the begining of firing the Arduino
// The ones I was talking at the begining
while (millis() < 10000){
long start = millis();
baseSensorVal = analogRead(baseSensor);
flashSensorVal = analogRead(flashSensor);
if(baseSensorVal > baseSenosrMax){
baseSenosrMax = baseSensorVal;
}
if(flashSensorVal > flashSenosrMax){
flashSenosrMax = flashSensorVal;
}
if(baseSensorVal < baseSenosrMin){
baseSenosrMin = baseSensorVal
}
if(flashSensorVal < flashSenosrMin){
flashSenosrMin = flashSensorVal
}
}
}
void loop() {
baseSensorVal = analogRead(baseSensor);
flashSensorVal = analogRead(flashSensor);
if ((flashSensorVal >= flashSenosrMax) && (baseSensorval >= baseSenosrMax)){
myservo.attach(servoPin);
myservo.write(120);
}
else if ((flashSensorVal >= flashSenosrMax) && (baseSensorval <= baseSenosrMax)){
myservo.attach(servoPin);
myservo.write(120);
}
else if ((flashSensorVal <= flashSenosrMax) && (baseSensorval >= baseSenosrMax)){
myservo.detach();
}
else if ((flashSensorVal <= flashSenosrMax) && (baseSensorval <= baseSenosrMax)){
myservo.detach();
}
else{
myservo.detach();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment