Topic outline

  • Topic 1


    It is interesting to reflect on what exactly do we mean by a measurement. A measurement is determining some value and comparing it to a known reference of similar values.

    In the entire world (except USA) todays temperature is measured by determing a value of a column of mercury or alcohol and comparing that value with the values measured in an ice bath and in steam (at 1ATM);

    Hence these measurements, indeed maybe all measurements, are just inferences against something that is known.

    We will explore this in the following with the following caviat. 

    This is not a textbook, just some notes taken along the journey.

    Data cycle

    • Data collection
    • Data storage
    • Data processing
    • Information retrieval
    • Information reporting
    • Inferring

    Most of the following will deal with temperature. What is it, how is it measured, how are those measurement stored, retrieved, displayed and analysed.
    • Topic 2

      Getting started

      The following modules explore how things can be done.

      Let us pause and reflect on what can be done.

      Remember, the reason you log data is to see how something changes with time. Usually the data is displayed with a graph.

      The Primary Science Teaching Trust (PSTT)

      The Primary Science Teaching Trust (formerly the AstraZeneca Science Teaching Trust) provides financial assistance to help improve the learning and teaching of science in the UK.

      The Trust was established in April 1997 as an independent charity operating with a substantial Trust Fund donated by AstraZeneca PLC.

      PSST website
      A really good resource The IT in Science book of Datalogging and control
      • Topic 3

        Electrical conductivity

        The periodic table of elements sorts all the elements known in the universe into metals and non metals.  Electrical conductivity with temperature

        The green line is the boundary, and like most things in the world, do not obey the rules.

        Metals conduct electriciy, non metals dont, and those in the middle sometimes do it one was, some the other.

        periodic table

        Resistance is th property of a body to resist the flow of electricity. This is a fixed value for anything at constant temperature. 

        However, as temperature changes, so does the reisitance. If the resistance changes, so does the applied potential (voltage) and if it has a voltage, we can measure it with an Arduino.

        A practical experiment
        • Topic 5

          Reading a sensor : the LDR

          A LDR is a light sensitive resistor which can change its electrical conductivity in response to incident light. (Light shining directly on it)

          One thing that this project demonstrates is the use of a voltage divider.

          You can vary the reading on the analogue pin by changing the voltage. 

          read ldr

          this code reads a light dependant resistor
          and then prints it out in the serial window
          of the Arduino SDK


          int reading1;

          void setup()
          Serial.begin(9600); // this communicates
          //with the serial window
          pinMode(A0, INPUT);
          void loop()
          reading1 = analogRead(A0);
          Serial.print("sensor =>, ");// note print
                                               // note comma    
          Serial.println(reading1);   // and println

          As a quick and dirty method, you can copy data from the serial window and paste it into a spreadsheet.

          From there you can graph the data to gain information.


          Analogu, digital, serial, BAUD, CSV, spreadsheet, graph, print, println, output

          • Topic 6

            • Topic 7

              Analogue and digital

              An analogue signal is one that changes contiuously in smooth incriments. Think of an analogue watch with the second hand moving slowly. In Arduino, 1024 steps between 0-5V.

              A digital signal has only two states. On and off.

              In Aduino 0 and 5 volts.

              • Topic 8

                Reading data and writing to a SD card

                Reading and writing to an SD card is really cool. It means we can now construct wxperiments where we can enclose out Arduino and data logger in some sort of water proof container write data to the SD card over an extended time.

                Later, bring it to the lab and analyse the data.


                SD card read/write

                This example shows how to read and write data to and from an SD card file
                The circuit:
                * SD card attached to SPI bus as follows:
                ** MOSI - pin 11
                ** MISO - pin 12
                ** CLK - pin 13
                ** CS - pin 4

                created Nov 2010
                by David A. Mellis
                modified 9 Apr 2012
                by Tom Igoe

                This example code is in the public domain.


                #include <SD.h>
                #include <SPI.h>

                File myFile;

                void setup()
                // Open serial communications and wait for port to open:
                while (!Serial) {
                ; // wait for serial port to connect. Needed for Leonardo only

                Serial.print("Initializing SD card...");
                // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
                // Note that even if it's not used as the CS pin, the hardware SS pin
                // (10 on most Arduino boards, 53 on the Mega) must be left as an output
                // or the SD library functions will not work.
                pinMode(10, OUTPUT);

                if (!SD.begin(4)) {
                Serial.println("initialization failed!");
                Serial.println("initialization done.");

                // open the file. note that only one file can be open at a time,
                // so you have to close this one before opening another.
                myFile ="test.txt", FILE_WRITE);

                // if the file opened okay, write to it:
                if (myFile) {
                Serial.print("Writing to test.txt...");
                myFile.println("testing 1, 2, 3.");
                // close the file:
                } else {
                // if the file didn't open, print an error:
                Serial.println("error opening test.txt");

                // re-open the file for reading:
                myFile ="test.txt");
                if (myFile) {

                // read from the file until there's nothing else in it:
                while (myFile.available()) {
                // close the file:
                } else {
                // if the file didn't open, print an error:
                Serial.println("error opening test.txt");

                void loop()
                // nothing happens after setup

                • Topic 9

                  Temperature measurement : lm35dz

                  This exercise reads the middle pin to the analogue 0 pin directly. There is no need to manipulate the voltage using a voltage dividers, reading directly does the trick. Use the serial window in your Arduino sketch application (Tools -> Serial Port) to see the results.

                  Note the use of read and readln to format the results. Using the concatenation + operator and the string "," later on means you can create output that can be read direct to a .csv file that can be read directly into a spreadsheet.

                  Also not this sensor reads in Centigrade, and the neat conversion formula to change it to Fahrenheit (for Americans).

                  Hint : 

                  Be careful. loooking at the IC from the flat side,

                  • Vcc is on the left,
                  • GND on the right
                  • Signal in, center
                  Get it wrong, the IC will heat very quickly and will no longer work.

                  /* code to read a centigrade sensor ln35dz and report
                  to the serial window */

                  int analogPin = 0;
                  int readValue = 0;
                  float temperatureC = 0;
                  float temperatureF = 0;

                  void setup() {

                  void loop() {
                  readValue = analogRead(analogPin);
                  temperatureC = (readValue * 0.0049);
                  temperatureC = temperatureC * 100;
                  temperatureF = (temperatureC * 1.8) + 32;
                  Serial.print("Temperature: ");
                  Serial.print("C ");


                  A quick tutorial on temp sensors

                • Topic 10

                  Temperature and humidity dht11

                  • Topic 11

                    Reading data to a Nokia 5110 screen

                    When purchasing components, it helps to keep in ming economies of scale. 

                    Back in the nineties, Nokia sold millions of mobile phones with LCD dosplays. Hence, the cost of producing such massive amounts of screens went down per unit.

                    A Nokia 5110 screen on ebay sells for under $aus5 making it an affordable addendum to any project.



                    This sketch will display a reading in degrees centigrade on a Nokia 5110 screen

                    pinouts nokia 5111
                    1 2 3 4 5 6 7 8
                    r c d d c v l g
                    s e c i l c g n
                    t n k c t d

                    code from


                    hacked by numbat mark


                    #include <OneWire.h>
                    #include <DallasTemperature.h>
                    #include <LCD5110_Graph.h>

                    #define ONE_WIRE_BUS 2 // it reads the digital pin

                    LCD5110 lcd(3,4,5,6,7);

                    extern unsigned char SmallFont[];
                    extern unsigned char BigNumbers[];
                    extern uint8_t temperatureIcon[];

                    char temperatureF[6];
                    char temperatureC[6];

                    OneWire oneWire(ONE_WIRE_BUS);

                    DallasTemperature sensors(&oneWire);

                    float tempC = 0;
                    float tempF = 0;

                    void setup(void)

                    void loop(void)

                    // lcd.drawBitmap(0, 0, temperatureIcon, 84, 48);


                    tempC = sensors.getTempCByIndex(0);
                    tempF = sensors.toFahrenheit(tempC);

                    // convertToString(tempF);
                    convertToString(tempC); //Uncomment this for degrees Celsius 
                    // lcd.print(temperatureF,25,11);


                    void convertToString(float number)
                    //dtostrf(number, 3, 1, temperatureF);
                    dtostrf(number, 3, 1, temperatureC);

                    • Topic 12

                      Reading data with Python

                      Arduino does not really have the capacity to store a large amount of data on it's chip. So to get data to be stored on a computer we need use an external language. After a quick straw poll, we have decided on Python as it is taught on Code Academy and is the language of choice for the Pi.

                      To get your computer to talk to a serial port, you must first download a library called Pyserial.

                      Download Python here.

                      Pyserial here

                      Reading a file, then writing it.

                      Be carful. Check which port the Arduino is connected to. It is unlikely to be COM4

                      import serial
                      import time
                      ser = serial.Serial('COM4', 9600, timeout=0)

                      while 1:
                      print (ser.readline())
                      except ser.SerialTimeoutException:
                      print('Data could not be read')

                      How to do this.

                    • Topic 13

                      Reading data and writing  to a file on a computer with Python

                      / this opens a file and write to it

                      file = open("newfile.txt", "w")
                      file.write("hello world in the new file\n")
                      file.write("and another line\n")

                      / this opens a file and writes it to the screen
                      file = open("newfile.txt", "r")
                      print (

                      • Topic 14

                        Reading data to the internet

                        • Topic 15


                          • Topic 17

                            Reading data to a bluetooth adapter

                            • Topic 18

                              Writing data to

                              • Topic 19

                                • Topic 20

                                  Moisture sensor : Hl-01 and HL-69

                                  Looking on will find lots of projects where people have just expanded on this code to turn on monitor gardens and turn on reticulation systems.

                                  You can fir a system based un a UNO into a soap holder or one baed on a mini pro into a mint tin.

                                  reading the moisture content from a hl-01/hl-69
                                  sensor system.

                                  Details on youtube

                                  this read the anaolgue value at A0

                                  this code can be adapted for monitoring or data logging

                                  void setup(){

                                  void loop(){

                                  Serial.print("Moisture Sensor Value:");

                                  humidity sensor