Hardware Reference
In-Depth Information
}
}
After that, we will try to initialize the SD card, as shown in the following code:
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
If this is successful, we will print out a message on the Serial port, as shown in the fol-
lowing code:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
We will also start the DHT sensor as follows:
dht.begin();
Finally, still in the setup() function, we will print out the IP address of the Ethernet
shield and create the connection to the NTP server. Note that here we are calling a func-
tion called getNtpTime , which is defined later in the sketch. As this is a function
provided by the Time library, we are not going to look into the details of this function.
The following is the code for this part:
Serial.print("IP number assigned by DHCP is ");
Serial.println(Ethernet.localIP());
Udp.begin(localPort);
Serial.println("waiting for sync");
setSyncProvider(getNtpTime);
Now, in the loop() function of the sketch, we will first measure the temperature and hu-
midity from the sensor using the following code:
float h = dht.readHumidity();
float t = dht.readTemperature();
Search WWH ::




Custom Search