text:
deprecated conversion from string constant to 'char*'
What does this error means?
I can't solve it in any way.

warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

This question should be on StackOverflow, not Arduino :)

As is my wont, I'm going to provide a bit of background technical information into the whys and wherefores of this this error.
I'm going to inspect four different ways of initializing C strings and see what the differences between them are.  These are the four ways in question:
char *text = "This is some text";
char text[] = "This is some text";
const char *text = "This is some text";
const char text[] = "This is some text";

Now for this I am going to want to change the third letter "i" into an "o" to make it "Thos is some text".  That could, in all cases (you would think), be achieved by:
text[2] = 'o';

Now let's look at what each way of declaring the string does and how that text[2] = 'o'; statement would affect things.
First the most commonly seen way: char *text = "This is some text";.  What does this literally mean?  Well, in C, it literally means "Create a variable called text which is a read-write pointer to this string literal which is held in read-only (code) space.".  If you have the option -Wwrite-strings turned on then you get a warning as seen in the question above.
Basically that means "Warning: You have tried to make a variable that is read-write point to an area you can't write to".  If you try and then set the third character to "o" you would in fact be trying to write to a read-only area and things won't be nice.  On a traditional PC with Linux that results in:

Segmentation Fault

Now the second one: char text[] = "This is some text";.  Literally, in C, that means "Create an array of type "char" and initialize it with the data "This is some text\0". The size of the array will be big enough to store the data".  So that actually allocates RAM and copies the value "This is some text\0" into it at runtime.  No warnings, no errors, perfectly valid.  And the right way to do it if you want to be able to edit the data.  Let's try running the command text[2] = 'o':

Thos is some text

It worked, perfectly.  Good.
Now the third way: const char *text = "This is some text";.  Again the literal meaning: "Create a variable called "text" that is a read only pointer to this data in read only memory.".  Note that both the pointer and the data are now read-only.  No errors, no warnings. What happens if we try and run our test command?  Well, we can't.  The compiler is now intelligent and knows that we are trying to do something bad:

error: assignment of read-only location ‘*(text + 2u)’

It won't even compile.  Trying to write to read-only memory is now protected because we have told the compiler that our pointer is to read-only memory.  Of course, it doesn't have to be pointing to read-only memory, but if you point it to read-write memory (RAM) that memory will still be protected from being written to by the compiler.
Finally the last form: const char text[] = "This is some text";.  Again, like before with [] it allocates an array in RAM and copies the data into it.  However, now this is a read-only array.  You can't write to it because the pointer to it is tagged as const.  Attempting to write to it results in:

error: assignment of read-only location ‘*(text + 2u)’

So, a quick summary of where we are:
This form is completely invalid and should be avoided at all costs.  It opens the door to all sorts of bad things happening:
char *text = "This is some text";

This form is the right form if you are wanting to make the data editable:
char text[] = "This is some text";

This form is the right form if you want strings that won't be edited:
const char *text = "This is some text";

This form seems wasteful of RAM but it does have its uses.  Best forget it for now though.
const char text[] = "This is some text";

It is worth noting that on the Arduinos (the AVR-based ones at least), string literals live in RAM, unless you declare them with a macro like PROGMEM, PSTR() or F(). Thus, const char text[] does not use more RAM than const char *text.

Teensyduino and many other more recent arduino-compatibles automatically place string literals in code space, so it's worth checking to see whether or not F() is needed on your board.

@Craig.Feied In general F() should be used regardless. Those that don't "need" it tend to define it as a simple (const char *)(...) casting. No real effect if the board doesn't need it, but a big saving if you then port your code to a board that does.

To elaborate on Makenko's excellent answer, there is a good reason why the compiler warns you about this. Let's make a test sketch:
char *foo = "This is some text";
char *bar = "This is some text";

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();
  foo [2] = 'o';     // change foo only
  Serial.println (foo);
  Serial.println (bar);
  }  // end of setup

void loop ()
  {
  }  // end of loop

We have two variables here, foo and bar. I modify one of those in setup(), but see what the result is:
Thos is some text
Thos is some text

They both got changed!
In fact if we look at the warnings we see:
sketch_jul14b.ino:1: warning: deprecated conversion from string constant to ‘char*’
sketch_jul14b.ino:2: warning: deprecated conversion from string constant to ‘char*’

The compiler knows this is dodgy, and it is right! The reason for this is, that the compiler (reasonably) expects that string constants don't change (since they are constants). Thus if you refer to the string constant "This is some text" multiple times in your code it is allowed to allocate the same memory to all of them. Now if you modify one, you modify all of them!

Holy Smoke! Who would have known... Is this still true for latest ArduinoIDE compilers? I just tried it on an ESP32 and it causes repeated GuruMeditation errors.

@not2qubit I just tested on Arduino 1.8.9 and it is true there.

The warnings are there for a reason. This time I got: warning: ISO C++ forbids converting a string constant to 'char' [-Wwrite-strings]
char bar = "This is some text"; - FORBIDS is a strong word. Since you are forbidden to do that, the compiler is free to muck around and share the same string over two variables. Don't do forbidden things! (Also, read and eliminate the warnings). :)

So in case you come across crappy code like this, and want to survive the day. Would an initial declaration of *foo and *bar using different string "constants", prevent this from happening? Also, how is this different from not putting any strings at all, like: char *foo;?

Different constants might help, but personally I wouldn't put anything there, and put data there in the usual way later (eg. with new, strcpy and delete).

Either stop trying to pass a string constant where a function takes a char*, or change the function so that it takes a const char* instead.
String like "random string" are constants.

Is a text like "random characters" a constant char?

String literals are string constants.

Example:
void foo (char * s)
  {
  Serial.println (s);
  }

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();
  foo ("bar");
  }  // end of setup

void loop ()
  {
  }  // end of loop

Warning:
sketch_jul14b.ino: In function ‘void setup()’:
sketch_jul14b.ino:10: warning: deprecated conversion from string constant to ‘char*’

The function foo expects a char* (which it can therefore modify) but you are passing a string literal, which should not be modified.
The compiler is warning you not to do this. Being deprecated it might turn from a warning into an error in a future compiler version.

Solution: Make foo take a const char *:
void foo (const char * s)
  {
  Serial.println (s);
  }

I don't get it. Do you mean can not be modified?

Older versions of C (and C++) let you write code like my example above. You could make a function (like foo) that prints something you pass down to it, and then pass down a literal string (eg. foo ("Hi there!");)
However a function that takes char * as an argument is allowed to modify its argument (ie. modify Hi there! in this case).
You might have written, for example:
void foo (char * s)
  {
  Serial.println (s);
  strcpy (s, "Goodbye");
  }

Unfortunately, by passing down a literal, you have now potentially modified that literal so that "Hi there!" is now "Goodbye" which is not good. In fact if you copied in a longer string, you might overwrite other variables. Or, on some implementations you would get an access violation because "Hi there!" might have been put in read-only (protected) RAM.
So the compiler-writers are gradually deprecating this usage, so that functions to which you pass down a literal, must declare that argument as const.

Is it a problem if I don't use a pointer?

What sort of problem? That particular warning is about converting a string constant into a char* pointer. Can you elaborate?

@Nick: What do you mean "(..)you are passing a string literal, which should not be modified". I don't get it. Do you mean can not be modified?

I modified my answer. Majenko covered most of these points in his answer.

