Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The ACS758 is a Hall-effect-based linear current sensor that provides an analog output voltage proportional to the current flowing through the device. Here's a simple Arduino code to read the sensor's output and display the current on the Serial Monitor:
- To wire the ACS758 sensor, connect its VIOUT (voltage output) pin to the ACS758_PIN (analog pin A0) on the Arduino. Connect the VCC pin to the 5V pin on the Arduino and the GND pin to the ground.
- This code will continuously read the sensor's output and print the raw readings, the corresponding voltage, and the calculated current on the Serial Monitor. Make sure to adjust the SENSITIVITY and ZERO_BIAS_VOLTAGE constants according to your specific ACS758 sensor model.
- Note that the ACS758 is a unidirectional current sensor, meaning it can only measure current in one direction. If you need to measure bidirectional currents, consider using an ACS758 bidirectional sensor and adjust the code accordingly.
- */
- const int ACS758_PIN = A0; // ACS758 sensor connected to analog pin A0
- // Sensor parameters (change these according to your specific sensor model)
- const float VOLTAGE_REF = 5.0;
- const float SENSITIVITY = 0.040; // Sensitivity in V/A (40 mV/A for ACS758LCB-100U)
- const float ZERO_BIAS_VOLTAGE = VOLTAGE_REF / 2; // Zero current output voltage (typically Vcc/2)
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- int sensorValue = analogRead(ACS758_PIN);
- // Convert the analog reading to voltage
- float voltage = sensorValue * (VOLTAGE_REF / 1023.0);
- // Calculate the current
- float current = (voltage - ZERO_BIAS_VOLTAGE) / SENSITIVITY;
- Serial.print("Sensor Value: ");
- Serial.println(sensorValue);
- Serial.print("Voltage: ");
- Serial.print(voltage);
- Serial.println(" V");
- Serial.print("Current: ");
- Serial.print(current);
- Serial.println(" A");
- delay(1000); // Wait 1 second between readings
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement