text:
Programming arduino via bluetooth module issue
I followed a tutorial on how to setup arduino and bluetooth so it can be programmed without usb cables. I didn't use capacitors or resistors asthere doesn't seem to be a need for them. I have the serial output appearing on arduino serial console via bluetooth (no usb cable connected). Since the is a working connection that means it is working to a point. However when trying to upload I get "avrdude: stk500_getsync(): not in sync: resp=0x4c" error.
I didn't connect pin 32 of hc-05 to arduino reset pin yet, could that be the issue? I don't actually need arduino to be reset since I can just kill the power to it manually at least for now. I also used 9600 as baud rate instead of 115200 as in the tutorial, because my arduino code used 9600 but maybe I misunderstood this and it actually needs to be 115200 regardless or my baud rate in arduino code?
What else could be the cause?
Edit 1:
From the answer by @sachleen I changed the baud rate as per the tutorial and soldered pin 32 of the hc-05 module to rst pin of arduino.
After baud rate change opening arduino serial console no longer outputs anything. Why did this happen? I was getting serial output before when baud rate of hc-05 was 9600.
After soldering the rst pin arduino also seems to reset after serial console is opened. I did not add the capacitor, is it required and if so why? I also excluded resistors since it seems they are only for voltage reduction from 5v to 3V (my arduino is 3.3V version).

have you fixed it?

@emj365 I have but unfortunately it was so long ago I just don't remember. I should have added the answer before I forgot but I forgot to do that too :) Will add the answer if I come across this issue again. I do remember it was a simple issue.

@emj365 Still don't remember for sure. What Arduino model are you using and what baudrate?

Thanks for tried. I used a fake Uno and changed ESP8266(new and very cheap) baud rate to 115200.

@emj365 Well, I used a Bluetooth module so it may be a different issue but then again it may be the exact same issue. Try 57600 baudrate as that's what I have in my old Arduino sketch. Also what is the baudrate for the ESP8266 module?

Sorry I made a mistake, I use Bluetooth too. The module should be HC-05. I've configed the baud rate 115200 to upload the program to Arduino. Also, I tried to use logic level converter. Failed, still have no idea about it. Maybe 115200 is too high for Bluetooth. And I tried reset Arduino when upload, it never work.

I bought a 3.3v Arduino Uno still failed.

Did you try the different baud rates as per my last comment? If still no luck I will try to retrace my steps and do a proper write up on this.

I wrote the tutorial you were following so maybe I can help. When I was building the circuit initially I used some of the other tutorials out there on Arduino Bluetooth programming which don't have a lot of the extra resistors and capacitor.  However, I couldn't get any of those to work reliably.  Using a circuit simulator and some trial and error, I ended up with the circuit shown in the tutorial which worked for me.
While there "doesn't seem to be a need for" some of the extra passives, if your circuit doesn't work without them, perhaps there is a need for them after all? ;-) Now, I have heard from other people that they were able to leave out certain bits so it seems that there is some variability in the hardware. But we're talking four passives to ensure reliable operation, so why leave them out?
Anyway, a couple of points:

Pin 32 on the HC-05 becomes active upon Bluetooth connection.  We configure the pin to be active low so we can use it to auto-reset the Arduino upon serial connection to emulate what happens with the normal USB connection.  You can leave out the connection to pin 32 only if you want to have to manually reset the Arduino to program it.
The 115200 baud rate is the rate for programming the Arduino and is set by the Arduino bootloader.  It is possible to re-flash the bootloader with a different configuration if you needed to for some reason.
So, the programming baud rate is fixed in the bootloader, but the communication baud rate is configurable in software using Serial.begin(). However, the HC-05's baud rate has to be the same as the Arduino's, so you need to stick with the same baud rate for both programming and communication (115200 by default).
There are two resistors involved with the reset, R3 and R2.  I believe R2 is only necessary for 5V Arduinos to act as a voltage divider with R3.  However, R3 should be included for any voltage Arduino. See this Atmel design note - "The reset line has an internal pull-up resistor, but if the environment is noisy it can be insufficient and reset can therefore occur sporadically ... This pull-up resistor makes sure that reset does not go low unintended." R3 should be 4.7k or greater; most designs stick with 10k.
The capacitor C1 is necessary because Pin 32 stays low the entire time Bluetooth is connected.  If you connect RST to Pin 32 directly, the Arduino will just stay reset until the Bluetooth connection drops and nothing will work just as if you held down the reset button and never let go.

With C1 in place, when Pin 32 goes low it will momentarily discharge C1, pulling RST low and resetting the Arduino. C1 will immediately begin charging through R3 back up to VCC which will restore RST to high, bringing the Arduino out of reset.  The values of R3 and C1 affect the timing of the reset and must be chosen appropriately.
Don't forget R1.  I can't remember the reason it is helpful, but it has something to do with the Arduino/Atmel UART.  I found the recommendation for adding it one day on an Atmel discussion board and it has solved a non-working circuit for me many times.

Hope that helps!

Thanks for taking your time to explain though I don't understand why at least some of this info wasn't in the original tutorial. There was barely any text there at all :)  You are also wrong on some points and far too vague on others. First of all 115200 baud rate is one reason why it didn't work for me. Arduino Pro Micro uses 57600 baud rate. I also did not need to use any resistors and I used a 450 nf capacitor and probably almost any value would have worked. R1 and R3 may be useful but I never had issues without them.

There's also a serious limitation that was not mentioned with the tutorial as it will reset when pairing or opening  serial console. There is a way to fix this and I will share it when I get it to work properly.

Have you got the TX from the Bluetooth module linked to the RX pin of the Arduino?
If you have you need to unhook it whilst uploading. A better solution is not to use the TX RX pins of the Arduino and use serial software instead.
Here's a simple tut but it spreads over a few pages:
http://ianlangelectronic.webeden.co.uk/#/arduino-bluetooth/4583456314
A Bluetooth baud rate bigger than 9600 is not recommended. The Arduino struggles to keep up if it's much faster than this.

Whilst you link may answer the question, it would be preferable to include the essential parts of the linked here, and provide the link for citation. Can you please edit your answer? Thanks!

I am using rx/tx, yes. Why would this cause problems exactly? I changed baud rate to 57600 of the bt module and was able to program OTA. It has to be specific baud rate as each arduino has it's own baud rate requirement for programming. Will try your link later.

The tutorial you linked to will only allow serial communication, but not for the Arduino to be programmed, via Bluetooth.  9600 baud is a good recommendation for a safe upper limit when using SoftwareSerial but doesn't apply when using the UART.

Both of those things will cause issues.
It needs to reset when its downloading a new sketch. You can manually reset it at just the right moment, but if you don't get the timing right, you'll get that issue.
The baud rate you set in your code for serial communication becomes irrelevant when you're loading a new sketch as that's set in the bootloader. Keep it at 115200 like the tutorial suggests.

Ok, I changed the baud rate but now I am not getting any output from serial console at all. Why? Will try to solder the pin to the module now.

I connected the arduino reset pin to pin 32 of hc-05 module but still unable to program it. It also seems to reset or seizes executing code for a while when serial console is opened but still no output. I did connect the rst pin directly, I am not sure what to make of the diagram showing capacitor and resistors relating to rst pin. My arduino is the 3.3V version so I dont need a voltage divider.

The baud rate depends on model of arduino you are using. For Pro-Micro; Pro-Mini and Nano that I use I had to change to 57600 baud as that is what the dll (downlineloader) avrdude forces this baud rate:
avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
     Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
     Copyright (c) 2007-2009 Joerg Wunsch

     System wide configuration file is "C:\Program Files (x86)\Arduino\hardware/tools/avr/etc/avrdude.conf"

     Using Port                    : \\.\COM40
     Using Programmer              : arduino
     Overriding Baud Rate          : 57600

For Mega the overriding Baud Rate is 115200.

