mndrj

temp+server+motor status

Apr 20th, 2018
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.45 KB | None | 0 0
  1. #include <OneWire.h>// Used for temperature sensor(s)
  2. #include <SPI.h>
  3. #include <Wire.h>
  4. #include <DallasTemperature.h>
  5. #include <LCD.h>
  6. #include <LiquidCrystal_I2C.h> // F Malpartida's NewLiquidCrystal library
  7. #include <Ethernet.h> // Used for Ethernet
  8.  
  9. #define ONE_WIRE_BUS 8
  10. #define Motor1 9
  11.  
  12. bool flag=false;
  13. int Motorstate = 0; // current state of the motor
  14. //int lastMotorstate = 0; // previous state of the motor
  15.  
  16. //char on [10]="Motor-ON ";
  17. //char off [12]="Motor-OFF ";
  18.  
  19. OneWire oneWire(ONE_WIRE_BUS);
  20. DallasTemperature sensors(&oneWire);
  21.  
  22. #define I2C_ADDR 0x27 // Define I2C Address for the PCF8574A on the LCD Backpack board
  23. //---(Following are the PCF8574 pin assignments to LCD connections )----
  24. // This are different than earlier/different I2C LCD displays
  25. #define BACKLIGHT_PIN 3
  26. #define En_pin 2
  27. #define Rw_pin 1
  28. #define Rs_pin 0
  29. #define D4_pin 4
  30. #define D5_pin 5
  31. #define D6_pin 6
  32. #define D7_pin 7
  33. #define LED_OFF 0
  34. #define LED_ON 1
  35.  
  36. DeviceAddress Probe01 = { 0x28, 0xFF, 0x25, 0x23, 0x00, 0x17, 0x05, 0x27 };
  37. DeviceAddress Probe02 = { 0x28, 0xFF, 0xF1, 0x23, 0x00, 0x17, 0x05, 0x66 };
  38. //DeviceAddress Probe03 = { 0x28, 0xFF, 0x98, 0x4C, 0x00, 0x17, 0x03, 0x53 };
  39. DeviceAddress Probe03 = { 0x28, 0xFF, 0x8B, 0x46, 0x00, 0x17, 0x03, 0x7A };
  40.  
  41.  
  42. // **** ETHERNET SETTING ****
  43. // Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
  44. // Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
  45. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  46. // For the rest we use DHCP (IP address and such)
  47. float temp1; // float value for 2 temperature value from DS18B20
  48. float temp2;
  49. float temp3;
  50. //float temp4;
  51. //float temp[2];
  52.  
  53. //Start the LCD display library
  54. LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
  55. EthernetClient client;
  56. char server[] ="........"; // IP Adres (or name) of server to dump data to
  57. unsigned long PreviousMillis = 0;// For when millis goes past app 49 days.
  58. //unsigned long interval = 10000; // Wait between dumps (10000 = 10 seconds)
  59. unsigned long interval = 3600; // Wait between dumps (1 min)
  60. unsigned long intervalTime; // Global var tracking Interval Time
  61.  
  62. // **** TEMPERATURE SETTINGS ****
  63. // Sensor(s) data pin is connected to Arduino pin 2 in non-parasite mode!
  64. //OneWire ds(2);
  65.  
  66. void setup()
  67. {
  68. //#ifdef DEBUG
  69. Serial.begin(9600); // only use serial when debugging
  70. // #endif
  71. Ethernet.begin(mac);
  72. // server.begin();
  73. // client.begin();
  74. Wire.begin();
  75. sensors.begin();
  76.  
  77. //------- Initialize the Temperature measurement library--------------
  78.  
  79. //set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  80. sensors.setResolution(Probe01, 12);
  81. sensors.setResolution(Probe02, 12);
  82. sensors.setResolution(Probe03, 12);
  83. //sensors.setResolution(Probe04, 10);
  84.  
  85.  
  86. //---------------- Initialize the lcd ------------------
  87. lcd.begin (20,4); // 20 characters, 4 lines
  88. //Switch on the backlight
  89. lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
  90. lcd.setBacklight(LED_ON);
  91. intervalTime = millis(); // Set initial target trigger time (right NOW!)
  92.  
  93. pinMode(Motor1,INPUT);
  94. //digitalWrite(MotorPin,LOW);
  95.  
  96. }
  97.  
  98. void loop()
  99. {
  100. sensors.requestTemperatures(); // get data from DS18B20
  101. delay(3000);
  102. //Serial.println();
  103.  
  104. lcd.clear(); // Reset the display
  105. lcd.home();
  106. lcd.backlight(); //Backlight ON if under program control
  107.  
  108. // Print our characters on the LCD
  109. // NOTE: Line number and character number start at 0 not 1
  110. //delay(1000);
  111. lcd.setCursor(0,0); //Start at character 0 on line 0
  112. lcd.print("1: ");
  113. printTemperature(Probe01);
  114. //delay(1000);
  115.  
  116. lcd.setCursor(0,1); //Start at character 0 on line 2
  117. lcd.print("2: ");
  118. printTemperature(Probe02);
  119. //delay(1000);
  120.  
  121. lcd.setCursor(0,2); //Start at character 0 on line 3
  122. lcd.print("3: ");
  123. printTemperature(Probe03);
  124. delay(7000);
  125. lcd.clear();
  126.  
  127. //Serial.println("Hello1 World");
  128. // if you get a connection, report back via serial:
  129. if (client.connect(server, 80))
  130. {
  131.  
  132. //Serial.println("-> Connected"); // only use serial when debugging
  133.  
  134. Motorstate = digitalRead(Motor1);
  135. temp1 = sensors.getTempCByIndex(0);
  136. Serial.println(temp1);
  137. Serial.print("Probe 01 temperature is: ");
  138. printTemperature(Probe01);
  139. //Serial.println();
  140. //Serial.println(temp1);
  141. delay(1000);
  142.  
  143. temp2 = sensors.getTempCByIndex(1);
  144. Serial.print("Probe 02 temperature is: ");
  145. printTemperature(Probe02);
  146. Serial.println();
  147. delay(1000);
  148.  
  149.  
  150. temp3 = sensors.getTempCByIndex(2);
  151. Serial.print("Probe 03 temperature is: ");
  152. printTemperature(Probe03);
  153. Serial.println();
  154. delay(1000);
  155.  
  156.  
  157. /*temp4 = sensors.getTempCByIndex(3);
  158. Serial.print("Probe 04 temperature is: ");
  159. printTemperature(Probe04);
  160. Serial.println();*/
  161.  
  162. //lcd.setCursor(0,3); //Start at character 0 on line 3
  163. //lcd.print("4: ");
  164. //displayTemperature(Probe04);
  165.  
  166. Serial.println("HITTTTT1");
  167.  
  168. //EthernetClient client = server.available();
  169. // Make a HTTP request:
  170. //client.println("Refresh: 7"); // refresh the page automatically every 5 sec
  171. client.print("GET /tempsensor/logger.php?");
  172. client.print("temp1="); //Defined file temp in php code
  173. client.print( temp1 );
  174. client.print("&");
  175. //client.print("id=");
  176. // client.print( " 1 " );
  177.  
  178. //client.print("GET /tempsensor/logger.php?");
  179. client.print("temp2="); //Defined file temp in php code
  180. client.print( temp2 );
  181. client.print("&");
  182. // client.print("id=");
  183. // client.print( " 2 " );
  184.  
  185. //client.print("GET /tempsensor/logger.php?");
  186. client.print("temp3="); //Defined file temp in php code
  187. client.print( temp3 );
  188. client.print("&");
  189. //client.print("id=");
  190. //client.print( " 3 " );
  191.  
  192. if (Motorstate == HIGH)
  193. {
  194. // client.print("GET /tempsensor/logger.php?");
  195. client.print("Motor1=");
  196. client.print("Motor-ON");
  197. client.print("&");
  198. Serial.print("Motor ON");
  199. //client.print("ON");
  200. //client.println(" HTTP/1.1"); // Part of the GET request
  201.  
  202. }
  203. else
  204. {
  205. client.print("Motor1=");
  206. client.print("Motor-Off");
  207. client.print("&");
  208. //client.print("OFF");
  209. Serial.print("Motor off");
  210.  
  211.  
  212. } //client.print("OFF");
  213.  
  214. client.println( "HTTP/1.1");
  215. client.print( "Host: ........" );
  216. client.println(server);
  217. client.println( "Content-Type: application/x-www-form-urlencoded" );
  218. client.println( "Connection: close" );
  219.  
  220. //client.println("Refresh: 5");
  221. client.println();
  222. client.stop();
  223. client.println();
  224.  
  225.  
  226. Serial.println("HITTTTT2");
  227. }
  228.  
  229. else
  230. {
  231. // you didn't get a connection to the server:
  232. //#ifdef DEBUG
  233. Serial.println("--> connection failed !!"); // only use serial when debugging
  234. // #endif
  235.  
  236. }
  237. delay(interval);
  238. }
  239.  
  240.  
  241.  
  242.  
  243. void printTemperature(DeviceAddress deviceAddress)
  244. {
  245.  
  246. float tempC = sensors.getTempC(deviceAddress);
  247.  
  248. if (tempC == -127.00)
  249. {
  250. Serial.print("Error getting temperature ");
  251. lcd.print("Temperature Error");
  252. }
  253. else
  254. {
  255. // Serial.print(" C: ");
  256. // Serial.print(tempC);
  257. //Serial.print(" F: ");
  258. // Serial.print(DallasTemperature::toFahrenheit(tempC));
  259.  
  260. lcd.print("Temp=");
  261. lcd.print(tempC);
  262. lcd.write(223);// degree symbol
  263. lcd.print("C");
  264.  
  265. }
  266. }
Add Comment
Please, Sign In to add comment