Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Here's an example code for interfacing two ACS758 AC/DC 200A current sensors with an Arduino:
- 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.
- 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.
- */
- #include <Arduino.h>
- // Pins connected to the ACS758 output
- const int sensor1Pin = A0;
- const int sensor2Pin = A1;
- // ACS758 sensor parameters
- const float VOLTAGE_REF = 5.0; // Reference voltage of the Arduino (5V for most boards, but check your specific board)
- const float SENSOR_SENSITIVITY = 40.0; // Sensitivity of the ACS758 (40 mV per A for ACS758LCB-200)
- const float SENSOR_ZERO_AMP_VOLTAGE = VOLTAGE_REF / 2; // Zero ampere output voltage (2.5V for bidirectional ACS758)
- void setup() {
- Serial.begin(9600);
- pinMode(sensor1Pin, INPUT);
- pinMode(sensor2Pin, INPUT);
- }
- void loop() {
- float current1 = readCurrent(sensor1Pin);
- float current2 = readCurrent(sensor2Pin);
- Serial.print("Current 1: ");
- Serial.print(current1);
- Serial.println(" A");
- Serial.print("Current 2: ");
- Serial.print(current2);
- Serial.println(" A");
- delay(1000);
- }
- float readCurrent(int sensorPin) {
- float sensorValue = analogRead(sensorPin) * (VOLTAGE_REF / 1023);
- float voltageOffset = sensorValue - SENSOR_ZERO_AMP_VOLTAGE;
- return voltageOffset / SENSOR_SENSITIVITY;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement