You are on page 1of 7

Cloud Hoppers Weather

Station using Arduino Uno


Board and Ethernet Shield

Maplin weather station part numbers:


Anemometer £2.49 part number :- N25FR
Wind direction sensor £9.99:-N96FY

You can build this onto


a little strip board for
easy connection :)

You can see a live version of this weather station running at :


debdalelodge.ddns.net
Ardunio with Ethernet Shield

Ethernet connected weather station - By Mike Gaylor


(www.routoutcnc.com)

www.cloudhoppersparamotorclub.co.uk
Cloud Hoppers Weather
Station using Arduino Uno
Board and Ethernet Shield
Arduino Code:- Please note this code is not perfect and does have a few bugs but it works, feel free to make it better and send me a copy :)

/*
Cloud Hoppers Weather station with Ethernet connectivity

A simple web server weather station by Mike Gaylor using the Arduino Uno and Ethernet shield - www.routoutcnc.com

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs:

Connect maplin wind direction sensor to A0


connect Maplin anemometer to D5

See Circuit Diagram.

*/

// Must make sure these are in the Arduino Libary !


#include <SPI.h>
#include <Ethernet.h>
#include <MsTimer2.h>

// Global Variables.
//hardwareCounterPin = 5;
const int samplePeriod = 2000;
unsigned int count = 0;
float numberOfCounts = 0;
int clock = 0;
long startTime = 0;
float peekWind = 0;
float gust = 0;
int sensorReading = 0;
int peakCounter = 0;

//Averaging stuff **************************************************


const int numReadings = 30;

int readings[numReadings]; // the readings from the analog input


int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
//*****************************************************************

Arduino Code 1
Cloud Hoppers Weather
Station using Arduino Uno
Board and Ethernet Shield

//initalise Vars

// Enter a MAC address and IP address for your controller below.


// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(172,16,0,50);

// Initialize the Ethernet server library


// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
TCCR1A = 0;
clock = 0;
// Open serial communications and wait for port to open:

//Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

// start the Ethernet connection and the server:


Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());

//averaging stuff *******************************************************


for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
}
//***********************************************************************
delay(1000); //wait for processor to stabalise
}

void loop() {

Arduino Code 2
Cloud Hoppers Weather
Station using Arduino Uno
Board and Ethernet Shield

pinMode(8, OUTPUT);
//MsTimer2::set(samplePeriod,realTime);
//MsTimer2::start();

// listen for incoming clients


EthernetClient client = server.available();
if (client) {

Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("<h1>Welcome to the Cloud Hoppers Weather station V3.1!</h1>");
client.print("<p>This is an experimental weather station and is used for our </p>");
client.print("<p>microlighting / Paramotoring and Horse Riding :) </p>");

//client.println(sensorReading);
if (sensorReading >=772 and sensorReading <=792) client.println("<h1>wind Direction: North Wind");
if (sensorReading >=449 and sensorReading <=469) client.println("<h1>wind Direction: North East Wind");
if (sensorReading >=80 and sensorReading <=100) client.println("<h1>wind Direction: East Wind");
if (sensorReading >=170 and sensorReading <=190) client.println("<h1>wind Direction: South East Wind");
if (sensorReading >=274 and sensorReading <=294) client.println("<h1>wind Direction: South Wind");
if (sensorReading >=619 and sensorReading <=639) client.println("<h1>wind Direction: South West Wind");
if (sensorReading >=935 and sensorReading <=955) client.println("<h1>wind Direction: West Wind");
if (sensorReading >=876 and sensorReading <=896) client.println("<h1>wind Direction: North West Wind");

//n=782
//ne=459

Arduino Code 3
Cloud Hoppers Weather
Station using Arduino Uno
Board and Ethernet Shield

//e=90
//se=180
//s=284
//sw=629
//w=945
//nw=886

client.print("<h1>Average Wind Speed = ");


client.print(average); //average wind speed
client.print(" MPH");
client.print("<h1>Current Wind Speed = ");
client.print(numberOfCounts); //average wind speed
client.print(" MPH");
client.print("<h1>Gust Wind Speed last 5mins = ");
client.print(gust); //average wind speed
client.print(" MPH");
client.println("");
if (average <=10 && gust <=10) client.println("<p style=""color:red;"">Based on the wind here It might be Flyable :) !........</p>");
if (average >=11 && gust >=11) client.println("<p style=""color:blue;"">Not Flyable stayin with a cupa !........</p>");

client.println("<br />");

client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}

Arduino Code 4
Cloud Hoppers Weather
Station using Arduino Uno
Board and Ethernet Shield

// give the web browser time to receive the data


delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
Ethernet.maintain();

}
windSpeed();
windDirection();
}

void windSpeed()
{
//start counting.............................................
//delay(100);
//digitalWrite(8, HIGH);
//delay(100);
//digitalWrite(8, LOW);

if (clock == 0) {
startTime = millis(); // read the current clock
bitSet(TCCR1B ,CS12); // counter clock source is externet pin
bitSet(TCCR1B ,CS11); // Clock rising Edge
clock = 1;
}

//delay(samplePeriod);
if ((millis() - startTime) >= 2000) //workout duration
{
peakCounter ++;

TCCR1B = 0; // stop counting


count = TCNT1;
TCNT1 = 0; //reset hardware counter
clock = 0;

if (peakCounter >=150) {
peakCounter = 0;
gust = peekWind; if (gust >200) gust = 0;
peekWind = 0;
}
numberOfCounts = count;
numberOfCounts = (1.6*numberOfCounts)/2;

Arduino Code 5
Cloud Hoppers Weather
Station using Arduino Uno
Board and Ethernet Shield

if (numberOfCounts > peekWind) (peekWind = numberOfCounts);

// averaging stuff************************************************
// subtract the last reading:
total = total - readings[readIndex];
// read from the sensor:
readings[readIndex] = numberOfCounts;
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;

// if we're at the end of the array...


if (readIndex >= numReadings) {
// ...wrap around to the beginning:
readIndex = 0;
}

// calculate the average:


average = total / numReadings;
if (average <= 0) average = 0;

//****************************************************************

//end counting ............................................

int windDirection ()

{
sensorReading = analogRead(0);

Arduino Code 6

You might also like