Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>// Used for temperature sensor(s)
- #include <SPI.h>
- #include <Wire.h>
- #include <DallasTemperature.h>
- #include <LCD.h>
- #include <LiquidCrystal_I2C.h> // F Malpartida's NewLiquidCrystal library
- #include <Ethernet.h> // Used for Ethernet
- #define ONE_WIRE_BUS 8
- #define Motor1 9
- bool flag=false;
- int Motorstate = 0; // current state of the motor
- //int lastMotorstate = 0; // previous state of the motor
- //char on [10]="Motor-ON ";
- //char off [12]="Motor-OFF ";
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- #define I2C_ADDR 0x27 // Define I2C Address for the PCF8574A on the LCD Backpack board
- //---(Following are the PCF8574 pin assignments to LCD connections )----
- // This are different than earlier/different I2C LCD displays
- #define BACKLIGHT_PIN 3
- #define En_pin 2
- #define Rw_pin 1
- #define Rs_pin 0
- #define D4_pin 4
- #define D5_pin 5
- #define D6_pin 6
- #define D7_pin 7
- #define LED_OFF 0
- #define LED_ON 1
- DeviceAddress Probe01 = { 0x28, 0xFF, 0x25, 0x23, 0x00, 0x17, 0x05, 0x27 };
- DeviceAddress Probe02 = { 0x28, 0xFF, 0xF1, 0x23, 0x00, 0x17, 0x05, 0x66 };
- //DeviceAddress Probe03 = { 0x28, 0xFF, 0x98, 0x4C, 0x00, 0x17, 0x03, 0x53 };
- DeviceAddress Probe03 = { 0x28, 0xFF, 0x8B, 0x46, 0x00, 0x17, 0x03, 0x7A };
- // **** ETHERNET SETTING ****
- // Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
- // Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- // For the rest we use DHCP (IP address and such)
- float temp1; // float value for 2 temperature value from DS18B20
- float temp2;
- float temp3;
- //float temp4;
- //float temp[2];
- //Start the LCD display library
- LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
- EthernetClient client;
- char server[] ="........"; // IP Adres (or name) of server to dump data to
- unsigned long PreviousMillis = 0;// For when millis goes past app 49 days.
- //unsigned long interval = 10000; // Wait between dumps (10000 = 10 seconds)
- unsigned long interval = 3600; // Wait between dumps (1 min)
- unsigned long intervalTime; // Global var tracking Interval Time
- // **** TEMPERATURE SETTINGS ****
- // Sensor(s) data pin is connected to Arduino pin 2 in non-parasite mode!
- //OneWire ds(2);
- void setup()
- {
- //#ifdef DEBUG
- Serial.begin(9600); // only use serial when debugging
- // #endif
- Ethernet.begin(mac);
- // server.begin();
- // client.begin();
- Wire.begin();
- sensors.begin();
- //------- Initialize the Temperature measurement library--------------
- //set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
- sensors.setResolution(Probe01, 12);
- sensors.setResolution(Probe02, 12);
- sensors.setResolution(Probe03, 12);
- //sensors.setResolution(Probe04, 10);
- //---------------- Initialize the lcd ------------------
- lcd.begin (20,4); // 20 characters, 4 lines
- //Switch on the backlight
- lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
- lcd.setBacklight(LED_ON);
- intervalTime = millis(); // Set initial target trigger time (right NOW!)
- pinMode(Motor1,INPUT);
- //digitalWrite(MotorPin,LOW);
- }
- void loop()
- {
- sensors.requestTemperatures(); // get data from DS18B20
- delay(3000);
- //Serial.println();
- lcd.clear(); // Reset the display
- lcd.home();
- lcd.backlight(); //Backlight ON if under program control
- // Print our characters on the LCD
- // NOTE: Line number and character number start at 0 not 1
- //delay(1000);
- lcd.setCursor(0,0); //Start at character 0 on line 0
- lcd.print("1: ");
- printTemperature(Probe01);
- //delay(1000);
- lcd.setCursor(0,1); //Start at character 0 on line 2
- lcd.print("2: ");
- printTemperature(Probe02);
- //delay(1000);
- lcd.setCursor(0,2); //Start at character 0 on line 3
- lcd.print("3: ");
- printTemperature(Probe03);
- delay(7000);
- lcd.clear();
- //Serial.println("Hello1 World");
- // if you get a connection, report back via serial:
- if (client.connect(server, 80))
- {
- //Serial.println("-> Connected"); // only use serial when debugging
- Motorstate = digitalRead(Motor1);
- temp1 = sensors.getTempCByIndex(0);
- Serial.println(temp1);
- Serial.print("Probe 01 temperature is: ");
- printTemperature(Probe01);
- //Serial.println();
- //Serial.println(temp1);
- delay(1000);
- temp2 = sensors.getTempCByIndex(1);
- Serial.print("Probe 02 temperature is: ");
- printTemperature(Probe02);
- Serial.println();
- delay(1000);
- temp3 = sensors.getTempCByIndex(2);
- Serial.print("Probe 03 temperature is: ");
- printTemperature(Probe03);
- Serial.println();
- delay(1000);
- /*temp4 = sensors.getTempCByIndex(3);
- Serial.print("Probe 04 temperature is: ");
- printTemperature(Probe04);
- Serial.println();*/
- //lcd.setCursor(0,3); //Start at character 0 on line 3
- //lcd.print("4: ");
- //displayTemperature(Probe04);
- Serial.println("HITTTTT1");
- //EthernetClient client = server.available();
- // Make a HTTP request:
- //client.println("Refresh: 7"); // refresh the page automatically every 5 sec
- client.print("GET /tempsensor/logger.php?");
- client.print("temp1="); //Defined file temp in php code
- client.print( temp1 );
- client.print("&");
- //client.print("id=");
- // client.print( " 1 " );
- //client.print("GET /tempsensor/logger.php?");
- client.print("temp2="); //Defined file temp in php code
- client.print( temp2 );
- client.print("&");
- // client.print("id=");
- // client.print( " 2 " );
- //client.print("GET /tempsensor/logger.php?");
- client.print("temp3="); //Defined file temp in php code
- client.print( temp3 );
- client.print("&");
- //client.print("id=");
- //client.print( " 3 " );
- if (Motorstate == HIGH)
- {
- // client.print("GET /tempsensor/logger.php?");
- client.print("Motor1=");
- client.print("Motor-ON");
- client.print("&");
- Serial.print("Motor ON");
- //client.print("ON");
- //client.println(" HTTP/1.1"); // Part of the GET request
- }
- else
- {
- client.print("Motor1=");
- client.print("Motor-Off");
- client.print("&");
- //client.print("OFF");
- Serial.print("Motor off");
- } //client.print("OFF");
- client.println( "HTTP/1.1");
- client.print( "Host: ........" );
- client.println(server);
- client.println( "Content-Type: application/x-www-form-urlencoded" );
- client.println( "Connection: close" );
- //client.println("Refresh: 5");
- client.println();
- client.stop();
- client.println();
- Serial.println("HITTTTT2");
- }
- else
- {
- // you didn't get a connection to the server:
- //#ifdef DEBUG
- Serial.println("--> connection failed !!"); // only use serial when debugging
- // #endif
- }
- delay(interval);
- }
- void printTemperature(DeviceAddress deviceAddress)
- {
- float tempC = sensors.getTempC(deviceAddress);
- if (tempC == -127.00)
- {
- Serial.print("Error getting temperature ");
- lcd.print("Temperature Error");
- }
- else
- {
- // Serial.print(" C: ");
- // Serial.print(tempC);
- //Serial.print(" F: ");
- // Serial.print(DallasTemperature::toFahrenheit(tempC));
- lcd.print("Temp=");
- lcd.print(tempC);
- lcd.write(223);// degree symbol
- lcd.print("C");
- }
- }
Add Comment
Please, Sign In to add comment