text:
How to reset ATmega328P fuses using USBasp programmer?
I think I bricked two ATmega328Ps when I was trying to burn new bootloaders using Arduino Pro Mini, the USBasp programmer and the Extreme Burner AVR software. I had two ATMega328p with bad booloaders and I intended burn the correct bootloader to the chips.
First I connected the USBasp programmer to my Arduino Pro Mini equipped with an ATmega328P. I verified that communication was good as I could read and write to EEPROM. All was excellent.
I was using the following fuses:
LOW Fuse Byte=0x62
High Fuse Byte=0xD9
Extended=0xFF
Lock = 0xFF
Calibration = 0xFFFF FF8A
Then the following happened:
I killed the 1st chip when I only pressed button ERASE CHIP on the programmer.
I killed the 2nd chip when I wrote the following fuses to it:
LOW Fuse Byte=0xFF
High Fuse Byte=0xDA
Extended=0xFD
Lock Fuse = 0xCF
In both cases I had the following error message:
Cannot Communication with chip
Power On failed
avrdude output similar messages:
RC=-1. No answer...
(avrdude -c usbasp -p m328p -U lfuse:w:0x62:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m )
How can I solve this problem?
How can I reset all the fuses to factory default to make the chips respond again?

So you were running the atmega at 1Mhz? In that case you need to program the chip at a lower speed. You can do that in avrdude using avrdude -B10 ....

http://electronics.stackexchange.com/a/36553/8627

http://electronics.stackexchange.com/a/66724/8627

Beware at least some versions of some of these simple programmers don't support altering the programming speed; not sure if they will complain or silently ignore the option.

The USBASP has to have a jumper set to program in low-speed mode and some of the ones you can buy don't have the jumper header installed; some don't even have the pins hooked up at all.  Grab the USBASP schematic and see if your programmer has the pins connected and see if you can hack on a header so you can set the jumper (or maybe luck out and find that the header is already there).

Thank you very much! I generated clock by NE555 and it´s working! Many Thanks to you! The first useful guide. :)

Its possible you may have disabled the SPIEN or the RSTDISBL fuses. The only way to check and fix is to use a High Voltage Programmer like the STK500, STK600 or AVR Dragon and see. I have the AVR Dragon and it saved me a few times.
Also, do a search for AVR Fuse Doctor. Its a homemade fuse repair device. Pretty cool. But save yourself some time and invest in a programmer/debugger that has HVPP (high voltage parallel programming) and HVSP (high voltage serial programming). You won't regret it.

As someone mentioned, the first chip you may be able to fix by passing -B10 to avrdude.  In order to program an AVR, the programmer has to be running at a slower speed than the chip you're programming is running.  The fuses you have set cause the chip to run at 1Mhz using the internal clock, and -B10 will cause it to go slower (the defaults are suitable for programming a chip that is running faster than 4MHz).
The second chip, the fuses are set to 8MHz using an external crystal, so in order to fix it, you'll need to hook up an 8MHz crystal, or use a high voltage programmer.
Good luck!

Hi that happened to my Nano with atmega 328p using a usbasp programmer just checking the fuse settings to make a backup with out programming, the Extreme Burner AVR software caused the problem as it read the wrong device signature, it gave me 0x0f951e after disconnecting and trying my Nano 328p it would not work I do not use that software anymore and never had a problem with making backups with other software.


text:
What is the frequency of PWM output on Arduino
What frequency do Arduinos use for normal PWM when you use analogWrite()?
And is it different for different Arduino model? I'm interested specifically in the Mega 2560, but also want to know if it's consistent between models.
I've seen a passing references to the Arduino using 500 Hz, which seems really slow.

That also depends on the pin you are using.

The PWM signal is generated by timers on the AVR chips. Each timer can generate a PWM signal on two or three different pins. Each pin can have it's own duty cycle, but they share the PWM frequency. You can change the frequency of the PWM by changing the clock source for the timers. By default they use the CPU clock divided by 64, ie. they have their prescaler set to 64 by Arduino initialization code.
  To confuse things more there are two different PWM modes: fast PWM and phase correct PWM. In fast PWM the timer counts to 255, then overflows and starts over from 0 (256 different states). In phase correct PWM the timer counts to 255, then changes direction and counts downwards to zero, changes direction and so on (510 different states).
The Arduino Mega has 5 timers, timer0 - timer4. Because timer0 is also used for the millis and micros functions it uses fast PWM, whereas the other timers are configured for phase correct PWM. This results in different frequencies on different pins:

Pin 4 and 13, controlled by timer0:
16 Mhz / 64 / 256 = 976.56 Hz
Other PWM pins, controlled by timer1-4:
16 Mhz / 64 / 510 = 490.20 Hz

The calculation is: Clock / Prescaler / PWM mode number of states
The situation is the same for all other Arduino boards I know of, except they have less timers that connect to different pins.
You can change the PWM frequency by changing the timer prescaler. See this page: http://playground.arduino.cc/Main/TimerPWMCheatsheet
It is also possible to make the timers count to a different value than 255. On the 8 bit timers you will loose an output pin, but on the 16 bit timers you can use the Input Capture Register to define a TOP value. The input capture functionality is a feature rarely used in the Arduino community so you likely won't miss it.
The Arduino libraries only allow you to use 8 bit resolution, even on the 16 bit timers. If you want the higher resolution, you will have to write your own analogWrite, or use a library made for the purpose.
On the Arduino Mega timer0 and timer2 are 8 bit, while the rest are 16 bit.
By changing the mode of the 16 bit timers to make use of the full resolution, in combination with changing the prescaler and the TOP value, you can achieve a very wide range of PWM frequencies.
The maximum frequency you can achieve is clock / 4, by setting the prescaler to 1 and TOP to 3 in fast PWM mode - a lower value isn't allowed. This will give you a 4 MHz PWM with 2 bit resolution. It can be on 0%, 25%, 50%, or 75% of the time. A higher TOP value will give you a higher resolution at a lower frequency.
For a longer explanation read this article or refer to the datasheet.
Changing the prescaler, PWM mode, or TOP value for timer0 will mess with millis() and micros().

I gather, then, that the fastest frequency you could get for PWM is 16Mhz/256 (prescaler = 1), or 62.5Khz?

And further that the PWM frequency has to be an even factor of 62.5KHz? Somebody on another thread wanted to control the fan speed of a 4-pin PC fan. Apparently it wants a PWM control signal of 25KHz. 62.5/25 is 2.5, which is not an integer value.

I updated the answer to elaborate more on the possibilities of achieving specific frequencies,

On the low frequency end, you could prescale a 16 bit timer in phase-correct mode by a 1024 prescaler  to get 16e6/1024/2^16/2 = 0.119Hz, or 7.1 cycles/minute.   For lower than that, one would need to toggle the bits based on something like millis().   Or maybe trigger the counter on the external input pin T?.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Arduino communicating back and forth with PHP server
I am researching to find the best method to work with in order to control the arduino from a web interface (hosted on a web server using PHP) and also sending data from arduino to webserver and save to mySql.
2 methods which I have found that a lot use are save the data to a text file or in the url.
Which is the best or are there any better methods?

How much data are you sending back and forth?

If you are sending large amounts of data, you might consider sending it in chunks, and processing the data as you receive it.

How are the server and the Arduino physically connected?

I would suggest your best bet would be to pass messages back and forth via JSON, via Get/Post http request.
So to send data, you send a POST request (to the PHP server) with your data in JSON in the content.  To get instructions, you send a GET request to the PHP server and get a contents field with JSON in it.

Upvote for technology invented after 1999

Another method is to use MQTT. That's a protocol often used for embedded messaging. Find here the (one of the?) arduino client.
As a server you can install mosquitto either on the same system running the web server, or on a different one.
Than the communication logic with php will be done with mosqitto-php
advantages:

decoupling the web server(s) from the arduino(s)
lightweight protocol for the arduino
easy interface with more applications (eg, storing data in mysql, independently of the web server, or any new in the future)

disadvantages:

few more work setting up the mosquitto server.

It sounds like your first need is a way to send the bytes back and forth.  A secondary question will be what that data should consist of (eg: text commands, binary commands, etc).  Let's tackle the "how" first.
You have described two dynamics to the communication between server and Arduino:

The arduino "sends data to the server" where PHP code will save it
to MySQL; if your Arduino can be an internet client (eg: has an
ethernet or wifi interface), it could use GET or POST (or PUT) HTTP calls to
php code.  GET is easiest, but normally GET calls shouldn't change the server, only
query it -- but many people make exceptions for small devices and small
amounts of data which can be encoded in the URL.
The web server "controls the Arduino".  Unless the Arduino sets up
an internet server, it is going to have to poll the web server from
time to time to find out what it should do (ie: to be controlled).
It can pretty easily use a GET to fetch some text which it can
interpret.

I'm guessing that HTTP will be the easiest path for communicating, because you probably understand that if you are a PHP programmer, and because it can often get through firewalls more easily if that matters; but a simple TCP socket or UDP datagrams are also possible.
Once you can send blocks of bytes between the server and the Arduino, you can focus on what those bytes should contain.  That could be simple text commands, or some binary protocol, or even the MQTT protocol transactions that another answer references.  You haven't given enough info to help select the protocol and format, so I'm assuming you are mostly looking at this time for the method of communicating, as described above.  If you want to ask about the format of what to send back and forth once you have the data flowing, please make that a new question.  You can test the basics by just sending a "Hello" text string between server and Arduino.

Buy a uart wifi such as WiFly series chip. You can control e chip via UART AT command. The chip capable of sending http post get to/from a server.
See this guide as an example
http://the.machini.st/posts/35

If it's not too much data, a textfile as a database should suffice, if you want something more scalable; I'm quite impressed with node.js: http://weworkweplay.com/play/raspberry-pi-nodejs/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Does Arduino run AC or DC
Does arduino run AC or DC? Based on my small knowledge on the crystal in an arduino, it seems like AC makes sense. True? No?

You are correct about the crystal producing an alternating signal, but it is a timing signal only and doesn't power the arduino. In fact, the crystal timing circuit is powered Arduino's DC power.

Thanks. Could you reference me to materials to help me understand amplifier circuits/resonator circuits such as the one that crystals use? I have already read the wikis.

(Edited):  Try these two: Wikipedia; Circuits Today. Also this question about how crystals work on Electrical Engineering Stack Exchange.

Lol I asked that question man

(Oops!) Good answers there, though - I learned a bunch, too.

The clock signal that CPUs use is switched DC, not AC. It alternates between the logic 1 voltage (usually +5) and zero volts, but doesn't go negative.

