• Arduino
  • Raspberry Pi
  • Raspberry Pi Pico
  • Micro:Bit

The BIHOR magnetic sensor module uses the AH49E Hall-effect sensor, which can detect magnetic fields. If no magnetic field is present, the sensor outputs a voltage that is approximately half the supply voltage.

If a south pole of a magnet comes close to the marked side of the sensor, the output voltage increases. If a north pole approaches, the voltage decreases. These changes are uniform and enable precise detection of the magnetic direction.

This module is ideal for detecting and measuring magnetic fields, which is useful in applications such as speed sensors, position sensors or various control and monitoring systems. It provides an easy way to respond to magnetic fields and is versatile.

Technical data
Chipset AH49E
Special features
  • A low-noise output makes filtering practically superfluous
  • Reacts to positive and negative Gauss (Gauss is the unit in which Magnetic Force is measured)
Measuring range -40 °C to 85 ° C
Electricity consumption 3.5mA at 5 V
Functional area 3,3 V to 5 V

Pin Assignment


Arduino Sensor
Pin A5 Signal
5 V +V
GND GND

Code example

The program measures the current voltage value on the sensor, calculates the current resistance value of the sensor from this and the known series resistor, and outputs the results on the serial output.

To load the following code example onto your Arduino, we recommend using the Arduino IDE. In the IDE, you can select the appropriate port and board for your device.

Copy the code below into your IDE. To upload the code to your Arduino, simply click on the upload button.

int sensorPin = A5; // The input pin is declared here

void setup() {
  // Serial output in 9600 baud
  Serial.begin(9600);
  Serial.println("KY-035 Magnetic field detection");
}
 
// The program measures the current voltage value at the sensor,
// calculates the current resistance value of the sensor from this and the known series resistance
// resistance value of the sensor and outputs the results to the serial output
void loop() {      
    // Current voltage value is measured...
    int rawValue = analogRead(sensorPin);
    float voltage = rawValue * (5.0/1023) * 1000;  
    float resitance = 10000 * (voltage / (5000.0 - voltage));
         
    // ... and printed here to the serial interface
    Serial.print("Voltage value: "); 
    Serial.print(voltage);
    Serial.print(" mV, \t Resistance value: "); 
    Serial.print(resitance); 
    Serial.println(" Ohm");
    Serial.println("---------------------------------------");
 
    delay(1000);
}

The BIHOR magnetic sensor module uses the AH49E Hall-effect sensor, which can detect magnetic fields. If no magnetic field is present, the sensor outputs a voltage that is approximately half the supply voltage.

If a south pole of a magnet comes close to the marked side of the sensor, the output voltage increases. If a north pole approaches, the voltage decreases. These changes are uniform and enable precise detection of the magnetic direction.

This module is ideal for detecting and measuring magnetic fields, which is useful in applications such as speed sensors, position sensors or various control and monitoring systems. It provides an easy way to respond to magnetic fields and is versatile.

Technical data
Chipset AH49E
Special features
  • A low-noise output makes filtering practically superfluous
  • Reacts to positive and negative Gauss (Gauss is the unit in which Magnetic Force is measured)
Measuring range -40 °C to 85 ° C
Electricity consumption 3.5mA at 5 V
Functional area 3,3 V to 5 V

Pin Assignment


Raspberry Pi Sensor
3,3 V [Pin 1] +V
GND [Pin 6] GND
- Signal
Sensor KY-053
Signal A0
+V -
GND -
Raspberry Pi KY-053
GPIO 3 [Pin 5] SCL
GPIO 2 [Pin 3] SDA
3,3 V [Pin 1] VDD
GND [Pin 6] GND

Analog sensor, therefore the following must be considered: The Raspberry Pi has, in contrast to the Arduino, no analog inputs or there is no ADC (analog digital converter) integrated in the chip of the Raspberry Pi. This limits the Raspberry Pi, if you want to use sensors, which do not output digital values, but a continuously changing value (example: potentiometer -> different position = different voltage value).

To avoid this problem, our sensor kit X40 contains the KY-053, a module with a 16-bit ADC, which you can use on the Raspberry to expand it with 4 analog inputs. This module is connected to the Raspberry Pi via I2C, takes over the analog measurement and transfers the value digitally to the Raspberry Pi.

So we recommend to connect the KY-053 module with the mentioned ADC in between for analog sensors of this set. You can find more information on the KY-053 Analog Digital Converter information page.

Code example

Attention! To use this module in combination with the KY-053 Analog-Digital-Converter, a virtual environment must be set up. All the necessary information can be found here.

import time
import board
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

# Create the ADC object using the I2C bus
ads = ADS.ADS1115(i2c)
voltageMax = 3.3
# Create single-ended input on channels
chan0 = AnalogIn(ads, ADS.P0)
chan1 = AnalogIn(ads, ADS.P1)
chan2 = AnalogIn(ads, ADS.P2)
chan3 = AnalogIn(ads, ADS.P3)

while True:
    resistance = chan0.voltage / (voltageMax - chan0.voltage) * 10000

    print("Voltage value: ",'%.2f' % chan0.voltage,"V, Resistance: ",'%.2f' % resistance, "Ohm")
    print("---------------------------------------------------")
    time.sleep(1)

The BIHOR magnetic sensor module uses the AH49E Hall-effect sensor, which can detect magnetic fields. If no magnetic field is present, the sensor outputs a voltage that is approximately half the supply voltage.

If a south pole of a magnet comes close to the marked side of the sensor, the output voltage increases. If a north pole approaches, the voltage decreases. These changes are uniform and enable precise detection of the magnetic direction.

This module is ideal for detecting and measuring magnetic fields, which is useful in applications such as speed sensors, position sensors or various control and monitoring systems. It provides an easy way to respond to magnetic fields and is versatile.

Technical data
Chipset AH49E
Special features
  • A low-noise output makes filtering practically superfluous
  • Reacts to positive and negative Gauss (Gauss is the unit in which Magnetic Force is measured)
Measuring range -40 °C to 85 ° C
Electricity consumption 3.5mA at 5 V
Functional area 3,3 V to 5 V

Pin Assignment


Micro:Bit Sensor
3,3 V +V
GND GND
- Signal
Sensor KY-053
Signal A0
+V -
GND -
Micro:Bit KY-053
Pin 19 SCL
Pin 20 SDA
3,3 V VDD
GND GND

Analog sensor, therefore the following must be observed: The Micro:Bit has analog inputs or there is an ADC (analog digital converter) integrated in the chip of the Micro:Bit. However, these are only limited to 10-bit and therefore offer only a rather low accuracy for analog measurements.

To avoid this problem, our sensor kit X40 contains the KY-053, a module with a 16-bit ADC, which you can use on the Micro:Bit to expand it by 4 analog inputs. This is connected to the Micro:Bit via I2C, takes over the analog measurement and transfers the value digitally to the Micro:Bit.

Therefore we recommend to connect the KY-053 module with the mentioned ADC in between for analog sensors of this set. More information can be found on the KY-053 Analog Digital Converter information page KY-053 Analog Digital Converter.

Code example

The program uses the corresponding library from us to control the ADS1115 ADC. This has been published under the following link pxt-ads1115 under the MIT-License.

	
		ADS1115.setMode(mode.Multi)
		ADS1115.setRate(rate.Rate5)
		ADS1115.setGain(gain.One)
		ADS1115.initADS1115(userInI2C.Gnd)
		basic.forever(function () {
		    serial.writeLine("" + (ADS1115.read(0)))
		    if (ADS1115.read(0) > 13500) {
		        serial.writeLine("Threshold value reached ")
		    } else {
		        serial.writeLine("Threshold value not yet reached")
		    }
		    serial.writeLine("_____________________________________")
		    basic.pause(1000)
		})
	

Sample program download

microbit-KY-035.zip

The BIHOR magnetic sensor module uses the AH49E Hall-effect sensor, which can detect magnetic fields. If no magnetic field is present, the sensor outputs a voltage that is approximately half the supply voltage.

If a south pole of a magnet comes close to the marked side of the sensor, the output voltage increases. If a north pole approaches, the voltage decreases. These changes are uniform and enable precise detection of the magnetic direction.

This module is ideal for detecting and measuring magnetic fields, which is useful in applications such as speed sensors, position sensors or various control and monitoring systems. It provides an easy way to respond to magnetic fields and is versatile.

Technical data
Chipset AH49E
Special features
  • A low-noise output makes filtering practically superfluous
  • Reacts to positive and negative Gauss (Gauss is the unit in which Magnetic Force is measured)
Measuring range -40 °C to 85 ° C
Electricity consumption 3.5mA at 5 V
Functional area 3,3 V to 5 V

Pin Assignment


Raspberry Pi Pico Sensor
GND GND
3 V +V
GPIO26 (A0) Signal

You can also use an ADC such as the KY-053. This ADC has a higher resolution than the internal ADC of the Raspberry Pi Pico, which means that the sensor can be analysed more accurately.

Code example

The program calculates the current voltage value at the sensor, calculates the current resistance value of the sensor from this and the known series resistance and then outputs text on the serial output under certain conditions.

To load the following code example onto your Pico, we recommend using the Thonny IDE. All you have to do first is go to Run > Configure interpreter ... > Interpreter > Which kind of interpreter should Thonny use for running your code? and select MicroPython (Raspberry Pi Pico).

Now copy the code below into your IDE and click on Run.

# Load libraries
from machine import ADC
from time import sleep

# Initialization of the ADC
adc = ADC(0)

print("KY-035 Magnetic field detection")

# Endless loop for reading out the ADC
while True:
    raw_value = adc.read_u16()
    # Conversion from analog value to voltage
    voltage = raw_value * 3.3 / 65536

    # Serial output of the analog value and the calculated voltage
    print("Analog value:", str(raw_value), "\t Analog voltage value:", str(round(voltage, 2)), "V")
 
    sleep(2)