text:
How to read my three-button inputs?
I am creating a three-person reaction time game but I would like to be able to read all three buttons' proximity to the start time - currently only the winner is displayed on the serial read.
Here is my code:
int ledPin = 12;
int buttonPin1 = 7;
int buttonPin2 = 6;
int buttonPin3 = 5;

void setup() {
  Serial.begin(9600);
  Serial.println("Setup start");
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  pinMode(buttonPin3, INPUT_PULLUP);
  randomSeed(analogRead(A0));
  Serial.println("Setup complete");
}

void loop() {
  Serial.println("Game start");
  digitalWrite(ledPin, HIGH);
  delay(2000);
  delay(random(1000, 3000));
  digitalWrite(ledPin, LOW);
  Serial.println("LED off, waiting for button press");

  unsigned long start_time = millis();
  int winner = 0;

  while (winner == 0) {
    winner = check_buttons();
  }

  unsigned long end_time = millis();
  unsigned long total_time = end_time - start_time;

  Serial.print("Player ");
  Serial.print(winner);
  Serial.println(" wins!");
  Serial.print("It took ");
  Serial.print(total_time);
  Serial.println(" ms to press the button.");

  delay(5000);
}

int check_buttons() {
  int player1 = digitalRead(buttonPin1);
  int player2 = digitalRead(buttonPin2);
  int player3 = digitalRead(buttonPin3);

  if (player1 == LOW) {
    return 1;
  } else if  (player2 == LOW) {
    return 2;
  } else if (player3 == LOW) {
    return 3;
  } else {
    return 0;
  }
}

while (second == 0) ...?

you cannot display data that does not exist ... you have to determine the timestamp when each button has been pressed, and you have to wait until all the buttons have been pressed before displaying the result

“i would like to be able to read all three buttons proximity to zero”: What does that mean?

What if all three players don't press their buttons? On a quiz show people often give up if someone else has pressed the button first.

You will need an end_time variable for each of the players, either as a distinct variable for each player, or use an array. Define as a global:
unsigned long end_time_player1;
unsigned long end_time_player2;
unsigned long end_time_player3;

or
unsigned long end_time_player[3];

Then in check_buttons() you will need to record the respective end_time, like so
  if (player1 == LOW) {
    end_time_player[0] = millis();
    //end_time_player1 = millis();
    return 1;
  } else if  (player2 == LOW) {
    end_time_player[1] = millis();
    //end_time_player2 = millis();
    return 2;
  }else if (player3 == LOW) {
    end_time_player[2] = millis();
    //end_time_player3 = millis();
    return 3;
  } else {
    return 0;
  }

Obviously, if using an array, then the index of the array is one less than the player number.

An array is probably more elegant and expandable, so for four players:
const int kNumPlayers=4
unsigned long end_time_player[kNumPlayers];

If using arrays (for both the times and the buttons (as well as the players)), you could also turn the series of if statements into a for loop using kNumPlayers:
int buttonPin[kNumPlayers] = {7, 6, 5};

...

int check_buttons() {
  int player[kNumPlayers];

  for (n=0; n < kNumPLayers; n++) {
     player[0] = digitalRead(buttonPin[n]);
     if (player[0] == LOW) {
        end_time_player[n] = millis();
        return n+1;
     } else {
        return 0;
     }
  }
}

or, more simply, just dispense with the player local variable altogether
int buttonPin[kNumPlayers] = {7, 6, 5};

...

int check_buttons() {
  for (n=0; n < kNumPlayers; n++) {
     if (digitalRead(buttonPin[n]) == LOW) {
        end_time_player[n] = millis();
        return n+1;
     } else {
        return 0;
     }
  }
}

Then you will need to change the code in loop() to display the time for each user. I'll let you work that bit out yourself.

Yes, but what if the third player doesn't press the button? Or the second?

Then the display in loop() won''t show a value for that player, or display "n/a". The  while loop would no longer have to wait for just one winner, but rather wait for a time out (of say, one second, maybe two). If a player hasn't hit a button within that time frame, then it can be safely assumed that they have died of boredom..! :-)  Yes, I must admit that there are some necessary logic changes required in loop() that I had overlooked... although, in fairness, I did leave that for the OP to figure out, as the question seemed to focus on the reading and not the displaying.


text:
Concave button wiring with Arduino
I am new to working with Arduino and I have a basic question.
I have an entire circuit set up and functioning, but I would like to add an arcade style button (Larger concave style) like this.
So my question is, how would I go about wiring this button to the Arduino? I don't need this button to control any lights or any other functions. The basic function of this button is for my code to register if the button is pressed or not. I also have the code done. I just want to know how to wire this.
Also I don't know if this helps, but I already have two normal tactile buttons (with 4 pins) in the circuit connected with a pull-up resistor and I know how to connect them. I just have no idea how to go about with only 2 pins.
Any help would be greatly appreciated. Thanks.

A simple switch, frequently called single pole single throw, will have only two pins. A switch works by breaking the circuit. This is shown in a wiring diagram in this manner:

It matters not that the switch in this image is not the same switch as in the image you linked, the operation is identical. You may find momentary switches with similar appearance and identical diagrams. The difference is that one has to hold the button to make (or break) a circuit, which reverts once released.
You mention four pins. Those switches are electrically identical to the SPST switch, except that you may find you can control two independent circuits that both activate when the button is pressed. That would be a double pole single throw. There is also the possibility that the four-pin switch has common connections on each side. That is to say that if you connect your circuit to one pin, it is conductive to the other on on the same side, while the closure of the switch will also equally effect the two pins on the opposite side. I've found some tiny switches that have this arrangement, ostensibly to provide for four points to solder to the circuit board, making for a more sturdy attachment.
One can find some useful switch information on Electronics Hub, which is too exhaustive to cover here.
There are many other types of switches

source: Stack Exchange

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

sort: votes


text:
Is my Arduino skipping a statement?
So, I made this code (I'm rather new to this). The only thing that the Arduino should do, is when I press the button on pin 2, turn on the LED on pin 4 and emulate CTRL + R on the keyboard for the computer. Then, if the LED is on and I hit the button again, turn it off and hit the spacebar on my computer. But as soon as I hit the button for the first time, it does indeed press CTRL + R and the LED turns on, but after the delay, it immediately skips checking if I am pressing the button and assumes that I am pressing the button. Thereby it only sees that the LED is on and it turns it off while hitting the spacebar. Any suggestions?

#include <Keyboard.h>

int buttonPin = 2;
int ledPin    = 4;
int val = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  val = digitalRead(buttonPin);
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if ((val == LOW) && (digitalRead(ledPin) == LOW)) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press('r');
    delay(100);
    Keyboard.release(KEY_LEFT_CTRL);
    Keyboard.release('r');
    delay(500);
  }
  if ((val == LOW) && (digitalRead(ledPin) == HIGH)) {
    digitalWrite(ledPin, LOW);
    Keyboard.write(32);
  }
  if ((val == HIGH) && (digitalRead(ledPin) == LOW)) {
    digitalWrite(ledPin, LOW);
  }
  if ((val == HIGH) && (digitalRead(ledPin) == HIGH)) {
    digitalWrite(ledPin, HIGH);
  }
}

think about what is the sequence of button states when you press the button twice ... are you checking for all of the states?

You declared ledPin as output, then in the loop you check its status with digitalRead(ledPin). This is not going to work as you intend doing. How is a pin meant to source current, read its own voltage? For that purpose you need a flag representing its state, not the electric state.

Try something like this.
The code does not use button states in its decision making.
Instead, it looks for the transition between button states, so holding the button does not generate events.
void loop() {

  val = digitalRead(buttonPin);

  if (val != oldButtonState) {      // button state transition
    oldButtonState = val;
    if (val == LOW) {               // transition from "released" to "pressed"
      buttonClicked = true;         // set click flag
    }
  }

  if ( buttonClicked ) {

    buttonClicked = false;                // clear click flag

    if (digitalRead(ledPin) == LOW) {
      digitalWrite(ledPin, HIGH);         // turn LED on
      Keyboard.press(KEY_LEFT_CTRL);      // send CTRL-R
      Keyboard.press('r');
      delay(100);
      Keyboard.release(KEY_LEFT_CTRL);
      Keyboard.release('r');
      delay(500);
    }

    else {
      digitalWrite(ledPin, LOW);          // turn LED off
      Keyboard.write(32);                 // send space
    }
  }
}

Your code isn't checking for a button.  It's checking the value in val.  That only gets updated once per loop.  Let's say the code enters the first if statement because the val is LOW and the LED is also LOW.  This sets the LED to HIGH.  Now the next if statement, val is still LOW and now LED is HIGH so that one is true as well.
I think what you want is to use "else if" so it will skip the rest once it finds a true one.
void loop() {
  val = digitalRead(buttonPin);
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if ((val == LOW) && (digitalRead(ledPin) == LOW)) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press('r');
    delay(100);
    Keyboard.release(KEY_LEFT_CTRL);
    Keyboard.release('r');
    delay(500);
  }
  else if ((val == LOW) && (digitalRead(ledPin) == HIGH)) {
    digitalWrite(ledPin, LOW);
    Keyboard.write(32);
  }
  else if ((val == HIGH) && (digitalRead(ledPin) == LOW)) {
    digitalWrite(ledPin, LOW);
  }
  else if ((val == HIGH) && (digitalRead(ledPin) == HIGH)) {
    digitalWrite(ledPin, HIGH);
  }
}

Hmm, if I try this, the LED does stay solid after the first press and it doesn't hit my spacebar yet. But when I hit the button a second time, it performes both CTRL + R and the spacebar and the LED stays solid. I think we're on the right trace but there's still some problems.

Well there's no delay or anything after the action in that second if statement like there is on the first one.  My bet is that the loop comes back around and sees that the button is still pressed and catches the first if again.  Look at the State Change Example in the IDE for some inspiration on how to respond to the change in state of the button and not just the fact that it is held down.  Detect the edges.  Only react once per press.

You got me on the right track. I now used press counts. After it its CTRL + R it sets the button press count to 2, and if the value becomes 3 (ie hitting the button a 2nd actual time) it hits space bar, turns off the LED and sets the press count back to 0. Works fllawlessly. THANK U very much!

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


text:
Get data from a running exe on my pc
I have made a button with an LED using an arduino micro. It's connected to my pc and when I hit the button, the LED activates and a recording on Reaper (digital audio workstation) is started. When I hit the button again, the LED turns off and the recording stops and is saved.
I want the LED to flash at the BPM rate of the project in Reaper. So it needs to read the amount of Beats per minute the project is set to.
Is there any way the arduino can read this value?
Without the flashing LED, the program works fine. Here's the code:
#include <Keyboard.h>

boolean toggle = false;
int inPin = 2;
int outPin = 3;

int state = HIGH;
int ledOn;
int reading;
int previous = LOW;

long time = 0;
long debounce = 200;

void setup() {
  // make pin 2 an input and turn on the
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(inPin, INPUT_PULLUP);
  pinMode(outPin, OUTPUT);
  Keyboard.begin();
}

