text:
Arduino controlled remote for an rc car. What am I doing wrong?
I have an Osepp Mega 2560 (Arduino Compatible) which I'm trying to use to run a RC Car from the remote control.

Can someone please explain how do I need to connect the pins from Osepp to the remote board.
The setup (please look at image for bolded details):
 - Osepp 5v Power pin going to the Positive (see red wire)
 - Osepp GND pin going to the Negative (Black wire)
 - Osepp Pin 13 (pwm) going to the signal to drive forward (bottom of the board).
The Code
int led = 13;

void setup() {
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
}

void loop() {

  digitalWrite(led, LOW);
  delay(10000);
  digitalWrite(led, HIGH);
  delay(10000);
}

The Problem
I expect that after 10 seconds the remote will start sending a signal to move forward.
In actuality the signal gets sent right away, even though the pin is set to LOW.
The "signal to drive forward" spot where I soldered a wire from pin 13 is where power gets sent once you press down the joystick (also highlighted in the pic) and complete the circuit.

FYI
I am not trying to do any modulation, pin 13 may have been a poor choice.
I do not have any kits nor manuals, just winging it
The joystick for the forward action is actually suppose to be top left(missing in this case but you can see the circuit) and not the one highlighted in the picture

So you have it wired, but you want to know how to create a PWM signal?

Yeah, this is a confusing question... please provide more detail about what your pin is connected to, include the code you think is driving that pin, why you think it should be PWM, and why you think it's not. If you're connected directly to a motor, PWM might act as a simple DC speed controller, but you're gonna need some code to do that, and the concept of ON and OFF and HIGH and LOW no longer apply. Makes me think you're using the wrong code.

Also, if you're working with a specific kit, please provide a link to that kit, and page numbers or something to indicate the step you're having trouble with, from the manual of said kit.

Thanks guys, I am writing up more details. Remember to look at the picture. On the step i mentioned "Osepp Pin 13 (pwm) going to the signal to drive forward"  In the picture you'll find the "signal to drive forward" mark on the circuit board where I'm connecting to

Why does it look like the top-left (button removed) pad is connected to the "move forward" pin. And from that, it looks like it gets pulled to ground when the button is pressed.

You're right, that is the pad for move forward. Any thoughts on how to connect it to the Arduino?

Totally the wrong code. Why did you think the "Blink" code would run an RC car? That code is for blinking an LED - that's what it does. It doesn't do something else. The "Blink" program does not send a PWM signal down the line. If your device expects a PWM signal, this code won't do anything reasonable.

OH also... this is more of a "project" than a "question" and it may be more appropriate to use the Arduino forum. http://forum.arduino.cc/

My logic here was:
The joystick completes that portion of the circuit when pressed so I measured how much power goes through the circuit into the microcontroller pin when the joystick is pressed. Pin 13 delivers roughly the same voltage when set to HIGH so I assumed that by 'enabling' the pin (setting OUTPUT = HIGH) you would deliver that much power. One would expect that. However, to my surprise, the power is always there regardless of the state of pin 13 (HIGH or LOW) so my question is why? and how can I control that?

Eh... well, you're getting confused pretty badly here. Power, voltage, and current don't really work that way. If you send too much current through your Arduino pin, it's gonna fry that pin and probably the ATmega chip too. We need to work this out on the forum, this isn't something we can give you a quick answer for. You need an intro to microcontroller electronics first. Have you done all the little projects in the starter kit? You really need to do those... I've been doing this stuff for 30 years and I loved this kit - https://www.youtube.com/watch?v=pf4qosqpv3A

If you go to the Arduino Forum, I will help you, along with the rest of the community. I've done videos to help people with things on there - that's how much we care.

ok I will check out the kit and then come back to update the question and perhaps move it to the forum if it's still unclear. Thanks

Added to the Arduino forum http://forum.arduino.cc/index.php?topic=241237.0      Thanks

As this has now been asked and discussed on the Arduino forum, and the original question is not very clear, I am going to close this question. I'm going to close this question. Thanks for your understanding and cooperation!


text:
8-segmet LED's on Adafruit Trinket
I would like to have an array of eight 7- and 8-segment LED numerical displays on my Adafruit Trinket.
I know that there are some prebuilt arrays of 4 LED's. So 2 in array would do just fine.
However, my Adafruit Trinket doesn't have enough ports for that. I have heard something about connecting it to a small piece of controlling hardware that makes me able to have way less ports in need.
What is the appropriate way of connecting a lot of those LED's on only a few ports on a micro controller?
My ideal output would be as follow:
88 88:88:88 or maybe 88 88.88.88
So ideally there would be a small space between the first group of 2 digits and the rest.
Basically, the last 6 digits will represent a time in minutes, seconds and hundreds of seconds.

Do you have to use LED's?  An LCD with a serial interface would be a better match for that board.  You can solve the problem with an I/O expander, but consider simply switching to something built with a full size ATmega328p chip, like one of the mini or micro boards - which would get you both sufficient I/Os and more program resources.

The screen should be visible while the sun is blasting on it. That is why I opted for those. Is there even a better solution for outdoor displays?

Bright sunlight readability is a tough enough requirement that you should pick your specific display first, and then pick a board to drive it.

Do you have a suggestion for a display? I don't have enough knowledge (in fact very little) to be able to pick the correct one.

For LED displays, I advise using a MAX7219.
This circuit:

can manage up to 8 digits (7-segments + 1 LED for DP or colon separator) or up to 64 LEDs
needs only 3 pins to manage display
can be daisy-chained if you need to interface with more than 64 LEDs
requires only 1 resistor to be fully functional
is easily supported on Arduino with this library

I have used it in several circuits and happy with it.
Note that there also other libraries that support this circuit but I haven't used them.
This circuit has only one downside: its price (about $10 each); but the price is counter-balanced by its simplicity and the fact you don't need any additional component (e.g. transistors) besides a simple resistor.

Wow thanks for this answer! I will look into it this weekend. Looks perfect for what I need!

source: Stack Exchange

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

sort: votes


text:
Timer1 stops firing
I am trying to use interrupts to play notes on a speaker.  Timer2 works fine, but after about 15 seconds, Timer1 stops firing for about 5 seconds, and then it comes back on.  If I keep running the sketch, it will stop and resume every now and then.
Here is my code:
#define SPEAKER1 8
#define SPEAKER2 7
volatile bool swap1;
volatile bool swap2;

ISR(TIMER1_COMPA_vect)
{
    digitalWrite(SPEAKER1, swap1);
    swap1 = !swap1;
}

ISR(TIMER2_COMPA_vect)
{
    digitalWrite(SPEAKER2, swap2);
    swap2 = !swap2;
}

void playNote1(unsigned note) { //Play a note on Timer1.
    uint8_t oldSREG = SREG;
    cli();
    bitSet(TCCR1B, CS10);
    bitSet(TCCR1B, CS12);
    unsigned ticks = (16000000 / 1024) / (note);
    ticks /= 2;
    OCR1A = (ticks <= 65535 ? ticks : 65535);
    SREG = oldSREG;
}

void playNote2(unsigned note) { //Play a note on Timer2.
    uint8_t oldSREG = SREG;
    cli();
    bitSet(TCCR2B, CS20);
    bitSet(TCCR2B, CS21);
    bitSet(TCCR2B, CS22);
    unsigned ticks = (16000000 / 1024) / (note);
    ticks /= 2;
    OCR2A = (ticks <= 255 ? ticks : 255);
    SREG = oldSREG;
}

void stopNote1() {  //Stop playing a note on Timer1.
    uint8_t oldSREG = SREG;
    cli();
    bitClear(TCCR1B, CS10);
    bitClear(TCCR1B, CS12);
    SREG = oldSREG;
}

void stopNote2() {  //Stop playing a note on Timer2.
    uint8_t oldSREG = SREG;
    cli();
    bitClear(TCCR2B, CS20);
    bitClear(TCCR2B, CS21);
    bitClear(TCCR2B, CS22);
    SREG = oldSREG;
}

void setup() {
    pinMode(SPEAKER1, OUTPUT);
    pinMode(SPEAKER2, OUTPUT);
    pinMode(13, OUTPUT);
    // initialize timers
    cli();          // disable global interrupts
    TCCR1A = 0;     // set entire TCCR1A register to 0
    TCCR1B = 0;     // same for TCCR1B
    // turn on CTC mode:
    bitSet(TCCR1B, WGM12);
    bitSet(TIMSK1, OCIE1A);

    TCCR2A = 0;     // set entire TCCR2A register to 0
    TCCR2B = 0;     // same for TCCR2B
    // turn on CTC mode:
    bitSet(TCCR2A, WGM21);
    bitSet(TIMSK2, OCIE2A);
    sei();          // enable global interrupts
}

void loop() {
    playNote1(523);
    delay(1000);
    stopNote1();
    delay(500);
    playNote1(131);
    delay(2000);
    stopNote1();
    delay(500);
}

Why are you using those ISRs instead of PWM?

I'm not sure why you think that answers what I asked...

You're twiddling pins manually instead of letting the hardware do it.

Fair enough. But the hardware timers can do square waves too. Try COMnx[1:0]=0b01, WGM1[3:0]=0b0100, and WGM2[2:0]=0b010.

They represent all the sequential bit places that should be accessed. The datasheet uses this convention quite a bit.

It means WGM22, WGM21, and WGM20.

The problem you have is that you never reset Timer1 counter (TCNT1) when you stop a note and then play another one.
Also, changing the clock divider selection to "no clock" by clearing bits CS10 and CS12 as you do is not the most effective way to stop the timer; in fact, rather than stopping it, you can let it run but just disable its interrupts.
I have modified your program and this worked correctly:
#define SPEAKER1 8
volatile bool swap1;

ISR(TIMER1_COMPA_vect)
{
    digitalWrite(SPEAKER1, swap1);
    swap1 = !swap1;
}

void playNote1(unsigned note) { //Play a note on Timer1.
    uint8_t oldSREG = SREG;
    cli();
    unsigned ticks = (16000000 / 1024) / (note);
    ticks /= 2;
    OCR1A = (ticks <= 65535 ? ticks : 65535);
    TCNT1 = 0;
    bitSet(TIMSK1, OCIE1A);
    SREG = oldSREG;
}

void stopNote1() {  //Stop playing a note on Timer1.
    uint8_t oldSREG = SREG;
    cli();
    bitClear(TIMSK1, OCIE1A);
    SREG = oldSREG;
}

void setup() {
    pinMode(SPEAKER1, OUTPUT);
    pinMode(13, OUTPUT);
    // initialize timers
    cli();          // disable global interrupts
    TCCR1A = 0;     // set entire TCCR1A register to 0
    TCCR1B = 0;     // same for TCCR1B
    TCCR1C = 0;     // same for TCCR1C
    // Set clock divider
    bitSet(TCCR1B, CS10);
    bitSet(TCCR1B, CS12);
    // turn on CTC mode:
    bitSet(TCCR1B, WGM12);
    bitClear(TIMSK1, OCIE1A);
    sei();          // enable global interrupts
}

void loop() {
    playNote1(523);
    delay(1000);
    stopNote1();
    delay(500);
    playNote1(131);
    delay(2000);
    stopNote1();
    delay(500);
}

Note that I have removed all code for Timer2 as it does not play any role in the initial problem.
The important changes are:

setup() now performs Timer1 setup completely (CTC mode, clock divider); note that I also included TCCR1C to ensure full setup (it is preferrable as Arduino libraries may have initialized it differently before setup() is called); it also ensures Timer1 interrupts are initially disabled.
playNote1 now clears TCNT1 and then enable Timer1 interrupt for TIMER1_COMPA_vect
stopNote1() just disables Timer1 interrupt for TIMER1_COMPA_vect

To be complete, you would also want to limit useless consumption on output pin 8, thus stopping a note should also force its output level to LOW (or HIGH depending on your actual circuit behind, but LOW is more likely):
void stopNote1() {  //Stop playing a note on Timer1.
    uint8_t oldSREG = SREG;
    cli();
    bitClear(TIMSK1, OCIE1A);
    swap1 = false;
    SREG = oldSREG;
    digitalWrite(SPEAKER1, LOW);
}

Now what about your code for Timer2, the code is the same, so why does it work?
Actually it doesn't :-)
But you can't hear the difference between Timer2 is an 8-bit counter so if you don't reset it, then it won't take long until it reaches 255 and resets to 0, so only the first wave phase will be wrong but your hear won't notice that...
So you should also modify the code for Timer2 to make it correct.

Wow!  I never would have guessed that!

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


text:
Servo Keeps Trying to Turn
I currently have a servo wired to my Arduino and have imported the Servo.h.  Here is my sketch:
#include <Servo.h>

Servo s1;
Servo s2;

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

  s1.attach(8);
  s2.attach(9);
}
int pos = 0;
void loop()
{
  pos = 0;
  if(s1.read() != pos)
    s1.write(pos);
  if(s2.read() != pos)
    s2.write(pos);

  delay(1000);
}

The problem is that even when my servos are at the position 0 it still tries to turn and I hear it trying.  What do I have to do to tell it to stop turning once it is already at the desired position?
So this is my second bit of code:
s1.write(0);
  delay(5000);
  s1.write(100);
  delay(5000);
  s1.write(180);
  delay(5000);

When I write them to 100/180 (or any number) they are silent after the turn, but when I write them to 0 I hear them keep trying to turn...

Can you command your servo to different positions and have it go there?  Some cheap servos simply do not "settle" well. You can try making a little program to exercise them by cycling them between extremes at a moderate rate, you can even try taking them apart to clean.  But the ultimate solution - assuming your PWM signal itself is reasonable and stable - may be to buy better quality servos.

I can turn them just fine, they work well.
The real problem is that when I turn them to 100 they turn and stop, but when I turn them to 0 they dont...

I have edited my post with better info...

0 may not be within their mechanical range.  How about you start at 100, and decrement that by 10 every couple of seconds, doing a serial print of the set value - and then see what they can get to without growling.  Or better yet make a sketch where you can type a value on the serial and it will command that to the servo, letting you manually experiment.  You can also print out a protractor scale and put a pointer on them and see where they stop moving.

Cheap servo. If 0 wont work, make 1 your center.

This probably should not have been migrated - as far as we know, the issue isn't with the arduino, but with the servo.

Is this a continuous rotation? Can you link a model number? Does it get stuck and stop moving?

The reason they keep trying to turn is mechanical. The physical stop in the gears is hit before the encoder/potentiometer reaches its end point.
You can make the servo stop fidgeting by completely relaxing it if you want. just use
s1.detach();
s2.detach();

and your arduino will stop sending any signal.
Bear in mind that "reading" the value of a servo in arduino gives you the servo's current set point, not its current location. Your code in unfortunately unaware of a servo's actual location. With that in mind, setting your servo to go to 0, waiting for it to get there with a delay, and then detaching it will have the desired effect, but since it will not maintain position and you will need to reattach it to function again, using 1 or 2 as your far left endpoint is likely the better option.

A common reason is could be because your servo cannot operate at a PWM signal of 0ms.
For conservative limits, you should stay between 100ms and 2800ms even for very high quality servos.
With lower quality servos that do not specify maximum and minimum values, conservative limits are 700ms to 2400ms.


text:
Why is that any sensor signal need to be hooked up to the interrupt pins on Andruino boards?
I have come across some Andruino Sensors like Motion, Light and all recommend to be connected to pin 2 or 3 on Andruino Uno board which are interrupt pins. This is especially true if you are looking for HIGH or LOW values. Why is that to be connected to interrupt pins?
One example would be is I used CC3000 Wifi Breakout and Motion sensor. Both were in fight to occupy the interrupt pin 2. I have seen the Motion sesnor not working correctly after getting it's signal hooked to Pin 4[It has pull up resistor enabled]
What should I do if i need to hook up more sensor which uses the limited interrupt pins and how should i handle the above scenario?

The interrupt pins are used to notify the MCU that a device needs attention. The INTx pins are chosen first because they are easy to program for; each gets a dedicated interrupt vector and hence ISR.
There is another type of external interrupt though, the Pin Change interrupt. This can be invoked via any of the PCINTxx pins on the device; on the '328 any pin can act as an interrupt.
The main difference between INT and PCINT is that PCINTs are grouped into banks of 8, which means that once the ISR has been invoked the appropriate pins need to be checked for their level, which furthermore means that it is possible to misread an interrupt if a bank is shared by multiple devices and the interrupt pulse itself is very short.
Further details can be read in the "External Interrupts" and "Interrupts" sections of the MCU datasheet.

Ignacio provides a great answer on the differences between the two types of interrupts.  But to add to that, it isn't a universal requirement to even use an interrupt.
Polling is also a possibility, though it has been compared to periodically picking up the phone to see if anyone is trying to talk to you.

Advantages of using an interrupt can include faster response, background response while a program is primarily doing something else, and often an associated ability wake up the processor from low-power sleep mode used in battery powered gadgets.
But polling can have a role, for example when the program runs in a tight loop and can only take action in response to input at certain times anyway - an interrupt service routine that merely sets a flag to tell the main program loop that something has happened may or may not be much benefit.
Often the best solution is a hybrid approach - an interrupt service routine records events - especially ones which might vanish or be repeated before the main program loop can poll for them.  Then when the main program loop reaches a logical decision point, it checks the flags or event queue to see if the interrupt service routine has recorded anything to which it should respond.  Serial receive is typically handled this way in the Arduino framework.


text:
Animated LED Strip & Sensing an Object
Problem: Have an LED strip do some animation (say it takes 15 seconds for that line of code to run) meanwhile, have a sensor (tried methods: PIR sensor and ultrasonic sensor) watching to see if an object passes by.  If it senses an object, stop the light animation and make the lights do something else.
Issues: The PIR sensor takes too long to reset... I have the timing turned all the way to minimum and I am still able to count 12 seconds before it starts sensing motion again.  (Is there anyway to override this in the code?)  The other issue is the ultrasonic sensor, as far as I know, can't reliably run the first animation and watch for a change in distance then call an interrupt since an interrupt can only happen on FALLING, RISING, LOW, or CHANGE. This is an issue because the ultrasonic sensor is continuously sending LOW to HIGH then back to LOW for its pulses.
OVERALL QUESTION: How can I effectively sense if an object passes by a sensor, run new LED animation then back to where it left off without having to wait 12 seconds every time.  Is there some other hardware I could try? Please help!?

PIRs are controlled by their hardware.

Can you post your code please.

It seems as you are using the delay(); function for your code. The reason that it doesn't run anything is your Arduino does nothing during the function. The easiest option IMHO is using millis();. This will "return" a long datatype. Some example code (modified from example sketches in Arduino IDE):
/*
 created 2005
 by David A. Mellis
 modified 8 Feb 2010
 by Paul Stoffregen
 modified 5/16/14 by Anno. Penguin
 This example code is in the public domain.
*/

const int ledPin =  13;      // the number of the LED pin
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  //Sensor code
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

Obviously, your code will be more complex than that. This one only blinks it, but you'll have to do some creative logic here. I don't know what the animation is, but most likely you'll need to add a few more variables (make sure to declare them outside loop() so they aren't disposed of each iteration!).


text:
To connect a simple toy circuit and trigger with an arduino?
I have a small circuit from a toy sword that has an LED and a small speaker. It was powered by a couple of small coin cells.
I am trying to figure out how to connect it to my Arduino so I can trigger it.
If I attached the circuit directly to the GND and +3.3V and press the switch in it I get the sound of a sword and flashing LED as desired.
Now I want to somehow get the Arduino to trigger the circuit but am very new to Arduino and quite unsure of how to approach this.
Can anyone advise how best to work with an existing low power circuit that can use the Arduino's power rails but needs the switch integrated?
Sorry for the noob question.

