text:
Digital Potentiometer and Motor Speed Controller
I'm trying to get a Chinese 20A DC Motor Speed Controller working with a MCP42100 Digital Potentiometer. The analogue potentiometer supplied was 100kOhm. I have programmed my arduino with the following code:
#define DATAOUT     11
#define DATAIN      12       //not used
#define SPICLOCK    13
#define SLAVESELECT 10
#define NOTEON      9
int potValue = 255;
float potInputValue;

void SPIInitialize()
{
  byte clr;
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK, OUTPUT);
  pinMode(SLAVESELECT, OUTPUT);

  digitalWrite(SLAVESELECT, HIGH); //disable device

  SPCR = (1 << SPE) | (1 << MSTR);
  clr = SPSR;
  clr = SPDR;
  delay(10);
}

char SPITransfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1 << SPIF)))   // Wait the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}

//--- MCP42100 code

byte SetPot(int address, int value)
{
  // Slave Select set low to allow commands
  digitalWrite(SLAVESELECT, LOW);

  // 2 byte command
  SPITransfer(0x10 + address);   // 0x10 = 'set pot' command
  SPITransfer(value);            // Value to set pot

  // Release chip, signal end transfer
  digitalWrite(SLAVESELECT, HIGH);
}

//--- Application code

void setup()
{
  SPIInitialize();          // Initialize the SPI interface

  Serial.begin(9600);
  delay(25);
  Serial.println("Type a resistance between 0-100 kOhms above.");
}

void loop()
{
  if (Serial.available() > 0) {
    // read the incoming byte:
    potInputValue = Serial.parseInt();
    float potValue = (potInputValue / 100.0) * 255;
    Serial.print("Value: ");
    Serial.print(potValue);
    Serial.print(", Resistance: ");
    Serial.print(potInputValue);
    Serial.println(" kOhms");
    SetPot(1, potValue);
  }

}

Here is a picture of my setup:
Currently at a resistance of 0 kOhms the motor runs at full speed, as it should do and this is how it reacts with the analogue potentiometer. At a resistance of 100 kOhms, the motor (in this case a computer fan) still has enough juice to spin, until I stop it with my finger, but then it doesn't spin without a little push. With the analogue potentiometer, at 100 kOhms the motor received no juice to spin.
Here is a link to the speed controller: http://www.ebay.co.uk/itm/301366805277?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
The speed controller appears to use a 555 timer.
What am I doing wrong with the digital potentiometer to make it so it doesn't behave the same way as the analogue potentiometer?

You haven't told us anything about the motor controller or what sort of inputs it expects, or given us a schematic, so I don't see how anyone could really answer this.

I'd suggest using a motor driver board that was explicitly designed to be interfaced with from a MCU - rather than trying to jury-rig this one. Alternately, you could use a DAC on the middle wire of the potentiomter, instead of trying to use a digipot.

The MCP42100 does not appear to be an appropriate digital pot for this application.
Without a schematic of the motor controller it is hard to tell, but a good guess would be that the digital pot is seeing voltages higher than the supply voltage you are feeding it, and higher than the maximum supply voltage of the digital pot (5.5V; 7.0V abs max). I don't see a voltage regulator on the motor controller board, nor would one be necessary for a low-end design. Probably just a PWM using a 555, as you say.
To make this work you probably need a different type of digital pot - one that can accept logic level inputs and has a higher supply voltage (12V + some margin). You also typically actually have to feed it the higher supply voltage (and be careful that nothing shorts and ruins the micro board).
Otherwise the input protection networks on the digital pot conducts more current than you would expect.

I'm not sure such a digipot exists, and a DAC is probably a better choice anyway.

Hi, @NickJohnson. I don't think a DAC (other than maybe a 4-quadrant multiplying DAC that can accept a 12V reference) will work. This kind of circuit generally uses the pot resistance to actively charge and discharge a capacitor- it does not simply accept a control voltage. Such digital pots certainly exist (eg. AD5290) and there are others from AD and Maxim.

If you look at the MCP42100 data sheet http://www.microchip.com/, on page 4 you will see the details for your unit. Notice that the actual resistance will be in the range of 70k to 130k.
So the reason that you are getting different results is (probably) due to your having a digital pot with a resistance somewhat lower than the physical pot you used.

Measuring the digital potentiometer with a multimeter reads a value between 0 to 100kOhms

What, exactly does the multimeter measure on the digital pot at 100%, and what, exactly does the multimeter measure on the physical pot at 100%?

The analogue reads 0Ohms at minimum and ~104kOhms at maximum. The digital potentiometer reads ~0.01kOhms at minimum and ~103.7kOhms at maximum.


text:
Using arduino IDE with USBasp
I'm trying to upload a Blink example from Arduino IDE to an atmega8a via USBasp. I have edited the boards.txt file with the specifications of the atmega8a, and I am using the "Upload with programmer" option.
AVRdude gives no errors, only a warning that my usbasp firmware needs an update. I assume the code is uploaded, but it does not execute. My fuse settings are hfuse - 0xc0, lfuse - 0x9f, but i have tried different ones to no avail.

Are the libraries you're using compatible with the 8a, and are you compiling for the 8a? You can't just upload Arduino code to an arbitrary AVR without making sure the toolchain supports it first.

I selected a board i have previously added to Arduino IDE.

Since Arduino doesn't support atmega8a by default, it would help if you told us what board that is in the question, then.

Sorry, couldn't answer earlier, but  I still hope for a reply. Currently, I've set it up in Arduino IDE 1.6.5 using board Arduino NG with atmega8 selected as processor. I already spent quite a lot of time playing with the board setting in boards.txt, but there could have been something I've missed.

source: Stack Exchange

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

sort: votes


text:
Arduino Due for camera control?
Could one use the Arduino Due to control camera module like OV5642 and send the data to spi device? My project is to capture image with OV5642 and then to send the image data(RGB565) to other device via spi. For this STM32 must be enough, but I'd be happy if I can use the arduino IDE. Because it is much easier to program.
Could you please let me know, if you can use the Due for this task?

The DUE doesn't have lots of memory. Depending on what you want to do, that might also be a constraint. You should detail more what you want to do.

What I want to do is to take a bayer-raw image data from OV5642 camera module and then send the data to beagle bone black or whatever via spi. If it is needed, I can use frame buffer or RAM.

Why not connect the camera directly to the BBB?

http://stackoverflow.com/questions/23860620/interfacing-with-a-custom-camera-in-linux-on-the-beaglebone

yep, the arduino seems to be totally redundant in this scenario.

ah... I didn't want this situation. Actually what I'm going to use is not the BBB. It was just an assumption. The spi master will be some board not using MCU. So the question is, is the Due capable of taking and sending 5MP data? I didn't know that this is so difficult question to understand.

And please note that I'm not meaning Uno. This is ARM arduino

I'm voting to close this question as off-topic because it is an old question which has been abandoned for years without the specifics to make it answerable ever having been provided.  The only "answer" is really a comment to this fact, and none better are likely to be possible.

You are still not giving the full picture, pun intended.
I'll give you an example of what sort of info is missing.
For example, what's the frame rate? What's the color depth of the sensor?
If you look at the SAM3x TRM, it says that the SPI is clocked at max 65MHz.
So, the (simplified) math would say:
24bit/pixel * 5Mpixel / 65MHz =  1.846 seconds
And that doesn't even account for acquisition time, so if you do not have fully working DMA on both sides, it's probably even worse.
And it will be worse, because you cannot stuff in RAM in one go the entire image.
But maybe that's good enough for you, however it's not possible to say because of the missing info.

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


text:
Doesn't work radio transmission from Arduino Uno to Arduino Pro Micro
I have Arduino Uno, Arduino Pro Micro, XY-MK-5V and FS1000A.
I need transmit data from Pro Micro to Uno.
Transmitter:
    #include <VirtualWire.h>

    void setup() {

      Serial.begin(9600);

      vw_setup(2000);
      vw_set_tx_pin(14);
    }

    void loop() {

      send("Test message!");
      delay(2000);
    }

    void send (char *message)
    {
      vw_send((uint8_t *)message, strlen(message));
      vw_wait_tx();
    }

Receiver:
#include <VirtualWire.h>

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

    vw_set_rx_pin(12);
    vw_setup(2000);

    vw_rx_start();
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if(vw_get_message(buf, &buflen))
    {
        for(int i = 0; i < buflen; i++)
        {
            Serial.print(buf[i]);
        }

        Serial.println();
    }
}

I dont know why it's doesn't works. When I changed Uno with Micro and Micro with Uno, it's worked.
But I need: Micro + transmitter FS1000A & Uno + receiver XY-MK-5V.
Please help me. I'm using this Pro Micro.

What in particular doesn't work? You don't receive any characters? You get a garbage message?

And which Pro Micro: the geniune SparkFun Pro Micro - which version (it says on the PCB); the A-Star variant; a cheap chinese copy?

Are you connecting the modules to the right pins? vw_set_tx_pin(14); looks a bit odd, if you used that on the UNO.

On a Pro Mirco, D14 is connected to the RX LED, and nothing else; it's not broken out to either of the headers so you would never be able to use it to connect to an external component.

Thanks for your answers. I solved this problem, my Chinese copy has problems with power.

Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question.

@NickGammon The problem was solved according to feok. This is an answer although it has not been accepted.


text:
LiPo battery charger
Is it possible to build a battery charger with just an arduino UNO board (and perharps some passive components)?. It's a 3.7V 550 mAh LiPo Battery. I understand I need to monitor the charge and the current flowing into the battery to properly (as in safely) charge it.

I'll assume that you are trying to charge from a 5V "USB" source.
If you only want to use a UNO + passive components then the hardware intensive method of application note AVR146: Lithium-Ion Battery Charging via USB with ATmega16/32U4 which Ignacio suggests does not meet your need. This is a capable charger but the UNO would not be the major part of it.
"Normal" charger
The use of any of the available LiIon charger ICs is an easy and low cost way of adding a charger. These ICs and all related components can cost as little as a few dollars. But ...
UNO + one resistor very low current charger:
If using a UNO with no external active parts the current drive rating of the UNO pins limits the maximum current able to be provided. If you really want to meet your specification you can achieve a few ten's of mA charge using with a UNO and a few resistors (possibly just one.)
Super simple good capability charger
But, a good compromise can be achieved using a UNO (or similar) + one transistor plus a few resistors and capacitors. This can achieve all the usual basic capabilities

Low current "trickle up" for very low voltage cells
Constant current charge until Vmax is reached
Constant voltage charge until I_cutoff is reached.
Terminate and stay active until recharge needed.

