Arduino Magnetic FIELD Detector KY-003 / KY-035

Arduino Magnetic FIELD Detector.
Hello world! Here i am again. Today i made 2 Different Schematics and 2 codes.
Don’t be confused they look a lot like each other, The only difference is.. 1 sensor, the KY-003 uses a
digital Input, and the KY-035 a Analog input. Therefore there are 2 schematics because they use different codes.
So you can choose which one you want to use, the KY-003 Or the KY-035.

Digital Schematic:
ky-003 reed switch, Arduino Magnetic FIELD Detector

Analog Schematic:
ky-035 analog reed switch

Parts list:
Arduino Uno, I used the RobotDyn Uno as i always do.
3 Color RGB KY-016
Hall magnetic sensor KY-003 or KY-035, Depends on which code and Schematic u use!
Buzzer.
A magnet of any kind. Small/big doesn’t matter.

(if a small magnet doesn’t work with the KY-035 You need to change values in the code, with the KY-003 code any magnet will work right away.)

Digital Code:

/*
Arduino Magnetic FIELD Detector KY-003 / KY-035.
Author: Danny van den Brande, Arduinosensors.nl. BlueCore Tech.
In this example we use the hall magnetic sensor as a magnetic 
field detector. A simple but useful code.
*/
int GreenLed = 2;
int BlueLed = 3; 
int MagneticHallSensor = 4;
int Buzzer = 5;
int val; 
 
void setup ()
{
  pinMode (GreenLed, OUTPUT);
  pinMode (BlueLed, OUTPUT);   
  pinMode (MagneticHallSensor, INPUT);
  pinMode (Buzzer, OUTPUT);
}
 
void loop ()
{
  val = digitalRead (MagneticHallSensor) ; 
  if (val == LOW) //Set to HIGH if you want the device to work the other way around.
  {
    digitalWrite (BlueLed, HIGH);
    digitalWrite (Buzzer, HIGH);
    delay(1000);
    digitalWrite (BlueLed, LOW);
    digitalWrite (Buzzer, LOW);
    delay(100);
    
  }
  else
  {
    digitalWrite (BlueLed, LOW);
    digitalWrite (GreenLed, HIGH);
    delay(1000);
    digitalWrite (GreenLed, LOW);
    digitalWrite (Buzzer, LOW);
    delay(100);
  }
}

Analog Code:

/*
Author: Danny van den Brande, Arduinosensors.nl. BlueCore Tech.
In this example we use the hall magnetic sensor as a magnetic 
field detector. A simple but useful code.
*/
int Buzzer = 4; 
int sensorPin = A0;  
int GreenLed = 2;   
int BlueLed = 3;   
int sensorValue = 0;   
 
void setup () {
pinMode (BlueLed, OUTPUT);
pinMode (GreenLed, OUTPUT);
pinMode (Buzzer, OUTPUT);
Serial.begin (9600);
}
 
void loop () {
sensorValue = analogRead (sensorPin);
if(analogRead(1)>575 && analogRead(1)< 700) 
//You can play with these values, open serial 
//monitor to see value readings.
  {
    digitalWrite (BlueLed, HIGH);
    digitalWrite (Buzzer, HIGH);
    delay(1000);
    digitalWrite (BlueLed, LOW);
    digitalWrite (Buzzer, LOW);
    delay(100);
    Serial.println(sensorValue, DEC);
  }
  else
  {
    digitalWrite (BlueLed, LOW);
    digitalWrite (GreenLed, HIGH);
    delay(1000);
    digitalWrite (GreenLed, LOW);
    digitalWrite (Buzzer, LOW);
    delay(100);
    Serial.println(sensorValue, DEC);
  }
  
}
Danny van den Brande

http://www.arduinosensors.nl

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

Your email address will not be published. Required fields are marked *