Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Ethernet.h>
- /*
- Sproutboard Server Room Monitor
- Sproutboard.com
- Analog I/O:
- Analog 0 - CCD Light Sensor (CDS1)
- Analog 1 - Accessory Terminal Block 1 (TA1) unused
- Analog 2 - Accessory Terminal Block 2 (TA2) unused
- Analog 3 - Onboard Accessories Socket 1 (Temperature sensor on external board J9)
- Analog 4 - Onboard Accessories Socket 1 (Humidity sensor on external board J9)
- Analog 5 - Onboard Accessories Socket 2 (Sound J10)
- Digital I/O:
- Digital 0 - Not used
- Digital 1 - Serial Terminal (TS1)
- Digital 2 - Onboard Switch (SW1)
- Digital 3 - Onboard Peizo Speaker (SP1)
- Digital 4 - LED 1 (LED 1)
- Digital 5 - LED 2 (LED 2)
- Digital 6 - Accessory Terminal Block 1 (DA1) unused
- Digital 7 - Accessory Terminal Block 2 (DA2) unused
- Digital 8 - Accessory Terminal Block 3 (DA3) unused
- Digital 9 - Accessory Terminal Block 4 (DA4) unused
- Digital 10 - Reserved For Additional Shield (Ethernet shield pins correspond)
- Digital 11 - Reserved For Additional Shield (Ethernet shield pins correspond)
- Digital 12 - Reserved For Additional Shield (Ethernet shield pins correspond)
- Digital 13 - Reserved For Additional Shield (Ethernet shield pins correspond)
- */
- /* application settings, you should coustimize*/
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // the mac address, you wont likely need to change this.
- byte ip[] = { 172, 24, 0, 77 }; // the ip address of the monitor
- byte gateway[] = { 172, 24, 0, 1 }; // neccessary to get access to the internet via your router
- byte subnet[] = { 255, 255, 255, 0 };
- Server server(80); // the port your system will be opperating from for the web browser.
- /* application settings, you may not want to tinker with these.*/
- const int analogPin0 = 0; // the pin that the potentiometer is attached to
- const int analogPin1 = 2; // the pin that the potentiometer is attached to
- const int analogPin2 = 1; // the pin that the potentiometer is attached to
- const int analogPin3 = 3; // the pin that the potentiometer is attached to
- const int analogPin4 = 4; // the pin that the potentiometer is attached to
- const int analogPin5 = 5; // the pin that the potentiometer is attached to
- int ledPin1 = 4;
- int ledPin2 = 5;
- int digitermRead1 = 6;
- int digitermRead2 = 7;
- int digitermRead3 = 8;
- int digitermRead4 = 9;
- int speakerPin = 3;
- int buttonPin = 2; // the number of the pushbutton pin
- int buttonState = 0;
- int alarmsilent = 0; // shuts up the alarm sound
- int alarmstate = 1; //1 is no alarm, 0 is alarm
- /* Humidity
- sensor settings*/
- int Hsamples[8]; // variables to make a better precision
- int i2;
- int humid = 0; // humidity variables
- /* Temp sensor settings*/
- int Tsamples[8]; // variables to make a better precision
- int i1;
- int tempc = 0,tempf=0; // temperature variables
- unsigned int sensorReading5 = 0;
- int sensorReading0 = 0;
- void setup() {
- pinMode(ledPin1, OUTPUT);
- pinMode(ledPin2, OUTPUT);
- pinMode(digitermRead1, OUTPUT);
- pinMode(digitermRead2, OUTPUT);
- pinMode(digitermRead3, OUTPUT);
- pinMode(digitermRead4, OUTPUT);
- pinMode(speakerPin, OUTPUT);
- pinMode(buttonPin, INPUT);
- blinkled2();
- delay(100);
- Serial.begin(9600);
- delay(100);
- clearLCD();
- delay(100);
- selectLineOne();
- Serial.print("System Starting");
- delay(1500);
- clearLCD();
- delay(100);
- selectLineOne();
- Serial.print("Web Server");
- selectLineTwo();
- Serial.print("172.24.0.77"); //manualy set this as your reminder to match the setting above
- delay(1000);
- //make the ethernet shield work
- Ethernet.begin(mac, ip, gateway, subnet);
- server.begin();
- delay(3000);
- clearLCD();
- // status led, system working
- digitalWrite(ledPin1, HIGH); // set the LED on
- selectLineOne();
- Serial.print("Processing");
- }
- void loop(){
- analogRead1();
- analogRead2();
- digiRead1();
- digiRead2();
- digiRead3();
- digiRead4();
- temp();
- humidity();
- sound();
- ldr();
- }
- void housekeeping(){
- alarm();
- blinkled2();
- button();
- webinterface();
- }
- void analogRead1(){
- housekeeping();
- }
- void analogRead2(){
- housekeeping();
- }
- void digiRead1(){
- housekeeping();
- }
- void digiRead2(){
- housekeeping();
- }
- void digiRead3(){
- housekeeping();
- }
- void digiRead4(){
- housekeeping();
- }
- void ldr(){
- housekeeping();
- sensorReading0 = analogRead(analogPin0);
- selectLineOne();
- Serial.print(sensorReading0 /10,DEC);
- Serial.print("% Light Level");
- delay(3000); // wait for a second
- clearLCD();
- }
- void humidity(){
- housekeeping();
- for(i2 = 0;i2<=7;i2++){ // gets 8 samples of temperature
- Hsamples[i2] = (analogRead(analogPin4) / 10);
- humid = humid + Hsamples[i2];
- delay (10);
- }
- humid = humid/8.0; // better precision
- selectLineOne();
- Serial.print(humid,DEC);
- Serial.print("% Humidity");
- delay(3000); // wait for a second
- clearLCD();
- }
- void temp(){
- housekeeping();
- for(i1 = 0;i1<=7;i1++){ // gets 8 samples of temperature
- Tsamples[i1] = (analogRead(analogPin4));
- tempc = tempc + Tsamples[i1];
- delay (10);
- }
- tempc = tempc/8.0; // better precision
- tempf = (tempc * 9)/ 5 + 32; // converts to fahrenheit
- selectLineOne();
- Serial.print(tempc,DEC);
- Serial.print(" Celsius");
- selectLineTwo();
- Serial.print(tempf,DEC);
- Serial.print(" Fahrenheit ");
- delay(3000); // wait for a second
- clearLCD();
- }
- void sound(){
- housekeeping();
- sensorReading5 = analogRead(analogPin5);
- selectLineOne();
- Serial.print(sensorReading5 / 10,DEC);
- Serial.print("% Sound Level");
- delay(3000); // wait for a second
- clearLCD();
- }
- /* Below this is general system utilitys*/
- void selectLineOne(){ //puts the cursor at line 0 char 0.
- Serial.print(0xFE, BYTE); //command flag
- Serial.print(128, BYTE); //position
- }
- void selectLineTwo(){ //puts the cursor at line 0 char 0.
- Serial.print(0xFE, BYTE); //command flag
- Serial.print(192, BYTE); //position
- }
- void clearLCD(){
- Serial.print(0xFE, BYTE); //command flag
- Serial.print(0x01, BYTE); //clear command.
- }
- void blinkled2(){
- digitalWrite(ledPin2, HIGH); // set the LED on
- delay(50); // wait for a second
- digitalWrite(ledPin2, LOW); // set the LED off
- delay(50); // wait for a second
- }
- void alarm(){
- alarmthresholds();
- if (alarmstate = 0){
- beep();
- }
- }
- void alarmthresholds(){
- // place your alarm conditions here. for example if you want to set an alert for a temp value.
- // change the value of alarm state if an exception occures.
- }
- void beep(){
- for (int i=0; i<1000; i++) { // generate tone
- digitalWrite(speakerPin, HIGH);
- delayMicroseconds(500);
- digitalWrite(speakerPin, LOW);
- delayMicroseconds(500);
- }
- }
- void button(){
- blinkled2();
- buttonState = digitalRead(buttonPin);
- if (buttonState == HIGH) {
- alarmsilent = 1;
- }
- }
- void webinterface(){
- delay (100);
- Client client = server.available();
- if (client) {
- // an http request ends with a blank line
- boolean current_line_is_blank = true;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- // if we've gotten to the end of the line (received a newline
- // character) and the line is blank, the http request has ended,
- // so we can send a reply
- if (c == '\n' && current_line_is_blank) {
- // send a standard http response header
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println();
- client.print("<h2>Server Status</h2>");
- client.print("<br/>");
- client.print(tempc,DEC);
- client.print("° Celsius");
- client.print("<br/><br/> ");
- client.print(tempf,DEC);
- client.print("° Fahrenheit");
- client.print("<br/><br/>");
- client.print(humid,DEC);
- client.print("% Humidity");
- client.print("<br/><br/>");
- client.print(sensorReading0 /10,DEC);
- client.print("% Light Level");
- client.print("<br/><br/>");
- client.print(sensorReading5 / 10,DEC);
- client.print("% Sound Level");
- client.print("<br/><br/>");
- break;
- }
- if (c == '\n') {
- // we're starting a new line
- current_line_is_blank = true;
- } else if (c != '\r') {
- // we've gotten a character on the current line
- current_line_is_blank = false;
- }
- }
- }
- // give the web browser time to receive the data
- delay(1);
- client.stop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement