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.

Siegel's Home Page

Physics Department| College of Science