Magnetic Sensor with Arduino

Using a Hall effect sensor with an Arduino to control a relay is a common application, especially in scenarios where you want to detect the presence of a magnetic field (such as a magnet) to switch a higher voltage or current circuit using a relay. Here’s a basic outline of how you can set this up:

Components Needed:
Arduino board (e.g., Arduino Uno)
Hall effect sensor module (e.g., A3144 or similar)
Relay module (ensure it can be controlled by the Arduino)
Magnet (to actuate the Hall effect sensor)
Circuit Diagram:

Hall Effect Sensor Module:
Typically, Hall effect sensor modules have three pins: VCC, GND, and OUT.

1. Connect VCC to the 5V output on Arduino.
2. Connect GND to the ground (GND) on Arduino.
3. Connect OUT to a digital input pin on Arduino (e.g., pin 2).

Relay Module:
Relay modules usually have three input pins: VCC, GND, and IN.
Connect VCC to the 5V output on Arduino.
Connect GND to the ground (GND) on Arduino.
Connect IN to a digital output pin on Arduino (e.g., pin 7).
Load (controlled by the relay):

Connect the power supply of the load (e.g., a lamp, motor) to the common (COM) terminal of the relay.
Connect one side of the load to the normally open (NO) terminal of the relay.
Connect the other side of the load to the power supply ground.

Arduino Sketch (Code):
Here’s a basic example code to control the relay based on the Hall effect sensor’s output:

// Define constants for sensor and relay pins

void setup()
{
Serial.begin(9600); // sensor buart rate
pinMode(9,OUTPUT); // LED connect D9 Pin
pinMode(10,OUTPUT); // Buzzer connect D10 Pin
}
void loop()
{
int s1 = analogRead(A0); //Hall Effect Sensor Connect A0 pin
Serial.println(s1);
delay(500);

if( s1 < 480 )
{
digitalWrite(9,HIGH); // LED ON
tone(10, 300); // Buzzer ON
Serial.println(" Magnet IS Detected ");
}
else
{
digitalWrite(9,LOW); // LED OFF
noTone(10); // Buzzer OFF
Serial.println(" Magnet IS not Detected ");
}
}

Setup:
There are two types of circuit diagrams given here. You have to make the circuit according to the diagram given above.

Connect the 5-volts pin of the Arduino to the VCC of the Hall effect sensor.
Attach the GND pin of the Arduino to the GND pin of the Hall effect sensor.

Join the positive leg of the LED to the digital-9 pin of the Arduino.

Connect the negative leg of the LED to the GND of the Arduino through a 220-ohm resistor. A
ttach the positive wire of the buzzer with the digital-10 pin of the Arduino and the negative wire of the buzzer with the GND of the Arduino.

Till now the connections are common for both of the configurations.
You can use a breadboard for making common connections.
For the Digital connection connect the D0 pin of the sensor to the digital-4 pin of the Arduino and for the Analog connection connect the A0 pin of the sensor to the analog-0 pin of the Arduino Project.

Subramanian
Subramanian

Subramanian MK, currently serving as a workshop instructor at Sakthi Polytechnic College, Erode Tamil Nadu. With a career spanning 25 + years, Subramanian MK has dedicated himself to advancing knowledge in Electronics and Communication Engineering (ECE). His passion for exploring new technologies has led to the development of numerous projects, showcasing expertise in IoT and PCB design.

Articles: 508

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

×

Hi, How can I help you?

×