Arduino + Ethernet Shield to Monitor Temperature

Arduino + Ethernet Shield to Monitor Temperature © MIT

This project makes a thermometer using a thermistor.

  • 11,954 views
  • 2 comments
  • 9 respects

Components and supplies

Apps and online services

About this project

Today, internet is a (daily) need, for messaging, browsing, business meetings and everything else that can be done with this technology. Here I will share about measuring temperature using Arduino and send data through the internet thanks to Arduino Ethernet shield. To do that, I will use thermistor 10K SEN as a sensor, Arduino UNO R3 as microcontroller (to convert analog data to digital), Arduino Ethernet shield to send data via LAN cable, and a simple webserver that's built to receive data and display it in the HTML file.

So, Let’s Get Dirty

The above picture is the schematic for the temperature measurement. Connect the 1st pin of the thermistor to the 10K resistor and the 2nd pin to the GND of Arduino. The 10K resistor’s 1st pin is connected to the Arduino 5V as supply and the 2nd pin is connected to the Analog Input 0 (A0) Arduino. After that, we could append the Ethernet shield atop the Arduino, which has exactly the same pin.

The Ethernet shield should use a LAN cable, which is a RJ45 cable, to communicate through the internet. When this is done, the last hardware step is to connect the Arduino with the computer using a USB cable. So, the real picture of the project should be like this.

Hardware Is Done, Let’s Move Onto the Fun Part: Coding!

There will be some files, folders, and language used in order to make this project to succeed. The very first task is to code the Arduino to read analog, convert it to a temperature value and make HTTP POST to the server.

#include 'Ethernet.h'
#include 'SPI.h'
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 }; // RESERVED MAC ADDRESS
EthernetClient client;
long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 3000; // READING INTERVAL
float p = 0.00;
String data;
void setup() { 
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP"); 
  }
  delay(10000); // GIVE THE SENSOR SOME TIME TO START
}
void loop(){
  currentMillis = millis();
  if(currentMillis - previousMillis > interval) { // READ ONLY ONCE PER INTERVAL
    previousMillis = currentMillis;
    p = (float) analogRead(A0) * (5.0 / 1023.0); // CONVERT TO ARDUINO READABLE VALUE;
    p = (float) -7.58 * p + 27.309; // CALIBRATION RESULT
  }
  data = "potentio=";
  data = data + p;
  if (client.connect("167.205.43.205",3500)) { // REPLACE WITH YOUR SERVER ADDRESS
    client.println("POST /results HTTP/1.1"); // HTTP POST TO /results
    client.println("Host: 167.205.43.205:3500"); // SERVER ADDRESS HERE TOO
    client.println("Content-Type: application/x-www-form-urlencoded"); // DATA TYPE
    client.print("Content-Length: ");  
    client.println(data.length()); 
    client.println(); 
    client.print(data); 
  } 
  if (client.connected()) { 
    client.stop();  // DISCONNECT FROM THE SERVER
  }
  delay(5000); // 5 SECONDS DELAY
}

Important Parts

  • Calibration result: The equation of graph voltage versus resistance of NTC Thermistor.
  • IP Address: You can use IP address or DNS. Pay attention to the port you are using.

After coding the Arduino, we need to make a webserver on that IP address (in this case is 167.205.43.205). In this project, I use a simple ExpressJS apps and MySQL database. The sample code is shown below:

app.js

app.post('/results', function(req, res){
    var post = {}
    post.date = new Date(),
    post.temp = req.body.temp
    sql.query('INSERT INTO analog_read SET ?', post, function(err, results, fields){
        if(err) throw err;
        console.log('sent success with value : ', post.temp)
        res.json({'status':'success!'})
    })
})

And display it to the HTML page as shown in the result below:

Pretty easy, right? For the full code, you can download it here.

Code

Code snippet #1Plain text
#include 'Ethernet.h'
#include 'SPI.h'

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 }; // RESERVED MAC ADDRESS
EthernetClient client;

long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 3000; // READING INTERVAL
float p = 0.00;
String data;

