Example Code for Arduino-Angle Detection
Last revision 2025/12/29
This tutorial demonstrates how to use hall angle sensor in 5 minutes. The sensors detect turn round and users can learn how to read the analog signal from the sensor to calculate the rotation angle.
Hardware Preparation
- DFRduino UNO R3 x1
- Gravity: IO Expansion Shield for Arduino V7.1 x1
- Hall Angle Sensor x1
- M-M/F-M/F-F Jumper wires x1
Software Preparation
- Arduino IDE Click to Download Arduino IDE from Arduino®
Wiring Diagram
Other Preparation Work
Sample Code
/*!
* @file hallAngleSensor.ino
* @brief This example The sensors detect turn round
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author [email protected]
* @version V1.0
* @date 2016-7-12
*/
void setup()
{
Serial.begin(115200);
}
void loop()
{
float analogValue = analogRead(A2); //Voltage reading
float amp = analogValue / 1024.0 * 360; //Angle calculation ( UNO is a 10-bit AD )
Serial.print("Angle:");
Serial.println(amp);
delay(500);
}
Result
The serial monitor shows the angle value.
Was this article helpful?
