testing the encoder of my final project with hall effect sensor i made this week
After a tedious machine week we are back to the usual flow. this week i planning to play with hall effect sensor which i can probably use in my final project.
individual assignment
Hall-effect sensors are integrated circuits that transduce magnetic fields to electrical signals with accuracy, consistency, and reliability.
i am using the available 811 in our fablab inventory.The MT811X family of Hall effect sensors represents a cutting-edge solution for precise and reliable magnetic field detection in a variety of applications, with a particular focus on automotive systems. Built using advanced BCD (Bipolar, CMOS, DMOS) technology, these sensors offer exceptional performance and robustness.
from DATA SHEET of mt811x
BCD Technology: This technology likely refers to "Bipolar, CMOS, DMOS" technology, a common process for integrated circuits that combines Bipolar and CMOS transistors with DMOS (Double-diffused Metal-Oxide Semiconductor) transistors, offering benefits like high power efficiency and integration.
pin out and package of 811
811 is sensitive to the magnetic field component that is perpendicular to the top of the package
so the sensor doesn't measure magnetic flux but just says which is north and which south by turning high and low.
functional block diagram of 811
operating voltage - 2.8v - 24v
supply current - 3.5 - 6 mA
typical output of the ic is given below
Digital Output vs. Magnetic Flux Density
the data sheet have a general application circuit DIAGRAM . i decided to mill the same board.
rl = 1KOhms to 10KOhms
schematics i done using kicad
note : in my schematic c1 =1nf and c2=100nf
then i routed the ic .
layout from kicad
then i milled the circuit and soldered it. you can refer WEEK 8 - ELECTRONICS DESIGN for more details about electronics designing
811 breakout board i have done
i am not getting proper reading from the board when i uploaded sample code to analog output.
error readings
. so decided to probe the board using an OSCILLOSCOPE.
we can use OSCILLOSCOPE an electronic test instrument which can be used to display varying voltages of one or more signals as a function of time.
i am using a bench power supply to power my sensor
power supply
probe pinout
the tektronix 5 series mixed signal oscilloscope i am using
from manual of this device
pin labels
connection setup
i took some neodymium magnets to test the sensor and anticipating to get low and high by moving magnets.
testing the magnets and getting digital output
OSCILLOSCOPE output
The current taken by the sensor during it's working at 5V constant ,It's about 0.00675 A only and the the output wave form we observe a straight line with out any operation.When we approach the magnet it goes high and when changed direction or removed magnet it goes low
i connected the sensor to the board i made in WEEK 8 - ELECTRONICS DESIGN and uploaded code to detect magnet.
me the testing sensor
circuit diagram
const int hallEffectPin = 31; // Pin connected to the output of the Hall effect sensor
void setup() {
pinMode(hallEffectPin, INPUT); // Set the pin as input
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int sensorValue = digitalRead(hallEffectPin); // Read the digital value from the sensor
if(sensorValue == HIGH) {
Serial.println("No magnet detected"); // Print message if magnet is detected
} else {
Serial.println("Magnet detected!"); // Print message if no magnet is detected
}
delay(500); // Delay for stability
}
code- generated using chat gpt
this part code runs this loop digital read logic high and low and display the CORRESPONDING message saying whether amgnet DETECTED or not
final testing
code is designed to read and interpret signals from a Hall effect sensor, which detects the presence of a magnetic field. The Hall effect sensor is connected to pin 31 on the SAMD11 microcontroller. In the setup
function, the code initializes pin 31 as an input and starts serial communication at a baud rate of 9600 for data transmission to a computer or serial monitor. In the loop
function, the code continuously reads the digital signal from the Hall effect sensor. If the sensor outputs a high signal (HIGH
), it indicates that no magnet is detected, and the message "No magnet detected" is printed to the serial monitor. Conversely, if the sensor outputs a low signal (LOW
), it indicates the presence of a magnet, and the message "Magnet detected!" is printed. The delay(500)
function pauses the loop for 500 milliseconds to ensure stable and readable output.
i included the hall effect sensor for Final project which is an encoder wheel embedded with 6 magnets in it.
tesing the encoder as a counter
// Define the pin for the hall effect sensor
const int hallEffectPin = 31;
// Variable to store the count of magnet detections
int magnetCount = 0;
// Flag to track whether the sensor was already triggered
bool sensorTriggered = false;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set the hall effect sensor pin as input
pinMode(hallEffectPin, INPUT);
}
void loop() {
// Read the state of the hall effect sensor
int sensorState = digitalRead(hallEffectPin);
// If the sensor detects a magnet (LOW state) and it wasn't triggered before
if (sensorState == LOW && !sensorTriggered) {
// Increment the magnet count
magnetCount++;
// Print the current magnet count
Serial.print("Magnet detected! Count: ");
Serial.println(magnetCount);
// Set the sensor triggered flag to true
sensorTriggered = true;
}
// If the sensor is not detecting a magnet (HIGH state)
// reset the sensor triggered flag to false
if (sensorState == HIGH) {
sensorTriggered = false;
}
// // A short delay to prevent rapid counting due to sensor noise
// delay(100);
}
the code
this is how th code works
The hall effect sensor is connected to pin 31 of the microcontroller. The setup
function initialises serial communication at a baud rate of 9600 and sets the hall effect sensor pin as an input. In the loop
function, the program continuously reads the state of the hall effect sensor. When the sensor detects a magnet (indicated by a LOW state) and it wasn't previously triggered, it increments the magnetCount
variable, prints the current count to the serial monitor, and sets a flag (sensorTriggered
) to true to indicate that the sensor has been triggered. If the sensor no longer detects the magnet (indicated by a HIGH state), the flag is reset to false, allowing the sensor to detect the magnet again the next time it passes by. A short delay, commented out in the code, can be used to prevent rapid counting due to sensor noise.
You can find our group page here and this week is here
setup of - us testing a hall effect sensor in for group assignment
This week, I learned the importance of deep diving into datasheets for any board we use. With a well-documented datasheet, I realized that we can figure out anything we need to know. This experience also brought me a step closer to my final project and boosted my confidence significantly.