Advertisement
microrobotics

HSTS016L Current Sensor 10A

May 10th, 2023
1,628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The HSTS016L is a non-invasive current sensor which is used to measure AC and DC current. It provides a voltage output that is linearly proportional to the input current. The output is centered around 2.5V (0A maps to 2.5V) and changes with current. For a 10A input, the output will be 2.5V ± 0.625V.
  3.  
  4. This code reads the voltage from the sensor, calculates the current by subtracting the zero current voltage and dividing by the sensitivity, and then prints the current value to the Serial Monitor.
  5.  
  6. Please note that you might need to adjust the zeroCurrentVoltage and sensitivity values based on the exact specifications of your sensor and the voltage reference of your Arduino board. It's also important to note that this sensor should only be used within its specified measurement range to avoid damaging the sensor or the Arduino board.
  7.  
  8. Here is a simple Arduino code to measure the current using this sensor:
  9. */
  10.  
  11. const int sensorPin = A0; // Sensor output pin to Arduino analog pin A0
  12. const float sensitivity = 0.0625; // Sensitivity is 0.0625V/A
  13. const float zeroCurrentVoltage = 2.5; // Zero current output voltage is 2.5V
  14.  
  15. void setup() {
  16.   Serial.begin(9600); // Start the serial communication with the baud rate of 9600
  17. }
  18.  
  19. void loop() {
  20.   // Read the voltage from the sensor
  21.   float sensorVoltage = analogRead(sensorPin) * (5.0 / 1023.0);
  22.  
  23.   // Calculate the current
  24.   float current = (sensorVoltage - zeroCurrentVoltage) / sensitivity;
  25.  
  26.   // Print the current value to the serial monitor
  27.   Serial.print("Current: ");
  28.   Serial.print(current);
  29.   Serial.println(" A");
  30.  
  31.   delay(500); // Add a delay to make it more readable
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement