PHYS2020-Arduino-Quick-Start

ANU PHYS2020 Thermodynamics Course Arduino Quick Start Guide

Tony.Yan @anu.edu.au

March 2024

GitHub Release arduino arduino MAX6675 MAX31855 DS18B20 MPU6050




Connecting to Arduino

First, download Arduino IDE (integrated development environment) from https://www.arduino.cc/en/software.

Once you have the Arduino IDE installed, we need to verify that the Arduino works by connecting it to your computer and the IDE.

As illustrated in the figure below, I also strongly recommend mounting your Arduino Nano onto a breadboard and connecting the 5V and 3.3V to each power rail on the breadboard. This makes connecting various modules much simpler later.

breadboard and voltage rails

Our Arduino Nano uses a USB Type-C connector; you can connect it to your computer with any Type-C cable and Arduino can be powered from Type-C.

The Arduino IDE will preload a default BareMinimum script (Menu -> File -> Examples -> Basic -> BareMinimum) so you can test your connections to your Arduino.

Configure the IDE to our specific Arduino by clicking Select Board

arduino setup - select board

Select Arduino Nano and its USB Serial Port.

arduino setup - select board 2

Then, you can try uploading the BareMinimum script onto your Arduino by pressing the Upload icon (or Menu -> Sketch -> Upload or Cmd-U).

arduino setup - upload button

You might experience the following error saying the programmer is not in sync

arduino setup - not in sync

In that case, you need to go to Menu -> Tools -> Processor and select: ATmega328P (Old Bootloader)

arduino setup - old bootloader

Then try upload again and it should upload without error.

arduino setup - success

Other Common Issues/Troubleshooting:

If there are other Arduino setting-up issues, feel free to contact us.

General Info and Tips about using Arduino in PHYS2020 Project

You might find the following Arduino Pin layout helpful (available at https://content.arduino.cc/assets/Pinout-NANO_latest.pdf).

Pinout-NANO_latest

MAX6675 (or MAX31855) Temperature Sensor

For a more detailed guide on using the MAX6675 module, please read https://lastminuteengineers.com/max6675-thermocouple-arduino-tutorial/

The MAX31855 is a newer version MAX6675, but they work basically the same.

The kit includes

The following table shows the connections used in the sample code:

MAX6675 Module Pinout

MAX6675 Arduino
VCC 3.3V or 5V
GND GND
SCK (Serial Clock for synchronising data transmission) D6
CS (Chip Select pin) D5
SO (Serial data Out) D4

breadboard MAX6678

You also need to grab a code library to use the MAX6675 module. Go to Menu -> Sketch -> Include Library -> Manage Libraries (or Shift-Cmd-I or click on the Library icon in the left sidebar) and search for MAX6675. I used the official library from Adafruit, but you’re of course welcome to experiment with other ones.

arduino library MAX6675

Once the library is installed, open the provided sample code at Menu -> File -> Examples -> MAX6675 library -> serialthermocouple; there’s also a copy of it named MAX6675SerialLogger.ino in this repository.

MAX6675 - sample

Try uploading their sample script and opening the serial monitor (Menu -> Tools -> Serial Monitor or Shift-Cmd-M or the top right Magnifying glass icon). You should see the thermocouple printing the temperatures onto the Serial Monitor. You could also show their timestamps by toggling the clock icon on the right.

MAX6675 - sample logging

Tips & Tricks

DS18B20 Temperature Sensor

For a more detailed guide on using the DS18B20 module, please read https://lastminuteengineers.com/ds18b20-arduino-tutorial/ .

We provide the DS18B20 sensor that comes in the waterproof probe. You also need a 4.7kΩ resistor between VCC and DQ.

DS18B20 wiring

DS18B20 Arduino
VCC 3.3V or 5V
GND GND
DQ (Data Queue) D2

breadboard DS18B20

You also need to grab a code library to use the DS18B20 module. Go to Menu -> Sketch -> Include Library -> Manage Libraries (or Shift-Cmd-I or click on the Library icon in the left sidebar) and search for DS18B20. I used the official library from DallasTemperature, but you’re of course welcome to experiment with other ones.

DS18B20 - library

Once the library is installed, open the provided sample code at Menu -> File -> Examples -> DallasTemperatures -> Single; there’s also a copy of it named DS18B20Simple.ino in this repository.

DS18B20 - sample logging

Try uploading their sample script and opening the serial monitor (Menu -> Tools -> Serial Monitor or Shift-Cmd-M or the top right Magnifying glass icon). You should see the thermometer printing the temperatures onto the Serial Monitor. You could also show their timestamps by toggling the clock icon on the right.

DS18B20 usage notes

MPU6050 Accelerometer and Gyroscope

For a more detailed guide on using the MPU6050 module, please read https://lastminuteengineers.com/mpu6050-accel-gyro-arduino-tutorial/.

You might need soldering skills to make the pins.

MPU6050 pinout

MPU6050 Arduino
VCC 3.3V or 5V
GND GND
SCL (Serial Clock Line) A5 (SCL)
SDA (Serial Data Line) A4 (SDA)
Other pins not connected.  

IMG_2252

You also need to grab a code library to use the MPU6050 module, go to Menu -> Sketch -> Include Library -> Manage Libraries (or Shift-Cmd-I or click on the Library icon in the left sidebar), and search up MPU6050.breadboard - MPU6050

I used the official library of Adafruit, but you’re of course welcome to experiment with other ones.

MPU6050 - library

Once the library is installed, open the provided sample code at Menu -> File -> Examples -> Adafruit MPU6050 -> basic readings; there’s also a copy of it named MPU6050Basic.ino in this repository.

MPU6050 - sample

Try uploading their sample script and opening the serial monitor (Menu -> Tools -> Serial Monitor or Shift-Cmd-M or the top right Magnifying glass icon). The sample codes use 115200 serial baud rate (instead of the default 9600), so you need to manually select the baud rate in the serial monitor. Then, you should see it printing the sensors’ values onto the Serial Monitor. You could also show their timestamps by toggling the clock icon on the right.

You could also try the script in Menu -> File -> Examples -> Adafruit MPU6050 -> plotter and use the Serial Plotter (top right oscilloscope icon) to get a realtime plot from the accelerometer and gyroscope.

MPU6050 - plotter

Notes

Pressure Sensor

Depending on your sensor type, usually, they only need ground and 5V, then the sensor output 0-5V depending on their spec. Then any Arduino’s analog pin can read that 0-5V in 1024 steps using analogRead(pinNo).

Recording Data to SD Card

For a more detailed guide on using the SD card module, please read https://lastminuteengineers.com/arduino-micro-sd-card-module-tutorial/

For the SD card module to work with the sample code (SDCardDataLogger.ino), connect the pins as follows,

SD Card Module pinout

microSD Card Module Arduino
VCC 3.3V or 5V
GND GND
MISO (Serial Peripheral Interface Output) 12
MOSI (Serial Peripheral Interface Input) 11
SCK (Serial Clock) 13
CS (Chip Select) 10

IMG_2253

Verify your SD card and reader module works

Open the built-in sample code at Menu -> File -> Examples -> SD -> CardInfo , and change the value of chipSelect at line 36 to 10, then upload the code onto Arduino, you should get the following info from the provided SD card (your’s probably will not show any files, I have some files from macOS filesystem crap).

SD Card module v2

Using the sample code

Unless you installed all the sensors mentioned in the exact pins (in pic below), the sample code SDCardDataLogger.ino would most likely throw some errors and complain about missing sensors.

IMG_2254

If you do have all sensors installed, then SDCardDataLogger.ino would log data to both the SD card and Serial Monitor, and it could also log data to the SD card without connecting it to a computer. The Serial monitor output would look something like this:

MPU6050 Initialised.
Initialising SD card...done.
Logging to: log20.csv
Tms,423,Acc,-3.10,3.44,-8.87,Rot,-0.08,-0.01,0.02,V1,0.01,TC,0.00,TS,25.00,
Tms,557,Acc,-3.09,3.45,-8.88,Rot,-0.08,-0.02,0.02,V1,0.01,TC,0.00,TS,25.00,
Tms,690,Acc,-3.11,3.47,-8.85,Rot,-0.08,-0.02,0.02,V1,0.00,TC,0.00,TS,25.00,
...
...

The first three lines are just checking setup; from the fourth line onwards, they show the exact data logged to the SD card.

The data are logged in CSV (comma separated value) format which can be easily read by Mathematica, Python, Excel or your preferred stats tool.

You should comment out (Cmd-/) any code about the sensors that you are not using.

Other things to consider