I’m new to electronics, and playing with Argon/Xenon.
I’m trying to understand how to read if a circuit is open/closed but not sure if I’m going about it the right way.
On an Argon, I have wiring from 3V3 to an LED for feedback, then reed switch set as normally closed, then going back to GND.
So 3V3-Resistor-LED-ReedSwitchNC-ReadSwitchCOM-GND.
When I open the reed switch, the light goes on. Hooray. But I want to be able to check if the switch is open, but I can’t seem to get it right. Rather than trying to fix what I have, what’s the best way to do that?
Thanks for any help and advice.
This is what I’ve tried:
I’ve tried pinMode(pin, INPUT / INPUT_PULLUP / INPUT_PULLDOWN), and putting the wire from D6 before and after the reedswitch.
Checking the variable on the web console or Particle mobile app always returns 1 if D6 is before the reed switch, or 0 after the reed switch.
Using digitalRead(), does D6 become like GND, so the circuit is complete if it is connected before the reed switch, regardless if the reed switch is open or closed?
int pin = D6;
int pinValue;
void setup() {
pinMode(pin, INPUT); // Before ReedSwitch = Always 1. After ReedSwitch = Always 0.
//pinMode(pin, INPUT_PULLDOWN); // Before ReedSwitch = Always 1. After ReedSwitch = Always 0.
//pinMode(pin, INPUT_PULLUP); // Before ReedSwitch = Always 1. After ReedSwitch = Always 0.
Particle.variable("PinStatus", pinValue);
}
void loop() {
pinValue=digitalRead(pin);
}