The easiest way to program your arduino via bluetooth (HC-05) is the following steps
1: change the baud rate of the bluetooth module to 57600 using software seriel, and that is all you need to do with your bluetooth, and when you use the software seriel sketch you do not need a ftdi converter, this is how you do it (  https://www.youtube.com/watch?v=zoJUAjW3vQ0 )
2: next step is to make a very simple and small circuit for the reset pin of your bluetooth module like the one in this youtube link ( the circuit I am talking about is a circuit made of a NPN transistor, a 0,01 capacitor and a 10 k resistor. the circuit is like a signal inverter or something. (https://www.youtube.com/watch?v=xXUKfTNHkKE). you will find the circuit in the middle of the video.
I have done it and it works,
thanks for reading
Arman


text:
Arduino reading serial data non-blocking

I have an Arduino reading serial data and responding to other inputs as well, I'm trying to read incoming serial data without using the while, if at all possible. the incoming serial data will be formatted in a specific manner each time and will be CSV; It will look like such:
19,1400700083, 1-0,1-10,and other values delimited with a new line character "/n".

The first value will tell how many bytes are coming in so the serial receive function wont parse data until it gets all the bytes,second value is a Unix time-stamp, the third value (1-0) is the "get" or set" value; which will tell the Arduino to return a value or to set a value. The fourth (1-10) value will correspond to what variable to get or set. and the other values will be integers as well but are dependent on the other values.
My code is as follows:
void CheckSerialData() { // begin function

  if(Serial.available() >= 2) { // begin one, first line will be how many bytes incoming.
  int NumberOfIncomingBytes = Serial.parseInt();
    if(Serial.available() >= NumberOfIncomingBytes) { //begin two
    int IncomingTime = Serial.parseInt();
    setTime(IncomingTime); //time is always incoming with serial values
    int GetOrSetValue = Serial.parseInt(); //this value should be 1 or 0 for "getting values(1)" or "setting values(0)"
      if(GetOrSetValue == 1) { //BEGIN THREE
        int ValueToGet = Serial.parseInt();
          switch(ValueToGet) {// BEGIN SWITCH
            case 0:
              Serial.print(GetTemp());
              Serial.print("/n");
              break;
            case 1:
              //serialwrite yaw pitch roll
              break;
            case 2:
              Serial.print(GetVoltage());
              Serial.print("/n");
              break;
            case 3:
              //append all RGB final values together and serial print it
              break;
            case 4:
              //print out accel values
              break;
            case 5:
              //print alarm alarmed status
              break;
            case 6:
              //print out last time alarm set off
              break;
            case 7:
              //print out time allowed lights to turn on
              break;
            case 8:
              //print out arduino time
              break;
            case 9:
              //print out system summary, (time,voltage,temp,yaw,pitch,roll,accel
              break;

          }//END SWITCH
         }//END THREE
      else { //BEGIN TWO B //SET VALUES
      int ValueToGet = Serial.parseInt();
          switch(ValueToGet) {// BEGIN SWITCH
            case 0:
              //set global rgb value set LEFT
              break;
            case 1:
              //set global rgb value set RIGHT
              break;
            case 2:
              //set global alarm value
              break;
            case 3:
              //set global angle to start flashing emergency led's
              break;
            case 4:
              //set turn signal RGB value
              break;
            case 5:
              //set time that lights are ok to turn on
              break;
            case 6:
              //set light override value
              break;
            case 7:
              //set pattern enable
              break;

          } //END SWITCH

      }//END TWO B

          }
        }//end two
      }//end one
    }//end function
    //**********************END SERIAL FUNCTION**************************

I would like to know if this looks like it can work, or am I going about this all wrong?
(I don't have access to my Arduino currently to test the code)

Unfortunately your code could end up dropping data quite easily, or parsing it incorrectly.
Let's say your code has successfully read the first couple of bytes into NumberOfIncomingBytes. However, when it reaches begin two, let's imagine the sender hasn't finished sending all the data yet.
Your code will drop through to end two, discarding the NumberOfIncomingBytes value it just read. Next time round, it will start all over again from scratch, and attempt to read NumberOfIncomingBytes again. However, that data isn't there anymore. The next data waiting on serial will actually be the timestamp from the previous message.
From there, it could end up parsing arbitrary data with unpredictable results, getting completely out-of-sync with the sender.
A way to fix it would be to store the NumberOfIncomingBytes value outside the function (e.g. as a global variable), along with a flag indicating if you're still waiting for the rest of the data to arrive. At the start of CheckSerialData(), the code should check that flag. If it's true, then it should skip trying to read NumberOfIncomingBytes. Instead, go straight on to begin two.
An alternative approach would be to avoid using NumberOfIncomingBytes at all. Each call to CheckSerialData() would read whatever serial data is available, and accumulate it in a buffer. As soon as it hits a newline character, it will stop reading, and parse the data it's accumulated. If it runs out of serial data before it hits a newline, it should stop and carry on from there next time it's called.

source: Stack Exchange

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

sort: votes


text:
bootloader uploading into Atmega328

Here is mine circuit. Intially i used arduino UNO directly for programming. Now i am Using atmega 328 IC for programming. I am trying to connect 32 hall sensor via Mux circut. I wanted to How to upload boot loader or HExfile Here. Will avr pocket programmer satisfy above circuit or i need to add addtional circuit here
AVr pocket programmer

The AVR pocket programmer should work fine. Sparkfun has a good guide for doing this.
Here's the pinout of the Atmega328:

You'll want to connect your programmer as follows (note, these are the pins for the bare Atmega328 chip only. The pin numbers on an Arduino board are different.):

Programmer Pin		Atmega328 Pin
5V			Vcc (7)
GND			GND (8)
MOSI			Digital 11 / Physical 17
MISO			Digital 12 / Physical 18
SCK			Digital 13 / Physical 19
Reset			Reset (1)

Note that the physical pins on the chip are numbered differently than the logical pins. In the table above the "Digital" pin numbers are those colored yellow in the figure, while the "Physical" pins correspond to the black-on-white numbers around the edge.
If you already have the ICSP header connected to those pins (it's not completely clear in the schematic if that is the case), you can connect the programmer to those pins instead. This can be easy if you have a 6-pin ICSP cable with your programmer.
Also, if you are already powering your Atmega328 from some other 5V power supply you can omit the 5V-Vcc pin. However, the programmer and the Atmega328 must share a common ground, so be sure the GND pins are connected.
Connect your programmer to the computer using USB, open the Arduino IDE, select the correct serial port of the programmer, and pick "Arduino Uno" in the "Board" menu. You can program the bootloader by selecting "Burn bootloader" in the Tools menu, or you can simply write your program by selecting "Uploading using programmer" in the File menu.

thanks for information.I wanted to know whether above circuit right or wrong

Uploading Hexfile to your arduino can be done using this application:
http://kmtronic.com/upload-hex-files-to-arduino.html

This is how you upload an Arduino Bootloader on an empty ATmega328 / ATmega328P-PU. Using an Arduino. (No need for a separate ISP Programmer).
From Arduino Uno to other Arduino Uno.

Open the ArduinoISP firmware (in Examples) to your Arduino board.
Select the items in the Tools > Board and Serial Port > Arduino Uno.
Upload the ArduinoISP sketch.
Wire your Arduino board to the target as shown in the diagram below. (Note: you'll need to add a 10 uF capacitor between reset and ground.)
Also connect TX from Arduino A to the RX of Arduino B and RX from Arduino A to TX Arduino B.
Select Target Board in Tools > Board > Arduino Duemilanove w/ ATmega328
Select programmer in Tools > Programmer > Arduino as ISP
Use the Burn Bootloader > Arduino as ISP command.
Go to Tools and Select Burn Bootloader. Done.

To upload on a breadboard without External clock.

Download: Breadboard.zip
Put boards.txt in your Arduino directory under Hardware > ATmega328. (For windows usually (C:/Program files/Arduino/Hardware/ATmega/boards.txt))
Close Arduino IDE and reopen it.
Open the ArduinoISP firmware (in Examples) to your Arduino board.
Select the items in the Tools > Board and Serial Port > Arduino Uno.
Upload the ArduinoISP sketch.
Hook pin13 from Arduino to pin19 on Chip
Pin12 from Arduino to pin18 on chip
Pin11 from Arduino to pin17 on chip
Pin10 from Arduino to pin1 on chip
pin0 from Arduino to pin3 on chip
pin1 from Arduino to pin2 on Chip
connect 5V from Arduino to pins 7 and 20 on chip
14, connect GND from Arduino to pins 8 and 22 on chip
Select Target Board in Tools > Board > ATmega328 on breadboard (8 MHz internal clock)
Select programmer in Tools > Programmer > Arduino as ISP.
Select Tools > Burn Bootloader. Done.

It's also possible with an Arduino Leonardo but you'll have to change some settings for that.
Note: You will need to put target board to Arduino Duemilanove w/ ATmega328 for programming the new chip (Uploading a code to it) instead of targeting Arduino Uno.

I need to uploaD IT TO empty IC atmega 328

Yes, and since you have an arduino you could use your arduino as ISP for programming your clean/empty chip to burn a bootloader on it and your sketch. Follow the links

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


text:
What is the smallest microcontroller capable of running Arduino?
I'd like to know which is the most powerful, lightest, and perhaps least expensive micro controller capable of running Arduino.

Each of those criteria has a different answer.

Is there not one that meets all the criteria above in some capacity better than others? If not, could you please provide a standout microcontroller for each of the listed criteria? Thanks.

There are so many that it's impossible to give a good recommendation based on such general criteria. Perhaps you could describe what you need the microcontroller for? Is it for a specific project, or just general tinkering?

I want to build a micro quadcopter drone

You'll need some idea of the I/O requirements, calculation load, and RAM requirements for controlling your drone, before you can select a processor to meet thme. Cook your design a bit more. Is this an R/C drone? Autonomous? Does it need on board navigation? Stability augmentation? Must it find it's own way home? Manage it's fuel/flight duration? Yesses to some of these questions will have strong implications for the processor you'll need.

Well, your questions is quite vague and perhaps overly broad.  I'll answer your main question "what is the smallest," assuming you meant dimensionally, while keeping in mind that you also want the most powerful one in that size. The pricing of different chips like this will be fairly similar so I'll ignore that.
Next, I'm not sure what you meant by saying "capable of running Arduino" which may mean capable of having the Arduino bootloader installed or could mean being capable of running code written with Arduino libraries.  I'll assume the latter since it's the most practical requirement. I'll also assume you want an Atmel chip since it will be the most directly compatible with the Arduino libraries.
So what is the most powerful of the smallest Atmel microcontrollers capable of running Arduino code?
The answer is probably the Attiny 10 which comes in a 2 x 2mm 8-UFDFN Exposed Pad package, or a 2.9 x 1.6mm SOT-23-6 package for about one dollar in small quantities.
Also see this Hackaday article on how to use the Attiny10 with Arduino.
Edit: After more research, I was unable to find an Arduino core for the Tiny10. So while you can program it with an Arduino using assembly or something, writing Arduino code for it won't work.  The smallest Attiny with an Arduino core I could easily find is the Attiny13 in a 3 x 3mm 10-VFDFN package.  The upside is that while not being that much bigger or more expensive, it's a way more capable chip for your project.

There is no Arduino core for the 4/5/9/10; they're just too small for it to be practical.


text:
Arduino to Raspberry Pi wired communication
I am new to Raspberry Pi (just brought mine before writing this post), and I am looking to see what is the most ideal way for two way communication between an Arduino and a Raspberry Pi (USB, SPI or I2C).
The reason I am asking is because I need to build a small, semi-autonomous robot and plan on using both the Arduino and Pi to control it, using the pins of the Arduino for the motor control and sensors and the Pi for video processing and autonomous part. Both will be on the robot itself. I am pretty good with the Arduino but never used a Raspberry Pi before.
So my biggest question is what would be the best form of communication for the two boards taking into account speed and safety (there is a voltage difference between the Pi and the Arduino).

Hands down, I can rule out the I2C. This post sums it all up:

SPI is faster.
I2C is more complex and not as easy to use if your microcontroller doesn't have an I2C   controller.
I2C only requires 2 lines.

Since speed is your first priority, either do USB or SPI. I'd personally go with USB, just for the reason that it's simple. Nearly any programming language can inference with COM ports, but that's not the case with SPI. Also, for SPI, you would have to either use a level shifter, or do a voltage divider for the Arduino to RPi wires (for RPi to Arduino wires, Arduino can still sense 3.3V as HIGH.)
Also, serial can be pretty fast. Technically, the Arduino can go up to 2 Mbps (not very fast compared to a lot of things, but fast enough for what the Arduino can even handle). One thing to note, the writer of the post stated that this is the highest you can practically achieve with the poorly optimized libraries:
Serial.begin(500000);

Firsr of all, When you say "there is a voltage difference", I assume you are referring to the raspberry pi being a 3.3v device vs the arduino's 5v, and not to some kind of ground potential difference. If theres a ground potential difference(which there shouldn't be in a robot), neither i2c or spi or usb will work without extra circuitry.
My short answer would be USB all the way because its easy and built into the arduino and pi. The only issue is that if anything mechanically bumps the usb enough to lose connection, sometimes linux is a little unpredictable with regards to naming serial ports, and when it reconnects it might give the arduino a different serial port name. But this isnt an issue if your cable isnt a cheap worn out one with a flaky connection like the one that bothered me for a hour today.
USB does have about a millisecond of latency because devices are usually polled at 1khz iirc. Using the raspberry pi hardware serial might be a good idea if milliseconds count which I doubt they do.
But on the software side, raspi hardware serial and USB serial are the same. So there should be no problem switching between them if you need to.
I wouldnt bother with i2c or spi. Why fuss around when serial works so well?


text:
Arduino Master-Slave Pins
Can I change the pins on the communication for a Master-Slave arduino Wire transmission? I want to communicate between 2 arduinos, but on one of them A4&A5 are taken

You cannot. Wire uses hardware I2C, and on the Uno only A4 and A5 are connected to the TWI peripheral on the MCU. You will need to either switch to a bit-bang I2C implementation or change the protocol you're using.

To complete Ignacio's answer, there's indeed no other hardware I2C on AVR Arduinos.
The only options you have to use other pins is:

to use bitbang i2c, which is way slower ;
or you can switch to the Arduino Due which features two TWI ports ;
or you can use an SPI to I2C serial bridge such has that one.


text:
controlling LEDs, few pin outputs lots of LEDs
We need to control many leds, about 40 with arduino (UNO) and we need some remain turned on and other off at the same time. Muted or pinned vary constantly.
What should I use to do this, I have several Multiplexers CD4051 but with these I can just light a LED at a time.
I do some calculation and then need to turn LEDs 1,2,5,7 and need to be pinned to the following calculation. In the following calculation I need to turn leds 4, 5, 10, 12 pinned and need to follow. What I need is something like that
With the multiplexer I can turn the LEDs I need and with minimal delay and it seems they are apprehended while, but I want to know if there is another alternative to do so

Do they need to be lit constantly or do they need to appear lit constantly?

Well, I do some calculation and then need to turn leds 1,2,5,7
and need to be pinned to the following calculation.
In the following calculation I need to turn leds 4, 5, 10, 12
pinned and need to follow.
What I need is something like that

Alright, but that wasn't what the question was asking.

Well, I edit my question, it was bad explained

What my question was asking, rather.

Sorry, my english is not good. It would be perfect if they be lit constantly

Let us continue this discussion in chat.

The most common technique for doing this is called "multiplexing". You arrange the 40 LEDs into 8 "columns" and 5 "rows" with common anodes and cathodes, and then you switch the columns or rows on or off individually, activating only the LEDs you want lit for that column or row. If done quickly enough it appears to the human eye that the LEDs are always lit due to persistence of vision. Note that the physical display does not need to be a rectangle; this is simply the logical arrangement used in order to simplify the circuit.

(note that the cathode side of the above image is wrong; the cathode needs to be low when you want the LED to light)
(source)
A naive implementation with 8 columns and 5 rows would use 13 pins to connect them all. However, since you don't need more than one column at a time what you can do is use a 74HC138/238 to use 3 inputs to control which of the 8 columns you want to activate. This drops the number of required pins to 8, which is low enough for anything larger than a ATtinyX5. Use of a 74HC595 for the 8 pins further drops the required MCU pins to 3, which is low enough for even a ATtiny4/5/9/10, but the timing is harder to get right due to the shift register.

Check out NeoPixels. Make sure to check out the datasheet, as a single Arduino Uno might not be able to provide the required current.


text:
help with input in a Simon arduino uno game
I' making a Simon game with the arduino uno.
I know something is wrong with the inputs but i don't know why or how to fix it.
The problem is the program takes an input and says it is correct no matter what it is or the length
#define NOTES

int tones[] = {NOTE_E5, NOTE_E6, NOTE_CS6, NOTE_A6};
String sequence;

void setup() {
    pinMode(13, OUTPUT); //green
    pinMode(12, OUTPUT); //yellow
    pinMode(11, OUTPUT); //blue
    pinMode(10, OUTPUT); //red
    pinMode(7, INPUT); //green
    pinMode(6, INPUT); //yellow
    pinMode(5, INPUT); //blue
    pinMode(4, INPUT); //red
    Serial.begin(9600);
}

void loop() {
    while(true) {
        delay(1000);
        randomSeed(random(random(1000000000)));
        sequence = String(random(4));
        boolean run = true;
        while(run) {
            for(int i = 0; i < sequence.length(); i++) {
                simonOut(sequence.charAt(i) - '0');
                delay(500);
                simonClear();
                delay(100);
            }
            for(int i = 0; i < sequence.length(); i++) {
                int input = simonIn();
                while(input < 0 || input > 3) {
                    delay(50);
                    input = simonIn();
                }
                if(sequence.charAt(i) - '0' == input) {
                    flash(0);
                    run = false;
                    goto reset;
                }
                else if(i = sequence.length() - 1)
                    flash(3);
            }
            sequence += random(4);
        }
        reset:;
    }
}

void boolOut(long pin, boolean val) {
    digitalWrite(pin,val ? HIGH : LOW);
}

void simonOut(long num) {
    boolOut(num + 10, true);
    tone(2, tones[num]);
}

 void flash(int led) {
     delay(300);
     for(int i = 0; i < 5; i++) {
         simonOut(led);
         delay(100);
         simonClear();
         delay(100);
     }
 }

 void simonClear() {
     for(int i = 0; i < 4; i++){
         boolOut(i + 10, false);
     }
     noTone(2);
 }

 int simonIn() {
     int ret = -1;
     for(int i = 0; i < 4; i++) {
         if(simonIn(i)){
             ret = i;
         }
     }
     if(ret != -1) {
         simonOut(ret);
         delay(500);
         simonClear();
         delay(100);
     }
 }

 boolean simonIn(long num) {
     return digitalRead(num + 4) == HIGH;
 }

Schematic where?

i already thoroughly tested the schematic it is good. pins 10 - 13 are light outputs; pins 4-7 are push button inputs.

So then your inputs and outputs are working perfectly?

yes, a test program was created so that when button pressed corresponding lights were turned on and outputted corresponding sound, and it worked as intended.

Please provide us of a schematic. With a schematic we've got a reference how your hardware setup is and how the programming should be. We don't know anything. Have you included other libraries into your sketch? That's important to know when we want to try to debug your sketch. When I get a full documentation of your script and a schematic I can try to help you, but I can't now.

The problem in your code is there:
int simonIn() {
    int ret = -1;
    for(int i = 0; i < 4; i++) {
        if(simonIn(i)){
            ret = i;
        }
    }
    if(ret != -1) {
        simonOut(ret);
        delay(500);
        simonClear();
        delay(100);
    }
}

This method never returns any value, so that means the caller will just tke whatever is in the stack at that time:
            int input = simonIn();
            while(input < 0 || input > 3) {
                delay(50);
                input = simonIn();
            }

input could be anything there.
So the fix should be easy:
int simonIn() {
    int ret = -1;
    for(int i = 0; i < 4; i++) {
        if(simonIn(i)){
            ret = i;
        }
    }
    if(ret != -1) {
        simonOut(ret);
        delay(500);
        simonClear();
        delay(100);
    }
    return ret;
}

It's surprising you did not get a warning from the compiler on that one, which IDE do you use?
Finally, regarding your code, I would also advise you the following improvements:

break down the loop() code further into functions that do ONE thing, e.g. showSequence(sequence), checkInput(seuquence), readSimonInput() (this last function would only return a value between 0 and 3 included. That would make your code much clearer.
use the right types for your variables: I see you abuse usage of long where int or byte, or you mix different types for the same data, thus forcing the compiler to cast data on some function calls.
avoid hardcoding constants in your code, e.g. you could define the number of buttons, the first pin of buttons, the first pin of LEDs, the various delays.

Is it possible that your problem might be just a typo?

#define NOTES
int tones[] = {NOTE_E5, NOTE_E6, NOTE_CS6, NOTE_A6};

In your array you talk about NOTE and you defined NOTES (See the S?)

that was shorthand because i didn't want to copy and past all 100+ lines of note definitions from my code


text:
Timestamp in Arduino
int sensorArray[32] ;
int selectPinZero = 8;
int selectPinOne = 9;
int selectPinTwo = 10;
int selectpinthree=11;
int Enablepin=7;

int inputPinOne = 0;
int inputPinTwo = 1;

int sensor1;
int sensor2;
int voltage1;
int voltage2;
int Current_Sensor1[16];
int Current_Sensor2[16];
int row;
int column;

int array[17][5]={
                    {0,0,0,0,0},
                    {0,0,0,0,1},
                    {0,0,0,1,0},
                    {0,0,0,1,1},
                    {0,0,1,0,0},
                    {0,0,1,0,1},
                    {0,0,1,1,0},
                    {0,0,1,1,1},
                    {0,1,0,0,0},
                    {0,1,0,0,1 },
                    {0,1,0,1,0},
                    {0,1,0,1,1},
                    {0,1,1,0,0 },
                    {0,1,1,0,1},
                    {0,1,1,1,0 },
                    {0,1,1,1,1},
                    {1,0,0,0,0}
                 };

unsigned long StopTime=0;
int Counter=0;

void setup(){

  Serial.begin(9600);
  pinMode(selectPinZero, OUTPUT);
  pinMode(selectPinOne, OUTPUT);
  pinMode(selectPinTwo, OUTPUT);
  pinMode(selectpinthree,OUTPUT);

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

void loop()
{

  for(row=0;row<17;row++)
  {

    digitalWrite(Enablepin,array[row][0]);
    digitalWrite(selectPinZero,array[row][1]);
    digitalWrite(selectPinOne,array[row][2]);
    digitalWrite(selectPinTwo,array[row][3]);
    digitalWrite(selectpinthree,array[row][4]);
    sensor1=analogRead(inputPinOne);
    sensor2=analogRead(inputPinTwo);
    voltage1=sensor1 * ARDUINO_ANALOG_SCALING;
    voltage2=sensor2* ARDUINO_ANALOG_SCALING;
    Current_Sensor1[row]=(10*voltage1)-25;
    Current_Sensor2[row]=(10*voltage2)-25;
    Serial.print("Currentsensor1:");
    Serial.println( Current_Sensor1[row]);
    Serial.print("Currentsensor2:");
    Serial.println( Current_Sensor2[row]);
     Counter=Counter+1;
    Serial.print("Counter:");
    Serial.println(Counter);
    Serial.println(".......................");
        delay(1000);

     }
}

Here is my Arduino code. I wanted to activate Digital pin for every 1000ms delay.
During each delay the analog value should be stored in an array of index.
I don't know how to keep track of analog value read, or from which port I am reading. I could flicker the LED on the hardware side but it doesn't make any sense. Any method you can suggest here?
Application:
I have 32 hall sensors connected via mux circuit. I wanted to know which sensor is reading value. I want any idea to might suggest to me to keep track here.

You should download timer1 library from http://playground.arduino.cc/Code/Timer1
Init timer1 with a value of 1000000 and it will perform an overflow every second. On every overflow it will perform an action, put your code to activate a pin there. And do the serial readings in your loop.


text:
Sending data from a GUI to an Arduino nano via USB
Can somebody point me in the right direction for information on sending data to an Arduino nano?
My project is to send data that is updated from a GUI (presently written in Python) to an Arduino nano that then makes adjustments to a number of servo motors.
I have the servo code working but am presently using potentiometers to control the servo positions & would like the control done via a GUI.
What libraries would I need to be looking at. Have any of you done anything similar.
Thanks
Nic

Arduino Nano supports FTDI i.e. Virtual Serial Port. So all you have to do is initialize the serial communication using pySerial.
When the data is entered into the GUI, store it in some variables. Send the data in variables to Arduino using Serial Communication. You might have design your own communication protocol on top of Virtual Serial Port in order to identify the data.
You can also use the same library to send the acknowledgement or some data from Arduino to PC, if you want.
Hope this helps you.


text:
How to improve wiring a breadboard?
just saw this tweet and was interested what wires are used there:
https://twitter.com/EngineersGarage/status/448014811280842752/photo/1

The wiring Looks cleaner than the setup I currently have with "normal" wires.
Thanks!

What exactly is the question?

I think the wire itself is perfectly normal. It looks like he's simply soldered right-angled header pins onto the ends. That way, the wires can lie flat on the breadboard instead of being bent over for connections, meaning the whole thing is lower-profile and a little easier to route neatly.
It also has the advantage that they will probably survive far more insertions/removals. With that said, it brings the disadvantage that it exposes the contacts more above the surface of the board, which could increase the risk of accidental connections (short circuits and such like).

thanks - indeed that was the explanation I was looking for. the wires I use quickly get harder to use, and These right-angle Header pins look helpful. any other advice on maybe special out of the shelve wires that help wiring a Project?

Various places sell packs of pre-cut and pre-bent wire specifically for breadboard prototyping. I find it's not really worth the price though. Fairly standard solid core wire is usually sufficient. Just make sure to use suitable lengths, and try to route things in straight lines (rather than sprawling all over the place!).

Using good wires helps to build clean breadboard setups. I also found that it greatly helps to wire vertically only and to use the breadboard for horizontal connections. If you look at my picture, wires are always vertical. This is easy to achieve when you work with buses like I²C. As you can see, I also used horizontal lines from another breadboard as you can use these like Lego bricks, though you need to cut the adhesive tape in the back. For the wires, I used standard Solderless Breadboard Jumper Cable Wire that you can buy almost everywhere online.
You can also check other pictures on my blog: http://ouilogique.com/horloge_cycles_ultradiens/


text:
Setting a Pin to HIGH to simulate a button with a "pull up" resistor
in the below Fritzing diagram, I have a button that has a pull-up resistor, which when pressed, sets the GPIO Pin 23 to HIGH. On the Raspberry Pi, when the button is released, the GPIO goes LOW. The Raspberry Pi detects when the button is released and pressed. This is my desired behavior.
However, in my current configuration, I have PIN 13 connected to the Base of a NPN transistor to try to simulate the same behavior as the button with a pull-up resistor. When pin 13 is set to high, it sets the GPIO 22 Pin to high. When I set the Arduino Pin 13 to low, The GPIO Pin goes low but the Raspberry PI does not detect that GPIO 22 pin went low. Is there a way to simulate the same behavior as a button with a pull-up resistor with an OUTPUT pin from the arduino?

So the solution to this was to remove the transistor all together and connect the Arduino pin directly to the Pi. However, I need to change my Arduino sketch. The approach was to set the pin HIGH and go LOW when selected. I had it backwards.

First of all, I don't think you will need full simulation of a button. There are a couple of things this approach won't have:

Bouncing: it'll be (kinda, minus interference) a square wave. With a real button, the metal contacts "bounce," thus creating a weird waveform. Depending on interference, you'll still need debouncing code, although I would be surprised if it was necessary. I'd inlcude it in case I modified it to add a real button and/or there's some weird interference.
The time it's "pushed" may be very short, depending on your code. Keep this in mind when designing this.

Basically, you're hooking up the Arduino and the RPi together, with a voltage divider or a level shifter between the two.
Voltage divider:

Sparkfun
That is a voltage regulator (drawn four different ways; it's the same circuit). I calculated the values you will need: 1700 ohm for R1, 3300 ohm for R2.
Of course, serial (with USB of the Arduino) communication would be a lot easier...

I don't think your circuit is correct. If red is positive and your switch is momentary closed then it actually pulls GPIO23 low.
Likewise with the NPN transistor, using it in this way gives you an inverter. It should work if internal pull ups are enabled on GPIO22 and you remove the resistor.
IF GPIO23 is 5V tolerant, you can instead connect the resistor to 5V and GPIO23 straight to the collector.
You should also have a 1K resistor between the arduino pin 13 and the base of the transistor to limit the base current.
This all assumes that the VCE of the transistor is lower than the 0.8V low-level cutoff of the GPIO pins (it should be).
In any case, if GPIO23 is 5V tolerant, just connect it straight to the Arduino. If it isn't, follow penguins advice and use a voltage divider.

I think you are correct. I tried all the suggestions and I believe the issue is the program running on the pi that translates the HIGH/LOWS key presses. The program is on GIT HUB and asked for clarification there. Thanks for the help

If you don't mind using SMD components you could use the NX3V1G66 analog switch.
When you send a signal to the IC it will simulate a push button.
Maybe there are leaded versions of this IC but I haven't found them on the website where I order all my components.


text:
Is arduino starter kit disappearing?
It seems they stop the production of arduino starter kit (official), it's hard to find it on pro website.
Is there an other very good starter kit to start ? I mean I would like to try everything on small given project before starting my own project.

I haven't seen any information about the official starter kit being discontinued. Did you read an announcement about it?

it's out of stock in all the pro website I checked for a while now.

I suspect they're just struggling to keep up with demand. There are many alternative starter kits available from various sellers, depending on what you want to do.

AFAIK, it's still available on the arduino store website

Yes I know but you can only pay with paypal ..

AFAIK, Paypal accepts plain credit card payments even without an account, if that is your issue

Make has one: Getting Started with Arduino Kit v3.0

Can somebody confirm me it's a good kit ?

I can. Its got everything you need to get started.

I recommmend you this one: Beginner Learning Kit for Arduino, but they do not add the code here.


text:
Decimals missing when using radio.write(); with Arduino
I'm adapting a sketch I found to send sensor data over a wifi chip (Nrf2401), and although I get the message through, the value I send contains decimals (e.g. 24.59), but the received message will only be 24.
I'm sure there's something wrong on the transmitter part of the code, but I can't see what.
Here's my code:
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>

OneWire oneWire(4);

DallasTemperature sensors(&oneWire);

// ce,csn pins
RF24 radio(8,7);

// init data buffer to hold a sensor type byte and one uint16_t sensor data
unsigned char data[3] = {
  0};
unsigned long count=0;
void setup(void)
{
  sensors.begin();
  Serial.begin(57600);
  Serial.println("**************V1 Send Sensor Data***********");
  radio.begin();
  radio.setPALevel(RF24_PA_LOW);
  radio.setChannel(0x4c);

  // open pipe for writing
  radio.openWritingPipe(0xF0F0F0F0E1LL);

  radio.enableDynamicPayloads();
  radio.setAutoAck(true);
  radio.powerUp();
  Serial.println("...Sending");
}

void loop(void)
{

  sensors.requestTemperatures();
  float currentTemp;
  currentTemp = sensors.getTempCByIndex(0);

  //assign 'T' to represent a Temperature reading
  data[0] = 'T';

  data[1] = currentTemp;

  count++;

  sprintf(data, "T %5.2f\n", currentTemp);  // build command in data[]
  radio.txMode(strlen(data));               // set # bytes to xmit
  radio.write(data);                        // send bytes

  // print and increment the counter
  Serial.print("Temperature sent:  ");
  Serial.println(currentTemp);
  // pause a second
  delay(500);
}

In this example, when I print currentTemp, it will display the decimals, but if I print data[1], it won't.
What am I missing?
EDIT:
I've modified the code to include the answer from JRobert (updated code above), but it comes back the following error:
nrf24SendSensorDataV1_ino.cpp: In function 'void loop()':
nrf24SendSensorDataV1_ino:56: error: invalid conversion from 'unsigned char*' to 'char*'
nrf24SendSensorDataV1_ino:56: error: initializing argument 1 of 'int sprintf(char*, const char*, ...)'
nrf24SendSensorDataV1_ino:57: error: 'class RF24' has no member named 'txMode'
nrf24SendSensorDataV1_ino:57: error: invalid conversion from 'unsigned char*' to 'const char*'
nrf24SendSensorDataV1_ino:57: error: initializing argument 1 of 'size_t strlen(const char*)'
nrf24SendSensorDataV1_ino:58: error: no matching function for call to 'RF24::write(unsigned char [3])'
C:\Users\Zuh\Downloads\arduino-1.0.1\libraries\RF24L01/RF24.h:281: note: candidates are: bool RF24::write(const void*, uint8_t)

Any thoughts?
EDIT 2
I've made a dirty fix that will solve the issue.
In the transmitter code I've added:
uint16_t sensorValue = currentTemp*100;
//do the bit shift to put uint16 into uint8 array
data[1] = sensorValue >> 8;
data[2] = sensorValue;
// print and increment the counter
radio.write(data, sizeof(uint16_t)+1);

This will send the (temperature value)*100
On the receiver end, I just convert the uint16_t to a float element and divide it by 100.
uint16_t sensorValue = data[2] | data[1] << 8;
float temp = (float) sensorValue/100;
Serial.print("T: ");
Serial.println(temp);

Dirty, but effective!
Many thanks guys for the help, it really pointed me and my lousy programming skills to the right direction.

You put the currentTemp float value in the data unsigned char vector. How do you expect the 'data' vector to hold a float number?

From the Arduino playground documentation for the Nrf2401 library, the .write method accepts either: a byte to transmit, a pointer to your unsigned char buffer; or a void argument meaning use the library's internal buffer. You must have called the .txmode() method first.
Since you're trying to use your own buffer, you'll need to make it long enough to contain the message you want to transmit (plus one byte for the terminating NUL). You'll need a character representation of the value you want to send, not the binary number itself. At a quick read of the library doc I didn't see the message format the library wants, but assuming it's something like:
  T<space>12.34<newline>, you'll need something like this (untested, it may need tweaking)
sprintf(data, "T %5.2f\n", currentTemp);  // build command in data[]
radio.txMode(strlen(data));               // set # bytes to xmit
radio.write(data);                        // send bytes

Ill test it tonite! Looks really good, thanks JRobert!!

I've tested it and I get the following error:
nrf24SendSensorDataV1_ino:54: error: stray '\' in program nrf24SendSensorDataV1_ino.cpp: In function 'void loop()': nrf24SendSensorDataV1_ino:54: error: 'f5' was not declared in this scope nrf24SendSensorDataV1_ino:55: error: 'class RF24' has no member named 'txMode' nrf24SendSensorDataV1_ino:55: error: invalid conversion from 'unsigned char*' to 'const char*'

nrf24SendSensorDataV1_ino:55: error: initializing argument 1 of 'size_t strlen(const char*)' nrf24SendSensorDataV1_ino:56: error: no matching function for call to 'RF24::write(unsigned char [3])' C:\Users\Zuh\Downloads\arduino-1.0.1\libraries\RF24L01/RF24.h:281: note: candidates are: bool RF24::write(const void*, uint8_t)

I fixed a couple typos in the sprintf() format string that should clean up some of the errors; you'll have to make sure your data types match what the library's requirements, especially with regard to const qualifiers. Sorry, I don't have the part to be able to debug this.

Updated question with your code. I'm using the RF24 library, maybe this interferes with it? Because the error mentions that 'class RF24' has no member named 'txMode'

data[] is an array of three chars.  You assign the letter "T" to data[0] (the first char of the array), then data[1] = currentTemp attempts to assign a float to the second char in the data array - floats won't fit in chars.

Hi Peter. I see! Is there any other way to send currentTemp using radio.write then? Thanks!!

I'm not familiar with the radio.* functions you are using.  In C, I'd use printf("%5.2f\n", currentTemp);  The %5.2f" tells the print function that the variable is a float, and it should be formatted with two digits after the decimal.

Since I can't comment yet I will place this as answer.
But have you tried to use radio.print(data[1], DEC); ?
DEC stands for Decimal for if you want to force something to print it in Decimals. When you want something to be printed in Hexadecimals you can use HEX for example. Hope this will help you.

This post is simply not true. Decimal and decimals are two entirely different things. He's missing the . decimal when sending the data. DEC just specifies that the info given is presented in the decimal (base ten) system. This isn't related.

The info given huh? Now I don't get it that I can simply make a calculator using arduino and print everything in DEC and HEX without writing a new calculation. All I do is printing it as DEC and or HEX. I would love to hear a more specific explanation about it cuz this is what I learned on my college.


text:
Arduino IDE has no shortcut in openSUSE
I just installed the Arduino IDE in openSUSE 13.1. I am able to open the application using the run dialogue, so I know it has installed. However, there is no way to open the IDE from any application launcher. I have tried both the Kickoff and Lancelot applciation managers. I have also tried to uninstall and re-install the IDE, both through the 1-click on the Arduino website as well as through the command line.
Does anyone know why I am unable to launch the application from the launcher? Thanks in advanced for any help!

I had the same problem and this seems to work. If you right click on the Kickoff Application launcher and open 'edit applications' with KDE Menu Editor, you can 'add new item' where you want and give it a name (ArduinoIDE) and then just put arduino (small case) in the 'command' box, and shut down KDE Menu Editor, it should appear in the menu where ever you placed it. At least it did for me.


text:
Arduino LCD shows only black boxes
I've hooked up my Arduino on this LCD, and after running the following code, all I see is a row with black boxes and another one empty.
//LiquidCrystal d(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(0, 1, 2, 3, 4, 5);

void setup() {
     lcd.begin(16, 2);
     lcd.print("hello, world!");
}

void loop() {
     lcd.print("hello, world!");
}

Wiring:

(The UTP cable is used just for the data lines :-)
Actual wiring photos: (sorry for the total klutz in the wiring, I had limited solid-core wires so I had to use these scrap ones)

CAT 5 solid core is notorious for making poor connection in a breadboard. Have you tried a continuity check between the output pin of the MCU and the LCD input pin for each? That is, checking it without touching the wire in question.

I think your contrast resistor may be too high. Do you have a 10k pot so you can adjust it? Do you also have a schematic that you're following? Can you post this up

I'l try connecting with non-CAT5e wires and report back

@Samuel I just tried with normal solid-core wires and still nothing, so I believe wire problems are ruled out.

@BigChris I'm afraid i don't actually have breadboard space for a potentiometer ):

The problem was that the R/W pin on the LCD was left floating, after I connected it to GND, I started working :)


text:
Problems controlling servos using proximity sensor
I've just started using Arduino and I need to make a code to simulate the behavior of a lizard, meaning that if you come close to it, it moves away from you.
I'm using a "Arduino duemilanove" that my university lend me, I was told that it was an alternative version of Arduino Uno.
Both of the servos says "Tower Pro, mg996r, digihi-speed"
Looking different codes I made one which I think is correct. Also, I checked for each servo motor (I'm using two) and the proximity sensor running codes for everyone of them alone, if they worked well and they did but with this code, they supposed to move when you are closer than a meter but they don't stop spinning.
If anyone could help me with this, it would be great.
Here is the code:
#define Servo1 9
#define Servo2 11
#define trigPin 10
#define echoPin A0

#include <Servo.h>

Servo servo1;
Servo servo2;

int pos = 0;    // variable to store the servo position

void setup() {
  Serial.begin (9600);
  pinMode(echoPin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(Servo1, OUTPUT);
  pinMode(Servo2, OUTPUT);
  servo1.attach(9);
  servo2.attach(11);

}

void loop(){
  long duracion, distancia; // variables

  /* Hacer el disparo */
  digitalWrite(10, LOW);
  delayMicroseconds(2);
  digitalWrite(10, HIGH);  // Flanco ascendente
  delayMicroseconds(10);        // Duracion del pulso
  digitalWrite(10, LOW);  // Flanco descendente

  /* Recepcion del eco de respuesta */
  duracion = pulseIn(A0, HIGH);

  /* Calculo de la distancia efectiva */
  distancia = (duracion/2) / 29.1;

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

  }
  else{
  }
}

print distance to the serial port monitor and check it gets above 100

Your loops to move both servos last 179 x 2 x 15 ms = 5.4 seconds, which means every time distance is less than 1 meter, your servos will move during 5.4 seconds. Also note that pulseIn will return 0 if the sensor does not detect any obstacle within its range 5the range depends on the sensor you use, but it is typically 3 to 4 meters).

If your servos "keep spinning" then they have been modified from normal positioning mode to instead be continuous rotation.  That means that there's only a specific narrow PWM input width which will cause them to stop.  Typically it is adjustable with a potentiometer through a hole in the case.  Otherwise, change the value of your "stop" condition PWM output width in your code.

I am new to servos as well, but I do have two coding thoughts. The servos I have used in the past have started in the halfway position. That would mean the "pos" variable would start off trying to go from the starting 90 position to the 0 value in 15ms. Not enough time before the next for loop. I could see that causing some weird spinning while the servos try to get to the intended position. So..
int pos = 90; // Start servo position.

And secondly, the "distancia" could just always be less than 100. I would try finding a max distance value to compare to vs a hard coded value.
void loop() {...
long duracion, distancia; // variables
boolean isMoveTrigger = false; // Movement trigger.

/* Calculo de la distancia efectiva */
distancia = (duracion/2) / 29.1;

// Store a maximum value.
if (distancia > maxDistance) {
    maxDistance = distancia;
}

// Wait to get a starting maximum distance value.
if (countDown > 0) {
    countDown--;
} else {
    if (distancia > 0) {
      int distancePercentage = (maxDistance * 100) / distancia; // A 0-100 percentage of the maximum value.
      // Then trigger the movement when less than this percentage.
      isMoveTrigger = distancePercentage < 50;
    }
}
if (isMoveTrigger) {
    for(pos = 0; pos < 180; pos += 1) ...

As an extra tip, from my experience do not power the servos from the same power supply as the sensors. I built a similar project to you and it didn't work as expected. I then powered the servos directly from the battery (6v) and the sensors and arduino from a regulated 5v supply taken from the battery.
The servos can cause power spikes that mess with the sensor readings.


text:
Prototyping method
I'm currently using a normal breadbord 'n' solid-core-wires for prototyping, but it gets messy when I need to connect a large number of pins on the arduino, as when using an LCD display + another sensor. What are my other options for prototyping?

The real strength of an Arduino is shields. Ironically, that's also its biggest weakness.

After seeing pictures of shields and shields on top of each other, I really wanted to stay away from stacking things as possible i can

Use a protoshield like: http://arduino.cc/en/Main/ArduinoProtoShield or make your own out of protoboard

One of the Arduino's greatest strengths are shields, and shields upon shields. (Another is it's ease of programming via USB amongst a whole host of others).
They are perfect for prototyping. There's nothing wrong with breadboarding it as well, but it's pretty much one or the other (excluding making your own circuit board).
I am working on a garage controller and it has three shields on top of the arduino itself.

XBee/wireless coms
a relay shield, and
a prototying shield where I have created custom circuitry (buttons, connectors, optocouplers etc).

Especially with the top shield, I have made several changes to get it to perform as I'd like. If I'd committed to making a custom board, then I would have had to change it (and re-change it). What I've done would be virtually impossible on a breadboard.
The idea is, you use the shields to get your idea up and running, as a proof of concept. Then, you could/can leave it as is, or you could take the next step, break it down to the required components and make a custom PCB for your project. If it wasn't for shields and stacking shields, you would either breadboard it (which as you've indicated can get ugly, cumbersome and problematic), or make a PCB which (depending on the project) might not be a small task. So shield it up, test it out, then build your own based on what you've put together.
That's not to say, you have to make your own PCB in the end, many projects can remain a shield on an arduino. So if you can find a shield to do specifically what you're after, then why wouldn't you use it?


text:
RF missing characters
I've got two arduino nano devices connected via RF 433 MHz. The modules are MX-05V and MX-FS-03V. I'm using VirtualWire for sending and receiving. The speed is set to 1000 bps.
One has got a pir sensor and sends "1:ON" when it detects movement and "1:OFF" when movement stops.
The other is just receiving these messages, but after a while (20 messages) the text is chopped off. I only receive "1". If I restart everything the same thing happens.
They are currently on my table (cca 20cm distance) and powered by my PC via USB.
What can I do? Is it because the modules are from ebay and probably not the best quality?
Receive part:
// recieve

int ledPin = 13;
int rcvPin = 13;

#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message

void setup() {
  Serial.begin(9600);
  Serial.println("Device is ready");

  // Initialize the IO and ISR
  vw_set_rx_pin(rcvPin); // set pin for rx
  vw_setup(1000); // Bits per sec
  vw_rx_start(); // Start the receiver

  digitalWrite(ledPin,HIGH);
}

void loop() {
  // non-blocking receive
  if (vw_get_message(message, &messageLength)) {
    Serial.print("Received: ");
    for (int i = 0; i < messageLength; i++)  {
      Serial.write(message[i]);
    }
    Serial.println();
    digitalWrite(ledPin, LOW);
    delay(500);
    digitalWrite(ledPin,HIGH);

  }
}

Transmit part:
/*
SimpleSend
This sketch transmits a short text message using the VirtualWire library
connect the Transmitter data pin to Arduino pin 12
pin 11 to high for power
gnd connected to gnd
*/

// RF
int ledPin = 13;
int trxPin = 12;
int pwrPin = 11;

// PIR
int inpPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

#include <VirtualWire.h>

void setup()
{
  Serial.begin(9600);
  Serial.println("Starting...");

  // PIR
  pinMode(inpPin, INPUT);     // declare sensor as input
  // RF
  pinMode(pwrPin, OUTPUT);   // Set digital pin 11 as OUTPUT pins
  digitalWrite(pwrPin,HIGH);

  // Initialize the IO and ISR
  vw_set_tx_pin(trxPin);
  vw_setup(1000); // Bits per sec

  Serial.println("Device is ready to send.");
}

void loop() {

  val = digitalRead(inpPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion on seonsor 1!");
      send("1:ON");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended on seonsor 1");
      send("1:OFF");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }

}

void send (char *message)
{
  vw_send((uint8_t *)message, strlen(message));
  vw_wait_tx(); // Wait until the whole message is gone
}

In your first sketch, you have
int ledPin = 13;
int rcvPin = 13;

Did you mean both those to be assigned to the hardware LED on the Nano? (Pin 13 is the on-board LED). If so, why? With all the pins available to you.
The other thing I don't understand is your use of:
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message

It will always just be one byte, won't it?
Why not use available()?
http://arduino.cc/en/Serial/available
I see this was posted six months ago - no doubt you have already solved it.


text:
Assigning formatted value to variable
Look at this snippet of code (from TinyGPS++ library):
Serial.print(gps.location.lat(), 6);

It prints the latitude location with 6 decimal points.
I want, instead of printing that value, to have it assigned to a variable.
But i want it assigned just like above, with six decimal points. Is there a way to do this?

Sounds like you want dtostrf() - http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga060c998e77fb5fc0d3168b3ce8771d42 It should do what you want (you have to preallocate the string, though).

To be clear, do you want to store the string with 6 decimal places, or a floating point value rounded to 6 decimal places?

Whatever will do, but i guess a string suits me better

What research have you done on this? @ConnorWolf gave you comment with a valid suggestion, have you looked into it?

Merely expanding on what ConnorWolf has said (which I saw yesterday), look at the link he gave you, it gives you a run down on the command you're after.

The dtostrf() function returns the pointer to the converted string s.
char* dtostrf ( double          __val,
                signed char     __width,
                unsigned char   __prec,
                char *          __s
  )
  The dtostrf() function converts the double value passed in val into an ASCII representationthat will be stored under s. The caller is responsible for providing sufficient storage in s.
Conversion is done in the format "[-]d.ddd". The minimum field width of the output string (including the '.' and the possible sign for negative values) is given in width, and prec determines the number of digits after the decimal sign. width is signed value, negative for left adjustment.

From that, I wrote a short sketch that divides millis() by 1000 and saves this in a float, we then use this float as a source for dtostrf() to do it's work and store the result in a char array.
void setup(){
  Serial.begin(9600);
}

void loop(){
  char c[12];
  float f = millis()/1000.0;
  dtostrf(f,11,3,c);
  Serial.println(c);
  delay(111);
}

I have picked arbitrary values, you're going to have to do the calculations on the size of the array to create (don't forget the leading negative sign, the digits before the decimal, the decimal and your precision digits as well as the null terminator!

I had the same problem and I found answer
char latitude[20];
char longitude[20];

dtostrf(gps.location.lat(),8,6,latitude);
dtostrf(gps.location.lng(),8,6,longitude);

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


text:
2 Arduino controller boards - 1 shared input
I'm beginning with electronics and don't have all the good reflexes yet. So here is my question:
Can I do what I did here?
can i do this http://www.movod-design.com/forum_img/canIDoThis.jpg
Do I have to add diodes between the Nano +5V and the junction point?
My goal is to have one button's state read by 2 Arduino Nano.

Providing the 5V to the button should be coming from just 1 arduino. And you can also use the internal pull-up resistor from the arduino. That way you'll only need to connect one side of the button to the ground and the other side of the button to the 2 input pins of the arduino. To use the internal pull-up use pinMode(pin, INPUT_PULLUP);

Question is: why do you want two arduinos to do exactly the same? Maybe we could get rid of the second one altogether :)

You don't need to add anymore components to your schematic. But you can leave some components.
Before you're adding a button to your schematic please consider first how you want to detect your signal. A logic 1 as if a button is pressed? Or logic 0 as if a button is pressed. You can do this using pull-up and pull-down resistors. These resistors should be wired like this.

(The 100Ohm resistor in an internal resistor from the MCU)
Using the pull-down resistor means that when the button is pressed you'd get a logic 1.
Using pull-up resistors means that when the button is pressed you'd get a logic 0.
When I see your schematic it seems like you're trying to make a pushbutton with pull-down resistor. Then you should wire your arduino like this.

Another option is to use the Arduino internal pull-up resistors. That way you don't have to add the 10k resistor in your schematic. And your schematic will look like this.

To use the internal pull-up resistors from the Arduino you'll need to put this in your setup(): pinMode(pin, INPUT_PULLUP); where pin should be your pin number. Please keep in mind that when you use the internal pull-up resistor a logic 0 means the button is pressed.

thx a lot for the trouble you went through explaining at such great length! Very appreciated! :))

No problem mate. That's why we're here ;)

I have done something like this to be able to have a redundant system.
Is this what you were doing: Two computers receiving the trigger, if one computer failed you have the other running?
If that is your case, then there is a problem on this setup:

If one computer shuts down the Arduino on that computer will be powered by the second one and there will be not enough power for both.

I fixed it with a couple of diodes.
I still had some problems with false triggering from time to time, with tests on a Mac running OSX. The same tests with a Linux machine give no problem for now.
I wanted to make this really stable (next I'll try to use opto-isolators)
I'm not a Programer nor a Engineer. Please tell me if I'm saying something stupid or if there is any other easy fix.
I was using two Arduino Pro micro Chinese copies and passing the data to midi to the computers - I did not test with real Arduinos to see if it was a board problem.


text:
Receiving SMS by Arduino GSM Shield and control the LED with the content of this SMS?
I am using Arduino GSM Shield receiving SMS from an Android app. And the content of this SMS will control a LED. If the content of this SMS is not "off", the LED will be on and the content will be printed in the serial monitor. But if it is "off", the LED will be off immediately. Besides, the LED will keep being on until the "off" message coming. For now, I used the code from the example of the software. But I cannot use the content of this SMS to control the status of LED. With the code below, the LED could not be turned on and the content could not be displayed on the monitor. I think it was because the sketch failed to get the whole content of this SMS. Could anybody tell me how to solve this problem? Thanks.
#include <GSM.h>
GSM gsmAccess;
GSM_SMS sms;
char senderNumber[20];
int led=13;
void setup()
{
  Serial.begin(9600);
  pinMode(led,OUTPUT);
  digitalWrite(led,LOW);
  while (!Serial) {
    ;
  }
  Serial.println("SMS Messages Receiver");
  boolean notConnected = true;
  while(notConnected)
    {
      if(gsmAccess.begin("6442")==GSM_READY)
        notConnected = false;
      else
        {
          Serial.println("Not connected");
          delay(1000);
        }
    }
  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop()
{
  char c;
  int val=0;
  val=digitalRead(led);
  if (val==HIGH){
    digitalWrite(led,HIGH);
  }
  if (sms.available()){
    Serial.println("Message received from:");
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    if(sms.peek()=='#')
      {
        Serial.println("Discarded SMS");
        sms.flush();
      }
    while(c=sms.read())
      if(c='off'){
        digitalWrite(led,LOW);
      }else{
        digitalWrite(led,HIGH);
        Serial.print(c);
      }
    Serial.println("\nEND OF MESSAGE");
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }
  delay(1000);
}

If the below answer actually helped you in fixing your problem, please mark it as answered/correct. Also, it would help others if you could edit your question to reflect the changes you have made to get it working.

first i want to know where did u add "smsData[smsIndex++] = c; smsData[smsIndex] = '\0';" ?

@user2788 I added it below while, and then use strcmp(smsData,"off")==0 to check whether the content of this sms is "off".

First of all, you have a typo: You need the double-equals operator in
if (c == 'off') {

But more importantly, you can't use a char variable to hold or compare more than one character at a time. I don't know the details of the Arduino GSM library, but if sms.read() returns a string, then you'll need a string variable or an array of char to hold the result.

I succeeded with adding "smsData[smsIndex++] = c;
smsData[smsIndex] = '\0';". Thanks for your answer.

sms.read() function returns only a single byte of the SMS string. You can store the whole data in a character array and process it later like following:
char c, message[140];
int i=0;
while (c = sms.read()) {
    message[i++] = c;
}
if (strstr (message, "off")) {    //If SMS contains off anywhere
    digitalWrite(led,LOW);
} else {
    digitalWrite(led,HIGH);
    Serial.print(message);
}

And I believe the following portion in your code is not required as it is doing nothing:
val=digitalRead(led);
if (val==HIGH){
    digitalWrite(led,HIGH);
}


text:
Are there any GPS data pusher for Arduino?
I plan to build a GPS logger for my car using a GPS device, an Arduino board and a SD Card. The plan is that the GPS device forwards the position to the Arduino which is responsible for storing the data on the SD card. However, I would like to regularly (say every hour) send my current position to a server at home.
For that you can use GPS pusher or puller, but I couldn't find any such devices on the Internet. Do these devices exist? What are my (other) options?

Not sure what goes into a data pusher but you could probably do it cheaper with a GSM module and server. - It wouldn't surprise me to find that in the device you're referring to.

Yes, that would be possible, but then I need a SIM and a dataplan imho.

So you want something besides the GSM shield?

If possible, yes.

How do you want to communicate with a server over the internet?

How do you expect to "push" gps data to a server? The only options you have available to you is 1) Internet (as suggested, bluetooth to phone and phone internet connection). 2) GSM module and either a) use data plan to push via internet, or b) use SMS to another device at the server location. Either way, you're going to need to transport the data over some medium for which you are going to have to have a "plan". As has been asked, what is the server connected to (I suspect the internet). There's no FREE magical internet like medium the Arduino can latch onto.

Check this shield out, it sounds almost exactly like what you need, plus it has OBD2 (CAN) access to log RPM, indicated speed, steering wheel angle, and whatever else your car exposes. You can get a GPS module from Sparkfun as well. Matter of fact, I'm using it in a very similar project, but development is paused until I upgrade to a Mega, since I've run out of RAM.

The shield comes with example code that's hacked together from other sources but it serves the demo purpose well.
As for pushing to a server--that'd be tougher. I would go the route of a Bluetooth shield and make a corresponding app for the phone that pushes the data.

Hi Nick and thanks. I see that you can use this for logging. Put what about pushing data to a remote host?

Easiest would probably be a Bluetooth shield and an app on an Android phone.

Yes, but then I still need a Internet connection.

How else are you going to access a server on the internet?


text:
Are there any pressure sensor for 22 kg (~50lbs) and more?
I'm looking for pressure sensors up to 22 kg and more. So far the highest capacity I could found was 25 lbs. Do higher ones not exist?

Why do you need to measure such a high pressure?

Use a lever to reduce your force. If you have a 4 foot lever, with a pivot on one end, and your sensor under the other, if you apply 10 pounds of force 1 foot from the pivot, you will get 2.5 pounds of force at on the sensor. This is how bathroom scales work to measure large loads with a small sensor.

