Skip to content

Commit 928b75c

Browse files
committed
cleanup code
1 parent 96a27bf commit 928b75c

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

examples/Example_01_BasicReadings/Example_01_BasicReadings.ino

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
/*
2+
*---------------------------------------------------------------------------------
3+
*
4+
* Copyright (c) 2025, SparkFun Electronics Inc.
5+
*
6+
* SPDX-License-Identifier: MIT
7+
*
8+
*---------------------------------------------------------------------------------
9+
*/
210

3-
*/
4-
5-
#include "SparkFun_Soil_Moisture_Sensor.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_Soil_Moisture
11+
#include "SparkFun_Soil_Moisture_Sensor.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_Soil_Moisture_Sensor
612
#include <Wire.h>
713

814
SparkFunSoilMoistureSensor mySoilSensor; // Create an instance of the sensor class
@@ -16,6 +22,7 @@ SparkFunSoilMoistureSensor mySoilSensor; // Create an instance of the sensor cla
1622
#define wirePort Wire
1723
#endif
1824

25+
1926
void setup()
2027
{
2128
Serial.begin(115200);
@@ -27,26 +34,35 @@ void setup()
2734
// Comment out this while loop, or it will prevent the remaining code from running.
2835

2936
Serial.println();
30-
Serial.println("Soil Sensor Example 1 - Basic Readings");
37+
Serial.println("------------------------------------------------------------");
38+
Serial.println("SparkFun Soil Sensor Example 1");
39+
Serial.println("Basic Readings");
40+
Serial.println("------------------------------------------------------------");
41+
Serial.println();
3142

3243
wirePort.begin();
3344

3445
if (mySoilSensor.begin() == false)
3546
{
36-
Serial.println("Soil Moisture Sensor not detected at default I2C address. Verify the sensor is connected "
37-
"correctly. Freezing...");
47+
Serial.println("Soil Moisture Sensor not detected at default I2C address. Verify the sensor is connected. Stopping.");
3848
while (1)
3949
;
4050
}
4151
Serial.println("Soil Moisture Sensor found!");
52+
53+
Serial.println();
54+
Serial.println("Reading soil moisture sensor...");
55+
Serial.println();
4256
}
4357

58+
//----------------------------------------------------------------------------------------
4459
void loop()
4560
{
4661
// Let's get some readings
4762
uint16_t soilMoisture = mySoilSensor.readMoistureValue();
4863
Serial.print("Soil Moisture: ");
4964
Serial.println(soilMoisture);
5065

66+
// loop delay - 2 seconds
5167
delay(2000);
5268
}

examples/Example_02_ReadingsAndLED/Example_02_ReadingsAndLED.ino

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
/*
2+
*---------------------------------------------------------------------------------
3+
*
4+
* Copyright (c) 2025, SparkFun Electronics Inc.
5+
*
6+
* SPDX-License-Identifier: MIT
7+
*
8+
*---------------------------------------------------------------------------------
9+
*/
210

3-
*/
4-
5-
#include "SparkFun_Soil_Moisture_Sensor.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_Soil_Moisture
11+
#include "SparkFun_Soil_Moisture_Sensor.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_Soil_Moisture_Sensor
612
#include <Wire.h>
713

814
SparkFunSoilMoistureSensor mySoilSensor; // Create an instance of the sensor class
@@ -16,6 +22,8 @@ SparkFunSoilMoistureSensor mySoilSensor; // Create an instance of the sensor cla
1622
#define wirePort Wire
1723
#endif
1824

25+
//----------------------------------------------------------------------------------------
26+
1927
void setup()
2028
{
2129
Serial.begin(115200);
@@ -27,33 +35,48 @@ void setup()
2735
// Comment out this while loop, or it will prevent the remaining code from running.
2836

2937
Serial.println();
30-
Serial.println("Soil Sensor Example 1 - Basic Readings");
38+
Serial.println("------------------------------------------------------------");
39+
Serial.println("SparkFun Soil Sensor Example 2");
40+
Serial.println("Basic Readings and On-Board LED Control");
41+
Serial.println("------------------------------------------------------------");
42+
Serial.println();
43+
3144

3245
wirePort.begin();
3346

3447
if (mySoilSensor.begin() == false)
3548
{
36-
Serial.println("Soil Moisture Sensor not detected at default I2C address. Verify the sensor is connected "
37-
"correctly. Freezing...");
49+
Serial.println("Soil Moisture Sensor not detected at default I2C address. Verify the sensor is connected. Stopping.");
50+
3851
while (1)
3952
;
4053
}
4154
Serial.println("Soil Moisture Sensor found!");
4255

4356
mySoilSensor.LEDOff();
57+
58+
Serial.println();
59+
Serial.println("Reading soil moisture sensor...");
60+
Serial.println();
4461
}
4562

63+
//----------------------------------------------------------------------------------------
64+
4665
void loop()
4766
{
4867
// Wink the LED during the reading
4968
mySoilSensor.LEDOn();
5069
// Let's get some readings
5170
uint16_t soilMoisture = mySoilSensor.readMoistureValue();
71+
72+
// Output the value:
5273
Serial.print("Soil Moisture: ");
5374
Serial.println(soilMoisture);
5475

76+
// small delay for the LED to be seen
5577
delay(100);
5678
mySoilSensor.LEDOff();
5779

80+
// delay our reading.
5881
delay(2000);
5982
}

0 commit comments

Comments
 (0)