Hi all
I am working on me bee hive monitor and am happy so far with what I have achieved.
But a but stumped on this one.
When I load my microphone sketch by its self I get good reading from the mic (if a little high) but when I include the code in my temp and humidity sketch, I get substantially higher readings for the mic.
Attached is the code and screenshots of the readings
Code for Microphone sketch
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
void setup()
{
Serial.begin(9600);
}
void loop()
{
unsigned long startMillis= millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(A0);
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
double volts = ((peakToPeak * 3.3) / 1024) * 0.707; // convert to volts
double first = log10(volts/0.00631)*20; // The microphone sensitivity is -44 ±2 so V RMS / PA is 0.00631
double second = first + 94 - 44; // The microphone sensitivity is -44 ±2
Serial.println("Db "+String(second));
}
Code for temp and humidity sketch
[code]
/*
* Rui Santos
* Complete Project Details https://randomnerdtutorials.com
*/
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHT.h"
#define DHTPIN 4 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
#define ONE_WIRE_BUS 15 // Data wire is connected to GPIO15
// Setup a oneWire instance to communicate with a OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
DeviceAddress sensor1 = { 0x28, 0x6A, 0x48, 0x7C, 0x0C, 0x00, 0x00, 0xC4 };
DeviceAddress sensor2 = { 0x28, 0xFA, 0x14, 0x7B, 0x0C, 0x00, 0x00, 0x47 };
//DeviceAddress sensor3= { 0x28, 0xFF, 0xA0, 0x11, 0x33, 0x17, 0x3, 0x96 };
DHT dht(DHTPIN, DHTTYPE);
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
void setup(void)
{
Serial.begin(9600);
sensors.begin();
dht.begin();
}
void loop(void){
//Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
// Serial.println("DONE");
Serial.print("Brood Box: ");
Serial.print(sensors.getTempC(sensor1));
Serial.print("°C: ");
Serial.print("Flow Super: ");
Serial.print(sensors.getTempC(sensor2));
Serial.print("°C: ");
// 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();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Roof Humidity: "));
Serial.print(h);
Serial.print(F("% Roof Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
{
unsigned long startMillis= millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(A0);
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
double volts = ((peakToPeak * 3.3) / 1024) * 0.707; // convert to volts
double first = log10(volts/0.00631)*20; // The microphone sensitivity is -44 ±2 so V RMS / PA is 0.00631
double second = first + 94 - 44; // The microphone sensitivity is -44 ±2
Serial.println(" Db "+String(second));
}
Serial.print('\n');
delay(2000);
}
[/code]