Hardware Reference
In-Depth Information
First, we will define a default IP address for the Ethernet shield. The sketch should not use
this address since we'll attempt to connect using DHCP, but if DHCP fails, we need this
default IP address. I recommend using an address that is in the same IP domain as your
computer IP address:
IPAddress ip(192,168,1,50);
Then, we can define the IP address of the server, which in this case is your computer. This
is where you need to enter the IP address you got before:
IPAddress server(192,168,1,100);
We can then create an instance of the Ethernet client:
EthernetClient client;
We can also create an instance of the DHT library:
DHT dht(DHTPIN, DHTTYPE);
Now in the setup() function of the sketch, we first try to use DHCP to automatically
get an IP address for the Ethernet shield. This is done using the following piece of code:
Serial.begin(115200);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
After this step, we print the IP address on the Serial port:
Serial.print("IP address: ");
Serial.println(Ethernet.localIP());
In the loop() function of the sketch, the first step is to take measurements from the
DHT11 sensor:
float h = dht.readHumidity();
float t = dht.readTemperature();
Convert these measurements into strings:
Search WWH ::




Custom Search