Gyro Camera For Motorcycle Using Arduino
Gyro Camera For Motorcycle Using Arduino
As seen in MotoGP Race, the rider is seen riding through corners while laying aside his bike to the left and
right. But there is an interesting moment when the motor looks to collapse sideward, the front views remain
horizontally. How could that be?
Such onboard camera applies GYRO system, where the camera will be fixed perpendicular to the gravity of the
earth.
In this article, the module is Triple Axis Accelerometer & Gyro Breakout MPU-6050, which has 3-axis
gyroscope and 3-axis accelerometer in one chip, supplied by power of 3.3volt.
In addition to module MPU6050, the following similar modules could also be applied:
IMU Fusion Board ADXL345 & IMU3000
IMU Digital Combo Board 6 Degrees of Freedom ITG3200/ADXL345
Module MPU6050 with its tiny size of 20mm x 15mm and height of 1.6mm.
If you using different board than Arduino Uno R3, SCL and SDA pins of MPU are also different:
VDD : +3.3V
VIO : +3.3V
GND : GND
SDA : Pin A4 (Arduino Uno, Ethernet) / Pin 20 (Mega2560, Due) / Pin 2 (Leonardo)
SCL : Pin A5 (Arduino Uno, Ethernet) / Pin 21 (Mega2560, Due) / Pin 3 (Leonardo)
Step 2: PROGRAMMING
After having completely assembled, it is time now to upload the program to Arduino.
This circuit is only to drive servo in axis-X only. However, data from Axis Y and Z are still required for the
respective Gyroscope and Accelerometer. I tried to combine them by applying Kalman Filter calculation so as to
reduce noise output from Gyroscope + Accelerometer so that servo movement is smooth and no unwanted
movement.
CODE:
/*
Demonstrates auto-leveling Camera Video by using Gyro & Accelerometer with Arduino
The circuit:
by Firmansyah Saftari
www.saft7.com
http://www.saft7.com/
*/
#include <Servo.h>
Servo xservo;
#include <Wire.h>
#include "Kalman.h"
Kalman kalmanX;
Kalman kalmanY;
Control the position of a RC (hobby) servo motor with your Arduino and a
potentiometer.
Hardware Required
Arduino Board
(1) Servo Motor
(1) Potentiometer
hook-up wire
Circuit
Servo motors have three wires: power, ground, and signal. The power wire is
typically red, and should be connected to the 5V pin on the Arduino board. The
ground wire is typically black or brown and should be connected to a ground
pin on the Arduino board. The signal pin is typically yellow or orange and
should be connected to pin 9 on the Arduino board.
The potentiometer should be wired so that its two outer pins are connected to
power (+5V) and ground, and its middle pin is connected to analog input 0 on
the Arduino.
Schematic
Code
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
#include <Servo.h>
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
val = analogRead(potpin); // reads the value of the
potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo
(value between 0 and 180)
myservo.write(val); // sets the servo position according
to the scaled value
delay(15); // waits for the servo to get there
}
[Get Code]
See also
attach()
write()
map()
analogRead()
Servo library reference
Sweep - sweep the shaft of a servo motor back and forth.
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable pos
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable pos
delay(15); // waits 15ms for the servo to reach the position
}
}