DFRobot Realy Sheild Version 2.1

Hello all,

I currently have a DFROBOT 4 Relay Sheild V 2.1, my goal is to trigger the device via an external source e.g a contact or signal, just for starters.

My ultimate goal is to have the Arduino board receive a signal that will begin to check the status of a reed switch, once all conditions are satisfied I then would like it to trigger / send a signal to the external device to perform a function.

any help even a simple start would be appreciated.

Regards
Theodore.

G’day,

For your first goal, testing the module and how to trigger a relay from an external source;

  • place the Relay Shield for Arduino V2.1 (SKU:DFR0144) on an insulating surface such as cardboard, paper, or plastic,
  • check that the digital I/O selection headers are in their original positions; for each of the three black based pins in the middle of the module, the shorting header should be on the position shown in the product photograph; shorting between an Arduino pin number and the centre pin; the Arduino pin numbers are D2, D7, D8, D10,
  • attach a 9V DC supply, observing correct polarity, to the power input screw terminal; it’s the screw terminal with only two screws and has a label behind it that says Servo_PWR,
  • if you’ve not got a 9V DC supply, any unregulated DC supply which has an output of between 8V and 12V could be used; any higher and there’s a increased risk of overheating of the regulator, especially in hot weather or outside; overheating shuts it down,
  • check that the PWR LED lights up,
  • press the S1, S2, S3, S4 buttons one by one; each should cause a click from the appropriate relay,
  • grab a short jumper lead and insert one end into the D2 socket (green), then touch the other end to a 5V pin; with a red base; nearby, within a centimetre; the S1 relay should click,
  • repeat for D7, D8 and D10,

With that, you’ve tested the module standing by itself; using a jumper lead as the source of the signal. You could add a switch between two jumper leads, and that will be your external source.

Then turn off the power, insert the Arduino Uno, write a “blink” sketch to turn D2 on and off as if it is a LED, upload the sketch, turn on the power, and the S1 relay will click on and off repeatedly.

With that, you’ve tested the Arduino can operate a relay.

Iterate from there; improving the sketch to meet your needs.

Hope that helps.

1 Like

Thank you for your advice,

I have tested the relay and all works well, all the buttons the pins connections labelled D0 etc… trigger the relay also, I also tested with a multimeter for continuity and all is working well.

I am using a regulated 12 V power supply, by the way, also the serial monitor interface, pressing 1 to 4 also triggers the relays.

my need is to amend the code so that I am able to trigger a series of events, e.g. the position of gates, using a reed switch to indicate a closed state, the unit then via relays or sends a signal or trigger to proceed to open the gates.

I have little experience with C++, I know loops, switches, pointers, inheritance, classes etc… but very little experience with software to the hardware interface, just need a guiding step and I can take care of the rest.

once again I thank you for giving me my first steps to checking the validity of the unit.

Regards
Theodore.

G’day,

I’m not quite sure what you want the Arduino to do in response to the reed switch closing or opening. You want it to close one or more of the relays; but is there a particular timing, or sequence needed? Put it into words as a list of steps, we can negotiate on the literal meaning, and then I can convert that into some code. I’m human, so I may make mistakes; test carefully.

Hello quozl,

ok, so ill try to clarify, pardon my poor pseudocode.

  1. 3 reed switches to indicate an open or closed circuit/state of a gate.

  2. trigger from gate control to Arduino unit.

  3. Arduino unit checks the state of the reed switch.

  4. If gate closed state: gate reed switch closed and the drop bolt reed switches down position(reed switch down pos closed), then send signal/trigger relays to pull up drop bolts.

  5. once bolts are up and reed switches are in up position (reed switches closed to up position), then trigger gate controller to operate arm to open gates.

  6. if gates open state: if reed switch of gate position open and reed switch of drop bolts down, then pull up drop bolts.

  7. If gate switches open and drop bolts reed switch set to up position, then send signal / Trigger to gate controller to operate arm to close the gate.

Vice Versa, not sure if this makes sense.

once again thank you for your assistance in this matter.

Thanks. I’m not sure I’ve got it right; I don’t know what a gate control or gate controller is, or how many there are. Let me rephrase and you tell me where I get it wrong. I’ll use italics for signal names.

  • there’s four input signals to the Arduino;
    • gate closed sensor,
    • drop bolt down sensor,
    • drop bolt up sensor,
    • a gate control switch; something a human operates perhaps,
  • there’s three output signals from the Arduino;
    • pull up the drop bolts,
    • gate controller please open,
    • gate controller please close,
  • the Arduino sketch will start by waiting for the gate control switch to be pressed, and then act depending on the state of the gate closed sensor;
    • if the gate closed sensor is active (the gate is closed), pull up the drop bolts, wait until the drop bolt up sensor is active, then ask gate controller please open, and go back to waiting as above,
    • if the gate closed sensor is inactive (the gate is open), then ask gate controller please close, wait until the gate closed sensor is active, release pull up the drop bolts, wait until the drop bolt down sensor is active, and go back to waiting as above.

Hello quozl,

yes, that is correct, thank you.

just one thing when the gate is closed the drop bolts should go down, it’s only when the gates have to open or close that the drop bolts should be up, otherwise the bolts drag on the ground and cause the motor sensors to heat and stop the operation.

Oh im using a Came gate system.

Regards
Theodore.

Hmm, okay, I thought I wrote that down; can you check what I wrote again? Especially note what happens before something else; the time ordering. Is the list of inputs and outputs correct? Does the bolt go down by gravity alone?

No, the drop bolt is a type of worm drive or actuators, driven by a motor attached to a helix or threaded shaft, I will take another look at your notes, Thank you again, really appreciate your help on this.

what you wrote earlier sound correct:
Stage 1.

  1. Remote signal to gate control to open/triggered, send a signal to Arduino to check the status of the gate and drop bolts.

  2. If the gate is closed and the reed switch is in closed position && Drop Bolt reed switch is in down position then,

  3. Trigger / Run actuators to pull drop bolts up (time delay for bolts to go up then check state-run step 4)

  4. If the gate is closed and the reed switch is in closed position && Drop Bolt reed switch is up position then,

  5. Send signal or trigger gate control to open gates.

Stage 2.

  1. Remote signal to gate control to close the gate / triggered, send a signal to Arduino to check the status of the gate and drop bolts.

  2. If gate position open and gate reed switch is open position && drop bolts position and reed switch position is down then

  3. Trigger / Run actuators to pull up drop bolts (time delay for bolts to go up then check state-run step 4).

  4. If gate position open and gate reed switch is open position && drop bolts position is up and reed switch up position, then

  5. Send signal / Trigger Gate control to close gate.

  6. once the gate is closed and reed switch closed && Drop bolts are in up position, then.

  7. Trigger / Run actuators to push down drop bolts.

Stage 3 goto Stage 1.

Hope this helps.

Thanks. Can the drop bolt be driven by one digital output from the Arduino, or will two be required? What I wrote earlier was that there was only one.

there are two drop bolts, but you can command one relay to operate two separate relays.

I’m not sure if my question got across; what I’m asking is whether one digital output from the Arduino can be used to operate the drop bolt mechanism. e.g. make the digital output HIGH to raise the drop bolt, make the digital output LOW to lower the drop bolt.

Or, alternatively, if two digital outputs are required; e.g. make one of them HIGH then LOW to command the drop bolt to raise, make the other of them HIGH then LOW to command the drop bolt to fall.

If you’ve specifications or schematics of the drop bolt device, let me know?

Oh, I’m so sorry, the motors work on polarity, therefore you will need separate relays to perform the up and down motion otherwise the Arduino will have to hold the relay in one position to either keep it up or down.

hmm, how to put this: you will trigger one relay to run the down motion say + - then up motion - +, they do not automatically go to a fixed position.

therefore you will need one trigger high (Polarity + -) to run up and another relay high (Polarity - +) for down.

so you can’t use one relay to do both up and down, you need two of them, one to trigger up and one to trigger down.

so all up there are 4 relays, 2 for one motor and 2 for the second motor.

not sure if this makes sense.

Ah, yes, makes sense. The diagram shows a DPDT switch with a centre-off position, or DPCO. The relay shield has SPDT relays with no centre-off position. Possible to use, but more difficult, as without the mechanical connection between the arms there’s a risk of one switch closed while the other is open. Look at your diagram and see how this creates a short circuit with the power supply and will blow the fuse. The fuse is on the left of the switch to protect the power supply and cabling from either motor overcurrent or switch mechanical breakage.

It would be more common to use a motor driver shield, selected for the drive current and voltages of the motors.

But you can do it with relays with care.

Now I’ll rewrite my psuedocode given this new data.

Suggested psuedocode for gate motor and bolt motor drive. You tell me where I get it wrong. I’ll use italics for signal names.

  • there’s five input signals to the Arduino;
    • gate closed sensor,
    • gate open sensor,
    • drop bolt up sensor,
    • drop bolt down sensor,
    • a gate control switch; something a human operates perhaps,
  • there’s four output signals from the Arduino;
    • gate controller please open,
    • gate controller please close,
    • drop bolts please pull up,
    • drop bolts please push down,
  • the Arduino sketch will start by waiting for the gate control switch to be pressed, and then act depending on the state of the gate closed sensor;
    • if the gate closed sensor is active (the gate is closed), ask drop bolts please pull up, wait until the drop bolt up sensor is active, turn off drop bolts please pull up, then ask gate controller please open, wait until the gate open sensor is active, then turn off gate controller please open, ask drop bolts please push down, wait until the drop bolt down sensor is active, and go back to waiting as above,
    • if the gate closed sensor is inactive (the gate is open), ask drop bolts please pull up, wait until the drop bolt up sensor is active, turn off drop bolts please pull up, then ask gate controller please close, wait until the gate closed sensor is active, then turn off gate controller please close, ask drop bolts please push down, wait until the drop bolt down sensor is active, and go back to waiting as above.

It may help to wave your arms about as you read this; one arm for the gate, the other arm for the drop bolts. Imagine obeying the pseudocode.

Also, it would be more common to attach NC (normally closed) limit switches, which are physical sensors, in place of the Arduino, so that the motors are stopped when they reach the desired position. This takes the Arduino out of the responsibility. Your diagram has an example of a “thrust detection part” which probably turns off the motor once enough tension has been detected.

Hello quozl,

yes, your pseudocode is correct, thank you so much for helping me, I will attempt to implement it the best I can, If you have any reference to an example code using the relay shield v2.1 please let me know.

I will also look into the motor shield as well cheers, didn’t know one existed.
p.s my arms are tired :stuck_out_tongue:

Kind Regards
Theodore