SOLVED AC detector - how to make it work?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

SOLVED AC detector - how to make it work?

#1 Post by pw444 » 20 Dec 2020, 15:37

Hya,

i have a ESP8266-12 and will use the D8 with a 4N25 as input for an AC detector.

Configuration:

Code: Select all

         0-----/\/\/\/\-------- +   1
mains          100K           --^-
                                      D1        4N25    5------ D8 ESP8266
         0----/\/\/\/\/------  +    2               4  ---- GND
                  100K
             
 D1 1N4007                  


As plugin P001 switch, i shall use it with PULLUP and when mains detected, GND on pin D8 will internally get HIGH.

My problem. VACC Not working.



My rules are:

Code: Select all

On System#Boot do
 GPIO,2,1  // status led - inversed - 1 OFF, 0 ON
 GPIO,12,0 // pb 2-4 PB24
 GPIO,14,0 // pb 5-8 PB58
 GPIO,15,0 // ACC sense
 GPIO,13,0 // pb off PBOFF
endon

on MQTT#Connected do
 event,publishstatus
endon

// loop

// B58 - statusoff P3 D5
On B58 do
  pulse,14,1,500
  pulse,2,0,500
  // stopped - publish
endon

// B24 - status24 P2 D6
On B24 do
  pulse,12,1,500
  pulse,2,0,500
  // started - publish
endon

// BOFF - statusoff P1 D7
On BOFF do 
  pulse,13,1,500
  pulse,2,0,500
  // started - publish
endon


// VACC - status
on VACC#status do
   if [VACC#status]=1
      let 1,1
   else
      let 1,0
   endif
endon
B24, B58, BOFF does what it's defined - pulses the gpios.

By VACC, i get nothing.


Any hint of what may i be doing wrong?
Attachments
4n25-pullup.png
4n25-pullup.png (3.02 KiB) Viewed 17608 times
D8 config.png
D8 config.png (56.91 KiB) Viewed 17616 times
Last edited by pw444 on 23 Dec 2020, 22:38, edited 1 time in total.

User avatar
Ath
Normal user
Posts: 3513
Joined: 10 Jun 2018, 12:06
Location: NL

Re: AC detector - how to make it work?

#2 Post by Ath » 20 Dec 2020, 20:05

I'm a bit puzzled: What are you trying to measure here? Voltage, frequency, on/off state, all three?
/Ton (PayPal.me)

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: AC detector - how to make it work?

#3 Post by pw444 » 20 Dec 2020, 20:13

Only state - mains on or off - only that.

To isolate the circuit from maisn (AC), i used the optcoupler 4N25.

RobertM
Normal user
Posts: 23
Joined: 22 Oct 2017, 15:23

Re: AC detector - how to make it work?

#4 Post by RobertM » 20 Dec 2020, 21:12

Use a 4.7uF capacitor between D8 and GND (in your diagram above)
Now you still have AC voltage at the input.
If the measurement is performed close to zero Volt then the result is 0;)
The capacitor will equalize the oscillation (50-60HZ).
Your mains switches will be detected normally :)

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: AC detector - how to make it work?

#5 Post by pw444 » 20 Dec 2020, 21:50

RobertM wrote: 20 Dec 2020, 21:12 Use a 4.7uF capacitor between D8 and GND (in your diagram above)
Thx! ceramic or eletroltic?

RobertM
Normal user
Posts: 23
Joined: 22 Oct 2017, 15:23

Re: AC detector - how to make it work?

#6 Post by RobertM » 20 Dec 2020, 22:40

eletroltic

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: AC detector - how to make it work?

#7 Post by pw444 » 20 Dec 2020, 23:41

thx, will test and post result.

TD-er
Core team member
Posts: 8749
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: AC detector - how to make it work?

#8 Post by TD-er » 21 Dec 2020, 14:23

How strong is the pull-up?
That resistor is the one to charge the capacitor and the transistor on the optocoupler is the discharger.
I assume the discharge current is a lot higher compared to the charging current, so it will probably not charge the capacitor.

I think you should use the transsitor in the optocoupler to charge the capacitor and have a weak resistor over the capacitor to discharge it when the transistor remains open.
But then you probably need a stronger (lower resistance) pull-up resistor to charge the capacitor.

Or to make it a lot simpler, have a capacitor over the LED. But then you have to deal with mains voltages.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: AC detector - how to make it work?

#9 Post by pw444 » 21 Dec 2020, 14:35

Hya,

worked, with the following scheme:

replaced D8 by D2 and internal pullup.

