Arduino Microcontroller Projects

Below I list some projects for the Arduino microcontrollers that can be used in a Physics or Engineering laboratory as well as projects for the hobbiest.

Measuring an objects acceleration and storing the data

In this project we use the Arduino Nano
and the MPU-6050 accelerometer.
The Arduino Nano receives the data from
the accelerometer via the I2C
SDA and SCL pins.
The wire connections are very
simple as shown in the figure on the right:
To program the Arduino and read the output, we use a Raspberry Pi. The Arduino Nano is programmed with the code: Accelnano.ino
using the Arduino IDE software. The serial monitor is set to ttyUSB0, which writes the data on the Raspberry Pi to the dev file: /dev/ttyUSB0. The data sent to ttyUSB0 are the byte values from the accelerometer registers. The byte values are read by the c code: usb0read.c .

After reading the byte values, the code calculates the x-, y-, and z- components of the acceleration in units of cm/s2.

Sending Data from the Arduino Nano via Bluetooth

In this project we check the bluetooth function
of the Arduino Nano. The bluetooth module HC-05,
or HC-06 is connected to the Nano as shown in
the figure on the right. We use pin D2 to transmit
the data from the Nano, which is connected to the
RX pin of the HC-05. Pin D3 would receive data
from the HC-05 and is connected to the TX pin of
the HC-05. The 1K and 2K Ohm resisters serve as
a voltage divider, since the RX pin of the HC-05 can
only handle 3.3 Volts. The voltage on the digital pins
on the Nano are 0 or 5 volts. The battery connected to
VIN consists of four AA batteries yielding 6 volts. A
voltage converter in the Nano reduces this value to 5 volts
for the Nano's operating voltage.
To program the Arduino for testing the bluetooth interface, we use a Raspberry Pi. The Arduino Nano is programmed with the code: BTexample.ino
using the Arduino IDE software. The unsigned char variable "nbyte" is incremented by one and sent to the bluetooth module. This byte is sent out via serial bluetooth. The byte is recieved and read by the Raspberry Pi from the dev file /dev/rfcomm0 using the C code: rfcommserial0.c.

Accelerometer using the Arduino Nano and
Bluetooth data transfer

In this project we use the Arduino Nano
with the MPU-6050 accelerometer and the
HC-06 (or HC-05) bluetooth module to measure
acceleration and transfer the data via bluetooth.
The Arduino Nano receives the data from
the accelerometer via the I2C
SDA and SCL pins. The bluetooth module HC-05,
or HC-06 is connected to the Nano as shown in
the figure on the right. We use pin D2 to transmit
the data from the Nano, which is connected to the
RX pin of the HC-05. Pin D3 would receive data
from the HC-05 and is connected to the TX pin of
the HC-05. The 1K and 2K Ohm resisters serve as
a voltage divider, since the RX pin of the HC-05 can
only handle 3.3 Volts. The voltage on the digital pins
on the Nano are 0 or 5 volts. The battery connected to
VIN consists of four AA batteries yielding 6 volts. A
voltage converter in the Nano reduces this value to 5 volts
for the Nano's operating voltage.

To program the Arduino and read the output, we use a Raspberry Pi. The Arduino Nano is programmed with the code: BTaccel.ino
using the Arduino IDE software. The six byte values for ax, ay and az are sent to the bluetooth module via serial bluetooth. The bytes are received and read by the Raspberry Pi from the dev file /dev/rfcomm0 using the C code: BTaccelread.c.

After reading the byte values, the code calculates the x-, y-, and z- components of the acceleration in units of cm/s2.

Sample code for fast timing

Often is it desirable to measure time or time intervals with high precision. The Arduino program Timertest.ino is a templet which shows how to count the processor clock cycles. We use the timer1 function, which increases the unsigned int TCNT1 by one unit. The rate of increase is determined by the set prescaler. We set up the timer1 overflow interupt, ISR(TIMER1_OVF_vect). Once TCNT1 is increased from 65535 to 65536 (causing an overflow), the overflow interrupt function is executed and TCNT1 returns to 0. For every overflow of TCNT1, the unsigned int tim1 is increased by one. Once tim1 is increased from 65535 to 65536 (causing it to overflow), then the unsigned int tim2 is increased by one.

The overflow interrupt therefore produces two unsigned int variables tim1 and tim2. These two variables along with TCNT1 yield a 48 bit counter that increases at the rate set by the prescaler. in Timertest.ino we have set the prescaler to 1, TCCR1B |= (1 << CS10);. With the prescaler set at 1, TCNT1 increases at a rate of 16X106 times per second. The three 16 bit numbers (tim2, tim1, and TCNT1) are each separated into their bytes (t0, t1, t2, t3, t4, and t5) and sent via serial to be re-combined for an accurate time stamp. One can reduce the timing rate by changing the prescaler. If the prescaler is changed, then one might need fewer bytes for the timing.

Measuring Speed versus Time using a Laser Gate

In this project we use the Arduino Nano
with a laser and a photodiode. The Nano detects
when the photodiode is blocked and unblocked from
the laser light. The nano then sends the time
data via the usb connector to a computer. The
blocking time data is read from the device file
ttyUSB0 via a C program or one written in nodeJS.
When the laser light is incident on the photodetector,
the detector's resistance is low, around 600 Ohms.
When the light is blocked, the resistance of the
photodetector is high, around 4000 Ohms. A pull-up
resistor of 2000 Ohms is in series with the detector,
so that when the light is incident on the detector
pin 8 reads LOW. When the laser light is blocked, pin
8 reads HIGH. A red led is connected to pin 7 to show
if the detector is unblocked or blocked.
The pin diagram is shown in the figure to the right.
The figure below is a picture of a proto-board setup:

To program the Arduino and read the output, we use a Raspberry Pi. The Arduino Nano is programmed with the code: Lasergate.ino
using the Arduino IDE software.

We use two different programs to record and analyze the data. Two in C: tandvfly_arduino.c and conaccfly_arduino.c, and the corresponding two in nodejs: tandv_arduino.js and conacc_arduino.js. For the program starting with tandv, one inputs the number of blocks and the effective thickness of the blocking tabs. The program starting with conacc can be used if one knows that the motion of one of constant acceleration. Links to the four codes are:

Each of the above programs reads the data from the arduino nano via the device file ttyUSB0, found in the linux dev directory. The C programs can be programmed in linux using gcc. We have also made a boot image, which uses Puppy Linux, and can be used in a 64 bit Windows or Linux operating system. Just "burn" the image file lasergate64_arduino.iso to a CD or usb flash drive. Then, set the boot order to start with the lasergate64_arduino.iso. To run the tandv or conacc programs, just right-click on the icon and "run in terminal". We use the boot-CD in our laboratory classes.

Laser Gate programs for Pendulum Project

The arduino code Pendgate.ino is loaded into an arduino nano. The output is read by the c code pend_kbhit_40.c . The Laser Gate for the Pendulum project works the same way as the speed versus time Laser Gate except the c code Pend_kbhit_40.c will continue to take data until the laser gate is blocked for more than 10 seconds. To use the software, set the pendulum swinging and start collecting data. Let the pendulum swing as long as you want. When you want the data collection to stop, first block the gate for more than 10 seconds, then unblock the gate. Data collection will stop and you can save your time versus speed data.

Siegel's Home Page

Physics Department| College of Science