Last week, I continued work on the project during a weekend that was extended due to snow.
I started off by running the Blink sketch on the Feather board. The board proved to be similar enough to the Adafruit Trinket that I have some experience with, which was reassuring. Next, I read the documentation for Adafruit's PIR sensor, loaded the PIR test code onto the Feather, wired the sensor to the Feather with some hookup wire and a breadboard, and did a brief test. Thankfully, the VBUS pin worked fine to power the sensor. The code, which can be found here, follows:
/*
* PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = 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;
}
}
}
After fumbling around with the Arduino IDE's GUI, I was able to view the results of the program in the Serial Monitor. Everything seemed to be in order.
I then read up on the documentation for the Relay FeatherWing. I added a wire to the Feather on pin A5, and a wire to the Signal pin of the FeatherWing. On a breadboard, I connected A5 to Signal and modified the PIR test code to switch on the relay when motion is detected. The code then read as follows:
/*
* PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = A0; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int relPin = A5;
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
pinMode(relPin, OUTPUT); //declare pin A5 as relay trigger
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
digitalWrite(relPin,HIGH);
Serial.println("Relay on!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
digitalWrite(relPin,LOW);
Serial.println("Relay off!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
I checked and uploaded the code, but saw no result on the relay. After closer inspection, I realized that the relay did not have power. I returned to my soldering iron, and added a wire to 3V on the FeatherWing, and a wire to the 3V bus on the Feather. I went back and tried the sketch again. Another round of thought revealed that I hadn't connected the FeatherWing to ground. At this point, I made two notes:
"This isn't a complete circuit. Oops"
and
"Solder ground to relay. Headers would have eased this process."
Once all the necessary connections were made, the sketch worked as expected.
Satisfied, I ended work on the project for the afternoon.
This past Friday, I began thinking about the manner in which I would power the board and sensor when the motion sensor assembly was installed in the gallery space. My professor suggested that I could hypothetically use the MIDI out of the MIDI Solutions F8 to power the assembly. After struggling with the idea for awhile, I realized that he meant that I could power the sensor with the F8, and have the board next to the F8 rack unit. After thinking some more, I realized that I could connect the Feather and PIR sensor's power, ground, and signal lines through an XLR cable, and thereby omitting the F8 from powering the board at all. The sensor proved capable of functioning when separated from the Feather by 100' of XLR.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.