You'll probably want to use a transistor to switch it on/off. You could just use the Arduino's digital pin but they can only supply a limited amount of current. Transistors can work with larger currents. The Arduino switches the transistor and it powers the external circuit.
There are a couple of existing questions that may help you.

How to switch an external circuit with Arduino?
How can higher current devices (motors, solenoids, lights, etc.) be controlled by an Arduino?

jippie's answer in the first link shows an example schematic for hooking up a transistor with a bunch of LEDs but you would replace them with your own circuit:

Thanks for this. I had been looking at this diagram earlier when trying to figure this out. In this diagram do you think I could just use the GND and +3.3V pins as the external circuits power supply?

It looks like the DC current for 3.3 pin is 50mA. If your circuit requires less than that, it should be okay.


text:
How to communicate arduino with Matlab
I have been working on a project which deals with analysing data from sensors to matlab. How do i establish this communication. Please help me

Presumably you need to find out how to do serial-port communication from matlab.  It's not clear that this is the best stack exchange site for that part of the problem, though the arduino part of message creation/parsing could best fit here.


text:
What is Serial.begin(9600)?
I know that this is to initialize something:
Serial.begin(9600);

But I want to know what it really means?

The documentation has a good description of it. http://arduino.cc/en/Serial/begin

Serial.begin(9600) doesn't actually print anything. For that you'd want to use Serial.print("Hello world!") to print the text "Hello world!" to the serial console. Rather it initializes the serial connection at 9600 bits per second.
Both sides of the serial connection (i.e. the Arduino and your computer) need to be set to use the same speed serial connection in order to get any sort of intelligible data. If there's a mismatch between what the two systems think the speed is then the data will be garbled.
9600 bits per second is the default for the Arduino, and is perfectly adequate for the majority of users, but you could change it to other speeds: Serial.begin(57600) would set the Arduino to transmit at 57600 bits per second. You'd need to set whatever software you're using on your computer (like the Arduino IDE's serial monitor) to the same speed in order to see the data being sent.

Baud and BPS are two different things... can't find the link I was looking for now.

what if I put "Serial.begin(0);" or "Serial.begin(4000);". I mean I want to know what is the difference between the numbers?

Serial.begin is used to set the speed of communication, in bits per second. One byte is equal to 8 bits, but serial connections send a start and stop bit to identify the start and end to a particular byte to the receiving system. Thus, 10 bits are needed to send one character.
Using Serial.begin(0) tells the Arduino that it should communicate with serial at 0 bits per second. As you might expect, this means that the Arduino will never send any data at all.
Serial.begin(4000) will cause the Arduino to send data at 4000 bits per second. This is non-standard, but otherwise fine.

In short: changing the number changes the speed. Making the number smaller (e.g. Serial.begin(300)) has the Arduino send data more slowly. Increasing it, say to 57600 will send data faster. Both the sending system and the receiving system need to agree on what speed to use: your computer's serial program, like the Arduino Serial Monitor window, will let you set the speed at which your computer will receive data but you can only select from the common speeds: 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600 and 11520 bit/sec. You can't enter other speeds, like 4000. 9600 is usually good.

Baud and BPS are two different things... can't find the link I was looking for now. - Here's one explanation: Appendix C: "baud" vs. "bps"

A picture is worth 1000 words, so they say, (1024 words if you work with computers) so I'll post some pictures ...
I set up my Uno to send "Fab" at 9600 baud and captured the results on a logic analyzer.

The parts shaded in red are the "idle" period between bytes.
From the above graphic note that the Tx (transmit) data line is normally high (1) until it drops low to indicate the start of a character (byte). This is the start bit. Then the 8 data bits (indicated by white dots) appear at the baud rate (9600 samples per second). After that the line is brought high again. This is the stop bit (the red part). Then we see the start bit for the next character, and so on. The "stop" portion can be indefinitely long, however it has to be at least one bit length.

More detail for the first character (the letter "F" or 0x46 or 0b01000110) can be seen here:

A - no data (Tx is high)
B - The "start bit". The line is taken low to tell the receiver that a character (byte) is commencing to be sent. The receiver waits for one and a half clock times before sampling the line.
C - First character arrives (the letter "F" or 0x46 or 0b01000110). There is no clock bit as such, the incoming data is simply sampled at the baud (transmission) rate. In contrast to SPI communication the data arrives least-significant bit first (in case you are not sending 8 bits per byte). Thus we see 01100010 (rather than 01000110).
D - The stop bit. This is always high, to ensure that we can distinguish between the end of this byte, and the start of the next one. Since the start bit is a zero, and the stop bit is a one, there is always a clear transition from one byte to the next.
E - The start bit for the next character.

You can see from the logic analyzer capture that T1 - T2 is 0.1041667 ms, and as it happens that is 1/9600:
1 / 9600 = 0.00010416666 seconds

Thus the rate of 9600 gives you the number of bits per second and the inverse is the time interval between bits.

Other considerations

Serial comms is not self-clocked (unlike SPI or I2C, and others) hence both sender and receiver have to agree on a clock rate.
The clock rate is not exact on the Arduino, because the hardware has to divide the system clock down to get a serial clock, and the division is not always exact. There is almost always an error, the amount is given in the datasheet (figures quoted for a 16 MHz system clock, such as on the Uno):

You can vary the number of data bits, you don't have to send 8 of them, in fact you can send 5 to 9 bits.
There can optionally be a parity bit sent after the data bits.

If you specify "odd" parity, the parity bit is set in such a way that the total number of 1-bits is odd.
If you specify "even" parity, the parity bit is set in such a way that the total number of 1-bits is even.
If you specify no parity, the parity bit is omitted.

This can help the receiver detect if the data arrived correctly or not.
The parity bit is sent before the stop bit.
In the case of 9 data bits (as used in the SeaTalk protocol) the parity bit is re-purposed as a 9th data bit. Therefore you can't have both 9 data bits and a parity bit.
You can also have two stop bits. This basically just lengthens the time between bytes. In the "olden days" this was so that slow electromechanical equipment could process the previous byte (eg. to print it).

Possible corruption
If you start listening to serial data in the middle of a stream, it is quite possible that a 0-bit in the middle of the stream will be interpreted as a start bit, and then the receiver will interpret everything after that incorrectly.
The only real way to recover from this is to have a large enough gap, from time to time, (eg. 10 bits long) that this cannot happen.

Inverted logic
The bits shown here (logic-level) are not inverted. That is, a 1-bit is HIGH and a 0-bit is LOW. If you have RS232 equipment that will probably be sending something like -12 V for a 1-bit, and +12 V for a 0-bit. This is inverted because a one is less than a zero, voltage-wise.
If you have such devices you need to do voltage conversion and logic inversion. Chips like the MAX232 will do both for you. They can also provide the -12 V needed to drive such equipment by generating it internally with the help of a few user-supplied capacitors.

Speed rule-of-thumb
Since, with one start bit, 8 data bits, and one stop bit we have a total of 10 bits, as a quick rule of thumb, you can calculate the number of bytes you can transmit in a second by dividing the bit rate by 10.
Eg. At 9600 BPS you can send 960 bytes per second.

Code to reproduce:
void setup()
  {
  Serial.begin(9600);
  Serial.print("Fab");
  }

void loop ()
  {
  }

;TLDR; It initializes the serial communication port and sets the baud rate. The device you're communicating with (or Arduino IDE Serial Monitor) have to be set to a matching baud rate. Once you've initialized the port you can begin sending or receiving characters. Arduino Serial Reference

Not to diminish or disrespect @Nick-Gammon's excellent coverage of this topic.

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


text:
How to make an electronic suction cup?
The uArm is a robot arm with a suction cup (or gripper). I'd like to try to make just the suction part of it, and I'm wondering what components I'd need?
By the looks of it, I'd need a hobby vacuum pump, but these seem few and far between on UK components sites.
How would I power it? It looks like they're all 12v, and I believe Arduino gives you 5v?
Exact what components would I need? Do I need any shields?
Here's a short video of the suction cup I'd like to copy:

What do you need to grip (i.e. how heavy)?

@AnnonomusPenguin Very light; one suction cup above and one below a thin plastic bag to pull it open (they're thin and tight together - this was the best way I could think of to open them).

You, of course, could open it with fire... :D If the plastic bag has a long area above the "zipper," you might be able to make some sort of hand contraption, which might work better.

@AnnonomusPenguin The bags don't have zips. Just one open edge and one sealed edge. They're not the easiest to open until you get the nack of it. Suction would definitely be better I think.

Before talking about the electronics parts you will need, you must know the characteristics of the pump you will use: voltage AND current.

@jfpoilpret The main components suppliers here are RS Components and Farnell. I'm looking for the cheapest pump they (or another UK supplier) offer which is compatible.

This kind of pump typically needs current between 500mA and 2A, depending on the model. The selection of a transistor will be based on the current you have to switch with the transistor. It's pretty straightforward to find out a trnasistor that matches current/voltage requirements.

You first need to determine the "strength" of the pump you'll need, based on the max weight of items you want to be able to grip. That will give you a list of pumps and associated motors, with the power they need. Power and Voltage will give you the current. Current and Voltage will tell you which transistor you may use.

@jfpoilpret The weight is negligible, just thin A4 sized bags.

may I know What are the components called in that video called? What are the approximate specifications for this parts ?

Just a note for those who wonder the same and are in need of a vacuum: In theory, you can use Venturi effect (or Bernoulli's Principle; it's basically the same) to create a vacuum. Or go buy an Aspirator pump. Since English is not my native language it's difficult for me to explain it in my own terms, but I'll try to give you a rough idea anyway. (Google it or feel free to answer with a better explanation).
First you need some flow of a fluid or gas (air from a compressor or water from a household outlet are fine). You pass that flow through left-to-right in a T-pipe (I'll call that the "flow pipe"). This will result in a weak vacuum in the orthogonal pipe (I'll call this the "vacuum pipe"), which you can connect to your suction cup.
The strength of the vacuum depends on the pressure in the "flow pipe". That means a higher velocity of your matter in the "flow pipe" is good (either a stronger compressor or smaller diameter of your flow pipe).
If I understand my physics book correctly, a higher density of the matter in your flow pipe will also produce a stronger vacuum. If you need a really strong vacuum, you could even use a water compressor, i.e. high pressure cleaner; but I suppose even a small air compressor will outperform a household water outlet (and you could toggle it from an Arduino with a relay board).
Since the air in the vacuum pipe expands more than many other materials, you could try to replace it with i.e. oil (be aware you'll pull out some of the air/replacement material at the intersection in aspirator!). This optimization is dangerous with a normal vacuum pump, since these usually break when sucking up fluids into their internals.
Also using an aspirator has the upside of not needing to buy a vacuum pump if you already own a compressor. On the other hand, that setup might be even louder (and possibly less efficient) than a dedicated vacuum pump.

There are two approaches I can think of that would work decently. Either a.) suck air out of a "cup," turning off the pump when done. OR b.) have a valve where the arm pushes one part of the bag against the table to squeeze all the air out of it, and shutting a valve attached to the "cup." Then, to release, the valve could be opened. For the suction cup, I'd personally try making it out of a suction cup hanger like this:

Source: http://www.amazon.com/Set-Large-Suction-Hanger-Hook/dp/B00439SCZO
The availability of these might vary by area, so I'm not sure how common these are in the UK. If you find one, make sure that it's pretty thick, with not that large of diameter so it's not too big to work with. I'd then remove the metal hook with pliers and drill a hole in the center. After that, you would need to superglue a tube through the center of the hole and seal it with some caulk.
Like I mentioned earlier, the two options are to a.) suck to grab and turn off pump to release or b.) have arm apply pressure to a flat surface and then shut a valve attached to the tube, creating negative pressure in the suction cup. Then, you could open the valve to balance the pressure and let the item go. I'd personally do the suction approach because, although it is louder and might use a little more electricity, it's a bit easier to build and execute and can grab in the air. I'm going to focus on that.
For the pump approach, build the suction cup (like I said above), attach the tube to one end of the motor with a hose clamp, leave the other hose terminal unconnected, and connect the pump (through a relay) to a 12V 1A+ power supply. You can do this by connecting the + pin of the pump to the "out" (or similar) pin of a relay breakout board, the "in" (or similar) of the relay to the power supply +, and the - of the pump to the power supply's - wire. This will make a circuit similar identical to a switch (the switch being the relay). To connect the relay to the Arduino you will have to connect the relay's logic signal to a pin on the Arduino and then you can just write HIGH or LOW to turn the pump on and off.
EDIT: Forgot to mention, you can use a transistor, too. Also, I illustrated the second method (hopefully it makes this clear).

