Страница 1 из 1
Arduino Uno + AM2301+BMP180+RainSensor
Добавлено: Пт фев 20, 2015 5:46 pm
visitor2100
Добрый день.
Подскажите пожалуйста начинающему...
Есть такие устройства: Arduino Uno, AM2301, BMP180, RainSensor, сервер на Debian c Majordome.
На первом этапе хочу подключить Arduino к ПК по USB.
Датчики все подключил, через монитор последовательного порта вижу данные, все работает.
Как мне эти данные отправлять по USB на сервер и затем выводить информацию в Majordome.
Спасибо. Буду рад даже ссылке на подобный проект.
Re: Arduino Uno + AM2301+BMP180+RainSensor
Добавлено: Пт фев 20, 2015 10:53 pm
Anton_kulibin
Re: Arduino Uno + AM2301+BMP180+RainSensor
Добавлено: Пт фев 20, 2015 11:21 pm
visitor2100
Спасибо за быстрый ответ. Изучил, завтра буду пробовать.
Re: Arduino Uno + AM2301+BMP180+RainSensor
Добавлено: Пт фев 20, 2015 11:24 pm
visitor2100
Можете одним глазом глянуть скетч, а то там сборная солянка, может подправить что то надо.
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include "dht.h"
#include "Wire.h"
#include "BMP085.h"
#define DHTPIN 2 // what pin we're connected to
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// lowest and highest sensor readings:
const int sensorMin = 0; // sensor minimum
const int sensorMax = 1024; // sensor maximum
DHT dht(DHTPIN, DHTTYPE);
BMP085 dps = BMP085();
long Temperature = 0, Pressure = 0, Altitude = 0;
void setup() {
Serial.begin(9600);
//sensors.setResolution(Temperature, 10);
//sensors.setResolution(Humidity, 10);
Wire.begin();
delay(10000);
// uncomment for different initialization settings
//dps.init(); // QFE (Field Elevation above ground level) is set to 0 meters.
// same as init(MODE_STANDARD, 0, true);
//dps.init(MODE_STANDARD, 101850, false); // 101850Pa = 1018.50hPa, false = using Pa units
// this initialization is useful for normalizing pressure to specific datum.
// OR setting current local hPa information from a weather station/local airport (QNH).
dps.init(MODE_STANDARD, 14200, true); // 250 meters, true = using meter units
// this initialization is useful if current altitude is known,
// pressure will be calculated based on TruePressure and known altitude.
// note: use zeroCal only after initialization.
// dps.zeroCal(101800, 0); // set zero point
Serial.println("DHT21 test!");
dht.begin();
}
void loop() {
// 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();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
//if (isnan(t) || isnan(h)) {
// Serial.println("Failed to read from DHT");
dps.getTemperature(&Temperature);
dps.getPressure(&Pressure);
dps.getAltitude(&Altitude);
// } else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
// }
Serial.print(" Temp(C):");
Serial.print(Temperature*0.1,1);
Serial.print(" Pressure(mm):");
Serial.println(Pressure/133.3,1);
Serial.print(" Alt(m):");
Serial.print(Altitude*0.01);
//Rain Sensor
// read the sensor on analog A0:
int sensorReading = analogRead(A0);
// map the sensor range (four options):
// ex: 'long int map(long int, long int, long int, long int, long int)'
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
// range value:
switch (range) {
case 0: // Sensor getting wet
Serial.println("Rain");
break;
case 1: // Sensor getting wet
Serial.println("Rain Warning");
break;
case 2: // Sensor dry - To shut this up delete the " Serial.println("Not Raining"); " below.
Serial.println("Not Raining");
break;
}
delay(10000);
}