Magnetic Detection Sensor Module

Hello world!

Some words about my tests with sensors I bought to go-kart project…

All of them work basically in the same way, you must connect VCC pin to Arduino 5v pin, G pin (or ground, or “-“) to Arduino groud pin and Out pin (or whatever its named) to some digital pin, in this example I used pin 2. When it detects a magnetic field (like a magnet) they change the status from 0 to 1, or from open to closed, or from LOW to HIGH… Whatever you need! Using digitalRead() function in Arduino is pretty easy to use them.

There’s one and a half exception only: The real exception is the last one (right side) in the picture below changes from 1 to 0 instead. For sure this is not a problem, you must just remember it when you’re writing your code. The “half” exception is the first one (left side) that looks to have also an analog output, I didn’t even tested it or Googled to know how it works… And I’m not planning to do it so soon…

.IMG_0630[1]

By now I tested them with a pretty small rare-earth magnet I found at home. The better one in my opinion is the red one in the right. It detected the magnet more or less from 1,5 cm and the others about 1 cm. I hoping to have better values with bigger magnet, otherwise I’m in a bad shape for what I’m planning to do.

To test it I wrote this small code that turns on the led at port 13. (or turn it of, in the case of right one).

int magnet = 2;
int led = 13;

void setup() {
pinMode(led, OUTPUT);
pinMode(magnet, INPUT);
digitalWrite(led, LOW);
}

void loop() {
int magnetState = digitalRead(magnet);
if (magnetState) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
delay(1);
}

Easy, isn’t it? You can replace digitalWrite(led, HIGH) or digitalWrite(led, LOW) for whatever you want to do when it detects the magnetic field.

DX links to the magnetic sensors (in the order of the picture):

Btw… I also tested a Funduino Uno that I bought, since DX is not selling Arduino (I know it was fake) anymore. So far now it seems to work as an Arduino Uno!

Leave a Reply