text:
ESP-12e, Arduino IDE, NeoPixel Strip - Flickering
I have a NeoPixel RGB strip connected directly to my NodeMCU ESP12-e board. I'm using Arduino IDE with the NODEMCU 1.0 ESP 12-e module to programm the board.
ESP12-e | NeoPixels
GND    ---> GND
3.3V   ---> +5V
GPIO0  ---> Din

With the 3.3V output I have a strange flickerin on the LEDs.
When I use the VIV 5V output of the ESP12-e the flickerin is gone, but the lights turn off after a few seconds and some lights turn on with strange behavior.
I guess 5V is to much for the board? What can I do to get rid of the 3.3V flicker?
EDIT: I'm using WS2812B LED Strip Band with 224 LEDs 5050 SMD connected directly (see above) to a NodeMCU ESP-12e (http://learn.acrobotic.com/uploads/esp8266_devkit_pinout.png)
I'm using:
#include <ESP8266WiFi.h>
#include <Adafruit_NeoPixel.h>

I'm turning LEDs on for example like this:
#define PIN 0
#define NUMPIXELS 224

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int individualPixels[NUMPIXELS];
  void allOn(){
      for(uint16_t i=0; i<pixels.numPixels(); i++) {
        individualPixels[i]=1;
        pixels.show();
      }
    }

   for (int i=0; i<sizeof(individualPixels); i++){
    if (individualPixels[i]==1){
      pixels.setPixelColor(i, pixels.Color(red,green,blue)); //Set Neopixel color
    }
    else{
      pixels.setPixelColor(i,pixels.Color(0,0,0));
    }
  }
  pixels.show();

The ESP12-e is plugged in via USB Power
Thanks in advance

how many LEDs are you using?

224 (but flicker and strange behavior @ 5v also happens when I have only 3 LEDs on)

maybe 3.3V GPIO is not enough to provide an assertive HIGH when Vin is 5V, and when Vin =3.3V it is. Is it viable for you to try and make a level shifter?

not sure how to do that. what components do I need for that in my case?

Provide a LOT more information about exactly what you are doing. How many LEDs, how many I/Os are being used, are you PWMing the LEDs, what LEDs are they, exactly, etc., etc., etc. Completely disclose what you are doing sufficient for someone else to fully understand your goals. You can't get an appropriate answer without that.

See the edit. I'm not using any other i/os

I found a solution for my problem:
USB Powerbank --> ESP12-e --3.3V--> WS2812 --> FLICKER
USB Powerbank --> ESP12-e --5V--> WS2812  --> Strange behavior

Solution:
USB Powerbank with 2 Outputs:
Output 1 --> ESP12-e
Output 2 --> WS2812
Connect GND form Output 2 with GND ESP12-e

This works without level shifter.

Have a google for (WS2812 or Neopixels) and ESP, it should give several good hints on how to wire it up reliably. Also really read this: https://learn.adafruit.com/adafruit-neopixel-uberguide/overview .
But some things to consider:

WS2812 requires 5V, so you do want to use a 5v source, not 3.3v.
Make sure all your grounds are connected together, especially if you have a separate power supply for the leds.
The data input on the WS2812 needs a 5v high signal, especially when the WS2812 is (correctly) powered by 5v. This means you probably need some kind of level shifter, which needs to be able to switch fast as well, cause it's a pretty high frequency signal.
224 WS2812's can chew up a lot of power, so make sure your 5v source can handle that. When all are set to full white, it's 20ma per color per led, that's 60ma per led, so 13,44 AMP maximum. Your average USB charger isn't gonna cope with that :) You can use a power supply which provides less power if you make sure you only turn on a few leds/colors at a time, but if you accidentially turn on more, voltage is gonna drop and stuff will stop working :)


text:
What Arduino data type allows decimals?
This probably sounds dumb, but I am not getting any clear answer for this. What data type allows a reasonable amount of decimals?

What does "reasonable" mean?

At least 2 or 3, just the type smallest amount above this so I can save processing power on my Trinket board

You can use a float but you might also consider multiplying your values by as scale factor in order to use integer arithmetic which will be much more efficient if you do not need a wider range.

If you need to represent numbers that are not integers, the simplest
solution is to use floating point variables, also known as “floats”. A
float is declared with the float keyword. A numeric constant is
automatically a float if it has a decimal point :

42 is an integer (int type)
42.0 is a float

If you combine an int and a float in an arithmetic operation, the int is
implicitly promoted to float, and the result is a float.
A float gives you a precision of 24 significant bits. “Significant”
means that we are counting both the bits before and after the binary
point. Then, a small number will have many fractional bits, whereas a
large number will have only a few, and any number larger than
223 = 8388608 will have no fractional bits at all.
This precision is almost always better that 7 significant decimals and
worse than 8 significant decimals. For example, the following two
numbers are consecutive: any computation that yields a result in
between them will be rounded to either of them (usually the closest):
    binary (24 bits)          decimal
101010.000000000000000000  42.0
101010.000000000000000001  42.000003814697265625

The issue with floats is that they are expensive. Unlike a desktop
computer, the Trinket has no hardware support for floats (it's an
ATtiny: it doesn't even have a hardware multiplier!). Then every
computation is done by software. Even the simplest things, like adding
two numbers, can take quite a few CPU cycles and a lot of flash space.
That's why on very small devices people sometimes prefer fixed point
arithmetic. In a nutshell, fixed point is all about choosing appropriate
units of measurement in order to achieve the required precision using
only integers. For example, the ADC converter in the Trinket gives you
the voltage readings in units of
5 V ÷ 1024 = 4.8828125 mV

That unit may seem unpractical, but it allows a reasonable precision
using only integers. If you can avoid converting to volts, you will be
able to write integer-only code which is smaller and faster.
I would suggest you first try using floats, as it's the simplest
solution. If that leads to code with is either too large or too slow,
then try to rewrite with fixed-point (i.e. integer only) arithmetic.

At least 2 or 3 [digits], just the type smallest amount above this so I can
  save processing power on my Trinket board

Processors (computers) do not normally store values in Binary Coded Decimal (BCD) (as in base 10) because such storage wast valuable space.  Rather, processors usually use Binary numbers (as in base 2).
Most processors deal with binary values in multiples of 8 bits.  So, values are usually represented by 8 bits, 16 bits, 32 bits, ect.  An 8 bit binary number can have 2^8 possible values or 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 or 256. That is to say, an 8 bit binary number can have values between 0 and 255 inclusive.
If your requirement of "reasonable amount of decimals" falls within that range, then the type you are looking for is "uint8_t" or "char".  Both are normally 8 bits in the C / C++ language.  If you need more the next binary number has 16 bits or 2^16 or values between 0 and 65535.  Then the type you are looking for is "uint16_t" or "unsigned int".

While the facts you state are mostly true, this does not address the question asked in any practical way.  As a result your final recommendations are wrong.  The questions concerns non-integers, so an integer type cannot, by itself be a solution, though as already mentioned it could be one by use of a scaling factor.

Another option that Edgar doesn't mention (mainly because it's a more esoteric and tricky system to use) is fixed point values. These values, also known as Q values, are often used in digital signal processing (DSP) since they give predictable resolution and high speed processing.
A Q value is simply an integer where you split the bits within that integer into two portions - the integer portion and the numerator portion.
For instance, you may choose to implement a Q4.11 format. That gives 4 bits of integer value (it can store 0-15) and 11 bits of numerator (that is a decimal resolution of 1/(2^11) or 0.000488281). The 16th bit (4+11 = 15, in a 16-bit integer there is one more bit to account for) is the implicit sign bit. Some implementations have that, some don't - it's entirely up to you. If you only want positive values you can include the 16th bit in your value to increase resolution or integer size, etc.
You're not limited to 16 bit of course - you could use 8 bit for smaller numbers and lower precision, or 32 bit for bigger numbers and higher precision.
The disadvantage to using Q values compared to using floats is that floats can arbitrarily exchange decimal precision for integer size. With fixed point you have limited yourself to the range of integers you can represent. But that sacrifice can be worth it if you have a limited range in the first place (0-5V, say) and you need extra speed.
To work with fixed point it is first necessary to convert a floating point number to and from your target Q value. This is quite simple - just multiply (or divide to convert from Q to float) the value by the Q value of 1. That is, for a Q4.11 you would use the value of the 12th bit (the first of the integer bits), or 1<<11 (start counting from 0, so the 12th bit is 11).
Once you have your Q values adding and subtracting is just that - exactly as normal, using the + and - operators. Multiplying and dividing though is slightly more involved, but the resultant code is considerably more efficient. The whole lot can be done using just left and right shifts. For instance, some functions which I use in a small library of mine for Q15 values (more specifically Q0.15), which store values between ±1 with 15 bit resolution, look like:
typedef int16_t Q15;

static inline int16_t __satQ15(int32_t x)
{
    if (x > 0x7FFFL) return 0x7FFF;
    else if (x < -0x8000L) return -0x8000;
    else return (int16_t)x;
}

