Fasensor

From Futuragora Wiki
Revision as of 21:01, 21 July 2018 by Reset (talk | contribs)

Fasensor é um sensor montado a partir de um arduino, com sensor de temperatura, humidade e pressão atmosférica. Pode consultar o projecto em:

Dados recolhidos: Temperatura, Humidade, Pressão Atmosférica


Opensenses Page

Fasensor

Componentes

Arduino ethernet

BMP085

DHT11


Be the change!

Code Test sensors

#include <Wire.h>
#include <Adafruit_BMP085.h>

/*************************************************** 
  This is an example for the BMP085 Barometric Pressure & Temp Sensor

  Designed specifically to work with the Adafruit BMP085 Breakout 
  ----> https://www.adafruit.com/products/391

  These displays use I2C to communicate, 2 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/
#include "DHT.h"

#define DHTPIN A1     // what digital pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT11   // DHT 22  (AM2302), AM2321

// Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!)
// Connect GND to Ground
// Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
// Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
// EOC is not used, it signifies an end of conversion
// XCLR is a reset pin, also not used here
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085 bmp;




double Fahrenheit(double celsius)
{
  return 1.8 * celsius + 32;
}

// fast integer version with rounding
//int Celcius2Fahrenheit(int celcius)
//{
//  return (celsius * 18 + 5)/10 + 32;
//}


//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
  return celsius + 273.15;
}

// dewPoint function NOAA
// reference (1) : http://wahiduddin.net/calc/density_algorithms.htm
// reference (2) : http://www.colorado.edu/geography/weather_station/Geog_site/about.htm
//
double dewPoint(double celsius, double humidity)
{
  // (1) Saturation Vapor Pressure = ESGG(T)
  double RATIO = 373.15 / (273.15 + celsius);
  double RHS = -7.90298 * (RATIO - 1);
  RHS += 5.02808 * log10(RATIO);
  RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
  RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
  RHS += log10(1013.246);

        // factor -3 is to adjust units - Vapor Pressure SVP * humidity
  double VP = pow(10, RHS - 3) * humidity;

        // (2) DEWPOINT = F(Vapor Pressure)
  double T = log(VP/0.61078);   // temp var
  return (241.88 * T) / (17.558 - T);
}

// delta max = 0.6544 wrt dewPoint()
// 6.9 x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
  double Td = (b * temp) / (a - temp);
  return Td;
}



  
void setup() {
  Serial.begin(9600);
  if (!bmp.begin()) {
  Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  while (1) {}
  }
}
void loop() {
    Serial.print("Humidity = ");
    Serial.print(dht.readHumidity());
    Serial.println(" *H");
    
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
    
    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
    
    // Calculate altitude assuming 'standard' barometric
    // pressure of 1013.25 millibar = 101325 Pascal
    Serial.print("Altitude = ");
    Serial.print(bmp.readAltitude());
    Serial.println(" meters");

  // you can get a more precise measurement of altitude
  // if you know the current sea level pressure which will
  // vary with weather and such. If it is 1015 millibars
  // that is equal to 101500 Pascals.
    Serial.print("Real altitude = ");
    Serial.print(bmp.readAltitude(101500));
    Serial.println(" meters");
    
    Serial.println();
    delay(5000);
}

PHP and Mysql

Create a database with three tables: temperature, humidity, pressure. Use the following code:


Add 2 files to your server: connect.php and add.php:


 
<?php 
    include("conec.php"); 
    $link=Conection(); 
    $timestamp=date('Y-m-d H:i:s'); 

mysql_query("insert into temperature (timestamp,temperature)  values  ('$timestamp', '".$_REQUEST["temperature"]."')"); 
mysql_query ("insert into pressure (timestamp,pressure)  values  ('$timestamp', '".$_REQUEST["pressure"]."')"); 
mysql_query ("insert into humidity (timestamp,humidity)  values  ('$timestamp', '".$_REQUEST["humidity"]."')"); 
mysql_query ("insert into temperature2 (timestamp,temperature2)  values  ('$timestamp', '".$_REQUEST["temperature2"]."')"); 
mysql_query ("insert into dew (timestamp,dew)  values ('$timestamp',  '".$_REQUEST["dew"]."')"); 
mysql_query ("insert into light (timestamp,light)  values ('$timestamp',  '".$_REQUEST["light"]."')"); 
?> 




Code

Libraries

https://github.com/adafruit/Adafruit_Sensor


PHP Code Arduino Mysql

Create Table:

CREATE TABLE `fasensor7`.`temperature` (
`id` INT( 255 ) NOT NULL AUTO_INCREMENT ,
`timestamp` VARCHAR( 255 ) NOT NULL ,
`temperature` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;

CREATE TABLE `fasensor7`.`pressure` (
`id` INT( 255 ) NOT NULL AUTO_INCREMENT ,
`timestamp` VARCHAR( 255 ) NOT NULL ,
`pressure` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;

CREATE TABLE `fasensor7`.`humidity` (
`id` INT( 255 ) NOT NULL AUTO_INCREMENT ,
`timestamp` VARCHAR( 255 ) NOT NULL ,
`temperature` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;

CREATE TABLE `fasensor7`.`light` (
`id` INT( 255 ) NOT NULL AUTO_INCREMENT ,
`timestamp` VARCHAR( 255 ) NOT NULL ,
`pressure` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;