Doing an experiment with the BMP085 pressure-temperature-altitude sensor

 Let's put together the reading of the BMP085 sensor and the writing of data to the SD card. We'll start from an Arduino program shown below that has already put the two pieces together. Upload this program to the Arduino and check that it is saving data to the SD card.


To make sure you have some understanding of the program, see if you can

  • Change the filename that is saved to "your initials.csv". The .csv will be recognized by Microsoft Excel for easy opening and analysis.
  • Add column headings to the file that are pressure, temperature, altitude
  • Add a delay so that it records data every 5 seconds.
  • Determine the units of each measurement (PTH).

Next, go outside and determine a method for estimating the height of the building. Write a procedure for this estimate that is clear such that someone else could use the procedure and repeat your estimation.

Now, add a breadboard power supply. The power actually comes from a 9 volt battery that connects to this, which regulates the power to be appropriate for the Arduino.

5V and 3.3V breadboard power supply.

With everything connected walk up the stairs from the first floor to the top floor and back to the lab. Remove the SD card and save your data to the computer in the lab. In Excel, determine how high the top floor is. How does it compare to your estimation? Your data should look something like the graph below if you plot it.

Altitude vs. time of walking from basement to observatory in the Berea Science Building.

Come up with a method for determining the uncertainty of your estimate. Does this uncertainty give agreement between your estimation and the measurement. Explain in some detail how this process could be improved to get better agreement.

Measuring Pressure, Temperature, and Altitude

 This is a big one! The Arduino is going to do some heavy lifting for us. We are going to program a pressure, temperature, and altitude sensor (all-in-one). We'll check that it works. Then, we'll program an SD card adapter and make sure we can send data to a file on the SD card. Finally, we'll put the two together and power the Arduino with a battery so we can do some portable data collection.

The PTH (pressure, temperature, height) sensor is the Adafruit BMP180. It is shown below. It communicates through a protocol called I2C (Inter-Integrated Circuit). While it is good to understand these protocols, we can get away with knowing almost nothing since libraries have already been written to work with this sensor. To begin, in Arduino open from the sketchbook a program called BMP085 (see below). We'll go over the code together in lab and see that we know how to identify key features for getting data from the sensor.

The BMP180 pressure/temperature/altitude sensor from Adafruit.


To wire the sensor, look at the diagram below. Make sure your Arduino is NOT connected to the computer while wiring the sensor. Let the TA or instructor verify your connections before connecting the Arduino to the computer through USB.

Connections of the BMP180 to the Arduino.


Upload the code to the Arduino and use the Serial Monitor to read the sensor output. Does it appear to work as you would expect? How might you test it for altitude? e.g., what is the altitude of Berea, KY above sea level? How might you test it for temperature? Try it.

Before we move on to the SD card, let's make sure we know how to create some data that looks like something we know. Open a new Arduino sketch and save it as SineWave-yourinitials. We'll write a program to create a sine function \(y=\sin\omega t\). First, we need to declare some variables to store the time and the y value. Note that in Arduino, "time" is a protected keyword, and we cannot use it to store the time. Both of these values need to be decimal numbers. In Arduino, this is declared as "float".

float ts=0, yt;
void setup(){ 
... 
}
We want to start the time at zero seconds. So it is initialized above. I call it "ts" for time in seconds. I call the function value "yt" for y as a function of t. Notice this declaration is before the setup, making these variables global to the entire program. In the loop we want to get the value of time using the millis() function. Convert this to seconds by dividing it by 1000.0. Once we have the time we can calculate the sine value. In Arduino "sin" is a known function and expects radians in its argument.
yt = sin(6.28*ts);

Finally, we need to write these values to the serial port. This requires beginning serial communication in the setup.

Serial.begin(9600);

Then, it requires writing the values to the serial port in the loop after they have been calculated.

Serial.print(ts);
Serial.print(", ");
Serial.println(yt);

Test that this works by uploading it to the Arduino and seeing what happens in the Serial Monitor. Copy and past some of the data into Excel and make a graph of it. Does it look like you expect?

Now that the sensor is working and we know how to create known data, let's try to save information to an SD card. We are going to use the Catalex MicroSD Card Adapter. An pin diagram is shown below.

This device communicates through what is called SPI (Serial Peripheral Interface). Similarly, we don't have to know exactly how this works at this point as long as we can use existing libraries. Wire the adapter as described. NOTE: The pins on your adapter are not in the same order as the image shown below. Read the connection table in the figure below. Disconnect your Arduino before making connections. Let a TA or instructor see your connections before powering the Arduino with the USB cable.
Wire connections for the SD Card adapter.


In the Arduino software, open the sketch SD_card_write (see below). We will discuss features of the program together in lab. Afterward, see if you can create a way to store the values of \(\sin \omega t\) where \(\omega = 2\pi\) and time is calculated using the Arduino function "millis()". Store the value in decimal variable (float) and write the time and sine wave values to a file on the SD card. Make the filename "sinewavedata.txt". Remove the SD card and use Excel to plot the data in the file.

Measuring the acceleration of a fan cart

 Let's look at some more complex motion with our motion sensor. We will measure the motion of a cart driven by a fan. The arrangement is shown below.

Fan Cart Setup
We are going to add one more level of complexity to our measurement. We want to get an accurate time measurement instead of assuming the time increases by the delay time. To do this we will use a function called "millis" on the Arduino. We can keep track of time and position by reporting both to the serial port using something like the following lines of code.
Serial.print(millis()*1000);
Serial.print(",");
Serial.println(distance);

In this example, the first line of code prints the time in milliseconds multiplied by 1000 to convert to seconds. This line will not put a carriage return since it has

print
rather than
println
The second line prints a comma, and the third line prints the distance with a carriage return. The distance should be your calibrated distance from previous lab work. The third line will insert a carriage return so that the next values that go to the serial port are on a new line.

Now we are ready to measure the motion. Place the cart on the track so that it moves away from the motion sensor.  Using the switch on the Arduino, start the cart moving by turning on the fan and measure the motion of the cart while it is moving freely between the track ends. Be sure the Serial Monitor is open so you can copy the time and position data after the measurement ends.

Copy and paste the data into Microsoft Excel. Make a graph of the data (be sure to label the graph axes). Add a polynomial trendline to the graph, and use it to determine the initial position, initial velocity, and acceleration. Recall \( x_f = x_i +v_i t + \frac{1}{2}at^2 \)is related to the trendline \( y=c+bx+ax^2 \)

Fan Cart Data


Have the cart move toward the motion sensor to determine whether the acceleration is the same magnitude but opposite direction. If you feel like the measurement of acceleration is reproducible, try adding mass to the cart and measuring the acceleration again. Repeat this for one more addition of mass.  Be sure to keep the mass in the middle of the cart so that it doesn't have more mass on one side of it.

When you have three masses measured, make a graph in Excel of acceleration (y-axis) vs. mass (x-axis). How do the two values appear to be related (linear, quadratic, hyperbolic)? Try adding a "power law" trendline to determine the dependence. Sir Isaac Newton said that force is mass times acceleration. \( F=ma \). Assuming the fan exerts a constant force because it always blows air in the same way, we can assume the force is some constant number. Rearranging the equation \( a=F/m \). Does this agree with your graph trendline? Explain. What is the force the fan exerts?