Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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.
- 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.
- 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.
- Here is a simple Arduino code to measure the current using this sensor:
- */
- const int sensorPin = A0; // Sensor output pin to Arduino analog pin A0
- const float sensitivity = 0.0625; // Sensitivity is 0.0625V/A
- const float zeroCurrentVoltage = 2.5; // Zero current output voltage is 2.5V
- void setup() {
- Serial.begin(9600); // Start the serial communication with the baud rate of 9600
- }
- void loop() {
- // Read the voltage from the sensor
- float sensorVoltage = analogRead(sensorPin) * (5.0 / 1023.0);
- // Calculate the current
- float current = (sensorVoltage - zeroCurrentVoltage) / sensitivity;
- // Print the current value to the serial monitor
- Serial.print("Current: ");
- Serial.print(current);
- Serial.println(" A");
- delay(500); // Add a delay to make it more readable
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement