LEVEL: BEGINNER
I bought linear Hall sensors for a project and since this is the first time I've used those, decided to test them first.
To sum it up: they are small(4.1 mm x 3 mm x 1.6 mm) and very simple to use (datasheet).
Connect Vcc to Arduino's 5V (actually it can take 2.7-6.5 V) and middle pin to ground and it's ready to go. Output pin should be around 2.5V and will change linearly with magnetic field. For a simple test you can connect the output pin to A0 on Arduino and load a following code:
Start serial monitor (in Arduino IDE you can find it under "Tools" menu) and you will see a steady stream of values coming from the Hall sensor. Take a magnet and approach the sensor and you should observe the value changing. It's as simple as that :)const int hall = A0; void setup() { pinMode(hall, INPUT); Serial.begin(9600); } void loop() { int sum = 0; for(int i = 0; i < 10; i++){ //averaging loop to reduce noise int value = analogRead(hall); sum += value; } sum = sum / 10; Serial.print("hall = "); Serial.print(sum); Serial.print("\n"); delay(100); }
No comments:
Post a Comment