void loop()
{
  reading = digitalRead(inPin);
  ledOn = digitalRead(outPin);

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  if ((reading == LOW) and (ledOn == LOW)) {
    state = HIGH;
    Keyboard.press((char) 128);
    Keyboard.press('r');
    delay(50);
    Keyboard.releaseAll();
    delay(300);
  }

  if ((reading == LOW) and (ledOn == HIGH)) {
    state = LOW;
    Keyboard.press((char) 32);
    delay(10);
    Keyboard.releaseAll();
    delay(100);
    Keyboard.press((char) 177);
    delay(10);
    Keyboard.releaseAll();
    delay(300);

    time = millis();
  }

  digitalWrite(outPin, state);

  previous = reading;
}

Never used this program, but apparently it has an API: http://www.reaper.fm/sdk/reascript/reascripthelp.html. If the program does not "publish" the BPM anywhere else where you could read with another software and send to the Arduino via Serial, you may need to write something to talk to the Reaper API and see if you can get it, after, just need to write some other code to send this value to the Arduino via the Serial Port (that's easy to find examples).

I just took a look at the website you provided me. I have been looking through all the variables you can use with Reaper and it seems that for C++ there is: bool GetTempoTimeSigMarker(ReaProject* proj);

There also seems to be: bool GetTempoTimeSigMarker(double* bpmOut)
I'm not sure if the ReaProject* proj means that it takes the tempo of the whole project or if double* bpmOut does that.

Great, now you need to write a software to call this function and "print" to screen. Next is to plug in a Serial library so you can send it to the Arduino while Arduino keep waiting for messages.

I'm kind of a beginner to the Arduino world as I got my first one 3 days ago (which was a fake arduino nano). I didn't do my research on what you could do with it and because of the ATMEGA328 it couldn't control my keyboard. I also poured a drop of solder on the crystal which was destroyed. I now have the (also fake) arduino pro micro. Great little thing.
I don't know however, how to get my code to communicate with reaper.

@Hendriks3D, if you have a hot-air part remover, or if the crystals are thru-hole, you could move the crystal from the fake to the one that needs a crystal.  Note that when ATmega328 fuses are set to use a crystal, you can't use it without a crystal without changing the fuse settings.

well, the one that's broken has a broken crystal. I'm not sure if it works, but when I ordered the arduino micro, I also ordered another 16mhz crystal. Its a big one. The one that was originally on the nano is very small. I hope I can use the big one as a replacement. I could use my nano for other thins.

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


text:
Why is D3 not activating?
So I made this circuit + a momentary push button on D2 and GND:
Because I don't use a real arduino, I use the RAW port to act like the +5V port. It all worked with a single LED without the npn transistor. Now, with the transistor, the strip of LED's doesn't turn off anymore when I hit the button. The code:
 #include <SoftwareSerial.h>

  #include <Keyboard.h>

  boolean toggle = false;
  int inPin = 2;
  int outPin = 3;

  int state = HIGH;
  int ledOn;
  int reading;
  int previous = LOW;

  long time = 0;
  long debounce = 200;

  void setup() {
    // make pin 2 an input and turn on the
    // pullup resistor so it goes high unless
    // connected to ground:
    pinMode(inPin, INPUT_PULLUP);
    pinMode(outPin, OUTPUT);
    Keyboard.begin();
  }

  void loop()
  {
    reading = digitalRead(inPin);
    ledOn = digitalRead(outPin);

    // if the input just went from LOW and HIGH and we've waited long enough
    // to ignore any noise on the circuit, toggle the output pin and remember
    // the time
    if ((reading == LOW) and (ledOn == LOW)) {
      state = HIGH;
      Keyboard.press((char) 128);
      Keyboard.press('r');
      delay(50);
      Keyboard.releaseAll();
      delay(200);
    }

    if ((reading == LOW) and (ledOn == HIGH)) {
      state = LOW;
      Keyboard.press((char) 32);
      delay(10);
      Keyboard.releaseAll();
      delay(100);
      Keyboard.press((char) 177);
      delay(10);
      Keyboard.releaseAll();
      delay(200);

      time = millis();
    }

    digitalWrite(outPin, state);

    previous = reading;
  }

Put a resistor in between the D3 output  and the base of the transistor, say 500ohms, and try it again. If it works, I'll post a proper answer explaining why.

Could you just explain it in an answer so I can mark it as solved?

Looks like Eric has beaten me to it with his answer, which is more thorough than mine, but I'll explain why the base resistor works anyway.
Your code relies on reading the level of a pin set to output.  It will only switch off the output if that output is already reading "high".
If you don't have a resistor on the base, then a pretty high current will flow from base to emitter.  This will pull the level of the output down below the threshold for "high", even if it's being driven.  (It also might blow the output, but I guess you have been lucky.)
It's unusual, even if perhaps not "wrong", to read the value of an output.  I'd use a global or static variable to hold the on/off state, rather than reading it.

You need to adjust the value of Rc, the collector current limiting resistor. When replacing the single LED with a strip of N LEDs of the same kind, you have increased N times the current required (that's why you need to use a BJT, because the Arduino I/O pins won't supply that much current). So, you need a new value for that resistor, let's call it Rc', much lower: Rc' = Rc/N. Otherwise, the old value may limit the current far below of what the LEDs need to light up.
But that's not all. You also need to add 2 resistors:

Rb: a current limiting resistor between D3 and the BJT base. Its value should be in the range 330 - 2200 Ohm. The higher the current draw of the LED strip, the lower the value of Rb should be.
Rpd: a pull-down resistor between the BJT base and ground to avoid it floating while D3 is not initialised as OUTPUT. Make it at least 20x the value of Rb.

All this should be enough to make it work.


text:
Arduino HTTP post image to external server
I'm trying to send an image from SPIFFS to my external server. When pictures are taken, they are saved into "/pics/" directory within SPIFFS. Ultimately, I'd like to post all the images saved onto "/pics/x.jpg" (x is the a number in increasing order - 7.jpg, 8.jpg, 9.jpg, etc...) to my external server as they come in. Currently, I can access all the images within the internal esp server. Right now, I'm trying to send a single image, "6.jpg" from "/pics/" to my external server. Unfortunately, I'm not seeing anything on the external server side. The http post code occurs in "void setup()".
The complete Arduino code is below:

// Program header files
#include <Wire.h>
#include <WiFi.h>
#include <WebServer.h>
#include <ArduCAM.h>
#include <SPI.h>
#include "FS.h"
#include "SPIFFS.h"
#include "memorysaver.h"

#define AP_SSID "apssid"
#define AP_PASSWORD "password"

#define WIFI_SSID "wifissid"
#define WIFI_PASSWORD "password"

#if !(defined (OV2640_MINI_2MP)||defined (OV5640_MINI_5MP_PLUS) || defined (OV5642_MINI_5MP_PLUS) \
    || defined (OV5642_MINI_5MP) || defined (OV5642_MINI_5MP_BIT_ROTATION_FIXED) \
    ||(defined (ARDUCAM_SHIELD_V2) && (defined (OV2640_CAM) || defined (OV5640_CAM) || defined (OV5642_CAM))))
#error Please select the hardware platform and camera module in the ../libraries/ArduCAM/memorysaver.h file
#endif

const int ArduCAM_Power = 32; // Controls power for ArduCAM

const int CS = 5; // GPIO5 as Slave Select for ArduCAM
int wifiType = 0; // 0: Station    1: AP

static const size_t bufferSize = 2048;
static uint8_t buffer[bufferSize] = {0xFF};
static const int fileSpaceOffset = 700000;

byte buf[256];
static int i = 0;
static int k = 0;
uint8_t temp = 0, temp_last = 0;
uint32_t len = 0;
bool is_header = false;

const String fName = "/res.txt"; // Whatever last resolution that was submitted, will be stored in the file
                                // If power goes out, it will use the last setting stored onto that file
int fileTotalKB = 0;
int fileUsedKB = 0;
int fileCount = 0;
String errMsg = "";
int imgMode = 1; // 0: stream    1: capture
int resolution = 3;
// resolutions:
// 0 = 160x120
// 1 = 176x144
// 2 = 320x240
// 3 = 352x288
// 4 = 640x480
// 5 = 800x600
// 6 = 1024x768
// 7 = 1280x1024
// 8 = 1600x1200

WiFiClient client;

WebServer server(80);

#if defined (OV2640_MINI_2MP) || defined (OV2640_CAM)
ArduCAM myCAM(OV2640, CS);
#endif

void start_capture()
{
  myCAM.clear_fifo_flag();
  myCAM.start_capture();
}

// Updates properties file with resolution
void updateDataFile()
{

  File f = SPIFFS.open(fName, FILE_WRITE);
  if(!f)
  {
    Serial.println("Property file failed to open");
  }
  else
  {
    Serial.println("========= Writing to Property file =========");

    f.println(resolution);
    Serial.println("Data file updated");
    f.close();
  }

}

void myCAMsaveToSPIFFS()
{
  // Reserves space when memory is full
  if((fileTotalKB - fileUsedKB) < fileSpaceOffset)
  {
    String maxStr = "========= Maximum Data Storage Reached =========";
    Serial.println(maxStr);
    errMsg = maxStr;
    return;
  }

  String str;

  // Flush the FIFO
  myCAM.flush_fifo();
  // Clear capture done flag
  myCAM.clear_fifo_flag();
  // Start capture
  myCAM.start_capture();

  Serial.println("Start capture.");
  while(!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK));
  Serial.println("Capture done!");

  // Increase file count since a capture was done
  fileCount++;

  len = myCAM.read_fifo_length();
  Serial.print("The FIFO length is: ");
  Serial.println(len, DEC);

  if(len >= MAX_FIFO_SIZE) // 8M
  {
    Serial.println("Over size!");
  }
  if(len == 0) // 0 KB
  {
    Serial.println("Size is 0 KB.");
  }

  str = "/pics/" + String(fileCount) + ".jpg";

  File f = SPIFFS.open(str, FILE_WRITE);
  if(!f)
  {
    Serial.println("Property file failed to open");
  }
  else
  {
    Serial.println(str);
  }

  i = 0;
  myCAM.CS_LOW();
  myCAM.set_fifo_burst();
  while (len--)
  {
    temp_last = temp;
    temp =  SPI.transfer(0x00);
    //Read JPEG data from FIFO
    if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while,
    {
      buf[i++] = temp;  //save the last  0XD9
      //Write the remain bytes in the buffer
      myCAM.CS_HIGH();
      f.write(buf, i);
      //Close the file
      f.close();
      Serial.println("CAM Save done!");
      is_header = false;
      i = 0;
    }
    if (is_header == true)
    {
      //Write image data to buffer if not full
      if (i < 256)
        buf[i++] = temp;
      else
      {
        //Write 256 bytes image data to file
        myCAM.CS_HIGH();
        f.write(buf, 256);
        i = 0;
        buf[i++] = temp;
        myCAM.CS_LOW();
        myCAM.set_fifo_burst();
      }
    }
    else if ((temp == 0xD8) & (temp_last == 0xFF))
    {
      is_header = true;
      buf[i++] = temp_last;
      buf[i++] = temp;
    }
  }

}

