message:
Sample code for using adafruit servo shield?

I would like to control 16 motors with a servo shield, however, I have found scant to nothing sample code online. The one I was able to find is...strange to say the least

https://github.com/kachok/arduino-libraries/blob/master/Adafruit_PWMServoDriver/examples/servo/servo.pde

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

    // called this way, it uses the default address 0x40
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

    #define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
    #define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)

    uint8_t servonum = 0;

    void setup() {
      Serial.begin(9600);
      Serial.println("16 channel Servo test!");

      pwm.begin();

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

    void loop() {
      // Drive each servo one at a time
      Serial.println(servonum);
      for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
        pwm.setPWM(servonum, 0, pulselen);
      }
      delay(500);
      for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
        pwm.setPWM(servonum, 0, pulselen);
      }
      delay(500);

      servonum ++;
      if (servonum > 15) servonum = 0;
    }

Im used to controlling motors using servo.write, but with the shield, it doesn't seem very intuitive as to how I should control the motors. How does Servomin and Servomax map to 0 degree and 180 degree?

Someone please elucidate!

body:
Adafruit's guide for the shield is here:
https://learn.adafruit.com/adafruit-16-channel-pwm-slash-servo-shield/using-the-adafruit-library

I'm not sure how much the library you linked and the official one differ. They seem to be used the same way, but you should probably stick with the official one.

You are going to have to use setPWM(pin, on, off) since the arduino is not generating the signals like it would with servo.write(), the arduino is sending commands to a chip on the shield that generates the signals for you.

Adafruit recommends calibrating SERVOMIN and SERVOMAX yourself with whatever brand of servo you plan on using, but those default values should be pretty close.


sender: user

sender: assistant

body:
The 2 values SERVOMIN and SERVOMAX define the pulse length, which tells the servo what angle to go to.  The example uses 150 for SERVOMIN and 600 for SERVOMAX.  When running the code, the servos travel 180 deg.  I changed the code to read:

    #define SERVOMIN  262 // this is the 'minimum' pulse length count (out of 4096)
    #define SERVOMAX  488 // this is the 'maximum' pulse length count (out of 4096)

and the servo now moved only 90 deg. centered at the same place as the original code.

the tutorial provided by Adafruit describes a way to define the movement by angle:

    pulselength = map(degrees, 0, 180, SERVOMIN, SERVOMAX);

found here:  https://learn.adafruit.com/adafruit-16-channel-pwm-slash-servo-shield/using-the-adafruit-library

hope this helps


message:
Salvaged Stepper Motor Blues

So recently my company threw away some rather large and reasonably old laser printers. One was a LaserJet 9050dn the other was a Epson printer/scanner combination. Being a little industrial I thought let me salvage them and brought them home.

I managed to salvage a couple of stepper motors. However I am having huge trouble is getting them to step properly. So lets get into the details.

Components used:

 - 1x Freetronics eleven (Arduino Uno compatbile)
 - 1X H-Bridge driver shield(Freetronics rated for 40V/2A max).
 - 1X Old scanner power supply which has a output of 24V/2A.

Currently there are two stepper motors I am interested in using. They have the following part numbers:

 - 1X MITSUMI M42SP-4N
 - 1X Minebea-Matshushita 17PM-J212-G2ST

Just to keep this short I am going to focus on the Minebea-Matshushita 17PM-J212-G2ST. I have been unable to find exact matches on these serial numbers when looking for datasheets but I have managed to find the following sheets on the net.

 1. [Minebea-Matshushita 17PM-K][1] datasheets found from Minebea. However I cant match the model exactly.
 2. [Minebea Stepper Motor Information & Specifications][2] also carries some useful information.

So it appears that these are 24V steppers(in both cases). The Minebea-Matshushita 17PM-J212-G2ST appears to have a step angle of 1.8 degrees which should give me 200 steps per revolution. I have not been able to find the current needed to drive this motor but judging by the looks of things it will be between 0.8A and 1.2A.

I then used my multimeter to find the pairs of wires. It has 4 wires coming out (Bipolar motor I guess). The colours of the wires are red, yellow,orange and blue. First pair was red and yellow with red being positive/anode. Second pair orange blue with orange positive/anode side.

I wired my power supply into my h-bridge and started using the [recipe and quickstart][3] found at the freetonics site. This is where the frustration begins. When asking the motor to do one complete revolution(360 degrees) it does more than 360 degrees at times and other times it does less. I tied a cable tie to the motor so I can confirm it.

So I tried the one-step-at a time sketch to see if I can troubleshoot it. Here is what I have noticed. The steps are mostly correct one step at a time clockwise however every now and again it will jump counter clock wise and then clock wise again. I suppose you can call it a jitter.

Interestingly both these motor show the same behaviour pretty good step action just every 25 degrees or so a jitter. So I suspect that this might not be bi-polar motors but uni-polar? [This blog][4] entry points me to believe that this might be the case. However the datasheet in this case points to a M42SP-7.

So my question would be simple how do I figure out if they are bi-polar or uni-polar?

Can someone help me with a proper datasheet?

Any tips would be really appreciated.

Update:

Note that I can get both motors to step clock-wise and counter clock-wise I just cant get them to do a whole 360 degrees without a jitter. Based on the [Wiring Mitsumi stepper ( M42sp-4np) with arduino blog ][4] it appears that the Mitsumi is a uni-polar motor with a 2-2 phase excitation. What stumps me is that the wires are paired thus it must be bi-polar?

So last night I tried 2-2 phase excitation with the MITSUMI M42SP-4N and it appears to be solve the problem with this motor in particular. From early observations the motor now steps without jitter, however it was late so I will need to confirm this.

I was previously using 1-1 phase excitation i.e.

    Step number: 1a 1b 2a 2b
    1            1  0  0  0
    2            0  0  1  0
    3            0  1  0  0
    4            0  0  0  1
    5            1  0  0  0

When using 2-2 phase excitation I get a more steady step however this needs to be confirmed a bit more:

    Step number   1a 1b 2a 2b
    1             1  0  0  1
    2             1  0  1  0
    3             0  1  1  0
    4             0  1 0  1
    5             1  0  0  1

Just some added observations. The headache continues but I am learning a LOT about steppers motors.

Update:

Not a 2-2 phase excitation these are definitely bi-polar. I am currently watching the Minebea-Matshushita 17PM-J212-G2ST do 360 degrees both clock and counter-clockwise. I hooked them up to a 12V/1A power supply both motors are running smoother and cooler and stepping relatively jitter free. I suspect the whole issue is a lack of a proper data-sheet.

Will update as things progress and once solved add pictures and sketches so the next lucky sod wont loose as much hair as me.

Update:

Thanks to Chris who made me look at the sketch in detail again. These motors seem to have a minimum rpm of sorts. I was trying to go for a really slow rpm under 5rpm at this speed these motors show the jitter effect. However when moving the speed to 10rpm and up no jitter.

  [1]: http://www.eminebea.com/en/product/rotary/steppingmotor/hybrid/standard/data/17pm-k.pdf
  [2]: http://www.theprojectasylum.com/electronicsprojects/componentdata/minebeasteppedatacirca1999.html
  [3]: http://www.freetronics.com/pages/hbridge-motor-driver-shield-quickstart-guide#.VA1jNfmvUrW
  [4]: http://josafatisai.blogspot.com.au/2013/04/wiring-mitsumi-stepper-m42sp-4np-with.html

body:
Keeping this here for future reference. It appears these motors have a minimum RPM of sorts and running them on a lower RPM causes the jitter effect described above.

Like I mentioned in the updates when running at 10RPM or above these motors seem to perform very nicely.

Update: I recently bought a ADAFruit motorshield and I am getting much more stable results with this shield and the stepper motors. I am even running them off 6V and they are working perfectly even at lower rpm.


message:
Is it possible to make an Arduino send signals to an RC receiver?

I have found bunch of information about how to hack an RC car with a PCB; and how to control an Arduino from a receiver. Also how to run a servo from an Arduino, but I'm looking for a way to make an Arduino send signals to a 27 MHz 3 channel receiver, Using three potentiometers to decide servo location.

Is there any information about this somewhere? - I have an old transmitter lying around if needed.

Links, pointers - anything is welcome.

[It does not have to be 27 MHz AM, it is just what I have on the shelve, without investing in new gear]

body:
The easiest way would be to open up the transmitter, desolder the potentiometer used for the stick and solder the cables to Arduino's PWM instead. Then use `analogWrite()` to simulate stick position. If your TX would use that potentiometer with more than 5 V, you'll not able to use full ppm values. A RC or a RCL filter may be needed between PWM output and RC input to "smooth" the PWM into an analog signal. There are a lot of online calculator to find good *R, C and L* to polish your signal.

This assuming your TX is using potentiometer like stick; if it is a really cheap one, it may be using *buttons*. If this is the case, then you connect a transistor in parallel with the button, that way you can keep manual button.

Another way is to program your Arduino to look for ppm signal (normally 50 Hz with high starting value with a period from 500 to 2000 µs) and then look for this signal into the Tx PCB; if found cut the trace of the generator and solder your cable from Arduino. I've seen around a lot of libraries outputting ppm (they are used on drones to mix single ppm channel back to PPM to use only one pin from logic board without having to hack standard RX


body:
Many RC TX have a remote connector where you can input the signal and not having to open them.

