Please may I have some help to clarify the use of the 2505 opto isolator to 'read' the presence of 240 vac mains with an Arduino digital input.
I am developing a project, it's coming on well, and it's time to modify the code to detect a 'call for heat' from a 240vac room thermostat; ie open circuit (0v) when the room is warm enough, 240vac when it requires the heating to come on. The thermostat is internet connected, and has no option of a volt free contact.
I have tried to do some research, and have come up with what I think is a suitable transducer - the PS2505-1 chip. From the data sheet I cannot find data which helps me to:
Determine the series resistor required to limit the input current to the 10mA or so required by the opto-diode....a simple Ohm's Law sum? R=(240/10) * 1000 = 24kohm?...Peak V is more like 380v, though max current into diode is 80mA, so maybe 20kohm?
How do I prevent the opto-coupler from switching the digital input at 100Hz frequency (switching off every time the mains crosses zero)? Would it be appropriate to allow this to happen but put a small smoothing capacitor on the dig in pin? As can be deduced from the application the dig in will have a very low switching frequency of about 4 times per hour!
Some additional info:
I want to avoid the use of a relay interface.
The control system already uses a digital temperature sensor to measure room temperature (plus outside temp and others), and calculate heating output, but I am trying to allow the user to have the option of quickly changing back to his old 240vac ON-OFF control should my fancy-pants Arduino based system go pop - and even if it doesn't and something else goes wrong, my experience has been that the user almost always blames the bit of kit he doesn't understand; the one with the flashing leds!
Forward Voltage VF @ IF = ±10 mA Max 1.17 Avg 1.4 V
220 - 1.4 = 218.6 / 0.010 = 21.860K
I would just use 2 10K resistors, one upstream and one downstream of (anode and cathode) of the LED. On the output side you need a pullup and I would place a cap between the out EC.
Just reading the presence of of 240VAC is much a easier requirement to meet than other applications like AC phase control, dimmers, etc.
I have tried to do some research, and have come up with what I think is a suitable transducer - the PS2505-1 chip. From the data sheet I cannot find data which helps me to:
I have a few of these on hand and have used them for the same purpose in a 120V/60Hz system.
Determine the series resistor required to limit the input current to the 10mA or so required by the opto-diode....a simple Ohm's Law sum? R=(240/10) * 1000 = 24kohm?...Peak V is more like 380v, though max current into diode is 80mA, so maybe 20kohm?
You could use much lower current, therefore higher resistor values and less power dissipation.
From the datasheet, they show using IF as low as 1mA, so 2mA would be a valid target current. With this, R calculates to be 120K. The power dissipation would be (240*240)/120000 = 0.48W. Look for the working voltage (continuous AC voltage) rating and go high 400V+ and connect several in series at each terminal of the opto LED. Therefore, if you use 27K, you'll have 108K in total.
How do I prevent the opto-coupler from switching the digital input at 100Hz frequency (switching off every time the mains crosses zero)? Would it be appropriate to allow this to happen but put a small smoothing capacitor on the dig in pin? As can be deduced from the application the dig in will have a very low switching frequency of about 4 times per hour!
Yes, you could ether filter it at the pin or in software. The simplest way in hardware should only require one 1µF capacitor, connected from VCC to the pin with the internal pullup resistor enabled. The opto transistor could then pull down the signal when AC is present. The time constant of the filter is about 30ms-50ms.
Yes. I've used the RR02 type in a 120VAC project. They are 2W and have limiting voltage of 500V. I only had 1 on each line, giving 1000V total limiting voltage. If you use 4 of these (as shown) in your 220VAC application, you would get 2000V total limiting voltage.
How do I prevent the opto-coupler from switching the digital input at 100Hz frequency (switching off every time the mains crosses zero)?
You could read in a "fast loop" and check to see if the voltage is present at any point over some period of time. i.e. If there is not any voltage for 1 second the power is off. It can be a relative long period, 1 second, 10 seconds, or maybe 15 minutes if you want to cycle/check 4 times per hour.
Using DVDdoug's suggestion, you wouldn't need the capacitor.
To get an actual picture of what's happening, you could use the serial plotter as a makeshift oscilloscope to plot the opto transistor output signal. This code will produce about 3 cycles (60ms) of data. Just jumper A0 to the transistor signal (this is your probe). Use another another jumper wire to trigger an update. Have one end connected to A1, then touch GND to get an update, or hold to GND for continuous updates.
const byte probePin = A0;
const byte plotUpdatePin = A1;
const word readings = 500;
word capture[readings];
word previousReading = 0;
void setup() {
Serial.begin(115200);
pinMode(plotUpdatePin, INPUT_PULLUP);
}
void loop() {
if (analogRead(probePin) < previousReading) { // check if probePin signal is falling
if (!(digitalRead(plotUpdatePin))) { // check if plot update is requested
for (int i = 0; i < readings; i++) { // record the readings
capture[i] = analogRead(probePin);
delayMicroseconds(20);
}
for (int i = 0; i < readings; i++) { // print the readings
Serial.println(capture[i]);
delayMicroseconds(20);
}
}
}
previousReading = analogRead(probePin);
delayMicroseconds(100);
}
I am going to go for dlloyd's solution because it is purely hardware based, and this will suit my application. I am using an Arduino Nano, and the rest of my code seems to be suffering mildly from the loop() repeat cycle being too long, and I want to keep the software load to a minimum....but this is not a question for this forum, I'll post again in the software forum.