//////////////////////////////////////////////////////////////////////////////////////////////////
//    Retrieves a stored jpg file and sends to browser based on url: http://IPaddress/1.jpg     //
//////////////////////////////////////////////////////////////////////////////////////////////////
bool loadFromSPIFFS(String path)
{
  String dataType = "text/plain";
  if(path.endsWith("/"))
  {
    path += "index.htm";
  }

  if(path.endsWith(".src"))
  {
    path = path.substring(0, path.lastIndexOf("."));
  }
  else if(path.endsWith(".jpg"))
  {
    dataType = "image/jpeg";
  }

  File dataFile = SPIFFS.open(path.c_str(), FILE_READ);
  if(server.hasArg("download"))
  {
    dataType = "application/octect-stream";
  }

  if(server.streamFile(dataFile, dataType) != dataFile.size())
  {

  }

  dataFile.close();
  return true;
}

/////////////////////////////////////////////////////////////
//  sets the HTML used for the resoultions drop down       //
/////////////////////////////////////////////////////////////
String getDropDown()
{
  String webString = "";
  webString += "<select name=\"rez\">\n";
  webString += "   <option value\"0\"  ";

  if (resolution == 0)
    webString += " selected=\"seleted\" ";
  webString += ">160x120</option>\n";

  webString += "   <option value=\"1\" ";
  if (resolution == 1)
    webString += " selected=\"seleted\" ";
  webString += ">176x144</option>\n";

  webString += "   <option value=\"2\" ";
  if (resolution == 2)
    webString += " selected=\"seleted\" ";
  webString += ">320x240</option>\n";

  webString += "   <option value=\"3\" ";
  if (resolution == 3)
    webString += " selected=\"seleted\" ";
  webString += ">352x288</option>\n";

  webString += "   <option value=\"4\" ";
  if (resolution == 4)
    webString += " selected=\"seleted\" ";
  webString += ">640x480</option>\n";

  webString += "   <option value=\"5\" ";
  if (resolution == 5)
    webString += " selected=\"seleted\" ";
  webString += ">800x600</option>\n";

  webString += "   <option value=\"6\" ";
  if (resolution == 6)
    webString += " selected=\"seleted\" ";
  webString += ">1024x768</option>\n";

  webString += "   <option value=\"7\" ";
  if (resolution == 7)
    webString += " selected=\"seleted\" ";
  webString += ">1280x1024</option>\n";

  webString += "   <option value=\"8\" ";
  if (resolution == 8)
    webString += " selected=\"seleted\" ";
  webString += ">1600x1200</option>\n";

  webString += "  </select>\n";

  return webString;
}

void camCapture(ArduCAM myCAM)
{
  WiFiClient client = server.client();

  len  = myCAM.read_fifo_length();
  if (len >= MAX_FIFO_SIZE) // 8M
  {
    Serial.println("Over size.");
  }
  if (len == 0 ) // 0KB
  {
    Serial.println("Size is 0.");
  }

  myCAM.CS_LOW();
  myCAM.set_fifo_burst();

  if (!client.connected()) return;

  i = 0;
  while ( len-- )
  {
    temp_last = temp;
    temp =  SPI.transfer(0x00);
    //Read JPEG data from FIFO
    if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while,
    {
      buffer[i++] = temp;  //save the last  0XD9
      //Write the remain bytes in the buffer
      if (!client.connected()) break;
      client.write(&buffer[0], i);
      is_header = false;
      i = 0;
      myCAM.CS_HIGH();
      break;
    }
    if (is_header == true)
    {
      //Write image data to buffer if not full
      if (i < bufferSize)
      {
      buffer[i++] = temp;
      }
    else
    {
      //Write bufferSize bytes image data to file
      if (!client.connected()) break;
      client.write(&buffer[0], bufferSize);
      i = 0;
      buffer[i++] = temp;
    }
    }
    else if ((temp == 0xD8) & (temp_last == 0xFF))
    {
      is_header = true;
      buffer[i++] = temp_last;
      buffer[i++] = temp;
    }
  }
}

void serverCapture()
{
  delay(1000);
  start_capture();
  Serial.println("CAM Capturing");

  int total_time = 0;

  total_time = millis();
  while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK));
  total_time = millis() - total_time;
  Serial.print("capture total_time used (in miliseconds):");
  Serial.println(total_time, DEC);

  total_time = 0;

  Serial.println(F("CAM Capture Done."));
  total_time = millis();
  camCapture(myCAM);
  total_time = millis() - total_time;
  Serial.print("send total_time used (in milliseconds): ");
  Serial.println(total_time, DEC);
  Serial.println("CAM send Done!");
}

void serverStream()
{
  WiFiClient client = server.client();

  String response = "HTTP/1.1 200 OK\r\n";
  response += "Content-Type: multipart/x-mixed-replace; boundary=frame\r\n\r\n";
  server.sendContent(response);

  while (1)
  {
    start_capture();
    while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK));
    size_t len = myCAM.read_fifo_length();
    if (len >= MAX_FIFO_SIZE) // 8M
    {
      Serial.println(F("Over size."));
      continue;
    }
    if (len == 0 ) // 0 KB
    {
      Serial.println(F("Size is 0."));
      continue;
    }

    myCAM.CS_LOW();
    myCAM.set_fifo_burst();

    if (!client.connected()) break;
    response = "--frame\r\n";
    response += "Content-Type: image/jpeg\r\n\r\n";
    server.sendContent(response);

    while (len--)
    {
      temp_last = temp;
      temp =  SPI.transfer(0x00);

      //Read JPEG data from FIFO
      if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while,
      {
        buffer[i++] = temp;  //save the last  0XD9
        //Write the remain bytes in the buffer
        myCAM.CS_HIGH();;
        if (!client.connected()) break;
        client.write(&buffer[0], i);
        is_header = false;
        i = 0;
      }
      if (is_header == true)
      {
        //Write image data to buffer if not full
        if (i < bufferSize)
        {
          buffer[i++] = temp;
        }
        else
        {
          //Write bufferSize bytes image data to file
          myCAM.CS_HIGH();
          if (!client.connected()) break;
          client.write(&buffer[0], bufferSize);
          i = 0;
          buffer[i++] = temp;
          myCAM.CS_LOW();
          myCAM.set_fifo_burst();
        }
      }
      else if ((temp == 0xD8) & (temp_last == 0xFF))
      {
        is_header = true;
        buffer[i++] = temp_last;
        buffer[i++] = temp;
      }
    }
    if (!client.connected()) break;
  }
}

void handleNotFound()
{
  String ipAddr = WiFi.localIP().toString();
  if(wifiType == 1)
  {
    ipAddr = WiFi.softAPIP().toString();
  }

  Serial.print("Server URI: ");
  Serial.println(server.uri());

  if(server.uri().indexOf(".jpg") != -1)
  {
    loadFromSPIFFS(server.uri());
    return;
  }

  //// Default HTML
  String message = "\n";
  message += "\n";
  message += "<form action=\"http://" + ipAddr + "/submit\" method=\"POST\">";
  message += "
ESP32 Arducam Mini
\n";
  if (errMsg != "")
  {
    message += "
" + errMsg + "
";
  }

  if (imgMode == 0) // stream mode
  {
    message += "

Video Streaming

 \n";
    message += "

\n";
    imgMode = 1; // set back to capture mode so it doesn't get stuck in streaming mode

  }
  else
  {
    message += "
";
    message += getDropDown();

    message += " <input type=\"radio\" id=\"strm\" name=\"imgMode\" value=\"stream\" ";

    if (imgMode == 0)
    {
      message += " checked ";
    }
    message += "> Stream \n";

    message += " <input type=\"radio\" id=\"capt\" name=\"imgMode\" value=\"capture\"  ";
    if (imgMode == 1)
      message += " checked ";
    message += "> Capture \n";

    message += "  <input type='submit' value='Submit'  >\n";
    message += "    Refresh";
    message += "     Clear Data\n";

    message += "
\n";

    fileTotalKB = (int)SPIFFS.totalBytes();
    fileUsedKB = (int)SPIFFS.usedBytes();

    if (fileCount > 0)
    {
      int percentUsed = ((float)fileUsedKB / (float)(fileTotalKB - fileSpaceOffset)) * 100;
      String colorStr = "green";
      if (percentUsed > 90)
        colorStr = "red";

      message += "
";
      message += "
   space used: " + String(percentUsed) + "%
";
      message += "

\n";

    }

    message += "

";
    int colCnt = 0;
    for (int i = 1; i <= fileCount; i++)
    {
      message += "" + i + ".jpg	\n";

      colCnt++;
      if (colCnt >= 10) //  columns
      {
        message += "

";
        colCnt = 0;
      }
    }
    message += "

\n";

    //useful for debugging max data storage
      /*
        message += "

Total Bytes: 	";
        message += fileTotalKB;
        message += "

Used Bytes: 	";
        message += fileUsedKB;
        message += "

Remaing Bytes: 	";
        message += (fileTotalKB - fileUsedKB);
        message += "

\n";
      */
      /*
        float flashChipSize = (float)ESP.getFlashChipSize() / 1024.0 / 1024.0;
        message += "
chipSize: ";
        message += flashChipSize;
      */

      message += "

\n";

  }

  message += "</form> \n";
  message += "\n";

  server.send(200, "text/html", message);
}

void setCamResolution(int reso)
{
  switch (reso)
  {
    case 0:
      myCAM.OV2640_set_JPEG_size(OV2640_160x120);
      resolution = 0;
      break;

    case 1:
      myCAM.OV2640_set_JPEG_size(OV2640_176x144);
      resolution = 1;
      break;

    case 2:
      myCAM.OV2640_set_JPEG_size(OV2640_320x240);
      resolution = 2;
      break;

    case 3:
      myCAM.OV2640_set_JPEG_size(OV2640_352x288);
      resolution = 3;
      break;

    case 4:
      myCAM.OV2640_set_JPEG_size(OV2640_640x480);
      resolution = 4;
      break;

    case 5:
      myCAM.OV2640_set_JPEG_size(OV2640_800x600);
      resolution = 5;
      break;

    case 6:
      myCAM.OV2640_set_JPEG_size(OV2640_1024x768);
      resolution = 6;
      break;

    case 7:
      myCAM.OV2640_set_JPEG_size(OV2640_1280x1024);
      resolution = 7;
      break;

    case 8:
      myCAM.OV2640_set_JPEG_size(OV2640_1600x1200);
      resolution = 8;
      break;

  }
}

void clearData()
{
  errMsg = "======  Data Storage Cleared =========";
  File dir = SPIFFS.open("/pics");
  while (dir.openNextFile())
  {
    SPIFFS.remove(dir.name());
  }

  fileCount = 0;
  fileTotalKB = 0;
  fileUsedKB = 0;

  handleNotFound();
}

void handleSubmit()
{
  errMsg = "";
  Serial.println( "--- Form Submited ---");
  Serial.println( "Server args " + server.args());

  if (server.args() > 0 )
  {
    for ( uint8_t i = 0; i < server.args(); i++ )
    {

      // can be useful to determine the values from a form post.
      Serial.println( "Server arg " + server.arg(i));
      Serial.println( "Server argName " + server.argName(i) );
      if (server.argName(i) == "imgMode")
      {
        Serial.println(" Image Mode: " + server.arg(i));

        if (server.arg(i) == "stream")
        {
          imgMode = 0;
        }
        else
        {
          imgMode = 1; // capture mode
        }
      }

      if (server.argName(i) == "rez")
      {

        if (server.arg(i).toInt() != resolution)
        {

          setCamResolution(server.arg(i).toInt());

          updateDataFile();

          //// IMPORTANT: removing or reducing the delay can result in dark images
          delay(1500); // add a delay to allow the white balance to adjust to new resolution
        }
      }
    }
  }

  if (imgMode == 1) // capture
  {
    myCAMsaveToSPIFFS();
  }

  handleNotFound();

}

void setup()
{
  SPIFFS.begin();
  delay(10);

  Wire.begin();
  Serial.begin(115200);
  SPI.begin();
  SPI.setFrequency(4000000); //4MHz
  pinMode(CS, OUTPUT);

  pinMode(ArduCAM_Power, OUTPUT);
  digitalWrite(ArduCAM_Power, HIGH);

  Serial.println();

  // Check for properties file
  File f = SPIFFS.open(fName, FILE_READ);

  if(!f)
  {
    // No file exists. Format and create properties file.
    Serial.println("Please wait for SPIFFS to be formatted.");

    SPIFFS.format();
    Serial.println("SPIFFS Formatted!");

    f = SPIFFS.open(fName, FILE_WRITE);
    if(!f)
    {
      Serial.println("Properties file failed to open.");
    }
    else
    {
      Serial.println("========= Writing to Property file =========");

      f.println(resolution);
      f.close();
    }
  }
  else
  {
    Serial.println("Properties file exists! Reading...");

    while(f.available())
    {
      String str = f.readStringUntil('\n');

      Serial.println(str);

      resolution = str.toInt();
    }

    f.close();
  }

  uint8_t vid, pid;
  uint8_t temp;

  while(1)
  {
    //Check if the ArduCAM SPI bus is OK
    myCAM.write_reg(ARDUCHIP_TEST1, 0x55);
    temp = myCAM.read_reg(ARDUCHIP_TEST1);
    if (temp != 0x55) {
      Serial.println(F("SPI interface Error!"));
      delay(2);
      continue;
    }
    else
      break;
  }

  #if defined (OV2640_MINI_2MP) || defined (OV2640_CAM)
  //Check if the camera module type is OV2640
  myCAM.wrSensorReg8_8(0xff, 0x01);
  myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid);
  myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid);
  if ((vid != 0x26 ) && (( pid != 0x41 ) || ( pid != 0x42 )))
    Serial.println(F("Can't find OV2640 module!"));
  else
    Serial.println(F("OV2640 detected."));
  #endif

  //Change to JPEG capture mode and initialize the OV2640 module
  myCAM.set_format(JPEG);
  myCAM.InitCAM();

  setCamResolution(resolution);
  myCAM.clear_fifo_flag();

  if (wifiType == 0)
  {
    if(!strcmp(WIFI_SSID,"SSID"))
    {
      Serial.println(F("Please set your SSID"));
      while(1);
    }
    if(!strcmp(WIFI_PASSWORD,"PASSWORD"))
    {
      Serial.println(F("Please set your PASSWORD"));
      while(1);
    }
    // Connect to WiFi network
    Serial.println();
    Serial.println();
    Serial.print(F("Connecting to "));
    Serial.println(WIFI_SSID);

    WiFi.mode(WIFI_STA);

    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

    while (WiFi.status() != WL_CONNECTED)
    {
      delay(500);
      Serial.print(F("."));
    }

    Serial.println(F("WiFi connected"));
    Serial.println("");
    Serial.println(WiFi.localIP());
  }
  else if (wifiType == 1)
  {
    Serial.println();
    Serial.println();
    Serial.print(F("Shared AP: "));
    Serial.println(AP_SSID);
    Serial.print(F("The password is: "));
    Serial.println(AP_PASSWORD);

    WiFi.mode(WIFI_AP);

    WiFi.softAP(AP_SSID, AP_PASSWORD);

    Serial.println();
    Serial.print("AP IP Address is: ");
    Serial.println(WiFi.softAPIP());
  }

  File normPicture = SPIFFS.open("/pics/6.jpg", FILE_READ);
  uint32_t jpgLen = normPicture.size();

  Serial.print("Sending image of ");
  Serial.print(jpgLen, DEC);
  Serial.println("bytes");

  // Prepare request
  String start_request = "";
  String end_request = "";
  start_request = start_request + "\n" + "--AaB03x" + "\n" + "Content-Type: image/jpeg" + "\n" + "Content-Disposition: form-data; name=\"fileToUpload\"; filename=\"6.jpg\"\n" + "Content-Transfer-Encoding: binary\n\n";
  end_request = end_request + "\n--AaB03x--\n";
  uint32_t extra_length;
  extra_length = start_request.length() + normPicture.size() + end_request.length();
  //Serial.println("Extra length:");
  //Serial.println(extra_length);
  long leng = jpgLen + extra_length;

  // Connect to server
  Serial.println("Starting connection to external server!");
  if (client.connect("172.xx.xx.x", 80))
  {
    Serial.println("Connected");
    client.print("POST /www/upload.php HTTP/1.1");
    client.println("Host: 172.xx.xx.x" );
    client.println("Content-Type: multipart/form-data; boundary=AaB03x");
    client.print("Content-Length: ");
    client.println(extra_length);
    client.println();
    client.print(start_request);
    Serial.println("Connected1");

    while(normPicture.available())
    {
      client.write(normPicture.read());
    }

    Serial.println("END REQUEST");
    client.println(end_request);

  }
  else
  {
    Serial.println("Connection failed!");
  }

  // Setup handlers for internal server
  server.on("/capture", HTTP_GET, serverCapture);
  server.on("/stream", HTTP_GET, serverStream);
  server.on("/submit", handleSubmit);
  server.on("/clear", clearData);
  server.onNotFound(handleNotFound);
  server.begin();
  Serial.println("Internal Server started");

  File dir = SPIFFS.open("/pics");
  while(dir.openNextFile())
  {
    fileCount++;
  }

  fileTotalKB = (int)SPIFFS.totalBytes();
  fileUsedKB = (int)SPIFFS.usedBytes();

}

void loop()
{
  server.handleClient();

  //delay(15000);
}

My php code (upload.php) is below:
<?php
if (!empty($_FILES) && isset($_FILES['fileToUpload'])) {
    switch ($_FILES['fileToUpload']["error"]) {
        case UPLOAD_ERR_OK:
            $target = "upload/";
            $target = $target . basename($_FILES['fileToUpload']['name']);

            if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target)) {
                $status = "The file " . basename($_FILES['fileToUpload']['name']) . " has been uploaded";
                $imageFileType = pathinfo($target, PATHINFO_EXTENSION);
                $check = getimagesize($target);
                if ($check !== false) {
                    echo "File is an image - " . $check["mime"] . ".
";
                    $uploadOk = 1;
                } else {
                    echo "File is not an image.
";
                    $uploadOk = 0;
                }

            } else {
                $status = "Sorry, there was a problem uploading your file.";
            }
            break;

    }

    echo "Status: {$status}
\n";

}
?>

I don't believe that I need any html code, since the php file receives the image and sends it to the "uploads/" folder in "www/uploads/" from my external server. My upload.php file is located in "www/".
UPDATE1: I believe my error is either the client headers, or when writing the image to send to the external server. I get an error 400 226 on the external server when trying to send the image. The 400 for a bad client request, and I believe the 226 is the amount of bytes sent/received.
Thanks!

you can do client.write(normPicture);

To get image on PHP Side using move_uploaded_file() you need to send them using a HTML Form with input like . So or you "simulate" such a form, or you send data directly. In that case, maybe the easiest way would be to have a folder on you remote server with a specific FTP acces to send data to it. Look for FTP Arduino on Google.

@Juraj I did try doing while(normPicture.available()){client.write(normPicture))} but it ends up writing incomplete. It starts writing fine like 56,78...,45, and then ends with a -1. On the external server, I get error 400 226. The 400 is a bad client request, and I believe the 226 is the bytes the external server received?

@Peter Thanks for the input. I’ll definitely look into it!

use esp8266 arduino package 2.4.2. Peter is right that you could do a direct upload, not a form simulation, but I don't understand his FTP recommendation. It would be a completely different approach

@juraj I’m using an esp32. Would it matter?

sorry. then latest version. I would guess it is "bad request" because of problems with your multipart boundaries

@Juraj It seemed like I wasn’t using the latest version. It writes correctly now I think, since it doesn’t end in “-1”. I do believe my boundaries are incorrect because the image did get sent to my external server, but I can’t open the file. It says “The file could not be opened. It may be damaged or use a file format that Preview doesn’t recognize”.

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


text:
Why am not being able to initialize the Micro-SD?
The reason I bought this MicroSD board because to follow their guide
and I have used the recommend code in:
 File > Example > SD > CardInfo
also did the slight change in the code for const int chipSelect = 10;
Here is the exact code I am using:

/*
  SD card test

  This example shows how use the utility libraries on which the'
  SD library is based in order to get info about your SD card.
  Very useful for testing a card when you're not sure whether its working or not.

  The circuit:
    SD card attached to SPI bus as follows:
 ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** CS - depends on your SD card shield or module.
     Pin 4 used here for consistency with other Arduino examples

  created  28 Mar 2011
  by Limor Fried
  modified 9 Apr 2012
  by Tom Igoe
*/
// include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// MKRZero SD: SDCARD_SS_PIN
const int chipSelect = 10;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

    pinMode(10, OUTPUT); // change this to 53 on a mega(don't follow this!!)
    digitalWrite(10, HIGH); // Add this line

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.print("\nInitializing SD card...");

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    while (1);
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.println();
  Serial.print("Card type:         ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    while (1);
  }

  Serial.print("Clusters:          ");
  Serial.println(volume.clusterCount());
  Serial.print("Blocks x Cluster:  ");
  Serial.println(volume.blocksPerCluster());

  Serial.print("Total Blocks:      ");
  Serial.println(volume.blocksPerCluster() * volume.clusterCount());
  Serial.println();

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("Volume type is:    FAT");
  Serial.println(volume.fatType(), DEC);

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize /= 2;                           // SD card blocks are always 512 bytes (2 blocks are 1KB)
  Serial.print("Volume size (Kb):  ");
  Serial.println(volumesize);
  Serial.print("Volume size (Mb):  ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Gb):  ");
  Serial.println((float)volumesize / 1024.0);

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {
}

and this is the schematic I have used as they recommended

but the serial monitor keeps outputting Initializing SD card...initialization failed  I have tried wiring again and again but I am still getting the same result.
Here are the photo of the wiring and running the test.
There is something I'm not sure if it is helpful but after I upload the file and before the serial monitor output:
Initializing SD card...initialization failed. Things to check:
* is a card inserted?
* is your wiring correct?
* did you change the chipSelect pin to match your shield or module?

a red led located next to R1 of the MicroSD card starts flashing and before that output, it flashes faster then it stops and I will be presenting with that output.
Things I have tried...

Different card
Without the card
Tried the 3v
Tried using  pin 4 for chipSelect

Please don't mark as duplicate because I looked at the other and I'm trying to use this guide by this company and also this guide was presenting as a solution for others and here I am using it.
Edit 1:
After the writing this question, I had to upload the file again so I can take pictures when I did that this time the serial monitor outputs:
23:02:10.089 ->
23:02:10.089 -> Initializing SD card...initialization failed. Things to check:
23:02:12.106 -> * is a card inserted?
23:02:12.106 -> * is your wiring correct?
23:02:12.106 -> * did you change the chipSelect pin to match your shield or module?

Looks like I am stuck with that and the only number keep changing
23:11:02.769 ->
23:11:02.769 -> Initializing SD card...initialization failed. Things to check:
23:11:04.778 -> * is a card inserted?
23:11:04.778 -> * is your wiring correct?
23:11:04.778 -> * did you change the chipSelect pin to match your shield or module?

Edit 2:
Sorry but it looks these numbers coming because I did mark the show timestamps box by mistake.

it looks everything ok. check the soldering of the pins of Nano.

Juraj -Tomorrow I was going to try to test the connective of the pins at school, hopefully, it is the cause.

Also wiggle the wires in the breadboard. Sometimes they don't make an electrical connection, even thought they are fully pushed in.

A quick question after only skimming the post, is this an older standard SDCard or one of the High Capacity SDCard which uses a different way to address internal memory?

@Juraj have checked connectives of all pins and they were good so soldering was alright. I don't know what next I should do

@Gerben  I have just tried that too and I even did it again in a different breadboard. No luck for me.

@st2000  I'm a beginner and not really sure about these terminologies but I can tell you I bought my Micro SD Card Breakout Board from adafruit.com

@Juraj I did upload new two images there https://imgur.com/a/B4La8kx

I think the SDCard addressing change somewhere around the 8GByte size.  Under and an address gets you a byte.  Above and an address gets you a block of bytes.  The drivers has to be able to handle both.  I think SDCards using the block of bytes approach are labeled "HC".  This has nothing to do with the SDCard break out board.

The board on the photo is Arduino Micro, not Arduino Nano. Arduino Micro doesn't have SPI on pins 11, 12, 13. Use pins MOSI, MISO and SCK.

MO to DI
MI to DO
SCK to CLK
you can use any pin as CS, only set it as parameter to SD.begin()

I'm sorry, would you explain again! So where are these DI, DO, and CLK located in my Arduino Micro!

DI, DO and CLK are on the SD module. MISO, MOSI and SCK are on the Arduino

Alright If this is what you meant
** MOSI - DI - pin  11
** MISO - DO - pin 12
** SCK - CLK -  pin 13
** CS - pin 4   :  but still initialization failed!

not 11, 12, 13 !!! they don't have a number on Arduino Micro. only labels. see the picture I added to the Answer. on your board there is MO and MI

Arduino Mini is not Arduino Micro

I'm confusing. why do you keep editing old comments? Just was curious. unfortunately, I don't have the same as the one micro you posted.

see on the board SCK is in the corner. MI is MISO and MO is MOSI

Alright, I see the editing photo, let me apply these changes.

Alright now I see this
Initializing SD card...Wiring is correct and a card is present.

This made it worked! Done!


text:
My PIR sensor output changes but digitalread high all the time
This is my final project, I have to communicate with two wemos d1 mini by LAN. The problem is that when I read the state of the PIR sensor it is "HIGH" all the time, but when I connect the led light, it blinks as I move my hand - so the sensor is not broken.
I have tried with D7,D2,D3 and its the same... code is in the loop body
PIR output is directly connected to the D0.

#include <SPI.h>
#include <ESP8266WiFi.h>

int pirPin = 0;
int val=0;
/*int led1 = 1;
int  led2 = 3;
int led3 = 4;
int senzor2 = 5;
int led4 = 6;
int led5 = 7;
//int led6 = ;
*/
int ledPin = 2;
String ID = "001";

boolean uspostavljenostVezeSaServerom=false;
char ssid[] = "arduinoserver";           // SSID od mreže na koju se spaja
char pass[] = "arduinoserver";            // lozinka mreže na koju se spaja

unsigned long askTimer = 0;

IPAddress server(192,168,1,80);       // fiksna adresa servera na koji se spaja arduino(klijent)
IPAddress ip(192, 168, 1, 79);
IPAddress gateway(192,168,1,1);           // gateway mreže (nije obavezno)
IPAddress subnet(255,255,255,0);          // subnet mreže (nije obavezno)

WiFiClient client;

void setup() {
  pinMode(pirPin,INPUT_PULLUP);

  Serial.begin(115200);               // podešavanje bauda za komunikaciju
  spajanjeNaMrezu();                  // spajanje na mrežu
}

void loop () {

  if(uspostavljenostVezeSaServerom==false)spajanjeSaServerom();  // arduino uspostavlja komunikaciju sa serverom
  if(WiFi.status() != WL_CONNECTED) spajanjeNaMrezu();

val = digitalRead(pirPin);
  Serial.println(val);
delay(300);

  //Serial.println(digitalRead(val));

 /* client.connect(server, 80);   // Spajanje na server
  client.flush();
  client.println(ID);
  String answer = client.readStringUntil('\r');   // čekanje povratne poruke dok ne dođe do znaka "/r"
  */
}

void spajanjeSaServerom(){

  String answer;
  while(answer != "OK")
    {
      Serial.println("Uspotavljanje veze s serverom...");
      client.connect(server, 80);   // Spajanje na server
      client.flush();
      client.println(ID); // slanje koda klijenta serveru
      Serial.println("Šaljem ID: " + ID);
      answer = client.readStringUntil('\r');
      Serial.println("Odgovor servera: " + answer);
    }

  Serial.print("Veza uspostavljena!");
  uspostavljenostVezeSaServerom=true;
}

void spajanjeNaMrezu(){
  WiFi.config(ip, gateway, subnet);
  WiFi.begin(ssid, pass);             // spajanje s ruterom
  while (WiFi.status() != WL_CONNECTED) {
      Serial.println("Spajanje na mrežu...");
      delay(500);
  }
  Serial.println("Uspjesno spajanje na WiFi");
  Serial.print("Status: "); Serial.println(WiFi.status());
  Serial.print("IP: ");     Serial.println(WiFi.localIP());
  Serial.print("Subnet: "); Serial.println(WiFi.subnetMask());
  Serial.print("Gateway: "); Serial.println(WiFi.gatewayIP());
  Serial.print("SSID: "); Serial.println(WiFi.SSID());
  Serial.print("Signal: "); Serial.println(WiFi.RSSI());

}

use Dx constants. pirPin = D2; https://electronics.stackexchange.com/questions/402066/esp8266-free-gpios-for-relay-switching/404845#404845

Yeah, int pirPin = 0; does not look right. Instead use int pirPin = D0;

I tried before, but not working :(
"error: 'D0' was not declared in this scope"

did you select "Wemos D1 R2 or mini" in Tools menu?

I selected ESP8266, that was the problem :). Thanks alot !


text:
Reading sensor data, massaging it and performing operation based on transformed data
This is the outline of my project:

interpret environment data (sensor, motor, etc..).
Modify this data into a more usable form,
send it back to the same motor for further operation from modified data.

As an example (this is not the project, but just an example to make sure I am being clear).
A motor moves a conveyor belt with various size flasks on it, some large other small. Depending on the reading of the position of the motor (from encoder) another process (filling the flasks) will take place.  If the first motor encoder data indicated the flask was small then the amount of liquid poured will be small. If large, the amount of liquid dispensed will be large.
More generally, read the location of an item based on motor encoder feedback.  Modify this data. Send this modified data back to a different motor so that it does something specifically as a function of the first motor encoder data.
I am able to send the original encoder feedback to a file, manually massage it and paste it into an Arduino script, compile and have everything work great. I just want to remove the manual steps (cut & paste) and data massaging (I'm looking to an Arduino program to do that).
To further complicate things, I want this process to be part of a distributable package that does not require further compiling. Reading from a sim card is fine.  Also, I am not too price sensitive as the Arduino is a small portion of the total cost of the final product.
I hope someone can give me some insight or pathway to a solution.
All the very best, John.

If I understand your question properly, you want to take some data which you have in memory on the Arduino, change it somehow, and put it somewhere else in memory.  Is that right?  I think you'll need to give us a clue as to what data you have and how you want to manipulate it.

i am taking encoder readings, performing text concatenations, sorting and then applying transformed data to a stepper motor controller.  I investigated using a raspberry PI and arduino combination (raspberry for concatenating and sorting and arduino for sensor feedback and motor control) but am stuck on how to have the 2 talk without the end user having to be involved (needs to end up being a distributed product)

A solution to what exactly? I would suggest that you write a sketch in C/C++ using the Arduino core and get back to us when you have an actual question. Do not forget to include the wiring/circuit/schematics and some code and a real question.

Yeah, I agree with @MikaelPatel - you haven't stated any clear problem to solve. You didn't even mention as Raspberry Pi in the question...!  Reading sensors, doing some processing on the data and controlling motors is bread-and-butter for the Arduino so I think you'll need to be more specific if you want an answer better than "yeah, maybe use an Arduino".

Sorry, I did mention I looked into R-Pi, not that I "wanted" to have it part of the solution.  To be honest, I am a total newbie to this and am looking for an idea of what to look into as I am not even sure if what I want to do can be done with Arduino.  I was hoping for a "use the XYZ" to talk to the "ABC" by running "123" kind of a "point in the right direction".  I do know python (a bit), just not that swift at electronics and C/C++

What is your sensor data?  What is your interpreted data?  What are your policies, based on the interpreted data?  As far as your question goes, one would need only write a few nested functions: motorDoWhatIMean(interpretedData(readSensor1(),readSensor2(),...));

Here's a back-of-envelope sketch, off the top of my head:
Conveyor belt driven by stepper motor, controlled by the Arduino.  Each step is a known distance.
Bottles are either of exactly two heights, at random.  Two beam break sensors, one to determine where a bottle starts and one to determine whether it's tall or short.
Some sort of valve to control the water flow - I presume you have some idea how this can be controlled.  I don't, but washing machines have electrically-controlled valves so something broadly along those lines.  Controllable on/off by the Arduino.
Software on the Arduino steps the motor until it sees the start of a bottle (first beam broken).  Then uses second beam to determine whether the bottle is large or small.
Arduino switches on the water valve (outlet positioned exactly right to be above the bottle) for either 2s or 4s accoriding to bottle size, then off again.   (Water pressure and flow rate regulated independently, perhaps fed from a header tank).
Arduino steps motor more until it sees another bottle.

No string concatenation in there, nor sorting of lists or need for a Raspberry Pi.  It's not clear to me why you'd need those things for the application described.
I'm not aware that you can program the Arduino in Python unfortunately.  Someone may know better.  C isn't hard though - get an Arduino and some LEDs or whatever, go through some tutorials, you'll get the hang of it.


text:
Arduino beginner question
I just got a new pro-micro Atmega32U4 board, and installed the current Arduino IDE (1.8) and cannot get it working.
There is no entry for a pro-micro, so I chose Leonardo as it uses the same chip.
When I choose upload, the two red LEDs blink fast, but I get an error from avrdude, saying that it cannot upload the code.
The board is probably from a Chinese web shop ($6 clone). There are no buttons on the board.
My questions are:

Is there already a bootloader on the chip, or do I have to program one? How do I check this?
How does it know that it must receive an upload, instead of running the flash program?
Which board should I choose in the IDE?

This is the error:

Couldn't find a Board on the selected port. Check that you have the correct port selected.  If it is correct, try pressing the board's reset button after initiating the upload.

It looks exactly like this one.
Update: I did everything the manual said. I can choose the pro-micro now. Still the same error message. How do I check what state the bootloader is in?

There is an extensive guide written by SparkFun explaining how to work with Arduino Pro Micro: Pro Micro & Fio V3 Hookup Guide.
There are specific drivers for the board, so make sure you have them installed. There are also board files for the IDE, which allow you to select the Pro Micro in Arduino software.

I'm answering my own question. It works now. You must reset it (maybe twice) before you can upload software to it. I soldered a few wires to it for this. That did the trick.


text:
RFID reader code to identify more than one tag
I'm new to using Arduino and I have managed a few changes to this sketch. But I want to check for a second tag if the first one is not correct. I just can't seem to get it to work. I think it would be good if the tag is not a match to ask it to check the next tag and carry on, but I'm not sure how to make this happen.
//RFID Password Typer
//If a matching tag is found, the keyboard types
//CTRL-ALT-DEL, then types the password and presses enter
//Which should log you on to a Windows computer
//Or Lock the computer if you're already logged in

#include <SPI.h>
#include <MFRC522.h>
#include "Keyboard.h"
#include <Mouse.h>

#define RST_PIN 9
#define SS_PIN 10

byte tag[10]={0x64,0xAE,0xDD,0xFC,};
char pswd[]="********\n";      //password, end with just \n
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

void setup() {
  SPI.begin();              //start SPI
  mfrc522.PCD_Init();       //start RC522 module
  Keyboard.begin();         //start USB keyboard
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);     //LED off
}

void loop() {
  if (!mfrc522.PICC_IsNewCardPresent()){ return; }
  if (!mfrc522.PICC_ReadCardSerial()){ return; }
  for(byte i = 0; i < mfrc522.uid.size; i++) {
    if(mfrc522.uid.uidByte[i]!=tag[i]){ return; }
  }
  mfrc522.PICC_HaltA(); //stop tag so we don't get repeats
  digitalWrite(13, HIGH); //LED on so we know we've got tag match
  Mouse.click();
  delay(1000);
  Keyboard.press(KEY_LEFT_CTRL);
  delay(1000);
  Keyboard.releaseAll();
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press(KEY_LEFT_ALT);
  Keyboard.press(KEY_DELETE);
  delay(100);
  Keyboard.releaseAll();
  delay(300);
  Keyboard.print(pswd);
  delay(100);
  digitalWrite(13, LOW); //LED off
}

Please edit your post and format the code using the code formatting markdown (four leading spaces). For help see Markdown help. You should be able to do this by selecting the code and pressing Ctrl+K to have your browser do this for you.

What have tried? You are looping through the UID of the card and exit if one of the bytes are not values. (This is by the way a timing side-channel.). You can just add a second for loop to see if it's equal to another constant tag value. For that you should put the "compare two byte arrays of a given size" logic in a function for easy re-use.

here's how I'd do it ... allowing for 4, 7 and 10 byte uid's (which are all possible apparently)
struct tagInfo {
  byte len;
  byte uid[10];
};
struct tagInfo tag[] = { // add your tags here
  // the len is 1, 2 or 3, for lengths 4, 7, and 10
  // you could just use 4, 7, 10 here and not bother
  // with the len * 3 + 1 calculation later
  // the choice is yours, really
  {1, {0x01, 0x02, 0x03, 0x04}},
  {1, {0x02, 0x03, 0x04, 0x05}},
  {2, {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}},
  {1, {0x02, 0x02, 0x02, 0x02}}
};
const int numtags = sizeof(tag)/sizeof(struct tagInfo);

Then, your loop
void loop() {
  if (!mfrc522.PICC_IsNewCardPresent()) { return; }
  if (!mfrc522.PICC_ReadCardSerial()) { return; }
  int i; // declare before the loop because we want to check the value after the loop ends
  for (i = 0; i < numtags; i++) {
    byte len = tag[i].len * 3 + 1;
    if(len == mfrc522.uid.size) { // 4, 7, 10?
      if(!memcmp(mfrc522.uid.uidByte, tag[i].uid, len)) {
        break; // found an exact match so stop the loop
      }
    }
  }
  if (i == NUMTAGS) { return; } // no matches
  // all good here - run the rest of your code
}

Got it. Not sure if it's the best way but it works. Thanks for your help.
//RFID Password Typer
//If a matching tag is found, the keyboard types
//CTRL-ALT-DEL, then types the password and presses enter
//Which should log you on to a Windows computer
//Or Lock the computer if you're already logged in

#include <SPI.h>
#include <MFRC522.h>
#include "Keyboard.h"

#define RST_PIN 9
#define SS_PIN 10

byte tag[10]={****,****,****,****,};
byte tag1[10]={****,****,****,***^,};
byte tag2[10]={****,****,****,**^^,};
byte tag3[10]={****,****,****,*^^^,};
char pswd[]="*********\n";      //password, end with just \n
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

void setup() {
  SPI.begin();              //start SPI
  mfrc522.PCD_Init();       //start RC522 module
  Keyboard.begin();         //start USB keyboard
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);     //LED off
}

void loop() {
  if (!mfrc522.PICC_IsNewCardPresent()) { return; }
  if (!mfrc522.PICC_ReadCardSerial()) { return; }
  for(byte i = 0; i < mfrc522.uid.size; i++) {
    if(mfrc522.uid.uidByte[i]!=tag[i]) {
    } else if(mfrc522.uid.uidByte[i]!=tag1[i]) {
    } else if(mfrc522.uid.uidByte[i]!=tag2[i]) {
    } else if(mfrc522.uid.uidByte[i]!=tag3[i]) { return; }
  }
  mfrc522.PICC_HaltA(); //stop tag so we don't get repeats
  digitalWrite(13, HIGH); //LED on so we know we've got tag match
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press(KEY_LEFT_ALT);
  Keyboard.press(KEY_DELETE);
  delay(100);
  Keyboard.releaseAll();
  delay(300);
  Keyboard.print(pswd);
  delay(100);
  digitalWrite(13,LOW); //LED off
}

no, not the best way at all - look at the logic in testing for a match ... work through it on paper, you'll see it is wrong

This is not the logic you want. You are looping through the UID and looking if any of the constant tags have that value in the current place. If you have tag1 = { 0x1, 0x2, 0x3} tag2 = {0x4, 0x5, 0x6} the tag {0x4, 0x2, 0x6} will be accepted although it does not match any tag completely. The other answer is what you'll want.


text:
Error array value after passed to a function
I would like to ask about a weirdness in my program. This is my program:
void setup() {
  Serial.begin(9600);
}

void loop() {
   workout_Text();
}

void workout_Text() {
  int woT_x[] = {1, 4, 8, 12, 16};
  int woT_y[] = {1, 4, 8, 12, 16};
  int n = sizeof(woT_y);
  on_led(woT_x, woT_y, n);
}

void on_led(int a_mat[], int b_mat[], int m) {
  for (int i = 0; i < m; i++) {
    Serial.print(a_mat[i]);
    Serial.print(" : ");
    Serial.println(b_mat[i]);
    delay(100);
  }
}

This is the part of my program for a LED matrix. The on_led purpose function is for printing the value of a_mat and b_mat. Instead of printing:
1 : 1
4 : 4
8 : 8
12 : 12
16 : 16
1 : 1
4 : 4
8 : 8
16 : 16

It prints:
1 : 1
4 : 4
8 : 8
12 : 12
16 : 16
13312 : 1
23296 : 4
1 : 8
4 : 12
8 : 16
1 : 1
4 : 4
8 : 8

Where does the big number come from? I am sure that my code is right to just print the a_mat and b_mat.
Thank you.

sizeof() returns the total number of bytes. If you have an array of 5 ints, where each int is 2 bytes long, sizeof will return 10.
If you want the number of elements in the array, you need to divide by the size of a single element:
int n = sizeof(woT_y) / sizeof(woT_y[0]);

sizeof counts bytes. the type of your array is int. sizeof of the int array of length 5 is 10 bytes. your for loop goes to i < 10 and reads after the 5th item of the array.


text:
Xbee S2C is resetting Arduino Uno
I have a coordinator radio hooked up to a sparkfun xbee shield, hooked up to an Uno. This is then hooked up to my computer. This coordinator talks with a number of xbee routers/end devices and sends them 6 commands to change the digital pins high or low on the corresponding xbees. The commands are always frame ID = 0, then the last (6th) command I send a 0x2 to save all the digital pins high or low at once.
The issue is that occasionally when the xbee receives all of the commands and saves them, the Uno will reset itself. (I can tell by the blinking LED on 13).
I have looked into it, and the best suggestion so far is to disable D7 on the receiving Xbee via XCTU. This unfortunately has not helped. Is there another reason that the arduino is resetting every couple of times I change the pins on the xbee? It doesn't happen every time, just once out of every 3-5 times...

Bleh, I figured it out. Not only do I have to turn D7 off, I also have to hook a jumper between 5V and RST as shown here.
https://learn.sparkfun.com/tutorials/xbee-shield-hookup-guide/all

It's OK to accept your own answer as the solution.


text:
Arduino simple resistors in series
Silly question but how would a circuit be set up with Arduino where two different resistors are in series but one has an unknown value (i.e. is just a piece of metal for example) and so how would we be able to find the current through each, collage through each and thus find the value of the resistance of the unknown wire.

If you know the voltage at either end of the chain, and the voltage at the middle node, as well as the value of one resistance, then you can calculate everything else.

series resistances have the same current flowing through them ... there is no "current through each" ... it is similar to water flowing through two pipes connected together

Just a math exercise really.
Say you had a 5V source, two Resistors R1 and R2, and an Arduino.
5V - R1 - R2 - Gnd, with R1/R2 junction feeding the Arduino.
R1 is unknown.
Vout is what the Arduino sees. Vout = 5VxR2/(R1+R2)
Vout (R1+R2) = 5VxR2
R1+R2 = 5VxR2/Vout
R1 = 5VxR2/Vout - R2
Vout = ~ 0.00488mV x Analog In reading. (5V/1024)
If you select R2 of say 5K ohm, and you determine Vout to be 3V (analogRead returns 615), then you can calculate R1:
(5V x 5000)/3V- 5000 = 3333 ohm.
Checking with Vout = 5VxR2/(R1+R2), 5V x 5000/(3333 + 5000) = 3.000V

While CrossRoads' answer got the math sorted out that is likely not the kind of measurement you are aiming for if the unknown resistor has a rather low resistance (i.e. is just a piece of metal). Assume the same circuit: 5V - R1 - R2 - GND.
Consider R1 to be a strand of copper wire of ribbon cable, AWG 26, i.e. with a diameter of 0.4 mm (0.016 inch) and a cross section of 0.13 mm², and a length of 3 inches (7.62 mm), being that "piece of metal". Its resistance will be 0.001 Ohms. To have any meaningful readings you'd want to have the other resistor (R2) in the same range otherwise the output voltage of the voltage divider will just be close to VCC (or GND if R1 and R2 are reversed). So assuming R2 to be 0.001 Ohms too, the total resistance of both resistors in series is therefore 0.002 Ohms. Connecting these to a 5V power supply (i.e. a voltage source) we find using Ohm's Law a current of 2500 A - which of course an ordinary Arduino wall plug will not provide. The power supply will either limit the current or its output voltage will be reduced or both - either way not a desirable situation in a measurement setup. Another approach of direct measurement is to apply a known current to the unknown resistor and measure the voltage across it. For any reasonable current that voltage will be rather small (i.e. 1 mV at 1 A) and would need to be amplified before being measured with an Arduino's ADC.
In short, measuring low resistances is difficult and might require a dedicated setup such as a Wheatstone bridge. Best answers are likely to be found at Electrical Engineering but need additional input on measurement range and required accuracy.


text:
nodemcu GPIO6 clock
is there a way that i can declare gpio6 (CLK) as an input without getting a wdt reset?  I'm somewhat new to circuitry, but my boss wants to use it(GPIO6) to talk with external devices.  I have more pictures of the schematics if you think that it would help.

No. There is no way you can use it (or not without a lot of messing around...).
According to the ESP8266 GPIO Reference Guide:

GPIO6 to GPIO11 are usually connected to the flash chip in ESP8266 boards. So, these pins are not recommended to use.

If you mess with those pins you won't be able to access the flash chip - and that means that you can't run code. And of course that means that the watchdog then times out.
I say that you can't "without a lot of messing around", because theoretically it could be possible if you had a function resident in RAM which reconfigured the pins, then did whatever was needed with them (taking into account the fact that there's a flash chip connected there...), then afterwards reconfigure the pins back to working in XIP SPI Flash mode.  But that's not something I would like to even contemplate doing.

No you can't.
Refer to this: https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html
However as that article states there is a dedicated SPI set of pins on the esp8266 so you should be able to use that?
From your circuit diagram I see this might not be an option for you as you seem to have most of the pins allocated to a different function.
Your best and most robust solution would probably be to have a separate microcontroller chip handling your I2C and SPI requirements, using the Esp8266 UART functionally to provide your wireless capabilities.
As a side note why do you have so many clock lines?

I think it has to do with the way the software was written previously.  The controller is supposed to run lights at 'belly', right, top-right, top-left, and left sides of the cabinet.  The lights they were using were rgb, but not individually addressable.  Now I have ws2812's and some other kind of ind. addressable lights and am not sure the clocks are necessary.  but i'm still a new guy to this.


text:
How to read voltage value from arduino to esp32
I am learning Arduino(uno)-ESP32 basics for a hobby project. In Arduino sketch, it's writing some random value(mimicking a sensor) to Arduino analog pin 9.
const int analogInPin = A0;  // NOT CONNECTED
const int outPin = 9;        // DIGITAL OUT. [ESP32 INPUT]

// SETUP()
randomSeed(analogRead(analogInPin));

// LOOP()
sensorValue = random(0, 1024);
// 0 - 5v WHEN MEASURED
// MAP VALUE OR JUST WRITE 'sensorValue'
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(outPin, outputValue);

In ESP32 sketch, I'm trying to read this value
int adc_value = 0; // EXPECTS A VALUE B/W 0 - 4095

//SETUP()
pinMode(26,INPUT);

//LOOP()
adc_value = analogRead(26);
Serial.println(adc_value);// OUTPUT 2 VALUES; 0 AND 4095
// MAP_VALUE = (adc_value * 5 ) / (4095);

The output is only 2 values, 0 and 4095. Is it due to ESP 3.3V and Arduino 0-5v output range or some other mistakes?

it is because analogWrite is PWM. https://www.arduino.cc/en/Tutorial/PWM

esp32 analog pin's maximum is 1 V


text:
My HC-05 Bluetooth Module is not working
I have been trying to use the HC-05 Module with my Arduino Uno to control a LED, which can be turned on and off by my phone. Everything is fine when i input the values from the serial monitor. The problem only occurs when I use my phone. I am using a bluetooth terminal for HC-05 and it shows it connected. The bluetooth module is conected as its blinking slows down when I use the app.
Here's the code:
#define ledPin 8
int state = 0;

void setup() {
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, LOW);
 Serial.begin(38400); /
}

void loop() {
 if(Serial.available() > 0){ // Checks whether data is comming from the serial port
 state = Serial.read();
 }
 if (state == '0') {
 digitalWrite(ledPin, LOW);
 Serial.println("LED: OFF");
 state = 0;
 }
 else if (state == '1') {
 digitalWrite(ledPin, HIGH);
 Serial.println("LED: ON");;
 state = 0;
 }
}

Here's the serial monitor output;

Appreciate the Help!

Can u plz say what is the name of the app u are using to control hc-05 Bluetooth module to turn on and off

What phone are you using? HC-05 is basic Bluetooth. Not BLE. If you're using iOS it will not work.

Few Points that you might want to Look into.

Where exactly are you connecting Bluetooth Module with Uno. Make sure you are connecting it with Rx and Tx Pin Only.
First make Simple Program to send some data on Serial Say "Hello World" at every 1second and make sure your Bluetooth is connected to Hardware Serial Pins only. If you receive data on phone then you are good to receive as well If not then Try below points.
Make sure your HC-05 Baudrate is correct. If you are not sure then try some others as well like 9600, 115200 etc.
Make sure Rx and Tx pins are connect with correct pins of HC-05. If you know your Baudrate then try swapping Rx Tx and it should response to you.

When switching from serial monitor to phone, did you change how the Arduino board was powered? If you power Arduino board via VIN port, then voltage across VIN and GND needs to be STRICTLY between 7 to 12 volts, otherwise the Arduino board is unstable (even if the board is on).
More tips and supporting information can be found on Step 3 of:
https://www.instructables.com/How-to-Connect-HC-05-to-Windows-1011-Mac-Apple-Com/


text:
Arduino-Bluetooth HC-05 Android app blueterm connection for chatting
I want to communicate between an arduino and an Android phone that has an Android app blue term. I connected HC-05 with Arduino using software serial and I connected the hc05 as a device with the android app. I am able to send data ( data as in message) from Android to Arduino but I am unable to send message from arduino to Android though I have given .write() command to Bluetooth connected.
Is it such that the Android app does not show the received message? Or there is some master-slave configuration issue? Do I need to configure HC-05 in master mode? It was configured in slave mode by default when I had connected it to Android app.

How is it wired? Where is your code?

Maybe some relevant lines are missing from your code.

Its totally Normal. You must be doing something wrong. It has happen to my Arduino Code a lot of times. try following:

Try interchanging you Tx and Rx Pin Positions. (This happens all the time).
Try connecting using default Serial and using Pin 1 and Pin 0 as Tx/Rx. (In this case remember to unplug the Tx/Rx Pins while running code.)
Try using just basic Serial.Write() function in beginning.


text:
Not able to upload program to "Arduino Due"

I'm not able to upload sketch on Arduino Due, using Programming Port.
Even blink sketch from examples is not working. So tried with blank sketch, I got following messages.

Are you sure that the COM port is precisely set?

If its not you COM port being set wrong or in use by something else then have you tried the old favourite of uninstalling the IDE and reinstalling it, just in case something has got messed up?

Upgrade to 1.6.9. There have been a number of changes in the upload system in the recent versions that have both broken and fixed things.

Go to device manager, and make sure that you can see the change in your com ports when you unplug and plug the Arduino into your computer.
You may also have to follow the instructions here: https://www.arduino.cc/en/Guide/Cores
I will also occasionally find that uploading won't work when I have something external connected to the RX,TX,3.3 and 5V, and GND pins.
It also helps to go to File-Preferences- and enable both options for "Show verbose output during". If you do that and post the output, we might have a better idea as to what is going wrong.

There is no FTDI chip on a due. How will installing the FTDI drivers help?

I didn't even see that he was using a DUE! To the OP- if you're using an IDE that's newer than 1.6.2, you may have to follow the instructions here: https://www.arduino.cc/en/Guide/Cores


text:
Signal pin of buzzer is connected with which Arduino uno pin
I bought a 3 pin buzzer. It has positive, negative and signal pin.
I don't understand how this signal pin should be connected with the Arduino.
Here is reported the description page of the buzzer.

Usually a buzzer only has two wires, positive and negative. The module you have bought though uses a transistor to drive the buzzer, which is a nice thing for very low power boards, which is not your case I believe.
Anyway, the module will take power from the positive and negative connections, allowing you to control it via the signal, from which very little power is drained.
How does a buzzer work? Actually to emit a sound via a buzzer you have to send a series of electrical pulses to the signal pin. The number of pulses per second (frequency, expressed in hertz, Hz) will determine the tone of the sound. higher the frequency, higher the pitch of the sound emitted.
Human ear is capable to detect frequencies between 20 and 20000Hz, but not everybody has such a broad perception, it decreases with age and not everybody is born with full range, so I advice to stay in the 2000-15000Hz range.
There is a nice library called Tone which helps you generate the correct signal for specific notes, allowing to even play some music via the buzzer (don't expect polyphony though!)
So, to play a note on your buzzer, assuming you have the buzzer signal pin tied to digital pin 6, you can just:
void setup() { /* empty */ }

void loop() {
    noTone(6);
    // play a note on pin 6 for 200 ms:
    tone(6, 440, 200);
    delay(200);
}

Also have a look at ToneMelody if you wish to emit specific notes (each note has its own particular frequency)

As I have read in the page you have linked, I think you should program the Arduino to provide an impulse to the signal (s) pin.
Therefore, to answer your question you can use any digital pin of the Arduino. And I guess that as long as the impulse last as long as the buzzer will produce a sound.
Here an example of code:
int buzzPin =  2;    //Connect Buzzer on Digital Pin3
void setup()
{
 pinMode(buzzPin, OUTPUT);
}
 void loop()
{
 digitalWrite(buzzPin, HIGH);
 delayMicroseconds(50);
 digitalWrite(buzzPin, LOW);
 delayMicroseconds(50);
}


text:
Sampling Rate of Arduino Uno
It might be a stupid question but, I am currently using Arduino Uno with the 16MHz processor, what is maximum sampling rate of data available to me if I want to read data of a sensors such as accelerometer?

It depends how the accelerometer is read. Is it I2C? SPI? Serial? Can you provide a part number or link? Please read How do I ask a good question?

I m sorry for incomplete information,i am using MPU6050 with I2C .

I have a page about I2C. The speed of I2C depends on a number of things, such as the I2C clock (which you can change) and also how many data bytes are in a "packet". There is a fixed overhead of the device address in each packet.
A broad rule-of-thumb would be around 4700 bytes per second for a single-byte payload at the default clock rate. You may also need to spend time asking for a reading. I haven't read the datasheet (which you didn't link).
The datasheet for the MPU6050 may give you more information about how fast it can respond.


text:
Start program on PC using Arduino
I want to create arduino sketch that start program on my computer (i.e., browser) when I push button on Arduino itself.
Is it possible to make it using Arduino uno? I already know how to make a serial connection between PC and Arduino and use Processing software, but as I know, Processing cannot interact with another programs.

