text:
Long run data wire
I need to connect the data of a LED strip (WS2812) to a pin but the strip is 10 meters away using AWG 22.
I use a 12V DC power supply.
Should I expect some misbehaviour, like the LED not getting the right color ?
If so, what could I do ?

What kind of LED strip? What gauge wire? How are you powering it? What signals does it use? etc, etc...

Is the power supply with the LED strip or the Arduino?

What kind of environment are you in?

Both, in a parallel circuit

It can't  be, unless you are bending the fabric of space-time.

The cables coming out my 12 dc transformer who is plug into 220V plug are divided into 2 branches, one for the arduino the other to the LED sttrip

If you are planning to power the LED strip from 12V then you can expect all the LEDs to explode. The WS2812 LEDs require 5V, not 12V.
If you have a large number of WS2812 in your strip, and you are powering them from the Arduino's 5V, then you can expect the Arduino to get extremely hot and go into thermal shutdown, or the voltage regulator to melt.
If you are in a noisy environment (electrically) then you can expect the data to get corrupted over that kind of distance.
What you should do:

Provide 5V to the LED strip from a power supply or regulator that can cope with the amount of current your LED strip needs.
Have another small Arduino next to the LED strip to drive the LEDs and communicate with that Arduino from your master Arduino through a suitable serial protocol that can cope with longer distance communications, or a wireless system.

LED strip has buck regulator, I could not have a 5V supply due to voltage drop so decided to have 12v and a LDO regulator. I unfortunatly cannot put any arduino near the LED strip, oonly small components

How small? You can get some pretty small Arduino boards...

Something as big as an ATtiny

I'm sure you could fit an ESP8266 in there if you tried...

Point of load regulation is a good idea, but you probably want a switching regulator not a linear one unless it is a short LED strip.  An ATtiny may be sufficient, and plenty of other processors including the ATmega come in small packages, the real question is where you LED patterns come from - program logic, an SPI flash, and sdcard, an external signal?  Of course you can also use a line driver and line receiver to accommodate a lengthy wire run between the MCU and the first LED.

I'm using 1 meter 60 Leds and planning on using internal memory of a controller with neopixel library. Line driver and receiver seems to be interesting could you  elaborate ?


text:
Why is my switch not working?
I'm trying to have a common light switch turn a LED on and off.
When I connect the light switch directly to a LED, it works like it should - the LED turns on and off with the switch.
When I connect the light switch back to the board, changing the switch does nothing - I get the exact same signals regardless of whether the switch is on or off.
Why?
How do I make the board recognize whether the switch is on or off?

The diagram I followed:

const int  buttonPin = 2;

const int ledUt = 13;
const int ledTest = 12;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;

int tilstand = 0;

int buttonStateForrigeForrige = 0;

boolean light = false;

void setup() {
  Serial.println("Hello World");
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  pinMode(ledUt, OUTPUT);
  pinMode(ledTest, OUTPUT);

}

void loop() {

  digitalWrite(ledTest, HIGH);
  buttonState = digitalRead(buttonPin);
  Serial.println("Sjekk");

  tilstand = LOW;
  if ( buttonState == HIGH ) {
    Serial.println("buttonState HIGH");
    if ( lastButtonState == HIGH ) {
      Serial.println("lastButtonState HIGH");
      tilstand = HIGH;
    } else {
      Serial.println("lastButtonState LOW");
    }
  } else {
    Serial.println("buttonState LOW");
  }

  if (buttonState != lastButtonState) {

    if (buttonState == HIGH) {
      buttonPushCounter++;
      Serial.println("on");
      Serial.println(buttonPushCounter);
    } else {
      Serial.println("off");
    }
  }
  buttonStateForrigeForrige = lastButtonState;
  lastButtonState = buttonState;

  if (tilstand == HIGH) {
    digitalWrite(ledUt, HIGH);
  } else {
    digitalWrite(ledUt, LOW);
  }
  }

At present this is not clearly stated enough to be answerable.  Your code appears to look for input on pin 2, but your second diagram, perhaps from Nick rather than your actual circuit, provides it on pin 8.  Your original diagram does not provide any useful information to indicate if you have a workable circuit or not.

You can draw a schematic in pen and scan it if you have to. Do you have a resistor in series with the LED?

See my page about switches. Judging by your very-hard-to-read diagram, you have just connected the switch to an input pin like this:

That will not give a positive reading either way because it is "floating". You should connect a pull-up or pull-down resistor, like this:

Now if the switch is open, it is pulled-up to 5V by the resistor and the input will read HIGH. When the switch is closed the switch conducts and "overpowers" the resistor, and it would read LOW.

An alternative is to use a pull-down resistor like this:

That reverses the sense of the switch. When open it will read LOW and when closed it will read HIGH.

I hope you have a resistor in series with the LED.

Sorry, I have no experience in making electronics diagrams.
Your diagram shows just what I did, with a 12k resistor.

source: Stack Exchange

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

authors: ภาณุพันธ์ ชินะวนิชกิจ

sort: votes


text:
Attiny85 - Method to discard glitched ADC values?
I have a problem i need to solve so i will simply it as much as possible.
Basically there is a system with a micro-controller where it reads 2 sensors. These 2 sensors are of variable resistance type, aka their measuring value is output as different resistance. For example one is a pressure sensor where at 0psi the sensor has a value of 20ohms to ground, and for 100psi it has a value of 120ohms. The sensor is connected between ground and a fixed value resistor so the output acts like a voltage divider.
The micro-controller seems to be multiplexing by switching pull up between each 2 sensors (probably because using a single ADC), at random times (as the microcontroller performs other functions) but approx. every 80ms for each sensor, and about 40ms between each sensor. So at 0ms it reads one sensor, at 40ms the other sensor, and at 80ms back at the first sensor and so on. I have no idea why they haven't used a fixed pull-up, but the pull-up is only done when the controller wants to read the sensor for only about 120us.
I wanted to read these sensors to input to an ECU, without affecting the original device. Thus the easiest solution i could think off as the pull-up isn't always high to perform a read, was to add another microcontroller (in my case a Digispark based on the ATtiny85 running at 16.5MHZ). Alternatively i could open up the device and modify it to use a fixed pull-up but let's say i want to avoid this route. The digispark essentially reads both sensor outputs and when it sees a voltage above ground it outputs it to the ECU. I have since then updated the program to check the ADC values it reads so that it is between the nominal range of the sensor. And while this works there are times where the ADC will read a wrong value and output it to the ECU which looks as random spikes and dips in the data.
Look at my following code:
  const int oil_in = 0; //P5
  const int temp_in = 1; //P2
  const int oil_out = 1; //P1
  const int temp_out = 4; //P4
  int oil_value = 0;
  int oil_value_good = 0;
  int temp_value = 0;
  int temp_value_good = 0;

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(oil_out, OUTPUT);
  pinMode(temp_out, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  oil_value = analogRead(oil_in);
  if (oil_value > 106 && oil_value < 466)
  {
    oil_value_good=oil_value;
    analogWrite (oil_out, oil_value_good/4);
  }

    temp_value = analogRead(temp_in);
  if (temp_value > 113 && temp_value < 920)
 {
    temp_value_good=temp_value;
    analogWrite (temp_out, temp_value_good/4);
  }
}

Each ADC pin has a range of acceptable values. These correspond to the MIN AND MAX nominal values for each sensor. However there are times where the ADC will read at the wrong time and it will output either a MIN or a MAX value depending on the condition. I can replicate this on the breadboard by having the input to the ADC reading a nominal value, and by shorting it to either ground or VCC (5V) i can sometimes trick the ADC to read a MIN or MAX value. And since the next measurement will be done after some time, the output will produce these spikes. Since there is no sync between the readings these error data can be sometimes be outputed for 1-1.5s.
I've tried thinking hard about this problem, but i am not sure for a certain solution that will eliminate this problem. ADC interrupts, changing ADC pre-scaler, filtering of data, problem the reading window is really small (100-120us).
Also nominal ADC input values for each sensors are between 0.56V-2.33V for one sensor, and 0.6V-4.68V for the other sensor. Not sure if the interrupt can even be activated at such low voltage.
How do you think i should proceed?
Kind regards

i can sometimes trick the ADC to read a MIN or MAX value - if you short it to Gnd or Vcc, don't you expect this?

Well yes and no, the problem is that the ADC sometimes reads on the falling or rising edge of the signal which might be in the acceptable range, therefore been passed as a "good" value.

I have no idea why they haven't used a fixed pull-up, but the pull-up
  is only done when the controller wants to read the sensor for only
  about 120us.

If you want to get a good resolution in the resistance measurement, the
resistance of your pull-up should be in the same range as the resistance
of your sensor. If your sensors have low resistance, this means the
voltage divider will draw significant current. In order to save energy,
it makes sense to power the voltage divider only while you are doing the
measurement.

the reading window is really small (100-120us).

That's short indeed. If you analogRead() a single channel in a tight
loop, you will get one reading every 108.6 µs (128×14 CPU
cycles ÷ 16.5 MHz), and you have a small risk of missing the
window. If you are reading two channels, then you have about 50% risk of
missing the window.
Here is what I would do:

Set the ADC prescaler to 64 instead of 128. This way you will get one
reading roughly every 54 µs, and at least one sample (but more
often two) during the reading window.
Read a single channel in a tight loop, until you get a value above
your minimum. Then take one more reading and use the largest of the
two as your “good” value.
Switch to the other channel and go back to step 2.

This assumes that outside the reading window your ADC input reads close
to zero, as it is grounded through the sensor, with no pull-up. You then
have, on each channel, a train of positive pulses, and you want to
measure the height of those pulses. There is a small risk of you
sampling the rising edge of a pulse, which could give a wrong value
which is nevertheless above your minimum. If this happens, then the next
sample will be near the center of the pulse. That's why I recommend
taking one extra sample and using the largest of the two.

I've already set the prescaler to 16 actually since depending on the bootloader version i have 16.5Mhz is only when running it through usb, otherwise the cpu runs @16mhz, giving an effective prescaler of 1Mhz which is in the acceptable range in the Atmel datasheet. It didn't affect much to be honest in bench testing (of which i cannot actually replicate exactly 100% the conditions), but last night i've integrated the MovingAverage lib which performs exponential moving average filtering with very good results, although i will do more testing and report back. Will consider the other recs as well

@TnF: 1 MHz is kind of borderline for the ADC frequency: it should work, but expect degraded accuracy. An exponential moving average is very good at filtering out Gaussian white noise, but is far from optimal against sporadic glitches. A median filter would be way better.

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


text:
Arduino nano -> 74HC595 -> LCD display
Greeting to all,
Newbie in the contraption above (Arduino nano -> 74HC595 -> LCD display); I would like some help from the experts.
I connect the 74HC595 to the LCD display using the 4 wires as described on the net.
I download one of the sample sketch and "voilà" the "World welcomed me".
But .... I would like to make use of Q0, Q1, Q2 and Q3 on the 595 for other functions like flashing an LED or connecting a 5V buzzer even if the lcd screen blink for a fraction of second.
ie.:
lcd.setCursor(0, 1);
lcd.print("Welcome to the world");

// flash the LED

delay(100);

lcd.setCursor(0, 1);
lcd.print("Welcome to the world");

Is it possible and (please) HOW?
Thank you for your support.
Eric

Could you post a schematic? It would make helping you much simpler.

The 74hc595 latches the output, so if the RS and E pins stay the same, the display will not blink. Please post a schematic and your sketch as well.

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


text:
Storing a 2 dimensional Array in PROGMEM
I am running a Mega 2560 processor board.
I have a large "unsigned char" database currently stored in a 2 dimensional array in SRAM.  I have plenty of room in program memory and need to move the database to PROGMEM.  It appears that the rules around how to use PROGMEM have changed and the documentation does not reflect the change. I have found a way to store the array in PROGMEM and can access the data statically (ARRAY[0,1]).  If I try to access the array dynamically, (ARRAY[var1,var2]), I get junk.
Since I have seen some questions what I mean by "static" and "Dynamic" I gladly add the following examples:
//Array initialization

const static unsigned char __attribute__ ((progmem)) Image_1d_Array[234]={
  0x00, 0x0e, 0xf8, 0xff, 0xdf, 0x03, 0xc0, 0x1d, 0x60, 0x1f, 0x60, 0x00, 0x03,
   0xdb, 0x01, 0x00, 0x08, 0xe3, 0x07, 0x00, 0x0e, 0x00, 0x1e, 0x30, 0x00, 0x00,
   0x00, 0x0e, 0xf0, 0x07, 0xfc, 0x01, 0xc0, 0x39, 0x00, 0x1f, 0xe0, 0x00, 0x03};

void setup:
  int i;
  char myChar;

//  Static read.  This will give me the correct values
  Serial.print("Image= "); Serial.println(Image_1d_Array[0],HEX);
  Serial.print("Image= "); Serial.println(Image_1d_Array[1],HEX);
  Serial.print("Image= "); Serial.println(Image_1d_Array[2],HEX);
  Serial.print("Image= "); Serial.println(Image_1d_Array[3],HEX);
  Serial.println("");

//  Dynamic read.  This will give me the junk values
  for(i = 0; i <=11; i++){
     Serial.print("AImage= ");
     myChar = pgm_read_byte_near(&Image_1d_Array + i);
     Serial.println(myChar,HEX);
    }

I can't even get a single dimensional array to work dynamically.
Does anybody understand the new rules to access the array?? The following data structures from the Arduino reference manual are no longer supported

prog_char - a signed char (1 byte) -127 to 128
prog_uchar - an unsigned char (1 byte) 0 to 255
prog_int16_t - a signed int (2 bytes) -32,767 to 32,768
prog_uint16_t - an unsigned int (2 bytes) 0 to 65,535
prog_int32_t - a signed long (4 bytes) -2,147,483,648 to * 2,147,483,647.
prog_uint32_t - an unsigned long (4 bytes) 0 to 4,294,967,295

Please edit your question and explain what you mean by the phrases  “access the data statically” and “access the data dynamically”.  You might need to add   a Minimal, Complete, and Verifiable example of code so people don't have to waste time guessing what you did or what you meant.   § AFAIK,  “the rules around how to use PROGMEM have changed” is false.

I tested on an UNO and it works fine if you remove the &.

You wrote:
myChar = pgm_read_byte_near(&Image_1d_Array + i);

Here &Image_1d_Array is the address of the array. Its type is “pointer
to an array of 234 unsigned chars”. When you add i to this pointer,
per the rules of pointer arithmetic, you are actually adding to the
address i times the size of the array.
What you actually mean by &Image_1d_Array is “the address of the first
element of the array”, which can be written &Image_1d_Array[0]. Or you
could rely on the usual “decay to pointer” semantics, and simply write
Image_1d_Array, as suggested  in Johnny Mopp's comment.
Now you should have noticed that both Image_1d_Array and
&Image_1d_Array behave as pointers to the same memory address, only
they have different types. See the
C FAQ and references therein
for more on this distinction.
Note that the usual way of doing what you want is:
myChar = pgm_read_byte_near(&Image_1d_Array[i]);

Thanks for the info, I thought the "i" in "(&Image_1_Array+i)"   was adding an offset of "i" to the Array not "i * Array size".   Big difference!!

@KenKloster: As a general rule, (size_t)(&foo + i) always means (size_t)&foo + i * sizeof foo. Note that size_t is just an integer type large enough to hold a pointer.


text:
Bluno + PS3 controller?
I'm seeking information about connecting a PS3 controller using Bluetooth to an Arduino.
Bluno cards could be an integrated solution for that, but can it work?
Also, I've seen some tutorials using a USB shield + a Bluetooth dongle: in this case, at some setup steps a USB connection is needed between the PS3 controller and the Arduino. It is still the case with a Bluno card?

While not strictly impossible, using a PS3 controller with the Bluno (ATmega + CC254x) is essentially impractical.
The PS3 controller is either a USB device, or a classic Bluetooth device.

A USB device can only communicate with a USB host.  Neither the ATmega nor the CC254x on the Bluno is capable of being a USB host.  An add-on USB host shield would cost more than simply buying a platform suitable for fulfilling the entire requirement natively.
The CC254x only speaks Bluetooth Low Energy.  It is not compatible with classic Bluetooth devices. To communicate with the PS3 via Bluetooth you would need to add a Bluetooth classic radio to the system.

If you wish to use a PS3 controller you should pick a non-Arduino platform having native USB Host capability or native classic Bluetooth capability.
Otherwise, if you wish to use an Arduino-like platform, pick an earlier generation controller with either a very old wire-per-function interface or a simple synchronous serial interface, for example a PS2 controller.


text:
Arduino sensing its 'Motion'
I am working on a project where I need the Arduino to 'sense' at what direction its moving. For example, I want the Arduino to 'sense' that it
is moving towards 'forward' direction, 'backwards' direction etc.
Is that possible using an Arduino? Can I use a motion sensor to do this (probably not)?
Can any one please help me to find the right 'direction'?

For this you need a acceleration/gyro sensor, like the MPU6050.
By tracking x/y/z movements, you can define what is forward/backards etc. Also you can track angles/tilts (in 3 directions).
See an example how to use it here: MPU-6050

Thank you, I don't wanna go deep here, but is there a library present which I could use to make my work easier?

You can change the example as library, or maybe this link helps: https://maker.pro/arduino/tutorial/how-to-interface-arduino-and-the-mpu-6050-sensor
I never tried the MPU6050 myself.

Well I tried by borrowing one from a friend, it worked  thanks

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


text:
How can I play music using a speaker and Micro SD card Module?
I am trying to play music using my Arduino and micro SD card module but can't seem to do it. Can anyone shed some light on this? The SD card module I'm using is a Catalex sainsmart micro SD card module. It has the outputs VCC, GND, MISO, MOSI, CS, and SCK. VCC is in 5v, GND is in GND, CS is in Pin 4, MISO is in Pin 12, and MOSI is in Pin 11.

Your question is very broad and more detail is needed. For example, I take it that the music file resides on the SD card but what format would the music be? Would you be willing to change format? Also, what is your circuit? What have you tried so far?

I don't care what kind of file it must be. Also CS is plugged into 4, SCK is plugged into 13, Mosi is plugged into 11, Miso is plugged into 12, VCC is plugged into 5v, and GND is in GND.

please edit your question and add these details. Comments are for information that can be ignored.

This Arduino project is one of the most simple and fun projects you
  can build with Arduino in 10-15 minutes. The result of this make will
  be an Arduino Audio Player which will play “.wav” files. It consist of
  a speaker, a simple transistor acting as an amplifier and a micro-SD
  card adapter with a micro-SD in it through which the .wav files are
  loaded and played.

https://diyhacking.com/arduino-audio-player/

Thank you but does the speaker have to be the one he is using or can it be one that just plays clicks?

I expect any speaker is fine as long as the power is catered for, You can probably just wire a Piezo Speaker directly to output pins to play clicks

Use an MP3 shield. This includes an SD card reader on the board. Many tutorials are available for this popular board. This shield makes it easier to program the Arduino.
https://www.sparkfun.com/products/12660


text:
Built-in capacitive touch detection with SAMD21 development board (Arduino Zero Compatible)
I bought this SAMD21 development board which shows up as an "Arduino/Genuino Zero (Native USB Port)" when plugged in. And I've successfully got a blink sketch running on it all good so far:

The reason I picked up this board was to experiment with the built-in capacitive touch sensor on the SAMD21. In the datasheet for this chip it claims to support a 'Peripheral Touch Controller with 256-Channel capacitive touch and proximity sensing'.
Does anyone know what this exactly means and how I would access this functionality to detect touches in my Arduino code? Obviously there are not 256 IO pins so how would this work? Is there some kind of internal multiplexer?
The 256 channel capacitive touch controller is also mentioned in a Sparkfun video about their SAMD21 board, so it must be possible to access this functionality.
Can someone direct me towards an Arduino library or method and more information on the wiring and pin connections for this. Thanks.

15 dollars at AliExpress. It is the same processor as in the Arduino Zero and Arduino M0. As far as I know there is a small difference for the pins between the Zero and the M0. You can find the complete datasheet here: http://www.microchip.com/wwwproducts/en/ATsamd21g18 The pins can be used in a matrix. For using it, they point to the Atmel QTouch library. Someone at Arduino has done a good job by mentioning the PTC pins in the table: https://github.com/arduino/ArduinoCore-samd/blob/master/variants/arduino_zero/variant.cpp So far I can only find this: https://github.com/jgilbert20/Libre_PTC

Thanks for pointing me towards this Libre_PTC library, it looks very promising. I really hope Jeremy continues work on this and adds support for SAMD21 soon.

You have three options for the silicon-based PTC (peripheral touch controlller).

LibrePTC - My own library that targets the SAMD11 but should work with some modifications for other SAMD architectures. The README file has lot of information on how the PTC works and how to specify designs for it.
Adafruit FreeTouch - Works only with the SAMD21. Given the high quality of the register documentation, I suspect they may have had inside help from Atmel but I haven't been able to reach Ladyada, their primary contributor, to learn more.
QTouch, which is Atmel's library available in closed source only but is extremely feature-rich. Arduino team decided not to allow closed source stuff in their IDE so its been banned from official distributions. However, it is possible to hack it into the Arduino IDE and I've used it successfully that way. However this requires esoteric modification to boards.txt that are beyond the scope of this answer.

The PTC hardware peripheral on the SAMD chips works on self-capacitance using "Y" lines specified in the data sheet. See the README on LibrePTC for details. Some chip variants have more pins broken out. For instance, the SAMD21G has fewer available Y pins than the SAMD21J, although the J series is not as readily available in breakout boards as of the summer of 2017 and it has limited Arduino IDE support. I personally prefer the SAMD11 because it is cheaper ($1.00) and has way more available Y lines in the QFN package.
As of August 2017, I intend to attempt a merge between the Adafruit and LibrePTC libraries but no guarantees when this will happen. I don't have access to insider documentation so my library was 100% reverse engineered through trial and error.

