I want to control a motor with an Arduino using a relay, and I want the motor to run only when the magnetic reed switch is triggered. However, even if I only use 'pinMode(10, OUTPUT)' without any code, the motor keeps running continuously. I want it to pause for a specific delay when the reed switch is triggered and then continue running. The Arduino is connected to the COM and NO pins of the relay. Is there a solution to this?
Your request is missing a lot of information that we need to have before we can offer intelligent assistance.
Please post the your code.
Please read the forum guidelines to see how to properly post code and some information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in a code block.
Please post a schematic or a wiring diagram. Written descriptions are always more ambiguous than a drawing. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.
Photos of the wiring and overall project are often helpful.
Provide links to data sheets or other technical documentation for the components.
A schematic would help...
Can you turn the relay & motor on & off with the Blink Example? (Modify the code for a longer on/off time so the motor has enough time to start/stop, and to trigger pin-10 if that's where the relay is connected.)
Once you define a pin as an output, it will be high or low (I'm not sure what the default is). Then of course you need to run code to change the state.
The Arduino can't supply enough current to drive a regular relay coil. Normally you need a relay driver circuit or a "relay board" with a built-in driver.
Welcome pisgivecd, you have an interesting problem. You found the core of your problem, you need to write some code. Also you have the Arduino connected improperly per your description. There is a good chance you now have a fried Arduino. Post an annotated schematic showing how you wired it. Also post your code following forum guidelines and use code tags.
If you don't understand what a schematic is, please Google to find out. It is not quite the same thing as a wiring diagram. Hand-drawn is ok.
For starters I recommend following some tutorials on the Arduino and basic electronics.
COM (common), NO (normally open), and NC (normally closed) are usually the outputs of the relay - to control whatever. There should be at least two other terminals marked, possibly, as V+ & GND.
Hi, @plsgivecd
Welcome to the forum.
Can you tell us what model Arduino you are using?
What relay or relay module?
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
Thanks... Tom..
Try this link, I think it will answer your question: Arduino - Relay | Arduino Tutorial
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.