Go Down

Topic: need help fast (Read 285 times) previous topic - next topic

ahmedmegahed

i have project to control light with ir remote control with 8relay board connect to arduino uno 
the problem is when power cut of arduino and came back all 8 relays became on automatically  and this cause all lights became on how can i cancel this case?           

groundFungus

https://forum.arduino.cc/index.php?topic=274215.0

May have the answer.  Don't know cause I have no idea which of a thousand different relay modules that you have.

vinceherman

A wiring diagram helps us help you.
Pencil, paper and a camera are good enough if you include good detail like pin numbers.
Code helps us help you.  Remember to use code tags like it says in the How to use this forum - please read. sticky post at the top of this and all forums.

And why the rush?

ahmedmegahed

my relay module like this
https://www.amazon.com/dp/B00Y7SNHEW/ref=sspa_dk_detail_0?psc=1


TomGeorge

#4
Nov 13, 2017, 11:58 pm Last Edit: Nov 13, 2017, 11:58 pm by TomGeorge
Hi,
Welcome to the forum.

Does that relay PCB, activate a relay when the arduino output goes LOW or HIGH.

You need to put    digitalWrite(relay1, what ever turns relay1 OFF);
in your setup().
A line for each relay, this will set the outputs to keep the relays OFF before entering the main loop() code.

If it doesn't work then we need to see your code.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :)


Everything runs on smoke, let the smoke out, it stops running....

6v6gt

I found this in the description:

Quote
*100% Brand New
*Size: 13.5 x 5.3 x 1.7cm (LxWxH)
*Working voltage: 5V
*Channel: 8 channel
*This relay module is 5V active low.
*It is an 8-channel relay interface board, which can be controlled directly by a wide range of microcontrollers such as Arduino, AVR, PIC, ARM, PLC, etc.
*It is also able to control various appliances and other equipments with large current.
*Relay output maximum contact is AC250V 10A and DC30V 10A.
*Standard interface can be directly connected with microcontrollers.
*Red working status indicator lights are conducive to the safe use.
*Widely used for all MCU control, industrial sector, PLC control, smart home control.
I can't understand why it has been designed like this, but you may get away with an external pull up resistor on the relay trigger and not setting pinMode() in your code until you are ready to switch the relay on.

Wawa

To prevent relays coming on (chattering) before the Arduino is ready to take contol, do this in setup().

digitalWrite(relayPin, HIGH); // enable the internal pull up
pinMode(relayPin, OUTPUT); // before making the pin an output

There might be other problems with your code.
If you want help, post it.
Read the forum rules first.
Leo..

dave-in-nj

there is a time while the power is ON and before the Arduino is ready to take control as mentioned in post #1

I call this the POST; power-on-self-test as left over my PC jargon.

things are out of control because there is no control.  things can go on and off like magic or annoying bugs.

one way is to never power off your Arduino.
another is to have a time delay when there is no power to any external things while the Arduino is in this POST condition.
yet another is to output fixed values using some device, and then once the Arduino is up, it can either shut off that device, bypass it, feedback on it, or whatever clever means you come up with.

to repeat. things are out of control, because there is no control.
you cannot control a thing that has no control.
without control, there is no way to control a thing.

so, what you have is a wish that if you do not disturb a thing, that it will not change.  this is not control.

if you have no signal when there is no power
and your desired setting is no output when there is  power
When you shut off power you have no control.  
Although your condition is met, there is no control.
 
this works in the hobby world, but not in factory automation or most of the real world applications.   if you want to control the output, you add a circuit to control it.   many of us have scars, either on on hands or memories,  of circuits without power being applied.

ahmedmegahed

this is my sketch