By initial tests, it's working.
Attachments
AC sensor with 4N25.png
AC sensor with 4N25.png (69.66 KiB) Viewed 17536 times
Last edited by pw444 on 21 Dec 2020, 19:29, edited 1 time in total.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: AC detector - how to make it work?

#10 Post by pw444 » 21 Dec 2020, 14:50

TD-er wrote: 21 Dec 2020, 14:23 Or to make it a lot simpler, have a capacitor over the LED. But then you have to deal with mains voltages.
i also thought about it, but dealing with the mains didn't seam a good idea, so i did as the new schema.

Worked on a 5 minut test as i will only be able to test more sometime later this week.

TD-er
Core team member
Posts: 8749
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: AC detector - how to make it work?

#11 Post by TD-er » 21 Dec 2020, 14:56

Ah that's indeed a way more simple schematic.
Should work just fine.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: AC detector - how to make it work?

#12 Post by pw444 » 21 Dec 2020, 22:56

Ok, guys, something is not right at all.

The pin D2 / GPIO 4 is the input for ACC sensor.

What does happen: VACC status does not change when ACC is detected. So, by devices, i enable Internal PullUp, and.. it works! status of VACC changes form 0 to 1 and 1 to 0 when ACC is detected.

Then after a reboot, PullUp enabled, the VACC status does not change. So, by devices, i disable Internal PullUp and, it works.

Long story short: i have to change the pullup behavior every time after boot to make it work.

The rules are:

Code: Select all

On System#Boot do
 GPIO,2,1  // status led - inversed - 1 OFF, 0 ON
 let,1,0
 let,2,0
endon

on MQTT#Connected do
 event,publishstatus
endon

// loop

// B58 - statusoff P3 D5
On B58 do
  pulse,14,1,500
  pulse,2,0,500
  // stopped - publish
endon

// B24 - status24 P2 D6
On B24 do
  pulse,12,1,500
  pulse,2,0,500
  // started - publish
endon

// BOFF - statusoff P1 D7
On BOFF do 
  pulse,13,1,500
  pulse,2,0,500
  // started - publish
endon

on VACC#status do
  if %eventvalue%=1
    if %v1%=1        
       Publish,%sysname%/Notify/status,1  // working
    endif
  else               // status = 0
    if %v1%=1        // status = 0 var1 =1
       let,1,0
       Publish,%sysname%/Notify/status,0   // finished
    endif 
    if %v1%=2        // status = 0 var1 =2
       let,1,0
       Publish,%sysname%/Notify/status,2   // cancelled
    endif
  endif
endon

Any hint?
Last edited by pw444 on 02 Jan 2021, 22:29, edited 2 times in total.

TD-er
Core team member
Posts: 8749
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: AC detector - how to make it work?

#13 Post by TD-er » 21 Dec 2020, 23:06

Have you set the boot states in the web uit for the pin?

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: AC detector - how to make it work?

#14 Post by pw444 » 21 Dec 2020, 23:07

TD-er wrote: 21 Dec 2020, 23:06 Have you set the boot states in the web uit for the pin?
can you please explain?

TD-er
Core team member
Posts: 8749
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: AC detector - how to make it work?

#15 Post by TD-er » 21 Dec 2020, 23:09

See the "Hardware" tab in the web UI.
There you can set the internal pull-up state which will be set at boot, before starting the plugins/controllers.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: AC detector - how to make it work?

#16 Post by pw444 » 21 Dec 2020, 23:16

TD-er wrote: 21 Dec 2020, 23:09 See the "Hardware" tab in the web UI.
There you can set the internal pull-up state which will be set at boot, before starting the plugins/controllers.
could not find pullup on the hardware tab. pullup i could only find on devices tab, inside the task definition.
Last edited by pw444 on 21 Dec 2020, 23:22, edited 1 time in total.

TD-er
Core team member
Posts: 8749
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: AC detector - how to make it work?

#17 Post by TD-er » 21 Dec 2020, 23:22

It is right under the "GPIO boot states" header.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

solved Re: AC detector - how to make it work?

#18 Post by pw444 » 21 Dec 2020, 23:25

Ok, it's all working now!!!

now i will refine the behavior.
Attachments
VACC.png
VACC.png (137.19 KiB) Viewed 16716 times
BOFF.png
BOFF.png (111.73 KiB) Viewed 16716 times
devices.png
devices.png (186.08 KiB) Viewed 16716 times
hardware.png
hardware.png (155 KiB) Viewed 16716 times

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 75 guests