Processing is just Java.  If Java can do it Processing can do it.
And Java can do it.
Just ask Google about the Java ProcessBuilder class.

You can also make the Arduino look like a keyboard/mouse to the PC and then reproduce some key combo that will perform the action you want.
See reference here.


text:
CC3000 cannot sending post data with content length more than 104
I'm trying to post data from my Arduino due to my web server (php) through POST using the CC3000 breakout board and for some reason, data with content length more than 104 is not being sent?
I've tried posting directly with postmaster with content length value greater than 104 to verify that it wasn't my server denying the request and it wasn't. So something with the Arduino or cc3000?
Right now, my post request looks like this which works:
POST /new/path/post.php HTTP/1.1
Host:  www.mywebsite.com
User-Agent: Arduino/1.0
Connection: close
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 104

userId=32&sscId=43&raVal=52&cvVal=62&bbvfgTempInF=723&bbvfgLevel=82345&humidity=92&lmassLevel=0283838383

And this is the one that doesn't (notice only one character difference in userId):
POST /new/path/post.php HTTP/1.1
Host:  www.mywebsite.com
User-Agent: Arduino/1.0
Connection: close
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: 105

userId=322&sscId=43&raVal=52&cvVal=62&bbvfgTempInF=723&bbvfgLevel=82345&humidity=92&lmassLevel=0283838383

And here is my full code:
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"

// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   28  // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT  26
#define ADAFRUIT_CC3000_CS    22
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIVIDER); // you can change this clock speed

#define WLAN_SSID       "mynetwork"   // cannot be longer than 32 characters!
#define WLAN_PASS       "mypassword"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define IDLE_TIMEOUT_MS  10000      // Amount of time to wait (in milliseconds) with no data
                                   // received before closing the connection.  If you know the server
                                   // you're accessing is quick to respond, you can reduce this value.

/**************************************************************************/
/*!
    @brief  Sets up the HW and the CC3000 module (called automatically
            on startup)
*/
/**************************************************************************/

uint32_t ip;

void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n"));

  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);

  /* Initialise the module */
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }

  // Optional SSID scan
  // listSSIDResults();

  Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }

  Serial.println(F("Connected!"));

  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }

  /* Display the IP address DNS, Gateway, etc. */
  while (! displayConnectionDetails()) {
    delay(1000);
  }

  ip = 0;
  // Try looking up the website's IP address
  Serial.print(WEBSITE); Serial.print(F(" -> "));
  while (ip == 0) {
    if (! cc3000.getHostByName(WEBSITE, &ip)) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }

  cc3000.printIPdotsRev(ip);

  // Optional: Do a ping test on the website
  /*
  Serial.print(F("\n\rPinging ")); cc3000.printIPdotsRev(ip); Serial.print("...");
  replies = cc3000.ping(ip, 5);
  Serial.print(replies); Serial.println(F(" replies"));
  */

  /* Try connecting to the website.
     Note: HTTP/1.1 protocol is used to keep the server from closing the connection before all data is read.
  */
  Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
  if (www.connected()) {
    Serial.println("Connected");
    String PostDatat = "userId=32&sscId=43&raVal=52&cvVal=62&bbvfgTempInF=723&bbvfgLevel=82345&humidity=92&lmassLevel=0283838383";

    Serial.println();
    Serial.println("POST /new/path/post.php HTTP/1.1");
    Serial.println("Host: www.mywebsite.com");
    Serial.println("User-Agent: Arduino/1.0");
    Serial.println("Connection: close");
    Serial.println("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
    Serial.print("Content-Length: ");
    Serial.println(PostDatat.length());
    Serial.println();
    Serial.println(PostDatat);

    //HANGS HERE IF CONTENT LENGTH > 104

    www.println("POST /new/path/post.php HTTP/1.1");
    www.println("Host: www.mywebsite.com");
    www.println("User-Agent: Arduino/1.0");
    www.println("Connection: close");
    www.println("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
    www.print("Content-Length: ");
    www.println(PostDatat.length());
    www.println();
    www.println(PostDatat);

    Serial.println();
    Serial.println("POST /new/path/post.php HTTP/1.1");
    Serial.println("Host:  www.mywebsite.com");
    Serial.println("User-Agent: Arduino/1.0");
    Serial.println("Connection: close");
    Serial.println("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
    Serial.print("Content-Length: ");
    Serial.println(PostDatat.length());
    Serial.println();
    Serial.println(PostDatat);

    Serial.println("SENT");
  } else {
    Serial.println(F("Connection failed"));
    return;
  }

  Serial.println(F("-------------------------------------"));

  /* Read data until either the connection is closed, or the idle timeout is reached. */
  unsigned long lastRead = millis();
  while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
    while (www.available()) {
      char c = www.read();
      Serial.print(c);
      lastRead = millis();
    }
  }
  www.close();
  Serial.println(F("-------------------------------------"));

  /* You need to make sure to clean up after yourself or the CC3000 can freak out */
  /* the next time your try to connect ... */
  Serial.println(F("\n\nDisconnecting"));
  cc3000.disconnect();

}

void loop(void)
{
 delay(1000);
}

/**************************************************************************/
/*!
    @brief  Begins an SSID scan and prints out all the visible networks
*/
/**************************************************************************/

void listSSIDResults(void)
{
  uint32_t index;
  uint8_t valid, rssi, sec;
  char ssidname[33];

  if (!cc3000.startSSIDscan(&index)) {
    Serial.println(F("SSID scan failed!"));
    return;
  }

  Serial.print(F("Networks found: ")); Serial.println(index);
  Serial.println(F("================================================"));

  while (index) {
    index--;

    valid = cc3000.getNextSSID(&rssi, &sec, ssidname);

    Serial.print(F("SSID Name    : ")); Serial.print(ssidname);
    Serial.println();
    Serial.print(F("RSSI         : "));
    Serial.println(rssi);
    Serial.print(F("Security Mode: "));
    Serial.println(sec);
    Serial.println();
  }
  Serial.println(F("================================================"));

  cc3000.stopSSIDscan();
}

/**************************************************************************/
/*!
    @brief  Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;

  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}

So after running this code and changing the PostDatat variable to the two data being 104 char long and 105 char long, the 104 char long goes all the way through and prints the message SENT to the Serial monitor. But the 105 char long just hangs after the first Serial.println() blocks and before the "www.println(..." Has anyone had or encountered this problem or can suggest a solution to this? Thanks!

I've gone through the library to locate the buffer where data is stored before being transmitted and I noticed that the minimum TX buffer size is set to 130 bytes. Certain control information in the form of headers are sent along with your data to the CC3000. The CC3000 interprets these headers, strips them away and re-formats your data for transmission to your gateway. So when your 105-byte content was added to these headers, the whole packet exceeded the 130-byte buffer and so caused it to overflow, overwrite a 'magic number' at its end, that is meant to detect this condition, and cause the program to stall indefinitely; this is all by design. From ccspi.h:
// The magic number that resides at the end of the TX/RX buffer (1 byte after the allocated size)
// for the purpose of detection of the overrun. The location of the memory where the magic number
// resides shall never be written. In case it is written - the overrun occured and either recevie function
// or send function will stuck forever.
#define CC3000_BUFFER_MAGIC_NUMBER (0xDE)

The value of the number itself doesnt matter; its presence/absence is what is important. So this is where your code most likely got stuck:
/* The magic number that resides at the end of the TX/RX buffer (1 byte after the allocated size)
   * for the purpose of overrun detection. If the magic number is overwritten - buffer overrun
   * occurred - and we will be stuck here forever! */
  if (wlan_tx_buffer[CC3000_TX_BUFFER_SIZE - 1] != CC3000_BUFFER_MAGIC_NUMBER)
  {
    DEBUGPRINT_F("\tCC3000: Error - No magic number found in SpiWrite\n\r");
    while (1);  //Infinite loop; end of the road
  }

And the reason you didnt get this error message is because debug mode is disabled by default in the library. You can enable it by changing #define DEBUG_MODE (0) to #define DEBUG_MODE  (1) in debug.h in the utility folder in the library.
Note that this buffer limitation applies to incoming data, as well as outgoing data.
Now you can increase the buffer size by changing:
#define CC3000_MINIMAL_TX_SIZE      (130 + 1)

to:
#define CC3000_MINIMAL_TX_SIZE      (150 + 1) // buffer size is now 150 bytes

in cc3000_common.h in the utility folder in your library folder, save the file and try again.
Even if this works though, I suggest you choose a fixed chunk size for sending data, one that is reasonably below 130 bytes. What happens next time when you want to send a 200-byte string? You increase the buffer again and you deprive the rest of your sketch of valuable SRAM. What you do is pass your POST content to some function that splits the string into chunks and sends them one at a time.
Assuming you send only ASCII strings:
#define CHUNK_SZ  80  // your chunk size

void send_all(Adafruit_CC3000_Client * conn, const uint8_t * data, uint16_t len){
  while (len >= CHUNK_SZ){   // while the length is greater than your chunk size
    conn->write(data, CHUNK_SZ);  // write a chunk to the socket
    data += CHUNK_SZ;  // advance the pointer to the start of the next chunk
    len -= CHUNK_SZ;  // get how many bytes are left
  }
  if (len)  // send whatever remains if anything remains
    conn->write(data, len);
}

void loop(){
  ...

  Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
  const uint8_t[] PostDatat = "userId=32&sscId=43&raVal=52\r\n";
  send_all(&www, PostDatat, sizeof(PostDatat) - 1); // -1 is to ignore the null byte

  ...
}

The function takes a pointer to your CC3000 socket object, a pointer to your data and the size of the data (array or not) in bytes. It should work for C strings. Note that I explicitly added \r\n at the end of the POST content, since println() isnt used here. I used the uint8_t type so that you can also use the function to send an arrays of ints or other numeric types, as long as you cast the array to uint8_t * and specify the length of the array in bytes with sizeof().
Finally, try to make your chunk size as large as you can without getting too close to the limit. A large chunk size means fewer chunks, which means less overhead (remember those pesky headers) and time taken to transmit your whole request.

Changed it and checked, but still the same issue :(

@dmantor try replacing all the www.println() and Serial.println() with www.println(F()) and Serial.println(F()). Use this only for string literals.

Also have you tried other lengths like 120, for instance? Why are you printing the POST to Serial twice?

I tried the replace to F() and still nothing. What does that do anyways? Also, I did try 120 and any length over 104 doesn't work :/ . And I have POST twice cause I wanted to see how the post looks before its sent even if it gets stuck at the actual POST. That was more for testing and seeing where my code was failing before.

@dmantor I've edited my answer

Changing the cc3000_common.h worked! Woo, thanks! Could you please just explain a little bit more on why the 105 failed when the limit was 130? Are there extra headers added on the content I assume that takes the other 25 more bytes by default? Also, I really don't want to change the library to make it work as a long term solution either...so could you please elaborate a little bit on the 50byte max chuck and an example of how to do that? Thanks! Much appreciated

@dmantor edited my answer again. glad it worked out for you.

Does it print out the part "Free Ram: " If not, then I doubt its a memory problem. Not too familiar with the CC3000, but possibly related to a UART Break Condition.

Was thinking the same thing before, but it did show. Regardless, the problem has been solved by @TisteAndii 's solution :D