Hall Magnetic Sensor Module (KY-003) [S047]



https://www.youtube.com/watch?v=MCSwGd2gwZA


*GitHubhttps://github.com/rdiot/rdiot-s047.git



* Specs

The KY-003 is a magnetic switch. If no magnetic field is present, the signal line of the sensor is HIGH (3.5 V). If a magnetic field is presented to the sensor, the signal line goes LOW, at the same time the LED on the sensor lights up. The polarity of the magnetic field is of influence to the switching action. The front side of the sensor needs the opposite polarity as the back of the sensor to switch on.

In the example program the led on the Arduino (pin 13) will be turned on when a magnetic field is present.


* Contents

- Connect

- ----- GND

middle ----- 5V

S ----- A0


- Key Code

#include <Wire.h> 

#include <LiquidCrystal_I2C.h>

 

LiquidCrystal_I2C lcd(0x27,20,4);  // LCD2004

int pin = A0;

 

void setup()

{

  lcd.init();  // initialize the lcd 

  lcd.backlight();

  lcd.print("start LCD2004");

 

  pinMode(pin,INPUT);

  delay(1000);

 

  lcd.clear();

}

 

void loop()

{

 

  lcd.setCursor(0,0);

  lcd.print("S047:Hall Magnetic");

 

  int val = analogRead(pin);

 

  lcd.setCursor(0,1);

  lcd.print("val=" + (String)val + "  ");

 

  if(val>=750)

  {

    lcd.setCursor(0,2);

    lcd.print("nomally >= 750      ");    

  }

  else

  {

    lcd.setCursor(0,2);

    lcd.print("detected : under 100");    

 

  } 

  delay(200); 

}

Posted by RDIoT
|