I will only outline the basic system here. More can be said as and if required.
The main point of note s that in its simplest form the charger uses a linear charging mode so a modest amount of heat needs to be dissipated in the control transistor. Max power dissipation for a A max charge rate would be 2 Watts when the battery was at 3V and full charge was wanted from 5V in.
Power dissipation = (Vin - Vbattery) x Icharge
Worst case here = (5V - 3V) x 1A = 2 watts.
A buck converter could be used (UNO controlled) if desired.
A transistor Q1 connects Vin to battery
Q1 can be PWM controlled by the Uno.
Battery current is monitored by a small resistor Rcur from B- to ground (or in B+ lead)
Vbattery is monitored with an ADC channel (ADC1 or ADC_V)
Current is measured by measuring voltage across Rcur with an ADC (ADC2 or ADC_I).
If Rcur is from B- to ground then V Rcur = V ADC2. If Rcur is in B+ lead V across Icur = V_ADC2 - V_ADC1.
Q1 on state can be varied by PWM from Uno to control battery current. PWM voltage is smoothed by an RC low pass filter to allow smooth DC control.
Charging:
The following steps constitute the standard LiIon charging algorithm implemented by most charger ICs. Variations can be made.

If Vbat < 3V set Ichg to Itrickle by PWMing Q1 and reading battery current.
While 3V <= Vbat <= 4.2V chg at Imax for battery.
When Vbattery = V-max = 4.2V adjust Ichg with PWM to hold Vbat at 4.2V until   Ichg falls to desired fraction of Imax.
Turn off chg voltage fully and monitor Vbat to restart charge at Vbat = Vrestart - maybe 4.0V or as desired.

Yes, it is. AVR146 describes how to charge a battery using a ATmega16U4/32U4 (Leonardo), but there is nothing specific to that chip regarding the actual charging, and the serial communication can easily enough be ported to the ATmega328P.


text:
Multi-threaded Robot
I am working on a small robot project, the code which i made for this has a sequential execution in a single thread. There are a lot of Delay() function needed. Due to which the accuracy is extremely bad.
i want to to implement the movements in one thread and the sensor detection in another thread.
#define M1 3
#define M2 5
#define M3 6
#define M4 9
#define L_trig 2
#define L_echo 4
#define R_trig 7
#define R_echo 8
#define servo 10
#define solenoid_pin 11
#define LDR_pin1 12
#define LDR_pin2 13
void setup()
{
// Motors Initilization
pinMode(M1,OUTPUT);
pinMode(M2,OUTPUT);
pinMode(M3,OUTPUT);
pinMode(M4,OUTPUT);
// Ultrasonic  Initilization
pinMode(L_trig, OUTPUT);
pinMode(L_echo, INPUT);
pinMode(R_trig, OUTPUT);
pinMode(R_echo, INPUT);
S.attach(servo);
}

void loop()
{

 Runmotor(M1);
 Runmotor(M2);
 Runmotor(M3);
 Runmotor(M4);
 servo_rotation();
 Ultrasonic_value(L_trig,L_echo);
 Ultrasonic_value(R_trig,R_echo);

 if(Ultrasonic_value(L_trig,L_echo)<5 || Ultrasonic_value(R_trig,R_echo)<5)

   {
     turnLeft();
     //Serial.println("Working");
   }

}

// Run Motor
void Runmotor(int which)
{
  for(int i=0;i<1023;i++)
  {
 analogWrite(which, i);
  }
}
// Stop Motor
void stopmotor(int which)
{
  digitalWrite(which,LOW);
}
// To turn the robot left side
void turnLeft()
{
  stopmotor(M2);
  stopmotor(M3);
  delay(5000);
  Runmotor(M2);
  Runmotor(M3);
}
// To turn the robot Rightside
void turnRight()
{
  stopmotor(M1);
  stopmotor(M4);
  delay(5000);
  Runmotor(M1);
  Runmotor(M4);
}
// Servo Rotation
void servo_rotation()
{
 for(angle=0;angle<=180;angle++)
{
 S.write(angle);
 if(angle==90)
 {
   delay(2000);
 }
}
delay(2000);
for(angle=180;angle>=0;angle--)
{
  S.write(angle);
  Serial.println(angle);
  if(angle==90)
 {
   delay(2000);
 }
}
 delay(2000);
}

// Calculation of distance
long Ultrasonic_value(int which_trig,int which_echo)
{
  long duration, distance;
  digitalWrite(which_trig, LOW);
  delayMicroseconds(2);
  digitalWrite(which_trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(which_trig, LOW);
  duration = pulseIn(which_echo, HIGH);
  // distance = duration*343*100/2;
  distance = (duration/2) / 29.1;
  delay(100);
  return distance;
}

void Solenoid_Fire()
{
  digitalWrite(solenoid_pin,LOW);
}

void Solenoid_Reload()
{
  digitalWrite(solenoid_pin,HIGH);
}
/*
bool LDR_reading(int LDR_pin1 , int LDR_pin2)
{

}
*/

Please help me. I want to implement this code in a Multi-thread fashion. Thanks in Advance

I don't think threads are going to help. That's like driving a car by having one person look out the window and another person operating the steering wheel, accelerator and brakes. You have to coordinate your inputs with your outputs. Hiving off the two things (observing and doing) into different threads is just going to create other problems.

Like many things in life, it's also a matter of personal preference. However threads have the advantage of showing clearly what will preempt what. And they avoid busylooping. Of course there is a price to pay, namely reduced ease of debug and risk of deadlocks. Any choice is good, as long as it is informed.

Make a function startTurning and stopTurning, rather than blocking your complete execution with a delay.
You might than use a hardware timer (or software timer) to call these functions, so that in the meantime you can perform other calculations/logic/code/interaction.

You could also give my ThreadHandler library a try
https://bitbucket.org/adamb3_14/threadhandler/src/master/
It uses an interrupting scheduler to allow context switching without relaying on yield() or delay().
I created the library because I needed three threads and I needed two of them to run at a precise time no matter what the others were doing. The first thread handled serial communication. The second was running a Kalman filter using float matrix multiplication with the Eigen library. And the third was a fast current control loop thread which had to be able to interrupt the matrix calculations.
How it works
Each cyclic thread has a priority and a period. If a thread, with higher priority than the current executing thread, reaches its next execution time the scheduler will pause the current thread and switch to the higher priority one. Once the high priority thread completes its execution the scheduler switches back to the previous thread.
Scheduling rules
The scheduling scheme of the ThreadHandler library is as follows:

Highest priority first.
If the priority is the same then the thread with the earliest deadline is executed first.
If two threads have the same deadline then the first created thread will execute first.
A thread can only be interrupted by threads with higher priority.
Once a thread is executing it will block execution for all threads with lower priority until the run function returns.
The loop function has priority -128 compared to ThreadHandler threads.

How to use
Threads can be created via c++ inheritance
class MyThread : public Thread
{
public:
    MyThread() : Thread(priority, period, offset){}

    virtual ~MyThread(){}

    virtual void run()
    {
        //code to run
    }
};

MyThread* threadObj = new MyThread();

Or via createThread and a lambda function
Thread* myThread = createThread(priority, period, offset,
    []()
    {
        //code to run
    });

Thread objects automatically connect to the ThreadHandler when they are created.
To start execution of created thread objects call:
ThreadHandler::getInstance()->enableThreadExecution();

I think this needs a major rework. First here:
  for(int i=0;i<1023;i++)
  {
  analogWrite(which, i);
  }

The maximum you can analogWrite is 255, so change 1023 to 255.
Next, get rid of the delay() calls.

Let's look at turnLeft :
// To turn the robot left side
void turnLeft()
{
  stopmotor(M2);
  stopmotor(M3);
  delay(5000);
  Runmotor(M2);
  Runmotor(M3);
}

Why stop the motor and then start it again? Do you mean:
// To turn the robot left side
void turnLeft()
{
  stopmotor(M1);
  stopmotor(M4);
  delay(5000);
  Runmotor(M2);
  Runmotor(M3);
}

I don't see what the delay achieves anyway. Get rid of it:
// To turn the robot left side
void turnLeft()
{
  stopmotor(M1);
  stopmotor(M4);
  Runmotor(M2);
  Runmotor(M3);
}

In fact, I don't see what any of the delay() calls achieve. Try removing them.

See my post How to do multiple things at once ... like cook bacon and eggs for tips on doing multiple things without using delay().

Also consider using arrays. Instead of M1, M2, M3, M4, make an array:
const int NUMBER_OF_MOTORS = 4;
const int motorPins [NUMBER_OF_MOTORS] = { 3, 4, 6, 9 };

Now it is easier to set them all to output:
// Motors Initilization

for (int i = 0; i < NUMBER_OF_MOTORS; i++)
  pinMode (motorPins [i], OUTPUT);

It is also easier to start or stop all of them:
for (int i = 0; i < NUMBER_OF_MOTORS; i++)
  stopmotor (i);

Where stopmotor is now:
// Stop Motor
void stopmotor(int which)
{
  digitalWrite(motorPins [which],LOW);
}

(Edited to add)
I also don't see what this achieves:
void Runmotor(int which)
{
  for(int i=0;i<1023;i++)
  {
 analogWrite(which, i);
  }
}

Apart from the fact that you can't go up to 1023, if you stop at 255, the time taken to do all those analogWrite is just over 2 ms. Why bother? Why not just do this:
void Runmotor(int which)
{
  digitalWrite (which, HIGH);
}

M1   M2                                                                                M3   M4                                                                                When i want to turn left i should Stop the motors lies on 2nd diagional, For turn Right in vice versa

Which motor is which? Are M1 and M2 on the left, and M3 and M4 on the right? Better names would make this obvious, like frontLeftMotor, and frontRightMotor, etc.

You may want to take a look at LMX by David Anderson A Light-Weight Multi-Tasking Executive.
He has a very good set of videos on the code that he did for Dallas Personal Robotics Group (DPRG).
The specific videos for LMX are:

David Anderson on Robotics Software - part 1
David Anderson on Robotics Software - part 2

You could use a scheduler and simply start tasks with:
#include <Scheduler.h>
...
void setup()
{
  ...
  Scheduler.start(servoSetup, servoLoop);
  Scheduler.start(sensorSetup, sensorLoop);
  ...
}

void servoSetup()
{
  S.attach(servo);
}

void servoLoop()
{
  int angle;
  for(angle = 0;angle <= 180; angle++) {
    S.write(angle);
    if (angle == 90) {
      delay(2000);
    }
  }
  delay(2000);
  ...
}
...

The tasks must call yield() or delay() to context switch. The taskSetup function is called first and once by the task. The taskLoop function is repeatedly called by the task. This can be viewed as running an additional sketch.
For more details see the example sketches.

I am looking at this, for a similar project.
It seems light and simple enough that you could have a quick trial.
Converting those functions to threads shouldn't be too time consuming.
Once every activity is implemented as thread, you could use semaphores to hold them blocked and then create a state machine which controls them through the semaphores.

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


text:
I have an 'error' with my code
The following code gives me an error:
// RFIDunio.h is from http://learn.robotgeek.com/getting-started-guides/39-robot-kits/151-rfiduino.html
#include <RFIDuino.h>

byte    keyTag[5] = {0,0,0,0,0};
boolean noise = false;
byte    masterTag[5] = {37,0,0,127,24};
byte    tagData[5];
byte    tagDatas[5];
boolean verifyKey = false;
boolean mastaKey = false;

void setup()
{
  Serial.begin(9600);
  Serial.println("Welcome to my system!");
}

RFIDuino myRFIDuino(1.2);

void loop()
{
  if(myRFIDunio.scanForTag(tagData == true)
  {
    verifyKey = myRFIDunio.compareTagData(tagData, keyTag);
    mastaKey = myRFIDunio.compareTagData(tagData, masterTag);
    if(verifyKey == true)
    {
      digitalWrite(myRFIDunio.led2,HIGH);
      if(noise == true)
      {
        myRFIDunio.successSound();
      }
      Serial.println("Correct Key!" + " UID = " + tagData[5]);
      delay(250);
      digitalWrite(myRFIDunio.led2,LOW);
    }
    else if(mastaKey == true)
    {
      Serial.println("Programming mode activated!");
      delay(500);
      Serial.println("Please scan a card.");
      myRFIDunio.scanForTag(tagDatas == true)
      delay(1000);
      tagDatas[5] = tagData[5];
      Serial.println("Card has been programmed!");
    }
    else
    {
      digitalWrite(myRFIDuno.led1,HIGH);
      if(noise == true)
         {
            myRFIDuino.errorSound();
         }
      Serial.println("Wrong! " + "UID = " + tagData[5]);
      delay(250);
      digitalWrite(myRFIDunio.led1,LOW);
    }
  }

The error is:
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Users\*****\Documents\Arduino\libraries\RFIDuino C:\Users\*****\AppData\Local\Temp\build6101268048586666869.tmp\sketch_jul24a.cpp -o C:\Users\*****\AppData\Local\Temp\build6101268048586666869.tmp\sketch_jul24a.cpp.o
sketch_jul24a.ino: In function 'void loop()':
sketch_jul24a:20: error: 'myRFIDunio' was not declared in this scope
sketch_jul24a:20: error: ISO C++ forbids comparison between pointer and integer
sketch_jul24a:21: error: expected `)' before '{' token
sketch_jul24a:55: error: expected statement at end of input
sketch_jul24a:55: error: expected `}' at end of input

Did you even read the errors?! It tells you precisely what's wrong. error: 'myRFIDunio' was not declared - because you've spelt it incorrectly. In fact, you've managed to spell it three different ways throughout your code: myRFIDuino; myRFIDunio; myRFIDuno. Read, read, and read again.

C++ is spelling-sensitive; identifiers need to be spelled the same way each time they are used.

if(myRFIDunio.scanForTag(tagData == true)

I think you have a bracket missing there.
if(myRFIDunio.scanForTag(tagData) == true)

Also I think you have spelled myRFIDuino wrong.  ni <-> in
if(myRFIDuino.scanForTag(tagData) == true)

And you need a } at the end of your program.
As well, you can't add strings together like you are doing in your Serial prints.  Break them up into multiple prints:
Serial.print("Correct Key!  UID = ");
Serial.println(tagData[5]);

You also have other bits that make no sense at all, such as:
myRFIDuino.scanForTag(tagDatas == true)

One further thing - that library will never work on Linux, or on MAC OS/X where case sensitivity is enabled on the filesystem.  The .cpp file is including a badly named .h file.

myRFIDunio.scanForTag(tagDatas == true)    is for getting the card information so you can program it, I am on windows. I will change the serial prints.                                                                                http://pastebin.com/RMrE8aD0

That line is gibberish, unless you are wanting to pass a boolean value to the scanForTag function which states whether or not tagDatas is true, which it can't be since it's an array.  Why is the == true even there?!

I am just trying to figure this out. Is there any way to get the tag data then.  and put it into a byte.

I have no idea. I don't know what "the tag data is", only that your program has syntax errors that I have identified.  I do not know what the program is supposed to do - nor even what a "RFIDuino" is or what it does.

Tag data is what rfid tags hold, they all have indiffrent unique ids. This reads them. I can show you the library if you want.

I have seen the library.  I have even submitted a pull request to it to correct their capitalization error.  I have never seen an RFID tag that just has a single byte for it's ID though.  If you want help with working out how to use the library then look at the examples.  First correct the syntax errors like I have told you.

@IanOxyMoron: If you have further questions then you would be best served by opening further questions.


text:
Is the SIM900 3G? Or is the SIM900A able to connect to 3G?
I would like to state that I am not familiar with the whole cellular connection thing. But I was wondering if the SIM900/or/SIM900A is 3G and will work with PTel Mobile.
I need this Arduino to be able to travel and needs to connect to every PTel's tower. Will I be able to connect to 3G or only the 2G and the 1G networks?

Do you need 3G, or do you just need Data? Arduinos don't run fast enough to even saturate 2G.

It's GPRS only (GPRS class 10: max. 85.6 kbps) according to the datasheet

I don't have enough reputation to post a comment, but this is a comment for both your answers, TP Ap and Ralph. What is the source for your answers? I'm trying to find out the answer to this question myself and I've seen a lot of claims like yours which aren't backed up by sources. I haven't found a single source which confirms this one way or another. I read the datasheet for the chip and couldn't find the answer there either.

Find the proper SIMCom module here.

First of all if you are in USA you cannot use SIM 900A since it supports only Dual frequency bands.(900,1800 MHz)it supports only Asian region countries.
According to Wikipedia, PTel Mobile supports only GSM 850/1900 frequencies.
so SIM 900 supports( 850,900,1800,1900 MHz ) you must use SIM900
Considering about the speed you cannot obtain 3g, 4g speed since GSM Shield(SIM900) provides maximum of GPRS class 10: max. 85.6 kbps (downlink) so,
It will able to connect but cannot get such speed in 3g and 4g.

It will not be able to connect to a 3G or 4G network. There has to be a 2G network / support and that support is getting less.

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


text:
Which bluetooth module should I buy?
I am doing a wireless rover using arduino mega 2560 that can be controlled by a smartphone and a PC. Which bluetooth module would fit me? Again I want to control it both by my Laptop(Built-in Bluetooth) and my smartphone. Thanks in advance.

Which smartphone. iOS is pretty strict in what kind of Bluetooth modules it supports.

A little late but in case someone like me ran into this:
HC-05 seems to be the DIY choice. Can work in slave or master mode and works with Android but not iOS.
HC-06 is the same as HC-05 except that you can only use it in slave mode.
HM-10 seems to be the option for iOS users.


text:
reversing a micro motor by reversing two pins - one Source and one sink?
can I use this configuration of two pins to run a micro motor ,so I be able to change the polarity of the current (by the code itself-one time out pin1-high out pin2 - low , while next time one low two high!) every time I would like ?(and by changing the polarity OF THE CURRENT to the motor it will revers it) !
Thank's !

For interest - how micro is "micro" and what is the motor used and application? If you need more power an H bridge driver can be built for tens of cents (and some ICs are low cost)

**Required:**

Drive micro-motor directly from two processor pins.

 - Pin 1 high / Pin 2 low for one direction.
 - Pin 1 low / Pin 2 high for other direction.**

This is not a very good idea if it can be avoided but yes, you can operate a motor that way,  providing that the motor current is low enough to meet the pin current ratings. It would have to be a very small motor to achieve this.
Take careful note of the current versus voltage drive capabilities of the processor concerned. While a pin may be shown as being able to source or sing 5 or 10 or 20 mA, this is accompanied by a voltage rise for a sink and voltage drop for a source, so at higher currents lower voltages will be available.
A danger is that motor noise may affect the processor.
Placing a small capacitor across the motor will help, and driving the motor through a small resistor from each pin will also help keep noise away from the processor. But depending on the motor used this may not be enough.
The series resistors will drop some voltage and so are limited in maximum allowable size.
The parallel capacitor will slow the direction transition - the larger the capacitor the slower the change.
Using drivers or "buffers" which are higher current rated would allow a larger motor to be driven and would help isolate the processor from the motor noise.
Ask further if any idea here sounds useful.

Added: Had a discussion with Gerben (below).
I'd avoided mentioning "catch diodes" but this is an add on that can help.
From each pin add a small Schottky diode* from pin to Vcc and pin to ground so that all 4 diodes are reverse biased.
(ie Cathode goes to Vcc = line on diode on upper diodes.
Anode goes to ground on "lower" diodes. )
These diodes are usually non conducting. If motor operation or switching causes spikes that rise above Vcc or below ground these diodes will conduct (slightly) before  the internal protection diodes do. This is not ideal but can help.
As Gerben notes, when reversing the motor, driving BOTH pins to ground until the motor has stopped and then applying reversing polarity can help. Also driving both high will do the same. There are pros and cons with either method.

eg BAT54 surface mount,   BAT48 through hole, 1N581x  or similar.

You also need to add some clamping diodes to eliminate flyback, which is the sudden voltage spike seen across an inductive load when its supply voltage is suddenly reduced or removed. I did this on my project where I was driving the tiny lavet stepper motor inside an analog clock. I added diode to clamp the voltage to VCC. Clamping to ground  was done by setting both pins to LOW before any further movement.

A problem with using diodes is that the motor polarity reverses. I considered suggesting Schottky diodes to gnd and VCC from each pin but decided to offer the cct as seen and see if the OP shows interest. It can then be refined. You can add an H bridge driver with jellybean transistors for very little $ indeed but providing detail on this initially is just liable to confuse.

thank you very much guys !                                                                                you are fantastic  !!!


text:
Measuring KWh connecting to the mains
I need to measure KWh of the mains, connecting something like a sensor to the mains and reading its value into analog. I already know to measure KWh from a KWh meter but I need to make my own.

You can put a current clamp around the wire, to measure the current. But you need to spit the live and neutral wires. Something you probably have to have an electrician done.

If i understand your question correctly, what you want to do is measure the current consumed from the mains by whatever load is connected to it (Fan, AC, computer etc).
What you need is basically a current sensor, have a look at https://www.sparkfun.com/products/8883 and https://www.sparkfun.com/products/11005
Please understand that you are playing with the mains and unless you take the required precautions, you can get seriously injured


text:
Arduino IDE on Fedora
I'm using Fedora_21_MATE.img on a Raspberry Pi. Installing the Arduino IDE 1.0.6 using these commands, taken from Arduino On Pi. Those instructions are for Raspbian, I assume, so changing for Fedora, apt-get to yum:
sudo yum install arduino

One waits and arduino installs. One can then run the Arduino IDE from the Fedora GUI menu, and it loads - after moaning about the user has to be a member of the dialout and lock groups. This is easily resolved by adding the user to the required groups, using the control panel.
However, trying to compile anything, i.e. blink, in the IDE, gives me the following error:
avr-g++: error trying to exec cc1plus: execvp: No such file or directory

In verbose mode, little additional information is offered.
Arduino: 1.0.6 (Linux), Board: "Arduino Uno"
avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /tmp/build6314348775898760987.tmp/Blink.cpp -o /tmp/build6314348775898760987.tmp/Blink.cpp.o
avr-g++: error trying to exec 'cc1plus': execvp: No such file or directory

The file in question, cc1plus, is actually present in the filesystem:
[piebody@berrybody ~]$ locate cc1plus
/usr/libexec/gcc/armv7hl-redhat-linux-gnueabi/4.9.2/cc1plus
/usr/libexec/gcc/avr/4.9.2/cc1plus
[piebody@berrybody ~]$

Does anyone know why it doesn't run "out of the box"? Do I need to modify any environment variables, and if so, which ones and with what exactly? I assume my PATH environment variable needs fixing, but is there any environment variable specific to avr-g++ that needs changing?
I appreciate that this is probably a simple UNIX paths issue, and that the question may be more suited to SE: Unix & Linux.

Can you post the verbose build output?

Could you try this again with Fedora 23? I just tested it, and it works for me out of the box.

There seem to be two issues:

Getting the IDE to fully function when launched from the command
line, and;
Getting the IDE to fully function (i.e. compile) when launched from
the Fedora GUI menu.

I have found a solution if I run the Arduino IDE from the command line, by adding the path to  one of the cc1plus binaries to the PATH environment variable:
[piebody@berrybody ~]$ PATH=${PATH}:/usr/libexec/gcc/avr/4.9.2
[piebody@berrybody ~]$ export PATH
[piebody@berrybody ~]$ arduino&

However, if I launch the Arduino IDE from the Fedora application menu, and then try to compile a sketch, it still can't locate cc1plus. Maybe the PATH needs to be added in my .profile, or some other mechanism, to get an application launched from the Fedora menu to see the path?1
Yet, even with the command line launch, it still does not finish compiling.  I now get the following error when the IDE attempts to compile:
In file included from Blink.ino:18:0:
/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:23:20: fatal error: stdlib.h: No such file or directory
 #include <stdlib.h>
                    ^
compilation terminated.

In verbose mode
Arduino: 1.0.6 (Linux), Board: "Arduino Uno"
avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /tmp/build1210300884764677972.tmp/Blink.cpp -o /tmp/build1210300884764677972.tmp/Blink.cpp.o
In file included from Blink.ino:18:0:
/usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:23:20: fatal error: stdlib.h: No such file or directory
 #include <stdlib.h>
                    ^
compilation terminated.

I assume that this is another PATH issue. One that relates to the path to the Arduino libraries, or libc libraries.
After reading can't locate avr libraries2, I can't see why avr-g++ is not picking up the avr directory in the /usr directory.
The actual path to stdlib.h is /usr/avr/include/stdlib.h
The output of avr-gcc (and avr-g++) shows --prefix=/usr
The Arduino IDE preference file (~/.arduino/preference.txt) shows the line
last.ide.1.0.6.hardwarepath=/usr/share/arduino/hardware

Linking the includes
If I manually link some header files to where the compiler actually is looking, then it works (until avr-gcc needs a header that I have not linked to):
cd /usr/share/arduino/hardware/arduino/cores/arduino
sudo ln -s /usr/avr/include/stdlib.h stdlib.h
sudo ln -s /usr/avr/include/string.h string.h
sudo ln -s /usr/avr/include/math.h math.h

but I can not do this for every header file, it is ridiculous. There must be a way of linking to /usr/avr from /usr/share/arduino/hardware/arduino/cores/arduino. I have tried linking the parent directories /usr/avr and /usr/avr/include, at various points along the directory hierarchy of /usr/share/arduino/hardware/arduino/cores/arduino, but none of those seem to work.
Copying the include directory
After reading default include file path?, and running avr-cpp -v I saw that the default #include search path was
#include <...> search starts here:
 /bin/../lib/gcc/avr/4.9.2/include
 /bin/../lib/gcc/avr/4.9.2/include-fixed
End of search list.

From this, I could see that avr-cpp was searching in /lib/gcc/avr/4.9.2/include. I examined, and compared, the contents of /lib/gcc/avr/4.9.2/include with /usr/avr/include and they held similar (the same) files, except /lib/gcc/avr/4.9.2/include was a subset, that is to say that it was missing the required files.
I ended up copying the /usr/avr/include directory, which contains the required header files (stdlid.h etc., to which I had linked previously), and replacing the original include directory, in the directory where avr-gcc seemed to be looking, which was in its own directory location /lib/gcc/avr/4.9.2/.
cd /lib/gcc/avr/4.9.2/
mv include include.old
cp -r /usr/avr/include .

Then the Arduino compiler seemed to work, until it then gave an assembler error:
Assembler messages
Error: unrecognized option -mmcu=avr5

This is an issue with avr-as.
I will update as I resolve these issues.

1 I eventually resolved this by creating a script in /usr/bin (where the arduino binary was located) called arduino.launch which contains the PATH settings and a call to arduino:
#!/bin/sh
PATH=${PATH}:/usr/libexec/gcc/avr/4.9.2
export PATH
arduino

setting it to be executable with chmod +x arduino.launch. Then I edited the properties of the Fedora Arduino launch icon, by right-clicking on the icon and selecting Properties, and changed the Command entry from arduino to arduino.launch.
However, there must be a better way of doing this, as this seems to be a bit of a hack.
2 Other posts 1, 2 and 3) that I have read, apart from providing useful paths to investigate, merely suggest reinstalling. However, as bone headed as I may seem, there must be a way of linking up what is already on the file system (everything is there - just in the "wrong" place), such that compiles work as they should.


text:
Use LED on pin 13 again after using the SD library
The question in short:
On an Arduino UNO or Nano using the SD library, is it somehow possible to use the LED on pin 13 (or any other pin that is used by the library) again after finishing all SD operations?
Detailed explanation:
In my sketch, during setup() I need to read some data from a file on the SD card, which is being closed again before leaving setup().
Now, I wanted to use the LED on pin 13 during loop() as a status indicator for the user, but it seems that after SD.begin(), pin 13 (and its LED) cannot be used as an OUTPUT anymore.
Here is a minimum sketch to show the behavior. It doesn't matter if I try to turn on the LED right after the call to SD.begin() in setup() or in loop():
#include <SD.h>
#include <SPI.h>

#define SD_CS  4
#define LED    13

void setup() {
  pinMode(LED, OUTPUT);

  // This still works:
  digitalWrite(LED, HIGH);
  delay(1000);
  digitalWrite(LED, LOW);

  SD.begin(SD_CS);

  // This does not work anymore:
  digitalWrite(LED, HIGH);
  delay(1000);
  digitalWrite(LED, LOW);
}

void loop() {}

It is possible to use the LED on pin 13 again by disabling the SPI bus that is used by the SD library to read/write data to/from the SD card. To disable the SPI bus, simply call SPI.end() after closing the file on the SD card.

Agreed. Betwen SPI.begin()  and SPI.end() the hardware takes over that pin.

Does anyone know, why the SD library has no .end()? Apparently you don't have to explicitly call SPI.begin() in your sketch, as SD.begin() seems to wrap this. So I think, a call to SPI.end() should also be wrapped in some complementary method like SD.end(). Should this be filed as a bug report/wishlist item to the library developers? Or is there any reason why there is no method like this?

Sounds odd to me. You could query it with the developers.

Any updates on your followup question @JohannesMaibaum?

@JaroslavZáruba: No, actually. I just checked the online reference for the SD library again, but still there is no SD.end() or similar. But simply calling SPI.end() worked and works for me.


text:
UNO Timer 1 CTC mode not resetting TCNT1
I'm trying to set up timer 1 to run an isr in CTC mode. no matter what i set OCR1A to it always executes at the same frequency and if i print out TCNT1 I get values higher than OCR1A.
here is my Code
    void timer1_init()
    {
    // set up timer with prescaler = 8 and CTC mode
    TCCR1B |= (1 << WGM12)|(0 << CS12)|(1 << CS11)|(0 << CS10);

    // initialize counter
    TCNT1 = 0;

    // initialize compare value
    OCR1A = 100;

    // enable compare interrupt
    TIMSK1 |= (1 << OCIE1A);

      // enable global interrupts
        sei();
    }

ISR(TIMER1_COMPA_vect){
    SET(MOTOR_PORT,LEFT_MOTOR_STEP); //set the pin high
    delayMicroseconds(3); //keep high for a bit
    CLR(MOTOR_PORT,LEFT_MOTOR_STEP); //set it low
}

I'm using this to drive a stepper motor so using PWM mode wont work.

It sounds as though timer 1 has not in fact been set to wavegen mode 4. You can ensure that it is by also clearing the other bits of WGM1:
TCCR1A &= ~(_BV(WGM10) | _BV(WGM11));
TCCR1B &= ~_BV(WGM13);

I normally assign to TCCR1A and TCCR1B rather than "or". That way I know it is set to a fixed value.


text:
Can PWM break a DC motor?
I want to know if controlling the speed of a DC motor with PWM could break (burn out the DC motor. Sorry my English isn't that good.

Provided that the voltage specs of the motor are not violated, no. However, the inductance of the motor stands a very good chance of destroying the switch unless an appropriately-rated flyback diode is used.

I'm new to Arduino and electronics. I'm planning to use a H-bridge (l293d) with the dc motor, in the project nº 10 of the arduino projects book that comes with the arduino starter kit there is no flyback diode.

In another project of the book, where a MOSFET is used, I found the flyback diode, but the project that uses the l293d there is no diode.

The l293d has these diodes already inside the package.

Providing that you send the appropriate voltage this shouldn't break your motor. The creator of Arduino suggest this way of driving motor on his book.
Source: Massimo Banzi's book : "getting started with arduino" : chapter 5 Advanced Input and Output.


text:
LIght bulb to light up
I'd like to write a JavaScript function that lights up an led light for X milliseconds depending on the response from the JavaScript function.
function HowManySeconds() {
   setTimeout(HowManySeconds,5000)
   return 1000
}

The JavaScript function will come from a website, so I suppose I would need an Internet enabled device that connects to my router and can 'browse' to my website.
Q: What do I need to buy? A tessel? An Espruino?

This is an Arduino forum.

I'm a newbie, so I'm not sure where to start. I don't want to invest a lot of time and money on something only to find out I could have done it easier and cheaper by buying something else or newer.

Just to clarify: You want a gadget (eg. an Arduino) connected to an Ethernet cable, which queries your website from time to time, and depending on what that website returns, turns on a light (ie. activates an output) for a few milliseconds. Is that it?

Yes. I'm trying to make the scenario as simple as possible. But I'm a web developer, so I can write the JavaScript. But I need a gadget that when plugged in, will automatically interrogate my web page and light up for the number of milliseconds that is returned. I can have the JavaScript running in an infinite loop so that it's constantly polling.

You could try the intel galileo or the intel edison with arduino shield. They can be programmed with a variant of the arduino ide, but it is possible to call also programs from the native linux os. Or you could have a look at the esp826.
At least on the edison it is possible to run node.js, while the esp supports lua.


text:
Servo motors won't work with motor controller
I have a motor controller controlling two motors, which works perfectly fine when I comment out the two servos in the below code. These two servos are not connected to the motor controller but simply being operated using other Arduino Uno pins, as seen in the code.
When the servo attach() functions are included in the code the motor controller only works with one of the motors and the other completely stops working.
I don't understand why the servos are interfering with the motor controller. What's going on here?
#include <Servo.h>
Servo myServo1;
Servo myServo2;

int m1_ALI = 10;
int m1_BLI = 9;
int m2_ALI = 3;
int m2_BLI = 11;

int m1_AHI = 12;
int m1_BHI = 4;
int m2_AHI = 6;
int m2_BHI = 5;

void setup() {

  //myServo1.attach(7);
  //myServo2.attach(8);

  pinMode(m1_AHI, OUTPUT);
  pinMode(m1_ALI, OUTPUT);
  pinMode(m1_BLI, OUTPUT);
  pinMode(m1_BHI, OUTPUT);
  pinMode(m2_AHI, OUTPUT);
  pinMode(m2_ALI, OUTPUT);
  pinMode(m2_BLI, OUTPUT);
  pinMode(m2_BHI, OUTPUT);
}

void loop() {

moveForward(30);

}//end loop

void moveForward(int x){

    digitalWrite(m1_AHI, LOW);
    digitalWrite(m1_BLI, LOW);
    digitalWrite(m1_BHI, HIGH);

    digitalWrite(m2_AHI, LOW);
    digitalWrite(m2_BLI, LOW);
    digitalWrite(m2_BHI, HIGH);

    analogWrite(m2_ALI, x);
    analogWrite(m1_ALI, x);
}//end moveForward

See Servo.cpp:

Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached.
   Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four.

Also Servo Library reference

On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.

You are using pins 9 and 10 for your motors.

analogWrite uses PWM, the servo library uses PWM, you have a conflict of resources here.

The servo's are not connected to PWM pins though.

wow thanks that worked. My goodness I have been trying to solve this for a week.

Strange with how many arduino robot car projects there are out there, how none I came across talked about this.  I just happened to decide to 'upgrade' to controlling the speed, and ran into this (5 years after the original question)


text:
What is Arduino?
Actually I don't know about Arduino, but seeing my fellow classmates, I want to start learning it. Could anybody tell what actually Arduino is about?

Google Arduino or got to arduino.cc

What is Arduino?
Arduino video tutorials
Official boards
Wikipedia - Arduino
Arduino forum

A popular Arduino - The Arduino Uno:

In case I get accused of writing a "link-only" answer ...
The Arduino is a hobbyist prototyping platform, where users can develop projects for microprocessors. Typically the boards have one or two processors on them, can connect to a PC/Mac/Linux by a USB interface, be programmed in C++, and operate external devices (eg. motors, lights, MIDI, LCD screens, LEDs) and take readings (eg. temperature, time, location, voltage).
Different boards have different capabilities, such as the number of I/O ports, the amount of memory, and the size of the program that can be uploaded.
You can connect them to the major operating systems:

Linux
Macintosh
Windows

The hardware and software are open-source, making development for them easy.

Image attribution: Sparkfun Electronics


text:
How to Publish to MQTT with retain option
I don't understand how to publish to mqtt with retain option (The fourth parameters)
I know that I need length in an byte array but I've try allot to determine how to calculate my payload message to an byte var.
here is my code to publish once I am connected.
String str;
char chBright[4];
str = String(ledBrightness); //converting integer into a string
str = str + '%';
str.toCharArray(chBright, 4);
MQTTClient.publish("/maison/GF/Escalier/stairLight/b", chBright);

document ask the third parameter to be an byte

topic – the topic to publish to char*
payload – the message to publish byte array
length – the length of the message byte
retained – whether the message should be retained byte

0 – not retained
1 – retained

mqtt client for Arduino
How in c++ to get bytes from the message I want to publish?
Tank you to clarify my knowledge

Just to clarify: char chBright[2]; and then str.toCharArray(chBright, 4); - you want to put 4 bytes into a 2 byte field, is that it?

ow! you'r right... good mistake sorry.

I think I've found something! https://www.arduino.cc/en/Reference/ByteCast

How to Publish to MQTT with retain option?

The quick answer is add payload length, and retained as true as the last parameters to publish().
const int BUF_MAX = 8;
char buf[BUF_MAX];
itoa(ledBrightness, buf, 10);
strcat(buf, "%");
int len = strlen(buf) + 1;
MQTTClient.publish("/maison/GF/Escalier/stairLight/b", buf, len, true);

Above is a rewrite with the extra parameter for "retained", payload length, and payload as a null-terminated string.
Cheers!

How in c++ to get bytes length from the message I want to publish?

For a String object, the method length() tells you the length.
eg.
int len = str.length ();

For a null-terminated C-type string, you can use strlen, eg.
char foo [20] = "bar";
int len = strlen (foo);


text:
Monster moto shield + Arduino +Pololu 12V, 29:1 Gear Motor Encoder hardware problem
Overflow enthusiasts!
I am trying to build a balancing robot with two wheels, using the polulu gear motor as mentioned above. In order to have a strong motor driver,the monster moto shield is used in this project. Here is the components and datasheets which is used.

Components
Li-poly RC Battery 2800mah 11.1V 35C.
Arduino saint smart
2x Pololu 12V, 29:1 Gear Motor w/Encoder
Monster moto shield
Now, back to the issue.. Well, the first problem I encountered was my motor driver. It keeps getting hot after a while, whenever I use it ( I run 2 motors through 1 driver). And the most frustrating part is that the motors can stop for a while, and then restart again ( suspect a hardware reset here). Is there any way this can be solved?, I have checked the datasheet for the monster moto driver but can't understand whether the components are already on the PCB boad or I manually have to add new components like resistors, capacitors and etc. Would be glad if you guys directed me on this issue.
Secondly, The other problem I have is that the motors are going fast CW and slow CCW whenever I reverse direction. I have also seen other ppl getting the same problem as I do and wonder why this happen. Could it be that the cables are to small for the current flow ?
Should I add external components ? Then which components should I use in order to subdue this problem?
Here are some pictures in order to clarify the problem. Mostly using cables to connect inputs and etc. I would be glad if you wonder something and want me to post more information.

pictures:

Code
/*  MonsterMoto Shield Example Sketch
  date: 5/24/11
  code by: Jim Lindblom
  hardware by: Nate Bernstein[![enter image description here][1]][1]
  SparkFun Electronics
 This is really simple example code to get you some basic
 functionality with the MonsterMoto Shield. The MonsterMote uses
 two VNH2SP30 high-current full-bridge motor drivers.

 Use the motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
 function to get motors going in either CW, CCW, BRAKE[![enter image description here][1]][1]VCC, or
 BRAKEGND. Use motorOff(int motor) to turn a specific motor off.

 The motor variable in each function should be either a 0 or a 1.
 pwm in the motorGo function should be a value between 0 and 255.

This code is beerware; if you see me (or any other SparkFun employee) at the
local, and you've found our code helpful, please buy us a round!
Distributed as-is; no warranty is given.
 */
#define BRAKEVCC 0
#define CW   1
#define CCW  2
#define BRAKEGND 3
#define CS_THRESHOLD 100

/*  VNH2SP30 pin definitions
 xxx[0] controls '1' outputs
 xxx[1] controls '2' outputs */
int inApin[2] = {7, 4};  // INA: Clockwise input
int inBpin[2] = {8, 9}; // INB: Counter-clockwise input
int pwmpin[2] = {5, 6}; // PWM input
int cspin[2] = {2, 3}; // CS: Current sense ANALOG input
int enpin[2] = {0, 1}; // EN: Status of switches output (Analog pin)

int statpin = 13;

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

  pinMode(statpin, OUTPUT);

  // Initialize digital pins as outputs
  for (int i=0; i<2; i++)
  {
    pinMode(inApin[i], OUTPUT);
    pinMode(inBpin[i], OUTPUT);
    pinMode(pwmpin[i], OUTPUT);
  }
  // Initialize braked
  for (int i=0; i<2; i++)
  {
    digitalWrite(inApin[i], LOW);
    digitalWrite(inBpin[i], LOW);
  }
  // motorGo(0, CW, 1022e3);
  // motorGo(1, CCW, 1023);
}

void loop()
{
  motorGo(0, CW, 1023);
  motorGo(1, CW, 1023);
  delay(500);
  motorGo(0, CCW, 1023);
  motorGo(1, CCW, 1023);
  delay(50);
  if ((analogRead(cspin[0]) < CS_THRESHOLD) && (analogRead(cspin[1]) < CS_THRESHOLD))
    digitalWrite(statpin, HIGH);
}

void motorOff(int motor)
{
  // Initialize braked
  for (int i=0; i<2; i++)
  {
    digitalWrite(inApin[i], LOW);
    digitalWrite(inBpin[i], LOW);
  }
  analogWrite(pwmpin[motor], 0);
}

/* motorGo() will set a motor going in a specific direction
 the motor will continue going in that direction, at that speed
 until told to do otherwise.

 motor: this should be either 0 or 1, will selet which of the two
 motors to be controlled

 direct: Should be between 0 and 3, with the following result
 0: Brake to VCC
 1: Clockwise
 2: CounterClockwise
 3: Brake to GND

 pwm: should be a value between ? and 1023, higher the number, the faster
 it'll go
 */
void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
{
  if (motor <= 1)
  {
    if (direct <=4)
    {
      // Set inA[motor]
      if (direct <=1)
        digitalWrite(inApin[motor], HIGH);
      else
        digitalWrite(inApin[motor], LOW);

      // Set inB[motor]
      if ((direct==0)||(direct==2))
        digitalWrite(inBpin[motor], HIGH);
      else
        digitalWrite(inBpin[motor], LOW);

      analogWrite(pwmpin[motor], pwm);
    }
  }
}

regards, Volkan

How are the orange and while wires connected?

I dont have high rep , so I cant post more than 2 pictures, I have edited my post, Now you can clearly see my battery and its connector above. I have no componenets between the battery and the motor driver its just cables

I use JST connectors from battery to the blue screw terminals


text:
Remote temperature and humidity sensor with long battery life
I want to build a remote sensor which will measure temperature (range 5-30°C) and humidity (range 20-90%) and provide regularly (in the range of one measurement every minute or tenth of minutes) the measurement via wireless. This sensor will be used indoor, mostly in dark areas.
Note: measurement could be done every minutes and sending them could be done immediately or in batch of 10 measurements or more).
I was looking to build this solution using an Arduino, DHT22 sensor and a radio transmitter using ZigBee or Z-Wave protocol, and power it via AA rechargeable batteries. But after studying this solution, I found that it would be challenging to even get a week of battery life, this would require using the radio sparingly and to try to use as much as possible the power modes of the Arduino ATmel controller.
That's not enough, I want a battery life in the range of several months, 1 month would be "acceptable", 6 months would be the target, breakthrough would be > 1 year.
Note: I don't want wifi, this seems to suck even more power than the other mentioned radio protocol
Questions
Is there another more power efficient way to wireless-ly transmit the data?
Or shall I reconsider Arduino all together and look for another more power efficient controller?
Or is there another way?

I made a Temperature and humidity sensor - battery powered in 2013. It is powered from 3 x AA batteries, and lasted, as I recall, until a couple of months ago before I changed the batteries. That is, almost two years.
It logs to an SD card every 15 minutes. You could change that interval of course, it would probably not last as long logging every minute.

I certainly wouldn't attempt it with a pre-made board, because of the drain by the power LEDs, the USB chip, the voltage regulator, etc.
I measured 6 µA consumption when asleep.

Schematic

(RH-click and "View Image" to see a larger version)
The schematic is deliberately presented as "blocks" of parts of the circuit. To understand it from scratch, make up individual parts, test them and get the code working to your satisfaction. For example, the clock or the temperature sensor.
Some of the parts (like the clock) are already available as pre-assembled boards, if you prefer to reduce soldering.
You could manage without the 7-segment LED readout, however I found it useful for confirming it is working "in the field". The readout LEDs can be purchased cheaply from eBay for around $US 3. Search for MAX7219 8-Digit LED Display Module 7-Segment or similar.

Example output
Example of measuring temperature and humidity every minute:

You can see from the graph that I left the room at 9:30 pm, and the temperature slowly dropped until 6:30 am the next morning. The zig-zag effect is the central heating turning on and off.

Construction details
See the linked page for construction notes, schematic, and code.
Power saving details at Power saving techniques for microprocessors.

Estimated life at logging once a minute
If my calculations are correct, logging every minute might reduce battery life to 7 months (these things are best tested of course), but that is because the consumption is much higher when you power up the SD card. It would probably be best to take 15 readings, and then write to the card every 15 minutes. The extra time writing would be minimal, and that would keep the need to power up the card low.

The 7-segment LEDs
To clarify, those 8 LEDs are not normally on. The battery wouldn't last long if they were! If you press the switch it gives an immediate reading through the LEDs, and also tells you how many writes to disk it has done, and how many write errors it has had. This confirms all is operating properly.
The "busy" LED is there to warn you to not remove the SD card while it is writing to it.

Radio communication
To transmit information you could use a NRF24L01 transceiver module. You get those for a couple of dollars on eBay. Example:

Underneath:

You would need another one at the other end to receive (you would need two of whatever radio you chose).
I did a solar powered project using a couple of those. The NRF24L01 uses about 0.9 µA in power-down mode, so that is pretty minimal.
It also uses SPI, so the connections would be very similar to the SD card connector.
I suggest if you are going to attempt this to first get confident with a normal Uno, get the code tested, make sure you have the sleeping/waking going OK, then move it to a low-power board. There are places like Evil Mad Scientist that make "bare" boards, with a prototyping area, which you can use to put things like your temperature sensor on.

I'm new to hardware making, and this looks like complicated but doable with the right instructions. How do you "plan/design" such a board? Do you use special software to verify voltages, etc.? I'm asking because I would like to replace your SD card reader by a radio module (e.g. RFM12B or XBee) and I'm sure it is not just a swap of the 2 modules...

I just start simple and work my way up. The bare-bones board for example is described here and here. I don't "verify" voltages because they can't get much higher than the battery supplies. If you take it slowly and connect and check one thing at a time it should all be pretty easy.

See amended reply for details about radio transmission.

There is an excellent article on power reduction at http://www.gammon.com.au/power , but it's definitely worth looking at the parts of your project OTHER than the arduino - that is, your sensor, and your radio. These tend to use much more than your Arduino.
There is some persistent storage on the Arduino - EEPROM - write all your data to that as you read it, then send it all in bulk. Most of the time your radio will spend will be start/end communication.
Making your board is not as daunting as it seems. Use a breadboard to develop & test your project, then use stripboard (aka veroboard) to build your project. You can cut the tracks with a sharp utility knife, or with a specialized stripboard cutting tool (accurate & easier than a knife).
If you are still nervous, find your local makerspace or hackerspace - there are people there that would be happy to teach you to solder, and help you work out your ideas.

Sleep mode of a Zigbee is around 5uA. Power-down mode of an arduino is about the same. You can power the DHT22 via one of the digital pins, so it only uses power if you need it (though I thing you need to give it some time to "warm up"). So I don't see much of a problem. You just need to get the software working right.
Also, don't use an Uno, but one of the more bare-bones boards (e.g. Pro Mini) that don't have an usb-to-serial chip on board. Remove the power-led. Maybe remove the voltage regulator, and use 3 AAs for 4.5V.
I use blank ATMega328 chips, and build my own "arduinos" without all the unnecessary parts. I'm currently working on something similar, and plan on using an CR2032 coincell for power. >1 Year should be possible as far as I can see. If not I'll switch to AAs (11 times more power).

