text:
PWM generation for inverter by Arduino
Can I generate a PWM signal for a Mosfet driver using a saw tooth wave and sine wave through Arduino ?

You could  add a DAC chip. Or use some resistors to create an R-2R resistor ladder.

PS I think most inverters use regular PWM (at a higher speed), and smooth the output. Using mosfet in a none-saturated is inefficient, and will make them run hot.

Read the datasheet of your inverter: What should the PWM signal look like? What frequency? Duty cycle? If you add this information to your question, it would be possible to provide a useful answer.

Yes you can very easy generate an PWM Output with an Arduino:
void setup()

{

  pinMode(pwmPin, OUTPUT);   // sets the pin as output

}

void loop()

{

  analogWrite(pwmPin, yourWantedValue);  // analogWrite values from 0 to 255

}

On most Arduino boards (those with the ATmega168 or ATmega328), this
  function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it
  works on pins 2 - 13 and 44 - 46. Older Arduino boards with an ATmega8
  only support analogWrite() on pins 9, 10, and 11.
The Arduino Due supports analogWrite() on pins 2 through 13, plus pins
  DAC0 and DAC1. Unlike the PWM pins, DAC0 and DAC1 are Digital to
  Analog converters, and act as true analog outputs.

Visit quote origin for more Information.

Note that the PWM frequency is quite low: 490 or 977 Hz depending on the pin. The OP should check the datasheet of the inverter to make sure those frequencies are OK.

Currently, none of the boards have a DAC on them, with the exception of the arduino Due. Thus, Unless you have the Due board, it is not possible.
If you have a due board, and are interested in generating wave functions, then check out here: https://www.arduino.cc/en/Tutorial/DueSimpleWaveformGenerator


text:
Design considerations for creating an Arduino 'shield' shield to limit EMI
I am building a shield that contains an AC power supply and relay for an Arduino-like board. The problem I am having is that the relay is quite noisy with respect to EMI, and I can see a few jitters or jumps in my system during normal operation even with a zero cross detector.
I have added in another shield between the 'relay' shield and the main board, which has helped the problem by creating a larger gap, but I would like a more permanent and robust solution.
I was thinking of building a simple shield that has nothing much on it and is simply a large ground plane that sits in between the relay shield and the main board. This would be a simple solution that does not involve making any shielding cages.
This ground plane would be connect to the chassis of my device, which is then earthed.
Since the device has both a DC ground voltage (0V DC) and a AC earth (0V AC) I was thinking maybe I should use both as part of my shielding. Since the board has layers on both sides perhaps I could design it to have the side facing the relays to be earthed, while on the other side, facing the CPU, would be DC ground. I could even couple the two planes with a capacitor, if it helps.
On the one hand I think the earthed option should be fine, but on the other hand I would like to know more about using the DC ground as an EMI shield. Would the simple earth only option work? Would even a DC ground only option work? Does it help to use the DC ground as an EMI shield for the DC components or am I over complicating it?

How are you detecting "a few jitters or jumps in my system"? Why do you think it is EMI rather than a voltage dip causing them? How are you powering the relay? Is it from the Arduino's 5V supply? The simplest explanation for most "jitters" around an Arduino is electrical rather than EMI.

It's a number of things, but mainly if I take away the AC I don't get the issues. Also as mentioned in the question if I move the shield further away I also don't see the issues. I can detect them as I have a sensor that goes offline when it encounters bad signals over the SPI bus.

Unfortunately your question has been migrated to a site where, IMHO, you might be less likely to get the kind of help you'd like.

What would be helpful would be explanation of the type of AC you are using and then possibly a schematic or board layout.
That aside, there does seem to be noise between the two boards. The Idea of placing a PCB with just a large copper pour would work.
DC Ground
If you connect the DC ground from the main board you should use a ferrite bead(FB) between the two grounds, this will ensure that you don't get noise getting back into the ground of the main board after you have tried to shield it. You should try to match the ferrite bead to the noise frequency you experiencing (use a scope if you have one).
Using the DC ground as a shield is often done, if you look at the EMI cages on cellular phones, WiFi modules, and other noise generating devices/susceptible-to-noise devices, they are connected to ground. It gives the noise somewhere to go, instead of your signal lines. Thus using the DC ground is defiantly an option
i.e.:
Main ground>--------[__FB__]-------<SHIELD

AC Ground
You could use the AC earth line on the top part of the shielding board. The coupling part might be a bit over kill, leave space for it to test to see if it helps when you make the board. Also AC earth can be used for shielding but is used for the safety aspect of earth leakage.
Don't do a direct DC ground to AC ground unless you know what you are doing as this will create a ground loop, this will change the way stuff behaves and will make your circuit no longer a floating device.
Other stuff
I would also make sure how you drive the relay is isolated from the control circuitry, although from what you describe:

if I move the shield further away I also don't see the issues.

If you share power rails between the relay board and the main board, try filtering the power going to the CPU section. Also the control lines can be isolated between the controller and the relay with opto-couplers, this might stop noise coming back into the circuit from the relay part.

source: Stack Exchange

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

sort: votes


text:
producing sine wave variable in amplitude and frequency
How to produce a sine wave with variable frequency and variable amplitude?
I found a library to produce variable frequency called sinwave but not produce variable amplitude (I want -2V to 2V amplitude)

How is -2V to 2V variable?

You can use a digital potentiometer as a programmable attenuator or as a feedback element in a programmable gain amplifier circuit.
See references  at arduino.cc regarding interfacing an AD5171 or AD5206 to Arduinos.

Here's one solution to do it using your own code implementing the following.The basic solution is as follows.
Start with the basic sine wave output (this has amplitude between -1 and 1, and repeats ever 360 degrees) implemented as a function in your Arduino sketch with a variable parameter for the frequency and amplitude.
Now input the frequency you want (which you don't specify) and the amplitude (that is multiply your sine function by 2). The frequency can be implemented by using the delay function to output a value corresponding to the y-axis of the sine wave  at the specified time on the x-axis. You would need the y output to depend on the delay and the frequency. This is all in code so far.
The next step is to output the corresponding voltages for each point on the sine wave. To make a varying voltage you can use a digital potentiometer with a voltage divider type circuit (it's not quite an voltage divider because it needs to produce negative voltages too). Thus you just need to make your code activate the digital potentiometer at the required resistance to create the required voltage that represents the y value of that sine value at that point in time (x axis has time). This voltage divider requires some more circuity to make the voltage between 0 and -2 volts (the negative voltage depends on the time the circuit has been on or the x-axis of the sine wave). There are lots of ways to make a corresponding negative voltage (the bottom half of the sine wave).  The triggering on or off of the potentiometer is done from the Arduino thus this also controls the frequency of the sine wave.
To sum up code the sine wave in a sketch with your desired frequency and amplitude use these values and implement the discrete point on the sine wave using a (digital) potentiometer which is part of a circuit which is a variation of  the simple voltage divider (the voltage divider type circuit will implement the amplitude of the sine wave which you want between 2v and -2v). The frequency is, basically, implemented with the delay function.

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


text:
XBee Shield Arduino External Power Issue
The XBee part of the entire thing works flawlessly no matter how things are being run.
Equipment:

Laptop
Arduino Uno
Sainsmart XBee Shield
USB XBee Explorer
2 x XBee Series1 modules
Terminal software

What we are doing:
Send data through terminal software using "XBee 1" on a USB explorer, to remote "XBee 2" which is connected to Arduino Uno using the Sainsmart Shield. Arduino sends a reply which we see in the terminal software. (This is basically just using the two XBee modules to eliminate physical RX-TX connections in a simple point to point communication.)
This configuration works perfectly fine when the remote Arduino + XBee are powered by a USB port of a PC (doesn't have to be the same PC - tried with separate PCs, one powering the transmitter and other the receiver.)
The problem:
This configuration does not work if the remote Arduino + XBee are being powered by:

9V Battery (brand new)
12V, 2A adaptor
5V, 2A mobile charger directly supplying through USB

BUT it starts working after pressing RESET (sometimes, very rarely, we have to press RESET 2 or 3 times but it does start working) and keeps working while the supply is not disconnected/turned off.
Important Note 1: As mentioned earlier, the remote XBee always works perfectly fine in all of the above cases as shorting RX/TX shows that the data perfectly and flawlessly echoes back.
Important Note 2: I don't think that the Arduino isn't starting up, as to check that I am blinking pin13 LED which always starts working fine in any of the scenarios listed above.
Please help. Having to RESET every time after power up makes the whole thing pretty useless for any real world application.
When I say that does not work, I mean I don't get a reply from arduino when I send a query over terminal.
After pressing Reset, it begins working, i.e. I start getting a reply.
But I don't think that Arduino isn't startup because Pin 13 LED blinks as expected which is something I put just to check whether Arduino code starts running.
As far as circuit, it is nothing but XBee Explorer USB plugged into my laptop and arduino with ready made XBee shield plugged into another USB port (which is when it works). Powering Arduino from a USB port of a different PC also gives no issues.
Only when Arduino is powered by external power source like an adapter or phone charger or 9V battery (literally tried all 3) does it not work automatically and I have to Reset the Arduino after which it starts replying.

You think you have described your system, but you really didn't. Either draw a circuit diagram, or find a simple setup which still reproduces the issue (and draw a circuit diagram of that).

I would also add more details to what you mean by "not working" (Is the Arduino operating system booting? Can you talk to it on the network? etc.)


text:
Arduino IDE programming help
I am trying to write a program to control a stepper, and incorporate a selector switch and a rheostat.
The object is to make the stepper oscillate, and to be able to control the speed with the rheostat, and the amount of oscillation with the selector switch.
What would the best way to go about this?

By writing a program to do it.

So you want to use the rheostat as an analog controller then?-If so your program would use the analog pins. Uisng the info gathred from the analog pins you can control the stepper motor, though you may need to build a h bridge or use something similar

A stepper motor may well not be the right choice

"The object is to make the stepper oscillate" if you mean you want to make the stepper go back a fixed number of degrees in one direction then go foward a fixed number of degrees in the opposite direction-then yes a stepper with control circuit can do this. My interpretation of your question is your are using select switch to vary degrees in an oscillation and rheostat as analog controller for speed of oscillation. Right?

Majenko provided the correct answer in his comment: you just have to
write a program to do it! This site is not meant to provide you with a
ready made solution, but to give help if you run into an issue while
trying to solve the problem yourself.
That being said, before you attempt to write the program, you should
learn how to interface with the hardware you are using. Here are the
relevant Arduino tutorials:

The Button tutorial is about reading a push button, but you would
do exactly the same to read a switch
Reading a Potentiometer (analog input)
Stepper Speed Control will teach you how to control your
stepper motor

And then there is plenty of material available on the Web for each of
these topics.
Go through the tutorials, understand the programs given as examples,
make them work with your hardware, then put the pieces together to solve
your problem. If you run into an issue you cannot solve buy yourself,
then come back here with a specific question and show us what you have
attempted so far, including code and schematic. See also How do I ask
a good question?.

Here are the code fragments that would help you.
Connect the three wires from the potentiometer to your board. The first goes from one of the outer pins of the potentiometerto ground. The second goes from the other outer pin of the potentiometer to 5 volts. The third goes from the middle pin of the potentiometer to the analog pin A0.
Here is the connection schematic:

Here is the code to read the analog value from port A0:
int sensorValue = analogRead(A0);

this would assign a value ranging fro 0-1023 to sensorValue according to the position of the Pot.
int stepsPerRevolution = 200;
//this variable holds the no of steps the motor rotates to complete a full circle rotation.

int stepCount = 0;  // number of steps the motor has taken

stepsPerRevolution = map(sensorReading, 0, 1023, 0, 200);

// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);

Here is an example program for controlling the direction of stepper using microswitches:
#define stepPin 2
#define dirPin 3
#define pinLimitswitchLeft 4  // these can be either left or right depending on motor wiring and dir pin.
#define pinLimitswitchRight 5 // these switches must be N.O. types
int stepDelay = 100; // this is the step delay in microseconds. Reduce this to speed up motor rotation and vice versa.

void setup()
{
    pinMode (stepPin, OUTPUT);
    pinMode (dirPin, OUTPUT);
    pinMode (pinLimitswitchLeft, INPUT_PULLUP);
    pinMode (pinLimitswitchRight, INPUT_PULLUP);
}

void loop()
{
    digitalWrite(dirPin, HIGH);  // set direction pin, the direction that the motor will rotate is dictated by it's wiring
    while (digitalRead(pinLimitswitchLeft) == HIGH) // move motor until left limit switch is pressed.
    {
        stepMotor();
    }

    digitalWrite(dirPin, LOW);  // set direction pin, the direction that the motor will rotate is dictated by it's wiring
    while (digitalRead(pinLimitswitchRight) == HIGH) // move motor until right limit switch is pressed.
    {
        stepMotor();
    }

}

void stepMotor()
{
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(stepDelay);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(stepDelay);
}

Change the control from the control switch to the number of steps taken by your motor when the switch is pressed and it will work as you require.
I have not included the header files.
Please edit the program as you require


text:
Using a lot of interrupts on a single Arduino
I'm doing a little project that requires a lot of sensors. Right now I'm using 4, but i want to reach up to 60 sensors, and a minimum of 16 (for me that's a lot).
So, I have an Arduino MEGA 2560, and I'm new to Arduino (Had a little experience with PIC before).
I've started my project with buttons and leds to simulate the sensor, but my sensors work normally HIGH, and when something pass in front of it, it goes quickly to LOW and back. English is not my first language so I don't recall the name of this sensor, kind of like movement sensor(?).
A lot of stuff pass normally, up to 50/s, in front of it, so it should keep "bouncing" between HIGH and LOW. But when I changed the buttons for the sensors, sometimes my processor won't react, and I think it's because the signal goes back to HIGH before the code reads it. Maybe it's not a problem when it's sensing lot of things, but I can't test it right now with a lot of sensors, and it's not something that can keep getting errors.
So I got to interrupts, reading the awesome gammon review. I understood a lot of new things that i didn't know and I searched for a interrupt Library, but the one I found can't use too many sensors.
I forgot to tell, but I'm using a touch 2,4" shield too, so a lot of interrupts pins can't be used.
Will I be able to use all the sensors I want? If not, could I do it with 2 Arduinos and 1 screen? Am i missing something about the interrupts? Where can I find something to help me?
Edit 1: All the sensor are the same

What you want here are pin change interrupts

This actually would be a great candidate for implementing on a CPLD with lots of pins.

On a Uno, all of the digital and analog pins can trigger a pin-change interrupt. That gives you 20 inputs straight away. The Mega also has pin change interrupts but not on all its pins. The pins that the Mega supports for pin-change interrupts are documented on the Software Serial page.

Not all pins on the Arduino Mega and Arduino Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

(Note that the Atmega2560 chip itself supports more pin change interrupts, however those extra ones are not brought out to header pins on the Arduino board).
That's still quite a few (18 if I counted correctly). Plus the hardware interrupt pins: 2, 3, 18, 19, 20, 21.

Right now I'm using 4, but i want to reach up to 60 sensors, and a minimum of 16

To reach 60 you probably want an input shift register such as the 74HC165 - you can daisy-chain them together to get lots of inputs. However you would have to poll to see if pins changed.
Otherwise you could use something like the MCP23017 chip, which has 16 input/output pins, and supports interrupts. You can use 4 of them (interfacing with I2C) and thus get 64 inputs. There is a shield that has 4 of those chips on it:

With suitable software (see my page about I2C) you could configure for interrupts and read any of those 64 inputs when they change.

Do I have to keep checking all the time for every sensor one by one?

No, because you can configure the interrupts as open-drain, which means you can connect them all together (if you want to). Or, you could bring out the interrupts for the 4 x MCP23017 chips to four interrupt inputs on the Mega (that narrows down for you which chip caused the interrupt). Then you can read the chip's register(s) to find the state of the pins - either at the time of the interrupt, or right now.
However you might find that it is actually faster to just poll the chips (say) 100 times a second. There is some overhead to using I2C, you can also get SPI versions of that chip (MCP23S17) which would operate a bit faster.
Alternatively, the 74HC165, whilst simpler, could also turn out to be overall faster if you just poll rapidly.

And the sensor sense a lot of movement per second, won't that cause trouble for the Arduino?

You need to define "a lot" and "trouble". You won't do billions of read a second. You can probably do thousands. What would you do with thousands of readings anyway? The time taken to process them would probably be the limiting factor.

At the same time I'm using a GPS, no problem for the usage of Serial and I2C together right?

No problem, because serial input is interrupt-driven. Within reason, you can do both at once.

That quote, “Not all pins on the Mega and Mega 2560 support change interrupts”, is slightly misleading as an explanation of only 18 PCI pins on the Mega.   ATmega640-1280-1281-2560-2561 series chips support 24 PCI pins – #0-#7 on PB0-PB7; #8-#15 on PE0 & PJ0-PJ6; #16-#23 on PK0-PK7.  However, PE6 and PJ2-PJ6 aren't brought out to headers, leaving 18 available as you mention.

The OP said I have an Arduino MEGA 2560 so I was addressing the Arduino board, not the raw processor. I'll amend the post to make that clearer.

So, I read about the Centipede Shield and your page about I2C and now I'm pretty sure I need to use I2C one way or another. I'm thinking about the Centipede, but I'm not sure I understood how to implement it. Do I have to keep checking all the time for every sensor one by one? Or one time for each Chip? My master will only read, it's all sensors anyway. And the sensor sense a lot of movement per second, won't that cause trouble for the Arduino? At the same time I'm using a GPS, no problem for the usage of Serial and I2C together right (newbie question)?

For that many sensors (way more than the number of interrupts available on the chip), your interrupt service routine (ISR) will need to be able to poll the sensors to discover which one(s) caused the interrupt.
That might mean connecting each motion-sensor's output to both a latch and a many-input OR-gate to one of the interrupt pins. Your ISR would have to read the latches; set a flag for each LOW latch; clear the latches (to HIGH) and exit. The main routine would then take whatever action was needed for each sensor that had been LOW.

When you have implemented the solution given above, by Nick Gammon, it is recommendable that you try both of the solutions he provides, and use the timer circuit to time each version of the algorithm.
That is: You need to try out if the polled reading he mentions of lets say 100 times per second, or the interrupted method is the best, given your circumstances.
Reason being that if your system pulls the interrupts from time to time, lets say, each of the 64 inputs pulls its interrupt pin maybe once in 30 seconds, then you have just above 2 pulls per second to the board. That is not a lot, and checking the registers like 100 times per second (if you need time wise accuracy for instance), may prove very time consuming, as you would otherwise only run 2 interrupted algorithms per second.
Use the diode on the Arduino Mega circuit board if you have no display or output unit on the Arduino, to display the results. (If you need help communicating from the Arduino to yourself (human) via 1 diode, such that you can be told how much different a particular setup is, then let me know - that would be outside of the scope of this answer, I guess). I short, you can communicate to yourself by creating a little algorithm which starts with ie. 3 rapid blinks, then a pause, then it can create countable blinks for each figure, counting 0 with 10 blinks, and then you can count the blinks by putting breaks in between the figures. Thereby you can communicate the figure 1874 by 1 blink, pause, 8 blinks, pause, 7 blinks, pause, 4 blinks - then long pause, then 3 short blinks, pause, then it repeats.


text:
GCC msg "note: in definition of macro 'max'" error message
I'm using the ATtiny x5 series board, compiling my project (.cpp.ino file).  Whenever I use the max(a,b) macro, I receive this message:
"C:\Documents and Settings\<user>\Local Settings\Application Data\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.3-arduino2/bin/avr-g++" -c -g -Os  -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=attiny85 -DF_CPU=8000000L -DARDUINO=10609 -DARDUINO_AVR_ATTINYX5 -DARDUINO_ARCH_AVR   "-IC:\Documents and Settings\<user>\Local Settings\Application Data\Arduino15\packages\ATTinyCore\hardware\avr\1.1.1\cores\tiny" "-IC:\Documents and Settings\<user>\Local Settings\Application Data\Arduino15\packages\ATTinyCore\hardware\avr\1.1.1\variants\tinyX5" "-IC:\Documents and Settings\<user>\My Documents\Arduino\libraries\Pins_xxxxx" "-IC:\Documents and Settings\<user>\My Documents\Arduino\libraries\TinyWireS" "C:\WINDOWS\TEMP\build18f8c74edd63168be814edc24cb0a11a.tmp\sketch\AT85PWM.ino.cpp" -o "C:\WINDOWS\TEMP\build18f8c74edd63168be814edc24cb0a11a.tmp\sketch\AT85PWM.ino.cpp.o"
C:\Documents and Settings\<user>\Local Settings\Application Data\Arduino15\packages\ATTinyCore\hardware\avr\1.1.1\cores\tiny/Arduino.h:54:24: note: in definition of macro 'max'
 #define max(a,b) ((a)>(b)?(a):(b))
                        ^

What does note: in definition of macro 'max' mean, do I need to do anything about it, and if so what?
Searching google for the message gives lots of compiler output listings with the message, but the posting is always for another different message that is causing trouble.  None of the fixes from those posts address the max note: message.

Is that the only message? Can you please post your code, or at least a Minimal, Complete, and Verifiable example. I suspect it is something to do with the data types being used when you use max in some context.

I spent a good hour trying to package up something small for you before I decided to abort.

@Nick, I spent a good hour trying to package up something small for you before I decided to abort.  The basic problem seemed to be a function call where MAX was used to calculate one parameter, and a macro was used to try and extract a field from a structure for use as another parameter.  Because of C++'s insistence that structs are classes, and therefore a search for explicit conversion routine, the macro used to extract the field gets flagged along with all other macros in the function call.  This seems a tad overzealous, but it's better to have too much info...

And there's a 5 minute rule about editing comments.  Should be more like 30.  Some of us are slow thinkers, need to consult references, need time to edit....   Buzzzzzzzzzzz  your time is up, next contestant please!

I was recently working on another project where I got a similar message. However before it was the real error message/warning. The "note" line just tells you where the macro is defined. The "real" error/warning occurs when the macro is used (because that is where you might have signed/unsigned mismatches, for example).

I can reproduce your message easily enough:
#define max(a,b) ((a)>(b)?(a):(b))

void setup() {
 int b = 66;
 unsigned int c = 42;
 analogWrite (3, max (b, c));
}

void loop() { }

I get these warnings:
/tmp/arduino_modified_sketch_857720/sketch_aug31a.ino: In function 'void setup()':
/tmp/arduino_modified_sketch_857720/sketch_aug31a.ino:1:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define max(a,b) ((a)>(b)?(a):(b))
                         ^
/tmp/arduino_modified_sketch_857720/sketch_aug31a.ino:6:18: note: in expansion of macro 'max'
  analogWrite (3, max (b, c));

The point is that the warning note: in expansion of macro 'max' is just telling you where the macro is defined, so you can make sense of the real warning. The real warning is: warning: comparison between signed and unsigned integer expressions
So, reading them together, you are comparing (in the macro) a signed and unsigned number, and the compiler is warning you about that.

The message seems like a red herring, given that there is no problem with the max(a,b) macro definition. I suspect it is being flagged only because it was tangentially involved with a statement in error.

That's right. There is no problem in that macro per se. Macros can generate weird error message because they are just text replacements. For example:
max (the quick brown fox, jumps over the lazy dog);

That will generate a slew of errors, including a "note" to where max is defined. There is nothing wrong with max until you try feeding garbage into it.

Templates
That's one of the reasons I prefer to avoid macros if possible. You can do "max" with a template. For example:
#undef max   // throw away the original macro in the Arduino header file

template<typename T> T max (T a, T b)
  {
  if (a > b)
    return a;

  return b;
  }

Now you get slightly more reasonable error messages:
/tmp/arduino_modified_sketch_711186/sketch_aug31a.ino: In function 'void setup()':
sketch_aug31a:14: error: no matching function for call to 'max(int&, unsigned int&)'
   analogWrite (3, max (b, c));
                            ^
/tmp/arduino_modified_sketch_711186/sketch_aug31a.ino:14:28: note: candidate is:
/tmp/arduino_modified_sketch_711186/sketch_aug31a.ino:3:24: note: template<class T> T max(T, T)
 template<typename T> T max (T a, T b)
                        ^
/tmp/arduino_modified_sketch_711186/sketch_aug31a.ino:3:24: note:   template argument deduction/substitution failed:
/tmp/arduino_modified_sketch_711186/sketch_aug31a.ino:14:28: note:   deduced conflicting types for parameter 'T' ('int' and 'unsigned int')
   analogWrite (3, max (b, c));
                            ^
exit status 1
no matching function for call to 'max(int&, unsigned int&)'

Of course, now you've gone from a warning to an error, because the template wants a single type.
Notice the notes? That's just the compiler trying to be helpful.

You could make the template take two types if you are prepared to guess the return type (will it be the first type, or the second type?):
#undef max

template<typename T1, typename T2> T1 max (T1 a, T2 b)
  {
  if (a > b)
    return a;

  return b;
  }

Now you don't get an error or a warning, however the result will be the first type (T1) which may or may not suit you.

Twasn't the case.
You constructed an example were the max() macro operands were in error.  In my case, the max() macro operands were just fine, and the relevant diagnostics involved another macro.  max() wasn't part of the expression in error.

Regarding templates:  the max() macro comes with the Arduino IDE base.  Perhaps you would be in a better position than I to get the IDE to change over to templates.

you would be in a better position than I to get the IDE to change over to templates - If they were to do that, it would probably throw up heaps of warnings, or even errors, in code that currently compiles with only a warning. So they probably won't. max() wasn't part of the expression in error - yes, well I would like to see this reproduced before I could agree.

the relevant diagnostics involved another macro - it would help to post all the diagnostics, and not just the ones involving max. Plus the defines for this other macro, and the lines of code which produced the error.

Note to the future:
(My particular case was a function call with several parameters.  One had the max(a,b), and another parameter had an error.  It used a different macro, which may have pushed the compiler to flag every macro in the whole call).
The message seems like a red herring, given that there is no problem with the max(a,b) macro definition.  I suspect it is being flagged only because it was tangentially involved with a statement in error.
Since it wasn't part of the problem, the compiler couldn't say anything specific about it or the code it generated.  Therefore the flagging message then ends up saying "in definition of macro" (kind of a default of last resort) since it couldn't say anything more specific.
If you ever get one of these, particularly from a system provided macro, ignore it until you've diagnosed your other problems.
Ignore the fact that the error message is first in the listing, and the statement using the macro doesn't get flagged until after several other statements are flagged.
Again, I suspect that compiler feels obligated to say something about the macro because it was used.  But since it's not part of the problem in the statement where it appears, it doesn't get flagged there.  Instead the compiler puts the message at the top because it has to go somewhere, but the compiler can't/doesn't want to associate it with the statement where it was used.
The solution worked for me, but a language lawyer or compiler developer may say my explanation has no basis.


text:
Controlling 5 DC motors with Arduino
I am looking to purchase the correct hardware to be able to control 5 DC Motors from an Arduino (UNO preferred, MEGA if necessary).
The Specs of the Motors are as follows: 12 V nominal, 3 → 12 V dc, 794 gcm, 100 rpm, 0.394 W
What would be your recommendations for how to set this up? As I am fairly new to circuitry a circuit diagram would be helpful along with the recommendation of what shield or drivers to use. Thank You

Do you need constant speeds or variable?  Do you need to sense the speeds?  Do you need reverse as well as forward rotation?

Constant speeds. I do need reverse and forward

Since youre new to circuitry - you should know an  actual  circuit for this is not hard to make. Its not something I'd buy a shield  for.

There are currently no expansion boards (shields) for the Arduino platform that are designed to do what you're asking of it. At most you'll find shields that can support up to 2 maybe 3 motors. My recommendation for a beginner would be to experiment with a breakout board like this one: https://www.sparkfun.com/products/9457 It's compact and can easily control 2 of the motors you need, three together and you could control up to 6.

would I need any other components to work with these?

No, nothing beyond a little soldering equipment, this blidr tutorial may help you, http://bildr.org/2012/04/tb6612fng-arduino/ . Note that for the motor direction pins on this breakout, if all your motors are spinning in a fixed direction, you could connect the proper pins to +5v and Ground without having to sacrifice more digital pins for it.

I would suggest to use the shield that is directly attachable to the Uno, for example: http://playground.arduino.cc/Main/AdafruitMotorShield. So everything you need is Uno, this shield and motors. No soldering.


text:
Soldering issue with arduino
I am trying to solder arduino nano onto a perfboard/solderable breadboard using rosin core solder. The connection is only working some of the time, when I check with a multimeter (+) at pin 29 (in image below) I and (-) at pin 17 there is power at the top of the pin sticking out of the via/hole but there is 0 volts if I check at the actual joint (lower portion of the pin). I see a little flux residue around pin 29 that could indicate a little burning around the area could that be causing this, it is only very minor .. anyway I can fix it?

Also is it normal  to have a little yellow residue left over on the joints? I am new to soldering so not sure if a little flux reside is a bad thing on the joint...

If all you are going to do is solder wires to the perfboard, why not eliminate it and just solder to the Arduino Nano?

Fair play, that is a lot of flux residue. I am assuming you are using some quite chunky solder with lots of flux in it.
Flux is non-conductive, so the residue will be forming an insulating layer on the outside of the solder. That doesn't mean the joint is bad, only that you can't get to the joint because the flux residue is in the way.
If there is a conductive path between the tip of the pin and the pad next to it then all is fine. The fact that you can't see the signal through the outside layer of flux is neither here nor there.
If you want to clean it off you can use isopropyl alcohol (AKA PCB cleaner, AKA "rubbing alcohol") and use, for instance, a tooth brush to scrub it off.

Would a hotter iron burn off the excess flux, or otherwise dispel it better from the solder as it solidified?

Not really, no. That will just bake it on more and risk lifting the annulae of your holes.

Fair point. I have used 'rework solder' before which is bursting with flux and has a lower melting point, designed to flow as much as possible to help lift awkward components. That required lowering the tip temperature otherwise the flux would disappear too quick. It makes sense that it's more likely to bake on than bake off.

“The connection is only working some of the time” does seem to indicate bad solder connections.  (Another possibility is wires in wrong holes.)
To locate problems, clip (rather than hold) one lead of an ohmmeter (or a DVM set to Ohms), to a wire soldered to the beginning of the problematic chain of connections.  Then advance step by step along the chain, looking for an open junction.
To fix problems, obtain a solder sucker and/or solder wick, a hot fine-point soldering iron (preferably temperature controlled), and thin (eg 1-2mm) 60-40 tin-lead rosin-core solder.  Use the solder wick or solder sucker to remove the old solder from the joint.  Apply new solder to make a nice shiny proper solder joint.

Unless you're in the civilised parts of the world where you're not allowed to use lead... I use 0.7mm 97.1, 2.6, 0.3 Sn, Ag, Cu


text:
Arduino running at 8MHz with external crystal
I want to use my Atmega328P in 8MHz, but I noticed that the internal clock is not as accurate and cause problems in my application. To add an external crystal 8MHz I do like the image below or 22pF capacitors are only necessary when I use a 16MHz crystal?

You need to use the capacitors as this helps the signal generated by the crystal to be stable. If you do not use them, it will be worse than the internal clock basically.

You need to use the correct capacitors. The capacitors to choose depend on the crystal. Read the datasheet.

If you want to keep your componenet count down- then you may want to consider a resonator instead of using crystals and capacitors

@qwerty10 Resonators aren't that much better than the internal RC clock source. Yes, they can be faster, but no more accurate. Personally I don't use either. I use MEMS clock chips now - usually the ASEMB range from ABRACON.

@Majenko My interpretation of the question is  seemed to  impliy that the OP wanted to use as few components as possible so I suggested using a resonator. In my experience Ive found resonators to be accurate. But it would depends on the situation of course how accurate the clock pulse is to be required which only the OP really knows. Yes you can use a clock chip too-sometimes found in old epson printers-which is what you seem to be referring to.

@qwerty10 I highly doubt that old Epson printers used MEMS® clock chips. They are a very recent invention.

@Majenko Thats why I said seem to be referring to. Maybe its more accurate if I said the following. You can get clock chips or subcircuits in Epson usb printers (that can be reused)  and maybe there made by ABRACON. It a long time since I looked inside epson printer to fix it so Im not totally  sure.

This is a board I am at the prototyping stage with now. The MEMS® clock chip is the small one immediately south-west of the main chip. I think you are referring to the old crystal oscillator modules - the big metal 4-pin cans.

What you trying to make overall? I recall there was a small clock chip in the printers-it had maybe up to 12 pins. It had its own battery supply in the printer control circuit. I dont recall if it used an external  crystal. If I can remember all the details I'll let you know. Basically it was a way to save money by reusing that part of the printer circuit.

That sounds like either a clock generator chip (needs a crystal with it) or a clock management chip (takes a clock from elsewhere and creates other clocks from it). Still, 12 pins is 8 too many...

It was a self contained clock circuit (if you cut it out from the PCB) yes the number of pins was up to 12, so could have been less-simply dont recall now as it was so long ago. What are the other chip names in your circuit?

I could understand your circuit design if you explained it all. Part names and so on.

Yes, you require the capacitors, and the capacitors have to be the right value for your crystal.
The datasheet will specify a load capacitance which you use in the following formula:
C1 = C2 = 2(CL - C_STRAY)

That is, the load capacitance of the crystal, minus the stray capacitance from your circuit (as long as your traces are short that is negligible and can be largely ignored unless you have very very tight timing requirements) multiplied by 2.
So for 22pF capacitors it is safe to assume that the crystal that is with them has a load capacitance of 11pF.
So check the datasheet for the load capacitance (it should be very prominent) and select the correct capacitors accordingly.
If you want to do away with the capacitors and your timing requirements aren't that precise you may get away with a ceramic resonator which doesn't require capacitors.
Another option is to use a MEMS® clock chip which generates a stable clock signal at a pre-set frequency. While this doesn't require capacitors for the clock signal it does still require a decoupling capacitor on the power supply for it, but of course that doesn't affect the timing of the clock signal, so precise selection of a specific value isn't needed.

When would stray capacitance or stray inductance be significant if the 22pf capacitance was made from a number of capicitors connected in a combination of series and parallel to make up a 22pf capacitance? E.g. use two 44pf capacitors in series to make 22pf-and two 11pf capacitors for another 22pf-but it could be a lot more complicated than that-such as using lower values e.g. 1pf capacitors.

This crystal here has 18pF capacitance, then I need two 36pF capacitors. Is correct? http://br.mouser.com/ProductDetail/ABRACON/ABLS-8000MHZ-B2-T/?qs=sGAEpiMZZMsBj6bBr9Q9aUe%252bp9Tek3UMgyOb46u0oQg%3d

Yep, that is correct.

it would be interesting to know a good answer to the question I made in the comment above.

I am sorry, I do not understand the question.

I would guess it to be yes there is a threshold where it becomes significant for my question in the comment. I got the idea for the question when trying to make a value for a capacitance from other capacitors.

It all depends what you are doing and how important the timing is to whatever it is you are doing.

And my question in the comment was referring to values such as - C_STRAY

I am sorry, you have completely lost me now. Go back to shining lasers at each other to try and make a yellow dot in mid air.

That's a Majenko style, end of this conversation then.


text:
dns lookup only works with DHCP and not with static setup (EtherCard library)
When I use DHCP with ether.dhcpSetup() the DNS lookup for NTP ether.dnsLookup("0.pool.ntp.org") works fine, but when I use a static setup (because my Android app needs to know the IP address) with ether.staticSetup(myip); then this returns false and I don't get an IP address from the NTP pool. How come?
I have an Arduino Nano ATmega328 with a ENC28j60 ethernet shield, and therefore use the EtherCard libray.
Full MWE:
#include <EtherCard.h>      // https://github.com/jcw/ethercard
#include <Time.h>           // http://www.arduino.cc/playground/Code/Time

static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = {192, 168, 2, 106};
const char poolNTP[] PROGMEM = "0.pool.ntp.org"; //pool to get time server from
uint8_t ntpMyPort = 123; //port for the time server, no idea why needed

byte Ethernet::buffer[700];

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

 //do not forget to add the extra '10' argument because of this ethernet shield
  if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0) {
    Serial.println(F("Failed to access Ethernet controller"));
  }

  //static setup
  ether.staticSetup(myip);
  ether.printIp("Address: http://", ether.myip);

 //this works
//  if (!ether.dhcpSetup())
//    Serial.println(F("DHCP failed"));

  //Find ip address of a time server from the pool
  if (!ether.dnsLookup(poolNTP)) {
    Serial.println("DNS failed"); //with static setup this line is executed, not so with DHCP
  }
  ether.printIp("Lookup IP   : ", ether.hisip);
}

void loop () {}

I'd suspect gateway IP is not set and DHCP provides it.

@KIIV As John Burger suggested in his answer that's probably one mistake, but it's not solved yet even with adding dns ip as well (see comment there)

BTW: why don't you set fixed IP on your DHCP for this device? It could save you these troubles.

@KIIV Sounds good but what do you mean? The documentation says dhcpSetup() doesn't take any parameters, so no way to give it my ip?

You can set it on your router side.

DHCP does more than just give you your IP address: it also gives you the Net Mask, the Gateway IP address, and the DNS Server IP address. If you don't call dhcpSetup(), you'll have to do it yourself.
According to the EtherCard documentation, you can do that as follows:
const static uint8_t ip[] = {192,168,0,100}; // Example
const static uint8_t gw[] = {192,168,0,254}; // Example
const static uint8_t dns[] = {192,168,0,1};  // Example

...

if (!ether.staticSetup(ip, gw, dns)
{
    // handle failure to configure static IP address
    // (current implementation always returns true!)
}

Thanks! I didn't know DNS lookup needed more than my ip address. I found my Gateway ip through an ipconfig command (windows), I'm currently searching what the DNS server ip address should be.

I found the dns ip with doing a DHCP setup and then printing ether.dnsip, and when I print it again after the static setup the ip shows correctly but still the dns lookup fails. Any idea what misses more?

A second look at the documentation solved it! I just had to add the netmask as well, after printing it (after DHCP) with ether.netmask.

the documentation of ethercard.h and examples doesn't fit the actual version of ethercard very well.
for static ip setup use:
ether.staticSetup(myip, gwip, dnsip, netmask);

then the dnslookup works. most examples use the old mymask name, that is replaced by netmask


text:
How to use Serial Monitor without Arduino board?
I want to use Arduino(atmega8) on breadboard using USBASP programmer and want to use Serial Monitor without using any Arduino board as ISP programmer.
My questions: 1. Is such thing possible?
2. How do I do that?

How to use Serial Monitor without Arduino board?

Yes that is possible. Connect to the RX/TX pins on the breadboard chip. Remember these are 5V. You will need an Serial-USB or RS232 adapter to connect your development machine. Please see this blog post for some inspiration.
Cheers!

Don't forget to also connect GND.

I stripped a USB cable and connected its green wire to RX and white wire to TX and red/black to supply pins of atmega8. But my PC is not detecting anything. (Atmega8 contains a arduino bootloader burnt using AVRDUDE and a basic analog to serial program. Please suggest where I am wrong.


text:
How do I know if bootloader flash was successful?
I just bought a raw Atmega328p microcontroller. I am attempting to flash it with the Arduino bootloader.
The process seemed relatively straightforward as I had just followed the posted tutorial (https://www.arduino.cc/en/Tutorial/ArduinoISP).
Everything seemed to go fine and I even got a message after the second attempt with a message of 'Burning Bootloader Done'. I am targeting the device as if it were an Arduino Pro Mini.
I then moved onto program the chip with an Arduino sketch via the FTDI programmer. However, the sketch upload fails. It says that it is out of sync. I verify that everything is wired up correctly, yet it still fails. I then remove power to the Atmega328p chip (just to see if I get a different error) yet I still get the out of sync error.
This has me questioning whether or not the bootloader was even flashed in the first place. So how do I know if the bootloader actually was successful? A couple things to note:

When I power on the Atmega328p, the PB6 output starts blinking immediately. I would assume that if there were a bootloader, there would be a moment of pause until the regular program starts. Should I expect to see a pause if the bootloader is on the chip?
If the bootloader is on the chip, should I even expect to see the Atemga328ps default heartbeat?
When I flash the chip with the bootloader, it says that it could take up to a minute to finish. However, it only takes 6 seconds until it states 'Bootloader Finished Burning'. This seems like it's happening too fast.

If we determine that the problem is due to something else (i.e. not the bootloader), I will begin a new discussion. However, right now I'm just curious how I know if the bootloader is actually on the device.

The LED blinks while the bootloader is running. That is the only "heartbeat" there is. If it blinks forever then there is no sketch installed.

See my page about burning bootloaders.
The sketch there has a "verify" option so you can check if the bootloader was burned.
See my post What happens when code is uploaded using the bootloader?.
With Optiboot installed you expect to see three flashes:

As for your other problems, see Have I bricked my Arduino Uno? Problems with uploading to board.
You may well not have set the fuses correctly.


text:
Why does the current drop through a multiplexer?
I am trying to control 64 leds through a number of 8:1 analog multiplexers. The input is from pin 11 on the Arduino which is giving 40mA (maximum) and it is pulsed at 38kHz. Then I use other pins to select one of 64 leds to control. For testing, I am just trying one of those leds. The problem is that the current across the led is just 2mA, which means it is very dim. Using a multimeter, the current after the first multiplexer seems to be 4mA and after the second just 2mA. How can I get the current to increase? Thanks in advance!

Please add circuit. Guess you are using 4051. The internal resistor is approx. 70 ohm. Please see http://www.ti.com.cn/cn/lit/ds/symlink/cd74hc4051-ep.pdf

Analog multiplexers are a silly choice for a digital signal. Be sensible.

Don't depend on a digital output to provide you 40mA. That is the maximum current it can provide before getting damaged.

Analog multiplexers are not a good design choice for switching digital signals.
You should instead choose a digital solution. Maybe the 74HC138 would be a better choice? That's a 3-to-8 decoder with 3 enable inputs.
You could use 9 of them to reduce pin usage on the Arduino, or 8 of them if you have pins to spare.
One of the enables on the first-stage can be a "mater enable" - or tie one of the enables of all 8 of the second-stage together for a "master enable". Another enable to all the 8 second-stage muxes can be the PWM signal. The third is driven by the Arduino or the first stage as a MUX selector.
Something like this arrangement:

Note that the outputs are active low, so you would connect the anode of your LEDs to +5V and the cathode, through a suitable resistor, to the output.
Another option would be to use a set of shift registers that have an output enable pin. Drive that pin with the PWM signal and you can have any combination of LEDs enabled at once.


text:
Absolute noob looking for troubleshooting help
My 10-year-old son went to a "Robotics Camp" and came home with a non-functional Arduino robot. I figured it shouldn't be too much trouble to get it working. He swears he had it operating at the camp, but our best efforts notwithstanding, we were unable to reproduce his successes at home to any degree at all. Currently we seem to have an ungainly, $400 paperweight.
I'm a .Net web-developer by day, but I'm completely uninitiated when it comes to Arduino. I did enough research to learn how to upload a basic sketch- the "Blink" sketch- to our board an verify that the board is functional. Upon uploading the Blink sketch we got a flashing red LED. I was able to go into the sketch and modify the the variable values and see the results in the duration of the LED flash after uploading the sketch again. So I'm confident that we have a good connection to the PC and a functioning Arduino board.
But beyond that I'm stumped. When I attempt to upload the program that my son brought home, the robot does nothing. I can see a red LED blink a few times on the Arduino, but other that that, nothing happens.
Here's some photos of our setup:

Here's the sketch that my son brought home:
/***************************************************
  This is an example for our Adafruit 16-channel PWM & Servo driver
  Servo test - this will drive 16 servos, one after the other

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/815

  These displays use I2C to communicate, 2 pins are required to
  interface. For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <QueueList.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#define SERVOMIN  300//150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  400//600 // this is the 'maximum' pulse length count (out of 4096)

uint16_t servoMins[] = {160, 200, 500, 150, 150, 150, 0};
uint16_t servoMaxs[] = {600, 600, 700, 600, 600, 600, 0};
uint16_t servoHomes[] = {380, 400, 300, 340, 375, 375, 0};

enum GroupType {WithPrevious, NewGroup};

#define PAUSE_COMMAND 6
#define NUM_TRANSITIONS (PAUSE_COMMAND+1)

unsigned long currentTime;

class transition
{
  private:
    unsigned long startTime;
    unsigned long totalTime;
    uint16_t pulseLenStart;
    uint16_t pulseLenEnd;
    uint16_t currentPulseLen;
    int id;
    bool transitioning;

  public:
    void init(int id, uint16_t current)
    {
      this->id = id;
      currentPulseLen = current;
      totalTime = 0;
      startTime = 0;
      pulseLenStart = current;
      pulseLenEnd = current;
      transitioning = false;

    }

    uint16_t calculate(unsigned long currentTime)
    {
      float t = 1.0f;
      if (totalTime > 1e-3f)
        t = (currentTime - startTime) / (float)totalTime;
      t = (t > 1.0f) ? 1.0f : t;
      currentPulseLen = (uint16_t)(((float)pulseLenEnd - (float)pulseLenStart) * t + pulseLenStart);
/*      if (transitioning)
      {
        Serial.println("transitioning");
        Serial.println(id);
        Serial.println(t);
        Serial.println(currentTime);
        Serial.println(startTime);
        Serial.println(totalTime);
        Serial.println(pulseLenStart);
        Serial.println(pulseLenEnd);
        Serial.println(currentPulseLen);
      }
*/
      if (t >= 1.0f)
        transitioning = false;
      return currentPulseLen;
    }

    void createTransition (uint16_t pulseLen, unsigned long time)
    {
/*      Serial.println("create Transition:");
      Serial.println(id);
      Serial.println(pulseLen);
      Serial.println(time);
*/
      pulseLenStart = currentPulseLen;
      pulseLenEnd = pulseLen;
      totalTime = time;
      startTime = currentTime;
      transitioning = true;
    }

    bool isTransitioning()
    {
      return transitioning;
    }
};

transition transitions[NUM_TRANSITIONS];

struct Command
{
  uint16_t pulseLen;
  unsigned long totalTime;
  int commandType;
  GroupType groupType;

  void execute()
  {
    transitions[commandType].createTransition(pulseLen, totalTime);
  }
};
QueueList<Command> commandQueue;

void program ();
void restoreHomePositions (double seconds);

void setup()
{
  pwm.begin();

  Serial.begin(9600);
  Serial.println("Hello world");

  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates

  for (int servoNum =0; servoNum < NUM_TRANSITIONS; servoNum++)
  {
    //pwm.setPWM(servoNum, 0, servoHomes[servoNum]);
    transitions[servoNum].init(servoNum, servoHomes[servoNum]);
  }

  restoreHomePositions (0);
  program();
  restoreHomePositions (.75);

  yield();
}

void processCommandQueue();

void loop()
{
  currentTime = millis();

  processCommandQueue();

  for (int servoNum = 0; servoNum < NUM_TRANSITIONS; servoNum++)
  {
    if (transitions[servoNum].isTransitioning())
    {
      uint16_t pulselen = transitions[servoNum].calculate(currentTime);
      if (servoNum != PAUSE_COMMAND)
      {
        pwm.setPWM(servoNum, 0, pulselen);
        Serial.println("setPWM");
        Serial.println(servoNum);
        Serial.println(pulselen);
      }
    }
  }
}

bool isTransitioning()
{
  for (int servoNum = 0; servoNum < NUM_TRANSITIONS; servoNum++)
  {
    if (transitions[servoNum].isTransitioning())
      return true;
  }
  return false;
}

int frame = 0;
void processCommandQueue()
{
  if (!commandQueue.isEmpty())
  {
    Serial.println("Frame");
    Serial.println(frame);
    frame++;
  }
  if (!commandQueue.isEmpty() && !isTransitioning())
  {
    do
    {
      Command top = commandQueue.pop();
      top.execute();
    }
    while (!commandQueue.isEmpty() && commandQueue.peek().groupType == WithPrevious);
  }
}

void move (int commandType, uint16_t pulseLen, double seconds, GroupType groupType = NewGroup)
{
  Command command;
  command.groupType = groupType;
  command.commandType = commandType;
  command.pulseLen = pulseLen;
  command.totalTime = (unsigned long)(seconds * 1000);
  Serial.println("Command:");
  Serial.println(groupType == NewGroup ? "NewGroup" : "WithPrevious");
  Serial.println(commandType);
  Serial.println(pulseLen);
  Serial.println(command.totalTime);
  commandQueue.push (command);
}

void rotateWrist (int percent, double seconds, GroupType groupType = NewGroup)
{
  percent = percent < -100 ? -100 : percent;
  percent = percent > 100 ? 100 : percent;
  uint16_t pulseLen = map (percent, -100, 100, servoMins[5], servoMaxs[5]);
  move (5, pulseLen, seconds, groupType);
}

void bendWrist (int percent, double seconds, GroupType groupType = NewGroup)
{
  percent = percent < -100 ? -100 : percent;
  percent = percent > 100 ? 100 : percent;
  uint16_t pulseLen = map (percent, -100, 100, servoMins[4], servoMaxs[4]);
  move (4, pulseLen, seconds, groupType);
}

void rotateForeArm (int percent, double seconds, GroupType groupType = NewGroup)
{
  percent = percent < -100 ? -100 : percent;
  percent = percent > 100 ? 100 : percent;
  uint16_t pulseLen = map (percent, -100, 100, servoMins[3], servoMaxs[3]);
  move (3, pulseLen, seconds, groupType);
}

void bendForeArm (int percent, double seconds, GroupType groupType = NewGroup)
{
  percent = percent < -100 ? -100 : percent;
  percent = percent > 100 ? 100 : percent;
  uint16_t pulseLen = map (percent, -100, 100, servoMins[2], servoMaxs[2]);
  move (2, pulseLen, seconds, groupType);
}

void bendUpperArm (int percent, double seconds, GroupType groupType = NewGroup)
{
  percent = percent < -100 ? -100 : percent;
  percent = percent > 100 ? 100 : percent;
  uint16_t pulseLen = map (percent, -100, 100, servoMins[1], servoMaxs[1]);
  move (1, pulseLen, seconds, groupType);
}

void rotateRobot (int percent, double seconds, GroupType groupType = NewGroup)
{
  percent = percent < -100 ? -100 : percent;
  percent = percent > 100 ? 100 : percent;
  uint16_t pulseLen = map (percent, -100, 100, servoMins[0], servoMaxs[0]);
  move (0, pulseLen, seconds, groupType);
}

void pause (double seconds)
{
  move (PAUSE_COMMAND, 0, seconds, NewGroup);
}

void restoreHomePositions (double seconds)
{
  rotateRobot (0, seconds, NewGroup);
  bendUpperArm (0, seconds, WithPrevious);
  bendForeArm (0, seconds, WithPrevious);
  rotateForeArm (0, seconds, WithPrevious);
  bendWrist (0, seconds, WithPrevious);
  rotateWrist (0, seconds, WithPrevious);

}

//This is where the program goes!

void program ()
{
    //Available commands
  /*rotateWrist (where, seconds, groupType)
  bendWrist (where, seconds, groupType)
  rotateForeArm (where, seconds, groupType)
  bendForeArm (where, seconds, groupType)
  bendUpperArm (where, seconds, groupType)
  rotateRobot (where, seconds, groupType)
  pause (seconds)*/

  //example 1 -- rotates the wrist servo 100% over 2 seconds,
  //starting a new transition group.
  rotateWrist (100, 2);
  //example 2 -- bends the upper arm and the forearm at the same time
  //moving both 45% over 1.5 seconds.
  bendUpperArm (45, 1.5);
  bendForeArm (45, 1.5, WithPrevious);
  bendForeArm(45, 1.7, WithPrevious);

}

  //To start a new group, the groupType should be either NewGroup or left blank
  //Any call after that set to WithPrevious will start the transition at the
  //same time as the first transition in the group.
  //As soon as a new call is made with a NewGroup groupType, a new transition group is m
// End of your program

I wanted to include more photos, but I don't have enough reputation. :(

Plug the power pack in? What does the second board do? It is hard or impossible to help without some sort of schematic. Do you get any output in the serial monitor (eg. "Hello world"). I am guessing the second board is a motor driver board. You could get a cheap multimeter and start measuring voltages to see if anything is being sent to the motors.

It sounds like you have a working Arduino, so the money isn't wasted. This could be a good opportunity to disconnect the robot for now, and just bring yourselves up to speed with simpler sketches (programs). There are quite a few examples that ship with the IDE. Once you have a bit more confidence in how it all hangs together, getting the robot working should be simpler.

My first step would be to (after documenting the current connections!) disconnect everything and write a simple program to "wave" one of the servos. Then try connecting more parts from there. This sort of troubleshooting experience (when it works) is priceless by the way.

@NickGammon The second board is an Adafruit 16 channel PWM and Servo Driver

I'm still curious to know if the power pack is plugged in or not. Naturally it won't work if the servo driver is not powered.

@NickGammon Yes, of course the power adapter is plugged in when I'm trying to run the sketch. I left it unplugged for the photo, just so it would fit in the frame. I can verify that the servos are getting power, because when I first plug in the power adapter several of them do a little jerk. After that though, nothing happens.

@NickGammon regarding your suggestion to test the setup with simpler sketchs, I have successfully run the Blink sketch that is packaged with the Arduino IDE. I am able to use it the Blink sketch to power the red LED on the Arduino board on and off. I can change the values of the variables in the blink sketch and observe the effect this has on the duration of the LED flashes.

Here's the code for the Blink sketch: `// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
delay(1000);              // wait for a second
digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
delay(1000);              // wait for a second
}`

@Majenko, My big question at the moment is whether or not I have the Arduino board wired up to the PWM servo driver correctly. How can I check this?

On my page about I2C I have a sketch that detects I2C devices (reply #6). It looks like the PWM board uses I2C, so run that sketch and see if it reports any devices (in particular 0x40).

For debugging, do you have a DVM (voltmeter)? Or even better yet, an oscilloscope? You mention seeing the servo twitch but not seeming to operate correctly, so I'm wondering whether the power supply voltage might be sagging under load. You might also verify whether the I2C SCL and SDA wires got swapped, or whether there is a missing GND connection.

I'm not familiar with the breadboard in your images. You didn't mention if you're familiar with how to use a breadboard and from what I can see I'm not even sure why its being used. It looks to me like you could just connect the jumper wires directly to the pins on the Arduino.
Was the Arduino ever unplugged from the breadboard after it was known to work properly?
Due to the angle of the photo it is hard to see which pins the wires are connected to. Can you identify which Arduino pins the six wires are connected to?

The breadboard is a standard one with lines of five connected terminals radiating away perpendicular from a center channel (which is covered in that photo). Typically this is used to allow standard jumper wires to be connected to the board's header pins rather than having to use jumper wires with a female socket at one end, and it also allows multiple jumper wires easily to be connected to a single pin.

Please consider the following to assist in your understanding of the Arduino and of the servo operation. I recently "instructed" a summer camp of teens to construct the MeArm robot arm, using inexpensive servos and an Arduino.
The servos you have will operate without the servo driver, enabling you to isolate the problem. Consider to connect the signal wire for each servo to an assigned pin on the Arduino and test each servo with the built-in Sweep sketch. Your off-board power for the servos should share the ground with the Arduino, while the +V would connect to the power lead for the breadboard and hence to the servos.
Pins 6, 9, 10, 11 are PWM capable and you can modify in the Sweep sketch to operate each one independently as a way of testing the base "kit."
The code for Sweep is simplistic, while the servo driver has a good bit of "middle-man" calculations to accomplish more refined control.
Example from the summer camp:
[in setup]
claw.attach(9);
inout.attach(10);
updown.attach(11);
rightleft.attach(6);
[in loop]
 - the following was placed in a for-loop:
claw.write(pos);
... and more code including delays and limits to pos to prevent servo chatter/slam.
This will likely show you that your servos are working (or not) and enable a better understanding of the basics, while perhaps increasing your chances of understanding the more complex and flexible servo board library of code.


text:
WizNet W5100 not connecting to modern switches and routers
I have an Arduino data collector with a W5100 module (see bottom of picture). Simple fixed IP connection:
 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
 byte ip[] = { 192, 168, 1, 242 };
 Ethernet.begin(mac,ip);

This works with my old routers (Asus WL500, TP-Link MR3420), but fails to connect when plugged in a gigabit switch or my new router (D-Link DWR-116). The connection LED on the new devices does not lit up or blinks slowly, showing repeated connection attempts. So the W5100 fails to make the physical connection.
I made it work by adding my 10-year old Surecom switch to the mix, but wonder what the problem could be. Is there some cable configuration that is used by the W5100 but have been removed from these new network devices? (Not sure if the cable is cross or straight, trying another cable is messy, the whole thing is built in the wall.)

Check the IP address. Might not be the correct sub-net.

I did that already. Both routers are set to 192.168.1.1. Also, replacing the router is not the only way to make it go wrong, it was enough to plug it to the switch instead of the (old) router.

Check the Ethernet module power supply.

This thing has been running continuously for 4 years now. It just stops working when I try to plug it in to a modern router or switch.

I think your problem is due to the MAC address that is being loading into the W5100.  Try setting the 2 low order bits of the first byte to 0.
These bits define whether the MAC address is unicast or multicast and whether it is private or universal.  Some switches appear to block ARP requests if these bits are set incorrectly.
I changed the first byte of the MAC address from x'47' to x'44' and things started working.

Thanks, great tip! Experimented a little, with strange results: my router accepts x46 but not x44, and my switch accepts x44 and refuses x46. Left it at x46, it doesn't need a Gigabit switch to send a few bytes.

I just made a setup on my Dell PowerConnect and it starts to accept the W5100.
I had to change the port speed to 10M and it starts working. The 100M and 1000M was not accepting the w5100.
Before, I had a CISCO wifi 10/100M wired connection between it and w5100 and it connects fine, but this isn't the main network on my company.

sounds like a mac address issue.
I googled for Tp-Link MAC address bytes and it worked perfectly. (it is first 4 bytes)

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


text:
Arduino Due SPI will not loop
Help please
I am trying to connect an Arduino Due via a SPI bus to a MAXIM31855 thermocouple sensing chip. I am using Arduino IDE version 1.6.11.
The problem I am having is that the code will only read the SPI bus once, it will not loop, regardless of how many times I call the function to read the SPI bus.
I have connected the clock and the MISO to the pin header just below the SAM processor chip its labeled SPI and I have connected the CS to pin 4.
Each time I press the reset button on the Due, the SPI will read once. I have confirmed this by using a Salae logic analyser. The Due doesn't lock up as other functions continue normally, it simply will not repeat the SPI read.
The 4 bytes that are returned from the Max are consistent with the specification for the chip as are the timing of the clk (4kHz) and the MISO logic levels (there is no MOSI in this MAX chip).
If anyone has a clue as to why this will not loop I would appreciate their input.
Cheers
#include <SPI.h>
//Give convenient names to the control pins

#define slaveAPin 10
// set up the speed, data order and data mode
SPISettings settingsA(4000000, MSBFIRST, SPI_MODE1);

void setup() {

  Serial.begin(9600);
  pinMode(slaveAPin,OUTPUT);
  SPI.begin(slaveAPin);

}

uint8_t  val1, val2, val3, val4;

void loop() {
// read four bytes from device A
 Serial.println(ReadTemp());
 delay(1000);

 }

uint8_t ReadTemp(void)
{
  SPI.beginTransaction(settingsA);
  digitalWrite (slaveAPin, LOW);
  // reading only, so data sent does not matter
  val1 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  val2 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  val3 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  val4 = SPI.transfer(slaveAPin,0x00,SPI_LAST);
  digitalWrite (slaveAPin, HIGH);
  SPI.endTransaction();

  return val2;

}

Where's your main function?
Does it have a forever loop?

Call the SPI Transaction in void loop and then print val2 and let us know the results. I don't know if Serial.println can take functions as an argument.

@ammar.cma it's not taking function as an argument. It's taking result from function call (type is uint8_t).

Check this bug report; https://github.com/arduino/Arduino/issues/1406. Might need to update the Arduino IDE with the latest Due version.

@KIIV yeah. Function call :/


text:
Can i supply the AREF pin with an Analog pin from the same board?
I guess its a dumb question but couldnt find anything about it online. I know its possible to supply the AREF pin with 3.3 V to increase the ADC resolution.
For the project i am working on the analog voltage i will be reading will be between 0 and 2.2 and the increased resolution is a must.
I know i can use another board that has a 12 bit resolution but i really would like to make do with Uno. So i wonder if i can set an analog pin to output 2.3 V and feed it to the Aref pin.
If thats not possible please let me know why, so i can increase my knowledge

With an input voltage between 0 and 2.2 V, you can use a 2:1 voltage divider to cut the voltage in half.  In your code, use analogReference(INTERNAL) to set the analog reference voltage to 1.1 V.  The 1.1 V internal reference voltage is created by a bandgap circuit so is reasonably accurate.
To make the voltage divider, put two equal resistors (eg 10KΩ each) in series; connect one end of the series to your input voltage, the other end to ground, and the mid-point to an analog input pin.

Once you set the analog voltage to the internal bandgap voltage source, you can measure the actual voltage on the AREF pin using a multimeter. You can use that voltage to "calibrate" that arduino.

@Gerben That seems like easiest option, thanks for the further explanation. I also checked the oversampling, which i have never heard of before. It also seems quite valid. Again thanks for the heads up

The output voltage of the "analog outputs" (which are actually PWM) are dependent on supply voltage and so are not a good choice where precision is required. Consider using either an integrated voltage reference (e.g. TL431) or a constant-current source feeding a zener diode instead.

Thanks for the quick reply! The things is i really try to refrain from using another circuit, allthough its relatively easy to use, the target users will have no idea how to set it up. The resolution i need is not that much, just 2.5 V /1024 instead of 5 V / 1024. sadly 3.3 V wouldnt do. Is the way i suggested still too unreliable in these conditions ? And if it is do you have any other suggestion that would not require another component ? thanks in advance!

@Firat.Berk.Cakar You could try oversampling to get better resolution.


text:
Arduino MPU6050 Control 2 Servo
I'm new to gyroscope and accelerometer and am working on my project to control servo with Arduino Uno R3 based on the reading from InvenSense MPU6050 6DOF gyroscope and accelerometer. I've found the a same sheet of code from different websites.
Website 1_http://www.projehocam.com/wp-content/uploads/mpu6050-2-servo.txt
Website 2_http://www.instructables.com/files/orig/FLY/GZAL/IDIN48PC/FLYGZALIDIN48PC.ino
And from this part of the code, I couldn't understand the servo.write part...
    #ifdef OUTPUT_READABLE_YAWPITCHROLL
        // display Euler angles in degrees
        mpu.dmpGetQuaternion(&q, fifoBuffer);
        mpu.dmpGetGravity(&gravity, &q);
        mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
        Serial.print("ypr\t");
        Serial.print(ypr[0] * 180/M_PI);
        Serial.print("\t");
        Serial.print(ypr[1] * 180/M_PI);
        myservoY.write(int(ypr[1] * -180/M_PI)+90);   // Rotation around Y
        Serial.print("\t");
        Serial.println(ypr[2] * 180/M_PI);
        myservoX.write(int(ypr[2] * 180/M_PI)+90);   // Rotation around X
    #endif

Why is the operation (int(ypr[1] * -180/M_PI)+90) ??

ypr contains the Yaw, Pitch and Roll. It is provided in radians.
Servo.write takes degrees.
Multiplying radians by 180/PI converts it to degrees.  Adding 90 centralises it around the 90 degree point (half way) of the servo.


text:
externally powering the Arduino questions
I have several questions on externally powering the Arduino Uno

I have a 7.2V power source that is 6 rechargeable AA batteries together, 1.2V and 1300mA each. If i use a 4.70 and 1.5 ohm resistors together to give 1.16 amps, can I power the arduino with this?

Can I power a servo off the Arduino 5V rail If i place a 470uF or more capacitor alongside it?
Will anything heat or blow up or am I just being paranoid like always?

Why would you use resistors?

(1) Which Arduino model?  Power supply varies between different kinds of Arduinos.  (2) In any case, using a voltage divider (if I understand correctly) to step down power supply voltage is a wrong idea.

I said arduino uno rev 3 is the model
Why is using a resistor bad for bringing power down?
The arduino said it needs around an 1 amp to work well.

DEFINE your surge load current or DCR of motor and Uno schematic plus any external loads.  Some use MC33269D with 1.25V drop on regulator to 5V for different current ratings.

The reasons why not to use voltage dividers to step down power supply voltage have been discussed in depth here and here.  I doubt that an Arduino needs 1A to work well.  I suspect that you are misreading the current rating; so read this.

Is it a genuine Arduino Rev3, or a 'clone'? AFAICT, their are clones which are not electrically identical to a genuine Arduino/Genuino.

I am guessing that you are thinking of dividing down the battery voltage from 7.2V down to 7.2*(4.7)/(4.7+1.5) = 5.5V. This is generally a bad idea for a few reasons.

The battery voltage will not be a constant 7.2V. When they are fully charged it could be even higher. As they discharge they could drop significantly and your Arduino POR (power-on-reset) circuit would potentially shut the board down before the batteries are fully discharged
The batterys' internal resistance would probably drop the output voltage considerably once the resistors try to draw 1A of current. It might even collapse the voltage to some unusable value.
Even if the battery internal resistance is very low and even if the Arduino is not drawing much power (or even off) you will always be drawing ~1A of current from the batteries. This will rapidly drain your batteries and will also heat them up from their internal resistance. Not to mention your external resistors better be able to handle > 5W or so. Conclusion: lots of unnecessary heat and power loss.

To answer your other question, assuming the servo is low power and the Arduino power supply is up, you could power it from the Arduino 5V supply (not your batteries).
If you need to use batteries to power an Arduino, I would highly recommend a power regulator to produce a stable output voltage to power your Arduino.

This question has been answered on electronics.stackexchange, e.g. How to provide separate voltages from a common power source
Daniel V has explained the main issues.
The 'killer' for most people is the resistors are always across the battery, and so they alone will take over 1A from the battery pack continuously, and hence run it flat in just over an hour. Further, they need to dissipate over 5W of heat, so they aren't that cheap either.
A NiMh rechargeable battery will have a voltage of about 1.4V when it's fully charged, dropping to under 1V before it is exhausted. So that would mean the resistor network needs to output 5V or less with an input voltage from 6x1.4V=8.2V down to under 6x1V=6V.
So the resistor ratio would need to handle 8.2V in and produce 5V out, and then 6V in would produce 3.66V. My reading of the ATmega sec is it might struggle to run at 16MHz at that 3.66V input voltage.
You might try to make a resistor-based voltage divider more efficient by increasing the total resistance.
However, as explained on the electronics.stackexchange, the load presented by the ATmega on an Arduino varies dynamically, from microsecond to microsecond, so it is very hard to choose resistors which would maintain the voltage within a reasonable operating range, while the current passing through the Arduino varies so much.
An Arduino has an on-board voltage regulator.
However, the typical 5V regulator on generic Arduino's have a drop-out voltage of 2V, i.e. the input voltage needs to be 7V or more. That means most of that battery pack capacity will provide less than 7V, so the voltage will start to drop.
You might be lucky and the on-board regulator will 'track' the input voltage down. That means it will fail below 5V as its input drops below 7V. You would need to test your Arduino; there is no guarantee that the regulator on the board does this. Further, it might struggle to run at 16MHz as the voltage approaches 4V.
So, if this is just a one-off hobby project, it might be reasonable to try that. However, if other people are going to use it, it might be too risky.
The ATmega can be run with anything between 5V and 1.8V if the clock is slow enough. Also you'd need to either modify the electronics, or change the bootloader of the Arduino to ensure it runs at a much lower clock frequency. So it is possible to run at a lower voltage than 5V, by changing the bootloader, but it seems like a strange exercise. Then a resistor divider (which wastes a lot of energy), or the on-board regulator could be used.
Instead, look at a Low-Drop-Out (LDO) voltage regulator. There are parts which will regulate anything from 8.4V down to 6V, or less, down to 5V. An Arduino alone uses well under 100mA, it is the electronics it is driving which uses the majority of an Arduino's specified 500mA.
So you look for a voltage regulator, which will take 9V in (as a safety margin) with a drop-out voltage of 0.7V (lots at this spec), 5V out, and 250mA or better. Most electronics distributors have a product selector which will help you find this, and you may find small ready-made modules which do exactly this (but not an LM111xx).
You don't post a link to the servo you're using.
Low-cost servo's typically take a lot of current as they move. I've measured some using a proper bench power-supply unit (bench PSU). They typically take well over 1A for periods long enough for me to see it happen. So the power supply would likely need to supply more than 1A for short periods, i.e. 10's of milliseconds. You will need quite a substantial capacitor to handle that.
Depending on the servo, you might be better to use 4xNiMh to power the servo directly, without any intermediate regulation, and a more modest capacitor. The ground (-) of that power supply needs to be connected to the GND of the Arduino so that the servo signal from the Arduino will drive the servo correctly.
In that case, you might use a low-cost (ebay) DC-DC step up (boost) switching regulator to provide the 5V to the Arduino. Their are lots available which are intended to power USB devices at 5V.

Your typical Arduino has a built-in 5V regulator. Just plug the batteries into the barrel jack - that is what it is for.
If you don't have a barrel jack on your Arduino (it's one of the little ones?) then you will need a voltage regulator. For battery usage you want a switching "buck" regulator.
You can find them cheaply enough under the name "UBEC" (Universal Battery Elimination Circuit) and are used for model aircraft etc.

You can connect the batteries fine into Vin or the barrel jack, however you will run into the issue that your battery voltage will sag. This will vary on what chemistry batteries you are using, NiMh voltage discharge sits on a bit of a plateau around 1.2V typically, alkaline has more of a gentle curve downwards and then drops off quite sharply around or below 1V.
The reason this is an issue is highlighted on the Arduino Uno page itself:

Input Voltage (recommended)   7-12V
Input Voltage (limit)  6-20V

and

The board can operate on an external supply from 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may become unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts.

The issue here is the dropout of the onboard regulator.
The solution is to use your own external regulator and connect it to the 5VDC pin.
You can use:

An external swithcmode DC-DC converter, you would be ideally after a buck boost. DC-DC converters are available from ICs for a full ground up DIY design to available on board modules and daughterboards and fully assembled circuits. Regarding the other answer a BEC or UBEC may not be suitable as typically they are buck converters and have higher minimum output voltages than that required by the OP, some however with careful selection may be alright to use.

Adafruit off the shelf buck-boost module:
https://www.adafruit.com/products/2190

An external linear LDO regulator, ideally with as low dropout as possible. You will need to pick this part to suit your input voltage range, this may be difficult as extremely low dropout parts are typically low current and not suitable if wanting to drive a servo. Something like a REG103 for example may work, depending on the dropout an LDO linear regulator may work down to around 5.2~5.3VDC minimum, which should be okay for most of the capacity of the batteries.

A premade shield, some may work for you, some to give you an idea of what is required.

DC-DC converter for battery shield:
https://www.wayneandlayne.com/projects/battery-booster-shield/
Adafruit has a lithium battery shield such as does Sparkfun (not enough rep for more links)
Itead has a AAA battery shield also.
Options here will depend on your design ability and assembly skills as to if you can DIY or need off the shelf.
Your servo will be fine connected to the external regulator as long as the option you use is rated to supply enough current.


text:
Sending data from Arduino w/HM10 to relay board with hm12
It all started when I tried connecting an hm10-nano to a relay board which is Bluetooth enabled.  Here is my nano with the hm10 module:

And here is the relay board's BT module, which looks like an hm12:

I started by connecting the nano-hm10 to my mac and using the Arduino IDE to send the module commands.  The hm12 has a mac for ble and another for edr:
ble:00-0e-0b-00-75-12
edr:00-0e-0e-00-75-12
The hm10 does connect because:

I get a steady blue led on the hm10 after AT+COmacble
I get the macble from the hm10 module after AT+RADD?
I hear the relay (channel1) open on the relay board after AT+COmacble

When I try the following steps -> I get these results
1. Unplug relay board -> hm10 blue blinking
2. Plug relay board -> hm10 blue steady, relay BT module blue led steady
3. AT commands to hm10 thru serial monitor stop working (expected)
4. AT+CO000e0e007512 to hm10 -> turns on relay 1 for some reason
5. Unplug relay -> RADD on hm10 = 00-0e-0b-00-75-12 instead of 00-0e-0e-00-75-12
My questions are:
A. Is it possible to send data from an hm10 to hm12?
B. Why does the relay get activated when I connect to the hm12-relay board?
C. I just realized my sketch's bluetooth.print() sends a command from the nano to the hm10, not to from the hm10 to the hm12.  How can I send the data from the nano to the hm12?
Sketch:

#include <SoftwareSerial.h>
int bluetoothTx = 10;  // TX-O pin of bluetooth
int bluetoothRx = 11;  // RX-I pin of bluetooth
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup(){
  Serial.begin(9600);  // Begin the serial monitor at 9600bps
  delay(200);
  bluetooth.begin(9600);  // Start bluetooth serial at 9600
  Serial.print("send...");
  bluetooth.print("AT");
    bluetooth.print("110"); //open relay 1
    delay(2000);
  bluetooth.print("100"); //close relay 1
}
void loop(){
  if(bluetooth.available()){
    Serial.print((char)bluetooth.read());
  }
  if(Serial.available()){
    bluetooth.print((char)Serial.read());
  }
}

Try switching the rx and tx pins

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


text:
How to serially communicate arduino uno to PIC18f4550?
I am new in PIC programming
my question is, how can i communicate arduino UNO with  PIC18f4550. i am using THIS programmer board for PIC controller and it has a builtin RS232 serial interface.
Can any body tell me how to communicate between them. I want to communicate in such a way that only Rx & Tx pins and the power pins of arduino will be used.

yeah you can quite easily do the Serial communication between Arduino and PIC Microcontroller. You need to connect the below pins:

Arduino TX will be connected to PIC RX.
Arduino RX will be connected to PIC TX.
GND of Arduino must be connected to GND of PIC.

Next thing you need to remember is to have same baud rate for both Arduino and PIC. Now you should check these two posts:

Arduino Serial Communication.
PIC Serial Communication

First one is explaining the Serial Communication of Arduino while the second one is Serial Communication of PIC Microcontroller. You should also read What is Serial Port? to get more idea about Serial communication.
I hope they will help you out. If you still got into some issues then let me know.


text:
Arduino Nano stuck on uploading
I recently bought an Arduino Nano ( a clone actually), I installed the CH340G drivers for it and got it working perfectly fine... Played around with it for a while and then kept it aside...
Now after sometime I get time to play with it again, I was actually trying to power it with my 11.1V 2200mAh 8C LiPo battery. So I plug the JST connector to the Vin and GND pin and the LED doesn't light up. I noticed that I had plugged it in the wrong way and I immediately unplugged it. Next I make another attempt and this time I plugged the pins entirely somewhere else, again I disconnect quickly. The third time I connect it properly and the power LED lights up (phew...)
Now I move on to my computer to program it but the Arduino IDE is stuck at uploading. It was working fine before, when I hit upload, the RX LED glows VERY dimly and the board just stays like that. Only the power LED glows up, not even the LED on pin 13 glows up.
Uploading to a UNO works perfectly fine.
This is the error I get after a while-

avrdude: stk500_recv(): programmer is not responding
  avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x7d

Did I burn my board? Or is it just a bootloader issue?

So I plug the JST connector to the Vin and GND pin and the LED doesn't light up. I noticed that I had plugged it in the wrong way and I immediately unplugged it. Next I make another attempt and this time I plugged the pins entirely somewhere else, again I disconnect quickly. The third time I connect it properly and the power LED lights up (phew...)

Unfortunately Vin on an Arduino Nano does not have a reverse polarity protection diode such as the Arduino Uno PWRin

Did I burn my board?

Very probable. For more details please see "10 Ways to Destroy an Arduino".
Cheers!

that's not at all good... Now I'm gonna have to run around with a UNO strapped to my wrist instead of the Nano

It's unfortunate and I guess not the answer you where looking for. Please leave the question open if you need further answers or mark as answered.

I guess you've already answered the main point of the question so.. I'll mark it as answered.


text:
EthernetUdp2 does not name a type
I'm using arduino Ethernet shield 2 form arduino.org and the arduino IDE 1.7.10 also from arduino.org
the code is :
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet2.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp2.h>
#include <Twitter.h>
#include <util.h>

#include<SPI.h>

EthernetUdp2 udp;
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

and it is giving the following Error :
Arduino: 1.7.10 (Windows 8.1), Board: "Arduino Uno"

UDPMessages002.ino:14:1: error: 'EthernetUdp2' does not name a type

Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

after Enabling Show verbose output I got :
Arduino: 1.7.10 (Windows 8.1), Board: "Arduino Uno"

Build options changed, rebuilding all

Using library Ethernet2 in folder: C:\Program Files\ArduinoOrg\libraries\Ethernet2

Using library SPI in folder: C:\Program Files\ArduinoOrg\hardware\arduino\avr\libraries\SPI

C:\Program Files\ArduinoOrg/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=107010 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\ArduinoOrg\hardware\arduino\avr\cores\arduino -IC:\Program Files\ArduinoOrg\hardware\arduino\avr\variants\standard -IC:\Program Files\ArduinoOrg\libraries\Ethernet2\src -IC:\Program Files\ArduinoOrg\hardware\arduino\avr\libraries\SPI C:\Users\friend\AppData\Local\Temp\build8617491196975133384.tmp\UDPMessages002.cpp -o C:\Users\friend\AppData\Local\Temp\build8617491196975133384.tmp\UDPMessages002.cpp.o

UDPMessages002.ino:14:1: error: 'EthernetUdp2' does not name a type

Error compiling.

any Help please
These libraries came with the IDE and were not added by me and all the includes
were added automatically after using Sketch --> Import Library --> Ethernet2

The error you see, 'EthernetUdp2' does not name a type, means exactly that - there is no type EthernetUdp2 defined.
If you look at the source of EthernetUdp2.h, you'll see that the class declaration is EthernetUDP. See:
class EthernetUDP : public UDP {
    private:
        // Private members...
    public:
        EthernetUDP();  // Constructor

      // Public members...

};

class EthernetUDP : public UDP defines a class called EthernetUDP that inherets from the base class UDP. The constructor is what gets called when you instantiate a new object of type EthernetUDP.
Replace the line EthernetUdp2 udp; in your code with EthernetUDP udp; and it should work because the types will match. For reference:
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet2.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp2.h>
#include <Twitter.h>
#include <util.h>

#include<SPI.h>

EthernetUDP udp; // <---- This works

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Which one do you mean ?

class EthernetUDP : public UDP {

here ? or here : public:
EthernetUDP();  // Constructor

The first one. I'll edit to make it more clear.

but I'm using Ethernet shield 2 not 1

Right, but the class name is still EthernetUDP in the Ethernet2 library

As it was answered above by Cheirbriados, the library is EthernetUdp.h not EthernetUdp2.h. I'll post you an example code, but you can also analyze it by yourself, by going on tab Examples of the Arduino IDE and choosing Ethernet -> UDPSendReceiveString:
#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

That library is for the legacy Ethernet shield. The Ethernet Shield 2 (which the OP has) uses the Ethernet2 library, so your answer is likely incompatible with their hardware.


text:
Which Barcode Scanner to be used with arduino in India
I know this question is not so releavant as it does not include any research, but I am in search of a barcode scanner that i can easily interface with arduino and get output from it but unfortunately the Scanner models which are listed from the people doing the same stuff are not easily available in India. So if anyone knows which barcode scanner would best suit the requirement please suggest.
Availabilty in Indian market would be much appreciated :)

Most barcode scanners behave just like a regular keyboard.
Try getting one with a PS2 port. You can pretty easily interface a PS2 keyboard to an Arduino. There are already libraries for it.


text:
Uploading a sketch causing an error message in Arduino Uno
avrdude:

no programmer has been specified on the command line or the config
  file
           Specify a programmer using the -c option and try again

On the "Tools" menu choose "Programmer:" and specify AVRISP mkII; be sure that you've also chosen the appropriate "Board:" entry for the Uno.

yeah i  know all that but it keeps showing me the same error!!!

Describe your environment:  Windows? Unix, which one? Which version of the Arduino IDE?  Or, are you using Eclipse or another IDE?  Perhaps you need to re-install?  Has it ever worked?  Does, "Get Board Info" work?

Oh, are you trying to use the command line tool (avrdude?)

I fixed it. I just reinstalled the drivers.