Hi guys in tutorial we are going to measure gravity with arduino. We are also measuring free fall time and free fall velocity. So lets get started.

For making this project you will need,

  1. Arduino,
  2. 2 IR sensor,
  3. LCD display 16X2,
  4. I2C,
  5. Breadboard,
  6. Jumper Wire.

This is simple project, we are measuring the free fall time and for measuring free fall time, we are using two IR sensor. In simple language, First sensor will start the timer and second sensor will stop the timer. And putting this value in a free fall formula, we will get gravity and free fall velocity.

Free fall without air resistance

h – Free fall distance

t- Free fall time

v- Free fall velocity

g- gravity

Do connection as shown in diagram.

How to measure gravity circuit diagram

Things to consider before making this project:

Before making this project I want to tell you something. Which cause error in reading if you don’t take consideration. These are the things to avoid errors or get less errors.

1. You have to take white colour box. Because we are using IR sensor it works best with white colour.

2. Minus the length of box in free fall height, for example we are dropping object from one meter and box length is 4 cm then effective height will be 0.96 meter. I will explain more this in code.

Effective free fall distance

3. Your second sensor should be at ground level. Not in middle of air because when object is falling it get around 5.5 m/s velocity for 1.5 meter height and sensor unable to detect it. Even if it detects it will not be processed by Arduino because it was detected just for a few millisecond till Arduino recognize this it is too late and object has already passed. You can try this.

4. Accuracy can be increase by increasing free fall distance. As Arduino timer and sensor has its own limitation. I would recommend, take height at least 1 meter.

5. make sure when you drop the object, you hold it from tip and don’t push it. Simply drop it. Otherwise you may have some error in reading.

6. Object should drop in a straight manner. It should not swing when it is falling. You may get errors if it wings.

7. I am using free fall formula without air resistance. Because it will make too complex for Arduino to consider air resistance. So expect some errors in reading.

free fall with and without air resistance

Now I am dropping object from 1 meter. You can see the readings with some error.

gravity measurement 1 meter test

Now I have increased the height to 1.5 meter. Now error is less. If we increase the distance it will reduce errors.

gravity measurement 1.5 meter test.jpg

Why it is not prefect?

There are four main reason for this error.

1. Arduino timer, because few millisecond delay in response can reflect an error in gravity.

2. IR sensor, because it takes few millisecond to detect. That millisecond is not counted by Arduino. I tried same project with ultrasonic sensor but it was really worse to detect a falling object at such a high speed.

3. Simply drop the object don’t exert slightest force.

4. There is one more reason it is not considering air resistance.

Sketch for gravity measurement:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x3F for a 16 chars and 2 line display // note: it may be different for your LCD please find it.
LiquidCrystal_I2C lcd(0x3F, 16, 2);
const int IR_Sensor1=2;
const int IR_Sensor2=7;
double startMillis; 
double endMillis;
double free_fall_time;
double h = 1.41; 
double g,v;
int activate=0;

void setup() { 

//Pin 2 is connected to the output of proximity sensor
pinMode(IR_Sensor1,INPUT);
pinMode(IR_Sensor2,INPUT);
// initialize the LCD
lcd.begin();
lcd.setCursor(0, 0);
lcd.print("T:");
lcd.setCursor(8, 0);
lcd.print("V:");
lcd.setCursor(0, 1);
lcd.print("Gravity:");
}

void loop() {
if(digitalRead(IR_Sensor1)==LOW) //Check the sensor output
{
//lcd.clear();
startMillis = millis(); 
activate=0;
}
if(digitalRead(IR_Sensor2)==LOW) //Check the sensor output
if (activate==0){
{
endMillis = millis(); 
free_fall_time = (endMillis-startMillis)/1000;
lcd.setCursor(2, 0);
lcd.print(free_fall_time);
lcd.setCursor(6, 0);
lcd.print("s");
g = 2*h/pow(free_fall_time, 2); // gravity
v = g*free_fall_time; // free fall velocity
lcd.setCursor(10, 0);
lcd.print(v);
lcd.setCursor(13, 0);
lcd.print("m/s");
lcd.setCursor(8, 1);
lcd.print(g);
lcd.setCursor(12, 1);
lcd.print("m/s2");
activate=1;
}
} 
}
Explanation:

Lets come to the programming part.

Add I2C library.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

If you dont know how to connect I2C with LCD you can see my previous tutorial on how to connect LCD with I2C.

Define pin numbers for IR sensor1 and Sensor2.

const int IR_Sensor1=2;
const int IR_Sensor2=7;

Storing a variables in double as we want precision in our calculation.

double startMillis;
double endMillis;
double finalMillis;
double h = 1.46;
double g,v;

When code is uploaded. By default it will show time, velocity and gravity on LCD.

lcd.setCursor(0, 0);
lcd.print("T:");
lcd.setCursor(8, 0);
lcd.print("V:");
lcd.setCursor(0, 1);
lcd.print("Gravity:");

by default screen of lcd

When sensor one detected object it will start counting time. And store time in millisecond in startMillis. It is constantly counting time until object is in front of the sensor.

startMillis = millis();

That is the main reason we are subtracting box length from the free fall distance. We are subtracting only for first sensor not for second sensor. As falling from such a height it already got 5.5m/s speed until second sensor recognize box. It already passed that distance. So no need to subtract for second sensor.

We want second sensor should only read one reading when it is detected. So by using this activate make sure second sensor only read one time. When object pass from second sensor it will make activate to 1. So it is like locking the reading of second sensor. Even object is constantly in front of sensor 2 it will not count that time.

Activate=0;

When second sensor detects object it will note down the time in endMillis.

endMillis = millis();

and rest of code is pretty simple. We are doing some math here to get free fall time.

free_fall_time = (endMillis-startMillis)/1000;

And applying formula for free fall without air resistance to get gravity and free fall velocity.

g = 2*h/pow(free_fall_time, 2); // gravity
v = g*free_fall_time; // free fall velocity

This lcd print will print the values to the lcd.

lcd.setCursor(10, 0);
lcd.print(v);
lcd.setCursor(13, 0);
lcd.print("m/s");
lcd.setCursor(8, 1);
lcd.print(g);
lcd.setCursor(12, 1);
lcd.print("m/s2");

Before coming out of the loop it will make activate equal to one. So that it will prevent second sensor to count it endMillis again.

 activate=1;

It must pass from the sensor one again to count the time on second sensor.

I hope you will like my effort. Let me know how it is working for you.

Till then keep learning keep making.