void setup() { 
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP"); 
  }
  delay(10000); // GIVE THE SENSOR SOME TIME TO START
}

void loop(){
  currentMillis = millis();
  if(currentMillis - previousMillis > interval) { // READ ONLY ONCE PER INTERVAL
    previousMillis = currentMillis;
    p = (float) analogRead(A0) * (5.0 / 1023.0); // CONVERT TO ARDUINO READABLE VALUE;
    p = (float) -7.58 * p + 27.309; // CALIBRATION RESULT
  }
  data = "potentio=";
  data = data + p;

  if (client.connect("167.205.43.205",3500)) { // REPLACE WITH YOUR SERVER ADDRESS
    client.println("POST /results HTTP/1.1"); // HTTP POST TO /results
    client.println("Host: 167.205.43.205:3500"); // SERVER ADDRESS HERE TOO
    client.println("Content-Type: application/x-www-form-urlencoded"); // DATA TYPE
    client.print("Content-Length: ");  
    client.println(data.length()); 
    client.println(); 
    client.print(data); 
  } 
  if (client.connected()) { 
    client.stop();  // DISCONNECT FROM THE SERVER
  }
  delay(5000); // 5 SECONDS DELAY
}
Code snippet #2Plain text
#include 'Ethernet.h'
#include 'SPI.h'

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 }; // RESERVED MAC ADDRESS
EthernetClient client;

long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 3000; // READING INTERVAL
float p = 0.00;
String data;

void setup() { 
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP"); 
  }
  delay(10000); // GIVE THE SENSOR SOME TIME TO START
}

void loop(){
  currentMillis = millis();
  if(currentMillis - previousMillis > interval) { // READ ONLY ONCE PER INTERVAL
    previousMillis = currentMillis;
    p = (float) analogRead(A0) * (5.0 / 1023.0); // CONVERT TO ARDUINO READABLE VALUE;
    p = (float) -7.58 * p + 27.309; // CALIBRATION RESULT
  }
  data = "potentio=";
  data = data + p;

  if (client.connect("167.205.43.205",3500)) { // REPLACE WITH YOUR SERVER ADDRESS
    client.println("POST /results HTTP/1.1"); // HTTP POST TO /results
    client.println("Host: 167.205.43.205:3500"); // SERVER ADDRESS HERE TOO
    client.println("Content-Type: application/x-www-form-urlencoded"); // DATA TYPE
    client.print("Content-Length: ");  
    client.println(data.length()); 
    client.println(); 
    client.print(data); 
  } 
  if (client.connected()) { 
    client.stop();  // DISCONNECT FROM THE SERVER
  }
  delay(5000); // 5 SECONDS DELAY
}
Code snippet #3Plain text
app.post('/results', function(req, res){
    var post = {}
    post.date = new Date(),
    post.temp = req.body.temp

    sql.query('INSERT INTO analog_read SET ?', post, function(err, results, fields){
        if(err) throw err;
        console.log('sent success with value : ', post.temp)
        res.json({'status':'success!'})
    })
})
Code snippet #4Plain text
app.post('/results', function(req, res){
    var post = {}
    post.date = new Date(),
    post.temp = req.body.temp

    sql.query('INSERT INTO analog_read SET ?', post, function(err, results, fields){
        if(err) throw err;
        console.log('sent success with value : ', post.temp)
        res.json({'status':'success!'})
    })
})
Github
http://github.com/wildan3105/arduino-ethernet

Comments

Similar projects you might like

Monitor Fire and Temperature Using ARTIK Cloud

Project tutorial by Samsung IoT

  • 2,919 views
  • 0 comments
  • 21 respects

Cayenne Temperature Monitor

by Krish

  • 2,058 views
  • 0 comments
  • 4 respects

Temperature Streaming with Arduino + Big Data Tools

Project showcase by Gabriel Rodriguez

  • 5,409 views
  • 1 comment
  • 28 respects

Arduino Temperature Control

Project tutorial by Team pandhoit

  • 18,243 views
  • 10 comments
  • 28 respects
Add projectSign up / Login