In any case, 27 MHz RC are a train of pulses, of variable width, from 2 to 20 ms each, one for each channel, flowed by a 20 ms pause.

This can be recreated in a single output pin.


body:
Consider the methods of US patent 9,996,079 (linked URL):

"Radio frequency device detection and intervention": [US 20180081354 A1][1]

After reverse engineering the badly written descriptive, you should be able to come up with an Arduino board set.

P.S. Try not to copy the whole patent.

  [1]: http://patents.com/us-9996079.html


message:
Optmizing print code when writing to file, and reducing print time

First things first, I have found some solutions to this problems but they all involved for printing to serial monitor. I am trying to take the information from the sensors and write them to an sd card. Here is my code so far:

    //-----Writes Data to SD Card-----//
    if(!Data) {
        u8g.firstPage();
        do {
           drawFileError();
        } while( u8g.nextPage() );
        while (1);  // don't do anything more:
    }

    dcounter++;
    if (dcounter=1){

        Data = SD.open("Data.txt", O_CREAT | O_APPEND | O_WRITE);
        Data.println(Header);
        Data.print(strutcDate + "  ");
        Data.print(strutcTime + "  ");
        Data.print(strgpsStatus + "  ");
        Data.print(strmodeIndicator + "  ");
        Data.print(strlatitude + "  ");
        Data.print(strlongitude + "  ");
        Data.print(strspeedOverGnd + "  ");
        Data.print(strcourseOverGnd + "  ");
        Data.print(t);
        Data.print("  ");
        Data.print(f);
        Data.print("  ");
        Data.print(h);
        Data.print("  ");
        Data.print(hi);
        Data.print("  ");
        Data.print(press_pKa);
        Data.print("  ");
        Data.println(str);
        Data.close();
    } else{
        Data.print(strutcDate + "  ");
        Data.print(strutcTime + "  ");
        Data.print(strgpsStatus + "  ");
        Data.print(strmodeIndicator + "  ");
        Data.print(strlatitude + "  ");
        Data.print(strlongitude + "  ");
        Data.print(strspeedOverGnd + "  ");
        Data.print(strcourseOverGnd + "  ");
        Data.print(t);
        Data.print("  ");
        Data.print(f);
        Data.print("  ");
        Data.print(h);
        Data.print("  ");
        Data.print(hi);
        Data.print("  ");
        Data.print(press_pKa);
        Data.print("  ");
        Data.println(str);
        Data.close();
    }

two questions: is it possible for me to reduce this chunk of code into something smaller? is there a way to decrease print time?

Edit: Ahh I see, the problem with my code is that the last few values are floats.Any way to shorten those as well, or do i need to do it individually? I do agree about the adding string parts.

body:
I would analize what I want to write, extrapolate all numeric value, then create a structure that hold numeric value. So at every write I would write the structure (it is a binary write, so use fixed byte size) followed by all others string(or even place string in different file, but may turn out harder to manipulate or fix in case of problem).

Then to read it you'll need to read back the structure, followed by eventual know number of string. If string may be of unknown number,, just put the number of following string into the struct. Outside string, as you can see, you need no special char to signal the end of chunk of data :)

Unrelated: please, remove all println in the if rather than the header as they are equal to the else; then remove the else statement (but not the else body!) That way the if will open file and add header, and then the code will always add the rest of code. It would be a shame if you edit your else branch and forgot the if, or viceversa. Code style matters, trust me


body:
First of all, the only difference between the two parts of the "if" statement is that, the first time, it prints the header. Instead of that code, you could do this:

    //(Include the top part of the code here...)
    dcounter++;
    if (dcounter=1){
        Data = SD.open("Data.txt", O_CREAT | O_APPEND | O_WRITE);
        Data.println(Header);
    }
    Data.print(strutcDate + "  ");
    Data.print(strutcTime + "  ");
    Data.print(strgpsStatus + "  ");
    Data.print(strmodeIndicator + "  ");
    Data.print(strlatitude + "  ");
    Data.print(strlongitude + "  ");
    Data.print(strspeedOverGnd + "  ");
    Data.print(strcourseOverGnd + "  ");
    Data.print(t);
    Data.print("  ");
    Data.print(f);
    Data.print("  ");
    Data.print(h);
    Data.print("  ");
    Data.print(hi);
    Data.print("  ");
    Data.print(press_pKa);
    Data.print("  ");
    Data.println(str);
    Data.close();

Like already mentioned, you can append strings with the `+` operator. This would be the final code then:

    //(Include the top part of the code here...)
    dcounter++;
    if (dcounter=1){
        Data = SD.open("Data.txt", O_CREAT | O_APPEND | O_WRITE);
        Data.println(Header);
    }
    Data.println(strutcDate + " " + strutcTime + "  " + strgpsStatus + "  " + strmodeIndicator + "  " + strlatitude + "  " + strlongitude + "  " + strspeedOverGnd + "  " + strcourseOverGnd + "  " + t + "  " + f + "  " + h + "  " + hi + "  " + press_pKa + "  " + str);
    Data.close();

FYI, it doesn't seem like you should close the stream every iteration at the end since you only open it the first time.


message:
Multiple Buttons on Single Analog Pin and Trigger Pin Arduino Uno

I've researched how to attach multiple buttons to a single analog input using a resistor network. Instructables has a good lesson on this: http://www.instructables.com/id/How-to-access-5-buttons-through-1-Arduino-input/?ALLSTEPS

My requirement is that I need to attach an interrupt to buttons (ie the analog input) before reading the analog value, so that all the buttons can act as a trigger.

This works for voltages in the higher range, but not in the lower range (the trigger input waits for a RISING edge).

Can any one suggest a circuit that steps a >0V+ to +5V input to a +5V output so that any button push would trigger the input?

Otherwise, does anyone have other suggestions on how to use triggers for each button?

body:
Use the analog comparator in the ATmega328P to trigger an interrupt once the input voltage rises enough to indicate a button press.

Connect the analog network to both the analog input and D6.

If your lowest analog voltage is not greater than 1.2V then apply a voltage greater than 0V but more than 40mV less than your lowest analog voltage to D7. If you have *not* connected the voltage then configure the comparator to use the internal bandgap reference (`ACSR |= _BV(ACBG)`).

Enable the comparator interrupt and capture on a rising edge (`ACSR |= _BV(ACIE) | _BV(ACIS1) | _BV(ACIS0)`).

Disable the digital input on D6 (AIN0), and on D7 (AIN1) if connected to a voltage reference (`DIDR1 |= _BV(AIN0D)`, `DIDR1 |= _BV(AIN1D)`).

Write an ISR that does what you want on comparator trigger (`ISR(ANALOG_COMP_vect) { ... }`).

Now go back and read all that ***three more times*** until you understand it. As always, see the ATmega328P datasheet for details.


body:
Considering the fact that from a *functional point of view*, you just want **to have more digital inputs, I would propose to use a `Parallel-In Serial-Out Expander`**, (e.g. `CD4021B` or `74HC165`).

This IC (i.e. `74HC165`) has 8 digital inputs, that can be 'shifted' and send to your Arduino using just 2 wires. Arduino has a built-in function for this (i.e. `shiftIn`) to read the input and to convert it to a byte.

If 8 inputs is not enough, then you can chain multiple IC to create 16, 24 ... digital inputs.

There is an official [tutorial for the CD4021B][1].

I don't know if this is a requirement, but if you want to register **multiple key-presses at the same time**, then this is a really good strategy.

  [1]: http://www.arduino.cc/en/Tutorial/ShiftIn


body:
I really do not know your level of experience, so please, ignore this if not applicable;
Most cases of a push button will not need an interrupt. It is a human pushing the button and so precise timing is no where close to needing an interrupt.  You would only need an interrupt if you wanted to actually interrupt some looping code. And since timing (of a human by definition) is not that great, simply checking for a button press in your looping code will always be good enough.
That being said, the common resistor networks you have read about will work adequately.

    psuedo code;
    void loop()
    {
      int btn = analogRead(pin);
      if (btn > pin1Level)
      {
        if (btn > pin5level) DoPin5();
        else if (btn > pin3level) DoPin3();
        else DoPin1();
      }
      doOtherStuff();
    }


message:
How does serialEvent gets into main()?

Ok, serialEvent "runs after loop()" and it is not an interrupt.
AS far as I know main() has two functions  - setup and "infinite" loop.
So where does serialEvent comes in?

And if I do not want loop()  to run and use only setup than  I cannot use serialEvent.

body:
Yes you are correct, the event handlers will not do anything in setup. Main runs "setup()", then loops infinity through "loop()", but gives the serial event handlers a chance to run in between. The actual main that runs on the arduino is this:

    int main(void)
    {
     init();

     initVariant();

    #if defined(USBCON)
     USBDevice.attach();
    #endif

     setup();

     for (;;) {
      loop();
      if (serialEventRun) serialEventRun();
     }

     return 0;
    }

this is found (on linux at least) in arduino/hardware/arduino/avr/cores/arduino/main.cpp

"serialEventRun()" is in HardwareSerial.cpp, but is not very interesting.

To be clear, Serial itself will still work fine in setup(). If you want to use the same event handler function, all you have to do is call "serialEventRun()" yourself periodically.


message:
Sample average of analog of current sensor

I have two problems in the code below. This ACS712 sensor is too noisy so I am not getting the count value properly, since I need approximate reading I consider curve is linear, and calculate the slope.

