Reed Sensor Beginner Tutorial ( Magnet Sensor )

Code:

const byte reedSensor = 3;
const byte led = 2;
void setup() {
  // put your setup code here, to run once:
  pinMode(led, OUTPUT);
  pinMode(reedSensor, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(led, digitalRead(reedSensor));
}

Hello
The contact needs an input_pullup configuration to works proper.

const byte reedSensor = 3;
const byte led = 2;
void setup() {
  // put your setup code here, to run once:
  pinMode(led, OUTPUT);
  pinMode(reedSensor, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(led, !digitalRead(reedSensor));
}

That's not true, the sensor already got the resistor integrated on the PCB.

digitalWrite(led, digitalRead(reedSensor) == LOW ? HIGH : LOW);
digitalWrite(led, digitalRead(reedSensor)^1); 

:nerd_face:

...and now try that with a returned enum :wink:

Do you have a link to the board of which you speak? The video showed a picture but I didn't catch the board name if it was spoken.

Microcontroller
Amazon US: https://amzn.to/3faTh3B
Amazon UK: https://amzn.to/3i8FeO6
Amazon DE: https://amzn.to/2TFNNq2

it's called magnetic spring here
Sensors:
Amazon US: https://amzn.to/3i7sWFE
Amazon UK: https://amzn.to/3l77mCX
Amazon DE: https://amzn.to/2WDJ8q1

It seems to me the board is some sort of general analog / digital interface board.

It looks like you have a Power and Ground pin with an analog and digital output. My guess for the reed switch you would sense at the digital output.

Do you have a multimeter? If not you should get one. Even a cheap one is very useful for working with Arduinos. If you can spend a little more you might want to get one that measured frequency.

Yeah, I know but I can't afford it.

I don't know your situation but did you know you can get a usable Multimeter on eBay for $12. It would be good enough to tell if a digital line was 0 or 3.3v or 5V.
and an ohmmeter that can show you there is a short, open or approx resistance.

Oh, thank you. I'll have to wait for my next salary, but I will definitely order it. :slightly_smiling_face:

That is because you spent all your money on that totally unnecessary sensor board. There is no need to have that, just use the reed switch as if it were a push button, wired between input and ground and enable the internal pull up resistor.

While you sensor kit is not something a seasoned designer would purchase, I believe it is a place to start and learn what things are possible and generate your creativity. I think it is the nature of learning "kits". I remember having one when learning electronics (back in grade school), I'm sure if a designer at that time looked at the Kit I had they would laugh. However it was a start.

I know, right now I'm just creating videos for absolute beginners, after I created videos for all sensors I will start making videos about more advanced projects.

1 Like

You do an absolute beginner no service at all by making things more complex than is needed. They will not know that your sensor board is not needed and could easily spend money that they could spend on something more useful.

What a beginner needs is something as simple as possible. Making it far more complex than necessary only reduces its usefulness.