SHARE
TWEET

Untitled

a guest Jul 21st, 2011 497 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Ethernet.h>
  2.  
  3. /*
  4. Sproutboard Server Room Monitor
  5. Sproutboard.com
  6.  
  7.  
  8. Analog I/O:
  9. Analog 0 - CCD Light Sensor (CDS1)
  10. Analog 1 - Accessory Terminal Block 1 (TA1) unused
  11. Analog 2 - Accessory Terminal Block 2 (TA2) unused
  12. Analog 3 - Onboard Accessories Socket 1 (Temperature sensor on external board J9)
  13. Analog 4 - Onboard Accessories Socket 1 (Humidity sensor on external board J9)
  14. Analog 5 - Onboard Accessories Socket 2 (Sound J10)
  15.  
  16. Digital I/O:
  17. Digital 0 - Not used
  18. Digital 1 - Serial Terminal (TS1)
  19. Digital 2 - Onboard Switch (SW1)
  20. Digital 3 - Onboard Peizo Speaker (SP1)
  21. Digital 4 - LED 1 (LED 1)
  22. Digital 5 - LED 2 (LED 2)
  23. Digital 6 - Accessory Terminal Block 1 (DA1) unused
  24. Digital 7 - Accessory Terminal Block 2 (DA2) unused
  25. Digital 8 - Accessory Terminal Block 3 (DA3) unused
  26. Digital 9 - Accessory Terminal Block 4 (DA4) unused
  27. Digital 10 - Reserved For Additional Shield (Ethernet shield pins correspond)
  28. Digital 11 - Reserved For Additional Shield (Ethernet shield pins correspond)
  29. Digital 12 - Reserved For Additional Shield (Ethernet shield pins correspond)
  30. Digital 13 - Reserved For Additional Shield (Ethernet shield pins correspond)
  31. */
  32.  
  33.  
  34. /* application settings, you should coustimize*/
  35. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // the mac address, you wont likely need to change this.
  36. byte ip[] = { 172, 24, 0, 77 }; // the ip address of the monitor
  37. byte gateway[] = { 172, 24, 0, 1 };                     // neccessary to get access to the internet via your router
  38. byte subnet[] = { 255, 255, 255, 0 };
  39. Server server(80); // the port your system will be opperating from for the web browser.
  40.  
  41. /* application settings, you may not want to tinker with these.*/
  42.  
  43. const int analogPin0 = 0;    // the pin that the potentiometer is attached to
  44. const int analogPin1 = 2;    // the pin that the potentiometer is attached to
  45. const int analogPin2 = 1;    // the pin that the potentiometer is attached to
  46. const int analogPin3 = 3;    // the pin that the potentiometer is attached to
  47. const int analogPin4 = 4;    // the pin that the potentiometer is attached to
  48. const int analogPin5 = 5;    // the pin that the potentiometer is attached to
  49.  
  50. int ledPin1 = 4;
  51. int ledPin2 = 5;
  52. int digitermRead1 = 6;
  53. int digitermRead2 = 7;
  54. int digitermRead3 = 8;
  55. int digitermRead4 = 9;
  56. int speakerPin =  3;
  57. int buttonPin = 2;     // the number of the pushbutton pin
  58. int buttonState = 0;
  59. int alarmsilent = 0; // shuts up the alarm sound
  60. int alarmstate = 1; //1 is no alarm, 0 is alarm
  61.  
  62. /* Humidity
  63. sensor settings*/
  64. int Hsamples[8]; // variables to make a better precision
  65. int i2;
  66. int humid = 0; // humidity variables
  67.  
  68. /* Temp sensor settings*/
  69. int Tsamples[8]; // variables to make a better precision
  70. int i1;
  71. int tempc = 0,tempf=0; // temperature variables
  72.  
  73. unsigned int sensorReading5 = 0;
  74. int sensorReading0 = 0;
  75.  
  76. void setup() {
  77.  pinMode(ledPin1, OUTPUT);    
  78.  pinMode(ledPin2, OUTPUT);
  79.  pinMode(digitermRead1, OUTPUT);
  80.  pinMode(digitermRead2, OUTPUT);
  81.  pinMode(digitermRead3, OUTPUT);
  82.  pinMode(digitermRead4, OUTPUT);
  83.  pinMode(speakerPin, OUTPUT);
  84.  pinMode(buttonPin, INPUT);
  85.  
  86.  blinkled2();
  87.  delay(100);
  88.  Serial.begin(9600);  
  89.  delay(100);
  90.  clearLCD();
  91.  delay(100);
  92.  selectLineOne();
  93.  Serial.print("System Starting");
  94.  delay(1500);
  95.  clearLCD();
  96.  delay(100);
  97.  
  98.  selectLineOne();
  99.  Serial.print("Web Server");
  100.  selectLineTwo();
  101.  Serial.print("172.24.0.77"); //manualy set this as your reminder to match the setting above
  102.  delay(1000);
  103.  
  104. //make the ethernet shield work
  105.  Ethernet.begin(mac, ip, gateway, subnet);
  106.  server.begin();
  107.  delay(3000);
  108.  clearLCD();
  109.  
  110.  
  111.  // status led, system working
  112.  digitalWrite(ledPin1, HIGH);   // set the LED on
  113.  
  114.  selectLineOne();
  115.  Serial.print("Processing");
  116.  
  117.  
  118. }
  119.  
  120. void loop(){
  121.  
  122. analogRead1();
  123. analogRead2();
  124. digiRead1();
  125. digiRead2();
  126. digiRead3();
  127. digiRead4();
  128. temp();
  129. humidity();
  130. sound();
  131. ldr();
  132.  
  133. }
  134.  
  135. void housekeeping(){
  136.   alarm();
  137.   blinkled2();
  138.   button();
  139.   webinterface();
  140. }
  141.  
  142. void analogRead1(){
  143.   housekeeping();
  144. }
  145.  
  146. void analogRead2(){
  147.   housekeeping();
  148. }
  149.  
  150. void digiRead1(){
  151.   housekeeping();
  152. }  
  153.  
  154. void digiRead2(){
  155.   housekeeping();
  156. }  
  157.  
  158. void digiRead3(){
  159.   housekeeping();
  160. }  
  161.  
  162. void digiRead4(){
  163.   housekeeping();
  164. }  
  165.  
  166.  
  167. void ldr(){
  168.    housekeeping();
  169.    sensorReading0 = analogRead(analogPin0);
  170.    selectLineOne();
  171.    Serial.print(sensorReading0 /10,DEC);
  172.    Serial.print("% Light Level");
  173.    delay(3000);                  // wait for a second
  174.    clearLCD();  
  175.  
  176.  
  177. }
  178. void humidity(){
  179.   housekeeping();
  180.  
  181.   for(i2 = 0;i2<=7;i2++){ // gets 8 samples of temperature
  182.   Hsamples[i2] = (analogRead(analogPin4) / 10);
  183.   humid = humid + Hsamples[i2];
  184.   delay (10);
  185.   }
  186.  
  187.   humid = humid/8.0; // better precision
  188.   selectLineOne();
  189.   Serial.print(humid,DEC);
  190.   Serial.print("% Humidity");
  191.   delay(3000);                  // wait for a second
  192.   clearLCD();  
  193. }
  194.  
  195. void temp(){
  196.   housekeeping();
  197.   for(i1 = 0;i1<=7;i1++){ // gets 8 samples of temperature  
  198.   Tsamples[i1] = (analogRead(analogPin4));
  199.   tempc = tempc + Tsamples[i1];
  200.   delay (10);
  201.   }
  202.        
  203.   tempc = tempc/8.0; // better precision
  204.   tempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit
  205.   selectLineOne();
  206.   Serial.print(tempc,DEC);
  207.   Serial.print(" Celsius");
  208.   selectLineTwo();
  209.   Serial.print(tempf,DEC);
  210.   Serial.print(" Fahrenheit ");
  211.   delay(3000);                  // wait for a second
  212.   clearLCD();  
  213.  
  214. }
  215. void sound(){
  216.    housekeeping();
  217.    sensorReading5 = analogRead(analogPin5);
  218.    selectLineOne();
  219.    Serial.print(sensorReading5 / 10,DEC);
  220.    Serial.print("% Sound Level");
  221.    delay(3000);                  // wait for a second
  222.    clearLCD();  
  223.  
  224. }
  225.  
  226.  
  227. /* Below this is general system utilitys*/
  228. void selectLineOne(){  //puts the cursor at line 0 char 0.
  229.    Serial.print(0xFE, BYTE);   //command flag
  230.    Serial.print(128, BYTE);    //position
  231. }
  232. void selectLineTwo(){  //puts the cursor at line 0 char 0.
  233.    Serial.print(0xFE, BYTE);   //command flag
  234.    Serial.print(192, BYTE);    //position
  235. }
  236. void clearLCD(){
  237.    Serial.print(0xFE, BYTE);   //command flag
  238.    Serial.print(0x01, BYTE);   //clear command.
  239. }
  240. void blinkled2(){
  241.   digitalWrite(ledPin2, HIGH);   // set the LED on
  242.   delay(50);                  // wait for a second
  243.   digitalWrite(ledPin2, LOW);    // set the LED off
  244.   delay(50);                  // wait for a second
  245. }
  246. void alarm(){
  247.   alarmthresholds();
  248.  
  249.   if (alarmstate = 0){
  250.   beep();
  251.   }
  252. }
  253.  
  254. void alarmthresholds(){
  255. // place your alarm conditions here. for example if you want to set an alert for a temp value.
  256. // change the value of alarm state if an exception occures.    
  257. }
  258.  
  259. void beep(){
  260.   for (int i=0; i<1000; i++) {  // generate tone
  261.   digitalWrite(speakerPin, HIGH);
  262.   delayMicroseconds(500);
  263.   digitalWrite(speakerPin, LOW);
  264.   delayMicroseconds(500);
  265.   }
  266. }
  267.  
  268. void button(){
  269.   blinkled2();
  270.   buttonState = digitalRead(buttonPin);
  271.   if (buttonState == HIGH) {    
  272.    alarmsilent = 1;
  273.     }
  274.   }
  275.  
  276. void webinterface(){
  277.  delay (100);
  278.    Client client = server.available();
  279.   if (client) {
  280.     // an http request ends with a blank line
  281.     boolean current_line_is_blank = true;
  282.     while (client.connected()) {
  283.       if (client.available()) {
  284.         char c = client.read();
  285.         // if we've gotten to the end of the line (received a newline
  286.         // character) and the line is blank, the http request has ended,
  287.         // so we can send a reply
  288.         if (c == '\n' && current_line_is_blank) {
  289.           // send a standard http response header
  290.           client.println("HTTP/1.1 200 OK");
  291.           client.println("Content-Type: text/html");
  292.  
  293.          
  294.           client.println();
  295.              
  296.        client.print("<h2>Server Status</h2>");
  297.        client.print("<br/>");    
  298.        
  299.        client.print(tempc,DEC);
  300.        client.print("&#176; Celsius");
  301.        client.print("<br/><br/> ");
  302.        client.print(tempf,DEC);
  303.        client.print("&#176; Fahrenheit");
  304.        client.print("<br/><br/>");
  305.  
  306.        client.print(humid,DEC);
  307.        client.print("% Humidity");
  308.        client.print("<br/><br/>");
  309.  
  310.        client.print(sensorReading0 /10,DEC);
  311.        client.print("% Light Level");
  312.        client.print("<br/><br/>");
  313.  
  314.        client.print(sensorReading5 / 10,DEC);
  315.        client.print("% Sound Level");
  316.        client.print("<br/><br/>");
  317.  
  318.           break;
  319.         }
  320.         if (c == '\n') {
  321.           // we're starting a new line
  322.           current_line_is_blank = true;
  323.         } else if (c != '\r') {
  324.           // we've gotten a character on the current line
  325.           current_line_is_blank = false;
  326.         }
  327.       }
  328.     }
  329.     // give the web browser time to receive the data
  330.     delay(1);
  331.     client.stop();
  332.   }  
  333.  
  334. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top