Anemometr to weather station.

Hello, i’m want to build weather station to my web site school. And i have a little problem, I want to merge two skatches. Both are working separatly correct. After merged skatches working only press, humid, temp. Would you like to check this sketches.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>

#define am 8 //anemometer is connected to pin 8 with pulldown resistor
int cnt = 0; //counter
int rot = 0; // number of rotations
boolean stan = 0; //state of anemometer -open or closed
float wind;

void setup() {
pinMode (am, INPUT);
Serial.begin(9600);
}

void loop() {
cnt = cnt + 1;
if (digitalRead(am) == LOW) { //I’ve checked that on free position anemometer is always closed
delay(2);
stan = !stan;
while (digitalRead(am) == LOW) ;
rot = rot + 1 ;
}

if (cnt == 100) {
//int czas1=millis();
wind = rot * 2.40114; ///5; //equation calculating average speed of the wind in 3 sec intervals
Serial.println(rot);
Serial.print(“Wind speed = “);
Serial.print(wind, 2);
Serial.println(” km/h”);
cnt = 0; //counter reset
rot = 0; //rotation number reset

//int czas2 =millis();
//int czas=czas2-czas1;
//Serial.println(czas);
}

delay(8); //this delay is put here to extend time of whole loop to 10ms
}

#include <SPI.h>
#include <Ethernet.h>
#include <DHT.h>
#include <Wire.h>
#include “Adafruit_BMP085.h” // This is the version 1 library
#define DHTPIN A0
#define DHTTYPE 11// The Temperature/Humidity sensor
Adafruit_BMP085 bmp;
DHT dht(DHTPIN, DHTTYPE);

// Local Network Settings
byte mac = { 0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; // Must be unique on local network
// ThingSpeak Settings
char thingSpeakAddress = “api.thingspeak.com”;
String writeAPIKey = “GHAGS5F1IPQCATXG”;
const int updateThingSpeakInterval = 16 * 1000; // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)
// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;
// Initialize Arduino Ethernet Client
EthernetClient client;
void setup()
{
// Start Serial for debugging on the Serial Monitor
Serial.begin(9600);
// Start Ethernet on Arduino
startEthernet();
}
void loop()
{

if (client.available())
{
char c = client.read();
Serial.print(c);
}

//------DHT11--------
int chk = dht.read(DHTPIN);
//char t_buffer[10];
char h_buffer[10];
//float t=dht.readTemperature();
//String temp=dtostrf(t,0,5,t_buffer);
//Serial.println(temp);
//Serial.print(" ");
float h = dht.readHumidity();
String humid = dtostrf(h, 0, 5, h_buffer);
Serial.println(humid);

//-----BMP180-----------
bmp.begin();
float p = (bmp.readPressure() / 100.0 + 4.14); //this is for pressure in hectoPascal
float t2 = (bmp.readTemperature());

char p_buffer[15];
char t2_buffer[15];
String pres = dtostrf(p, 0, 5, p_buffer);
String temp2 = dtostrf(t2, 0, 2, t2_buffer);

Serial.println(pres);
Serial.println(t2);
Serial.println("------------------------");
// }
//----------------

// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)
{
Serial.println("…disconnected");
Serial.println();
client.stop();
}
// Update ThingSpeak
if (!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval))
{
updateThingSpeak(“field1=” + temp2 + “&field2=” + humid + “&field3=” + pres);
}
// Check if Arduino Ethernet needs to be restarted
if (failedCounter > 3 ) {
startEthernet();
}
lastConnected = client.connected();
}
void updateThingSpeak(String tsData)
{
if (client.connect(thingSpeakAddress, 80))
{
client.print(“POST /update HTTP/1.1\n”);
client.print(“Host: api.thingspeak.com\n”);
client.print(“Connection: close\n”);
client.print("X-THINGSPEAKAPIKEY: " + writeAPIKey + “\n”);
client.print(“Content-Type: application/x-www-form-urlencoded\n”);
client.print(“Content-Length: “);
client.print(tsData.length());
client.print(”\n\n”);
client.print(tsData);
lastConnectionTime = millis();
if (client.connected())
{
Serial.println(“Connecting to ThingSpeak…”);
Serial.println();
failedCounter = 0;
}
else
{
failedCounter++;
Serial.println(“Connection to ThingSpeak failed (” + String(failedCounter, DEC) + “)”);
Serial.println();
}
}
else
{
failedCounter++;
Serial.println(“Connection to ThingSpeak Failed (” + String(failedCounter, DEC) + “)”);
Serial.println();
lastConnectionTime = millis();
}
}
void startEthernet()
{
client.stop();
Serial.println(“Connecting Arduino to network…”);
Serial.println();
delay(1000);
// Connect to network amd obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0)
{
Serial.println(“DHCP Failed, reset Arduino to try again”);
Serial.println();
}
else
{
Serial.println(“Arduino connected to network using DHCP”);
Serial.println();
}
delay(1000);
}

If those sketches work, why are you showing us them, and asking us to check them? Where is the combined code? Where are the code tags?

