Advertisement
microrobotics

A3144 Hall Effect Sensor

Apr 17th, 2023
2,614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. This code uses the digitalRead() function to read the state of the sensor pin. In the setup() function, the sensor pin is set as an input using the pinMode() function.
  3.  
  4. In the loop() function, the sensor value is read using digitalRead() and printed to the serial port using the Serial.println() function. A short delay is added using the delay() function before the loop starts again.
  5.  
  6. This code provides a basic framework for reading from an A3144 Hall Effect Sensor using an Arduino. You can modify the code to suit your specific requirements, such as adding threshold values or calculating the frequency of the sensor output.
  7. */
  8.  
  9. // define the sensor pin
  10. const int SENSOR_PIN = 2;
  11.  
  12. void setup() {
  13.   // initialize the serial port for debugging
  14.   Serial.begin(9600);
  15.  
  16.   // set the sensor pin as an input
  17.   pinMode(SENSOR_PIN, INPUT);
  18.  
  19.   // print a message to the serial port
  20.   Serial.println("A3144 Hall Effect Sensor ready!");
  21. }
  22.  
  23. void loop() {
  24.   // read the sensor value
  25.   int sensorValue = digitalRead(SENSOR_PIN);
  26.  
  27.   // print the sensor value to the serial port
  28.   Serial.print("Sensor value: ");
  29.   Serial.println(sensorValue);
  30.  
  31.   // wait for a short time
  32.   delay(100);
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement