First Sketch: simple_logging.ino

Overview

Teaching: 30 min
Exercises: 30 min
Questions
  • How do I run multiple sensors and log to an SD card?

Objectives
  • Run simple_logging.ino to collect data from the Mayfly data logger’s built-in sensors.

  • Modify simple_logging.ino to also collect data from a DS18 submersible temperature sensor and/or a BME280 air temperature, humidity and barometric pressure sensor.

Episode 10: Your first Modular Sensors sketch

Prerequisites

Collect data from the Mayfly data logger’s built-in sensors

First we will use simple_logging.ino to collect data from the Mayfly data logger’s built-in sensors.

Congratulations you successfully set up your first Modular Sensors sketch!

Modify simple_logging to also collect data from external sensors

Now we will modify your existing simple_logging.ino to add the Maxim DS18 submersible temperature sensor.

  // ==========================================================================
  //    Maxim DS18 One Wire Temperature Sensor
  // ==========================================================================
  #include <sensors/MaximDS18.h>

  // OneWire Address [array of 8 hex characters]
  // If only using a single sensor on the OneWire bus, you may omit the address
  // DeviceAddress OneWireAddress1 = {0x28, 0xFF, 0xBD, 0xBA, 0x81, 0x16, 0x03, 0x0C};
  const int8_t OneWirePower = sensorPowerPin;  // Pin to switch power on and off (-1 if unconnected)
  const int8_t OneWireBus = 7;  // Pin attached to the OneWire Bus (-1 if unconnected) (D24 = A0)

  // Create a Maxim DS18 sensor objects (use this form for a known address)
  // MaximDS18 ds18(OneWireAddress1, OneWirePower, OneWireBus);

  // Create a Maxim DS18 sensor object (use this form for a single sensor on bus with an unknown address)
  MaximDS18 ds18(OneWirePower, OneWireBus);

- Note that some sensors will require you to initiate serial ports to run them (modbus and sonar are supported examples of this), so you will have to add additional code snippets for these sensors, but most sensors only have two snippets: the main sensor block and the variable array snippet.

Solution

A working version of simple_logging.ino with two external sensors, including the DS18, is among the examples in the Modular Sensors library.

In our next few episodes, we will set up the EnviroDIY/Monitor My Watershed data portal to receive your data. Then we will use a sketch that expands the format of simple_logging.ino to send data to the portal.

Key Points

  • Simple logging is a good way to test and deploy sensors and log to an SD card.