I am working on a knock sensor project and using the code I found in Instructables. I am changing it up a bit to run a relay that will shut off power to a maglock. The project as it is controls a servo. I have worked with relays before, but have not had to actually wire them up (they have already been connected to the UNO in project boards I have used before.)
I hope I am following any guidelines set up for help. If not, let me know and I will figure it out. Thanks in advance.
So I actually have two questions and need the guidance.
-
Hooking up the relay. I just need guidance to hook it into the correct pins on the UNO. I can handle the connection to the NC Maglock.
-
In the sketch attached , I know this is the section that runs the motor to turn the lock, but need guidance to change this to trigger a relay on the 5v pin:
/ Runs the motor (or whatever) to unlock the door.
void triggerDoorUnlock(){
Serial.println("Door unlocked!");
int i=0;
// turn the motor on for a bit.
digitalWrite(lockMotor, HIGH);
digitalWrite(greenLED, HIGH); // And the green LED too.
delay (lockTurnTime); // Wait a bit.
digitalWrite(lockMotor, LOW); // Turn the motor off.
/code]/
which I changed to:
[code]// Runs the motor (or whatever) to unlock the door.
void triggerDoorUnlock(){
Serial.println("Door unlocked!");
int i=0;
digitalWrite(relay, 0); // Closes the relay
digitalWrite(greenLED, HIGH); // And the green LED too.
delay (relayon); // keep it closed for 650ms
digitalWrite(relay, 1); // opens the relay again
/code]
[/code]
I also made sure to change the definitions in the beginning of the sketch. Here is the full sketch.
The sketch is too long so I am attaching as directed.
secret_knock2.ino (9.92 KB)