#include <IRremote.h>
int aa1;
int aa2;
int aa3;
int aa4;
int aa5;
int aa6;
int aa7;
int aa8;
int p1=0;
int p2=1;
int p3=2;
int p4=3;
int p5=4;
int p6=5;
int p7=6;
int p8=7;
int RECV_PIN = 13;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
 
  irrecv.enableIRIn(); // Start the receiver
 
  pinMode(p1,OUTPUT);
  pinMode(p2,OUTPUT);
  pinMode(p3,OUTPUT);
  pinMode(p4,OUTPUT);
  pinMode(p5,OUTPUT);
  pinMode(p6,OUTPUT);
  pinMode(p7,OUTPUT);
  pinMode(p8,OUTPUT);
   digitalWrite(aa1, LOW);
  digitalWrite(aa2, LOW);
  digitalWrite(aa3, LOW);
  digitalWrite(aa4, LOW);
  digitalWrite(aa5, LOW);
  digitalWrite(aa6, LOW);
  digitalWrite(aa7, LOW);
  digitalWrite(aa8, LOW);
  }

void loop() {
  if (irrecv.decode(&results)) {
    if (results.value==0xFFE11E){
   if(aa1==0){
      digitalWrite(p1,HIGH);
      aa1=1;
      }
      else{
        digitalWrite(p1,LOW);
      aa1=0;
      }}
    else if (results.value==0xFF619E){
    if(aa2==0){
      digitalWrite(p2,HIGH);
      aa2=1;
      }
      else{
        digitalWrite(p2,LOW);
      aa2=0;
      }}
    else if (results.value==0xFFA15E){
    if(aa3==0){
      digitalWrite(p3,HIGH);
      aa3=1;
      }
      else{
        digitalWrite(p3,LOW);
      aa3=0;
      }}
    else if (results.value==0xFF6996){
    if(aa4==0){
      digitalWrite(p4,HIGH);
      aa4=1;
      }
      else{
        digitalWrite(p4,LOW);
      aa4=0;
      }}
    else if (results.value==0xFFD12E){
    if(aa5==0){
      digitalWrite(p5,HIGH);
      aa5=1;
      }
      else{
        digitalWrite(p5,LOW);
      aa5=0;
      }}
    else if (results.value==0xFF51AE){
    if(aa6==0){
      digitalWrite(p6,HIGH);
      aa6=1;
      }
      else{
        digitalWrite(p6,LOW);
      aa6=0;
      }}
    else if (results.value==0xFF916E){
    if(aa7==0){
      digitalWrite(p7,HIGH);
      aa7=1;
      }
      else{
        digitalWrite(p7,LOW);
      aa7=0;
      }}
    else if (results.value==0xFF49B6){
    if(aa8==0){
      digitalWrite(p8,HIGH);
      aa8=1;
      }
      else{
        digitalWrite(p8,LOW);
      aa8=0;
      }}
 
    irrecv.resume(); // Receive the next value
  }
  delay(10);
}

6v6gt

What value has aa1, for example, when you do this is setup() :

Code: [Select]
 
digitalWrite(aa1, LOW);

Southpark

#10
Nov 14, 2017, 07:31 pm Last Edit: Nov 14, 2017, 07:33 pm by Southpark
Maybe you need an SDcard for storing the 'states' of the relays. So each time the arduino restarts (after a power-outage), it will then know what to do.

And I agree that pull-ups or pull-downs (resistors) should be used.

TomGeorge

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Wawa

int p1=0;
int p2=1;

Don't use pin 0 and 1 for the relays.
Those pins are already used by the USB<>Serial chip.

Also try to avoid pin 13. That pin (onboard LED) could flash (relay chatter) during bootup.

The relay you linked to is active LOW (a low on the pin turns the relay on).

In general, eight relays (8*80mA) can't be powered from Arduino's 5volt pin.
You must use a separate 5volt/1Amp supply for the relay module.

If you want opto isolation, then the JD-VCC jumper needs to be removed, and relay power applied to the JD-VCC pin(+) and relay ground. A 5volt/1Amp phone/tablet charger is ok for that.
VCC should be connected to Arduino's 5volt pin, and relay ground should NOT be connected to Arduino ground.
Leo..

Southpark

#13
Nov 14, 2017, 09:30 pm Last Edit: Nov 14, 2017, 09:58 pm by Southpark
OP ...... have you also thought about what happens if you're using the relays, and the arduino gets a temporary power outage for some reason? If so...... then how do you want those relays to start up? All reset to some initial state? Or you want the relays to remain in the same state as they were already before the power glitch?

Go Up