So there's no way to have the pump on the same circuit without a relay? Your last paragraph is what's relevant to me. It's more the electronics I need help with. As for "squeeze all the air out", I'm not sure what you mean; there is no air whatsoever inside the bags. They're flat - only 1-2mm thick. Thanks for your answer, it's useful!

Actually you don't necessarily need a relay to command the pump, a transistor could be enough, depending on the current needed by the pump. The important thing is that you need a separate power supply (12V if this is what the pump needs) than Arduino 5V output.

@Danny You'll need a relay or transistor; the Arduino can only supply 4% of the current needed and 46% of the voltage needed. I haven't worked with transistors that much, so I can't advise you on that. As for the squeeze all the air out, I meant pushing the suction cup against a surface so the air in the suction cup flows out, through the tube. Then, when you would close the valve, it would try to expand, thus creating negative pressure between the bag and the cup. I'll try making a picture.

I am afraid the second method would require to exercise a high pressure first on the object to hold, that may need an engine even stronger than a pump! I think the vacuum-pump is more reliable here.

@jfpoil Yeah, it was a last minute kind of idea. If it works like I imagine it would, then it would need only slightly stronger arm motor.

You can control the 12v pump using any of the popular methods for controlling motors, Google "Arduino ULN2003" for many examples.

You can't power things like pumps and motors with the power supply from an Arduino. It doesn't provide nearly enough current. It's meant for providing regulated 5V for low powered logic circuits, and nothing else.
What you can do is use a transistor as a switch to turn on and off the power from a suitable external power supply.
If you find a vacuum pump that runs on 12V, get a 12V power supply with enough current to drive the pump, and then use a MOSFET transistor (example link) that will can handle enough current at 12V and can be controlled by a 5V signal to it's gate, and use that to switch the power on and off. Then you'd need a diode to protect the transistor against the reverse current you get from inductors like motors.

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


text:
Initialize a "Matrix" object in my own library?
So, I'm trying to make a custom library to drive a 8x8 Bi-Color LED Matrix from 2 MAX7219's that incorporates two "Matrix" objects from the "Matrix" library and I cannot, for the life of me, figure out how to initialize them in my class. Can someone help me? By the way, I have been programming for 8 years, and consequently have a decent knowledge of the topic! Here is my current code:
header file
#include "Arduino.h"
#include "Matrix.h"
#include "Sprite.h"

class ZackBiColorMatrix{

    public:

        ZackBiColorMatrix(byte dataR, byte loadR, byte clockR, byte dataG, byte loadG, byte clockG);

        Matrix r;
        Matrix g;

        void setLED(byte col, byte row, byte val, char color);
        void writeSprite(byte x, byte y, Sprite sp, char color);

    private:

        byte redData;
        byte redLoad;
        byte redClock;

        byte greenData;
        byte greenLoad;
        byte greenClock;

};

and the .cpp file:
#include "Arduino.h"
#include "Sprite.h"
#include "Matrix.h"
#include "ZackBiColorMatrix.h"

ZackBiColorMatrix::ZackBiColorMatrix (byte dataR, byte loadR, byte clockR, byte dataG, byte loadG, byte clockG) {

    redData = dataR;
    redLoad = loadR;
    redClock = clockR;

    greenData = dataG;
    greenLoad = loadG;
    greenClock = clockG;

    r = Matrix (redData, redClock, redLoad);
    g = Matrix (greenData, greenClock, greenLoad);

}

void ZackBiColorMatrix::setLED (byte col, byte row, byte val, char color) {

    if (color == 'g') {

        g.write (col, row, val);

    }
    else if (color == 'r') {

        r.write (col, row, val);

    }

}
void ZackBiColorMatrix::writeSprite (byte x, byte y, Sprite sp, char color) {

    if (color == 'g') {

        g.write (x, y, sp);

    }
    else if (color == 'r') {

        r.write (x, y, sp);

    }

}

Also, I use the Eclipse Arduino IDE if that matters.

What you have in your constructor is perfectly valid C++, and it will initialise the member variables.

This is a C++ question actually.
In C++, you initialize class members in the class constructor definition by using a "member intialization list" as follows for your example:
ZackBiColorMatrix::ZackBiColorMatrix (byte dataR, byte loadR, byte clockR, byte dataG, byte loadG, byte clockG)
:   r(dataR, clockR, loadR),
    g(dataG, clockG, loadG) {
    ... Additional initialization here
}

This is a special C++ construct (note the colon : after the constructor declaration but before its implementation).
Also note that, in your example, I think you don't need to declare redData, redLoad, redClock, greenData, greenLoad, greenClock, sicne they are not being used once your 2 Matrix fields have been initialized.
Hence you could simplify your class further, I think.

Hey @ZackElec, if the answer helped you, please consider accepting it. You can do it by clicking the checkmark on the left-hand side of the question, just below the up/down vote arrows and the question vote count. Once you get 15 reputation points, you can also upvote the question. Thanks!!


text:
Include statement not working
I am creating my own library for the Arduino and I have the following code:
#include <Arduino.h>
#include <Servo.h>

class ServoMotorController {
    public:
        ServoMotorController(int servoPin, int motorPin, int angle);
        void setAngle(int angle);
        void setSpeed(int speed);
    private:
        Servo servo;

        int servoPin;
        int servoAngle;
        int motorPin;
        int motorSpeed;
};

I am getting the error that Servo does not name a type; however if I do
#include <Servo.h>
#include <ServoMotorController.h>

in my actual Arduino code then I do not get the error. Why is the include statement not working in my C++ lib?

Where are the files located?  There is an important distinction between #include <File.h> and #include "File.h".

There is a folder called "libraries" in them there are (for our purposes) 2 folders "ServoMotorController" (which has my files) and "Servo" (which has the servo files)

Check out the include path that is configured for your pre-processor/compiler.  It is quite possible the folders aren't included.

Here is the thing.  When I do include "" it says the file deosn't exist.  But when I do include <> no such error occurs.  Ontop of that the file is actually called SoftwareServo.h but the arduino software just include Servo.h...

It seems this question is similar to http://arduino.stackexchange.com/questions/322/why-do-i-need-to-include-libraries-used-in-other-libraries I suggest you take a look at it, it may provide you with the answer you're looking for.

This is a symptom of the arduino IDE. libraries can't add other libraries to the include path, but the can use other libs if they have already been included. you can use an error directive so your compiler output is more informative at least
#ifndef Servo_h
    #error "ServoMotorController Lib requires Servo.h to be included first to function"
#else

Arduino 1.5.6 beta's new library format has a section for dependencies in the new library.properties file that should allow one library to add another to the include path, but I'm not entirely sure if the functionality is fully implemented yet (its beta after all).


text:
SoftwareSerial error
I have arduino , upon arduino I have Arduino GSM shield (Tx-2, Rx-3, Modem reset-7) and upon it, I have the Adafruit GPS Logger shield. I am trying to send sms of Latitude  from the GPS Logger shield to my numer through GSM shield. I am getting a error ..
SoftwareSerial/SoftwareSerial.cpp.o: In function `SoftwareSerial::SoftwareSerial(unsigned char, unsigned char, bool)':
/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/SoftwareSerial/SoftwareSerial.cpp:335: multiple definition of `__vector_3'

GSM/GSM3SoftSerial.cpp.o:/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/GSM/GSM3SoftSerial.cpp:148: first defined here
SoftwareSerial/SoftwareSerial.cpp.o: In function `SoftwareSerial::SoftwareSerial(unsigned char, unsigned char, bool)':
/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/SoftwareSerial/SoftwareSerial.cpp:335: multiple definition of `__vector_4'

GSM/GSM3SoftSerial.cpp.o:/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/GSM/GSM3SoftSerial.cpp:148: first defined here
SoftwareSerial/SoftwareSerial.cpp.o: In function `SoftwareSerial::SoftwareSerial(unsigned char, unsigned char, bool)':
/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/SoftwareSerial/SoftwareSerial.cpp:335: multiple definition of `__vector_5'

GSM/GSM3SoftSerial.cpp.o:/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/GSM/GSM3SoftSerial.cpp:148: first defined here

What is the meaning of this error ? what should I do to solve it?

This error means, that there is library overlapping on a vectors. To solve this error, you need to modify your Library file :
STEPS :

Remove the Softserial Library
Download AltSoftSerial library
if you have shield then you need to replace AltSoftSerial in place of SoftwareSerial in both .cpp as well as .h files.
Import AltSoftSerial library in place of SoftwareSerial in the sketch.

Execute .


text:
Why does the Arduino Due have a native and USB programming port?
According to the schematics, the Arduino Due has two USB inputs:

Native
Programming

Why is this? And when would I use the different ports?

Is there a mapping of the native port to serial pins? The programming port maps to 0 and 1 correct?

Either port can be used for programming, but the native USB port lets you do other things:

It also enables the Due to emulate a USB mouse or keyboard to an attached computer. To
  use these features, see the Mouse and Keyboard library reference pages.
The Native USB port can also act as a USB host for connected
  peripherals such as mice, keyboards, and smartphones. To use these
  features, see the USBHost reference pages. http://arduino.cc/en/Main/arduinoBoardDue

So you can use the Due to interface with USB devices or connect it to your computer and have it act like a USB device.

So, it would be possible to attach a mouse to USB native, and detect and Register mouse movements in the host laptop via the other USB input?

I think only the native one can do both of those things. The other one is for programming only.


text:
Error while connecting Arduino to Macbook: “serial port already in use. try quitting any programs that may be using it”
I'm trying to connect to my Arduino board through a macbook pro with mac os x 10.9.3 installed. I'm following the instructions from the arduino guide and in the connection section:

" Connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.
  If you're using the Arduino Uno or Arduino Mega 2560, a dialog box will appear telling you that a new network interface has been detected. Click "Network Preferences...", and when it opens, simply click "Apply". The Uno or Mega 2560 will show up as "Not Configured", but it's working properly. Quit System Preferences.

I cannot see any ports that hold the USBModem port.
How to setup the connection in the right way?
I read some articles about making a lock folder and I followed them but they didn't work for me, I also tried following this article but the solution there didn't work as well.

Try this What's keeping me, is a program that tells you which process is using something

I've found the free terminal utility CoolTerm helpful in resolving "port already in use" problems. Mac Serial is a bit flakey. http://freeware.the-meiers.org/

Sorry about providing this as an answer, rather than comments; however, I do have some suggestions to troubleshoot the connection.
First, check the usb connections with lsusb
    lsusb |grep -i arduino

Similarly, you can try following the output of dmesg; though, I'm not sure about the version of dmesg your system's installation is running.  Newer version of dmesg have a "follow" option available. On my Fedora system it's:
    dmesg -wH

Check the output as you plug in the arduino for messages related to the device, such as the resulting location of the tty. As a desperate measure, you can also look in the /dev/ folder for the last modified device, and search your logs for those devices:
    ls -alrth /dev/

This is not a applicable answer, as the system in question is not running Linux.

Under what circumstances does this happen? I see this message whenever I try to download to the Arduino but I've left my terminal program connected to that port. The fix in that situation is to disconnect it (after a <face-palm> to remind myself, yet again....  :-)


text:
How can I automatically start a LAN connection?
I have a Samsung Galaxy Note 10.1 with JuiceSSH installed. I also have Debian Linux installed via chroot. I'll be ordering an Intel Galileo to use as a portable compilation server. I have an attachment for the Note 10.1 that serves as a USB and an ethernet adapter. I figure I could power the Note 10.1 with the USB port and connect to it via SSH through the ethernet port.
Unfortunately, this post notes that in order to connect the Galileo via ssh, the LAN connection must be started manually through Arduino Sketch.
I'd like to install Debian Linux on the Galileo, get rid of my chroot Debian on my tablet, and have that LAN connection started automatically when the Galileo boots so that I can just connect to it through JuiceSSH on my tablet. This is so I can do everything without depending on WiFi and compile "offline". How do I automatically start the LAN connection and avoid having to use Arduino Sketch?
Also, does anyone know if ArduinoDroid works on the Galileo?


text:
Is there a way to test whether the UART Tx buffer is empty without waiting?
Is there a way to test whether the UART Tx buffer is empty without waiting?
serial.flush() waits, so it won't help me.
I tried looking into serial.SerialEvent(), but the link was broken on the Arduino reference page.
Can anyone point me to a description of it?

If you need such fine control over the UART then you may need to drop to low-level manipulation of the registers.

No, there is no method to do this in the source of the serial driver in the main Arduino repository, but it shouldn't be too hard to add one, which checks either the software-maintained buffer or the hardware register of the UART itself, or both, according to your need.

If you use SoftwareSerial then definitely not. With HardwareSerial that could be possible but you'd have to change the source code yourself.

It doesn't look like that function is implemented. The source for HardwareSerial.{cpp,h} are in /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino under OS-X. (Someone better versed in Window than I may have to chime in here to point you to that source location.)
Taking HardwareSerial::available() as a model, create a new function, say, HardwareSerial::txremaining(), that does the same thing, but for the transmit buffer.
Left as an exercise for the student:Make a common function that returns the contents of an arbitrary ring-buffer and use it in both ::available() and ::txremaining().


text:
avrdude: stk500_getsync(): not in sync: resp=0x00
I have arduino pro mini 5V, 16M ATMega328 and CP2102 USB to TTL. I've wired them like this:

When I try to upload a sketch to the arduino board I'm getting the following error:
avrdude: stk500_getsync(): not in sync: resp=0x00

The board type and the serial port are correct. The sketch also compiles successfully and I've installed the CP2102 drivers. I've noticed that even if I unplug all wires from the arduino board(and just leave the cp2102 connected to the PC), I'm getting the same error again. I'm using Windows 7.
Anyone else encountered the same issue?

is your cp2102 shown in lsusb (linux and mac users) ? or in device manager (in case of windows)?

@nidhin Yes, it appears http://i.imgur.com/JHaDWbt.png

did you try what Nicolas said in his answer?

@nidhin
I tried to press the reset button at the same time as I clicked the upload button. Also I tried to wire the rst pin on the cp2102 to both rst pins on arduino, none worked.

possible duplicate of Some dude named avr won't let me upload my program, aka "avrdude: stk500_getsync(): not in sync: resp=0x00"

You should check that your baudrate matches the bootloader on the board (there is one, right? is that a genuine board or a clone?).  Also, disconnect the arduino and wire the CP2102's TXD and RXD pins together.  Open the arduino serial monitor and type characters; you should either see one copy of what you type with the pins jumpered and none with them open, or else two copies with the pins jumpered and only one with them open.

Deepsy,
I have exactly the same FTDI module and Arduino Mini Pro.
Like say Corvin, if you add DTR to GRN, it will work. It's used to reset the arduino to start the bootloader

I had the same error message come up when I had shorted the digital inputs. oops!

It's hard to tell from your pictures, but are all the header pins soldered to the boards? If not, they need to be: there's no chance that the proper electrical connections will be made reliably if they're just inserted loosely into the holes.

Good spot, I did not see that on the picture at first, but it seems you are right, it looks like pin headers have just been inserted into the holes without any soldering.

This error means that the program responsible for uploading (avrdude) can not communicate with your arduino.
Did you reset the board just before programming? The reset pin of the arduino seems unconnected in your picture; so the board wouldn't be executing the bootloader when the serial cables expects it to.
Try either to reset the board manually just before programming, or connect the rst pin.

I tried to press the reset button at the same time as I clicked the upload button. Also I tried to wire the rst pin on the cp2102 to both rst pins on arduino, none worked.

Not simultaneously -- you must first do the hardware reset, then try the upload.

Sometimes it works better with a capacitor in series with the reset pin. I'd start around 0.1µF and try a few different values (it depends on the value of the reset pullup)

@NicolasD Is there a way I can do it without capacitor? I think the arduino is not even connecting to the cp2102, but I don't know how to check. I also tried reseting the board(with the button on it) few seconds before uploading, still getting same error.

As @DaveTweed said, you can reset the board, say, half a second before clicking the "upload" button in arduino IDE. The capacitor is just for autmating this.

BTW, Did you use that arduino board already?

I know someone with a similar problem. But his problem is solved with a 1k resistor on both Tx and Rx in series and a 10uF capacitor which is required for arduino devices using the ATmega328 between the reset pin and ground. You could also try a PULLUP resistor on the reset. Which will mean a 10k resistor between the reset and +5V

I solved this problem by connecting DTR signal from USB-converter to the pin which says GRN on the board (the one aside TXD). It was not obvious to find, but seen on ebay some arduino-dedicated-usb-programmer which seemed to be connected this way - so I took the chance. I do not get this error anymore and uploading works every time!!!
Cheers!

As some of the other answers have said, you may not have soldered on the header pins. You can't just push them into place and hope for the best. See my Pro Mini:

My soldering is reasonably neat, however you can see the solder come through to the other side.
Also see:

Some dude named avr won't let me upload my program, aka “avrdude: stk500_getsync(): not in sync: resp=0x00”
Have I bricked my Arduino Uno? .

A lot of the issues in those threads apply to any Arduino.

To solve my sync issue I added a connection from USB serial adapter RST to ProMini DTR pin. I'm using Linux Mint 18 OS with Arduino IDE 1.8.5 -
My other Arduino clones (UNO_r3 and Nano) uses the CH340G chip so I knew I had working drivers. Sorry for the picture quality, my old camera and I don't know how to balance LED light bulbs. The pins from USB to ProMini are: (U)GND-(P)GND; (U)3V3-(P)no connection; (U)5V-(P)VCC; (U)TX-(P)TX; (U)RX-(P)RX; (U)RST-(P)DTR.  Hope this helps. 73 AB1OP_Ralph

This problem is caused by using the wrong USB cable. I have three cables, two of which work find, and one of which has this issue. The cables with the ferrite bead around them will work. The one cable that I have which works has a braided shield surrounding the conductors, and it is about 2 feet long. I have a 3 foot cable with no bead and no shield that exhibits this issue.

This is a possibility but it's a bit of a leap to assert that it is the cause.  Typically, as the USB interface is a lot more "delicate" than the serial downstream of it, in a bad cabling situation the USB serial device would fail to enumerate rather than enumerate and stay present but fail to proxy serial data.

I had the exact same problem. I tried installing the IDE on another laptop and uploaded the program from that laptop. Problem solved. Then I came back to my laptop, uninstalled the IDE and re-installed it. It works.
However, I wasn't satisfied because I can't find the source of the problem... so I tried running everything again the same exact way.. I found the problem but am not sure if that can be the actual cause of it.
In my project, I needed to carry out serial communication between Arduino and MATLAB (GUI). In order to see/verify the output(type) of MATLAB (GUI) serial data, I used HYPERTERMINAL and also VIRTUAL SERIAL PORT EMULATOR. I noticed that every time hyperterminal is running or VSPE is running while my serial monitor is on, it screws up the uploading feature of the program. I'm not sure if it's because of the VSPE or HYPERTERMINAL, but reinstalling the IDE worked for me. :-)

This has happpened to me as well. I had a bluetooth/TTL unit wired to RX/TX, which are the same ports used by the usb connection to the computer (where transfer of the program happens), and all I had to do was disconnect RX to the BT unit when transferring the program.

{linux}
The solution for me was to set the correct USB port.
I had been previously working with my Uno on USB0.
I could not upload to my nano as I had it connected on USB1
In menu: Serial Port -> /dev/ttyUSB1

Its logical to change a port when you change a board.

I spent hours looking for a solution to  the same error message. Everything was correct - Board chosen, COM port, everything.
I switched my TX and RX pins, and connected the tx and rx to each other, instead of them being switched (which I saw from a tutorial).
Then I pressed the manual reset, held it down, and uploaded, then released while it read Uploading. It worked.
Hope this helps.


text:
arduino EM408 GPS problem
I have written this little snippet of code to interface with EM408 GPS.
#include <SoftwareSerial.h>
SoftwareSerial GPS = SoftwareSerial(2,3);  //rx,tx
void setup()
{
  GPS.begin(4800);
  Serial.begin(9600);
}

void loop()
{
  //Serial.print(GPS.read(), BYTE);
  Serial.write(byte(GPS.read()));  //as of Arduino 1.0
}

Hardware side i have these connections:
ENABLE: 3.3V
Vcc   : 3.3V
Ground: Ground
Rx, Tx correctly connected to arduino and correctly initialized with SoftwareSerial
However, the values i get are just junk data
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

I get these without ending...
I experimenting with changing the baud rate, still the same thing goes on.
Any ideas?
EDIT:
I used to get random junk data before with the EM406 gps module, but i solved it by casting everything to BYTE. I have tried both approaches here, but the results are the same...

what about Serial.write((byte)(GPS.read()));?

just the same result....

related: http://electronics.stackexchange.com/questions/110699/gps-sensor-serial-monitor-output

The datasheet indicates that the communications port is "TTL Levels", which usually means that the data is inverted relative to normal RS-232 levels.  If you are connecting to a true RS-232 port on the Arduino, you will need to invert the signals to/from the GPS module.

What Arduino model do you use?

Duemilanove with 328

The problem you get is that read() does not wait for a byte to be available, it just returns -1 if there is no byte available; converted as an unsigned byte that becomes 255.
In ISO-8859-1, which I guess is the encoding that your serial monitor is using, 255 translates to ÿ, so this is exactly what you observe.
Fixing this problem is straightforward, just check that a byte is available on SoftwareSerial before reading it:
void loop()
{
    if (GPS.available()) {
        Serial.write(byte(GPS.read()));  //as of Arduino 1.0
    }
}

Thanks, but when i use this method, i receive nothing at all, with all baud rates combination and independent of time passed...

If you receive nothing, that may come from your wiring: voltage level, crossed connections, short-circuit...

Note that in your current code, you don't receive either, as I have explained, if ÿ is the only thing you get, it means your GPS stream never receives anything...


text:
Using Arduino Micro with MPU6050
I have an Arduino Micro and an MPU6050 gyro/accelerometer board; I want to read DMP data from the MPU6050, but the sketch requires the use of the interrupt pin, of which I have none of the interrupt pins available and they cannot be switched around.
I'm wondering how to go about reading the DMP data when needed. I've tried but always just receive the value 180 for any reading.
Thank you!

Do you have any current code that you are using? If so, edit the question to include this. Thanks!

I searched quite some time for everything regarding the MPU6050, but there is just rumors and jokes about the dmp funcionality. One project encorporates the hard reverse-engeneering some wise people did, which is: http://www.i2cdevlib.com/docs/html/class_m_p_u6050.html
This also uses the interrupt, which I suppose you can't really avoid. Why exaclty this would be necessary though, is not a thing I could tell you.. I assume, that the dmp works somehow with the fifo buffer and can only interact through it. The cited library has examples with and without dmp, which I can really recommend.
Using this thing for a quadcopter however I can just say, that the dmp is too slow to control such a fast system, so maybe first consider what you really need. From my experience it does some magic things, but acts strange is due to it's not documentary it is a pain to work with.
Hope this helps.

You can, in fact, avoid the use of an interrupt with the MPU6050/DMP combination.  See the ongoing thread at https://github.com/jrowberg/i2cdevlib/issues/479 and this post for example.  I've been running an MPU-6050 based system using polled (vs interrupt) driven configuration for months without any issues (other than a pesky motor noise issue I'm currently trying to resolve).
Regards,
Frank


text:
Send text according to an ultrasonic measurement, on battery
I have this big bucket where I would like to install an arduino on the top of the bucket where it would calculate the % of the bucket being filled up with water. Then, every day at night the arduino will send a text message (via SIM card) to the server where it would collect data for that bucket.
As far as a beginner point of view, I can understand that I will need:
an Arduino Board
PING))) Ultrasonic Distance Sensor
Battery pack that would allow to run the board for a year?
and the Arduino GSM Shield (integrated antenna) OR the GSM/GPRS Module M10?
My question is:
What arduino board do I need for my setup?
How long will 2 large or 4 AA batteries lasts for receiving a value from the ultrasonic sensor once a day and sending that value to a server? The point of the instrument is to be as small as possible.

You'd probably need more than 4x AAs, as that's only 6V. The regulator on the Uno needs at least 7 to function correctly, so say 6x AAs. My Uno uses about 25mA, so that battery pack would -- as a generous estimate -- last about 3 days. Unless you could put the GSM shield and sensor into a low-power state they would shorten that time. I agree with Tom below when he says to consider solar power and rechargeable batteries.

Related: http://arduino.stackexchange.com/q/501/37 and http://arduino.stackexchange.com/q/488/37

First of all: what is the intention of your setup? What are you trying to measure, what do you want to do with the data? Where is the bucket located, in your backyard or miles away in a forest?
I foresee some problems with your current setup.
First of all, you need a enclosure that keeps your 'duino and other components dry and at a comfortable temperature. I don't know how severe the weather conditions are, but stuff can get unreliable when used close to the min/max operating temperatures. Can you find an enclosure that can protect your electronics against the elements?
My advice: think of a good enclosure.
Second, do you really think PING))) is the best sensor? Have you already tested how it behaves around water? Are the measurements correct?
Another option would be an array of metal strips, one connected to +V or GND, the others to separate ports on your Arduino. Space them evenly from the bottom of your bucket to your maximum water level (drill a hole in the bucket to prevent overflowing or drowning your duino). Poll the pins at a predefined interval (not too short, keeping battery life in mind) to see which ones make contact with the water (allowing current to flow from/to the pins from/to +V/GND)
My advice: do some research on sensors, or try to make your own
The best way to communicate with your 'server' (what are you going to use?) totally depends on how far it is from the bucket. GSM shields are quite pricey, other alternatives may be preferable (and do not have additional phone costs).
Is your server on the other site of the window? Bluetooth? Somewhere in your backyard? Zigbee. Across the street? High-power Zigbee (if allowed by local authorities). Far away but with WIFI access? Zigbee, posting data to an online place. In the middle of nowhere but with great cell phone reception? GSM.
My advice: check out wireless communication possibilities. There's a ton of them, each with pros and cons.
Last hurdle, energy. Your battery setup will most definitely NOT be able to provide enough energy for a whole year. There's just too little juice in them.
Arduino and standalone AVRs often have a sleep mode, in which power consumption can be very very low. Google is your friend on this one. Still, that won't let your setup last a year.
Unless there was a gigantic glowing ball of plasma hanging around some 8 lightminutes from here and we could harness its incredible power with the use of photovoltaic elements... Wait, we totally can! Using (a) solar panel(s) and some simple circuitry you can recharge your batteries, and depending on the weather conditions this could keep your project up and running for a year.
My advice: get down and dirty with small solar panels.
I really appreciate your ambition. If done right, this could be quite the project for a beginner! Just make sure you thoroughly research every part of the system, on itself and as a whole. This could prevent a lot of disappointment and unnecessary costs, while only expanding your knowledge.
Good luck!


text:
Power small hobby motor using Vin pin on Arduino and 9V battery, safe?
I want to power a small motor with a 9V battery and control it with PWM using an Arduino Leonardo. I know I can power the motor separately, but this introduces the problem of needing a battery to power the motor (9V battery) and another power source to power the Arduino (another 9V battery?)
Would it be safe to simply power the Arduino with a 9V battery and use the Vin pin on the board (which is unregulated and outputs directly the power source powering the Arduino) to drive the motor? That way, I power everything from the 9V battery, and use a transistor to drive the motor.
Thanks a lot!
Steve.

That should work. But you may have a problem with the small capacity of 5V battery, compared to AA or even AAA 1.5V batteries. I don't think that will be enough to drive a motor.

I will probably use a couple of AA instead. I'll calculate which type of batteries would be optimal for my project.

If you use a transistor circuit as shown below, back EMF would not cause any trouble.

Great! That's exactly what I was going for, assuming the +9V on the diagram is coming from that Vin pin on the Arduino.

You need at least an additional diode, see "purpose of the diode and capacitor in this motor circuit".

Yes it is  OK to do that. But the thing you should consider in mind is "What is the current requirement of the motor?"
You say

I want to motor a small motor with a 9V battery and control it with PWM

This means you have a servo motor, which might require a lot of current depending on the torque. So if you have a battery with low 'mAh', your battery will dry out very quickly. This might or might not be a problem for you depending on your requirements.

Woops I meant "drve a motor". It's actually not a servo but just a simple motor harvested from an old cd changer. I am aware that a 9V battery might not provide a very good battery life, but that is not my priority for now. As long as it works and is reliable all is good for now.

in that case, it would work just fine.

You also need to ensure that the Arduino you use has a voltage regulator. Not all of them do.

The arduino has its on voltage regulator, so feeing 9v to the arduino is not a problem. But the arduino will not drive the motor directly. You need to use a transistor big enough  to  hundle the amperage of your motor (e.g.tip120). The diagram above is a good indication of how to connect it. Yet the diagram is missing a diode (1n4001 or 1n4004) from the GnD to Vcc, as to avoid back voltage from the motor, which may damage your arduino.


text:
Setting time frame in Arduino Uno
I have built the circuit below using mux ICs. In a particular interval the respective selector pins get selected and analog signal from hall sensors are read and give a particular analog value out. There is a total of 30 hall sensors which are represented by HS0 to HS31.

Now I wanted to set time as in the table below. After 8000ms I would like it to reset the time automatically and start reading. Can someone tell me which timer example would let me achieve this?
TIME IS ms  OUT1    OUT2    OUT3    OUT4
  0-1000    HS0     HS8     HS16    HS24
1000-2000   HS1     HS9     HS17    HS25
2000-3000   HS2     HS10    HS18    HS26
3000-4000   HS3     HS11    HS19    HS27
4000-5000   HS4     HS12    HS20    HS28
5000-6000   HS5     HS13    HS21    HS29
6000-7000   HS6     HS14    HS22    HS30
7000-8000   HS7     HS15    HS23    HS31

Could you tell us which multiplexer IC you are using? This way, we can help you better. Also, why do you need the 8 second cycle? Does it matter if it's a little shorter or longer? If timing does not have to be very precise it would make things a lot easier.
By the way: you say there are 30 sensors, but your table has 32...
The following pseudocode will not work on your Arduino, but you can use the same structure.
int sensorArray[32] // we will store our 32 sensor values here

// these pins control the multiplexer chips
int selectPinZero = 8;
int selectPinOne = 9;
int selectPinTwo = 10;

// these pins will receive the sensor values from the multiplexer chips
int inputPinOne = 0;
int inputPinTwo = 1;
int inputPinThree = 2;
int inputPintFour = 3;

void setup(){
    // make sure the correct pins are inputs and outputs
    pinMode(selectPinZero, OUTPUT);
    pinMode(selectPinOne, OUTPUT);
    pinMode(selectPinTwo, OUTPUT);

    pinMode(inputPinOne, INPUT);
    pinMode(inputPinTwo, INPUT);
    pinMode(inputPinThree, INPUT);
    pinMode(inputPinFour, INPUT);
}

// all done, now keep reading the sensors
void loop(){

    // set selectPins so that each Multiplexer will output its first channel
    digitalWrite(selectPinZero, HIGH); // or low, depending on your Multiplexer IC
    digitalWrite(selectPinOne, HIGH); // or low, depending on your Multiplexer IC
    digitalWrite(selectPinTwo, HIGH); // or low, depending on your Multiplexer IC

    // start reading sensors

    int i = 0;
    while(i<32){
        sensorArray[i] = analogRead(inputPinOne);
        i++; // variable i was 0, now 1

        sensorArray[i] = analogRead(inputPinTwo);
        i++; // variable i was 1, now 2

        sensorArray[i] = analogRead(inputPinThree);
        i++; // variable i was 2, now 3

        sensorArray[i] = analogRead(inputPinFour);
        i++; // variable i was 3, now 4

        /*
        use digitalWrite() on all the selectPins to make the Multiplexer IC output the next channel
        */

        delay(1000); // wait 1000 milliseconds
    }

    /*
    this will repeat until all 32 sensors are read and stored in the array
    */

}

This code is by no means optimized, but written to make it easy for you to understand. Good luck!


text:
Data packet format when USB initialized as COM port
Does anyone know how the data in data packet looks like when the USB is initialized as COM port?
I have a Arduino Mega 2560. I have initialized COM port with a baud rate of 9600. I know that there are four types of USB packets as

Token Packet (Commonly used for device identification and transaction initiation.)
Data Packet (Contains the data that needs to be transferred from host to client or vice-versa.)
Acknowledgement Packet (Acknowledgement for error-free data reception.)
Special Packets (Hub to hub communication and speed differential.)

The payload in data packet is formatted as
DATA1 >> PAYLOAD >> CRC16 ; DATA2 >> >> PAYLOAD >> CRC16 ; etc.
Till this point I am clear about whats happening.
Now all I want to know is

How the data is structured in the PAYLOAD section, when USB is initialized as COM port?
How the baud rate comes into picture i.e how a particular baudrate is achieved in this type of communication?
How is communication in terms of packet sequence? Does the sequence of packets change? (Like token>>data>>ack>>data>>ack>>...)

I really need to know this urgently as I am working on program that has to connect with 3 MEga2560 boards through a USB hub. I want to fix my design constraints depending on what is the maximum baud rate that I can achieve for all boards.

What you are looking for is a reference on the CDC/ACM scheme (or where applicable older vendor-unique schemes such as that of the ftdi chips).  You might find it interesting to either read the relevant linux kernel driver, some of the Android USB host code that is out there, or the firmware of the 8u2 chip.  However, normally an application would not pay any attention to this, and the let the operating system handle it.

The user-visible baud rate has no effect on the USB (which is probably 12MB/s), it is just a configuration parameter passed through for the 8u2-Mega2560 serial channel.  What you do have to watch out for on USB is latency - regardless of "serial" baud rate it can take longer than on a true serial link to a send byte or two and get a response, as the USB portion of the connection is limited to packets sent at fixed intervals no matter how small.

Once the USB connection is initialized as a COM port, it no longer utilizes traditional USB packets (only internally). It acts as a regular COM port. This layer of abstraction is created by 8u2 chip on Arduino side and by the driver on the PC side.
If you need to use the USB without the COM port abstraction, you have to probably configure the 8u2 chip to behave this way. I think it should be possible to configure to act as some HID device for example. You would also need to take care about the PC side and you might have to write your own driver.
For a guide on hacking and configuring the 8u2 chip on Mega, see following link:
http://arduino.cc/en/Hacking/DFUProgramming8U2

Can you suggest me any link where I can read more about this:- "it no longer utilizes traditional USB packets" . This would be really helpful.

The first sentence here is not very accurate.  There is no difference between initialization and operation - it is still a USB device on the wire, and a serial device to client programs downstream of the ttyACM driver (or whatever your operating system choses to call it).


text:
How to program an empty Mega2560 with an Arduino sketch?
I am writing code on Arduino mega. My current code is working fine. However, I'm not using all the pins.
My question is:

I have the hex file for my code and I can purchase a Mega2560 MCU. Is there any way to upload the hex file to it and how?
What are the circuits I would need to to build?
Eagle files of the Arduino mega are available here. Is this circuit more than enough?

The Arduino circuit is overkill for production use.

@IgnacioVazquez-Abrams I didnt understand what you are saying

Last time I checked, the chip on the Mega was SMD only; that's hard to solder, and would be difficult to load a bootloader on the chip soldered to some PCBs.

@AnnonomusPenguin - the Mega2560 chip is relatively low density for a surface mount device, and fairly easy to solder once one learns that it is done by using flux and surface tension to place the solder with a normal (1-3mm) tip, not by trying to touch single pins with a tiny iron.  Secure it with a thin piece of tape diagonally, solder ONLY one corner, check alignment, solder the opposite, check alignment, then wipe solder all around.  Any bridge that won't clear with flux will clean up with fine desolder braid.

@AMPS - I've rolled-back your recent edit on this question because it substantially changed the content (including going from a 2560 to a 328, which is a different chip entirely). Editing your question to clarify it is OK, but changing it entirely (especially after there is already an answer) is not OK.

@but i found that if i post question eqicalent of that all saying replicate question. So i am changing here  itself. Yes i accept fact IC are change.

If you buy an empty mega2560 IC. It won't contains any bootloader.
That means that you need an extra circuit, a programmer, to upload your HEX file into your MCU. "When to use the bootloader" questions link
But, if you buy your mega2560 from an Arduino provider, you should be able to order the MCU with the arduino booloader already programmed. Then a simple serial link from your PC to your MCU will suffice to program the MCU with your Arduino sketch using the Arduino environment. You could clone the serial part that you have on the Eagle files of the original Arduino to do this.
In summary:

Programming an empty chip requires a programmer
Programming a chip that has a booloader requires either a programmer, or a simple serial link.

You may also use another Arduino with the suited sketch as a programmer and use it for programming another empty MCU. There are examples of this on the web.

There is Device  avr pocket programmer if i use device and ISP . Is it possible to upload boot loader.

@AMPS yeah that should work.

@AMPS - if you already have an Arduino of some sort, you don't need to buy another board just for programming bootloaders.  Some of those little programmers are based on software USB with diodes to approximate the USB electrical spec.

