Working with the KY-003 Hall Magnetic Sensor using evive

Description
Learn how to interface the KY-003 Hall Magnetic Sensor with Evive and display the magnetic field status on the TFT display. Understand how the output of the sensor works and how to draw a round rectangle and fill it with a different color.

Introduction

The KY-003 Hall magnetic sensor is a magnetic switch. If a magnetic field is present near the KY-003 Hall magnetic sensor, the signal pin will output a LOW signal. The polarity of the magnetic field affects the switch action, with the front side needing an opposite polarity to the back to turn on.

Working Principle of the Hall Magnetic Sensor

The KY-003 Hall magnetic sensor has a beam of electrons flowing, when there is no magnetic field present there is no electron deflection occurs, which supply a high voltage to the signal pin, when a magnetic field is applied these electrons get deflected and there is a fall in voltage and the signal pin receives a low input

In this tutorial we will display whether the magnetic field is present or not on the TFT display, if the magnetic field is present then we will turn the color of the round rectangle to “Green” otherwise “Red”.

Pin Description

KY-003 Hall magnetic sensor has 3 pins

  • VCC
  • GND
  • Signal

Circuit Diagram

  • Connect VCC of KY-003 Hall sensor module to VCC of evive board
  • Connect GND of KY-003 Hall sensor module to GND of evive board
  • Connect Signal pin of  Ky-003 Hall sensor module to pin number 10 of evive board

Arduino Code


/* 
 * evive 
 * 
 * This code demonstrates interface KY-003 hall magnetic sensor with evive
 * 
 * Created by punit chotaliya
 * On 29 May, 2018
 */

#include<evive.h>

const int signalPin = 10 ;        //attaching signal pin to digital pin 10
int val =0 ; 

void setup ()
{
    Serial.begin(9600);
    
    tft.drawRoundRect(20, 30, 120, 68, 10, ST7735_WHITE);  // drawing round rectangle
    
    tft_init(INITR_GREENTAB);              // initialize a ST7735S chip, black tab
    tft.setRotation(1);
    tft.fillScreen(ST7735_BLACK);
    
      
    pinMode (signalPin, INPUT) ;         // declaring sensor pin as a INPUT pin 
    
   
    tft.setTextColor(ST7735_WHITE);
    tft.setCursor(30,40);
    tft.setTextSize(1.5);
    tft.print(" MAGNETIC FIELD");

  
}
 
void loop ()
{
  val = digitalRead(signalPin); 

  if (val == LOW)               // when the Hall sensor detects a magnetic field,LED lights up
  { 
    tft.fillRoundRect(40, 65, 80, 25, 5, ST7735_GREEN);
    Serial.println("Magnetic field detected");
    
  }
  else 
  {
    tft.fillRoundRect(40, 65, 80, 25, 5, ST7735_BLUE);
   Serial.println("No Magnetic field present");
  }

}

Expected Result

Conclusion

In this tutorial, we learned how to interface KY-003 Hall magnetic sensor with evive and how to display the magnetic field status on the TFT display. The output of the KY-003 Hall magnetic sensor is either LOW or HIGH; if the magnetic field is present, the output of the sensor is LOW, and if not, then it is HIGH. We also learned how to draw a round rectangle and fill it in with a different color, depending on the output of the KY-003 Hall magnetic sensor.

Table of Contents