Hello and thank you!
I have a gyro and I am getting nonsensical values. It is the first time I've used one so I want to make sure I'm not doing anything wrong. But I followed guides, tutorials and datasheets to the letter.
Here is the sensor: https://solarbotics.com/product/50815/
Here is my code:
/* Keep track of gyro angle over time
* Connect Gyro to Analog Pin 0
*
* Sketch by eric barch / ericbarch.com
* v. 0.1 - simple serial output
*
*/
int gyroPin = 14; //Gyro is connected to analog pin A0
float gyroVoltage = 5.0; //Gyro is running at 5V
float gyroZeroVoltage = 1.35; //Gyro is zeroed at 1.35V
float gyroSensitivity = .002; //Our example gyro is 2mV/deg/sec
float rotationThreshold = 1.00; //Minimum deg/sec to keep track of - helps with gyro drifting
float currentAngle = 0; //Keep track of our current angle
void setup() {
Serial.begin (9600);
}
void loop() {
//This line converts the 0-1023 signal to 0-5V
float gyroRate = (analogRead(gyroPin) * gyroVoltage) / 1023;
//This line finds the voltage offset from sitting still
gyroRate -= gyroZeroVoltage;
//This line divides the voltage we found by the gyro's sensitivity
gyroRate /= gyroSensitivity;
//Ignore the gyro if our angular velocity does not meet our threshold
if (gyroRate >= rotationThreshold || gyroRate <= -rotationThreshold) {
//This line divides the value by 100 since we are running in a 10ms loop (1000ms/10ms)
gyroRate /= 100;
currentAngle += gyroRate;
}
//Keep our angle between 0-359 degrees
if (currentAngle < 0)
currentAngle += 360;
else if (currentAngle > 359)
currentAngle -= 360;
//DEBUG
Serial.println(currentAngle);
delay(10);
}
As for the hardware,
I have my Vin on the gyro connected to 5V output on the arduino
Y-OUT connected to A0
GND connected to GND
What happens is it starts at 360 and goes all the way down to 0 and then goes to 360 again. And my moving the gyro around doesn't do anything to increase the rate or decrease it or anything really.
Am I doing anything wrong??