I have this compilation error:
TimeSerial.ino:68:29: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   if(Serial.find(TIME_HEADER)) {

                         ^

Please replace this line:
#define TIME_HEADER  "T"   // Header tag for serial time sync message
with this line:
#define TIME_HEADER  'T'   // Header tag for serial time sync message
and compilation goes well.

This change changes the define from a one character string "T" to a single character with the value of the ASCII code for the letter capital T.


text:
Empty char variable
How do I empty all the values inside a variable char array[256];?
I tried a for loop assigning an empty value at each iteration, but it doesn't compile.

Please post this loop.

You can't "empty" an array, you can only fill it with meaningless values.

char array[256];

...

int i;
for( i=0; i<256;i++ ) {
    array[i] = 0x00;
}

There is a single-line command you can use:
memset(array, 0, 256);

Or memset(array, 0, sizeof array); preferably.

@NickGammon Assuming you are using "array" directly, and not in a function which has a pointer passed to it.  Better is to use a #define or a const int for both the array size and the memset length.

Quite right, for a pointer that is correct.

source: Stack Exchange

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

sort: votes


text:
Issue with time-dependant conditional I/O control flow (Arduino UNO)
We are working on a project to control the reaction of a system to a lever, whose position is monitored by two IR sensors at the ends of its travel, the Reward sensor and the Trigger sensor.
There are three modes of action:
Mode1: lever has to start at TriggerSensor, and a success is recorded if and when the lever is moved to RewardSensor
Mode2: lever starts at TriggerSensor and has to be held for 4 seconds. At the end of this interval a tone is played for 2 seconds, the reward interval. Within this 2 seconds, if the lever is moved to the RewardSensor, a success is recorded.
Mode3: same as Mode2, but the initial 4 second timeout is of random length.
We also want to use the following lines:
digitalWrite(TriggerSensorOut, digitalRead(TriggerSensorIn));  //This is to record to our computer the states of the trigger sensor
  digitalWrite(RewardSensorOut, digitalRead(RewardSensorIn));  //This is to record to our computer the states of the reward sensor
to constantly write the state of both sensors to our computer. However, this doesn't work as planned: there are delays between the execution of the mode functions (as described in full code below).Essentially, we are struggling to come up with a suitable way to time things correctly.
Please see full code below
// -----LIBRARIES

//#include <elapsedMillis.h>

// ----CONSTANTS (won't change)

const int TriggerSensorIn = 2;   //  Input from trigger sensor, LOW = broken
const int RewardSensorIn = 3;    //  Input from reward sensor, LOW = broken
const int ModeStateIn1 = 4;      //  Input 1 from switch to define paradigm mode
const int ModeStateIn2 = 5;      //  Input 2 from switch to define paradigm mode
const int RewardSignalOut = 12;   //  Output signal of reward, parallel taken off to counter module
const int ServoResetOut = 6;     //  Servo reset output signal
const int ToneOut = 10;          //  Audio stimulus
const int TriggerSensorOut = 7;  //  Output from trigger sensor for DAC board recording
const int RewardSensorOut = 8;   //  Output from reward sensor for DAC board recording

//------- VARIABLES (will change)

boolean backPressed = false;

int timeoutWindow = 4000;    // 4 second preliminary interval
int rewardWindow = 2000;    // 2 second reward interval

unsigned long currentMillis = 0;

//===============

void setup() {

  // initialise the digital pins as inputs and outputs

  pinMode(TriggerSensorIn, INPUT);
  pinMode(RewardSensorIn, INPUT);
  pinMode(ModeStateIn1, INPUT);
  pinMode(ModeStateIn2, INPUT);

  pinMode(RewardSignalOut, OUTPUT);
  pinMode(ServoResetOut, OUTPUT);
  pinMode(ToneOut, OUTPUT);
  pinMode(TriggerSensorOut, OUTPUT);
  pinMode(RewardSensorOut, OUTPUT);

}

//===============

void giveReward() {
  // This function is the protocol for recording a reward
  currentMillis=millis();
  digitalWrite(RewardSignalOut, HIGH);
  while (millis()>currentMillis+200) {
    digitalWrite(RewardSignalOut, LOW);
  }
}

//===============

void servoReset() {
  // This function is the protocol for resetting servos after a failed action
  currentMillis=millis();
  digitalWrite(ServoResetOut, HIGH);
  while (millis()>currentMillis+200) {
    digitalWrite(ServoResetOut, LOW);
  }
}

//===============

void mode1() {
  // This function is the protocol for controlling the system during mode 1, no time constraint on the action
  if (digitalRead(TriggerSensorIn == LOW)) {
    backPressed = true;

    if (backPressed == true && digitalRead(RewardSensorIn == LOW)) {
      giveReward();
      backPressed = false;
    }
  }
}

//===============

void mode2() {
  if (digitalRead(TriggerSensorIn == LOW)) {
    currentMillis=millis();
    while (digitalRead(TriggerSensorIn == LOW)) {
      while (millis() > currentMillis + timeoutWindow) {
        tone(ToneOut, 3000, 2000);
        {
          goto rewardSeeking2;
        }
      }
    }

rewardSeeking2:
    currentMillis=millis();  // reset timer
    if (millis() < (currentMillis + rewardWindow) && digitalRead(RewardSensorIn == LOW)) {
      giveReward();
    }
    else if (millis() > (currentMillis + rewardWindow)) {
      servoReset();
    }
  }
}

//===============

void mode3() {
  timeoutWindow=random(1000,5000);
  if (digitalRead(TriggerSensorIn == LOW)) {
    currentMillis=millis();
    while (digitalRead(TriggerSensorIn == LOW)) {
      while (millis() > currentMillis + timeoutWindow) {
        tone(ToneOut, 3000, 2000);
        {
          goto rewardSeeking3;
        }
      }
    }

rewardSeeking3:
    currentMillis=millis();  // reset timer
    if (millis() < (currentMillis + rewardWindow) && digitalRead(RewardSensorIn == LOW)) {
      giveReward();
    }
    else if (millis() > (currentMillis + rewardWindow)) {
      servoReset();
    }
  }
}

//===============

void loop() {

  digitalWrite(TriggerSensorOut, digitalRead(TriggerSensorIn));  //This is to record to our computer the states of the trigger sensor
  digitalWrite(RewardSensorOut, digitalRead(RewardSensorIn));  //This is to record to our computer the states of the reward sensor

  if (digitalRead(ModeStateIn1) == LOW && digitalRead(ModeStateIn2) == LOW) {
    // Using the two mode selective switches to define mode1
    mode1();
  }

  else if (digitalRead(ModeStateIn1) == LOW && digitalRead(ModeStateIn2) == HIGH) {
    // Using the two mode selective switches to define mode2
    mode2();
  }

  else if (digitalRead(ModeStateIn1) == HIGH && digitalRead(ModeStateIn2) == LOW)  {
    // Using the two mode selective switches to define mode3
    mode3();
  }
}

//===============END

while (millis() > currentMillis + timeoutWindow) looks wrong to me. I'd think the > should be a < .

Even with a < it would be wrong because of the millis() rollover. The right way to write that would be while (millis() - currentMillis < timeoutWindow).

Goto?  GOTO?!?!?!?!  AAAAAARRRRRGGGHHHH!!!!!!  NO!!!!!

what would you recommend using instead of GOTO, just use break?

Well, goto has its use, see for example the way in the linux kernel device drivers undo partial initialization, when some intermediate test fails.
However here its use seems strange: it's inside a while loop that actually gets executed only once (therefore it could be turned into and "if").
And the execution breaks out of the outer while when the inner condition is verified. Since it's not possible to add readable code to a comment here, I'll try to put it in a separate answer.

Virtually nobody (maybe excepting Linux kernel device driver authors) should need to use goto. It leads to Spaghetti code.

This is a snippet of how I would refactor the code:
void mode3() {
  int timeout = millis() + random(1000,5000);
  while (digitalRead(TriggerSensorIn == LOW) &&
         millis() < timeout) {
  };
  if (digitalRead(TriggerSensorIn == LOW) &&
         millis() > timeout) {
     tone(ToneOut, 3000);
     timeout = millis() + rewardWindow;
     while (millis() < timeout)
       if (digitalRead(RewardSensorIn == LOW)
         giveReward();
  }
  noTone();
}

....
void loop() {
  // This is to record to our computer the states of
  // the trigger sensor
  digitalWrite(TriggerSensorOut, digitalRead(TriggerSensorIn));

  // This is to record to our computer the states of
  // the reward sensor
  digitalWrite(RewardSensorOut, digitalRead(RewardSensorIn));

  int msin1 = digitalRead(ModeStateIn1);
  int msin2 = digitalRead(ModeStateIn2);

  if (msin1 == LOW)
      if (msin2 == LOW)
          mode1();
      else
          mode2();
  else if (msin2 == LOW)
    mode3();
}

But I think you should first try to write it down in plain English and verify that at least that algo works.
Then you can think how to transpose it into code.

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


text:
Two motors in one set of pins/plugs
I have been putting together a small robot using an Arduino Motor Shield R3. The shield has two sockets for motors, however the wheel carriage I bought has four motors. I tried putting both right side motors in one socket set, and the left side motors in the other socket set.
When I turn on the Arduino, the left side motors turn together according to how I coded the board, however the right side behaves differently.
One of the motors does not start. If I push it a little it will start turning. Though not always. When I plugged in the misbehaving motor by itself, it runs correctly.
I am wondering about cause of the problem here. Is it likely the second motor on the right side is faulty? Or am I trying to use up too much power and disrupting the current?

What are the ratings of the motors you are using?

This is the info I have from a website, the motors themselves did not come with this.Operating voltage: 3V~12VDC (recommended operating voltage of about 6 to 8V)

Maximum torque: 800gf cm min (3V)
No-load speed: 1:48 (3V time)
the load current: 70mA (250mA MAX) (3V)
This motor with EMC, anti-interference ability. The microcontroller without interference.

Sometimes two motors in parallel causes this problem - the stall current of one motor causes the overall voltage to drop under load and stops the other motor from starting. So that second motor is probably NOT faulty. You might need a higher current battery (but the same voltage), it also might help to make sure the power supply to the arduino and the shield are separate - that shield seems to have a jumper for that. Best, but expensive solution would be to have separate drivers for each motor...

Do you have a DMM (digital multi-meter) available? It would help to take the guesswork out of troubleshooting problems like this. Even a cheap one is better than no meter.

@radiobrain77, one other thing. What voltage battery are you using? (The motor driver you are using may drop a little bit of voltage before it gets to the motors.) Also is there a "Stall current" for your motors,and if so what is it?

The drive capacity of the Motor Shield should match the motors – two of the motors. The shield was probably designed for a load of one motor, and you're giving two, so it is possible that neither of the motors on that side is getting enough current to get started. Here are somethings to check to get started:

Find the drive capacity of the Motor Shield and compare it to the motors (if you don't have specs for the motors you could measure the current they draw if you have an DMM). It might be wise to measure the current anyway, just in case you have a defective motor or shield.
If the capacity or the current draw is out of line, that's your problem. You can probably just add a power transistor to the circuit to drive the motors in this case.
Try it with just one motor on each output and see if they run normally. If they do, that would suggest a loading problem or a defective motor or shield. You can sort out which is which by swapping sides – if one motor runs and the other doesn't, swap them. If the problem follows the motor, then blame the motor, otherwise blame the shield.


text:
Arduino Uno powers off when circuit plugged in to +5V and GND pins
I have a max7219 driving an 8 digit 7 segment LED array with forward current of 20mA and typical forward voltage of 1.85V. I'm trying to power this through my arduino UNO (which itself is drawing power from USB), and have the max7219 chip's +5V and ISet(+resistor) and ground pins connected to the respective pins on the arduino.  When I try to plug this in, the arduino will not power up, but removing the jumpers from +5V and GND allows the arduino to power up.
I have confirmed with my multimeter that there is no short between any of the power cables on my led circuit.
The voltage supplied by the arduino works normally if I connect it up to a simple resistor and led on a breadboard.
The voltage across the +5V & GND pins on the arduino drops from 5V to 0V if the jumpers are inserted whilst the arduino is powered up.
I thought perhaps the circuit was trying to draw too much power from the USB, so tried higher resistor values than my initial resistor (20K), to no effect.
What else could be causing this?

Are you running the Arduino direct from the computer's USB port or from a USB hub?  If the latter, is it a powered or an unpowered hub?

Your circuit is using to much power. This will trip the resettable fuse on the Arduino. That's why 5v will go to 0v. Since the max7219 shouldn't draw the 500mA needed to trip the fuse, you probably miswired something. Could you add a picture of your wiring?

@Gerben It may not be. It may be the USB host port being shut down through too much current draw. An unpowered hub will (should) shut down at more than just 100mA.

@Majenko Different result, but still the same cause. PS I've seen unpowered hub with no fuses at all. And motherboards with 900mA fuses (2 ports per fuse I think; maybe).

It's a usb3 port directly from the mobo. The general consensus is too much current draw, which is what i suspected. Now to work out why...I don't think a picture will help much - the circuits on two sided protoboard and a lot of wires are hidden under the displays. I must have miswired something, perhaps transposed the max +5v and Iset wires. That could explain it. Thanks for the comments.

@Gerben It doesn't have to be a fuse - most commonly it's active power switching managed by the hub chip.  Also 900mA is fine for CDP - in fact it may be a little low ;)

Active power management in an external hub (especially enforcing a 100mA limit) is theoretically possible, but quite rare.  Most have polyfuses, at most.

I'm voting to close this question as unanswerable as the poster's rebuilding of the circuit demonstrated that it was a transient wiring fault, not anything a stack exchange site can help with.

and have the ... ISet(+resistor) and ground pins connected to the respective pins on the arduino.

What pin on the Arduino?
The ISet resistor should go to +5 V - don't connect it to an Arduino pin (unless you mean the +5 V Arduino pin). See diagram:

I had a 7-segment display working fine on an Arduino via the USB, see photo:

More details here: Interfacing LED displays with the MAX7219 driver

Sorry for the confusion. I did indeed mean that ISet was connected to the +5V pin on the arduino. I managed to get it going fine on a breadboard, I guess I must have shorted something when wiring/soldering my final board.
However, my circuit doesn't include the capacitors in the top left of your schematic (and indeed I don't see them in your photo). What purpose do they serve?

You are right, I didn't have them. However they are in the schematic as the standard recommended decoupling capacitors - read the link for more information. The larger one provides an "energy well" to cope with fluctuations in the supply voltage over the connecting wires, the smaller one smooths out sudden spikes in Vcc which might cause the digital logic to misbehave.


text:
Console monitor on different wifi network
I have a Yun doing data logging. It runs nicely and when I am on the same wifi network I can use the Console Monitor to watch what it is doing in more detail. However, my arduino is deployed far from me so it generally isn't possible to get on the same wifi network to monitor the console.
Is there a way to monitor the console from a different wifi network?

The Yun is just an ordinary network device.  However, the tools you are provided with use a system called mDNS to find the Yun.  That only works across the same local subnet that you are on.
If the Yun is on a different subnet then you will have to (assuming the routing between subnets is working fine) do it manually by knowing the IP address of your Yun.  Use that IP address in place of "arduino.local" or whatever your Yun is called.

Please note that you will have to port forward on your router/firewall, although that is beyond the scope of this site.

So if I would be starting with googling "IP address lookup" and "router port forwarding", the answer is probably that it would take more than a few hours to set up?

If you have to google those terms, then yes, probably.  If you know what they are and how to configure your router(s) then it won't take long.  If the two network segments are isolated by NAT then you will need some form of tunnelling mechanism to get from one segment to the other, such as port forwarding (and connect to the router not the Yun) or a VPN.


text:
Disabling i2c internal pull up resistors
How do you do this? I've been digging around and I can see that I should do this and supply my own external pull up resistors but I don't know exactly how to disable them. The pages I've been reading never explicity state how.
I'm trying to enable I2C between a leonardo and an uno, but I think the i2c bus is slowing down considerably because of the internal pullups. I want to switch to two 4.7k resistors but I can't figure out how to disable the internal ones. I know that the Wire library enables the internals by default, but how do I edit the library or disable the pullups in my sketch?
Maybe I just haven't been reading the right forums or articles, but if anyone could point me in the right direction that would be much appreciated.
EDIT: So the problem is probably with my setup or code, I'll put it down here. Everything I have before setup is importing libraries and variables like my mac, ip, placeholders for output, pwm, etc.
Master:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while(!Serial){
  }

  Wire.begin();

  Ethernet.begin(mac, ip);
  delay(1000);

  server.begin();
  if(server.available()){
    Serial.println("Client Available");
  }
}

void loop() {
  // put your main code here, to run repeatedly:

  ethernetwrite();

}

void ethernetwrite() {
  EthernetClient client = server.available();
  while(client) {
    if(client.find("P")) {
      output = client.parseInt();
      pwm = client.parseInt();

      Serial.println("Begin Transmitting");
      Wire.beginTransmission(14);
      Wire.write(output);
      Wire.write('\t');
      Wire.write(pwm);
      Wire.endTransmission();
      Serial.println("Done Transmitting");

      Serial.print(output);
      Serial.print('\t');
      Serial.println(pwm);

    }
  }
}

Slave:
void setup() {
  Wire.begin(14);
  Wire.onReceive(wirewrite);

// *   - Base frequencies:
// *      o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
// *      o The base frequency for pins 5 and 6 is 62500 Hz.
// *   - Divisors:
// *      o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64,
// *        256, and 1024.
// *      o The divisors available p1on pins 3 and 11 are: 1, 8, 32, 64,
// *        128, 256, and 1024.

    // Leg 1
    pinMode(leg[1], OUTPUT); setPwmFrequency(leg[1],8); analogWrite(leg[1], offset);

    // Leg 2
    pinMode(leg[2], OUTPUT); setPwmFrequency(leg[2],8); analogWrite(leg[2], offset);

    // Leg 3
    pinMode(leg[3], OUTPUT); setPwmFrequency(leg[3],8); analogWrite(leg[3], offset);

    // Leg 4
    pinMode(leg[4], OUTPUT); setPwmFrequency(leg[4],8); analogWrite(leg[4], offset);

    // Mirror
    pinMode(leg[0], OUTPUT); setPwmFrequency(leg[0],clkdivisor); analogWrite(leg[0], 255);
}

void loop() {

    int time = 10;
    time = time*128/clkdivisor;

    // box(time, 255, 1); // box(delay time, radius pwm, pwm step size);
    // autodisplay();
    updateL();

}

void updateL(){
  if (output == 0) pwm = 255 - pwm;
  switch (output) {
    case 1: pin =  3; break;
    case 2: pin =  9; break;
    case 3: pin =  10; break;
    case 4: pin =  11; break;
    case 0: pin = 5; break;
  }
  //if (output < 5) {
    analogWrite(pin, pwm);
  //}
}

void wirewrite(int numBytes) {
  String message;
  while(Wire.available()>0) {
    char c = Wire.read();
    message.concat(c);
  }
  output = Wire.parseInt();
  pwm = Wire.parseInt();
}

When I send data to the master, on the serial monitor it freezes in the first wiring transmission or in the next few, and my slave doesn't seem to respond to the message being sent over i2c. My controls for my device and setup worked prior to my attempts with the Wire library, so there's no problem there.
EDIT: I also am sending a message that looks like this:
"P1 103"
every .4 seconds or so, but I usually can't get past the first transmission between the arduinos

Why bother to disable the internals?  Say the internal is 50K - leaving it enabled and adding the 4k7 would end up with an equivalent of 4.2962K

I think the i2c bus is slowing down considerably because of the internal pullups; I2C is clocked, so it's speed is not dependent on the external resistor. You have to set the I2C clock to a higher frequency, if you want more speed.

Just out of curiosity, why do you want do (disable the resistors)? I think the i2c bus is slowing down considerably because of the internal pullups - no, it isn't. if anyone could point me in the right direction that would be much appreciated - if you could post your code that would be much appreciated.

My bad then, I was misinformed or just misinterpreted what I was reading. I was trying to read up on i2c for a project I'm working on and I'd been seeing a lot of disabling of the internal pullup resistors for people's projects involving i2c, sorry for the ignorance

From the datasheet:

Note that the internal pull-ups in the AVR pads can be enabled by setting the PORT bits corresponding to the SCL and SDA pins, as explained in the I/O Port section.

To disable the internal pull-ups:
digitalWrite(A4, LOW);
digitalWrite(A5, LOW);

or
digitalWrite(2, LOW);
digitalWrite(3, LOW);

It looks like SDA and SCL are constants, so safest would be to do a digitalWrite(SDA, LOW); digitalWrite(SCL, LOW); to avoid worrying about which pin they are on which board.

Just to clarify, as the quote from the datasheet talks about enabling the pullups: These commands disable the pullups.

Let's go back to basics. A low-value pull-up resistor actually improves the shape of the I2C clock and data.

One internal pull-up:

Both ends with the internal pull-up:

10 k external pull-up:

4.7 k external pull-up:

2.2 k external pull-up:

As Majenko pointed out, leaving the internal pull-ups enabled would give you a pull-up between 4.7 k and 2.2 k. And as my screenshots show, that is perfectly acceptable.
In fact, it is probably better. See the nice square signals?

So your hypothesis that the pull-up is responsible for it running slowly is not supported.
You need to post your code, and other details, such as the length of the cable runs.

I think the i2c bus is slowing down considerably ...

What do you mean "slowing down"? Compared to what? What are your figures? What is the transmission time? What do you expect it to be? Some facts please.

Reference
My page about I2C

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


text:
TinyGPS (Plus) Library
Is there a particular function in the library TinyGPS or TinyGPS Plus which outputs the raw NMEA sentences? I couldn't find anything about it on the website guide of the library.

There doesn't seem to be, but what you could do is print each character as it arrives. From their example code:
  while (nss.available())
  {
    if (gps.encode(nss.read()))    // <--- pass to TinyGPS
      return true;
  }

So, change that to be:
  while (nss.available())
  {
    char c = nss.read();  // <--- get the incoming character
    Serial.print (c);     // <--- print it
    if (gps.encode(c))    // <--- now pass it to TinyGPS
      return true;
  }


text:
Quick Programming Check/Review
I've been racking my head trying to start programming in a library organized method. My code works, but the translation and split to a .h and .cpp file is riddled with errors.
It's gotta be stupidly simple all I'm asking for is a review:
Header File
# ifndef _INITIALIZE_H
#define _INITIALIZE_H

#if (ARDUINO >= 100)
# include <Arduino.h>
#else
# include <WProgram.h>
#endif

//-Extra Includes-
#include <config.h> //Provides baud...
#include <SSC32.h>

#define STANDARD 0
#define DEBUG    1
#define VIRTUAL  2

class Initialize {
    private:
        int _mode;
    public:
        Initialize();
        void begin();

};

#endif

associated .cpp file:
//Comments
#include <Initialize.h>
SSC32 SSC;

Initialize::Initialize()
{
    _mode = STANDARD;
}

void Initialize::begin()
{
    SSC.begin(baud);
    if(Serial.available() > 0){
        if(sscReturn == 1){
            Serial.println("ver");
        }
    }
}

The error from the compiler:
D:\Github\Project-Onyx-Quadruped\code\HostControllerFirmware\Onyx-HostFirmware-Initial-7-2-15\libraries\Initialize\Initialize.cpp: In member function 'void Initialize::begin()':
D:\Github\Project-Onyx-Quadruped\code\HostControllerFirmware\Onyx-HostFirmware-Initial-7-2-15\libraries\Initialize\Initialize.cpp:9:12: error: expected primary-expression before '=' token
D:\Github\Project-Onyx-Quadruped\code\HostControllerFirmware\Onyx-HostFirmware-Initial-7-2-15\libraries\Initialize\Initialize.cpp:9:16: error: expected primary-expression before ')' token
D:\Github\Project-Onyx-Quadruped\code\HostControllerFirmware\Onyx-HostFirmware-Initial-7-2-15\libraries\Initialize\Initialize.cpp:9:16: error: expected ';' before ')' token
D:\Github\Project-Onyx-Quadruped\code\HostControllerFirmware\Onyx-HostFirmware-Initial-7-2-15\libraries\Initialize\Initialize.cpp:11:7: error: expected primary-expression before '=' token
D:\Github\Project-Onyx-Quadruped\code\HostControllerFirmware\Onyx-HostFirmware-Initial-7-2-15\libraries\Initialize\Initialize.cpp:11:7: error: expected ')' before ';' token
D:\Github\Project-Onyx-Quadruped\code\HostControllerFirmware\Onyx-HostFirmware-Initial-7-2-15\libraries\Initialize\Initialize.cpp:11:17: error: expected primary-expression before '==' token
D:\Github\Project-Onyx-Quadruped\code\HostControllerFirmware\Onyx-HostFirmware-Initial-7-2-15\libraries\Initialize\Initialize.cpp:11:21: error: expected ';' before ')' token
Failed compiling libraries

What is sscReturn?

Where is sscReturn declared? This seems to be the (main) cause of the compiler errors.

Sorry, figured it out.
In the "config.h" file I was pulling, I had a
 #define = 18;
instead of a #define 18
I might be wrong, but the compiler stopped complaining

What are you defining as 18?

@user you cannot just type #define 18, it should be something like #define xyz 18. This means that from now on in your code xyz will be replaced by 18 (https://www.arduino.cc/en/Reference/Define)

I might be wrong - You are wrong. The line #define 18 doesn't compile: error: macro names must be identifiers. This is not a helpful answer. I'm going to vote to close the question and the answer.


text:
AES Simplified for Arduino - Having hard time achieving desired result
Okay, here's the story. I'm not very familiar with how Arduino works but learning. I have a project that requires AES encryption on the Arduino Uno. As per a previous question we managed to figure out the problem but failed to resolve it fully so we started using another library. (This one: https://github.com/qistoph/ArduinoAES256)
uint8_t key[] = { //
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  };
Now onto the problem itself. Using an online AES encryption tool such as: http://aesencryption.net/ Simply asks for a Key of the encryption in plain text and the output is base64 as specified by the service here: The result of the encryption will appear in base64 encoded to prevent character encoding problems.

Also, plain text can be used to process the encryption using AES algorithm.
I've been trying to achieve the exact same result using an Arduino Uno board with the exact same requirements. The end result is to have a base64 string that can be decrypted on another remote location having the same key.
Now as for the .ino file it has this setup:
#include "aes256.h" //Include library files
#define DUMP(str, i, buf, sz) { Serial.println(str); \
    for(i=0; i<(sz); ++i) { if(buf[i]<0x10) Serial.print('0'); Serial.print(char(buf[i]), HEX); } \
    Serial.println(); } //Help function for printing the Output

aes256_context ctxt;

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

  Serial.println("Initializing AES256... ");
  uint8_t key[] = { //
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  };
  DUMP("Key: ", i, key, sizeof(key));
  aes256_init(&ctxt, key);

  uint8_t data[] = { //"asdfasdfasdfasdf"
    0x61, 0x73, 0x64, 0x66, 0x61, 0x73, 0x64, 0x66,
    0x61, 0x73, 0x64, 0x66, 0x61, 0x73, 0x64, 0x66
  };
  DUMP("Unencrypted data: ", i, data, sizeof(data));

  aes256_encrypt_ecb(&ctxt, data);
  DUMP("Encrypted data: ", i, data, sizeof(data));

  aes256_decrypt_ecb(&ctxt, data);
  DUMP("Back decrypted data: ", i, data, sizeof(data));

  aes256_done(&ctxt);
}

void loop() {
}

1) I can't seem to understand what is required to have a plain text key and plain text message to encrypt giving an end result of base64 output.
For example if I were to do this using JavaScript: (And this is just an example).

2) I'd like to achieve something like this:
var key = "32 characters plain text here";
var plain = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
var base64_output = aes.encrypt256(key, plain);

3) I'd like to have the base64_output as base64 string so that it can be printed on a third-party printer hooked to the Arduino. - Is this impossible to achieve? We've been trying for some time now from endless conversions to splitting up our plain text into chunks of 16 characters so that we can encrypt the message.

Any help is greatly appreciated. If someone doesn't mind us contacting them over the phone we would also greatly appreciate a phone call to have this issue explained and resolve so we can share our experience with the Arduino community.
Thanks in advance.
edit:
We're getting this error

edit2:
Thank you @Nick Gammon for the quick response.
After removing const from the function 4 places and the key variable declaration, everything seems to be working fine now.
We modified the code in order to print all bytes for each cipher block. We have this output:
140 145 154 38 228 66 98 128 116 68 245 193 70 84 205 115
Œ‘š&äBb€tDõÁFTÍsŒ‘š&äBb€tDõÁFTÍs
186 174 17 21 162 83 96 210 128 134 46 206 172 215 0 103
º®¢S`Ò€†.Î¬×
112 4 216 150 27 202 6 176 77 159 123 231 127 128 32 132
pØ–Ê°MŸ{ç€ „pØ–Ê°MŸ{ç€ „
215 110 118 33 167 193 212 121 156 46 63 139 183 124 63 152
×nv!§ÁÔyœ.?‹·|?˜×nv!§ÁÔyœ.?‹·|?˜
130 91 174 118 4 202 250 74 228 7 173 40 246 124 53 173
‚[®vÊúJä(ö|5‚[®vÊúJä(ö|5
231 48 204 82 235 172 202 139 33 134 137 81 209 191 210 217
ç0ÌRë¬Ê‹!†‰QÑ¿ÒÙç0ÌRë¬Ê‹!†‰QÑ¿ÒÙ
184 161 98 135 12 230 86 213 183 113 103 234 187 213 224 133
¸¡b‡æVÕ·qgê»Õà…¸¡b‡æVÕ·qgê»Õà…
Done

We're trying to convert each array of bytes into a char array of hex values then base_64 encode it.  But we're getting this output which is not what we want. Can you please explain how can we achieve this.
Please let us know if it is possible to open a chat with you so that we can understand this better.

What is stopping you? Is it the conversion of the encrypted string to base-64?

Well for starters I am unable to do a simple plain text conversation such as the silly JavaScript example above for the key and plain variables and convert them to uint8_t arrays of hex. Among other issues described above.

What I'm asking, more specifically, is: what have you tried; what were you expecting to happen; and what actually did happen?

@JRobert 1, The lack of documentation out there for implementing AES properly on Arduino devices. And 2, Converting a string such as String plain = "Hello World" into a uint8_t array.

We've been trying for some time now from endless conversions to splitting up our plain text into chunks of 16 characters so that we can encrypt the message. - I'm a little confused as to why that is a problem. Can you show your attempts to break your string of text into groups of 16 bytes? I'm thinking: a for loop - what are you thinking?

possible duplicate of Implementing DES or AES Encryption with DateTime Synchronization on Uno

You have also posted about your AES troubles on AES encryption arduino  - this is against the StackExchange rules: Is cross-posting a question on multiple Stack Exchange sites permitted if the question is on-topic for each site? - The answer being NO by the way.

@NickGammon well, thanks anyway. If having another question is a problem we can remove it.

We've been trying for some time now from endless conversions to splitting up our plain text into chunks of 16 characters so that we can encrypt the message.

To address this question/issue, below is some code that will take an arbitrary length string and break it into 16-character strings suitable for encoding with AES:
const int KEY_SIZE = 32;
const int BLOCK_SIZE = 16;
const char message [] = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
const byte key [KEY_SIZE] = "32 characters plain text here";

void encrypt_it (const byte plaintext [BLOCK_SIZE], const byte cipherkey [KEY_SIZE]);  // prototype
void encrypt_it (const byte plaintext [BLOCK_SIZE], const byte cipherkey [KEY_SIZE])
  {
  // encrypt here
  }

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

  const char * p = message;

  while (strlen (p) > 0)
    {
    byte plain [BLOCK_SIZE];
    memset (plain, 0, BLOCK_SIZE);  // ensure trailing zeros
    // copy block into plain array
    memcpy (plain, p, min (strlen (p), BLOCK_SIZE));
    // encrypt it
    encrypt_it (plain, key);
    // advance past this block
    p += min (strlen (p), BLOCK_SIZE);
    }
  Serial.println ("Done");
  }  // end of setup

void loop ()
  {
  }  // end of loop

I'd like to have the base64_output as base64 string so that it can be printed on a third-party printer hooked to the Arduino. - Is this impossible to achieve?

Of course it is possible. Just look up (Google) a C or C++ function to base-64 encode a string. There must be thousands of them. This is not an Arduino question, this is a C programming question.

As per a previous question we managed to figure out the problem but failed to resolve it fully ...

Namely here: Implementing DES or AES Encryption with DateTime Synchronization on Uno.
This question actually looks remarkably similar to your previous one.

please check our edit on the post. It shows the error that we are getting when trying to implement aes encryption according to your method. Thank you

You can copy and paste error messages you know (the text of them). You don't have to take screenshots. Change const byte on the function encrypt_it to byte (4 places).

sorry for uploading a screenshot. We implemented the changes and updated our post. Appreciate if you can take a look at it again. Thanks in advance

The reason of this conversion is to decode it online using this website which takes a base_64 encoded string. http://aesencryption.net/

2) I'd like to achieve something like this:

  var key = "32 characters plain text here";
  var plain = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
  var base64_output = aes.encrypt256(key, plain);

So do it.
#define MAX_MESSAGE_SIZE 256
uint8_t key[] = "32 characters plain text here";
uint8_t plain[MAX_MESSAGE_SIZE+1] = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
aes256_init(&ctxt, key);
aes256_encrypt_ecb(&ctxt, plain);
// plain is now encrypted.

That is limited to a maximum message (and encrypted output) size of 256 bytes due to the (purely arbitrary) size of the array I chose.

I think unlimited is an unwise word to use considering that the Arduino Uno has 2 KB of RAM.

@NickGammon Not my word - copied and pasted from the question.  Like the universe - "Infinite but bounded" - what does it really mean?  Unlimited as long as it's less than the maximum number of characters allowed by the array ;) - as noted in the "That is limit to ..." paragraph.

I realize it isn't your word. It is the OP's word. :)

If you don't have to have the features of the String object, I'd highly recommend you use a uint8_t (or 'byte' or 'char') array from the get-go. It avoids the conversion altogether, as well as the code complexities of dealing with Strings.
uint8_t plain = "Hello World"; works great for a literal string, or if you need more flexibility, uint8_t plain[256+1] = "Hello World"; lets you use or re-use that space for whatever strings you need to hold at run-time (pick a size appropriate for your needs, obviously). Will that let you get past the conversion road-block to focus on encryption (about which, I'd be no help at all).

How will uint8_t plain = "Hello World"; be equal to this?   uint8_t key[] = { //     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,     0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,     0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f   };  Given that Hello World` will change based on keyboard input?

I think you mean uint8_t plain[] = "Hello World" - you forgot the array notation []


text:
Connect the Sparkfun CAN bus shield with an RFduino
I have a problem which I am working on for some days now. I do have knowledge in electronics, but not extensively. I also posted this question in the RFduino Forum but couldn't get any good answers.
What I am trying to do: I want to connect the Sparkfun CAN bus shield to the RFduino. I am using the code further below. It compiles without problem and does work with my Arduino Leonardo!
I used a logic analyser (ignore the filled shapes, some display error) to further narrow down the problem and found the following on the RFduino:

On the Leonardo, it looks different:

It seems like I don't get a response on the MISO line! I played around with different speeds, but nothing seemed to work.
I do have a suspicion however: The RFduino works with 3.3V, while the Leonardo works with 5V. So the logic signals on the RFduino can only achieve 3.3V P-P. I confirmed this with my old CRO, LOW is at GND and HIGH at 3.3V. The Leonardo has 5V P-P.
On page 70 of the datasheet for the MCP2515 (the chip used on the shield), it says that the supply voltage VDD ranges from 2.7V to 5.5V. So supply voltage should be ok. V_INPUT_HIGH ranges from 2.31 to 4.3V. V_INPUT_LOW ranges from -0.3V to 0.495V. I am in this range! Similarly so for the V_OUTPUT_LOW (up to 0.6V) and V_OUTPUT_HIGH (at least 2.8V). Could this nevertheless be a problem?
What would you try or change?
MCP2515 Datasheet
#include <SPI.h>

// demo: CAN-BUS Shield, send data
#include <mcp_can.h>

MCP_CAN CAN0(SS);                                      // Set CS to pin 10

unsigned char stmp[8] = {0, 1, 0, 3, 0, 5, 0, 7};

void setup()
{
  Serial.begin(115200);
  while (!Serial) {
    ;                  // wait for serial port to connect. Needed for Leonardo only
  }
  // init can bus, baudrate: 500k
  if(CAN0.begin(CAN_500KBPS) == CAN_OK) Serial.print("can init ok!!\r\n");
  else Serial.print("Can init fail!!\r\n");
               // send data per 100ms
}

void loop()
{
//    // send data:  id = 0x00, standrad flame, data len = 8, stmp: data buf
//  CAN0.sendMsgBuf(0x00, 0, 8, stmp);
}

