Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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:
- 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.
- */
- const int SENSOR_PIN = A0; // the pin connected to the sensor
- float voltage; // the voltage reading from the sensor
- float current; // the current calculated from the voltage
- void setup() {
- Serial.begin(9600);
- pinMode(SENSOR_PIN, INPUT);
- }
- void loop() {
- // read the voltage from the sensor
- voltage = analogRead(SENSOR_PIN) * (5.0 / 1023.0);
- // calculate the current flowing through the sensor in amps
- current = ((voltage - 2.5) / 0.185);
- // print the current flowing through the sensor
- Serial.print("Current: ");
- Serial.print(current);
- Serial.println(" A");
- // delay before reading from the sensor again
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement