text:
Increasing analogread speed on the Arduino Uno
I want to transfer data from my smartphon to the Arduino by using the audio jack of my smartphone. For this I need verry high reading frequencys.
I have used
bitClear(ADCSRA,ADPS0);
bitSet(ADCSRA,ADPS1);
bitClear(ADCSRA,ADPS2);

to boost analogread to ~10microseconds, which would be enough. But somehow I am still wasting 5.4 ms at the beginning of the transmission.
The only thing between signal start and first analogread is a start of a for loop:
while(analogRead(A0)<50) (true); //wait for start of transmission
for(i = 0; i<500;i++){
data[i]=analogRead(A0);
}

But does starting a for loop take 5.4 ms?
Do you have any ideas?

Before we spend any more time on this, what conversion speed/rate do you require?

Currently recieving a 40 bit packet takes about 10ms. I would consider 5ms a good value.

An Instructable on audio sampling got 125us per sample using analogRead(), down to 26us per sample by bypassing analogRead, reading straight from the register, and clipping to 8-bit resolution. See sections 5 and 6. I suspect that's pretty much as fast as it gets. http://www.instructables.com/id/Arduino-Audio-Input/?ALLSTEPS

I am allready at 10us. But between seeing the first signal and saving the next signal 5.4 ms pass.

So only the first cycle (i==0) takes 4.5ms, all the others (i>0) take 10uS? From the datasheet; A normal conversion takes 13 ADC clock cycles. The first conversion after the ADC is switched on (ADEN in ADCSRA is set) takes 25 ADC clock cycles in order to initialize the analog circuitry.. Try doing a dummy analogRead in the setup function.

@Gerben From while(analogRead(A0)<50) (true); to data[i]=... it takes 4.5ms. My signals are stronger than 50 and so the while loop stops and the next analogread is written to the array. But the array contains only values, which were send 4.5 ms before. So analogread is called many times before the actual measurement.

It sounds like you could benefit from interrupt handled free running sampling, doing that should get you sampling rates up to the maximum listed on the 328's datasheet, 76.9 kSPs. Although, that's at a reduced resolution. This site explains better, under the section "Free running sampling".

I did some further analysis on the signal and the problem was not the Arduino. It did everything quick and correct.
The problem was my smartphone. I used androids AudioTrack class and somehow it did cut off parts of the signal. This could be "fixed" by increasing the length of the signal. I just added 0's at the beginning and end.


text:
Incremental encoder code
can somebody tell me what`s wrong with my code, i am using it to calculate rpm using incremental encoder
long counter=0;
 long  rpm = 0, z =0;
 long  ini_time = 0;
long  end_time=0;

void setup(){
  attachInterrupt(0, A_RISE, RISING);

  Serial.begin(115200);
}//setup

void loop(){

    Serial.println(rpm);
}

void A_RISE(){
  counter ++;
  if (counter == 1)
    ini_time = micros();
  else if (counter>470){ //470 is ticks per revolution
    z = counter;
    rpm_counter(z);

    counter =0;
  }
}

void rpm_counter(int x){

  end_time=micros()-ini_time;
  rpm=(60*10^6)/end_time;

}

You need to tell us more about: what currently happens with your program, what you would expect instead.

it does not give any output in serial monitor @jfpoilpret

Can you clarify your wiring: which Arduino pin did you wire your encoder to?

i attached encoder`s channel A to digital Pin 2 on arduino which is interrupt 0.

What is weird is that you mention there is NO output on the serial monitor, which would mean thzn loop() is not even called? I suspect, your motor runs very fast and may generate too many interrupts which would prevent loop() from running.. Could you first try to add a delay in your loop (1 second would be fair) and see what happens?

Also, you could chnage the init order in your setup() to first Serial.begin(...), that would give time for serial init before triggering encoder interrupts.

Volatile.
Essentially any variable declared within global scope (anything you declare before you get to setup()) MUST have the volatile qualifier if you want to use it within an interrupt service routine otherwise it will not be correctly utilised/implemented/instantiated.
As your code stands, you need to add voltatile to all four of your global variables:
volatile int counter = 0;     // if you're stopping at 470, int is all you need
volatile long rpm = 0;
volatile long z = 0;          // this isn't necessary, see below!
volatile long ini_time = 0;
voltaile long end_time = 0;

Your ISR includes some wasteful instructions, which will increase the time it takes for the routine to complete. As @jfpoilpret suggested, you may be constantly interrupting loop(). Cutting the time down may solve this:
Firstly, z = counter; rpm_counter(z); . Pointless, if I'm honest. Why not just call rpm_counter with counter?
Secondly, rpm_counter() function... it doesn't use the arguement you sent! "x" is not used anywhere within the function, so why are you sending it?
Thirdly, even if my second point wasn't valid rpm_counter() doesn't really need to be a function in its own right. Unless you're going to be calling it from lots of different places, just inline the contents of the function to into A_RISE():
else if (counter>470)
{ //470 is ticks per revolution
    end_time = micros() - ini_time;
    rpm = (60*10^6) / end_time;
    counter = 0;
}

That could save a great deal of execute cycles.

“any variable declared within global scope [...] MUST have the volatile qualifier if you want to use it within an interrupt service routine”. This is incorrect. The volatile qualifier is needed if the variable is going to be used both in the ISR and in the main program. OTOH, if the variable is only used inside the ISR, it should be static local rather than global.

Could this be what's wrong with the code in my question here: https://arduino.stackexchange.com/questions/88812/variable-getting-set-to-zero-nondeterministically?noredirect=1#comment202751_88812

source: Stack Exchange

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

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

sort: votes


text:
Arduino screws up trivial program involving enum
Behold this insanity:
enum WhatArduinoIs {
  Easy, But, Insane, Obsolete, And, Far, Worse, Than, mBed
};

void TellMe(WhatArduinoIs pls) { }

void setup() { }
void loop() { }

I'm pretty good at C++, so I'm fairly sure that should compile. However I get this error:
sketch_jan21b.ino:3:13: error: variable or field 'TellMe' declared void
sketch_jan21b.ino:3:13: error: 'WhatArduinoIs' was not declared in this scope
Error compiling.

I've encountered the Arduino "IDE"'s propensity for insane and totally unrobust modification of programs before. Specifically when you #include libraries Arduino only magically adds the relevant C++ files if the #include is in your main sketch. #include <LiquidCrystal.h> in another C++ file? Link errors.
I suspect in this case it is Arduino magically trying to add function declarations to the start of the file so their order doesn't matter. I.e. it turns the file into this:
void TellMe(WhatArduinoIs pls);

enum WhatArduinoIs {
  Easy, But, Insane, Obsolete, And, Far, Worse, Than, mBed
};

void TellMe(WhatArduinoIs pls) { }

void setup() { }
void loop() { }

That obviously doesn't work. How can I tell Arduino to leave my damn program alone?

You can workaround the issue by putting your enum and function into a namespace. You can even take advantage of C++ unnamed namespaces if you like:
namespace
{
  enum WhatArduinoIs {
    Easy, But, Insane, Obsolete, And, Far, Worse, Than, mBed
  };

  void TellMe(WhatArduinoIs pls) { }
}

void setup() { }
void loop() { }

It's annoying (as are many things in the Arduino IDE), but it seems to work.
If you're more experienced with programming then you might want to consider using a 3rd party IDE with an Arduino plugin, such as Eclipse. The Arduino IDE is really only designed for beginners.

Or even something like Geany with (or without) Ino.

Thanks! I was going to say the only thing worse than Arduino's IDE is Eclipse, but I think actually I think even Eclipse might be better! I strongly prefer Qt Creator - I use that for mBed. I may have to finally set up Arduino in it. The problem is many details of Arduino's build system are hidden in Arduino.exe so it is a pain to set up any other IDE. Didn't know Eclipse had an Arduino plugin though.

There is also the free Atmel Studio Ide. It supports professional programming features like multiple source files, SVN and the AVR dragon debugger.

This is something that is getting fixed. Try the IDE linked here https://github.com/arduino/Arduino/pull/2729. The sketch will compile just fine.

Or you could just use a plain Makefile. There are a couple of generic Arduino Makefiles floating around, that do almost all the IDE does, except messing with your source.

You seem to be correct about what the arduino IDE is doing to your sketch.
Arduino will not preprocess any .h or .cpp files, so you could use a second file. you could also break the IDE's function locating regex with a dummy throw() statement like this:
void TellMe(WhatArduinoIs pls) throw() { }

The dummy throw allows it to compile for me on 1.5.8

All you need is a function prototype. I have a detailed explanation at Classes and objects: how many and which file types I actually need to use them?
So, this compiles:
enum WhatArduinoIs {
  Easy, But, Insane, Obsolete, And, Far, Worse, Than, mBed
};

void TellMe(WhatArduinoIs pls);  // prototype
void TellMe(WhatArduinoIs pls)
  {
  }
void setup() { }
void loop() { }

Off-site reference: How to avoid the quirks of the IDE sketch file pre-preprocessing

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


text:
object with multiple instances with internal data store separate for each instance
I'm trying to keep track of a timer, and the internal variables seem to be overrun by one another.
I just want two instances of the Output class, which can keep track of the _elapsed_time so I can check if the time elapsed. It's a poor-man's real-time for a game. I know there are libraries available and I'm planning to use them, but I would really appreciate knowing what's going on here: I want a buzzer pin, and status led pin to 'blink' at different intervals. They both work individually, but when I have them both uncommented they work somewhat serially...
#include "Arduino.h"

#include "MTC.h"

#include <SoftwareSerial.h>   //Software Serial Port

//HARDWARE SETTINGS
#define PIN_STATUS                  13
#define PIN_BUZZER                  A2

Output *STATUS(0);
Output *BUZZER;

void setup()
{
    Serial.begin(9600);
    STATUS = new Output();
    STATUS->Begin(PIN_STATUS, STATE_OFF);
    BUZZER = new (Output) Output(3);
    BUZZER->Begin(PIN_BUZZER, STATE_OFF);
}

void loop()
{
    static bool run_once = true;

    if (run_once == true)
    {
        run_once = false;
        Serial.print("Running");
        Serial.flush();
    }
    delay(250);

    //Serial.println("still running");

    STATUS->SetStrobe(3000);

    //BUZZER->SetStrobe(4000);

}

and class:
#ifndef MTC_h
#define MTC_H

typedef int OUTPUT_STATE;
OUTPUT_STATE STATE_OFF = 0;
OUTPUT_STATE STATE_ON = 1;
OUTPUT_STATE STATE_STROBE = 2;

class Output
{
private:
    int _pin;
    OUTPUT_STATE _last_state;
    unsigned long _cycle_duration;
        unsigned long _last_elapsed;

public:
    Output();                                           //constructor: set pin data store
    void Begin(int pin, OUTPUT_STATE state);                                //set hardware to output and defaul state
    void Set(OUTPUT_STATE state);                               //toggle operability
    void SetStrobe(unsigned long duration);                     //strobe operability
};

Output::Output()                                    //constructor: set pin data store
{

}

void Output::Begin(int pin, OUTPUT_STATE state)
{
    _pin = pin;
        _last_elapsed = millis();
    pinMode(_pin, OUTPUT);
    digitalWrite(_pin, state);
    _last_state = state;
}

void Output::Set(OUTPUT_STATE state)
{
    if (_last_state != state)
    {
        digitalWrite(_pin, state);
        _last_state = state;
    }
}

void Output::SetStrobe(unsigned long duration)
{
    static OUTPUT_STATE _last_strobe_state = STATE_OFF;

    unsigned long elapsed = millis() - _last_elapsed;
    if (elapsed >= duration)
    {
        if (_last_strobe_state == STATE_OFF)
        {
            digitalWrite(_pin, STATE_ON);
            _last_strobe_state = STATE_ON;
        }
        else
        {
            digitalWrite(_pin, STATE_OFF);
            _last_strobe_state = STATE_OFF;
        }
        _last_state = STATE_STROBE;
        _last_elapsed = millis();
    }
}
#endif

Your Output::SetStrobe() is wrong, it uses a static variable (_lasr_strobe_state) that is thus shared between all instances of OUTPUT, which is NOT what you want.
You have to change it into a non-static member of class Output instead:
class Output
{
private:
    int _pin;
    OUTPUT_STATE _last_state;
    // NEW member here!!!
    OUTPUT_STATE _last_strobe_state;
    unsigned long _cycle_duration;
        unsigned long _last_elapsed;

public:
    Output();     //constructor: set pin data store
    void Begin(int pin, OUTPUT_STATE state);//set hardware to output and defaul state
    void Set(OUTPUT_STATE state);            //toggle operability
    void SetStrobe(unsigned long duration);  //strobe operability
};

Then you initialize it in the constructor:
Output::Output():_last_strobe_state(STATE_OFF)
{

}

And you remove it (static declaration) from method SetProbe (the rest of the method does not change):
void Output::SetStrobe(unsigned long duration)
{
    unsigned long elapsed = millis() - _last_elapsed;
    if (elapsed >= duration)
    {
        if (_last_strobe_state == STATE_OFF)
        {
            digitalWrite(_pin, STATE_ON);
            _last_strobe_state = STATE_ON;
        }
        else
        {
            digitalWrite(_pin, STATE_OFF);
            _last_strobe_state = STATE_OFF;
        }
        _last_state = STATE_STROBE;
        _last_elapsed = millis();
    }
}

This is not a real answer, as @jfpoilpret already gave a perfectly valid
one. Just a few observations and suggestions from looking at your code.
I write is as an answer only because it is too long to fit in a comment.

The member variable _cycle_duration is not used. You could remove
it and save a couple of bytes per Output instance.
if (run_once == true) is equivalent to if ((run_once == true) ==
true). They are both considered bad style. Preferred style is to
just write if (run_once).
On the Arduino, it is generally good practice to avoid dynamic
allocation whenever possible. Of course, it is not always possible,
but in this instance it is quite easy: declare STATUS and BUZZER as
objects instead of pointers (as in Output STATUS;), then replace
-> by a single dot (.).


text:
How to identify Arduino Mini Pro 5v vs 3.3v
I have many Arduino Mini Pro, every from different seller.
Few are 3.3v and most 5v.
I had to clean table for Xmas and now I do not have any idea how to identify 3.3v Arduinos.
They do not have any marks. I bought them on ebay.
I know 3.3v has 8mhz clock but only one my arduino has big crystal with 16.000-30.

Look at the central chip. 5V pro mini has 328p printed, 3V3 pro mini has 168.

The regulator should be marked K850(5.0V) or K833(3.3V).
A 5 volt part has a 16MHz resonator may be marked with "A1" or "A'N"
A 3.3 volt part has a 8MHz resonator may be marked with "80'0"
As others have indicated, you can apply up to 12V at the RAW pin, and measure the output of the regulator.

I have some 3.3V with resonator marked "80.0M" and some 5V marked "AE"

I have resonator marked as 80'Y, (Atmega 328P AU 1710) And I measured the output ACC-pin (same as VCC) is 3.3V

Consideration (go down for the actual solution)
If you have a lot of different China-Arduino-clones, the easiest way will be to just test it. The cloned Arduinos use a lot of different voltage regulators and often you won't even be able to find datasheets for them on Google.
Someone here provided an Arduino sketch which helps you identify the frequency with which the Atmel is running and the comments say "it is the safest method". But why? It is complicated (you need to connect the USB-TTL-converter to each of the different Arduinos and sometimes they have different pinouts, so it's error-prone - you could easily fry your Arduino if you connect the wires to the wrong pins)...

Solution
I think the safest way is just connecting a voltage in the range of 6V-12V to the RAW-pin and measuring the (regulated) output of the VCC-pin.
There is no reason why this would kill your Arduino (in case your Arduino isn't broken - which would be good to know anyway; and of course you shouldn't short anything).
I've done a short sketch of how you should connect your Arduino Pro Mini:

RAW <---> 6V-12V
VCC <---> multimeter (5V = 5V Arduino, 3.3V = 3.3V Arduino)
One GND pins to the GND of the power source and one GND pins to the GND of the multimeter (you can take any of the Arduino pins labeled with GND)

Don't worry if your Arduino looks a little bit different, just look for the pin labels. For instance, one of my 5V Arduino Pro Minis looks like this, but also has RAW-, VCC- and GND-labels (just one of the GND pins is at a different position, make sure you check your Arduino pin-labels):

Alternative
You don't want to use the method above for some reasons? Then you need sharp eyes and some luck that the following list includes you components (some of these are collected from the other posts, some of them from my Arduinos):

3.3V:

Voltage regulators: KB33, S20K, F34V, L0RA, L0RB
Oscillators: 80e., 80'0

5V:

Voltage regulators: KB50, L05, L0UA, L0UB
Oscillators: R160JAC6s, 16.000-30, A1, A'N, A'a

(no limit or warranty for these details...)

More Suggestions
Some of the Arduino Pro Minis come with MHz and V markings on the back. In my case, none of these were checked. Make sure you check them as your new Arduinos arrive, so you won't have any problems identifying them later!

@Paul -> Sure this question is old, but still relevant - and that's the charm of stackoverflow / stackexchange -> you often can choose between multiple answers and most of the time there is still an up-to-date answer. Most people (just like me) will come here via Google, but none of the answers satisfied me completely, so I went to write my own one (and for sure I will come here again in the future when I need this again and forgot how to do it again ;) )

S2RA is also 3V3.

Warning - some Chinese Arduino clones do not accept higher than 11.5V and you can fry them when testing. So, to play it safe, use something lower in RAW.

The safe way (i tested it).
First connect to 3.3V USB-TTL output first (also 5V Mini can work with 3.3V).
Now prepare this sketch:
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(10000);
  digitalWrite(13, LOW);
  delay(10000);
}

Choose "Arduino Pro/Mini" with 5v/16MHz board and upload sketch.
If you see that the blinking is correct (10 sec ON/10sec OFF) - you have 5V/16MHz Arduino. Otherwise it will blink at 5 sec intervals instead of 10 sec.

Thanks, I thing this is the safest method ;)
(and you don't need a magnifying glass!)
I just tested it and the 5V mini can work fine with 3.3V

Thank you also. For me this is the simplest solution and works with arduino clones also.

Otherwise it will blink at 5 sec intervals instead of 10 sec. should be 20 seconds since, when running at 8MHz, things take twice as long versus 16MHz. Tested experimentally.

I hope you are all wrong otherwise it would mean the specifications of delay() function are not acurate since they would depend on the crystal frequency, I believe the function takes the clock frequency into account...so this test cannot be relevant...10000 ms would run the same delay on any arduino model (hopefully)

No, they are not wrong. When you program your sketch into the Pro Mini you have to select whether you are using the 3.3v 8Mhz part or the 5v 16Mhz part. The timing delays are adjusted accordingly. You can, in fact, program Blink into a 5v part using the 3.3v settings and it will blink twice as fast as it should and talk to the Serial monitor at 19200 instead of 9600.

Plug it in and measure the voltage on pin 4 of the MCU.

Is it safe to plug it in 5v FTDI ?

The way you ask that, it sounds like what you have isn't a Pro Mini at all, or even a clone.

I have this boards http://arduino.cc/en/Main/ArduinoBoardProMini Some have a bit different pins.

Check the label of the voltage regulator, KB50 for 5V and KB33 for 3.3

The only difference would be the regulator and crystal (8MHz on 3.3V). As @IgnacioVazquez-Abrams suggest supply power to the "raw" and measure Vcc.

Supply 5v to RAW and measure VCC ?

On my board the regulator is marked L0UA which is the code for a 5V regulator type LP2985, L0UB is also 5V.
A 3.3V regulator would be marked L0RA or L0RB.

Some clones on ebay labeled "the simple" come with 4B2X. They are 3.3v but the maximum voltage is 10v instead of 12v so beware to not burn it out.

On my board, the voltage regulator is marked F34V.  On the back is listed "The Simple" and Arduino-Pro-Mini"  I purchased it as a 3.3 v board off e-Bay, and I assume it is.  I have not yet applied vcc to it and measured the output.

AVR isn't specified to work at 16MHz at a 3.3V supply; it only can work at this high frequency at 5V supply. So you'll be able to tell them apart from reading the crystal. (It's possible, but unlikely, that you have a 5V version working with an 8MHz crystal. In any case 16MHz is safe for 5V.)

I wish to know if I have 3.3v 8Mhz or 5v 16Mhz. (The correct answer right is now is The regulator should be marked K850(5.0V) or K833(3.3V). But regulator is too small I can't see K850(5.0V) neither K833(3.3V).

Please post a photograph of it. Also, try shining a light on it at a 45-ish degree angle and attempt to read the reflection, rather than the ink itself.


text:
How to control 19 RGB LED strips with one arduino?
I need to light up 19 RGB LED strips, which it seems would require 19*3=57 PWM outs and 57 transistors.  The transistors aren't an issue, but of course the 57 PWM's is.  Even if I hacked the digital IO ports to work as PWM, I still wouldn't have enough.
How can I do this more simply?  Is there some kind of device I can get that would let me just pass data to it, perhaps over I2C, and it would control many PWMs? Is there another solution I haven't considered?  Maybe whatever is used to control those 8x8 RGB LED dot matrixes?
Any help would be greatly appreciated.  Thank you!

There is "set and forget" hardware available to do this, but a simple processor intensive method is to use either a 57+ long serial shift register or 9 x 8 bit parallel latches and write them with on/off patterns fast enough to PWM them. Depending on what PWM frame rate is acceptable this is "easy enough" or hard. At say 1 kHz rate you need to each of write 9 parallel latches every 100 uS or so. That's scrambling but doable.

You can use addressable LEDs that allow chaining from one LED to another using a serial protocol.
Like this :

This would alow you to set the first row blue, the second purple, each one can be controled independently.
Take a look at Ada Fruit's neopixels to start. These are basically skillfully branded WS2811 & WS2812 LEDs, but they are very well documented and well built. They feature 8 bit per channel RGB color (24 bit color) and take care of PWM internally. You could even chain the end of one strip to another, allowing all control to come from two pins of an arduino.
Assuming you go this route, consider the following:

You will need enough RAM to store the full array of pixels in memory, which is 3 bytes per pixel.  Alternatively, you can create a custom library with reduced bit depth, or one that stores pixels in clusters, because at the end of the day you are just operating a giant shift register.
You will need to supply enough current (60mA per led), and supply it at several points along longer strips.  You will likely need to use external power sources.  You can drive a decent amount of LEDs from Vin (before the power regulator), but not anything near 19 strips.

Now if you already have the strips, and they are analog strips, I think you can find similar drivers that output more power to drive strips, but still use a serial protocol.
You can use my example code here:
// NeoPixel Demo minimum
// By leo etchaas
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

#include <Adafruit_NeoPixel.h>
#include <avr/power.h>

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN            6

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      55

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 500; // delay for half a second

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code

pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {

// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.

for(int i=0;i<NUMPIXELS;i++){

// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(25,255,255)); // Moderately bright green color.

pixels.show(); // This sends the updated pixel color to the hardware.

delay(delayval); // Delay for a period of time (in milliseconds).

}for(int i;i>0;i-=1){

// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(255,5,255)); // Moderately bright green color.

pixels.show(); // This sends the updated pixel color to the hardware.

delay(delayval); // Delay for a period of time (in milliseconds).

}
}

There are several ways you can do this:
Option 1 - the easy way: You can use a serial-in-parallel out. Google "Arduino SIPO", and you will find examples. You basically send out 8 bits at a time, to a SIPO chip, then "enable" the chip; this changes the 8 "output" pins of the sipo to combinations of high/low as per the 8 bits that went in. You can pwm the "enable" pin. The best part is that each SIPO chip has an overflow - if you put a ninth bit in, you will get the first bit out of the overflow pin, which you can hook up to the input pin of a second SIPO, and so forth.
This option uses about arduino 4 pins, for an unlimited number of output pins.
This also has the advantage that SIPO chips can normally carry much more power than an arduino. Check the spec sheet on the SIPO to see how many milliamps it can carry at once (maximum). An example of a SIP is 74HC595.
Option 2 - Control the common pin for each strip.
Basically, you will be using e.g. 3 pins to select the colour, 19 to select which strip - I think some arduinos have that many pins? To light up red on strip 3, you would put the red pin high (and green & blue low); then you would put the pin for strip 3 low, and all the others high. You would step through each pin you want to light, or you could light them in groups - first red goes high (green/blue low), and all the strips you DONT want red on have their cathode high, and those you DO want red on would have their cathode low. drop red down; then do the same for green and blue. This does mean that you can't light up leds more than 1/3 of the time. This can be combined with the SIPO chip above - it may be easier. This does mean that you need to break out the "common" (cathode, normally to ground).
None of these allow very fine-grained control like pwm - you can't just say "led 3, green, 40%"; you will have to do a lot more work. You may burn all your Arduino time just doing the LEDs; this may or may not be a problem. You have the option of offloading your work onto another AtMega chip, or even an AtTiny; I think I would use an AtTiny and three SIPOs - 4 pins of the AtTiny to control the SIPOs, and 4 for SPI to receive the new settings (e.g. send the AtTiny 57 half-bytes, would give you 12-bit colour depth). You would need to do your own "fake pwm", but you could devote the entire AtTiny to running the light show. The AtTiny is programmed the same way as an Arduino; you would use a USBISP to send the program. Just hook up the power and away you go! An AtTiny will set you back around $2, depending on how many you get and where you get them from.
ADDITIONAL!
What about using something like a TLC5940? I haven't looked at the specs, but I found a reference to Arduino code. 16 Channel, 12 bit duty cycle per channel; you would need 4 of them. Apparently they can be daisy-chained as well. http://playground.arduino.cc/Learning/TLC5940

The DM13A is similar to the TLC5940, so that's an alternative.


text:
Motor Shield with 4 DC motors + small servo, which battery is suitable?
I am building my first 4wd vehicle with Adafruit motor shield with one Ultrasonic sensor and one small servo to move sensor.
I am facing some problems.

Bought 4 motors (2 GM9 and 2 GM3), found the difference when start running and GM9 were running double the speed of GM3. Tried to slow down th eGM9 with speed in code but now one of the motor stop many times while other run.
Running spearate power for Arduino (now USB) and 9v batteries for motorshield. Should I remove the jumper on motor shield as found that after removing 9v battery, its getting some volts from Arduino and motors running very slowly.
Servo motor is not running at all. While its pins are according to the circuit.
Should 9v batteries will be OK to run 4 GM9/GM3 motors + 1 small Servo? if not please recommend any other.
When running I feel small smell from boards, nothing is hot, is it a problem?

Too many questions but tried to put in one place.
Thanks

9v batteries can't produce much current. Better use a pack of AA NiMH batteries. If a new board gets warm it might smell a bit. Should go away after a while, but keep checking that nothing gets too hot.

Thanks for reply. what about the jumper on motor shield? its removed now but still getting current from Arduino.

Removing the jumper would be a good idea. With the jumper, the arduino would run on the same 9v battery instead of the usb power. Sudden spikes in power draw could crash/hang the arduino. I don't see how the motors could be running without the 9v battery attaches. That one puzzles me.

The Arduino is connected to USB to PC, but motorshield is with 9v battery. When I disconnect motorshield from battery the wheels runs and green light on sheild is still on.

From my understanding that shouldn't happen, so I guess my understanding is wrong (-: . Does this also happen without the jumper attached?

yes I checked with/without both. I am afraid if I connect 6 AA cells now it could burn one or both boards. I checked the adafruit site as well for connections.


text:
Adafruit motorshield disconnected but getting current from Arduino
my Adafruit motorshield is getting current from Arduino board even after disconnected from battery. I was planning to give separate dc power from 6 AA cells to motor shield but not sure if extra current will enter into Arduino and damage it. I have Ultrasonic sensor connected to motorshield which is getting +5v from board (may be Arduino).
Please suggest how to solve this problem.
Thanks

How did you get on with this?

If all else fails, read The Manual
The manual indicates that it is intended that the MS electronics may be operated by the Arduino power supply while using a separate external supply for the motor.
Pages 37 to 39 explain about powering options.
The Arduino and the shield interconnect all of : 3V, 5V, Vin.
3V may not be used by the shield.
Arduino Vin to MS V+ is broken by jumper "PWRJMP" - purple rectangle in diagram below.
Arduino 5V to MS Vcc is not interrupted by a jumper - See labels in red squares below.

You did not say what version shield you had or which Arduino or what you mean by "disconnected from battery" or supply any links to relevant documents. ALL of these things will help people to help you better.
Assuming latest MS version,
adafruit motor shield v1.2  - discontinued.
github v1.2 schematic this appears to be pre V2 BUT is linked to from a ference in the V2 manual so is probably "more or less correct".
adafruit motor shield v2 manual - probably what you have
adafruit current MS page
This probably tells you what you need to know.  Manual page 37-38

How to set up the Arduino + Shield for powering motors
Servos are powered off of the same regulated 5V that the Arduino uses. This
is OK for the small hobby servos suggested. If you want something beefier, cut the trace
going to + on the servo connectors and wire up your own 5-6V supply!
The DC motors are powered off of a 'high voltage supply' and NOT the regulated 5V.
Don't connect the motor power supply to the 5V line. This is a very very very bad idea unless you are sure you know what you're doing!
There are two places you can get your motor 'high voltage supply' from. One is the DC jack on the Arduino board and the other is the 2-terminal block on the shield that is
labeled EXT_PWR. The DC Jack on the Arduino has a protection diode so you won't be able
to mess things up too bad if you plug in the wrong kind of power. However the EXT_PWR
terminals on the shield do not have a protection diode (for a fairly good
reason). Be utterly careful not to plug it in backwards or you will destroy the motor
shield and/or your Arduino!

I am using Adafruit motor shield V 1.0 and Arduino UNO which comes with starter kit. When I say disconnected means that I am supplying 9v from 6 AA cells to motor shield on power terminals 'EXT_PWR' and removed the power jumper on motor shield. But as defined here it is still getting +5v from Arduino and its green LED is lit.

@qazifarhan We are slowly getting there. The extra information is useful. All the information will be even more so  |1. Please post links to documents describing what you say you have. If you do not have them then having you locate them makes more sense than expecting someone else to dos so. IF you can't find then then others will no doubt help. | 2. Read the material I posted and the manual. What it says sounds very likely to be completely applicable to what you have. | 3. Then ask again if still uncertain

@qazifarhan Here is the circuit diagram for V1.0 I suggest you add a link to it in your question. The advice I offered re V2 also applies to this. Here is the V1.2 shield page that lists the V1.0 diagram  - I suggest you add it to your question.


text:
Porting my project to multiple Nanos
I'm still fairly new to the Arduino world. I got myself a kit with a clone board  couple of months ago and have successfully prototyped the project and got it to the state I want it to be. I now want to create 5 - 10 working models of what I've done.
I'd seen on Amazon that I could get 5 Nano clones for about £10 and this seemed ideal to me. Until I saw that people were complaining that some Nano's aren't quite a direct replacement for the Uno that I have working. There's some kind of problem with loading the software from the IDE.
I really don't want to do anything more than just load my software onto the Nanos "As Is" using the IDE I already have.
Can anyone recommend what I need to look out for to ensure that the Nanos I buy will work this way please?

The Arduino Uno and Arduino Nano are fairly compatible.
Problems:

The board layout isn't the same, Nano's won't wield a classic "shield".
Nano's don't have a barrel jack.
Nano's (usually) have a micro USB connector. While the Uno has another one.
But, Nano's are smaller, withouth leaving out the USB connection.

But wait!
Microcontrollers of the same family are quite scaleable, Nano and Uno might even have the same micro on it! Be sure your Nano has the same Atmega328(P?) chip as your Uno.
Check if the pins you're using, are accessible on the Nano. Then you should be fine.
There is a little problem with cheap Arduino Nano's, I've bought 2, from 2 different vendors. They we're about 3$.

The first one featured a counterfeit FTDI chip. By installing the latest FTDI drivers, my FTDI actually got bricked. I had to undo this by using M_PROG or some EEPROM flashing tool to unbrick the chip, and install older drivers (which didn't corrupt it).
The second one featured an CH340G usb-serial chip. I had to download and install the drivers from a chinese website. But Windows wouldn't install unsinged drivers that easily. You have to go into advanced boot options mode and allow installing unsigned drivers.

Getting these Nano's working took me an reasonable amount of time. But they now are working quite well :)
It's something to take into account when buying cheap.
I wouldn't really bother for the alternative crystal, as long as they're 16Mhz. For time-critical behaviour, I wouldn't rely too much on your crystal.

... people were complaining that some Nano's aren't quite a direct replacement for the Uno

First, I hope you have understood that the Nano and Uno have totally different board formats. The Uno is the classical Arduino format. And the Nano is for breadboards.
Second, (and this will have to be a guess in lack of info or reference in your question) the Nano USB hardware on clones may differ and require another device driver. There might be other component selections to reduce the cost such as alternative a crystal for the oscillator, protection fuse, etc.
Cheers!

The project I'm doing is just controlling RGB LEDs. All I need is to connect to one digital pin on the board and supply it with power. I was hoping I could solder a wire to a pin, load the software then seal the entire thing in a box with power in and power/signal out.

An even cheaper solution is then to use Pro Mini clones. You would have to buy a FDTI or USB-RS232 module for sketch uploading.

Why use such a complex system when surely a little 8-pin ATTiny would be a better fit?

@Majenko the ATTiny looks interesting - but I doubt very much if it will be a simple replacement for my Uno. Can you point me to any further reading please?


text:
Mounting Arduino in an enclosure
I've decided to use Sparkfun's Pro Mini boards to make my project into a semi-professional product.
My first thought turned to enclosures - of which the entire internet seems to be bereft. If I ever DO see an enclosure, it's for the Uno sized board and costs about twice the price of the board, which seems incredible to me.
No matter, I have found a way to make quite good enclosures for the Pro Mini pretty easily and cheaply.
HOWEVER, the next problem is mounting the board inside the box. I would like to be able to mount it firmly to the base but in a way which allows it to be removed if necessary. Obviously, there's not a lot of scope for putting screws through the board. It occurs to me that anything which holds it would need to do so by gripping the edges or the corners. Is there such a thing?
If there's nothing that fits the bill, would the board be OK if I were to HOT GLUE it to the base of the enclosure?

What about using the pins to secure it? If you want to make it look "professional", just make a custom daughter board with the connections, make it so that you can firmly attach it (screws, plastic tabs, hot glue or even just rubber and a well-sized enclosure), then use the two pins rows to join them, so that you can unmount it easily

What do you mean by "The Pins"? The pro mini doesn't have any pins, just connection "holes", is that what you mean?

Ok, then one more step should be added (forgive me, I thought it was obvious): you should solder the pins to the pro mini like this image (of course without the serial connector - the six pins 90-degrees connector on the top layer)

@frarugi87 It probably WAS obvious to most people but not to me unfortunately. I'm not intending to use pins for the electrical connection - was just going to solder wires direct to the board as needed. However, I like the idea of using a few of the pins as "legs", I will explore that option if no-one offers anything better as an answer. Thanks for your help.

that's why I wrote it ;) and the comment was not sarcastic: I really meant "forgive me", because I really though it was and I understand it wasn't.. Anyway I suggest you to avoid soldering them directly on the board (this will limit your replacing easiness), but instead solder them on the base and then use just the pins for connection. If you want to avoid an extra board, you can use a perfboard or even just two female headers glued on the case and with the wires soldered to it.

I like the idea of the female headers as a holder, I'll experiment with this suggestion too. Thanks for all your help.

There are also little clips available, that grip a board by the edges, for example https://www.adafruit.com/product/1116 For boards with holes, I just hot-melt glue a few bolts to the case, sticking up in the right places, then put the board on and secure it with nuts; or use stick-on board clips like https://www.amazon.com/gp/product/B00R4ZT1FY

Seems like someone could make a good amount of money if they designed a plast slotted standoff that could hold the edges of the smaller like mini and nano boards into an enclosure. I’m kind of amazed I don’t see any at all.

One thing to be aware of, if your intention is to make this a consumer item is safety regulations. These tend to be quite specific, so you would need to have documentation to evidence your adherence to them. For example, UL certificates for the plastic enclosure you choose to use, RoHS certificates, etc.

What type of box?
Howmany times/how easily do you want to remove the Arduino Mini?
Hot glue
Hot glue is the way to go in many occasions.

It does not conduct electricity, so is pretty safe. (Please check your specific hot glue first)
It sticks quite well, for quite a time. You should also check if it's water resistant or fit for your target environment though.

But, it may have some side-effects:

It can get quite messy (which does not look really professional)
It's not that easily removable and has to be "re-glued" when you want to stick it back.
It might be too sticky (in a carboard box, you won't be able to just rip out the Arduino, withouth damaging the box).

You could use double sided tape, which might actually work fine. Or atleast better/neater as the hot glue.
Sticky velcro
A neat solution would be sticky velcro. You can easily attach, detach and re-attach the arduino to the velcro. It looks quite fancy and should hold well.
Again, you should check the specific velcro, it might not last 1000+ times of re-attaching (become loose or smh). But will be a good option overall.

Extra
You can use mint-boxes as an enclosure. But they're usually made of tin or another conductive material. Please take care and cover the back of your arduino (or box) with electrical tape, to avoid shorts.
Extra-extra, you should (for "replacability") add connectors or headers to your Arduino. Since soldering the leads directly will still give the need to un-solder or resolder your Arduino when replacing.
Note on making your Arduino project a consumer item
You might save yourself quite some money by using a barebones arduino. Or actually, an ATmega 328P chip. Which is around 3€.
These will be a little more difficult to program, but might also look more professional.
You can also enable "program protection" fuse bits, so that others can't download the code from your arduino/microcontroller.

Excellent answer, thank you @paul. I don't really intend to keep removing the Arduino from the box, but I'm sure I will need to, especially on the first ones. I like the idea of the sticky velcro - I actually have some of that in house already so will give it a try. The box is going to be made from plastic and I can easily make them exactly the size I need. The Pro Minis work-out to around the £2/3 euro cost too, so I'm not that concerned, especially if it's going to be harder to program - BUT, I am interested in keeping my code secret though so will investigate.

@Lefty, Pro Mini's are 10€ at more "official" shops. But indeed, for €3,- it's not really worth it. You could however use barebones arduino's to fit in even smaller enclosures or, on your very own PCB (if you need other circuitry). Programming should actually be the same as in the pro mini (IF you have a bootloader installed in your barebones implementation.).  (Basic) code protection involves disabling the "Fuse bits" for SPI download. Keywords to search will be: "flash protect, code download disable, fuse bits" etc.

thanks again. I will investigate the barebones option, purely because of the code-protection aspect, but size-wise, the Pro mini is well within the maximum size I can tolerate. I don't need any extra components and haven't made a PCB since I was at school - 40 years ago! So the pro-mini is ideal except for the code protection aspect. I paid £3.75 for the one I have bought so far, but the price drops significantly if I get 5, 10, or 20 at a time. Amazingly, it's about the cheapest part of the project.

@lefty the pro mini isn't that much different from a barebones arduino. If you have an icsp programmerer. You can actually enable read protection on a pro mini. But it won't work through serial-usb programming. By using an icsp programmerer, you don't even need the bootloader, thus have more program memory and others can't just upload arduino sketches through serial. Which might be usefull

More interesting stuff! I don't know about "ICSP" but I have an FTDI(?) programmer that I realised I needed for the Pro Mini. I used it successfully with the IDE. Looks like I have some more searching to do....

@lefty Arduino's have a bootloader that allows programming over serial. FTDI is an USB to serial converter. Bigger Arduino boards have these converters built on the board, even the Arduino Nano has this. Most Arduino's have/are an Atmega328P microcontroller, which are usually programmed with an ICSP programmer, since they do not have a bootloader.


text:
Very strange power supply problem
So, I've put together my Christmas tree lights - a string of WS2811s driven by my Uno board. They are 12 volt WS2811s, so I have rigged a 12 volt supply to them and just using the Uno for the data channel, powered, initially by the USB port of the PC. So far, so good.
Then I take the whole arrangement to the tree and try to power the Uno from a USB charger - but that's where it all goes wrong! The LEDS start to flash madly, nothing like the pattern that I've programmed.
I've tried various USB chargers and various USB cables to no avail, I've tried powering with 6 volts to the DC in socket - same thing. When I go back to the PC and pick up the Uno power from the USB cable, all is good! I have no idea what can be causing this, please help!

Garbage chargers. Did you try powering the Uno from the 12V supply as well?

Also, 6V is out of spec for Vin.

If I don't get  an answer from here, I will try putting the 12 volt supply to the Uno too - but that will require soldering that  don't want to do if I can avoid it.

The chargers are actually very good quality ones - from an HTC phone and a Sony phone. Do you think the voltage could be too HIGH rather than too low?

I found a page on arduino.cc which said I could supply up to 20 volts to  the DC in - so I thought 6 volts would be fine.

You are using two different power supplies?  (PC + 12V or USB Charger + 12V)
Have you connected the grounds from the two power supplies?

@Gerben The power supply has been working perfectly well during all of my development - and will work again now if I power the Uno from the PC, so I don't think there's an issue there....?

@Matt I have NOT connected the 2 grounds and I was a bit worried about that - but again, it works fine with the PC. Do you have reason to believe it should be necessary?

Yes its necessary.  The fact that it worked with the PC confused me.

@Matt That worked! Thank you very much! This is one of those times when I have to just accept that I'll never really understand some of these subtle things that can happen with things like ground lines. If you want to enter this as an answer I will happily upvote and mark this as accepted.

@Matt most PCs have GND referenced to EARTH. If the power supply too, has it's ground referenced to earth, both grounds are effectively tied together (via the earth). Most phone chargers are isolated.

@Lefty I have written a blog post about the importance of linking the grounds together - why you do it, what happens, and what it means to your circuit: https://hackingmajenkoblog.wordpress.com/2016/12/06/the-importance-of-sharing-grounds/

@Majenko Thank you, I read your blog and I mostly understand it - the main problem I have is understanding how the grounds are connected through the mains of the house given the nature of the step-down transformers that are powering both my 12 volt side and my 5 volt side. There is no sense in which the grounds are even connected to the 240 volt supply at all!

...They are actually both connected to coils which are in the presence of other coils that have one side of their AC supply connected together through the earth. This is where it needs explaining for me.

@Matt - you should turn your comment into an answer, as it is the correct solution to the OP's issue

[Turning my comment and other peoples replies into an answer to make it easier to read]
You are using two different power supplies? (PC + 12V or USB Charger + 12V) Have you connected the grounds from the two power supplies?
I have a limited understanding of why, but I know that unless the two power supplies have a common ground level the values for 0V and 5V may not be the same across the two feeds and you get odd and unpredictable behaviour.
Gerban explained that the reason it works on your PC is that most PC Power supplies reference Gnd from the Earth.  If you 12V supply is an ex-PC PSU, or similar, that will be doing the same which is why that setup works, they share a common ground via the mains earth.  The 5V phone charge probably has a plastic earth pin, which means it doesn't do this and therefore the Gnds are not tied to each other.
Majenko's blog will provide a more detailed, less hand wavey explanation:
https://hackingmajenkoblog.wordpress.com/2016/12/06/the-importance-of-sharing-grounds/

The Arduino Uno barrel jack input connects to a linear 5 volt regulator.  These types of regulators require a several volt difference between the input and output.  So you need to supply 5 volts + several more volts or at least 7 volts at the barrel jack.
From the Arduino Uno web page:

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.

Good theory - I assumed this myself when I first saw the behaviour I was getting - but the Sony USB charger I tried next is the highest power one I have - I once used it to power the Uno AND 100 5 volt WS2811s drawing about 2 amps between them.

I deleted the part of my answer concerning a power supply as I re-read your question and am not clear on how you connected everything together.  From my understanding, are you using 2 power supplies?  One for the LEDs and one for the Arduino?  And is the Arduino power supply a USB power supply connected to the Arduino's USB port?  And is the ground of the Arduino connected to the ground of the LED strip?

Also, are you sure WS2811 are 12 volt parts?

I've been using 5 volt WS2811s most of the time, powering them direct from the Uno, the Uno was, in turn just powered from the USB cable from the PC. I found that having even 100 in a string meant that I couldn't get power from 1 end to the other. I got a string of 200 12 volt ones and, obviously needed to power them from an external source. I wired a 12 volt laptop supply to the + and - of the string but leaving the rest as it was - i.e. USB to Uno, data channel from Uno to string AND NO OTHER CONNECTION to Uno. That worked fine...

...so I thought I would be able to just power the Uno from a USB charger and all would be OK - but then hit the problem exactly as I have described in the question. So it seems that from Gerben's comment at the top, the PC worked fine because its ground was connected through the mains power to the ground of the 12 volt supply - but when I used an   isolated USB charger, this broke the connection between the 2 grounds. When I now connect the ground from the 12 volt line to the ground of the Uno, the problem goes away.

Thanks for answering my questions.  I'm glad it worked out for you.  However, you should avoid assuming if a power supply is floating or connected to earth.  Certain situations can result in ground loops.  Think about what would happen if the ground of the LEDs were, say, 20 volts different than the ground of the Arduino. Something would almost certainly blow out.  I'm saying this because I don't want you to think it is normal to go back to your PC and not connect the grounds.

I'm afraid the whole concept of ground is something that I still have trouble with. I will have to do some research I think. I tend to just try these things and see what works - which is why I get confused when it works - then doesn't!


text:
Lost Source Sketch
I wrote an interface to a radio about 1-year ago. I have since rebuilt that machine. Is there any way to retrieve the code. Now I do not expect it to be sources code.
I know the radio code still works as I tried it the other day. Part of the problem is that I am using about 30 wires all on the rear end of the card
and  have to figure out which pins that they go to in my radio. My interface has two DB25 connectors. And the decoder 2 of 5 negative going signals.

Asusming the lock bits on the MCU haven't been set, you can use avrdude to download the contents of flash and EEPROM to your system. From there you can use avr-objdump to disassemble the .hex file and try to figure out how it works. I recommend looking at the disassembly of a .elf file from a current project as well as having both the avr-gcc and avr-libc documentation as well as the ATmegaXXX0 datasheet close at hand at all times.

Once you have the .hex file off the chip you can do this to diassemble it: avr-objdump -j .sec1 -d -m avr3 myfile.hex


text:
Can I change font Color and/or Type for IDE 1.5.6r2?
The program becomes harder to read (at least on my particular monitor) after upgrading.
Any way to change font Color to darker color and/or Type to thicker stroke (like B in this question editor) for IDE 1.5.6r2?

Sounds like what you need is a fully theme-able IDE.  Why not give UECIDE a go?

Yes.
Under the file menu select the preferences. From this you can find and than view/edit the preferences.txt file, which has the color settings.
Example preferences.txt

I log on as Admin (Win7) but cannot save the edit due to "access deny". Checked the property and 'ticked' for read, write and full control.

Solved. The one to change is C:\Users\username\AppData\Roaming\Arduino15\preferences.txt

In 1.6.0, or 1.6.1 it does not seem to be possible to change console.color or console.error.color. To be precise, you can change the settings in the preferences.txt file, but they appear to be ignored. Have these become hard coded? Orange text on black is just horrific to read. See How do I change the Console colour of Arduino IDE?

The link is broken (Google Code was shut down).

What about the thicker stroke? What should e.g. editor.font=Monospaced,plain,16 be replaced with (supposedly plain with something else)?


text:
Fade in UV lights connected to mains
I have a PIR motion sensor and would like some ultra bright UV led lights to fade in when this is triggered. It is one unit, consisting of 225 led lights connected to 240v mains (Australia). I bought a relay for the basic on/off function but was wondering if fading on and off can be done relatively easily - this is my first arduino project. I would value any suggestions.

You should be able to do that using a PWM signal and the "for" command. But keep in mind that you'd also need some mosfets.

Do you have like a part number for that led unit?

Most LED lights can't be dimmed from the mains supply.
In order to dim LEDs you have 2 choices: Limit the current through each LED or series string of LEDs, or pulse them very rapidly with a varying ratio of on/off times (known as a variable "duty cycle")
It's usually easiest to pulse them. To do that you need to be able to control the flow of DC to the LED array. If you were to take apart your IR array you would very likely find an AC to DC power supply that then feeds the LEDs through current limiting resistors.
If you can figure out the voltage and current that comes out of the DC power supply, you can select a power transistor (almost certainly a logic level power MOSFET) to wire in as an electronic switch that enables you to pulse the power to the LEDs using a logic signal from your Arduino.
This is actually a lot simpler than it sounds. You would cut 1 wire inside your LED array, solder in a single transistor to the 2 ends of the cut wire, and run the third wire from the transistor out to your Arduino.
Arduinos have several I/O lines that can be configured for PWM (Pulse Width Modulation) which is designed for this very purpose. You'd connect a PWM line to the gate of a logic level power MOSFET, and then send it a signal from 0 to 255, which would effectively dim the LED array in 255 brightness steps.
There are beginner sample projects that let you dim single visible light LEDs using this very approach. (For a single LED you don't need a transistor though, so they are really easy to wire up. All you need is a current limiting resistor.) I suggest you find and build one of those projects to get a feel for how (and how well) it works.

So how does this connect to the mains? Do I still use the relay that I have or can I bypass that and use the arduino to talk directly with the MOSFET to dim the lights? Basically I just have a PIR sensor and when movement detected --> fade in lights.

You could leave your IR light bank powered up all the time, and use the MOSFET to control the duty cycle of the output. However you'd then be running the power supply all the time, probably increasing wear on the IR light. It's probably better to use both a relay AND a MOSFET that controls the duty cycle of the light output.


text:
If I connect a battery to the vin pin on the arduino, will the 5V pin be activated?
My wording might be a bit confusing, if I plug an 8 volt battery into Vin, will the arduino be powered and will the 5V pins work?

Yes, that's what the Vin pin is for: unregulated voltage or a voltage higher than 5V. Then the 5V pin will be at 5V, regulated by the on board regulator. You would only connect a source to the 5V pin if the source is already a regulated 5V.

VIN. The input voltage to the Arduino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). You can supply voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.

source


text:
Confusing Arduino Leonardo PWM
I'm having problems with using Arduino Leonardo PWM outputs (I'm actually using YUN board).
I need 4 PWM outputs that generally have the same base frequency of around 10 to 20 Hz or so.
I'm using timer 1 (A-pin-9,B-pin-10,C-pin-11) and timer 4 (A-pin-13)
I get pins 9,10,and 13 PWM output working decent, but for some reason pin 11 PWM frequency is much much higher.
Pins 9,10,11 should be working off TIMER 1 which all use the same pre-scaler, so I dont know how 9 and 10 can have one frequency, and 11 have a different frequency.
Here is my code can anybody see anything wrong? thanks!
    #define PWM_4A_PIN  13
    #define PWM_1C_PIN  11

    #define PWM_1B_PIN  10
    #define PWM_1A_PIN  9

    void setup() {
     TCCR1B = TCCR1B & 0b11111000 | 0x05;
     TCCR4B = TCCR1B & 0b11110000 | 0x09;
     analogWrite(PWM_4A_PIN,128);
     analogWrite(PWM_1C_PIN,128);
     analogWrite(PWM_1B_PIN,128);
     analogWrite(PWM_1A_PIN,128);
    }

    void loop()
    {
    }

Pins 9,10,11 should be working off TIMER 1 which all use the same pre-scaler, so I dont know how 9 and 10 can have one frequency, and 11 have a different frequency.

Unless D11 is configured as OC0A instead of OC1C, which means that it will work off timer 0.
TCCR0A &= ~(_BV(COM0A1) | _BV(COM0A0));
TCCR1A |= _BV(COM1C1) | _BV(COM1C0);
 ...
OCR1C = ...;

Thanks Inacio, I tried your code but the same result D11 has much higher freq than 9 and 10, its very strange!

Did you use analogWrite() on D11? That will reset it to OC0A.

if I replace analogWrite(11,128) with OCR1C=128, then no output at all

Here is the whole code as it is now#define PWM_4A_PIN  13
#define PWM_1C_PIN  11
#define PWM_1B_PIN  10
#define PWM_1A_PIN  9
void setup() {
TCCR1B = TCCR1B & 0b11111000 | 0x05;
TCCR4B = TCCR1B & 0b11110000 | 0x09;
TCCR0A &= ~(_BV(COM0A1) | _BV(COM0A0));
TCCR3A |= _BV(COM1C1) | _BV(COM1C0);
//TCCR0A=0;
//TCCR1A=0xb01010101;
pinMode(11,OUTPUT);
OCR1C=128;
analogWrite(PWM_4A_PIN,128);
//analogWrite(PWM_1C_PIN,128);
analogWrite(PWM_1B_PIN,128);
analogWrite(PWM_1A_PIN,128);
}
void loop() {
}

Call analogWrite() once to configure everything else, then perform the assignments in my answer.

void setup() {
TCCR1B = TCCR1B & 0b11111000 | 0x05;
TCCR4B = TCCR1B & 0b11110000 | 0x09;
analogWrite(PWM_4A_PIN,128);
analogWrite(PWM_1C_PIN,128);
analogWrite(PWM_1B_PIN,128);
analogWrite(PWM_1A_PIN,128);
TCCR0A &= ~(_BV(COM0A1) | _BV(COM0A0));
TCCR3A |= _BV(COM1C1) | _BV(COM1C0);
//TCCR0A=0;
//TCCR1A=0xb01010101;
OCR1C=128;
}  D11 as no output anymore, but 9,10,and 13 still works

WORKS NOW!!! you have typo in your answer, TCCR3A should be TCCR1A, I changed that one thing and now it works!! THANKS VERY MUCH FOR YOUR HELP GOD BLESS YOU!!!

Pfft, yes, I suppose I goofed that part. Stupid joint datasheet sections...

why when I write to analogWrite it makes it back to OCOA???

I need to keep changing the PWM duty cycle, so I cant use analogwrite for any pin, only OC1C, OC1A, OC1B fro then on?

analogWrite() does a lot of housekeeping behind the scenes, including preparing the pin for how it thinks it should work. One of these bits is setting D11 as OC0A. Another is setting the PWM frequency. Sometimes the Arduino libraries are handy, and sometimes they interfere.


text:
Arduino UNO + Arduino GSM Shield + Sparkfun Venus GPS
I am using an Arduino UNO that is connected to an Arduino GSM shield (http://www.arduino.cc/en/Main/ArduinoGSMShield).
Now, I want to connect the SparkFun Venus GPS module to this combination. (*unfortunately due to my rep I can only post two links)
The Venus GPS works fine with the Arduino UNO by itself, but I am having some trouble getting the GPS module to communicate with the Arduino when the GSM shield is stacked on top.
The GPS powers on and begins blinking (which means it has a lock), but the serial monitor is not showing any information.
Coming from the programming side of things, I really don't understand much about electronics, so please pardon me if I am missing something basic here.
Based on what I've managed to figure out so far, I think it has something to do with the shield requiring 5V operating voltage and the Venus operating at 3.3V.
I think that when the GSM shield is plugged in, its expecting a 5V input, but the Venus GPS is only capable of sending a 3.3V signal.  Furthermore, any other 5V sensors that I am currently using don't have any problems communicating with the UNO through the GSM shield.
So, I actually have two questions:

Is this assumption correct or could something else be the cause of my issue?
If this is correct, could I use something like this logic level converter (https://solarbotics.com/product/50550/) to step up the Venus GPS input signal?

Thank you in advance for any help and guidance you are able to provide.

I received my logic level converter today and wired it in between the Venus GPS and the Arduino GSM shield.
The issue seems to be resolved and I'm able to properly receive information from the TX on the Venus GPS.  It would seem that my assumption was correct and I needed to "step-up" the 3.3V TX signal from the Venus GPS in order to use it with the GSM shield.


text:
Venus GPS + Arduino. Kill 3.3V TX during sketch upload
I am playing around with the Sparkfun Venus GPS.  I followed this tutorial to get started.  In here the author states that you should

Upload the following sketch to your Arduino BEFORE making any
  connections. 5V from an IO pin left high on the Arduino may well kill
  the 3.3V output from the Tx pin on the GPS module.

However, I am using the Sparkfun bi-directional logic level converter in between the Arduino and the Venus GPS (because I'm using the 5V Arduino GSM shield stacked on top of the Arduino).  In that case, would the above statement still apply?

If you have a logic-converter between the Arduino and the GPS then you won't have any problems.
The warning was about having the output from the Tx pin on the GPS possibly being damaged by +5 V from the Arduino, if a previously loaded sketch made it an output and HIGH.
However you could just as easily upload a "do nothing" sketch like this:
int main () { }

That is sound practice anyway, if you are connecting up new hardware and are not sure what the currently-loaded sketch does.

I've been running it without any issues with a logic converter for a while now.  Thanks for the tip on the do nothing sketch though.


text:
Are Arduino's truly OSH?
I keep reading how Arduinos are "open source", but my understanding of OSH is that all its components must be open source.
Arduino uses an Atmel 8-bit CPU - but Googling this shows the Atmel is proprietary!?
So I ask: how can Arduino be OSH if it's chief component - its Atmel CPU - is proprietary?!?

I don't think a discussion of the nuances of the term OSH really belongs here; Maybe on the arduino forum?

Thanks @BrettM (I'd upvote your comment if I had the rep to do so) - sorry, I thought this was an Arduino "forum" (well, Q+A site). Also, I'm not really asking about the nuances of OSH, I am straight-up accusing Arduino of advertising as something that it's not! If I say, "I am selling a car, and the price is $10." And then you get to the lot, and the car is actually $10,000, that's false advertising.

Either way this site is not really for open ended discussion questions. The Arduino forum would be better for this kind of question.

I just scanned over the TAPR and CERN open hardware licenses and I didn't see such a provision. My quick take on OHLs is that they are specifications for building the hardware - and therefore, information - not the hardware itself. And it only makes sense when we consider the incredibly expensive and complicated (from an experimenter's point of view) infrastructure that is a chip foundry necessary to create the kinds of hardware we take for granted and have reduced to commodity parts, CPUs, & MCUs being a prime example.
Thus "Arduino" is an open source specification for building microcontroller boards or board-sets based on ATMEL MCU chips, as well as the products of the Italian company SmartProjects. That is why there are so-called Arduino clones, otherwise, why wouldn't any clone of an Arduino be an Arduino?

Thanks @JRobert (I'd upvote you if I had the rep to do so). However I'mnot quite following you: are you saying that the Arduino designs are actually what is open source, and that in reality, whatever company makes Arduinos uses licensed/proprietary hardware to implement these designs? Thanks again!

My read of the licenses is that the physical device - an Arduino or compatible, in this case - is built of many components, some (many?) of which are proprietary but that he designs and specs for building it are open.


text:
Can Arduino's open design be "scaled" to 64-bit CPUs?
If Arduino is OSH that simply uses 8-bit Atmel AVR MCU as a design component, then can Arduino somehow be tweaked to work with a 64-bit CPU/MCU? If so, what might this entail?

If you mean the software, yes in principle though such processors may not have great direct I/O.  If you mean the board layout, perhaps though cost would be prohibitive for any small actor wanting to exercise the openess, and the alarming trend of not releasing real data sheets to the public may be an issue.  Have you truly exhausted the potential of inexpensive to work with 32 bit MCU's?

It has already been ported to a 32-bit Arm - the Arduino Due - 84mhz, Cortex M3.
To port it to a 64-bit CPU, someone would need to create a design for the PCB, and set up an appropriate build/compile system for it.
Having said that, a 32-bit CPU is an awful lot of power for this sort of thing - I suspect that if a 32-bit Arm isn't enough, then what you're really looking for is a full-blown PC. A Cortex M3 can handle 4GB of memory, and can run a version of Linux (uCLinux, since the M3 does not have a memory management unit, MMU, and the standard Linux kernel needs this). The Due would be unable to run even uCLinux, due to limited memory.
In fact, the Raspberry Pi is also a (700mhz Cortex A8) 32-bit CPU; I imagine that a little bit of tweaking could make the Arduino IDE compile & upload for the Raspberry Pi. This would fall into the category of "Because I can".
Note: The Raspberry Pi is not opensource, I know. Neither is the Arm in the Arduino Due, nor the AtMega that is at the heart of the Arduino Uno.


text:
Using 555 as an external Watchdog
I would like to use a 555 circuit as an external watchdog for my Arduino project. The project is a cellular tracker that goes to sleep for an hour, wakes up and does some measurements, uploads them and then goes to sleep again. The 555 should take care that the active period does not take too long because the systems hangs, and in that case trigger a reset. My first thought was to power the 555 circuit with a PIN of the Arduino so that it only goes on when the system is awake and is turned off while sleeping.
But this does not work as the reset line has to stay high even while sleeping and if i turn the 555 off reset would also go low. Could a Mosfet help? Any other ideas?

Why can't you use the internal watchdog for this?

Because it is not reliable and way too fast. I am running on reduced clock speed which means maximum watchdog cycle would be 3-4seconds. GSM communication takes time...

GSM communication shouldn't block the arduino code. You should at least be able to work around any blocking code that is in the library. Something like while(!Serial.available() && millis()-starttime<10000){wdt_reset()}.

Will give it a try - but nevertheless - would feel saver with an external fallback, still. Any ideas on this?

ok guys - found the answer: this post here at electronics-stackexchange gave the right hint: Watch-Dog Timer. And my gut feeling was right as well - i simply use a NPN-Mosfet that is being triggered by an Arduino-PIN (which easily can be done while sleeping as well as sleeping means waking up every 8seconds anyway) that connects the capacitor to ground and therefore discharges the guy. Awesome.
This solution can be used as a real fallback in case of whatever happens, while operating the system with built in watchdog-functions while everything is ok.

authors: Руслан Бондаренко


text:
arduino weather shield and wind speed
I have Arduino Mega and Weather Shield. I want to calculate wind speed.
float get_wind_speed()
{

float deltaTime = millis() - lastWindCheck; //750ms

deltaTime /= 1000.0;

  float windSpeed = (float)windClicks / deltaTime; //3 / 0.750s = 4

  windClicks = 0; //Sıfırla ve yeni oluşan rüzgarı izle
  lastWindCheck = millis();

  windSpeed *= 1.492; //4 * 1.492 = 5.968MPH

 Serial.println();
 Serial.print("Windspeed :");
 Serial.println(windSpeed);

 return(windSpeed);
}

But when I run my code I see two windspeed value. First one is windspeed=0.0 or any value. Second one is windspeed=nan.
How can I make it better?

When debugging a problem like this one, print out values of the variables that the calculation depends on.
In this case, you may find that both windClicks and deltaTime are 0 or 0.0.  The IEEE 754 floating-point-operations specification dictates a result of NaN (not-a-number) for various zero over zero calculations.  It dictates a result of +Inf or -Inf for calculations like 7/0.0 or -13/0.0.  [See, for example, the stackoverflow question, Why does division by zero with floating point (or double precision) numbers not throw an exception.]
If arithmetic generates a NaN or +Inf result, subsequent arithmetic using that result will also produce NaN or +Inf results.
To deal with the problem, you could use deltaTime > 0 as a required pre-condition for calculation of windSpeed.  That is, have an if-statement protecting the calculation block.


text:
arduino weather shield with gps
I have Arduino Mega and Weather shield and GPS Receiver - GP-635T (50 Channel).
here is my code for GPS
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

TinyGPSPlus gps;

static const int RXPin = 5, TXPin = 4;
SoftwareSerial ss(RXPin, TXPin);

const byte GPS_PWRCTL = 6;

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

  pinMode(GPS_PWRCTL, OUTPUT);
  digitalWrite(GPS_PWRCTL, HIGH);
}

void loop()
{
  smartdelay(800);
}

And print weather with this code
void printWeather()
{
  Serial.print("lat=");
  Serial.print(gps.location.lat(), 6);
  Serial.print("lat=");
  Serial.print(gps.location.lng(), 6);
  Serial.print("altitude=");
  Serial.print(gps.altitude.meters());
  Serial.print("sats=");
  Serial.print(gps.satellites.value());

  char sz[32];
  Serial.print("date=");
  sprintf(sz, "%02d/%02d/%02d", gps.date.month(), gps.date.day(),gps.date.year());
  Serial.print(sz);

  Serial.print("time=");
  sprintf(sz, "%02d:%02d:%02d", gps.time.hour(), gps.time.minute(), gps.time.second());
  Serial.print(sz);
}

But I see only zero for location and date and time. What should I do?

Until you have the correct baud rate and good satellite reception, many fields will be zero or empty.  I wrote a diagnostic program for NeoGPS that will try different baud rates and confirm that the GPS device is functioning.  The example program is in this directory:
examples/NMEAdiagnostic

Installation instructions are here.
If you're inside, you may not be able to receive anything.  Move next to a window or go outside.

You need to feed the output from the GPS module to the TinyGPSPlus routines, otherwise they won't do anything (other than return 0). Try adding:
while (Serial.available() > 0) {
  gps.encode(Serial.read());
}

to your loop. TinyGPSPlus comes with examples that you should have a look at. It also provides many debug statistics, e.g. the number of characters processed (gps.charsProcessed()) and the if these made sense (gps.passedChecksum()).

When I try examples in TinyGPSPlus i see     È†ÔÂ`1h±PÁ   like this symbol.

That looks like you have a mismatch in the rate settings. 9600 baud is usually the default for GPS devices. Make sure the setting on your computer is correct, too (i.e. also 9600 baud, following your code snippet).

BTW, smartDelay feeds the TinyGPS routines.  There are many issues with these libraries that I have documented and fixed in NeoGPS.  Be sure to check out the Troubleshooting section.


text:
Proxy and Authentication in Arduino Uno
I am using the Ethernet Shield on top of the Arduino Uno. I want to use this setup to access  webpages. But I am unable to access because the ethernet connection is present in a University which requires a proxy server with authentication. I am unsure of what extra code to include so as to get past the proxy which requires authentication.
Can anyone help in solving this problem?

Any semi-reputable authentication mechanism would be performed over HTTPS, which is an encrypted connection - this would require an SSL library to be installed for use along with the normal Ethernet and HTTP libraries, and I don't believe the arduino really has the processing capability to make connections like this feasible.
Unfortunately this is one of those cases where a more sophisticated device may be more appropriate.... (like a Beaglebone Black, or a Raspberry Pi.)
It is possible that you could add headers into the HTTP connection packet to either bypass proxy authentication, or include a cookie that has already undergone authentication and is cached by the proxy. How you do this is almost entirely down to how your proxy works. You may also find this doesn't work unless you spoof the MAC address of your device to match that of the machine used to fulfill the authentication.
It is entirely possible to set up a system to share the internet connection (act as a router) between two adapters - so you end up making connection requests to webpages, but the authenticated proxy only sees requests coming from your system (this is kind of how mobile phone tethering works, when you access the internet on a laptop or tablet through your smartphone's internet connection).
If the proxy supports unencrypted authentication, it may be possible to pass through username/password details in plaintext (or Base64 encoded) in Basic access authentication, which is what HTTP (and HTTPS) often uses - but this is unsafe on HTTP and is VERY unsafe when any part of the connection is publicly transmitted - like when using wifi, for example. (Doesn't matter if the wifi is encrypted - as on a university network, everyone who can connect to the wifi can see your wifi traffic (typically).)
If you're going to be using your own personal university login credentials to do this, make sure you always use ethernet to do it, not wifi, and if possible, obtain a second username/password explicitly for connecting this way - you don't want to have to hard-code your own personal username and password into source code that you have to give to anyone.
Here's a few links to get you started:

HTTP Spec: Proxy-Authorization and Authorization headers
How to use authentication in an HTTP Proxy?
Wikipedia: X-Forwarded-For


text:
How to avoid pulling the RX0 pin to reset sketch
My project requires reading 5 serial devices (RFID readers) at the same time. I chose an Arduino Mega 2560 as it comes with 4 serial RX ports. For the fifth port I am using the SoftwareSerial library.
My loop() checks each Serial port to detect if an RFID tag is being read. This works perfectly.
However, I am powering the board from an wall wart. When the power is disconnected the sketch no longer runs. I must unplug RX0, plug in the power supply, and reattach RX0.
If the board ever loses power it will have to be reset manually which is not ideal.
Please help me understand Why is this happening? and how can I fix it?

My guess is that the bootloader gets activated after reset, and waits for code. I don't know how to avoid this however.

Does it sit there with an LED flashing?

If you are willing to use ISP for programming you could remove the bootloader.  Or you can modify the bootloader to time out if no valid programming operations occur, or to check an "I'm being programmed" pin.

It looks like your RFID readers are very chatty on startup, and the board is going into bootloader mode.
I'd consider either controlling the RFID reader's power using another pin (and a transistor or mosfet if the reader needs more than 20mA), or using a gate ( AND for instance, or a simple switch IC like the 4066) that you can control to disable the RX0 input until program start.
Another thing I've done in the past is multiplexed multiple serial devices to one serial input.  The RFID readers probably have outputs that indicate a card presence, so use those and a multiplexor.  When the card presence is indicated, connect that serial port using the multiplexor, read the card and act accordingly, then wait for another card detect event.

You can simply disable the bootloader rather than erasing it. Find out the current fuse settings using a fuse-detection program. Change the BOOTRST flag in the High fuse to be unchecked, referring to this page: Engbedded Atmel AVR® Fuse Calculator
Write the High fuse back. Then it will ignore the bootloader and go straight to your code. Of course, to upload a new version you will have to put the BOOTRST fuse back, or you won't be able to use the bootloader to upload a new sketch.
One way of changing the fuse is to use my Atmega chip stand-alone programmer sketch. This has an interactive "change fuses" option. To run this you just need a spare board (eg. a Uno) and 6 wires to connect the programming board to your target Mega2560.
Example wiring shown on the linked page. Note that you do not need the SD board to merely change fuses. Just the two Arduinos and the connecting wires are enough for that.
When you first run the sketch it should inform you of the current fuses. Look at the High fuse and follow my instructions above.
You should see something like this:
Entered programming mode OK.
Signature = 1E 98 01
Processor = ATmega2560
Flash memory size = 262144
LFuse = FF
HFuse = D8
EFuse = FD
Lock byte = FF
Bootloader in use: Yes

In this case the High fuse was D8, which has the bootloader enabled. Using the Fuse Calculator site we can see that it should now be D9 which disables the bootloader.

An alternative way to change the fuse is to use Avrdude, if you have a stand-alone ISP programmer handy.


text:
Shield board with holes, do I need to solder?
I have a motor shield.
I can put it on top of my arduino Mega and works perfect.
However, since the shield plugs in on top of the arduino board, I don't have access to 5V and GND from Arduino Mega.
I just have holes on the board with 5V and GND. (look at image)
Do I have to solder a cable there to have access to 5V and GND? or there is another easier way?

Since there are two grounds, a 2-pin terminal block of the type already on the board may fit. Or, since the shield doesn't obscure the far end of the Mega (the end with the high numbered I/Os), you could pick up 5V and Gnd there. The ends of the double-row female header have respectively, 2 each 5V and Gnd connectors. You would pick those up with breadboard wires, though it is admittedly less secure.

do you mean that the 2 female header after 52 and 53 are 5v and GND ? (on the bottom right corner of my image)

Below 52,53 are both ground. Above 22,23 are both 5V. It also written on the board.

... in tiny script! It's easy to miss.

It also looks like, to the right of the yellow square, are 3 rows of through-board holes. Labelled: +5V, Gnd, and A0 to A5. You could remove the shield temporarily, and solder on a couple of rows of sockets there, giving you 6 x +5V and 6 x Gnd connectors.

You can also use a Mega Screw Shield if you don't want to solder wires


text:
How can I programming detect that a Bulb/LED is ON/OFF or a circuit is working as expected using Arduino?
I've created a circuit to turn on bulb using GSM module and Arduino. I want a mechanism(or programming) to know whether the bulb is on or off or fused. I've tried taking the input from the pins. But it only tells whether the pin is on or off but not the circuit as a whole.

You could measure current (perhaps as voltage across a small shunt resistor inline with the load).  Or you could use a photocell or other light detector.

This can be done using a few methods.  The simplest and least expensive option is to measure the current consumption of the device you want to verify correct operation of, and see if it's using enough, but not too much, current.
For instance, the following would work well in the arduino case of using an LED:

simulate this circuit – Schematic created using CircuitLab
Connect the Power to 5V or to the pin you're controlling the LED with. Connect the Sense to an analog input such as A0.
If the LED isn't installed, or is broken as an open circuit, the sense would register 5V.  If the LED is broken as a shorted element, the sense would register 0v. If the LED is operating correctly, you would sense the voltage drop of the LED (which varies according to the LED's design), but it would be well above 0V and well below 5V.
For bulbs and other loads, use a much smaller resister for R1 (so the resistor doesn't affect the load as much) and it would be considered a current shunt.  Knowing the resister value, and the voltage at the Sense location will give you a current value using Current = Voltage / Resistance. Again, the load should be drawing current within an acceptable range during proper operation.  If it's not drawing enough current, or too much current, it may not be operating correctly.
This won't tell you if the LED is on, however it's a very reliable method to discover if it's working correctly, and you'll probably never run into a situation where the correct LED is installed and in the right current range, but not emitting light.

Yes, though putting the sense resistor on the ground side can let you measure with a lower reference on the ADC which helps if the resistor is small in value, and if it is protected with a diode clamp in case the load open-circuits can let you measure the current on loads supplied from a higher voltage than the ATmega.

@ChrisStratton Correct, but it also messes with shared grounds and can be confusing for electronics beginners. Consider, instead, trying to determine if a zigbee or bluetooth radio is operating correctly.  As it transmits its ground would be bouncing relative to the Arduino's ground, messing up communications.  I wouldn't recommend it to an arduino beginner generally, and specifically in this case where the voltage is known to be lower than the analog input, the circuit requires a resistor, and in the vast majority of beginner LED designs the resistor is always high side - not that it matters.


text:
How to power on Arduino a few seconds later after GSM module initialization?
I've connected a SIM900A GSM module to Arduino and the circuit works standalone on a 12V power supply. The problem is when I provide the 12V power supply, both GSM module and Arduino starts but the Arduino don't initializes the program for GSM module and hence the send or receive message functions don't work. Also when I first power on the GSM module and let it initialize first and then power on the Arduino, everything works fine. How to deal with this problem?

It sounds like your problem is that the GSM module needs time to initialize before it is ready to be talked to by the Arduino.
A crude way of providing this would be to use the delay() function in the Setup() of your sketch.  The argument to that is an unsigned long number of milliseconds (thousandths of a second) so it can produce delays far longer than you need.
But a more sophisticated solution would be to repeatedly try to talk to the module and check for an expected response.  Apparently, with at least some of these, if you disable baud rate detection they will announce themselves with a prompt when they are ready - you could wait for that.  But I think repeatedly trying until you get a response is going to be the most robust.

Yes! Got that after posting this status. The delay I had mentioned earlier was less than the delay required to initialise the GSM.
How to disable baud rate and how will they themselves prompt when they will be ready? I've different modules too connected with the same circuit. I cannot disable it.

Let the 12 V charge a large capacitor over a resistor. The time to charge to 63% is RxC. Place a 5 V zener diode parallel to the capacitor, so that doesn't damage the microcontroller. Then either connect to the microcontroller's reset, or, and this is "nicer", use a MAX809 reset controller. The latter will keep the output low until a precise threshold is reached, there's for instance a 4.00 V version. Use that output to keep the microcontroller reset for some time.
Not sure how much delay you want, but a 10 uF capacitor and a 100k resistor will give you (from the top of my head) about half a second before the voltage on the capacitor reaches 4 V.

Why not just do the delay in software??

@Chris: Oh dear... Er, because that was too obvious? Well, in my defense, OP looked like a Real Problem at first sight. :-)


text:
Which device to use to measure AC current using Arduino?
I'm building a home automation product and want to measure AC current using Arduino (as of now). I've used ACS712 5A Hall Effect Current module but there's a lot of electrical noise and also the accuracy is not good. There's a lot of deflection in value when no current passes through it. I want to pack the whole kit in a box. So how to make sure that there will be no magnetic interference?
Can you suggest some other module to use for the same? Also that can last long enough.

Some sort of Current Transformer usually does the trick.  You run the AC line (not the neutral) through a ferrite core and it converts current into an output voltage.  You can find them packaged like this one with a web search.


text:
Cannot open ov7670 output file
I have taken a data file using arduino and ov7670 camera module. In this project I used the famous code https://github.com/ComputerNerd/ov7670-no-ram-arduino-uno . But after taking the datafile ov7670NoRam.hex, I can't open it. I spent 3 hours to search how to open, but failed.
Could anyone please let me know how to have a look the image in .hex? or would it be possible to take image data from ov7670 directly to jpg?
I tried to convert the hex file to bin using hex2bin, but when I opened the bin, only errors occurred.
The following is the content of the ov7670NoRam.hex
:100000000C9436000C944B000C944B000C944B0059
:100010000C944B000C944B000C944B000C944B0034
:100020000C944B000C944B000C944B000C944B0024
:100030000C944B000C944B000C944B000C944B0014
:100040000C944B000C944B000C944B000C944B0004
:100050000C944B000C944B000C944B000C944B00F4
:100060000C944B000C944B005244590011241FBEB9
:10007000CFEFD8E0DEBFCDBF12E0A0E0B1E0EAE70D
:10008000F2E002C005900D92A235B107D9F70E94A7
:10009000AF000C943B010C9400008093BB0084E8FB
:1000A0008093BC008091BC0087FFFCCF8091B90099
:1000B000887F90E070E08617970709F408950E9402
:1000C000A00084EA8093BC008091BC0087FFFCCF35
:1000D0008091B900887F883009F408950E94A000BB
:1000E000CF93DF93D82FC62F0E94610068E182E48E
:1000F0000E944D0068E28D2F0E944D0068E28C2F17
:100100000E944D0084E98093BC008FE99FE0019735
:10011000F1F700C00000DF91CF910895CF93DF93F6
:10012000EC0103C00E9470002296FE01849131967A
:1001300064918F3FB9F76F3FA9F7DF91CF91089591
:10014000259A90E285B1892785B92FEF31EE84E0B9
:10015000215030408040E1F700C00000F3CFF89418
:10016000239A8091B6008F798093B60083E48093C0
:10017000B00089E08093B1001092B30087B1807F16
:1001800087B98AB183708AB92FEF8BE792E9215042
:1001900080409040E1F700C000008091B9008C7F62
:1001A0008093B90088E48093B8001092C50081E084
:1001B0008093C4008091C00082608093C00088E179
:1001C0008093C10086E08093C20060E882E10E94D3
:1001D00070002FEF81EE94E0215080409040E1F7D5
:1001E00000C0000080E091E00E948E0060E285E1A6
:1001F0000E94700060E08CE00E9470008AE392E050
:100200000E948E0088E492E00E948E0069E181E104
:100210000E947000E8E6F0E094918091C00085FFB4
:10022000FCCF9093C6008091C00085FFFCCF319633
:1002300084918111F1CF4B9BFECF4B99FECF40EEC5
:1002400051E08FE792E04A99FECF36B129B1207F85
:100250003F70232B2093C6004A9BFECF9C01215068
:100260003109892B11F0C901EECF415051094115D7
:0A027000510539F7CFCFF894FFCF06
:10027A0012803A0412001713180132B619021A7AB8
:10028A00030A0C003E00703A7135721173F0A20134
:10029A0015027A207B107C1E7D357E5A7F69807616
:1002AA0081808288838F849685A386AF87C488D706
:1002BA0089E813C0000010000D401418A505AB070B
:1002CA002495253326E39F78A068A103A6D8A7D84A
:1002DA00A8F0A990AA9413C5300031000E610F4B03
:1002EA0016021E07210222912907330B350B371DEF
:1002FA003871392A3C784D404E20690074108D4F70
:10030A008E008F009000910096009A00B084B10C84
:10031A00B20EB382B80A430A44F045344658472815
:10032A00483A59885A885B445C675D495E0E6C0A94
:10033A006D556E116F9E6A400140026013C74F806F
:10034A00508051005222535E5480589E41083F000B
:10035A00750576E14C0077013D484B09C960564066
:10036A0034113B12A48296009730982099309A84CF
:10037A009B299C039D4C9E3F78047901C8F0790F14
:10038A00C8007910C87E790AC880790BC801790C2F
:10039A00C80F790DC8207909C8807902C8C07903C5
:1003AA00C8407905C8307926FFFF32F617131801BD
:1003BA0019021A7A030AFFFF12013D08413D76E14C
:0203CA00FFFF33
:00000001FF

What is it you hope to achieve by "opening" the hex file or "converting it to binary"?
A hex file is a compiled sketch. It is intended to be installed into the Arduino Uno using avrdude.

...you mean that it is not an image data? Oh.... I misunderstood. Because it was generated after the 'make write flash' I thought that it is the image. Thank you a lot for informing it.

But could you please let me know how I can get an image...? I know it is a stupid question, but I have no idea how to take it now.

It looks like you open the serial port on your computer, and the image data arrives.  From my initial glance at the code it looks like you get the marker "RDY" between frames.

If I type 'make write flash', then does the image arrive? Or is it just installation and the should I do something to run the code?

I am the author of the code and needless to say I am very confused right now on what you are trying to do. You run make writeflash in order to do what the target names implies write the hex file to microcontroller's internal flash memory. After that is done the code will run and you will use my frame grabber https://github.com/ComputerNerd/simpleFrameGrabber to capture an image.

Thank you for your answer. I misunderstood what the hex file is. But now I can't capture any image too. After running your simpleframegrabber I only see a black screen, even my oscilloscope shows that the ports D0~D7 are giving output signal. I set baud rate of the camera to be 9600 and then changed baud rate of the simpleframegrabber to be 9600 too. However it doesn't work. Even I tried opening IDE and then checked serial monitor which shows nothing. Could you please let me know what the problem would be?


text:
Having trouble bootloading my Two-Up printer
I am following these instructions to set up my Two-Up 3D printer, and I have no problems all the way up until step 18.  The board uses the arduino IDE to burn the bootloader, which is why I am posting this here.
I have my board set to "[BootloaderCDC]Teensylu/Printrboard" in the tools menu, and I have selected the appropriate COM port.  I use arduino for tons of other things so I know my way around the IDE reasonably well, but I have never encountered this error before so I'm not quite sure what to make of it or how to fix it.
Here is the error.
I have the red board (version 2) and I am using Arduino version 1.0.6.  As far as I can tell, I have perfectly followed all of the steps up until this part with no noticible problems.  I remembered to bridge the boot pins and everything.
In the video the guy says there may be an error when you go to program the board but my error is way different than his error in the video, and hbe says you should hear the dissconnect and reconnect sounds as the board gets reset after a bootload (I didn't hear them).
Anyone have any idea how to fix this issue?