Thursday 20 August 2015

Using Arduino to measure friction coefficient

As a sideproject I decided to design a simple experiment and use Arduino to measure the friction coefficient of an object sliding on a given material.

Ideally we would like our first object to slide (not roll) on a sheet of a given material as below:

im

If we know the angle (we can easily set it) and the mass of the wooden block, then the only unknown variable is the friction coefficient and we can easily estimate it by measuring how long it took for the block to go over a certain distance x.


By using two cheap laser pen pointers and two photoresistors we can build a simple timing device. Here is the basic sketch

im2

Now we only need to set up the circuit in the Arduino board, by the way Fritzing is great for Arduino visual schemes

im3

The basic idea is that when the light beam from the laser pointer to the photoresistor gets interrupted, Arduino knows that the wooden block has passed in front of our simple timing device. The first photoresistor starts to record time, the second one stops the counting.

Now we only need to write the Arduino code and Python code to read the measurements through the serial port of our computer.

The Arduino sketch goes as follows:

The Arduino scripts is engineered so that once the number of measurements to be done has been set the current sensor is turned off. Note that the number of measurement in the sketch must the same as the variable nSamples in the following Python script.

The Python script is based on the Arduino class I made previously. You can download it here, while the article where I talk about connecting with Arduino is here. This script uses an Arduino object through a measuring function that collects nSamples measurements. It is very important that the number of measurements to be made is the same both on the Python script and Arduino sketch. The script loops until it collects the measurements and then if save is equal to True, it saves the data into a .txt file. optionally you could improve this using Pandas and the df.to_csv() method. Since I wrote this before I learned about Pandas I will leave it as it is. However, better and more concise code can of course be written.

Hope this was inspiring.

2 comments: