How to use a Hall Effect Sensor
What is ana LDR?Hall Effect Sensor?
AnThe LDRhall oreffect Light Dependent Resistorsensor is a componenttype of magnetic sensor which restricts how much power can flowbe throughused for detecting the strength and direction of a circuitmagnetic basedfield onproduced howfrom mucha permanent magnet or littlean lightelectromagnet hitswith its output varying in proportion to the sensitive part on the top.
To use a Light Dependent Resistor, we have to use it in combination with a fixed value resistor, the combination of these two components acts a little like a kitchen mixer tap, we can vary the temperature (voltage) by adjusting the tap.
The zig-zag lines indicate resistors, the voltage output we measure with the Arduino comes from this middle point between the two, as the valuestrength of the LDRmagnetic variesfield itbeing changesdetected.
Wiring
(1)legleft to 5V (Power)(2)leg splitmiddle to GND- right to PIN2 via 10K resistor
(2)legsplit to A0
Getting started
The following code uses
to get a integer analogRead(digitalRead()between 0-1023(1/0) representing the voltage,detection whereof 0 is 0V and 1023 is 5V.
The code below uses the serial port to output the value every 50ms to the Serial Monitor.magnet.
#defineconst ldrPinint A0hallSensorPin = 2; // Hall Effect sensor connected to digital pin 2
int hallSensorState; // Variable to store the state of the sensor
void setup() {
Serial.begin(9600); // Start serial communication at 9600 )baud
pinMode(hallSensorPin, INPUT); pinMode(// ldrPin,Set the Hall Effect sensor pin as an INPUT );
}
void loop() {
hallSensorState = digitalRead(hallSensorPin); // Read the state of the sensor
Serial.println( analogRead( ldrPin ) )hallSensorState);
delay( 50 )100);
}