Offline
Newbie
Karma: 1
Posts: 14
|
 |
« on: December 11, 2012, 03:05:05 am » |
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! 
|
|
|
|
|
Logged
|
|
|
|
|
Malaysia
Offline
Sr. Member
Karma: 7
Posts: 385
|
 |
« Reply #1 on: December 11, 2012, 03:33:58 am » |
Urm yes. with a little bit of programming yeah.
|
|
|
|
|
Logged
|
|
|
|
|
SW Scotland
Offline
Edison Member
Karma: 6
Posts: 1053
Arduino rocks
|
 |
« Reply #2 on: December 11, 2012, 04:56:58 am » |
You don't ned the 100ohm resistor - the 10k to ground is all you need
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25506
Solder is electric glue
|
 |
« Reply #3 on: December 11, 2012, 04:59:58 am » |
Change the +5V to be a ground, and enable the internal pull up resistors and you don't need any resistors at all.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #4 on: December 11, 2012, 06:06:58 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Florida USA
Offline
Newbie
Karma: 2
Posts: 44
|
 |
« Reply #5 on: December 11, 2012, 08:33:08 am » |
I would at a minimum put a diode across the relay coil to protect the Arduino chip.. jolphil
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 1
Posts: 14
|
 |
« Reply #6 on: December 11, 2012, 08:34:17 pm » |
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? 
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Western New York, USA
Offline
Faraday Member
Karma: 17
Posts: 3465
|
 |
« Reply #8 on: December 11, 2012, 11:03:43 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 29
Posts: 1569
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #9 on: December 11, 2012, 11:24:55 pm » |
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
|
|
|
|
« Last Edit: December 11, 2012, 11:41:33 pm by HazardsMind »
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25506
Solder is electric glue
|
 |
« Reply #10 on: December 12, 2012, 03:33:47 am » |
What current does relay 1 take? You normally need a transistor to drive a relay, you also need a diode across the coil.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 1
Posts: 14
|
 |
« Reply #11 on: December 16, 2012, 09:23:43 pm » |
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? 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?
|
|
|
|
« Last Edit: December 16, 2012, 09:35:02 pm by RobV15 »
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 29
Posts: 1569
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #12 on: December 16, 2012, 10:12:10 pm » |
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); }
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Western New York, USA
Offline
Faraday Member
Karma: 17
Posts: 3465
|
 |
« Reply #13 on: December 16, 2012, 11:49:13 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 6
|
 |
« Reply #14 on: December 17, 2012, 12:11:32 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
|