Skip navigation

Bluetooth Instrument Datalogger

Posted by rsc Mar 28, 2016




The standard for transfer of digital data from instrumentation for many years has been RS232. Very few computers and laptops are currently manufactured with RS232 interfaces. To interface with these instruments, USB adapters can be used, or older computers can be retained in the lab for specific instrument use. This can cause problems for researchers with software compatibility and network interfacing. The Bluetooth ® wireless technology has been around since 1994 and can be used to interface with these instruments. This paper describes a method to interface a R. M. Young model 81000 ultrasonic anemometer to a small Arduino ® (Atmel) microprocessor via Bluetooth, and logging the digital data directly to a micro-SD non-volatile memory card. A real-time clock (RTC) is included to add a timestamp to the data stream.

Hardware – Instrument Transmitter

  The ultrasonic anemometer is powered by an external DC power supply from 12 to 30 volts.The Bluetooth interface requires a 5VDC power supply.A circuit board was built with a 5VDC regulator to utilize the same power supply as the anemometer.Two other circuits are required on the instrument side, a RS232 voltage level shifter, and the Bluetooth RF module.Bluetooth modules have different output levels for specific applications, a Class-1 module was chosen for this project for maximum distance (20m-30m).The circuit board for the instrument transmitter is shown in figure 1.


The Bluetooth module was designed by SparkFun electronics (WRL-12580) as a simple streaming modem, and is capable of baud rates up to 115200bps. The inputs to the module are TTL Rx, Tx, and 3.3 to 6 VDC.The module can be programmed for master or slave operation, and can be bound to a specific module, or can pair to the first device it finds.The RS232 level shifter for this project is also from SparkFun electronics (PRT-08780) and interfaces the Bluetooth module TTL Rx and Tx pins to the RS232 level pins of the instrument.The schematic for the instrument side wiring is shown in figure 2.


The physical connections to the R.M. Young 81000 anemometer are shown in figure 3.Pins used are +PWR (12VDC), PWR REF(GND), Tx-O, RX-I, and SREF(GND).


Hardware – Bluetooth DataLogger

The datalogger circuit was built by combining four off-the-shelf modules.The first is an Arduino ® Micro prototyping board designed around the Atmel ATmega32u416MHz processor.A real-time clock (RTC) module from SparkFun (BOB-12708) is connected to the Arduino via a two wire I²C interface. This module is required to add a timestamp to the data stream.The data is received by another Bluetooth module (WRL-12580) and the combined time information and anemometer data is written to a micro-SD memory card using another SparkFun product called OpenLog (DEV-09530).OpenLog is a small PCB that combines a SD card reader with an AtmelATmega328 processor,and uses an open source software library available through the GitHub repository.The datalogger is programmable using the Arduino ® PC software, and the PCB can be powered by battery or a small (500ma) 5 VDC power supply.The datalogger is shown in figure 4.



The four modules are connected using a standard prototyping pcb and a few jumpers to allow in-circuit programming of the Bluetooth module and the OpenLog module with a serial port TTL adapter and a standard PC terminal program such as Hyperterminal or TeraTerm.Figure 5 shows a block schematic of the module wiring.The 5 VDC power to all the modules comes from the micro-USB connector on the Arduino board.An externalpower supply can power the datalogger from this port also.


Software – Bluetooth Module Programming

To save time and keep the Arduino program simple, the programming for the modules are done off-line before powering the system.The parameters for the Bluetooth module are as follows:










In this mode, the Bluetooth module will automatically look for device 00066669bbbb and pair with it after powering up.

Software – RTC Module Programming

The real time clock module only needs to be set once when the lithium coin cell battery is first inserted.A line in the Arduino code is added to set the clock, then it is commented out and reloaded.The following is the line of code required to adjust the time to 17 April 2015 at 11:20am:

Rtc.adjust(DateTime(2015, 4, 17, 11, 20, 0));

The RTC module keeps time in seconds only, so the Arduino software must add the milliseconds to the timestamp before sending the data to the SD card.

Software – OpenLog Module Programming

The software for the OpenLog module did not need to be changed for this project.The configuration settings are written to a file on the SD card when a new formatted card is inserted in its socket.The standard configuration file is very short and consists of the following two lines:



Software – Arduino Micro Programming

#include "RTClib.h"
RTC_DS1307 rtc;
char inblue = '$';
const int ledPin = 13;  
int ledState = LOW;  
long msa = 0;
long msb = 0;
bool sync = false;
DateTime now;
DateTime now1;
void setup () {
  pinMode(ledPin, OUTPUT);
  now =;
  msa = millis();

void loop () {
  now =;
  if (now1.second() != now.second())
  msa = millis();
  now1 = now;
  msb = (millis()-msa);
  if (msb > 999)
  msb = 999;
  Serial1.print(now.year(), DEC);
  Serial1.print(now.month(), DEC);
  Serial1.print(, DEC);
  Serial1.print(' ');
  Serial1.print(now.hour(), DEC);
  Serial1.print(now.minute(), DEC);
  Serial1.print(now.second(), DEC);
  Serial1.print(msb, DEC);  
  Serial1.print(' ');
  inblue = '$'; 
  while (inblue != '\r')
  ledState = HIGH;
  digitalWrite(ledPin, ledState);
  inblue = '$';
  if (Serial1.available())
  inblue =;
  if (inblue != -1){
  if (inblue != '$')
  ledState = LOW;  
  digitalWrite(ledPin, ledState);


Data – Sample Data Stream recorded on SD card (LOGO00145.TXT)

2015/4/17 15:55:27:937 -0.03 -0.08 0.16 26.47

2015/4/17 15:55:27:950 -0.03 0.00 0.16 26.47

2015/4/17 15:55:27:983 -0.08 -0.03 0.14 26.51

2015/4/17 15:55:27:996 -0.10 0.03 0.16 26.47

2015/4/17 15:55:28:0 -0.08 0.00 0.18 26.51

2015/4/17 15:55:28:50 -0.03 0.03 0.19 26.56

2015/4/17 15:55:28:64 -0.03 0.00 0.16 26.59

2015/4/17 15:55:28:131 -0.07 0.03 0.14 26.56

2015/4/17 15:55:28:170 -0.07 0.03 0.14 26.56

2015/4/17 15:55:28:182 -0.03 0.08 0.16 26.59


(Published also on

At last a chance to catch up with my Energy Monitor Arduino Project.


Here is the circuit I will build to work with my Arduino Uno via the SPI interface:


It is a design that was informed by discussions from this question:


How to Use Current and Voltage Sensors on Domestic supplies - Worldwide?


In the USA they use a split transformer to feed power to houses so that appliance will run on 110V or 220V. Using 220V keeps the current down for cookers and heaters.


The next step will be to make a prototype and set up the SPI port of the Arduino.


Previous Blogs:


1. AardEnergy – Kick Off - a new project

2. AardEnergy – Set Up Uno and Due

3. AardEnergy – Current and Voltage Transformers

4. AardEnergy – Metering Chips


The RC circuit

Posted by organtin Mar 4, 2016

This time I am going to share with you an amazingly simple experience that is made possible using just an Arduino UNO board, a resistor and a capacitor. The RC circuit is a classic circuit in physics teaching and is composed by just a resistor R and a capacitor C in series. For details you can look at the Charging a Capacitor page of the HyperPhysics pages. Pupils study the charging and discharging of the capacitor when the circuit is connected to a battery. A rather simple mathematics gives the laws governing the process. It is easy to show that the voltage across the capacitor VC is a function of the time t: when the capacitor is not charged and is connected to a voltage V0 through the resistor, one gets

VC(t)=V0(1etθ )

Here  θ is a parameter having the dimensions of a time called the time constant of the circuit and is given by the product RC. When the capacitor is at its full charge and the two leads of the circuit are short circuited, the voltage across the capacitor drops with time with an exponential law whose time constant is still given by RC.


In the past, making the experience in a physics laboratory, was not so easy for students. The time constants that one can get using easily available components are short. For R of the order of few tens of kΩ and C of the order of few μF, the time constant is of the order of 10×103×10-6≈10-2s, i.e. a hundredth of a second. In order to measure the voltage across the capacitor as a function of time you need to connect the leads of a multimeter to the capacitor and read its value as a function of time, so you need time constants of the order, at least, of few seconds. That requires extremely large values of C (and R) that, of course, are not impossible to obtain, but are not so easy to find. Even in this case you can only collect few values.


With an Arduino board the job is greatly simplified and, needless to say, the precision you can attain with it is impressive.


The circuit, shown in the picture below (made with Fritzing), is easily realised connecting one of the leads of the resistor to the 5V pin of Arduino; the resistor is mounted in series with the capacitor that, in turn, has its second lead to the ground (GND). In order to measure the voltage across the capacitor, we connect the first lead of the capacitor to one of the Arduino analog inputs (A5).



Initially, the red wire is not connected to the 5V pin and the capacitor is not charged. Using the new Arduino IDE one can plot the values written to the Serial monitor as a function of time (in fact as a function of the reading). Consider the following code:

   void loop() {
    while (fabs(analogRead(A5)*5/1024. - lastReading) < 0.1) {
      // do nothing
    for (int i = 0; i < 480; i++) {
      float currentReading = analogRead(A5)*5/1024.;
    while (1) {
      // do nothing

The first loop just waits until the current reading of the A5 pin (analogRead(A5)) differs from the value of lastReading for more than one tenth of a volt. The fabs function returns the absolute value of its argument. The reading of the analog input can be an integer number between 0 and 1024 representing a voltage ranging from 0 to 5 V. Multiplying the reading by 5 and dividing it by 1024 we then get the value of the voltage across the capacitor in Volts. Note the dot after 1024 that is needed to make the value a floating point number. If the dot is missing, both 5 and 1024 are represented as integers in the Arduino memory, as well as the value returned by analogRead(A5). This can lead to important consequences. Suppose, for example, that the analogRead(A5) function returns 123. Once multiplied by 5, we get 615 that, divided by 1024 gives just zero! In fact, 615/1024 is a ratio between two integers and the result is interpreted as an integer, too. Writing 615/1024. (with the dot after 1024) forces the CPU to represent the number 1024 as a floating point number and any operation made using an integer (615) and a floating point number (1024.) is a floating point number (about 0.6).


The value of lastReading must be set in the setup() of the Arduino sketch, in which we also initialise the Serial monitor with


The first loop, then, is needed to start the program as well as the Serial plotter, having the time to connect the red wire to the 5V pin. Only when such a wire is connected to that pin the capacitor starts charging and the voltage across its leads starts raising. At this point we just read a fixed number of values of such a voltage (480 in our case) and write them on the Serial monitor. Each value written to the Serial monitor is shown on the Serial plotter versus time (in fact each value written to the Serial monitor is plotted against a sequential number, but in our case the readings are made at almost constant intervals of time, hence the horizontal axis values are proportional to time).


Once we read all the values we just stop doing anything with the last loop. The result is shown below.



Such a very nice curve is exactly what we expected. You can even measure the discharge curve just repeating the experience in the following way: once charged, the capacitor remains charged until it is short circuited on the resistor. So, just disconnect the red wire from the 5V pin, restart the program and the Serial plotter, and connect the free lead of the red wire to the ground. The capacitor starts discharging on the resistor and the voltage across it changes. Soon after, the program makes 480 readings of the voltage and plot them, as can be seen below.



You can even be more quantitative with a slight change into the Arduino sketch. Consider the following:


   float lastReading;
   unsigned long time;
   void setup() {
     lastReading = analogRead(A5)*5/1024.;
    void loop() {
    while (fabs(analogRead(A5)*5/1024. - lastReading) < 0.1) {
      time = micros();
    for (int i = 0; i < 480; i++) {
      unsigned long now = micros();
      Serial.print(now - time);
      Serial.print(" ");
      float currentReading = analogRead(A5)*5/1024.;
    while (1) {
      // do nothing

At the beginning of the loop we still wait for a change in the voltage, but in this case we collect the current time in the time variable. The current time is given by the micros() function returning the number of microseconds elapsed since the start of the sketch. As soon as the voltage changes we start measuring the voltages across the capacitor, but in this case we also get the time of each measurement and send to the Serial monitor both the time elapsed since the start of the measurements and the measurement values.


We write those two numbers to the Serial monitor, then copy and paste them into a text file for subsequent analysis. The picture below shows the data collected by us, during the charge:



Times are in microseconds and you can see how rapid is the process. The capacitor is almost at its full charge already after 2 seconds. We used a resistor whose resistance was R=9.94 kΩ. We can then get the value of the capacitor from these measurements. With some mathematics one obtains a time constant θ of 0.53 s, from which we can derive C as θ/R≈54 μF. The nominal value of the capacitor we used is 47 μF. The error in the determination of it is then less than 15%.

Filter Blog

By date: By tag: