OC
OceanRemote
Low-code IoT platform
← Back to Tutorials
← Previous Next →

Tutorial 08: Installing Required Libraries

📖 What You'll Learn in This Tutorial:
  • ✓ Understanding which libraries OceanRemote needs
  • ✓ Installing the ArduinoJson library (required for all boards)
  • ✓ Installing DHT sensor library (for DHT22/DHT11)
  • ✓ Installing OneWire and DallasTemperature (for DS18B20)
  • ✓ Verifying correct library installation
  • ✓ Troubleshooting common library issues

Why Do We Need Libraries?

Libraries are pre-written code that make it easier to work with sensors and components. Instead of writing complex low-level code yourself, you can use libraries that handle the hard work.

OceanRemote firmware uses three main libraries depending on your sensor choice:

  • ArduinoJson - Required for ALL boards. Parses the data from OceanRemote servers.
  • DHT sensor library - Required if you're using a DHT22 or DHT11 temperature/humidity sensor.
  • OneWire + DallasTemperature - Required if you're using a DS18B20 digital temperature sensor.
📚 No Sensor? No Problem!

If you're not using any temperature sensor, you don't need to install DHT or OneWire/DallasTemperature libraries. Only ArduinoJson is required for all devices.

Library 1: ArduinoJson (Required for All Boards)

ArduinoJson is the most important library. It parses the JSON data sent by OceanRemote servers to control your relays and sensors.

Installation Steps:

  1. Open Arduino IDE
  2. Go to Sketch → Include Library → Manage Libraries
  3. In the search box, type "ArduinoJson"
  4. Look for "ArduinoJson by Benoit Blanchon"
  5. Click Install (version 6.21.0 or newer)
  6. Wait for installation to complete
💡 Version Note:

OceanRemote firmware works with ArduinoJson version 6.x. Version 7.x may have breaking changes. Install version 6.21.0 for guaranteed compatibility.

Verifying ArduinoJson Installation:

  1. Go to File → Examples
  2. Look for "ArduinoJson" in the list
  3. If you see it, the library is installed correctly
// Test code to verify ArduinoJson
#include <ArduinoJson.h>

void setup() {
  Serial.begin(115200);
  Serial.println("ArduinoJson version: ");
  Serial.println(ARDUINOJSON_VERSION);
}

void loop() {}

Upload this test code. If you see a version number in Serial Monitor, it's working!

Library 2: DHT Sensor Library (For DHT22/DHT11)

The DHT22 and DHT11 are popular temperature and humidity sensors. This library makes reading them simple.

🌡️ DHT22 vs DHT11:
Feature DHT22 DHT11
Temperature Range -40°C to +80°C 0°C to +50°C
Accuracy ±0.5°C ±2°C
Humidity Range 0-100% 20-80%
Sampling Rate Every 2 seconds Every 1 second
Price $4-6 $2-3

Installation Steps:

  1. In Library Manager, search for "DHT sensor library"
  2. Look for "DHT sensor library by Adafruit"
  3. Click Install
  4. It will ask to install dependencies. Click Install All (this includes "Adafruit Unified Sensor")

Verifying DHT Installation:

// Test code for DHT22/DHT11
#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  dht.begin();
  Serial.println("DHT library working!");
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  if (isnan(h) || isnan(t)) {
    Serial.println("Sensor not connected");
  } else {
    Serial.print("Temp: "); Serial.print(t); Serial.print("°C, ");
    Serial.print("Humidity: "); Serial.print(h); Serial.println("%");
  }
  delay(2000);
}
⚠️ Note:

The DHT22 can only be read every 2 seconds. Reading faster may give errors. OceanRemote firmware handles this automatically.

Library 3: OneWire and DallasTemperature (For DS18B20)

The DS18B20 is a digital temperature sensor that uses the 1-Wire protocol. It's very accurate (±0.5°C) and multiple sensors can share the same pin.

🌡️ Why Choose DS18B20?
  • Very accurate (±0.5°C from -10°C to +85°C)
  • Waterproof versions available (great for aquariums, outdoors)
  • Multiple sensors on one pin (each has a unique 64-bit address)
  • Range: -55°C to +125°C

Installation Steps:

  1. In Library Manager, search for "OneWire"
  2. Find "OneWire by Jim Studt" (or Paul Stoffregen version)
  3. Click Install
  4. Search for "DallasTemperature"
  5. Find "DallasTemperature by Miles Burton"
  6. Click Install

Verifying DS18B20 Installation:

// Test code for DS18B20
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(115200);
  sensors.begin();
  Serial.println("DS18B20 library working!");
}

void loop() {
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);
  
  if (temp == -127.0) {
    Serial.println("Sensor not connected");
  } else {
    Serial.print("Temperature: ");
    Serial.print(temp);
    Serial.println("°C");
  }
  delay(1000);
}
⚠️ Hardware Note:

DS18B20 requires a 4.7kΩ pull-up resistor between DATA and VCC. Without it, readings will fail or be erratic.

Library Installation Summary

Library Required For Install?
ArduinoJson ALL BOARDS ✅ YES (required)
DHT sensor library DHT22 or DHT11 sensor ⚠️ Only if using DHT
Adafruit Unified Sensor Dependency for DHT ⚠️ Auto-installed with DHT
OneWire DS18B20 sensor ⚠️ Only if using DS18B20
DallasTemperature DS18B20 sensor ⚠️ Only if using DS18B20
💡 One Library to Rule Them All:

The NTC thermistor doesn't need any special library! It uses the built-in analogRead() function. No additional installation required.

Troubleshooting Library Issues

Problem: "ArduinoJson.h: No such file or directory"

  • Solution: ArduinoJson is not installed. Go to Library Manager and install it.

Problem: "DHT.h: No such file or directory"

  • Solution: DHT library not installed. Install "DHT sensor library by Adafruit".

Problem: "OneWire.h: No such file or directory"

  • Solution: OneWire library not installed. Install "OneWire by Jim Studt".

Problem: Multiple library versions conflict

  • Solution: Go to Documents/Arduino/libraries (Windows) or ~/Arduino/libraries (Mac/Linux) and delete old versions manually.
🔧 Library Locations:
  • Windows: C:\Users\[YourUser]\Documents\Arduino\libraries
  • Mac: ~/Documents/Arduino/libraries
  • Linux: ~/Arduino/libraries

Next Steps

Now that your libraries are installed, continue with:

  • Tutorial 09: Configuring Board Settings
  • Tutorial 10-15: Wiring diagrams for your specific board
  • Tutorial 16-20: Working with sensors (DHT22, DS18B20, NTC)
  • Return to Tutorial 02: Generate and flash your firmware!
🎯 You're Ready!

All required libraries are now installed. Your Arduino IDE is fully configured for OceanRemote firmware.