Where should I
connect the wires? What code should I use?
Connect COM to ground and NO to an Arduino digital input pin. Set the pin mode to INPUT_PULLUP and use digitalRead() to check the switch.
Identify the normally closed contact pair. Wire one contact to 0v, the other to any digital pin D2 to D12. In the code declare the pin as an INPUT_PULLUP . Use the NC contact pair is best practice for a limit switch as it fails safe if the wire gets disconnected.
That's a very basic question...
You have hundreds of online tutorials and videos to start with. For example try with this video, but if this is your Arduino skill level (absolute beginner), you need to start studying a bit at first instead of getting code from the forum.
Im new to unojoy coding but i can still like code on a normal arduino.
0v?
a/k/a GND
oh thank you
Which contacts? nc no or gnd
Best practice, one side of NC to GND the other to digital input pin.
Why are you asking that kind of things? Just watch the video I linked before, you'll get what you're asking for, and it'll let you start learning the basics, there's no need for you to keep asking how to do that.
type or paste code here
```thanks
Limit switches have 3 pins you can clearly see in the video its a two pin switch
Need help with the code?
If you're asking that, other than the coding (I still don't know what is your knowledge), I also must suppose you know nothing about switches and pushbuttons and you don't even have a tester/mutimeter to see how that switch works, and you have never connected anything to Arduino.
By the way, NO and NC pins mean Normally Open and Normally Closed respect the central pin. It means che if you don't press the switch the NO pin is not connected to the central one, while NC does that. When you press the switch, it reverses the connections (the NO pin is connected to the central one, and the NC is open).
But if you carefully see the video and listen what author explains, it will let you understand how the shown circuit works, how to connect it to an Arduino pin, and then the code needed to do something when pressed. The only difference with your hardware is in the fact the video uses a simple pushbutton (e.g. with NO only, Normally Open connection between the pins) and a "pull-down" resistor. In your case you either use the NO pin and a resistor, or NC pin without any resistor, as others said to you before. But the code will need changes to LOW and HIGH checks.
So, for the last time: watch that video, and start learning something instead of post questions about things you don't know at all at the moment.
No, but is the code shown under appropriate?
void setup() {
pinMode(7, INPUT_PULLUP);
}
Yes.
Thank you both