Step 3Arduino Sketch
I used the 1K resistors on the led1Pin and led2Pin.
I used the 10K resistor on speakerPin going to 2N2222 transistor base, ground to the emitter. Then the emiter went to one side of the toy switch and the collector went to the other. This worked the 2N2222 transistor as a switch.
Look at the comments for the arduino pin wiring.
#include <X10Firecracker.h>
#include <Servo.h>
Servo myservo; // New instance of Servo.h
int rtsPin = 2; // RTS line for C17A - DB9 pin 7
int dtrPin = 3; // DTR line for C17A - DB9 pin 4
// Connect DB9 pin 5 to ground.
int servoPin = 5; // Servo used to lift the reel
int pirPin = 8;
int led1Pin = 10; // Left led
int led2Pin = 11; // Right led
int speakerPin = 12; // Piezo buzzer speaker
int bitDelay = 1; // mS delay between bits (1 mS OK)
int ledStatus = 0;
int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int booCounter = 1;
void setup(){
Serial.begin(9600); // Start serial communication at 9600 baud rate
pinMode(led1Pin, OUTPUT); // Set led1Pin digital pin to output
pinMode(led2Pin, OUTPUT); // Set led1Pin digital pin to output
pinMode(speakerPin, OUTPUT);// Set speakerPin digital pin to output
pinMode(servoPin, OUTPUT); // Set led1Pin digital pin to output
myservo.attach(7); // Atach servo on pin 7 for continous rotation servo
X10.init(rtsPin, dtrPin, bitDelay); // Initialize X10 C17A
pinMode(pirPin, INPUT);
digitalWrite(pirPin, LOW);
//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
myservo.write(140);
}
void loop(){
if(digitalRead(pirPin) == HIGH){
Serial.print("[[[get|http://www.mysite.com/iobridge.html]]]"); // send serial message to iobridge.
digitalWrite(led1Pin, HIGH); //the led visualizes the sensors output pin state
digitalWrite(led2Pin, HIGH); //the led visualizes the sensors output pin state
if(lockLow){
// makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
// Release the reel by lifting servo.
myservo.write(140);
// Turn on toy with sound
digitalWrite(speakerPin, HIGH);
delay(100);
digitalWrite(speakerPin, LOW);
delay(7000);
myservo.write(65);
// send x10 commands to trun off/on lights
X10.sendCmd( hcC, 1, cmdOn );
X10.sendCmd( hcC, 3, cmdOn );
X10.sendCmd( hcC, 2, cmdOff );
int var = 0;
// Activate the continous rotation servo.
while(var < 800){
digitalWrite(servoPin,HIGH);
delayMicroseconds(1200); // 1.5ms
digitalWrite(servoPin,LOW);
delay(20); // 20ms
var++;
}
delay(50);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW){
if (ledStatus == 0){
digitalWrite(led1Pin, HIGH);
digitalWrite(led2Pin, LOW);
ledStatus = 1;
delay(100);
}
else{
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, HIGH);
ledStatus = 0;
delay(100);
}
if(takeLowTime){
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
// Send x10 commands
X10.sendCmd( hcC, 1, cmdOff );
X10.sendCmd( hcC, 3, cmdOff );
X10.sendCmd( hcC, 2, cmdOn );
}
}
}
| « Previous Step | Download PDFView All Steps | Next Step » |














































Sorry about that and we'll have it back as soon as we can!