How to see ON/OFF status by using SCT-013 via Raspberry Pi?

Discussion in 'The Projects Forum' started by coskukoz, Jun 23, 2016.

  1. coskukoz

    Thread Starter New Member

    Jun 23, 2016
    5
    0
    Hello,

    I'm trying to make a project and I have a trouble. The project is 'online monitoring of machine'. I will show ON if machine works and OFF if machine does not work. And the rule is: I can not effect machine by my circuit. So it looks so simple. I bought SCT-013 non-invasive current sensor and connected it to the Raspberry Pi over MCP3008 ADC. When I run the program I see ON and OFF both even machine works. I just need ON or OFF according to machine status. I checked the signal from SCT-013 by oscilloscop and the signal is like below here. If you guys have ideas please share with me.

    current.png


    Best Regards.
    Coskun.
     
  2. Marley

    Member

    Apr 4, 2016
    142
    40
    Is this wave at line frequency (50 or 60Hz)?
     
  3. coskukoz

    Thread Starter New Member

    Jun 23, 2016
    5
    0
    It's 50 Hz.
     
  4. jnre

    New Member

    Jul 13, 2016
    3
    0
    dear coskukoz,

    i am a student and i am currently doing the same exact setup, raspberry to mcp3008 as adc followed by a sct013-000 yhdc current sensor.

    my objective is to hook this up to a machine to calibrate current data.

    problem is i come from a mechanical engineering background an am pretty inexperience into the world of electronics.

    it would be a huge favour if you could guide me on the setup. i have already look at the openenergymonitor website which uses arduino and have roughly put all the wiring together. however i do not wish to blow my pi up and am unsure on the coding part too.

    do advise me on steps i can take and would be good if you have a schematic of your work.

    cheers
     
  5. coskukoz

    Thread Starter New Member

    Jun 23, 2016
    5
    0
    Hey jnre,

    Nice to hear that you are working on the same project. We may share experiences. I checked the sensor output signal by using oscilloscope but I couldn't find any solution to fix signal. I'm thinking to buy Arduino Mega just because of the EmonLib that is a library for energy monitoring. So I'm not expert unfortunately. Looking for your reply.

    Coskun.
     
  6. jnre

    New Member

    Jul 13, 2016
    3
    0
    dear coskukoz,

    using arduino would definitely be alot easier since there is a full tutorial on openenergymonitor and homautomation. however what i want is for the data to be eventually passed on to a computer; like a pi.

    from your post i gathered that you have already manage to get it up and working which i am currently struggling with. it would be good if you could share your program code and schematic on the wiring aspect.

    maybe if i reach your stage i similarly can be able to see the issue and likewise tackle your problem.

    cheers.
     
  7. coskukoz

    Thread Starter New Member

    Jun 23, 2016
    5
    0
    Dear jnre,
    I draw a scheme for you. I hope you can understand. If you have troubles on connection of between MCP3008 and Raspberry Pi I can show you some documents about it. Also I paste the code here. Don't forget that these are not correct form but you can figure out about it.


    Code (Text):
    1. import spidev
    2. import time
    3. import os
    4. import urllib
    5. import RPi.GPIO as GPIO
    6. from collections import deque
    7. GPIO.setmode(GPIO.BCM)
    8.  
    9. spi=spidev.SpiDev()
    10. spi.open(0,0)
    11.  
    12. def ReadChannel (channel):
    13. adc = spi.xfer2([1,(8+channel)<<4,0])
    14. data = ((adc[1]&3)<<8) + adc[2]
    15. return data
    16.  
    17. def ConvertVolts(data,places):
    18. volts = (data*3.1815)/float(1023)
    19. volts = round(volts,places)
    20. return volts
    21.  
    22. sensor1_channel = 1
    23.  
    24. previous_Status = None
    25.  
    26. foldtime = time.time()
    27. fnewtime = time.time()
    28. fstore = 3.0
    29.  
    30. prev_statuses = deque([], maxlen=5)
    31.  
    32. while True:
    33. fnewtime = time.time()
    34. fdtime = fnewtime-foldtime
    35.  
    36. if fdtime >= fstore:
    37.   foldtime = fnewtime
    38.   sensor1_level = ReadChannel(sensor1_channel)
    39.   sensor1_volts = ConvertVolts(sensor1_level,9)
    40.  
    41.   if sensor1_volts > 0.10:
    42.    Status = 'ON'
    43.   elif sensor1_volts <= 0.1:
    44.    Status = 'OFF'
    45.  
    46.   prev_statuses.append(Status)
    47.  
    48.   if 'ON' in prev_statuses:
    49.     Status = 'ON'
    50.   else:
    51.     Status = 'OFF'
    52.  
    53.   if Status != previous_Status:
    54.    print("Status: {}".format(Status))
    55.    previous_Status = Status
    56.  
    57. time.sleep(delay)
     
  8. jnre

    New Member

    Jul 13, 2016
    3
    0
    dear coskukoz

    http://www.barissanli.com/electronics/spark.php .i hope that this link might be useful to you seeing that your want to get into IOT.

    Thank you very much for the code and the schematic. I will experiment with it and get back to you asap if I solve it.

    some questions that i have,

    did u cut your current transformer wire to add the burden resistor or did you use a intermediary to add the burden resistor. Will I be able to use a breadboard to connect the current transformer to the burden resistor as I do not want to cut the wire of the CT.

    for your code, how did u arrive at sensor volt value of 0.1 and data*3.1815. for the data transfer when u moved the bits is that a spi interface as i am very unfamilar with it. if need be i will read more into it.

    sorry if i asked too much as my knowledge on electronics only started a few weeks back.

    cheers
     
  9. coskukoz

    Thread Starter New Member

    Jun 23, 2016
    5
    0
    The SCT 013 has internal resistor. If you check the sensor by multimeter you'll see the resistor value. So you do not have to cut. Please check the picture ( https://buyhere22.com/components/current-sensor-100a-diagram.png ). You must use 'output' parts for multimeter.

    These values just for test. Feel free to change them. '(data*3,1815)/float(1023)' is for converting digital value to volts. You may use 3,3 if your maximum range 0-3.3V.
     
Loading...