Ok, I found the solution. The fix first: I had to physically connect the reset line from the RFduino to the MCP2515 reset pin.
On page 55 in the datasheet of the MCP2515 it says that you can either reset it by pulling the reset line low or by sending a command over the SPI. The library I used is sending this reset command, but it isn't working for some reason. The logic analyser shows me this signal, it is the first recorded. Maybe it is a timing issue, that the reset has to be sent at the same time as the RFduino resets. Connecting the reset pin solves this issue, because then the RFduino and the MCP2515 are being reset at the same time.
If anybody knows more about this, feel free to tell me!

It is difficult to tell whether your chip select is working correctly or not with the logic analyzer view.  Have you tried hooking it up to an o-scope to capture what the CS is actually doing(in the analog world)?
What cabling have you chosen between the CAN and arduino?
If you get the o-scope out, you may want to check the MISO and MOSI for ringing, which may lead back to cabling.

I just hooked up my oscilloscope. Looks like the analyser wasn't lying, the signal is good. A little bit of overshoot (0.1V at max), but the separation is good, the MOSI is only active when CS is low and so on. On the MISO I have some strange signal, about 25 MHz and very small (0.4V). It goes blank when the chips is reset. Giving the CAN shield/MPC2515 5V to work with doesn't change anything.

After looking through the data sheets, i have to ask how are you powering the CAN BUS?  From the Leonardo/RFduino?

The CAN BUS schematic shows a VCC and a +12V, but the source of VCC is not shown.  If VCC is being regulated down from +5V provided by the leonarado, then VCC might not be able to be regulated down by the +3.3V provided by the rfduino.  If 3.3V is the input to an LDO somewhere and 3.3V has to be the output too, you'll definately have problems..    Moral of the story, make sure you understand the Power chain fully.

The 'power chain' with the Leonardo depends on the operation: with the CAN bus connected, the 12V goes through the Vin pin of the Leonardo to its onboard 5V regulator, which then provides 5V on a pin. This pin is via the shield connected to the VCC pin on the MCP2515. The other chain is for testing, where I just initialize the chip without actually doing anything on the CAN bus: I provide 5V via USB and the Leonardo then again provides it on the same pin as above. The RFduino provides 3.3V from USB via a regulator on the programming shield, which I connect to the VCC on the CAN bus shield.

So Leonardo+CANbus active: CAN->CAN Shield->Leonardo (12V->5V)->CAN Shield->MCP2515. Leonardo on USB: USB->Leonardo->CAN Shield->MCP2515. RFduino on USB: USB->Programming Shield (5V->3.3V)->CAN Shield->MCP2515.


text:
MQTT client on Arduino + SIM900
I have used the pubsubclient library for Arduino for communicating with an MQTT broker in the past, however the library works only with Ethernet connecction. I need to use GSM in my application and am using the SIM900 at the moment. However, I cannot seem to find any library for MQTT communication using an Arduino as MQTT client and SIM900 as gateway. I found this to be surprising as there must surely be many instances where one would want to upload data from Arduino to a MQTT broker in a mobile scenario where cellular network is the only option (in place of Ethernet). So my questions are:

Is it possible to use the Arduino as MQTT client and SIM900 as gateway for communicating with an MQTT broker? Are there any libraries for the same?
What is the current standard way (gateway / communication protocol) of uploading some sensor data from Arduino to an internet server in a mobile scenario (i.e., where Ethernet is not an option)?

I too had the same problem. Mine was a self powered(battery) arduino sensor kit. I tried many and at last ,as the last resort had to use the usual HTTP requests to send data.

MQTT Library for SIM800 GSM Modem is available at ElementzTechBlog, ElementzGithubRepository
Functionalities:
Auto connect
   Automatically connect to TCP and to MQTT server.

connect function
   This function can be used to connect your client to MQTT broker.
   Use only if you do not use Auto connect functionality.
   Optionally  you can use username, password, WILL topic and WILL Message.

OnConnect CallBack function
   This call back function is called when MQTT connection is established.
   You can call subscription and publish functions inside it (according to your need).

publish function
   This function can be used to publish messages to different topics.
   You can select  QoS levels and RETAIN flag according to your need.

subscribe function
   This function can be used to subscribe messages from different topics.

OnMessage CallBack function
   This callback function is called when messages are received from  subscribed topics
   Topic, TopicLength, Message, MessageLength are the arguments of  OnMessage callback function.
   Inside this, you can write your custom code.

unsubscribe function
   This function can be used to unsubscribe from a previously subscribed topic.

disconnect function
   This function can be used to disconnect your client from MQTT broker.

Keep Alive
   You can specify your KeepAlive duration while initializing.
   Ping requests are sent and received automatically.

Update
Nowadays the easiest solution is to use SIM7600 4G/3G/2G modem. It supports MQTT using AT commands !. For more details the following link can be useful to get started.
https://www.elementzonline.com/blog/using-mqtt-at-commands-with-sim7600-and-arduino-for-gsm-iot-projects

The SIM900 allows creation of TCP sockets through an AT style command language, so this addresses point #1 of the previous comments concern.
This is only half the story though, you'll still need to learn how to create the requests, and handle the responses of the MQTT protocol using the SIM900's protocol.
There may be usable examples to start from in the ESP8266 community, as their style of TCP API looks similar to the SIM900.

MQTT by definition is a TCP/IP protocol, so if you don't have a TCP/IP stack, then it is a no go.
A common pattern/infrastructure in the IoT is to have your "things" connect to a hub of some kind (via BLE, XBee, or ... etc.) and then the hub will connect to the network and post the data. Another option would be to get a cellular device that provides a data connection (i.e. 2G/3G) and therefore a TCP/IP stack. It looks like the SIM900 only supports calls and texts, and as of this moment I am not aware of such a device that has libraries for Arduino.

Actually, the SIM900 comes with a built-in TCP/IP stack. Also 'pubsubclient' accepts a generic Client, which has defined the usual read(), print(), connect(), etc methods; it is definitely possible to create these methods for a 'SIM900 object' and pass it to the pubsubclient constructor and so achieve MQTT functionality.

Take a look at the FONA library from Adafruit.
https://github.com/adafruit/Adafruit_MQTT_Library/blob/master/examples/mqtt_fona/
The FONA Library uses SIM800 which is a newer version of SIM900. You will find MQTT and FONA within the same library. They also run an MQTT Broker service in adafruit.io

These tutorials should help on getting started with MQTT on SIM900 or SIM800.
MQTT Protocol tutorial - LIVE DEMO using Mosquitto and CloudMQTT
https://youtu.be/Oh3ZYAQBTko
This video explains about the main important control packets of MQTT protocol by explaining what each byte in a MQTT packet means and also shows how to send and receive data using TCP and Websockets UI of CloudMQTT.com Control panel. We also learn on  how to use the Mosquitto Open source broker on Windows machine to Publish and subscribe to MQTT message and topics on localhost and to cloud servers with and without Authentication.
MQTT Protocol tutorial using SIM900/SIM800 modules - LIVE DEMO
https://youtu.be/dcpMa2UwEeA
This video demonstrates how you can use the light weight MQTT protocol on the SIM900 or SIM800 GSM modules using TCP over the GPRS connection. Here you will learn, how you can use the SIM900/SIM800 TCP commands to send and receive messages as a publisher and a subscriber in almost realtime.


text:
Arduino Xbee AT command mode
I have 2 Xbee Series 2 modules.
One of it is connected to arduino via an adapter. And Ground 5V, as well as Rx>>Tx and Tx>>Rx.
The xbee is configured AT mode Coordinator.
I want to use the serial monitor in arduino to change the parameters of the xbee, such as DH or DL or PAN ID things like this.
Is there a way for the xbee to display its "OK" response after entering command mode on the serial monitor?

Because you have an Arduino Mega, you can set it up to use it like a USB-to-UART adapter by using the following code (source):
void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.write(inByte);
  }
}

Basically what this does is it takes the data it receives from the USB port via Serial and transmits it to Serial1 and then also reads from the UART port via Serial1 and transmits it back to the computer via Serial. With this code running you should be able to hook up the XBee to RX1 and TX1 and communicate to it using the Serial Monitor.

Wow, Thank you for your response. I tried it out, it worked, but somehow it only work if i connect xbee rx to arduino rx1 and xbee tx to arduino tx1. Is this supposed to be this way. all i change is changing int inByte to char inByte

And, i also tried using +++ to enter command mode. i can receive the first OK response, but the subsequent commands are not able to go through. thank you in advance

It should be rx to tx in both directions. Also the baudrate in my example (9600) should be changed to match whatever your xbee is configured for.

THANK YOU SO MUCH, it worked as you said.. My coordinator DL is wrongly typed.

Not if you have it connected to pins 0 and 1, no.  You should not use those pins for anything unless you absolutely have to, since they are what are used for communication with the PC.  You can't do both communication with the PC and with the XBee using the same pins.
You should ensure that the XBee is connected to one of the other serial ports on the Mega and then write a sketch that passes the data through from one port to the other as needed so you can view it on the serial monitor.


text:
Signal sampling: losing data every 103 points when it is recorded in SD
I'm working on a system of acquisition and ECG datalogging with the Arduino, and I'm having the following problem:
I'm losing data every 103 points (just 103). No matter the sampling frequency to use, every 103 points, some points are lost, damaging the signal sampling.
It could be the recording time on the SD card, but even when the SD.close () command is run only once, the data is lost.
Here is a simple test algorithm with a 100 Hz sine wave at the entrance.

#include <SD.h>
#include <SPI.h>

int CS = 4;
int ECG_PIN = 1;
int voltage;

int index = 0;
const int bufferSize = 5;
int vetor[bufferSize];
int RECORD_TIME = 20000;
File logFile;

void setup(){
  pinMode(CS, OUTPUT);
  pinMode(ECG_PIN,INPUT);

  if(!SD.begin(CS)){
    return;
  }
  logFile = SD.open("ECG_log.txt", O_CREAT | O_WRITE);

}

void loop(){
  while(millis() <= RECORD_TIME){

      voltage = analogRead(ECG_PIN);
    if(logFile){

       logFile.println(voltage);

       delay(0.5);
    }
  }
  logFile.close();
}

What could it be? Speed analogRead ()? Problem on the SD card?
Sorry if the question is very basic, I am beginner, in a way, the Arduino platform. Any help will be very welcome.
Thanks!...

It's all to do with writing to the SD card.
You have a buffer of 512 bytes which is one "block" of the SD card.  When you have written to the card enough to fill that buffer up it has to write that buffer to the SD card and empty the buffer so you can start filling it again.
That writing to the SD card takes time - lots and lots of time (relatively), and it can't be doing anything else at the same time as writing to the SD card.
The only way you can get around that is to have your sampling performed within an interrupt - maybe a timer interrupt - so that it can interrupt the writing to the SD card.  However, that's not a simple task.
You would need to implement a system known as ping-pong buffers.  You have a pair of buffers for storing incoming samples within your interrupt routine.  When one buffer is filled up you switch to the other buffer and signal to your main loop() routine that you have filled the buffer.  It's then the job of loop() to save that buffer to the SD card and empty it ready for when the second buffer has been filled up.  The name ping-pong comes from the game of table tennis (also known as ping-pong) as you are switching from one buffer to the other and back again in a constant backwards-and-forwards motion like the ball in a game of table tennis.
Getting the right size of buffers is also critical.  You have to ensure that the time taken to fill one buffer is always going to be longer than the longest amount of time it takes to write a buffer to the SD card, including any flushing of the internal SD card buffer.  The best size is probably going to be to match that internal SD card buffer so every ping or pong you will be doing an entire SD card block's worth of data - so 512 bytes.
That means you have 3 buffers of 512 bytes - your two ping-pong buffers and the SD card's buffer, which is 1536 bytes - not far off the limit of an Uno, so you may struggle with that.  For this kind of thing it is better to use one of the boards with a more meaty chip, like the Mega2560.
Also the line:
delay(0.5);

is meaningless.  delay() takes an integer value, so 0.anything is actually truncated to 0.  To delay for less than a millisecond you should use delayMicroseconds().

Thank you for quick and didatic response, @Majenko.
I've been having insufficient memory problems with the Uno from the start of the project. I will purchase a Mega as soon as possible.
I got the idea of ping pong buffer, but still can not understand how to put it in the form of code. Could you point me some material or program as a reference?
Thank you very much.

I don't have any examples online at the moment. It's simple enough - 2 buffers, 2 flags. One flag says which buffer is being filled at the moment, the other flag is used to indicate that a buffer is ready for writing. When the writing flag is set loop() notices it, writes out the non-filling buffer by checking the first flag, and clears the second flag. When you have filled a buffer you set or clear the filling flag and set the writing (ready-to-empty) flag.

512 bytes divided by 5 bytes per datapoint (three digits + carriage return + newline) = 102.4 (rounds up to 103)

@Gerben What a coincidence ;)


text:
Arduino with ESP8266
I have completed the circuit and code to interface ESP8266 module with Arduino UNO.
When i send AT,AT+RST from serial monitor the reply is correct .
But when i send AT commands to search WIFI networks (AT+CWLAP) & connect to WIFI (AT+CWJAP="SSID","password") the reply is ERROR.
But the IP address (may be default) is obtained as 192.168.4.1
 when i send AT+CIFSR .
Here is my code
#include <SoftwareSerial.h>
SoftwareSerial esp8266(2,3); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
                             // This means that you need to connect the TX line from the esp to the Arduino's pin 2
                             // and the RX line from the esp to the Arduino's pin 3

void setup()
{
    Serial.begin(9600);
    esp8266.begin(9600); // your esp's baud rate might be different
}

void loop()
{
    if(esp8266.available()) // check if the esp is sending a message
    {
        while(esp8266.available())
        {
            // The esp has data so display its output to the serial window
            char c = esp8266.read(); // read the next character.
            Serial.write(c);
        }
    }
    if(Serial.available())
    {
        // the following delay is required because otherwise the arduino will read the first letter of the command but not the rest
        // In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it
        // but we want to send everything at the same time.
        delay(1000);
        String command="";
        while(Serial.available()) // read the command character by character
        {
            // read one character
            command+=(char)Serial.read();
        }
        esp8266.println(command); // send the read character to the esp8266
    }
}

Your serial reading code, with that really horrible delay, is not good.  You should read and digest this: http://hacking.majenko.co.uk/reading-serial-on-the-arduino

You want to use  AT+CWSAP="SSID","password",1,0

Finally i found the solution .
Send AT+CWMODE=1 first , then all other commands working fine.


text:
CH340: right endpoint?
I'm working on implementing CH340 drivers used by cheap Arduino clones on Android (Linux). What endpoints should be used as read endpoint since two endpoints have IN flag - 0x81 and 0x82?
http://usbdriverwriting.blogspot.ru/2012/10/connection-status-device-connected.html
Is there any developer documentation except some old c #1 (http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/drivers/usb/serial/ch341.c?v=2.6.25.8) and some linux driver #2 (http://0xcf.com/?wpdmdl=124)

Try looking at the (normal) Linux drivers source code.  Of course, you could always try one and see - if it doesn't work, try the other instead.

can you send me the link for normal Linux driver sources for CH340 chip?

none if them is working because of another reasons so i can't detect which one is correct. i need just to know which one is right

Plug it into a linux machine and use lsusb -v -d <vid:pid> to find which endpoint is the bulk one?  You can probably do something similar on Windows but I don't have a clue how.

according to the link above (http://usbdriverwriting.blogspot.ru/2012/10/connection-status-device-connected.html) 0x82 is bulk endpoint and 0x81 is not

So it should be 0x82 then I would guess.  The other one is probably for sending configuration or control line messages.

thanks for help, Majenko. If someone has any documentation on this please share it

The trouble with cheap Chinese chips is that you get cheap Chinese datasheets. "You gets what you pays for" as they say.


text:
One free pin. Need to display output for the user?
I'm working with lightblue bean. I have a device that writes data to an SD card on a long button press and switches what will be written (from a list of 5 items) on short button press.
The output, printed both to the SD card and to serial looks like this:
12:38, 7/15/15, subway
12:55, 7/15/15, subway
12:38, 7/15/15, bus
12:55, 7/15/15, rail

etc. It's basically a time stamp then a vale from this list:
char* modes[]= {"walking", "subway", "bus", "railroad", "other"};

This works perfectly. But the bean has very few pins:

5 SCK  -- connected to SD card.
4 MISO -- connected to SD card.
3 MOSI -- connected to SD card.
2 SS   -- connected to SD card.
1      -- input button, takes long and short presses
0      --
A1 SDA --- connected to real time clock for timestamp
A0 SCL --- connected to RTC (real time clock) for timestamp

I have one free DIGITAL pin. I need to let the user know what they have selected. This could be done with 5 LEDs that light up next to the user's choice, or maybe displayed text? This is a portable item so a servo that points to the user's choice might be too unreliable.
I've done some research into shift registers. They all seem to need 3 digital pins min. If I could do it with 2 I could rework the button...
Ideas?

Have you considered morse code? ;)

Use SPI to send data to a shift register (or several) to drive LEDs, or 7-segment displays, etc. The free pin becomes the latch signal to the shift registers.  SPI is a bus, use it like one.

The 7-segment display board is all very well, but that displays 4 digits. That isn't exactly 5 LEDs. In any case that board has a chip on it, if you are going to buy another chip you may as well get an Attiny and use that. Just have serial input (same as the 7-segment board did).
On the Attiny you have 8 pins, 3 of which will be reserved: Vcc, Gnd, Reset. That leaves you with 5 for the communications and the 5 LEDs. So, use one pin for incoming serial, or two pins for SDA/SCL, and use the remaining 3 pins for the LEDs. You can can use Charliplexing to use 3 pins to light up to 6 LEDs.

For the fun of it, I made up an example using my Uno (it still only uses 3 pins to light 6 LEDs).

There are 3 x 100 Ω resistors as in the schematic. One is completely hidden by the LEDs (leading from the middle yellow wire to the middle pins of the LEDs).
Code:
const byte X1 = bit (2);   // D2 on Uno
const byte X2 = bit (3);   // D3 on Uno
const byte X3 = bit (4);   // D4 on Uno

const byte patterns [7] [2] = {
// PORT DDR
  { 0,   0, }, // all off
  { X1, X1 | X2 }, // LED1: X1 on,  X2 off, X3 HiZ
  { X2, X1 | X2 }, // LED2: X1 off, X2 on,  X3 HiZ
  { X2, X2 | X3 }, // LED3: X2 on,  X3 off, X1 HiZ
  { X3, X2 | X3 }, // LED4: X2 off, X3 on,  X1 HiZ
  { X1, X1 | X3 }, // LED5: X1 on,  X3 off, X2 HiZ
  { X3, X1 | X3 }, // LED6: X3 on,  X1 off, X2 HiZ
};

void setup ()
  {
  }  // end of setup

void loop ()
  {
  for (int i = 0; i < 7; i++)
    {
    DDRD = patterns [i] [1];
    PORTD = patterns [i] [0];
    delay (500);
    }  // end of for loop
  }  // end of loop

The code displays each of the 6 LEDs (plus all off) in a cycle. For each one it configures the DDR (data direction register) plus the PORT (output register) appropriately to light the desired LED.
It works perfectly, except that you may need to work out which LED is which by experimentation.

Seems you have I²C on the board you could possibly use an I²C LCD backpack, like from breakouts if you already have an LCD, this means you can have the RTC and display on the I²C bus and probably more things.
Another option seems you mentioned LEDs, you could still use the I²C bus and use an I/O expander and hook LEDs up to that and address them over the I²C. You can use a PCF8575(16 I/O), as there are Arduino libraries. There are breakouts for it. Or you could make your own from another AVR, like one from the ATTiny line, seems there is 5 LEDs.
A I²C bus example:

(source: ermicro.com)
Seems you want to use the PWM, you can use a dot/bar driver IC, such as the LM3914 it takes an analog value and shows it as a point on the strip of LEDs, example below:

The IC can also work down to 3V.
What you will need to do is add a low pass filter to convert the PWM to a smooth analog value. You will add this in place of the input circuitry(D1 & C1) there:

If there is any confusion on the LM3914, there are quite a few tutorials on google.

l2C takes two pins in addition to power and ground-- both  of the options you mention take as many pins as a shift register. I might just need to redesign....

I'm giving you credit for helping but maybe my question should have been more clear.

@futurebird  I2C uses the same two pins which you are using, it is a bus? You can use both the RTC and a display option together. What's wrong with that?

l2C takes two pins in addition to power and ground - you share the same two pins. Each device on the I2C bus has its own address. That answer was perfectly feasible.

