changed temperature sensor

sensor-connect
033zhek 1 year ago
parent 97528622db
commit 8624f652f2

@ -2,10 +2,7 @@
float Sensor::temperatureSensor(){ float Sensor::temperatureSensor(){
tempSens->requestTemperatures(); return analogRead(TEMP_SENS);
while (!tempSens->isConversionComplete());
float temp = tempSens->getTempCByIndex(1);
return temp;
} }
float Sensor::humiditySensor(){ float Sensor::humiditySensor(){

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "Arduino.h" #include "Arduino.h"
#include "DallasTemperature.h"
#include "DHT.h" #include "DHT.h"
#include "math.h"
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
// Pins Definitions // Pins Definitions
@ -14,9 +14,6 @@
class Sensor{ class Sensor{
private: private:
// KY-001
OneWire *oneWire;
DallasTemperature *tempSens;
//KY-015 //KY-015
DHT *dht; DHT *dht;
@ -28,12 +25,7 @@ class Sensor{
Sensor() Sensor()
{ {
oneWire = new OneWire(TEMP_SENS);
tempSens = new DallasTemperature(oneWire);
dht = new DHT(HUM_SENS, DHT11); dht = new DHT(HUM_SENS, DHT11);
tempSens->begin();
dht->begin(); dht->begin();
} }
}; };

@ -19,10 +19,38 @@ uint16_t getMockSensorData() {
} }
void loop() { void loop() {
MeasureData measureData; MeasureData measureData_temp;
measureData.sensor_id = 0xA5; measureData_temp.sensor_id = 0xA5;
measureData.sensor_type = 0x01; measureData_temp.sensor_type = 0x01;
measureData.payload = getMockSensorData(); measureData_temp.payload = sensors.temperatureSensor();
transmissionModule.transmit(measureData_temp);
delay(100);
MeasureData measureData_hum;
measureData_hum.sensor_id = 0xA5;
measureData_hum.sensor_type = 0x02;
measureData_hum.payload = sensors.humiditySensor();
transmissionModule.transmit(measureData_hum);
delay(100);
MeasureData measureData_photo;
measureData_photo.sensor_id = 0xA5;
measureData_photo.sensor_type = 0x03;
measureData_photo.payload = sensors.photoSensor();
transmissionModule.transmit(measureData_photo);
delay(100);
MeasureData measureData_vibro;
measureData_vibro.sensor_id = 0xA5;
measureData_vibro.sensor_type = 0x04;
measureData_vibro.payload = sensors.photoSensor();
transmissionModule.transmit(measureData_vibro);
delay(100);
Serial.print(sensors.humiditySensor(), DEC); Serial.print(sensors.humiditySensor(), DEC);
Serial.print(" "); Serial.print(" ");
Serial.print(sensors.temperatureSensor(), DEC); Serial.print(sensors.temperatureSensor(), DEC);
@ -30,6 +58,6 @@ void loop() {
Serial.print(sensors.photoSensor(), DEC); Serial.print(sensors.photoSensor(), DEC);
Serial.print(" "); Serial.print(" ");
Serial.println(sensors.vibroSensor(), DEC); Serial.println(sensors.vibroSensor(), DEC);
transmissionModule.transmit(measureData);
delay(100); delay(100);
} }
Loading…
Cancel
Save