/* Arduino UNO + I2C sensors + digitale/analoge sensors data versturen via http request (GET) en usb (serieel) */ #include #include #include #include #include #include #include #include #include "Adafruit_AM2320.h" Adafruit_AM2320 am2320 = Adafruit_AM2320(); // --- Analogue Wind Speed int analogChannel0 = 0; float vout = 0.0; float vin = 0.0; float R1 = 0000.0; // R1 = 0K float R2 = 1000.0; // R2 = 1K float pressure = 0.0; float a1P = 0.0; int value = 0; // --- Analogue Wind Speed // --- Analogue Wind Bearing int analogChannel1 = 1; float vout1 = 0.0; float vin1 = 0.0; float R3 = 0000.0; // R3 = 0K float R4 = 1000.0; // R4 = 1K int value1 = 0; // --- Analogue Wind Bearing // --- Analogue UV Detection int analogChannel2 = 2; float vout2 = 0.0; float vin2 = 0.0; float R5 = 0000.0; // R5 = 0K float R6 = 1000.0; // R6 = 1K int value2 = 0; // --- Analogue UV Detection // --- Rain perticipation counter const int DRMpin = 3; int val = 0; int old_val = 0; int a1R = 0; // --- Rain perticipation counter // --- I2C Barometric Pressure Adafruit_BMP085 bmp; // I2C // --- I2C Barometric Pressure // --- I2C Current Adafruit_INA219 ina219; // --- I2C Current // --- I2C Luminance Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); //I2C void configureSensor(void) { tsl.setGain(TSL2561_GAIN_1X); tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); } // --- I2C Luminance // Create I2C LM75A temperature instance LM75A lm75a_sensor02(false, //A0 LM75A pin state sensor behuizing false, //A1 LM75A pin state false); //A2 LM75A pin state LM75A lm75a_sensor01(false, //A0 LM75A pin state sensor weathershield true, //A1 LM75A pin state false); //A2 LM75A pin state // Equivalent to "LM75A lm75a_sensor;" // Create I2C LM75A temperature instance // --- NIC W5100 byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xDC, 0xDF }; IPAddress ip(xxx.xxx.xxx.xxx); <---- IP-adres Arduino invullen EthernetServer server(80); IPAddress server_addr(xxx.xxx.xxx.xxx); // IP of the MySQL *server* here <--- IP-adres MySQL server // --- NIC W5100 void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial); // start the Ethernet connection and the server: Ethernet.begin(mac_addr, ip); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); uint32_t currentFrequency; // --- initialize I2C sensors Current, Barometric Pressure, Luminance ina219.begin(); if (!bmp.begin()) { Serial.println("BMP180 sensor not found"); while (1) {} } if(!tsl.begin()) { Serial.println("TSL2561 not detected"); while (1) {} } // --- initialize I2C sensors Current, Barometric Pressure, Luminance // --- initialize I2C sensor Humidity am2320.begin(); // --- initialize I2C sensor Humidity // --- pin 3 rain perticipation pinMode(DRMpin,INPUT_PULLUP); } void loop() { // listen for incoming clients EthernetClient client = server.available(); // Windsnelheid (Anemometer) // output the value Windspeed in m/s value = analogRead(analogChannel0); vout = (value * 5.0) / 1024.0; // e.v.t. aanpassen op 5 Volt voedingsspanning vin = vout / (R2/(R1+R2)); if (vin<0.03) { vin=0.0; // rommel weg } float a1W = vin * 6.48; // output the value Windspeed in m/s // Windrichting // output the value and convert to Wind Bearing value1 = analogRead(analogChannel1); vout1 = (value1 * 5.0) / 1024.0; // e.v.t. aanpassen op 5 Volt voedingsspanning vin1 = vout1 / (R4/(R3+R4)); if (vin1<0.03) { vin1=0.0; // rommel weg } float a1B = 0.0; if (vin1<0.45||vin1>2.0) { a1B = 0.0; } else if (vin1<0.55) { a1B = 22.5; } else if (vin1<0.65) { a1B = 45.0; } else if (vin1<0.75) { a1B = 67.5; } else if (vin1<0.85) { a1B = 90.0; } else if (vin1<0.95) { a1B = 112.5; } else if (vin1<1.05) { a1B = 135.0; } else if (vin1<1.15) { a1B = 157.5; } else if (vin1<1.25) { a1B = 180.0; } else if (vin1<1.35) { a1B = 202.5; } else if (vin1<1.45) { a1B = 225.0; } else if (vin1<1.55) { a1B = 247.5; } else if (vin1<1.65) { a1B = 270.0; } else if (vin1<1.75) { a1B = 292.5; } else if (vin1<1.85) { a1B = 315.0; } else { a1B = 337.5; } // output the value and convert to Wind Bearing // UV-index (analoog) // output the value and convert to UV Index value2 = analogRead(analogChannel2); vout2 = (value2 * 5.0) / 1024.0; // e.v.t. aanpassen op 5 Volt voedingsspanning vin2 = vout2 / (R6/(R5+R6)); if (vin2<0.03) { vin2=0.0; // rommel weg } int a1UV = 0; if (vin2<0.08||vin2>1.55) { a1UV = 0; } else if (vin2<0.14) { a1UV = 1; } else if (vin2<0.24) { a1UV = 2; } else if (vin2<0.34) { a1UV = 3; } else if (vin2<0.44) { a1UV = 4; } else if (vin2<0.54) { a1UV = 5; } else if (vin2<0.64) { a1UV = 6; } else if (vin2<0.74) { a1UV = 7; } else if (vin2<0.84) { a1UV = 8; } else if (vin2<0.94) { a1UV = 9; } else if (vin2<1.04) { a1UV = 10; } else if (vin2<1.14) { a1UV = 11; } else if (vin2<1.24) { a1UV = 12; } else if (vin2<1.34) { a1UV = 13; } else if (vin2<1.44) { a1UV = 14; } else { a1UV = 15; } // output the value and convert to UV Index // BMP180 I2C luchtdruksensor float a1T2 = (bmp.readTemperature()); pressure = bmp.readPressure(); a1P = pressure / 100; // TSL2561 I2C luminatiesensor sensors_event_t event; tsl.getEvent(&event); float a1L = (event.light); // LM75 I2C temperatuursensoren float temperature_in_degrees = lm75a_sensor01.getTemperatureInDegrees(); float a1T = (temperature_in_degrees); // temp weathershield if (temperature_in_degrees == INVALID_LM75A_TEMPERATURE) { a1T = 0; } float temperature_in_degrees2 = lm75a_sensor02.getTemperatureInDegrees(); float a1T3 = (temperature_in_degrees2); // temp behuizing if (temperature_in_degrees2 == INVALID_LM75A_TEMPERATURE) { //client.println("Error while getting temperature"); a1T3 = 0; } // Neerslaghoeveelheid val = digitalRead(DRMpin); if ((val == LOW) && (old_val == HIGH) || (val == HIGH) && (old_val == LOW)){ delay(10); a1R = 1; old_val = val; } else { a1R = 0; old_val = val; } // INA 219 I2C spanning/stroomsensor float shuntvoltage = 0; float a1U = 0; float a1I = 0; float loadvoltage = 0; shuntvoltage = ina219.getShuntVoltage_mV(); a1U = ina219.getBusVoltage_V(); a1I = ina219.getCurrent_mA(); loadvoltage = a1U + (shuntvoltage / 1000); // AM2320 I2C luchtvochtigheidssensor float a1H = 0; float a1T1 = 0; a1H = am2320.readHumidity(); a1T1 = am2320.readTemperature(); if (client.connect(server_addr,80)){ Serial.println("-> Connected"); // Make a HTTP request: client.print("GET /xxxxxxx.php?"); <--- url / link naar MySQL(webserver) client.print("a1W="); // Windspeed client.print(a1W); client.print("&"); client.print("a1B="); // Wind Bearing client.print(a1B); client.print("&"); client.print("a1UV="); // UV Index 0-15 client.print(a1UV); client.print("&"); client.print("a1T="); // Temperature weathershield LM75 client.print(a1T); client.print("&"); client.print("a1P="); // Pressure BMP180 weathershield client.print(a1P); client.print("&"); client.print("a1L="); // Luminance TSL2561 client.print(a1L); client.print("&"); client.print("a1H="); // Humidity AM2320 weathershield client.print(a1H); client.print("&"); client.print("a1T1="); // Temperature AM2320 weathershield client.print(a1T1); client.print("&"); client.print("a1T2="); // Temperature BMP180 weathershield client.print(a1T2); client.print("&"); client.print("a1T3="); // Temperature behuizing client.print(a1T3); client.print("&"); client.print("a1R="); // Rain client.print(a1R); client.print("&"); client.print("a1U="); // Voltage client.print(a1U); client.print("&"); client.print("a1I="); // Current client.print(a1I); client.println(); client.stop(); } Serial.print("W "); Serial.print(a1W); // 1. wind speed Serial.print(","); Serial.print("B "); Serial.print(a1B); // 2. wind bearing Serial.print(","); Serial.print("UV "); Serial.print(a1UV); // 3. UV index Serial.print(","); Serial.print("T "); Serial.print(a1T); // 4. temperature Serial.print(","); Serial.print("P "); Serial.print(a1P); // 5. pressure Serial.print(","); Serial.print("L "); Serial.print(a1L); // 6. luminance Serial.print(","); Serial.print("H "); Serial.print(a1H); // 7. humidity Serial.print(","); Serial.print("T1 "); Serial.print(a1T1); // 8. temperature 1 Serial.print(","); Serial.print("T2 "); Serial.print(a1T2); // 8. temperature 2 Serial.print(","); Serial.print("T3 "); Serial.print(a1T3); // 9. temperature 3 Serial.print(","); Serial.print("R "); Serial.print(a1R); // 11. rain (0,254 mm/pulse) Serial.print(","); Serial.print("U "); Serial.print(a1U); // 12. voltage Serial.print(","); Serial.print("I "); Serial.print(a1I); // 13. current Serial.print("\n"); delay(5000); /* T = temperature *C H = relative humidity % UV = UV index 0...15 P = barometric presurre mBar W = windspeed m/s L = Luminance Lux B = wind bearing 0 - 360 degrees (16 steps) R = rain * 0.254 inch converted to mm U = voltage Volt I = current milliAmperes */ }