Weather sensors dht11 + hall sensor anemometer

Hello all,

I am new here and new to the world of arduino and a complete noob when it comes to coding.

To the point…

I am working on a small project to build a weather station for my area and the hopes of using it for amateur radio weather spotting information in my area.

I have put together so far a Anemometer with a few plastic cups some PVC and a hall sensor. I also added a dht11 for temperature / humidity readings.

I have been able to get both codes to work just fine but I am unable to stitch them together and make them work as one.

A high level overview of the setup is the following.

  • plastic cups spinning with 2 magnets triggering a hall sensor
  • a hall sensor connected to 5v + ground and a 10k resistor to the arduino
  • the dht11 temp / humidity sensor is also connected to the same 5v and ground but a different data line to the arduino.
  • using a 4wire phone cord from the sensor on the anemometer / temp to the arduino in the house.

everything is wired up to the 4 wires using 5v + gnd + A2 for the dht11 and D4 for the hall sensor.

My hall sensor code was found by searching around and copied, it has stuff in it that I do not think I need from a different temp sensor the original creator used. I found the code here and mostly copied this project with a few changes to my design.

The code is nice in the fact that it also calculates wind chill based on temp and wind speed, I would like to try and maintain that feature and add my dht11 sensor into it if possible.

here is the code that works for my anemometer.

#####Anemometer / Hall Sensor code####

#include <Wire.h>

// An anemometer for the Arduino
int LogInterval;
int SampInterval=2; //Number of seconds in the LogInterval

#define WAIT_TO_START    0 // Wait for serial input in setup()

const byte nsamp=10;

// the digital pins that connect to the LEDs
//#define redLEDpin 2
#define greenLEDpin 3
#define WindPin 4

// Wind variables
bool SeeHigh=false;
int CntRPM=0;
unsigned long CntPeriod=0;
float RPM=0.0;
float AvPeriod=0.0;
float MPH=0.0;
float Twc=0.0; //Wind chill Temperature

// Timing counters
unsigned long StartTime; //Log Interval counter
unsigned long StartPeriod=0; // Period Start
unsigned long timeSense=0;

// Analog pins
int ThermPin=2; //MPC9701 thermal sensor

unsigned int ThermValue = 0;  // value coming from thermal sensor
int ThermValueAvg;
float mVout; // Temp voltage in mV 
float TempC=0.0;
float TempF=0.0;

void error(char *str)
 Serial.print("error: ");

void setup(void)
 analogReference(EXTERNAL); //3.3V connected to AREF thru 3.3K AREF=3VDC
 int dummy=analogRead(ThermPin); //discard first analogRead
Serial.println("Type any character to start");
while (!Serial.available());
#endif //WAIT_TO_START

Serial.println("TempF, RPM, MPH, Twc");

LogInterval=SampInterval*1000; //  sec between entries
StartTime=millis(); //Initialize StartTime

void loop(void)
// Wind calculator Look for High
if (digitalRead(WindPin)==HIGH)
digitalWrite(greenLEDpin, LOW);
//Look for Low thus a High to Low transistion
else if (SeeHigh==true)
if (StartPeriod != 0) //Not first sampleFrt
 // Number of milliseconds in a revolution, added together
//Increment counter
if ((millis()-StartTime)>long(LogInterval))  // Log Interval has passed
// Do Wind calculations for LogInterval
// RPM is calculated, Period is averaged
MPH=RPM*.054; //Estimate
// Get temperature readings Average nsamps
for (byte j=0;j<nsamp;j++)
ThermValue += analogRead(ThermPin);    

mVout=(float) ThermValueAvg*3000.0/1023.0; //3.0V = 3000mV
//TempC=(mVout-400.0)/19.5; //Ta = (Vout-400mV)/19.5mV //Original
//TempC=(mVout-580.0)/19.5; //Ta = (Vout-400mV)/19.5mV  //Modified
TempC=(mVout-490.0)/19.5; //Ta = (Vout-400mV)/19.5mV  //Modified

//Wind Chill formula Twc=35.74+0.6215Tf-35.75MPH 0.16 +0.4275TfMPH 0.16
//double pow (double base, double exponent )
if ((TempF <50.0) && (MPH > 3.0))
ThermValue=0; //Clear Buffers

Serial.print("$, ");
Serial.print(", ");
Serial.print(", ");    
Serial.print(", ");    


StartTime = millis(); //Get StartTime for next LogInterval
// Clear variables for next LogInterval
digitalWrite(greenLEDpin, LOW);

Here is the code that works for my dht11 temp/humidity sensor.

#####DHT11 Temp / Humidity code####

#include <DHT.h>
#define dht_apin A0 // Analog Pin sensor is connected to

dht DHT;

void setup(){

 delay(500);//Delay to let system boot
 Serial.println("DHT11 Humidity & temperature Sensor\n\n");
 delay(1000);//Wait before accessing Sensor

}//end "setup()"

void loop(){
 //Start of Program 

   Serial.print("Current humidity = ");
   Serial.print("%  ");
   Serial.print("temperature = ");
   Serial.println("C  ");
   delay(5000);//Wait 5 seconds before accessing sensor again.

 //Fastest should be once every two seconds.

}// end loop()

Your first code already handles Temperature reading look at the code after      // Get temperature readings Average nsamps piece so that's where your DHT reading would go (and take into account that your DHT cannot be read nsamp times in a very quick fashion)

Some variables dealing with timing would be declared as unsigned long

Don't create delay or you might miss some wind high low or low high transitions. May be you need to explore interrupts if winds can be high where you are or only read T° once in a while, usually does not change very quickly (like reading every 2 seconds is not needed)

Thank you for your advice, I will play around and remove delay on the wind speed.