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. http://www.instructables.com/id/Arduino-Wind-Chill-Machine/
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: ");
Serial.println(str);
while(1);
}
void setup(void)
{
analogReference(EXTERNAL); //3.3V connected to AREF thru 3.3K AREF=3VDC
int dummy=analogRead(ThermPin); //discard first analogRead
Serial.begin(9600);
Serial.println();
pinMode(WindPin,INPUT);
#if WAIT_TO_START
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)
{
SeeHigh=true;
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
CntPeriod=CntPeriod+millis()-StartPeriod;
}
StartPeriod=millis();
//Increment counter
CntRPM++;
SeeHigh=false;
digitalWrite(greenLEDpin,HIGH);
}
if ((millis()-StartTime)>long(LogInterval)) // Log Interval has passed
{
// Do Wind calculations for LogInterval
// RPM is calculated, Period is averaged
RPM=CntRPM*(60.0/SampInterval);
AvPeriod=CntPeriod/(CntRPM-1);
MPH=RPM*.054; //Estimate
// Get temperature readings Average nsamps
for (byte j=0;j<nsamp;j++)
{
ThermValue += analogRead(ThermPin);
}
ThermValueAvg=ThermValue/nsamp;
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
TempF=TempC*(9.0/5.0)+32;
//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))
{
Twc=35.74+0.6215*TempF-35.75*pow(MPH,0.16)+0.4275*TempF*pow(MPH,0.16);
}
else
{
Twc=TempF;
}
ThermValue=0; //Clear Buffers
Serial.print("$, ");
Serial.print(TempF,1);
Serial.print(", ");
Serial.print(RPM,1);
Serial.print(", ");
Serial.print(MPH,1);
Serial.print(", ");
Serial.print(Twc,1);
StartTime=millis();
Serial.println();
StartTime = millis(); //Get StartTime for next LogInterval
// Clear variables for next LogInterval
digitalWrite(greenLEDpin, LOW);
SeeHigh=false;
CntRPM=0;
AvPeriod=0.0;
}
}
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(){
Serial.begin(9600);
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
DHT.read11(dht_apin);
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(5000);//Wait 5 seconds before accessing sensor again.
//Fastest should be once every two seconds.
}// end loop()