newb here with a few questions...
so here's a quick schematic i did of what im trying to accomplish. First and foremost, im trying to control a regular 120v, 75w light fixture from both a 3 way switch and the arduino simultaneously. Furthermore, the serial monitor will be used to send on/off commands to the light, as well as receive the status of the light (light is on/ light is off). My question is; will this schematic function for my intended purpose?
thanks!
Urm yes. with a little bit of programming yeah.
You don't ned the 100ohm resistor - the 10k to ground is all you need
Change the +5V to be a ground, and enable the internal pull up resistors and you don't need any resistors at all.
s well as receive the status of the light (light is on/ light is off).
As designed, it detects whether the line is energized nor not, not if the light is on or off. For example, it would not detect if a light bulb is not present, or if it has been burned out.
I would at a minimum put a diode across the relay coil to protect the Arduino chip..
jolphil
As for RELAY 1, how would i compose the sketch where a single character is used to toggle both the HIGH and LOW positions. For example, if i type in '1' on the serial monitor, pin2 will go from HIGH to LOW; if i type in the same character '1' again, pin2 will go from LOW to HIGH. In other words; one command triggers either a HIGH or LOW position on RELAY 1.
Can someone compose a sketch of the code required for my whole operation corresponding to the schematic?
RobV15:
As for RELAY 1, how would i compose the sketch where a single character is used to toggle both the HIGH and LOW positions. For example, if i type in '1' on the serial monitor, pin2 will go from HIGH to LOW; if i type in the same character '1' again, pin2 will go from LOW to HIGH. In other words; one command triggers either a HIGH or LOW position on RELAY 1.
This part is trivial in assembly language so a competent C programmer (which I am not) should be able to come up with something for you.
The PINx register is where you normally read digital input data so writing to that register is not something one would normally do. However, if you do write to that register the result is that the corresponding output bit(s) in PORTx is (are) toggled.
It's spelled out this way in the datasheet:
... writing a logic one to a bit in the PINx Register, will result in a toggle in the corresponding bit in the Data Register.
Don
You need to make a coded latch.
Psudocode:
If button1 == high && latch == false {
Output high;
Latch ==true;
}
If button1 == high && latch == true{
Output low;
Latch == false;
}
In your case,
If SerialRead== 1 && latch == false
.
.
.
.....................&& latch ==true
.
.
.
Done
What current does relay 1 take? You normally need a transistor to drive a relay, you also need a diode across the coil.
HazardsMind:
You need to make a coded latch.
Psudocode:
If button1 == high && latch == false {
Output high;
Latch ==true;
}If button1 == high && latch == true{
Output low;
Latch == false;
}In your case,
If SerialRead== 1 && latch == false
.
.
.
.....................&& latch ==true
.
.
.
Done
hum.. do i need additional hardware to operate the latch function? What is a latch command?
Grumpy_Mike:
What current does relay 1 take? You normally need a transistor to drive a relay, you also need a diode across the coil.
i will be purchasing a relay board/shield from ebay which i believe comes ready to receive signals from the arduino without any additional components/hardware. As for relay2, what should the polarity direction be when attaching the diode to the circuit on the relay? where do i attach the diode?
so... can anyone compose an IDE sketch of the code necessary to operate my project?
No extra hardware that I am aware of.
Also, you can simplify the latch code with this.
boolean latch= false;
If( button1 == HIGH) {
~latch; // latch = !latch;
digitalWrite(relayPin, latch ? HIGH : LOW);
}
As for relay2, what should the polarity direction be when attaching the diode to the circuit on the relay? where do i attach the diode?
Your original post states that you want to "receive the status of the light (light is on/ light is off)"
You should carefully reread reply #4 and consider another technique.
Don
First up, I assume you realize the relays are going to have to be different - one is triggering on DC the other on AC. Relay 1 needs a diode fitted opposite to the current flow across the coil terminals if it isn't otherwise protected. I don't know if the relay shield has this protection, but I would assume so. In fact I'm pretty sure the relays will be transistor driven in the shield.
Relay 2 doesn't need a diode since the coil is isolated from the arduino, and in any case you would need a snubber since you're dealing with AC.
Smarter people than me have given you some good code snippets.