Advertisement
microrobotics

Pololu ACHS-7121

Mar 30th, 2023
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The Pololu ACHS-7121 Current Sensor Carrier is a carrier board for the Allegro ACS712 Hall effect-based linear current sensor. Here's an example code in Arduino that reads the current from the sensor:
  3.  
  4. Note: This code assumes that the Pololu ACHS-7121 Current Sensor Carrier is connected to pin A0 of the Arduino board. If you're using a different pin, you'll need to modify the SENSOR_PIN definition accordingly. Also, the sensitivity of the sensor is assumed to be 185 mV/A, which corresponds to the ACS712ELC-10A version of the sensor. If you're using a different version of the sensor, you'll need to adjust the sensitivity accordingly.
  5. */
  6.  
  7. const int SENSOR_PIN = A0;  // the pin connected to the sensor
  8. float voltage;  // the voltage reading from the sensor
  9. float current;  // the current calculated from the voltage
  10.  
  11. void setup() {
  12.   Serial.begin(9600);
  13.  
  14.   pinMode(SENSOR_PIN, INPUT);
  15. }
  16.  
  17. void loop() {
  18.   // read the voltage from the sensor
  19.   voltage = analogRead(SENSOR_PIN) * (5.0 / 1023.0);
  20.  
  21.   // calculate the current flowing through the sensor in amps
  22.   current = ((voltage - 2.5) / 0.185);
  23.  
  24.   // print the current flowing through the sensor
  25.   Serial.print("Current: ");
  26.   Serial.print(current);
  27.   Serial.println(" A");
  28.  
  29.   // delay before reading from the sensor again
  30.   delay(1000);
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement