Browse Source

working rev.

master
Your Name 6 years ago
parent
commit
c4eada4f74
1 changed files with 66 additions and 50 deletions
  1. +66
    -50
      ZMHW_Project_InfraredDiodeSensor.ino

+ 66
- 50
ZMHW_Project_InfraredDiodeSensor.ino View File

@ -53,7 +53,7 @@
#include <UIPEthernet.h> #include <UIPEthernet.h>
#include <EEPROM.h>
//#include <EEPROM.h>
@ -65,12 +65,12 @@
#define SICK 0 // set to 1 if using sick sensor (on analog pin) #define SICK 0 // set to 1 if using sick sensor (on analog pin)
// sick sensor is a transistor activated photoelectric // sick sensor is a transistor activated photoelectric
// sensor. More details below. // sensor. More details below.
#define NORMALMODECT 0 // For a digital High motion sensor.
#define NORMALMODECT 1 // For a digital High motion sensor.
/***************Ethernet ENC28J60***************/ /***************Ethernet ENC28J60***************/
//Mac must be unique for each sensor //Mac must be unique for each sensor
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xEA, 0x15 };
byte mac[] = { 0xD3, 0x5D, 0xBE, 0xEF, 0xEE, 0x15 };
//Static IP of Arduino //Static IP of Arduino
byte ip[] = { 192, 168, 1, 177 }; byte ip[] = { 192, 168, 1, 177 };
//IP of ZM Server //IP of ZM Server
@ -108,13 +108,13 @@ char* LOCATIONOFSENSOR = "Bay Four - Tool Room";
/***************Variables************/ /***************Variables************/
uint16_t MotionSensorRead = 0;
uint8_t AlarmActive = 0; uint8_t AlarmActive = 0;
char* ZMTriggerMessage = "1234567890123456789012345678901234"; //Initialize this with dummy data
char* ZMTriggerMessage = "1234567890123456789012345"; //Initialize this with dummy data
uint8_t TEMPERATUREVALUE = 0; uint8_t TEMPERATUREVALUE = 0;
uint8_t TEMPERATUREVALUE2 = 0; uint8_t TEMPERATUREVALUE2 = 0;
uint8_t SOUNDVALUE = 0; uint8_t SOUNDVALUE = 0;
uint8_t MODECTVALUE = 0;
uint16_t MODECTVALUE = 0;
/* /*
@ -137,7 +137,7 @@ char* monnum = "25"; //monitor number
char* onoff = "on"; //command to send to zmtrigger. char* onoff = "on"; //command to send to zmtrigger.
char* timealarm = "10"; //time to set monitor to alarm char* timealarm = "10"; //time to set monitor to alarm
char* score = "100"; //score to assign char* score = "100"; //score to assign
char* source = "ZMHW MotionSensor"; //source. Add details as needed (e.g. Hallway sensor)
char* source = "ZMHW"; //source. Add details as needed (e.g. Hallway sensor)
@ -154,7 +154,7 @@ char* source = "ZMHW MotionSensor"; //source. Add details as needed (e
EthernetClient client; EthernetClient client;
EthernetServer server2 = EthernetServer(LISTENPORT); EthernetServer server2 = EthernetServer(LISTENPORT);
/*
void chime(int freq){ void chime(int freq){
tone(SPEAKERPIN, freq, 50); tone(SPEAKERPIN, freq, 50);
delay(50); delay(50);
@ -163,7 +163,7 @@ void chime(int freq){
void chimefast(int freq, int fast){ void chimefast(int freq, int fast){
tone(SPEAKERPIN, freq, fast); tone(SPEAKERPIN, freq, fast);
delay(fast); delay(fast);
}
}*/
//timer/interrupt //timer/interrupt
uint16_t timer1; uint16_t timer1;
@ -193,13 +193,17 @@ void setup()
{ {
Serial.begin(9600); Serial.begin(9600);
Serial.println("ZMHW Project");
Serial.println("Motion Sensor");
Serial.println(F("ZMHW Project"));
Serial.println(F("Motion Sensor"));
//if sick
pinMode(SICKPIN, INPUT); pinMode(SICKPIN, INPUT);
//if mic
pinMode(MICROPHONEPIN, INPUT); pinMode(MICROPHONEPIN, INPUT);
//if speaker
pinMode(SPEAKERPIN, OUTPUT); pinMode(SPEAKERPIN, OUTPUT);
pinMode(MODECTPIN, INPUT); pinMode(MODECTPIN, INPUT);
pinMode(TEMPPIN, INPUT);
//Be careful. This sets Areg to 1.1v!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //Be careful. This sets Areg to 1.1v!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
analogReference(INTERNAL); analogReference(INTERNAL);
@ -208,7 +212,7 @@ void setup()
Ethernet.begin(mac, ip); Ethernet.begin(mac, ip);
server2.begin(); server2.begin();
Serial.print("server is at ");
Serial.print(F("server is at "));
Serial.println(Ethernet.localIP()); Serial.println(Ethernet.localIP());
@ -239,19 +243,19 @@ void setup()
sei(); //timer needs interrupts, enable (set) interrupts sei(); //timer needs interrupts, enable (set) interrupts
tone(SPEAKERPIN, 1000, 200);
delay(100);
tone(SPEAKERPIN, 2000, 200);
delay(100);
tone(SPEAKERPIN, 2200, 200);
delay(100);
//tone(SPEAKERPIN, 1000, 200);
//delay(100);
//tone(SPEAKERPIN, 2000, 200);
//delay(100);
//tone(SPEAKERPIN, 2200, 200);
//delay(100);
} }
void loop() void loop()
{ {
//delay(50);
@ -263,33 +267,40 @@ void loop()
//saves a few seconds to put a diode on the end instead of transistor //saves a few seconds to put a diode on the end instead of transistor
//when soldering by hand. Works equally as well. Requires ADC pin. //when soldering by hand. Works equally as well. Requires ADC pin.
/*
if (SICK){ if (SICK){
MotionSensorRead = analogRead(SICKPIN); MotionSensorRead = analogRead(SICKPIN);
Serial.print("Motion Sensor Value: "); Serial.print("Motion Sensor Value: ");
Serial.println(String(MotionSensorRead)); Serial.println(String(MotionSensorRead));
//Serial.println(String(timer1)); //Serial.println(String(timer1));
delay(10);
delay(30);
} }
*/
TEMPERATUREVALUE = analogRead(TEMPPIN); TEMPERATUREVALUE = analogRead(TEMPPIN);
Serial.print("Temperature Value: ");
Serial.print(F("Temperature Value: "));
// See resources. uses 1.1 aref, converts to celcius, then to Fareinheit. // See resources. uses 1.1 aref, converts to celcius, then to Fareinheit.
TEMPERATUREVALUE2 = (TEMPERATUREVALUE / 9.31)* 2 + 30; TEMPERATUREVALUE2 = (TEMPERATUREVALUE / 9.31)* 2 + 30;
Serial.println(String(TEMPERATUREVALUE2)); Serial.println(String(TEMPERATUREVALUE2));
delay(10);
delay(30);
/*
if (MIC){ if (MIC){
SOUNDVALUE = analogRead(MICROPHONEPIN); SOUNDVALUE = analogRead(MICROPHONEPIN);
Serial.print("Sound Value: "); Serial.print("Sound Value: ");
Serial.println(String(SOUNDVALUE)); Serial.println(String(SOUNDVALUE));
delay(10);
delay(30);
} }
//if (NORMALMODECT){
*/
if (NORMALMODECT){
delay(10);
MODECTVALUE = digitalRead(MODECTPIN); MODECTVALUE = digitalRead(MODECTPIN);
Serial.print("Motion Detector Value (normal): ");
Serial.println(String(MODECTVALUE));
//}
delay(10);
Serial.print(F("Motion Detector Value (normal): "));
//Serial.println(String(MODECTVALUE));
Serial.println(MODECTVALUE);
delay(30);
}
if(DEBUGMODE){ if(DEBUGMODE){
@ -307,8 +318,8 @@ void loop()
//Motion sensing for Sick Photoelectric sensor only //Motion sensing for Sick Photoelectric sensor only
//upon boot, values are around 400 sometimes, so only alert at higher //upon boot, values are around 400 sometimes, so only alert at higher
if(SICK){ if(SICK){
if (MotionSensorRead > 500 && AlarmActive == 0){
Serial.println("Motion Detected on Sick");
if (MODECTVALUE > 500 && AlarmActive == 0){
Serial.println(F("Motion Detected on Sick"));
//firstpacketsend = 0; //firstpacketsend = 0;
@ -322,7 +333,7 @@ void loop()
//Want the chime to be only noticeable if you know what to listen //Want the chime to be only noticeable if you know what to listen
//for. Make it a high freq. sound that is easy to miss. //for. Make it a high freq. sound that is easy to miss.
//Resistors to speaker should be high //Resistors to speaker should be high
chime(13000);
//chime(13000);
Serial.println("Connecting..."); Serial.println("Connecting...");
@ -330,16 +341,16 @@ void loop()
if (client.connect(server, ZMTRIGGERPORT)) { if (client.connect(server, ZMTRIGGERPORT)) {
chime(13000);
//chime(13000);
//beware that the buffer in snprintf is big enough to hold everything //beware that the buffer in snprintf is big enough to hold everything
snprintf(ZMTriggerMessage, 56, "%s|%s+%s|%s|%s||", monnum, onoff, timealarm, score, source); snprintf(ZMTriggerMessage, 56, "%s|%s+%s|%s|%s||", monnum, onoff, timealarm, score, source);
Serial.print("the TCP Packet being sent:");
Serial.print(F("the TCP Packet being sent:"));
Serial.println(String(ZMTriggerMessage)); Serial.println(String(ZMTriggerMessage));
client.println(String(ZMTriggerMessage)); //required client.println(String(ZMTriggerMessage)); //required
Serial.println("TCP packet sent to ZMTrigger");
Serial.println(F("TCP packet sent to ZMTrigger"));
client.stop(); client.stop();
} }
else { else {
@ -349,14 +360,16 @@ void loop()
//If you ARE connected to the network, and server is not available //If you ARE connected to the network, and server is not available
//then it will timeout. //then it will timeout.
Serial.println("Connection to ZM Server failed");
Serial.println(F("Connection to ZM Server failed"));
chime(50);
/*chime(50);
delay(100); delay(100);
chime(50); chime(50);
delay(100); delay(100);
chime(50); chime(50);
delay(100); delay(100);
*/
} }
} }
}//end sick }//end sick
@ -368,8 +381,8 @@ void loop()
//Digital High Motion Sensor //Digital High Motion Sensor
if(NORMALMODECT){ if(NORMALMODECT){
if (MODECTVALUE==HIGH){
Serial.println("Motion Detected on Normal Sensor");
if (MODECTVALUE==HIGH && AlarmActive == 0){
Serial.println(F("Motion Detected on Normal Sensor"));
//firstpacketsend = 0; //firstpacketsend = 0;
@ -383,24 +396,25 @@ void loop()
//Want the chime to be only noticeable if you know what to listen //Want the chime to be only noticeable if you know what to listen
//for. Make it a high freq. sound that is easy to miss. //for. Make it a high freq. sound that is easy to miss.
//Resistors to speaker should be high //Resistors to speaker should be high
chime(13000);
//chime(13000);
delay(10);
Serial.println("Connecting...");
Serial.println(F("Connecting..."));
if (client.connect(server, ZMTRIGGERPORT)) { if (client.connect(server, ZMTRIGGERPORT)) {
chime(13000);
//chime(13000);
//delay(10);
//beware that the buffer in snprintf is big enough to hold everything //beware that the buffer in snprintf is big enough to hold everything
snprintf(ZMTriggerMessage, 56, "%s|%s+%s|%s|%s||", monnum, onoff, timealarm, score, source); snprintf(ZMTriggerMessage, 56, "%s|%s+%s|%s|%s||", monnum, onoff, timealarm, score, source);
Serial.print("the TCP Packet being sent:");
Serial.print(F("the TCP Packet being sent:"));
Serial.println(String(ZMTriggerMessage)); Serial.println(String(ZMTriggerMessage));
client.println(String(ZMTriggerMessage)); //required client.println(String(ZMTriggerMessage)); //required
Serial.println("TCP packet sent to ZMTrigger");
Serial.println(F("TCP packet sent to ZMTrigger"));
client.stop(); client.stop();
} }
else { else {
@ -410,14 +424,15 @@ void loop()
//If you ARE connected to the network, and server is not available //If you ARE connected to the network, and server is not available
//then it will timeout. //then it will timeout.
Serial.println("Connection to ZM Server failed");
Serial.println(F("Connection to ZM Server failed"));
chime(40);
/* chime(40);
delay(100); delay(100);
chime(60); chime(60);
delay(100); delay(100);
chime(60); chime(60);
delay(100); delay(100);
*/
} }
} }
MODECTVALUE=LOW; MODECTVALUE=LOW;
@ -449,7 +464,7 @@ void loop()
// listen for incoming clients // listen for incoming clients
EthernetClient client = server2.available(); EthernetClient client = server2.available();
if (client) { if (client) {
Serial.println("new client");
Serial.println(F("web visitor"));
// an http request ends with a blank line // an http request ends with a blank line
boolean currentLineIsBlank = true; boolean currentLineIsBlank = true;
while (client.connected()) { while (client.connected()) {
@ -463,8 +478,8 @@ void loop()
// send a standard http response header // send a standard http response header
client.println("HTTP/1.1 200 OK"); client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html"); 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("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("<!DOCTYPE HTML>"); client.println("<!DOCTYPE HTML>");
client.println("<html><pre>"); client.println("<html><pre>");
@ -474,6 +489,7 @@ void loop()
//client.println("<b>IP Address:</b>"); //client.println("<b>IP Address:</b>");
//client.println(Ethernet.localIP()); //client.println(Ethernet.localIP());
client.println("<b>Sensor Location:</b>"); client.println("<b>Sensor Location:</b>");
//client.println("Bay Four - Tool Room");
client.println(LOCATIONOFSENSOR); client.println(LOCATIONOFSENSOR);
client.println("<b>Type of Sensor</b>:"); client.println("<b>Type of Sensor</b>:");
client.println("Microwave - HFS-DC06H"); client.println("Microwave - HFS-DC06H");
@ -495,7 +511,7 @@ void loop()
delay(1); delay(1);
// close the connection: // close the connection:
client.stop(); client.stop();
Serial.println("client disconnected");
Serial.println(F("client disconnected"));
} }

Loading…
Cancel
Save