Professional Documents
Culture Documents
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:
*/
// 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;
Arduino Code 1
Cloud Hoppers Weather
Station using Arduino Uno
Board and Ethernet Shield
//initalise Vars
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
}
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();
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.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
}
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 ++;
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
// 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;
//****************************************************************
int windDirection ()
{
sensorReading = analogRead(0);
Arduino Code 6