Advertisement
microrobotics

Winson WCS1800 current sensor

Mar 31st, 2023 (edited)
2,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The Winson WCS1800 is a Hall-effect-based linear current sensor. It outputs an analog voltage that is proportional to the current flowing through its sensing range. Here's an example of how to use the WCS1800 with an Arduino to read the current and display it on the Serial Monitor:
  3.  
  4. To wire the WCS1800 sensor, connect its VCC pin to the 5V pin on the Arduino and the GND pin to the ground. Connect the sensor's output (OUT) pin to the WCS1800_PIN (analog pin A0) on the Arduino.
  5.  
  6. This code will continuously read the current from the WCS1800 sensor and print it on the Serial Monitor in Amperes. Note that the sensitivity value and VREF should be adjusted based on your specific sensor's datasheet if they differ from the example.
  7.  
  8. Note: The internal reference voltage can vary from chip to chip. You should measure the actual internal reference voltage on your specific Arduino and adjust the INTERNAL_REF_VOLTAGE constant accordingly for better accuracy.
  9. */
  10.  
  11. const int WCS1800_PIN = A0; // WCS1800 connected to Arduino analog pin A0
  12. const float SENSITIVITY = 0.066; // Sensitivity in V/A (66 mV/A for WCS1800)
  13. const float VREF = 2.5; // Reference voltage at zero current (2.5V for WCS1800)
  14. const float INTERNAL_REF_VOLTAGE = 1.1; // Arduino's internal reference voltage (1.1V for ATmega328P)
  15.  
  16. void setup() {
  17.   Serial.begin(9600);
  18.   analogReference(INTERNAL); // Set the analog reference voltage to the internal reference
  19. }
  20.  
  21. void loop() {
  22.   float current = readWCS1800Current();
  23.  
  24.   Serial.print("Current: ");
  25.   Serial.print(current);
  26.   Serial.println(" A");
  27.  
  28.   delay(1000); // Wait 1 second between readings
  29. }
  30.  
  31. float readWCS1800Current() {
  32.   int sensorValue = analogRead(WCS1800_PIN);
  33.   float voltage = sensorValue * (INTERNAL_REF_VOLTAGE / 1023.0); // Convert sensor value to voltage using the internal reference voltage
  34.   float current = (voltage - VREF) / SENSITIVITY; // Calculate current in Amperes
  35.   return current;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement