I'm trying to make a circuit that makes a quarter-wave cut to the input voltage and keep the voltage at zero for two seconds, for this I have a voltage sensor, a relay and an arduino Uno. However, the code that I have failed to do what I need, so I ask for help, since as the code is currently, every time the voltage reaches the indicated value the relay will operate and I need to keep it at zero for two seconds.
I still do not perform the conversion of what the sensor reads to values of voltage, while I am testing with the values delivered by the sensor without measuring, since to test the cut of the relay is not necessary to know that yet.
Attached explanatory image of what I need to accomplish.
The code is as follows:
int rele = 3; //relé conectao al pin digital 3
int sensorvalue = 0; // variable to store the value read
void setup()
{
pinMode(rele, OUTPUT); // inicializar entrada digital 3 como una salida (OUTPUT).
Serial.begin(9600); // initialize serial communication at 9600 bits per second:
}
// the loop function runs over and over again forever
void loop()
{
int sensorvalue = analogRead(A0); // read the input on analog pin 0:
Serial.println(sensorvalue); // print out the value you read:
if (sensorvalue <= 400)
{
digitalWrite(rele, HIGH); // turn the relé on (HIGH is the voltage level)
delay(2000); // wait for 2 second
digitalWrite(rele, LOW);
VictorA:
I'm trying to make a circuit that makes a quarter-wave cut to the input voltage
So you have AC input? What frequency/amplitude? Image suggests 5 Hz which is quite slow.
How is everything wired?
In to your program you switch off your relay for two seconds whenever the voltage on A0 drops below 2.56V (you do make sure not to get negative voltages there? Why below, not above that value?). If you want to switch it on at the peak you'd instead need to do some peak detection unless you're very sure about the peak level of your signal.
The frecuency is 50 Hz, the cuerter of the wave in the image has 0.005 s (that's means 50 Hz), the 2 seconds represent the time that i need to be zero. And the peak of the signal will be set in a fixed value.
A relay isn’t the best way to switch at these frequencies.
Your ON time is 5mS of a 20mS cycle duration. (Asymmetric 50Hz)
Look into an SSR or triac to do the switching.
Designed exactly for that purpose.
If your project can accommodate the trailing 5mS rather than the leading part of the cycle - a triac is the perfect device, as it automatically stops conducting when the voltage drops to zero.... all you have to do is find the start of the cycle, then hold off as long as you want vefore turning ‘on’ for the remainder of that cycle.
This is how cheap dimmers operate.
Yes, i trie with a GTO and that give me a quarter of the wave as i want but it repeats in each cycle, and i don't want the repeat, i want the quarter of the wave once in two seconds.
With a triac, YOU need to identify the turn on point, and pulse the gate momentarily - then the triac will drop out by itself at the next zero crossing. This is why triacs are good for trailing edge control.
With an SSR, don’t use one with built-inzero crossing detection...
Again, YOU need to detect the zero crossing points, and turn on/off whenever you need to.
In both cases, keep in mind the electrical noise generated by switching on the waveform.
What does 400 represent? Is that the value at the 90 degree peak? If so, your logic is "backwards" because it's less than 400 before you get to the 90 degree peak.
It's also "tricky" to find the peak (because of normal analog variations). It's better to find the positive-going zero-crossing and calculate the time to the peak. (In the real-world, it's often best to find some known-point after the zero crossing, but before the peak.)
Wit a real )electro-mechanical) relay you'll have to compensate for the turn-on & turn-off delay (which you'll have to determine experimentally with an oscilloscope) and it will never be "perfect". AC solid state relays (usually made with TRIACs) have their own problems (as has been pointed out). But, if you never need to get negative voltage out you can use a transistor or MOSFET (depending on the current & voltage requirements).
You can keep a TRIAC switched on through the zero-crossings by keeping the gate high - not just a short pulse to switch it on (that's indeed what you'd do in a regular dimmer). So instead of a short pulse keep it high for 2 seconds, after which at the first zero crossing it will switch itself off.
Thyristors (by their original definition), are a DC control component...
Triacs are bidirectional thyristors intended for AC...
They aren’t the same as you discovered with your quarter cycle switch!
A lot of people use the names interchangeably- which the actual parts aren’t!
SSRs can be made from either - depending on the application, and may have the zero-crossing detection within the component packaging.
ok, here’s another thought...
Using that schematic,
Put a ‘switch’ of your choosing between the pulse generator and gate.
Drive a simple counter from the pulse generator side of the switch.
Use the counter and ‘switch’ to inhibit the SCR gate signal for 50*2 cycles - then reset for the next pulse... and repeat.
Use the AC frequency as your timing reference.