Analog Hall Magnetic Sensor Module (KY-035) [S046]



https://www.youtube.com/watch?v=knrf0orPK-w


*GitHub https://github.com/rdiot/rdiot-s046.git



* Specs

KY-035 is an analog magnetic field sensor module. The strength of the field is given by an analog voltage at the signal pin of the module KY-035. The sensor is connected to gnd and 5V of the Arduino board. The output voltage is measured by analog pin A5 on the Arduino board.

The example program measures the output voltage of the sensor en presents the measured value in the serial monitor of the Arduino.

The led on the board flashes in a speed depending on the strength of the magnetic field. With a small magnet this can be demonstrated.



* 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("S046:Analog Hall Mag");


  int val = analogRead(pin);


  lcd.setCursor(0,1);

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


  if(val >= 527 && val <= 528)

  {

    lcd.setCursor(0,2);

    lcd.print("nomally = 527~528");    

  }

  else if (val < 527)

  {

    lcd.setCursor(0,2);

    lcd.print("under 527 : N     ");    

  }

  else if (val > 528)

  { 

    lcd.setCursor(0,2);

    lcd.print("over 527 : S      ");       

  }

  delay(200);

}

Posted by RDIoT
|