Data Logger with Arduino and the Ethernet shield

details

Description:

For our project we wanted to create an Ethernet data logger that could take data from a temperature sensor and a PIR motion sensor.  This would allow us to graph motion and temperature over time allowing users to know when a space was most in use and perhaps whether it was being heated effectively.

Hardware:

• Arduino Uno

• Ethernet Shield( W5100)

• Tempertaure Sensor

• PIR Motion Sensor.

Arduino– The Arduino here connects collects the temperature data and movement data to the Internet as a client and posts data to the Google App Engine site every 60 seconds. An external interrupt allows for motion to be detected and polled at any time. The temperature is read just before the HTTP post is made.
      Google App Engine — On this side the app engine takes the data posted from the Arduino and stores it in a simple / and probably inefficient database. If someone visits the site it uses the google graph api to make a pretty neat graph of the data over time.
183
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//Cannot use Pins 4,10,11,12,13 as they are in use by ethernet shield
#define ONE_WIRE_BUS 3
 
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
 
// arrays to hold device address
DeviceAddress insideThermometer;
 
void postData();
void pir2ISR();
void getTemp();
 
//Data
float temp = 0.0;
volatile int movement = 0;
volatile int moves =0;
 
// Enter a MAC address for your controller below
byte mac[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
//Server to connect to
char serverName[] = "http://091-labs.appspot.com";
// Initialize the Ethernet client library
EthernetClient client;
 
void setup()
{
  //Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0)
  {
    while(true);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
 
  sensors.begin();
  sensors.getAddress(insideThermometer, 0);
  sensors.setResolution(insideThermometer, 9);
 
  attachInterrupt(0,pir2ISR,RISING); //sets pin 2 as interrupt for movement pin
pinMode(2,INPUT);
}
 
void loop()
{
  delay(60000);
  getTemp();
  if (digitalRead(2)){
    movement=1;
    moves+=1;
  }
  postData();
  moves=0;
  movement=0;
}
 
void pir2ISR()
{
  moves +=1;
  movement =1;
}
 
void postData()
{
  String temperature = String((int)(temp+0.5));
  String move = String(movement);
  String moves1 = String(moves);
  String data = String("temp="+ temperature+"&movement="+move+"&moves="+moves1);
  while(!client.connected())
  {
    client.connect(serverName, 80);
  }
  client.println("POST /arduino_post HTTP/1.1");
  client.println("Host: 091-labs.appspot.com");
  client.println("Connection: keep-alive");
  client.print("Content-Length: ");
  client.println(data.length());
  client.println("Cache-Control: max-age=0");
  client.println("Content-Type: application/x-www-form-urlencoded");
  client.println("Accept-Language: en-US,en;q=0.8");
  client.println();
  client.print(data);
  client.println();
  char c;
  while(client.available())
  {
    c = client.read();
  }
  client.stop();
}
 
void getTemp()
{
  sensors.requestTemperatures();
  temp = sensors.getTempC(insideThermometer);
}

 

More information:

https://nuigarduino.wordpress.com/2012/03/29/arduino-ethernet-shield-motion-sensor-temperature-sensor-google-app-engine-data-logger/

Description:

For our project we wanted to create an Ethernet data logger that could take data from a temperature sensor and a PIR motion sensor.  This would allow us to graph motion and temperature over time allowing users to know when a space was most in use and perhaps whether it was being heated effectively.

Hardware:

• Arduino Uno

• Ethernet Shield( W5100)

• Tempertaure Sensor

• PIR Motion Sensor.

Arduino– The Arduino here connects collects the temperature data and movement data to the Internet as a client and posts data to the Google App Engine site every 60 seconds. An external interrupt allows for motion to be detected and polled at any time. The temperature is read just before the HTTP post is made.
      Google App Engine — On this side the app engine takes the data posted from the Arduino and stores it in a simple / and probably inefficient database. If someone visits the site it uses the google graph api to make a pretty neat graph of the data over time.
183
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//Cannot use Pins 4,10,11,12,13 as they are in use by ethernet shield
#define ONE_WIRE_BUS 3
 
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
 
// arrays to hold device address
DeviceAddress insideThermometer;
 
void postData();
void pir2ISR();
void getTemp();
 
//Data
float temp = 0.0;
volatile int movement = 0;
volatile int moves =0;
 
// Enter a MAC address for your controller below
byte mac[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
//Server to connect to
char serverName[] = "http://091-labs.appspot.com";
// Initialize the Ethernet client library
EthernetClient client;
 
void setup()
{
  //Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0)
  {
    while(true);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
 
  sensors.begin();
  sensors.getAddress(insideThermometer, 0);
  sensors.setResolution(insideThermometer, 9);
 
  attachInterrupt(0,pir2ISR,RISING); //sets pin 2 as interrupt for movement pin
pinMode(2,INPUT);
}
 
void loop()
{
  delay(60000);
  getTemp();
  if (digitalRead(2)){
    movement=1;
    moves+=1;
  }
  postData();
  moves=0;
  movement=0;
}
 
void pir2ISR()
{
  moves +=1;
  movement =1;
}
 
void postData()
{
  String temperature = String((int)(temp+0.5));
  String move = String(movement);
  String moves1 = String(moves);
  String data = String("temp="+ temperature+"&movement="+move+"&moves="+moves1);
  while(!client.connected())
  {
    client.connect(serverName, 80);
  }
  client.println("POST /arduino_post HTTP/1.1");
  client.println("Host: 091-labs.appspot.com");
  client.println("Connection: keep-alive");
  client.print("Content-Length: ");
  client.println(data.length());
  client.println("Cache-Control: max-age=0");
  client.println("Content-Type: application/x-www-form-urlencoded");
  client.println("Accept-Language: en-US,en;q=0.8");
  client.println();
  client.print(data);
  client.println();
  char c;
  while(client.available())
  {
    c = client.read();
  }
  client.stop();
}
 
void getTemp()
{
  sensors.requestTemperatures();
  temp = sensors.getTempC(insideThermometer);
}

 

More information:

https://nuigarduino.wordpress.com/2012/03/29/arduino-ethernet-shield-motion-sensor-temperature-sensor-google-app-engine-data-logger/

COMMENTS

Please Login to comment
  Subscribe  
Notify of