Nathaniel ShepherdJohn Driver
Published

Simon's Weather Station For MEGR 3171

A dual sensor weather station measuring Wind Speed and Temperature.

IntermediateWork in progress10 hours11
Simon's Weather Station For MEGR 3171

Things used in this project

Hardware components

Adafruit Anemometer Wind Speed Sensor w/Analog Voltage Output
×1
Argon
Particle Argon
×2
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×15
NI myDAQ with LabVIEW and Multisim 30-day Evaluation Software
Digilent NI myDAQ with LabVIEW and Multisim 30-day Evaluation Software
Temporary Power Supply
×1
HiLetgo 2pcs DHT22/AM2302 Digital Temperature And Humidity Sensor Module
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Plier, Needle Nose
Plier, Needle Nose

Story

Read more

Schematics

Wind Speed Schematic

The Adafruit Wind Speed Sensor connects to the Particle Argon by three wires. Brown wire goes to 15V Power Supply. Blue Wire is the signal, so it connects to any pin on the argon between A0 and A5. The Black is signal ground, so it connects to the ground on the argon. The argon is powered by a USB connection.

Temperature Sensor Circuit Diagram

Code

Wind Speed Sensor

C/C++
The code reads an analog DC voltage from one of the analog pins on the Particle Argon. That data is read as an integer between 0 and 4096. This number is converted from an integer to a DC Voltage output between 0 and 3.3V. Then this is converted to m/s and then MPH. The final wind speed is sent to Thing Speak. Note Channel and API key are blank on purpose.
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

// SYNTAX



int analogPin = A0;             
float val;                    
float WindSpeed;
float voltage;
int receivedinteger =0; 
int led = D7;
int Trigger;
int Light_Position;
TCPClient client;

unsigned long myChannelNumber = 1909363;    // change this to your channel number
const char * myWriteAPIKey = "6NX3IH7VQMRQA9BW"; // change this to your channels write API key

void setup()
{
ThingSpeak.begin(client);
Serial.begin(9600);
//Particle.subscribe("Simon's Weather Station Wind Speed", myHandler, MY_DEVICES);  //subscribes to 
//pinMode(led, OUTPUT);

Particle.subscribe("Air Temp", myHandler_temp, MY_DEVICES);  //subscribes to 
pinMode(led, OUTPUT);
}




void loop()
{
  
val = analogRead(analogPin);
delay(15s);
float voltage = val *(3.3/4096);

if (voltage < 0.42)
        WindSpeed = 0;
    else
    {
	// Convert voltage to 0 to 1.6, then multiply by 20 to make it 0 to 32.
        WindSpeed = (voltage * 20.506) - 8.6127;
    }

// Convert m/s to mph. The range is 0 to 72
WindSpeed = WindSpeed * 2.237;

Particle.publish("Wind Speed", String(WindSpeed));






char eventData[100];
sprintf(eventData, "%.5f", voltage);
Particle.publish("Voltage", eventData, 60, PRIVATE);

sprintf(eventData, "%.5f", val);
Particle.publish("val", eventData, 60, PRIVATE);

sprintf(eventData, "%.5f", WindSpeed);
Particle.publish("Wind Speed", eventData, 60, PRIVATE);


// print out the value you read:

ThingSpeak.writeField(myChannelNumber, 2, WindSpeed, myWriteAPIKey);


	
}
 
 
void myHandler(const char *event, const char *data) {
  // Handle the integration response
}

void myHandler_temp(const char *event, const char *temp) {
     receivedinteger = String(temp).toInt();  //converts char array to string and then to a int
     
     if (receivedinteger >= 35){
     
     digitalWrite(led, HIGH);
     
     }
     else{
     
     digitalWrite(led, LOW);
     }
}

Temperature Sensor Code

C/C++
The code reads the temperature sensor reading from the analog pins on the Particle Argon. The temperature reading is sent to Thing Speak for both John and Nathaniel.
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>

// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>


#define DHTPIN D2   //declares pin D6 as the DHT sensor pin
#define DHTTYPE DHT22   //delcares the DHT sensors as a type 11 sensor
#define INTERVAL 20000
const pin_t MY_LED = D7;
int receivedinteger = 0;
float receivedfloat = 0;
int led = D7;

int Trigger;
int Light_Position;
DHT dht(DHTPIN, DHTTYPE);

// Declare globa variables for the readings and the time last checked
double temp;
double hum;
unsigned long lastCheck = 0;

TCPClient client;       // Open the TCP Client

unsigned long myChannelNumber = 1956444;    // change this to your channel number
const char * myWriteAPIKey = "M26MZGB0KV86T0F4"; // change this to your channels write API key
unsigned long myChannelNumber1 = 1909363;     //Since Humidity and Temperature, need 2 Thingspeak Channels
const char * myWriteAPIKey1 = "6NX3IH7VQMRQA9BW";


// Function that can be called from the Particle console
void readSensor() {
    hum = dht.getHumidity();
    temp = dht.getTempCelcius();
}

// Callback function to allow the Particle console access to readSensor()
int checkHandler(String command) {
readSensor();
return 1;
}
 


void setup() {
    ThingSpeak.begin(client);     // Begin Thingspeak client
    dht.begin();

    // Declare variables that can be seen in the Particle console
    Particle.variable("temperature", temp);
    Particle.variable("humidity", hum);
    Particle.function("readSensor", checkHandler);
    

    Particle.subscribe("Wind Speed", myHandler_wind, MY_DEVICES);
    pinMode(led, OUTPUT);
    
    

 
}

void loop() {
    
    
    if (lastCheck + INTERVAL < millis()) {
        lastCheck = millis();
        readSensor();

        // Check if any reads failed and exit early (to try again).
        if (isnan(hum) || isnan(temp)) {
            Serial.println("Failed to read from DHT sensor!");
            return;

             // Get some data

  String data = String(10);
  // Trigger the integration
  Particle.publish("temperature", data, PRIVATE);
  Particle.publish("humidity", data, PRIVATE);
    }
        
Particle.publish("Air Temp", String(temp));
delay(15s);


ThingSpeak.writeField(myChannelNumber, 1, String(temp), myWriteAPIKey); 
//Thingspeak for 1st Channel (Temp)
ThingSpeak.writeField(myChannelNumber1, 1, String(temp), myWriteAPIKey1);

}


}

void myHandler(const char *event, const char *data) {
  // Handle the integration response
}

void myHandler_wind(const char *event, const char *data) {
     receivedinteger = String(data).toInt();  //converts char array to string and then to a int
     
     if (receivedinteger > 700){
     
     digitalWrite(led, HIGH);
     
     }
     else{
     
     digitalWrite(led, LOW);
     }
}

Credits

Nathaniel Shepherd

Nathaniel Shepherd

0 projects • 0 followers
UNC Charlotte Mechanical Engineering Student
John Driver

John Driver

0 projects • 0 followers
Thanks to Simon Hart, Steven Atkins, Luigi Stanisa, and Dr. John McAlpine.

Comments

Add projectSign up / Login