How do you design such hardware build? I know how to program, but putting electronic components together is "terra incognita" for me, e.g. I didn't know the UNO had a voltage regulator, and apart from a few clues I get from the name, I don't know what it does really. :-) So if I want to go the low level way, is there some nice resource where I can learn this stuff? (not just duplicating someone else project, but really understanding what I'm doing)

Have a look at the bareduino. The voltage regulator on the arduino takes any voltage above 5v and brings it down to a stable 5v by "burning off" the excess voltage. Kind of wasteful. It also requires current, even when nothing is connected (quiescent current). Not a lot, but when using batteries, it becomes significant. See Amadanon's answer about breadboards and stripboard/protoboards. You could use e.g. Fritzing if you like to design on you PC first.

If you first build on a breadboard (BB), you can fix a lot of mistakes for free, as long as no parts get damaged. Then you can choose whether to use PCBs that mimic the layout of a BB, or strip-board, which requires a little bit of re-laying out but may let you reduce the board size. In the US, Adafruit.com sells Perma-Proto boards, high-quality PCBs in 1/4, 1/2, and full-size BB layouts, so you can quickly transfer your design from the solderless BB to the PCB. I use both and I can recommend both approaches. The Perma-Proto wins on time to 1st prototype.


text:
Teensy: SPI and Pressure Sensor
I'm first time working with a Teensy 3.1. I have to connect this (MS5803-01BA: http://www.amsys.de/products/ms5803.htm) pressure sensor via SPI to my Teensy.
My problem is, that I don't have any reliable knowledge on SPI. I read the Wikipedia for it and also the Teensy-Manual.
For the pressure sensor I already got a C-Code but it is only working with the ATMEL ATmega644p microcontroller. I tried to get the code to work with my Teensy, but it seems like I don't get either any input nor any output.
I hope that one of you can help me with the following code and tell me what I'm missing out on. Thank you.
Code:
http://pastebin.com/xaWXfRUR
Datasheet of the pressure sensor:
http://www.amsys.de/sheets/amsys.de.ms5803_01b.pdf
C-Code for the pressure sensor for the ATMEL ATmega644p microcontroller:
http://www.amsys.de/sheets/amsys.de.an520_e.pdf

PS: Please excuse my not perfect English for it's not my native language.

Details about SPI at SPI - Serial Peripheral Interface - for Arduino
This isn't right:
  SPI.transfer(CMD_ADC_READ); // send ADC read command
  SPDR = SPI.transfer(0x00); // send 0 to read 1st byte (MSB)
  ret = SPDR;
  temp = 65536 * ret;
  SPDR = SPI.transfer(0x00); // send 0 to read 2nd byte
  ret = SPDR;
  temp = temp + 256 * ret;
  SPDR = SPI.transfer(0x00); // send 0 to read 3rd byte (LSB)

The SPI library handles SPDR for you. Writing to it yourself will corrupt its behaviour.
It should be more like:
  SPI.transfer(CMD_ADC_READ); // send ADC read command
  ret = SPI.transfer(0x00); // send 0 to read 1st byte (MSB)
  temp = 65536 * ret;
  ret = SPI.transfer(0x00); // send 0 to read 2nd byte
  temp = temp + 256 * ret;
  ret = SPI.transfer(0x00); // send 0 to read 3rd byte (LSB)

Ditto for elsewhere.

Was the answer helpful? If so, please accept it and possibly upvote it. This indicates to other users that you found the answer useful, and it also stops Stack Exchange from periodically "bumping" your question in the hope of getting an accepted answer.


text:
Background processes - Arduino Mega and SeeedStudio CAN shield
I am attempting to interface an Arduino Mega 2560 with a system of four Black Jaguar motor controllers connected in CAN. I'm using the CAN shield from SeeedStudios to accomplish this.
The way Jaguars in CAN mode are configured, you must send a message every 100 ms to the network to keep the link active. However, I'm also getting input from Serial to another Arduino as well as sending other commands to the Jaguars, but not regularly enough to specifically time it out.
Is it possible to have the link message sent asynchronously in the background while I perform other code? I have looked into timers and interrupts, however I am unsure if this would truly solve the issue considering I have other processes that take more than 100 ms to complete.
Here's my loop statement:
loop() {
  CAN.sendMsgBuf(HEARTBEAT,1,0,volModeEnable); //HEARTBEAT keeps CAN link active
  setVoltage(3,.5); //Sets voltage of Motor by percent
  setVoltage(4,.5);
  setVoltage(6,.5);
  setVoltage(8,.5);
  //GrabFromSerial(); Takes longer than 100ms
  //Control Statement for Additional Commands goes here... (also necessary to be > 100ms)
}

Just curious why does it take you more than 100ms to read the serial port?

Im using this library: https://github.com/madsci1016/Arduino-EasyTransfer to save me the trouble of writing my own serial protocol.   However i cant always garauntee it's time to execute because of the other arduinos timing.

I havnt looked at the library but perhaps it would be more simple to write your own protocol. Then you can use methods such as serial.available() that will tell you when data ia ready to be received without blocking the execution of your program

I see several options:

Change your code to achieve lower delays on the other functions
Use interrupts at a set frequency to trigger the sending (and maybe the automatic transmission trigger pins, see MCP2515 datasheet, depending on pin use & schematic of your specific shield)
Use a basic scheduler/rtos

It is hard to tell what is going on without the rest of your code, if it is a good idea to try to achieve faster functions.
I am not 100% sure the CAN-lib would will work well in the context of an interrupt.


text:
Arduino with NFC: Garbled Serial Monitor
I started working on a small programming project just for fun and I have got stuck. I have been using the following tutorial to make an Amiibo Music Box
Now using the libraries the tutorial suggested, I successfully uploaded the sketch to the device. However when I put an Amiibo or NFC card on top and look at the Serial Monitor, I get lots of garble and no sound.
¸ý×ÿòœy_ÿ#À–Yÿ›l°   _Yÿ8dÐa4’ÿ’Í�©ÿ›—Lµ›ú’áo°)h@’öþ8‚¤hþ:dÐ S4ê’ÉãÈô›l°É�°ò“ƒc¶ÿ™l±a“ùü8‚´hþ›l°É�´÷“ÅiØð
¶–t=Üý’ÉãÈôâd@àÉ‘ø8‚¤hþ
–e¼Õý’ÍÐPÿK¬ÀàÉ�ú8�·i™–e¼Õý8©Pòý’t=Üý“ƒf–ÿü’t=Ø9UY6þ›hX Cú’Í�©ÿ(l„±Ô_ü8‚´hþKìAÀò ý:‚´hþ8lÐaÓ4â’ÌcÈõ›hX Cú“ƒf–ÿKìEÀò ý’ÌiØõ8lÐaâtý“ƒ&–ÿè4@’âþ“ƒ&–ÿš’L²µšý8�·yÿ)l„úÈï’ÉãÈõ(l„±Ô_ü’ÍÙ:dÐ`S4ê2"´žþ)l„úÈï2"ßŸÿ›h±ÑªÛÖ’áoÞÿüÒt=Ø‘�&’ÿ�šA’âþ“ƒc¶þ›l±ÑªËÓ’Í�©ÿ8lÐaâtý’ÍÙ
––\5,ÿ’Í�©ÿè4@àâþ8©Pòý–t=Üý:‚´hþ
––t=Üý8‚´hþ8l€a¢tý’ÉãÈõš’L²µšýÜ,þÍ›þëÖÿÜ,þÜ,ÿÜ,ÿYÿ\ÿëòÿÜ,þêëòÿëòÿê4KÖÿ\ÿ]ÓÜ,ÿ\

I tried the card that comes with the kit and it does not work either. Has anyone got any idea why this has failed? I have put a link to the libraries and code I am using below.

https://github.com/ModusPwnin/Interactive-Amiibo-Stand
https://github.com/ModusPwnin/Interactive-Amiibo-Stand/blob/master/Amiibo%20Stand%20v3
https://github.com/adafruit/Adafruit_NFCShield_I2C
https://code.google.com/p/wavehc/

I am new to this but I want to understand why this is not working as well. Can anyone help me?


text:
Can't upload sketches to breadboard Arduino

I have an ATmega328 chip with the boot-loader installed.
I also have an Arduino Uno with the ATmega328 chip removed.
I hooked this chip up to a breadboard with the proper 22pF caps, 16MHz crystal, and 10kΩ pull-up resistor.
The LED flasher was loaded prior, and this works fine when I hook an LED and resistor up to pin 19. I have confirmed my external crystal works by disconnecting it, and the flashing stops, when I reconnect the crystal, the flashing continues.
Power is fed from my Arduino Uno 5 V out to the DIY Arduino
I connected the reset wire, and data wires, ensuring pin 2 went to RX and pin 3 to TX.

In the software
First to confirm everything works, I removed the chip from the breadboard and placed it in the Arduino. The sketch uploaded successfully using the settings:  Arduino Uno as board and AVRISP mkll as programmer.
Now I move the chip to the breadboard, and ensure all the wires are connected. The LED starts to blink again, but when I try to upload the sketch, I get an error:
avrdude: stk500_recv(): programmer is not responding
I ensure continuity between the reset, TX, RX, and power connections and try different settings like Arduino as ISP and different boards under settings including the Duemilanove and nano but nothing seems to be working.
Any suggestions on what to try next?

So you have 5 wires, right? 5V, Gnd, Tx, Rx and Reset? Stick to the Uno in the boards menu, after all it worked as a Uno when plugged in, didn't it? Can you post a photo please?

5 wires, works when chip is plugged into the socket.

Never mind, found the problem. My software switched to the bluetooth for some reason after I changed some other settings. Hate when the simple things always get me

Answered by Skyler440:

Never mind, found the problem. My software switched to the bluetooth for some reason after I changed some other settings.

Converted to answer to reduce unanswered questions.

@ChetanBhargava : Removed request. However is their a link for that assertion?

well, on raspberry pi SE, I did same thing and I was told my a mod not to do that. That was a while back on a chat session.

Found it here

There are two AVR ICs present on the Arduino board, one is used for the USB to ICSP interface and the other one is the μC which you're using.
As I've noticed that you've tried to connect Tx and Rx pins including reset for programming the IC. Those pins are used for communication on serial protocol, where as the AVR in Arduino is programmed using SPI Protocol, so you should be using MISO, MOSI, SCK, SS (they're pins 13-10 respectively) and Reset pins on the Arduino, then the AVR which is used as USB-SPI bridge for programming can communicate with the μC and program it.


text:
that no matter what the inputs are Motor1 always moves
int motor_forward1 = 7;
int motor_reverse1 = 6;
int motor_forward2 = 5;
int motor_reverse2 = 4;
int motor_forward3 = 3;
int motor_reverse3 = 2;
int sensor1 = A0;
int sensor2 = A1;

 void setup()
{

   pinMode(motor_forward1, OUTPUT);
   pinMode(motor_reverse1, OUTPUT);
   pinMode(motor_forward2, OUTPUT);
   pinMode(motor_reverse2, OUTPUT);
   pinMode(motor_forward3, OUTPUT);
   pinMode(motor_reverse3, OUTPUT);
   pinMode(sensor1, INPUT);
   pinMode(sensor2, INPUT);
 }

 void loop()
 {
   if (digitalRead(A0) == HIGH)
   {
     digitalWrite(motor_forward1,1);
     digitalWrite(motor_reverse1,0);
     delay(5000);
     digitalWrite(motor_forward1,0);
     digitalWrite(motor_reverse1,1);
     delay(5000);
     digitalWrite(motor_forward1,0);
     digitalWrite(motor_reverse1,0);
     delay(1000);
   }
   else if (digitalRead(A1) == HIGH)
   {
     digitalWrite(motor_forward2,1);
     digitalWrite(motor_reverse2,0);
     delay(5000);
     digitalWrite(motor_forward2,0);
     digitalWrite(motor_reverse2,1);
     delay(5000);
     digitalWrite(motor_forward2,0);
     digitalWrite(motor_reverse2,0);
     delay(1000);
   }
   else
   {
     digitalWrite(motor_forward3,1);
     digitalWrite(motor_reverse3,0);
     delay(5000);
     digitalWrite(motor_forward3,0);
     digitalWrite(motor_reverse3,1);
     delay(5000);
     digitalWrite(motor_forward3,0);
     digitalWrite(motor_reverse3,0);
     delay(1000);
   }
   delay(5000);
 }

Schematic here.

Could you add a little bit more than an un-formatted dump of code? Also circuit diagrams, possibly images... won't get closed then

@RSM before this I don't have any input and not using If else statement. My motor can rotate forward and reverse. after using if else statement my circuit not function correctly. How want to put image here?

An external link to the schematic is fine for now. I don't know why you're using a 5V regulator for each of the inputs - it seems a strange way of doing things. Proteus has some odd quirks, so pull each input to ground with a 10k resistor (between the switch and the Arduino) and see if that helps.

@RSM my push button in schematic circuit act as sensor. this software didn't have suitable sensor.

@CharlieHanson my sensor 5v at the input. my project using 2 sensor.

Be sure you if/else nestings are as you intend.

@RussellMcMahon I think switch/case and if/else most suitable in my project. I more understand using If/case. you have any idea about my project?

OK, that makes sense now, thank you. You say it doesn't function correctly - what does it do? It's very clear from the code what you want to happen, but we need to know what you're seeing. Update the question to say, for example, that no matter what the inputs are Motor2 always moves, or whatever it actually is.

@CharlieHanson my problem is when run the simulation and push the either button 1 or 2 only the motor1 always move. what I want in this project when push button 1 motor1 run forward and reverse and push button 2 the motor2 also run forward and reverse. the motor stop when the both button not push.

Looks like you use digitalRead to read analog pins A0, A1. Try changing to analogRead or using digital pins.

@tamberg I already change but it's didn't work. motor3 only run. I don't know what problem in my coding.

The code isn't wrong, it's far too simple to be at fault.
The error is from within Proteus. Those 'pushbutton' switches (and the other switch simulations) are not quite as straightforward as one would like. They have an OFF resistance, usually 100 Megaohms, but that's enough to trick the simulation into not behaving like it should do. You MUST pull the inputs to ground with a resistor - any sensible value will do as it's only required for the simulation. As they are, they're in some odd floating/magic/unknown state; common sense does not apply here!
An alternative is to swap the pushbutton for a SPDT switch; connect the common to the Arduino and the other contacts to the 7805 output and ground. You won't need the resistor in this case.

OK. Which code I need to use? mine code or need to replace "pinMode(sensor1, INPUT); pinMode(sensor2, INPUT);" to "pinMode(sensor1, INPUT_PULLUP); pinMode(sensor2, INPUT_PULLUP);"

I'd sick with the original code. Using INPUT_PULLUP will work but that places restrictions on the value of your external pulldown resistors. Nothing a bit of maths and datasheet-reading won't solve, but it's just extra work.


text:
Self-diagnose components in the circuit
How can I tackle self-diagnosis problem within my Arduino project?
For example, I have a temperature sensor and humidity sensor. How can I know if they work or not on Arduino start or inside the sketch loop?

You could get your program to output messages to the serial pin on your board, Tx. For example:
Serial.begin(9600) //baud rate of 9600

Serial.print("Debug Message");

You can use this to print out string and integers. Here is the link to further information on the Arduino website - https://www.arduino.cc/en/reference/serial
If you are already using the Serial pins then you could use the SoftwareSerial Library - https://www.arduino.cc/en/Reference/softwareSerial
This library allows you to make two other pins on your board Tx and Rx. For example:
SoftwareSerial mySerial(12,13) //Makes pin 12 Rx and pin 13 Tx

mySerial.begin(9600) //baud rate of 9600

mySerial.println("Debug Message");

To read the output from any of the pins on your arduino - use a USB to TTL serial cable. Plug it into your computer and use a program like PuTTY to connect to the serial cable and read the messages coming from the Arduino.

If you can define "it works" in code (e.g. the temperature is between X and Y degrees, and changes no faster than 2 degrees per second), and all you need is a "Yes" or a "No", then you can write this into code, then the easiest way is to use an LED. Make sure you blink it, rather than having it on steadily, so you can tell if it's frozen.
Make sure you try unplugging your sensor, to understand what it does when it fails; this is one thing you specifically want to test for.
If you specifically do not want to do this in your main loop, you can do an interrupt-driven version, but that adds a lot of complexity. I suggest you do it in your main loop if you can.
You can use the current time to blink the light regularly:
if (everything_is_working()) {
  if (millis()%10000<1000) {
     <turn led on>
  } else {
     <turn led off>
  }
}

The two numbers let you control the flashes. I've used 10,000 and 1,000; this means that out of every 10,000 millis (10 seconds), the led is on 1,000 millis (1 second). Depending on your preference, you can adjust these to your liking. You can also add an else clause which blinks a different pattern depending on what is wrong - 9 seconds on out of 10 for a problem with the humidity sensor, and 5 seconds out of 10 for the temperature sensor having issues.
If your sketch isn't running, the led will stay in it's current state - either on, or off, indefinitely. If your project has no power, the light will obviously be off.
If you want more data, you can either make more complex blink codes - short-long-short-long, for example - or add multiple lights, or even a three-colour LED, with different colours indicating different problems.

Another approach can be handy if you want to do detailed debugging (like outputting numbers) but your serial port is already in use for something, like a GPS. You can use a second Arduino as a "debugging interface" using SPI or I2C. For example, using SPI:

Or via I2C:

In these examples the "debugging" Uno also supplies power to the "main" Uno via the 5 V / Gnd pins.
I have a description about this method on Debugging using SPI/I2C and a second processor. Code is available at: http://gammon.com.au/Arduino/SPI_Debugging.zip and http://gammon.com.au/Arduino/I2C_Debugging.zip .
To demonstrate the idea, on the "main" Uno this is an example of sending debugging info via SPI:
// make true to debug, false to not
#define DEBUG true

#include <SPI.h>

// conditional debugging
#if DEBUG

  #define beginDebug()  do { SPI.begin (); SPI.setClockDivider(SPI_CLOCK_DIV8); } while (0)
  #define Trace(x)      SPIdebug.print   (x)
  #define Trace2(x,y)   SPIdebug.print   (x,y)
  #define Traceln(x)    SPIdebug.println (x)
  #define Traceln2(x,y) SPIdebug.println (x,y)
  #define TraceFunc()   do { SPIdebug.print (F("In function: ")); SPIdebug.println (__PRETTY_FUNCTION__); } while (0)

  class tSPIdebug : public Print
  {
  public:
    virtual size_t write (const byte c)
      {
      digitalWrite(SS, LOW);
      SPI.transfer (c);
      digitalWrite(SS, HIGH);
      return 1;
      }  // end of tSPIdebug::write
  }; // end of tSPIdebug

  // an instance of the SPIdebug object
  tSPIdebug SPIdebug;

#else
  #define beginDebug()  ((void) 0)
  #define Trace(x)      ((void) 0)
  #define Trace2(x,y)   ((void) 0)
  #define Traceln(x)    ((void) 0)
  #define Traceln2(x,y) ((void) 0)
  #define TraceFunc()   ((void) 0)
#endif // DEBUG

long counter;
unsigned long start;

void setup() {
  start = micros ();

  beginDebug ();
  Traceln (F("Commenced device-under-test debugging!"));
  TraceFunc ();  // show current function name

}  // end of setup

void foo ()
  {
  TraceFunc (); // show current function name
  }

void loop()
{

  counter++;
  if (counter == 100000)
  {
    Traceln (F("100000 reached."));
    Trace (F("took "));
    Traceln (micros () - start);
    counter = 0;
    foo ();
  }  // end of if

}  // end of loop

If DEBUG is true then the debugging prints are activated. Otherwise they turn into "no code".
The receiving end looks like this:
volatile char buf [1000];
volatile int inpoint, outpoint;

void setup (void)
{
  Serial.begin (115200);   // debugging

  Serial.println ();
  Serial.println (F("Commencing debugging session ..."));
  Serial.println ();

  // have to send on master in, *slave out*
  pinMode(MISO, OUTPUT);

  // turn on SPI in slave mode
  SPCR |= bit (SPE);

  // now turn on interrupts
  SPCR |= bit (SPIE);

}  // end of setup

// SPI interrupt routine
ISR (SPI_STC_vect)
{
byte c = SPDR;  // grab byte from SPI Data Register
int next = inpoint + 1;  // next insert point

  // wrap-around at end of buffer
  if (next >= sizeof buf)
    next = 0;

  if (next == outpoint)  // caught up with removal point?
    return;  // give up

  // insert at insertion point
  buf [inpoint] = c;
  inpoint = next;  // advance to next

}  // end of interrupt routine SPI_STC_vect

void loop (void)
{
  // insertion and removal point the same, nothing there
  noInterrupts ();  // atomic test of a 16-bit variable
  if (outpoint == inpoint)
    {
    interrupts ();
    return;
    }
  interrupts ();

  // display anything found in the circular buffer
  Serial.print (buf [outpoint]);

  noInterrupts ();
  if (++outpoint >= sizeof buf)
    outpoint = 0;  // wrap around
  interrupts ();

}  // end of loop

There is a 1000 byte buffer which will cope with bursts of incoming data, which is then sent out the serial port on the debugging Uno (that is, to your serial monitor).
The linked library above includes code for SPI and I2C debugging interfaces.

Having said that, the simplest thing is just to do serial debugging prints inside your code on the main device, if that is practical.
Remember to use the F() macro, or your debugging code might take up so much RAM it causes a crash.
eg.
Serial.println (F("Temperature sensor working."));


text:
Printing SD card file contents on LCD

This is a part of my program which reads data from file stored in SD card and displays that on an LCD screen.
  File dataFile = SD.open("1165.txt");

  if (dataFile) {
    Serial.println("File Opened");
    lcd.clear();
       delay( 5 );  //LCD-specific M
       lcd.setCursor( 0,0 );

  while (dataFile.available()) {
      Serial.write(dataFile.read());
      lcd.write(dataFile.read());
      lcd.print(dataFile.read());
    }
  dataFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error");
  }

When I look at the serial monitor it prints the contents of that file but none of these commands print what is printed in the serial monitor,
lcd.write(dataFile.read());
lcd.print(dataFile.read());

Any ideas?

When you call dataFile.read(), the file pointer is advanced, so you always read different bytes in each read call. Imagine the file like a book with many lines: Each time you read, you advance the current line, so with multiple calls, you never get the same data. The solution is to currently store the last read byte:
while (dataFile.available()) {
  char readByte = dataFile.read();
  Serial.write(readByte);
  lcd.write(readByte);
  lcd.print(readByte);
}

You have two calls for displaying data in the LCD, but be careful that the second call (print) might interpret your data as a number, so just remove the lcd.print(readByte) call altogether to be sure it's printing the raw character.

You could also implement a readLine routine, similar to:
void _readLine(File f, char *line)
{
    boolean cr_found = false;
    int p = 0;
    while (f.available()) {
        char b = f.read();
        if(b!='\r' && b!='\n')
            line[p++] = b;

        if(b == '\r') cr_found = true;
        if((b == '\n') && cr_found) break;
    }
    line[p] = '\0';
}

And read the SD file line by line, processing each one of them by its own.
char buffer[32];

while(dataFile.available()) {
    _readLine(dataFile, buffer);
    // do something with buffer
}


text:
nRF2401 communication (extended vs normal)
Communicating to the antenna-less version from an extended range nRF2401 seems to produce some strange results...
At a distance, the receiver seems to receive a number of values instead of one. For example, if I send a 1, I will receive a 1, but 30 times.
Has anyone had experience communicating across the two models, or is it just best practice to stick to communicating across same models? (Short range <-> short range, long range <-> long range)?

I've run both version fine together
Your symptom of receiving the same value 30 times would be related to a failed ACK, so the sender thinks it hasn't been received and resends it.
I've had potentially similar problems with the power amplified version running at full power causing interference in nearby circuity, try dialling down the power setting on it.

I agree. I've used one with an aerial and one without, with no problems.

When you say try dialing down the power, what do you mean? It's running at 3.3v, which is the prescribed voltage. I'm using the rf24network library for what it's worth. Thanks for the help

Use RF24::setPALevel

Yes i meant power amplifier setting

Setting the power level didn't seem to have an effect on the issue. Can you elaborate on the failed ACK? Maybe that's actually what I'm dealing with. The issue only seems to occur at a distance, but not an unreasonable distance. I have two antennae-less nrf2401's that communicate fine from the same range.

So you tried setting the PA level on the external antenna based one to lower than default. ACK is short for 'acknowledgement' and is the receiving device sending back a message automatically to confirm it got the message.  Try this fork of rf24, i had better results with it after initially having trouble with the original.

I don't see a link, did you paste it? Thanks again for the help.

sorry , here it is: http://maniacalbits.blogspot.com.au/2013/04/new-rf24-driver-release-fork.html

@jmwagg What library were you using? Also, are you aware that clone modules may lack proper ACK functionality?


text:
Arduino UNO not working?
Recently I assembled my Shapeoko machine, we used Grbl shield with an Uno for the same.
For 1-2 weeks everything worked perfectly then once when I tried to work the machine, the serial communication was not working. I tried to replace the 16 MHz oscillator because I thought the problem might be with the oscillator since the LEDs were not blinking but they were lighting up.

Please visit Have I bricked my Arduino Uno? and see if the steps suggested there help solve your problem.

Did you mean 16MHz and not 16Hz?

Maybe the 5v regulator? Hard to say without the symptoms.


text:
Want to add an LCD display screen for the output motor
I want add an LCD display screen at output motor. When the motor runs the LCD display show like "motor 1 run forward" and "motor 1 run reverse". I want it display for all motor but I don't know how code using arduino using 16x2 LCD display screen.
int motor_forward1 = 7;
int motor_reverse1 = 6;
int motor_forward2 = 5;
int motor_reverse2 = 4;
int motor_forward3 = 3;
int motor_reverse3 = 2;
int sensor1 = 13;
int sensor2 = 12;

 void setup()
{

   pinMode(motor_forward1, OUTPUT);
   pinMode(motor_reverse1, OUTPUT);
   pinMode(motor_forward2, OUTPUT);
   pinMode(motor_reverse2, OUTPUT);
   pinMode(motor_forward3, OUTPUT);
   pinMode(motor_reverse3, OUTPUT);
   pinMode(sensor1, INPUT);
   pinMode(sensor2, INPUT);
 }

 void loop()
 {
   if (digitalRead(13) == HIGH)
   {
     print
     digitalWrite(motor_forward1,1);
     digitalWrite(motor_reverse1,0);
     delay(5000);
     digitalWrite(motor_forward1,0);
     digitalWrite(motor_reverse1,1);
     delay(5000);
     digitalWrite(motor_forward1,0);
     digitalWrite(motor_reverse1,0);
     delay(1000);
   }
   else if (digitalRead(12) == HIGH)
   {
     digitalWrite(motor_forward2,1);
     digitalWrite(motor_reverse2,0);
     delay(5000);
     digitalWrite(motor_forward2,0);
     digitalWrite(motor_reverse2,1);
     delay(5000);
     digitalWrite(motor_forward2,0);
     digitalWrite(motor_reverse2,0);
     delay(1000);
   }
   else
   {
     digitalWrite(motor_forward3,1);
     digitalWrite(motor_reverse3,0);
     delay(5000);
     digitalWrite(motor_forward3,0);
     digitalWrite(motor_reverse3,1);
     delay(5000);
     digitalWrite(motor_forward3,0);
     digitalWrite(motor_reverse3,0);
     delay(1000);
   }
   delay(5000);
 }

Other than the LiquidCrystal library?

From this instructable:
// include the library code:
#include <LiquidCrystal.h>

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

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print(" **Text for line 1 of LCD**");
  lcd.setCursor(0, 1);
  lcd.print(" **Text for line 2 of LCD**");
  // THE REST OF YOUR SETUP
}

void loop() {
    if (digitalRead(13) == HIGH) {
        // I assume this is the motor going forward
        lcd.print("motor 1 run forward");
    }
}

"Install" is a bit facetious though, since it comes with the IDE these days.

Wasn't aware of that :)

@circuitBurn Thanks for your code. But I have used arduino pin 5,4,3 and 2. need connect parallel to LCD screen?


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

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

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

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

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

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

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

Never underestimate the capabilities of NOS.

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

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

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

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

Other vendors will probably have similar products.

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

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

The ultimate solution would be to build it yourself!

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

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

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