My combinated code, not working wind speed.

#include "Adafruit_GFX.h"
#include <SPI.h>
#include <Ethernet.h>
#include <DHT.h>
#include <Wire.h>
#include "Adafruit_BMP085.h" // This is the version 1 library
#define DHTPIN A0
#define DHTTYPE 11// The Temperature/Humidity sensor
#define am 8
Adafruit_BMP085 bmp;
DHT dht(DHTPIN, DHTTYPE);
int cnt = 0; //counter
int rot = 0; // number of rotations
boolean stan = 0; //state of anemometer -open or closed
float wind;

// Local Network Settings
byte mac[] = { 0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; // Must be unique on local network
// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "GHAGS5F1IPQCATXG";
const int updateThingSpeakInterval = 16 * 1000; // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)
// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;
// Initialize Arduino Ethernet Client
EthernetClient client;
void setup()
{
  // Start Serial for debugging on the Serial Monitor
  Serial.begin(9600);
  pinMode (am, INPUT);
  startEthernet();
}
void loop()
{
  

  if (client.available())
  {
    char c = client.read();
    Serial.print(c);
  }

  {
  cnt = cnt + 1;
  if (digitalRead(am) == LOW) { //I've checked that on free position anemometer is always closed
    delay(2);
    stan = !stan;
    while (digitalRead(am) == LOW) ;
    rot = rot + 1 ;
  }

  if (cnt == 100) {
    //int czas1=millis();
    wind = rot * 2.40114; ///5;  //equation calculating average speed of the wind in 3 sec intervals
    
    

    
    cnt = 0; //counter reset
    rot = 0; //rotation number reset

    

    //int czas2 =millis();
    //int czas=czas2-czas1;
    //Serial.println(czas);
  }

  delay(8); //this delay is put here to extend time of whole loop to 10ms
}



//------DHT11--------
int chk = dht.read(DHTPIN);
//char t_buffer[10];
char h_buffer[10];
//float t=dht.readTemperature();
//String temp=dtostrf(t,0,5,t_buffer);
//Serial.println(temp);
//Serial.print(" ");
float h = dht.readHumidity();
String humid = dtostrf(h, 0, 2, h_buffer);


//-----BMP180-----------
bmp.begin();
float p = (bmp.readPressure() / 100.0 + 4.14); //this is for pressure in hectoPascal
float t2 = (bmp.readTemperature());

char p_buffer[15];
char t2_buffer[15];
String pres = dtostrf(p, 0, 2, p_buffer);
String temp2 = dtostrf(t2, 0, 2, t2_buffer);

char wind_buffer[5];
String w = dtostrf(wind,0,5,wind_buffer);

delay(10);


Serial.print("Wind speed = ");
Serial.print(wind, 2);
Serial.println(" km/h");
Serial.print("Pressure = ");
Serial.print(pres);
Serial.println(" hPa");
Serial.print("Temperature = ");
Serial.print(t2);
Serial.println(" *C");
Serial.print("Humidity = ");
Serial.print(humid);
Serial.println(" %");
Serial.println("------------------------");
delay(1500);
//         }
//----------------

// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)
{
  Serial.println("...disconnected");
  Serial.println();
  client.stop();
}
// Update ThingSpeak
if (!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval))
{
  updateThingSpeak("&field1=" + temp2 + "&field2=" + humid + "&field3=" + pres + "&field4=" + wind);
}
// Check if Arduino Ethernet needs to be restarted
if (failedCounter > 3 ) {
  startEthernet();
}
lastConnected = client.connected();
}
void updateThingSpeak(String tsData)
{
  if (client.connect(thingSpeakAddress, 80))
  {
    client.print("");

    lastConnectionTime = millis();
    if (client.connected())
    {
      Serial.println("Connecting to ThingSpeak...");
      Serial.println();
      failedCounter = 0;
    }
    else
    {
      failedCounter++;
      Serial.println("Connection to ThingSpeak failed (" + String(failedCounter, DEC) + ")");
      Serial.println();
    }
  }
  else
  {
    failedCounter++;
    Serial.println("Connection to ThingSpeak Failed (" + String(failedCounter, DEC) + ")");
    Serial.println();
    lastConnectionTime = millis();
  }
}
void startEthernet()
{
  client.stop();
  Serial.println("Connecting Arduino to network...");
  Serial.println();
  delay(1000);
  // Connect to network amd obtain an IP address using DHCP
  if (Ethernet.begin(mac) == 0)
  {
    Serial.println("DHCP Failed, reset Arduino to try again");
    Serial.println();
  }
  else
  {
    Serial.println("Arduino connected to network using DHCP");
    Serial.println();
  }
  delay(1000);
}

Does that compile?

Yes it is compile, but windspeed is not working. Windspeed is not working in serial monitor and thingspeak also. Temp, humid, press working well in serial and thingspeak.

Go through the entire, combined program [u]line by line[/u] to make sure that you understand what each line does and why.

Put Serial.print() statements in various places to see where things are going wrong.