Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <UIPEthernet.h>
- #include <PubSubClient.h>
- #include <Pir.h>
- #include <avr/wdt.h>
- // Update these with values suitable for your network.
- String devices[] = {"PR1"};
- String boardName = "BA01";
- String boardsChannel = "wrks_boards";
- String sensorsChannel = "wrks_sensors/BA01";
- EthernetClient ethClient;
- PubSubClient client(ethClient);
- int pr1Pin = 2; // choose the input pin (for PIR sensor)
- int pr1State = LOW; // we start, assuming no motion detected
- int pr1Val = 0; // variable for reading the pin status
- void setup()
- {
- // BEGIN Ethernet client declaration
- // Change MAC Address
- byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
- // MQTT Server IP Address
- IPAddress server(192, 168, 1, 181);
- Serial.print("Ethernet Begin");
- Serial.begin(9600);
- Ethernet.begin(mac);
- Serial.print("Board IP Address: ");
- Serial.println(Ethernet.localIP());
- client.setServer(server, 1883);
- // END Ethernet client declaration
- pinMode(pr1Pin, INPUT); // declare PIR sensor as input
- // Allow the hardware to sort itself out
- delay(2000);
- }
- void loop()
- {
- g5 = digitalRead(pr1Pin); // read input value
- if (pr1Val == HIGH) { // check if the input is HIGH
- if (pr1State == LOW) {
- // we have just turned on
- Serial.println("Motion detected!");
- // We only want to print on the output change, not state
- pr1State = HIGH;
- }
- } else {
- digitalWrite(ledPin, LOW); // turn LED OFF
- if (pirState == HIGH){
- // we have just turned of
- Serial.println("Motion ended!");
- // We only want to print on the output change, not state
- pirState = LOW;
- }
- }
- }
Add Comment
Please, Sign In to add comment