text:
A whole basic game project Arduino
Firstly, I know that I have already posted this. I do not think anyone here is stupid so:
The game is: a power source connected to 6 buttons connected to 6 LEDs. you press them all in the randomly generated order, and they blink in the order pressed after completion, then randomize and reset.
I have an array shuffler code  1)Does the array shuffler work 2)How do I configure ports and attach them to values in the array, 3) How do I use an if-then statement to say if all buttons pressed in order, then LEDs blink 3 times?  I have a picture but not the actual Arduino, so, upon request, I can post the picture. Thank you. code:
void setup() {
    // put your setup code here, to run once:
}

void loop() {
    // put your main code here, to run repeatedly:
    int questionNumberArray[] = {0,1,2,3,4,5,6};//the array itself
    const size_t n = sizeof(questionNumberArray) / //the array used
    sizeof(questionNumberArray[0]);//the base of the array

    for (size_t i = 0; i < n - 1; i++) //the loop itself
    {
        size_t j = random(1, n - i);
        int t = questionNumberArray[i]; //integer output for increase
        questionNumberArray[i] = questionNumberArray[j];//the value definition
        questionNumberArray[j] = t;
    }

}

The six buttons are connected to digital pins (1, 2, 9, 11, 12, 13)

If you've already posted this, why have you posted it again? It won't get answered any quicker.

Possible duplicate of array shuffler if-then and output question

Yes, this version is just much more organized so...I figured people would be more inclined to answer it

my arduino's ports are 1, 2, 9, 11, 12, and 13. for me to link to them at the top of the code how would I distinguish between all the different PinB's. also, they would be pins, not ports right, since there needs to be detection of the button being pressed?

What pins are the 6 buttons connected to?

@Chris ports 1, 2, 9, 11, 12, and 13

I assumed those were for the leds. What pins are the leds on then?

@Chris same. power connects to ports which connects to buttons which then connect to LEDs

The leds need to be connected to some pins in order for the arduino to turn them on and off. Can you upload a picture of the schematic you are using? You can download and make a schematic with a breadboard with fritzing. It's free here: http://fritzing.org/download/

this version is just much more organized so - you know you can edit your original question, right?

So you leds are connected to "pins" not "ports." Since each of the buttons will turn on only 1 led we need to keep track of which button pairs with which led. To do this we can use a struct like this one:
struct ButtonLed{
        int buttonPin;
        int ledPin;
};

You declare a ButtonLed like this: ButtonLed button1 = {1, 0} where the first parameter is the button's pin and the second is the led's pin. (All of the led pins are set to 0 since I don't know which pins you have them connected to.)
And the array will hold the button/led pin pair like this:
ButtonLed questionNumberArray[] = {button1, button2, button3, button4, button5, button6};
Since there are 6 leds you know that your array is size 6 so use this declaration instead
const int n = 6;
I fixed you range for the random number generation. Look at the documentation for random() here https://www.arduino.cc/en/Reference/Random. We can use this function for shuffling the array.
void shuffleArray (ButtonLed arr [], const int size){
    for (int i = 0; i < size - 1; i++){ // iterates through array except last element
        int j = random(0, size); // generates a random index from (0 to n-1) inclusive

        // swap current index with random index
        ButtonLed t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    }
}

We will use this function to wait until the user enters a sequence of button presses:
ButtonLed getButtonPress (ButtonLed arr [], const int size){
    bool pressed = false;
    ButtonLed  pressedButton;
    while (!pressed){ // loops until a button was pressed
        for (int i = 0; i < size && !pressed; i++){ // !pressed allows early out
            if (digitalRead(arr[i].buttonPin)){ // one of the six buttons was pressed
                pressed = true; // exit both loops
                pressedButton = arr[i]; // stores which button was pressed
            }
        }
    }
    return pressedButton; // return the pressed button
}

Essentially it gets stuck in a loop and reads each of the 6 buttons until one of them is pressed and then records which one was pressed.
Try using the code below and read the comments the only thing you need to do is change all the zeros in the ButtonLed declarations to whatever pin the leds are connected to. Also the struct above needs to go into it's only file called "ButtonLed.h" It must be called that.
#include "ButtonLed.h"

// These are ButtonLeds our newly created data type
// they hold both an led's pin and the pin for the button
// that turns it on
ButtonLed button1 = {1, 10};
ButtonLed button2 = {2,  8};
ButtonLed button3 = {9,  7};
ButtonLed button4 = {11, 6};
ButtonLed button5 = {12, 5};
ButtonLed button6 = {13, 4};

// This function will randomly shuffle an array of ButtonLeds
void shuffleArray (ButtonLed arr [], const int size){
    for (int i = 0; i < size - 1; i++){ // iterates through array except last element
        int j = random(0, size); // generates a random index from (0 to size-1) inclusive

        // swap current index with random index
        ButtonLed t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    }
}

ButtonLed getButtonPress (ButtonLed arr [], const int size){
    bool pressed = false;
    ButtonLed  pressedButton;
    while (!pressed){ // loops until a button was pressed
        for (int i = 0; i < size && !pressed; i++){ // !pressed allows early out
            if (digitalRead(arr[i].buttonPin)){ // one of the six buttons was pressed
                digitalWrite(digitalRead(arr[i].ledPin, HIGH); // turns on the led the user chose
                delay(200);
                digitalWrite(digitalRead(arr[i].ledPin, LOW); // turns it back off
                pressed = true; // exit both loops
                pressedButton = arr[i]; // stores which button was pressed
            }
        }
    }
    return pressedButton; // return the pressed button
}

void setup() {
    randomSeed(analogRead(A0));
    // This is how you set up the leds for output
    pinMode(button1.ledPin, OUTPUT);
    pinMode(button2.ledPin, OUTPUT);
    pinMode(button3.ledPin, OUTPUT);
    pinMode(button4.ledPin, OUTPUT);
    pinMode(button5.ledPin, OUTPUT);
    pinMode(button6.ledPin, OUTPUT);

    // This is how you set up the buttons for input
    pinMode(button1.buttonPin, INPUT);
    pinMode(button2.buttonPin, INPUT);
    pinMode(button3.buttonPin, INPUT);
    pinMode(button4.buttonPin, INPUT);
    pinMode(button5.buttonPin, INPUT);
    pinMode(button6.buttonPin, INPUT);
}

void loop() {

    // This array is of type ButtonLed our newly created data type
    ButtonLed questionNumberArray[] = {button1, button2, button3,
                                       button4, button5, button6};
    const size_t n = 6; // array's size

    shuffleArray(questionNumberArray, n);

    numLeds = 1;
    bool guessCorrectly = false;

    // this while loop allows the user to keep trying until they get it right
    while (!guessCorrectly){

        // This loop displays the correct sequence to the user
        for (int i = 0; i < numLeds; i++){
            digitalWrite(questionNumberArray[i].ledPin, HIGH); // turn on the led

            delay(500); // decrease this number to flash faster; increase to flash slower

            digitalWrite(questionNumberArray[i].ledPin, LOW); // turn off the led
        }

        bool correctButton = true; // the user has pressed the correct button
        ButtonLed userSequence [6];      // stores the sequence the user entered
        // lets the user push 6 buttons
        for (int i = 0; i < numLeds; i++){
            userSequence[i] = getButtonPress(questionNumberArray, numLeds);
            delay(500); // delay between button presses
        }

        // check if the user entered the correct sequence
        for (int i = 0; i < numLeds && correctButton; i++){
            if (userSequence[i].buttonPin != questionNumberArray[i].buttonPin)
                correctButton = false;
        }

        if (correctButton){ // user entered the correct sequence
            guessCorrectly = true;
            // This will turn on the leds in the correct sequence
            for (int i = 0; i < numLeds; i++){
                digitalWrite(questionNumberArray[i].ledPin, HIGH); // turn on the led
                delay(500); // delay half a second
                digitalWrite(questionNumberArray[i].ledPin, LOW); // turn off the led
            }
            numLeds++;
            if (numLeds > 6)
                --numLeds;
        }
    }
}

After you are finished typing the code above it ctrl+shift+n and open a new tab called "ButtonLed.h" and add this to it:
#ifndef BUTTONLED_H
#define BUTTONLED_H
#include <Arduino.h>

// We create new data type called ButtonLed which stores the button's pin
    // and the led's pin; this allows us to keep both an led and it's
    // corresponding button together without have to manage 2 arrays
    struct ButtonLed{
        int buttonPin;
        int ledPin;
    };

#endif

Make sure you open a new tab and not a new project. Also as others have said you should really learn how to program. Be aware this code compiles however, I haven't tested it. I will update the code when you tell me what pins the leds are connected to.
Edit 1
I added a while loop that allows the user to keep trying until they guess correctly.
Edit 2
I also updated the code for which pins the leds are connected to. Remember they're connected to "pins" Not "ports.

The arduino looks like this: http://postimg.org/image/j65d4jd6b/59b97e93/

how do I choose an answer

how do i choose an answer, and what are the ports of the buttonLEDs in relation to the picture? They are hitting multiple points, how do I know which to use?

Ok so the way your arduino is set up right now won't work. This is because none of the leds are connected to the Arduino's pins. I have added a picture of a schematic to my answer. You must replicate the schematic exactly in order for it to work with the code. Also what do you mean by "choose an answer"? Do you mean "how do you guess a sequence?" or "how do you choose a sequence for someone else to guess?"

i mean literally the buttons are in place. to replace the zeros, which number do I put for each?

wait...where's the schematic?

Reload the page there's a picture at the end of the answer, also I've updated the code to replace the zeros. However, you have to connect the leds to the digital pins for it to work. You need to change the way your buttons are connected in order for them to work with the code. Did you want the leds to flash in order and then the user must remember that order?

Let us continue this discussion in chat.


text:
Arduino Digital Input Causing Output Problems
I am working on a simple project using an Arduino Mega 2560 that involves reading a 12-bit binary encoder signal and which is used to cycle a digital pin high and low (depending on the angular location of the encoder).
My problem is that when the digital output pin is told to go low, it only goes down to about 4V. I also noticed that it would occasionally dip down to ground, instead of just 4V. Much to my surprise, when I unplug the Arduino, the digital output pin is still reading 4V. When I turned off power to my encoder which is connected up the the Arduino through 12 digital input pins, the output pin dropped down to 0V. When I turn the encoder back on it goes back up to about 4V.
I have tried connecting the output pin to ground and obviously the voltage goes to 0, but as soon as I remove the connection to ground the voltage springs back up to around 4V. It appears as though somehow the voltage being fed to the digital input pins (in the form of a ~5V digital input signal) is preventing the digital output pin from going to ground. I have no idea why this is the case, I have searched all over and could not find any similar complaints. My code is posted below, any help is greatly appreciated!
unsigned long CamAngle = 0;       // Variable to store encoder value
unsigned long PrevCamAngle = 0;   // Variable to store previous encoder value
int i = 0;                        // Cycle index
int BDC[] = {683,2048,3413};      // BDC angle (12-bit encoder value)
int TDC[] = {0,1365,2731};        // TDC angle (12-bit encoder value)

boolean TDCycle = false;          // TDC Cycle
boolean BDCycle = false;          // BDC Cycle
boolean Cycle = true;             // Encoder rollover cycle (replaces TDC cycle 0)

void setup()
{
  pinMode(37, INPUT);           // Encoder bit 0 (PORTC-0)
  pinMode(36, INPUT);           // Encoder bit 1 (PORTC-1)
  pinMode(35, INPUT);           // Encoder bit 2 (PORTC-2)
  pinMode(34, INPUT);           // Encoder bit 3 (PORTC-3)
  pinMode(22, INPUT);           // Encoder bit 4 (PORTA-0)
  pinMode(23, INPUT);           // Encoder bit 5 (PORTA-1)
  pinMode(24, INPUT);           // Encoder bit 6 (PORTA-2)
  pinMode(25, INPUT);           // Encoder bit 7 (PORTA-3)
  pinMode(26, INPUT);           // Encoder bit 8 (PORTA-4)
  pinMode(27, INPUT);           // Encoder bit 9 (PORTA-5)
  pinMode(28, INPUT);           // Encoder bit 10 (PORTA-6)
  pinMode(29, INPUT);           // Encoder bit 11 (PORTA-7)

  pinMode(30, OUTPUT);          // Set PORTC pin 8 to output (stop pin float)
  pinMode(31, OUTPUT);          // Set PORTC pin 7 to output (stop pin float)
  pinMode(32, OUTPUT);          // Set PORTC pin 6 to output (stop pin float)
  pinMode(33, OUTPUT);          // Set PORTC pin 5 to output (stop pin float)

  digitalWrite(30, LOW);        // Set PORTC pin 8 low (stop pin float)
  digitalWrite(31, LOW);        // Set PORTC pin 7 low (stop pin float)
  digitalWrite(32, LOW);        // Set PORTC pin 6 low (stop pin float)
  digitalWrite(33, LOW);        // Set PORTC pin 5 low (stop pin float)

  pinMode(53, OUTPUT);          // Set pin 53 (PORTB-0) as digital output
  digitalWrite(53, LOW);        // Set pin 53 (PORTB-0) LOW

}

void loop()
{

  // Cam Angle Update
  PrevCamAngle = CamAngle;      // Set variable to previous encoder value
  CamAngle = (PINA << 4) + PINC;    // Read encoder, set variable to value

  if (TDCycle == true && CamAngle >= TDC[i])  // Wait for encoder to reach angle if cycle active
  {
    PORTB = 0;                                  // Set digital pin 53 LOW
    TDCycle = false;
    BDCycle = true;
  }

  if (BDCycle == true && CamAngle >= BDC[i])  // Wait for encoder to reach angle if cycle active
  {
    PORTB = 1;                                  // Set digital pin 53 HIGH
    TDCycle = false;
    BDCycle = true;
    i++;
    if (i > 2)                                  // Reset every 3 cycles (3 cycles per revolution)
    {
      i = 0;
      BDCycle = false;
      Cycle = true;
    }
  }

  if (Cycle == true && CamAngle < (PrevCamAngle + 1))  // Wait for encoder to cycle back to 0
  {
    PORTB = 0;                                  // Set digital pin 53 LOW
    BDCycle = true;
    Cycle = false;
  }

}

As you can see I am utilizing direct port manipulation, however I have the same issues when I use the Arduino library commands as well.  I'm fairly certain this is some sort of hardware issue, however I could be wrong.

Could you post a picture of the wiring?

Have you linked the ground of the encoder to the arduino's ground?

Yes, the encoder ground is linked to the Arduino's ground.  I will try to get a schematic of the wiring up shortly.

What is the output connected to? Also is there any resistor between the pin and the connected device?

Sounds like a pull-up / pull-down resistor problem. You're leaving the pin floating instead of giving it the physical ability to go to 0V.

In addition to a schematic of your wiring, also post actual pictures as well. All of us have had many "oh duh" moments where someone looks at our circuit and immediately points out a wiring mistake.

I think you have two issues here.
First:

Much to my surprise, when I unplug the Arduino, the digital output pin is still reading 4V.

With a powered device connected to the input pins, the overvoltage protection diodes power your 5V line with what is called "parasitic power". Those diodes are supposed to clamp an input pin to not exceed 5V, but if the power is off, they actually supply 5V (assuming at least some of the pins are high), hence powering up the processor. It is not designed to do this, and you should not power off the processor in this way.

Second:

My problem is that when the digital output pin is told to go low, it only goes down to about 4V.

I tried out your code, but without the encoder to hand, I just comment out the three "if" tests:
//  if (TDCycle == true && CamAngle >= TDC[i])
...
//  if (BDCycle == true && CamAngle >= BDC[i])
...
//  if (Cycle == true && CamAngle < (PrevCamAngle + 1))

A multimeter on pin 53 reads 0.98V, however this is because the pin is being turned on and off quickly. I can't work out for sure whether some or all of these conditions would be satisfied in sequence (they don't seem directly related). One thing you could do, since you seem to want pin 53 either on or off is use "else", eg.
if (TDCycle == true && CamAngle >= TDC[i])
{
...
} else if (BDCycle == true && CamAngle >= BDC[i])
{
...
}
else if (Cycle == true && CamAngle < (PrevCamAngle + 1))
{
...
}

Now you won't have multiple attempts to turn the pin on and off through one turn through the loop.

source: Stack Exchange

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

sort: votes


text:
IR remote heater
I am having issues to reproduce the remote control of my heater , this is the dump of one button:
Encoding  : UNKNOWN
Code      : A32AB931 (32 bits)
Timing[23]:
     +1300, - 400     +1250, - 450     + 400, -1250     +1250, - 450
     +1250, - 450     + 400, -1250     + 400, -1300     + 400, -1250
     + 400, -1300     + 400, -1250     + 400, -1300     +1250
unsigned int  rawData[23] = {1300,400, 1250,450, 400,1250, 1250,450, 1250,450, 400,1250, 400,1300, 400,1250, 400,1300, 400,1250, 400,1300, 1250};  // UNKNOWN A32AB931

I wonder why I cant just send the raw of this data, maybe because it doesnt run at 38khz? How do I find out what is the frequency ?
It worked fine to dump data from my tv and dvr so it is not an error n my code.
Note:
Opening the remote I found a BEC5104S which doesn't really tells me what frequency runs, not even the Chinese datahsheet
This is the spectrum which confirms that is working at 38khz

what IR library are you using? they should provide such methods...

Looks like manchester encoding to me. Were you able to emulate the TV/DVR remote?

I am using IRremote, the most common one. It works for my TV and DVR. It doesnt work for my heater. I am not sure if my heater is using a different frequency.

Update the post with spectrum which confirms that is working at 38khz

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


text:
Extracting a substring from original string
I am trying to extract a substring out of another string, but it doesn't seem to be working. I am new to programming in arduino and c++ in general. Here is my code:
void setup()
{
    Serial.begin(9600);
}

char rfid;

void loop()
{
  while (Serial.available() > 0)
  {
    rfid = Serial.read();
    String cardnum(rfid);
    cardnum.replace("", "");
    cardnum.replace("", "");
    String id = cardnum.substring(0,2);
    Serial.print(id);
  }
}

The first argument in cardnum.replace("", ""); and cardnum.replace("", ""); replaces the start and end bit with nothing, but it somehow doesn't display it correctly here.
Now on to the problem at hand. The output for cardnum is 1F006B471F2C which it should be, but the ouput for id is the same, when i want it to be only the first two characters of cardnum. How would i go about achieving that.
Thanks in advance for any answers you can provide.

First off you're not reading the serial properly. You should read and digest this before you go any further: https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/

The entire while{} loop executes once for each character you read - is that what you intend? I suspect your intent was to read the the whole string and then modify it. If so, perhaps you'd find the Serial.readBytes() function useful.

Thanks for your answers. Yes my intent was to read the whole string. This helps me out a lot.

Let's dissect your program a moment and see why it's not doing what you want:
while (Serial.available() > 0)
{

So while there are characters available to read in the serial buffer
  rfid = Serial.read();

read one character into the rfid variable.
  String cardnum(rfid);

Convert that character into a string.
  cardnum.replace("", "");

Replace nothing ("") with nothing ("")
  cardnum.replace("", "");

Do the same again,
  String id = cardnum.substring(0,2);

Take the first two characters of the string that contains the single character that you have read.
  Serial.print(id);

Print it.
So basically you have read one character, made it into a string, done nothing to it, copied it to another string, then printed it.
Instead of this method, which does nothing useful, you should read the whole ID into a string (I'd use a C string [i.e., char array] rather than an Arduino String object) then perform operations on that string once you have read the whole ID code.
There's many methods of doing that, but how you do it is heavily influenced by exactly how the data is presented to you. Does it have a terminating CR or LF to indicate the end of the string? If not you will have to use some form of timeout to determine when the string has been completer.

Thanks for your answer. cardnum.replace("", ""); replaces the bit that signals the start and the end of the id with nothing. It looks like there is nothing because Stackexchange can't display the symbol. When i print cardnum it displays 1F006B471F2C. So it should have read more than one character i assume.


text:
Ethernet shield or Wifi sheild - Arduino?
To control some LEDs through internet using Arduino UNO, which type of connection  is better ? Ethernet or Wifi? (Later, I may connect some relays instead of LEDs, and control (turn on and off) some devices using this setup).
The only difference I know is the wired and wireless connectivity.
Is there any other difference?

If you are beginner with Arduino its better to start with Ethernet Shield. Its much more easy to connect with Arduino.
WiFi Module - ESP8266 required some more knowledge, that you will learn in future.
The bought products are cheap, so you can start with Ethernet and after that to switch to ESP.


text:
SMS Receiving problem - Arduino Uno and SIM900A GSM Module
My intention is to control an LED according to the content of the SMS received. For example, if the SMS is "ON", turn on the LED and if it is "OFF", turn it off. I referred many sites and got the below code.
The digital pins 9 and 10 are used instead of Rx and Tx to avoid the code uploading problem.
(I have kept the different versions of AT commands commented in the code because I'm not sure which one is correct. With the current one, I'm able to get some kind of output which I've mentioned after the code.)
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);

char msg;
void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);   // Setting the baud rate of GSM Module
  delay(1000);
  //mySerial.print("AT+CMGF=1r"); // set SMS mode to text
  mySerial.print("AT+CMGF=1\r");  // set SMS mode to text

  delay(100);
  //mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  //mySerial.print("AT+CNMI=2,2,0,0,0r");

  mySerial.print("AT+CNMI=1,2,0,0,0\r"); // AT Command to receive a live SMS
  delay(100);
  Serial.println("Ready");
}

void loop()
{
  if (mySerial.available()>0)
  {
    msg=mySerial.read();
    Serial.print(msg);
  }
}

This is the output I'm getting..
Ready
AT+CMGF=1
AT+CNMI=1,2,0,0,0

OK

+CMTI: "SM",31

+CMTI: "SM",32

+CMTI: "SM",33

+CMTI: "SM",34

The issue is, I'm not able to retrieve the message content. What I'm getting is
"+CMTI: "SM",31"
"+CMTI: "SM",32"
and the number keeps on incrementing. (33, 34 and so on).
I do understand that I have to parse the message to get the exact content, but here I'm not getting the content at all. What exactly should I do to get the SMS content? Could anybody help me to solve this?
One more thing, the GSM module I'm using is a SIM900A type (from elementzonline.com). It's not a shield type, so I've made connections using wires; the Rx, Tx connections and the ground one.
(Sorry for the bad explanation, I'm a complete noob in Arduino, a hobbyist.)
Thanks in advance.

You should download the SIM900 command set (Google away) and read it. According to your CNMI settings, sms notifications are pushed to the Arduino not the sms content, thus the +CMTI data you're receiving. SM tells you the sms is stored on the SIM and the number that follows tells you the index of the sms in the SIM memory. With that index, you use the command AT+CMGR=<index> to get the sms content (as well as the sender number and timestamp) from the modem.
So basically, you must parse the CMTI notification, get the number at the end, and use that number to retrieve the SMS content from the modem with the CMGR command. You could also change your CNMI settings to (2,2,0,0,0) i think, if you want the content of the messages to be sent by the modem, and not the notifications alone.
In either case, the SoftwareSerial Receive buffer will most likely overflow when receiving the sms content from the modem; because you cant read() fast enough. This will make the message appear truncated. You have to increase the size of the SoftwareSerial RX buffer to prevent this. Here's a link to an answer where this is explained. Good luck.

Thank you so much for the answer ! I modified the code as in the link. I just tried mySerial.println("AT+CMGR=35"); and I'm getting the content of the SMS. The output is like OK AT+CMGR=35 +CMGR: "REC READ","+919******7","","16/04/06,18:38:49+22" Hello. In this, "Hello" is the actual content. But now, the issue is, the output is getting displayed infinitely.

@AparnaShajiPeter well, thats probably because you placed it in loop(). Place it in setup() if u want it to print the message only once. Structure your code to do what u want

one more update, now I'm not getting the notifications. i.e., if I run the same first program, I'm not getting the +CMTI messages.  checked the connections, everything is perfect. I'm getting ring as well.Not sure what's happening. :(

@AparnaShajiPeter you are using your original code right? And you havent changed the CNMI settings from (2,2,0,0,0)? And you have sent new messages while the modem is connected? Also, theres no CMGR command present?

first, run the AT+CNMI command to get the index of the message, and then using that index, run the AT+CMGR command. This is the idea, right?

Yeah, same exact code which I posted in the question here. (with CNMI 1,2,0,0,0). While the modem is connected. And, CMGR is not there, because I just tried printing the index, the first program.

@AparnaShajiPeter No. AT+CNMI sets the notification mode of the modem. Using a setting of (1,0,0,0,0) will make the modem forward messages to the terminal directly as they are received WITHOUT notifications. Whereas (2,2,0,0,0) will make the modem forward only the notifications and then you have to use CMGR to get the sms content. The CMTI notifications are unsolicited; u dont ask for them, u simply wait till data is available over serial, and then you parse and obtain the index

@AparnaShajiPeter i suspect your sim memory is full. Maximum is about 15 msgs. Try this command to delete everything: AT+CMGD=ALL or AT+CMGD="ALL"...cant remember which is correct. Place it in setup() on its own and print the results. Then try your original code and send another sms.

I too suspected the same and deleted all messages using AT+CMGDA="DEL ALL"and tried running it again, but it didn't make any change.

@AparnaShajiPeter thats the wrong command. Try the command i gave u...also print the results so u can know if it succeeded

Let us continue this discussion in chat.

Instead of using At commands use the GSM library of Arduino it easier to understand and implement.
the code to recieve SMS
    #include <GSM.h>

    // PIN Number for the SIM
    #define PINNUMBER "" //sim pin incase the sim is kept locked

    // initialize the library instances
    GSM gsmAccess;
    GSM_SMS sms;

    // Array to hold the number a SMS is retreived from
    char senderNumber[20];

    void setup() {
      // initialize serial communications and wait for port to open:
      Serial.begin(9600);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }

      Serial.println("SMS Messages Receiver");

      // connection state
      boolean notConnected = true;

      // Start GSM connection
      while (notConnected) {
        if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
          notConnected = false;
        } else {
          Serial.println("Not connected");
          delay(1000);
        }
      }

      Serial.println("GSM initialized");
      Serial.println("Waiting for messages");
    }

    void loop() {
      char c;

      // If there are any SMSs available()
      if (sms.available()) {
        Serial.println("Message received from:");

        // Get remote number
        sms.remoteNumber(senderNumber, 20);
        Serial.println(senderNumber);

        // An example of message disposal
        // Any messages starting with # should be discarded
        if (sms.peek() == '#') {
          Serial.println("Discarded SMS");
          sms.flush();
        }

        // Read message bytes and print them
        while (c = sms.read()) {
          Serial.print(c);
        }

        Serial.println("\nEND OF MESSAGE");

        // Delete message from modem memory
        sms.flush();
        Serial.println("MESSAGE DELETED");
      }

      delay(1000);

    }

GSM library is used with Arduino GSM Shield, right? Here, I'm using another SIM900A GSM module, not the shield..

use cnmi 2,2,0,0,0 to get the SMS contents
use cnmi 1,2,0,0,0, to get only the notification with CMTI+.... if you want to read the cont then u need to parse and check wht number u get in SM and then read that numbered msg using CMGR

Can you please spell this out in English and show an example?


text:
Changing the tick time in FreeRTOS
I am trying to use FreeRTOS's vTaskDelay() function in order to periodically execute tasks.  The latest version of FreeRTOS came with the "tick" time set to 15 ms. Therefore, the smallest resolution I can delay for is 15 ms. I would like to lower this resolution to at least 1 ms.  Is it possible to configure FreeRTOS in this way?  I found this answer online : http://www.freertos.org/FreeRTOS_Support_Forum_Archive/November_2012/freertos_Problem_changing_Tick_time_from_1ms_to_10ms_6231539.html.
But for me, the configTICK_RATE_HZ is not defined and it seems to be using a watchdog timer to enforce the 15 ms resolution. I think the forums are referring to an earlier version.

see also this FreeRTOS port with F_CPU

See the configTICK_RATE_HZ configuration option.
Also note it is better to specify times in milliseconds, rather than ticks, so you can change the tick frequency without effecting the timing (other than the resolution of the time).
The pdMS_TO_TICKS() macro can be used for that purpose, for example to create a delay of 100ms.
const TickType_t xBlockTime = pdMS_TO_TICKS( 100 );
vTaskDelay( xBlockTime );

authors: Андрей Тернити

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


text:
How to properly receive data from accelerometer @ arduino in processing and map it?
I'm busy making a project where my accelerometer @arduino can controle a ellipse @processing
But the problem is, it doesn't work. With the code I have now, I can receive the data from the accelerometer in processing. But my map function doesn't seem to work because with my code, the ellipse doesn't move at all. When i want to map the val (string) it says it must be a float to be mapped. I've tried to convert the string into a float but it doesn't work at all..
Hope someone can help me out!
My arduino Code:
#include <Wire.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>

int waardeX;
int waardeY;

Adafruit_MMA8451 mma = Adafruit_MMA8451();            //maak object acceleromter aan

void setup(void) {
  Serial.begin(9600);                                 //begin Seriële verbinding
  Serial.println("Adafruit MMA8451 test!");           //print waardes accelerometer

  if (! mma.begin()) {                                //mma.begin() om de sensor te herkennen.
    Serial.println("Couldnt start");                  //"MMA8451 found!" bij goed signaal, "Couldnt start" bij slecht signaal
    while (1);
  }
  Serial.println("MMA8451 found!");

  mma.setRange(MMA8451_RANGE_2_G);                    //lees range van 2_G (voor relatief slome bewegingen)

  Serial.print("Range = "); Serial.print(2 << mma.getRange());
  Serial.println("G");

}

void loop() {

  // Read the 'raw' data in 14-bit counts
  mma.read();                                         //lees rauwe data accelerometer uit
  Serial.print("X:\t"); Serial.print(mma.x);          //lees x waardes
  Serial.print("\tY:\t"); Serial.print(mma.y);        // lees y waardes
  Serial.println();                                   //print de waardes met een delay van 500ms
  delay(500);

  /* Get a new sensor event */
  sensors_event_t event;

  Serial.write(waardeX);
  Serial.write(waardeY);
}

Processing code:
import processing.serial.*;

Serial myPort;                                   //Maak Serial object aan
String waardeX;                                      //Ontvangen data van serial poort.

//int waardeX;
int waardeX1;
int waardeY2;
int waardeY;

void setup() {
  printArray(Serial.list());
  String portName = Serial.list()[0];            //0 is mijn Arduino poort.
  myPort = new Serial(this, portName, 9600);     //open de poort. Zelfde als serial.begin(9600) bij arduino zodat arduino en processing hetzelfde communiceren.

  size(500, 500);                                //Grootte van het scherm
}

void draw() {
  background(255);                               //Achtergrondkleur
  ellipse(waardeX1, waardeY, 20, 20);               //20,20 is grootte/breedte cirkel
  fill(200, 10, 100);                                       //maak het bolletje zwart

  waardeX1 = (int)map(waardeX, 4000, -4000, 0, 500);        //waardeX mappen naar waa
//  waardeY = (int)map(waardeY2, -4000, 4000, 0, 500);

  {
    if ( myPort.available() > 0)
    {  // Als de data beschikbaar is:
      val = myPort.readStringUntil('\n');         //Lees het en zet het in val
    }
        println(waardeX); //print it out in the console
  }
}

Hi, Welcome to SE Arduino.  I'm sorry but, its really difficult for me to follow your code.  You seem to be mixing the use of waardeX and waardeX1 and using values before you have calculated them, meaning they are old values.  Can I suggest you put this code on the shelf and start a new minimal program that creates an ellipse at 10, 10, 20, 20 and 20, 20, 20, 20 and 30, 30, 20, 20 and map those.  If they work as expected then we now its not the functions that are the problems, just the data.  (Also a simple program like that will help people understand your code better, hopefully).

The problem you are facing is that you are sending the string:
X:⇥23.87⇥Y:⇥11.34

and trying to interpret that as a single number. It's just not going to happen. There's two numbers and two labels there.
Instead you are going to have to parse the string to get at the individual components.
You might want to look at the java String.split() function to convert the string into an array of 4 items, then you can use the second and fourth slices (slices 1 and 3 since it's zero-based) and convert them to floats.


text:
Make an LED less bright
As an exercise to learn rather then the most efficient way to accomplish a goal.... (i'm a hands on hardware guy, but I need to get my Sh!T together and learn some coding)
I would like to make an LED less bright within a project.  I have a nano set up to control a relay to control a dc load when a momentary switch is pressed (this is kinda needlessly complicated solely to allow me to use a particular momentary switch I wanted to use for a bunch of not that great reasons ;-)
Anyway... the code i'm using is this:
int pbuttonPin = 2;// connect output to push button
int relayPin = 10;// Connected to relay (LED)

int val = 0; // push value from pin 2
int lightON = 0;//light status
int pushed = 0;//push status

void setup() {
  // Robojax.com code and video tutorial for push button ON and OFF
  Serial.begin(9600);
  pinMode(pbuttonPin, INPUT_PULLUP);
  pinMode(relayPin, OUTPUT);
 digitalWrite(relayPin, HIGH);// keep the load OFF at the begining. If you wanted to be ON, change the HIGH to LOW
}

void loop() {
// Robojax.com code and video tutorial for push button ON and OFF
  val = digitalRead(pbuttonPin);// read the push button value

  if(val == HIGH && lightON == LOW){

    pushed = 1-pushed;
    delay(100);
  }

  lightON = val;

      if(pushed == HIGH){
        Serial.println("Light ON");
        digitalWrite(relayPin, LOW);

      }else{
        Serial.println("Light OFF");
        digitalWrite(relayPin, HIGH);

      }

// Robojax.com code and video tutorial for push button ON and OFF

  delay(100);

The above code is straight up cut and paste... i'm clueless
I have a LED cathode on pin 10, (so i know the relay is on more easily from a distance).  however the application is on a boat, and at night it is too bright and distracting.  So i want to make the LED dimmer... I know I could add a larger value resistor, but i want to expand my understanding and would like suggestions on other ways PWM maybe....
cheers:

What's your Arduino? If you can connect the LED to the Arduino (=if the Arduino provides enough power), you can connect it to a PWM pin and use analogWrite(10, brightness); to change the brightness. Of course, you'd have to initialize it in the setup and replace brightness with a number in the range of 0-255.

If using the relay is your only option, here is an discussion about it in the Arduino forums.

add a resistor, don't waste resources of the MCU for this

Yeah, use Jurajs method if you want to change it just once to a lower brightness.

You could add a second relay, with a resistor, like Juraj suggested. Connect that in parallel to the cathode of the led. You can then switch between the two relays for two different brightness levels. But I think it would be better, depending on the LED you used, to swap out the relay for a mosfet. Then you can change the brightness using PWM. Add a light sensor, to automatically switch between day, and night mode, to somehow justify using an Arduino in the first place ;-p

My preferred approach is to wrap the LED in tape to make it dimmer. :) It's easier than soldering a resistor! :) j/k

There are two methods of dimming a LED : by PWM or by a limiting current resistor.

PWM code
 `//Initializing LED Pin
 int led_pin = 10;
 void setup() {
 //Declaring LED pin as output
         pinMode(led_pin, OUTPUT);
 }
 void loop() {
         analogWrite(led_pin, 127); // half intensity
         delay(5);
 }`

Hardware. Use following schematic

This soulution doesn't consider the LED needs more power than the Arduino can provide.

not all POTs will like all LEDs. while a fire is a remote chance, losing the POT isn't.

Unless you have regulated current (which would be the third option) you need a current limiting resistor in any case. No matter if you're going to dim using pwm afterwards. Your answer is misleading in that point. Also, how are you dimming the led in the second example? Isn't this pwm as well?

If you want to decrease the brightness in general, the easiest solution would in deed be to use a high value resistor.
If you want to use PWM - for example to change brightness programmatically - you just need to replace the calls to digitalWrite(HIGH|LOW) with calls to analogWrite(x) (ref), where x represents the duty cycle/brightness. The range of x depends on your microcontroller.
Note, that PWM (which is used by analogWrite()) only works on dedicated pins.
On the other side, there are microcontrollers wich have analog pin with a "true" analog output. On such an analog pin - though it is possible to use analogWrite() - the brightness will not be linear and have an offset, which makes it pretty much useless for dimming an LED.

"...the brightness will not be linear and have an offset." I don't know what you mean when you say the brightness will have an offset. It won't. It just won't be linear is all, but all PWM values > 0 will indeed produce light. There isn't a "dead band" in PWM as there is with potentiometers and joysticks, for instance.

That point referes to true analog outputs - I'll make this more clear. If I remember right, those analog pins are also used with analogWrite() on the respective arduinos, but show a much different behaviour than a PWM pin.

Oh, I see what you're saying. PWMing an output voltage which is > Vthreshold when HIGH always produces light on an LED, but if it's a true analog output there will be a deadband, or "offset", equal to the threshold voltage before the LED starts producing light. This is one of the benefits of PWM pseudo-analog output for driving LEDs over using true analog output for driving LEDs. PWM, in this case, is probably actually better.

It was a bit unclear what I meant, I guess.

Follow this tutorial. It doesn't get any better than this.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade

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


text:
How do you know what to call the digital pin your using? changing the sensor pin your using
I downloaded a water flow sketch and got it working on a bread board using an Uno, and a LCD shield.  I what to make it on perf board using a Nano, and an NOT I2C LCD.
I soldered it all up, got "Hello World" to run ok.  But because my water flow sketch originally uses D2 for the sensor, and the new sketch uses D2 for the LCD I obviously need to change the sensor pin.  I have the sensor hooked up to D8, but I can't figure out how to tell the sketch that....
I believe it is this line of code:
    byte sensorInterrupt = 0;  // 0 = digital pin 2
    byte sensorPin       = 2;

But I have tried changing the values based on the nano pin out diagram, but I just can't get it to read.  I don't think it is a hardware problem, but if i can get confirmation that i have the pin declared correctly I can go back a de-solder stuff and check....
    /*
Liquid flow rate sensor -DIYhacking.com Arvind Sanjeev

Measure the liquid/water flow rate using this code.
Connect Vcc and Gnd of sensor to arduino, and the
signal line to arduino digital pin 2.

 */
// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

byte statusLed    = 13;

byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 2;

// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 7.55;  //biger more / min

volatile byte pulseCount;

float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;

unsigned long oldTime;

void setup()
{

  // Initialize a serial connection for reporting values to the host
  Serial.begin(9600);

     lcd.begin(16, 2);
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("S.V. SAVANNAH");
   lcd.setCursor(0,1);
   lcd.print("DAY TANK");

  // Set up the status LED line as an output
  pinMode(statusLed, OUTPUT);
  digitalWrite(statusLed, HIGH);  // We have an active-low LED attached

  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;

  // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
  // Configured to trigger on a FALLING state change (transition from HIGH
  // state to LOW state)
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}

/**
 * Main program loop
 */
void loop()
{

   if((millis() - oldTime) > 1000)    // Only process counters once per second
  {
    // Disable the interrupt while calculating flow rate and sending the value to
    // the host
    detachInterrupt(sensorInterrupt);

    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;

    // Note the time this processing pass was executed. Note that because we've
    // disabled interrupts the millis() function won't actually be incrementing right
    // at this point, but it will still return the value it was set to just before
    // interrupts went away.
    oldTime = millis();

    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    flowMilliLitres = (flowRate / 60) * 1000;

    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres += flowMilliLitres;

    unsigned int frac;

    // Print the flow rate for this second in litres / minute
    Serial.print("Flow rate: ");
    Serial.print(int(flowRate));  // Print the integer part of the variable
    Serial.print("L/min");
    Serial.print("\t");       // Print tab space

    // Print the cumulative total of litres flowed since starting
    Serial.print("Output Liquid Quantity: ");
    Serial.print(totalMilliLitres);
    Serial.println("mL");
    Serial.print("\t");       // Print tab space
  Serial.print(totalMilliLitres/1000);
  Serial.print("L");

      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print(int(flowRate));  // Print the integer part of the variable
      lcd.print("L/min ");

    // Print the cumulative total of litres flowed since starting
    lcd.print("Total ");
  lcd.print(totalMilliLitres/1000.00);
  lcd.print("L");

    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;

    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  }
}

/*
Insterrupt Service Routine
 */
void pulseCounter()
{
  // Increment the pulse counter
  pulseCount++;
}

on Nano only pins 2 and 3 can be used with attachInterrupt(digitalPinToInterrupt(pin), ... https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

Can the LCD use D8 instead of D2 or D3 for "RS" or "E" on the LCD?


text:
void declaration error
I am new to Arduino and C++ and I was practicing with a traffic light project.
This is my code:
int red = 10;
int yellow = 9;
int green = 8;

void setup() {
  pinMode(red,OUTPUT);
  pinMode(yellow,OUTPUT);
  pinMode(green,OUTPUT);
}

void loop() {
  changelights();
  delay (15000);
}

void changelights{
  // 1st action: green off to yellow
  digitalWrite(green, LOW);
  digitalWrite(yellow, HIGH);
  delay (3000)
  // 2nd action: tellow to red
  digitalWrite(yellow, LOW);
  digitalWrite(red, HIGH);
  //3rd action: caution light
  digitalWrite(yellow, HIGH);
  delay (3000)
  //4th action: caution to go
  digitalWrite(red,LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(green, HIGH);
}

I tried compiling it and returned an error message that said that I did not declare my "changelights" function. What should I do to fix this?
Thank you very much

I recommend to put only 1 instruction in 1 line. that improves readability by a lot and makes it easier to find errors.

You forgot the parentheses ( ) for the parameters after the definition of changelights. You need these, even if you don't provide any parameters. Though this is a pure C/C++ syntax question, thus I'm voting to close. Fixing such problems doesn't help any other people, thus I'm always helping in the comments and then vote to close.

Missing semi-colons after the delay(3000) calls.

You forgot to put the parenthenses () after the name of the function changelights. They are there to declare variables you can use later in the code like that:
void function(int a){
  a+=1;
  return a;
}

To fix your error just change
void changelights{

to
void changelights(){

Keep in mind if you want to program C++ (which would be Off-Topic here, but you mentioned it in your question) you have to declare the function in the beginning or mention it.

The Arduino IDE takes care of adding the forward declarations for you.

The problem is with the missing parentheses at the function definition. The forward declaration of the functions is done by the Arduino IDE. And I think we can assume, that he uses it. At that point working with Arduino that is the simplest way.

@chrisl I see, I will edit the answer.


text:
ESP8266 occasionally stops receiving data
So I have an ESP8266 board that I am using to control some LED lights. I wasn't a fan of the needing to reflash my board everytime I wanted to try a new light pattern, so I decided to send the light data over wifi (UDP), and that works for certain light patterns, but any pattern that has leds that turn on/off starts to stutter and stop after a while. If every light is on, there's no problem with the speed I'm sending data, but if there are some that are on and some off, without fail it will always stop receiving data at a certain point. I've got a couple points of failure and this is my first time messing with an arduino so I'm not sure whether the problem could be on my local program, on the program for the board, the data, my wifi, or something else.

You should probably describe how the board and leds are powered and how many leds.  In short, it sounds ultimately like a power problem this is being revealed when you request a change.

do you have a question?  ... you described the problem, but there is nothing that can be answered

does it stop until reboot, or does it just pause? You might want to try dumping system_get_free_heap_size() to see if you have a mem leak.

It was a memory leak! The data I was sending was slowly growing due to some poor math on my end; fixed that up and it worked great.

dandavis helped me find the answer! Turns out it was a memory leak, due to some poor math on my end. All I had to do was fix that up and it worked fine.


text:
On the Uno, why does VIN require 7-12 volts and the USB only 5 volts?
I'm just wondering why the VIN would require 7-12 volts when the USB port itself only requires 5 volts? What happens if you power an Uno on VIN with 5 volts?

Feel free to supply 5 volts to the 5V pin on the Uno.

Possible duplicate of Powering an Arduino UNO through 5V

USB's Vcc pin is assumed to be a stable, 5v supply, and is directly connected to the 5v bus on the Arduino board with no further regulation. Vin is assumed to be an unknown and unregulated voltage in the range of 7-12 volts.
The 7v minimum is a requirement of the design of the on-board voltage regulator which needs the 2v "head room" to maintain its output at 5v. A 5v power supply could be designed with a larger input range, even including voltages less than 5v, but the simple design used on the board covers a range of sources at a lower cost than a higher-performance power supply.

The UNO takes your input power supply (7-12 volts) and then regulates the voltage down to 5 volts. This way, the UNO operates at a constant voltage regardless if your input power supply wanders about from 7 to 12 volts.
The USB port,  BY DEFINITION and International Standards, needs to operate at 5 volts.
If you apply 5 volts power supply, the UNO won't be able to regulate to 5 volts. The voltage regulator itself will have a voltage drop, and the UNO will operate at less than 5 volts.  The UNO may or may not operate properly. The USB will likely suffer from more problems than the UNO if you apply 5 volts.
Good news is that the UNO will not likely suffer permanent damage.

What does this mean "The USB will likely suffer from more problems than the UNO if you apply 5 volts. "

Items connected to the USB port can become disfunctional if operated from less than 5 volts.


text:
What is the proper way to turn an Arduino UNO into an ISP?
I have a bricked Arduino Uno and I want to try to flash the bootloader. I'm trying to figure out how to do it. On this tutorial from SparkFun you can see this diagram:

They also show this table of the pinout

That seems simple enough but it's totally different than the official tutorial, "Circuit (targeting Arduino Uno, Duemilanove, or Diecimila)"

Which also says

An Arduino board serving as an ISP to program the ATmega on another Arduino board. On the Arduino Uno, you'll need to connect a 10 uF capacitor between reset and ground (after uploading the ArduinoISP sketch). Note that you need access to the reset pin on the target board, which isn't available on NG or older boards.

So do I need a 10 uF capacitor between reset and ground? How do I put a 10 uF capacitor in between reset and ground when, in this configuration, reset is connected to PIN 10? Why are there two configurations? What's the upsides and downsides to either of them?

Take a look at my circuit for a minimal "Arduino":

The top image in the question uses the ICSP header, which you can see from the schematic "mirrors" pins on the processor. That is:

SCK is D13
MISO is D12
MOSI is D11
Reset on the target goes to D10 on the programming board
Vcc and Gnd are connected

Trace out the wires to the ICSP header and you will see.

So do I need a 10 uF capacitor between reset and ground?

No you do not.

I have a bricked Arduino Uno and I want to try to flash the bootloader.

See my page about programming a bootloader.

Why are there two configurations?

Just different ways of connecting the same thing to the same thing.

What's the upsides and downsides to either of them?

No difference.

I will debate you one one small point, on the last question about the upsides/downsides, there are two small differences. the lesser is that using the side rails is easier for temporary setups, and the ISCP is easier for reusable setups. the other is that on different models of boards the spi pins may not be in the same place (mega is a case in point) so using the ISCP is more portable.

OK, yes there may be physical differences like that. If you make up an ICSP cable, then the ICSP header is somewhat easier to use.

The wiring is actually identical. It just uses the ISP header (2x3 pins) on the target board, instead of the pins 5v, GND, RST, 11, 12, 13. Just like the table you added says.
The downside to using the ISP header, is you need a male to female wire for connecting. Upside is you can easily take of these 6 pins, and connect it to a different arduino to be programmed.
I always needed to add a capacitor between RESET and GND. The exact value isn't that critical.
The reset pin is the one to the left of 3v3.

You're missing the question: RESET isn't connected to GND, it's connected to Pin10? Do you mean you needed to add a capacitor between RESET and Pin10?

A capacitor between the ISP Arduino's RESET and GND stops the auto-reset happening when the serial port is opened. That's the ISP's reset, NOT the target's reset which is wired direct to pin 10.

Not on the target arduino, but the programming arduino's reset.

Ah.. I see here is the guide for the capacitor on ground-reset

You're missing the question: RESET isn't connected to GND - on both diagrams pin 10 on the programming board is connected to RESET on the target board. The wiring is identical, as Gerben said.

authors: مریم ترکاشوند


text:
How do I resolve "avrdude: stk500_recv(): programmer is not responding"?
Whenever I try to program my Arduino UNO Rev.3, I'm seeing the following error
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00

When I plug this in, I do see a power light. There are no cables whatsoever connected other than the USB. I have another Arduino UNO which works fine when I upload the sketch (I'm using the basic blink sketch). How do I resolve this? What kind of problem can it be?

Make sure there are no wires connected to the Serial Interface (pin 0 and pin 1)

@KiraSan updated the question with more information (nothing plugged into 1 or 0).

I think you should consider using that Arduino Duo to reburn the bootloader of your Arduino UNO.

Also before doing that, make sure you selected AVR ISP as programmer, and chosen the right board.

Don't forget to try another USB cable. Also you can try to swap MCUs and try it again to figure out if it's board problem or bootloader problem...

What OS are you using?

D_Graeme solution is what worked for me (Nano, OSX). Here's a Stack Overflow question with many answers/solutions: Arduino Sketch upload issue - avrdude: stk500_recv(): programmer is not responding

After trying numerous suggestions, 2 different boards, 3 different cables on a WinXP and a Win7 machine, I finally got things working by going to "Tools -> Processors -> ATmega 328P Old Bootloader"

Although this answer would be correct for a Nano, this question is about an Uno and so your answer is off topic. We already have a question for that Nano problem: https://arduino.stackexchange.com/q/51771

For me it was the opposite: had to select nanoatmega328new on PlatformIO. Thanks dude

I'm using VS Code. Sadly, there is no "Tools" menu that I can find.

I had this problem when working with Arduino IDE and XOD running on top of it.
What I found; looked like baud rates were being set differently at different stages in the setup. I compared Windows 'device settings', arduino IDE settings and XOD settings...and they are not the same and seem to change ? ...hence the 'avrdude:stk500_**** errors!
To demonstrate
Connect an Arduino board to a PC USB socket.

On Windows 7; Control Panel\ System and Security\System\ Device Manager... then double-click on 'Ports (COM & LPT)
You should see FTDI
or
USB-SERIAL CH340(COM7) ... for a chinese serial com chip on the arduino board.
Right-click on this and check 'Properties\ Port Settings' and note  the 'Bits per second' value : e.g. 57600 ... (write it down !)
Open the arduino IDE and click on File\Preferences and tick the option ;'Show verbose output during: 'upload'.Then close the 'Preferences' screen.
Load a small program that works. e.g. File\Examples\01.Blink
In the for your arduino board setup in the Arduino IDE;
Tools\Board ... such as Arduino Nano
Tools\Processor ... such as ATmega328P
Tools\Port:COM7 for example ... make sure a tick is selected.
Tools\Get Board Info ... will show info from the arduino serial chip (a good sign your usb cable works!)
On the IDE toolbar select;

'Verify' and shortly it should show 'Done Compiling'
Click 'Upload' and the Blink program should load into the arduino chip.

Now here is the interesting observation; The 'verbose message at the bottom of the IDE screen will indicate what 'Overriding Baud Rate : XXXXX' is being used! Write this number down next to the value you found on the Windows devices setting.
Now, if you are a XOD man, leave the arduino IDE running and run XOD.
Open the XOD IDE and open (Deploy) say the 01-hello program and load it into your arduino board.
Select'welcome-xod' and select 01-hello program on left-side menu.
Select 'Deploy\Upload to Arduino ...'
select 'Board model:'  and 'Serial port:' ... eg COM7
Scroll up in the 'Deployment ' window and there will be another value labeled 'Overriding Baud Rate : e.g.115200'

I HAVE FOUND THESE BAUD RATE SETTINGS CHANGE INEXPLICABLY !
I hope my observations will throw some light on your problem of erratic uploads.

Thanks Lionelb! What I had to do was go to Tools and change Port to COM3 instead of COM1, which was in use for a serial port on my system. This was after reading your solution and checking Control Panel\ System and Security\System\ Device Manager.. I did not happen to have an issue with the bits per second, but that is helpful too.

Thanks worked for me. After File\Preferences and ticking the option ;'Show verbose output during: 'upload'. I only needed to set the bits per second in the device manager for the used com.port.

To upload the program again I needed to change the baud rate to 9600 (after initially 57600)

I was having the same problem, however I was able to solve as follows,

rebooting my computer
or, changing the cable, basically switching between 2 USB cables (may be it just needed to unplug the USB and plug it in again).
or, resetting the COM port

closing the Arduino IDE
disabling the COM port
enabling the COM port
opening the Arduino IDE

I had periodically encountered this as well and was stumped after I had tried all the recommended solutions I could find. In my particular case it turned out to be the cable I was using.

Have you already tried this?
https://stackoverflow.com/a/20735393/5507619

I had this problem with a Crowduino, running the Arduino IDE on OSX.
  The solution for me was to switch on verbose output during upload (in
  the arduino IDE preferences pane).
Then, when uploading, you can see avrdude sending three packets
  avrdude: Send: 0 [30]   [20] (with corresponding RX flashes on the
  board) right before the avrdude: ser_recv(): programmer is not
  responding error.
The trick is to hit the reset button on the board immediately before
  these three packets are sent. Then the program will be uploaded
  successfully.

For me it was a matter of -B 10 instead of -b xxxx. So:
sudo ~/arduino-1.8.12/hardware/tools/avr/bin/avrdude -P /dev/ttyACM0 -B 10 -c arduino -p m328p -C ~/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -U eeprom:r:eeprom.hex:r


text:
Does Arduino.cc silkscreen the pin headers? What explains the differences here?
I have two Arduino's. One from .org, and one from .cc. The arduino.org one has really nice silk screening on the header pins. The arduino.cc one does not. In addition there are some visible component differences. One has a 504S (not sure what this chip is), one has a 504L. The button on the .org one is a bit more tactile. The headers on the top (not the ICSP) headers are missing on the .org one. And, the four points that look like they're for soldering or testing are absent. I can try to get a high-res picture of the two up.
I bought the .org one in a beginner kit online from Amazon (from the official seller). And, the .cc I bought from their website directly.
The .org one seems like it's made from higher-end components, and actually having the headers at the top makes it seem more polished. Is there any through guide to what these differences are or a changelog from one hardware revision to another?

This doesn't make a lot of sense - until fairly recently, arduino.cc's boards were supplied by the folks now calling themselves arduino.org and the pictures on arduino.cc all show very nice silk screen designation of the pin headers.  What exact deficiency are you questioning?  Are you sure these boards were obtained from the sources you think they were?

This is a new Arduino.cc board, presumably not made by the arduino.org folks. It lacks silk screens on the pins, actually lacks a whole set of of header pins, and has some different components. Some either minor imperfections too. The caps are crooked and don't line up like the Arduino.org one.

Is there any through guide to what these differences are or a changelog from one hardware revision to another? - I strongly doubt it.

No, there is nothing that documents the differences as in a changelog, purely because this is not an iterative change.
The two boards are designed and manufactured by two different (competing) companies in two different countries (USA and Italy) using different component suppliers.
Just because they both say Arduino UNO doesn't make them both the same board - not these days anyway, since the founders of Arduino got really childish and started throwing their faeces at each other like monkeys in the zoo.


text:
Program to run two motors with Motor driver
I'm trying to make a program that would run two motors clockwise and then anticlockwise. But my program is causing my motors to only run clockwise everytime . It doesn't run anticlockwise at all. Can anyone help me find the bug?
Main code:
void loop()
{
  // turn on motor A
  digitalWrite(In1, HIGH);
  digitalWrite(In2, LOW);
  // set speed to 150 out 255
  analogWrite(EnA, 150);
  // turn on motor B
  digitalWrite(In3, HIGH);
  digitalWrite(In4, LOW);
  // set speed to 150 out 255
  analogWrite(EnB, 150);
  delay(2000);
   digitalWrite(In1, LOW);
  digitalWrite(In2, HIGH);
   digitalWrite(In3,LOW);
  digitalWrite(In4, HIGH);
  // now turn off motors
  digitalWrite(In1, LOW);
  digitalWrite(In2, LOW);
  digitalWrite(In3, LOW);
  digitalWrite(In4, LOW);
  delay(2000);
}

How long is there between turning anti-clockwise and stopping the motors...?

I didn't set any delay between anticlockwise rotation.

Which means what...?

check this one
void loop()
{
  // turn on motor A
  digitalWrite(In1, HIGH);
  digitalWrite(In2, LOW);
  // set speed to 150 out 255
  analogWrite(EnA, 150);
  // turn on motor B
  digitalWrite(In3, HIGH);
  digitalWrite(In4, LOW);
  // set speed to 150 out 255
  analogWrite(EnB, 150);
  delay(2000);
   digitalWrite(In1, LOW);
  digitalWrite(In2, HIGH);
   digitalWrite(In3,LOW);
  digitalWrite(In4, HIGH);
  // now turn off motors
  delay(5000);
  digitalWrite(In1, LOW);
  digitalWrite(In2, LOW);
  digitalWrite(In3, LOW);
  digitalWrite(In4, LOW);
  delay(2000);
}


text:
Cant upload, port not found error, ubuntu 20.04 LTS
I have installed Arduino IDE on Ubuntu 20.04 LTS. I have installed it from the tar file (ie not from snap) and I have added myself to the dialout and tty groups. When I look at groups I get:
adm tty dialout cdrom sudo dip plugdev lpadmin lxd sambashare
I am trying to upload a simple bluetooth script to a Nano 33 BLE, and I have installed the mbed board driver and the ArduinoBLE library.
Whatever I try, I get an error, preventing me from uploading to the board.
Caused by: jssc.SerialPortException: Port name - /dev/ttyACM0; Method name - openPort(); Exception type - Port not found.

I dont know what else to try, so if anyone has any suggestions, I would really appreciate it. I have googled for a while, and havent been able to find anything that works.
Thanks!

Is your Arduino recognized at all? "Port not found" does not sound as if your priviledges are wrong. You might like to use lsusb or similar to check. Or search the web how to detect USB connections.


text:
Serial plotter looks different and doesnt print graph
When I open my serial plotter to get the graph for my HC-SR04 sensor it doesn't show anything. My plotter looks different too. I have attached images below as well.

Only those numbers on the top-most move with time.(100,200,300)
Here's my code:
int trigPin = 12;
int echoPin = 11;

int pingTravelTime;
float pingTravelDistance;
float distToTarget;

int baudRate = 9600;

int dT = 10;
int dT2 = 500 ;

String msg1 = "The distance is equal to ";
String msg2 = "cm";

void setup() {
  // put your setup code here, to run once:
  Serial.begin(baudRate);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(trigPin, LOW);
  delayMicroseconds(dT);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(dT);
  digitalWrite(trigPin, LOW);

  pingTravelTime = pulseIn(echoPin, HIGH);

  pingTravelDistance = pingTravelTime * ((765. * 5280. * 12.) / (3600. * 1000000));
  pingTravelDistance = 2.54 * pingTravelDistance;
  distToTarget = (pingTravelDistance / 2);

  Serial.println(msg1 + distToTarget + msg2);

  delay(dT2);
}

What do I do??

Does the serial monitor connect without issue with this code?

Yes, the serial monitor behaves properly and poses no problem for me. It's just the serial plotter that seems to have a problem.

The serial plotter expects you to send numbers, and only numbers. If it
reads any other text, like for example
“The distance is equal to 9.88cm”
It assumes these are the names of the columns of data that are to
follow. So it chooses one color for each column and prints the color key
on top of the graph.

What do I do??

Just remove the prose and print only the numbers. You may print
something like “distance(cm)” in setup() if you want to have the key
displayed, but that is not required.

Ok thanks a lot, I will try that.

Yes, it works now, thanks.

@unibeam Then mark this answer as correct.


text:
Arduino Uno Clone Error Compilig AVRDUDE
Can anyone please help me with this error?
Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

Sketch uses 2964 bytes (9%) of program storage space. Maximum is 32256 bytes.

Global variables use 89 bytes (4%) of dynamic memory, leaving 1959 bytes for local variables. Maximum is 2048 bytes.

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xcd

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xcd

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xcd

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xcd

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xcd

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xcd

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xcd

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xcd

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xcd

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xcd

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

With enabled a in comment:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Duemilanove or Diecimila, ATmega168"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries D:\Documents\Arduino\libraries -fqbn=arduino:avr:diecimila:cpu=atmega168 -vid-pid=1A86_7523 -ide-version=10813 -build-path C:\Users\Mark\AppData\Local\Temp\arduino_build_293669 -warnings=none -build-cache C:\Users\Mark\AppData\Local\Temp\arduino_cache_250344 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose D:\Downloads Chrome\sketch_apr20a\sketch_apr20a.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries D:\Documents\Arduino\libraries -fqbn=arduino:avr:diecimila:cpu=atmega168 -vid-pid=1A86_7523 -ide-version=10813 -build-path C:\Users\Mark\AppData\Local\Temp\arduino_build_293669 -warnings=none -build-cache C:\Users\Mark\AppData\Local\Temp\arduino_cache_250344 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose D:\Downloads Chrome\sketch_apr20a\sketch_apr20a.ino

Using board 'diecimila' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr

Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr

Detecting libraries used...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega168 -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\sketch\\sketch_apr20a.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

Alternatives for Servo.h: [Servo@1.1.6 Servo@1.1.3]

ResolveLibrary(Servo.h)

  -> candidates: [Servo@1.1.6 Servo@1.1.3]

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega168 -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-ID:\\Documents\\Arduino\\libraries\\Servo\\src" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\sketch\\sketch_apr20a.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

Using cached library dependencies for file: D:\Documents\Arduino\libraries\Servo\src\avr\Servo.cpp

Using cached library dependencies for file: D:\Documents\Arduino\libraries\Servo\src\megaavr\Servo.cpp

Using cached library dependencies for file: D:\Documents\Arduino\libraries\Servo\src\nrf52\Servo.cpp

Using cached library dependencies for file: D:\Documents\Arduino\libraries\Servo\src\sam\Servo.cpp

Using cached library dependencies for file: D:\Documents\Arduino\libraries\Servo\src\samd\Servo.cpp

Using cached library dependencies for file: D:\Documents\Arduino\libraries\Servo\src\stm32f4\Servo.cpp

Generating function prototypes...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega168 -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-ID:\\Documents\\Arduino\\libraries\\Servo\\src" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\sketch\\sketch_apr20a.ino.cpp" -o "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\preproc\\ctags_target_for_gcc_minus_e.cpp" -DARDUINO_LIB_DISCOVERY_PHASE

"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\preproc\\ctags_target_for_gcc_minus_e.cpp"

Compiling sketch...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega168 -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\standard" "-ID:\\Documents\\Arduino\\libraries\\Servo\\src" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\sketch\\sketch_apr20a.ino.cpp" -o "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\sketch\\sketch_apr20a.ino.cpp.o"

Compiling libraries...

Compiling library "Servo"

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\libraries\Servo\avr\Servo.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\libraries\Servo\megaavr\Servo.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\libraries\Servo\nrf52\Servo.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\libraries\Servo\sam\Servo.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\libraries\Servo\samd\Servo.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\libraries\Servo\stm32f4\Servo.cpp.o

Compiling core...

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\wiring_pulse.S.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\hooks.c.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\WInterrupts.c.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\wiring.c.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\wiring_analog.c.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\wiring_shift.c.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\wiring_digital.c.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\wiring_pulse.c.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\CDC.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\HardwareSerial1.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\PluggableUSB.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\HardwareSerial3.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\HardwareSerial.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\IPAddress.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\HardwareSerial2.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\HardwareSerial0.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\WMath.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\Print.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\WString.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\abi.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\Stream.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\Tone.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\new.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\USBCore.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\main.cpp.o

Using previously compiled file: C:\Users\Mark\AppData\Local\Temp\arduino_build_293669\core\core.a

Archiving built core (caching) in: C:\Users\Mark\AppData\Local\Temp\arduino_cache_250344\core\core_arduino_avr_diecimila_cpu_atmega168_0c812875ac70eb4a9b385d8fb077f54c.a

Linking everything together...

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega168 -o "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669/sketch_apr20a.ino.elf" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\sketch\\sketch_apr20a.ino.cpp.o" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\libraries\\Servo\\avr\\Servo.cpp.o" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\libraries\\Servo\\megaavr\\Servo.cpp.o" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\libraries\\Servo\\nrf52\\Servo.cpp.o" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\libraries\\Servo\\sam\\Servo.cpp.o" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\libraries\\Servo\\samd\\Servo.cpp.o" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669\\libraries\\Servo\\stm32f4\\Servo.cpp.o" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669/core\\core.a" "-LC:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669" -lm

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669/sketch_apr20a.ino.elf" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669/sketch_apr20a.ino.eep"

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669/sketch_apr20a.ino.elf" "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669/sketch_apr20a.ino.hex"

Multiple libraries were found for "Servo.h"

 Used: D:\Documents\Arduino\libraries\Servo

 Not used: C:\Program Files (x86)\Arduino\libraries\Servo

Using library Servo at version 1.1.3 in folder: D:\Documents\Arduino\libraries\Servo

"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-size" -A "C:\\Users\\Mark\\AppData\\Local\\Temp\\arduino_build_293669/sketch_apr20a.ino.elf"

Sketch uses 2964 bytes (20%) of program storage space. Maximum is 14336 bytes.

Global variables use 89 bytes (8%) of dynamic memory, leaving 935 bytes for local variables. Maximum is 1024 bytes.

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega168 -carduino -PCOM4 -b19200 -D -Uflash:w:C:\Users\Mark\AppData\Local\Temp\arduino_build_293669/sketch_apr20a.ino.hex:i

avrdude: Version 6.3-20190619

         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         Copyright (c) 2007-2014 Joerg Wunsch

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

         Using Port                    : COM4

         Using Programmer              : arduino

         Overriding Baud Rate          : 19200

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x62

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x62

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x62

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x62

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x62

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x62

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x62

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x62

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x62

avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x62

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

'''

It might be helpful if you add the error message with verbose output during compilation as instructed at the end of the error message. Is it an original Arduino or a Clone? And possible duplicate of this post.

Sorry, didn't see the Clone in the title and can't edit my comment now.

Hi, i updated my post. Would you mind checking it again? Thanks

Did you follow the weblink in the error message? Have you checked the Stackexchange post and the answers I linked to?

Board: "Arduino Duemilanove or Diecimila, ATmega168" is not Uno. what did you select in Tools menu?

Does this answer your question? "avrdude: stk500_getsync(): not in sync: resp=0x00," aka Some Dude Named Avr Won't Let Me Upload My Program

@Juraj Already linked it, see my first comment.

i already checked the link before submitting a post here but the post's solutions do not work

Did you change the board to UNO, as @Juraj said? In the second error message the selected board is a Arduino Duemilanove or Diecimila, ATmega168, not a UNO as you said in the title and in the first error message.

More words. Explain what board you actually have, the process your going through, and make sure the listings in your question match the output of the steps described.  If it the answer is as simple as "I selected the wrong board" you can just delete your question rather than letting it float around in the system forever being of no use to anyone else.

Hi, i have an arduino uno. the reason why the board was diecimila was that i found a thread before posting here that changing the board to the latter will somehow fix the issue. I already installed a driver for the board and my computer can read it, i just am not able to upload codes within it. I tried playing with the boards and programmers but nothing works, and yes i changed it back to the default yet still, it has the same problem. Thank you


text:
Brushless Motor "twitches" on its own when connected to battery
I've been trying to make a Bluetooth slider app that can control the spin speed of a brushless motor. The transmitter I am using is Arduino Mega. The problem I'm having is that my motor will start twitching at very random times even though my Arduino code specifies ESC.write(0), meaning the ESC should remain completely still.
Furthermore, I've noticed that the twitching begins the exact moment I connect my HM10 Bluetooth module to the Arduino. The motor is still able to be controlled by the slider on my app, however, even when the slider is set at zero, the motor turns on its own! I will attach a video to the problem in this link.
A couple of things I've noticed that may be of interest: when the ESC bullet connectors touch each other, there are audible sparks as well as burn holes.
Here is my arduino code

/*
   -- New project --

   This source code of graphical user interface
   has been generated automatically by RemoteXY editor.
   To compile this code using RemoteXY library 2.4.3 or later version
   download by link http://remotexy.com/en/library/
   To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
     - for ANDROID 4.7.12 or later version;
     - for iOS 1.4.7 or later version;

   This source code is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.
*/

//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>

#include <RemoteXY.h>

#include <Servo.h>

Servo ESC; //create servo object

// RemoteXY connection settings
#define REMOTEXY_SERIAL_RX 10
#define REMOTEXY_SERIAL_TX 11
#define REMOTEXY_SERIAL_SPEED 9600

// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,2,0,0,0,60,0,11,13,1,
  4,0,23,16,17,64,2,26,2,0,
  31,5,22,11,2,26,31,31,79,78,
  0,79,70,70,0,129,0,5,7,18,
  6,17,76,69,68,0,129,0,15,85,
  37,6,17,83,101,114,105,97,108,32,
  111,117,116,112,117,116,0 };

// this structure defines all the variables and events of your control interface
struct {

    // input variables
  int8_t slider_1; // =0..100 slider position
  uint8_t switch_1; // =1 if switch ON and =0 if OFF

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////

int power = 8;
int ledPin = 2;

void setup()
{
  RemoteXY_Init ();

  digitalWrite(LED_BUILTIN, HIGH);
  // TODO you setup code

  pinMode (LED_BUILTIN, OUTPUT);
  pinMode (power, OUTPUT);
  pinMode (ledPin, OUTPUT);
  //pinMode (7, OUTPUT);
  //int ledMapping;

  ESC.attach(6, 1000, 2000); //attach ESC to output from pin 6

  Serial.begin(9600);
}

void loop()
{
  RemoteXY_Handler ();

  //Serial.println(RemoteXY.slider_1);
  digitalWrite(power, HIGH); //supply power to Bluetooth module through pin 8
  //digitalWrite(7, HIGH);
  int ledMapping = map(RemoteXY.slider_1, 0, 100, 0, 255);
  //Serial.println(ledMapping);
  analogWrite(ledPin, ledMapping);

  int spinMapping = map(RemoteXY.slider_1, 0, 100, 0, 180); //map the slider to the servo
  if (RemoteXY.switch_1 == 1){
  ESC.write(spinMapping); //write to the ESC the value of mapped slider
  }
  else if (RemoteXY.switch_1 == 0){
  ESC.write(0);
  }
  Serial.println(spinMapping);

  if(RemoteXY.switch_1 == 1){
  digitalWrite(LED_BUILTIN, HIGH);
  }
  else if (RemoteXY.switch_1 == 0){
   digitalWrite(LED_BUILTIN, LOW);
  }

  // TODO you loop code
  // use the RemoteXY structure for data transfer
  // do not call delay()

}

But I don't think it is the problem. The reason is because even though I have ESC.write(0) when the LED switch is off, the ESC still turns (as is apparent in the video) randomly and twitches.
Any help would be greatly appreciated. I am trying to use this as a prototype for an eletric skateboard, but obivously if the motor is turning on its own even when it should be stopped, it is very dangerous to use.

please include the actual code instead of a link .... also add a schematic diagram of the circuit

what is your question? ... this is a Q&A site

Here is my arduino code, which I don't think is the problem. The reason is because even though I have ESC.write(0) when the LED switch is off ... how do you know that the led is off? ... the LED code is in a different if statement from the motor code ... also the LED could light very briefly, and you would never see it ... your code contains no debugging functions that could be used to confirm your thinking

you also have no way of knowing what data passes between the android device and the arduino ... write a simple sketch that does not have any motor functions, but logs the data that is received from android ... until you prove the quality of the connection between the two devices, it is kind of pointless to be thinking about the motor

@jsotola thanks for the responses. I should clarify: I've been using RemoteXY, which is an app that allows the Arduino to communicate with a smartphone via Bluetooth. I know that the slider_1 variable is set to zero (since the built_in LED turns on and off when the slider is set on and off), so the code should enter the else if (slider_1 ==0)  {ESC.write(0)} section. I'm suspect that it does, however perhaps a faulty connection may be causing the ESC to deliver power to the motor regardless of  the logical statements in the code?

faulty connection may be causing the ESC to deliver power to the motor ... start thinking about testing individual components ... test the "bad connection" theory ... write code that runs the motor for one or two seconds, stops motor for five seconds, and repeats

look at blinkWithoutDelay example code ... modify it so that the LED is turned off every second, or two, no matter what state it is in .... turn the LED on using if(RemoteXY.switch_1 == 1){ .... that will tell you if there are any phantom button presses .... basically, only a button press turns on the LED, and only a timeout turns it off .... chances are very high that the LED will stay on long enough for you to see it, if a phantom button press is received

try detaching the ESC instead of ESC.write(0)

Could you please expand on your answer. Like quickly explaining how to detach ESC and how that will have an effect.