Can it work at 3.3v? The bean is a 3.3v device and the project is battery powered (can't add a power supply.)

@futurebird - Yes, the IC can work from 0 - 3.3V, datasheet

The peak detector on the original '3914 circuit may work fine as a LPF.

@IgnacioVazquez-Abrams - ok good point, +1, keep this  up top

I've found a solution! 7-segment display breakout board.

This works art 3.3v which is critical for a lightblue bean. I think a servo might be the most creative solution.
I'm still convinced there must be some way to use PWM...

It looks like that particular board (can) use async serial, thus the one-wire solution (plus power and ground) will use serial output to drive it.

If you're going to use that board then you may as well use the MCU on it and dump the Bean.

The bean has very nice BLE (bluetooth) I'd rather not drop that feature.


text:
Multiple if statement conditions
I would like to make this code using the Arduino Uno. I am using three on/off switches and based on the truth table would like to turn on one of 8 LEDs. When I use digitalWrite(), I get an error code saying that there are too few arguments.
Here is the code
int x = A3;    // select the input pin for the switch
int y = A4;
int z = A5;

int ledPin1 = 2;      // select the pin for the LED
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 7;
int ledPin5 = 8;
int ledPin6 = 9;
int ledPin7 = 12;
int ledPin8 = 13;

void setup(){

  // declare the ledPin as an OUTPUT:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);

  pinMode(x, INPUT);
  pinMode(y, INPUT);
  pinMode(z, INPUT);
}

void loop() {

  if ( (x = LOW) && (y = LOW) && (z = LOW))              //condition 1
  {
    digitalWrite (ledPin1 = HIGH);
    digitalWrite (ledPin2 = LOW);
    digitalWrite (ledPin3 = LOW);
    digitalWrite (ledPin4 = LOW);
    digitalWrite (ledPin5 = LOW);
    digitalWrite (ledPin6 = LOW);
    digitalWrite (ledPin7 = LOW);
    digitalWrite (ledPin8 = LOW);
  }

  if ( (x = LOW) && (y = LOW) && (z = HIGH))             //condition 2
  {
    ledPin1 = LOW;
    ledPin2 = HIGH;
    ledPin3 = LOW;
    ledPin4 = LOW;
    ledPin5 = LOW;
    ledPin6 = LOW;
    ledPin7 = LOW;
    ledPin8 = LOW;
  }

  if ( (x = LOW) && (y = HIGH) && (z = LOW))             //condition 3
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = HIGH;
    ledPin4 = LOW;
    ledPin5 = LOW;
    ledPin6 = LOW;
    ledPin7 = LOW;
    ledPin8 = LOW;
  }

  if ( (x = LOW) && (y = HIGH) && (z = HIGH))              //condition 4
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = LOW;
    ledPin4 = HIGH;
    ledPin5 = LOW;
    ledPin6 = LOW;
    ledPin7 = LOW;
    ledPin8 = LOW;
  }

  if ( (x = HIGH) && (y = LOW) && (z = LOW))               //condition 5
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = LOW;
    ledPin4 = LOW;
    ledPin5 = HIGH;
    ledPin6 = LOW;
    ledPin7 = LOW;
    ledPin8 = LOW;
  }

  if ( (x = HIGH) && (y = LOW) && (z = HIGH))               //condition 6
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = LOW;
    ledPin4 = LOW;
    ledPin5 = LOW;
    ledPin6 = HIGH;
    ledPin7 = LOW;
    ledPin8 = LOW;
  }

  if ( (x = HIGH) && (y = HIGH) && (z = LOW))                //condition 7
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = LOW;
    ledPin4 = LOW;
    ledPin5 = LOW;
    ledPin6 = LOW;
    ledPin7 = HIGH;
    ledPin8 = LOW;
  }

  if ( (x = HIGH) && (y = HIGH) && (z = HIGH))                //condition 8
  {
    ledPin1 = LOW;
    ledPin2 = LOW;
    ledPin3 = LOW;
    ledPin4 = LOW;
    ledPin5 = LOW;
    ledPin6 = LOW;
    ledPin7 = LOW;
    ledPin8 = HIGH;
  }
}

I used your code as a reference but when I uploaded it, it gives me "too few arguments to function". Any solutions?

digitalWrite (ledPin1 = HIGH); should be digitalWrite (ledPin1, HIGH);
PS if ( (x = LOW) && (y = LOW) && (z = LOW)) should be if ( (x == LOW) && (y == LOW) && (z == LOW)). = is for assignment, == is for comparison.

Thanks I changed all of that in the code. I just dont know why the simulation program is still not lighting the LED.

you should simply write code to compute the state necessary for each led based on the truth table and write out that state to the specific digital pin only once; you would not need so many if/else conditions and so many calls to the digitalWrite function either; by the way your code will also work fine if you update your assignments to digitalWrite statements in your code in all the if/else blocks;

void loop() {
 if ( (x = LOW) && (y = LOW) && (z = LOW))              //condition 1
 {

Apart from the issue of needing == instead of = you are never reading those pins. In fact you are comparing the pin numbers (which will never change), not the data on those pins.
You need:
void loop() {
  if ( (digitalRead (x) == LOW) &&
       (digitalRead (y) == LOW) &&
       (digitalRead (z) == LOW))              //condition 1
    {

... and so on.

This is wrong too, I'm surprised it compiled:

   digitalWrite (ledPin1 = HIGH);
   digitalWrite (ledPin2 = LOW);
   digitalWrite (ledPin3 = LOW);
   digitalWrite (ledPin4 = LOW);
   digitalWrite (ledPin5 = LOW);
   digitalWrite (ledPin6 = LOW);
   digitalWrite (ledPin7 = LOW);
   digitalWrite (ledPin8 = LOW);

It should be:
  digitalWrite (ledPin1, HIGH);
  digitalWrite (ledPin2, LOW);
  digitalWrite (ledPin3, LOW);
  digitalWrite (ledPin4, LOW);
  digitalWrite (ledPin5, LOW);
  digitalWrite (ledPin6, LOW);
  digitalWrite (ledPin7, LOW);
  digitalWrite (ledPin8, LOW);

when i use digital write i get an error code saying that there are too few arguments.
  ...
   I just dont know why the simulation program is still not lighting the LED

Oh I see, it did not compile. No wonder the LEDs didn't turn on.

Here's a little tip for you (it has nothing to do with your problem, it's just a good programming method).  This will massively reduce the size of your program.
You have three boolean state variables, and you are comparing the state of all combinations - that's 8 combinations.  If you take each boolean value as 1 bit of a value between 0 and 7 - that is values (as binary) 000, 001, 010, 011, 100, 101, 110, and 111 - then you can use much simpler methods for controlling your LEDs.
For instance, this (untested) code will turn three digital reads into a single number between 0 and 7:
uint8_t value = digitalRead(x) | (digitalRead(y) << 1) | (digitalRead(z) << 2);

x is the least significant bit, and z is the most significant.  So value will now be a value between 0 and 7 representing the state of those three pins.
Now you can use that value variable to decide which pin to turn on.  Here's another trick:  Store you LED pins as an array.  That means, instead of having ledPin1, ledPin2, etc, you just have a list of pin numbers known as ledPin[x]:
const uint8_t ledPin[8] = { 2, 3, 4, 7, 8, 9, 12, 13 };

Now you can use a for loop to iterate though that list and turn on the LED you want:
for (uint8_t i = 0; i < 8; i++) {
    if (i == value) {
        digitalWrite(ledPin[i], HIGH);
    } else {
        digitalWrite(ledPin[i], LOW);
    }
}

In fact, that can be further compressed, since HIGH and LOW are basically truth values (HIGH is 1, or true, and LOW is 0, or false):
for (uint8_t i = 0; i < 8; i++) {
    digitalWrite(ledPin[i], i == value);
}

So your whole program could look like this:
const uint8_t x = A3;    // select the input pin for the switch
const uint8_t y = A4;
const uint8_t z = A5;

const uint8_t ledPin[8] = { 2, 3, 4, 7, 8, 9, 12, 13 };

void setup() {
    for (uint8_t i = 0; i < 8; i++) {
        pinMode(ledPin[i], OUTPUT);
    }
    pinMode(x, INPUT);
    pinMode(y, INPUT);
    pinMode(z, INPUT);
}

void loop() {
    uint8_t value = digitalRead(x) | (digitalRead(y) << 1) | (digitalRead(z) << 2);
    for (uint8_t i = 0; i < 8; i++) {
        digitalWrite(ledPin[i], i == value);
    }
}

Saves a huge amount of typing and also ends up using considerably less Flash memory.

Thanks I am still learning about arduino programming. this is definitely an easier way to go about it. thanks again for teaching me this!

Great way to get beginners interested in arrays and booleans by way of showing their utility value. Nice.

Since you mentioned you are new to programming, I am posting your own solution modified to work with right things; this code can be optimize to a great extent if you get good at programming; For your benefit, I will post both your approach and a slightly better approach
Your approach:
int x = A3;    // select the input pin for the switch
int y = A4;
int z = A5;

int ledPin1 = 2;      // select the pin for the LED
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 7;
int ledPin5 = 8;
int ledPin6 = 9;
int ledPin7 = 12;
int ledPin8 = 13;

void setup(){

    // declare the ledPin as an OUTPUT:
    pinMode(ledPin1, OUTPUT);
    pinMode(ledPin2, OUTPUT);
    pinMode(ledPin3, OUTPUT);
    pinMode(ledPin4, OUTPUT);
    pinMode(ledPin5, OUTPUT);
    pinMode(ledPin6, OUTPUT);
    pinMode(ledPin7, OUTPUT);
    pinMode(ledPin8, OUTPUT);

    pinMode(x, INPUT);
    pinMode(y, INPUT);
    pinMode(z, INPUT);
}

void loop() {

    if ( (x = LOW) && (y = LOW) && (z = LOW))              //condition 1
    {
        digitalWrite (ledPin1, HIGH);
        digitalWrite (ledPin2, LOW);
        digitalWrite (ledPin3, LOW);
        digitalWrite (ledPin4, LOW);
        digitalWrite (ledPin5, LOW);
        digitalWrite (ledPin6, LOW);
        digitalWrite (ledPin7, LOW);
        digitalWrite (ledPin8, LOW);
    }

    if ( (x = LOW) && (y = LOW) && (z = HIGH))             //condition 2
    {
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin2, HIGH);
        digitalWrite(ledPin3, LOW);
        digitalWrite(ledPin4, LOW);
        digitalWrite(ledPin5, LOW);
        digitalWrite(ledPin6, LOW);
        digitalWrite(ledPin7, LOW);
        digitalWrite(ledPin8, LOW);
    }

    if ( (x = LOW) && (y = HIGH) && (z = LOW))             //condition 3
    {
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin2, LOW);
        digitalWrite(ledPin3, HIGH);
        digitalWrite(ledPin4, LOW);
        digitalWrite(ledPin5, LOW);
        digitalWrite(ledPin6, LOW);
        digitalWrite(ledPin7, LOW);
        digitalWrite(ledPin8, LOW);
    }

    if ( (x = LOW) && (y = HIGH) && (z = HIGH))              //condition 4
    {
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin2, LOW);
        digitalWrite(ledPin3, LOW);
        digitalWrite(ledPin4, HIGH);
        digitalWrite(ledPin5, LOW);
        digitalWrite(ledPin6, LOW);
        digitalWrite(ledPin7, LOW);
        digitalWrite(ledPin8, LOW);
    }

    if ( (x = HIGH) && (y = LOW) && (z = LOW))               //condition 5
    {
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin2, LOW);
        digitalWrite(ledPin3, LOW);
        digitalWrite(ledPin4, LOW);
        digitalWrite(ledPin5, HIGH);
        digitalWrite(ledPin6, LOW);
        digitalWrite(ledPin7, LOW);
        digitalWrite(ledPin8, LOW);
    }

    if ( (x = HIGH) && (y = LOW) && (z = HIGH))               //condition 6
    {
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin2, LOW);
        digitalWrite(ledPin3, LOW);
        digitalWrite(ledPin4, LOW);
        digitalWrite(ledPin5, LOW);
        digitalWrite(ledPin6, HIGH);
        digitalWrite(ledPin7, LOW);
        digitalWrite(ledPin8, LOW);
    }

    if ( (x = HIGH) && (y = HIGH) && (z = LOW))                //condition 7
    {
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin2, LOW);
        digitalWrite(ledPin3, LOW);
        digitalWrite(ledPin4, LOW);
        digitalWrite(ledPin5, LOW);
        digitalWrite(ledPin6, LOW);
        digitalWrite(ledPin7, HIGH);
        digitalWrite(ledPin8, LOW);
    }

    if ( (x = HIGH) && (y = HIGH) && (z = HIGH))                //condition 8
    {
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin2, LOW);
        digitalWrite(ledPin3, LOW);
        digitalWrite(ledPin4, LOW);
        digitalWrite(ledPin5, LOW);
        digitalWrite(ledPin6, LOW);
        digitalWrite(ledPin7, LOW);
        digitalWrite(ledPin8, HIGH);
    }
}

Slightly better approach:(better programmers may be able to write even more optimized code)
int x = A3;    // select the input pin for the switch
int y = A4;
int z = A5;

int ledPin1 = 2;      // select the pin for the LED
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 7;
int ledPin5 = 8;
int ledPin6 = 9;
int ledPin7 = 12;
int ledPin8 = 13;

void setup(){

  // declare the ledPin as an OUTPUT:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(ledPin8, OUTPUT);

  pinMode(x, INPUT);
  pinMode(y, INPUT);
  pinMode(z, INPUT);
}

void loop() {
  int pinToTurnHigh = 2; // just making sure its a valid pin
  if ( (x = LOW) && (y = LOW) && (z = LOW))              //condition 1
  {
    pinToTurnHigh = ledPin1;
  }

  if ( (x = LOW) && (y = LOW) && (z = HIGH))             //condition 2
  {
    pinToTurnHigh = ledPin2;
  }

  if ( (x = LOW) && (y = HIGH) && (z = LOW))             //condition 3
  {
    pinToTurnHigh = ledPin3;
  }

  if ( (x = LOW) && (y = HIGH) && (z = HIGH))              //condition 4
  {
    pinToTurnHigh = ledPin4;
  }

  if ( (x = HIGH) && (y = LOW) && (z = LOW))               //condition 5
  {
    pinToTurnHigh = ledPin5;
  }

  if ( (x = HIGH) && (y = LOW) && (z = HIGH))               //condition 6
  {
    pinToTurnHigh = ledPin6;
  }

  if ( (x = HIGH) && (y = HIGH) && (z = LOW))                //condition 7
  {
    pinToTurnHigh = ledPin7;
  }

  if ( (x = HIGH) && (y = HIGH) && (z = HIGH))                //condition 8
  {
    pinToTurnHigh = ledPin8;
  }
  resetAllLEDs();
  digitalWrite(pinToTurnHigh, HIGH);
}

void resetAllLEDs()
{
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin3, LOW);
  digitalWrite(ledPin4, LOW);
  digitalWrite(ledPin5, LOW);
  digitalWrite(ledPin6, LOW);
  digitalWrite(ledPin7, LOW);
  digitalWrite(ledPin8, LOW);
}

The sole error in digitalWrites is that digitalWrite (ledPin1 = HIGH); should be digitalWrite (ledPin1, HIGH); same for other digitalWrite calls;
"too few arguments to function" clearly implies that the number of arguments you are passing are less than expected by the function;
by the way your code will also work fine if you update your assignments to digitalWrite statements in your code in all the if/else blocks;
you can read more about the digitalWrite function in the link below
https://www.arduino.cc/en/Reference/DigitalWrite


text:
Using CD4053 for arduino
I would like to use CD4053 for multiplexing in arduino but the problem is that I don't understand how CD4053 works, is it the same as CD4051, can someone help me, provide example code and circuit??

Have you looked at the datasheet yet?

Yeah but I really don't understand how it works

You should tell us what you want to achieve, nit how you think it should be done. The 4053 may be a fine choice for your need - or may not be needed at all. Also - provide datasheet link to things you ask about to save need for N people to look up same thing to help you. What is the application? 4051 is a 1 of 8 bidirectional analog selector. You supply 3 address lines which can have 8 address states (000 001 010 011 ... ) and these connect 1 of 8 input / outputs to one master ouput/input. | A 4053 is 3 x SPDT switches. each switch is controlled by it's own enable lead. BUT

... if you do not know how a CD4053 works you cannot possibly know that you need to use one or how to do so in any meaningful way. SO tell us what you are trying to achieve. || CD 4051-53 data sheet

I am actually trying to add more IO pins for my arduino, so I researched and found out that I should use 4051. Then I went to my local electronic shop but they don't have 4051 instead they gave me 4053. Here is the link of the arduino tutorial: http://playground.arduino.cc/Learning/4051 :))

-1 for stating a vague problem and directly demanding a full solution (explanation, circuit and source code).

Consider one of the many I2C I/O boards (search for i2c expander on eBay) that can be purchased for a few bucks.  They are also available from many of the people that support Arduino.   It then only requires 2 pins from the Arduino for up to 8 external devices which can have from 8, 16 and sometimes more I/O per board.  They can be used as input or output.
You can also operate several displays on the same two pins as the I/O.
Have fun

The 4053 can replace the 4051 (data sheet). To do that the three output pins on 4053 should be tied together (pin 4, 14 and 15, see logic diagram).
The device allows adding eight analog pins at the cost of three digital pins and one analog pin. The device will multiplex the eight new analog pins onto the arduino analog pin. Three digital pins are used to select which pin is multiplexed.
The arduino tutorial for 4051 will work just fine with the above modification of the wiring.
Cheers!


text:
Password code using interrupts and timers on Arduino Uno

I have a group project where we are trying to make a user enter a password that we have pre-selected for them. They enter the password using tactile buttons, and they have 5 tries to enter the password correctly. If they enter the password incorrectly, one of 5 LED's will light up to indicate that they have entered it wrong. If they get it right, one LED will light up.
We are using timers to time out the attempt if the users take too long to enter the entire password, or if they take too long between pressing buttons. Also, if they use all 5 tries, we are trying to make the LED's that were on turn off one by one.
Right now the code doesn't get past Serial.print("done").
This is our code:
int input_pin_blue = 5;
int input_pin_yellow = 6;
volatile int state_button_red = LOW;
volatile int state_button_blue = LOW;
volatile int state_button_yellow = LOW;
int num_wrong = 0;
double time_between_buttons = 0;
double time_since_first_button = 0;
const int max_time_between_buttons = 10000;
const int max_time_since_first_button = 30000;
int reset = 4;
void setup() {
    pinMode(input_pin_blue, INPUT);
    pinMode(input_pin_yellow, INPUT);
    pinMode(4, INPUT);
    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(10, OUTPUT);
    pinMode(11, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
    attachInterrupt(0, handler_red, CHANGE);
    attachInterrupt(1, handler_blue_yellow, CHANGE);
    Serial.begin(9600);
}
void loop() {
    Serial.print("bhi"); //wait for button press

    for (num_wrong = 0; num_wrong < 5; num_wrong++) {
        Serial.print("blah"); //wait for button press

        while (state_button_red == LOW && state_button_blue == LOW && state_button_yellow == LOW) {
            Serial.print("waiting"); //wait for button press
        }

        Serial.print("DOne");

        if (state_button_red == LOW) {                  //check if first button pressed is incorrect
            digitalWrite(num_wrong + 8, HIGH);
        } else if (state_button_red == HIGH) {
            time_between_buttons = millis();
            time_since_first_button = millis();

            while (state_button_red == LOW && state_button_blue == LOW && state_button_yellow == LOW
                    && time_between_buttons < max_time_between_buttons && time_since_first_button < max_time_since_first_button) {
                //wait for button press
            }

            if (state_button_yellow == LOW || time_between_buttons < max_time_between_buttons || time_since_first_button < max_time_since_first_button)
//check if second button pressed is incorrect or time has run out
            {
                digitalWrite(num_wrong + 8, HIGH);
            } else if (state_button_yellow == HIGH) {
                time_between_buttons = millis();

                while (state_button_red == LOW && state_button_blue == LOW && state_button_yellow == LOW
                        && time_between_buttons < max_time_between_buttons && time_since_first_button < max_time_since_first_button) {
                    //wait for button press
                }

                if (state_button_blue == LOW || time_between_buttons < max_time_between_buttons || time_since_first_button < max_time_since_first_button)
//check if third button pressed is incorrect or time has run out
                {
                    digitalWrite(num_wrong + 8, HIGH);
                } else if (state_button_blue == HIGH) {
                    time_between_buttons = millis();

                    while (state_button_red == LOW && state_button_blue == LOW && state_button_yellow == LOW
                            && time_between_buttons < max_time_between_buttons && time_since_first_button < max_time_since_first_button) {
                        //wait for button press
                    }

                    if (state_button_yellow == LOW || time_between_buttons < max_time_between_buttons || time_since_first_button < max_time_since_first_button)
//check if fourth(last) button pressed is incorrect or time has run out
                    {
                        digitalWrite(num_wrong + 8, HIGH);
                    } else if (state_button_yellow == HIGH) {
                        digitalWrite(13, HIGH);
                        num_wrong = 10;
                    }
                }
            }
        }
    }

    if (num_wrong == 10) {
        while (digitalRead(reset) == LOW) {
            //wait for reset
        }
    } else if (num_wrong == 5) {
        while (digitalRead(reset) == LOW) {
            digitalWrite(8, LOW);
            delay(100);
            digitalWrite(8, HIGH);
            digitalWrite(9, LOW);
            delay(100);
            digitalWrite(9, HIGH);
            digitalWrite(10, LOW);
            delay(100);
            digitalWrite(10, HIGH);
            digitalWrite(11, LOW);
            delay(100);
            digitalWrite(11, HIGH);
            digitalWrite(12, LOW);
            delay(100);
            digitalWrite(12, HIGH);
        }
    }

    if (digitalRead(reset) == HIGH) {
        digitalWrite(13, LOW);
        delay(100);
        digitalWrite(12, LOW);
        delay(100);
        digitalWrite(11, LOW);
        delay(100);
        digitalWrite(10, LOW);
        delay(100);
        digitalWrite(9, LOW);
        delay(100);
        digitalWrite(8, LOW);
    }
}
// interrupt handler function
void handler_red() {
    state_button_red = !state_button_red;
}
void handler_blue_yellow() {
    if (digitalRead(input_pin_blue) == HIGH) {
        state_button_blue = !state_button_blue;
    }

    if (digitalRead(input_pin_yellow) == HIGH) {
        state_button_yellow = !state_button_yellow;
    }
}

Is there any specific reason why you feel you need to use interrupts for the buttons?

@Majenko it's just one of the requirements for the project that we use 3 interrupts and 2 timers

Ok, that's fair enough. So it's for the purpose of learning how they work, which is good.

I understand that you have to use timers, however, just as comment, if you didn't have such constraint, I think it would be far simpler (and efficient) to define a state machine which reacts exclusively to button presses. When a button is pressed, it checks the time elapsed from the previous button event and acts accordingly.

int input_pin_blue = 5;
int input_pin_yellow = 6;
volatile int state_button_red = LOW;
volatile int state_button_blue = LOW;
volatile int state_button_yellow = LOW;
...
pinMode(input_pin_blue, INPUT);
pinMode(input_pin_yellow, INPUT);
...
attachInterrupt(0, handler_red, CHANGE);
attachInterrupt(1, handler_blue_yellow, CHANGE);

// interrupt handler function
void handler_red() {
    state_button_red = !state_button_red;
}
void handler_blue_yellow() {
    if (digitalRead(input_pin_blue) == HIGH) {
        state_button_blue = !state_button_blue;
    }

    if (digitalRead(input_pin_yellow) == HIGH) {
        state_button_yellow = !state_button_yellow;
    }
}

On the Uno external interrupt 0 is pin D2 not D5, and interrupt 1 is pin D3, not D6.
Hence you are not testing the correct pins.
Also I would use INPUT_PULLUP instead of INPUT mode for those pins, unless you have external pull-up or pull-down resistors on them.