diff --git a/Resources/LM35HigherResolution.html b/Resources/LM35HigherResolution.html new file mode 100644 index 0000000..d2fc91e --- /dev/null +++ b/Resources/LM35HigherResolution.html @@ -0,0 +1,184 @@ + + + + + + + + + Arduino Playground - LM35HigherResolution + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ +
+

The LM35 is a common TO-92 temperature sensor. It is often used with the equation +

+

+

+
temp = (5.0 * analogRead(tempPin) * 100.0) / 1024;
+ +
+ +

+

However, this does not yield high resolution. This can easily be avoided, however. The LM35 only produces voltages from 0 to +1V. The ADC uses 5V as the highest possible value. This is wasting 80% of the possible range. If you change aRef to 1.1V, you will get almost the highest resolution possible. +

+

The original equation came from taking the reading, finding what percentage of the range (1024) it is, multiplying that by the range itself(aRef, or 5000 mV), and dividing by ten (10 mV per degree Celcius, according to the datasheet: http://www.ti.com/lit/ds/symlink/lm35.pdf +

+

However, if you use 1.1V as aRef, the equation changes entirely. If you divide 1.1V over 1024, each step up in the analog reading is equal to approximately 0.001074V = 1.0742 mV. If 10mV is equal to 1 degree Celcius, 10 / 1.0742 = ~9.31. So, for every change of 9.31 in the analog reading, there is one degree of temperature change. +

+

To change aRef to 1.1V, you use the command "analogReference(INTERNAL);" +

+

Here's an example sketch using 1.1 as aRef: +

+

+

+

float tempC;
int reading;
int tempPin = 0;

void setup()
{
analogReference(INTERNAL);
Serial.begin(9600);
}

void loop()
{
reading = analogRead(tempPin);
tempC = reading / 9.31;
Serial.println(tempC);
delay(1000);
}

+ +
+ +

+

With this sketch, approximately a tenth of a degree resolution is possible. Of course, such small numbers are going to be somewhat inaccurate because aRef will not be exactly 1.1V. Also, the LM35 is only guaranteed to be within 0.5 degrees of the actual temperature. However, it does yield higher resolution, if only for appearances' sake. +

+

A side note: with aRef at 1.1V, the temperature range of the LM35 is limited to 0 to 110 degrees Celcius. +

+
+ + + +
+ +
+ +
+ + + + + + + + + +
+
+ +
+ + + + diff --git a/Resources/lm35.pdf b/Resources/lm35.pdf new file mode 100644 index 0000000..0095431 Binary files /dev/null and b/Resources/lm35.pdf differ diff --git a/ZMHW_Project_LaserDiodeSensor.ino b/ZMHW_Project_InfraredDiodeSensor.ino similarity index 67% rename from ZMHW_Project_LaserDiodeSensor.ino rename to ZMHW_Project_InfraredDiodeSensor.ino index fae3cdd..29058ba 100644 --- a/ZMHW_Project_LaserDiodeSensor.ino +++ b/ZMHW_Project_InfraredDiodeSensor.ino @@ -56,7 +56,7 @@ /***************Ethernet ENC28J60***************/ //Mac must be unique -byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xEA, 0x11 }; +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xEA, 0x15 }; //IP of Arduino byte ip[] = { 192, 168, 1, 177 }; //IP of zm server @@ -69,9 +69,9 @@ String host="192.168.1.178"; //username and password to login to Zoneminder Server. //If you don't have authentication, you will need to edit the //script. -//NOTE: not needed for ZMTrigger. Only API. -String username="username"; -String password="password"; +//NOTE: not needed for ZMTrigger. Only API. DO NOT USE +//String username="username"; +//String password="password"; EthernetClient client; @@ -79,14 +79,17 @@ EthernetClient client; #define ZMTRIGGERPORT 6802 +//set to 1 if using sick sensor (on analog pin) +#define SICK 0 /***************Pins***************/ #define SPEAKER_PIN 6 #define LED_PIN 9 -#define RESETPIN 2 //may not be needed here +//#define RESETPIN 2 //may not be needed here #define SENSORPIN A1 +#define TEMPPIN A0 @@ -95,8 +98,9 @@ EthernetClient client; int MotionSensorRead = 0; uint8_t AlarmActive = 0; -char* ZMTriggerMessage = "1234567890123456789012345678901234"; //Initialize this with dummy data - +char* ZMTriggerMessage = "1234567890123456789012345678901234"; //Initialize this with dummy data +int TEMPERATUREVALUE = 0; +int TEMPERATUREVALUE2 = 0; // Upper and lower limit for ADC to register motion @@ -138,6 +142,17 @@ char* source = "ZMHW MotionSensor"; //source + +// Initialize the Ethernet server library + +#define LISTENPORT 80// (port 80 is default for HTTP): +EthernetServer server2 = EthernetServer(LISTENPORT); + + + + + + //Do not need to edit below @@ -189,11 +204,17 @@ void setup() pinMode(SENSORPIN, INPUT); pinMode(SPEAKER_PIN, OUTPUT); - pinMode(RESETPIN, OUTPUT); + //pinMode(RESETPIN, OUTPUT); + + //Be careful. Areg is 1.1v!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + analogReference(INTERNAL); Ethernet.begin(mac, ip); + server2.begin(); + Serial.print("server is at "); + Serial.println(Ethernet.localIP()); @@ -247,13 +268,23 @@ void loop() Serial.print("Motion Sensor Value: "); Serial.println(String(MotionSensorRead)); //Serial.println(String(timer1)); + delay(10); + + TEMPERATUREVALUE = analogRead(TEMPPIN); + Serial.print("Temperature Value: "); + // See resources. uses 1.1 aref, converts to celcius, then to Fareinheit. + TEMPERATUREVALUE2 = (TEMPERATUREVALUE / 9.31)* 2 + 30; + Serial.println(String(TEMPERATUREVALUE2)); + delay(10); if(DEBUGMODE){ delay(10); } + //Motion sensing for Sick Photoelectric sensor only //upon boot, values are around 400 sometimes, so only alert at higher + if(SICK == 1){ if (MotionSensorRead > 500 && AlarmActive == 0){ Serial.println("Motion Detected"); @@ -309,6 +340,7 @@ void loop() delay(100); } } + }//end sick @@ -321,7 +353,58 @@ void loop() - + //Serve Status Page + // listen for incoming clients + EthernetClient client = server2.available(); + if (client) { + Serial.println("new client"); + // an http request ends with a blank line + boolean currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the http request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard http response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println("
");
+          client.println("Steak Electronics");
+          client.println("\"Steak it easy... That is, don't overcook steak\"");
+          client.println("");
+          //client.println("IP Address:");
+          //client.println(Ethernet.localIP());
+          client.println("Sensor Location:");
+          client.println("Bay Four - Tool Room");
+          client.println("Type of Sensor:");
+          client.println("Microwave - HFS-DC06H");
+          client.println("Temperature Sensor Value:");
+          client.println(TEMPERATUREVALUE2);
+          client.println("
"); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + // close the connection: + client.stop(); + Serial.println("client disconnected"); + }