Go Down

Topic: led doesn't turn off! (Read 1 time) previous topic - next topic

legacynl

Code: [Select]
void loop()
{
  int packetSize = Udp.available();
  if (packetSize)
  {
    packetSize = packetSize - 8;
    Serial.print("received packet of size: ");
    Serial.println(packetSize);
   
    Udp.readPacket(packetBuffer, UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
    Serial.println("contents:");
    Serial.println(packetBuffer);
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
  }

}


when i run this code the led connected on ledPin doens't turn off?
is there something i'm missing?

Grumpy_Mike

It would help if you showed all your code.
The setup function is not shown.
How are you wiring up the LED? What resistor value did you use?

In the heading for this section it says:-
Quote
For problems with Arduino itself, NOT your project

What part of that did you not understand?

legacynl

Code: [Select]
#include <SPI.h>
#include <Ethernet.h>
#include <Udp.h>

//variabelen def:
byte mac[] = {0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF};
byte ip[] = {192,168,1,199};
unsigned int localPort = 8888;

byte remoteIp[4];
unsigned int remotePort;

char packetBuffer[UDP_TX_PACKET_MAX_SIZE];

int ledPin = 12;

//setup
void setup()
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
 
  Ethernet.begin(mac, ip);
   
  Udp.begin(localPort);
  Serial.println("udp begin");
 
  Serial.println("setup klaar");
}


//main()
void loop()
{
  int packetSize = Udp.available();
  if (packetSize)
  {
    packetSize = packetSize - 8;
    Serial.print("received packet of size: ");
    Serial.println(packetSize);
   
    Udp.readPacket(packetBuffer, UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
    Serial.println("contents:");
    Serial.println(packetBuffer);
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
  }

}


that's the whole code.
I didn't use a resistor for the LED.
it's connected on GND and pin 12.

Grumpy_Mike

Quote
I didn't use a resistor for the LED.
it's connected on GND and pin 12.


OK arduino frying time
!!!!!!PUT IN A RESISTOR!!!!!!

see:-
http://www.thebox.myzen.co.uk/Tutorial/LEDs.html

legacynl

i just read that pin 13 has an 1k resistor. So will you help me if i connect it to that pin?

AWOL

You shouldn't believe all you read.
Show us your reference.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

retrolefty


i just read that pin 13 has an 1k resistor. So will you help me if i connect it to that pin?


The on-board led wired to pin 13 does have a series on-baord 1k resistor, however that does not protect the shield connector pin 13. So any output pin wired to a shield connector requires a series current limiting resistor if driving LEDs.

Lefty


Grumpy_Mike

Quote
So will you help me if i connect it to that pin?

I am helping you. It is possible that you have blown your output pin. Connect the LED and resistor to use another pin and see if that fixes it.

legacynl

my reference was http://www.arduino.cc/en/Tutorial/BlinkingLED

anyways, I don't have a resistor here (at parents house). So I can't test this until tuesday.

I will report back here then.
Thanks for fast replies, everyone!

Grumpy_Mike

Sadly that tutorial is pants but the Arduino team won't take it down. That was true about 4 years ago but the design has changed since then. Sadly it is a trap that most beginners fall into.
Why not just use the on board LED with the built in resistor and see if that goes on and off?

James C4S

#10
Sep 11, 2011, 01:45 am Last Edit: Sep 11, 2011, 01:55 am by James C4S Reason: 1
How long do you think it will take from when the digitalWrite LOW until the next digitalWrite HIGH occurs?  It is very likely the led is being turned off and then back on fast enough that your eye can't see it.

Put an additional delay(1000) after turning the led off, to see if the overall behavior changes.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Go Up