Danny van den Brande
Published © CC BY-SA

Arduino - Magnetic FIELD Detector Using the KY-003 or KY-035

Hello world! Here I am again. Today I made 2 Different Schematics and 2 codes. Don't be confused even if they look a lot like each other.

BeginnerProtip1 hour1,104
Arduino - Magnetic FIELD Detector Using the KY-003 or KY-035

Things used in this project

Story

Read more

Schematics

Schematic KY-003

Schematic KY-035

Code

KY-003_Hall_Magnetic_Sensor_Digital.ino

Arduino
In this example we use the hall magnetic sensor as a magnetic
field detector. A simple but useful 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 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);
  }
}

KY-035_Hall_Magnetic_Sensor_Analog.ino

Arduino
In this example we use the hall magnetic sensor as a magnetic
field detector. A simple but useful 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);
  }
  
}

Credits

Danny van den Brande

Danny van den Brande

36 projects • 77 followers
"Hello world."

Comments