Go Down

Topic: Multiple LED's, an Ethernet shield, a relay and low voltage outputs. Help! (Read 193 times) previous topic - next topic

slickpuss

Hi guys.  After searching for answers Ive come up empty.  Please give your opinions.

Ive got an UNO with a Ethernet shield.  Im getting input from a sound meter on A2 and have 8 DO's to 7 LEDs and a 5v relay.

Problem is Im not getting enough juice to properly light the LEDs and not enough to pull in the relay.

Each LED has a 220ohm resister in series. 

The relay is like this...  http://rlx.sk/sk/breakout-boards-accessories-cables/1927-electronic-brick-5v-relay-im120710007-rele-arduinoavrpic.html

Some other info: With this UNO/shield setup I cant use DO 4,10,11,12 and 13.  I dont use the sd card function so I have DO 4 fixed at high output.

When each of my LEDs are called high in the program they are very dull, and the relay cant pull in. Each output is only a bit more than 3v.

But the DO 4 has a nice 5v that pulls in the relay or lights the LEDs just fine.

Any thoughts?

I can show my code setup if it will help, but I dont think it has any problems.


slickpuss

Actually maybe it would be best to show the code too.  Coding is not my forte, maybe I screwed it up.

Im using a 9v external power supply as well.

Code: [Select]
/*

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 */

#include <SPI.h>
#include <Ethernet.h>
int dbMeter = A2;    // select the input pin for the db meter
int sig = 0;  // variable to store the value coming from the sensor

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 2, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);
 
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  pinMode(2,OUTPUT); // Output to flashing quiet light
  pinMode(3,OUTPUT); // green 2
  //pinMode(4,OUTPUT);  green 1 This pin is always HIGH with the Ethernet shield, run to 1st green light
  pinMode(5,OUTPUT); // green 3
  pinMode(6,OUTPUT); // yellow 1
  pinMode(7,OUTPUT); // yellow 2
  pinMode(8,OUTPUT); // yellow 3
  pinMode(9,OUTPUT); // red 1
   
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // info for db meter
  sig = analogRead(dbMeter);
  Serial.print ("db Meter:  ");
  Serial.println (sig);

  // light control
  if(sig>70){digitalWrite(2,HIGH);} else{digitalWrite(2,LOW);}  // flashing red
  if(sig>70){digitalWrite(3,HIGH);} else{digitalWrite(3,LOW);}  // green 2
  // if(sig>100){digitalWrite(4,HIGH);} else{digitalWrite(4,LOW);}  // green 1
  if(sig>70){digitalWrite(5,HIGH);} else{digitalWrite(5,LOW);}  // green 3
  if(sig>120){digitalWrite(6,HIGH);} else{digitalWrite(6,LOW);}  // yellow 1
  if(sig>130){digitalWrite(7,HIGH);} else{digitalWrite(7,LOW);}  // yellow 2
  if(sig>140){digitalWrite(8,HIGH);} else{digitalWrite(8,LOW);}  // yellow 3
  if(sig>150){digitalWrite(9,HIGH);} else{digitalWrite(9,LOW);}  // red 1
 
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");

ieee488


PaulRB

This problem with the leds & relay: have you tried without the Ethernet shield attached? If you still have some pins which do not output 5V and light a Led brightly, but other pins that light the same led (with same series resistor) brightly, then it sounds like your Uno is damaged.

slickpuss

Thanks guys.

@ieee488  - I get the same results using USB power. Im using the 9v psu just because of the Arduino recomendation, "Input Voltage (recommended)   7-12V".

The relay is a 5v relay controlling  12vdc power to a different LED light contraption I made.


@PaulRB  -  I was thinking perhaps it may be something like that. I was hoping I just screwed something simple up.  What I find strange is that the DO that lights an LED great or pulls the relay in, is DO4.  The DO that needs to be set high for the sd card reader that Im not using on this Ethernet shield.  Im not exactly sure why this DO would behave different than any other DO voltage/amperage wise.

I thought I had already proved this UNO good, but Ive done so much troubleshooting Ill have to go back a few steps.  I have a few more UNO's , a Mega and a Wifi WeMos I can try out.

jurs

The relay is like this...  http://rlx.sk/sk/breakout-boards-accessories-cables/1927-electronic-brick-5v-relay-im120710007-rele-arduinoavrpic.html
Your  relay brick does not look like it has either a transistor or an optocoupler for driving the current of the relay coil.