As a general rule, any modern electronic device with computational ability has to use DC. The reason is that they use specific voltage levels to indicate binary/logical states (i.e. 0's and 1's).
In theory, an ideal DC supply (Direct Current) should provide a constant voltage. That allows the circuit to effectively turn it on an off to represent binary states. (In reality, there's no such thing as truly "off" though, because voltage is relative.)
However, the voltage from an AC supply (Alternating Current) is constantly varying. If you plot it on a chart, you should see a nice sine wave, flowing smoothly between positive and negative several times per second. Hypothetically, if a digital circuit tried to use AC then it would get very confused, because everything would seem to be turning on and off all the time.
With all that said, it's very common to turn AC into DC through a process called rectification. For example, that's what allows DC devices to get power from an AC outlet (e.g. to run your computer or charge your phone).

Rectification, filtering, and regulation. Simple rectification leads to switched DC, where the negative part of the sine wave is inverted and you just have a series of positive humps that still drop to zero. Filtering smooths out the power to a flat DC voltage. However, the voltage from a filtered but not regulated supply will vary based on load. The more current you draw from it, the more the voltage will drop. A regulated power supply will adjust the output to keep the voltage constant. Logic circuits run much better with a regulated supply. Some logic circuits like TTL require it.

All digital logic circuits run on DC.
Most Arduino boards include a voltage regulator. You can feed them an input ranging from 7 to 12 volts, and they "clean up" that input and lock it to precisely 5 volts, the voltage needed by the Arduino.
They can also run directly off the regulated 5 volts from the USB connector.

Have a look at this: http://arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf and try and have a guess.
I don't want to be nasty, but have you at least googled this? Google: "Arduino Power Source" and the first hit is http://playground.arduino.cc/Learning/WhatAdapter
It runs from USB as well as from an external power source.
To answer your question: DC

@Sciiiiience, the general rule with SO is that you should exert a little effort yourself before posting a question. If a casual google query answers your question on the first page, don't ask it. (People resent it when you expect them to put more effort into answering your question than you put into asking it.)


text:
Questions on programming logic?
So I am learning arduino code by going through examples and playing with them, and I came across something interesting. I am not fluent in any coding language but I am fully familiarized with computer logic and function so I can read what you suggest just fine.
What I want to know is, why are these two code pieces different?
const int ledPin =  13;

int ledState = LOW;

long interval = 1000;

void setup() {

pinMode(ledPin, OUTPUT);
}

void loop()
{

  unsigned long currentMillis = millis();

  if(currentMillis > interval) {

    currentMillis = 0;

    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    digitalWrite(ledPin, ledState);
  }
}

This is my code, or rather modification to this code:
const int ledPin =  13;

int ledState = LOW;
long previousMillis = 0;

long interval = 1000;

void setup() {

  pinMode(ledPin, OUTPUT);
}

void loop()
{

  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {

    previousMillis = currentMillis;

    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    digitalWrite(ledPin, ledState);
  }

}

How is it that the first code works, and the second code turns the led on and either terminates or never turns the LED off? The code is designed to blink the LED once every 1 second.

Ah yes, this problem.
Note the declaration of currentMillis:
unsigned long currentMillis = ...;

And now note the declaration of previousMillis:
long previousMillis = ...;

You wouldn't think that one little word could make that much difference, but it does. It completely changes how C performs mathematics. previousMillis must also be unsigned or you will get undesired results.

How so? That is what confuses me. I /can/ fix it in this scenario, but should this happen with my own code I would be stumped.

Answer this question: What is the value of a negative number when stored in an unsigned variable?

Unsigned is essentially absolute value, no? So, positive.

It is not the absolute value. You need to be more precise than "positive" to understand.

Then what is it?

http://stackoverflow.com/questions/2084949/arithmetic-operations-on-unsigned-and-signed-integers

Okay. That makes some sense. So, to fix it, I should..? I'm thinking make them both regular ints? Sorry, I may know what's up with programming but I'm not really a genius.

What is the return type of millis()?

I'm not sure. And I can't test right this minute. Should I set the unsigned/signed based on the millis() return type?

Yes, you should. That will ensure that your results make the most sense. Also, this

http://en.wikipedia.org/wiki/Two%27s_complement - good read regarding signed numbers in binary format. It really isn't "complex"; the highest bit being "1" denotes a negative number. As there is no "-0" the negative numbers also have an offset of one.
If you mix unsigned and signed - you simply get unexpected results.
You need to be very precise, i.e. check if the signed number is negative and handle it with care to make it "compatible" with the unsigned number before you use them together.
What "care" ends up be in reality depends on what you expect to get out of it, as result.

Thanks man I would up vote but I don't have the rep lol

Noted an error there, now it should be ok.


text:
How to send multi variable information over serial?
I would like to send information between my Arduino and my computer. Is there a way to send multiple variables from one Arduino? If so, how would I go about separating the variables?

This may help: http://electronics.stackexchange.com/a/79321/8627

You have three options for what you want to achieve (if I understand it right):

Have a fixed length for each variable: If I know each number is going to be two digits, I can send "1234" and the other side can figure out the numbers are "12" and "34".
Have a delimiter character: Have a character that signals a new variable. For example: "213|1234" would translate into "213" and "1234". You could even use the newline character to signal a new line (with Serial.println();).
Do some sort of validation to separate the data: If sending a favorite number and favorite color, I can send "12RED345BLUE" and the other side it can find that it's "12" (both numbers), then "RED" (all letters), then "345" (three numbers), and finally "BLUE" (again, all letters).

♦ can we do this like this as well? 'LI5' or something like this? 'LA4|LI5' or something like Serial.println('LA4|LI5'); Serial.println('LT2|LP3|LM5|LR4|LI6'); //close reverse will open thanks in advanced.

@Frank'sDesig'Nature there's no reason you can't do that; you would just have to have the appropriate processing on the other side to handle that

im not being allow to comment or edit so this is the only way for me to input my next comment "i really hate how this website works" Ok so now if i was to flood the serial with something like this: `gfhvfglfngvern98t34u05u305v4up0653utvp53t4t56526vgf5gvsd4gv6h4d65h4d63hbd4hb354g35gb435vb4zf35gdf35gb4d3v5h4vg3v5hb4fg6z24gv6dfgv4fd65vg2652f6g5hb74ki6k57n6v54sh64yul6oh4;g6fjd4g6wr5cg4yrdb68oin7n6ubj84g6jnujg4hm;l62g4kn6gfj42mjh6l54g6k5gf4dbhv16d5sg41tb6uh541jh1j34nfj35ffff4n4j2h3n14b5jgn352ghj3kj18hbuni5dj6tui5dty32hf3h1bgh3gfhvfglfngvern98t34u05u305v4@p0653utvp53t4t56526vgf5gvsd4gv6h4d65h4d63hbd

@Frank'sDesig'Nature (when I converted this into a comment some of your message got cut off) I'm not sure exactly what you're saying. Can you clarify?


text:
Arduino 433Mhz weather sensor receiver
I want to monitor the temperatur around the house and outside. I want to save the data to mysql and then create some kind of webapplication that displlays the data. It is pretty easy to find temperature sensors that transmitts over 433Mhz, and I have thought about Telldus tellstick to receive data and store them. This receiver costs about 30 - 40 $ and 10 - 20 $ for each sensor.
But since I just learned that Arduino can be used for everything, I would love to hear more about it.
Can someone please give me an introduction to what I would need to make this solution? The arduino should basicly receive data from 433 Mhz sensors and store it to MySQL.
What woulds be the challanges when doing something like this?

Where is the MySQL server running? A local computer connected over ... or a remote server, or do you wan't an Arduino capable of running MySQL?

I have MySql on NAS on my local network, but I also have an windows pc that's always on that can run MySql

You could use an Arduino with an ethernet shield to store the data to a MySQL server on the local network. See this blog post for an introduction to a library.
The tellstick is designed to be plugged into a USB host, so it doesn't make much sense in combination with an Arduino. You can get a USB host module but it's an expensive solution and you are using way more hardware than necessary.
Instead you could get 433 MHz receivers dirt cheap on ebay, but I'm afraid they only work on one channel, and there are a bunch of channels in the 433 MHz spectrum. So they might not work with the sensors you are talking about.
Another option would be to use eg. Arduino Pro Mini's in combination with a 433 MHz transmitter, powered by a battery. You could get the temperature reading from the internal sensor, or use an external one. The internal sensor takes quite a bit of calibration work to give a precise reading though.
You can get Pro Mini clones on ebay for a few dollars. You would have to dive into sleep modes and such, if you don't want't the batteries eaten away in a short time. To program it, you'll need an FTDI cable, or another Arduino programmed as an ArduinoISP (In System Programmer).
As an alternative to the Pro Mini board you could use a plain AVR chip, but it will be more work.

Okey so the best way to make the temperature sensor is to buy a pro mini and add external sensor, battery and 433mhz sender? Can this be made to work with the tellstick receiver? And can I mount any sensor on this pro mini? Like humidity, barometer, light, volume etc?

The microcontroller on the Pro Mini is the same as on the Uno. You can hook it up to all sorts of sensors. I don't know if it will work with the Tellstick. It might, but you would have to implement a protocol supported by Tellstick yourself. I'm not sure if the cheap 433 MHz modules run on the same frequency (433.92 MHz) as the Tellstick though.


text:
Running an LCD keypad shield from a separate power source
I need to use a motor shield and an LCD keypad shield simultaneously hooked up to a single Arduino Mega Board. Since I can't physically stack them, I decided to reroute all the pins used for the LCD keypad shield. When I reroute all pins except the two power pins, the LCD and keypad work fine. But when I disconnect those 2 pins and connect them to any other power source than the Arduino Mega, it fails. The screen becomes either blank / jumble of illegible characters / brief moments of expected output followed by the same jumble.
This behavior is really strange since the power pins don't carry any information, they are just power sources. The LCD keypad shield shouldn't be able to discriminate whether the power is coming from the Arduino Mega or not - but it does. I checked with a voltmeter that all power sources I tried are DC 5V.
At first I thought this is because the lcd.begin() function is called only once, so I rewrote my code to re-initialize the lcd at every iteration. This doesn't solve the problem.
Here is a picture of the setup that works. (rerouting all pins except the power.) Ignore the location of analog input cable, since it doesn't do anything in the current code.

And one that fails. The only difference from above is the power source.

And my code.
#include <LiquidCrystal.h>

// select the pins used on the LCD panel
LiquidCrystal lcd(28, 29, 24, 25, 26, 27);

void setup()
{
  lcd.begin(16, 2);
  lcd.print("Hello World!");
}

void loop()
{
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Hello World!");
  delay(1000);
  lcd.setCursor(0, 0);
  lcd.print("Hello Again!");
  delay(1000);
}

Any suggestions?

You can use a different power source, but the two circuit need to have a common ground, since all electrical signals are relative to ground. So connect a wire from GND on the LCD to GND on your Arduino and everything should work as expected.

Those little 16x2 LCDs are quite prone to power fluctuations.  Even powered solely by an Arduino I've seen them run OK for a few minutes than turn to showing gibberish.  Ensure you have good power connections, bring your power in as close as possible.
Maybe a capacitor across the power input to the display might help.


text:
Cannot upload program to Arduino Duemilanove w/ Atmega328

This is the error I receive while trying to upload to the Arduino.
I have installed FTDI drivers for mac. (http://www.ftdichip.com/Drivers/VCP/MacOSX/FTDIUSBSerialDriver_v2_2_18.dmg)
The board is part of a quadcopter: https://www.hobbyking.com/hobbyking/store/uh_viewItem.asp?idProduct=50460
The processor is an Atmel 328P. Do I have the correct drivers?
What else could be the issue?

You shouldn't need to load any drivers for your Mac; it should (mine does) recognize your FTDI USB device the moment you plug it in.

You may have wrong port:  /dev/tty.usbserial-A9007LXq works with Duemilanove on my Mac.

You can check this by opening a terminal and typing in ls/dev/tty. and then hitting tab. It should tell you all the open ports


text:
Arduino based small LCD screen with camera video capturing
i have a idea to create a small screen which displays video recorded from arduino with camera. so camera will be back side of human and screen will be at near to eye. human can see the pictures from back side.
i have found https://electronics.stackexchange.com/questions/29139/processing-ntsc-video-feed-for-spi-display
but its not give me a clear idea. is there any one who can advice me for that kind project?

What exactly do you need advice on?

the devices or any projects already done with this idea???

An arduino (at least the classic ATMEGA-based ones) is nowhere near fast enough for this task, and also lacks the necessary memory to hold even a single frame of reasonable resolution video.  One of the ARM-based boards also offered from arduino.cc might barely work, but overall you'd be better with at least a raspberry pi or something even more capable likely based on a smartphone SoC.

@ChrisStratton: You should post that as an answer - it's dead on.

An Arduino doesn't have anywhere near the processing ability to transcode video from a camera unless you had an abysmal frame rate and very low quality. Even then, you would have to add extra storage because the Arduino would be over capacity in a heartbeat.
I recommend converting this project to a higher powered board like the Udoo. I have the Udoo Quad and it's beastly considering its form factor. You're going to need something a lot bigger than an Arduino!


text:
Digital Read Serial tutorial - calculating the resistor value
The Arduino Digital Read Serial tutorial guides you through the wiring of a simple button. My questions are centered around the resistor.
Why is the resistor necessary?
I think I understand this, but correct me if I am wrong. To ensure that the input pin reads a low signal, and does not float, we should connect the pin to ground when the button is not pushed. When the button gets pushed, we will have a 5V signal flowing to both the pin and to ground. Kirchhoff's voltage law states that total voltage in closed loop must equal zero, so we have to deal with this 5V that is flowing directly to ground. That is why we put a resistor between the button and ground.
How was the resistor value chosen?
This is what I am unclear on. Ohm's law states that...
resistance = voltage / current

This is a 5V supply and the Arduino Uno spec says that the pin provides 40 mA of DC current. So..
resistance = 5V / 0.04A = 125 Ohms

In the Digital Read Serial tutorial, why do we have a 10K Ohms resistor? That is way overkill, right? Which leads to another question: Can you ever put too much resistance in place, if your only goal is to obliterate voltage?
Thanks in advance for any feedback!

You're very close. The resistor is there to act as a pull down resistor; If the input pin is floating it is just an antenna picking up random static. The key is that when positive is supplied (by pressing the button) the positive source needs to "overwhelm" the pull down resistor so that the input pin reads positive.
If there were no resistance, than the input pin would be reading in the middle of a direct path that does not favor positive or negative. Asside from the direct short that would be occurring, Which state the arduino would read I suspect would either be random or some property of the power supply; It would probably still read ground.
With the resistor, the signal is read directly connected to positive, before the load resistance. This way it will be sure to get a HIGH signal.
The exact size of the resistor is of little consequence. Too small and you waste current, but too much resistance is effectively just disconnecting ground again. There is a very wide range of values that will work fine between those.
I would like to note that when an arduino pin is set to input mode, it will effectively supply no current. It can be moddeled is being in series with a 100 megaOhm resistor. see http://arduino.cc/en/Tutorial/DigitalPins
for details.

The key thing here is that if you don't use a resistor, when the switch is closed, you have shorted the +5 volt to ground. A direct short will overload the power supply and trip the protection circuit on the power supply, causing the whole Arduino to shut down. You want a resistor of high enough impedance to keep the current flow low. I usually use a 100k resistor, which is plenty to pull the input signal to 0 volts when the switch is open, and only allows .00005 pas to flow, a trivial amount of current. A 10k resistor works too, but that allows 10 times as much current to flow.

Why is the resistor necessary?

The Arduino inputs have very high resistance. The datasheed of the Atmega328
says 100 MOhm for ADC, Such high values are good, but have also the drawback to deal with parasitic effects (resistance, inductance, capacitance). Such effects can also be used as Capacitance Sensors.

How was the resistor value chosen?

The resistor needs to have an arbitrary value, that is smaller than the input resistance. 10k and above are good for disabling the input leakage.
However you can also leave out the resistor when you use the internal pull-up resitors. In this case you deal with negative logic:
pinMode(3, INPUT);
digitalWrite(3, HIGH);

On pin 3 you'll measure HIGH and the button needs to be connected to the pin and the ground. The internal I/0 pull-up resistor has the value of 50k.

You've already gotten a couple of good answers on why a pull-down resistor is needed.
To summarize, you need to connect the input to ground to keep the input from floating semi-randomly between high and low. You use a resistor so that when you close the switch, you don't create a short circuit between the +5V supply and ground.
Another point, though. The Arduino's inputs include an optional internal, software-controlled pull-up resistor. If you first set up the pin as an input, then write a HIGH value to that port, it activates the pull-up resistor. That causes the pin to read as HIGH when nothing is connected to it.
You can then connect your switch to ground instead of +5V. You then need to change your code logic to treat a HIGH value as not pressed, and a LOW value as pressed. This lets you simplify your wiring a little, since you don't need an external resistor.


text:
How can I make my Arduino code work?
I am trying to make an automatic lock which stays open during different times and on different days. I want the door open Monday through Friday 8am to 5pm. On Saturdays and Sundays I want the door locked. I will be using an electric lock strike the + wire to pin 9 and - to ground on arduino. I am using an LED for development purposes for now because I don't have the lock yet. The code I have now works (stays open) for 8am to 5pm through the whole week but i want the door locked for Saturdays and Sundays. This is my code so far:
#include <Time.h>
#define doorPin 9
void setup() {
  // put your setup code here, to run once:
  pinMode(doorPin, OUTPUT); // Connected to relay to activate the door lock
  setTime(10,1,1,6,7,2014);
}

void loop() {
if (hour()>=8 && hour()<=17){
  digitalWrite(doorPin, HIGH);
}
else if (weekday()==1 || weekday()==7){
  digitalWrite(doorPin, LOW);
}

This is what's happening: it's still between 8 AM and 5 PM on the weekend, so it unlocks it. Since you use an else if, it terminates the if statement and never checks the day between 8 and 5. I'm almost positive that if you checked it another time in the day, it'd be "locked."
Fixed code:
#include <Time.h>
#define doorPin 9
void setup() {
  // put your setup code here, to run once:
  pinMode(doorPin, OUTPUT); // Connected to relay to activate the door lock
  setTime(10,1,1,6,7,2014);
}

void loop() {
if ((hour()>=8 && hour()<=17) && !(weekday()==1 || weekday()==7)){
  digitalWrite(doorPin, HIGH);
}
else {
  digitalWrite(doorPin, LOW);
}

Note: ! means "not." Thus, the door is locked only if it's not a weekend and it's between 8 and 5.
Additionally, you might want to get a lock that is the other way around: unlocked only with power applied so someone can't unplug the Arduino to get access. EDIT: miscommunication, ignore this part paragraph...

I'm sorry I meant open from Mon - Fri 8-5, locked on Sat - Sun. (The lock is unlocked with electricity)

@user the code should stay the same, just with a [slightly] different explanation.

Adding to Annonomus Penguin's answer, it might be cleaner and easier to understand if you extract the variable:
bool doorOpen = ( (hour()>=8 && hour()<=17) && !(weekday()==1 || weekday()==7) );

Or in my eyes even nicer if you unnegate the last part, ymmv:
bool doorOpen = ( (hour()>=8 && hour()<=17) && (weekday()!=1 && weekday()!=7) );

And then use them directly in the code without the if statement:
digitalWrite( doorPin, doorOpen ? HIGH : LOW );

This way you make sure that the doorPin always gets set and you din't forget a path like in your if-elseif-nothing version.
Another benefit is you can test independently if the doorOpen variable is correct and if the functionality that is triggered by it is correct.

In that last Boolean expression, all of the parentheses other than the function calls are redundant and distracting. bool doorOpen = hour() >= 8 && hour() <= 17 && weekday() != 1 && weekday() != 7; is much clearer.

[As for the boolean statement change]: It's pretty much a personal preference, I personally think it flows better the way in my answer, but I'm pretty quirky! :-) However, a boolean directly is a good idea, +1 for that.


text:
Error building Arduino WiShield Flash example: 'dflash' was not declared in this scope
I'm using WiShield library from: https://github.com/jcmuller/WiShield
What is wrong with this library?
The code:
/*
 * Web Server using Flash
 *
 * A simple web server example using the WiShield 2.0
 * that reads the manufacturing ID from the Flash and
 * displays it on a webpage.
 */

#include <WiShield.h>
#include <dataflash.h>

#define WIRELESS_MODE_INFRA    1
#define WIRELESS_MODE_ADHOC    2

#define FLASH_SLAVE_SELECT 7
#define WIFI_SLAVE_SELECT  10

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2};   // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};  // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes

unsigned char security_type = 0;    // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};   // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {   0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,     0x09, 0x0a, 0x0b, 0x0c, 0x0d,   // Key 0
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 1
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 2
                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00    // Key 3
                            };

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

unsigned char mfg_id[4];

void setup()
{
  initShield();
}

// This is the webpage that is served up by the webserver
const prog_char webpage[] PROGMEM = "HTTP/1.1 200 OK\r\nContent-Type:     text/html\r\n\r\n"
                                ""
                                ""
                                "
Flash Mfg ID: 000 000 000
"
                                "<form method=post action=\"/upload\" enctype=\"multipart/form-data\">"
                                "FS Image Upload"
                                "
"
                                "<input type=file name=i size=40>   <input type=submit value=\"Upload\">"
                                "</form>"
                                ""
                                "";

void loop()
{
  dflash.read_id(mfg_id);

  WiFi.run();
}

void initShield()
{
  // there is some contention on the SPI between the flash and wifi chip,
  // so disable both devices at the beginning until they are properly
  // initialized by their respective libraries
  pinMode(FLASH_SLAVE_SELECT, OUTPUT);
  digitalWrite(FLASH_SLAVE_SELECT, HIGH);
  pinMode(WIFI_SLAVE_SELECT, OUTPUT);
  digitalWrite(WIFI_SLAVE_SELECT, HIGH);

  // now init dataflash
  dflash.init(FLASH_SLAVE_SELECT);

  // now init wifi
  WiFi.init();
}

Try putting Dataflash dflash; along with your other variables.

error: 'Dataflash' does not name a type

I doubt anything is wrong with the library, but in your initShield and loop methods you refer to a variable called 'dflash' which does not seem to be defined anywhere.

This is the example that comes with the library. No changes.
https://github.com/jcmuller/WiShield/blob/master/examples/Flash/Flash.pde

Interesting; looks like there is no dataflash.h in the repo.  Post an issue; the file might not have been committed correctly.

Never mind; you need this library too: https://github.com/asynclabs/dataflash


text:
Breadboard-to-Arduino wiring with flat flex cable assemblies?
I want to wire Arduino Due connectors to a breadboard 8-at-a-time, so they're easier to remove and more reliable.
I tried these Flat Flex Cable Assemblies (FFC assemblies) terminated with "solder lugs" from Digi-Key, but the pins are just a little too short to penetrate the Arduino connectors well.  Similarly they barely reach into to the breadboard contacts, so they tend to fall out.  Anyone find a workable product for this?

This solution is good but requires a lot of manual soldering.  Looking for prepackaged.

For now, you could solder some male headers to those flatflex cables, making them easier to work with.

When I had to breadboard 8-bit computer projects, I'd wire all the busses with 4 colors of discrete hookup wire used in spectral order.  That way if anything came out it was easy to tell where it should be reconnected.  (I also tied the bundles down with little jumpers in the supply rows or unused rows, but that wouldn't apply here).

http://www.youtube.com/watch?v=GkbOJSvhCgU looks like being a possible solution.

You may be onto something, @yeti.  Male-to-male pre-crimped wires for 0.1" spacing connectors.  http://www.pololu.com/product/1808

Search for male-male jumper wire. Some of what you'll find is individual wires but there are also many that are connected together and you can rip off the width you need.
Here's one from Adafruit but there is no shortage of them on ebay/amazon.

Thanks, Sachleen!  Are any of them spaced at fixed 0.100" centers?  I am actually now using breadboard jumper wire and it works fine, but I was hoping for quicker interchange, something that didn't require error-prone unplugging and plugging dozens of individual wires.

Not that I know of. I've seen some that are groups of four wires but they aren't specifically designed as breadbaord jumper wires but for a specific product.

Bought a handful from China to try out.

Again similar to Sachleen's answer. You can crimp your own connectors onto a ribbon cable, that way you can have the desired header size.
I've just done this manually with some pliers (I couldn't afford the crimping tool) a bit tricky but I'm pleased with the results. I got all of the bits I needed from www.hobbytronics.co.uk. Anywho I'm happy with the results now after a few failed attempts.

Very close, Nick J Adams.  Thanks to a tip from @yeti I just bought some pre-crimped wires from Pololu and some 0.1" headers to try out.  It looks as if you are using headers here that space the contacts 0.1" apart?

Yes that's right, so would work on a breadboard, perf board and of course Adafruit's combination of both as shown in the photo.

Although Sachleen's answer is preferable in a lot of situations, there are a few other options that you have.
Quick note on his answer: I find clamping a row of those wires together and rubbing a thin line of superglue over the connectors a useful way to keep them together. It's not very neat, but it works pretty well and, with that many wires connected, can make it more stable than before.
There are two main alternatives I see:

Ribbon cable: very similar to the wires pointed out in Sachleen's answer, only the connectors come already as one piece.

Source: http://www.adafruit.com/blog/wp-content/uploads/2012/06/window-207.jpg

They are typically two rows, but I've seen them before with one (although pretty rare). You could just ignore one row of those and use some male headers to connect the same side of the ribbon cable to the breadboard/Due.
DIY: although you said that you didn't like soldering, it's still the best solution here IMHO. You'll need soldering later on, and breadboards aren't reliable beyond just simple development, so you'll need to learn at one point or another. This is a great entry project because it's pretty hard to mess a simple thing like this up, unless you accidentally bridge two joints. However, you won't damage an expensive chip if you mess up (which you will on the first few times you solder), you can just clean the joints and start over.
Anyway, just grab some perf board and some wire (twisted pair (similar to CAT5e)/ribbon cable with or without an adapter and plug/loose wires, and a few rows of male headers. The type of wire you choose doesn't really matter, just don't get something too thick or too thin. Anyway, solder some headers to the perf board and then you can solder the wires/the socket (if you choose a ribbon cable with ends) together. You can then cut the perf board to size (you can do this step before soldering) and you're done!

Close, mister penguin.  Good suggestion with the inserted headers.  DigiKey has plug-to-plug ribbon cable assemblies for $8 each.

And now I understand what you mean about the superglue-variant on @sachleen 's answer.  Do they end up 0.1" apart when you do that?

@BobStein For the ribbon cable, that's definitely a cleaner and easier variant, but it does cost a little more (especially costing experience with soldering). As far as the superglue, yes, mine did fit perfectly with some 0.1" headers. I didn't try with a breadboard, but the headers are the same spacing as a standard 2.54mm breadboard.


text:
Sending MIDI messages using PING ultrasonic sensor
I am working on a project that uses a potentiometer and an ultrasonic sensor to create MIDI signals. This is my first time working with an arduino. I took a class in C++, but am teaching myself some C in order to program the arduino. So far I have been looking at code that has been written, I've been trying to understand it and mess with it so that my arduino works. The first code creates notes, but I have no control over what notes play or when they play. The first code:
#include <SoftwareSerial.h>

int val;
int AnalogValue = 0;
byte note = 0;
SoftwareSerial midiSerial(2, 3);

void setup ()
{

  pinMode(Pingpin, OUTPUT);
  Serial.begin(9600);
  midiSerial.begin(31250);
}

void loop()
{
  val = 0;
  digitalWrite(Pingpin, LOW);
  delayMicroseconds(2);
  digitalWrite(Pingpin, HIGH);
  delayMicroseconds(5);
  digitalWrite(Pingpin, LOW);

  AnalogValue = analogRead(0);
  note = AnalogValue/8;

  pinMode(Pingpin, INPUT);
  val = digitalRead(Pingpin);
  while(val == LOW)
  {
    noteOn(val, note, 0x40);
  }
  while(val == HIGH)
  {
     noteOn(val, note, 0x40);

  }

}
void noteOn(byte cmd, byte data1, byte  data2)
{
    midiSerial.write(cmd);
   midiSerial.write(data1);
   midiSerial.write(data2);
}

The second code makes more sense to me, but I get no notes to play. I am lost, and can't seem to get the second code to work. Second code:
#include <SoftwareSerial.h>

int val;
int timecount;
int AnalogValue;
int ultrasoundValue;
const int Pingpin = 8;

byte note = 0;

SoftwareSerial midiSerial(2, 3);

void setup ()
{

  pinMode(Pingpin, OUTPUT);
  Serial.begin(9600);
  midiSerial.begin(31250);
}
void loop()
{
  AnalogValue = analogRead(0);
  note = AnalogValue/8;
  Serial.print(note,HEX);
  Serial.print("\t");

  timecount = 0;
  val = 0;
  digitalWrite(Pingpin, LOW);
  delayMicroseconds(2);
  digitalWrite(Pingpin, HIGH);
  delayMicroseconds(5);
  digitalWrite(Pingpin, LOW);

  pinMode(Pingpin, INPUT);
  val = digitalRead(Pingpin);
  while(val == LOW)
  {
   val = digitalRead(Pingpin);
  }

  while(val == HIGH)
  {
   val = digitalRead(Pingpin);
   timecount++;
  }

   ultrasoundValue = timecount;
   ultrasoundValue = ultrasoundValue - 14;
   ultrasoundValue = ultrasoundValue / 5;

  Serial.print(ultrasoundValue);

if(ultrasoundValue > 127)
 {

 }

else
  {

   noteOn(ultrasoundValue, note, 0x40);

  }

}
void noteOn(byte cmd, byte data1, byte  data2)
{
   midiSerial.write(cmd);
   midiSerial.write(data1);
   midiSerial.write(data2);
}

There is quite a bit that needs to be addressed for these programs to work, and I don't know too much about midi, but i'll use the arduino midi tutorial for info. http://arduino.cc/en/Tutorial/Midi?from=Tutorial.MIDI
The first code will take one measurement of an analog value, set it to note, make one digital reading of pingPin, set that to val, and then write noteOn() forever afterwards. The second code will continually make analog and Ping readings and then write those to serial if the ping reading is greater than 127.
Infinite loop aside, Your programs don't work largely because they send the sensor data in the wrong ways. The first byte sent to noteOn is a command byte, it should not contain sensor data. the arduino tutorial uses the command 0x90 to control the note being played on channel one. the second byte is the note and the third byte is velocity, which seems to work like volume.
to set the pitch and volume of channel one, you need to repeatedly send
noteOn( 0x90, note, volume);

If you want to play a note based on the analog readings that both of your codes set to "note" only when the ping value is larger than 127, you need something like this
if(ultrasoundValue > 127){
    noteOn(0x90, note, 0x45); //middle volume according to arduino tutorial
} else {
    noteOn(0x90, note, 0x00); //make the note silent by using 0 volume
}

if you instead wanted to control the pitch with the ultrasoundValue, you would need to scale the value to being within 0-255, and then use that as note instead of the analog reading. You can get much more complicated than this, but you will need to find a reference for the MIDI protocol you can use.

Thank you for the info, I was able to read more on MIDI. I have a good grasp on how these messages are composed. I still have not solved the main problem. I have a MIDI cable that flashes when MIDI signals are being sent. When I upload code #1 the light flashes, but when I make any adjustments to the code and upload the a modified version, the light stops blinking. I printed the value of UltrasoundValue and it is around 600, so the ping sensor is working. I don't know why it won't go into the "if" statement.

I recommend you start with the code from the arduino tutorial and then very slowly hack on that until it does what you need. Make changes one at a time so you can isolate which change makes the code stop working.


text:
GPS - Speed doesn't update as should - EM408 & Arduino Mega & GSM
I'm developing a system that will get the GPS signal and send it though the GSM with information about position, speed and temperature from some digital sensors.
Currently I'm using the GPS EM408, the Arduino mega plus the GSM board (official one).
The problem is that the GPS (by the library TinyGPSPlus) gives me the same speed for long time or sometimes give me 0km/h.
The sketch works like this:
loop()
{
   getGPSData() - ~ 1 sec to execute and take one data from the GPS.
   getSensors() - ~ 1 sec to execute and take one data from the digital sensors.
   sendData() - ~ 6 n 10 secs to send the data through the internet.
}

The whole process takes around 10 ~ 15 secs to be completed.
If I remove the sendData() and the system starts getting the GPS information each second the speed value works perfectly but if I get the data from the GPS each 12 secs (because of the GSM delay) the speed doesn't work as expected.
I understand that the problem is because the library TinyGPSPlus calculate the speed between two points and the getGPSData() only takes one information each loop and the next point has 15 secs of difference.
Although I've added a "for(i=0;i<=4;i++)" to the getGPSData() enforcing it to get at least 4 times of position before the GSM send it over the internet, now is working better but still getting the wrong value or sometimes it freezes to the same speedy for long time.
I've tried to add a second board and put both to communicate with I2C turning it "dual core", where one board will be getting the data from the GPS each second and another one will send though the data each 15 secs, but the GSM freezes sometimes when the I2C is connected :(.
Does anyone has any clue how to do it?

You will likely have to show more of your code. In your for loop, did you add a little delay after getting gps data? That may help.

Thanks @sachleen
I've checked the serial communication between the GPS and the Arduino, therewith I've detected that the problem was because there is a gap in the middle of the communication. My code has a WHILE() to keep taking information from the serial while data is coming from the serial, but sometimes the connection between both has a small stop (the gap) and it was closing the WHILE(). I added another WHILE() to keep checking the serial for at least 2 seconds and it solved the problem. Thank you


text:
Can I hook up a compass directly to my GPS module?
I have a Parallax PMB-688 GPS module I'm using with an Arduino and was wondering if I could hook up a compass directly to my GPS. The GPS has an RX port which I hypothesized a compass could be attached to but I don't know if the GPS would be able to comprehend the compass data alone or if I would need to hook it up to the Arduino separately. Please let me know if you have done this or know whether or not it will work. Thanks,
Chris

Unfortunately this will not work. If you take a look at the documentation for the module (here and here) you'll see that the RX pin is just there to receive commands for doing things like changing the baud rate and the protocol. The GPS wouldn't be able to comprehend the compass data.

Thanks, this was really helpful. I should have checked the documentation before asking the question.


text:
3.5" TFT LCD Display is not working with Arduino Mega 2560 R3
Even I can't do similarly with my 2.4" TFT LCD in here still: 2.4" TFT LCD Shield isn't working on Arduino Mega
Now, I have bought 3.5" TFT LCD display for my Arduino Mega 2560 R3 to try whether I could run the screen or not, and it is not working now! I am so depressed and angry for these two's misbehaviors. I have already checked website and a lot of Arduino IDE code examples and libraries such as UTFT.h, UTouch.h, UTFT_MEGA, UTFT_CTE, TFTLCD. I tried these and I can not run my 3.5" screen. Where am I faulty? There is something below the screen shield: www.mcufriend.com and 3.5" TFTLCD for Arduino 2560. Are there any basic code or have anyone tried to run Mcufriend's displays correctly?

possible duplicate of 2.4" TFT LCD Shield isn't working on Arduino Mega

I would recommend contacting the seller about example code/libraries, or at the least a datasheet.

I have the same problem and the seller does not respond

I know how to make these work, but they are all a little different. Please post a link to the exact product you bought. A link to an online store or something will work fine. If it's like the one in my photo, I can make it work... https://www.flickr.com/photos/77816686@N02/11719888193/in/set-72157636192458205

Yes it is @Jasmine. Please do. Thank you in advance.

I still don't see a link to the product? I could write up a general approach, but it might be a waste of time.

http://www.henningkarlsen.com/electronics/library.php?id=51
Download hennings new UTFT library.
in myGLCD define R61581 as this is the driver chip for 3.5 display.
Regards!

Try this code:
https://www.dropbox.com/s/fce43rxofttl001/Librer%C3%ADas%20UTFT%20%2B%20UTouch%20para%203.5%20TFTLCD%20para%20Arduino%20Mega%202560%20%20-%20copia.rar
First delete the old UTFT library, then copy and paste the library inside de RAR file.

Can you please post the contents of the file?

This might be a silly suggestion, but the mega2560 is 5v, and the display is 3.3v...and you need an interface board between.  I have successfully run a 3.2" display using this interface board
http://www.elecfreaks.com/store/lcd-tft01-arduino-shield-v20-shd09-p-213.html
Hope this helps

I have the same lcd shield from mcufriend. It has ILI9327 in 8 bit mode.
This shield doesn't work with original UTFT library (it supports only 16-bit mode).
Try modified version from https://github.com/dgolda/UTFT and use:
myGLCD(NIC35WS,38,39,40,41); //3.5" TFTLCD for arduino 2560 from mcufriend.com


text:
What is causing my Uno to wake up?
NOTE: this code was working perfectly fine in another program.
I have a simple piece of code that puts the Arduino to sleep. When it is finished and intergrated into my project, it will only wake the processor up when an alarm from an external RTC triggers one of the hardware interrupts.
#include <avr/sleep.h>
#include <avr/power.h>

void setup(){
    Serial.begin(9600);
}

void loop(){
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);        //deep sleep mode
    Serial.println("Device is going to sleep...");
    sleep_enable();        //put device to sleep

    sleep_disable();        //Device restarts here on wake
    Serial.println("Device is awake...");
    delay(1000);        //to slow down serial output
}

In theory, the program should shut down the processor indefinitely because there is nothing available to wake it up.
However, the device continues waking itself up immediately after shutting down.
I have tried attaching the interrupts hoping it was some kind of anomalous watch-dog function. I have tried tying the interrupt pins to +5V and also (in a separate attempt) to GND. Nothing has helped.
What is causing the processor (and/or program) to constantly wake itself up?

sleep_enable() allows the MCU to sleep, but it does not cause it to sleep. Call sleep_cpu() after enabling.

I can't believe I overlooked that, it works perfectly.


text:
Arduino Leonardo timing Inconsistency
I've got a question regarding the use of Millis() on a Leonardo Arduino. I'm currently using it to time 4 seconds elapsed while sending a serial message every second. These messages play a sound. On the fourth message the sound is different to signify that the Arduino has started an event.
I'm running into an issue where the sounds are occasionally being played sporadically without a consistent 1 second between them. I'm wondering if there is a better way of doing what I'm doing? During the timing the Arduino is doing nothing else, and the receiving computer is also generally not doing anything taxing. Is this even an issue from the Arduino side? My receiving program is written in C# using System.IO.Ports.SerialPort.
The reason this is done through Arduino is because the event started by the Arduino needs to correspond exactly to the sounds, though if this remains unresolved I will need to rework this.
Edit: Code as requested.
void setup()
{
    //Setup Code
}

void loop()
{
    //Code that handles other serial messages and various states
    if (isSpecificState == true)
        onSpecificState();
}

void onSpecificState()
{
    //Setup to handle state

    long holdStart = millis();
    long holdDuration = 0;

    boolean print1 = false;
    boolean print2 = false;
    boolean print3 = false;
    boolean print4 = false;

    while(holdDuration <= 4000)
    {
        if (holdDuration >= 4000 && !print4)
        {
            Serial.println("tt_sound:2");
            print4 = true;
        }
        else if (holdDuration >= 3000 && !print3)
        {
            Serial.println("tt_sound:1");
            print3 = true;
        }
        else if (holdDuration >= 2000 && !print2)
        {
            Serial.println("tt_sound:1");
            print2 = true;
        }
        else if (holdDuration >= 1000 && !print1)
        {
            Serial.println("tt_sound:1");
            print1 = true;
        }
        holdDuration = millis() - holdStart;
    }

    //Handle state
}

As I mentioned in the comments, the Arduino is doing nothing else while the timing is happening.

Can you post your Arduino code so that we see if there is an issue in there?

Why the downvote? @jfpoilpret code is up, its painfully simple though.

Added clarification, the reason I didn't post the code initially is because 95% of the time it works flawlessly. There are however occasions caused by circumstances I haven't figured out in which the sounds are off. This is what I need help with.

Why not use another timer to schedule them?

Have you tried printing the value for holdDuration and see if it is consistent?

Just to clarify: I did not downvote your question. About your code, I doubt you always pass in the first if, typically that first if should be located after the while loop. Important question: what are the types of holdDuration and holdStart?

@IgnacioVazquez-Abrams Could you elaborate? I'm not sure I understand. @Craig I haven't, I've not been able to consistently reproduce the issue. @jfpoilpret Didn't mean to imply you had, was an open question :) Both holdDuration and holdStart are of type long, same as millis() return type.

I think millis() is actually unsigned long but that is probably not the issue unless you are running for more than 24 days.

Please post the entire code, not just the part that, I presume, is inside the loop function.

All I can say is I do not understand what you mean, because you did not give a reproducible example.

Notice items 2 and 3 in this answer: http://electronics.stackexchange.com/a/126063/8627 You may be able to pin point if this is the issue by disabling USB communications and switching to UART combined with a UART-to-USB cable.

Thoughs:
Unfortunately I have been unable to get to the bottom of this issue. I noticed the problem tends to happen the first time the interaction starts after the computer and Arduino are idle.
Without knowing too much about how the serial communication is built I'm guessing that without traffic the connection is put to sleep, or generally inactive, and the sound delay is a result of the connection needing to re-initialize or something of that nature. I cant recall a time when the issue occurred and I had a recent correct previous interaction. Once it works any immediate retrial will also behavior correctly.
Solution:
I have since moved my timing/sound playing component within my C# app. The Arduino now signals the start of the timer, and then end of the timer with an immediate start to my event.

There is only a very slight chance that you meet the holdDuration >= 4000 condition in the while loop. Only when holdDuration will be exactly 4000 the while loop will be executed AND the subsequent test in the if statement will pass.
The serial print commands can easily take long enough to have millis() jump from a number less than 4000 to a number higher than 4000 in a single pass of the while loop.
To prove this assumption, increase the while test to holdDuration <= 4100 and see if the intermittent effect goes away.


text:
Read car high temperature exhaust pressure sensor
Is it possible to read the exhaust gas pressure of a turbo car with an Arduino, and then control an electric motor based on the pressure?

Probably.  Might be simpler if you could either install a second sensor to use independently, or tap into the CAN or OBD and get the readings that way.  Finding specs on the sensor would be key; is there perhaps a group of car people who hack on those habitually?  Or re-apply them to model aircraft turbines or something like that?

Yes.

Yes, I don't see why it wouldn't be possible.
You would need a sturdy barometer, preferably a digital I2C one because they are typically more accurate. I recently bought this one to measure altitude: BMP180 Barometric Pressure/Temperature/Altitude Sensor- 5V ready.
Be careful about the temperature that the sensor will have to deal with, its maximum temperature is 85°C (185°F).
The motor, I'm assuming, would be fairly large so you would need a beefy motor driver that uses a 5 volt logic level, maybe like this one: L298 Dual H-Bridge Motor Driver.
This is a fairly difficult project, I'd say mostly because of the difficulty you would have mounting the barometer and motor. Never the less, it still is possible.

I don't think the question is asking about replacing the sensor with something generic, but rather reading the sensor already present (or an additional similar one).  Generally, parts actually used on cars are a lot cheaper than generic functional equivalents, due to economies of scale in both manufacturing and distribution.

oh, The question was kind of vague.

Also using that adafruit sensor above would be a bad idea.  It was not designed to withstand the conditions around exhaust.  plus the dirt and oil.

You might want to look at https://github.com/designer2k2/multidisplay they're doing exhaust gas pressure monitoring and a number of other things.

Although this answers the question, it will be useless if the link breaks. For that reason please edit your answer with a summary of key points so that the question is answered on this site. Users can then go to the link for more detailed information. Please edit your answer.


text:
Why PIN3 stays at 1v3 in a IR emitter project?
Here is my very simple IR emitter circuit.
OSI5FU5111C-40 is an infrared LED.

I am using the IRremote library from here
in this simple sketch,
#include <IRremote.h>
unsigned int raw[100]={... *SOME RAW SIGNAL* ...};
IRsend irsend;

void setup()
{
  Serial.begin(9600);
}

void loop() {
  if (Serial.read() != -1) {
    for (int i = 0; i < 3; i++) {
      Serial.print("Start sending ...");
      irsend.sendRaw(raw, 100, 38);
      delay(40);
    }
  }
}

The problem is when I send 1 to serial monitor,
it outputs triple Start sending ... and LED emits no signal.
So I test the voltage between PIN3 and GND before and after sending the 1.
The voltage stays around 1V3.
Would someone please give me some advice? Thank you!

Just add a normal led instead of the ir-led, so you can at least see what is happening. Also note that when transmitting the led is pulsed at 38kHz, so your multimeter will some average voltage, and never the full 5 volt.

In addition to the duty cycle being averaged by a meter, the current drawn is likely enough that the output pin will be noticeably below the supply rail even during the fraction of time it is "on".  It should be noted that the LED itself is specified with a typical forward voltage of 1.35v so the anode of the LED will be limited to around that voltage, with the difference from the supply dropped across the resistor and the internal impedance of the ATmega.

You can also detect the IR with a cheap cell phone or digital camera.

A few things. As somebody else suggested, try a normal red LED and make sure that works first.
Note that your resistor is allowing too much current through the LED. A high-current LED might tolerate 20 mA (thousandths of an amp.) With a 47 ohm resistor, you're pumping 5/47, or about 106 mA into the LED, which is likely more than 5 times what it is designed to handle. You will quickly burn out your LED. You should use a 270 ohm resistor instead.
Also try just setting pin 3 to an output with this line:
pinMode(3, OUTPUT);

And then manually setting that pin to on:
digitalWrite(3, 1);

If the LED lights up, you know the pin is working correctly. Then use the code you posted with the same setup, and make sure your LED flashes. If THAT works, try putting your IR LED back in the circuit.

Bear in mind that ~1.5v is dropped across the LED, so only ~3.5v is going across the resistor. That means the current driving the LED is about 74 mA, which is below the rated maximum of 100 mA specified in the datasheet.

100 mA? Wowzers, that's a high current LED! (You'r right, I forgot to subtract out the voltage drop of the LED).

IR LEDs usually have a much higher If than visible light LEDs. Not that the pin is actually capable of sourcing that much, of course...

@IgnacioVazquez-Abrams - That's a good point -- attempting to draw that much current for any length of time is definitely not a good idea.

Thank you for all your comments. This is what I tried, I switched the IR LED to a normal LED, increased the resistor and tested with digitalWrite. It worked fine. Then I switched the sketch program without changing anything in the circuit. The LED failed to work. I tested PIN3 and GND without any circuit attached. The voltage reads 1.6v. Is there any chance the sketch is wrong

If you're using a high current LED, you can't drive it directly with an output pin. The absolute max current you can draw from an Arduino Mega pin is 40 mA. Not sure about other models. To protect the I/O pins on your Arduino, you shouldn't connect anything to ground with less than 125 ohms total resistance. Otherwise you risk burning out the driver for the I/O pin.

You should use an NPN transistor to drive the LED, with the Arduino output pin driving the base of the transistor through a resistor, and the LED connected between +5V and the collector (through your 47 ohm resistor.) Then connect the emitter to ground.


text:
How does one build a door motion sensor project with Arduino Uno board to send alerts to an Android Phone?

What are the materials I will need for the project? We want the project to work like this: When the door is opened, we get an alert to our Android Phone.
What is the circuit structure going to look like?
Which is simpler, GPRS, Bluetooth or Wifi to get the alert?
What is the best IDE to work on for this project?

If I could comment on this, I would say that this question really sounds like you haven't actually done any research to look into a solution.
But, in simple terms:

Arduino Uno, Android phone, GSM shield, contact sensor or limit switch
The sensor or switch needs to be connected to an I/O pin on the Arduino, and will probably need to be connected to 5V.
GSM(GPRS) is going to provide the most mobility
Arduino


text:
Leonardo-based tachometer?
I'm new here. I'm not a native speaker, so pardon my English.
I just received my Arduino Leonardo today. I tried some basic calculations and stuff like blinking and LCD interfacing. Its interesting.
I am now trying to make a tachometer with the Leonardo. I'm following this tutorial.
I guess the board they've used differs from the Arduino Leonardo (ie pin 3 is interrupt0 in the Leonardo but it is pin 2 in the Arduino Uno board used in the tutorial). I tried changing the pins on the program and reconnecting the circuit but it doesn't work.

This is the code from the tutorial:
/* Optical Tachometer
 *
 * Uses an IR LED and IR phototransistor to implement an optical tachometer.
 * The IR LED is connected to pin 13 and ran continually.
 * Pin 3 (interrupt 0) is connected across the IR detector.
 *
 * Code based on: www.instructables.com/id/Arduino-Based-Optical-Tachometer/
 * Coded by: arduinoprojects101.com
 */

int ledPin = 13; // IR LED connected to digital pin 13
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void rpm_fun() {
  //Each rotation, this interrupt function is run twice,
  //so take that into consideration for calculating RPM
  //Update count
  rpmcount++;
}

void setup() {
  lcd.begin(16, 2); // intialise the LCD
  //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
  //Triggers on FALLING (change from HIGH to LOW)
  attachInterrupt(0, rpm_fun, FALLING);
  //Turn on IR LED
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  rpmcount = 0;
  rpm = 0;
  timeold = 0;
}

void loop() {
  //Update RPM every second
  delay(1000);
  //Don't process interrupts during calculations
  detachInterrupt(0);
  //Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt
  //happened once per revolution instead of twice. Other multiples could be used
  //for multi-bladed propellers or fans
  rpm = 30*1000/(millis() - timeold)*rpmcount;
  timeold = millis();
  rpmcount = 0;
  //Print out result to LCD
  lcd.clear();
  lcd.print("RPM=");
  lcd.print(rpm);
  //Restart the interrupt processing
  attachInterrupt(0, rpm_fun, FALLING);
}

Can anyone help me to fix the project? Has anyone here tried this project before?
Thank you!

Try removing the phototransistor, get a jumbercable from ground and insert and remove it a few time at the point where the resistor and the photodiode were connected. If any rpm shows up on the lcd, you'd know it's that photodiode that is faulty, or just not near enough to the ir-diode. The code looks fine, and INT0 is indeed on pin D3 instead of D2.

Your circuit looks wrong to me (although I haven't worked much with phototransistors). Why do you not have a resistor for the LED? Is it one built for 5V? Also, as far as I know, phototransistors only conduct when there's light. It seems odd to add a pull up resistor so it always reads high...

What specifically did you do when you said you tried changing the pins in the program? have you tried running the program stock and changing the wiring to use pin 3? Also, can you be more specific how it is not working? is it always printing 0 RPM?

yeah it is always writing rpm = 0. I've changed the interrupt0 to pin 3 on leonardo. would you guys suggest some simple way to test attachInterrupt() with ir transistor, i have both 2 pinned ( ?, ? )and 3 pinned (+, out , -) ir transistors/sensors. thank you!

First, make sure that your LCD routines and wiring are working, by trying to display something on it.
Second, the code isn't correct - it will have some fluctuations from one measurement to another.
One way to do it is to start timing only after the first pulse has arrived, and stop timing only after the last pulse has passed.
Something like this:

Wait until a falling edge.
Time0 is millis().
Wait for N pulses to pass.
Time0 is millis() minus time0.

Now with time0 and N you can calculate your rpm.
Edit:
Here is the above code at work, running Arduino on a PIC24.

The input signal is 10Hz, 1 pulse per revolution, aka 600 rpm.
As you can see the rpm read-out is precisely 600rpm. I'm running the code at 8x oversampling.
As I indicated earlier, your code will introduce uncertainty, as much as one period for the pulses. So in a single pulse measurement, the rpm can be anywhere from 0.5x of the true value to 1.0x of the true value.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Multiple independent LED patterns
I have an problem, which at first thoughts (and being new to Arduino) I though was a perfect application for an Arduino. However, after trying and failing to implement it I am doubting myself!
Simply - I need to control many LEDs independently, many of which will have their own individual patterns - for example "5 seconds on - 5 seconds off". "continuous flashes" - or sequences such as "2 flashes, pause, 1 flash". Obviously without the luxury of threads I am becoming a little unstuck. Be great to hear if a) Arduino is the best choice and b) if it is - how can I go about this!
Thanks in advance :)

Have you looked into protothreads? There are a couple of Arduino libraries that let you easily incorporate protothreads in your project.

Use Arduino library NonBlockingSequece. It has many clean examples to answer this specific question.

Handling multiple patterns at the same time is certainly possible with a platform like Arduino, and there are a number of ways you could go about it.
One method I would consider is writing functions which effectively represent each pattern mathematically. You'd just pass it the total time that's elapsed in your program so far, and it will do the appropriate action for that specific moment in time. It will return immediately afterwards (no delays or anything).
To do that, you'll first need to know how long a single cycle of the pattern lasts. You can then use the modulo operator to figure out how far through the current cycle you are. From there, all you need to do is have some if conditions to determine what to do at any given time.
Here's what it might look like for your "5 seconds on, 5 seconds off" pattern:
function pattern5on5off(unsigned long totalTime)
{
  // Calculate how far through the current cycle we are
  const unsigned long cycleTime = totalTime % 10000;

  // If we're in the first 5 seconds of the cycle then turn the light on.
  // Otherwise, turn it off.
  if (cycleTime < 5000)
    digitalWrite(3, HIGH);
  else
    digitalWrite(3, LOW);
}

Admittedly, constantly calling digitalWrite() when you don't technically need to isn't very efficient. It shouldn't cause any harm though, and is fairly easy to optimise if necessary.
To use the above example in a sketch, you'd just need to call it in loop(), and pass the number you get from millis(); e.g.:
void loop()
{
  const unsigned long totalTime = millis();

  pattern5on5off(totalTime);

  // call other patterns here...
}

Other patterns will be more complex, but follow the same principle. You'd just to use appropriate if statements to express your logic.
The vital thing to remember is that the function represents a specific moment in time. It should never pause or delay the program, otherwise it will prevent the other patterns from running.
Edit: Timing on the first cycle
As jfpoilpret noted in the comments, the very first cycle will start at a random point. This is because the first time you call millis() in loop(), it won't start at 0 (the device will already have been running for a short time before loop() gets called). It's easy to resolve though, if necessary.
You would do it by offsetting the totalTime value by the whatever value you got on the very first time around loop(). For example:
unsigned long g_startTime = 0;

void loop()
{
  unsigned long totalTime = 0;

  if (g_startTime == 0) {
    // This is the first cycle.
    // Store the start time so we can compensate later.
    g_startTime = millis();

  } else {
    // This is not the first cycle.
    // Compensate for the start time.
    totalTime = millis() - g_startTime;
  }

  pattern5on5off(totalTime);
  // etc..
}

Thank you so much - makes perfect sense! Ive definitely been banging my head against a wall with the wrong approach... :)

The problem with the % approach is that the timing won't be correct the very first time, as it will be just random at first.

@jfpoilpret That's true. It's easy to fix though, so I've added it to my answer. :)

Another option would be, instead of running millis once in the loop and pass its value as a parameter to every led function, to have each function as a parameterless one, and run millis inside each one. That would allow each function to get a more precise value, which might or might not be important depending on how much time each function in the loop takes to run, and also the timing correctness requirements of the application.

Arduino is a fine choice for the task - easy to get started with. The key is to write non-blocking code. You could take a look at the BlinkWithoutDelay example.
I made a suggestion for your task:
// Timing suquences for the LED's in milliseconds
// First value is on time, second value is off time,
// third value on time and so on (up to 10 values)
// One row for each LED
unsigned int led_timing[][10] = {
  {5000, 5000},
  {100, 1000},
  {100, 100, 100, 1500, 100, 1500}
};

// The pins the LED's are connected to
byte led_pins[] = {11, 12, 13};

// Keep track of timing sequence
// Array size taken from led_pins
unsigned long last_change[sizeof(led_pins)/sizeof(led_pins[0])];
byte timing_i[sizeof(led_pins)/sizeof(led_pins[0])];

void setup()
{
  // Initialize LED's as output
  for (byte i = 0; i < sizeof(led_pins)/sizeof(led_pins[0]); i++)
  {
    pinMode(led_pins[i], OUTPUT);
    digitalWrite(led_pins[i], HIGH);
  }
}

void loop()
{
  // Current timestamp
  unsigned long now = millis();

  // Keep track of sequence for each LED
  for (byte i = 0; i < sizeof(led_pins)/sizeof(led_pins[0]); i++)
  {
    if (now - last_change[i] >= led_timing[i][timing_i[i]])
    {
      digitalWrite(led_pins[i], !digitalRead(led_pins[i]));
      timing_i[i]++;

      // Start over at the end of timing sequence
      timing_i[i] %= sizeof(led_timing[i])/sizeof(led_timing[i][0]);

      last_change[i] = now;
    }
  }
}

I know the post is old, but I checked the example with the array based approach and in my opinion:
sizeof(led_timing[i])/sizeof(led_timing[i][0])

will always yield the allocated size (number of elements) of the array - in this case 10. So the timing won't restart until you reached the "end" of the array, using undefined elements. For LED "0":
int led_timing[0][10]:
5000,5000, <undefined>, <undefined>, <undefined>, <undefined>, <undefined>, <undefined>, <undefined>, <undefined>

Greetings
 Tommy


text:
Problem uploading big program to arduino
I have an arduino duemilanove with ATmega328.
Been doing several experiments with multiple peripherals
I had no problem uploading at all
But when i try to upload a big program (27,074 bytes (of a 30,720 byte maximum))
it compiles fine, then says uploading...
After some time passes i get this error
avrdude: stk500_getsync(): not in sync: resp=0x00

The board and serial port connections are fine.
Any ideas?
PS: Then i tried to upload the blink example, but i get the same error for some reason
Everything worked fine before i uploaded my "big" program

The sync error is a common issue that doesn't have one simple solution (as shown here)
It means that the computer can't communicate with the processor, but it recognizes that it's there (out of sync). This is probably due to something (a peripheral, stray wire) interfering with the transmission from computer to device.
Solutions that have worked in the past:

Unplugging the Arduino for 30 seconds, then plugging it back in.
Removing any wires connected to Rx and Tx pins during upload.
Soldering components connected to Rx or Tx to the board (in this case, I was using a shield that allowed me to do this)

There are lots of solutions available from different sources on the internet, but I have not come across one that names program size as the reason.

Removing any wires connected to Rx and Tx pins during upload. This was the issue after all. Thanks!


text:
How do I install the firmware on an Arduino Mega clone?
I have a brand new board which is a clone of the Mega2560.  I need to install the USB firmware on the 16U2 and the bootloader on the 2650 chip.  I have Atmel Studio and a JTAGICE-3. Using those, I can download HEX files compiled with the Arduino  IDE, and they run successfully.
But I'm having trouble finding Mega-specific instructions for getting the firmware installed so that I can use the Arduino ISP protocol for downloading new sketches. I can find much more information about the Uno than the Mega. And much of the information I do find seems to be dated.
1) Which are the right files to download?
   I've tried to install the 'MEGA-dfu_and_usbserial_combined.hex' to the 16U2 and the 'stk500boot_v2_mega2560.hex' to the 2560.
But the IDE won't connect via AVR ISP, and I get no serial communications from a serial sample sketch downloaded with the ICE.
2) What are the correct Fuse settings after I flash those files?
3) Is there a good way to confirm that the 16U2  USB converter is working correctly in isolation from the 2560 chip?

Let focus on one thing at a time, that is flashing the 16u2. You can see if you've successfully done that when you can see the Arduino in your device-manager.
First of, MEGA-dfu_and_usbserial_combined.hex is, as stated on the github page, for the 8u2, not the 16u2. Since you already have a ISP programmer you don't need the dfu functionality.  You can just flash the precompiled Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex file.
The fuses can also be found in the readme.txt on github: -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:m. I don't see any difference in the fuses between the 8u2 and 16u2, so they should work for the 16u2 too.
Hope this helps.

Thank you. Is there any reason not to include the DFU?

dfu is needed if you want to reprogram the 16u2 over usb. First you'll probably never have to update it. Second you already have a JTAG programmer, so you can use that one. Thirdly, to get the dfu version for the 16u2 you'll have to compile it yourself, as it isn't present precompiled in the github repository. (And it needs LUFA to compile). So in short, it's just not worth the trouble.


text:
Using Bluetooth Dongle on Arduino
I need to communicate my arduino by bluetooth but I'm living in a small town recently so I can't buy a bluetooth shield for my arduino.
Here is my question: Can I use a usb bluetooth dongle on my Arduino without a shield?
PS: There is no need to re-use that bluetooth dongle with usb again.

You'll most likely need a USB host shield (like this) for the Arduino to be able to communicate with the dongle, so that doesn't help. You may (this is a long shot) be able to crack open the dongle, look up some datasheets, and possibly find a serial interface inside that you could connect to Arduino... but like I said, it's a long shot.

Unless your Arduino is based on a AT90USBXX7, no. Bluetooth dongles are highly integrated and have no accessible interfaces other than USB.


text:
No valid serial ports for Arduino UNO on Mac
UPDATE: The issue turned out to be with my work laptop. Our IT department has them configured in such a way that the assignment of serial ports is different somehow. When I plugged in on my personal Macbook Pro it all worked perfectly.

I just got my first Arduino. Its an UNO R3. I'm running OS X 10.8.5 (Mountain Lion) and the Arduino IDE 1.0.5
Under Tools>Board I have Arduino Uno selected
Under Tools>Serial Port my options are:

/dev/tty.Bluetooth-Serial-1
/dev/cu.Bluetooth-Serial-1
/dev/tty.Bluetooth-Serial-2
/dev/cu.Bluetooth-Serial-2
/dev/tty.Bluetooth-Modem
/dev/cu.Bluetooth-Modem
/dev/tty.Bluetooth-PDA-Sync
/dev/cu.Bluetooth-PDA-Sync

I've tried all of them, but when I try to upload a sketch it fails. Most give the following error:
avrdude: stk500_recv(): programmer is not responding

The two "modem" options return this message:
Serial port '/dev/tty.Bluetooth-Modem' already in use. Try quitting any programs that may be using it.

I'm at a loss. None of these serial ports seems correct but there aren't any other options.
Also under Tools>Programmer which option should I be using?

The issue turned out to be with my work laptop. Our IT department has them configured in such a way that the assignment of serial ports is different somehow. When I plugged in on my personal Macbook Pro it all worked perfectly.

Have you hooked up your Arduino prior to pulling down the tools>Serial Port menu? I only see the port for my Arduino listed when it's actually connected and running. (And it's never one of the bluetooth ports.) I don't have my Arduino with me at the moment so I can't tell you exactly what it is.
Also note that on my MBP (running 10.9.4) I have to be sure to plug the USB cable into the CORRECT USB port. The other port maps to a different port in the list of serial ports.


text:
Is it possible to program a few Arduinos at the same time?
I have 10 Arduino Pro Minis and one Arduino Uno. Via breadboard, if I connect Pro Minis in parallel, can I program all of them at same time?
Is it possible?

Take a look in this link: http://electronics.stackexchange.com/questions/82466/programming-several-avr-mcus-simultaneously-with-parallel

What problem are you trying to solve?

@IgnacioVazquez-Abrams I've 60 Arduino Pro Minis and all of them need to be programmed same. I just wanted to do this 10 by 10.

https://www.sparkfun.com/products/11591

Arduino Pro Mini is programmed through serial, using a bootloader. It uses STK500 protocol, which is described by Atmel.
In theory, it can be possible to program multiple boards if only one TX Arduino pin is connected to USB-Serial converter, and all RX are in parralel, but this is an unreliable method. Only the board with TX pin connected can send its status back to programmer.
Arduino Mini also requires a physical reset before uploading. Make sure that all Reset pins are connected together when reset button is pressed.

Thank you, may ask, is it worth to risk? What can be go wrong?

Noting that the avrdude using STK500 protocol expects responses, which is initially accommodated above by "only one TX pin connected" However, this will be very very problematic, as the "only TX" will likely respond (even occasionally or just once) before the other slaves are not ready and such slaves will fall out of sync. I have done just this on a different product(not AVR) and we had to add long delays on the Master (avrdude in this case) to after it got the response to ensure all the slaves had a chance to catch-up. Likely will not be able to do the same here.

In this case I would recommend considering using multiple USB-to-Serial Ports and simply replacing the ".\arduino-1.5.6-r2\hardware\tools\avr\bin\avrdude.exe" with a batch file that then called 10 (or any number of Serial Ports) of your choice.

I would recommend reading my answer from Programming Arduino's from a centralized location.
Where that solution may be a bit more complicated, then needed. But the same pieces would allow you to create a custom programmer that can specifically call the custom avrdude. Allowing the original methods to still exist.

Additionally worth noting. Is that you can turn on verbose for the compiling and uploading from the IDE's preferences. This will display the temporary directory that contains the exact location of the bin file and command executed to upload. Which can then be easily re-executed your convenience. Noting the temporary directory is not immediately destroyed. Where you can also change the arguments to execute different ports and sending it to the background. To call others. So that you can simultaneously upload many devices.


text:
Can I use notepad++ for writing sketches?
Before I install the Arduino IDE, I was just wondering whether I could just use notepad++ to write the files and move them into correct location. I assume notepad++ doesn't support Arduino code, but I suspect there will be a mod for it, even though sketches are a low-end version of C++, which is supported.

You can easily use notepad++ or any text editor to edit arduino code files (.pde or .ino). I use the sublime text editor for all my arduino coding.
As you noted, the arduino syntax is c++, so setting the syntax highlighting mode to c++ is all that you need to do; no mod should be necessary.
Arduino includes a "Use external editor" option in the preferences menu that will make it reload the file every time you compile or upload. It also disables editing in the editor window. In this mode, just save your file in any editor, change to the arduino window, and hit upload.
Since 1.5, arduino has had command line support. most editors allow making the "build" button execute arbitrary commands in the current directory. by setting build to run "arduino --verify" or "arduino --upload" you can code in any editor you want even without having an arduino window open.

You can use any editor to write Arduino code. @BrettM has already detailed it.
Instead of the external editor option, you can do away with the Arduino IDE completely using Makefile and build and upload your code yourself.

Arduino IDE sucks. Ok, I admit it’s nice for beginners and for the
  click-and-forget kind of programmers, but it needs the full Java stack
  and hides to the user the fundamental steps involved in compiling and
  uploading programs to the arduino board.
I (like many other software developers) prefer to understand what I’m
  doing and running a Makefile from the command line is the way to see
  the individual steps and choose which to run and when. Finally, I’m
  not going to drop my favourite editor just to write arduino programs.

Here's how to do it.

The Arduino files are just text files with the *.ino extension, so it is OK to edit them with a text editor.
The Arduino IDE is needed to compile them (easily) however. To make an Arduino project without the IDE, create a directory e.g. MyProject, and create a file inside it called MyProject.ino. They have to have the same name. Adding extra *.ino files inside the directory will result in extra tabs in the Arduino IDE for those files when you open MyProject.ino.

The Arduino IDE isn't needed to compile them. It's just calling the avr-g++ compiler then avrdude to upload. (Ok, so it does some pre-processing too, but it's probably worthwhile to just write valid c++ anyway)

@RubberDuck The Arduino build script adds all the headers in to the *.ino files. Personally I use netbeans with avr-g++ and a library of all the Arduino code. Works really well once it is setup.

Its fine,  you have to start asking questions somewhere right? You could use notepad++ to write your files and move them to a correct location, but it would be pointless, because you would need a mod to compile and upload it to your Arduino. I would recommend just using the native Arduino IDE, because it does all the work for you, all you have to do is write your code, upload it, and sit back and watch.


text:
What purpose does the yellow and green LEDs have on the Arduino?
I have wired up a small project with a shift register (see below), but depending on how I put the 74HC595 IC (8-bit shift register with 3-state output register), the green and yellow LEDs of the Arduino stop shining.
What are these LEDs for? Do they tell something about a possible damage of the IC/short circuit in the setup?

The green LED is marked with ON, and it indicates that the Arduino has power.
The yellow LED is marked L and is just connected to pin 13. So when you set pin 13 to HIGH the LED lights up. You can however still use pin 13 for other things.
When the green LED stops shining you most likely have a short somewhere. As the short will drain all power away, so the Arduino has no power left to light the LED(s).

Or if you draw too much power from the +5V, the thermal protection circuit on the voltage regulator will trip and the whole Arduino will shut down.

Also be warned that the L LED (the one activated by pin 13) may light up if pin 13 is high-impedance (set to input), and is not connected to anything.
On my Uno, a trivial sketch like this lights up the L LED:
void setup ()
  {
  }  // end of setup

void loop ()
  {
  }  // end of loop

This is because the LED is not driven directly by pin 13, but by an op-amp (U5B) which -- if the pin is configured as an input -- may pick up enough stray voltage to activate and light up the LED.
This can be confusing because you might look at your board and think "huh? I didn't command that LED to come on".

What, an op-amp on the L LED? Uh, you are right. They added it in Rev3. It was not there on the Uno Rev2.

I suspect that driving the LED directly was influencing the pin when it was being used for other things (like SPI). So inserting a high-impedance driver (the op-amp) minimized that. And you are right, it was a moderately new addition, but I didn't have the energy to find exactly which board had it, so I left that unsaid. ;)

This is a new "feature" in Uno R3 boards.

Also note that there is the TX and RX pins on Uno (orange/yellowish) are for the USB connection. When the LED labeled TX is lit up, the Arduino is transmitting data to the computer. When the RX is lit up, it is receiving data from the computer.

Just wanted to re-iterate that On the MEGA 2560 Revision 3 you can't change the L led pin 13 due to the op-amp like Nick Reported.
Spent a couple hours on this scratching my head only to find this out


text:
Whats the difference between RF options (wifi, xbee, NRF24L01)
When doing RF, you have many options.
Three of the most basic are in the title box

WiFi
Xbee
NRF24L01

What are the practical differences in using them. What is the purpose of each other and the pros and cons. What would you use depending on the application you had?
I do not have a project in mind, but i want to start learning about Rf. I searched ebay for wireless devices. but i couldnt understand the differences. My goal is simply learning

did it (nRF24L01 / RFM12B / RFM22B(SI4432)) work behind the walls because I want to use it inside the water tank

There are many different type of RF networks with various advantages and disadvantages. The main things I consider when choosing a wireless communication method are network topology, data rate and power consumption.
WiFi:
High data rate (54Mbit/s +) but also high power consumption. Used when you need to connect directly to the internet, such as an internet-of-things device, and have an external power source.
XBee:
Low data rate (250kbit/s) and low power consumption. Used to make mesh-type sensor networks; each XBee device can communication with each other, and through each other via the mesh to devices that are out of range. Used for networks of devices, particular home automation and sensors. link.
Bluetooth:
Medium data rate and medium power consumption. IEEE standard has different device profiles to enable interoperability between devices. 'Pairing' type network however, so not useful for sensor networks, but good for controlling devices using a laptop or phone which usually have Bluetooth on board. Communicates with Arduino via serial RX and TX pins. link.
Bluetooth Low Energy, ANT, etc:
Very low data rate and very low power. These RF chips can run for years on an AA battery and so are used for things like heart rate sensors. The data rate is quite low so only good for transferring a small amount of data such as sensor readings. Most devices are setup as peripherals and can only connect to one 'central' device, so no good for sensor networks. Bluetooth low energy is supported by the latest mobile phones and laptops however. Useful to enable control of a device using a phone or laptop, for example a LED lamp. (See redbearlab for some Arduino options)
GSM
Phone connection. TODO
nRF24L01 / RFM12B / RFM22B(SI4432)
Popular proprietary transceivers. They can connect via SPI and have a lot of fancy features like low power modes, multiple channels, channel hopping, frequency calibration, CRC, retransmit and so on. The nRF24L01 from Nordic Semiconductor link operates in the 2.4GHz band, others use the ISM band 433/470/868/915Mhz.
These are todays state of the art highly integrated and low cost hardware for  reliable telemetry and consumer applications. The range is between 10m and 150m. The SI4432/RFM22B has the range of about 1.5Km.
Other RF modules
Simple and cheap serial devices. Single transmitter/receiver or transceiver that operate in the ISM band link. Often used as garage door opener. Useful for sensor network where interoperability with other devices is not required and you can implement your own protocol. link

I admit the Q is broad. It would perhaps be more nice to introduce also the protocols of the devices because many devices use just a simple serial line, others communicate via I2C or SPI etc. They are mostly transceivers. Bluetooth communicates via AT commands. The NRF24L01 is a very special low power device, which has more than hundred of channels, etc. but is a unique proprietary protocol. Bluetooth is a wireless communication standard, ... and so on. For a user, on the other hand, is perhaps more interesting how easy or hard is the hardware setup and programming of the device.

@bersch Yes, there is so much to put in. Feel like editing the answer with more info? :) This could become a community wiki. What would be the info? Data rate, power consumption, network topology, IEEE standard, interface, protocol, channels, difficulty? BTW do you know any commercial products that use nFR24L01?