static inline Q15 Q15_mul_Q15(Q15 a, Q15 b) {
    int16_t result;
    int32_t temp;

    temp = (int32_t)a * (int32_t)b; // result type is operand's type
    // Rounding; mid values are rounded up
    temp += (1 << 14);;
    // Correct by dividing by base and saturate result
    result = __satQ15(temp >> 15);
    return result;
}

static inline Q15 Q15_div_Q15(Q15 a, Q15 b)
{
    int16_t result;
    int32_t temp;

    // pre-multiply by the base (Upscale to Q16 so that the result will be in Q8 format)
    temp = (int32_t)a << 15;
    // Rounding: mid values are rounded up (down for negative values).
    if ((temp >= 0 && b >= 0) || (temp < 0 && b < 0))
        temp += b / 2;
    else
        temp -= b / 2;
    result = (int16_t)(temp / b);

    return result;
}

You can learn more about Q numbers here:

https://en.wikipedia.org/wiki/Q_(number_format)

Note that Q0.15 is natively supported by gcc as _Fract. I haven't yet experimented with that type though.

@EdgarBonet Only if the version of GCC you use has that option compiled in - not all do. I don't know off hand if the Arduino's compilation of avr-gcc has it or not.

source: Stack Exchange

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

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

sort: votes


text:
SoftwareSerial data not available
Second time I'm asking the same question with no solution, let me elaborate in other way for clarity.
I wrote an Arduino program which uses two serial ports, one is hardware serial port and other is SoftwareSerial port.
No problem with hardware serial port, the problem is with software serial port.
The software serial port's Tx pin works but Rx pin does not work, i.e. portone.available() is always zero, nothing in the input buffer of the software serial port.
I'm using Arduino IDE 1.6.12 with an Uno board. Previously I used version 1.6.9 but neither works. Here is the piece of code:
#include <SoftwareSerial.h>

String code = "", customer = "";
bool complete = false;
byte c = 0, j = 0;
char customercode[27];
SoftwareSerial portone(10, 11);
void setup() {
  Serial.begin(9600);
  portone.begin(115200);
  pinMode(10, INPUT);
  pinMode(11, OUTPUT);
  if (Serial) {
    Serial.print("Connecting");
  }
}

void loop() {
  String copy = "";
  char inchar = '0';

  if (Serial.available() > 0) {
    while (Serial.available()) {
      char bytes = (char)Serial.read();
      if (bytes == '1' || bytes == '2' || bytes == '3' || bytes == '4' || bytes == '5' || bytes == '6' || bytes == '7' || bytes == '8' || bytes == '9' || bytes == '0' || bytes == '.' || bytes == '-' && bytes != '#') {
        customercode[c] = bytes;
        c++;
      } else if (bytes == '#') {
        complete = true;
      }
      if (c > 12 && bytes != '#') {
        code += bytes;
      }
    }

    if (c == 13) {
      customer += '+';
      for (byte i = 0; i < 12; i++) {
        customer += customercode[i];
      }
    }
  }
  portone.listen();
  if (portone.available() > 0) {
    portone.println("AT+CMGF=1");
    portone.println("AT+CNMI=2,2,0,0,0");
    portone.flush();

    while (portone.available()) {
      inchar = (char)portone.read();
      copy += inchar;
    }
    delay(1);
    Serial.print(copy);

  } else if (complete == true && customercode != "" && code != "") {
    sending();
  }
  Serial.print(portone.available());
  delay(1000);
}

SoftwareSerial is pretty low performance, and 115200 bps is probably asking too much. Can you lower the baud rate? Can you search the Internet for alternative implementations of a software serial port?

before I was using the 9600 baudrate but nothing happened that is why I decided to change, also I searched a lot in internet but I end up no solution. that is why I decided to come back again.

Don't call portone.listen().  That method is only necessary when you have created multiple SoftwareSerial ports.  It specifies which port you are listening to, because only one of them can receive at a time (you can transmit on any of them at any time).  It also empties the receive buffer so that data from one SoftwareSerial port is not mistakenly returned by another.  In your code, this empties the input buffer before checking portone.available().  Surprise, it's always empty!  ;)
Also, don't set the pin mode of the pins used for the SoftwareSerial object.  The pin modes were set during the constructor of portone, which happens before setup.  You're messing with pins that have been "promised" to that library for its own use and control.
As Edgar suggested, you should consider a more-efficient software serial library.  AltSoftSerial is best, but is only available on certain pins.  My NeoSWSerial library is next best, and works on any two pins, but only at 9600, 19200 and 38400.  Both of those libraries can transmit and receive at the same time, unlike SoftwareSerial.  Here is an answer with all the gory details.
And you really should ditch the String class usage.  You obviously know how to use char arrays (aka "C strings").  We can't see the sending() function, but you can probably just print a few pieces instead of building a complete String and printing it:
    portone.print( '+' ); // leading plus sign
    portone.write( (uint8_t *) customerCode, 13 ); // array of bytes, length

It would be better to terminate the character arrays with a zero byte (NUL-termination) in loop so they can be used as a standard C string instead of a byte array:
    customerCode[14] = '\0'; // NUL-terminate the C string

Then you can use the standard C string print in sending:
    portone.print( '+' ); // leading plus sign
    portone.print( customerCode );

Printing the pieces is always more efficient than building a big buffer with all the pieces.  This avoids copying the pieces and needing twice as much RAM.     :P

portone.print(code) is printing to the GSM module, then how can I control message so that it prints by iterations of peace wise message  while the full message should reach the receiver, and to control the iterations on receiving the message from the GSM module peace wise between the input buffer of an arduino and GSM, as it is sent full.

@kassim, if I understand your question, I think you are asking about calling print several times instead of just once.  The GSM does not see how many print calls were made, just that a certain number of characters were sent.  Because it takes about 1ms per char, the Arduino is able to start sending the second piece (i.e., customerCode ) almost immediately (~ 0.001ms) after the '+' character.  The GSM will not notice that tiny pause.  It will see an almost continuous stream of chars.  It is probably accumulating chars from the Arduino in the same way as loop accumulates customerCode.

I think the problem was library because I had added AltSoftwareSerial library now is fine.

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


text:
Low power wifi temperature sensor
I want to make a wifi-enabled temperature sensor and place it inside my HVAC system to measure and push the temperature to a central server, every minute or so.
I have a LoLin NodeMcu v3 unit laying around, and I am wondering if it is possible to use this one - and have it last for many years inside the HVAC system?
I realize the LoLin unit has a onboard wifi chip, I also realize LoLin takes 3v input. Aside from that, I am pretty blank.
Yesterday I tested the LoLin board by programming it with the following code, which lists networks in the vicinity. It worked great:
#include "ESP8266WiFi.h"

void setup() {
  Serial.begin(9600);
  // Set WiFi to station mode and disconnect from an AP if it was previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(2000);
  Serial.println("Setup done");
}

void loop() {
  Serial.println("scan start");

  int n = WiFi.scanNetworks();// WiFi.scanNetworks will return the number of networks found
  Serial.println("scan done");
  if (n == 0)
    Serial.println("no networks found");
  else
  {
    Serial.print(n);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i)
    {
      // Print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
      delay(10);
    }
  }
  Serial.println("");

  // Wait a bit before scanning again
  delay(5000);
}

The actual question
Is the LoLin board a feasible board for making a low power wifi enabled temperature sensor? Or should I rather make board that communicates with a wall-connected parent unit via radio?

What part of that is your actual question?

Execllent question @majenko. Thanks for pointing that out ;-)

How are you thinking of powering it?

I was thinking a battery. Any battery.

Yes, the NodeMCU can connect to a temperature sensor and forward that on to your WiFi access point to send to the internet.
Yes, the NideMCU can run from batteries.
Can it do it off one battery for many years? Only if that battery contains a small nuclear reactor.
Running something from battery for many years requires incredibly close attention to detail and incredibly tight component specifications, even down to the precise battery chemistry used. It's a very very difficult task for which people are very highly paid.
When you start looking at periods like that you begin to run up against the problem of battery self-discharge. Getting your power consumption down to an absolute minimum is a must, but even then if you have near zero power consumption the battery is still going to go flat by itself. So you have to invest time and effort into selecting a battery technology with a very low self-discharge.
All that is pretty moot though with the NodeMCU since:

WiFi is a power hungry technology. You can expect hundreds of mA while transmitting, and doing that once a minute for, say, 10 seconds (reconnecting to the WiFi takes time) will give you quite a high average power consumption just from the WiFi
The NodeMCU is far from optimised WRT power consumption. Linear voltage regulators, poor choice of components for low power consumption, etc, abound.

So yes you can run it from batteries, but be prepared to replace the batteries very often. By "very often" I mean every couple of days.
That means you basically have two options:

Don't use the NodeMCU but instead use something designed to be incredibly low power and run for long periods on battery (typically it won't use WiFi but something more efficient like nRF24L01+)
Don't use batteries. Hard-wire your NodeMCU into a mains-connected power supply.

Great answer @majenko. Thanks for taking the time to educate newbies like me :-)

You're welcome. Incidentally, my current wireless keyboard uses the nRF24L01+ (actually a Nordic MCU with built-in nRF24L01+) and runs from two AAA batteries. I have had it a number of years now, and it is still on the same batteries it came with. So it is possible if done the right way, but it takes expertise to do it.

Interesting. I had a chat with representatives from Nordic Semiconductors at NDC Oslo a few years ago, and I had the impression they could sell me IoT-devices with years of battery capacity (off a coin battery). They were probably Bluetooth 4 (?) devices.

Most likely nRF24L01+ based devices using a gateway to the internet. There's a new technology these days specially for IoT - LoRa - which is low power and long range designed to work with municipal-grade carrier gateways. There's a big one in Munich.


text:
Options for turning on/off an output at a specific time?
I am building a night light that will turn on when it detects motion using a Passive Infrared (PIR) sensor. I only want the light to turn on overnight, between specific hours that I specify. Outside of this time the Arduino will sleep.
For my Arduino to check the time, there are a couple of options:
1. Real-time clock
Description: A small add-on board powered by a cell battery (lifetime usually a couple of years). The user sets the time manually after the battery is inserted. Communicates with the microcontroller via SPI, I2C, etc. Upon request from the microcontroller (using a supplied real-time clock library function), the real-time clock sends back the current time (in a specified format).
Advantages

Completely offline

Disadvantages

The clock time can drift (due to electronic component manufacturing tolerances, temperature cycles and oscillator ageing).

To account for daylight saving, a "daylight saving" switch could be used that is manually set by the user.
2. WiFi link to an Internet time server
Description: A WiFi add-on board that allows access to the Internet. A time server could be requested for a specific time.
Advantages

Daylight saving is taken into account automatically
Clock would not need resyncing periodically

Disadvantages

Dependent on connection to the Internet
Dependent on availability of time server

Questions

Before I invest hours of time into making something work, are there any other options?
How much could a real-time clock be expected to drift after a year? (I'd be happy with +/- 15 minutes).
Are there any pitfalls with trying to obtain the time from an Internet time server?

I guess a third option is a combination: an Internet time-syncing Real-Time Clock that conducts synchronisation every week or so!
Note: I am planning on using my Arduino Pro Mini, but I wouldn't be against investing in other hardware.

A DS3231 RTC is quite accurate. Check this page for its test result on time drift. http://www.switchdoc.com/2014/12/benchmarks-realtime-clocks-ds3231-pcf8563-mcp79400-ds1307/

Other options: GPS receiver (should get rough time even with only 1 satellite in view), radio time signal (DCF77, WWVB, etc., depending on your location) or maybe even forget completely about time and use an LDR to know when it's dark enough for the light to be useful. BTW, the DS3231 is good to ±2 ppm, i.e. 63.1 seconds per year.

authors: Евгений Онегин


text:
Input PUK code, when requested
Problem:
I'm working with a GPRS module (the same as in the Arduino GSMShield). In some cases the PUK code is requested, and the PIN is thus locked. For this I wrote some code (which can be seen under "Software"). This code is based on the documentation of "GSM PIN Management". The only problem is that the module is telling us that both the PIN & PUK code is locked. The tutorials, however, does not provide an example how we should resolve this issue from the Arduino itself.
EDIT: When the SIM card is inserted in a smartphone. The PUK code is requested. When the PUK code is provided (and a new PIN) the SIM card is back to normal. But adding the PUK code via the GSM lib. doesn't really work, in contrast to using a smartphone to unlock the PIN code.
Question:

Does anybody have an idea how to resolve this issue? And if it can be done?

Hardware:

Atmega328p
Quectel M95 (as GPRS module)

Software:
PINManager.begin();
int pin_query = PINManager.isPIN();
Serial.print(F("Pin Query is: ")); //output: -2
Serial.println(pin_query);
if(pin_query == -1)
{
  #ifdef DEBUG
    Serial.println(F("PUK is requested"));
  #endif

  if(PINManager.checkPUK(PUK_NUMBER, PIN_NUMBER_CORRECT) == 0)
  {
    PINManager.setPINUsed(true); // I also think this must by "false". Both things were tested, none of them worked.

  }
}

If you enter the wrong PUK code 10 times or more, then you will need a new SIM card.

That's not the case. Because when the SIM is inserted in a smartphone/gsm, the PUK is requested. When adding the PUK code and a new PIN code, the SIM works fine. See the EDIT in the post.

I've resolved the issue by using AT commands instead of the GSM library provided through Arduino.
if(sendGPRSCommand(F("AT+CPIN?"),100).equals("AT+CPIN+CPIN:SIMPUKOK")){
    Serial.println(F("PUK is requested, entering it now"));
    String cmd = "AT+CPIN=\"";
    cmd.concat(PUK_NUMBER);
    cmd.concat("\",\"");
    cmd.concat(PIN_NUMBER);
    cmd.concat("\"");
    sendGPRSCommand(cmd,100);
  }

This code checks if the PUK code is requested, this is the case when the pin_query is -1 or -2 (see question). When the PUK code is requested the new PIN (which is still the same pin as the old one) is given in combination with the PUK code.
The AT commands were found in this manual.


text:
How to keep amperage in serial and parallel?
I have a 2000mA AC adapter and also I have the lights that I show here:

Each of these lights consume up to 300mA.
If I make a circuit with 3 lights in serial, ¿will the amperage of each light decrease?
If I make a circuit with 3 lights in parallel, ¿will the amperage of each light decrease?
I am asking it because I don't want the lights to decrease the luminosity. I want the maximum luminosity in each light.
The lights are for growing lettuces. Now I am using a low consumption light but are not efficient:

You haven't said what the voltage rating of your Power Supply is, but if we assume it is a "constant voltage" regulated supply, then it will attempt to maintain a constant voltage up to the rated current capacity (2000 mA).
If you put your LEDs in series, then the voltage from your power supply is distributed across the LEDs, and is therefore lower on each LED. This would cause your LEDs to be less bright.
If you put your LEDs in parallel, then the voltage remains constant.

The power supply convert from 220v to 12v. Your answer confirm what I was thinking about voltage, but I would like to know about the amperage.

The other answers by Gerben and Majenko correctly note the requirement to limit current to avoid destroying your LEDs. If you don't limit the current on purpose, the LEDs will dissipate more power than they are designed to and will die.

The simple answer to that is "No, and stop right now whatever you are doing."
Those LEDs, because of their high current requirements, need a constant current driver.
First a little theory:

LEDs in series sum the voltage, the current stays the same.
LEDs in parallel with no form of current management split the current unevenly and LEDs start dying (or even exploding when you have high currents involved).

If you don't want any control over the brightness then the simplest constant current driver is to use an LM317 voltage regulator wired in constant current mode.
It is also possible to make a constant current sink (the same as a constant current source but between the LED and ground instead of positive) using discrete components.
If you want control of the brightness then the best solution is to use something like the CAT4101 PWM LED driver.
Why don't you use a simple resistor like you would for any other small LED? It's quite simple. Both resistors and LEDs characteristics change with heat. When you are using higher currents like this both the resistor and the LED give off heat (more so the LED than the resistor unless you pick too small a wattage). That means you get changes in the characteristics, which means the current you originally calculated for is now wrong - typically the current increases above what you had originally calculated. More current means more heat. More heat means more current. The result: a cascade. Worst case? The LED dies.

If you put them in series the they require 300mA, but you'd need to have a higher voltage (around 10 Volt).
If you put them in parallel, you could keep the same voltage as a single led (around 3.3 Volt), but you'd require trice the amount of current (i.e. 900mA).
You however need to add proper current regulation, of you'll burn out the leds. The advantage of having the leds in series, is that you only need a single constant current driver.
You could use resistors, but since these leds require that much current, the leds will have to dissipate a lot of heat. Which is both wasteful, and requires special high wattage resistors.


text:
How to add toggle button for LCD display text and backlight?
I have set up a BMP180 and a DHT11 to display data on an HD44780 20x4 LCD.

I want to be able to toggle the altitude from meters to feet, the temperature from Celsius to Fahrenheit, and the pressure from absolute to sea level pressure using a tactile push button.
Here is the software code I have:
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#include <SFE_BMP180.h>
#include<dht.h>
dht DHT;

#define DHT11_PIN 8 // Second pin, leave 3rd pin unconnected 4th is ground
#include <SFE_BMP180.h>
#include <Wire.h>

// You will need to create an SFE_BMP180 object, here called "pressure":

SFE_BMP180 pressure;

#define ALTITUDE 237.0 // Altitude of Phillaur in Punjab, India. in meters

void setup() {
  lcd.begin(20, 4);
  lcd.setCursor(0, 0); // Zeroth Row
  lcd.print("hello, world!");
  lcd.clear();
  int chk = DHT.read11(DHT11_PIN);
  // Initialize the sensor (it is important to get calibration values stored on the device).
  if (pressure.begin()) {
    lcd.print("BMP180 init Success");
    delay(300);
  } else {
    lcd.print("BMP180 init fail");
    while (1); // Pause forever.
  }
}

void loop() {
  char status;
  double T, P, p0, a;
  lcd.clear();
  lcd.setCursor(0,0);
  //TODO Display in Feet as well using toggle
  lcd.print("Altitude: ");
  lcd.print(ALTITUDE, 0);
  lcd.print(" mtrs ");
  status = pressure.startTemperature();
  if (status != 0) {
    // Wait for the measurement to complete:
    delay(status);
    status = pressure.getTemperature(T);
    if (status != 0) {
      // Print out the measurement:
      Serial.print("temperature in deg C, From BMP180: ");
      lcd.setCursor(0, 1);
      lcd.print("Tmpratre: ");
      lcd.print(T, 2);
      lcd.print("'C");
      lcd.setCursor(0, 2);
      lcd.print("Humidity: ");
      lcd.print(DHT.humidity, 1);
      lcd.print("%");
      status = pressure.startPressure(3);
      if (status != 0) {
        // Wait for the measurement to complete:
        delay(status);
        status = pressure.getPressure(P, T);
        if (status != 0) {
          lcd.setCursor(0,3);
          // Print out the measurement:
          lcd.print("Pressure: ");
          lcd.print(P * 0.0295333727, 2);
          lcd.print(" mb");
          p0 = pressure.sealevel(P, ALTITUDE);
          // we're at 234 meters (Phillaur, Pb)
          // TODO: toggle to sea level to absolute pressure
          Serial.print("relative (sea-level) pressure: ");
          Serial.print(p0, 2);
          Serial.print(" mb, ");
          Serial.print(p0 * 0.0295333727, 2);
          Serial.println(" inHg");
          a = pressure.altitude(P, p0);
          Serial.print("computed altitude: ");
          Serial.print(a, 0);
          Serial.print(" meters, ");
          Serial.print(a * 3.28084, 0);
          Serial.println(" feet");
        } else Serial.println("error retrieving pressure measurement\n");
      } else Serial.println("error starting pressure measurement\n");
    } else Serial.println("error retrieving temperature measurement\n");
  } else Serial.println("error starting temperature measurement\n");
  delay(5000);  // Pause for 5 seconds.
}

And what part of that "I want" is it you are having problems with, if any?

Hooking the tactile button to LCD using arduino UNO :(

Well, you don't. You hook the button to the Arduno. It's then up to your software to decide what to do with it.

well, thats the part I am wondering how to do

Which part? Wiring the button up, or changing your program?

both , Wiring the button up, or changing your program

To wire the button up you need two wires - one to an input and one to ground. We can't help you change your program since we don't have your program to know what wants changing. We're not psychic you know (well, most of us aren't)

@Majenko added the software code as well.

You need to connect the button(s) to available digital inputs of the Arduino. I suggest that you use more than one button based on your description in the question.
The following tutorial describes the circuit needed and the associated code to read that input. All you have to do is duplicate it with a few more buttons on separate (available) digital inputs.
Arduino button tutorial

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


text:
All of the sudden the Nano will not accept programming
I have been working merrily along with CH340 to make Com10 work.  It has been working flawlessly but now I am getting various messages like it can't open the port then the programmer is not responding.  It tries several times before giving up.
This was working fine yesterday.
I tried uploading to a raw board not connecting to anything and am getting the same result.
Suggestions?

Throw away the CH340 and use something that is more likely to last you more than a few days.

I believe CH340 is installed with the IDE.  I did a reinstall and it still shows it.  I have used it for several months just like this.  But I do see your point - since the same problem happens with multiple boards the problem must be in the PC.

OK, problem solved.  I wish I knew enough to be able to say why it worked, but here is what did the trick:
I uninstalled the IDE.
THEN REBOOTED.
Then installed the IDE (version 1.6.10) again, this time not selecting the USB driver.
THEN REBOOTED.
In Device manager it still shows the CH340 driver on COM14
All my sketches and the two libraries (DHT and LCD) in the documents/Arduino directory were unaffected.
And now it will upload to my boards just fine.
This is one of those times where I can't explain why, but I can tell you for sure that it worked for me.  I had tried uninstalling/reinstalling, but without the rebooting in between.  Perhaps that was the crucial step that needed to be taken.

This problem occurs quite often with all the boards. Here is how to troubleshoot it.
1 - Unplug the Arduino.
2 - Upload the program WITHOUT any boards connected to your computer.
3 - Replug your Arduino.
4 - Upload the program WITH your Arduino connected to your PC.
If this doesn't work, read this post by Nick Gammon.

@ Dat Hair Do.----in additon to above answer- you may connect the arduino on another computer running arduino IDE if that possible. If the arduino is detected and works on another different PC than it still ok. That may save time - if you have multiple PCs or can borrow one-if you just want to know your arduino still works.

@ Dat Hair Do ---the idea in the above comment has now been added by Nick Gammon to his post. So its a good idea. I would give try the stuff with it if possible

@yabbadabba, why the hell do you call me Dat Hair Do? Please stop or I'll be forced to flag you.

@yabbadabba - Please read the Be Nice policy

I found a method that works and added it as an answer.  I am glad that it is acceptable to post answers to our own questions as we learn more.  My desire is that this might be useful to others.


text:
The Mysterious Case of the Mostly-Vegetable Servo
Story:
I was playing around with my Uno along with a servo.
To my stupidity (or more appropriately: ignorance), I set the voltage to my servo with analogWrite(), rather than servo.write(). It worked for a bit; but once it reached it's limit, it kept trying to move, to no avail.
Realizing what I had done, I pull the power source from my Uno.
Then, I went to change the code, and tested my servo once more.
The servo's casing is transparent (there is a sticker blocking the motor and circuit; but I can see 4 of the gears).
The bottom 2 gears are ticking ever so slightly (and the top 2 even less so), resulting in the propeller to move at most 5 degrees. At this threshold, none of the mentioned gears are ticking, but something is heard (probably a whirring gear not in sight).
At this point, I would've come to the conclusion that a tooth of the third gear had broken.
However, after I pull the power plug and put it back in, it spins (backwards) into it's initial position and begins the process mentioned above again.

Mystery:
Is my servo indeed broken?
What's not functioning correctly?
Can it easily be repaired?

Is my servo indeed broken?

Yes.

What's not functioning correctly?

As you said, some of the gears must have shifted in some way hindering the smooth mouvement of the servo or making it simply not working correctly.

Can it easily be repaired?

Well, it depends on you. Do you like repairing EXTREMELY small things? Are you skilled at that. I would say no, because it requires a lot of knowlage on the servo to be able to remove it, fix it, and not to forget, replace it into its original case. Simply buying a new one is quite cheaper and simpler.

@ Dat Hair Do----Rather than forgetting  it-  the OP could use the use the servo motor from it and make your own driver circuit for it they wanted to. They could also make a large new gearbox -if they wanted to. I dont think both of these things are difficult.

@DatHa -- I most likely won't fix it; I'm not willing to waste time (not saying that it's not useful; I'm just an ignorant teen who's got limited time to learn) learning how to fix tiny gears. However, I'll probably open it up and play around with it. Thanks for your diagnosis, though!

Very good idea. I also do that, before I throw anything to the garbage, I usualy open it to see how it works!!

P.S. check this out! https://www.youtube.com/watch?v=J8atdmEqZsc


text:
How fast can I drive a stepper motor?
I have a 28BYJ 48, 5V stepper motor. After some trial and error I got it working with the all the sample examples in Arduino IDE.
However when I increase the speed of the motor using setSpeed() beyond 15, the motor stopped rotating. Following is the configuration in which I am running the motor.
const int stepsPerRevolution = 2048;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
myStepper.setSpeed(15);

I wanted to understand what factors limit the speed. And how fast can I rotate this motor?
Thanks,
Manish

Read about chopping drivers.  There are many answered questions on EESE, no need for a new one.

"I wanted to understand what factors limit the speed. And how fast can I rotate this motor?"
Read through the data sheet for your motor-the answers are there. Each different motor has its own data sheet. This will require some work on your part to find the data sheet and the info from it you require. Which can be used to deduce the answer your question.

While the data sheet will give you the inductance the actual speed limitation of a given motor is determined not by the motor but by the driver's available voltage, which must be many times the nominal motor voltage.  Often all you really need to know about the motor is rated current, or steady state voltage from which it can be calculated.

@ChrisStratton yeah-youre right- it would depend on the circuit controlling the motor too. So youre's sayin the speed limitation does not strongly depend on the information in the data sheet. .

The inductance may the used as a parameter to a chopping software-if the motor is chopping driven


text:
Compiling Error
I am trying  to compile this code on arduino IDE...It showing error
code is
#include <IRremote.h>

int RECV_PIN = 6;
int led = 12;//1FE50AF
int led1 = 10;//1FED827
int led2 = 9; //1FEF807
int led3 = 8;//1FE3087
int led4 = 7;//1FEB04F
boolean previousState=LOW;
boolean previousState1=LOW;
boolean previousState2=LOW;
boolean previousState3=LOW;
boolean previousState4=LOW;
boolean state;
boolean state1;
boolean state2;
boolean state3;
boolean state4;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
  Serial.begin(9600);
  pinMode(12,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(7,OUTPUT);
  irrecv.enableIRIn();// Start the receiver
}
void loop() {
  if (irrecv.decode(&results))
  {
    Serial.println(results.value, HEX);
    switch(results.value)
    {
       case 0x1FE50AF:
       if (previousState == LOW)
       {state=HIGH;
        digitalWrite(led,state);
       previousState=state;}
       else
       {state=LOW;
       digitalWrite(led,state);
       previousState=state;}
       break;
        case 0x1FED827:
       if (previousState1 == LOW)
       {state=HIGH;
        digitalWrite(led1,state1);
       previousState1=state1;}
       else
       {state1=LOW;
       digitalWrite(led1,state1);
       previousState1=state1;}
       break;
       case 0x1FEF807:
       if (previousState2 == LOW)
       {state2=HIGH;
       digitalWrite(led2,state2);
       previousState2=state2;}
       else
       {state2=LOW;
       digitalWrite(led2,state2);
       previousState2=state2;}
       break;
        case 0x1FE30CF:
       if (previousState3 == LOW)
       {state3=HIGH;
        digitalWrite(led3,state3);
       previousState3=state3;}
       else
       {state3=LOW;
       digitalWrite(led3,state3);
       previousState3=state3;}
       break;
        case 0x1FEB04F:
       if (previousState4 == LOW)
       {state4=HIGH;
        digitalWrite(led4,state4);
       previousState4=state4;}
       else
       {state4=LOW;
       digitalWrite(led4,state4);
       previousState4=state4;}
       break;
    }
    irrecv.resume(); // Receive the next value
  }
}

Error massage which I Getting during compiling

Arduino: 1.6.5 (Windows XP), Board: "Arduino/Genuino Uno"
Using library IRremote in folder: C:\Documents and Settings\Santanu
  Mandal\My Documents\Arduino\libraries\IRremote (legacy)
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard -IC:\Documents
  and Settings\Santanu Mandal\My Documents\Arduino\libraries\IRremote
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IRrecvDemowithled.cpp
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IRrecvDemowithled.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard -IC:\Documents
  and Settings\Santanu Mandal\My Documents\Arduino\libraries\IRremote
  -IC:\Documents and Settings\Santanu Mandal\My Documents\Arduino\libraries\IRremote\utility C:\Documents and
  Settings\Santanu Mandal\My
  Documents\Arduino\libraries\IRremote\IRremote.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IRremote\IRremote.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -x
  assembler-with-cpp -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605
  -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_pulse.S -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_pulse.S.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\hooks.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\hooks.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\WInterrupts.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WInterrupts.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\wiring.c
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_analog.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_analog.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_digital.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_digital.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_pulse.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_pulse.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -c -g -Os
  -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\wiring_shift.c -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_shift.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\abi.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\abi.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\CDC.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\CDC.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial0.cpp
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial0.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial1.cpp
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial1.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial2.cpp
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial2.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial3.cpp
  -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial3.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\HID.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HID.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\IPAddress.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IPAddress.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\main.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\main.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\new.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\new.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\Print.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Print.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\Stream.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Stream.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\Tone.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Tone.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\USBCore.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\USBCore.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\WMath.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WMath.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os
  -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program
  Files\Arduino\hardware\arduino\avr\variants\standard C:\Program
  Files\Arduino\hardware\arduino\avr\cores\arduino\WString.cpp -o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WString.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_pulse.S.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\hooks.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WInterrupts.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_analog.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_digital.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_pulse.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\wiring_shift.c.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\abi.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\CDC.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial0.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial1.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial2.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HardwareSerial3.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\HID.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IPAddress.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\main.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\new.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Print.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Stream.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\Tone.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\USBCore.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WMath.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-ar rcs
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\WString.cpp.o
C:\Program Files\Arduino\hardware\tools\avr/bin/avr-gcc -Os
  -Wl,--gc-sections -mmcu=atmega328p -o C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/IRrecvDemowithled.cpp.elf
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IRrecvDemowithled.cpp.o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp\IRremote\IRremote.cpp.o
  C:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp/core.a
  -LC:\DOCUME~1\SANTAN~1\LOCALS~1\Temp\build8586850450850335044.tmp -lm
collect2.exe: error: ld returned 5 exit status Error compiling.

Windows XP...... Sorry but we are in 2016 (almost 2017) and Windows XP is like not even supported anymore (since a LONG LONG time). Could that be your problem??

I have been faced with this GCC LD issue on Windows a million times. I finally decided to build all my Arduino stuff on Linux without any problem. This LD issue has loads of reported errors, discussions on Internet, with various weird workarounds that sometimes work once but fail the next time...

Sir, I have used  IDE 1.6.12 to compile this code but it also give error    Arduino: 1.6.12 (Windows XP), Board: "Arduino/Genuino Uno"
collect2.exe: error: ld returned 5 exit status
Using library IRremote in folder: C:\Documents and Settings\Santanu Mandal\My Documents\Arduino\libraries\IRremote (legacy)
exit status 1
Error compiling for board Arduino/Genuino Uno.

You have been bitten by a bug in the compiler toolchain. The bug has already been reported. Suggested workarounds:

add a few unused global variables
add some unused functions.


text:
How to display an entire incoming string from the serial monitor in arduino ide?
this is my first question in this forum.
I need to receive a string from the Arduino serial monitor and display it when the communication is over. I have a similar problem like the one discussed in this thread:
https://electronics.stackexchange.com/questions/45543/how-do-i-receive-an-entire-string-as-opposed-to-1-character-at-a-time-on-the-ard
Only I'm using the Arduino serial monitor instead of a RaspberryPi to send strings so I can't program the sender to attach an identifier like '\n' at the end of the string.
char inData[20];
char inChar=-1;
byte index = 0;

while (Serial.available() > 0){
  ending[1]=ending[1]+1;
  if(index < 19){

      inChar = Serial.read();
      inData[index] = inChar;
      index++;
      inData[index] = '\0';
      Serial.flush();
  }
  Serial.print(inData);Serial.print("\t");Serial.println();
}

What I receive in the console looks like this:
M
Me
Mes
Mess
Messa
Messag
Message

I need to display only the final string
Message

The code has to know when the incoming string ended and then display it once.
I'd really appreciate any help I can get.

You have two options. The most reliable is to decide that a particular character will serve as an end-of-message indicator. \n is a common choice, but you can choose whatever you are not going to use in the message itself. The other option is to have a timeout: if no further characters have been received for XXX ms, then assume the message is complete.

If you really want a string. Try using Serial.readString(). It will return the full string.
The code could look like this:
if(Serial.available()  > 0)
{
  String message = Serial.readString();
  Serial.println(message);
}

It is worth noting that Stream::readString() works with a timeout, which is 1 second by default, but can be changed with setTimeout().

Thank you, that's exactly what I needed. Now the output in the serial monitor is the entire text input. First post, first issue solved. I'm really grateful.


text:
Arduino Nano (3.0) Use an USB Bluetooth stick
I was thinking to build a very small USB Audio Streaming device with aux output for an amp (I know they already exist, but I like the self invention). So I bought an Arduino Nano and a USB Bluetooth device with was originally for a computer. But I thought I might use it on the Arduino. After I removed the housing and soldered four wires onto the USB plug:
https://www.dropbox.com/s/ye5vveb98sfz1zq/IMG_20161030_132648_01.jpg?dl=0
I needed to know how to wire them:
https://www.moddiy.com/product_images/uploaded_images/patillaje-conector-usb.jpg
So I connected:

"1" to 5V+ on arduino
"2" and "3" need to be connected to txd and rxd on the arduino (but I don't know whitch way around)...
I read that I need to have 3.3v on "3" or the "+" wire but I have 5V Output on the digital Pins on the arduino (so I need some resistors, but I'm not familiar with calculating them).
"4" to gnd

Can someone confirm and / or provide some information for me to get this thing running (Bluetooth device enabled and functioning)?
Further steps would be:

coding the arduino to Use the Bluetooth module for audio streaming - preferrably three Channel.
configure the arduino to give the stream to an amp.

I know my knowledge of electronics is not very good and I need some education. If you can provide some good learning websites - feel free to suggest.

Do note that USB (universal serial bus) is not the same
As the other serial bus. USB is by itself -I dont think is hard-but it does,
Truly use a lot of layers  In the protocol you need to get correct to get.
I  give a link be low. to a USB host implemented in software for ATMEGA32
I see the source code is there-which you may try and modify for your uses,
Read the USB software is implemented in using the tx and rx type pins of ATMEGA 32 -(the pairs of pins corresponding to
D+,D-)- as they write on the page there its easy to write a keyboard driver (though not done).

Only a few componenets are used in the solution there.
https://courses.cit.cornell.edu/ee476/FinalProjects/s2007/blh36_cdl28_dct23/blh36_cdl28_dct23/

This is a suggestionfor a starting point-note that its low speed USB so maybe  its not fast enough for your device-but maybe you can find a workaround for this

Interfacing an Arduino with USB is already VERY hard. USB does not use the same Serial as protocol so don't connect it to Tx and Rx. The only way to interface an Arduino and an USB device is trough a USB shield, which is quite complex already.
Just for you information. USB uses 5V so no voltage divider is needed to reduce it to 3.3V. A voltage divider is pretty much 2 resistors in series where the original voltage goes in one end, the output voltages is between the 2 resistors and the other end is connected to ground. Read more about them here.
Now, communicating with Bluetooth is also complicated, but mix USB + Bluetooth and you get something ALMOST impossible (I hope the ALMOST is clear enough for any hatters). It is possible, but seeing you level of knowlage, simply don't risk having a severe depression trying to fingure it out!
In the end of the day, your plan of using that Bluetooth USB module is just going to be crazy complicated and big.
A more effective solution would be to use a module such as the HC-05 Bluetooth module. It is quite cheap if you get it from sites such as Amazon. Link here for this product on Amazon.com. It is designed with the Arduino in mind thus making programming easier. You project could also be a little smaller, because this module pretty much has the size of your Arduino Nano.
Hope it was helpful!

A lot you have said here is right, but there's a glaring error.  While USB uses 5v power the signalling is not 5v.  When a low-speed USB connection is crudely implemented in software using GPIO pins of a 5v MCU, voltage translation is required.  Of course it's not going to work for the purposes of the question anyway, but the data lines are not rated for 5v.


text:
void loop followed by other "void" expressions
I hope this is a simple request from a newcomer to Arduino and programming. I have understood that once a program enters a void loop section, it loops round indefinitely. However I have recently seen examples of sketches where another void $$$$$ section follows the closure (by}) of the void loop. As I write this, I am looking at one example concerning a 7 segment display where "void Num_Write(int)" follows the closure of the void loop. If the "loop" section does just that, as I have been lead to believe, how is a following section accessed?
Thank you,
Rob

By calling it. https://www.tutorialspoint.com/cplusplus/cpp_functions.htm

It's also covered in the Arduino reference: https://www.arduino.cc/en/Reference/FunctionDeclaration

To top it off : http://www.cplusplus.com/doc/tutorial/functions/

The void loop() section is a function, the same as void setup() is a function.  When you start you Arduino program another function, that you can't see in the IDE, call setup() and then calls loop() repeatedly.
These other function you have seen, i.e. void Num_Write(int n) can be called from either setup() or loop() and they will execute their instructions before returning to the function that called them. Its also possible the Num_Write() may call other functions before it returns controller to the function that called it.
The type void is used to represent nothing (its actually more complex than that, but for this level of explanation nothing will do).  Other functions may return other types int, char, bool for instance.  So if we had a function like this:
int theMeaningOfLife(void)
{
  return 42;
}

This is a function that returns an int (a number) so you would call it like this:
void setup()
{
  int number = theMeaningOfLife();
}

There is one catch, the function has to be declared BEFORE it is used, this allows the compiler to know what you are referring to.  The simplest way of doing this is to write the function above the function that is calling it.  The second way is to just write the function's signature above the function using it, i.e.:
int theMeaningOfLife(void);

void setup()
{
  int number = theMeaningOfLife();
}

The best way (but not always practical on an Arduino) is to have all the function declarations in a header file (.h) and the code in a .cpp file.  (Have a look a library to see what I mean).
Summary
There is only one function that is called repeatedly and that is the loop function.
Just because a function returns void doesn't mean its going to loop repeatedly.

You wrote: “the function has to be declared BEFORE it is used”. Actually, the Arduino IDE runs your code through a pre-processing step that does that for you, meaning you do not have to do it yourself. I still would consider good practice to stick to this rule, if only because it makes the code compilable outside the IDE, e.g. with a Makefile.

@EdgarBonet - Thanks, I never knew that.  I think I should forget it though, otherwise I'll start trying it at work and end up pulling my hair out trying to work out why [it] won't compile. :)


text:
relay working problem
I am using circuits.io with Arduino. my program is to blink the led with 2 seconds delay. The led in the circuit blink according to program but the bulb does not blink. I am very weak in electronics. This is what i starting to learn from the scratch. the problem here is the bulb doesnt blink according to the program. which is meant to blink. i have uploaded the circuit image below.. . thanks in advanced.

Your layout makes no sense.  Please post a schematic showing all the circuit connections and the power input to the arduino.

you show no ground connection between arduino and relay, does this represent what you have?

this layout... use the schematic editor.

In the circuit.io layouts that I have seen, they do connect power to the Arduino board.  You have yet to do this. (There are other problems, but let's start with the obvious one 1st.)

Sorry, I downvoted this, because even after three hours of being pointed to a lack of clear schematic, you haven't tried to improve your diagram. Thus, no answer can be given, and your question holds no value in itself.

sorry i am lacking in explaining the question , m trying, as i said i am very new to electronics , what knowledge i have till date is i am using.
i do not have any schematics , i dont even know how to design it. what i am trying is to play with arduino boards hence ii am trying things only on circuits.io.
guys what i can provide is , the link of my circuit.
https://circuits.io/circuits/3117748-the-unnamed-circuit
u can start the simulation and check that how it is working.
i just need to blink the Bulb like the led in my circuit blinks. please take a trial from the link..

If you search for "arduino drive relay" you will get plenty of information. Note that all the circuits will have a diode across the relay: that is required to prevent other components from being damaged.

http://www.allaboutcircuits.com/textbook/direct-current/chpt-1/electric-circuits/

@AndrewMorton : ur suggestion helped me. i got the answer , user:emfields diagram helped me .

If you wire up your circuit as shown below, the bulb and the LED should flash together.


text:
LED won't turn on and serial monitor won't display values
I am trying to use my Arduino to record some values from a photo-resister. The idea is when a character other than g is read the LED will turn on and 512 values will be recorded.
When I type in a character in the serial monitor whether it is g or not it just says 1 or 0 but doesn't not provide me with the values I need from the photo-resistor. My code is as follows:
int timeOut = 60000;
int pollTime = 0;
int time = 0;
unsigned long startTime = 0;
unsigned long endTime = 0;
int x = 0;
int Vs[512];
int analogPin = 0;

void setup() {
  Serial.begin(9600);
  pinMode(9, OUTPUT);
  while (!waitFor('g', 200, 60e6)) {}
  analogWrite(9, 128);
  startTime = micros();
  for (x = 0; x < 512; x = x + 1)  {
    Vs[x] = (analogRead(analogPin));
  }
  endTime = micros();
  for (int x = 0; x < 512; x = x + 1)  {
    Serial.println(Vs[x]);
  }
  Serial.println(endTime - startTime);
}

void loop() {
}

boolean waitFor(char in, int pollTime, int timeOut)  {
  boolean done = false;
  char charWait;
  time = micros();
  while (time < timeOut)  {
    if (Serial.available())  {
      charWait = Serial.read();
      done = (charWait == in);
      Serial.println(done);
    }
  }
}

Since you never update time, then while (time < timeOut) {...} is an infinite loop.

Like Edgar says, what you need to do is this:
bool waitFor(char in, int pollTime, unsigned long timeOut)
{
  while (micros() < timeOut)
  {
    if (Serial.available())
    {
      if (Serial.read() == in)
      {
        Serial.println("done");
        return true;
      }
    }
    delay(pollTime);
  }
  return false;
}

If it still doesn't run after that then change setup() to this:
void setup()
{
  Serial.begin(9600);
  Serial.println("Initialising...");
  pinMode(9, OUTPUT);
  while (!waitFor('g', 200, 60e6)) {}
  Serial.println("g command received...");
  analogWrite(9, 128);
  Serial.println("About to start...");
  startTime = micros();
  for (x = 0; x < 512; x = x + 1)  {
    Vs[x] = (analogRead(analogPin));
  }
  endTime = micros();
  Serial.println("Finished...");
  for (int x = 0; x < 512; x = x + 1)  {
    Serial.println(Vs[x]);
  }
  Serial.print("The result is : ");
  Serial.println(endTime - startTime);
  Serial.println("All finished.");
}

This still doesn't print anything to the serial monitor.

OK.  Can you alter the setup function as above and report what the last line of output is.  If you get no output at all then check you have the correct serial port.

In the prototype of waitFor(), timeout should be unsigned long: and int can be no bigger than 32767.


text:
What is the datatype of the pinMode function?
I just tried it, but the Arduino IDE crashed, I hope its not related.
I want to declare a datatype like this:
int a = pinMode(pin, OUTPUT);

or something like that, but I'm not sure what datatype the pinMode function uses. I looked on the pinMode documentation page, of the Arduino website, and I see basic usage, but not a more clear definition of the source code for that function.

pinMode(pin, Mode); is a void. It doesn't return anything. It simply sets a pin as an OUTPUT or an INPUT.
It says it in the link you posted.

Returns
None

That means that the function doesn't return any value.


text:
Blank.txt at the End of Transmission
I'm using my HC-05 (Master) to receive strings from a sensor (Slave), each string is suppose to have 7 items divided by ',' like so "a,b,c,d,e,f,g". I also have to write these strings in a .txt file in the SD card, being that I receive the strings and save them in a string array to later be written to a file. For some reason I can't receive it and write it to a file simultaneously, it alters the string. So the best way would be an array but when i open the file it's blank and when I print it on screen it starts correctly then prints only the first char of what would be the string. I tried it with 80 strings and it works correctly, so I can only guess it would be insufficient memory, But wouldn't it still write to the file since there is something in the strings.
PS:I'm using Arduino Mega
#include <SD.h>

const int tam=480;
char aux;
File myFile;

void setup() {
  Serial1.begin(115200);
  Serial.begin(115200);
  Capture();
}

void openSD()
{
  SD.begin(4);
  if( SD.exists("test.txt") )
  {
    Serial.println("O arquivo de amostras sera removido");
    SD.remove("test.txt");
      if( !SD.exists("test.txt") )
        Serial.println("Arquivo removido com sucesso!");
  }
  myFile = SD.open("test.txt", FILE_WRITE);
}

void Capture()
{
  String test[tam];
  openSD();
  Serial.println("BEGIN");
  for(int i=0;i<tam;i++)
  {
    test[i]="";
    do
    {
      while(!Serial1.available());
      aux=Serial1.read();
      test[i]+=aux;
      Serial.print(aux);
    }while(aux!='\n');
  }
  Serial.println("END");
  for(int i=0;i<tam;i++)
    myFile.print(test[i]);
  myFile.close();
}

void loop() {

}

Your strings should barely fit in memory if each item is a single character.

Rules of sequential file is : It's saved when its closed, which mean if the file not closed properly, anything written before will not saved, and you'll get blank file.
so, if you get a blank file while you are sure that the data is received, the only possibility is your program doesn't reach
myFile.close();

one of the possibility is the received data not fit into your memory, so the '\n' is undetected.


text:
Get Battery voltage on raw
I power my Arduino Mini with 3 AA batteries on RAW input. Is it possible to get the voltage on RAW and therefore the expected longevity of the batteries?

No. Not directly. You can use voltage divider and measure the result with using internal reference. But it's another current consumption and you can't reduce it by (for example) entering one of the sleep modes.
And if you have 5V Arduino Mini variant, you can power it directly through 5V power pin. Otherwise you are losing about 1.5V on voltage regulator. On 3.3V variant it might be better, but it also depends on used regulator voltage drop and would be better to power it directly (if you don't have connected anything strictly with 3.3V power, and for AVR based Arduinos it's not a problem)
Anyway, if you power it directly, you can measure the power source voltage by measuring internal bandgap voltage reference against power as reference. But, as far as I know, it can't be done by analogRead, as it doesn't support other sources than analog pins.

What you can do is making a voltage divider using high value resistors and read that out on an analog pin. This isn't super accurate but gives an impression of the state of your batteries.

@Len Yes, I just don't like voltage dividers on batteries, when you need output impedance about 10k. However it's possible to use big resistors and capacitor big enough to charge sampling capacitor without bigger voltage drop.

Voltage dividers on batteries for measuring the voltage with the device they are powering can only work if the battery voltage is greater than the regulator voltage + dropout - otherwise your VRef will be a percentage of the battery voltage which makes measuring a percentage of the battery voltage meaningless. You need a stable reference (such as the band-gap) to measure what the Vref (Vcc) is. https://hackingmajenkoblog.wordpress.com/2016/02/01/making-accurate-adc-readings-on-the-arduino/

@KIIV I completely agree, I don't like it either but it is something. Majenko also points out some solid information.

You can indeed use a stable builtin voltage as reference. So you can check it against the max voltage.

Using internal voltage reff with voltage divider will solve your problem. Some arduino have 2.5v internal voltage reff while some have 1.1v


text:
code for line following robot not working perfectly
I have made a line following robot using 2 IR sensor. My line following robot was working successfully with this code.
#define LS 2      // left sensor
#define RS 3      // right sensor

/*-------definning Outputs------*/
int LM1= 5;       // left motor
int LM2= 6;     // left motor
int RM1= 9;       // right motor
int RM2= 10;

void setup()
{
  pinMode(LS, INPUT);
  pinMode(RS, INPUT);
  pinMode(LM1, OUTPUT);
  pinMode(LM2, OUTPUT);
  pinMode(RM1, OUTPUT);
  pinMode(RM2, OUTPUT);
}

void loop()
{
  if(digitalRead(LS) && digitalRead(RS))     // Move Forward
  {
    digitalWrite(LM1, HIGH);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, HIGH);
    digitalWrite(RM2, LOW);
  }
 else if(!(digitalRead(LS)) && digitalRead(RS))     // Turn right
  {
    digitalWrite(LM1,HIGH);
    digitalWrite(LM2, LOW);
    analogWrite(RM1,70);
    digitalWrite(RM2,LOW);
  }
  else if(digitalRead(LS) && !(digitalRead(RS)))     // turn left
  {
    analogWrite(LM1,70);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1,HIGH);
    digitalWrite(RM2,LOW);
  }else{
    digitalWrite(LM1, LOW);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1,LOW);
    digitalWrite(RM2, LOW);
  }
}

As I used only two sensor,sometimes it goes out of the line. So I have tried to make an advanced line following robot which could get back to track automatically when it goes out of the line.But the code is taking only the 1st value of tmp.(tmp=1) even when left sensor touches the line after white sensor and the robot goes out of the line.The value of tmp should be 2 when the robot goes out of the line and the left sensor touches the line after the white sensor.  Here is the code:
/*-------definning Inputs------*/
#define LS 2      // left sensor
#define RS 3      // right sensor

/*-------definning Outputs------*/
int LM1= 5;       // left motor
int LM2= 6;      // left motor
int RM1= 9;       // right motor
int RM2= 10;  //right motor
int tmp;

void setup()
{
  pinMode(LS, INPUT);
  pinMode(RS, INPUT);
  pinMode(LM1, OUTPUT);
  pinMode(LM2, OUTPUT);
  pinMode(RM1, OUTPUT);
  pinMode(RM2, OUTPUT);
}

void loop()
{
  if(digitalRead(LS) && digitalRead(RS))     // Move Forward
  {
    digitalWrite(LM1, HIGH);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, HIGH);
    digitalWrite(RM2, LOW);
  }
 else if(!(digitalRead(LS)) && digitalRead(RS))     // Turn right
  {
    digitalWrite(LM1,HIGH);
    digitalWrite(LM2, LOW);
    analogWrite(RM1,70);
    digitalWrite(RM2,LOW);
    tmp=1;
  }
  else if(digitalRead(LS) && !(digitalRead(RS)))     // turn left
  {
    analogWrite(LM1,70);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1,HIGH);
    digitalWrite(RM2,LOW);
    tmp=2;
  }
  else//out of the line
  {
    if(tmp=1){
      analogWrite(LM1,70);
      digitalWrite(LM2, LOW);
      digitalWrite(RM1,LOW);
      analogWrite(RM2,70);
    }else if(tmp=2){
      digitalWrite(LM1,LOW);
      analogWrite(LM2, 70);
      analogWrite(RM1,70);
      digitalWrite(RM2,LOW);
    }
  }
}

This test:
if (tmp = 1)

is always true. You are assigning 1 to tmp and that value (1), when
interpreted in a boolean context (i.e. as a truth value), is true.
You probably mean
if (tmp == 1)

and similarly for the next test.


text:
ATtiny84A support with "Attiny" board manager installed to Arduino IDE
Referring to page http://highlowtech.org/?p=1695, is it possible to program ATtiny84A as well, or just the chip version ATtiny84 (without "A")? Does anybody know?

6 years old question but anyway, tt works I can confirm, I have been using ATTiny84A-U, SOIC-14 chip.

According to the PDF ATTiny24/44/84 to ATTiny24A/44A/84A Migration AppNote it should be pretty easy as there are only some differences in electrical specifications. No changes in registers or so.
The signature bytes are the same too, so it should be posible even without adding another boards.


text:
Using Arduino as Keylogger
Is it possible to use arduino uno r3 as USB keylogger by connecting the usb male pin to CPU and keybord cable to female USB pin of arduino.
So that the keystrokes are stored in EEPROM. Without using an external storage modules or other components?
I am new to arduino, even suggestions are appreciated.
Thanks in advance.

It might help if you explained what you are trying to do.  Are you trying to capture passwords?  Repeat tests?

Yes it possible to to implement USB host in software but you need a few extra components, which are a few resistors
and a USB socket. What youre trying to do is make arduino a USB host for keyboard-some folks
have nearly done  this. I give a link be low. to a USB host  implemented in software for ATMEGA32 I see the source code is there-which you may
try and modify for your uses–they give a driver for mouse-and say the keyboard host (youre interested in)  is is possible
and easy (but not done). ATMEGA32 is similar to AMTMEGA 8 (used in older arduino).

Only a few componenets are used in the solution there-and its cheapers than a USB host shield-the software is there as a zip file -this is a suggestion for starting point-you need to modify software for you own use- see
https://courses.cit.cornell.edu/ee476/FinalProjects/s2007/blh36_cdl28_dct23/blh36_cdl28_dct23/

But for emjulating a keyboard on arduino-there's different ways to do it on arduino-it been done

Of course if you can manage to do the above  you would have good bragging rights-becuase no one made a cheap USB host (for keyboard)  for arduino/arduino library  -instead most people use USB host shield (costing about ten dollars or more)-it would save money of course. Its not as difficult as it looks.

arduino works at 16mhz pushed to maximum speed- that USB solution there  works on 15Mhz arduino-which means is can to do a low speed USB device such as a keyboard

Since you asked for USB (rather than a USB keyobard that also emulates PS2 with a passive adapter -which they dont all do) -I am assuming you have only a USB keyboard in mind -I gave a suggested answer only for USB.. I suggest try that. If you get stuck or have any further question then ask on here.  USB acting as PS2 keyboard or  PS2 keyboard can also be done and the answer has been fully fleshed out.

USB-host is hard if not impossible to implement on an UNO.
Though I believe most USB keyboards support PS2 as well (normally done with a USB-to-PS2 plug). So you should be able to talk to the keyboard using the PS2 protocol, which is a lot easier. There are libraries to do this for you.
Next you could use V-USB to emulate a keyboard to the PC. For that USB connection you need to add some resistors and zener diodes, to stay withing the usb specification. This is all explained on the V-USB website.
Using a different Arduino that has real USB support might be a better option. Also the UNO is rather large, so not that easy to hide.

It is highly unlikely using an arduino uno r3.
USB Device: (To emulate a HID (Human Interface Device) Keyboard):
While there are Arduino libraries for emulating a keyboard, these will not work with the Uno R3.  Instead, to make a Uno R3 act like a USB Keyboard Device, you need to reprogram the 2nd processor on the board and switch it from a USB Serial Device to a USB Keyboard Device.  This is talked about in this stackexchange question.
USB Host (to talk to a USB Keyboard):
I do not believe there are any software solutions for emulating a USB Host on most Arduinos. Certainly not a Uno R3.  A USB Host is a very complex software & hardware device. Instead, most Arduino projects use a USB Host Shield for this purpose.

Down voting with out a comment is not that unusual.  However, it does make it difficult to improve the answer.  Why do you think some of these answers are not correct?

No, it's not. Or not with any degree of ease. The best you could hope for would be to intercept the USB data and try and decode it, but that really is beyond the ability of a lowly Arduino.
I have thousands of dollars worth of equipment aimed at doing that kind of thing - it's not a simple task.

Then is there any possibility to do this?

If you use some device that can sample a signal in the high tens of megahertz (which an Arduino has no hope of doing) then you may be able to capture a waveform and decode it. Not with an Arduino though.

What are those device which can sample the signal. can you name them

Microcontrollers that run in the hundreds of megahertz. FPGAs. CPLDs (maybe). I use a TotalPhase Beagle 480.


text:
digispark - 2 pin push button to iterate through an hashmap
I'm trying to create a project with my digispark where i can iterate through an hashmap, when i press the push button the digispark writes via digikeyboard the values from an hashmap. Each time i press the button it's supposed to write the first value, then i press the push button again and in the same line it cleans what was written in the first value and writes the second value and so on. when the last value is reached it goes again to the first value if the button is pressed.
Right now i'm trying to put the iterator to work preperlly, this is the code i have:
#include "DigiKeyboard.h"
#include "HashMap.h"

HashMap<String, String> hashMap;
int i = 0;

void setup() {
   //setup hashmap
  hashMap.put("key0","test0");
  hashMap.put("key1","test1");
  hashMap.put("key2","test2");
  hashMap.put("key3","test3");
  hashMap.put("key4","test4");

  DigiKeyboard.sendKeyStroke(0);
  pinMode(0, INPUT);
}
void loop() {
  int sensorValue = digitalRead(0);
      while(sensorValue ==1 and i < hashMap.count())
      {
        delay(100);
        DigiKeyboard.println( hashMap.valueAt(i));
        i++;
      }
}

when i plug the digispark it prints automatically the first and the second value ("test0" "test1") and every time i press the button i get nothing.
This is my configuration:
http://cdn.instructables.com/FZA/0UN8/HI3TXV8D/FZA0UN8HI3TXV8D.LARGE.jpg
Can anyone help me please?

Have you read through your code yet?

hi there, yes, i've read it, and i know that the code don't do what i what to do but for now i just wanted to when i press the button the value from the first position appear, and when i push it again the next one appear in another line and so on...from there i would move for something more complex like cleaning the previous value and start from the beginning when the last value is reached...

You've looked at it, but you haven't actually read it. Read each line in loop() and understand fully what it does. Try explaining what each line does to someone else.

i've done that and the code inside the loop makes me sense: first loop: it reads the input from the pin 0, and enters the while, inside the while, while the sensorValue is equal to 1 (button pressed) and the i variable is less than the number of item inside the hashmap (5 items), in the first loop the i = 0 so 0 < 5 and it enters the while, inside the while it will print the value from the hashmap in the position 0 (test0), after this it will increment the i variable and start over again...

"sensorValue is equal to 1 (button pressed)" Those are two independent things. You have no idea what the state of the button is after the assignment.

thank you all.
i've manage to found a solution to my problem with this code, probably is not the most elegant way to do it but it works:
#include "DigiKeyboard.h"
#include "HashMap.h"

HashMap<char*, char*> hashMap;
int i = 0;
bool flag;

const byte switchPin = 0;
byte oldSwitchState = HIGH;  // assume switch open because of pull-up resistor
const unsigned long debounceTime = 100;  // milliseconds
unsigned long switchPressTime;  // when the switch last changed state

void setup ()
  {
  pinMode (switchPin, INPUT_PULLUP);

     //setup hashmap
  hashMap.put("key0","test0");
  hashMap.put("key1","test1");
  hashMap.put("key2","test2");
  hashMap.put("key3","test3");
  hashMap.put("key4","test4");

  DigiKeyboard.sendKeyStroke(0);

  }  // end of setup

void loop ()
  {
  // see if switch is open or closed
  byte switchState = digitalRead (switchPin);

  // has it changed since last time?
  if (switchState != oldSwitchState)
    {
    // debounce
    if (millis () - switchPressTime >= debounceTime)
       {
       switchPressTime = millis ();  // when we closed the switch
       oldSwitchState =  switchState;  // remember for next time
       if (switchState == HIGH)
          {
            delay(500);
            flag = true;
           while(i < hashMap.count() and flag == true)
            {
              DigiKeyboard.println( hashMap.valueAt(i));
              i++;
              flag = false;
              }
          }  // end if switchState is LOW
       }  // end if debounce time up

    }  // end of state change

  // other code here ...

  }  // end of loop

Even with a "clean" button, your while() loop will whip through all 5 hashmap values before you can release the button.
Switches and button aren't clean. They will (appear to) bounce, sending many pulses before they settle down to a fully on or fully off state. Read Nick Gammon's tutorial on de-bouncing switches.
I'm not familiar with your display but if it is a one-line display, and you .println() at it, will the newline character "scroll" the line of text off the display? This could explain why you didn't at least see the final line. You may need a plain .print() call in order not to do that.
Most LCD displays have a set of control codes to clear it, move the cursor, etc., which you would have to embed into the text string you send, or send using separate .print() calls. I don't see any provision in your code for including or sending those, so you'll need to fix that, too. Right now, I expect your display receives something like
test0\ntest1\ntest2\ntest3\ntest4\nIt probably needs to see something more like\033Etest0, e.g., for the first one, etc. That cruft at the beginning of the string is the VT52-code,escE, for "Clear the display". (I have no idea what command set your display uses, but the VT-52 commands have been in use for ... um, hmmph! well, a long time, anyway. :)  You'll probably to replace it with whatever your particular device uses.