Hopefully a quick solution

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.

  1. 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.

  2. 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)

In the sketch attached (in Word for ease)

Don't do that please read How to use this forum

I am changing it up a bit to run a relay that will shut off power to a maglock.

So you have a project that you are not going to show us the schematic of and you want us to show you how to change the schematic to something different. Reading How to use this forum will teach you how to ask a question as well.

Sorry Mike, i am trying to get it right. I could not upload a pic of BB or Uno, they were too large. But hopefully what I did right will work.

Sorry we don't need a picture we need a schematic. A picture is only useful to see if you have wired it like the schematic.

If the picture is too big can you not reduce the size in a photo editing program. They come free with the Mac, I am sure Windows has the same simple free app.