Yes, they exist - do a search for "load cell"

Your problem may be that you are using sub-optimal search terms.
The kilogram is not a unit of pressure, but instead of mass.
Scales technically do not sense mass, but instead sense force.
This is assumed to be the force exerted by a resting body under earth gravity.
Pressure is force over an area, such as pounds-per-square-inch (PSI) or the Pascal which is a newton per square meter.
Anyway, the sensor you want is called a force cell.
The nice ones are rated in newtons or kilonewtons, with a kg being equivalent to
9.8 newtons.
Here is a load cell that take up to 50 kg.
http://www.phidgets.com/products.php?product_id=3135
Sources:
http://en.wikipedia.org/wiki/Force


text:
Reading a car mass air flow, volumetric air flow meter
I'm looking to build an air flow meter that will output in standard liters per minute. The cheapest sensors seems to be a car's Mass Air Flow sensor. I'm wondering if there is a way use  one of these MAF to measure air flow in liters per minute.
Essentially I need to measure a medical ventilator's air flow in order to calibrate it. The gas flow analyzers that are normally used are way too expensive and offer too many extra features that I don't need.
Thank You

You'll have to tell us more about the MAF.. a datasheet would be good. What protocol does it use to communicate with the host device?

Is a ventilator's MAF in a range where an automotive sensor would work accurately / reliably?

