Pages: [1]   Go Down
Author Topic: led doesn't turn off!  (Read 1551 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34183
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34183
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26312
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You shouldn't believe all you read.
Show us your reference.
 
Logged

"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.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34183
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34183
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: September 10, 2011, 06:55:07 pm by James C4S » Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Pages: [1]   Go Up
Jump to: