I kind of hope this is just me, but my SOS program from Michael McRoberts 'Beginning Arduino' doesn't seem to be working as expected. I'll post the code, but what is happening is that, for the Ss I only seem to be getting 2 Dits instead of three. What makes it especially strange is that I cut and pasted the code for the first 'S' to both the 'O' and the last 'S", but only the 'O' seems to be giving all three LED illuminations. I changed the on, off, and delay times to try make it easier for me to see what is going on.
Edit: I just changed the delay between letters to a full second. The 'O' still works fine, and now the two Ss seem to be intermittent. Maybe I should go to bed and look at it again tomorrow.
// Project 2 - LED Flashes SOS
// LED connected to Pin 10
int ledPin = 10;
void setup()
{
// Sets Pin 10 as an output
pinMode(ledPin, OUTPUT);
}
void loop()
{
// 3 Dits
for(int x = 0; x < 3; x++)
{
digitalWrite(ledPin, HIGH);
delay(150);
digitalWrite(ledPin, LOW);
delay(200);
}
// 100ms delay between groups of letters.
delay(300);
// 3 Dahs
for(int x = 0; x < 3; x++)
{
digitalWrite(ledPin, HIGH);
delay(400);
digitalWrite(ledPin, LOW);
delay(200);
}
// 100ms delay between groups of letters.
delay(300);
// 3 Dits
for(int x = 0; x < 3; x++)
{
digitalWrite(ledPin, HIGH);
delay(150);
digitalWrite(ledPin, LOW);
delay(200);
}
// 5 second delay before resend.
delay(5000);
Hmmm. I turned it around and it doesn't come on at all. I checked the illustration for the wiring, and, "yes" the LED is hooked up backwards according the directions. But, as I said it won't come on at all if I turn it around.
LarryD:
Your code is good except for the missing } at the end of loop().
It has to be your wiring.
Wouldn't doubt it. I hadn't planned to do this tonight. I thought I had lost the books, but finally looked under a particularly large cobweb, and there they were, so I slapped together an approximation, under a 13 watt bulb. I'm not even sure what voltage the UNO is producing.
Definitely need to get some sleep before I look at it again.
Thanks a lot, guys.
To HazardsMind: It's still the same. LED still backwards and unpredictable number of flashes for the Ss.
Oh that's a good idea to try the built in LED. I only suggested it might be backwards because I made that exact mistake and I had the same issue you have.
jasmine2501:
Oh that's a good idea to try the built in LED. I only suggested it might be backwards because I made that exact mistake and I had the same issue you have.
I will try the LED 13 in the morning. VERY good idea.
Jasmine, do you remember if your LED lit up at all when you reversed it? (To the correct position?)
Honduras:
Jasmine, do you remember if your LED lit up at all when you reversed it? (To the correct position?)
If the LED lit at all, reversing it will cause it to not light at all. If it is, in fact, turning off when you tell it to turn on, you have it wired to the wrong rail. You always wire it such that the cathode is 'toward" GND, and the anode is "Toward" +5V.
The difference is that if you want the LED to turn ON with a LOW, you wire the LED and resistor in series from the pin to +5V, with the anode toward the +5V.
If you want the LED to turn ON with a HIGH, you wire the LED and resistor in series from the pin to GND, with the anode toward the pin.
Yeah that's correct. If the board is flowing current in a particular direction, the LED will not light in the other direction. You have to reverse the whole setup not just LED. I made the mistake because I typically wire resistors and stuff to the negative side of LEDs, so I hooked up that side to the pin too. So, what happens is - the pin is the negative side remember - if the pin is HIGH it's at +5 V and so is the positive side, so no current will flow because there's no potential. When you take that pin low, there's now a 5V potential, but the pin is ground and the source is high. Follow?
Voltage is about difference. We can use the pins on the Arduino to cause that difference in either direction. The proper way is to connect the + of the LED to the pin and the - of the LED and the resistor to the GROUND.
Believe it or not, I spent 16 years as an electronics technician in the military. No way for you to know that. ]
Anyway, I tried Pin 13, and then a different a different LED, and I still get the same results. Sometimes I get 3 Dits for the Ss, sometimes only 2. The Os are still nice and distinct.
I'm starting to think that it may be a problem with my eyes or my brain's perception of events, so I'm going to move on and see what other fascinating things Arduino has in store for me.
Honduras:
Believe it or not, I spent 16 years as an electronics technician in the military. No way for you to know that. ]
That experience is probably less applicable than it should be. You probably don't need to be told how voltage works, but some of our standards seem to be different from the professional community. We had a guy a while back claiming "Arduino is a joke" because he was an experienced engineer and he couldn't make it work. This tells me it must be significantly different from standards used by professionals in the electronics design industry, and that make sense because it's designed for a different crowd. The differences were enough to throw that guy completely off and make him quite angry about his failure, and he reached a point where all he could do was lash out at the community, and he was angry to the point where he didn't even want to fix the issues and continue.
I have also noticed that the beginner kits aren't very well made in terms of the code and wiring examples (but I would consider them well made in terms of what you get and the potential learning activities). There are coding errors and wiring errors in the training kits. That's how I ended up with the same issue you're facing - do what you can and try to fix it. In my case, now that I remember, I fixed it both ways - by 'reversing' the highs and lows in the code, and then realizing that my wiring was just backwards and fixing that, which required the code to be fixed back again.
Here's the 'wrong' version of the code, maybe give it a try - it blinks out "Hello World" in morse code, using a slightly different method, and using reversed highs and lows.
Actually, Arduino isn't that much different electrically.
It turns out that one of my problems was mechanical/electrical. While doing the next project, 'Traffic Lights(UK)' I was forced to realize that I am using 1/8 watt resistors with a new breadboard, which kind of fits them like socks on a rooster. (The resistors don't get hot, BTW) So I can have the same effect as randomly changing the program just by touching some of the components with a toothpick. Pretty cool, eh? BTW, the traffic light system in the UK is logically flawed, so take that. ]
Actually, the closest thing I have done to Arduino was PLC programming. At the time I stopped, some of the PLC programming software houses were just starting to use structured programming languages to do the work instead of 'Ladder Logic'. I felt that was a big breakthrough, but still it was nothing like the Arduino experience in my opinion. Especially considering the experience I have had this is the next best thing to starting from scratch. I can't afford to make any assumptions, and as clumsy as that can be sometimes, it's a good thing. I became complacent in a different world.
My recommendation to any new Arduino users is that they leave any assumptions and complacency at the door.