Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #include <SPI.h>
- #include <Ethernet.h>
- #include <Dhcp.h>
- #include <Dns.h>
- #include <EthernetUdp.h>
- #include <Wire.h>
- #define ONE_WIRE_BUS 2
- float teplota = 0;
- float ph=0;
- float zakalenie=0;
- int hlbka=0;
- OneWire oneWire(ONE_WIRE_BUS);
- // Pass our oneWire reference to Dallas Temperature sensor
- DallasTemperature sensors(&oneWire);
- #define Hostname "Arduino" //Meno v sieti
- byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //MAC adresa
- char server[] = "www.logaro.studenthosting.sk"; //adresa webservera
- IPAddress ip(10, 0, 0, 8); //IP adresa v lokalnej sieti
- EthernetClient client; //Spustenie ethernetu ako klienta
- int sensorPin = A1;
- float volt;
- float ntu;
- float val;
- const int analogInPin = A0;
- int sensorValue = 0;
- unsigned long int avgValue;
- float b;
- int buf[10],temp;
- float round_to_dp( float in_value, int decimal_place )
- {
- float multiplier = powf( 10.0f, decimal_place );
- in_value = roundf( in_value * multiplier ) / multiplier;
- return in_value;
- }
- const int trigPin = 3;
- const int echoPin = 4;
- // defines variables
- float duration;
- int distance;
- void setup() {
- // komunikácia cez sériovú linku rýchlosťou 112500 baud
- pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
- pinMode(echoPin, INPUT); // Sets the echoPin as an Input
- Serial.begin(9600);
- // Start up the library
- sensors.begin();
- }
- void loop() {
- // Clears the trigPin
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- // Sets the trigPin on HIGH state for 10 micro seconds
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- // Reads the echoPin, returns the sound wave travel time in microseconds
- duration = pulseIn(echoPin, HIGH);
- // Calculating the distance
- distance= duration*0.034/2;
- sensors.requestTemperatures();
- volt = 0;
- for(int i=0; i<800; i++)
- {
- volt += ((float)analogRead(sensorPin)/1023)*5;
- }
- volt = volt/800;
- volt = round_to_dp(volt,1);
- if(volt < 2.5){
- ntu = 3000;
- }else{
- ntu = -1120.4*square(volt)+5742.3*volt-4353.8;
- }
- val = map(ntu, 1798,3000 , 0, 100);
- sensors.requestTemperatures();
- for(int i=0;i<10;i++)
- {
- buf[i]=analogRead(analogInPin);
- delay(10);
- }
- for(int i=0;i<9;i++)
- {
- for(int j=i+1;j<10;j++)
- {
- if(buf[i]>buf[j])
- {
- temp=buf[i];
- buf[i]=buf[j];
- buf[j]=temp;
- }
- }
- }
- avgValue=0;
- for(int i=2;i<8;i++)
- avgValue+=buf[i];
- float pHVol=(float)avgValue*5.0/1024/6;
- float phValue = -5.70 * pHVol + 21.34;
- // Serial.print("sensor = ");
- //Serial.println(phValue);
- hlbka=distance;
- ph=phValue;
- zakalenie=val;
- teplota=sensors.getTempCByIndex(0);
- if (Ethernet.begin(mac) == 0) { //V prípade zlyhania vypíš
- Serial.println("Chyba konfiguracie cez DHCP"); //Vypis na seriovu linku
- Ethernet.begin(mac, ip); //Nastavenie IP a MAC adresy pre ethernet modul
- }
- odosli_data();
- delay(1000);
- Serial.println(teplota);
- Serial.println(ph);
- Serial.println(zakalenie);
- Serial.println(hlbka);
- }// Koniec loop slučky
- void odosli_data() {
- if (client.connect(server, 80)) { // Ak pripojí na server, port 80
- Serial.println("Pripojenie uspesne na webserver"); //vypise na seriovu linku
- client.print("GET /water/arduino/zapisdata.php?teplota="); //Začiatok HTTP REQUEST --> client.print GET Metodou s oznacenim premennej, do ktorej sa zapíšu dáta
- client.print(teplota);
- client.print("&zakalenie=");
- client.print(zakalenie);
- client.print("&hlbka=");
- client.print(hlbka);
- client.print("&ph=");
- client.print(ph);
- client.println(" HTTP/1.1");
- client.println("Host: www.logaro.studenthosting.sk"); // Adresa hosta na ktorý, bol mierený REQUEST
- client.println("Connection: close");
- client.println(); //Zalomenie riadka
- client.stop(); // Ukoncenie pripojenia ethernet shieldu
- } else {
- Serial.println("Pripojenie zlyhalo...");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement