Intermittent ringer - 200mv to trigger with 4N35 optocoupler

ericgibbs

Joined Jan 29, 2010
18,848
hi a,
Running tests with a 1kHz sine wave, set to 250mVrms, the detection point count is close to 15,
Use this Sketch for testing, note the onboard LED lights when it senses the ringer.
E
OT: Hope the weather is better in B'rum.

C++:
/*
 Basic ADC read 06/12/2021  author Ringer4
 Onboard LED Lights when Limit is exceeded. ie:Ringing
*/

int ADCin0 = A0;
int ADC0val = 0;
int ADC0avg = 0;
int ledPin = 13;

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop(){
for (int i =0; i<= 100; i++){ //get100 samples
  ADC0val= analogRead(ADCin0);
  ADC0avg= (ADC0avg + ADC0val);// sum samples
  delay(10);//100samples*10mSec=1Sec Period
  }
  ADC0avg=(ADC0avg/100);
  Serial.println(ADC0avg); // Test ONLY
 
if (ADC0avg >= 15){ // check for over Limit
  Serial.println ("Ring On"); // greater thanlimit 
   digitalWrite(ledPin, HIGH);
   }else{
   Serial.println ("Off"); // greater thanlimit
   digitalWrite(ledPin, LOW);
  }
 delay(500);
 ADC0avg=0; // clear average
 
}
 

Thread Starter

authorleon

Joined Nov 30, 2021
17
1638798915090.png

hello. Absolutely fantastic..

The next thing is I needed to turn on a relay. But the relay should stay on for 1500 ms.

I'm just looking at how to do that now

Thank you
 

ericgibbs

Joined Jan 29, 2010
18,848
Hi a,
Look up the millis option for a time delay, if you need any input, just ask.

Use the same method for the Relay pin as the Onboard LED pin control
E

BTW:
If the Uno is not doing any other operations while the Relay is On for 1.5 Secs a simple delay
would do,
(delay1500);
 
Last edited:

Thread Starter

authorleon

Joined Nov 30, 2021
17
Excellent.

Code:
/*
 Basic ADC read 06/12/2021  author Ringer3
*/
int ADCin0 = A0;
int ADC0val = 0;
int ADC0avg = 0;

// constants won't change
const int RELAY_PIN = 3;  // the Arduino pin, which connects to the IN pin of relay


void setup()
{
  Serial.begin(9600);
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop(){
for (int i =0; i<= 150; i++){ //get100 samples
  ADC0val= analogRead(ADCin0);
  ADC0avg= (ADC0avg + ADC0val);// sum samples
  delay(10);//100samples*10mSec=1Sec Period
  }
  ADC0avg=(ADC0avg/100);
  // Serial.println(ADC0avg); // Test ONLY
 
if (ADC0avg >= 40){ // check for over Limit
  Serial.println ("Ringing");
  digitalWrite(RELAY_PIN, HIGH);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);
  digitalWrite(RELAY_PIN, LOW);
  digitalWrite(LED_BUILTIN, LOW);
  delay(100);// greater thanlimit
  }
 delay(500);
 ADC0avg=0; // clear average


 
}
So this is feasible to do on an Arduino Nano as well?

Thank you
 

Thread Starter

authorleon

Joined Nov 30, 2021
17
Hi,

So I have kept it one for about a good 4 hours, however it has started to act up.

1638829915655.png

Code:
/*
 Basic ADC read 06/12/2021  author Ringer4
 Onboard LED Lights when Limit is exceeded. ie:Ringing
*/

int ADCin0 = A0;
int ADC0val = 0;
int ADC0avg = 0;
int ledPin = 13;
const int RELAY_PIN = 3;  // the Arduino pin, which connects to the IN pin of relay
void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(RELAY_PIN, OUTPUT);
}

void loop(){
for (int i =0; i<= 100; i++){ //get100 samples
  ADC0val= analogRead(ADCin0);
  ADC0avg= (ADC0avg + ADC0val);// sum samples
  delay(10);//100samples*10mSec=1Sec Period
  }
  ADC0avg=(ADC0avg/100);
  Serial.println(ADC0avg); // Test ONLY
 
if (ADC0avg >= 50){ // check for over Limit
  Serial.println ("Ring On"); // greater thanlimit
   digitalWrite(ledPin, HIGH);
   digitalWrite(RELAY_PIN, HIGH);
   digitalWrite(LED_BUILTIN, HIGH);
   delay(1500);
   digitalWrite(RELAY_PIN, LOW);
   digitalWrite(LED_BUILTIN, LOW);
   }else{
   Serial.println ("Off"); // greater thanlimit
   digitalWrite(ledPin, LOW);
  }
 delay(100);
 ADC0avg=0; // clear average
 
}
I have been playing with the values, but I am not quite sure.

Thanks
 

ericgibbs

Joined Jan 29, 2010
18,848
Hi a,
Post a print-out showing the ADC value when the ringer is connected, but NOT ringing
This value should be close to zero, ie: 0V and stay close to zero over a period of time.

If it not then you may have electrical noise on the connecting wires, how long and what type of wire are you using.?

Then a short print out when ringing, so that we can compare the two levels.

If possible, a photo shot of the project may help.

E
BTW: did a quick check for the Nano, works as expected.

Update:
Test run for that incrementing problem, nothing showing here.
Two text files, Ring Off, Ring On for comparison
 

Attachments

Last edited:

Thread Starter

authorleon

Joined Nov 30, 2021
17
Here we go:
Code:
int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 3
                    // outside leads to ground and +5V
int val = 0;  // variable to store the value read

const int RELAY_PIN = 3;  // the Arduino pin, which connects to the IN pin of relay
int ledPin = 13;

void setup() {
  Serial.begin(9600);           //  setup serial
   pinMode(ledPin, OUTPUT);
  pinMode(RELAY_PIN, OUTPUT);
}

void loop() {
  val = analogRead(analogPin);  // read the input pin
  Serial.println(val);          // debug value
  delay (50);

if (val >= 125){ // check for over Limit
Serial.println ("Ring On"); // greater thanlimit
   digitalWrite(ledPin, HIGH);
   digitalWrite(RELAY_PIN, HIGH);
   digitalWrite(LED_BUILTIN, HIGH);
   delay(2000);
   digitalWrite(RELAY_PIN, LOW);
   digitalWrite(LED_BUILTIN, LOW);
   delay(500);
   }else{
   Serial.println ("Off"); // greater thanlimit
   digitalWrite(ledPin, LOW);
 
  }
}
After leaving it for 20 minutes:
1638877697155.png



When Ring is on:

1638877734314.png

So far the above code works... However, I am up for suggestions on how to improve it.
 

ericgibbs

Joined Jan 29, 2010
18,848
hi a,
Until I see how your circuit is wired I don't see how I can suggest improvements, please post a diagram or photo shot.:)

I don't see any problems with the two Arduino's I have running.
E

Update:
I assume you are using the Nano internal Vref of 5V.?
The readings you are getting suggest a signal from the ringer is greater than 250mV...

Added:
Uno been running the Sketch for 4 hours, no change. Image print..
 

Attachments

Last edited:
Top