Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    STC013-015 analogic schema at 3.3 v

    Scheduled Pinned Locked Moved LoPy
    7 Posts 3 Posters 78 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      StefanoF
      last edited by StefanoF

      Hello,

      I’ve a sensor STC013-015 AC 15A, please , I need the elettronic schema , for analogic connection to Lopy at 3.3 volt in out.

      Thanks in adavance

      Stefano

      robert-hhR 1 Reply Last reply Reply Quote 0
      • R Offline
        ric2498
        last edited by

        Hi,

        Could be a good start for what you're looking for...

        https://forum.pycom.io/topic/3092/current-sensor-15a-sct-013

        1 Reply Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @StefanoF
          last edited by

          @StefanoF I used the set-up shown below. It is more than you might expect You have to center the input voltage at about Vcc/2, which is done by R1 and R2. And you have to limit the incoming voltage, done by R4 and D1-D4. Even if the nominal voltage is 1V, which is 2.8V peak-peak, in overcurrent situations the current sensor put out 20V peak-peak at low impedance. Without limiting, that will grill your board.
          connecting.jpg

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            StefanoF @robert-hh
            last edited by

            @robert-hh

            Many thanks Robert,
            The Stc013 sensor has an electronic circuit on board clamp with resistor and diodes, what I add two resistors and a capacitor?

            Stefano

            robert-hhR 3 Replies Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @StefanoF
              last edited by

              @StefanoF I the limiting circuit is already in the sensor, then you can omit these. Then you only need C1, R1 , R2. I would still add R3 and C2 as additional protection. What you then get at the ADC input is an AC signal with offset. To get the AC level, you have to run a single frequency Spektrum analysis. The usual method for that is the Goertzel-Algorithm, which needs only little memory. I had made tests with such a set-up. It works well unless the current is very low. Then the noise of the ESP32 ADC steps in. In order to reduce that, you have to take either longer test sequences.

              1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @StefanoF
                last edited by robert-hh

                @StefanoF A test program with the goertzel algorithm is below. The time parameter is sample time in ms. The longer, the less noise and the better the resolution for small currents.

                #
                import gc
                import math
                import array
                from utime import sleep_ms, sleep_us
                from machine import ADC, Timer, idle, enable_irq, disable_irq, Pin
                
                #
                # acquire ADC values. The paramters of the constructor are:
                # 1. the mains frequency (number, typically 50 or 60)
                # 2. the sampling period (ms). The default is 2 ms.
                #
                class Acquire:
                    def __init__(self, freq=50, *, sample_period=2):
                        self.sample_period = sample_period
                        self.omega = 2.0 * math.pi * freq / (1000 / sample_period)
                        self.coeff = 2.0 * math.cos(self.omega)
                        self.adc = ADC(bits=9)
                
                    def start(self, pin, time=200):
                        gc.collect() # avoids automatic gc during sampling
                        self.pin_adc = self.adc.channel(pin=pin, attn=ADC.ATTN_11DB)
                        self.samples = time // self.sample_period
                        self.count = 0
                        self.busy = True
                        self.q1 = 0.0
                        self.q2 = 0.0
                        self.alarm = Timer.Alarm(self.read_adc, 0, ms=self.sample_period, periodic=True)
                
                    def stop(self):
                        self.alarm.cancel()
                
                    def read_adc(self, alarm):
                        self.q0 = self.pin_adc() + self.coeff * self.q1 - self.q2
                        self.q2 = self.q1
                        self.q1 = self.q0
                        self.count += 1
                        if self.count >= self.samples:
                            self.alarm.cancel()
                            self.busy = False
                
                    def result(self):
                        while self.busy == True:
                            sleep_ms(self.sample_period)
                
                        amplitude = 2 * math.sqrt(self.q1 * self.q1 +
                                                  self.q2 * self.q2 -
                                                  self.q1 * self.q2 * self.coeff) / self.count
                        # if phase is required:
                        # real = self.q1 - self.q2 * math.cos(self.omega)
                        # imag = self.q2 * math.sin(self.omega)
                        # amplitude = 2 * math.sqrt(real * real + imag * imag) / self.count
                        # phase = math.atan2(real, imag)
                        #
                        return amplitude
                
                    def reading(self, pin, time):
                        self.start(pin, time)
                        return self.result()
                #
                
                while True:
                    acq = Acquire(50) # 50 Hz
                    value = acq.reading("P13", 1000)
                    print (value)
                
                
                1 Reply Last reply Reply Quote 0
                • robert-hhR Offline
                  robert-hh @StefanoF
                  last edited by robert-hh

                  @StefanoF said in STC013-015 analogic schema at 3.3 v:

                  The Stc013 sensor has an electronic circuit on board clamp with resistor and diodes

                  I looked up the sensor data sheet. If your sensor has printed on the case 15A/1V, then it is the voltage type sensor. And That's the one you need. But I made my tests with exactly that SCT013-015 sensor, and got up to 15Vpp, when there was a shortage in the sensed circuit. How did I test that?
                  I had the sensor at a wire with a basic load of 1 A at 230V. And then I shortened these 230V. Boom, spark! Obviously the mains 16A fuse stepped in, but for a short moment I had a huge current, about 200A. I had an oscilloscope at the sensor output to capture the peak. Copy below.
                  pic2.jpg

                  With the limiting circuit I showed in my last post, this overshoot was limited to about 3.5Vpp:
                  with_limiting.jpg

                  1 Reply Last reply Reply Quote 0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • 1 / 1
                  • First post
                    Last post

                  Pycom on Twitter

                  Pycom