no temp, others work

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

@ -0,0 +1,31 @@
#include <Sensors.h>
float Sensor::temperatureSensor(){
tempSens->requestTemperatures();
while (!tempSens->isConversionComplete());
float temp = tempSens->getTempCByIndex(1);
return temp;
}
float Sensor::humiditySensor(){
float h = dht->readHumidity();
if (isnan(h)) {
return -1;
}
else{
return h;
}
}
int Sensor::photoSensor(){
int value = analogRead(PHOTO_SENS);
return value;
}
int Sensor::vibroSensor(){
int value = analogRead(VIBRO_SENS);
return value;
}

@ -0,0 +1,39 @@
#pragma once
#include "Arduino.h"
#include "DallasTemperature.h"
#include "DHT.h"
///////////////////////////////////////////////////////
// Pins Definitions
///////////////////////////////////////////////////////
#define HUM_SENS 33
#define TEMP_SENS 32
#define PHOTO_SENS 25
#define VIBRO_SENS 26
class Sensor{
private:
// KY-001
OneWire *oneWire;
DallasTemperature *tempSens;
//KY-015
DHT *dht;
public:
float temperatureSensor();
float humiditySensor();
int photoSensor();
int vibroSensor();
Sensor()
{
oneWire = new OneWire(TEMP_SENS);
tempSens = new DallasTemperature(oneWire);
dht = new DHT(HUM_SENS, DHT11);
tempSens->begin();
dht->begin();
}
};

@ -16,3 +16,7 @@ monitor_speed = 115200
lib_deps =
mikem/RadioHead@^1.120
rweather/Crypto@^0.4.0
paulstoffregen/OneWire@^2.3.7
milesburton/DallasTemperature@^3.11.0
adafruit/DHT sensor library@^1.4.4
adafruit/Adafruit Unified Sensor@^1.1.13

@ -2,10 +2,12 @@
#include "TransmitterModule.h"
#include "TransmissionModule.h"
#include "ReedSolomonModule.h"
#include "Sensors.h"
TransmitterModule transmitterModule;
ReedSolomonModule reedSolomonModule;
TransmissionModule transmissionModule(transmitterModule, reedSolomonModule);
Sensor sensors;
void setup() {
Serial.begin(115200);
@ -21,6 +23,13 @@ void loop() {
measureData.sensor_id = 0xA5;
measureData.sensor_type = 0x01;
measureData.payload = getMockSensorData();
Serial.print(sensors.humiditySensor(), DEC);
Serial.print(" ");
Serial.print(sensors.temperatureSensor(), DEC);
Serial.print(" ");
Serial.print(sensors.photoSensor(), DEC);
Serial.print(" ");
Serial.println(sensors.vibroSensor(), DEC);
transmissionModule.transmit(measureData);
delay(1000);
delay(100);
}
Loading…
Cancel
Save