My problems are:

1. When I take a 10 sample average, the first value it reads properly, i.e. 512 is count value, other value taking as 0. I don't why.

2. Once current exceeds 1A, my relay output should go low. Once it goes low it waits for 30s & again it must high the relay high. Since I am checking output in loop, it making high & low without waiting for 30s. Can someone help me how can I do this?

If you used without MStimer, the `newaverage` values print 512 which is my reference, but for other 9 values print `newaverage` as zero.

    #include <MsTimer2.h>

    #define RELAY1  3
    #define RELAY2  4

    int num_readings=10;
    //int total;
    int readings[10];
    int index;
    float CS_Value;
    static float Output_Current;
    float mad;
    float madstd;
    float lowlimit ;
    float highlimit;
    int count;
    int total;
    int reading;
    static int newaverage;
    unsigned long Wait_Time=30000;
    unsigned long Current_Time;
    static int Tripped_Flag=0;

    float standard_deviation(int avg1) {
      total = 0;
      for( int i=0; i<num_readings; i++)
        total = total + pow((avg1 -readings[i]), 2);
      return sqrt(total/num_readings);
    }

    int  average()
    {
      total = 0;
      for( int i=0; i<num_readings; i++)
      {
        total = total + readings[i];
      }
      return total/num_readings;
    }

    void TakeReading()
    {

      reading = analogRead(A0);
      readings[index] = reading;
      index = index + 1;

      if (index >= num_readings)
      {
        index=0;
        int avg = average();
        float std = standard_deviation(avg);
        madstd = mad * std;
        lowlimit = avg - madstd;
        highlimit = avg + madstd;

        total=0;
        count=0;
        for(int i=0; i<num_readings; i++) {
          // Check if the values of the readings are within the limits.
          if(readings[i] >= lowlimit && readings[i] <= highlimit) {
            total = total + readings[i];
            count = count + 1;
          }

        }

        // compute the new average
        newaverage = total/count;
        // send it to the serial port (as ASCII digits)

        Serial.print("Newaverage:");
        Serial.println(newaverage, DEC);
        Output_Current = 0.0336666666667*newaverage - 17.17;
        //return(Output_Current);
      }

    }

    void setup() {
      // sets the serial port to 9600
      Serial.begin(9600);
      pinMode(RELAY1, OUTPUT);
      pinMode(RELAY2, OUTPUT);
      Relay_Intialize();

    }

    void loop()
    {
      MsTimer2::set(50, TakeReading); // 500ms period
      MsTimer2::start();
      //  CS_Value=  TakeReading();
      Serial.print("current is :");
      Serial.println(Output_Current);
      //if (CS_Value>0.95 && Tripped_Flag==0)
      if (Output_Current>0.95 && Tripped_Flag==0)
      {
        Serial.println("Main Activate");
        Serial.print("Tripped_Flag_status:");
        Serial.println(Tripped_Flag);
        Relay_Activate();

      }
      else
      {

        Serial.println("Main Deactivate");
        Serial.print("Tripped_Flag_status:");
        Serial.println(Tripped_Flag);
        Relay_Deactivate();
      }
      Serial.println(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
      delay(1000);

    }

    void Relay_Activate()
    {
      for (unsigned long start = millis(); millis() - start < 10000;)
      {
        digitalWrite(RELAY1,LOW);
        digitalWrite(RELAY2,LOW);
        Serial.println("RELAY GOT TRIPPED");
        Tripped_Flag=1;
      }

    }

    void  Relay_Deactivate()
    {
      digitalWrite(RELAY1,HIGH);
      digitalWrite(RELAY2,HIGH);
      Serial.println("RELAY NOT TRIPPED");
      Tripped_Flag=0;

    }

    void Relay_Intialize()
    {
      Serial.println("RELAY GOT INTIALISE....");
      digitalWrite(RELAY1,HIGH);
      digitalWrite(RELAY2,HIGH);
    }

[![Data output when load connected with MS library][1]][1]

  [1]: https://i.stack.imgur.com/Is2C7.jpg

body:
I didn't have a look at your item 2, but regarding item 1:

Please consider that in function `TakeReading()`, if the condition is never true, count is 0 when you come to `newaverage = total/count;`!

I don't know what the Arduino does in case 0/0, but -1 may be a proper return value.


message:
Stacking Arduino Shield (Motor Shield, LCD Keypad, LED Sensor)

I'm building a line follower with arduino, here some part that I'm going to use

- Arduino Uno

- Motor Shield 2A http://www.dfrobot.com/index.php?route=product/product&product_id=69
- LCD Keypad

- 4 Channel Line Tracking Sensor http://www.aliexpress.com/item/4Channel-Infraed-Line-Tracking-Sensor-Module-w-Connector-Line/2021343637.html

I'm using LiPo Batteries 3 Cell 11.1v for power source.

I'm new in here so I didn't know how to stack that shield, if I recall I can stack up Arduino and the LCD Keypad, and Arduino and the Motor Shield, but didnt know how to stack those 2 together and adding another sensor like that line tracking sensor. May I know how to resolve that? thanks.

body:
The Motor Shield 2A plugs in on top of the Arduino Uno, and the LCD Keypad plugs in on top of the motor shield. [But see *Edit 1* below]

There is better information about the  4 Channel Line Tracking Sensor at [uctronics.com](http://www.uctronics.com/channel-tracking-sensor-module-line-hunting-sensor-p-1463.html) where you can see that its main board (with the LM339 chip) connects to the Arduino via six lines: Vcc, Gnd, Out1, Out2, Out3, Out4.  That main sensor board does not mount on the stack, but instead can be located whereever is convenient and leaves its four comparator-level pots accessible for adjustment.
Mount the four small boards for the tracking module as convenient and necessary for line following.

For connecting the six lines from the sensor main board to the Uno, you probably will need to solder two headers (rows of pins) to a board in the stack.  Using right-angle headers (see below) will allow the pins to come out of the side of the stack without interfering with other layers of the stack.  One of the headers should let you connect sensor Out1...Out4 digital outputs to four otherwise unused analog or digital pins, and the other header should let you connect Vcc and Gnd.

![6-pin angle header, 0.1" spacing][1]

***Edit 1:*** In the [LCD shield page](http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)), section 2 (Diagram) shows Vcc, Gnd, and D0-D3 available at the top right corner (the angled corner).  Those six pins probably are a reasonable place to add a six-pin angled header for the sensor board.

Given that the LCD KeyPad Shield is a [DFRobot.com](http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)) model, the [summary pinout](http://www.shieldlist.org/dfrobot/lcd) at shieldlist.org shows that its use of D4,5,6,7 will conflict with use of [those same lines](http://www.shieldlist.org/dfrobot/2a-motor) by the DFRobot 2A Motor Shield.  There are several ways to handle a conflict like this:  **1,** use two Uno's, one per shield; **2,** make one shield or the other use different lines; **3,** share the lines.

**Method 2** could work as follows:  Stack the LCD shield directly on the Uno (or any other compatible Arduino).  Besides a header for the sensor board, add a header for a cable to the motor board, and drive the motor board's D4-7 inputs with some other lines from the Uno, eg A4-7.  [Alternately  one could remove the D4-7 pins on the LCD shield and jumper from A4-7 to the D4-7 lines on the LCD shield.  This would leave the boards in a single stack but would make some serious changes to the LCD board.]

**Method 3** would work as follows:  The LCD shield only pays attention to D4-7 (which from the [DFRobot schematic](http://www.dfrobot.com/wiki/images/a/a7/LCDKeypad_Shield_SCH.png) drive DB4-DB7 on an LCD TC1602 chip) when the TC1602's E line is strobed.  See pages 7 and 8 of Adafruit.com's [copy of TC1602 specs](https://www.adafruit.com/datasheets/TC1602A-01T.pdf), where timing diagrams show about half-microsecond times for writing to or reading from the TC1602.

You would need to run tests with your motors and see if they work ok in spite of the four inputs to the motor shield being random during the occasional half-microseconds that data is being written to the LCD.  You might have to add more diodes or capacitors to  suppress electrical noise due to rapid switching.

[DFRobot's motor shield page](http://www.dfrobot.com/index.php?route=product/product&product_id=69) has links to that board's schematic and to its L298 chip data sheet.  Page 7 of the datasheet says
>An external bridge of diodes are required when inductive loads are driven and when the inputs of the IC are chopped; Shottky diodes would be preferred.

The motor shield schematic shows diodes; although not drawn using [Schottky diode](http://en.wikipedia.org/wiki/Schottky_diode) symbols they might be Schottky anyway (which would give better noise suppression, less heating, etc).  The schematic also shows that JP1, a 16-pin dual row header, has jumpers that control ENA and ENB on the L298.  In a "proper solution" for sharing D4-7 between the LCD and motor shields, you'd drive ENA and ENB low when using D4-7 for LCD i/o, which would allow the attached motors to briefly free run, as opposed to being suddenly commanded to stop or reverse.

  [1]: https://i.stack.imgur.com/SEASS.jpg


body:
The most elegant approach would probably be to use shields controlled by the I2C bus. I've found LCD+keypad and [motor shield](https://www.adafruit.com/products/1438) offered by Adafruit for example.

The I2C bus is shared by all slaves connected to it, and you should find microswitches on each shield to set its I2C address.

Regular shields should not interfere with I2C lines, so as last resort you can put one shield controlled "traditional way".


message:
Confusing Arduino Leonardo PWM

I'm having problems with using Arduino Leonardo PWM outputs (I'm actually using YUN board).

I need 4 PWM outputs that generally have the same base frequency of around 10 to 20 Hz or so.

I'm using timer 1 (A-pin-9,B-pin-10,C-pin-11) and timer 4 (A-pin-13)

I get pins 9,10,and 13 PWM output working decent, but for some reason pin 11 PWM frequency is much much higher.

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

Here is my code can anybody see anything wrong? thanks!

        #define PWM_4A_PIN  13
        #define PWM_1C_PIN  11

        #define PWM_1B_PIN  10
        #define PWM_1A_PIN  9

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

        void loop()
        {
        }

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

Unless D11 is configured as OC0A instead of OC1C, which means that it will work off timer 0.

    TCCR0A &= ~(_BV(COM0A1) | _BV(COM0A0));
    TCCR1A |= _BV(COM1C1) | _BV(COM1C0);
     ...
    OCR1C = ...;


message:
Burning sketch with I2C

Not a pure Arduino question really. I'm actually using a standalone ATmega168. So far I've been using AVR-ISP programmer (working from AVR Studio) to program the chip. After everything is done, the chip will be covered and I will only have access to the I2C pins. The MISO,MOSI, etc pins will be unreachable.

I was just wondering if there was a way to use the I2C pins to update the program that is burned on the chip. I won't need to burn the bootloader again, but just to update the program if it needs to be.

body:
You need to write a I2C bootloader to the AVR. There seems to be a [project that has already created such a bootloader](https://code.google.com/p/raspy-juice/wiki/Bootloader).

Atmel has provided a [TWI/I2C bootloader](http://www.atmel.com/ru/ru/Images/doc8435.pdf) for their XMega processors (not the ATmega168).

Next problem is uploading the code via I2C. You'd need some hardware to convert USB  to I2C. And some software to talk to this hardware. The last part is probably supported by AVR studio, as Atmel has provided an I2C bootloader. Though I'm not sure both of the above bootloaders are using a compatible protocol over the I2C.


body: Take a look at [miniboot](https://github.com/mihaigalos/miniboot). I implemented it as a self-contained bootloader. Instructions about uploading from USB to I2C are also provided. Live long and prosper.


message:
Serial input parallel output shift registers with arduino

I need a way to rewrite the switch case part in a more efficient way.

    int y , x ;
    byte dataArray[6];

    void setup () {
       pinMode(8,OUTPUT);
       pinMode(11,OUTPUT);
       pinMode(12,OUTPUT);

       Serial.begin(9600);
       dataArray[0] = 0x3 ; //00000011
       dataArray[1] = 0x5 ; //00000101
       dataArray[2] = 0x9 ; //00001001
       dataArray[3] = 0x11; //00010001
       dataArray[4] = 0x21; //00100001
       dataArray[5] = 0x41; //01000001
    }

    void loop () {
       while (Serial.available()>0) {
         y = Serial.read();
         x = Serial.read();
         switch ( x ) {
         case 1:
            digitalWrite(8,LOW);
            shiftOut(11,12,LSBFIRST,0);
            shiftOut(11,12,LSBFIRST,0);
            shiftOut(11,12,LSBFIRST,0);
            shiftOut(11,12,LSBFIRST,0);
            shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,dataArray[y]);
   digitalWrite(8,HIGH);
   delay(10);
   digitalWrite(8,LOW);
         break;

         case 2:
   digitalWrite(8,LOW);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,dataArray[y]);
   shiftOut(11,12,LSBFIRST,0);
   digitalWrite(8,HIGH);
   delay(10);
   digitalWrite(8,LOW);
         break;

   case 3:
   digitalWrite(8,LOW);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,dataArray[y]);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   digitalWrite(8,HIGH);
   delay(10);
   digitalWrite(8,LOW);
         break;

          case 4:
   digitalWrite(8,LOW);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,dataArray[y]);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   digitalWrite(8,HIGH);
   delay(10);
   digitalWrite(8,LOW);
         break;

          case 5:
            digitalWrite(8,LOW);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,dataArray[y]);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   digitalWrite(8,HIGH);
   delay(10);
   digitalWrite(8,LOW);
         break;

          case 6:
            digitalWrite(8,LOW);
   shiftOut(11,12,LSBFIRST,dataArray[y]);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   digitalWrite(8,HIGH);
   delay(10);
   digitalWrite(8,LOW);
         break;

         default:
            digitalWrite(8,LOW);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   shiftOut(11,12,LSBFIRST,0);
   digitalWrite(8,HIGH);
   delay(10);
   digitalWrite(8,LOW);
         break;
         }
       }
     }

body:
    unsigned char i;

    digitalWrite(8,LOW);
    for(i=0;i<=6;i++){
        if(x+i==6) shiftOut(11,12,LSBFIRST,dataArray[y]);
        else shiftOut(11,12,LSBFIRST,0);
        }
    digitalWrite(8,HIGH);
    delay(10);
    digitalWrite(8,LOW);


message:
8X8 LED not lightning up according to matrix assignment on a Arduino Nano

I'm currently trying to code a simple program that would allow me to light up an individual LED on an 8X8 LED board using a double array.

Here are the problems:

All the rows can ON individually UNTIL I turn all 8 rows ON. When I do this the last column turns OFF by itself (see attached pictures).

The columns aren't even working properly either. Every time I assign a column ON, the last column faintly turns ON too (one of the LEDs light in that column is broken so that is expect to be OFF. See picture).

I think those are the reasons why I am not able to singly assign a particular LED to be ON according to assignments in the array. If someone could spot my mistakes, it would greatly be appreciated. Thanks!

    int led2 = 2;
    int led3 = 3;
    int led4 = 4;
    int led5 = 5;
    int led6 = 6;
    int led7 = 7;
    int led8 = 8;
    int led9 = 9;
    int led10 = 10;
    int led11 = 11;
    int led12 = 12;
    int led13 = 13;
    int led16 = 16;
    int led17 = 17;
    int led18 = 18;
    int led19 = 19;

    int rowPins [8] ={led19, led18, led11, led7, led12, led5, led4, led16};//assigning each LED to a row.
    int columnPins [8] ={led13, led17, led9, led10, led2, led8, led3, led6};//assigning each LED to a column

    int image [8][8]=
    {

    {0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0},

    };

    void setup()
    {
      for (int i = 0; i<8; i++)
      {
          pinMode(rowPins[i], OUTPUT);
          pinMode(columnPins[i], OUTPUT);
      }
    }//end of setup()

    void loop ()
    {
    for (int y=0; y<8; y++)
    {
     for (int x=0; x<8; x++)
     {
       if (image[x][y]==1)
       {
         digitalWrite (columnPins[x], HIGH);
       }
       else
       {
         digitalWrite(columnPins[x], LOW);
       }
     }//end of 2nd for loop

      digitalWrite(rowPins[y], LOW);
      delayMicroseconds(100);
      digitalWrite(rowPins[y], HIGH);
    }//end of first for loop
    }//end of loop

![When all 8 rows are ON the last column turns OFF][1]

![When only 7 rows are ON][2]

![when one column is ON the other is faintly also ON][3]

  [1]: https://i.stack.imgur.com/eax3Z.jpg
  [2]: https://i.stack.imgur.com/G0m3w.jpg
  [3]: https://i.stack.imgur.com/Fc4Kj.jpg

body:
I don't see any program statements in the code as shown to cause the described behavior, and imagine it is some hardware problem.  (I'm assuming you put some non-zero values into the `image[][]` array; it looks to me like nothing should light up when `image[][]` is all-zeroes.)

Hardware problems break into several categories:  A wiring problem (which we can't see without much better pictures); incorrect software setup of HW; temporary misbehavior of the processor; or permanent damage.  For the sake of discussion, suppose temporary misbehavior applies.

Temporary misbehavior can be caused by overheating.  Overheating can be caused by drawing or sinking a lot of current for too long a time.  (If a large current is a fast transient event, it may have little effect.)

Note that most Arduino I/O lines are rated to sink or source at most 40 mA current each.  Ground and Vcc lines have higher limits, like 200 or 100 mA.  For more details see the spec sheet for your processor; also see [ArduinoPinCurrentLimitations](http://playground.arduino.cc/Main/ArduinoPinCurrentLimitations) at arduino.cc, and [Real maximum current for ATmega328?](https://electronics.stackexchange.com/q/17962) on Electronics SE.

If an LED is directly connected to 5V, it is likely to draw several times more current than nominal.  Connecting  an LED directly to an Arduino digital line also will allow it to draw too much current.  Connecting 8 LEDs to a single processor IO line is likely to cause enough overheating to damage the processor permanently.  You may need to add 8 or 16 resistors to your circuit.

Anyhow, instead of trying to debug while using a 100 μs multiplexing delay in your program, and instead of turning on lots of lights at the same time, try turning on one at a time for a brief but visible period each, and see if the array of lights scans ok, via code like the following:

    int rowPins[]    = {19, 18, 11, 7, 12, 5, 4, 16}; //assign row lines
    int columnPins[] = {13, 17, 9, 10,  2, 8, 3,  6}; //assign col lines

    void setup() {
      int i;
      for (i=0; i<8; ++i) {
        pinMode(rowPins[i], OUTPUT);
        digitalWrite(rowPins[i], HIGH);
        pinMode(columnPins[i], OUTPUT);
        digitalWrite(columnPins[i], LOW);
      }
    }
    void loop () {
      int x, y;
      for (y=0; y<8; ++y) {
        digitalWrite(rowPins[y], LOW);
        for (x=0; x<8; ++x)  {
          digitalWrite (columnPins[x], HIGH);
          delay(250);     // wait about .25 seconds
          digitalWrite(columnPins[x], LOW);
        }
        digitalWrite(rowPins[y], HIGH);
      }
    }

If multiple lights are on there may be miswiring on your project board, or the chip might be damaged, or there may be some roundabout leakage path from columns to ground or from rows to Vcc.  If you make the delay longer or add a pushbutton to advance manually, you can check voltages on LEDs and wires, or measure currents in wires, and perhaps deduce what the path is.


message:
Code to use an Arduino Mega 2560 to transfer UART <-> USB to debug an other Microcontroller

I have the following circuit and want to use the Arduino Mega 2560 as an debugger for an other Microcontroller.
![circuit][1]

So I am looking for the code to redirect the UART input from "P17 (RX2)" to the serial USB and the data coming from the serial USB to the output of "P16 (TX2)"

  [1]: https://i.stack.imgur.com/uEZTh.png

body:
A very simple sketch to pass serial through looks like this:

    void setup(){
      Serial1.begin(/*BAUD*/);
      Serial2.begin(/*BAUD*/);
    }

    void loop(){
      if(Serial1.available()){
        Serial2.print((char)Serial1.read());
      }
      if(Serial2.available()){
        Serial1.print((char)Serial2.read());
      }
    }

I would advise both run at the same baud rate, otherwise you may need to do some extra buffering yourself if the arduino starts running out of buffer space. If you want to use the mega's USB connection instead of "Serial1" like your schematic, just switch "Serial1" to "Serial"


message:
Analog Reference and Power Voltage

On the Arduino website it states that the analog pins read voltages from 0 to 5 volts (default) and return a value from 0 to 1023. One can also set the range with analogReference(). However, this is probably assuming the Arduino is running at 5 volts. If one powers the board with, say 4 volts, will the analog reference still be 5 volts default, or changed to the input voltage of 4 volts?

body: Your suspicions are correct. Calling `analogReference()` with a value of `DEFAULT` sets the ADC reference to the voltage at AVCC which at least on the Uno R3 is tied directly to VCC and hence has the same voltage as whatever you're supplying there.


body: There is code published that shows how to read the internal voltage, I use that to correct my A/D readings. It is not perfect but close. You can of course select a lower reference voltage by changing the appropriate registers and use a different reference. This is much safer then supplying an external reference.


message:
Selecting a MOSFET Shield

Im building an electrical system for my EBike.  My bike has 2 power sources, one is the 48 volt battery, the other is a 12 power converter coming off the battery pack.  I need an arduino shield that has 4 switching channels.  2 that can take in the 48 volt and switch it on and off, and two that can take in the 12 volt and switch it on and off.  Something that can take the 12 volt to power the arduino uno would be nice but I can find a chip to do that if necessary.

Since these are lights, normally off would be more more efficient but with the power consumption we are talking about, i can probably run the battery all day to the point of dry and the fets eat all of 50 feet worth of power staying closed.

Does anyone know of anything like that?  I found several shields out there like [this](http://arduino-info.wikispaces.com/Brick-4ChannelPowerFetSwitch) but all of them seem to be setup to take 1 voltage input and switch it between the 4 or 6 fets on the board, not different voltages per fet and since I'm a programmer, not an EE so I have trouble reading the schematics.

Because my grounds have to be tied, its easier to switch the positive on and off than the negative.

body:
You can make your own. Buy a protoshield and 4 fets (and a few resistors).

You can also use the shield you linked to, by not using the `+` terminals on the board. Just connect the `+` of the lights directly to the battery and only the `-` of the light to the shield.

The Uno can be powered by up-to 20V, so you can connect it directly to the battery.


message:
Budgeting Power for 5V Arduino Pro Mini

In my low power project, I'm using a Arduino Pro Mini (5V, 16 MHz, ATMEGA328) and a low wattage 3W power supply. Everything else on the system other than the Arduino uses a max of 1.98W.

How much power should I budget for the Arduino Pro Mini (without any mods, ie: disconnecting the voltage regulator and LED)?

body: Arduino mini, and atmega328 in general use less than 10mA with default arduino code. Turning down unused component (ADC and so on), using deep sleep and optimizing pbc would lover this consumption a lot, in the land of uA


message:
Arduino starter kit servo is shaking

In the example of the arduino starter kit the point is to use a potenciometer to control a servo.

The code is

    angle = map(potVal, 0, 1023, 0, 179);

The output in the serial

    potVal: 1023, angle: 179
    potVal: 1015, angle: 177
    potVal: 1023, angle: 179
    potVal: 1016, angle: 177
    potVal: 1023, angle: 179
    potVal: 1023, angle: 179

I noticed that the servo is shaking like trying to go passing over the 179, when it is suppose to use an angle max 180º (0-179)

What could be the problem?

body:
If the problem is due to jittery pot readings, you may want to smooth the `potval` data sequence by code like the following, where `rawreading` stands for what you just read from the potentiometer's input line.

    potval = alpha*potval + (1-alpha)*rawreading;

Set `alpha` to a number (eg 0.8 or 0.9 or 0.95 etc) between 0 and 1.  `alpha` represents the fraction of the old value that you retain, and  `1-alpha` represents the fractional influence of the new raw reading.   `alpha` closer to 1 causes smoother but slower response.

If you prefer integer arithmetic for faster or smaller code, then represent `alpha` as a ratio of integers.  For example:

    potval = (potval*12 + rawreading)/13;

The technique mentioned above is called *[exponential smoothing](http://en.wikipedia.org/wiki/Exponential_smoothing#The_exponential_moving_average)* or  *exponential moving average*.


body:
I like this method the best (personal preference) for smoothing signals:

    //In setup
    int bufferedVal = analogRead(A0);
    int unbufferedVal = analogRead(A0);
    #define _TOLERANCE_ 5

    //The loop
    unbufferedVal = analogRead(A0);
    if(abs(unbufferedVal - bufferedVal) >= _TOLERANCE_ ) {
      bufferedVal = unbufferedVal;
    }

This finds the error using the `abs()` function (absolute value; makes sure it is positive).

Another thing you can do is round it to the tenth placeholder (i.e. 88 -> 90, 83 -> 80) so it always is a good number to work with:

    int val = analogRead(A0);
    val += 5;
    val = val / 10;
    val = val * 10;

The last two lines work because of the lack of precision that integers offer with decimals. If I divide 88 by 10, it doesn't output 8.8; it outputs 8 instead. We then multiply by ten again so it isn't 8 when it really should be 80. The only problem with this is it only rounds down. We can fix this by adding 5 (the halfway point between 10 and 0). That way, it goes: 88 to 93 to 9.3 to 9 to 90.

**NOTE:** I'm not sure if the compiler will notice the redundancy of the last two lines. If it acts weird, try using the `volatile` keyword.


body:
Since the previous answers were all code-related, let me suggest you use a smoothing capacitor. In noisy environments, or where you want to get more consistent readings, place a capacitor across your signal lines (signal to ground). The result is less "spikes" in your readings, and can sometimes cause a slight delay in signal changes, as charge has to build up in the capacitor before the voltage goes up.

http://www.learningaboutelectronics.com/Articles/What-is-a-smoothing-capacitor


message:
Problem connecting Arduino Uno with Wifi and NFC

I'm new here and also new to Arduino.

I've got a rather specific problem and I've posted to the official Forum
on arduino.cc two days ago ([original Post][1])

Sadly, I've yet to recieve any help and since it's a project for work, theres a (loose) schedule. So I've decided to post it here as well.

If you have some ideas, it'd be really great!

Also, if I've posted this question without acknowleding some forum rules please tell me so that I can write better posts in the future ;-)

Regards,

Patrick

**Edit:**
The original Posts as Text :-)

**Post # 1**

Hello Guys,

this is my first time posting in the forum since I'm new to Arduino, so please be kind  smiley-wink.
Me and a colleague of mine have been given a Project to create with arduino hardware.

The Project is, that you should be able to read NFC tags with the arduino
and send them to a server to be checked and eventually being written into a db.

The hardware:
Arduino Uno R3 (funduino.de/index.php/shop/product/view/2/4)
Adafruit CC3000 (www.adafruit.com/products/1469)
Adafruit PN532 (www.adafruit.com/products/789)
Stepper Motor (not yet included and not relevant for the problem)

Sorry about not using hyperlinks, but the forum says I'm not allowed to post more than 2 links at once...

Now on to the Problem:
When we're using the shields separately (meaning connecting the arduino to either of the shields by itself), the shields work fine. The cc3000 gets a connection and the PN532 reads cards.
Now we've tried to stack them together for live use. That's where the trouble starts...

If I connect the PN532 5V to the arduino 3.3V
and CC3000 VIN to 5V arduino,
the shields both do what they should with separate example sketches ('readMifare' and 'buildTest').

If I put my sketch in (which combines both of those sketches and some other stuff)
and comment out the initialization of either the PN532 or the CC3000, the other shield works.

Now if I try to use both, the CC3000 and the PN532,
the CC3000 tries to initialize, but falls into a loop of restarts.
I've read that that (possibly) is because of the lack of power supply.
(I've connected a 12V wall-wart by the way and it didn't work with that either)

The manual says, that the CC3000 needs 5V, but can work on 3.3V too (though I didn't find a source to explain how)
and the PN532 needs 3.3V to run.

Am I doing something wrong, or is it a problem with the arduino?
If I'm doing it wrong, how am I connecting these parts correctly?

I really am not that good with electronics and didn't find a sollution to my problem nearly a days worth of searching the net.
For your understanding I'll post the script I'm using and some pictures of the board setup.
Thanks in advance for ANY help you guys can give me (even if it's just  good guide for problems like mine) ^^

Regards,
Patrick

The part of the sketch that initializes the components (and also where the CC3000 gets stuck...)
Code:

    //WLAN-Libraries
    #include <Adafruit_CC3000.h>
    #include <ccspi.h>
    #include <SPI.h>
    #include <string.h>
    #include "utility/debug.h"

    //NFC-Libraries
    #include <Wire.h>
    #include <Adafruit_NFCShield_I2C.h>

    //Motor-Libraries
    #include <Stepper.h>

    //NFC-shield PINs
    #define IRQ   (2)
    #define RESET (4)  // Not connected by default on the NFC Shield

    Adafruit_NFCShield_I2C nfc(IRQ, RESET);

  //Motor-settings

    const int stepsPerRevolution = 180;  // change this to fit the number of steps per revolution
                                         // for your motor

    Stepper Motor(stepsPerRevolution, 6,7,8,9);  // initialize the stepper library on pins 8 through 11:

  //Wifi-settings

    // These are the interrupt and control pins
    #define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
    // These can be any two pins
    #define ADAFRUIT_CC3000_VBAT  5
    #define ADAFRUIT_CC3000_CS    10
    // Use hardware SPI for the remaining pins
    // On an UNO, SCK = 13, MISO = 12, and MOSI = 11
    Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                             SPI_CLOCK_DIV2); // you can change this clock speed

    #define WLAN_SSID       "mySSID"           // changed for your convenience
    #define WLAN_PASS       "myPassphrase"
    // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
    #define WLAN_SECURITY   WLAN_SEC_WPA2

    Adafruit_CC3000_Client www;  //defines how we will refer to the cc3000 connection object

    // What page to grab!
    #define WEBSITE      "10.2.10.170"  //NOTE: CC3000 doesn't seem to like the default localhost address of 127.0.0.1 - need to enter actual IP
    #define WEBPAGE     "/index.php"

    //this is the counter that will be used for uploading data
    long pollCounter = 1;

    //used for storing data for upload
    //set it to the data type that suits your data
    int
      NFC_ID, Session_ID, UID_final;

    //used for commands received from base station
    int
      command_open, command_close;

      boolean pollFlag = false;         //tells the sketch whether to poll or not

    //declare a variable to hold a numeric IP address
    //can be overridden below if you use lookup
      uint32_t ip = (192L << 24) | (168L<<16) | (1<<8) | 13;

    /**************************************************************************/
    /*!
        @brief  Initialization of the modules (Motor, Wifi, NFC-Reader)
    */
    /**************************************************************************/

    void setup(void)
    {
  //Set up the Motor for the lock

      // set the Motor speed at 60 rpm:
      Motor.setSpeed(60);

  //Set up the Wifi module

      Serial.begin(115200);
      Serial.println(F("Hello, CC3000!\n"));

      Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);

      /* Initialize the Wifi module */
      Serial.println(F("\nInitializing..."));                 //<======== Here the CC3000 gets stuck in a loop
      if (!cc3000.begin())                                          //                          when both shields are connected
        {
          Serial.println(F("Couldn't begin()! Check your wiring?"));
          while(1);
        }

      cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);

      Serial.println(F("Connected!"));

      /* Wait for DHCP to complete */
      Serial.println(F("Request DHCP"));
      while (!cc3000.checkDHCP())
        {
          delay(100); // ToDo: Insert a DHCP timeout!
        }

      /* Display the IP address DNS, Gateway, etc. */
      while (! displayConnectionDetails())
        {
          delay(1000);
        }

      cc3000.printIPdotsRev(ip);

  //Set up the NFC module
      if (pollFlag == true)
      {
            nfc.begin();

            uint32_t versiondata = nfc.getFirmwareVersion();
            if (! versiondata) {
              Serial.print("Didn't find PN53x board");
              while (1); // halt
            }
            // Got ok data, print it out!
            Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
            Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
            Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);

            // configure board to read RFID tags
            nfc.SAMConfig();

            Serial.println("Waiting for an ISO14443A Card ...");
      }
      else {
         Serial.println("Failed to initialize NFC-Reader... Sorry...");
      }

      }

Hope I'm not messing up the image-uploads...
(I kept the wiring-colors where I coul for you to see the connections easily)

The boards connected via cables (both separately working)
www.directupload.net/file/d/3740/j3y3tx38_jpg.htm

The boards put together
www.directupload.net/file/d/3740/yb9q6qla_jpg.htm

The boards connected together with the Wifi in the picture.
(You can't see the LED on the CC3000 light up, but I swear it does  smiley-wink)
www.directupload.net/file/d/3740/uorksjrj_jpg.htm

**Post # 2**

Ok, I got myself a multimeter today to measure if it is really a problem with the power supply.

With the NFC-Reader running I measured 4.85V on the 5V-Pin and 3.32V on the 3.3V-Pin.
This means, that the CC3000 should have enough Power to run.

So I'm now looking for a possible address collision in the libraries (specifically I2C- and SPI-collisions). As I'm still new to this, help is really appreciated.

**Edit #2:**

Morning everyone!
What I've found out since yesterday is, that the PN532 uses I2C while the CC3000 uses SPI to communicate. When I looked through the libraries I found out that the PN532 includes Wire.h which gets its address at "nfc.begin();"

In the begin-function in Wire.cpp there is an address transmitted to the function, but I can't find it's source. Is it possible that that address collides with the one the CC3000 uses?

When I uploaded an I2C-Scanner to the UNO, it said that the only device fount is the PN532 on address '0x24'.

I don't really know what to do with that info though, since there are more libraries being included (like <string.h> which in term calls others) and I cant even find these on the Mac I'm working on at the moment...

**Edit #3:**

The problem has been solved in the arduino.cc forum. The SRAM was overflowing, but applying the F()-macro to the strings being printed solved the issue!
(Just in case someone has similar issues ^^)
  [1]: http://forum.arduino.cc/index.php?topic=265800.0


message:
Not able to send SMS to Mobile using GSM900A and Arduino Uno

I tried the code shown below ([found here](http://letsplaywitharduino.blogspot.in/p/gsm-modem-with-arduino-uno.html))

    void setup()
    {
      Serial.begin(9600);  //Baud rate of the GSM/GPRS Module
      Serial.print("\r");
      delay(1000);
      Serial.print("AT+CMGF=1\r");
      delay(1000);
      Serial.print("AT+CMGS=\"+919449835011\"\r");    //Number to which you want to send the sms
      delay(1000);
      Serial.print("Test SMS -Jay\r");   //The text of the message to be sent
      delay(1000);
      Serial.write(0x1A);
      delay(1000);
    }
    void loop()
    {
    }

I interfaced my GSM SIM900A module to the Arduino UNO (connections - GSM Tx to Arduino Rx, GSM Rx to Arduino Tx, GSM provided with supply (12V) using external adapter, GSM gnd to Arduino gnd).

I dumped the code into Arduino and then opened the Arduino IDE serial terminal. In the serial terminal, I get `AT+CMGF=1AT+CMGS="+919449835011"Test SMS -Jay\r` being displayed and I am not receiving any sms to my phone. I am not sure if its a problem with the code or connections.

body:
looks like you should be using `Serial.begin(2400);`

also, I'm assuming your sms phone number isn't actually 919449835011 and that that's not actually the number you used in your code


message:
Sine Wave Inverter

I am working on building a pure sine wave inverter using an Arduino Uno to output two PWM signals for the top and bottom half of the wave. Currently I am outputting pre-calculated values with an interrupt as PWM. This seems to be working but I was wondering if anyone had any feedback on my design, and whether there is a better way to go about doing this. I will also need to incorporate feedback into this to vary the max PWM duty cycle, and I am worried the ATMEGA will not be able to keep up do this fast enough.

Please let me know if you want any more details, thanks in advance!

Olls

The [spreadsheet](https://docs.google.com/spreadsheets/d/1iyveHnOxIzqg907T6pu4znsJE-6tg40juMihDvU8Tbg/edit?usp=sharing) I'm using to calculate the values.

    #include "TimerOne.h"

    int duty_cycle;
    int x = 0;

    // sin_table is made up of sin(0-400) values multiplied by PWM_PERIOD
    // https://docs.google.com/spreadsheets/d/1iyveHnOxIzqg907T6pu4znsJE-6tg40juMihDvU8Tbg/edit?usp=sharing
    uint8_t _sin[] = { // Calculated for 50Hz at 200 pulses per half wave.
        0,0,0,1,1,1,2,2,3,3,3,4,4,5,5,5,6,6,6,7,7,8,8,8,9,9,9,10,10,10,11,11,12,12,12,13,13,13,14,14,14,15,15,15,15,16,16,16,17,17,17,17,18,18,18,19,19,19,19,19,20,20,20,20,21,21,21,21,21,22,22,22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,23,23,23,23,23,23,23,22,22,22,22,22,22,21,21,21,21,21,20,20,20,20,19,19,19,19,19,18,18,18,17,17,17,17,16,16,16,15,15,15,15,14,14,14,13,13,13,12,12,12,11,11,10,10,10,9,9,9,8,8,8,7,7,6,6,6,5,5,5,4,4,3,3,3,2,2,1,1,1,0,0,0,0,0,1,1,1,2,2,3,3,3,4,4,5,5,5,6,6,6,7,7,8,8,8,9,9,9,10,10,10,11,11,12,12,12,13,13,13,14,14,14,15,15,15,15,16,16,16,17,17,17,17,18,18,18,19,19,19,19,19,20,20,20,20,21,21,21,21,21,22,22,22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,23,23,23,23,23,23,23,22,22,22,22,22,22,21,21,21,21,21,20,20,20,20,19,19,19,19,19,18,18,18,17,17,17,17,16,16,16,15,15,15,15,14,14,14,13,13,13,12,12,12,11,11,10,10,10,9,9,9,8,8,8,7,7,6,6,6,5,5,5,4,4,3,3,3,2,2,1,1,1,0,0,0
    };

    void setup() {
     // Pin mode, and set low.
     DDRD = DDRD | B00011000;
     PORTD = B00000000;

     Timer1.initialize(47);
     Timer1.attachInterrupt(pwm);
    }

    void pwm() {
     if (PIND & B00000100) { // Inhibit switch

      // Lower half or upper half of wave, start PWM pulse
      if (x > 200) {
       PORTD = B00010000;
      } else {
       PORTD = B00001000;
      }

      duty_cycle = _sin[x];
      if (duty_cycle > 3) {
       delayMicroseconds(duty_cycle);
      }

      PORTD = B00000000;

      x++;
      if (x > 400) {
       x = 0;
      }
     }
    }

    void loop() {}

body:
*Comment by olls converted to an answer*:

I did get it working. The schematic isn't mine to share unfortunately, but it consisted of some transistors to shift the PWM up to 20v, which then went into an inverter circuit (not made by me, quite complex) which merged the two PWM signals together into a AC signal. Then there was a transformer and RC filter to smooth out and amplify the PWM. Sorry I can't be more help, but it was a while ago, and I didn't make all of it.


message:
When I connect the Vcc and GND of my circuit to my Arduino, it is powered off?

When I connect the Vcc and GND of my circuit to the 5v and GND in my Arduino, it is powered off and stops working. What is the reason and how shall I fix it?

![enter image description here][1]

Reference: [Serial to Parallel Shifting-Out with a 74HC595](https://www.arduino.cc/en/Tutorial/ShiftOut)

  [1]: https://i.stack.imgur.com/18eHM.gif

body:
Note: if you are changing something have the power off.

The first thing to try is unplug the IC. If it powers up after the IC is removed it is Possibly the IC is bad; However measure the Voltages on the proto board where the IC is inserted, be sure Pin 16 is +5V when referenced to pin 8.  Check the data sheet for the correct pinout, I do not know what IC you are using. If the voltage is correct it is pointing more to a bad IC.

The final check for the IC is to insert the IC and remove the ground lead to the LEDs.  If the system comes up then the problem is not enough power to drive the LEDs as is. If it does not come up replace the IC.  Even a momentary reverse voltage or a ESD (Electro Static Discharge) incident will damage the IC, we know is is going to fail, we do not know when.

Be sure your resistors are at least 300 Ohm or higher, with that resistance the LEDs when all on will draw a total of 80mA. If you want to do the calculations try this link: "http://www.onlineconversion.com/ohms_law.htm".

If you want to check the LEDs, remove the IC and connect +5V one at a time to the wire that goes to the resistor from the IC.
Good Luck,
Gil


message:
Switch 230V 50Hz using a digital out pin

I would like to control normal household appliances like lamps, pumps etc. using my Arduino with up to 5 A. I looked a little around, but it seems, that most relais draw more current than the Arduino is capable of supplying.

How can I switch an 230 V AC current using my Arduino?

body:
Get a logic level n-channel MOSFET that is rated for your relay's voltage and current requirements, and an external DC power supply that's able to put out enough current to drive the relay. Feed the power supply into the relay coil. Connect the ground of the coil to the drain of the MOSFET. Connect the source of the MOSFET to ground. Connect the MOSFET gate to your Arduino control pin.

You might be able to find a relay that will run on 5V at low enough current that you can drive it with a MOSFET and the 5V out from your Arduino, but make sure you don't exceed the total current limit of your Arduino's regulator.

Make sure you put a flyback protection diode in parallel with your relay coil, pointing to block the normal flow of current through the coil, so you don't fry your transistor.

Alternatively you can buy solid state relays that can switch large AC loads using logic level signals, but they're expensive.


body:
The good advice to people asking how to drive a relay to control mains voltage is: **don't**.

Start with a complete solution such as those from PowerswitchTail.com and sold by many places:  [Powerswitch Tail][1]

You can get these already built or in kit form.  The 20 $ price is small price compared to damage to people or home you might incur with a home built solution.

  [1]: http://www.powerswitchtail.com/Pages/PowerSwitchTail240vackit.aspx


message:
Receiving and sending on the Arduino Duemilanove with an MAX3232 chip

I have a [max3232](http://datasheets.maximintegrated.com/en/ds/MAX3222-MAX3241.pdf) hooked up to the RX and TX pins of the Arduino Due.  I'm trying to write a simple program to relay messages received from USB and output as RS232 through the chip.  Here is my code:

    char readbyte;

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

    void loop(){

      while (Serial.available() > 0 ) {
        readbyte = Serial.read();
        Serial.print(readbyte);
      }
    }

This program works when I don't have the MAX2323 hooked up (e.g. I send "123" and get "123" echoed back), but when I hook up the MAX2323, the Arduino isn't sending back.  I've written another test program that sends random data and it seems to work fine.  I'm at a lost at what is wrong with my simple program, can anyone help?

Here is the schematic:
![Circuit][1]

  [1]: https://i.stack.imgur.com/PY27U.png

body:
With your final comment, the behavior is understandable.  The schematic will help

![enter image description here][1]

You have wired two devices to the single UART on the processor.

The TX pin (output) on the ATMEGA8 is connected to the input pins of both your MAX2323 and the FT232 chip on the Ardiuno.  That works okay because 1 output pin can easily drive 2 inputs.

The RX pin (input) on the ATMEGA8 is connected to the **output** pins of both your MAX and FT.  The two transceivers are both attempting to drive the single input -- this is a bad thing.  When one output pin tries to drive logic 1 and the other is driving logic 0, one of the devices will win and one will lose.  Whether any of the devices is physically damaged depends on whether one device can source enough current to damage the other.

But you haven't broken anything because of the wise series resistors, R8, you see on the schematic.  The series resistor limits the current to 5 mA even if you short the RX pin to ground.  The series resistor is what creates the unequal behavior:

 - The ability of the FT chip to source current and drive a logic 1 is limited. So when the FT chip tries to drive logic 1 and the MAX is output 0, a 5 V drop will be seen across R8.  The RX pin is on the MAX side, so the Arduino sees 0.

 - The MAX chip is not limited.  When it drives 1 and the FT is at 0 there is still 5 V across the resistor.  But the RX pin is on the MAX side and sees the 1's (data).

If you want the Arduino to receive from two devices you need to "add" the data correctly with a circuit.  There are several ways, here are two:

 - Use an OR gate to combine the data.  The serial bus is idle at zero.  When data comes across it is a sequence of 1 bits.  Remove R8 and connect the M8RXD side to the OR input.  Connect the MAX to the other OR input.  Connect the OR output to the RX input.

 - Cheap and small is "wire or'd".  Remove R8 and replace with small diode, pointing at RX.  Connect small pull down resistor (10k) from RX to ground.  Connect external MAX with diode pointing at RX.  In this arrangement, either chip will source current towards the RX ping to drive a logic 1, but neither chip can sink current to drive the logic 0.  Only the pull down resistor creates the 0.

  [1]: https://i.stack.imgur.com/S0xch.jpg


message:
Powering motors

I'm trying to control two DC 3-6V motors with a HG7881 driver and an Arduino Nano, but the Nano is always resetting if it has the same power supply than the driver. I'm connecting the batteries to HG7881 Vcc and Nano Vin (and also same ground).

If I power the Nano with USB and the driver with batteries then it works but that's not a good solution for me.

So the question is, is there any way to make both driver and Nano work with the same power supply?

Thanks!

body:
You need to know the peak current demands of your motor circuit before you can solve this problem. If you have a digital multimeter you can measure the constant current, and make a guess at the peak current. Put your multimeter in series with the motor driver and operate it at full power. The peak current may be as high as twice the steady current of the running motor. Also check the current with the motor under heavy load.

Then you need a power supply that can put out that much current, plus the current of your Arduino, without the voltage dropping below the minimum requirement for the Arduino voltage regulator (~7 volts).

What kind of batteries are you using? If you put 6 C cells in series you'll get 9 volts and pretty high peak current.


body:
If the reset is due to transients when the motor starts or stops, you can get by with isolating Nano power via a diode and capacitor.  (See below.)  If, on the other hand, the motor is dragging the supply voltage so low the Nano won't run, you may need to add a separate battery for the Nano or upgrade your batteries, as mentioned in Duncan's answer.

To isolate Nano power from motor power, open the connection between battery V+ and Nano Vcc; connect the anode of a diode to V+; connect the cathode to the positive lead of a capacitor of a few hundred microfarads and to Nano Vcc.  Connect the capacitor's negative lead to ground.  If simple diode+capacitor filtering isn't enough, you probably should attach an oscilloscope and find out more exactly what's happening.  Further options include series resistors, wound inductors, and ferrite beads, as seen in some [Google images](https://www.google.com/search?q=power+supply+filtering&biw=1140&bih=640&tbm=isch&tbo=u&source=univ&sa=X&ei=xxMTVM-0K4nGiwLW34GoBQ&sqi=2&ved=0CDQQsAQ) for power supply filtering.


message:
How to power IR LEDs with arduino?

I need a circuit or something to power up IR leds as arduino only give 5v and IR leds needs 1.2V. Is there a way to make one arduino pin a power supply of 1.2 V code or something ?

body:
Typically, rational control of an LED sets the amount of current that goes through the LED, rather than setting its voltage.  You could add series resistors so that when the desired current is flowing through the LED, about 1.2 volts is across the LED and the rest (say 3.6–3.8V) is across the resistor.  (See [Google images](https://www.google.com/search?q=power+supply+filtering&biw=1140&bih=640&tbm=isch&tbo=u&source=univ&sa=X&ei=xxMTVM-0K4nGiwLW34GoBQ&sqi=2&ved=0CDQQsAQ#tbm=isch&q=Arduino+LED+series+resistor) for typical circuits, and see various [LED resistor](https://www.google.com/?gws_rd=ssl#q=arduino+led+resistor+calculator) calculator, eg the [LED resistor calculator](http://www.hacktronics.com/Tools/led-resistor-calculator.html) at hacktronics.com.)  It also is possible to use PWM to control LED brightness.

Note that if you have 3.6V across a resistor and 1.2V across an LED, you are wasting 3/4 of the power expended.  When LEDs are low voltage (ie, like 1.2V for your LEDs, vs. 1.6 for typical red or orange LEDs, vs 3+ V for white or blue) you can put several of them in series.  For example, put three of your IR LEDs in series, and calculate R so that 1.2 V drops across a resistor and 3.6 across the series of LEDs.  Also try four LEDs in series, and calculate R to drop 0.1 to 0.3 V.

***Edit 1:*** Ignacio Vazquez-Abrams says, a little  obscurely, “Getting warmer. But this is a IR LED” and also “Pull up the datasheet for a IR LED. Read it carefully. The AVR can't handle one of the numbers”, perhaps in reference to IR LED current requirements.

Typical 5mm IR LEDs can handle several times more current than typical 5mm visible light LEDs.  For example, a typical green LED might be rated 30 mA max sustained current and 20 mA recommended, while a typical IR LED might be rated 100 mA max and 50 mA recommended.  Also note that 50 mA is 10 mA more than the 40 mA that most Arduino pins list as absolute max.  A sustained current of 40 mA or more in or out of an Arduino i/o pin may damage the processor.  If you want to drive a high-current IR LED, use an external driver (eg a transistor).  See eg the answer to [How can I efficiently drive an LED?](https://electronics.stackexchange.com/q/55823) in Electronics SE, which shows dropping resistor calculations, constant current sources, etc. Also see links given in [JYelton's answer](https://electronics.stackexchange.com/a/56133/7479) to  [Infra Red LEDs - Voltage Advice](https://electronics.stackexchange.com/q/56131).

Treesrule14 points out “IR leds ... don't emit in the visible light range”, which is true; they emit infrared radiation, or heat.  Note, using an IR LED in a remote control usually is incompatible with controlling its average brightness with PWM; the pulses used in PWM would conflict with the pulse train in typical [36, 38, or 40 KHz IR control protocols](http://en.wikipedia.org/wiki/RC-5).


message:
Connecting arduino to a PC

How would you send data wirelessly from arduino uno to a pc?

I know you can connect wifi shield / wifi breakout to arduino and use that, but what other ways are there and how practical would they be?

body:
You have several options. One is Bluetooth and another is [nRF24L01+ 2.4GHz Wireless Transceiver][1]. I love the `nRF24L01+`. They are cheap and there are tons of examples online.

The concept with the `nRF24L01+` is to connect the RF24 to a Ft232rl Ftdi Usb to Ttl Serial Adapter. The Ft232rl  connects to your PC. Most modern computer languages support communicating via Serial. This is the way to go.

Google around for a ton of tutorials

  [1]: https://raspberrypi.stackexchange.com/a/22460/13281


message:
Is it ok to share the same power rail for the arduino and a shield?

I have a two amp 5VDC power rail.  I have configured a motor shield to use external DC (by moving a jumper.)  Is it ok to share the rail between the arduino's 5V and Gnd pins, and the motor shield?

body: Yes, but I wouldn't try to do it through the 5V pin on the Arduino. Run a separate 18AWG or larger wire to bring power and ground to the shield.


body:
the Vin pin on the Arduino is the source to the internal voltage regulator. It needs about 7 volts in order to work. If you try to feed 5V into the Vin then the Arduino won't get a full 5V.

Motors draw a lot of current, and cause transients on the power line as they switch on and off. (They will cause transients even in a regulated supply, because it takes the regulator time to respond to the rapidly changing load of the motor.) If you're going to feed both your motor shield and the Arduino's 5V from the same power supply, you will need a reservoir capacitor between 5V and ground as close to the Arduino 5V input as possible. The reservoir capacitor will even out drops and spikes in power to the Arduino.

You'd be much better off feeding 7-9V into the Arduino's Vin. That way it's power is regulated separately.


message:
Using VirtualWire and RCSwitch in same PRoject

I have the problem, that I want some Arduinos communicate in a wireless mesh network using the VirtualWire library but also be able to receive (and send) codes for my rc sockets using the RCSwitch library.

I have some Arduinos using VirtualWire and some devices using the hx2262 IC for RC-Decoding.

I want to send and receive messages between the Arduinos (each message must be at least 10 bytes long) and also be able to send and receive messages from the hx2262 RC power sockets.

My idea would be to use VirtualWire for inter Arduino communication and RCSwitch for the power sockets. Both work fine as long as I do not put both libraries on the same controller.

Does anyone have an idea to solve that problem?

body: I finally found a solution: Just use both libraries. The problem I head: VirtualWire uses Pin numbering, RCSwitch uses Interrupt numbering. That was the reason, why it did not work.


message:
Bluetooth HC-05 module returns encoded data

I have searched online, and haven't found anyone hitting this issue. Strangely my Bluetooth HC-05 is returning encoded data. I have tried using different boards - Induing, Uno, Freeduino and I have the same problem with them all.

The Bluetooth module I am using is a [HC-05 Bluetooth Module][1].

When I pass 'AT' command, I expect the return to be 'OK'. I get data as

    CF  A7  86  85

This is 8-bit data, and if I drop the MSB I would be:

    4F  27  06  05

Instead I should have received:

    4F  4B  0D  0A

I looked at the binary pattern to understand if this is something like 7 bit encoding used in GSM.

    Actual Data
    CF       A7       86       85
    11001111 10100111 10000110 10000101

    Expected Data
    4F  4B  0D  0A
    01001111 01001011 00001101 00001010

I have tried other AT commands and everything appears to be encoded.

The code I have written is pretty standard, module is blinking at 2 sec pulse (in command mode). I get encoded output for all AT commands. I even tried ORGL, INIT and other commands as suggested on various discussion threads.

    #include <SoftwareSerial.h>

    SoftwareSerial BtDongle = SoftwareSerial(10, 11);

    void setup() {
      digitalWrite(9, LOW);
      delay(100);
      digitalWrite(9, HIGH);
      delay(100);
      Serial.begin(9600);
      Serial.write("AT Command: \n\n");
      BtDongle.begin(38400);
    }

    void loop() {
      while(BtDongle.available()) {
        unsigned char data = BtDongle.read();
        Serial.println(data, HEX);
      }

      while(Serial.available()) {
        char data = Serial.read();
        Serial.print(data);
        BtDongle.print(data);
      }
    }

  [1]: https://www.fabtolab.com/radio/bluetooth/HC-05-bluetooth-module-6-pin

body:
Use a scope to check levels on the TX of the BT module. Some HC-xx modules come with 3.3V levels which can make problems.

I would suggest using the same speed for the serial port and for the bt dongle. You have a glitch here, which may make problems:

    while(BtDongle.available()) {
      unsigned char data = BtDongle.read();
      Serial.println(data, HEX);
    }

Eventually, the Bluetooth module sends you data at a high bit rate. You get the first letter, then send it out to the PC at a lower bit rate. Sending it out to the PC takes as long time as the BT dongle sends four more characters.

Although there are serial buffers in the Arduino, this problem will easily cause a loss of data, as @Avamander has pointed out.

Based on your comment telling that you were able to get an endless mess from Putty, this can escalate to losing the sync on the RX from the BT module, and then further bits will start a new byte, giving you a total mess. However, OK must work, so you likely have also level problems.