text:
Not have to wait for if statement to run
I need some advice. I am trying to code a setup of 4 stepper motors that are connected to a keypad and 2 DC-motors that run a conveyor belt. My goal is to be able to push a key, the correspondning stepper motor starts and the DC-motors starts as well and run for a couple of seconds after the stepper. However, I want to be able to push multiple keys while the DC-motors are running. Right now I need to wait for the DC-motors to be done before I can push another key. How can I make this happen?
I think there will be issues if I code it with a timer since the keys are waiting for an input. I don't have any sensors.
This is my code:
#include <Keypad.h>
#include <Stepper.h>

const int stepsPerRevolution = 1024;

Stepper myStepper1(stepsPerRevolution, 22, 26, 24, 28);
Stepper myStepper2(stepsPerRevolution, 32, 36, 34, 38);
Stepper myStepper3(stepsPerRevolution, 23, 27, 25, 29);
Stepper myStepper4(stepsPerRevolution, 33, 37, 35, 39);

const int IN1 = 47;
const int IN2 = 45;
const int IN3 = 51;
const int IN4 = 49;

const int ENA = 43;
const int ENB = 53;

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'D','C','B','A'},
  {'H','G','F','E'},
  {'L','K','J','I'},
  {'P','O','N','M'}
};

byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8, 9}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
   myStepper1.setSpeed(10);
   myStepper2.setSpeed(10);
   myStepper3.setSpeed(10);
   myStepper4.setSpeed(10);

  pinMode (IN1, OUTPUT);
  pinMode (IN2, OUTPUT);
  pinMode (IN3, OUTPUT);
  pinMode (IN4, OUTPUT);
  pinMode (ENA, OUTPUT);
  pinMode (ENB, OUTPUT);

}

void loop(){
 // char key = keypad.getKey();
 char key = keypad.waitForKey();

   if (key){
    Serial.println(key);
//control speed
  analogWrite(ENA, 200);
  analogWrite(ENB, 200);
//control direction
int onTime   = 5000;
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);

// ----------------------------------Stepper1-----------------------------

        // just print the pressed key
   if (key == 'A' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper1.step(256);
  delay(100);
}

  // just print the pressed key
   if (key == 'E' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper1.step(512);
  delay(100);
}

  if (key == 'I' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper1.step(768);
  delay(100);
  }

  if (key == 'M' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper1.step(1024);
  delay(100);
  }

//-----------------------Stepper2------------------------

if (key == 'B' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper2.step(256);
  delay(100);
}

  // just print the pressed key
   if (key == 'F' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper2.step(512);
  delay(100);
}

  if (key == 'J' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper2.step(768);
  delay(100);
  }

  if (key == 'N' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper2.step(1024);
  delay(100);
  }

 //------------------------Stepper3--------------------

if (key == 'C' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper3.step(256);
  delay(100);
}

  // just print the pressed key
   if (key == 'G' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper3.step(512);
  delay(100);
}

  if (key == 'K' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper3.step(768);
  delay(100);
  }

  if (key == 'O' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper3.step(1024);
  delay(100);
  }

 //------------------------Stepper4--------------------

if (key == 'D' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper4.step(256);
  delay(100);
}

  // just print the pressed key
   if (key == 'H' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper4.step(512);
  delay(100);
}

  if (key == 'L' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper4.step(768);
  delay(100);
  }

  if (key == 'P' ){
    Serial.println(key);
     // step one revolution in one direction:
  Serial.println("clockwise");
  myStepper4.step(1024);
  delay(100);
  }

//---------DC_Motor---------

   delay(onTime);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);

 }
}

Have you checked the millis()?

If you want to know how to use the millis() to avoid using delay() check the BlinkWithoutDelay example in the Arduino IDE. File->Examples->02.Digital->BlinkWithoutDelay.

In order to do several things simultaneously you need to get rid of the delay() statements and also of the waitForKey() statement.
Instead the Keypad library offers the possibility to add an event listener with the function  keypad.addEventListener(keypadEvent).
Look into the example on the arduino page: https://playground.arduino.cc/KeypadTutorial/EventKeypad/

The delay(onTime); statement in the //---------DC_Motor--------- section of your code is preventing anything else taking place until the end of the DC motor run. Instead of delaying, you need to test how long the motor has been running, and do nothing if that time has not been reached yet. As others have pointed out, the BlinkWithoutDelay example program demonstrates how to do this. But in short, the motor section needs to do:
// Start motor here
timeMotorStarted = millis();
   :
   :
   :
if( millis() - timeMotorStarted > onTime ){  // has motor run long enough?
  // stop the motor
}


