Commit 3bd71040 authored by Rafael Pezzi's avatar Rafael Pezzi
Browse files

Commit inicial da estação meteorolog

 Contém esquemáticos, programa em python de controle e registro
 e firmware para o Arduino de interface com os sensores
 DHT11 - Temperatura e Umidade do Ar
 BMP085 Pressão e Temperatura
 LRD - Luminosidade
 Condutividade do solo
parents
EESchema-LIBRARY Version 2.3 Date: 1/9/2011 10:16:29 PM
#
# ARDUINO_MEGA_SHIELD
#
DEF ARDUINO_MEGA_SHIELD SHIELD 0 40 Y Y 1 F N
F0 "SHIELD" -400 2500 60 H V C CNN
F1 "ARDUINO_MEGA_SHIELD" -100 -2700 60 H V C CNN
DRAW
T 0 0 750 60 0 0 0 Arduino Normal 0 C C
T 0 0 650 60 0 0 0 MEGA Normal 0 C C
S -700 -2600 600 2450 0 1 0 N
P 3 0 1 0 -600 700 500 700 500 700 N
X RX0 0 900 750 300 L 50 50 1 1 B
X TX0 1 900 850 300 L 50 50 1 1 B
X 2 2 900 950 300 L 50 50 1 1 B
X 3 3 900 1050 300 L 50 50 1 1 B
X 4 4 900 1150 300 L 50 50 1 1 B
X 5 5 900 1250 300 L 50 50 1 1 B
X 6 6 900 1350 300 L 50 50 1 1 B
X 7 7 900 1450 300 L 50 50 1 1 B
X 8 8 900 1650 300 L 50 50 1 1 B
X 9 9 900 1750 300 L 50 50 1 1 B
X 10 10 900 1850 300 L 50 50 1 1 B
X SDA 20 900 -50 300 L 50 50 1 1 B
X PC7 30 900 -1500 300 L 50 50 1 1 B
X PG1 40 -1000 -2250 300 R 50 50 1 1 B
X PB3_(MISO) 50 -1000 -1150 300 R 50 50 1 1 B
X 11 11 900 1950 300 L 50 50 1 1 B
X SCL 21 900 -150 300 L 50 50 1 1 B
X PC6 31 900 -1600 300 L 50 50 1 1 B
X PG0 41 -1000 -2150 300 R 50 50 1 1 B
X PB2_(MOSI) 51 -1000 -1050 300 R 50 50 1 1 B
X 12 12 900 2050 300 L 50 50 1 1 B
X PA0 22 900 -650 300 L 50 50 1 1 B
X PC5 32 900 -1700 300 L 50 50 1 1 B
X PL7 42 -1000 -2000 300 R 50 50 1 1 B
X PB1_(SCK) 52 -1000 -950 300 R 50 50 1 1 B
X 13 13 900 2150 300 L 50 50 1 1 B
X PA1 23 900 -750 300 L 50 50 1 1 B
X PC4 33 900 -1800 300 L 50 50 1 1 B
X PL6 43 -1000 -1900 300 R 50 50 1 1 B
X PB0_(SS) 53 -1000 -850 300 R 50 50 1 1 B
X TX3 14 900 550 300 L 50 50 1 1 B
X PA2 24 900 -850 300 L 50 50 1 1 B
X PC3 34 900 -1900 300 L 50 50 1 1 B
X PL5 44 -1000 -1800 300 R 50 50 1 1 B
X RX3 15 900 450 300 L 50 50 1 1 B
X PA3 25 900 -950 300 L 50 50 1 1 B
X PC2 35 900 -2000 300 L 50 50 1 1 B
X PL4 45 -1000 -1700 300 R 50 50 1 1 B
X TX2 16 900 350 300 L 50 50 1 1 B
X PA4 26 900 -1050 300 L 50 50 1 1 B
X PC1 36 900 -2100 300 L 50 50 1 1 B
X PL3 46 -1000 -1600 300 R 50 50 1 1 B
X RX2 17 900 250 300 L 50 50 1 1 B
X PA5 27 900 -1150 300 L 50 50 1 1 B
X PC0 37 900 -2200 300 L 50 50 1 1 B
X PL2 47 -1000 -1500 300 R 50 50 1 1 B
X TX1 18 900 150 300 L 50 50 1 1 B
X PA6 28 900 -1250 300 L 50 50 1 1 B
X PD7 38 -1000 -2450 300 R 50 50 1 1 B
X PL1 48 -1000 -1400 300 R 50 50 1 1 B
X RX1 19 900 50 300 L 50 50 1 1 B
X PA7 29 900 -1350 300 L 50 50 1 1 B
X PG2 39 -1000 -2350 300 R 50 50 1 1 B
X PL0 49 -1000 -1300 300 R 50 50 1 1 B
X 5V 5V -1000 1750 300 R 50 50 1 1 W
X AD0 AD0 -1000 1250 300 R 50 50 1 1 B
X AD1 AD1 -1000 1150 300 R 50 50 1 1 B
X AD2 AD2 -1000 1050 300 R 50 50 1 1 B
X AD3 AD3 -1000 950 300 R 50 50 1 1 B
X 3V3 3V3 -1000 1850 300 R 50 50 1 1 W
X AD4 AD4 -1000 850 300 R 50 50 1 1 B
X AD5 AD5 -1000 750 300 R 50 50 1 1 B
X AD6 AD6 -1000 650 300 R 50 50 1 1 B
X AD7 AD7 -1000 550 300 R 50 50 1 1 B
X AD8 AD8 -1000 350 300 R 50 50 1 1 B
X AD9 AD9 -1000 250 300 R 50 50 1 1 B
X RST RST -1000 1950 300 R 50 50 1 1 I
X AD10 AD10 -1000 150 300 R 50 50 1 1 B
X AD11 AD11 -1000 50 300 R 50 50 1 1 B
X GND1 GND1 -1000 1650 300 R 50 50 1 1 W
X AD12 AD12 -1000 -50 300 R 50 50 1 1 B
X GND2 GND2 -1000 1550 300 R 50 50 1 1 W
X AD13 AD13 -1000 -150 300 R 50 50 1 1 B
X GND3 GND3 900 2250 300 L 50 50 1 1 W
X AD14 AD14 -1000 -250 300 R 50 50 1 1 B
X GND4 GND4 -1000 -600 300 R 50 50 1 1 W
X 5V_4 5V_4 900 -400 300 L 50 50 1 1 W
X AD15 AD15 -1000 -350 300 R 50 50 1 1 B
X GND5 GND5 -1000 -700 300 R 50 50 1 1 W
X 5V_5 5V_5 900 -500 300 L 50 50 1 1 W
X AREF AREF 900 2350 300 L 50 50 1 1 W
X V_IN V_IN -1000 1450 300 R 50 50 1 1 W
ENDDRAW
ENDDEF
#
# ARDUINO_SHIELD
#
DEF ARDUINO_SHIELD SHIELD 0 40 Y Y 1 F N
F0 "SHIELD" -350 950 60 H V C CNN
F1 "ARDUINO_SHIELD" 50 -950 60 H V C CNN
DRAW
S -650 -900 650 900 0 1 0 N
X 0 0 950 -800 300 L 50 50 1 1 B
X 1 1 950 -700 300 L 50 50 1 1 B
X 2 2 950 -600 300 L 50 50 1 1 B
X 3 3 950 -500 300 L 50 50 1 1 B
X 4 4 950 -400 300 L 50 50 1 1 B
X 5 5 950 -300 300 L 50 50 1 1 B
X 6 6 950 -200 300 L 50 50 1 1 B
X 7 7 950 -100 300 L 50 50 1 1 B
X 8 8 950 100 300 L 50 50 1 1 B
X 9 9 950 200 300 L 50 50 1 1 B
X 10 10 950 300 300 L 50 50 1 1 B
X 11 11 950 400 300 L 50 50 1 1 B
X 12 12 950 500 300 L 50 50 1 1 B
X 13 13 950 600 300 L 50 50 1 1 B
X 5V 5V -950 200 300 R 50 50 1 1 W
X AD0 AD0 -950 -300 300 R 50 50 1 1 B
X AD1 AD1 -950 -400 300 R 50 50 1 1 B
X AD2 AD2 -950 -500 300 R 50 50 1 1 B
X AD3 AD3 -950 -600 300 R 50 50 1 1 B
X 3V3 3V3 -950 300 300 R 50 50 1 1 W
X AD4 AD4 -950 -700 300 R 50 50 1 1 B
X AD5 AD5 -950 -800 300 R 50 50 1 1 B
X RST RST -950 400 300 R 50 50 1 1 I
X GND1 GND1 -950 100 300 R 50 50 1 1 W
X GND2 GND2 -950 0 300 R 50 50 1 1 W
X GND3 GND3 950 700 300 L 50 50 1 1 W
X AREF AREF 950 800 300 L 50 50 1 1 W
X V_IN V_IN -950 -100 300 R 50 50 1 1 W
ENDDRAW
ENDDEF
#
#End Library
EESchema Schematic File Version 2 date Seg 04 Mar 2013 21:35:54 BRT
LIBS:power
LIBS:device
LIBS:transistors
LIBS:conn
LIBS:linear
LIBS:regul
LIBS:74xx
LIBS:cmos4000
LIBS:adc-dac
LIBS:memory
LIBS:xilinx
LIBS:special
LIBS:microcontrollers
LIBS:dsp
LIBS:microchip
LIBS:analog_switches
LIBS:motorola
LIBS:texas
LIBS:intel
LIBS:audio
LIBS:interface
LIBS:digital-audio
LIBS:philips
LIBS:display
LIBS:cypress
LIBS:siliconi
LIBS:opto
LIBS:atmel
LIBS:contrib
LIBS:valves
LIBS:arduino_shieldsNCL
EELAYER 24 0
EELAYER END
$Descr A4 11700 8267
Sheet 1 1
Title ""
Date "4 mar 2013"
Rev ""
Comp ""
Comment1 ""
Comment2 ""
Comment3 ""
Comment4 ""
$EndDescr
Text Notes 650 7700 0 60 ~ 0
Centro de Tecnologia Academica - http://cta.if.ufrgs.br
Text Notes 650 7550 0 60 ~ 0
Rafael Pezzi
Text Notes 7500 7550 0 60 ~ 0
Estacao Meteorológica - CTA
Connection ~ 4300 4600
Wire Wire Line
4300 4600 4500 4600
Wire Wire Line
4500 4600 4500 4250
Wire Wire Line
4500 4250 4900 4250
Connection ~ 4300 3650
Wire Wire Line
4300 3950 4300 3650
Wire Wire Line
7750 3150 7150 3150
Wire Wire Line
7150 3150 7150 3250
Wire Wire Line
7150 3250 6800 3250
Wire Wire Line
4900 3550 4800 3550
Wire Wire Line
4800 3550 4800 5400
Wire Wire Line
4800 5400 5500 5400
Wire Wire Line
5500 5700 4700 5700
Wire Wire Line
4700 5700 4700 4650
Wire Wire Line
4700 4650 4900 4650
Wire Wire Line
3900 3850 4050 3850
Wire Wire Line
4050 3850 4400 3850
Wire Wire Line
4400 3850 4400 4950
Wire Wire Line
4400 4950 7250 4950
Wire Wire Line
7250 4950 7250 4250
Wire Wire Line
7250 4250 6800 4250
Wire Wire Line
3900 3650 4300 3650
Wire Wire Line
4300 3650 4900 3650
Wire Wire Line
7750 2950 7400 2950
Wire Wire Line
7400 2950 7400 2700
Wire Wire Line
7400 2700 4500 2700
Wire Wire Line
4500 2700 4500 4150
Wire Wire Line
4500 4150 4900 4150
Wire Wire Line
4900 3750 4150 3750
Wire Wire Line
3900 4150 4150 4150
Wire Wire Line
4250 3150 4050 3150
Wire Wire Line
4050 3150 4050 3850
Connection ~ 4050 3850
Wire Wire Line
4900 4550 4550 4550
Wire Wire Line
4550 4550 4550 5850
Wire Wire Line
4550 5850 5500 5850
Wire Wire Line
4150 5550 5500 5550
Wire Wire Line
4150 3750 4150 4150
Wire Wire Line
4150 4150 4150 5550
Connection ~ 4150 4150
Wire Wire Line
6800 3150 7000 3150
Wire Wire Line
7000 3150 7000 3050
Wire Wire Line
7000 3050 7400 3050
Wire Wire Line
7400 3050 7750 3050
Wire Wire Line
7400 4250 7400 4250
Wire Wire Line
7400 4250 7400 3050
Connection ~ 7400 3050
Wire Wire Line
4300 4450 4300 4600
Wire Wire Line
4300 4600 4300 5100
$Comp
L R R1
U 1 1 5134BB7E
P 4300 4200
F 0 "R1" V 4380 4200 50 0000 C CNN
F 1 "100k" V 4300 4200 50 0000 C CNN
1 4300 4200
-1 0 0 1
$EndComp
Text Notes 5550 5900 0 60 ~ 0
SDA
Text Notes 5550 5750 0 60 ~ 0
SCL
Text Notes 5550 5600 0 60 ~ 0
GND
Text Notes 5550 5450 0 60 ~ 0
Vcc - 3.3 V
Text Notes 4850 5300 0 60 ~ 0
BMP085 - Temperatura e Pressão
$Comp
L PHOTORESISTOR LDR1
U 1 1 5134B800
P 8000 4450
F 0 "LDR1" H 8010 4770 70 0000 C CNN
F 1 "LDR" H 8010 4130 70 0000 C CNN
1 8000 4450
-1 0 0 1
$EndComp
$Comp
L R R2
U 1 1 5134B78D
P 4250 3400
F 0 "R2" V 4330 3400 50 0000 C CNN
F 1 "4k7" V 4250 3400 50 0000 C CNN
1 4250 3400
1 0 0 -1
$EndComp
Text Notes 3350 4150 0 60 ~ 0
4 - GND
Text Notes 3350 4000 0 60 ~ 0
3 - NC
Text Notes 3350 3850 0 60 ~ 0
2 - Data
Text Notes 3350 3700 0 60 ~ 0
1 - Vcc
Text Notes 3450 3550 0 60 ~ 0
DHT11
Text Notes 7800 3000 0 60 ~ 0
sig
Text Notes 7800 3100 0 60 ~ 0
gnd
Text Notes 7800 3200 0 60 ~ 0
vcc
Text Notes 7500 2900 0 60 ~ 0
Sensor Umidade do Solo
$Comp
L ARDUINO_SHIELD Arduino~Uno
U 0 1 512FBC7E
P 5850 3850
F 0 "Arduino Uno" H 5850 4850 60 0000 C CNN
F 1 "ARDUINO1" H 5900 2900 60 0000 C CNN
0 5850 3850
1 0 0 -1
$EndComp
Text Notes 10650 7650 0 60 ~ 0
0.1
Wire Wire Line
7400 4650 7400 5100
Wire Wire Line
7400 5100 4300 5100
Text Notes 3300 3400 0 60 ~ 0
Umidade do Ar
$EndSCHEMATC
// Interface de controle da estacao meteorologica meteorolog
// Centro de Tecnologia Academica - UFRGS
// http://cta.if.ufrgs.br - Março de 2013
// Rafael Pezzi
int soloPinVCC = 13; //Pino VCC do sensor de umidade do solo
int soloPinleitura = 0; //Pino VCC do sensor de umidade do solo
#define LDRpin 1
#define PinoPiezo 9
#define DHTPIN 4 // Pino de dados do DHT11
// Para utilização do DHT11
// Biblioteca desenvolvida por Adafuit
// https://github.com/adafruit/DHT-sensor-library
#include "DHT.h"
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// Configuracao do BMP085
// Fonte: http://bildr.org/2011/06/bmp085-arduino/
#include <Wire.h>
#define BMP085_ADDRESS 0x77 // I2C address of BMP085
const unsigned char OSS = 0; // Oversampling Setting
// Calibration values
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;
// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5;
void setup() {
//Inicialização do DHT11
dht.begin();
// Configuração do BPM085
Wire.begin();
bmp085Calibration();
Serial.begin(115200);
// Configura pino de alimentação do sensor de umidade do solo
pinMode(soloPinVCC, OUTPUT);
}
void loop()
{
if (Serial.available())
{
switch (Serial.read())
{
case 'p':
pressao();
break;
case 'l':
luminosidade();
break;
case 'u':
umidade_ar();
break;
case 's':
umidade_solo();
break;
case 't':
temperatura_BMP085();
break;
case 'T':
leDHT11_temp();
break;
default:
break;
}
}
}
void temperatura_BMP085()
{
float temperature = bmp085GetTemperature(bmp085ReadUT()); //MUST be called first
Serial.println(temperature, 2); //display 2 decimal places
}
void pressao()
{
float temperature = bmp085GetTemperature(bmp085ReadUT()); //MUST be called first
float pressure = bmp085GetPressure(bmp085ReadUP());
Serial.println(pressure, 0); //whole number only.
}
void umidade_ar()
{
leDHT11_umid();
}
void luminosidade()
{
int lum=analogRead(LDRpin);
Serial.println(1023-lum);
}
void umidade_solo()
{
digitalWrite(soloPinVCC,HIGH);
delay(300);
int us1 = analogRead(soloPinleitura);
delay(10);
int us2 = analogRead(soloPinleitura);
delay(10);
int us3 = analogRead(soloPinleitura);
delay(10);
int us4 = analogRead(soloPinleitura);
delay(10);
int us5 = analogRead(soloPinleitura);
int umidsolo = (us1+us2+us3+us4+us5)/5;
// Serial.print("Umidade do solo: ");
Serial.println(umidsolo);
digitalWrite(soloPinVCC,LOW);
}
void leDHT11_temp()
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) ) {
Serial.println("Failed to read from DHT");
} else {
// Serial.print("Temperatura: ");
Serial.println(t);
// Serial.println(" *C");
}
}
void leDHT11_umid()
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
// Serial.print("Umidade relativa do ar: ");
Serial.println(h);
// Serial.println(" %\t");
}
}
// Stores all of the bmp085's calibration values into global variables
// Calibration values are required to calculate temp and pressure
// This function should be called at the beginning of the program
void bmp085Calibration()
{
ac1 = bmp085ReadInt(0xAA);
ac2 = bmp085ReadInt(0xAC);
ac3 = bmp085ReadInt(0xAE);
ac4 = bmp085ReadInt(0xB0);
ac5 = bmp085ReadInt(0xB2);
ac6 = bmp085ReadInt(0xB4);
b1 = bmp085ReadInt(0xB6);
b2 = bmp085ReadInt(0xB8);
mb = bmp085ReadInt(0xBA);
mc = bmp085ReadInt(0xBC);
md = bmp085ReadInt(0xBE);
}
// Calculate temperature in deg C
float bmp085GetTemperature(unsigned int ut){
long x1, x2;
x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
x2 = ((long)mc << 11)/(x1 + md);
b5 = x1 + x2;
float temp = ((b5 + 8)>>4);
temp = temp /10;
return temp;
}
// Calculate pressure given up
// calibration values must be known
// b5 is also required so bmp085GetTemperature(...) must be called first.
// Value returned will be pressure in units of Pa.
long bmp085GetPressure(unsigned long up){
long x1, x2, x3, b3, b6, p;
unsigned long b4, b7;
b6 = b5 - 4000;
// Calculate B3
x1 = (b2 * (b6 * b6)>>12)>>11;
x2 = (ac2 * b6)>>11;
x3 = x1 + x2;
b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
// Calculate B4
x1 = (ac3 * b6)>>13;
x2 = (b1 * ((b6 * b6)>>12))>>16;
x3 = ((x1 + x2) + 2)>>2;
b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
b7 = ((unsigned long)(up - b3) * (50000>>OSS));
if (b7 < 0x80000000)
p = (b7<<1)/b4;
else
p = (b7/b4)<<1;
x1 = (p>>8) * (p>>8);
x1 = (x1 * 3038)>>16;
x2 = (-7357 * p)>>16;
p += (x1 + x2 + 3791)>>4;
long temp = p;
return temp;
}
// Read 1 byte from the BMP085 at 'address'
char bmp085Read(unsigned char address)
{
unsigned char data;
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(BMP085_ADDRESS, 1);
while(!Wire.available())
;
return Wire.read();
}
// Read 2 bytes from the BMP085
// First byte will be from 'address'
// Second byte will be from 'address'+1
int bmp085ReadInt(unsigned char address)
{
unsigned char msb, lsb;
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(BMP085_ADDRESS, 2);
while(Wire.available()<2)
;
msb = Wire.read();
lsb = Wire.read();
return (int) msb<<8 | lsb;
}
// Read the uncompensated temperature value
unsigned int bmp085ReadUT(){
unsigned int ut;
// Write 0x2E into Register 0xF4
// This requests a temperature reading
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(0xF4);
Wire.write(0x2E);
Wire.endTransmission();
// Wait at least 4.5ms
delay(5);
// Read two bytes from registers 0xF6 and 0xF7