text:
How to switch a low-voltage (1.5V) toy motor with an arduino?
I would like to add an Arduino to control a toy with a 1.5V battery and motor in it.  The toy is currently controlled by a SPST switch in series with a single 1.5V AA battery and a cheap motor.
I could put in a transistor like How to switch an external circuit with Arduino? or To connect a simple toy circuit and trigger with an arduino?  but I would think the voltage drop of the transistor would be significant in the 1.5V circuit.
What would you recommend for switching a 1.5V circuit?

You would be better off using a MOSFET which, when on, has quite a low resistance. For example the RFP30N06LE datasheet shows a RDS(on) of 0.047 Ω at 30A and 5V.
Using Ohm's Law we therefore expect a voltage drop of:
V = IR
V = 0.5 x 0.047
V = 0.0235

Thus, only 23 mV drop if you are drawing half an amp. I measured using a toy that drew 200 mA and found a 5 mV drop at 1.5V (compared to the theoretical 9 mV).
I have a page about driving motors that illustrates how you might wire up such a device.

The 12V on that schematic could just as easily be 1.5V.
The diode on the schematic is a snubber diode which protects the transistor from flyback voltages from the motor.

Comparison to transistor
BJT transistors will have a higher voltage drop between collector and emitter. For example the 2N3904 has a 200 mV drop (0.2V) (called VCE(sat)) when conducting 50 mA. This is a somewhat larger drop than the 5 mV drop that I got with the MOSFET, and a somewhat larger percentage of the 1.5V that you are starting with.

Cool, so if I snub the motor, I could jumper the Drain and Source terminals to my switch terminals.

Yes, the MOSFET will act as a switch. As per the schematic you want the Drain to be on the positive side. The Source would be the lead connected to the negative side of the battery.

Note that it is an N-channel MOSFET. Check the specs for the MOSFET you choose to make sure it can handle the current of whatever device it is that you are controlling. You could work that out by using a multimeter to bridge the switch connection (in amps mode) and get a current reading.

I'd always been a little shy of MOS devices because of static sensitivity from way back when my dad wouldn't let me solder a 4K dynamic memory board, but the device you linked looks like it has plenty of internal protection.

Those were the days! These days however I am careful but not obsessive about handling MOS devices. I mean, you don't dance around on a nylon carpet and then pick up a MOSFET, but if you calmly handle them after discharging any stray voltages by touching something which is grounded, you should be OK.


text:
How to make a smooth serial print?
I have a code which make some calculations using sensor values and provide two comma separated values.
float x;// initialization
float y;// initialization
//some calculations here using sensor values
Serial.print(x);Serial.print(",");Serial.print(y);

but the issue is due to some unstable situations of the sensor readings, I don't receive sensor data in same time intervals (overall delay is 1 second). I send these values to my Android device through a Bluetooth connection. At that stage, android device cannot separate two values due to lack of smoothness of the Serial.print(). Is there any way to make it smooth (like saving to a buffer before serial print or something) ?

Can you show us your sketch please?

please explain this cannot separate two values due to lack of smoothness ... do not use a word like smooth without explaining what it means

I bet your problem has nothing to do with “smoothness” (whatever that
means), but is entirely due to lack of message framing. The serial and
bluetooth links do not transmit messages: they transmit only a stream of
bytes, with no built-in notion of where a message ends and the next one
starts. Relying on the timing of the received bytes to tell the messages
apart is very unwise. You should instead use some kind of delimiter for
your messages.
For text-based transmissions like yours, the most natural choice is to
send a line terminator at the end of each message. Typically a CR+LF
pair. The Serial object has the println() methods designed precisely
for this purpose: they send their arguments immediately followed by
CRLF:
Serial.print(x); Serial.print(","); Serial.println(y);

At the receiving end, you have to buffer all the incoming characters
until you see the line termination. Then you know the message is
complete and you can process it.

Are there any way to make it smooth. (like saving to a buffer before serial print or something) ?

you can use sprintf function
char buff[50];
sprintf(buff, "{i:%i,t:%lu,v1:%d,v2:%d,c:%u}", ix, events[ix].timestamp, events[ix].value1, events[ix].value2, events[ix].count);
s.print(buff);

but this will not help you, I think. if you do not print nothing else only those 3 prints, then your next loop will print the first number 'glued' to the last number from the previous loop. use for example prinln to separate them with a newline.
if you have an interrupt in work which can interrupt the execution of the loop and make the prints 'not smooth', it too will be not repaired by printing a buffer. because the interrupt disrupts the Serial too

source: Stack Exchange

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

sort: votes


text:
AT response clean-up
I am trying to get the response from server using AT commands. This is my program
#include <SoftwareSerial.h>

const byte rxPin = 2; // Wire this to Tx Pin of ESP8266
const byte txPin = 3; // Wire this to Rx Pin of ESP8266

// We'll use a software serial interface to connect to ESP8266
SoftwareSerial ESP8266 (rxPin, txPin);

void setup() {
  Serial.begin(115200);
  ESP8266.begin(115200); // Change this to the baudrate used by ESP8266
  delay(1000); // Let the module self-initialize
}

void loop() {
  Serial.println("Sending an AT command...");
  ESP8266.println("AT+CIPMUX=1");
  delay(3000);

  ESP8266.println("AT+CIPSTART=0,\"TCP\",\"192.168.50.1\",1234");
  delay(3000);

  while (ESP8266.available()){
     String res = ESP8266.readStringUntil('\t');
     Serial.println(res);
  }

}

My server is just sending just one string as the output.
My console is getting this kind of output? Is there a way to clean this?
Sending an AT command...
AZi%PSՊj
C⸮j⸮L⸮AT+CIPSTART<0,"TCP","193.168.50.1",1234
0,CONNECT

OK
+IPD,0,1:10,CLOSDD

Sending an AT command...

I read thread and changed SoftwareSerial.h file. But still no luck.
Thanks in advance.

why do you not use a library? WiFiEsp for example?

You can't use SoftwareSerial reliably at 115200 baud.

@Majenko Yes, I tested even for 9600

@Juraj can you given me an example? I had been looking for this days.

https://github.com/bportaluri/WiFiEsp

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


text:
Need help on the "expected primary expression before "}" token"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

#define M11  2
#define M12  3
#define M13  4
#define M14  5

#define M21  6
#define M22  7
#define M23  8
#define M24  9

uint32_t commands[32];
int confirmationBuzzer = 17;
int i = 0;
boolean DirectionR = true;
boolean DirectionL = true;
int StepsR;
int StepsL;
int steps_left = 4095;
int caseLeft;

RF24 radio(10, 14); // CE, CSN
SoftwareSerial mySoftwareSerial(15, 16); // RX, TX

DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

const byte address[6] = "00001";

void stepperR(int xw) {
    for (int x = 0;x < xw;x++) {
        switch (StepsR) {
        case 0:
            digitalWrite(M11, LOW);
            digitalWrite(M12, LOW);
            digitalWrite(M13, LOW);
            digitalWrite(M14, HIGH);
            break;
        case 1:
            digitalWrite(M11, LOW);
            digitalWrite(M12, LOW);
            digitalWrite(M13, HIGH);
            digitalWrite(M14, HIGH);
            break;
        case 2:
            digitalWrite(M11, LOW);
            digitalWrite(M12, LOW);
            digitalWrite(M13, HIGH);
            digitalWrite(M14, LOW);
            break;
        case 3:
            digitalWrite(M11, LOW);
            digitalWrite(M12, HIGH);
            digitalWrite(M13, HIGH);
            digitalWrite(M14, LOW);
            break;
        case 4:
            digitalWrite(M11, LOW);
            digitalWrite(M12, HIGH);
            digitalWrite(M13, LOW);
            digitalWrite(M14, LOW);
            break;
        case 5:
            digitalWrite(M11, HIGH);
            digitalWrite(M12, HIGH);
            digitalWrite(M13, LOW);
            digitalWrite(M14, LOW);
            break;
        case 6:
            digitalWrite(M11, HIGH);
            digitalWrite(M12, LOW);
            digitalWrite(M13, LOW);
            digitalWrite(M14, LOW);
            break;
        case 7:
            digitalWrite(M11, HIGH);
            digitalWrite(M12, LOW);
            digitalWrite(M13, LOW);
            digitalWrite(M14, HIGH);
            break;
        default:
            digitalWrite(M11, LOW);
            digitalWrite(M12, LOW);
            digitalWrite(M13, LOW);
            digitalWrite(M14, LOW);
            break;
        }
        SetDirectionR();
    }
}

void SetDirectionR() {
    if (DirectionR == 1) { StepsR++; }
    if (DirectionR == 0) { StepsR--; }
    if (StepsR>7) { StepsR = 0; }
    if (StepsR<0) { StepsR = 7; }
}

void stepperL(int xw) {
    for (int x = 0;x<xw;x++) {
        switch (StepsL) {
        case 0:
            digitalWrite(M11, LOW);
            digitalWrite(M12, LOW);
            digitalWrite(M13, LOW);
            digitalWrite(M14, HIGH);
            break;
        case 1:
            digitalWrite(M11, LOW);
            digitalWrite(M12, LOW);
            digitalWrite(M13, HIGH);
            digitalWrite(M14, HIGH);
            break;
        case 2:
            digitalWrite(M11, LOW);
            digitalWrite(M12, LOW);
            digitalWrite(M13, HIGH);
            digitalWrite(M14, LOW);
            break;
        case 3:
            digitalWrite(M11, LOW);
            digitalWrite(M12, HIGH);
            digitalWrite(M13, HIGH);
            digitalWrite(M14, LOW);
            break;
        case 4:
            digitalWrite(M11, LOW);
            digitalWrite(M12, HIGH);
            digitalWrite(M13, LOW);
            digitalWrite(M14, LOW);
            break;
        case 5:
            digitalWrite(M11, HIGH);
            digitalWrite(M12, HIGH);
            digitalWrite(M13, LOW);
            digitalWrite(M14, LOW);
            break;
        case 6:
            digitalWrite(M11, HIGH);
            digitalWrite(M12, LOW);
            digitalWrite(M13, LOW);
            digitalWrite(M14, LOW);
            break;
        case 7:
            digitalWrite(M11, HIGH);
            digitalWrite(M12, LOW);
            digitalWrite(M13, LOW);
            digitalWrite(M14, HIGH);
            break;
        default:
            digitalWrite(M11, LOW);
            digitalWrite(M12, LOW);
            digitalWrite(M13, LOW);
            digitalWrite(M14, LOW);
            break;
        }
        SetDirectionL();
    }
}

void SetDirectionL() {
    if (DirectionL == 1) { StepsL++; }
    if (DirectionL == 0) { StepsL--; }
    if (StepsL>7) { StepsL = 0; }
    if (StepsL<0) { StepsL = 7; }
}

void setup() {

    myDFPlayer.volume(7);

    radio.begin();
    radio.openReadingPipe(0, address);
    radio.setPALevel(RF24_PA_MIN);
    radio.startListening();
}
void loop() {

    if (radio.available()) {
        radio.read(&commands, sizeof(commands));
    }
    for (i = 0; i<15; i++) {
        switch (i) {

        case(0):

            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }

            break;

        case(1): {
        case1:
            int caseLeft = 1;
            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }

            break;
        }
        case(2): {
        case2:
            int caseLeft = 2;
            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }
            break;
        }
        case(3): {
        case3:
            int caseLeft = 3;
            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }
            break;
        }
        case(4): {
        case4:
            int caseLeft = 4;
            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }
            break;
        }
        case(5): {
        case5:
            int caseLeft = 5;
            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }
            break;
        }
        case(6): {
        case6:
            int caseLeft = 6;
            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }
            break;
        }
        case(7): {
        case7:
            int caseLeft = 7;
            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }
            break;
        }
        case(8): {
        case8:
            int caseLeft = 8;
            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }
            break;
        }
        case(9): {
        case9:
            int caseLeft = 9;
            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }
            break;
        }
        case(10): {
        case10:
            int caseLeft = 10;
            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }
            break;
        }
        case(11): {
        case11:
            int caseLeft = 11;
            switch (commands[i]) {
            case(0):
                goto outoftheloop;
                break;

            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):

                goto function1;

                break;
            }
            break;
        }
        case(12): {
        function1:
            switch (commands[i]) {
            case(0):
                switch (caseLeft) {

                case(0):
                    goto case1;
                    break;

                case(1):
                    goto case2;
                    break;

                case(2):
                    goto case3;
                    break;

                case(3):
                    goto case4;
                    break;
                case(4):
                    goto case5;
                    break;

                case(5):
                    goto case6;
                    break;

                case(6):
                    goto case1;
                    break;

                case(7):
                    goto case2;
                    break;

                case(8):
                    goto case1;
                    break;

                case(9):
                    goto case2;
                    break;
                case(10):
                    goto case1;
                    break;

                case(11):
                    goto case2;
                    break;
                }
                break;
            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                goto function2;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                goto function2;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                goto function2;
                break;

            case(4):
                goto function1;

                break;

            }
            break;
        }
        case(13): {
        function2:
            switch (commands[i]) {
            case(0):
                switch (caseLeft) {

                case(0):
                    goto case1;
                    break;

                case(1):
                    goto case2;
                    break;

                case(2):
                    goto case3;
                    break;

                case(3):
                    goto case4;
                    break;
                case(4):
                    goto case5;
                    break;

                case(5):
                    goto case6;
                    break;

                case(6):
                    goto case1;
                    break;

                case(7):
                    goto case2;
                    break;

                case(8):
                    goto case1;
                    break;

                case(9):
                    goto case2;
                    break;
                case(10):
                    goto case1;
                    break;

                case(11):
                    goto case2;
                    break;
                }
                break;
            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                goto function3;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                goto function3;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                goto function3;
                break;

            case(4):
                goto function1;

                break;

            }
            break;
        }
        case(14): {
        function3:
            switch (commands[i]) {
            case(0):
                switch (caseLeft) {

                case(0):
                    goto case1;
                    break;

                case(1):
                    goto case2;
                    break;

                case(2):
                    goto case3;
                    break;

                case(3):
                    goto case4;
                    break;
                case(4):
                    goto case5;
                    break;

                case(5):
                    goto case6;
                    break;

                case(6):
                    goto case1;
                    break;

                case(7):
                    goto case2;
                    break;

                case(8):
                    goto case1;
                    break;

                case(9):
                    goto case2;
                    break;
                case(10):
                    goto case1;
                    break;

                case(11):
                    goto case2;
                    break;
                }
                break;
            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                goto function4;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                goto function4;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                goto function4;
                break;

            case(4):
                goto function1;

                break;

            }
            break;
        }
        case(15): {
        function4:
            switch (commands[i]) {
            case(0):
                switch (caseLeft) {

                case(0):
                    goto case1;
                    break;

                case(1):
                    goto case2;
                    break;

                case(2):
                    goto case3;
                    break;

                case(3):
                    goto case4;
                    break;
                case(4):
                    goto case5;
                    break;

                case(5):
                    goto case6;
                    break;

                case(6):
                    goto case1;
                    break;

                case(7):
                    goto case2;
                    break;

                case(8):
                    goto case1;
                    break;

                case(9):
                    goto case2;
                    break;
                case(10):
                    goto case1;
                    break;

                case(11):
                    goto case2;
                    break;
                }
                break;
            case(1):

                DirectionR = true;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(2);
                    stepperL(2);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(2):
                DirectionR = true;
                DirectionL = false;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(3):
                DirectionR = false;
                DirectionL = true;

                while (steps_left>0) {

                    stepperR(1);
                    stepperL(1);
                    steps_left--;
                }
                steps_left = 4095;
                break;

            case(4):
                goto function1;

                break;

            }
            break;
        }
        }
    }
outoftheloop:
}

Sorry for the long code,I would send only a part of the code that shows error however I am not sure if the other parts are related to the code. I get this error.

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\TEDNOKENT2\Desktop\sketch_dec22a\sketch_dec22a.ino: In function 'void setup()':
C:\Users\TEDNOKENT2\Desktop\sketch_dec22a\sketch_dec22a.ino:183:35: warning: invalid conversion from 'const byte* {aka const unsigned char*}' to 'uint64_t {aka long long unsigned int}' [-fpermissive]
radio.openReadingPipe(0, address);
In file included from >C:\Users\TEDNOKENT2\Desktop\sketch_dec22a\sketch_dec22a.ino:3:0:
C:\Users\TEDNOKENT2\Documents\Arduino\libraries\RF24-master/RF24.h:350:8: note: >initializing argument 2 of 'void RF24::openReadingPipe(uint8_t, uint64_t)'
void openReadingPipe(uint8_t number, uint64_t address);
C:\Users\TEDNOKENT2\Desktop\sketch_dec22a\sketch_dec22a.ino: In function 'void loop()':
sketch_dec22a:1288: error: expected primary-expression before '}' token
}
exit status 1
  expected primary-expression before '}' token
This report would have more information with
  "Show verbose output during compilation"
  option enabled in File -> Preferences.

Normally, it should have been fixed adter I deleted some extra brackets but it just stayed there. I have no idea why. I know I shouldn't use gotos that often, however, I am kind of a novice programmer and goto s make it a lot easier to code. I would appreaciate any suggestions on the error. If anthing else that is not related to the error but you think is not necessary, you can mention them too.
Thanks in advance

That is terrible code! There is no call ever to use goto. Full stop. And certainly never in the way you have used it. That code is completely impossible to follow the flow of.

You should not only use goto's that often, you should not use them ever.

goto s make it a lot easier to code - but not as easy to read, eh? Or debug?

Actually, although I'm not going to check for every bracket, here are some tips to prevent the problem (and if you follow them you will find your missing/extra bracket):

Align brackets, I know it saves one line if you put the { directly after statements, but much neater to put them separately on the next line.
Make short functions. If you get a compiler error in a function, it's much easier to find the location. It also helps clearity, maintainability, testability etc. To do this:
Do not use  more than 2 or 3 compound statements (while, switch, if etc).
Put (almost) duplicate code in separate functions and call them (either without parameters or with parameters if needed).
Never use goto statements. You can always replace them by if, while, for or do statements.

My two cents here.
When you have lots of repetitive structures, like in function stepperR, is time to simplify, put some things as data and reduce the repetitiveness of your code.
Here is stepperR reimplemented
byte values[9] = {1, 3, 2, 6, 4, 12, 8, 9, 0};
void stepperR(int xw) {
    for (int x = 0;x < xw;x++) {
            digitalWrite(M11, values[StepsR] & 0x08);
            digitalWrite(M12, values[StepsR] & 0x04);
            digitalWrite(M13, values[StepsR] & 0x02);
            digitalWrite(M14, values[StepsR] & 0x01);
            SetDirectionR();
    }
}

I choose StepsR == 8 as the default value (all zeros).


text:
ESP8266 odd HTTP GET request
I'm using an Arduino Uno to send HTTP requests to my local webserver. To communicate to the ESP8266 I created a SoftwareSerial which is set to a baud rate of 9600.
Whenever I send a HTTP request, the request looks like the following:
    192.168.2.132 - - [22/Dec/2017:12:22:57 +0100] "TP/1.1" 400 173 "-" "-"
    192.168.2.132 - - [22/Dec/2017:12:23:38 +0100] "z\x02BQQA\xBD1.1" 400 173 "-" "-"
    192.168.2.132 - - [22/Dec/2017:12:23:56 +0100] "z\x02BQQA\xBD1.1" 400 173 "-" "-"
    192.168.2.132 - - [22/Dec/2017:12:24:14 +0100] "z\x02BQQA\xBD1.1" 400 173 "-" "-"
    192.168.2.132 - - [22/Dec/2017:12:24:34 +0100] "\xE9\x09BQQA\xBD1.1" 400 173 "-" "-"
    192.168.2.132 - - [22/Dec/2017:12:25:06 +0100] "z\x02BQQA\xBD1.1" 400 173 "-" "-"
    192.168.2.132 - - [22/Dec/2017:12:27:01 +0100] "\x02BQQA\xBD1.1" 400 173 "-" "-"
    192.168.2.132 - - [22/Dec/2017:12:28:11 +0100] "\x02BQQA\xBD1.1" 400 173 "-" "-"

The code to create GET request to send over TCP:
  char *hello = "GET / HTTP/1.1\r\nHost: 192.168.2.106\r\nConnection: close\r\n\r\n";

  if (wifi.send((const uint8_t*)hello, strlen(hello))) {
    Serial.print("Wifi send succesfull\r\n");
  } else {
    Serial.print("Wifi not send succesfully\r\n");
  }

The actual send method:
bool ESP8266::sATCIPSENDSingle(const uint8_t *buffer, uint32_t len)
{
    rx_empty();
    m_puart->print("AT+CIPSEND=");
    m_puart->println(len - 4);

    if (recvFind(">", 5000)) {
        Serial.println("found >");
        rx_empty();

        for (uint32_t i = 0; i <= len; i++) {
            m_puart->write(buffer[i]);
        }

        return recvFind("SEND OK", 30000);
    }
    return false;
}

This line:
m_puart->println(len - 4);

Was in the library actually just m_puart->println(len);
I had to shorten the length of the buffer for esp8266 to wait to, otherwise it wouldn't send the TCP command. The counting part of bytes looks fine to me. Not sure what's causing this behaviour.
The part above is just some extra unusual behaviour but isn't the main priority. So any ideas what's causing the odd HTTP requests?

did you set the 9600 baud rate in the AT firmware?

Yes i did, it's also saved in the flash.


text:
how to check 24c32 eprom is connected or not to arduino runtime?
I want to check it on runtime if runitme i remove eprom then it shows "please insert dongle " also tried using while loop showing eroor.. How can i solve it?
Wire.beginTransmission(80);
      error = Wire.endTransmission();
    if (error == 0)
    {
    serial.print("connected");
    }
    else
    {
    serial.print("please insert dongle");
    }

also tried using while loop in loop()
void loop()
{
while (error == 0){
Serial.print("connected");
}

Serial.print("insert dongle");
}

Don't completely change the question and invalidate the existing answer. Also write properly. What is this: "usin ehilw llop"?

Did you try Wire.avaliable()?

You should take parts of the I2C Scanner. You don't need to scan for all addresses - you can just scan for the one address you're interested in:
Wire.beginTransmission(80);
error = Wire.endTransmission();

if (error == 0)
{
  Serial.print("Connected");
} else {
  Serial.println("Insert dongle");
}

not working in runtime using also while loop? how to work as runtime?

Define "doesnt work"...


text:
Problem uploading the code into an Arduino Uno
I was trying to upload code for a blinking LED. It is a new Arduino Uno board. Any further help will be appreciated.I got the following error:

Info.: OS- Ubuntu 16.04
Software: Arduino IDE 1.8.5

I could not see any port.
I have tried dialout. But still it is not working.
I also have a confusion, i.e. the Programmer menu shows AVRISP mkll.

If anyone wants any information, please do comment.
Error:

An error occurred while uploading the sketch
avrdude: ser_open(): can't open device "COM1": No such file or directory`

An Arduino Uno on Ubuntu will typically be at /dev/ttyACM0.

Ubuntu and other Linux operating systems don’t name the serial ports “COM1” or similar.
They use special files like
/dev/tty.[something]

The [something] depends on the USB device driver. The IDE should list available serial ports in the Port selection menu.

there is not port available

What ports show up?

NO port is shown.

@ChandramauliChakraborty are you in dialout group? Or better, have you read any tutorial about Arduino in Linux?

Perhaps you don’t have the right permissions to access the serial ports. Your user must have access to the serial ports. On Ubuntu, this can be accomplished by adding your user to the dialout group. Also, make sure you have the Uno plugged into the computer.

How to do it? Please elaborate.

https://playground.arduino.cc/Linux/Ubuntu

I have tried it is not working.

After adding your user to the dialout group, you have to log out completely and log back in.

Stil it is not working

One troubleshooting step - unplug the board, then open a terminal window and run the lsusb command.  Note the devices that appear in the list.  Then plug the board back in and run lsusb again - you should see the new device.  If you don't, that could explain why you're not getting a list of available ports.  On my Ubuntu system (Studio, 16.04), the device name shows up as "1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter" and connects through /dev/ttyUSB0.


text:
How to control 6 servo motors with an Arduino Mega board?
I am trying to make autonomous hexapod with an Arduino Mega board. I have followed tripod mechanism of hexapod movement. First I could control simultaneously legs (0, 2, 4) and (1, 3, 5) separately but whenever I tried to combine both i.e control 6 legs at a time I could not see any movement in the hexapod. Even in the IDE I am not getting any error.
I have connected the legs (0 to 5) to signal pins (2 to 7) respectively. I have connected a common +5v voltage and common ground voltage to individual legs using a breadboard. Can anyone give me a proper solution to overcome this issue and further would like to know how to control multiple servos and source code for it?
Here is my Arduino source code for controlling 6 servo motors.
#include <Servo.h>
Servo myservo[6];
int f=0;// create servo object to control a servo
//[0] -tibia , [1] -femur , [2] -coxa motors
void setup() {
  myservo[0].attach(2);
  myservo[1].attach(3);
  myservo[2].attach(4);
  myservo[3].attach(5);
  myservo[4].attach(6);
  myservo[5].attach(7);
}

void loop() {
  //alternatively making hexapod stand at its place
  //f is just flag variable to make it stop
  if(f==0) {
    myservo[0].write(130);
    myservo[2].write(130);
    myservo[4].write(90);
    myservo[1].write(130);
    myservo[3].write(90);
    myservo[5].write(0);
    f=1;
  }
}

Note the values that are added above are calculated separately for individual legs to mount legs on ground.

If you set your code to control 6 servos, does it work when you only connect 3 servos? If it does, then the problem may just be that your power supply is not strong enough to power 6 servos.

@EdgarBonet thank you it works fine when it connected to external power supply

I want to control 18 servos and based on your code I would add in 14 more servo objects. Is there a final code that you already finished with the 6 servos?

The Arduino Mega can handle at most 40mA on the I/O pins, and 200mA on the 5V/GND pins. Six servos will draw far more current than the max of 200mA. You could try hooking up the servo power to a separate power source and the data pins to the Arduino. Hope this helps!

in the odd case that you are actually powering your (small?) servo's directly through the arduino : you'll need an external power source for your servo's.


text:
WiFi module ESP8266-01 for Arduino not working
I am new to using Arduino just bought my first one yesterday, and I also got an WiFi module. The Arduino I got is another brand but should be the same as the Arduino Uno rev 3 and I got the ESP8266-01 wifi module.
I've tried doing some simple examples projects following some YouYube videos, and all those have worked without problem.
What I am trying to create is a simple magnetic door switch. When it's opened I get a signal to my computer. Getting the magnetic door switch wired with the Arduino and getting an LED to light up when the magnetic switch opened worked without problem.
But to set up the wifi module, I can't get it to work.
I have spent hours and hours watching tutorials reading all I can find to trying everything to get this to work, but no luck.
I don't know If I am doing something wrong (probably) or if something is broken.
These are the instructions I am trying currently.
Video of my Arduino setup
For the Arduino board I use 12v DC in and USB from my PC.
Code:
#include "Arduino.h"
#include "ESP8266.h"

#include "SoftwareSerial.h"
SoftwareSerial  ConsoleOut(8, 9);

#define SSID  "ASUS"
#define PWD   "tmpPassword"

void setup() {
  char  *ipAddress, ap[31];

  WiFi.reset(WIFI_RESET_HARD);
  WiFi.begin(9600);
  ConsoleOut.print("flag2");
  if (WiFi.join(SSID, PWD) == WIFI_ERR_OK) {
    ipAddress = WiFi.ip(WIFI_MODE_STA);
    ConsoleOut.print(F("\n\rIP address:"));
    ConsoleOut.print(ipAddress);
    ConsoleOut.print(':');
    ConsoleOut.print("flag1");
    if (WiFi.isConnect(ap))
      ConsoleOut.println(ap);
    else
      ConsoleOut.println(F("not found"));
  } else
    while (1);
}

void loop() {
  if (WiFi.connect((char *)"www.google.co.jp", 80) == WIFI_ERR_CONNECT) {
    if (WiFi.send((const uint8_t *)"GET / HTTP/1.1\r\n\r\n") == WIFI_ERR_OK) {
      int16_t c;
      uint16_t len = WiFi.listen(10000UL);
      while (len)
        if ((c = WiFi.read()) > 0) {
          ConsoleOut.write((char)c);
          len--;
        }
    } else
      ConsoleOut.println(F("Send fail"));
    WiFi.close();
  } else
    ConsoleOut.println(F("TCP connect fail"));
  WiFi.disconnect();
  while (1);
}

Code:

Different from the example sketch is that I use 2K instead of 3K resistors for R2, R4 and 1K for R1, R3. (2K on left side in the video 1K on the right side)
The LED of the WiFi lights red constantly. I don't know what that means,  and the blue LED on the wiFi module lights up whenever I upload a sketch to the Arduino.
Thanks in advance. Any help is really, really appreciated.

Did you set the baud rate of the esp to 9600? Setting it in code is not enough.

@Jamie when I read other people doing that they say they bricked the esp8266, I changed it to 115200 in code, I believe that is the default?not that It really made any difference, if I try to send command in the serial monitor nothing happens.

SoftwareSerial can't handle that speed. 9600 is the maximum. I'll write an answer because I've to paste some code you can use.

@PatrikFröhler What library are you using, could you send a link?

library https://github.com/Hieromon/ESP8266

Use this code to send commands to the ESP:
#include <SoftwareSerial.h>

    SoftwareSerial esp8266(2, 3);

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

      esp8266.begin(9600);
    }

    void loop() {
      while(esp8266.available()) {
         Serial.write(esp8266.read());
      }

      while(Serial.available()) {
        esp8266.write(Serial.read());
      }
    }

This simply reads everything from the ESP chip and sends it to the console and vica versa.
To modify the baud rate on the chip, send the following command in the serial monitor:
AT+UART_DEF=9600,8,1,0,0

This sets the baud rate to 9600 and remembers it for further use.

Nothing happens with that code serial monitor blank, what should I have the serial monitor set to when trying to send commands?

I recommend 9600. You probably won't see anything at first. But after a reset you should see your responses. To test responses send the following command: AT, you should get OK bad.

After I reset I only get "   ⸮  ⸮       ⸮⸮  " in the serial monitor nothing happens when trying  AT

The two other problems i can only think of is using other resistors than 1k and a different voltage than 3.3 volt..

Try another library, because I just tested yours and it doesn't work for me as well. https://github.com/itead/ITEADLIB_Arduino_WeeESP8266


text:
Will Arduino Mega support stepper motor NEMA 24, NEMA 34
Will two stepper motor NEMA 24, 10 kg cm, 2. 8 amp, 24 vdc work at same time on Arduino Mega and when they stop stepper motor NEMA 34, 34 kg cm, 4amp, 24 VDC will work or not? This is my first project please help me to choose the controller.

Properly running multiple stepper motors is a bit challenging if they need to move at the same time, but any Arduino-based 3d printer firmware manages to do so.  If only one needs to move at time then it is far simpler.  Selecting the power drivers for a given motor is not an Arduino question and therefore not on topic here.

I'm using 4x Nema 24s for a CNC project of mine.  They only need a couple of signals/pins each from the Arduino to work, the rest is up to the stepper controller board.
For my steppers, I'm using TB6600s, since I need ~3.5 amps per motor/channel.  There are others out there that'll work, but it's what I saw other people at my maker space using.
Nema34s would probably need higher rated amps, so that would determine what controller you need to use.
In fact, every motor is rated for different amps and voltages, so that will always determine what motor controller you use.  Since you need a higher voltage to run the motor controllers than the Arduino, using a separate stepping power supply is a requirement.
The Arduino gets hooked to the step/pulse and direction pins of the motor controller and the other pins on the motor controller go elsewhere.  The CNC motor controller shields you normally see are for lower amp controllers and do most of the pin connections for you.  With the higher amperage motors, you'll have to do this yourself.
When you determine what motor controller you are going to use, find a wiring diagram for it (and maybe a friend) to figure out how it should be wired.


text:
How to fade an LED in response to a sensor?
As the sensor "sees" an object nearby, it makes the LED go to full brightness and it remains like that for as long as the sensor keeps on sensing the object. Then, as soon as the sensor stops sensing it, the LED goes OFF instantly... and so on, endlessly. This part of the code works perfectly as it is right now.
MY PROBLEM:
I need all of this ON and OFF switching to happen with smooth PWM fades instead of with abrupt "instant ON" and "instant OFF" changes. I need to have a 1.5 seconds PWM fade-in of the LED from 0% to 100% as soon as the sensor gets activated; and then a 3.5 seconds fade-out as soon as the sensor stops sensing something nearby. As long as the sensor is activated, the LED needs to remain at full brightness. So, simply put: I need the LED to dim smoothly between the sensor's state-changes, instead of changing instantly in an abrupt manner.

Look at the Fade example sketch under Examples/Basics.

But i am not getting how to synchronize it with the sensor,, i want that as the sensor remains high the LED should remain high Fade in and vice versa

In the loop function, check the value of the sensor.  Based on that value set a goal for the led brightness of 0 or 255.  Maintain another variable for the current brightness, if the current brightness is not equal to the goal brightness, move it a little closer and do an analogWrite.  Put a delay at the bottom of the loop to make the fade transition more gradual (delay = time to go from 0 to 100 in milliseconds divided by 256).  The PWM will be 0..255 which corresponds to 0..100%.

This is the typical problem which calls for a finite state machine.
You create a “state” variable to keep track of the LED state, which can
be OFF, FADING_IN, ON or FADING_OUT. You also need another
variable to remember when you started the fade-in or the fade-out. I
would start the program some declarations like the following:
const uint8_t  LED_PIN       = 3;
const uint32_t FADE_IN_TIME  = 1500;
const uint32_t FADE_OUT_TIME = 3500;

static enum { OFF, FADING_IN, ON, FADING_OUT } led_state;
static uint32_t fade_start;

Now that you know the LED state, you use it to condition the LED
handling on the current state. For example, the brightness at any given
time can be computed as:
/* Compute the LED brightness after the given fade time */
static uint8_t led_brightness(uint32_t fade_time)
{
    int mapped;
    switch (led_state) {
        case FADING_IN:
            mapped = map(fade_time, 0, FADE_IN_TIME, 0, 255);
            return constrain(mapped, 0, 255);
        case FADING_OUT:
            mapped = map(fade_time, 0, FADE_OUT_TIME, 255, 0);
            return constrain(mapped, 0, 255);
        case ON:
            return 255;
        default:
            return 0;
    }
}

where fade_time would be millis() - fade_start. Note the use of the
standard map() function to generate a linear ramp, and constrain()
to avoid overflowing the range 0 – 255.
Now, switching the LED on or off is just a matter of setting the correct
state... and updating fade_start as necessary:
/* Set the LED pin to HIGH or LOW, through fading. */
void ledWrite(uint8_t value)
{
    uint32_t now = millis();
    if (value == HIGH) {
        if (led_state == OFF) {
            fade_start = now;
        }
        else if (led_state == FADING_OUT) {
            fade_start = now - map(now - fade_start,
                    0, FADE_OUT_TIME,
                    FADE_IN_TIME, 0);
        }
        if (led_state != ON)
            led_state = FADING_IN;
    }
    else {
        if (led_state == ON) {
            fade_start = now;
        }
        else if (led_state == FADING_IN) {
            fade_start = now - map(now - fade_start,
                    0, FADE_IN_TIME,
                    FADE_OUT_TIME, 0);
        }
        if (led_state != OFF)
            led_state = FADING_OUT;
    }
}

A few things worth noting:

trying to switch the LED on has no effect if it's already on or fading
in, and trying to switch it off has no effect if it's either off or
fading out
if you switch it on while it's fading out, it will move to the state
FADING_IN, and the fade_start time will be set to a value that
ensures continuity of the brightness; same thing when switching from
FADING_IN to FADING_OUT.

There is one more thing to do. Your program should periodically update
the LED state, not only to update its brightness, but also to enforce
the transitions FADING_IN → ON and FADING_OUT → OFF when needed:
/* This should be called periodically to update the LED. */
void update_led()
{
    uint32_t fade_time = millis() - fade_start;
    if (led_state == FADING_IN && fade_time >= FADE_IN_TIME)
        led_state = ON;
    else if (led_state == FADING_OUT && fade_time >= FADE_OUT_TIME)
        led_state = OFF;
    analogWrite(LED_PIN, led_brightness(fade_time));
}

With all this in place, you can write the main program just as you did
with no fading, only with the extra call to update_led() on every loop
iteration:
void setup()
{
    // Initialize the sensor.
    sensor.begin();
}

void loop()
{
    // Set the LED as per the sensor reading.
    if (sensor.detects_object())
        ledWrite(HIGH);
    else
        ledWrite(LOW);

    // Update the LED brightness on every loop iteration.
    update_led();
}

Oh, and beware not to do anything blocking in loop() (e.g., no calls
to delay()). Otherwise the LED brightness would be “jumpy”.

Do analogRead(sensor) and check what range of values you are getting. Arduino has 10 bit adc which means you can get 0-1023 in readings. However the sensor might not go complete LOW (0) or complete HIGH (1023). So just measure what's the range you are getting. Assume the range is 125 - 980.
PWM on arduino - This one is 8 bit, which means you can write 0-255. 0 means LED is OFF and 255 means LED is fully ON. Now you need to map 125-980 to 0-255 (as far as I can understand from your comments about synchronizing it with the sensor).
Here is what your code will look like:
/* Map an analog value (125-980) to 8 bits (0 to 255) */

    void loop()
    {
      int val = analogRead(0); //sensor attached to A0
      val = map(val, 125, 980, 0, 255);
      analogWrite(9, val); //LED attached to D9
    }

Thank you very much for your support this is what i tested and its working fine


text:
Clion Arduino plugin: Error:Could not find Arduino SDK (set ARDUINO_SDK_PATH)
I am trying to setup CLion as my workspace for my arduino. I have installed the two Arduino plugins for CLion, generated a new sketch project, but I am getting cmake errors on opening the project.
CMake Error at /cygdrive/c/Users/user/project/cmake/ArduinoToolchain.cmake:86 (message):
  Could not find Arduino SDK (set ARDUINO_SDK_PATH)!
Call Stack (most recent call first):
  /cygdrive/c/Users/user/project/CMakeFiles/3.9.4/CMakeSystem.cmake:6 (include)
  /cygdrive/c/Users/user/project/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)

The issue is similar to this logged issue here:
https://github.com/francoiscampbell/CLionArduinoPlugin/issues/11
As a Windows 10 user, I have the Arduino SDK installed here: C:\Program Files (x86)\Arduino
What's interesting is that the cmake file is calling the UNIX commands when it's running in this if statement:
    if(UNIX)
        file(GLOB SDK_PATH_HINTS /usr/share/arduino*
            /opt/local/arduino*
            /opt/arduino*
            /usr/local/share/arduino*

                )
    elseif(WIN32)
        set(SDK_PATH_HINTS "C:\\Program Files\\Arduino"
            "C:\\Program Files (x86)\\Arduino\\libraries"
            )
    endif()

I have the same error, even if I set it manually: set(ARDUINO_SDK_PATH C:\Program Files\Arduino) I checked my path, but nothing wrong in the arduino path, I'm using Cygwin if it can help...

Me too. Did you ever figure this out?

unfortunately no :(


text:
Object Sensor on conveyor belt (want to record the data in EEPROM for testing)
void setup ()
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LED_Blue_pin, OUTPUT);
pinMode(LED_White_pin, OUTPUT);

Serial.begin(9600);
digitalWrite(LED_Blue_pin, LOW);
digitalWrite(LED_White_pin, LOW);

void loop()
{
    long duration, cm;

    pinMode(trigPin, OUTPUT);
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(5);
    digitalWrite(trigPin, LOW);

    pinMode(echoPin, INPUT);
    duration = pulseIn(echoPin, HIGH);

    cm = microsecondsToCentimeters(duration);
    long distance = 70 - cm ;

    if (distance < 20) {
        Serial.println("NO ITEM");
        digitalWrite(LED_White_pin, HIGH);
    } else {
        digitalWrite(LED_White_pin, LOW);
    }

    if (distance > 20 && distance < 70) {
        digitalWrite(LED_Blue_pin, HIGH);
        Serial.print("Item : ");
        Serial.print(item++);
        Serial.println(" stk");
    } else {
        digitalWrite(LED_Blue_pin, LOW);
    }

    delay(1500);
}

long microsecondsToCentimeters(long microseconds)
{
    return microseconds / 29 / 2;
}

The code above is for the Ultrasonic Sensor HC-SR04. The sensor detects items that passes through and counts them along the way. The Blue Led indicates that the sensor detected an item while the White Led detects none. How can I store the data from HC-SR04 to EEPROM? The reason is, I just want to test it out before I sent the data from EEPROM to a database server. I'm still a novice at this.

You can use the EEPROM.write() function. There is a useful tutorial on the Arduino site.
The sample code from that tutorial is shown below:
/*
 * EEPROM Write
 *
 * Stores values read from analog input 0 into the EEPROM.
 * These values will stay in the EEPROM when the board is
 * turned off and may be retrieved later by another sketch.
 */

#include <EEPROM.h>

/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int addr = 0;

void setup() {
  /** Empty setup. **/
}

void loop() {
  /***
    Need to divide by 4 because analog inputs range from
    0 to 1023 and each byte of the EEPROM can only hold a
    value from 0 to 255.
  ***/

  int val = analogRead(0) / 4;

  /***
    Write the value to the appropriate byte of the EEPROM.
    these values will remain there when the board is
    turned off.
  ***/

  EEPROM.write(addr, val);

  /***
    Advance to the next address, when at the end restart at the beginning.

    Larger AVR processors have larger EEPROM sizes, E.g:
    - Arduno Duemilanove: 512b EEPROM storage.
    - Arduino Uno:        1kb EEPROM storage.
    - Arduino Mega:       4kb EEPROM storage.

    Rather than hard-coding the length, you should use the pre-provided length function.
    This will make your code portable to all AVR processors.
  ***/
  addr = addr + 1;
  if (addr == EEPROM.length()) {
    addr = 0;
  }

  /***
    As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
    EEPROM address is also doable by a bitwise and of the length - 1.

    ++addr &= EEPROM.length() - 1;
  ***/

  delay(100);
}


text:
What options do I have to get 5v on my current project?
I'm very new to arduino and have started work on my first project, a simple little web server. I'm using a NodeMCU with an sd card module and screen. The issue is that in order to power my sd card module, I need to input 5V which the MCU doesn't provide.
In order to work around this I'm simply using an arduino nano as a power supply to pass into the vin input on the mcu.
What options do I have to exclude the need for the nano? Is there a simple module I can buy that acts as a power supply for 5v?
Any help would be great, thanks!

what's your existing power source?

SD cards usually use around 3.3V. Get a module that doesn't need 5V.

SD cards require 3.3V. Usually, to connect them to an Arduino running at 5V you need to get a level converter. However in your case it sounds like you are making work for yourself:
3.3V <--> 5V <--> 3.3V

in order to power my sd card module, I need to input 5V

Which SD card module? Maybe you don't need a "module".

The others write that the card needs 3.3V. Your module need 5V. This means that between the input of the module and the sd card is something. it can be a voltage regulator or something like a voltage dropper (resistor in series with diodes). You can search for it on your module. If you are sure you found it you can solder a bridge around it. After this you can give 3.3V to this module.
I think this must work.

To supplement; if you don’t have a level converter on hand, have a look at this diagram:
http://homediyelectronics.com/projects/arduino/seriallevelconverter/
Just test it on a breadboard, and if Vcc, Rx and Tx are within 10% of 3.3V, solder it to a bit of perfboard. Haven’t needed to build one myself, since these come in tiny SMD packages which cost almost nothing:
https://rover.ebay.com/rover/0/0/0?mpre=https%3A%2F%2Fwww.ebay.com%2Fulk%2Fitm%2F202151474158
... Are you sure your SD module isn’t 5V tolerant? All mine step down 5V to ~3.3V.


text:
Where is the definition of system_adc_read() in the esp8266 Arduino code?
Where is the definition of uint16 system_adc_read(void) in the esp8266 Arduino code?
I can see it being declared in Arduino/tools/sdk/include/user_interface.h, however there seems to be no definition of this. system_adc_read() gets called in analogRead() in Arduino/cores/esp8266/core_esp8266_wiring_analog.c
I suspect system_adc_read() calls system_adc_read_fast() to read the ADC, but can't actually find it in the code! Could somebody please point me to this? I've been struggling for quite some time.
Purpose: To manipulate the system_adc_read() in ESP8266 to get higher ADC sampling rates. Right now ADC sampling rate is 10ksps. I want it to be more than 30-40ksps.

esp8266 sdk is not open source

Oh my god! Thanks for telling me this. So, what are my alternatives here? I've searched for ways to improve the sampling rate, but couldn't get to the desired (30-40 ksps) level.

try ESP8266 Non-OS SDK API Reference here http://espressif.com/en/support/download/overview?keys=&field_type_tid%5B%5D=14

The "definition" of uint16 system_adc_read(void) is inside the compiled archive/object file libmain.a inside one of the NONOSDK folders which is located in /tools/sdk/lib/ . The version is selected in platform.txt. For example in my platform.txt:
# default SDK for all boards
# (generic board overrides this variable)
build.sdk=NONOSDK22x_190703
#build.sdk=NONOSDK22x_191024
#build.sdk=NONOSDK22x_191105

Running the xtensa-lx106-elf-objdump.exe -d on this file I can find this section inside:
00000258 <system_adc_read>:
     258:   020c                    movi.n  a2, 0
     25a:   f0c112                  addi    a1, a1, -16
     25d:   0109                    s32i.n  a0, a1, 0
     25f:   fffc01                  l32r    a0, 250 <system_pp_recycle_rx_pkt+0x18>
     262:   0000c0                  callx0  a0
     265:   fff901                  l32r    a0, 24c <system_pp_recycle_rx_pkt+0x14>
     268:   f42020                  extui   a2, a2, 0, 16
     26b:   1b1207                  beq a2, a0, 28a <system_adc_read+0x32>
     26e:   b30c                    movi.n  a3, 11
     270:   902220                  addx2   a2, a2, a2
     273:   1122e0                  slli    a2, a2, 2
     276:   fff701                  l32r    a0, 254 <system_pp_recycle_rx_pkt+0x1c>
     279:   0000c0                  callx0  a0
     27c:   f42020                  extui   a2, a2, 0, 16
     27f:   00a402                  movi    a0, 0x400
     282:   013027                  bltu    a0, a2, 287 <system_adc_read+0x2f>
     285:   020d                    mov.n   a0, a2
     287:   f42000                  extui   a2, a0, 0, 16
     28a:   0108                    l32i.n  a0, a1, 0
     28c:   10c112                  addi    a1, a1, 16
     28f:   f00d                    ret.n
     291:   00                          .byte 00
     292:   00                          .byte 00
     293:   00                          .byte 00
     294:   ff ff 00 00
    ...

000002a0 <system_adc_read_fast>:
     2a0:   e0c112                  addi    a1, a1, -32
     2a3:   11c9                    s32i.n  a12, a1, 4
     2a5:   21d9                    s32i.n  a13, a1, 8
     2a7:   31e9                    s32i.n  a14, a1, 12
     2a9:   5129                    s32i.n  a2, a1, 20
     2ab:   41f9                    s32i.n  a15, a1, 16
     2ad:   0109                    s32i.n  a0, a1, 0
     2af:   03fd                    mov.n   a15, a3
     2b1:   fff901                  l32r    a0, 298 <system_adc_read+0x40>
     2b4:   0000c0                  callx0  a0
     2b7:   4fbc                    beqz.n  a15, 2ef <system_adc_read_fast+0x4f>
     2b9:   fff6e1                  l32r    a14, 294 <system_adc_read+0x3c>
     2bc:   0c0c                    movi.n  a12, 0
     2be:   51d8                    l32i.n  a13, a1, 20
     2c0:   90dcd0                  addx2   a13, a12, a13
     2c3:   001d32                  l16ui   a3, a13, 0
     2c6:   1a13e7                  beq a3, a14, 2e4 <system_adc_read_fast+0x44>
     2c9:   902330                  addx2   a2, a3, a3
     2cc:   1122e0                  slli    a2, a2, 2
     2cf:   b30c                    movi.n  a3, 11
     2d1:   fff201                  l32r    a0, 29c <system_adc_read+0x44>
     2d4:   0000c0                  callx0  a0
     2d7:   f44020                  extui   a4, a2, 0, 16
     2da:   00a402                  movi    a0, 0x400
     2dd:   003d                    mov.n   a3, a0
     2df:   013047                  bltu    a0, a4, 2e4 <system_adc_read_fast+0x44>
     2e2:   043d                    mov.n   a3, a4
     2e4:   005d32                  s16i    a3, a13, 0
     2e7:   cc1b                    addi.n  a12, a12, 1
     2e9:   f4c0c0                  extui   a12, a12, 0, 16
     2ec:   ce9fc7                  bne a15, a12, 2be <system_adc_read_fast+0x1e>
     2ef:   11c8                    l32i.n  a12, a1, 4
     2f1:   21d8                    l32i.n  a13, a1, 8
     2f3:   31e8                    l32i.n  a14, a1, 12
     2f5:   41f8                    l32i.n  a15, a1, 16
     2f7:   0108                    l32i.n  a0, a1, 0
     2f9:   20c112                  addi    a1, a1, 32
     2fc:   f00d                    ret.n
     2fe:   00                          .byte 00
     2ff:   00                          .byte 00
     300:   ff ff 00 00
    ...

Cool detective work. Thanks! I was able to achieve my use case using this: https://arduino.stackexchange.com/a/52854/25931

@loadingnow can anyone clarify whether system_adc_read returns 0-1023 or whether it returns 1-1024?

@S.Imp I am not sure, but you should ask a separate question to clarify. It would be much more helpful for others who have the same question.

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


text:
Uno r3 - Can't get USB Keyboards to work with an USB Host Shield
I'm a day 1 beginner to Arduino, and I am trying to obtain input from a USB keyboard. I've connected the USB keyboard to an Arduino USB host shield attached to an Arduino Uno r3, and I am using the example HID sketch (USBHIDBootKeyboard.ino) provided with the USB Host Shield libraries : https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino
I am powering the Arduino Uno r3 + USB Host Shield via USB. Upon init, only Start is written to the Serial Monitor. Tests show that SetReportParser exits with 0. Yet the keyboards are silent. I've tried three keyboards, all of which work properly when connected to the computer.
When using USBHidBootMouse.ino with a mouse, movements & buttons are perceived and print messages as intended.
https://www.circuitsathome.com/mcu/hid-support-for-usb-host-shield-library-2-0-released/ states that

Also, it is recommended to use external power supply while working with HID devices – I’ve seen many devices which would refuse to function when Arduino receives power from its USB port only.

EDIT : I tried to test if the power was the issue, so I used a 5V generator with intensity measurement. The results are : the Arduino Uno r3 uses 60mA, the keyboard uses 60 mA, connecting to the serial port uses 40 mA (much to my surprise).
This means the keyboard's power requirements shouldn't be the problem.
Then what would the problem be ? I'm helpless here. If the library linked on the official Arduino site doesn't work, then it should mean i'm using it wrong.

You should determine if this works when providing power.  If not, then it's more likely a software problem - keyboards and mice as similar, but different, and your keyboard code may not be correct.

You should probably also measure the voltage supplied to the USB peripheral, either at F2 on the board (hopefully a polyfuse not a one-time fuse), especially when loaded by a keyboard.  Or you could use one of those inline USB power meters assuming it is one which supports proper data passthrough.

@ChrisStratton It doesn't work when providing power. I've used a generator that supplied a 5V voltage while measuring the intensity : the arduino Uno itself uses 60mA, connecting it to the computer through serial uses 40mA (for a reason I don't understand), and connecting the keyboard uses 60mA. So it means the keyboard uses significantly less than 500mA, which means it's not the problem. So it - should - be a software problem ? But I'm only launching the library example sketch, so it not working is quite surprising. (EDITING OP IN PROGRESS)

see last paragraph of this page https://github.com/felis/USB_Host_Shield_2.0
it says this:

FAQ
When I plug my device into the USB connector nothing happens?
Try to connect a external power supply to the Arduino - this solves
  the problem in most cases.
You can also use a powered hub between the device and the USB Host
  Shield.
You should then include the USB hub library: #include <usbhub.h>
and create the instance like so: USBHub Hub1(&Usb);.

your keyboard may be multiple HID devices with a USB hub to connect them

A possibility, though less likely to be coincidentally true for the three keyboards reportedly tried, unless they are all the same and obviously all combo devices.

Thanks, I had missed this. As stated in my other answer, uncommenting the provided commented line "USBHub Hub(&Usb);" made it work for one keyboard, and I hastily thought it would work with others but didn't test it. The keyboard I tried is indeed a keyboard that accepts 2 other USB connections on its shell. The other 2 keyboards are simple keyboards, and the 3 are significantly different. I'm going to test these 2 with a hub instanciated and see if it makes them work.

I looked for the difference between USBHIDBootMouse & USBHIDBootKbd, and noticed line 100,

USBHub     Hub(&Usb);

was commented in the BootKbd side. Uncommenting it got the code to work.
I'm quite unsure how what interpretation to have from this. There should be a reason this line is commented in the library github.
Or maybe it is simply an error. In any case, uncommenting it got the code to work here.


text:
A function-definition is not allowed here before '{' token
I'm trying to light up 81 on a 4-digit 7-segment display, but when I try to upload the code to my Uno R3 it gives me this error: "a function-definition is not allowed here before '{' token". I'm new to Arduino and this is my second day using it, so I would like to get help and know how to fix this problem. Here is my code:
int isej1 = 2;
int isej2 = 3;
int vienetas[] = { 12, 11 };
int astuonetas[] = { 13, 12, 11, 10, 9, 8, 7 };

void setup() {
  pinMode (vienetas[2], OUTPUT);
  pinMode (astuonetas[8], OUTPUT);
  pinMode (isej1, OUTPUT);
  pinMode (isej2, OUTPUT);
}

void uz_vien() {
  digitalWrite (vienetas[0], HIGH);
  digitalWrite (vienetas[1], HIGH);
}

void uz_astuon() {
  digitalWrite (astuonetas[0], HIGH);
  digitalWrite (astuonetas[1], HIGH);
  digitalWrite (astuonetas[2], HIGH);
  digitalWrite (astuonetas[3], HIGH);
  digitalWrite (astuonetas[4], HIGH);
  digitalWrite (astuonetas[5], HIGH);
  digitalWrite (astuonetas[6], HIGH);
}

void is_vien() {
  digitalWrite (vienetas[0], LOW);
  digitalWrite (vienetas[1], LOW);
}

void is_astuon() {
  digitalWrite (astuonetas[0], LOW);
  digitalWrite (astuonetas[1], LOW);
  digitalWrite (astuonetas[2], LOW);
  digitalWrite (astuonetas[3], LOW);
  digitalWrite (astuonetas[4], LOW);
  digitalWrite (astuonetas[5], LOW);
  digitalWrite (astuonetas[6], LOW);

void loop() {
  digitalWrite (isej1, LOW);
  digitalWrite (isej2, HIGH);
  void uz_vien();
  delay(5);
  void is_vien();
  digitalWrite (isej1, HIGH);
  digitalWrite (isej2, LOW);
  void uz_astuon();
  delay(5);
  void is_astuon();
}

You are missing a "}" just before loop
  void is_astuon() {
    digitalWrite (astuonetas[0], LOW);
    digitalWrite (astuonetas[1], LOW);
    digitalWrite (astuonetas[2], LOW);
    digitalWrite (astuonetas[3], LOW);
    digitalWrite (astuonetas[4], LOW);
    digitalWrite (astuonetas[5], LOW);
    digitalWrite (astuonetas[6], LOW);
   } // <- missing here.
  void loop() {

The importance of proper indentation is clear here...
I thought you were missing a closing curly braces. When you type code, press regularly cmd/ctrl-T to ident your code -- it helps catching mistakes. You are indeed missing one, for is_astuon().
Moreover these lines are wrong too:
**void** uz_vien();
delay(5);
**void** is_vien();
digitalWrite (isej1, HIGH);
digitalWrite (isej2, LOW);
**void** uz_astuon();

The void part is not needed and creates the error.


text:
Is my HC-SR04 sensor broken?
I am extremely new to Arduino and electrical engineering, and the project I am attempting involves a ultrasonic sensor.  I am using the HC-SR04 with the Elegoo Mega2560 Arduino board.  A few days ago I was able to print out the distance correctly with an Arduino library, but after adding a h-bridge, 2 motors, and 2 9-volt batteries, the sensor didn't seem to work properly.  I went back to a simple circuit with only the HC-SR04, and the distance readouts were all over the place.  No matter what, the distance stayed between 90 and 120, mainly staying in the 110s.  These numbers seemed to have no correlation with the actual distance.  I even tried to calculate the distance myself in case there was something wrong with the library.
I have the VCC pin on the HC-SR04 connected to the 5v on the Arduino, the GND pin connected to the GND pin on the Arduino, the Trigger pin connected to pin 50 on the Arduino, and the Echo pin on the Arduino connected to pin 52 on the Arduino.  The Arduino is connected to my computer through USB.
Here is my sketch for printing out the distance without a library:
const int triggerPIN = 50;  //these are digital pins on the Arduino board
const int echoPIN = 52;     //I'm sure these pins aren't broken because I never used them before now

long duration;
int distance;

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

    pinMode (triggerPIN, OUTPUT);
    pinMode (echoPIN, INPUT);

    delay(1000);
}

int getDistance () {
    digitalWrite (triggerPIN, LOW);
    delayMicroseconds (2);

    digitalWrite (triggerPIN, HIGH);
    delayMicroseconds (10);
    digitalWrite (triggerPIN, LOW);

    duration = pulseIn (echoPIN, HIGH);
    distance = duration * 0.034 / 2;

    Serial.println (distance);
}

void loop() {
    getDistance ();  //I tried putting the code directly in the loop function with the same result
}

I am afraid that I broke either a part of the Arduino board or the sensor when I was fiddling around with the two batteries.  Is it possible to break a HCSR04 sensor by connecting two much voltage to the VCC pin on the sensor?  If so, how should I prevent this in the future?  I know that the working voltage for a HCSR04 is 5V, does this mean it needs at least 5V or no more than 5V?  I wanted to know for sure that it was broken and not an error on my part before I bought a new one.    Thanks in advance!

Unfortunately, it seems the HC-SR04 has no proper datasheet with maximum values. The only documents you can find define the operating voltage of 5V. I personally tested it with less than 5V (IIRC I could make it work at 4V and a bit less).

The code that you have provided for the distance calculation is fine according to me. There is a high chance that you might have damaged your HC-SR04, Ultrasonic sensor.
As you have asked about how to prevent this from happening in the future, I would suggest that you should use a voltage regulator in the circuit, LM7805, it restricts the output voltage to 5V - just matching your ultrasonic sensor's operating voltage as it works perfectly at 5 Volts.

Thank you so much Manav.  I bought a few more ultrasonic sensors and the sketch works perfectly. I will definitely look into a voltage regulator.

Amazing! Glad to be of help.

No.  Don't use a discrete 7805.  The Arduino already has a better regulator which is wired up properly, while adding another one is easy to get wrong.  And should the ground connection not be there, even for an instant, the regulator will pass the full input voltage.

I guess the main problem is a serial printing. It always bother the system mainly the analog reading. It's quiet good for check some sub result while you programing (what the return value from a method etc) but not good to test your project result. In this case the distance measurement. Try a different way, put some led into the circuit and if the distance over 10cm switch on first, if over 20 cm switch on the second and so on. Or write the result  on an lcd panel, or 8x8 led.

I will keep that in mind for future projects, an lcd panel seems like the way to go.

No, the problem is not serial printing.  But putting in a delay (or non-blocking timer check before taking a new measurement) to allow any old echoes to die out would not be a bad idea.

A major functional difference between the code in your question and the usual ping sensor example is that your code repetitively measures as fast as it or the output stream will allow.
In contrast, the normal example has a delay(100) after each measurement cycle.  This allows 1/10th of a second time for any longer room echoes to die out, and thus avoid confusing new measurements.
While that might not be your immediate or only problem, it is generally a good idea not to try to take sonar measurements so closely spaced in time that they could overlap.
Should your sketch also need to do other things, instead of a blocking delay() you can check the elapsed time and only take a new sonar measurement once a certain amount of time has passed; in the meantime your program can continue with any other critical operations.


text:
Arduino Uno versus Arduino Nano power consumption
I have both an Arduino Uno and an Arduino Nano but I can't decide which one to use for my project. My aim is to maximize battery lifetime. I have also implemented an 8-second watchdog timer to periodically sleep and wake up the ATMega328P.

Option 1: Arduino Uno R3 + DHT11 sensor: The board is powered on by 4 * 1.25V (2700 mAh) Nickel Metal Hydride batteries and the 3.3V output voltage of the Arduino is supplied to VCC of DHT11. (Arduino Uno specification DC Current per I/O Pin 40 mA, DC Current for 3.3V Pin 50 mA).
Option 2: Arduino Nano + DHT11 sensor. The board is powered on by 4 * 1.25V (2700 mAh) Nickel Metal Hydride batteries and the 3.3V output voltage of the Arduino is supplied to VCC of DHT11. (Arduino Nano specification: DC Current per I/O Pin: 40 mA but NO information for DC current for 3.3V or 5V).

I would like to know which one will be more power-efficient.

DHT11 can work from 5V. Why did you choose 3.3V?

DHT11 works for both. What difference it makes if 5V is used?

Voltage regulator at 3.3 volts dissipates part of the energy. What battery lifetime do you have? What do you want to achieve?

Both these boards draw a lot of extra current due to LEDs, regulators, etc. An alternative solution is to simply turn the board on/off: https://electronics.stackexchange.com/questions/266716/power-off-arduino-via-software

I am currently using Arduino Uno and running overnight successfully. With 2700 mAh batteries, I expect will last more than 3 days but I found in many forums sleeping only ATmega328p with watchdog timer of 8s  will not  save much power. How much do you think battery life time will be? So let's say I power using only battery and deploy in a place where NO power mains is available, it is going to last only 3 to 4 days?? This is a MAJOR issue I am facing.

Please add  code and wiring diagram.

Related: Are there good batteries to power on Arduino? by same person.

A Uno which isn't doing anything useful except being turned on will use about 50 mA of current from the power jack at 9V.
If you use 3 x alkaline AA batteries (giving a nominal voltage of 4.5V) directly into the 5V pin of the Arduino then you might get 2500 mAh which would be 50 hours at 50 mA per hour.
You can save a considerable amount of power by using sleep modes as I describe on my page about power. It also helps to use a bare processor (no voltage regulator, no LEDs).
I made a temperature and humidity sensor which runs from 3 x AA batteries. Using sleep mode, plus various other techniques, that is running for over a year without needing new batteries.

I would like to know which one will be power efficient?

Both the Uno and the Nano use the same Atmega328P processor. Thus the technical considerations would be the same. Both have a voltage regulator and a "power on" LED which alone would use a lot of current, compared to everything else.

It's not that hard to make a minimal board. I have a page about doing that. Example of all you need:

If you use a deep sleep mode, combined with using the watchdog timer to wake every 8 seconds (and check the time, say every 10 times it wakes) you can reduce power consumption right down.
My temperature sensor uses an average of 42 µA which is a lot less than 50 mA. (A thousand times less). Thus your 50 hours run time becomes 50,000 hours which is 2083 days. Your batteries will probably self-discharge sooner. :)

Thank you for your detailed answer. Just a quick question: how do we supply 3.3 v or 5 v to temperature sensor because we will remove the voltage regulator from the chip? Can we use ftdi adapter which gives 3.3v or 5v output?

In that case will FTDI adapter too NOT consume current?

Well, if you are powering the processor you can power the temperature sensor, can't you? Did you read my page about my temperature sensor?

Yes. I read it. It seems you are powering the processor and temperature sensor sensor with FTDI? Correct me if I am wrong. My question is: does FTDI not pull the current from battery like voltage regulator of other arduino boards do?I agree we can get rid of led power consumption.

No, I am powering them from a battery. The FTDI connection is just for reprogramming it.

You are powering from 3.3 V regulated  battery?

You said you read my article about the sensor. The schematic is there. It is powered by 3 x 1.5V Alkaline batteries. There is no voltage regulator. It is marked as 5V on the top left-hand corner of the schematic, but would actually be closer to 4.5V (which is what 3 x 1.5 is). It is quite acceptable to run the processor at 4.5V. If you run at 8 MHz, as I did, then 3V (1V each from 3 batteries) is still OK, as might be expected towards the end of the battery life.

If needed the power LED can just be unsoldered right?

From the Uno board? Yes, but the voltage regulator still takes some power to run.

Don't use either use something with no USB, regulator - e.g. Pro Mini (run from 3.3V)
Just running the Arduino (or indeed most digital circuitry) from a lower voltage will already reduce power consumption - admittedly at a slight cost in processor speed. The Atmega328P will run at 12MHz on 3.3V, although the Pro Mini uses the more conservative 8MHz.

I thought of using pro mini but I found that I have to work on making circuit as pro mini is not much user friendly (in terms of loading code etc) than Arduino nano and uno. Also pro mini does not give output voltage 3.3V or 5V which can be supplied to DHT11 vcc pin easily. So

I found more work to be done from HW side. I am not good at HW making as my background is programming only.

Can we supply Vcc of pro mini to DHT11 vcc?

yes, run it all from 3.3v, using a dc-dc buck (smps) to get 3.3v instead of an LDO

@JyotiRajSharma You miss my point - run the Pro Mini from 3.3V, and use the same source to run your peripherals, avoiding any lossy linear regulators. It really isn't that hard to use a USB-serial dongle to program (which is done when connected to computer) rather than a power hogging on-board converter you aren't using.


text:
Why is my servo spinning over 360 degrees?
I decided to try out my servo on my Arduino. I'm pretty new to this and I can't seem to figure out why this is happening. My servo will spin for about 5 seconds in one direction and then it will spin the opposite way for less than a second and pause for about 3 seconds. This is the code I uploaded to my Arduino:
# include <Servo.h>
const int servopin = 8;
Servo servo;

void setup() {
  Serial.begin(9600);
  servo.attach(servopin);
  servo.write(0);
}

void loop() {
  servo.write(0);
  delay(5000);
  servo.write(180);
  delay(5000);
}

I believe the servo is a Tower Pro Micro Servo 99 (either 9 might be a g) SG90.

An RC hobby type servo which rotates more than a full rotation is either a continuous rotation or possibly "sail winch" model, not an ordinary one.  Continuous rotation servos are typically made from ordinary servo chassis with the feedback potentiometer and associated stop removed, so they may be hard to visually distinguish by anything but model number and behavior.

pause for about 3 seconds ... and then what?

you only tried 0 and 180 ?  no experimenting of any kind??

How long does it take to spin 180º?

I might want to try decreasing the range, e.g. start from 10 instead of 0, or finish at 170 instead of 180. Here is an example:
# include <Servo.h>
const int servopin = 8;
Servo servo;

void setup() {
  Serial.begin(9600);
  servo.attach(servopin);
  servo.write(0);
}

void loop() {
  servo.write(10);
  delay(5000);
  servo.write(170);
  delay(5000);
}

After checking it works, try experimenting with different ranges to see how your servo reacts.
For me starting at 7 instead of 0 did the job.

When I am getting started with my Servo motor SG90, I have experience the same issue, and finally I have solved the issue. I have used external power supply for Servo and my Arduino with laptop USB port and control signal from Arduino to Servo motor make my Servo motor to spinning continuously.
Make sure ground reference of power supply of Servo motor and Arduino are same.


text:
Getting error ets jan 8 2013,rst cause:4,boot mode(1,6) wdt reset
I'm working on a project to send ultrasonic sensor data to my webserver. For that I'm using ESP8266  WiFi module, 3.3V regulator IC by giving input volt of 5v from aduino uno.
I successfully uploaded a code but in serial monitor I got an error
ets jan 8 2013,rst cause:4,boot mode(1,6) wdt reset.

Please, tell what does it mean?
Here is my code. Guide me if I made something wrong. Thanks in  advance.
Note:
Before sending sensor values I successfully send a raw data  manually to webserver, i.e string data, but when I try to send sensor values, I got an error.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "VENTURE 11";
const char* pass = "12345678";

WiFiClient clientx;
const int trigPin = 8;  //Digital port D5
const int echoPin = 9;  //Digital port D6

long duration;
float distance;
float Mdistance;
float MAX_HEIGHT = 0;

void setup() {

  Serial.begin(115200);                                  //Serial connection
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT);

  WiFi.begin("VENTURE 11", "12345678");   //WiFi connection
  Serial.println("Setup iniated");
  while (WiFi.status() != 3) {  //Wait for the WiFI connection completion
    delay(500);
    Serial.println("Waiting for connection");
    Serial.print("WIFI STATUS : ");
    Serial.println(String(WiFi.status()));
  }
  Serial.println(String(WiFi.status()));
}

void loop() {
  Serial.println(String(WiFi.status()));
  if (WiFi.status() != 3)
  {
    WiFi.begin("VENTURE", "12345678");   //WiFi connection
    while (WiFi.status() != 3)
    {
      Serial.println("Waiting for connection");
    }
  }
  else
  {
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);

    // Sets the trigPin on HIGH state for 10 micro seconds
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);

    // Reads the echoPin, returns the sound wave travel time in microseconds
    duration = pulseIn(echoPin, HIGH);

    // Calculating the distance
    distance = (duration * 0.034) / 2;

    if (MAX_HEIGHT == 0) {
      //MAX_HEIGHT = distance;
      Serial.print("Max height has been set to ");
      //Serial.print(distance);
      Serial.println(" cm");
      Serial.println("Waiting for 5 seconds...");
      delay(5000);
    } else {
      Serial.print("Distance:\n");
      Serial.print(distance);
      Serial.print("cm\n");
      Serial.print("Distance:\n");
      Serial.print(distance / 100);
      Serial.print("m\n");
      delay(1000);

    }

    HTTPClient http;
    String Data = "x=" + (String)distance + "&y=" + (String)MAX_HEIGHT + "&z=0";
    //String Data = "x=Finally&y=Did&z=it;)";
    http.begin("http://testingblahblah.000webhostapp.com/IOTCON.php");
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    int sent = http.POST(Data);
    Serial.println(sent);
    String httpPayload = http.getString();
    Serial.println(httpPayload);
    if (sent > 0)
    {
      Serial.println("Message has been sent");
    } else {
      Serial.println("unable to send data");
    }
    delay(20000);

  }
}`

Do you see the serial prints on your serial monitor? where do they stop?

also in String Data, you should type String(distance) and String(MAX_HEIGHT) (paranthesis around the argument not the func)

Please check SSID name of the WiFi in the code.

port D6 doesn't exist on most of esp8266 board, change it to another pin

@Erez.Electronic.can, D6 is a label and constant on NodeMcu and Wemos boards and is mapped to io 12. but you are right about wrong pin. io 6 to io 10 are used for communication with the flash memory

Found a possible solution.
I was facing with the same problem.
Apparently this is a hardware stack overflow watch dog preventing malfunction. This may not apply to every possible scenario but I discovered that the allocated pin number on the board itself is incorrect.
What is numbered 03 is in fact D15 for example. So assigning the pin to D15 worked but 3 created this error.
I hope this helps others.

Your loop():
void loop() {
  Serial.println(String(WiFi.status()));
  if (WiFi.status() != 3)
  {
    WiFi.begin("VENTURE", "12345678");   //WiFi connection
    while (WiFi.status() != 3)
    {
      Serial.println("Waiting for connection");
    }
  }
  else
  {
    // Other code...
  }
}

While waiting for the connection, you are creating String objects at a very high rate, since your delay(20000) is in the else clause.
This means you are possibly running out of memory, as you are creating the String objects with every iteration, which is in the Megahertz range.
You likely don't need the String(...) wrappers, as the Serial.println() function can work with C-style strings returned by the WiFi library. Then, your program won't be allocating memory to hold the result of WiFi.status() millions of times per second, which you don't use later on in your program.

the answer is not valid anymore. begin with const char* parameters exists. but this answer was never the right answer