text:
Sim800l doesn't respond to AT commands
My SIM800L doesn't respond to AT commands. The serial monitor is simply blank.
And the led blinks every 3 seconds which means it is connected to a network
I power it through an LM2596 buck down converter with 4.0 v (I've tried to power with voltages until 4.4v), From a 12v power supply.
Can you help me?
(Please keep in mind that I'm an absolute beginner in this field. Thanks)
I used this wiring diagram from Last Minute Engineers.

And also their code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2

void setup() {

    Serial.begin(9600);

    mySerial.begin(9600);

    Serial.println("Initializing...");

    delay(1000);
    mySerial.println("AT");

    updateSerial();

    mySerial.println("AT+CMGF=1");

    updateSerial();

    mySerial.println("AT+CNMI=1,2,0,0,0");

    updateSerial();
}

void loop()

{
    updateSerial();
}

void updateSerial() {

    delay(500);

    while (Serial.available()) {

        mySerial.write(Serial.read());
    }

    while(mySerial.available()) {

        Serial.write(mySerial.read());
    }
}

Check the Tx and Rx wiring carefully. Do the Arduino Tx and Rx LEDs blink?

Yes. I used the same wiring diagram with a GPS module (minus the resistors) and it worked fine

source: Stack Exchange

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

sort: votes


text:
ard-reset-arduino resetting Leonardo/Micro via USB works on OSX, fails on Ubuntu
I'm trying to program a Leonardo (actually a Micro ATmega32U4) via the command line using USB.  Schematically, I'm doing ard-reset-arduino followed by a sleep 1 and an avrdude command.
This works reliably on my Mac (OSX 10.12.1, avrdude v6.3), but bombs out on Ubuntu (Ubuntu 5.2.1-22ubuntu2, avrdude v6.1) with the message:
.avrdude: butterfly_recv(): programmer is not responding

Update: I believe this is actually due to a failure to get the atmega32u4 into the bootloader.  See update at the bottom of this post...
Has anyone seen this?  Any suggestions for debugging strategies or things to try?
Details on the Mac:
Here is the command line with results under OS X:
$ ./ard-reset-arduino --verbose --caterina /dev/cu.usbmodem1411 && sleep 1 && /Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude -V -D -p atmega32u4 -C /Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf -c avr109 -b 9600 -P /dev/cu.usbmodem1411 -U flash:w:./leds_test.ino.leonardo.hex:i
Forcing reset using 1200bps open/close on port /dev/cu.usbmodem1411
/dev/cu.usbmodem1411 has come back after reset

Connecting to programmer: .
Found programmer: Id = "CATERIN"; type = S
    Software Version = 1.0; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.
Programmer supports the following devices:
    Device code: 0x44

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: reading input file "./leds_test.ino.leonardo.hex"
avrdude: writing flash (9146 bytes):

Writing | ################################################## | 100% 0.70s

avrdude: 9146 bytes of flash written
avrdude: safemode: Fuses OK (E:CB, H:D8, L:FF)
avrdude done.  Thank you.

Details on Ubuntu:
Here is the command line with results under Ubuntu.  Except for the pathnames, all of the options are the same as under OSX:
$ /boot/ard-reset-arduino --verbose --caterina /dev/ttyACM0 && sleep 1 && /usr/share/arduino/hardware/tools/avr/../avrdude -V -D -p atmega32u4 -C /usr/share/arduino/hardware/tools/avr/../avrdude.conf -c avr109 -b 9600 -P /dev/ttyACM0 -U flash:w:/boot/leds_test.ino.leonardo.hex:i
Forcing reset using 1200bps open/close on port /dev/ttyACM0
Waiting for /dev/ttyACM0 to come back
Waiting for /dev/ttyACM0 to come back
Waiting for /dev/ttyACM0 to come back
Waiting for /dev/ttyACM0 to come back
Waiting for /dev/ttyACM0 to come back
Waiting for /dev/ttyACM0 to come back
Waiting for /dev/ttyACM0 to come back
Waiting for /dev/ttyACM0 to come back
/dev/ttyACM0 has come back after reset

Connecting to programmer: .avrdude: butterfly_recv(): programmer is not responding

Postscript
Just to make sure I hadn't borked the bootloader somehow, I moved the Leonardo/Micro back to the OSX and re-ran the reset / programming sequence under OSX.  It worked without error, so I conclude that the resident bootloader is intact.
Update
I believe the real problem is that under Ubuntu, ard-reset-arduino fails to put the Leonardo into the bootloader.
Here's why I believe this is the problem: the resident sketch makes the onboard LEDs blink.  On the Mac, running ard-reset-arduino makes the blinking stop for about 8 seconds.  On Ubuntu, the LEDs continue to blink without interruption after the ard-reset-arduino command returns.
Update 2
Here's an even simpler Python program that resets the Leonardo under OSX but not under Ubuntu.
#! /usr/bin/python
import sys
import serial

ser = serial.Serial(sys.argv[1], 1200)
ser.close()

I'm somewhat embarrassed as to the source of the problem.  It wasn't an OSX vs Ubuntu issue.
Rather, on the Ubuntu system, there was an another application that was holding the USB port open, so attempts to reset the Leonardo were failing.
Rather than delete this post out of shame, I'm leaving it here in case someone else stumbles across the same problem.

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


text:
What is a cheap way to interface a USB keyboard to an Arduino Uno?
What is the cheapest way to interface a USB 2.0 keyboard to an Arduino Uno?
The keyboard does not support PS/2 emulation (interfacing a PS/2 keyboard to Arduino is easy). So this means the Arduino will read the USB keyboard's keystrokes - whatever their speed of input is.
If it can be solved using an IC then DIP is preferred as it quicker to work  with for soldering and pluggin into breadboard.

Don't it's a bad idea.  Or if you must, use a teensy LC in place of the Uno.

@ChrisStratton I know it possible to do becuase thheres a one chip solution-its here http://www.hobbytronics.co.uk/usb-host-board-v2

but I cant figure out the circuit from that photo-maybe iots based around a max 3421e? teensy LC at its cheapest is a cost of a few arduino Unos-so I dont think its that cheap.

What to figure out? The description text says: "The USB Host Board is based around the Microchip 24FJ64GB002 microcontroller which contains a built-in full-speed USB host controller".

@yabbadabba not true. The Teensy LC costs less than an Arduino Uno even before adding the host shield the latter would require, which probably makes the Arduino solution cost three times as much.  If you go unbranded, the microcontrollers are about the same cost, but the Kinetis as used by the Teensy is vastly more capable than the ATmega used on an Uno, and not only in its ability to be a USB host.  Granted, if you go with an unbranded or original board you'll probably need to use something like mbed USB libraries rather than Arduino-type ones.

@ChrisStratton Im looking ad different ARM CPUs now-which as you imply are about the same cost or cheaper and can handle USB host. Im looking at the  MKL03Z16VFG4 which is about $2 as a solution-but it doesnt look like its in DIP form. So what I need to know now is how to get started using ARM MCU.

There's hardly any MCU that can handle USB in DIP form.  You'll need to learn new techniques or buy something already on a board.  Not sure the kl03 does USB but the kl25z and similar do.  If it sounds complicated, remember the first thing I said was that the project was a bad idea.

It is currently totally unclear what the OP's project is, what is the scale of the project, and why there is such a limitation as DIP packaging. So we can't say if this is a bad or good idea.

@Chris Stratton Here a potentially cheap solution-its USB host implemented in software on ATMEGA 32 -unfortunately they only have driver for mouse not keyboard https://courses.cit.cornell.edu/ee476/FinalProjects/s2007/blh36_cdl28_dct23/blh36_cdl28_dct23/

With V-USB https://www.obdev.at/vusb/ it is possible to bitbang USB 1.1 on Arduino. If ARM MCU in DIP is needed, NXP has some: LPC1114 (M0), LPC1768 (M3)

The cheapest way is to get a plain PS/2 (or PS/2-USB convertible) keyboard instead of USB1.1 (I hope you mean the standard LS keyboard, since USB2.0 HS keyboards hardly exist), and interface it to GPIOs in accord with known solutions.
The Arduino Uno is designed around Atmega8u2 and ATmega328P chips, which can act as USB device only, FS and LS. To interface it with a dedicated USB keyboard (which is a USB device), the you need to have the Arduino as a USB host. Probably it is possible to emulate some limited hardware host functionality for LS mode (1.5Mbps) over GPIOs, but it will be a remarkable effort.

For the senario I am interested in I cant switch over to PS/2 unfortunately-as I mentioned in question if it was PS/2 it would be easy to do. I have a guess it can be done with using a single chip that acts as USB host in conjunction with arduino uno.

You asked for a cheap way. Of course, you can use a dedicated USB host controller based on MAX3421E chip (to SPI), aka "Arduino USB Host Shield", but it will cost you $20-$30, instead of an old junk PS/2 keyboard from some trash.

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


text:
Is it possible to upload a program from a tablet?
Is there any easy way to upload a program/sketch from an iPad or Android tablet without adding extra an shield (Bluetooth or Wi-Fi)?
If not, can it be done using shield? Which shield is preferred?
Also what are the IDE options available?

Related: http://arduino.stackexchange.com/questions/40/what-are-the-other-ides-for-arduino

"Which shield is preferred?" is a little to subjective without any criteria to base it on

I figured out a way to do this without having to port the compiler to iOS. It only works with the arduino Yún, but the Yún can send code to other arduinos with an spi cable.

Install an SSH app on your device so you can communicate with the arduino
Using that, install Ino on your Yún, a command line arduino compiler
Create a file, put your code in it, then save it
use Ino to upload your code!

kind of confusing, but it could work!

Unfortunately Apple doesn't allow apps that implement programming languages. This being said, it is unclear why they would not allow an app that has to do with the Arduino IDE due to the fact that the code doesn't actually run on the Ipad itself.
See here for more Info.
As far as an Android IDE, I have heard that there are a few people working on different IDEs that sends the code to the Arduino over the internet, although they have not been released yet, and the details are still a bit unclear.
Source:
http://forum.arduino.cc/index.php?topic=61305.0

Some arduino-eqsue systems already support programming via-Wifi -- Electric Imp comes to mind.

This comment is a bit old. There are many IDEs in the App Store these days including Python, Rust and Javascript to name a few.

You can always upload to the Arduino via Bluetooth.

You must have a bluetooth chip/shield (any should do) and a PC that has bluetooth (or a table that can compile, most likely an Android tablet)
You must change the BT baud rate to the same as normal arduino upload, which is 19200 (default BT baud is 9600).
Connect the BT to Pin 0 and 1 so act the same as having a USB cord connected
Connect a wire to the reset pin to allow remote resetting the arduino to statup the bootloader

There must be a delay before
hitting the reset pin as the bootloader must be active when hitting
the upload button.

Enjoy

For a more detailed description please read: http://ame2.asu.edu/staff/kidane/ArdWilessBtProg.pdf

Is there any easy way to upload a program/sketch from an iPad or
  Android tablet without a shield (Bluetooth or Wi-Fi)?

If you don't mind re-writing your program in an interpreted language,
one option is:

Install an interpreter on the Arduino, perhaps using the standard Arduino IDE running on a standard desktop PC -- like the bootloader, this only needs to be done once.

Then:

Use your favorite terminal emulator on the tablet
Somehow link the Arduino and the Android together, and tell the terminal emulator to talk over that link.(*)
Tell the terminal emulator to send the (more-or-less human-readable plain text) program to the interpreter over the link. (No compiler necessary on the tablet).

(*) There are several different ways to make this link; some of them are mentioned at How do I write an Arduino sketch and an Android application to talk to each other over a standard USB cable? .

Since your question is only about uploading, this will work with a Yun

compile your sketches with the IDE on your pc
for each hex file, copy it to the yun and run merge-sketch-with-bootloader.lua PATH_TO_HEX_FILE
manage to connect to the Yun from your tablet via SSH
once logged in, run run-avrdude PATH_TO_HEX_FILE

I have tried android app to programming Arduino Uno via bluetooth, simply by adding Bluino_Shield to your Arduino Uno. This link app https://play.google.com/store/apps/details?id=com.bluino.bluinoloader

i have been trying out arduinodroid - it's an ide that claims you can upload to your arduino from it. you need an OTG cable (on the go) and to be honest i never actually managed to upload from arduinodroid but others seem to be able to...
my arduino is currently not talking to my computer - a bootloader problem it seems - so i'm getting hold of an AVR ISP MKii - with one of them it is apparently possible to send from terminal ide - an android app, will feedback when and if i get it to work.

Yes, you can upload over BLE with free(mium) iOS app - Apploader
http://www.apploader.info

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


text:
Is an Arduino capable of running 24/7?
I'm making a simple Arduino web server and I want to keep it turned on all the time. So it must endure to stay working continuously.
I'm using an Arduino Uno with a Ethernet Shield.
It's powered with a simple outlet power supply 5V @ 1A.
My Questions:

Will I have any problems leaving the Arduino turned on all the time?
Is there some other Arduino board better recommended for this?
Are there any precautions that I need to heed regarding this?

First question!

Moderator note: we seem to be getting a lot of answers that state that it worked in their situation. If you have something technical to add to the question, feel free to answer. However, the technical answers seem to cover that it works. If you absolutely must state that your situation worked, it'd be better to add a comment.

You shouldn't have any issues keeping it on all the time, however, some thing to consider is any counters you may have, like the use of millis().
From the Arduino docs on millis:

This number will overflow (go back to zero), after approximately 50 days.

So for projects that are on for long periods of time, you may not see an issue immediately but something like this could pop up and cause errors down the road.

To be precise, millis is a uint32_t variable, so it will overflow ("go back to zero") in 4294967296 milliseconds, which is ~49.7 days, ~1193 hours or ~71582 minutes.

Then all you have to do is use another uint32_t that increments when the first rolls over.
Then you can enjoy roughly 5.846×10^8 years between rollovers.

A lot of the time, mills() rollover isn't really a problem because people tend to use millis() is a relative way. They will take the difference between two millis() calls, or they will take a start time, and check if millis() is greater than start+Time. Arithmetic rollover and millis() rollover often cancel out such that time2-time1 is accurate even if there is a rollover between them, as long as there isn't two rollovers. Often if your code uses absolute millis() values it can be refactored to use relative millis() logic.

if you do millis()-startTime  (with start time as a unsigned long, aka uint32_t), you'll always get a valid result unless more than one overflow is happened

To be more precise, the overflow happens after 49 days, 17 hours, 2 minutes, 47 seconds and 295 milliseconds.

The millis() overflow never has to be a problem. See millis() overflow ... a bad thing? for more details. Basically if you calculate time intervals by subtraction, using the appropriate data types, you will never have an issue.

Even if one doesn't use millis directly, I wonder whether one can be confident that neither of the imported libraries does.

A couple of things to keep in mind (outside of @Sachleen's mention of millis()):

Like any electronics, heat can be disruptive. The micro-controller itself isn't likely going to be a huge issue from the perspective of heat, but other components like the power supply might cause issues.
If your code uses EEPROM.write(), be aware that the EEPROM in your Uno's ATmega328P is only rated for 100,000 writes.

Keep in mind that the flash and EEPROM have limited lifetimes (about 10,000 and 100,000 write cycles respectively) so if you're doing a lot of writing to those, they may become corrupted. In a test I did, an external EEPROM took about 3 days to start becoming corrupted.

While the documentation may list 10k cycles, many tests have shown ~100k is where problems start to occur.

EEPROM lifetime is minimum 100,000 write cycles according to the datasheet. I think I remember reading a test where corruption started at close to one million writes.

Running the Arduino 24/7 Shouldn't be a problem.
But be sure that you have a case that allows for ventilation and you keep it in a well ventilated area. Just like computers, if you do not keep them in an environment that can keep them cool, they will not stay cool.
Server load also should be a thing to consider, the more load there is on the server the more processing it has to do, and the more heat it will generate.

The ATmega does not have traditional low-power modes like normal computers, so load is irrelevant. If you're not doing active computation, it's just spin-waiting. Power consumption when running is actually pretty much static (except things like writing to the EEPROM/flash), at least for the ATmega MCU. There may be variations in the ethernet interface power draw determined by traffic loading, but nothing is likely to generate enough heat to be an issue unless it's in a perfect vacuum or on a heater or something.

Atmega328p has a low power sleep mode that draws ~0.1 uA.

Which would only be relevant if the code actually puts the processor to sleep.

We've been running our Arduino-based RFID access system at Bloominglabs Hackerspace in Bloomington IN since late 2011 and aside from a couple power outages and software updates it runs around the clock, no problem. More recently we added a networked thermostat, same deal - it's running round the clock.

I too have an RFID access system running 24/7. The only time it "fails" is if the power goes off, because it runs from mains power. This has been running since 2011 with no issues.

Haha, hey Steve!

@NickGammon Yes, your system is cool, but why is auth not based on card DATA, but only token UID? Please show us a clever solution.

what's your point? that's unrelated to the poster's question.

Arduinos can run without issues for a really long time, though depending on local conditions and the intensity of computation you may have to attach heat sinks.
In addition, keep it well ventilated.
It depends on the program being used, too, if your server is serving a page every now and then, it shouldn't be an issue, but if you expect constant traffic then the Arduino may heat up quickly.
You'll also want to ensure stability of power supply, when running benchtop experiments with an Arduino this isn't a big issue, bit it can become an issue if transforming power from the mains for a permanent fixture.

There is no reason whatsoever to expect computational load to cause an Arduino to overheat.  As has been pointed out in the more fact-based answers, the normal case is to run at full load.  If there's a component that may overheat that will be the voltage regulator, but that is primarily a function of input voltage, since it is already running at nearly the highest expected current when doing nothing.

@ChrisStratton a Ethernet shield might vary power depending on usage. Also, the Arduino could be in a low power state (for example, sleeping between 12AM and 5AM).

I've never ran an Arduino for that long, but there shouldn't be a problem. One thing to watch out for is the input voltage.
While an Arduino is capable of handling 7-20v as input anything over 12v can overheat after longer periods of time and cause board damage. As a quick recommendation to avoid any overheating of the Arduino I would keep the voltage as close to 7v as possible.

I'd like to mention an issue that doesn't come up very often but can cause long term issues. Memory Leaks and Heap Fragmentation. Almost nobody mallocs in embedded stuff, but if you do, do it right.

You beat me to it, +1.

I believe the String class uses malloc and it's quite common.

Agreed. Especially with a web server, make sure you don't do anything that might fragment memory, like use the String class. However it is easy to avoid that. I have an Arduino running as a web server to let me know if my garage door is closed. That has been running for years.

I built a simple power monitor with my first Arduino. It is powered via USB from a web-server that in turn is powered via a quite substantial battery backup (which  does not have notification abilities).
It is also connected to a mobile phone charger plugged into a non-UPS power socket.
So if the power dies the Arduino sends a message to a little program running on the server. The server program in turn sends me an email notification.
It was installed in late September 2013, on the 23rd March 2014 - I got my first email!
So I have not seen a problem (it does not use millis() ) but it does sample the power every 5 seconds.

Is an Arduino capable of running 24/7?
This is a reliability question. In reliability, there are a lots of things to consider.

The software. There are more robust softwares. There are less
robust softwares. For instance, for critical applications, dynamic
memory allocation is discouraged, as it might lead to memory
fragmentation. Unfortunately, Arduino heavily relies on dynamic
memory allocation. This problem is exacerbated as most of the
Arduino board have a very limited RAM.
The libraries. Many Arduino libraries do have bugs (even those
built-in in the Arduino package, as simple as WString!). In normal
operation, such bugs may not appear at all. However, you can't hope
that "everything will be fine" and that "the user" (or subsystem)
will act as predicted. Libraries could also have their limits (i.e.
not properly bugs). For instance, many users already cited the
millis() function, which resets after 50 days. This, if not handled
correctly, might lead to severe bugs.
The reliability of the hardware (not even talking about cheap
Arduino clones...).  Here a new class of subquestions opens. I will
cite only a very limited subset.

Are the Arduino Boards designed for reliability? (e.g. what's the
reliability of the used capacitors? and other components?)
Robustness against EMI ? I wouldn't rely on that: most of Arduino boards have just two layers, and lack of a proper ground/power plane.
EEPROM (this is both software and hardware). Is your software using the EEPROM? Is implementing some algorithm to prevent cycling (repeated write/erase on the same cells)?
Flash memory retention time. Retention time decreases with temperature, and also with the number of programming cycles.
Ionizing radiation. Yes, even if the probability is VERY low, at least at sea level, the probability of radiation-induced single-event upset is not zero, and it adequate countermeasures should be taken (especially taken into consideration that the RAM has no hardware error detection) in critical applications.
The quality of the power supply.
The operating environment. A 25-°C controlled environment, or in a black box over the roof (70°C under the sun in summer)? The higher the temperature, the faster all the degradation mechanisms.
...

Still, you should not be surprised if your arduino will work flawlessy for many years. But this does not ensure that every arduino will.
Some countermeasures will increase the reliability:

Use the watchdog: it's better to reset a non responsive system, than
having a stuck/misbehaving one.
Avoid using any library that uses memory allocation.
Implement (if you use the EEPROM) an algorithm to preserve it!
Good power supply.
Avoid harsh evironments (high temperature, high humidity, large and continuous thermal cycles, etc).

It certainly can run 24/7. I either use 5V to the 5V pin, or a 7808 to the Vin pin to offload the vreg. Ideally it would be 6.5V, but I don’t have such supplies. You may want a decoupler cap on 5V though, to soak any minor spikes when powering up your supply.
Any hardware attached which runs at 5V, I feed with a 7805. You can use LM317s or LM350s in lieu of 78XXs, but you’ll need a few resistors for those, perhaps trimpots.


text:
i uploaded the code but when i open the serial monitor, but the 'sendCommand' isn't working in serial monitor...plzz help
#include <SoftwareSerial.h>
#define DEBUG true

SoftwareSerial esp8266(2, 3); // RX, TX

void setup() { // Open serial communications and wait for port to open:
Serial.begin(9600); //for monitoring purposes
esp8266.begin(9600);

  sendCommand("AT+CIFS+RST\r\n", 2000, DEBUG); // reset module
  sendCommand("AT+IPR=115200\r\n", 1000, DEBUG);
  sendCommand("AT+CWMODE=1\r\n", 1000, DEBUG); // configure as access point
  sendCommand("AT+CWJAP=\"ABCDEFG\",\"12345678\"\r\n", 3000, DEBUG);//connect to a network with name ABCDEFG with password 12345678
  delay(1000);
  sendCommand("AT+CIFSR\r\n", 1000, DEBUG); // get ip address
  sendCommand("AT+CIPSTA=\"192.168.43.16\"\r\n", 1000, DEBUG);
  sendCommand("AT+CIPMUX=1\r\n", 1000, DEBUG); // configure for multiple connections
  sendCommand("AT+CIPSERVER=1,6625\r\n", 1000, DEBUG); // turn on server on port 6625
  Serial.println("Server Ready");

  }

  void loop() { // run over and over
  if (esp8266.available()) {
  if (esp8266.find("+IPD,0,")) {
  delay(10);
  esp8266.find(":");
  delay(10);
  char letter = esp8266.read();
  Serial.print(letter); //for monitoring purposes
  //Gets the value/char from android app
   }
  }}

  String sendCommand(String command, const int timeout, boolean debug) {
  String response = "";
  esp8266.print(command); // send the read character to the esp8266
  long int time = millis();
  while ((time + timeout) > millis()) {
  while (esp8266.available()) {
  // The esp has data so display its output to the serial window
  char c = esp8266.read(); // read the next character.
  response += c;
  }
  }

  if (debug) {
   Serial.print(response);
  }
  return response;
  }

This isn't a "dump your code and make a statement" site. What is your question? This looks amazingly similar to your code at https://arduino.stackexchange.com/questions/52285/when-i-compile-this-code-it-always-sendcommand-was-not-declare-in-this-scope

sory sir..thats also my post...
that time...it already solve...
sory sir..

Questions like these are fine and well-answerable when they include a problem description, the expected behaviour, the actual behavior and the things you've tried, as it is highlighted in the How-To-Ask page (https://arduino.stackexchange.com/help/how-to-ask). But in this state no one can answer your question. If you solved it yourself you can also answer it yourself and accept it.

I don't know where you found (or how you came up with) this bit of code:
long int time = millis();
while ((time + timeout) > millis()) {
    while (esp8266.available()) {
        // The esp has data so display its output to the serial window
        char c = esp8266.read(); // read the next character.
        response += c;
    }
}

But it's horrible.
Not only is your time calculation completely wrong and will suffer a nasty death when millis() rollover occurs, but the whole concept of what you are doing there is bad.
The ESP8266 (assuming it's working, which hasn't been confirmed) sends a response that is terminated by a line-feed ("\n") character.  You are ignoring that and just reading for a pre-defined amount of time (badly).
Instead you should be reading up until you get that "\n" character, or breaking if your timeout has been exceeded.
For instance:
String sendCommand(String command, const int timeout, boolean debug) {
    String response = ""; // ugh... strings... yuck
    esp8266.println(command);
    uint32_t ts = millis();
    while (millis() - ts < timeout) {
        if (esp8266.available()) {
            char c = esp8266.read();
            if (c == '\n') {
                #ifdef DEBUG
                    Serial.println(response);
                #endif
                return response;
            } else {
                response += c;
            }
        }
    }
    return String("timeout");
}

Better that that though is to ditch those nasty String objects. Instead pass a char* buffer to collect the response in:
int sendCommand(const char *command, uint32_t timeout, char *response, uint32_t rlen) {
    esp8266.println(command);
    response[0] = 0;
    uint32_t rpos = 0;
    uint32_t ts = millis();
    while (millis() - ts < timeout) {
        if (esp8266.available()) {
            char c = esp8266.read();
            if (c == '\n') {
                if (debug) Serial.println(response);
                return rpos;
            } else {
                if (rpos < rlen - 2) {
                    response[rpos++] = c;
                    response[rpos] = 0;
                }
            }
        }
    }
    return -1;
}

Then you use that like this:
char response[80];

if (sendCommand("AT+CIFS+RST", 1000, response, 80) == -1) {
    Serial.println("CIFS Timed out!");
}
if (sendCommand("AT+IPR=115200", 1000, response, 80) == -1) {
    Serial.println("IPR Timed out!");
}

And so on.
By the way - that AT+IPR=115200 is a bit of a stupid thing to do. You create a software serial port at 9600 baud (fine), then almost immediately instruct the ESP8266 to switch to 115200 baud instead. You don't then start communicating at 115200 baud, but stay at 9600 baud, so communication can never continue from that point on.  Not only that, but SoftwareSerial is highly unstable at 115200 baud and is not recommended. Stick to 9600 baud.

thank you sir for the response sir..
i tried this change but the response is
= cannot convert 'bool' to 'char*' for argument '3' to 'int sendCommand(const char*, uint32_t, char*, uint32_t)'
i dont know why sir..


text:
when i compile this code it always 'sendCommand' was not declare in this scope..plzz help
#include <SoftwareSerial.h>
#define DEBUG true

SoftwareSerial esp8266(10, 11); // RX, TX

void setup() { // Open serial communications and wait for port to open:
  Serial.begin(9600); //for monitoring purposes

  sendCommand("AT+CIFS+RST\r\n", 2000, DEBUG); // reset module
  sendCommand("AT+IPR=115200\r\n", 1000, DEBUG);
  sendCommand("AT+CWMODE=1\r\n", 1000, DEBUG); // configure as access point
  sendCommand("AT+CWJAP=\"ABCDEFG\",\"12345678\"\r\n", 3000, DEBUG); //connect to a network with name ABCDEFG with password 12345678
  delay(1000);
  sendCommand("AT+CIFSR\r\n", 1000, DEBUG); // get ip address
  sendCommand("AT+CIPSTA=\"192.168.43.16\"\r\n", 1000, DEBUG);
  sendCommand("AT+CIPMUX=1\r\n", 1000, DEBUG); // configure for multiple connections
  sendCommand("AT+CIPSERVER=1,6625\r\n", 1000, DEBUG); // turn on server on port 6625
  Serial.println("Server Ready");

}

void loop() { // run over and over
  if (esp8266.available()) {
    if (esp8266.find("+IPD,0,")) {
      delay(10);
      esp8266.find(":");
      delay(10);
      char letter = esp8266.read();
      Serial.print(letter); //for monitoring purposes
      //Gets the value/char from android app
    }

String sendCommand(String command, const int timeout, boolean debug) {
  String response = "";
  esp8266.print(command); // send the read character to the esp8266
  long int time = millis();
  while ((time + timeout) > millis()) {
    while (esp8266.available()) {
      // The esp has data so display its output to the serial window
      char c = esp8266.read(); // read the next character.
      response += c;
    }
  }

  if (debug) {
    Serial.print(response);
  }
  return response;
}

I formatted your code and now you can see two } missing to close the loop. (and misplaced comment). and I added char before letter

sir..i add change the code but still, i cant compile it, it still says 'sendCommand' was not declared in this scope..

Then edit your question to reflect the new code, so that we can help you

You did notice that you declared and defined SendCommand() inside loop(), right?

sir sorry for being slow..
what loop() do you mean sir?

there is only one loop()

In loop you have three opening braces and one closing brace. This won't end well:
void loop() { // run over and over
  if (esp8266.available()) {
    if (esp8266.find("+IPD,0,")) {
      delay(10);
      esp8266.find(":");
      delay(10);
      char letter = esp8266.read();
      Serial.print(letter); //for monitoring purposes
      //Gets the value/char from android app
    }

Two more closing braces would fix it.

tnx sir..i can upload it now..
sory again sir...can i ask again sir..
i can upload it now but when use at command in serial monitor, no words is going out,,


text:
Hold a random number
I am trying to create a code that has at least 6 servos attached and two buttons for a two player game. I want to be able to roll a random number and have it hold that value then when it is that players turn. The program should also take that previous number and add it to the next. It would eventually be adding up all the values of the rolls. This is what I have so far. Any advice would be helpful. Thanks!
#include <Servo.h>

Servo myservo;

int pos = 0;    // variable to store the servo position
int x;
int button = 8;
int BUTTON;
int randomNumber;
int xPrevious;

void setup() {
    pinMode(button, INPUT);
    Serial.begin(9600);
}

void loop() {
  for (x = 2; x <= 7; x += 1) {
    myservo.attach(x);

    for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
      // in steps of 1 degree
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
    }
    for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position

      BUTTON = digitalRead(button);
      if(BUTTON == LOW){
        randomNumber = random(1,7);
        delay(350);
        Serial.println(randomNumber);
      }
    }
    randomNumber += xPrevious;
  }
}

You are redefining the random number wrongly each time with
randomNumber += xPrevious;

this is an error. You need another new variable (initialised at 0) to keep the running totals of all the random "rolls". You should be able to fix your program now you know this. Maybe something like
TotalofTherandomNumbers += xPrevious;

to start off with.
You may also want to add in the after the line
 randomNumber = random(1,7);

a new function, of yours, that takes random value randomNumber  do the action in the game, what ever that is,  depending on if its the first or second player.

Your xPrevious is declared but never given any value.
Is this what you're looking for?
    randomNumber += random(1,7);

Another thing is that you should not assume that randomNumber is initialized to 0. Better assign it a starting value.
    int randomNumber = 0;   // or whatever you want

Lastly, an Arduino int is a 2 bytes signed number. If the game goes on for a long time the variable will roll over at 32,767. Consider making it a unsigned long instead.


text:
2d 3*3 LED matrix code error
I have  written a trivial code in Arduino IDE but while verifying its returning a error displaying "i was not declared in scope 12'
  int pinMatrix[i][j]= {{2,3,4},{5,6,7},{7,8,9}};
void setup() {
for (i=0;i<3;i++){
  for(j=0;j<3;j++){
    pinMode(pinMatrix[i][j],OUTPUT);
  }
}

}

void loop() {
for(i=0;i<3;i++){
  for(j=0;j<3;j++){
      digitalWrite(pinMatrix[i][j],HIGH);
      delay(1000);
      digitalWrite(pinMatrix[i][j],LOW);
  }

  }

}

Variable i & j are not declared. They should be declared as 3. Try this:
const int x = 3;
const int y = 3;

int pinMatrix[x][y] = {{2, 3, 4}, {5, 6, 7}, {7, 8, 9}};

void setup() {
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      pinMode(pinMatrix[i][j], OUTPUT);
    }
  }
}

void loop() {
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      digitalWrite(pinMatrix[i][j], HIGH);
      delay(1000);
      digitalWrite(pinMatrix[i][j], LOW);
    }
  }
}

tried it , it ain't working and is returning the same error

Try it again, the code I posted, and post the FULL eror message.

Thanks!!                                                                                yeah by mistake i wasn't reading the full error message , now i read it and i made the changes, the code is running now

Please accept the answer if this answer helped you. It means that this question is resolved and needs no further attention.


text:
Combining Strings into a datestamp
I'm creating a weather station / environmental datalogger and am saving my data to a SD card Breakout. The SD card works fine but I would like to name the files I am saving on it after the date when the readings were taken.I've tryed multiple things but I can't work out how to combine the date from my RTC and put them in a file name. I've tryed this:
dataFile = SD.open(String(now.day()) + "-" + String(now.month()) + "-" + String(now.year()) + ".csv",FILE_WRITE);

But this gives me an error -
char dateName[13] = {String(now.day()) + "-" + String(now.month()) + "-" + String(now.year()) + ".csv"};
dataFile = SD.open(dateName,FILE_WRITE);

But this gives me this error:
 cannot convert 'StringSumHelper' to 'char' in initialization

Help! How do I do this?

EDIT: As noted by Klaus Warzecha, the SD library may only support 8.3 format filenames (i.e. 8 characters for the name, 3 characters for the extension). The solution may in fact be to ensure that the years is only 2 digits, resulting in names like: 20-12-14.csv

From what I can see in the SD library code, the open() method isn't designed to accept a String object as a parameter. It only wants a plain old C-style string (which means a char array). That explains why your first example doesn't work -- it's trying to pass a String object.
The second example unfortunately is invalid C++. You simply can't initialise an array like that. What you want to do instead is to build the String object, then extract the characters out using String::toCharArray().
Something like this should work:
String filename = String(now.day()) + "-" + String(now.month()) + "-" + String(now.year()) + ".csv";
char str[16] = {0};
filename.toCharArray(str, 16);
dataFile = SD.open(str, FILE_WRITE);

I'm not sure what your now.year() returns; i.e. if that's a 2 digit or 4 digit year. I've assumed 4 digits, so I've made the char array big enough for 15 characters in total, plus an extra null terminator (which is essential for C-style strings).

The SD card doesn't get files saved onto it when using this.

Can you check if it works when you write the filename manually? E.g.: dataFile = SD.open("test.csv", FILE_WRITE);

@SquarePie I tested the filename code just now, and it works as expected. I suspect the problem must be somewhere else in your code (or possibly the hardware).

@SquarePie I suggest you create a new question for this more specific SD write issue; it seems to me (but it's you to decide) that the current question has been correctly answered.

Is this based on the SDFat library?
Then you have to live with short 8.3 filenames for the moment.

It looks like this applies to the core SD library too. I hadn't noticed that. Well spotted.

In your second case, you need to break the initialization into two lines and use toCharArray() as shown:
char dateName[13];
String(String(now.day()) + "-" + String(now.month()) + "-" + String(now.year()) + ".csv").toCharArray(dateName, 13);

Then, you can move ahead with opening the file.
The problem you are seeing is quite literally what the error message says. An initialization of a character array requires a character array. It cannot be initialised with a string object.

The SD card doesn't get files saved onto it when using this.

@SquarePie That's odd. Maybe there is something wrong  elsewhere, in the code, or in the hardware?

//////////////////////////////////////////////////////////////
String filename = String(now.month()) + "-" + String(now.year()) + ".csv";

char str[16] = {0};

filename.toCharArray(str, 16);

File dataFile = SD.open(str, FILE_WRITE);

//////////////////////////////////////////////////////////////

Add some explanation to your code only solution.


text:
Connect to more than one Arduino with Adobe AIR
I am using the arduinconnector ANE to connect to an arduino baord in an AIR application. https://code.google.com/p/as3-arduino-connector/
Can anyone tell me if its possible to connect to more than 1 board, simply by instantiating additional instances of the ANE and passing in unique port #'s?
Or is there some reason why this isn't possible and a unique AIR application is required for every arduino you connect to?

don't know if this is a definitive answer, or only pertains to this ANE, but was told by the dev that The flash runtime is all shared memory space, so you will run into conflicts. Needs to be reengineered.

This seems to be possible with as3Glue as per the docs:

as3Glue is an ActionScript 3 library that enables communication between Flash/Flex/AIR applications and Arduino boards. It can together with one or several Arduino boards be used to monitor sensors (such as rotary encoders and motion detectors), control actuators (such as LEDs and motors) and interface other electronics (such as RFID readers) from Flash, Flex and AIR applications.

as3Glue can be used with as3-arduino-connector as mentioned in the docs:

Using with as3Glue
Download either the SWC or Source Code from the Downloads section of this project for a patched version of as3Glue. This patched version has the exact same interfaces as v20, with a notable exception of the constructor. When you instantiate a new "Arduino" object, replace the IP address and port with the COM port and baud rate. For example :
public var myArduino:Arduino = new Arduino("COM10", 57600);


text:
Turning a DC motor a set number of Rotations using an encoder
I'm using an arduino UNO, and i want to turn a motor a set number of revolutions, i'm trying to read the clicks of the encoder which has a resolution of 360 clicks/ revolution, my logic is that i count the number of clicks until i get to the desired number which represents the the number of revolutions * the resolution of the encoder:
1 revolution ==> 360 clicks
5 revolutions ==> 360*5 (desired number)
i'm a beginner with arduino so here is my code:
volatile int counter=0;
int motor=5;  // motor is connected to pin 5

void setup(){
  pinMode(motor,OUTPUT);
  attachInterrupt(0, count,RISING); // attaching encoder on interrupt 0
}

void loop(){
  while(counter< 360*5){
    analogWrite(motor,255);
  }
}

void count(){
  counter++;
}

This code is not working at all, how can i fix it?

You need to tell us what "not working" means. If it doesn't do what you want, What does it do?

There are so many potential issues here: oscillating across encoder ticks even when the motor is "not moving" (most designs of that resolution interpret a quadrature encoder to give a reversible count and ignore stationary vibration), integer overflow in a relatively small number of revolutions, lack of allowance for acceleration and deceleration.  What type of motor/reduction?  Is the encoder directly on the motor or after the reduction?

Thanks for the response, i'm actually simulating this on Proteus, and since it is an ideal model i don't think it has these issues, i'm really skeptical about the code itself, i think there is something wrong about how i'm reading the encoder.

How do you drive the motor? Directly attached to Arduino or using a motor driver (shield)?

I'm simulating this on ISIS, i'm using a mosfet to drive the motor.

You never tell the motor to stop.
void loop(){
   while(counter< 360*5){
     analogWrite(motor,255);
   }
   analogWrite(motor, 0); //add something like this or whatever could stop it
   //you may want to disable the counter now too
}

However, even with that change you are likely a long way from having a working, or at least reliable system - see other issues in my comment on the question.

But i'm telling it to run only if the condition is right, nevertheless i tried it and it isn't working.

The output statement you are using continues to generate the requested output until countermanded.  So if you want to stop doing that, you must tell it to do something else instead.  But there are doubtless other problems as well.

Since the Encoder resolution is high, the Arduino Uno misses some pulses hence you could not get the accurate reading from it. You could use the hardware quadrature decoder in Arduine Due board which can easily read the encoder values.
Here is a code which can only be executed in arduino Due to Read one quadrature encoder.
How to configure 2nd Quadrature Decoder IO pins in Arduino IDE


text:
How do I write an Arduino sketch and an Android application to talk to each other over a standard USB cable?
How do I write an Arduino sketch and an Android application to talk to each other over a standard USB cable?

You can use one of the many usb interfaces

Android devices usually don't have a USB host: they expect to be connected to some smarter device like your computer. Same goes with Arduino.
For this reason Arduino made the Mega ADK (that means Accessory Development Kit).
Mega ADK and Due act as USB hosts and can be connected directly to your Android phone. If you already have a board, another option is to get a USB host shield to add USB host capababilities.
Your sketch will tell the phone what kind of accessory application it is and your phone will download the appropriate application from the store.
There is a book about connecting Arduino to Android.

There are converters from mini USB to USB-A host.

@anorton Yes: those are OTG cables... see my post.

The premise of this answer was outdated years before it was posted - most contemporary android devices were intended to have USB host support, though there are cases where some quirk of the design leaves it broken.

You never mentioned your tablet model... or Arduino model
There are some tablets designed to work with USB flash drives and printers. This is called OTG (on the go.
You need:

A tablet supporting OTG
An OTG adapter that fits into your tablets USB slot and is compatible
The Arduino Uno Communicator App
Arduino Uno (or clone) [Note: It says that it works with Atmega16U2 or Atmega8U2 programmed as a USB-to-serial converter so I would assume that that would cover a few boards more than the Uno.)

Another alternitive is to look into Bluetooth (Note: I just picked a random link but there are hundreds of similar BT adapters)

Note that standard Android USB host mode does not support flash drives with any operating system functionality (though a few vendor builds do) - rather, it exposes a fairly raw USB host API to application code.

Processing is a great place to get started with device to device communication.
The interface and language are very similar to Arduino and there are many examples to get you started.
http://playground.arduino.cc/Interfacing/Processing

Does that run on Android?

@AnnonomusPerson Yes, processing for android

@Faux_Clef Hmm didn't know that. I still don't know if it's the best for Android, that link that you posted didn't seem like it was very stable... I know that processing has USB support but I don't know if you can do that on Android...

The USB protocol requires one end to be a "host" and the other end to be a "peripheral", and it doesn't work if the devices at both ends of the cable are "peripherals".
Alas, most Arduinos and many early Android devices are "peripherals", so connecting such devices with a standard USB cable doesn't work.
Some modern Android devices support "OTG", so in theory one could make the Android end of the cable the "host". Has anyone gotten this to work?
Another approach is to somehow make the Arduino end of the cable the "host", and the Android end of the cable the "peripheral".
That's the approach taken by

Microbridge (a) (b)
The IOIO board (a) (b)
The Android Accessory Development Kit (ADK) (a) (b) (c)

(The Amarino (a) and Cellbots (a) (b) take yet another completely different approach).

You can connect Android and Arduino with usb and use the easy tool App inventor 2 for android
Did you try this new application : https://play.google.com/store/apps/details?id=bp.usbbridge.appinvDemo and full version : https://play.google.com/store/apps/details?id=bp.usbbridge.appinv
Find Videos about Explications : USB OTG Bridge Serial UART for APP Inventor 2 and ARDUBLOCK on youtube


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

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

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


text:
Converting Arduino UNO's analog pins to digital I/O
I am working on an Arduino UNO Project and running out of digital pins.
Can I convert the six analog pins to digital I/O and use them to drive servos?
Please suggest me a method

Just putting it out there that it is a Uno, not a UNO. It is not an acronym.

A0 through A5 already have GPIO capability; treat them as you would any other non-PWM pin.
A6 and A7, found in similar boards that use a SMD package, do not have any GPIO capability whatsoever and can only be used for analog input.

Please explain.  Can I use A1 To A6 to drive my servos Normally ??

Only PWM-capable pins can drive servos normally.

The servo library uses software pwm if I'm not mistaken. So you should be able to use any pin.

@RanjanJha: A0 to A5 can be referred to as  D14 to D20. You could use digitalWrite(A0)  or digitalWrite(14) and the effect would be the same.


text:
Suggest me an Arduino development board, with a removable ATmega chip?
I want to buy an arduino development board which has facility to remove its chip and insert a new one anytime. I want to use multiple chips in a single board for different purposes.
If it is not possible, Please suggest me any alternative.

You have another post Which Arduino has maximum features? which also requests Suggest me an arduino board - this is pretty close to a cross-post of the same question.

@NickGammon - I understand where you are coming from, but it is not necessarily true. If the title of this question was changed to "Suggest me an Arduino development board with a removable MCU", which would more accurately describe the meat of this post, then the answer to the other question would arguably be the Arduino Mega, in lieu of the UNO.

Yes, putting the two posts together it is unclear if the OP wants maximum features or a removable chip. Maybe he wants the board with maximum features that also has a removable chip? Or maybe he wants two boards recommended? It isn't clear.

Only the Arduino Uno has a socketed IC chip. All the rest are using soldered SMD ICs.

And the 2009, but almost no one uses those anymore.

I don't think you can buy Duemilanoves anymore. Also, make sure you don't get the Uno SMD obviously.

Never underestimate the capabilities of NOS.

"I don't think you can buy Duemilanoves anymore." see http://www.ebay.com/sch/i.html?_nkw=duemilanove and increasingly more sellers again offer Uno variations with other USB helper chips than the 8u2/16u2, so that could be seen as 2015ish version of Duemilanoves. And there is not much difference in handling between Uno and Duemilanove when you update your "2009er" to Optiboot.

The ultimate solution would be to build it yourself!

Arduino has an excellent step by step guide on how to build a standalone Arduino, using a ATMega328, on a breadboard. Now everything is removable, not just the chip.
Note that there is one slight error in the guide, which I have highlighted here, Arduino Standalone - photo shows incorrect pin wired to MOSI.
There is a video on how to achieve, more or less, the same thing, 1-Day Project: Build Your Own Arduino Uno for $5.

You could get an ATmegaXX8 target board from Evil Mad Scientist. That has (or can have) a ZIF socket so you can easily remove the chip without bending its legs.

That's around $US 3 for the board, $2 for the ZIF socket, $1 for the crystal, 45 cents for the ICSP header.
You can put an Atmega328P into the socket (same chip as on the Uno). Note that some soldering is required. You would need to solder on the ZIF socket, the ISP header, and make up an FTDI header if you wanted to easily program it from the IDE.
You would also need (or it would be helpful to have) a 16 MHz crystal along with 2 x 18 pF capacitors. They have them for sale at that site.
You would also need a 10 k pull-up resistor for Reset, a couple of 0.1 µF decoupling capacitors, and another 0.1 µF capacitor for handling reset via the FTDI interface - if you use it.
If you want to program serially (and do serial debugging) you need some sort of USB interface, such as an FTDI cable or board.
Example FTDI Serial TTL-232 USB Cable.

That is around $US 18. (Of course, you only need to buy the cable once, so this is a one-time cost).
You would need to solder in 6 header pins in a line to plug that into (on the prototyping area) and then run appropriate wires to Tx/Rx/Gnd/5V and Reset via the 0.1 µF capacitor I mentioned.
Adafruit have an Arduino bootloader-programmed chip (Atmega328P) for $US 6.
All-up it would probably cost you around $US 30 to put it together. (The FTDI cable is a once-off cost, as you can use that on multiple projects).

Other vendors will probably have similar products.

I'm going to second the EMS board because those pin labels are super handy to have (and unstoppable when you pair it with one of these. Can't say I like how far the crystal is, but at 20MHz it doesn't seem horrible. But get yourself a EvUSBasp; the 2015 edition has a tiny 3.3V/5V switch (and don't forget the 10-to-6-pin adapter if you need one).

Good idea. In fact you can make those labels yourself, see Arduino Breadboard Labels

It is possible, you could probably do it on most of the Arduino boards too.
This page on the Arduino website may help you - https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard
I have personally never attempted it but I know quite a few people who have and they have never had too many big issues.

If the question is driven by need of minimizing the overall cost, well, on ebay you can find plenty of Arduino Mini Pro at about $2, shipment included. Add an USBASP programmer at the cost of $5 and you get a solution which is still pretty cheap and allows each board to be used, rather than having just one with multiple chips to insert/remove.
At a fraction of the cost of the other solutions described here.


text:
Suggest me a power source for my Arduino UNO project
I am working on a Project with:

1 Arduino UNO
5 micro 9g servos (Only one Working at a time)
2 small LED bulbs
1 MicroSD reader module
1 Speaker

Can I power my Arduino UNO with a common 9v Battery?
I also have in mind to use an external power supply for servos... but what to use?
Please suggest me a perfect power supply system

Have you looked into methods of voltage regulation? What about different batteries? Do you have any size, space or cost restrictions? You're really asking too much of Arduiono.SE to do all the work.

Unfortunately, the perfect power supply system doesn't exist yet. However, powering an Arduino is simple.  You have to main options 9V for standard "full size" Arduinos (such as the UNO that you mention), although you could go for the low voltage 3.3V options.
Covering just the 9V option, from the Power section of Arduino Uno:

Power
The Arduino Uno can be powered via the USB connection or with an
external power supply. The power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter
(wall-wart) or battery. The adapter can be connected by plugging a
2.1mm center-positive plug into the board's power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER
connector.
The board can operate on an external supply of 6 to 20 volts. If
supplied with less than 7V, however, the 5V pin may supply less than
five volts and the board may be unstable. If using more than 12V, the
voltage regulator may overheat and damage the board. The recommended
range is 7 to 12 volts.

You should probably also take a look at Power Supplies, in particular the section on Batteries and cells, also from the following section Voltage conversion and regulation, it states:

In a very simple scenario, you connect a disposable 9v battery
(probably one of the (approx) 4cm x 2.5cm x 1.5cm units with two snap
connectors on one end) to your Arduino, and the Arduino's built in
voltage regulator takes care of reducing the voltage to a consistent
5v or 3.3v, depending on the sort of Arduino you have.

So you have a couple of choices regarding 9V, either the P9 cell

or a pack that holds six 1.5V AA or AAA batteries.
You may find this link, How to run an Arduino (clone) on (AA) batteries for over a year – part 2, an interesting read. Here the chap uses four AA batteries, which only gives 6V, to power an UNO:

I have just highlighted some information, you should take the time to read the links fully, and google for more information.

Regarding the servo motors, more current may be required. You can use the same four AA battery pack, thusly:

but the capacity of the batteries may leave something to be desired, especially if you use rechargeable batteries (which in today's eco-concious world, you should), so you may require something more hefty. A quick google will show you the options available.
Addendum
The video Flite Test : RC Planes for Beginners: Batteries and Safety - Beginner Series - Ep. 7 is an extremely useful video tutorial about LiPO batteries for RC projects.

Selecting a power supply involves considering the following:
1. Voltage Requirement
2. Current Required
3. Running duration
4. Cost
Voltage Requirement:
From the list of items specified all of your items except the microSD card (which works at 3.3V) works at 5V.
Current Requirement:
Arduino UNO: about 50mA
9G servo motor: 730mA peak
LED 5mm: 20mA*2 = 40mA
microSD Card Reader: 200mA peak
Speaker: 350mA
Total Current: 1.370 Amps
Running Duration:
Say I want this device to run for 1 hour straight, in order to this I will need a battery supplying 5V 1370mAh and a 1C rating. So if you want your device to run longer you will need to get a battery with a higher capacity (for 2 hours 2740 mAh and so on)
Cost
I dont think i need to mention much in this criteria
Solution 1:
For these requirements your easiest solution is to use a USB power bank with 2000mAh or more.
On a protoboard solder 1x USB male, 1x USB female, 2x header pins. Solder All the positives together and all the negative together. And now you have a breakout for the power rails from the USB as well.
Power the Arduino via usb, microsd card via the 3.3V on the arduino and the rest via the breakout pins.
Solution 2:
Using lipo batteries. Lipo batteries have the advantage of having a large capacity in a small package (or a high power to weight ratio). In order to use this you will need a voltage regulator to get 5V. Please note that as per the calculation you will need a total of 1.37A to power your device at peak, this cannot be done via the on board regulator of the Arduino.
In total you will the following components to get this to work:
LiPo battery
Voltage regulator
LiPo Charger
Solution 3:
Using Alkaline battery. You can refer to the Minty Boost tutorial over at Adafruit to learn about this.
Conclusion:
If you want a headache free solution to your problem, buy a USB power bank , but if you want a more customizable and low cost solution go for the LiPo battery
And if you dont need a portable solution. Go for a wall adapter 5V/2A, thats pretty much every high end mobile phone charger

Everything @Greenonline said plus...
A 2 Cell Lipo battery is 7.4 V. A modest 500 mAH battery would run your project for several hours, perhaps days. If you're not satisfied with the run time, buy a battery with more mAH, they go well past 5000 mAH! After all, these are the same types of batteries used in all forms of Radio Control Aeromodeling (lots of servos and brushless DC motors).
The Uno can regulate the 7.4 V although you'll need to buy/build a cable to connect the battery to the Uno. I'm not sure how much current the Uno regulator can provide but I've driven two micro servos with mine.
If the servos chatter, hum, are otherwise not working right or if there is smoke coming out of the regulator, you probably need a separate power source for the servos. A BEC like this https://en.wikipedia.org/wiki/Battery_eliminator_circuit is an inexpensive alternate and also a common RC part. :)

If you can, run it all off a 1S Lipo battery, which may involve finding servos that can tolerate the lower voltage. Also, the on-board regulator can handle about 1A but I really wouldn't try it for more than 500mA given the board's construction.

+1 - Good point about LiPO... I've added a link to a video tutorial to my answer.

I have had a lot of success using an off-the-shelf power bank - they're easy to get, already have charging circuits (from USB), and are at the right voltage (+5V). You can plug the power bank directly into the USB port of the Arduino.
The only problem I've had is that some power banks shut down if there is not enough current being drawn - a resistor from +5V to GND solves that problem (make sure you work out how many watts your resistor is letting through, to make sure it can dissipate the heat - I used a 100Ohm resistor, at 5v; I put "Ohms Law calculator" into google, filled in 5V & 100 Ohm, and found that it needed to be a 1/4 watt resistor - perfect! I also noted that it drew 50 milli amps AKA 0.05 amps. I tried resistors with a higher resistance e.g. 200 Ohm, and the power bank powered down. If your project is drawing more power (continuously!) then you might get away with a higher resistance).
My power bank can supply 1.5 Amps, which should be plenty for your project.

You can use 9v battery and use separate one for servos. Due to voltage being "relative," you still need to connect the grounds.
You can connect the + of the battery to the VIN of the Arduino.


text:
ATtiny461 PWM CTC mode help
I am a beginner at AVR and programming. I am using ATtiny461 and asked to make code to use timer in PWM and CTC mode and use interrupts and pin toggle, this code worked for me with normal timer and toggle but I don't know how to make it work with CTC and PWM:
#include <avr/io.h>
#include <avr/interrupt.h>

//Init PD6 pin as output
void InitPort(void)
{
    PORTB&=~(1<<PB1);//initial value 0
    DDRB|=(1<<PB1);
}
//Initialize Timer0
void InitTimer0(void)
{
    //Enable Timer0 overflow Interrupt
    TIMSK|=(1<<TOIE0);
    //Set Initial Timer value
    TCNT1=5;
}
void StartTimer0(void)
{
    //Set prescaller 64 and start timer
    TCCR0B|=(1<<CS01)|(1<<CS00);
    //Enable global interrupts
    sei();
}
//Timer0 Overflow ISR
ISR(TIMER0_OVF_vect)
{
    //Reset Initial Timer value
    TCNT1=5;
    //toggle PD6 pin
    PINB=(1<<PB1);
}

int main(void)
{
    InitPort();
    InitTimer0();
    StartTimer0();
    while(1)
    {
        //doing nothing
    }
}

and I know those commands for setting fast PWM and CTC:
TCCR1D |= (0<<WGM10)|(0<<WGM11);
TCCR1A |= (1<<PWM1A)|(1<<COM1A0)|(0<<COM1A1);

PWM is only supported for timer1 on the ATTiny461. Not in timer0.
Look at TCCR1A; specifically the COM1xn bits.

ok,thank you,good so i use timer1...but where can i include using PWM,TCCR1A und com1A,B  bits in this code...since the code above worked for me but i didnt understand the whole sequnce..since the company asked me for results.

You can put it at the beginning of main. Or copy/replace the functions InitTimer0 and startTimer0 and change 0 to 1. Change the contents to apply to timer 1, and call those functions in main, just like with timer0


text:
UART error can not compile on Arduino Yun (ATmega32u4)
This code is used for communication between the Glediator interface and a NeoPixel Matrix, but I receive an error saying 'UCSR0A' is not defined within the scope.
UCSR0A |= (1<<U2X0);
UCSR0B |= (1<<RXEN0)  | (1<<TXEN0) | (1<<RXCIE0);
UCSR0C |= (1<<UCSZ01) | (1<<UCSZ00)             ;
UBRR0H = 0;
UBRR0L = 1; //Baud Rate 1 MBit (at F_CPU = 16MHz)

Any feedback is appreciated.

Those register names are for a different chip (maybe the ATMega328P of the Uno).
Instead you need to use the right register names.  Start by reading the datasheet for the ATMega32U4.  You might find that the register names are UCSR1A etc, or UCSRA or something like that instead of UCSR0A.

You should be able to use Serial1 to access the USART. But...

Note that on the Yún, the Serial class refers to USB (CDC)
  communication; for TTL serial on pins 0 and 1, use the Serial1 class.
  The hardware serials of the ATmega32U4 and the AR9331 on the Yún are
  connected together and are used to communicate between the two
  processors. As is common in Linux systems, on the serial port of the
  AR9331 is exposed the console for access to the system, this means
  that you can access to the programs and tools offered by Linux from
  your sketch[1].

Please see below references for further details:

https://www.arduino.cc/en/Main/ArduinoBoardYun
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/variants/yun/pins_arduino.h#L40
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/variants/leonardo/pins_arduino.h#L363

Thanks Mikael, I think you just helped me find the problem with the serial communication. I am trying to communicate with an interface called Glediator which is a program that controls LED's of matrices. I have an 16x16 matrix connected to the Yun and It works when upload a sketch to it from ADI itself, but for Glediator i have to upload a Communication Interface script but I think something is edited wrong. As soon as I Open Serial in Glediator, the program freezes. Would you have the time to look at my code, I posted it on this page underneath your comment. Thank you in advance!

So what I did was changing the codes by replacing the '0' from the other chipset to the '1' on the Atmega32u4
UCSR1A |= (1<<U2X1);
UCSR1B |= (1<<RXEN1)  | (1<<TXEN1) | (1<<RXCIE1);
UCSR1C |= (1<<UCSZ11) | (1<<UCSZ10)             ;
UBRR1H = 0;
UBRR1L = 1; //Baud Rate 1 MBit (at F_CPU = 16MHz)

ISR(USART_RX_vect)
{
  unsigned char b;
  b=UDR1;
...

I think that this is the problem that causes freeze when I Open Serial.
Any advice? Thanks In advance


text:
Why doesn't interrupt TIMER0_COMPA work with loops?
I need have two stepping motors working at the same time each with a different number of steps. But loops (for, while) don't work with this task using type of interrupt above. What is wrong?

My code:
class Driver {
    int pinStep;
    long times;
    int state;
    unsigned long previousTime;

  public:
    Driver(int pin, long interval) {
      pinStep = pin;
      pinMode(pinStep, OUTPUT);
      times = interval;
      state = LOW;
      previousTime = 0;
    }

    void update(unsigned long currentTime) {
      int iteration;
      while ((iteration < 5) & (currentTime - previousTime >= times)) {
        previousTime = currentTime;
        if (state == LOW) {
          state = HIGH;
        } else {
          state = LOW;
        }
        digitalWrite(pinStep, state);
        iteration++;
      }
    }
};

Driver drv1(5, 2);
Driver drv2(7, 50);

// set timer behavior
void setup() {
  OCR0A = 0x80; // 128
  TIMSK0 |= _BV(OCIE0A);
}

// interrupt handler
SIGNAL(TIMER0_COMPA_vect) {
  unsigned long currentTime = millis();
  drv1.update(currentTime);
  drv2.update(currentTime);
}

void loop() {
}

Try moving both instantiations of Driver into volatile memory - voltatile Driver drv1(5, 2); - and again for drv2.

void update(unsigned long currentTime) {
      int iteration;
      while ((iteration < 5)

Your code take a variable with an undefined value (iteration) and loops while it is less than 5. How is this useful? Perhaps set iteration to zero:
      int iteration = 0;

But cycles (for, while) don't work with this task using type of interrupt above.

Please define what "don't work" means here. It does too much? Too little? Nothing at all?

And Serial.print prints out iteration value as "111111"

The only way that could happen is if currentTime - previousTime >= times is false. Which it would be.
  while ((iteration < 5) & (currentTime - previousTime >= times)) {

Do you mean: currentTime - previousTime < times?

Thanks for answer.
I initialized iteration variable as zero but loop doesn't work correctly: stepping motor is moving all the time, not on certain steps (5). And Serial.print prints out iteration value as "111111" See screenshot: https://i.sstatic.net/1uyPO.jpg

I don't see any Serial.print in your code.


text:
Problem on Arduino Interrupt and RTC
I am doing an experiment. In this experiment I want to start the RTC by presing the external Push Button which is connected with Aquino's pin 2 and take varites of action according to Time. For interrupt I have made a ISR and in this interrupt I wrote my main logic. But this things is not working.
The schematics is
and The code is
`include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>

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

RTC_DS1307 rtc;
int k = 0;
int led =13;
int pin =2;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
 lcd.begin(16, 2);
 rtc.begin();
 Serial.begin(11520);
 pinMode(led,OUTPUT);
 pinMode(pin,INPUT);
 attachInterrupt(0, Time  , LOW);
  // Print a message to the LCD.
  if (! rtc.begin()) {
    lcd.print("hello, world!");
    while (1);
}

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
  }
}
void loop()
{}

void Time()
   {
    {DateTime now = rtc.now();
    lcd.setCursor(0, 0);
    lcd.print(now.year(), DEC);
    lcd.print("/");
    lcd.print(now.month(), DEC);
    lcd.print("/");
    lcd.print(now.day(), DEC);
    lcd.print(" ");
    lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
    int c = now.second();
    lcd.setCursor(0, 1);
    lcd.print(c);
    if(c==58)
      {
        k=k+1;
        lcd.setCursor(5, 1);
        lcd.print(k);
        if(k==4)
          {
            digitalWrite(led,HIGH);
            k=0;
          }
     }

    }}`

please help me.

Well, for example Arduino's delay needs interrupts to be working and as you may not know it's disabled inside of ISR handler.
Never ever use anything like while (1), delay(1000) and so on inside of ISR! And also do not reenable interrupts either! Set a simple volatile flag and use it inside of loop function instead.
Basically something like this:

constexpr int8_t button = 2;
volatile bool      flag = false;

void setFlag() {
  flag = true;
}

void setup() {
  pinMode(button, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(button), &setFlag, FALLING);
}

void loop() {
  if (flag) {
    // it's running, you can do something here

    // and you can reset the flag here either
  }
  //delay(100); // if needed
}

sorry I am not getting your point. I have used while(1) and delay() for special reason forget about that. I have checked this code without while(1) delay() inside ISR still its not working.

@Prayuktibid: You wrote “I have checked this code without [...] still its not working.” There is no point in talking about code we cannot see. Please update the question with the relevant code and tell us exactly how it is not working.

@EdgarBonet  I have updated the code plaese check it

@KIIV Sir, Why you using address of setFlag() Function Instead of setFlag() function in this program please explain me.

@Prayuktibid Well, without ampersand it's converted to the function pointer implicitly, so it's not required. But it's more obvious for reviewers or coworkers. For the class methods (member functions) it's required.


text:
How to store 1 bit Boolean data into EEPROM and retrieve this 1 bit data?
I am building a project where I have to store the digital state which is Boolean (either HIGH or LOW) of each I/O port such that after power off the state of I/O ports store in EEPROM and I can retrieve this I/O port's state after power on.
This is my code..
    #include <IRremote.h>
    #include <EEPROM.h>
    int EEPROMaddress = 0;
    int EEPROMaddress1 = 1;
    byte EEPROMbyte = EEPROM.read(EEPROMaddress);
    byte EEPROMbyte1 = EEPROM.read(EEPROMaddress1);
    int RECV_PIN = 11;
    int led = 10;//1FE50AF
    int led1 = 9;//1FED827
    boolean previousState = bitRead(EEPROM.read(EEPROMaddress), led);
    boolean previousState1 = bitRead(EEPROM.read(EEPROMaddress1), led1);
    boolean state;
    boolean state1;
    IRrecv irrecv(RECV_PIN);
    decode_results results;
    void setup()
    {
      Serial.begin(9600);
      pinMode(10,OUTPUT);
      pinMode(9,OUTPUT);
      irrecv.enableIRIn();
    }
    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;
           bitWrite(EEPROMbyte,led,state);
           EEPROM.update(EEPROMaddress,EEPROMbyte);
           delay(50);}
           else
           {state=LOW;
           digitalWrite(led,state);
           previousState=state;
           bitWrite(EEPROMbyte,led, state);
           EEPROM.update(EEPROMaddress,EEPROMbyte);
           delay(50);
           }
           break;
            case 0x1FED827:
           if (previousState1 == LOW)
           {state1=HIGH;
           digitalWrite(led1,state1);
           previousState1=state1;
           bitWrite(EEPROMbyte1,led1, state1);
           delay(50);}
           else
           {state1=LOW;
           digitalWrite(led1,state1);
           previousState1=state1;
           bitWrite(EEPROMbyte1,led1,state1);
           delay(50);}
           break;
}
        irrecv.resume();
      }
}

Out of curiosity, how are you going to do this after power off? And if you do it before power off, the EEPROM has a limited number of writes it can do.

Are these input or output ports you want to store the state of?

In my code, the state of  each arduino's pin will change randomly within a loop and present(changed) state of each pins will store in EEPROM parallely. So that if power failure will occurs any instance of time during running this code then after power on I can get the each pin's state from EEPROM which were before shutdown.

The chip on the Uno is designed for 100,000 writes to EEPROM. That's a lot, but if you are doing it every time around a loop, you may exceed that number in a couple of minutes.

Since this is Arduino SE I'm going to do this with the Arduino functions, there are other ways of course.
Write a bit to EEPROM:
byte EEPROMbyte = EEPROM.read(EEPROMaddress);
bitWrite(EEPROMbyte, pinBit, pinState);
EEPROM.update(EEPROMaddress, EEPROMbyte);

Read a bit from EEPROM:
boolean pinState = bitRead(EEPROM.read(EEPROMaddress), pinBit);

This is for updating/reading a single bit at a time as asked. If you need to read/write multiple bits at the same time(as I'd assume you are doing after power on) then it's more efficient(and less wear on the EEPROM in the case of the write) to do all the bits at once instead of one EEPROM read/write per bit.
I assume by "I/O ports" you mean Arduino pins. If you're working directly with the PORT registers(e.g. PORTB) then you can just write or read the whole register to the EEPROM, no need to deal with the individual bits.

Thank you Sir for your great contribution. In my code, the state of  each arduino's pin will change randomly within a loop and present(changed) state of each pins will store in EEPROM parallely. So that if power failure will occurs any instance of time during running this code then after power on I can get the each pin's state from EEPROM which were before shutdown. have some doubt  which EEPROM library need to run these code which you given in your comment?

It's the EEPROM library included with the Arduino AVR Boards core but there should be a similar API for any hardware core for an MCU with EEPROM(or pseudo-EEPROM in the case of ESP8266). Which board are you using?

I am using arduino uno  board.. .after successful implication in this board I will implement it on AVR atmega 32 MCU later

You just need to add #include <EEPROM.h> to the top of the sketch and the code I wrote will work fine. The core you use for ATmega32 will probably either have the same library or reference the Arduino AVR Boards core so it will work either way. If it doesn't you can use avr-libc's avr/eeprom.h library, you just need to change EEPROM.read/EEPROM.update to eeprom_read_byte/eeprom_update_byte. Keep in mind that the ATmega328P/ATmega32's EEPROM is only rated for 100000 writes/cell so you need to do some calculations of the expected lifetime and maybe do some wear leveling.

Sir I have written my sketch as per your instruction but the memory part is not functioning.. If I make any particular ardunio's pin HIGH before power off after power on it goes to LOW but it should be HIGH.. I have Added my Ardunio's Sketch in my Post Please check it. Thank you

Each EEPROM cell is one byte. There are 8 bits per byte. You're trying to read and write from bits 10 (led) and 9 (led1). The bits are zero indexed so you need to define a bit for each pin that's between 0 and 7. If you're not running short of EEPROM memory you might consider just using a whole byte for each pin's state.

You also forgot to write the state of led1 to EEPROM in your case 0x1FED827.

Also, I don't know exactly what your intent is in your code but it seems like you would want to set the pins to the states read from EEPROM in setup().

I want to control electrical appliance its state(On/OFF) also its power by using PWM technique through IR remote.. but right now I just written the code to control appliance's State(ON/OFF) only for real time

Note that writing EEPROM is slow - on the order of milliseconds per write - which may limit the performance of your sketch.
A better technique is to provide a limited backup power supply to the MCU; enough to complete a set of EEPROM writes + a safety margin. A capacitor could possibly provide enough run time if doesn't have to power much else. Then, detect and interrupt on a failure of the main supply, immediately write your backup data to EEPROM, and enter an infinite loop to wait for the backup supply to fail. When the system resets, examine the EEPROM to be sure there is valid backup data there, restore what needs to be restored, and resume your task.
Update:
A search for "arduino backup power" finds a number of articles related to switching an Arduino from mains power to battery power when the mains fails. You would only need a very small battery if you're willing to only save necessary information then shut down until the power returns. A capacitor might keep your MCU running long enough to do that. Designing the circuit depends on too much we don't know about your system, though.
In fact, simply switching a backup battery as some of these articles describe, or better, running on a battery which is kept on a mains charger, may make a much simpler system that can surviVe reasonably long power outages without shutting down. Again, we don't know how often or how long your power goes out, and how reliable your system is required to be.

Thank you sir for your suggestion. But I understand your suggestion but its not clear to me how it will done. Actually I am beginner in this field.. so my request to you please explain me details with an example whatever you wanted to say.. then it will be very helpful to me.

You can store any bits or bytes into eeprom in byte units. The eeprom itself doesn't care whether the data ISS bits or bytes or multi bytes.
Your code only needs to make sure that consistency is maintained in storying and retrieving of eeprom data.


text:
Can I drive this relay shield with an Arduino Due?
Sorry I'm new to electronics while I've some experience in coding. This let me very curious about the Arduino Due board: it is super powerful and I can run some C++ code that I can not with the normal Arduino Uno. But I lack in electronic theory, sorry if the question is a little bit dumb.
Can I drive this shield with an Arduino Due? The Due board is at 3.3V while the relays in the shield are at 5V.
What do I need to make them run smoothly?
Actually I'd like to run 5 of those shield with only one Arduino Due board. Do I have some problem with power supply?

You'd have to remove the yellow jumper. Connect 3.3v to the VCC and 5v to the JDVCC. But please double check that JDVCC is connected to one side of all the relays.
This way the opto-couplers are activated by 3.3v signals, which in turn activate the transistor (5v) used to engage the relay.

just in case that JDVCC is NOT connected to one side of all the relays? But anyway, how did you understand which kind of optocouple are in the shield?

If not, switch the 3.3v and 5v. Most relay boards use the same circuit. Also the optocouplers are kind of easy to spot.

Sorry but why can it work? Those relay are 5V relay.. why I don't need any extra transistor? and then, are you sure I can drive 20 relay simultaneously from one Arduino Due? Only  130mA for all the digital i/o

No need for any additional hardware. If you look closely at the board, you can see there is already a transistor in place (Q4, Q5 and Q6 in the image). This transistors and relays are powered with 5v. The 3.3v digital I/O is only used for the optocoupler and the indicator led, so only a few mA.


text:
OSC parsing code. Can it be optimised?
I'm using this OSC library and TouchOSC to controls some motors.
Right now I'm receiving those two kind of messages:
/u/1       // move motor 1 of default steps
/u/2       // move motor 2 of default steps

/u/1/5     // move motor 1 of 5 steps
/u/3/25    // move motor 1 of 25 steps

and so on.
Right now I have this piece of code:
void loop() {
  OSCMsgReceive();
}

void OSCMsgReceive() {

  OSCMessage msgIN;
  int size;
  if ((size = Udp.parsePacket()) > 0) {
    //Serial.println("incoming message.. ");
    while (size--) {
      byte n = Udp.read();
      msgIN.fill(n);
      Serial.print((char)n);
    }
    Serial.println();
    if (!msgIN.hasError()) {
      msgIN.route("/u", up);
    }
  }
}

void upValueExtraction(char *ca, int &num_motor, int &num_step) {
    String s = String(ca);
    String num_motor_s = "";
    String num_step_s = "-1";
    int n = 0;
    for(int i=0; i<s.length(); i++) {
      char c = s[i];
      if(c=='\\') {
        n++;
      }
      if(n==0) num_motor_s += c;
      if(n==1) num_step_s += c;
    }
    Serial.print("num motor: "); Serial.println(num_motor_s.toInt());
    Serial.print("num step: "); Serial.println(num_step_s.toInt());

    num_motor = num_motor_s.toInt();
    num_step = num_step_s.toInt();
}

void up(OSCMessage &msg, int addrOffset) {
  static boolean flag = false;
  if (!flag) {
    Serial.print("route: up "); Serial.println(addrOffset);

    char ca[200];
    msg.getAddress(ca, addrOffset+1);

    int num_motor, num_step;
    upValueExtraction(ca, num_motor, num_step);

    if(num_step==-1) {
      num_step = defaul_steps;
    }

    Serial.print("Have to move motor n ");
    Serial.print(num_motor);
    Serial.print(" of step ");
    Serial.println(num_step);
  }
  flag = !flag;
}

Even if it is working and even if I'm using an Arduino DUE (much more memory then the UNO) I think it can be optimised.
Does it contains some leeks? How can I better use the OSC matching part of the library? Any kind of "embedded c++" guidelines? Can I do everything inline without a ca char array and s String variables? Is better to use Arduino Lib String class or plain old C str* functions? Any kind of comment?
Thanks in advance.

OSC is such a simple format that I ended up ditching libraries entirely, and just parsing the UDP packets directly with a state machine.  Just learn the wire format of the bytes and parse the state machine explicitly.
It's just a trivial function calling format.  The message starts with a 32-bit padded zero terminated string (important!) for the method name.  I am not sure if the type tag is mandatory but it was always being sent (ie: ",iff"), then the binary values corresponding to what type tag says - like bigendian int32,float32,float32.
This was related to OSC generated by ChucK, SuperCollider, and CSound.
Real optimizations would come just from the design of the protocol itself.  You will need to assume that any UDP packet can be dropped.
You are sending motor changes as diffs from current position, so you need to handle packet drops somehow.  (ie: Do you have a TCP-like mechanism?  Do you change the design to send absolute motor positions so that position reports are idempotent and subject to re-broadcast?  Do you ack message receipt individually, or do you periodically poll the device for its current state?)