Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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:
- 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.
- 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.
- 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.
- */
- const int WCS1800_PIN = A0; // WCS1800 connected to Arduino analog pin A0
- const float SENSITIVITY = 0.066; // Sensitivity in V/A (66 mV/A for WCS1800)
- const float VREF = 2.5; // Reference voltage at zero current (2.5V for WCS1800)
- const float INTERNAL_REF_VOLTAGE = 1.1; // Arduino's internal reference voltage (1.1V for ATmega328P)
- void setup() {
- Serial.begin(9600);
- analogReference(INTERNAL); // Set the analog reference voltage to the internal reference
- }
- void loop() {
- float current = readWCS1800Current();
- Serial.print("Current: ");
- Serial.print(current);
- Serial.println(" A");
- delay(1000); // Wait 1 second between readings
- }
- float readWCS1800Current() {
- int sensorValue = analogRead(WCS1800_PIN);
- float voltage = sensorValue * (INTERNAL_REF_VOLTAGE / 1023.0); // Convert sensor value to voltage using the internal reference voltage
- float current = (voltage - VREF) / SENSITIVITY; // Calculate current in Amperes
- return current;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement