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

Thread Starter

coskukoz

Joined Jun 23, 2016
5
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.
 

jnre

Joined Jul 13, 2016
3
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
 

Thread Starter

coskukoz

Joined Jun 23, 2016
5
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
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.
 

jnre

Joined Jul 13, 2016
3
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.
 

Thread Starter

coskukoz

Joined Jun 23, 2016
5
... 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.
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:
import spidev
import time
import os
import urllib
import RPi.GPIO as GPIO
from collections import deque
GPIO.setmode(GPIO.BCM)

spi=spidev.SpiDev()
spi.open(0,0)

def ReadChannel (channel):
adc = spi.xfer2([1,(8+channel)<<4,0])
data = ((adc[1]&3)<<8) + adc[2]
return data

def ConvertVolts(data,places):
volts = (data*3.1815)/float(1023)
volts = round(volts,places)
return volts

sensor1_channel = 1

previous_Status = None

foldtime = time.time()
fnewtime = time.time()
fstore = 3.0

prev_statuses = deque([], maxlen=5)

while True:
fnewtime = time.time()
fdtime = fnewtime-foldtime

if fdtime >= fstore:
  foldtime = fnewtime
  sensor1_level = ReadChannel(sensor1_channel)
  sensor1_volts = ConvertVolts(sensor1_level,9)

  if sensor1_volts > 0.10:
   Status = 'ON'
  elif sensor1_volts <= 0.1:
   Status = 'OFF'

  prev_statuses.append(Status)

  if 'ON' in prev_statuses:
    Status = 'ON'
  else:
    Status = 'OFF'

  if Status != previous_Status:
   print("Status: {}".format(Status))
   previous_Status = Status

time.sleep(delay)
 

Attachments

jnre

Joined Jul 13, 2016
3
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
 

Thread Starter

coskukoz

Joined Jun 23, 2016
5
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.
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.

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.
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.
 
Top