Interface Arduino with Ethernet shield & display Temperature using LM35 on Web browser

details

Description:

In this project we have introduced on how to interface LM35 using Arduino Mega 2560.  This shows  how to interface Ethernet Shield with Arduino 2560 and display temperature data using LM35 on your Web Browser.

Hardware:

•Arduino shield

•Ethernet Shield

•LM-35 temperature sensor

•Breadboard

Ethernet shield can be easily connected to Arduino by stacking on it. As explained in this article connect LM35 to Arduino (with Ethernet shield)

 

46

/// Brave Learn ///
/// http://bravelearn.com ///
// Connect LM35 to Arduino (with Ethernet shield) as shown in the diagram
#include <SPI.h>
#include <Ethernet.h>
int tempPin = 0;
float reading;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177); //This is the ip of Ardunio. Make sure your computer is connected to the same network
// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);  
void setup() {
  pinMode(A0, INPUT);
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
}
void loop() {
  reading = (5.0 * analogRead(tempPin) * 100.0) / 1024;
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
	  client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          ///HTML Codes goes here //
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<title>Bravelearn | Arduino | Temperature Sensor Data </title>");
          client.println("<div align=center>");
          client.println("<a href=http://bravelearn.com/equiz><img src=http://bravelearn.com/equiz/img/logo.png></a><br />"); 
          client.println("<h2>Welcome to Brave Learn Arduino Webserver with LM-35 Temperature Sensor</h2>");
          client.println("<tr><td><hr size=4 color=#0099FF> </td></tr>");
          // output the value of each analog input pin
          client.print("<h3>Temperature Right Now is: ");
          client.println((float)reading);
          client.print(" &#8451;");
          client.println("</h3>");
          client.println("<br/>");
          client.println("</div>");
           client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1); 
    // close the connection:
    client.stop();
    delay(10000); // wait for 10 seconds before taking the reading again
  }
}

After successful connections,The following page navigates in the Web browser.

Tags:201802,Arduino mega 2560,Ethernet shield,LM350

Author:Brave Learn.

 

Original Source: http://bravelearn.com/interface-arduino-with-ethernet-shield-display-temperature-using-lm35-on-web-browser/

Description:

In this project we have introduced on how to interface LM35 using Arduino Mega 2560.  This shows  how to interface Ethernet Shield with Arduino 2560 and display temperature data using LM35 on your Web Browser.

Hardware:

•Arduino shield

•Ethernet Shield

•LM-35 temperature sensor

•Breadboard

Ethernet shield can be easily connected to Arduino by stacking on it. As explained in this article connect LM35 to Arduino (with Ethernet shield)

 

46

/// Brave Learn ///
/// http://bravelearn.com ///
// Connect LM35 to Arduino (with Ethernet shield) as shown in the diagram
#include <SPI.h>
#include <Ethernet.h>
int tempPin = 0;
float reading;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177); //This is the ip of Ardunio. Make sure your computer is connected to the same network
// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);  
void setup() {
  pinMode(A0, INPUT);
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
}
void loop() {
  reading = (5.0 * analogRead(tempPin) * 100.0) / 1024;
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
	  client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          ///HTML Codes goes here //
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<title>Bravelearn | Arduino | Temperature Sensor Data </title>");
          client.println("<div align=center>");
          client.println("<a href=http://bravelearn.com/equiz><img src=http://bravelearn.com/equiz/img/logo.png></a><br />"); 
          client.println("<h2>Welcome to Brave Learn Arduino Webserver with LM-35 Temperature Sensor</h2>");
          client.println("<tr><td><hr size=4 color=#0099FF> </td></tr>");
          // output the value of each analog input pin
          client.print("<h3>Temperature Right Now is: ");
          client.println((float)reading);
          client.print(" &#8451;");
          client.println("</h3>");
          client.println("<br/>");
          client.println("</div>");
           client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1); 
    // close the connection:
    client.stop();
    delay(10000); // wait for 10 seconds before taking the reading again
  }
}

After successful connections,The following page navigates in the Web browser.

Tags:201802,Arduino mega 2560,Ethernet shield,LM350

Author:Brave Learn.

 

Original Source: http://bravelearn.com/interface-arduino-with-ethernet-shield-display-temperature-using-lm35-on-web-browser/

COMMENTS

Please Login to comment
  Subscribe  
Notify of