I want the Arduino UNO to control a LED strip that requires 12v at 600mA continuous. This is obviously too much for the Arduino so I decided to use a relay to control the lights. However, no matter which tutorial I follow, which relay issue I read, I always end up with the LED coming on and off without a relay click. I decided to try and see if I could run the relay using a separate power supply and have the Arduino just controlling the optocoupler. Still no luck. So I decided to grab another power supply and control the optocoupler circuit manually. But no matter which voltage level I had, the relay remained silent. Frustrated, I bypassed the optocoupler and attempted to power the relay without any of the fancy electronics beforehand. And it did manage to click, which shows that the relay is good. I also did a countinuity check on the optocoupler and confirmed that it was not blown. And I cannot for the life of me figure out what the hell is happening!
I'm stumped and running out of options, If someone would be so kind as to assist me with this relay project I would be eternally grateful! Thanks!
The only difference is that I am using the UNO and the powerlines are not 120Vac, they are 12vdc. But as far as I know, that should not make a difference!
This relay module must be wired as outsider cites; there is no connection between the "GND" on the module and the Arduino unless indirectly through the separately wired relay supply if this is also connected to the Arduino.
So your
BigKitty10: (First power supply)
3.3/5V power connected to the Vcc pin
Ground pin connected to the In1 pin
makes no sense. Why the reference to 3.3 V which clearly has nothing to do with anything here?
But then you refer to an optocoupler and give a circuit diagram of something connected to an optocoupler. What is this about?
It is indeed confusing. What are you using for power supplies? You do need a 5 V supply to power the Arduino - a common "phone charger" would suit and the same for the relay module. You can use the same supply for both if it is adequately rated but you need to run separate - paired - wiring for power and ground from power supply to relay board and power supply to Arduino and you really should have a substantial - 1 mF - capacitor across the power connections somewhere between the power supply terminals where the supplies split, and the relay board.
Yes, if you are having difficulties explaining your project, some photos taken in adequate light (that is, outside daylight unless you have a fully equipped photo studio) would be a great help.
The OP here is not concerned as he is not using a Raspberry Pi, but why would you expect it to damage a Raspberry anyway? Given the approximately 3 V drop across indicator LED and opto-coupler, the 1k resistor limits the activation current to 2 mA of which I do believe the Pi is capable. Am I wrong?
It is completely impossible to report an eBay listing as incorrect; eBay deliberately prohibits this. Gotta get that commission!
Is Amazon different?
Grumpy_Mike:
As a rule everything past the ? In a URL is a tag used to indicate what you were searching for or what intermediary passed you the link.
The link I cited is correct. I do tell people to remove the "?" and all after for eBay URLs, but in this case, it is the "/ref=sr_1_4" which begins the referrer link and should also be discarded.
anyway? Given the approximately 3 V drop across indicator LED and opto-coupler, the 1k resistor limits the activation current to 2 mA of which I do believe the Pi is capable.
The page says
Driver Current:15-20mA each
Which is too much current for a Pi’s GPIO pin. It might be because of indicator LED, or indeed it might be rubbish but I am only going on what they put on the page.
Also if running as a current sync, which is what the page says it can do, this puts 5V on the pin when it is off.
Grumpy_Mike:
Which is too much current for a Pi’s GPIO pin. It might be because of indicator LED, or indeed it might be rubbish but I am only going on what they put on the page.
Very unwise. This is an Amazon advert. It is indeed rubbish.
Inspection of the images given confirms this is the circuit:
1k resistor with 2 V across it - 2 mA give or take a milliamp.
Grumpy_Mike:
Also if running as a current sync, which is what the page says it can do, this puts 5V on the pin when it is off.
No, it cannot. The combined voltage drop of LED and optocoupler LED means it could not pull up to more than 2 V if that.
It would be wise to ensure that the relay module is powered from the 5 V supply to the Raspberry so that it cannot be on when the latter is not.
From what we can see, the wires are just plugged into the Arduino headers.
This might be okay for Dupont ends but iffy for plain stripped wires.
Can you focus in on your Arduino to module wiring.
Let’s see your sketch.
Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags.
Use the </> icon in the posting menu: [code]Paste your sketch here[/code]
From what we can see, the wires are just plugged into the Arduino headers.
This might be okay for Dupont ends but iffy for plain stripped wires.
Can you focus in on your Arduino to module wiring.
Let's see your sketch.
Use CTRL T to format your code.
Attach your 'complete' sketch between code tags.
Use the </> icon in the posting menu: Paste your sketch here
Here
Note: The other wires that do not have the Dupont ends should not effect the relay as far as I'm concerned. They are for other LED's.)
And here is the code. Pins 11 and 12 are for the relays, but for now I'm focusing on 11.
unsigned long TargetFloor;
unsigned long CurrentFloor;
unsigned long LastCurrentFloor;
unsigned long Direction;
unsigned long Arrow;
int a = 1;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
randomSeed(analogRead(0));
pinMode(10, OUTPUT); //UP ARROW
pinMode(2, OUTPUT); //DOWN ARROW
pinMode(3, OUTPUT); //BASEMENT
pinMode(4, OUTPUT); //1
pinMode(5, OUTPUT); //2
pinMode(6, OUTPUT); //3
pinMode(7, OUTPUT); //4
pinMode(8, OUTPUT); //5
pinMode(9, OUTPUT); //6
pinMode(11, OUTPUT); //UP INDICATOR
pinMode(12, OUTPUT); //DOWN INDICATOR
TargetFloor = random(2, 8);
Serial.println(TargetFloor);
CurrentFloor = 2;
TargetFloor = random(1, 8);
Serial.println(TargetFloor);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
if (CurrentFloor == 1) {
digitalWrite (3, HIGH);
}
else {}
if (CurrentFloor == 2) {
digitalWrite (4, HIGH);
}
else {}
if (CurrentFloor == 3) {
digitalWrite (5, HIGH);
}
else {}
if (CurrentFloor == 4) {
digitalWrite (6, HIGH);
}
else {}
if (CurrentFloor == 5) {
digitalWrite (7, HIGH);
}
else {}
if (CurrentFloor == 6) {
digitalWrite (8, HIGH);
}
else {}
if (CurrentFloor == 7) {
digitalWrite (9, HIGH);
}
else {}
digitalWrite (10, LOW);
digitalWrite (2, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
if (TargetFloor == CurrentFloor) {
do
{
digitalWrite(10, LOW);
digitalWrite(2, LOW);
delay(10000);
TargetFloor = random(1, 8);
Serial.println(TargetFloor);
} while (TargetFloor == CurrentFloor);
}
else {}
if (TargetFloor > CurrentFloor) {
Direction = (2);
if (CurrentFloor == 2) {
digitalWrite(11, LOW);
}
else {}
Arrow = random(1, 3);
if (Arrow == 1) {
digitalWrite(10, LOW);
digitalWrite(2, LOW);
} else {
digitalWrite(10, HIGH);
digitalWrite(2, LOW);
}
}
else {
Direction = (1);
if (CurrentFloor == 2) {
digitalWrite(12, LOW);
delay(1000);
digitalWrite(12, HIGH);
delay(500);
digitalWrite(12, LOW);
}
else {}
Arrow = random(1, 3);
if (Arrow == 1) {
digitalWrite(2, LOW);
digitalWrite(10, LOW);
} else {digitalWrite(2, HIGH);
digitalWrite(10, LOW);}
}
delay(10000);
if (Direction == 2) {
do { digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(10, HIGH);
delay(1500);
if (CurrentFloor == 1) {
digitalWrite (3, LOW);
}
else {}
if (CurrentFloor == 2) {
digitalWrite (4, LOW);
}
else {}
if (CurrentFloor == 3) {
digitalWrite (5, LOW);
}
else {}
if (CurrentFloor == 4) {
digitalWrite (6, LOW);
}
else {}
if (CurrentFloor == 5) {
digitalWrite (7, LOW);
}
else {}
if (CurrentFloor == 6) {
digitalWrite (8, LOW);
}
else {}
if (CurrentFloor == 7) {
digitalWrite (9, LOW);
}
else {}
delay(1000);
LastCurrentFloor = CurrentFloor;
CurrentFloor = LastCurrentFloor + a;
Arrow = random(1, 3);
if (CurrentFloor == TargetFloor) {
if (Arrow == 1) {
digitalWrite(10, LOW);
} else {}
}
else {}
delay(500);
if (CurrentFloor == 1) {
digitalWrite (3, HIGH);
}
else {}
if (CurrentFloor == 2) {
digitalWrite (4, HIGH);
}
else {}
if (CurrentFloor == 3) {
digitalWrite (5, HIGH);
}
else {}
if (CurrentFloor == 4) {
digitalWrite (6, HIGH);
}
else {}
if (CurrentFloor == 5) {
digitalWrite (7, HIGH);
}
else {}
if (CurrentFloor == 6) {
digitalWrite (8, HIGH);
}
else {}
if (CurrentFloor == 7) {
digitalWrite (9, HIGH);
}
else {}
}
while (CurrentFloor != TargetFloor);
Direction = 0;
}
else {}
if (Direction == 1) {
do { digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(2, HIGH);
delay(1500);
if (CurrentFloor == 1) {
digitalWrite (3, LOW);
}
else {}
if (CurrentFloor == 2) {
digitalWrite (4, LOW);
}
else {}
if (CurrentFloor == 3) {
digitalWrite (5, LOW);
}
else {}
if (CurrentFloor == 4) {
digitalWrite (6, LOW);
}
else {}
if (CurrentFloor == 5) {
digitalWrite (7, LOW);
}
else {}
if (CurrentFloor == 6) {
digitalWrite (8, LOW);
}
else {}
if (CurrentFloor == 7) {
digitalWrite (9, LOW);
}
else {}
delay(1000);
LastCurrentFloor = CurrentFloor;
CurrentFloor = LastCurrentFloor - a;
Arrow = random(1, 3);
if (CurrentFloor == TargetFloor) {
if (Arrow == 1) {
digitalWrite(2, LOW);
} else {}
}
else {}
delay(500);
if (CurrentFloor == 1) {
digitalWrite (3, HIGH);
}
else {}
if (CurrentFloor == 2) {
digitalWrite (4, HIGH);
}
else {}
if (CurrentFloor == 3) {
digitalWrite (5, HIGH);
}
else {}
if (CurrentFloor == 4) {
digitalWrite (6, HIGH);
}
else {}
if (CurrentFloor == 5) {
digitalWrite (7, HIGH);
}
else {}
if (CurrentFloor == 6) {
digitalWrite (8, HIGH);
}
else {}
if (CurrentFloor == 7) {
digitalWrite (9, HIGH);
}
else {}
}
while (CurrentFloor != TargetFloor);
Direction = 0;
}
else {}
delay(4000);
TargetFloor = random(1, 8);
Serial.println(TargetFloor);
}