@ChrisStratton How to dothis??

If you already have an arduino you don't need another ISP programmer but you'll be able to use your arduino with bootloader to burn a bootloader on a clean chip. Just follow the steps on this site. http://arduino.cc/en/Tutorial/ArduinoISP


text:
Stacking shields without headers
In the project I am working on, I have a limited space with which I can work. I am using an Arduino Uno with 2 Adafruit motor shields, and when I stack them using normal, female stacking headers it is too tall to fit. I thought that one way to solve this would be to lay them out side to side rather than one on top of the other. So, instead of this
+--------Motor shield 2 ----------+
|||||||||||||||||||||||||||||||||||
+--------Motor shield 1 ----------+
|||||||||||||||||||||||||||||||||||
+---------Arduino Uno ------------+

it would look like this
               -----------------------------------------Wires -------------------------------
+---------Arduino Uno ------------+    +--------Motor shield 1 ----------+    +--------Motor shield 2 ----------+

Would this be possible if I were to connect all of the pins with wires, and has anyone successfully done this before?

It is possible to have some success with this, but keep in mind that the longer the wire, the higher the inductance and voltage drop across the wire. Prefer to use a star topology rather than a chain topology, with the Arduino in the middle of all the shields in use.

Also you probably only need a few wires connected.  It looks like the motor shield uses 6 pins, 2 I2C pins, pins 9 and 10 (if using hobby servos), power and ground.

Yes, no problem running individual wires, and also like Craig says, only run the wires you need. For some inspiration, here's a project I did with a bit of hand wiring. And then there's this project with kinda epic wiring.


text:
Is it possible to transmit using an NRF24L01+ without an Arduino?
I have two NRF24L01+ modules which are transceivers, but for my project I would like to send a very simple signal from one of these modules to the be read by the other.
That would've been very simple if I had an Arduino on each side but due to power consumption constraints as well as size, cost and practicality, the transmitting side won't have one. Would it still be possible to do this?
To clarify, the message itself is not important and can be set in stone, it will never change. I really just want to detect on the receiving side (which will have an Arduino) that the transmitter is in fact transmitting. Transmission will be triggered by a push-button.
Ideally I would have a way of identifying my particular transmitter from others on similar frequencies but I am not too precious about that.

You don't need an "Arduino" but you do need a microcontroller core as that particular chip does not have a user-programmable one.  To stay with something that can be treated Arduino-style you could probably make do with an attiny85 (or even the 45 or 25), in a tiny surface mount package, and have it only active a tiny fraction of the time and in negligible-power sleep the rest.

Thank you, Chris, that actually answers my question so if you'd like to post it as an answer I can vote it up.

Also, would you then suggest another approach to doing what I intend with a different transceiver or transmitter / receiver pair that does not need a programmable microcontroller?

Not sure why the question was voted down?

is there a difference between the nrf24l01 and nrf24l01 + libraries?

The nRF24L01+ has a somewhat complex SPI based interface, where many registers have to be configured and tested and timeouts honored.  Therefore it requires some kind of microcontroller to send or receive even the simplest message.
This can be as simple as a 3.3v Arduino Pro Mini (less than $3 with shipping), and there are libraries which simplify the task of interfacing to it - in particular see the RF24 library (there are many variations, see https://github.com/TMRh20/RF24 for a good one).
But many other microcontrollers could work as well.
Once you bite the bullet and accept the need for a microcontroller, yes the code can identify the source of the signal (which pushbutton) and much, much more.
Or you could use a dedicated device like an xBee which can be configured using a Windows utility to send the state of an input pin to another xBee; basically there is already a programmed microcontroller on the module along with the radio (not nRF24L01+ compatible).

Thanks, Zeph, I appreciate the clear answer. I would vote up except I don't have the reputation to do so yet.

An ATTiny85 can drive the NRF24L01+: "nrf24l01+ control with 3 ATtiny85 pins"
At least this is not a "full" Arduino...
Edit 2015-06-06:
Hackaday News: "EMBED WITH ELLIOT: MULTIPLEXING SPI USES FEW PINS"
The referred blog entry is: "nRF24l01 control with 2 MCU pins using time-division duplexed SPI".
(-: Nice countdown... 3 pins, 2 pins, ... ;-)

Note, there is also the NRF24LE1 SoC which has its own ULP MCU - good for transmitting simple data such as sensor readings. If used to Arduino, ARduino Pro Mini 3.3v and the NRF24L01+ is easier and better way to go. (Mod the Arduino to be ULP)

The nRF24L01+ needs an external microcontroller to be used.
I believe an XBee could be used if you want a "single module" solution, however using even the Atmega328p (standard for Arduino Uno) would probably be cheaper than this.

1) Easy way
This transmitter uses only SPI interface so you need to drive it some logic unit, i.e. microcontroller that supports this interface (i.e. AVR atmega8) and is able to use driver for this module as a ready to use set of high level functions to express your intentions in your code.
2) Badly bad way
You can use the SPI to I2C converter as well. Connect it to your computer via serial port - but note that it's a big effort. You will need to port nRF24L01 driver, etc.
http://www.elecrow.com/nrf24l01-wireless-shield-spi-to-i2c-interface-for-arduino-p-737.html


text:
How to loop over analog pins?
I want to do something along the lines of
for (int i = 0; i < 4; i++) {
  analogRead(i);
}

Which appears to work, but the following does not:
for (int i = 0; i < 4; i++) {
  pinMode(i, INPUT);
  pinMode(i + 4, OUTPUT); // should make Analog Pin (i + 4) into an output
  digitalWrite(i + 4, LOW);
  analogRead(i);
}

Instead, it appears to treat the pin addressed by digitalWrite(i + 4, LOW); as one of the digital pins.
Do I really have to explicitly specify A0, A1, A2, ... anytime I want to loop over the analog pins?

Sorry to resurrect this thread but I wanted to note the pros and cons of the answers provided above..
Craig's nuclear bunker is the most bulletproof; it would work even if there were nonconsecutive mappings.
Geometrikal's paper airplane is the least bulletproof as his/her magic numbers will fail as soon as you move to a different board (because there's nothing hypothetical about the mappings being different between boards). Now in fairness, they make it clear that they're offering "another way of writing BrettAM's answer" and thus perhaps they're not making a serious recommendation at all.

BrettAM's Swiss watch seems very reasonable to me because it only fails in the event of a nonconsecutive mapping which, to the best of my knowledge, remains a purely hypothetical concern. What BrettAM's answer does do best is make clear the salient point that A0 is just a predefined constant of the same type (8 bit unsigned integer) as any literal you might reasonably use in that for loop. A0 is just a number. What number is it exactly? Well, that depends, and furthermore, doesn't matter much. But what you can count on is that it is a number and that you're free to use it as such.

I like your poetic descriptions of the different answers! The metaphors are apt - but you may want to put them in quotes for our non-native English readers, to highlight you are being a little hyperbolic: "nuclear bunker", "paper airplane", etc.

Yes, the analog pins must be addressed using A0, A1,... when using them for digital I/O.
Depending on the board you are using A0,A1,etc. are mapped to different values (for instance it looks like A0 is 18 on some boards but 14 on others.
One solution for looping over the analog pins would be this:
static const uint8_t analog_pins[] = {A0,A1,A2,A3,A4};
// Setup pins for input
for (int i = 0; i < 5; i++) { //or i <= 4
  digitalRead(analog_pins[i]);
}

If you are using the analog pins only with the analogRead() call you can use 0,1,... instead of A0,A1,...

According to http://arduino.cc/en/Reference/analogRead you can read from analog pins merely by number (e.g. 0, 1, 2, 3, etc.); the "A" in "A0" is optional. Of course, it can be more clear if you distinguish them with the "A" prefix but it is not required for analogRead. On the other hand, digitalWrite(i) assumes that i refers to a digital pin; to use digitalWrite with an analog pin one needs to include the "A" prefix.

Good catch. I updated the answer.

This is the most portable solution I've seen so far, and it's the one I'm using now, thanks.

At least an Uno/Megas/leonardos, all the values mapped to analog pin numbers are consecutive, so
for (int i = A0; i < A4; i++) {
  pinMode(i, OUTPUT);
  digitalWrite(i, LOW);
}

will set A0, A1, A2, and A3 to OUTPUT, and then LOW.

Pins 14 through 19 are the analog pins A0 to A5. A0 is just an alias for 14 and so on.
So another way of writing BrettM's answer:
for (int i = 14; i < 18 i++) {
  pinMode(i, OUTPUT);
  digitalWrite(i, LOW);
}

This does not work on all Arduino boards. Not all boards use 14-19.

Your first loop will work just fine indeed, however, you might want to add delay(1); after you analogRead(i);, to give the ADC some time to settle.
Could you elaborate on what you are trying to do with your second piece of code? As it looks right now, it doesn't really make sense to use analog inputs as digital outputs.
Besides, you're trying to read a pin's input just a couple of lines after you specified the pin to be an output.
Please explain what you are trying achieve, so the nice folks around here can you help you better.

I know this is old, but if you hover your mouse over A0 to A7 in visual micro it will show you the true value, they are just a variable (it actually shows as 14U but while addressing you do not need to include the U). What Craig said is wrong, they do NOT have to be addressed by A0, A1 ect..
A0 = 14
A1 = 15
.
.
A7 = 21
//Will set all pins, digital and analog to LOW (0)
for (int i = 1; i < 22; i++) {
    digitalWrite(i, LOW);
}

//Will set all analog pins to LOW (0)
for (int i = 14; i < 22; i++) {
    digitalWrite(i, LOW);
}

//Will set all analog pins to LOW (0)
for (int i = A0; i < A7 + 1; i++) {
    digitalWrite(i, LOW);
}

The last for loop is basically saying i = 1 (A0), and stop on 21 (A7).

Assuming pin numbers are consecutives you can iterate them:
int acc = 0;
for (int Ai = A0; Ai < A0 + NUM_ANALOG_INPUTS; Ai++) {
    acc += analogRead(Ai);
}
Serial.println(acc);