Advertisement
microrobotics

ACS758 AC/DC 200A Current Sensor

Apr 4th, 2023
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Here's an example code for interfacing two ACS758 AC/DC 200A current sensors with an Arduino:
  3.  
  4. This code initializes two ACS758 current sensors on analog pins A0 and A1. It reads the current values every second and prints them to the Serial Monitor.
  5.  
  6. Also, be sure to check your specific board and sensor specifications before using this code. Working with high currents can be dangerous; take all necessary precautions and safety measures while working with high-current circuits.
  7. */
  8.  
  9. #include <Arduino.h>
  10.  
  11. // Pins connected to the ACS758 output
  12. const int sensor1Pin = A0;
  13. const int sensor2Pin = A1;
  14.  
  15. // ACS758 sensor parameters
  16. const float VOLTAGE_REF = 5.0; // Reference voltage of the Arduino (5V for most boards, but check your specific board)
  17. const float SENSOR_SENSITIVITY = 40.0; // Sensitivity of the ACS758 (40 mV per A for ACS758LCB-200)
  18. const float SENSOR_ZERO_AMP_VOLTAGE = VOLTAGE_REF / 2; // Zero ampere output voltage (2.5V for bidirectional ACS758)
  19.  
  20. void setup() {
  21.   Serial.begin(9600);
  22.   pinMode(sensor1Pin, INPUT);
  23.   pinMode(sensor2Pin, INPUT);
  24. }
  25.  
  26. void loop() {
  27.   float current1 = readCurrent(sensor1Pin);
  28.   float current2 = readCurrent(sensor2Pin);
  29.  
  30.   Serial.print("Current 1: ");
  31.   Serial.print(current1);
  32.   Serial.println(" A");
  33.  
  34.   Serial.print("Current 2: ");
  35.   Serial.print(current2);
  36.   Serial.println(" A");
  37.  
  38.   delay(1000);
  39. }
  40.  
  41. float readCurrent(int sensorPin) {
  42.   float sensorValue = analogRead(sensorPin) * (VOLTAGE_REF / 1023);
  43.   float voltageOffset = sensorValue - SENSOR_ZERO_AMP_VOLTAGE;
  44.   return voltageOffset / SENSOR_SENSITIVITY;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement