This is a simple demonstration of the SDI-12 library for Arduino.
It discovers the address of all sensors active on any pin on your board.
Each sensor should have a unique address already - if not, multiple sensors may respond simultaenously to the same request and the output will not be readable by the Arduino.
To address a sensor, please see Example B: b_address_change.ino
PlatformIO Configuration
1; PlatformIO Project Configuration File
4description = SDI-12 Library Example C: Searching all Addresses for Sensors
5src_dir = .piolibdeps/Arduino-SDI-12_ID1486/examples/c_check_all_addresses
The Complete Example
2 * @example{lineno} c_check_all_addresses.ino
3 * @copyright Stroud Water Research Center
4 * @license This example is published under the BSD-3 license.
5 * @author Kevin M.Smith <SDI12@ethosengineering.org>
8 * @brief Example C: Check all Addresses for Active Sensors and Print Status
10 * This is a simple demonstration of the SDI-12 library for Arduino.
12 * It discovers the address of all sensors active and attached to the board.
13 * THIS CAN BE *REALLY* SLOW TO RUN!!!
15 * Each sensor should have a unique address already - if not, multiple sensors may
16 * respond simultaenously to the same request and the output will not be readable
19 * To address a sensor, please see Example B: b_address_change.ino
24uint32_t serialBaud = 115200; /*!< The baud rate for the output serial port */
25int8_t powerPin = 22; /*!< The sensor power pin (or -1 if not switching power) */
26#define FirstPin 5 /*! change to lowest pin number on your board */
27#define LastPin 24 /*! change to highest pin number on your board */
30 * @brief gets identification information from a sensor, and prints it to the serial
33 * @param sdi the SDI-12 instance
34 * @param i a character between '0'-'9', 'a'-'z', or 'A'-'Z'
36void printInfo(SDI12 sdi, char i) {
40 sdi.sendCommand(command);
48 while (sdi.available()) {
49 Serial.write(sdi.read());
50 delay(10); // 1 character ~ 7.5ms
54// this checks for activity at a particular address
55// expects a char, '0'-'9', 'a'-'z', or 'A'-'Z'
56boolean checkActive(SDI12 sdi, char i) {
57 String myCommand = "";
59 myCommand += (char)i; // sends basic 'acknowledge' command [address][!]
62 for (int j = 0; j < 3; j++) { // goes through three rapid contact attempts
63 sdi.sendCommand(myCommand);
66 if (sdi.available()) { // If we here anything, assume we have an active sensor
74void scanAddressSpace(SDI12 sdi) {
75 // scan address space 0-9
76 for (char i = '0'; i <= '9'; i++)
77 if (checkActive(sdi, i)) { printInfo(sdi, i); }
78 // scan address space a-z
79 for (char i = 'a'; i <= 'z'; i++)
80 if (checkActive(sdi, i)) { printInfo(sdi, i); }
81 // scan address space A-Z
82 for (char i = 'A'; i <= 'Z'; i++)
83 if (checkActive(sdi, i)) { printInfo(sdi, i); };
87 Serial.begin(serialBaud);
88 Serial.println("//\n// Start Search for SDI-12 Devices \n// -----------------------");
92 Serial.println("Powering up sensors...");
93 pinMode(powerPin, OUTPUT);
94 digitalWrite(powerPin, HIGH);
98 for (uint8_t pin = FirstPin; pin <= LastPin; pin++) {
99 if (pin != powerPin) {
103 Serial.print("Checking pin ");
105 Serial.println("...");
106 scanAddressSpace(mySDI12);
111 Serial.println("\n//\n// End Search for SDI-12 Devices \n// ---------------------");
114 digitalWrite(powerPin, LOW);