Great. Thanks Jeremy. I’ll start with trying out that Adafruit FreeTouch library, I did’t know Ladyada had written something like this. Then I’ll search for an affordable SAMD11 development board to order and then I'll play around with your library beginning with the SAMD11 and then the SAMD21. And I also really look forward to seeing your updates after merging your’s and the Adafruit libraries.

Will do. The AF library does not work out of the box. For anyone following this, you will need to install the Adafruit_ASFCore library too or use my fork here: https://github.com/jgilbert20/Adafruit_FreeTouch

I had a play with your Adafruit_FreeTouch branch on the SAMD21… It’s doing something when I touch an input so that’s a good thing, but it doesn't seem right. Maybe you could advise me in setting it up, I’m getting very noisy readings with the example code.

Seems to be easy to include the qtouch library now a days... https://github.com/arduino-libraries/Arduino_MCHPTouch


text:
Using Capacitive Sensing Library with a 74HC4067 multiplexer
I'm trying to use the Capacitive Sensing Library by Paul Badger in conjunction with one or more 74HC4067 multiplexers to achieve a lot of capacitive touch inputs. I came across this youtube video where the poster seems to have accomplished what I'm trying but I can't seem to replicate this.
Here is the setup I'm using with an arduino nano, some 1MΩ resistors and a CD74HC4067 breakout :

Here is my Arduino code :
#include <CapacitiveSensor.h>

#define muxS0Pin 7
#define muxS1Pin 6
#define muxS2Pin 5
#define muxS3Pin 4
#define muxSignalPin 3
#define muxEnPin 8
#define capSenseSendPin 2
#define sampleRate 5

int touch[4] = {};

CapacitiveSensor capSense = CapacitiveSensor( capSenseSendPin, muxSignalPin );

void setup() {
    digitalWrite( muxEnPin, LOW );
    Serial.begin( 115200 );
}

void loop(){
    byte touchIndex = 0;
    for ( byte channel = 0; channel < 4; ++channel ) {
        digitalWrite( muxS0Pin, ( channel & 1 ) >> 0 );
        digitalWrite( muxS1Pin, ( channel & 2 ) >> 1 );
        digitalWrite( muxS2Pin, ( channel & 4 ) >> 2 );
        digitalWrite( muxS3Pin, ( channel & 8 ) >> 3 );
        touch[touchIndex] = capSense.capacitiveSensor( sampleRate );
        ++touchIndex;
    }
    for ( byte i = 0; i < 10; ++i ) {
        Serial.print( touch[i] );
        Serial.print("\t");
    }
    Serial.println();
}

This example attempts only four capacitive touch pads but eventually I plan to use all 16 and then another multiplexer, but right now I'm stuck on getting anything, I seem to be getting some readings on touching the last pad but it's not what I expect to see, and it affects all the reading.
I've successfully got a version of this running without a multiplexer just on ten IO pins and it worked great. I also got the multiplexer running fine in a separate example with 16 push buttons.
Could the problem be due to pad charge times or the send-recieve capsense signals getting stopped in the multiplexer?
Any and all help would be appreciated.

Here is the link to the library : http://playground.arduino.cc/Main/CapacitiveSensor

And here's a video of my example not working : https://www.youtube.com/watch?v=4bGJw1UrgOk. The setup in the video is slightly different than the illustration above; I have pads connected to C6 to C15 on the multiplexer and I loop through them backwards to display them in order on the serial monitor. But the point is, it seems to be only the last multiplexer pin that affects all the readings.

Might need to set the mux enable pin (muxEnPin) mode to output in setup().

This is way late, but for anyone who runs across this, here was my solution. The two main thing is explicitly using analog input pins (which could be quantized to digital values in the software, and making sure you have resitors on each channel being sensed. Also, ground the EN pin on the multiplexer
#include <CapacitiveSensor.h>

#define muxS0Pin 9  // I used these rather than 4-7
#define muxS1Pin 10
#define muxS2Pin 11
#define muxS3Pin 12

#define muxSignalPin A0      // explicitly set ro analog
#define capSenseSendPin A2   //

#define sampleRate 10
#define n_inputs 16

int touch[n_inputs] = {};

CapacitiveSensor capSense = CapacitiveSensor( capSenseSendPin, muxSignalPin );

int readMux(int channel) {
  int controlPin[] = {muxS0Pin, muxS1Pin, muxS2Pin, muxS3Pin};

  int muxChannel[16][4] = {
    {0, 0, 0, 0}, //channel 0
    {1, 0, 0, 0}, //channel 1
    {0, 1, 0, 0}, //channel 2
    {1, 1, 0, 0}, //channel 3
    {0, 0, 1, 0}, //channel 4
    {1, 0, 1, 0}, //channel 5
    {0, 1, 1, 0}, //channel 6
    {1, 1, 1, 0}, //channel 7
    {0, 0, 0, 1}, //channel 8
    {1, 0, 0, 1}, //channel 9
    {0, 1, 0, 1}, //channel 10
    {1, 1, 0, 1}, //channel 11
    {0, 0, 1, 1}, //channel 12
    {1, 0, 1, 1}, //channel 13
    {0, 1, 1, 1}, //channel 14
    {1, 1, 1, 1} //channel 15
  };

  //loop through the 4 contol pins
  for (int k = 0; k < 4; k ++) {
    digitalWrite(controlPin[k], muxChannel[channel][k]);
  }
  //read the value at the SIG pin
  return capSense.capacitiveSensor( sampleRate );
}

void setup() {
  // Very important to set control pins to output mode
  pinMode(muxS0Pin, OUTPUT);
  pinMode(muxS1Pin, OUTPUT);
  pinMode(muxS2Pin, OUTPUT);
  pinMode(muxS3Pin, OUTPUT);

  digitalWrite(muxS0Pin, LOW);
  digitalWrite(muxS1Pin, LOW);
  digitalWrite(muxS2Pin, LOW);
  digitalWrite(muxS3Pin, LOW);
  Serial.begin( 9600 );
}

void loop() {
  byte touchIndex = 0;
  for ( byte channel = 0; channel < n_inputs; ++channel ) {
    Serial.print( readMux(channel));
    Serial.print("\t");
  }
  Serial.println();
}


text:
Connect 2 Arduino UNOs via Bluetooth? (HC-05 and HC-06)?
So I've researched this topic a lot online, but haven't found what I'm looking for. Before I tell you this, I'll give you guys an idea of what I'm trying to accomplish. Please understand that I'm an extreme beginner to Arduino, and that I've only been at this for a month or so, but plan on doing so much more.
My friend and I are building an RC car. We have an Android phone that has a downloadable application which connects to the Bluetooth HC-06 module that is on the Arduino UNO. We have configured our circuit, and it works fine! I want to go a step above and beyond, though.
My goal is to build a physical, handheld controller or remote (literally plopping everything on a breadboard), and connect that controller or remote to our car using Bluetooth. We have an HC-05 and HC-06 module, and the HC-06 is on the car. Now comes the doubt.
I understand how the android application sends characters through to the RC Car via Bluetooth; that's pretty straightforward as the two pieces are paired (using Android's Bluetooth Settings). What I don't understand is how to pair the two HC-05 and HC-06 Bluetooth modules. There isn't too much help online, I feel. I've looked and people have shown that they connect, but they don't explain the theory, so to speak.
What I want to understand is:

How the two HC-05 and HC-06 modules pair, and
How can I read input from one (remote controller) and execute an action on the other (RC car). From the app-to-Arduino, I was using Serial.available() to see if the Serial had any characters sent over from the application. I can't see how I can do that with HC-05 to HC-06 pairing, however. This concept is hard for me to grasp.

Any help is greatly appreciated. Thank you!

You need to set HC-05 to master, and this done by soldering pin 34 of BT and connecting it to digital pin on Arduino to enter AT command. Then after powering the Arduino, you need to put pin 34 high. This way it will enter AT command. In serial monitor, follow these AT commands:
AT+cmode=0
AT+ROLE=1 // THIS WILL SET THE BT AS MASTER
AT+INIT
AT+LINK= ????,??,??????  // REPLACE ?... WITH HC-06 MAC ADDR

Have a look at this for how to pair them http://www.martyncurrey.com/connecting-2-arduinos-by-bluetooth-using-a-hc-05-and-a-hc-06-pair-bind-and-link basically you need to use the AT mode.
As far as I know you will be using the serial connection to communicate, but if you are using UNOs debugging becomes a bit more difficult, because you can't use serial for debugging.

For this you just have to pair the both bluetooth modules with each other.!
For this use AT commands.
You can find those here:
https://www.rcscomponents.kiev.ua/datasheets/hc_hc-05-user-instructions-bluetooth.pdf.
For pairing use MAC address of one module and hardcode it in second module using AT commands.
Now from theory point of view for pairing between any two bluetooth modules,there are some handshaking signals which are processed and if they are correctly processed then the device gets paired.
Its very hard to debug. But for that purpose use software serial


text:
How to read and write EEPROM in ESP8266
I need to know how I can write integer values in EEPROM and retain the value on power on.
char *Red = strstr(myTestUrl, "/R");
if (Red) {
  int RedValue  = atoi(Red + 2);
  analogWrite(12, RedValue);
  Serial.println("Red :");
  Serial.println(RedValue);
}

I want to write RedValue in EEPROM. How can it be done?

Have a look in the EEPROM sample sketches that are installed when you add ESP8266 support to the arduino ide

having a question if there are any flash dependencies using the EEPROM. Can I flash with 1 MB (no SPIFFS) and have access to EEPROM? Thanks T

While EEPROM.read and EEPROM.write are valid methods, it's like mopping the floor with a toothbrush. Use EEPROM.put and EEPROM.get instead.
For example:
#include <EEPROM.h>

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

  uint addr = 0;

  // fake data
  struct {
    uint val = 0;
    char str[20] = "";
  } data;

  // commit 512 bytes of ESP8266 flash (for "EEPROM" emulation)
  // this step actually loads the content (512 bytes) of flash into
  // a 512-byte-array cache in RAM
  EEPROM.begin(512);

  // read bytes (i.e. sizeof(data) from "EEPROM"),
  // in reality, reads from byte-array cache
  // cast bytes into structure called data
  EEPROM.get(addr,data);
  Serial.println("Old values are: "+String(data.val)+","+String(data.str));

  // fiddle with the data "read" from EEPROM
  data.val += 5;
  if ( strcmp(data.str,"hello") == 0 )
      strncpy(data.str, "jerry",20);
  else
      strncpy(data.str, "hello",20);

  // replace values in byte-array cache with modified data
  // no changes made to flash, all in local byte-array cache
  EEPROM.put(addr,data);

  // actually write the content of byte-array cache to
  // hardware flash.  flash write occurs if and only if one or more byte
  // in byte-array cache has been changed, but if so, ALL 512 bytes are
  // written to flash
  EEPROM.commit();

  // clear 'data' structure
  data.val = 0;
  strncpy(data.str,"",20);

  // reload data for EEPROM, see the change
  //   OOPS, not actually reading flash, but reading byte-array cache (in RAM),
  //   power cycle ESP8266 to really see the flash/"EEPROM" updated
  EEPROM.get(addr,data);
  Serial.println("New values are: "+String(data.val)+","+String(data.str));
}

void loop()
{
  delay(1000);
}

UPDATE:  If you want to understand how the "EEPROM" is emulated in the ESP8266, you might want to reference https://github.com/esp8266/Arduino/tree/master/libraries/EEPROM, specifically, EEPROM.h.
Also, EEPROM.end is not needed, it simply clears the local byte-array cache of the flash/EEPROM from RAM.  It serves on other function.

you have saved my day, I was searching for more than five hours for a solution and you have gave it !

The actual Arduino documentation is really lacking here and the sources do not really help either. Is EEPROM.end() still needed? Why is begin(512) needed?
Plus a get()/put() combination or using update() would help to prevent EEPROM wear. Maybe you could update the answer.

I did a copy/paste of this exact code for a NodeMCU v3 and it's not retrieving the written value after a power cycle (I commented out the "write portion for the second run").

@WhiskerBiscuit,  are you seeing ANY output in serial console?  are you sure baud rate is set correctly?   i don't have v3, just v0.9, so can't help if this is a forwards compatibility problem.

from reference "EEPROM.write does not write to flash immediately, instead you must call EEPROM.commit() whenever you wish to save changes to flash. EEPROM.end() will also commit, and will release the RAM copy of EEPROM contents."

What I have learnt practically is that EEPROM.commit() is absolutely necessary, at least on esp8266, in order for the EEPROM data to survive a reboot.

Method using the number of letters.
#include <ESP8266WiFi.h>

const char* SSID = "R360"; //MAX 32
const char* PASSWORD = "HFDYUK64323246"; //MAX 32

#include <EEPROM.h>

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

  EEPROM_ESP8266_GRABAR(SSID, 0); //Primero de 0 al 32, del 32 al 64, etc
  EEPROM_ESP8266_GRABAR(PASSWORD, 32); //SAVE

  Serial.println();
  Serial.println(EEPROM_ESP8266_LEER(0, 32));//Primero de 0 al 32, del 32 al 64, etc
  Serial.println(EEPROM_ESP8266_LEER(32, 64));

  WiFi.begin(EEPROM_ESP8266_LEER(0,32).c_str(), EEPROM_ESP8266_LEER(32,64).c_str());

}
//
void loop() {}
//
void EEPROM_ESP8266_GRABAR(String buffer, int N) {
  EEPROM.begin(512); delay(10);
  for (int L = 0; L < 32; ++L) {
    EEPROM.write(N + L, buffer[L]);
  }
  EEPROM.commit();
}
//
String EEPROM_ESP8266_LEER(int min, int max) {
  EEPROM.begin(512); delay(10); String buffer;
  for (int L = min; L < max; ++L)
    if (isAlphaNumeric(EEPROM.read(L)))
      buffer += char(EEPROM.read(L));
  return buffer;
}

I use 2 separate functions in my code on ESP8266 - one with EEPROM.put(), one with EEPROM.get().
I had EEPROM.begin(sizeof...); only in EEPROM.put() function and put worked.
But it took me quite a while, until I found out, that it must be used before EEPROM.get() as well.

Use #include <EEPROM.h>
EEPROM.begin(size); //Size can be anywhere between 4 and 4096 bytes.
EEPROM.write(0, RedValue);   // To store in 0th Location
EEPROM.commit();


text:
When the TX and RX pins for Bluetooth are connected the LCD screen will not update. Why is that?
I have connected a Bluetooth shield and LCD screen to an Arduino Uno. I have two active low push buttons to increase or decrease the variable desiredTemp. This value is meant to be displayed on the LCD screen, and on my smartphone over the Bluetooth serial connection.
This works as intended for my smartphone, however, when my transmission and receive pins are connected to the board the LCD screen is frozen until the pins are removed. Additionally, I'm not able to update the desiredTemp variable through the Bluetooth serial connection.
Attached is my code:
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>

LiquidCrystal LCD(10,9,3,2,1,0);
double inIRPin = A0;
double inThermPin = A1;

int LED = 4;
char recvChar;

int increaseTemp = 7;
int decreaseTemp = 6;
int increaseTempState = 0;
int decreaseTempState = 0;

#define RxD         13
#define TxD         12
SoftwareSerial BTSerial(RxD,TxD);

double valIR = 0;
double valTherm = 0;
double val = 0;
double temp = 0;
double const tempRatio = 0.125;
double desiredTemp = 40; //Degrees Celcius

void setup() {
 // put your setup code here, to run once:

 pinMode(increaseTemp,INPUT);
 pinMode(decreaseTemp,INPUT);

pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(LED, OUTPUT);
setupBlueToothConnection();

pinMode(inIRPin, INPUT);
pinMode(inThermPin, INPUT);
LCD.begin(16,2);
LCD.setCursor(0,0);

}

void loop() {
  // put your main code here, to run repeatedly:
   valIR = analogRead(inIRPin); //IR Sensor Output
  valTherm = analogRead(inThermPin);

   increaseTempState = digitalRead(increaseTemp);
   decreaseTempState = digitalRead(decreaseTemp);

   if(increaseTempState == LOW){
    desiredTemp++;
  }
   if(decreaseTempState == LOW){
     desiredTemp--;
   }
   if(BTSerial.available()){
      recvChar = BTSerial.read();
      Serial.print(recvChar);
      BTSerial.println(desiredTemp);
      if(increaseTempState == LOW){
         desiredTemp++;
         updateLCD();
       }
       if(decreaseTempState == LOW){
         desiredTemp--;
         updateLCD();
       }
       if(recvChar == '1'){
         BTSerial.println("Increasing Temp");
         desiredTemp++;
       }
       if(recvChar == '0'){
         BTSerial.println("Decreasing Temp");
         desiredTemp--;
       }
   }
    updateLCD();
  }

 void setupBlueToothConnection()
 {
    BTSerial.begin(9600);

    BTSerial.print("AT");
    delay(400);

    BTSerial.print("AT+DEFAULT");             // Restore all setup value to
    factory setup
    delay(2000);

    BTSerial.print("AT+NAMESmartCoaster");    // set the bluetooth name
    delay(400);

    BTSerial.print("AT+PIN0000");             // set the pair code to connect
    delay(400);

    BTSerial.print("AT+AUTH1");             //
    delay(400);

    BTSerial.flush();

  }

 void updateLCD(){
      LCD.setCursor(0,0);
      LCD.print("Current Temp:");
      LCD.println(temp);
      LCD.setCursor(0,1);
      LCD.print("Desired Temp:");
      LCD.println(desiredTemp);
      delay(100);
  }

So you connected the LCD to RX and TX pins and wonder why the LCD fails when the serial sends something?

Nope the LCD screen is using pins 10,9,3,2,1,0. Rx is using pin 13 and Tx is using pin 12.

Serial.print(recvChar); sends to pins 0 and 1.

I need some help with Arduino serial communication, could you please tell me one thing, if I want to connect two serial communication with Arduino Uno pin 2,3 and normal hardware serial communication 0,1 and two devices are one is Bluetooth and another one is GPS, so my question is there is any problem will come during the time of receiving and transmitting data from Bluetooth? And the next question is what serial communication we can use for this type of project?

You connected the LCD module to serial hardware pins 0 (RX) and 1 (TX).
When you receive the data from the Bluetooth module, through the software serial, you send it to the hardware serial.
if(BTSerial.available()){
      recvChar = BTSerial.read();
      Serial.print(recvChar);
...

This messes up the communication with the LCD module. Remove Serial.print(recvChar); and it should work.

A more sensible solution would be to use hardware serial for the Bluetooth module and the other pins for the LCD module.
Software serial should only be used, if you really can't use the hardware serial, e.g. you need the hardware serial to communicate with another device (a PC or some other module).


text:
Serial structure data transfer between an Arduino and a Linux PC
I use the Arduino compatible chipKIT WF32 board. I want to transfer structure data between my board and a Linux PC. Can I do it like the following?
struct data d;
char *tx = (char*)d;
Serial.print(tx);

Even if the above code works, the data type size in Arduino and on Linux will vary. Is there a way to serialize the data, like Protocol Buffers on Arduino?

Casting to a char* will make Serial.print expect a null terminated string. So the amount of data transferred will depend on the next zero byte in memory(arbitrary).

The following solution isn't strictly portable, but it should work as long as both ends are little-endian (most platforms).
You can use the GCC attribute packed to tell the compiler not to pad the fields like this:
struct __attribute__ ((packed)) my_struct {
  char c;
  int32_t n;
};

Then you can send your struct like this:
Serial.write((uint8_t*) a_my_struct_ptr, sizeof(my_struct));

On the receiving end you just copy the received data to a similarly packed struct. If you would rather use Python over C/C++ you can use the struct module to unserialize the data.

I just googled your product and the MIPS processor is bi-endian, but I will assume that it is configured for little-endian by default. You can try and see if ints keep their value after transmit. Also remember to use explicit size types such as int16_t, uint64_t, etc.

This may get messy - is an int 32 bits on the chipkit reflecting its processor's actual word width, or is it 16 bits for compatibility with ATmega-insipired Arduinos?  It probably makes sense to use explicit width types on both ends.

Yes you are right I forgot to consider that, I've updated the answer to use fixed size types.

@lionlai The __attribute__ ((packed)) makes sure no padding is applied. If padding was used, you would get into trouble trying to send data from eg. an 8 bit platform to a 32 bit one.
However, sizeof does represent the size of the structure in memory including padding. Try this on eg. x86 printf("%d\n", sizeof(struct {uint8_t a; uint32_t b;})); It should print 8 (remember to include stdint.h).

I usually send structures from arduino via serial port to PC and use the memcpy function to do it.
Let's say you have the struct data d (as pointed by the comments the memcpy as unnecessary. Use cast or union):
 struct data state;
 len = sizeof(state);
 Serial.write((uint8_t *)&state,len);

It is useful to create a starting and ending character to delimit your important data and make sure you receive all data and good information.
Let me give you one of my recent work example:
...

void send_state(){
 len = sizeof(state);
 Serial.write('S');
 Serial.write((uint8_t *)&state, len);
 Serial.write('E');
 return;
}
...

In this example the struct state is preceded with "S" (start) and succeeded with "E".
Then in python, for example, you can get the data using the unpack function. In my case:
...

# wait for data from arduino
myByte = port.read(1)
if myByte == 'S':
    data = port.read(39)
    myByte = port.read(1)
    if myByte == 'E':
        # is  a valid message struct
        new_values = unpack('<c6BH14B4f', data)

...

See if arduino sends data in little endian. The one I have used to send it.

What do you hope to achieve by re-buffering the data especially on the transmit side?  It is already in memory, so if you have a reason for making a copy of it, that should be stated.

Thanks for pointing out. Indeed it is not necessary (and even stupid). I do not really remember any particular reason for that, but looking at it after all this time, I would guess it was some newbie mistake due to compile error related to the Serial.write expecting uint8_t and I (stupidly) made that work around. The simple cast should be enough or more safely, as I've been learning here, using unions right?


text:
How to check my Arduino board is working or dead?
When you have a board in your hand but you don't know is it working or not, how to verify if it's working or dead?

I would suggest that the title and question is either changed to be "Arduino Uno", or the tag "uno" is removed and the question made more generic.

See also https://arduino.stackexchange.com/a/13293/39212 for several more checks.

Note : After the @Ricardo's comment on my last post, I am posting this !

Plug the board into a USB port on your computer and check that the green LED power indicator on the board illuminates. Standard Arduino boards (Uno, Duemilanove, and Mega) have a green LED power indicator located near the reset switch.
An orange LED near the center of the board (labeled “Pin 13 LED” in the image below) should flash on and off when the board is powered up (boards come from the factory preloaded with software to flash the LED as a simple check that the board is working).

If the power LED does not illuminate when the board is connected to your computer, the board is probably not receiving power.
The flashing LED (connected to digital output pin 13) is being controlled by code running on the board (new boards are preloaded with the Blink example sketch). If the pin 13 LED is flashing, the sketch is running correctly, which means the chip on the board is working. If the green power LED is on but the pin 13 LED is not flashing, it could be that the factory code is not on the chip. If you are not using a standard board, it may not have a built-in LED on pin 13, so check the documentation for details of your board.
Online guides for getting started with Arduino are available at for Windows,  for Mac OS X, and for Linux.

Note: This will work only if the USB port or the FTDI chip have not been burnt. The Atmega chip could be functioning correctly even if these two components are not.

+1 Right on, Hardik! Funny thing is that just yesterday someone asked a question about a problem with their Arduino and I wanted to point it to your answer. Now we can do it properly.

@Ricardo : Bingo :P

If you reset the board (with the button), the bootloader usually flashes the pin 13 LED

My first board was a Duemilanove and came with a dead FTDI chip. Was very frustrating until I got a working replacement board.

Supposed one owns a USB programmer, there's another way to inspect the Arduino.
Connect the programmer to the ICSP pins of the Arduino and call avrdude with the right parameters to read the fuses of your Arduino.
avrdude -c programmer-id -p partno -P port

For an Arduino Uno, partno is m328p. Programmer-id depends on the device used. In my case (mySmartUSB light) stk500v2 is a supported and port is /dev/ttyUSB0. Here
avrdude -c stk500v2 -p m328p -P /dev/ttyUSB0

gives the following output
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e950f
avrdude: safemode: Fuses OK
avrdude done.  Thank you.

The UNO board responds with the correct signature and is ready for some action :)
How to connect?
My USB programmer came with a 6-wire ribbon cable with 2x3 female connectors on both sides. As usual, the wire for pin 1 is marked red. Due to a notch in at the 2x3 male connector of the programmer, the cable only fits here in one direction.
If you look at the Arduino UNO, the ICSP header is to the right of the reset button.
The pinout is as follows.

MISO  1    2 VCC
SCK   3    4 MOSI
RESET 5    6 GND

NOTE Pin 1 is the top left one, marked with a white dot!

This won't test the USB->Serial interface however.

@Cybergibbons Absolutely true! But even with a fried USB, there might still be a chance to flash the Arduino using the programmer then ;)

+1 Good to know! Will put my 3 dead ATmegas through this test. Do you know how to check the fuses using an Arduino UNO as a programmer, with the ArduinoISP sketch loaded?

If you have another, working, Uno, and both have socketed microcontroller chips, you could use the known board to program a test sketch onto the unknown board's chip, put it back on the unknown board, and run it.
I like the following (pseudo-coded) test sketch for quick-checking my hand-built boards; it's just as handy for testing an unknown factory-built one. It's not an exhaustive test, it just checks for basic digital I/O, serial I/O, and shorts or opens:
forever,
  for each digital I/O pin:
    write high;
    delay 100ms;
    write low;
  end;

  write "Hello, World!\n" to serial output;
  while serial character available,
    write character to serial output;
  end;
  write "\n" to the serial output;
end;

A test LED - an LED with its resistor soldered to it - connected between any I/O and ground should blink every 2 seconds. If it doesn't, that pin may have failed or have a bad connection.
Two test LEDs connected to numerically adjacent pins (they may not be physically next to one another) should blink in sequence. If they blink together, it indicates a short, probably a solder bridge, between them.
The terminal should say "Hello World!" every two seconds. If not, that pin or the FTDI cable or on-board USB/Serial chip may have failed.
Type something on the keyboard and it should be repeated back to the serial terminal (if the previous test passed). If not, again that pin or the FTDI cable or on-board USB/Serial chip may have failed.


text:
"avrdude: stk500_getsync(): not in sync: resp=0x00," aka Some Dude Named Avr Won't Let Me Upload My Program
I made an awesome program the other day, and I wanted to upload it to my Arduino. After clicking the upload button, some mean dude named avr came along and stopped me, saying:

avrdude: stk500_getsync(): not in sync: resp=0x00

All I want to do is just upload my program, but avr won't let me. He's even unintelligible, so can someone tell me what the heck he's trying to say and how to get rid of him?

i.e.:
Whenever I try to upload a program to my Arduino, I get this error message:

avrdude: stk500_getsync(): not in sync: resp=0x00

What does this mean, and how can I fix it?

Pretty common error message, not always trivial to solve: http://electronics.stackexchange.com/search?q=avrdude%3A+stk500_getsync%28%29%3A+not+in+sync%3A+resp%3D0x00

Nice title! I've had that error myself...

+1 for the title :D... I really hate this dude as much as you did!

This June 2018 post solved it for me (1st answer): https://arduino.stackexchange.com/questions/51729/ch340-nano-avrdude-stk500-getsync-not-in-sync-resp-0xa4

I had the same problem and tried the common suggestions to no avail. I could see output from the old code in the serial monitor. I switched to UECIDE and it built and uploaded with no problems or changes. Not sure what's happening, but it was an easy fix.

I was working with NANO. And I found this problem can be solved by selecting old bootloader of 328 p

For me it was as simple as a bad USB cable. It was the same cable I used in the past but I guess it finally died. Important to note that if you're getting the sync error AND you also don't see your Arduino show up on your computer as an attached USB drive, then it's definitely a bad USB cable.

In my case, it was the problem of the Bluetooth shield. I removed it and the problem solved. After uploading, I reconnected it.

This is caused by a generic connection error between your computer and the Arduino, and can result from many different specific problems.
Here are some easy things that can often fix this error:

Disconnect and reconnect the USB cable.
Press the reset button on the board.
Restart the Arduino IDE.
Make sure you select the right board in Tools ► Board ►, e.g. If you are using the Duemilanove 328, select that instead of Duemilanove 128. The board should say what version it is on the microchip.
Make sure you selected the right port in Tools ► Serial Port ►. One way to figure out which port it is on is by following these steps:

Disconnect the USB cable.
Go to Tools ► Serial Port ► and see which ports are listed (e.g. COM4 COM5 COM14).
Reconnect the USB cable.
Go back to Tools ► Serial Port ►, and see which port appeared that wasn't there before.

Make sure digital pins 0 and 1 do not have any parts connected, including any shields.

If none of those work, you will want to try to isolate the issue by replacing things: try a different computer on the same arduino, try a different arduino on the same computer, and try using a different USB cable.
If the issue is with the computer:

Double-check all computer-related issues in the "easy fixes" list above.
Reinstall the IDE.
Reinstall the drivers.

If the issue is with the Arduino:

Double-check all board-related issues in the "easy fixes" list above.
Make sure the microcontroller is seated correctly.
You may need to burn the bootloader.
Replace the microcontroller if you have another one handy nearby.
You may have bricked your Arduino. Sorry :(

There are other possible causes. Your could have damaged the ATmega, you could have damaged the bootloader on the ATmega, you could have power issues, or a myriad of other possibilities. The not in sync: resp=0x00 is really a generic "ATmega not responding" message. Anything that could cause the ATmega to not respond can cause it.

So can I not have anything in 0 or 1 ever?

@Tim You can connect stuff to those pins, but you have to disconnect them if you want to communicate with your Arduino via the USB cable.

I got this error on my very first Duemillanove years ago. It was a dead UART chip (or connection from USB to UART chip). Very frustrating. I bought an AVR programmer and burned the bootloader. Purchased another CPU with bootloader preloaded. Wasn't until vendor sent a replacement that I was able to join the world of Arduino aficionados (and I now have two spare CPUs).

"Disconnect and reconnect the USB cable" works for me

The part about pins 0 and 1.  Kinda sucks when the whole point of your project is a 232 port on pins 0 and 1. UGH

"Press the reset button on the board" helped.

Thank you so much. This error went away when I removed my ethernet shield and tried uploading. You just helped me meet a serious deadline.

Could you please append also  Tools->Processor->Atmega 328P to Atmega 328P (Old Bootloader)    to the list of possible solutions.

Note about the bootloader: On the Arduino Uno and Mega 2560, there's actually two bootloaders! One on the microcontroller which the sketch gets written to, and one on the 16u2 which handles the USB stack and acts as the actual programmer for the sketch-micro. In my case, the 16u2 was the problem.

I bought a 3 pack of cheap rexqualis nanos on amazon. The first one I was trying kept giving me this error so I tried another and it worked fine...odd

For me it was a component connected to digital port 0

@TheGuywithTheHat: you were absolutely correct. I bought my board from Aliexpress https://www.aliexpress.us/item/2251832472713563.html?spm=a2g0o.order_detail.0.0.8149f19c0AgE4n&gatewayAdapt=glo2usa&_randl_shipto=US and was trying to use "Arduino Pro or Pro Mini" as my board which keep giving me this error, after I read more about the board I figured its based on ESP8266, so I installed the driver and then selected "Node MCU 1.0" which worked just fine. Thanks a lot.

Another fix:
Change Tools->Processor->Atmega 328P to Atmega 328P (Old Bootloader). Remind that the Processor option is only available when you select some specific Boards at Tools>Board.
This worked for my Arduino Nano with CH340, using Arduino IDE 1.8.5 under Linux Ubuntu 17.10. Besides, this will probably happen if you use IDE 1.8.9 or newer and you get an old or cloned Nano.

Unfortunately, it can also mean that you burned your microcontroller. Were you doing anything dangerous right before you tried to upload a new sketch? Is the microcontroller still working, with its previously loaded sketch?

In my case I hadn't wired the RTS pin of the FTDI chip to a capacitor which went to the RST pin of the Arduino Pro Mini.  Once I installed this connection, I no longer got the error and I was able to upload code.
Nick Gammon explains this in his forum.
I've added a picture of where/how the capacitor should be placed.

+1 for the nice picture of the usb programmer hookup directly to an atmega chip.

I also had some bad connections on my board, I unplugged everything and uploaded a basic sketch and it worked. Now go figure what cable is not in the right place

I am using ATMEGA8-16PC. I burned the bootloader onto the mcu with SCK, MISO and MOSI pins on the my Arduino uno. Do I then need to change the connections to TxD and RxD to upload sketches to the mcu? Like say making a LED at mcu's Pin 1 blink.

If none of the above steps work, try reinstalling Avrdude and the avr-gcc compiler. I had to do this after my Mega started suffering from this.
If you installed Avrdude and avr-gcc separately, simply uninstall them. if not, you may have to reinstall the Arduino IDE. These steps will depend on your operating system.

Its highly unlikely that the problem would be caused because of the toolchain being used. This is too extreme, IMO.

What is this installation process you are talking about? The arduino editor tool is just unzipped. There is no installation process.

I've had the same message. Every time it has been solved by selecting the right port ie USB under the menu Tools then Ports. Its a simple step but I always forget. I'll unplug the Arduino to stop the current program, plug it in again to my computer to upload the new program and get the error, panic, curse, and only then, remember.

I had the exact same problem. I tried installing the IDE in another laptop and uploaded the program from that laptop. Problem solved. Then I came back to my laptop, uninstalled the IDE and re-install it.. it started working.
However, I wasn't satisfied because I couldn't find the source of the problem... so I tried running everything again the same exact way... I found the problem but not sure if that can be the actual cause of it.
In my project, I needed to carry out serial communication between arduino and MATLAB (GUI). In order to see/verify the output(type) of MATLAB (GUI) serial data, I used HYPERTERMINAL and also VIRTUAL SERIAL PORT EMULATOR. I noticed that every time when when hyperterminal is running or VSPE is running while my serial monitor is on it screws up the uploading feature of the program. I'm not sure if it's because of the VSPE or HYPERTERMINAL, but reinstalling the IDE worked for me.

One of the Serial Control lines, I think it is DTR, is used to reset the Arduino. When you try to program your Arduino, your terminal program could be interfering.

This worked for me only when I also deleted my Arduino Library folder, which contains all settings and extra libs.

For people using Linux Mint I found that by selecting the "TTY SO" port instead of the one labeled "Arduino" it would work (I can't tell you exactly because I don't have that computer in front of me right now).
Then the next time I used the Arduino I again got the same message so I switched back to the "Arduino" port and it has worked that way ever since.
I am not as technically knowledgeable as the rest of you guys so I have no idea why this works or what the problem was, but it worked which is all I care about.  Maybe this will be useful to someone.

I uninstalled the IDE and drivers etc, installed it all again, then I ran the Arduino IDE as an administrator and set to run compatibility as windows 7 (I'm currently using 10).
I also changed the programmer to AVR ISP (I don't think this matters, but I changed it anyway).
All is working again... hopefully, this can help someone else out too.

I had a similar issue with my Uno board
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x90

Tried many methods

Press reset before sending packets
different IDE versions
Change cable
Change controller itself
Loopback test

but all of the above failed.
I use Ubuntu 16.04.4 LTS 4.15.0-33-generic (while writing this comment). The CDC ACM module was not loaded, therefore no /dev/ttyACM0 device was created to select in Arduino IDE -> Tools -> Port
Therefore,
Get the module name and load it
$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 005: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

$ sudo modprobe cdc-acm

The above command will insert the required module.
Now i'm able to select the right port and upload the code
Out of various solutions this worked for me, hope this helps someone too.

An unusual one but I've been swapping out the microcontrollers a lot and i got this error when one wasn't seated correctly.. i was able to burn a few times but i guess it slipped back out - a little push on the back of the ATMega328 fixed it!

I had this error come up too. It was the first time using a new Arduino Nano board after I had soldered on headers. Just tyring the Blink Sketch, nothing was connected to the board.
I found a tiny short of solder between the GROUND and RESET pins. I picked it off and then I could upload ok.
I suppose this might happen if you had the same short on a circuit somewhere.

There is also the possibility of the the controller itself being placed the wrong way in the socket on the Arduino. This can be dangerous for the controller (which may get zapped) but, in my case, it only gave the out of sync error, preventing me from uploading code.
So just check if the notch on the IC is in the right direction (you can cross check with images of board online). The notch on the Uno's controller should point towards edge of board.

Just had this same error with a brand new Mini Pro.  Since the default blink program that came preloaded with most Arduino is running, I know that the unit is probably OK.
So I inspected the headers I just soldered one more time, and found that there was not enough solder on the TX0 pins.  After re-soldering every works.

I solved it by updating the boards (under "board manager")

Do you have an Arduino Nano?

I had this error in my Linux Mint 17.3 laptop with Arduino Nano
avrdude: stk500_getsync(): not in sync: resp=0x00
Solved:

removed all that had 'arduino' or 'avr' in its name
removed directories .arduino and .arduino15 (Note the dot in the name)
removed ver 1.8.7 with uninstall of the packet
apt-get install arduino (ver 1.1.0)
tested with a simple sketch (everything OK)
installed ver 1.8.7 with the install of the packet
compiled.
selected ATmega328p(Old bootloader) for processor, Arduino Nano for card and /dev/ttyUSB0 for port
=> IT WORKS !

It seems that the 'Old bootloader' was the trick in this case.
I have now both ver 1.1.0 an 1.8.7, who cares.

you should first read the answer from aguadopd

What I tried was to not connect one Ground of one board to the other ground on the other board. This stopped the problem for me.

I faced the same problem for some code today and I solved it as follows:
1- First I ran  a basic LED blinking code. It gave the same error. It confirms that  the error is in uploading  and has nothing to do with compiling. I also checked my code was compiling fine.
2- I took another board, but it was working fine on this PC. That  means computer and the USB wire is OK.
3- I connected the faulty board to another PC, and surprisingly, there was no such error in uploading. That gave me hint about issues in driver in the first PC.
4- So I uninstalled the driver and re-installed it on the first PC by downloading from here
( make sure that while installing the driver from this link, you keep your board  connected to the PC)
It worked fine now :-)

After lots of unplugging, checking ports, restarting IDE, etc. The ting which seemed to make a difference fixing this fault with Arduino Mega 2560 was to uninstall the windows USB arduino driver then reinstall it usig the driver here & select manually from the list>com ports>arduino
http://drivers.softpedia.com/get/Other-DRIVERS-TOOLS/Others/Arduino-Mega-2560-USB-Driver-1110-for-Windows-7-64-bit.shtml
I may have tested it on my uno then back to the mega so there's a small chance talking to the uno made AVRDUDE happy but unlikely.

If you use arduino-cli and a Arduino Nano clone, you can change the bootloader to the old one, as said in other answers, by using the following command to upload to the Arduino:
arduino-cli upload -v -p /dev/ttyUSB0 --fqbn arduino:avr:nano:cpu=atmega328old program_name

Explanation:

command
explanation

arduino-cli
call arduino-cli

-v
Use verbose output

-p /dev/ttyUSB0
The port, use arduino-cli board list to find the right port

--fqbn arduino:avr:nano:cpu=atmega328old
Use avr board library, nano board and the Atmega328 CPU with the old bootloader

program_name
Replace this with the name of the program you want to upload

When I get a problem uploading to my boards I upload a different program like the blink example.  This seems to reset something and I am then able to upload my own program (which is quite large).
It might be worth trying this to see if it works in your case, although I have no idea why it works.

what board and bootloader?

Arduino Nano, ATMega328P (not 3rd party).  Hardware Version: 2, Firmware Version: 1.16, device signature is 0x1e950f
I have not checked the bootloader, but they are advertised as the "traditional bootloader"

so your answer is specific for old Nano bootloader

Thanks!  I will look at bootloaders and try to upgrade it.  Do you have any info on this bug?


text:
Run an Arduino without a PC
I would like to use an Arduino to make tasks in my life automatic - maybe to rotate every morning a motor, or to open a door.
So, can I run an Arduino as solo with no pc needed? Can i connect it to the Internet and can I setup software like PHP and Apache on it to control it over the internet? Has it any protocols like SSH like a normal server?
As an example: I will send over any protocol a signal to my Arduino with a certification and then the Arduino would run a function...
Is that possible?
thanks ahead

You can run the Arduino without a PC. use arduino to make tasks in my life automatic - what tasks do you have in mind?

i will send via putty to my arduino a command and the arduino open my garden door with electric

I will use arduino to make tasks in my life automatic maybe to let rotate every morning a motor or to open the door.

That's the kind of thing it's designed for.

So i will ask can i run arduino as solo so no pc needed,

Yes, you only need a PC to program it, once programmed it will run without the PC.

Can I connect it to the internet

Yes, there are Ethernet and WiFi shields available for connecting it to a network.

and can I setup PHP and Apache on it to control it over it; has it any protocols like SSH like an normal server ?

No.  The Arduino isn't powerful enough to run software like that.  You would normally connect it via the network / internet to a server to process data.  It would just receive simple instructions or send data to the server for processing.

as example: I will send over any protocol a signal to my Arduino with a certification and then the Arduino is running a function...

I assume by "a certification" you want to run SSL on the Arduino. That's not going to happen since it's way too underpowered for that.  As I mentioned earlier, the Arduino would connect to a server on the internet to receive its instructions, or you could interface to it directly within your local network (say from a smart phone) through a simple web server interface (very simplistic due to lack of memory - a few buttons and text, that sort of thing).

It is debatable if the Intel Edison can be called "Arduino", but it has an expansion board which allows to interfacing with Arduino shields and it can  run Apache/PHP/you-name-it.

I don't count the Edison as an Arduino. It's an embedded computer with an Arduino strapped on the side.  Personally I'd rather go for a Raspberry Pi 2 with a chipKIT Pi on top of it.

From that perspective, Edison is less of a cheat than Yun and Tre.
While both Yun and Tre make use of a separate microcontroller, to emulate the Arduino functionality, the Edison has only one Quark core for certain specific functionality. Last time I checked the PI2, it was still depending on a binary blob for booting, so I don't think it's the best choice. If I have to stay in the ARM filed, I think a BBB or an ODroid are much better choices.

Bbb is better than Pi certainly, but there is no chipKIT daughterboard available yet.


text:
IRremote library and Moteino
Does somebody know if the IRremote library is compatible with Moteino boards?
If not, do you know a cheap solution to build a IR-remote controllable via wireless?

Yes, the moteino is just an UNO clone using the same ATMega328P microcontroller.

You need two spare digital pins to use the IR-library. These pins can be set to whatever you like. Pins D3 to D7 are free on the Moteino so the library will be OK to use if you connect the IR LED and receiver to two of those pins.

Your Arduino do not need to be wireless to be able to control it wirelessly.
If you have a wireless network at home (which most people do), there is usally some ethernet RJ45 ports as well.
So instead you use a very cheap ENC28J60 to connect your arduino to the network. You can then access your Arduino wirelessly through your home router. As long as it is connected to your local network its should work.
As for connecting the IR sender and reciever, you need as said before, one digital pin for recieving IR-signals and one digital pin for sending. Which should be no problem even when adding the ENC28J60. It should also work very well with the Moteino if you choose to go that way.


text:
Send and Read packet XBee AT mode
I have a simple network created using XBee Series 2 devices.
My network is very simple, my end-device with Arduino Uno read a temperature and Lightning, display this value into LCD and send using XBee to a coordinator. It is setting for sleep and wake up using PIN hibernation.
It is setting like End-Device AT mode.
I try to send a Remote AT command with XCTU from coordinator to my end device and it parse this command and response.
What I try to do is parse received packet into my Arduino code and decide what response (for example discharge it).
It is possible to do using only one Serial? The Arduino Uno and XBee are connected with an XBee shield.
I have try using this code but the Arduino don't display the packet received from the Coordinator.
This is my code:
#include <avr/sleep.h>
#define XBEE_sleepPin 7
#include <LiquidCrystal.h>

//Sensor variable
int sensorPin = 0;
int fotoResistenzaPin = A1;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
String data = "";
String name = "Arduino1";

//Time Variable
unsigned long seconds = 1000L;
unsigned long minutes = seconds * 60;
unsigned long hours = minutes * 60;

void setup() {
  pinMode(fotoResistenzaPin, INPUT);
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Status:");
  lcd.setCursor(0, 1);
  lcd.print("Connected");
  Serial.begin(9600);
  delay(2000);
}

void xbeesleep() {
  delay (300);
  pinMode (XBEE_sleepPin, OUTPUT);   // put XBee to sleep
  digitalWrite(XBEE_sleepPin, HIGH); // Setting this pin to LOW turns off the pull up resistor, thus saving precious current
  //delay(10 * minutes);
  delay(5 * seconds);
}

void xbeewake() {
  pinMode(XBEE_sleepPin, OUTPUT);  // Set the "wake-up pin" to output
  digitalWrite(XBEE_sleepPin, LOW); // wake-up XBee
  delay(10 * seconds); //make sure that XBee is ready, time to connect to Xbee Coordinator

}

void loop() {
 //wait message
  if (Serial.available()>0) {

    //see if it is a Xbee packet
    if (Serial.read() == 0x7E) {

      for (int i = 0; i < 15; i++) {
        byte skip = Serial.read();
        Serial.println(skip);

        //check if it is a Remote AT commnad
        if (skip == 0x17) {

            //do something when i find the Remote AT command packet
          lcd.setCursor(0, 0);
          lcd.print("Remote AT command ");
        }
      }
    }
  }

  xbeewake();
  int reading = analogRead(sensorPin);
  int val = analogRead(fotoResistenzaPin);
  float voltage = reading * 5.0;
  voltage /= 1024.0;

  float temperatureC = (voltage - 0.5) * 100 ;
  data = name + ',' + temperatureC + ',' + val;
  if (Serial) {
    Serial.println(data);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Temp: ");
    lcd.print(temperatureC);
    lcd.print(" C");
    lcd.setCursor(0, 1);
    lcd.print("Lightning: ");
    lcd.print(val);
  }
  else {
    lcd.setCursor(0, 0);
    lcd.print("Serial Error ");
    lcd.setCursor(0, 1);
    lcd.print("Stop Trasmission");
  }

  xbeesleep();

}

I'm not sure about this, but similar to any other serial communication modules used on the Arduino, you need to setup a software serial pins which act as Tx and Rx between the Arduino and the module, XBee in this case. Look at software serial. this should solve your problem. Then you can use the "Serial" object to debug your communication between the two. I have worked with both a GSM and a Wifi module and the method was the same as I have explained above.

That not correct for all Arduinos, some have multiple serial ports (Mega), but for the Uno (which it looks like this is) then its the right way of doing things.


text:
Can I use an ATmega328 alone without anything and what is the max voltage I can power the atmega328 with
Okay 2 questions. If I am to replace the Arduino with an ATmega328 programmed with a standard blink on pin 13, is this configuration correct, do I still need oscillators and whatnot?

Second question is, what is the max voltage I can power the ATmega328 with without frying it? I have seen conflicting answers of this on the net. Some have said 5V while some say 6V can someone clarify?

Always go to the official source: http://www.mouser.com/pdfdocs/Gravitech_ATMEGA328_datasheet.pdf  (page 18)

@Jasmine alright it says 1.8v - 5.5v. okay thats one down. Then is this a possible way to hook up an atmega328 in place of the arduino?

Check this question: http://electronics.stackexchange.com/questions/53713/what-is-the-minimal-set-of-parts-for-a-circut-with-this-avr-microcontroller

My advice would be to research a standard board like Arduino, and keep what you feel is necessary. For example, keep the voltage regulator, but remove the blink led.

You also need to connect the other GND (pin 22) and the AVCC (pin 20).

The datasheet describes the electrical and clock requirements of the chip, and AVR042 describes the external hardware configuration required. Decoupling, analog voltages, external crystal or oscillator if required.

If you take a look at the Standalone Arduino on the Arduino website, then this is what you require:

Note that there is one slight error in the guide, which I have highlighted here, Arduino Standalone - photo shows incorrect pin wired to MOSI.
There is a video on how to achieve, more or less, the same thing, 1-Day Project: Build Your Own Arduino Uno for $5.

You only need all that if you're trying to replicate an Uno. The chip itself is fine with very few external components, all supply-related.

@IgnacioVazquez-Abrams - Good point. I was going to update my answer later - with the minimal setup (the timing caps etc. in lieu of the xtal) - but time isn't on my side currently. ;-)

@IgnacioVazquez-Abrams - I think I'm going to delete this answer, as it is wrong and Nick's answer is the right one. Mine is just cluttering up the question :-)

I have a page describing How to make an Arduino-compatible minimal board. The minimal setup would be:

That excludes the circuitry for uploading your code.
By the way, in the image in the question you have an LED with no resistor. That will damage both the LED and the Atmega328. You need a current-limiting resistor.

do I still need oscillators

Not if you program the fuse to use the internal oscillator.

Some have said 5v while some say 6v can someone clarify?

The datasheet says 1.8 to 5.5 V operating range with an absolute maximum rating of 6 V.
This is what the datasheet says about absolute maximum ratings:

This is a stress rating only and functional operation of the device at these
  or other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability.

Page 2 of the datasheet says:

Operating Voltage:
1.8 - 5.5V

That is poor positioning of the decoupling capacitors since there are large high-frequency loops. Also, the distance between the ground pins means that some of the peripherals on the chip will have a slightly different ground potential.

Ach, I knew I should have re-taken that photograph! I'll get onto it. The other photo currently posted seems to have the caps even further away though. :P -- I'm not sure what you mean by the distance between the ground pins. What would you do differently there?

I use a very short wire going directly over the chip to connect them.

I've redone the photo with the decoupling capacitors adjacent to the pins. I haven't put the short wire in, as I think that would just make the photo look cluttered. I'm not sure if the different ground potential for analog ground would make a lot of difference to the operation, perhaps the ADC readings would be affected slightly.

It's not "analog ground", it's ground for the peripherals that happen to be on that side of the die.

Oh, OK, I suppose that makes more sense.


text:
SainSmart CO2 sensor module use?
I purchased this CO2 sensor a while back: SainSmart MG811 Gas CO2 Carbon Dioxide Sensor Module Sensor Module for Arduino UNO R3 Raspberry Pi
The module has four pins, Vin, GND, Dout and Aout. I assume Dout and Aout are digital output and analog output, respectively.
Other than that, the sensor came with no datasheet, instructions, or tutorial. I also searched online but fail to find anything useful.
I'm going simple for now, just hooking up the sensor module to Arduino board. I know I can probably connect the output pins to the analog pins, and analogRead them, but what I am looking for is how to convert the raw data readings into CO2 levels in PPM. Like a formula.
Also, I'm curious as to how the digital output works...

http://www.olimex.cl/pdf/CO2b.pdf

The Dout is a TTL threshold indicator; basically it goes high when a certain threshold of the sensor is reached, which is adjusted by the pot.  The Aout is the VRef of the sensor.
Now the MG-811 is not the best sensor in the world; I did look at the datasheet which shows this sensor outputs mV in relation to the PPM so a map function could be used such as 100-600mV maps to 400-10000ppm CO2, see MG-811 CO2 Sensor Module, so you could feed this into a map() function and get the result but since there is a signal conditioning circuit consisting of a op-amp I'm not sure what it does to the raw sensor voltage.
Now the sandbox electronics module may not be identical to the SainSmart module, so you may need to reverse engineer the module you have to determine what is going on or use the schematic from the sandbox site to build your own and de-solder the MG-811 from the SainSmart module.

You can not directly convert the reading to ppm because you do not know what value means what ppm. You'd need at least one calibration point to calculate how many particles per million there are. The sensor is both affected by temperature and humidity so you might wish to compensate that too.


text:
Unexpected value change of 2nd Potentiometer
I'm trying to connect 2 potentiometer (10k) and pass their value to Hairless Midi software (For Serial to Midi Bridge) the first pot is working fine but the second pot's value keep on changing and when i move around the knob of pot1 the value of pot 2 also changes.
I have tried reading the value twice but no luck....
My code:
void setup()
{
   Serial.begin(9600);
}

void loop()
{
  analogRead(0);
   val = analogRead(0)/8;   // Divide by 8 to get range of 0-127 for midi
   if (val > lastVal+1 or val < lastVal+1 )
   {
   MIDImessage(176,1,val);}
   lastVal = val;

  analogRead(2);
   val2 = analogRead(2)/8;   // Divide by 8 to get range of 0-127 for midi
   if (val2 > lastVal2 + 1 or val2 < lastVal2 + 1 )
   {
   MIDImessage(176,2,val2);}         // 176 = CC command, 2 = Which Control, val = value read from Potentionmeter 2
   lastVal2 = val2;

   //val3 = analogRead(2)/8;   // Divide by 8 to get range of 0-127 for midi
   //if (val3 != lastVal3)
   //{
   //MIDImessage(176,3,val3);}         // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
   //lastVal3 = val3;

delay(100);
}

void MIDImessage(byte command, byte data1, byte data2) //pass values out through standard Midi Command
{
   Serial.write(command);
   Serial.write(data1);
   Serial.write(data2);
}

What happens if you swap the two pot? That shield point to whether it’s a software or hardware problem.

I have tried swapping the pots,changing the input pin number but still the problem persist...

What is your circuit? Did you wire the pots in series maybe?

Give me 5 min i will upload my circuit...

You should have something like that, right? (https://i.sstatic.net/JrLxr.png)

This is my circuit

You must have an error in your circuit. It works on my Arduino Nano and 2 pots perfectly. See screenshot https://i.sstatic.net/ZVzLR.png and code https://pastebin.com/Ww7JcBp0 and circuit picture https://i.sstatic.net/5zpN0.jpg

I have connected the same way as my circuit image and your is also the same right...

Try to add more debugging. Instead of connecting the serial to a MIDI device, let it print out the raw Pot analog values and the "would be sent" MIDI bytes to your PC.

One More thing i tried out what i did was I removed the pot one connection from arduino and connected the pot 2 to arduino pin 0 which was earlier used for pot 1. So here the values are changing automatically...adding the circuit

Let us continue this discussion in chat.

Also posted on the Arduino Forum

@tttapa  that's me who had posted on the Arduino forum  i got a lot of help from there but got stuck at this point so posted it here also...

As I was having chat with @Maxmilian Gerhardt he suggested to check the voltage of pot 2 so when I checked I was getting 0 volt So he Suggested me there may be a loose connection or something with the beadboard.
So This was a workaround :

Thnx for the help @Maxmilian Gerhardt

Some of those protoboards have power rails split in the middle.


text:
Unable to use ir receiver and motor shield together
#include <IRremote.h>
#include <AFMotor.h>
AF_DCMotor motor(1);

int RECV_PIN = 14;//The definition of the infrared receiver pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600); //Open serial
  irrecv.enableIRIn(); // Initialization infrared receiver
  motor.setSpeed(255);
  motor.run(RELEASE);
  Serial.println("start");
  motor.run(FORWARD);
  delay(1000);
}

void loop()
{
  if (irrecv.decode(&results)) {
    if(results.value==0x3D9AE3F7)
    {

      motor.run(FORWARD);
      delay(2000);
    }
    else if(results.value==0x1BC0157B)
    {
      motor.run(RELEASE);
      motor.run(BACKWARD);
    }
    Serial.println(results.value, HEX);//Wrap output in hex receive code
    Serial.println();//For ease of viewing the output to add a blank line
    irrecv.resume(); //Receiving the next value
  }
}

Motor shield is not working when I use an IR receiver.
I tried connecting the ir receiver in different analog pins but it didn't work. I guess it's due to some error in my code but unable to figure out.

Is the motor using pin 1?

Yes I've connected the motor to pin1 also. I tried running the motor using a separate code and its working fine. @Delta_G

No by pin 1 I meant I connected the motor to the M1(motor ) pin of the motor shield. @Delta_G

What pin on the Uno is it connected to?   It says 1 in the constructor call.

I've tried connecting it (the ir sensor) in all the analong pins as they are not used by the shield @Delta_G

No the motor.  What arduino pin is the motor using?

It's an motor sheild so it's connected to all the pins and it sits on top of the arduino @Delta_G

But most of the pins come through.  Only some of them are used for the actual driving of the motor.  What pins does it use?   Oh never mind.  Just wait until someone who has one of those shields comes along and they may already know.

@Delta_G This shield runs 4 motors so it takes up a lot of pins. Only the analog pins and digital io 2 is free.

That seems unlikely but if true explains your problem.  If it is using pin 0 or 1 then you can’t use Serial.  What motor shield do you have exactly?   Do you have a link?

It's a normal adafruit motor shield https://learn.adafruit.com/adafruit-motor-shield

Are you sure it's the V1 and not the V2?

This would be a lot easier to example if you specified (1) Exactly how are the motors connected to the Arduino -- how are the pins connected to the motor shield, exactly which motor shield are you using, etc. ? (2) Exactly what code are you using when the motors do work? (3) What do you expect to happen with the above code? (4) exactly what actually happens with the above code? (Is it a syntax error in the IDE? Does the IR reciever stuff seem to work, but not the motors? etc.)


text:
Using Two Arduino to Lower Power Consumption
I am planning to build a water quality sensor with ph, temperature, and dissolved oxygen, conductivity. The power consumption looks like it will be very high especially due to the signal isolator, I'm estimating about 250mA. I'm going to place it in a remote area so I need it to be as power-efficient as possible.
I was thinking would this work?
What if I use two Arduino to control the power? The first Arduino will control the power supply to second Arduino, which has the sensor installed, using a timer(RTC) to turn off the power for 30 minutes and on for 30 seconds for it to read the sensor data.
Can this work? What would the circuit look like?
For the isolator, I was thinking to use Tentacle Shield and in the documentation, it says that the isolator itself uses about 150mA plus the sensor circuit.
https://www.whiteboxes.ch/docs/tentacle/t1/#/
Thanks for the help.

Please tell us what signal isolator you are referring to. Some Arduino's (maybe all of them) can be put into sleep modes which can save a lot of power. A good place to start learning how to do this is by using the search bar at the top of the page. There is a LowPower library available in the Arduino IDE.

First of all, you don't need two arduino. You can put arduino in deep sleep. Secondly, if you have a power consumption of 250mA, it is most likely come from all the sensor boards that you have, so you need to have a circuitry (such as an MOSFET) to cut off the power for those boards before the Arduino go into sleep mode.

I added details on the isolator

An Arduino with its leds and linear power regulators is not optimized for minimal power consumption. BTW: How do you signal the results of your sensors and measurement?

I would do as follows:
Software:

Arduino is in sleep mode

every x seconds (x depending on your needs), wake up then switch on and read one sensor after the other and transmit the results or whatever you want to do.

then go back to sleep

Hardware:

as you have 4 sensors, you can connect their outputs to the arduino analog inputs (or digital...)
you will need 4 electronic switches, preferably Mosfets, connected to 4 digital outputs to switch the power of each sensor independently

This should reduce the consumption to the minimum.
Once your system is running, you may also think about using only the AVR microchip, not the complete Arduino, e.g. If you don't need the USB connection. In addition, you can further reduce consumption by clocking the AVR chip to a lower clock, if not using Arduino.

In fact, for a project like this, you should use two Arduinos, one as SLAVE and the other as MASTER.
You mentioned 4 sensors for measuring water quality, but you will have more modules such as RTC and MicroSD to store the data.
So, I think you should use Slave to colect the data from sensors using the Tentacle Shield, and the other Arduino as Master, to MANAGE other modules and the SLAVE.
For this, you can setup the communication between using I2C protocol. For my Major Qualifying Project, I presented a full prototype for Remote Surface Water Parameter Plataform Sensor, using both Arduino Uno (SLAVE) and Mega (MASTER). For power supply, I have used 12V 8A motorcycle battery.
All the data captured by the sensors, were stored locally by SDModulo and sent by a SIM module to a RaspberryPi server.
For low power consumption, you should DeepSleep mode for the Arduinos. You can setup this mode using the RTC module.
Arduino LowPowerDeepSleep.
For the circuit, I think you will be fine if you use the Tentacle Shield. It's already done.

Actually, you can just run 1 Arduino and use it for

All needed measurements
Control power supply to sensors (power off when unneeded)
Additional: use low-power modes of MCU installed in Arduino

Upd: About 2nd option:
You can use electric relay or transistor to control power supply to sensor. Often sensors have several connections: ground (-), Vin(+) and some signal connections. So between power supply and Vin(+) of sensor you can put electric relay. Control pin of electric relay connect to any free pin on Arduino. Therefore, Arduino can enable and disable power supply to sensor just by settings 1 or 0 to that pin. I recommend you to use electric relay, because it is easier, but if you want to try transistor, you can refer to this question & answers: https://electronics.stackexchange.com/questions/95089/switching-9v-using-a-npn-transistor-and-an-arduino
About 3rd option: Arduinos are based on some MCU (often AVR, not always). These MCUs have several low-power modes. You can directly control power mode of MCU to achieve better power-efficiency.
So, you can do 1st and 2nd options, and try to do the 3rd one:

Investigate which MCU installed in your Arduino
Investigate which power modes it supports
Implement power management according to datasheet of this MCU

For example, if you have Arduino Mega 2560, then it is based on ATmega2560 MCU, find datasheet (https://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf) and there find info about power/sleep modes (page 50) and ways to "wake up" from these modes.
Also you can read about it here: https://microchipdeveloper.com/8avr:avrsleep
Also you can try to find some handy libraries for Arduino, for example "Low-Power" and just use them without diving into MCUs, datasheets, etc

How would I go about doing the second option?

@JSK, I've updated answer: added more info about 2nd option


text:
How to prevent an Arduino connected to the Internet from being hacked?
I have an Arduino (with environmental sensors doing measurements) connected to the Internet via ethernet. Can it be hacked? Can someone access it via Internet and upload his own C/C++ code? If, yes how can I prevent this?
Update (03/03/2023): One final thought: Supposing that I have secured USB plug and nobody can access it. However, I am using the Serial interface of the Arduino MEGA 2560. So, Serial_1 is continuously reading. Can someone with physical access to the Arduino inject malicious code via the Serial_1 so that can alter the code inside my Arduino and have access to information?

does it have Ethernet bootloader or ArduinoOTA library?

I am using the Arduino MEGA 2560 R3 + original Arduino Ethernet Shield 2....if that helps...

Depending on the architecture of your solution, the risk could be exposing your home network to the internet. If your Arduino system is designed to accept incoming traffic from the internet, say it runs a web server, and you configure port forwarding on your router to support this, then you expose your network to such a risk.

This depends on what you consider "hacked".
Do you care about someone reading the data, or changing it on its way to the target? Or do you provide endpoints to trigger something in your project from the internet, that only you should be able to do? Then you need to think about authentication and encryption. Though I guess that this data will be published either way, so that is not a big problem. But you should write down every endpoint, that you expose to the internet, and every request you are making. Then decide what level of security you need them to have individually. Exposed endpoints can easily be found and you have to decide yourself, if it is OK for others to use them.
If you mean getting into the device and executing malicious code from there: IOT devices are often vulnerable because of two reasons. They often have an OS (like a small linux OS), that is badly secured (often using standard password). And they often get updates via the internet. If someone can hijack the update process, malicious code might be delivered. An Arduino doesn't have an OS, so that isn't a problem. And hijacking the update process won't be possible, if you don't provide the possibility to update through the network. This makes updating your code a bit more complicated (since you need to connect the Arduino via USB or similar to program it), but more secure. That way no one (not even you) can inject malicious code into your project without physical access to the Arduino. To take up Jurajs comment: Updating through network is normally done by the Ethernet bootloader or the ArduinoOTA library (Over The Air updates). If you are not using those or similar projects, then you will be safe in that regard.

With strangers having physical access to the device it is a different story. To reprogram the Arduino one would need access to Serial (RX0 and TX0) and a possibility to reset the Arduino (either Reset pin or a way for power cycling it), or access to the ISP pins and the reset pin.
If you can secure the Arduino itself from physical access and only expose the Serial1 interface and ground/5V, then you will be safe, since the bootloader is only listening on Serial (RX0 and TX0). But keep in mind, that someone might still break into your project with brute force - depending on how you secured it physically. At that point nothing can stop them from overwriting your code. Only you can assess how big the chance for that is and how bad it would be.
Another point: If someone manages to break into your project, he can read out the program and push it through a deassembler. That doesn't give them the C++ code - they are not seeing C++ code, only assembler, and no meaningful variable names - but if they are determined enough they can read out credentials, that you might have hard coded or saved in EEPROM. Though especially for environmental sensors I would say the chance is very low, that someone would go to such lengths. If you think the danger to be big enough for some inconvenience, you can have a look at code protection (protecting the program memory from being read), though that still doesn't completely block reprogramming.
All in all: Preventing physical access is a big step in security. You yourself need to assess how much security you really need for your project.

I have updated my question...please read it again!! Everyone many thanks for your help...

@just_learning I added some paragraphs about that in my answer