AC Mains contactless detection with DIGITAL out

OP mentions

On my actual project i just have a digital pin left so i decided to search just for a Voltage->Digital 0/1 solution. Otherwise i need another MCU to send the results from the A/D converter over I2C (No UART left) which leads to cable lenght problems etc.

Not a specific Arduino but definitely an MCU.

Behind a custom made shield is a MKR 1010, 1400 or 1500. I forgot that on the shield is already a level shifter so I/O with 5v is possible

There you go.

Holy maccaroni, you make me speechless, so cool... Thank you! Your design?

So seven identical parts (4069), right? Which ones exactly?
I will solder ASAP...can't wait to test

One part, the cd4069 hex inverter.
has six inverters plus power/grd.

yep;

1 part - just U1 a single 4069 hex inverter- UNBUFFERED

I've just found one! my test facilities are a bit limited but I'll try it out tomorrow sometime.

What is the U1G ?
Hex Inverter: Is the SN74HC04N from Texas Instruments also fine?

It’s all the same chip.

Probably not the same chip because the 4049UBE is not buffered, does not have the 'B' series output circuit. The 4049 is not a good good choice for slow moving waveforms or linear operation because it tends to draw too much current in those circuits.

Do you have recommendations?

I think that a 74HC04 would be a better choice than the CD4049UBE.

Careful, hex inverters from different suppliers can have very different characteristics. I designed a gadget years back that used a CD4069 in quasi-analogue mode, and found that only Motorola parts had the right thresholds for it to work.

Thank you all so far (Especially John Errington for the schema) , i will build that thing and keep the topic up to date.

Well, I bought (long overdue) a HANTEK 6022BE scope - its a canny piece of kit - and I've done some testing.

The problem is that what you are seeking is a detector that will give a positive and reliable digital result - but the field strength you are working with can be very unpredictable. The circuit above is extremely sensitive - so picks up mains and all sorts of other EM.

Now that I can see what its doing I'm playing around with values to make the indication more reliable

I think the problem with any circuit is that mains signal is "everywhere." If you make the circuit too sensitive it will always detect something and if you make it less sensitive you may not detect even if the wanted signal is present. Setting the thresholds may be very tricky.

That would be great! Thx. Question: What about a potentiometer on the 10M R at the antenna to adjust sensitivity?

I'm really pleased with my new Hantek 'scope
Revised diagram, tested (and proved working_) as best I can in my office with mains everywhere.
Needed a LOT less gain than I had anticipated.

It gives 50Hz pulses out that you can easily detect with an Arduino.

Here's the code I'm using

/*
  Contactless mains detector
  for arduino nano; need to use Tools:processor:328p old bootloader

  Reads D3 and copies to D4

  The circuit:
  https://www.arduino.cc/reference/en/language/functions/digital-io/digitalread/
*/


int ledPin = 4;      // select the pin for the LED
int input = 3;      // Digital input pin

int newInput, oldInput = 1;
int count = 0;

void setup() {
  pinMode(input, INPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(57600);
  Serial.println(F("Starting...")); // Message to send initially (no pulses detected yet).
}

void loop() {
  newInput = digitalRead(input);
  if (newInput > oldInput) {
    //gone high
    digitalWrite(ledPin, LOW);
    delay(100);
    Serial.print("its gone high! ");
    oldInput = newInput;
  }
  if (newInput < oldInput) {
    //gone low
    digitalWrite(ledPin, HIGH);
    delay(100);
    oldInput = newInput;
    count++;
    Serial.print("its gone low: pulse count is ");
    Serial.println(count);
  }

  delay(1); // Delay for stability.
}

Supercool, thank you! What a difference a scope makes...can't wait to solder this one.

I breadboarded the schema. It pulses with or without antenna, with AC near the antenna i can see with analog read a difference in the waveform, i can detect when i touch the antenna, i can't detect AC. The digital signal is nice but i'm not able to build a reliabale detector. Do you have a hint or it's just me?