Your Arduino board will not be able to provide enough current on an OUTPUT pin to drive the relay coil directly.

I see two possible solutions:

1. Go and get a "relay module"  with an optocoupler or transistor as a driver for the relay coil currrent

2. Get a NPN transistor and create your own relay driver circuit.

PaulRB

Your  relay brick does not look like it has either a transistor or an optocoupler for driving the current of the relay coil.
I think it does. You can see what looks to me like a transistor on the right hand edge. Probably a MOSFET. I can see what looks like a pull-down resistor attached presumably to the gate. You would not need that with a BJT.

PaulRB

I have a few more UNO's , a Mega and a Wifi WeMos I can try out.
Be careful with the Wemos - don't forget it is a 3.3V chip. If you connect the power pin of the relay module to the 5V pin on the Wemos, the 3.3V from the output pins may not trigger the relay. If you connect the relay module power pin to the 3.3V pin on the Wemos, that may work and it may not. The relay module spec says the minimum voltage is 4.5V:
Code: [Select]
Electrical characteristics
Parameter Min. Typical Max. Unit
Working voltage 4.5 5 5.5 VDC
Digital input voltage(VCC=5V) 0 - 5 V
Working current(VCC=5V) - 34 - mA
Maximum Switch current - 2 - A
Maximum Switch AC - 120 - VAC
Maximum Switch DC - 24 - VDC

slickpuss

Thanks for the all the info.  I tried all my boards today and they all seem fine.  In fact when I have the Ethernet shield on and run just my normal sketch the lights  are all nice and bright, the relay works fine.

So it seems that something in my sketch pertaining to the Ethernet shield is killing the juice to the outputs.  Ill have to mess around with it, perhaps line by line enable the code and see where the problem starts.

It sketch creates a small webpage that displays my AO readings, and it seems to do it good, but messes up the voltages in the process.

I forgot that wemos is only 3.3 volts, cool little unit, but it wont work for this project.

I really appreciate your guys input.

PaulRB

I might just have spotted the problem in your sketch.

In setup() there is a } in the wrong place. This could be resulting in the pins not getting set as OUTPUT. Later, when these pins are set as HIGH, all that will happen is that the internal pull-up resistors will be enabled. This will cause leds to be dim and maybe not enough voltage to trigger your relay.

So try moving that } to before the pinMode() lines.

PS the Wemos would be great for your project. It might or might not be compatible with that relay. What is the relay doing anyway? Relays are useful when switching AC, or maybe when a changeover contact is needed, but often they could be replaced with something from the last century like a MOSFET. Relays are a technology from the centruary before last.

slickpuss

Wow. Thanks a ton @PaulRB!!!

It did seem like the outputs weren't set up right, but I didn't see the error in the code.

Its working like a charm now.


The relay is switching on a mess of LEDs wired up for 12v operation.  Id like to use the WeMos, but I may have to use some different components or something.


The project is actually pretty simple.  Im taking an input from a handheld db meter, then lighting off progressive lights from green to red based on the acceptable noise levels.  The final light is a sign that basically says too loud and gets attention with some flashing leds.

I want the network capability because Im making a simple app that will display the sound level and lights and can be used for some other things.

I've really got to be more careful with my coding. That's a lesson I wont forget.

PaulRB

Quote
That's a lesson I wont forget.
Yes indeed, the importance of indentation! If you had done a Tools-->Auto Format, you might have noticed that the pinMode() code lines were at the wrong level of indentation. It's one of the things I always try when my code is behaving unexpectedly. Good to hear it's working ok now.
Quote
Id like to use the WeMos, but I may have to use some different components or something.
Older designs of relay modules for use with Arduino were all built for 5V operation, because until perhaps the Due came along, all Arduino were 5V. Now there are many 3.3V Arduino compatible boards and newer relay module designs will work at either 5V or 3.3V, and make a point of saying so in the spec. Actually many of the older designs will too, but it's not guaranteed.

I tend to use MOSFETs instead of relays, with either Wemos or 5V Nano etc. For example irl540 or stp16nf06l. They can switch much more current than a tiny relay, don't wear out or make noise. They have logic level gates and are fine at either 3.3V or 5V. But they won't work with AC.

Go Up