Moderators: adafruit_support_bill, adafruit
I can usually get the whole thing going again after a lot of wire swapping, resetting etc
//
// PIR motion detector with LED indicator
// Status info by XBee to PC
// 11 Jan 2013
//
#include <Wire.h>
#include <RTClib.h>
#include <SoftwareSerial.h>
RTC_DS1307 RTC;
SoftwareSerial XBSerial = SoftwareSerial(2, 3);
int PIRpin = 4; // digital pin 4 for PIR
int LEDpin = 13; // digital pin 13 for LED
int PIRval; // PIR HIGH or LOW value
void setup() {
pinMode(LEDpin, OUTPUT); // set the LED pin as ouput
pinMode(PIRpin, INPUT); // set the PIR pin as an input
// Setup SoftwareSerial port
XBSerial.begin(9600);
Serial.begin(9600);
XBSerial.println("Setup finished.");
if (! RTC.isrunning())
{
Serial.println("RTC is NOT running!");
}
}
void loop() {
PIRval = digitalRead(PIRpin); // read PIR
if (PIRval == HIGH) {
Serial.print("H");
digitalWrite(LEDpin, HIGH); // LED ON
}
else {
Serial.print("L");
digitalWrite(LEDpin, LOW); // LED OFF
}
delay(100);
}
//XBeeReceive
//Sketch for receiving XBee transmissions from RemotePIR on remote
//Boarduino connected to a PIR and XBee
//KC 11-Jan-13
int LedPin = 13;
int speakerPin = 9;
void setup() {
//
Serial.begin(9600);
pinMode(LedPin, OUTPUT);
pinMode(speakerPin, OUTPUT);
}
void playTone(int tone, int duration){
for (long i = 0; i < duration*1000L; i += tone*2){
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void loop() {
//
if (Serial.available())
{
int data = Serial.read();
if (data == 'H')
{
//Serial.println("Somebody's in the garden");
digitalWrite(LedPin, HIGH);
Serial.write("h");
playTone(956, 50);
playTone(500, 50);
playTone(250, 50);
playTone(125, 50);
}
else if (data == 'L')
{
digitalWrite(LedPin, LOW);
Serial.write("l");
}
else
{
digitalWrite(LedPin, LOW);
}
//delay(10);
}
}
Return to XBee products from Adafruit
Users browsing this forum: No registered users and 3 guests