In this post, we present a simple experimental setup for estimating the gravitational acceleration constant. The gravitational acceleration is estimated using a least-squares method. The data acquisition and computations are performed using a Raspberry Pi (RP) microcontroller. A video about this post is given below.
The working principle of the experimental setup is shown in Fig.1 below.
![](https://aleksandarhaber.com/wp-content/uploads/2019/06/working_principle-1024x923.jpg)
A (tennis) ball freely falls in a PVC pipe. The PVC pipe has ball openings and sensor mounts at prescribed heights ,
. At the bottom of the pipe, an InfraRed (IR) proximity sensor is mounted. We use OSOYOO low-cost IR proximity sensors whose specs can be found here. The sensor output is a digital signal (HIGH or LOW voltage) depending on the proximity of the object. Another IR proximity sensor is placed at prescribed heights
. Using an RP microcontroller we measure the time between the activations of the upper and lower sensors. This time, denoted by
, is approximately equal to the time it takes for the ball to fall from the height
.
The estimation problem can be formulated as follows. From the set of measurements , estimate the gravitational acceleration constant.
Next, we derive the equation of motion of the free-falling ball. The second Newton’s law governs the motion of the ball:
(1)
or
(2)
where
![Rendered by QuickLaTeX.com \vec{a}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-3b955d57f52c537ae0837fb60776ee05_l3.png)
![Rendered by QuickLaTeX.com z](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-4586e340cb83d5b642972e97a288fec2_l3.png)
![Rendered by QuickLaTeX.com g](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-d208fd391fa57c168dc0f151de829fee_l3.png)
![Rendered by QuickLaTeX.com z](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-4586e340cb83d5b642972e97a288fec2_l3.png)
(3)
By integrating this equation two times, and by taking into account the initial condition
![Rendered by QuickLaTeX.com \dot{z}(0)=0](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-f042f5bbbeb81b972835328b1b005015_l3.png)
![Rendered by QuickLaTeX.com z(0)=z_{i}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-cde771e7f1061257fd63a054a70b1170_l3.png)
(4)
where
![Rendered by QuickLaTeX.com t](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-b4e3cbf5d4c5c6d9b702dd139f14c147_l3.png)
![Rendered by QuickLaTeX.com t=t_{i}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-dbbf109a1f2a5732e6b70051e2314887_l3.png)
![Rendered by QuickLaTeX.com z(t_{i})=0](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-1959e48fdc1d83ba2c680b869860bd04_l3.png)
(5)
This equation can be used to form the least-squares problem for estimating the constant
![Rendered by QuickLaTeX.com g](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-d208fd391fa57c168dc0f151de829fee_l3.png)
(6)
where
![Rendered by QuickLaTeX.com \mathbf{z} \in \mathbb{R}^{n}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-37a917bd038caadd31b6f7934d032289_l3.png)
![Rendered by QuickLaTeX.com \mathbf{w} \in \mathbb{R}^{n}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-05462208a0483da7e454d3160af82242_l3.png)
![Rendered by QuickLaTeX.com t_{i}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-94d5f7b0dbdd44630705a73ad650c5fd_l3.png)
(7)
where
![Rendered by QuickLaTeX.com \mathbf{e}\in \mathbb{R}^{n}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-88429cfaec20cc723147b97d11083546_l3.png)
![Rendered by QuickLaTeX.com g](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-d208fd391fa57c168dc0f151de829fee_l3.png)
(8)
where denotes the 2-norm.
The solution is given by:
(9)
where
![Rendered by QuickLaTeX.com \big(\cdot \big)^{-1}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-13182bc04e9e56c56f50126ac0586374_l3.png)
![Rendered by QuickLaTeX.com \big(\cdot \big)^{T}](https://aleksandarhaber.com/wp-content/ql-cache/quicklatex.com-9d0b2b0eefd34d2e7ae9f2077067c960_l3.png)
The MATLAB code for calculating the g constant is given below.
g_true=9.80665;
data=[0.2 1 0.1539 0.171467;
0.4 2 0.250098 0.244594;
0.6 3 0.324306 0.320726;
0.8 4 0.383247 0.40603 ;
1 5 0.443352 0.437858;
1.2 6 0.493963 0.508561;
1.4 7 0.542227 0.542927;
1.6 8 0.577312 0.570544;
1.8 9 0.598127 0.603123;
2 10 0.664753 0.650943;];
w_est=data(:,3).^2/2;
w_val=data(:,4).^2/2;
z =data(:,1)+0.01;
g=inv(w_est'*w_est)*(w_est'*z)
error=((g_true-g)/g_true)*100
The estimation error is 0.5 %. Notice that on line 16 we added an additional centimeter to the height vector. This is has been done to take into account the fact that the sensors are placed 1cm below the point from which the ball falls (for more details see the video). The C/C++ code for obtaining the measurements is given below.
/*
/ Andrew Brennan
/ Nicholas Doherty
/ Prof. Aleksandar Haber, PhD
/ Verifying Earth's Gravitational Acceleration
/ CUNY College of Staten Island
/ 6/19/2019
/
*/
#include <wiringPi.h>
#include <iostream>
#include <ctime>
using namespace std;
int main(void)
{
clock_t startTime;
clock_t endTime;
double duration = 0;
int sensor_upper_pin = 0; // Set upper sensor pin.
int sensor_lower_pin = 2;// Set lower sensor pin.
int sensor_upper = 0;
int sensor_lower = 0;
int iteration_num = 0;
wiringPiSetup();
pinMode(sensor_upper_pin, INPUT); // Set upper sensor to input.
pinMode(sensor_lower_pin, INPUT); // Set lower sensor to input.
while(1)
{
sensor_upper = digitalRead(sensor_upper_pin); // Continually check upper sensor for input.
if (sensor_upper == 0) // When ball passes upper sensor,
{
startTime = clock(); // start clock.
sensor_lower = digitalRead(sensor_lower_pin); // Continually check lower sensor for input.
while (sensor_lower == 1) // While no input from lower sensor.
{
sensor_lower = digitalRead(sensor_lower_pin); // Do nothing.
}
endTime = clock(); // Stop clock when ball passes lower sensor.
duration = (endTime - startTime) / (double) CLOCKS_PER_SEC; // Calculate time difference between readings.
iteration_num++;
cout<<"\nIteration "<<iteration_num<<".\nTime between sensor detections: "<<duration<<" seconds."<<endl; // Output duration.
}
}
return 0;
}
The wiring diagram for one sensor is shown below. Notice that that the power pin of the sensor should be attached to the external power supply.
![](https://aleksandarhaber.com/wp-content/uploads/2019/06/diagram_bb-1024x656.jpg)