There's no reason that an MAF couldn't be used with an Arduino.  It's likely that the sensor will run on 12v and output an analog voltage from 0 - 12, so you might need to use a voltage divider with the Arduino.
See this Sparkfun article on implementing a voltage divider to scale down the 0-12 volt signal to 0-5v for the Arduino.

Does the sensor have to elecrtonic? How about a ball and tube flow-meter, say a lucite tube with a gradually expanding bore (harder) or constant bore just larger than a ping-pong ball, with a number of relief holes up the side (easier)? The higher the ball rises, the more air escapes through the relief holes. leaving less to support the ball while escaping around it.
You'd calibrate it with a positive displacement (piston) pump driven at values of (displacement/time) in the range if interest, and marking pen to record the ball position for each.

If you don't need to much precision, then use pulse counting from turbine wheel measuring device, that will give you the speed og air in the duct, multiply with duct area and you get the flow Volume.
Alternatively use a delta pressure sensor for the air speed measurement something like http://www.rcdrone.cl/producto/sensor-velocidad-aire-para-aviones/
Just some idea from
Lars Funder
Have a great day


text:
Arduino Wifi Shield with monitor mode ( promiscuous mode )
Is there a WiFi Shield or driver that supports monitor mode and receiving raw packets ?

What is it that you're specifically that you want to achieve and what research have you done on this already?

I want to capture probe requests packets essentially.

I'd like to do something similar and have yet to arrive at an Arduino-based solution. Here's some resources I've found useful in learning about this topic. http://security.stackexchange.com/questions/54062/how-to-detect-the-hello-packets-sent-by-a-wifi-enabled-smartphone
http://www.engr.uic.edu/pub/Bits/Musa/musa-eriksson-sensys12.pdf

Does it have to be a shield?
I would consider buying a cheap Wi-Fi router instead with good open-source support and a way to interface it to the Arduino. Their price is near to the price of Wi-Fi shields.

They consume little power, can be powered by 5V and have built in Wi-Fi.
Some have a built-in USB port, most have a serial port, which can be used to talk to the Arduino.
You would have to put custom firmware on it, plus the program which receives the raw packets for you.

Specifically, I would get a TP-Link TL-WR703ND for this task.

It can be fed 5 Volts, or 3.3 Volts with a little hacking
It has USB
It also has serial, and you can even hack an I2C port onto it
It can run OpenWRT

More info on this particular router

You actually gave me a nice idea. Could I plug a 3G modem in the usb port and send the packets over the air?

Most certainly. On the OpenWRT website you can find instructions on getting the USB modem to work. You can use a hub to plug both the Arduino and the USB modem into the router. But beware that most USB modems communicate using serial-over-USB, so it's easy to mix up the two devices (because Arduinos also do and you will only see two serial ports, numbered by the order they were detected by the system). Also you may have to install the kernel module(s) for the USB/serial chip of the Arduino.

If this question is still open, I can also suggest using an ESP8266 board. It's a small board with a WiFi-enabled CPU, flash memory and an antenna - so it can be programmed and it can run without the Arduino. It supports promiscuous mode, so I think probe packets can also be captured. Also, it costs less than $4. (It came out in late 2014, about the time you asked the question)


text:
Operating HB100 backpack with Arduino Due
I need to connect a speed sensor module with an Arduino Due and calculate the speed of an approaching object.
the sensor is:
http://www.limpkin.fr/index.php?post/2013/08/09/Making-the-electronics-for-a-%247-USD-doppler-motion-sensor
The sensor already output a signal that its' frequency represents the speed of the object.
I would really appreciate any help understating how can it be connected and operated by the Arduino without burning it, and how can I sample its output?
If more details are needed I'll be happy to supply.
Thanks.

This looks useful: http://tushev.org/articles/arduino/item/51-measuring-frequency-with-arduino

The articles and tutorials I've read on the subject say that the HB100 module produces a very weak signal which needs to be amplified before your Arduino can read it. They recommend building an op amp. This post on the Arduino forums, for example: http://forum.arduino.cc/index.php?topic=61989.0
BUT looking at your picture and linked article, I find that your device already includes the signal amplification and filtering you need in the backpack board. I found the store page for this module, which has a more noob-friendly explanation. From what I gather:

VCC: provide the module with a 5v supply.
VOUT: analog reading of the amount of return signal being received. My guess is you could use this with analogRead() to get a rough estimate of the size or distance of the object being read. If you want only the speed reading, you don't need this pin.
FOUT: digital output of the speed that the sensor is reading. Thanks to @sachleen's link, you can use either pulseIn() or FreqCounter library to measure the frequency and then convert it to a MPH or KPH speed.
GND - ground, aka common, aka -.

So connect VCC to 5v, GND to ground, and FOUT to an input pin on your Arduino. If you use pulseIn(), frequency f = 1 / t, t being the return value from pulseIn(). If you use the FreqCounter library, it no doubt has documentation on its usage.


text:
what is the coversion details of temperature usnig lm35?
I found similar type of code in many sites for coverting analog signal lm35 to centigrade.
But i can't understand that fully. So I need some help what this equation means
tempC = (5.0 * tempC * 100.0)/1024.0;

Thank you,

That equation doesn't quite make sense. Are you sure you copied it accurately?

I took a quick look at the data sheet for LM35 and it says that each centigrade means a 10 millivolt change.
If you have an ADC with 10-bit resolution, it means you have 1024 steps from 0 V to 5 V.
The temperature is then:
tempC = 5 * (ADCdata / 1024) * 100
This is equal to your equation. So it seems to be correct.
EDIT:
A more thorough explanation of the formula:
Lets call the value you read from your LM35 "ADCdata". The range of this value is determined by the resolution of the Analog-to-Digital Converter (ADC). The ADC converts a voltage to a digital value in the Arduino. This value is again what I refer to here as "ADCdata".
If the ADC resolution is 10-bits, it means the 5 volt input can be divided into 1024 equal levels. One level is about 5 millivolts (five thousands of a volt).
To find what value "ADCdata" is in volts we need to divide it with the resolution (1024) and multiply with 5 volts.
Lets say we have a 2.5 volt input signal. The ADCdata will then be 512. If we now divide 512 by 1024 we get 0.5. Lets multiply that with 5 volts and we get 2.5 volts!
We know from the data sheet that 10 millivolts equals 1 centigrade. Since we have our value in volts (2.5 V, which is the same as 2500 millivolts) we need to multiply it with 100 to get centigrades.


text:
Seeking to measure back EMF of an electric motor via Arduino
Is it possible to measure the back EMF of a motor, using just the Arduino and no sensors?
Or what type of sensor do I need? One that measures current?

There is no need to measure the windings of the motor... please see the great write up for full details using an Arduino to sense the back EMF on a PWM driven motor to control the speed. This can be applied to a 3 phase motor as well, see Back EMF.
This person uses the analog input and a voltage divider to sense when the EMF happened, basically he gets the motor running, then periodically grounds one side of the motor through the H-Bridge he is using to drive it, and the other side of the  motor goes to a voltage divider into the Arduino... and it is also an open circuit at this time so the voltage generated is from the collapsing of the coil field so if it is 12V it becomes a safe 4V at the Arduino Analog input.
Now your question says "measure the back EMF", what I provided senses the back EMF... to measure it you just need to sample the Analog pin a bunch of times, and that will give you a reference of the max amplitude.

You will need at least an external current sensor, the arduino has no way of measuring current built in. You will also need to measure the winding resistance of the motor beforehand. look to this answer for a good explanation:
https://electronics.stackexchange.com/questions/54997/how-can-i-measure-back-emf-to-infer-the-speed-of-a-dc-motor
DC current sensors compatible with arduino should not be hard to find; just search one of the standard hobby electronics components sites.

Technically EMF is a voltage, not a current.

Take a look at this website:
http://www.vwlowen.co.uk/arduino/current/current.html
It shows how to make a create a simple current sensor with just a few resistors.

Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline.

EMF is a voltage, not a current.


text:
Wired serial connection between two Arduinos - do they need a common Ground (GND)?
I would like to connect two Arduinos by a serial connection. Is it sufficient to connect TX1<-->RX2 and RX1<-->TX2 or do I also need to connect the GND of the two Arduinos?

Short answer: Yes.
Rx/Tx is referenced with a logic ground. Without ground being common, there is no way to determine what is high or low.
(Sorry I don't have a more technical explanation)
Edit: I thought I would add, if you are using the same power source, then they probably have a common ground. In this case, a common power source doesn't mean the wall side of a wall adapter, but the SAME wall adapter.


text:
Reading the rpm of multiple fans
I am trying to build a fan controller for my pc, the problem is that the example code(http://playground.arduino.cc/Main/ReadingRPM) im using utilizes interrupts. On my uno I can then only read the rpm of one fan. I want to also control the rpm (via pwm) and monitor temperatures (via thermistors) Anyone know how I coud do it differently? I. E. Without interrupts. I would also like it to be as close to real time as possible

It may help to add some more detail. Do you just want to monitor the fans, or control them also? What is your desired outcome? How many fans? What RPM range? The more detail the better, as it makes the question more interesting and useful.

@jlbnjmn I want to monitor and control them and temperatures from thermistors

If temperature regulation is what you seek, why bother with the Tachometer signal at all?
Thermistors don't require interrupts. Why do you need fully closed loop fan control? A simple proportional control of each fan and each hot item would likely suffice in keeping your system cool. Noise concerns, perhaps?
A brief article on proportional temperature control
A data sheet on a TI chip that may have some inspiration for you

I'm wanting to use this on my pc so it's got to be quiet. And with monitoring rpm I can set up a fan failure alarm and other things.

Looking at that chip, it looks like it'll do exactly what I'm wanting. Am I mistaken or does it also have an i2c interface? Does that mean I could just read the values off of it?

If you only want 2 fans, the uno has 2 external interrupts, so you can use the same strategy as your example, just make another interrupt function for fan 2 and attach it on interrupt 1 instead of 0. the fan should be plugged in to pin 3 in this case. On a leonardo, you could have 5 fans on interrupts, and a mega has 6 external interrupts. See http://arduino.cc/en/Reference/attachInterrupt
If you need more than what your hardware can support, I would look into using a timed interrupt to check all the fans. If you find the minimum amount of time in-between reads to read your fans at max RPM and then use a timer interrupt to check some pins at that interval, you can probably read as many as you need, provided the interrupt routine stays fast enough. the function
attachInterrupt(function, period);

from the libraries on this page : http://playground.arduino.cc/Code/Timer1
should help you out with this.


text:
Watchdog timer stuck in restart loop? (green led flashing)
I am trying to set up a way to reboot arduino on command. The code below should do that but it seems like my arduino just get's stuck in some sort of a loop where I cant upload or get any serial output. The green led (pin 13) flashes very fast. The only way to stop this is to cut power to the device, even reset button does not work. This happens only when "R" is received via serial or if wdt_reset() function is commented out.
#include <avr/io.h>
#include <avr/wdt.h>

int ledPin = 3;

void setup()
{
  MCUSR=0;
  wdt_disable();
  Serial.begin(57600);
  Serial.println("BOOT!");
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  delay(500);
}

void loop(){
  if (Serial.available() > 0){
    char cmd = Serial.read();
    if (cmd == 'R'){
      Serial.println("R received!");
      wdt_enable(WDTO_1S);
      delay(2000);
      Serial.println("1 SEC.");
    }
  }
  wdt_reset();
  digitalWrite(ledPin, HIGH);
}

What am I doing wrong?

I think I ran into this a while ago, to upload a new sketch (without the watchdog stuff) I held down the reset button until right before the IDE began its "uploading" state.

Also see the note at the bottom of this post: http://ariverpad.wordpress.com/2012/02/26/resetting-the-arduino-through-software-for-fun-and-profit/

@sachleen yes, I followed that write up but am a little confused where that code goes. I assume it does not go into the sketch? I would prefer not to edit source files as that would affect every arduino I program.

Yes that would modify the bootloader and affect other sketches as well, but only if you're using the watchdog.

@sachleen Does that mean the bootloader would need to be re-flashed?

One of the most obvious issues here is that you are enabling the watchdog timer with a delay of 1S and then you are asking the micro controller to sleep for 2S, printing something and then going back into the loop. This, in theory, should be fine(your wdt should trigger a reboot during the 2 second wait) but I've seen it cause issues.
Additionally some bootloaders(notably the Optiboot bootloader on Uno and newer boards) can have issues with watchdog timers causing the wdt to remain enabled after reset even though the setup loop disables it. To start with - try increasing the wdt time to something greater than 2S(you should be able to do WDTO_8S) and see if the issue persists.
EDIT - The OP is using an Arduino Pro Mini clone. The included bootloader on the Arduino Pro Mini does not support system restarts by the WDT. Essentially, on a device with a bootloader that does not support WDT restarts, the board will restart but the timer / reset will not causing the board to continuously reset on reboot. There are alternative bootloaders for Arduino boards that may resolve this issue. Another solution is to use a different method to reboot the board.

So if it can cause issues, what method does not cause issues? I just tried 8 seconds with 9 second delay with same results. 8 seconds would bee too long anyways as I don't actually need any delay after serial command.

One of the first questions would be - what board is it and what bootloader are you running on it? Additionally - what happens with a simpler version of the watchdog code? For example one that is not reading an input but is rather looping a print statement n times and then resetting? Here(http://www.megunolink.com/how-to-detect-lockups-using-the-arduino-watchdog/) is an example of a very simple use of the watchdog timer - what happens when you run something like this?

I am using arduino pro mini clone with default bootloader (not sure what it is). With the copy pasted sample from the link it locks up just the same after a couple of seconds after power on.

A quick google on your product shows others with the same issue. The bootloader on the Arduino Pro Mini does not support system restarts supported by the watchdog timer. Essentially they restart the system but do not restart the timer causing the board continuously reset on reboot. I have not used an Arduino Pro mini nor have I had much luck with offbrands(nothing wrong with them, just bad luck on my part) so I can't recommend another bootloader offhand but a quick google search shows that there are folks who have found a functioning bootloader for the device that supports the WDT.

Is the bootloader required for watchdog at all? Could I just get rid of bootloader altogether, as long a I can program it over bluetooth that would be the best option for me.

That probably won't resolve your issue. It's not that the bootloader is the problem - it's the implementation of the WDT in the bootloader and how the bootloader is handing WDT events that is the problem. Getting rid of the bootloader doesn't get rid of the problem - it just changes it so that you need to implement the handling of WDT on your own. It is certainly possible to burn a sketch to an arduino without the bootloader(Here is some documentation about it.) But without a bootloader you will not be able to load a sketch via bluetooth.

Is there a particular reason you're using a WDT to reset the arduino? There are several other methods(here is an instructable detailing these methods) that you could use that would get around this.

WDT is the only software only solution but I guess I will go with using one of the pins to trigger the reset.

Enabling watchdog timer system restart and waiting in a loop until reset is a legitimate way of SW resetting the µC as is using watchdog for catching µC's misbehavior which can be caused by various reasons.
However, some precautions have to be made when using watchdog system reset because on all AVRs that also have watchdog interrupt the watchdog with prescaler set to 0000 = 16 ms remains active after watchdog system reset condition. It is therefore responsibility of a programmer to clear MCUSR and to disable watchdog timer as soon as possible after occurrence of such a condition. Since LPM routines for initializing .data and .bss sections can last longer than watchdog timeout interval, the code for disabling the watchdog must be placed in .init3 section and the contents of MCUSR can optionally be saved for later reset source examination. Here is the code that does the described:
uint8_t mcusr_copy __attribute__ ((section (".noinit")));
void disable_wdt(void) \
     __attribute__((naked)) \
     __attribute__((section(".init3")));
void disable_wdt(void) {
  mcusr_copy = MCUSR;
  MCUSR = 0x00;
  wdt_disable();
}

However, the problem may arise when using a bootloader which does not account for the possibility of watchdog system reset condition. If that is the case, watchdog timeout will happen inside bootloader (which is executed the first) before the above code will have the chance to disable the watchdog timer and µC will be stuck in an endless reset loop. Since reseting the µC will not clear WDRF flag in MCUSR register (it can be cleared only in software or by Power-on reset) the only way will then be to cycle the power and upload a new code when watchdog timer is still not activated by previous code. WDRF in MCUSR register must be cleared before wdt_disable() because WDE can not be cleared if WDRF is still set - therefore the order of the instrucions in the above code is very important. The function placed in .init3 section must not be called from later code.

Remove watchdogs flag at init is one solution. I am using optiboot 8.0 and it works perfect.
// Function Pototype
void wdt_init(void) __attribute__ ((naked, used, section(".init3")));

// Function Implementation
void wdt_init(void)
{
    MCUSR = 0;
    wdt_disable();
    return;
}

You can restart the Arduino with this command:
asm volatile ("  jmp 0");

This only does soft reset and will not reset it to defaults completely.