CHAPTER 12 ■ IOT PLATFORMS
Serial.println(ret);
Serial.println("-----------------------------------------------");
}
Standard Functions
The final code section is provided in Listing 12-4. It implements Arduino’s standard
setup() and loop() functions.
The setup() function initializes the serial port and connects to the Internet. The
loop() function first reads the soil moisture sensor by calling readSensorData() and
then transmits these values to Xively in a feed by calling transmitData(). For each
iteration, you can add a delay depending on your requirements.
Listing 12-4. Code for Standard Arduino Functions
void setup()
{
// Initialize serial port
Serial.begin(9600);
// Connect Arduino to internet
connectToInternet();
}
void loop()
{
readSensorData();
transmitData();
//Delay
delay(6000);
}
Your Arduino code is now complete.
The Final Product
To test the application, verify and upload the Arduino code as discussed in Chapter 1.
Either insert your soil moisture sensor in the dry soil or simply dip it in water as shown
in Figure 12-29.
■ Note Do not fully submerge the circuit or sensor in water or soil. Make sure the
wiring does not get wet. For exact instructions about your soil moisture sensor, read the
manufacturer’s product specifications and directions.