text:
Arduino Uno keeps looping on setup() everytime I press a specific button on the remote
I'm trying to decode my Panasonic television remote using the IR_RECEIVE sketch below.
When I press the remote's buttons it works fine and Iget the values, except from when I press the power button - the setup() function executes.
This is the code:
/* Raw IR decoder sketch!

This sketch/program uses the Arduno and a PNA4602 to
decode IR received. This can be used to make a IR receiver
(by looking for a particular code)
or transmitter (by pulsing an IR LED at ~38KHz for the
durations detected

Code is public domain, check out www.ladyada.net and adafruit.com
for more tutorials!
*/

#define IRpin_PIN      PIND
#define IRpin          2
#define MAXPULSE 65000
#define RESOLUTION 20

uint16_t pulses[100][2];  // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing

void setup(void) {
    Serial.begin(9600);
    Serial.println("Ready to decode IR!");
}

void loop(void) {
    uint16_t highpulse, lowpulse;  // temporary storage timing
    highpulse = lowpulse = 0; // start out with no pulse length

    while (IRpin_PIN & (1 << IRpin)) {
        highpulse++;
        delayMicroseconds(RESOLUTION);

        if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
            printpulses();
            currentpulse = 0;
            return;
        }
    }
    pulses[currentpulse][0] = highpulse;

    while (!(IRpin_PIN & _BV(IRpin))) {
        lowpulse++;
        delayMicroseconds(RESOLUTION);
        if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
            printpulses();
            currentpulse = 0;
            return;
        }
    }
    pulses[currentpulse][1] = lowpulse;

    currentpulse++;
}

void printpulses(void) {
    Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
    for (uint8_t i = 0; i < currentpulse; i++) {
        Serial.print("delayMicroseconds(");
        Serial.print(pulses[i][0] * RESOLUTION, DEC);
        Serial.println(");");

        Serial.print("pulseIR(");
        Serial.print(pulses[i][1] * RESOLUTION, DEC);
        Serial.println(");");
    }
}

This is the output:

Ready to decode IR!
Received:
OFF   ON
  delayMicroseconds(34724);
  pulseIR(3600);
  delayMicroseconds(1800);
  ......
  delayMicroseconds(1340);
  pulseIR(460);
  delayMicroseconds(1360);
  pulseIR(460);
  Ready to decode IR!
  Ready to decode IR!

The last 2 rows appeared when I pressed the power button (twice).
The rows above appears when I press any other button.
I played around with the Arduino and the remote, I might have done something to cause this. The first time I tried it - it worked fine.
I tried resetting and re-uploading.
Sorry if the post is too long or not informative enough - I'm new to this and not really sure what kind of information to provide.

the chip resets on some error

try larger array uint16_t pulses[150][2];

How high can currentpulse get before it is reset to zero? It is used an array index and if it gets larger than the (number of array elements-1), your code will write outside of the array.
Can the array be so far over-written that it grows into the stack area? That could definitely cause a reset, or reset-like behavior.


text:
Why is 'n' parameter of snprintf ignored?
I have found that the n parameter of snprintf() seems to be ignored in my code.
char asdf[10];
Serial1.println(snprintf(asdf, 2, "hello"));

This prints 5 when I would expect it to print 2. What is happening?

Does the variable asdf contain "hello" or "h"? If it contains "h" then the parameter has not been ignored.

snprintf() will not write more than <size> (snprintf's 2d argument) characters to your buffer, but it does count (and discard the extra) characters it would have written, had there been space enough, and that is the number it returns. Yeah, it can be confusing!
See this snprintf() reference.

It would be helpful because you could snprintf to a very small buffer, note the number returned, then malloc a buffer of the appropriate size, and do it again. That way you know how many bytes to allocate.

@NickGammon: Or you can snprintf to no buffer whatsoever (a null destination pointer is explicitly described as a valid argument for the destlength==0 case) when measuring the length.

Indeed. That is also done in Windows text output routines to measure how much space some text in some font would occupy, without actually drawing it.

A test sketch for the Arduino Uno:
char buffer[10];

void setup() {
  Serial.begin(9600);
  int n = snprintf(buffer, 2, "hello");
  Serial.println(n);
  Serial.println(buffer);
}

void loop() {
}

As @JRobert wrote, the "would have" is the key. As far as I know only the snprintf and the vsnprintf return a "would have" number.
I think the reason is to be able to tell if the string was truncated. Suppose the 'size' parameter is 25 and the format string is very long, then the return value can be tested against 25. If the return value was 26 (the "would have" number of bytes), then the string was truncated.
This information was not possible to retrieve when the "would have" number was not available.

For completion, the man page for fprintf states:

The snprintf() function shall be equivalent to sprintf(), with the
  addition of the n argument which states the size of the buffer
  referred to by s.  If n is zero, nothing shall be written and s may
  be a null pointer. Otherwise, output bytes beyond the n‐1st shall be
  discarded instead of being written to the array, and a null byte is
  written at the end of the bytes actually written into the array.

and, more relevant:

Upon successful completion, the snprintf() function shall return the
         number of bytes that would be written to s had n been sufficiently
         large excluding the terminating null byte.

source: Stack Exchange

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

sort: votes


text:
Stepper Motor won't reverse/turn CCW
Before bothering anybody, I've been Googling this issue for the last three weeks and have not been able to solve the issue, so must reach out for help.
My son has done multiple Arduino projects after having a Creation Crate subscription, and now we're working on a project together.  We bought a 28BYJ-48 stepper with driver, and figured it'd be just a question of copy-and-paste coding and we'd be in business.
I've tried the Arduino library, the AccelStepper library, countless other sketches from various websites and for some reason the stepper only vibrates when it's supposed to turn CCW.  There was one sketch we were using that used Serial Monitor to enter in the number of steps, and when i'd do a minus number of steps, it'd go CCW, but the next day no longer would!  I thought this was a motor or driver issue, but we've bought three more motor/drivers and still have the same problem.  In researching an answer, I've seen some people say to switch IN 3 & 4 but I still get same results.
We've been connecting 8 to IN1, 9 to IN2, 10 to IN3 and 11 to IN4.  Using a separate 5V power supply to the driver which is also grounded to the Arduino (have tried both ground pins just in case that makes a difference, but no).  We've also tried changing for another Arduino and this hasn't made a difference either.
we've tried multiple sketches from multiple sources, here's one as an example:
#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}

The Serial Monitor will state that it's turning CCW, but it isn't.  Any help would be much appreciated!  What we thought would be a simple step in our project has become a major roadblock!

which driver are you using?

one of the problems lies here figured it'd be just a question of copy-and-paste coding ..... the only time you should be copy-pasting is when you truly understand the code that you are copying and you are 100% sure that there are no errors .............. maybe you can start by activating the stepper motor windings one after another using digitalWrite()with a 1 second pause between steps .... that should make the motor move between steps

this appears to address your issue https://www.instructables.com/id/BYJ48-Stepper-Motor/

I'm using a ULN2003 driver board, thanks!

then look at the instructables.com page

I can confirm that it works witch switched wires, 2,4,3,5 worked for me.

I had this issue myself, when I tried to use these stepper motors (which are to be honest really crappy ones, but very cheap). Vibrating mostly means, that the phases of the motor are not activated in the correct order. These motors seem to work with an activation pattern for half steps (I don't know, if the motor is really doing half steps with this, because I didn't counted them for a whole revolution. But at least they worked). The Stepper library (I assume from your code, that you are using this one) isn't meant for this driver, so it will turn on the phases in a wrong order and always two phases at the same time (as for full steps).
I had success, when driving the 4 phases of the driver with the following pattern (for half steps):
1000
1100
0100
0110
0010
0011
0001
1001

I also found hints on the web (on a german site, just for reference, if you can read german), that - despite being meant for half steps - you can drive the motor with full steps with the Stepper library as well. You would have to change the order of pins in the definition of the stepper:
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);

This assumes the wiring as: D8->IN1, D9->IN2, D10->IN3, D11->IN4. Note, that using full steps means 2048 steps per revolution.

I also found a library specific for this stepper motor, but I haven't tested it: Stepper_28BYJ_48

Now you can decide yourself, which way you want to go. I personally would go for the full steps with the official Arduino Stepper library.

About the number of steps per revolution: I don't know, why the stepper doesn't work with a vale of 2048. But since the library only uses this to wrap up the correct phases for the revolutions, you can use a lower value, that is dividable by 4. For example 32, which is the number of full steps per revolution of the actual motor (it is attached to gears with a factor of 64). That should work.

Thanks for the input- indeed changing the pin order to 8,10,9,11 did the trick.  Oddly enough however, when I change variable for the steps per revolution from 200 to 2048 (the true number of steps in one revolution for this motor), it chokes and won't turn at all.  200 only turns it about a tenth of a rotation.  I've played with this variable and can change it amp to 660 (about a quarter turn), but any number higher than this and the stepper won't turn at all.  Any thoughts appreciated!

@Matt I edited by answer and added my thoughts about this. I hope, that helps.

Changing the pattern to 8x half-steps did the trick. Thanks!

https://forum.arduino.cc/index.php?topic=549927.0
This guy just flipped IN2 and IN3 and it solved the problem of going forwards and backwards. It worked for me and here is the code.
#include <Stepper.h> // Include the header file

// change this to the number of steps on your motor
#define STEPS 64

// create an instance of the stepper class using the steps and pins
Stepper stepper(STEPS, 8, 10, 9, 11);

int Pval = 0;
int potVal = 0;

void setup() {
  Serial.begin(9600);
  stepper.setSpeed(200);
}

void loop() {

potVal = map(analogRead(A0),0,1024,0,100);
if (potVal>Pval)
  stepper.step(10);
if (potVal<Pval)
  stepper.step(-10);

Pval = potVal;

Serial.println(Pval); //for debugging
}

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


text:
How to change speed of multiple servos acting at the same time with PCA9685 module?
I'm using the PCA9685 module with its Adafruit library. In my code I have one object of the servodriver class that has 14 channels (controlling 14 servos basically).
void Positioning(){
  ServoDriver.setPWM(right_foot, 0, MapRotation(rotations[0],"1"));
  ServoDriver.setPWM(left_foot, 0, MapRotation(rotations[1],"2"));
  ServoDriver.setPWM(right_calf, 0, MapRotation(rotations[2],"1"));
  ServoDriver.setPWM(left_calf, 0, MapRotation(rotations[3],"2"));
  ServoDriver.setPWM(right_thigh, 0, MapRotation(rotations[4],"1"));
  ServoDriver.setPWM(left_thigh, 0, MapRotation(rotations[5],"2"));
  ServoDriver.setPWM(right_pelvis, 0, MapRotation(rotations[6],"1"));
  ServoDriver.setPWM(left_pelvis, 0, MapRotation(rotations[7],"2"));
  ServoDriver.setPWM(torso, 0, MapRotation(rotations[8], "1"));
  ServoDriver.setPWM(right_shoulder, 0, MapRotation(rotations[9], "1"));
  ServoDriver.setPWM(left_shoulder, 0, MapRotation(rotations[10], "2"));
  ServoDriver.setPWM(right_arm, 0, MapRotation(rotations[11], "1"));
  ServoDriver.setPWM(left_arm, 0, MapRotation(rotations[12], "2"));
  ServoDriver.setPWM(right_hand, 0, MapRotation(rotations[13], "1"));
  ServoDriver.setPWM(left_hand, 0, MapRotation(rotations[14], "2"));
}

All the function positioning does is just set all the servos to a certain position (they're in a humanoid robot and so this position is for standing). The array rotations[] just contains the servo positions from 0 to 180 which is set elsewhere in the code for each servo respectively. The second argument for map rotation just maps it between the servos pulse min and max values (115 and 560) in normal order or reverse depending on number.
My question is how do I change the speed of the servos? I cannot use delay() or loops because wouldn't that cause all the servos to turn sequentially instead of all at once. a change in any rotations[] value indicates the robot is moving and so how do I make the servos slower instead of turning at their fastest to the new rotations[] positions whenever they are changed (as positioning() is called in the loop() function)?

You cannot simply change the speed of a servo. You can only move step my step to the desired position, waiting inbetween. So for example instead of directly moving from 0° to 90°, you can first move to 5°, wait a bit, move to 10°, wait a bit, move to 15°,  wait a bit,... until you reached 90°. You can also go in 1° steps to make it smoother.
You can solve this with delays, but if you want to move the servos at different speeds, you will need a non-blocking coding style like in the BlinkWithoutDelay example of the Arduino IDE (it was described countless times at this site and on the web).
Also, when building a humanoid robot, at some point you will have to consider not only the pose, that you want the robot to reach, but also the way to get there. This can be very important and it can be a complex task. Basically you need formulas for the movements, which return you the exact position for Dach servo at any given time in a movement. Then you can set the servos to this value for the current time.


text:
Serial Moniter is repeating output
I do apologize for the constant posts on here.  However I ran into an issue and I cannot seem to find any solution to it.  The goal is to enter a username, through the Serial.read function, and if the username matches it simply responds "Welcome Steven", and lights a green LED, when the wrong username is submitted it responds "Access Denied" and lights a red LED.  So far the code works in response to access granted, and access denied, while also lighting the appropriate LEDs.  However the Serial Monitor does not wait until there is a user input, it automatically starts repetitively "access denied" and lights the red LED.  When the username is entered the red LED turns off, the green LED turns on, and Serial Monitor repetitively responds "Welcome Steven".  I can do this multiple times, and each time it will change state.  I have looked at many tutorials and read many posts on here concerning issues, but so far nothing has worked out. Even tried making changes NickGammon suggested in another post.  Would like to get rid of the repetitive issue, and wait for user input before access denied or granted appears.
int led1 = 9;
int led2 = 10;
String user_name;

void setup()
{
  Serial.begin(9600);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  Serial.println("Enter Username");
}

void loop()
{
 if(Serial.available())
   user_name = Serial.readStringUntil('\n');
{

if(user_name == "Grantham1")
{
  Serial.println("Welcome Steven");
  digitalWrite(led1, HIGH);
  digitalWrite(led2, LOW);
}
else if(user_name != "Grantham1")
{
  Serial.println("Invalid Input");
  digitalWrite(led1, LOW);
  digitalWrite(led2, HIGH);
}
else
{
  Serial.println("Waiting Pateintly");
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
}
}
}

your code is badly formatted .... indentation is not what it should be .... that makes it very difficult to follow the program flow ..... please correct the formatting and the cause of the problem may become apparent at first glance

@jsotola i edited the code, hope its better.  Also for some reason I tried a separate code (for some reason would only accept 4 char lines for an array instead of the 9) but when i tried to re-upload this one, it quit working on me.  Still repetitively saying "access denied" but when i enter "Grantham1" it will no longer read it,

i do not understand how you  are able to run this code .... it has errors and does not compile as a result

@jsotola That could be why it stopped working for me properly after I had uploaded a different code.  Every time I compile a new code now, my error window will flash orange, but complete the compile.  I managed to build a shorter and much more simpler code for this program, but still having the same issue with the Serial Monitor.  Ill update the code through edit.

Change
if(Serial.available())
    user_name = Serial.readStringUntil('\n');
{

to
if(Serial.available()) {
    user_name = Serial.readStringUntil('\n');

Edit: The reason why it didn't work properly was because all subsequent ifs were evaluated repeatedly regardless of whether there was anything new in the serial buffer or not. The modification fixes that problem.

It did work thank you. I thought I had all the necessary {} in there.  Im a little surprised it didnt give me a compiler error for lacking them while uploading.

@Steven The if (statement) command; is completely valid in C++ and the stand alone block { commands; } is also perfectly valid in C++

@Steven, accept the answer if it works now

@Juraj Accepted the answer, I apologize for taking so long to do so.

@KIIV Im intermediate in C++ probably why im having so many issues with coding in the Arduino.  Wish i could just write with Python that language made so much more sense to me.


text:
Increase and Decrease Motor Speed
I'm a newbie on Arduino and I'm doing an exercise about the Motor controller
"Increase the motor speed from zero to maxium (255) and then decrease slowly from the maximum to the minium."
Here's my code. I don't know whether it's true or not. So, can anyone help me to check it and give me some advice how to do better on Arduino ?
int i;
void setup()
{
   pinMode(motor, OUTPUT);
}

void loop()
{
   for (i=0; i<=255; i++)
   {
   analogWrite(motor, i);
   }

   for (i=255; i>=0; i--)
   {
   analogWrite(motor, i);
   }
}

I also have one other problem :D that I don't know what will happen if I set the analogWrite value to 300.
Thank you so much.

@per1234 Per, why unclear?

It's unclear because there is no question in it, just a "check my code please"...

"check my code please" is a valid question according to https://arduino.stackexchange.com/help/on-topic

It won't work, as you don't give it any time to do anything. The PWM works about 1kHz and motor needs much more time to start rotating. And you are sending values as fast as possible (it means microseconds for every analogWrite)
And analogWrite(300) without changing the Arduino default settings means it overflows to value 300 % 256 = 44. All Timers are set near to 1kHz and 8bit resolution by Arduino core.


text:
Solenoid "vibrates" instead of pushing
I'm using my Arduino Uno to control a 5V 1A solenoid.
I'm using an N-Channel MOSFET linked to the Uno's 0 pin to switch the solenoid on and off. It is protected by a Schottky diode. Initially, I tested the circuit with the blink example sketch (just set to blink Pin 0 instead of Pin 13). I used the Uno's built in 5V 500mA output and the solenoid "blinked" on/off perfectly at whatever interval I wanted:

I plan on controlling multiple solenoids in a future version, which will draw more current than the Arduino output can supply, so I bought a 5V 12A power supply. I proceeded to test it with my single-solenoid set up using the same blink example sketch:

When I power the solenoid with my 5V 10A my power supply, the solenoid doesn't push on command. It merely "vibrates," travelling only about .5mm at several hundred Hz. The solenoid vibrates constantly the moment I plug in the power supply, and does so completely independently of whatever interval I have set it to "blink."
Any ideas as to what may be causing this to work with the Arduino's built in power supply, but not with an external power supply? I've tested the voltage on my power supply, and it reads 5V as advertised. I'm somewhat new this, and feel like I may be missing something obvious.
Thanks,
Max

https://majenko.co.uk/blog/importance-sharing-grounds

From your schematics it looks like:

you connected the power supply backwards (on both schematics actually, I wonder how come you did not fry your Arduino)
the external supply and the Arduino do not share a common ground as they should.

Edit: about the orientation of the power supply:

the (−) side of the supply (and GND of the Arduino) should be connected to the source of the N-MOSFET
the (+) side of the supply should be connected to the cathode of diode (the side identified by the small white bar)

Could you please elaborate on what you mean by the power supply being connected backwards?


text:
Does a normal Ultra-Sonic sensor (HC SR04) sense through a Football Net like obstacle?
I am planning to to use ultrasonic sensors mounted on a drone for obstacle avoidance. I am not sure if the sensors would be capable of detecting a Net Like obstacle in its path.

Most likely it will not sense the net

There is always a chance of picking up the net for a split second, but most likely, you will never accurately detect the net with this type of sensor. There is too little to detect.


text:
Adafruit Trinket M0 persistent storage?
I am using an Adafruit Trinket M0 to program a small game and would like to save the game state every so often. I am programming it through the Arduino IDE as the chip does not have enough space to run my game with circuitpython (too many libraries). Does the Trinket M0 have any form of persistent storage that I can use, or will I need to use a different device?
I couldn't find EEPROM in the documentation, but I wasn't able to find a definitive answer whether or not it has any form of long term storage. Knowing the board is based on the Attiny85 I would expect it to have 512 bytes or so, but the arduino library is giving me problems when I try to use it as well, so there is no way for me to trial and error this.

Add a i2c eeprom to store data. There is a 'emulation' eeprom that writes to flash memory. I don't know the current status of that library. I don't know if that works with the trinket and I don't know if that has been added to the arduino eeprom library. https://github.com/cmaglie/FlashStorage The adafruit trinket m0 is not based on a attiny chip. Please add this link to your question: https://www.adafruit.com/product/3500

The M0 boards use a SAMD chip. It has no EEPROM. To store data without additional hardware like external EEPROM or SD card, you can use the flash memory of the SAMD. But it has a drawback of limited count of writes to flash memory.
An EEPROM emulation library exits. It uses the flash memory, so the drawback of limited writes, applies. I used it, it works. The library is almost official. The author is Arduino's coworker.


text:
How do i fade a colorwipe from off to on in 1 color?
So I want to make the same effect as a colorwipe (like going around in a circle turning leds on till they all turn on) except that instead of going from off to 100% brightness immediately I need it to look more natural by making it fade from off to on gradually to a single color and the LEDS should stay on after the fade on is complete. This is my current code and i cant figure out how to make it fade. everything ive found on google is massively complex to do a simple thing. is it really that complex to accomplish this?
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 24
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);

void setup() {
  strip.setBrightness(2);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  colorWipe(strip.Color(255, 255, 255, 255), 70); //white

}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(50);
  }
}

Do you want them to glow up one after the other or have the next one to start glowing while the previous one hasn't yet reached full brightness?

Note that the "wait" variable is not actually used in your colorwipe function.
The colorwipe function seems to turn them all on in succession. The only thing you need to do is add fading to it.
for(uint16_t i=0; i<strip.numPixels(); i++) {
    for(uint8_t brightness=0; brightness<maxBrightness; brightness++){
       strip.setPixelColor(i, strip.Color(brightness, brightness, brightness, brightness );
       strip.show();
       delay(wait);
  }

See my answer here.
Code from that answer:
/*
 *
 * NeoPixels demo - fades colours (in array) up and down
 *
 */

#include <SPI.h>
#include <NeoPixels_SPI.h>

const unsigned int PIXELS = 8; // Number of pixels in the string

void setup()
  {
  ledsetup();
  } // end of setup

float patterns [] [3] = {
  { 1, 0, 0 },  // red
  { 0, 1, 0 },  // green
  { 0, 0, 1 },  // blue
  { 1, 1, 0 },  // yellow
  { 1, 0, 1 },  // magenta
  { 0, 1, 1 },  // cyan
  { 1, 1, 1 },  // white
  { 160.0 / 256, 82.0 / 256, 45.0 / 256 },  // sienna
  { 46.0 / 256, 139.0 / 256, 87.0 / 256 },  // sea green

};

// number of items in an array
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

void loop()
  {

  for (byte i = 0; i < ARRAY_SIZE (patterns); i++)
    {
    // fade up
    for (byte m = 0; m < 100; m++)
      {
      showColor (PIXELS, patterns [i] [0] * m, patterns [i] [1] * m, patterns [i] [2] * m);
      delay (10);
      } // end of for

    // fade down
    for (byte m = 100; m > 0; m--)
      {
      showColor (PIXELS, patterns [i] [0] * m, patterns [i] [1] * m, patterns [i] [2] * m);
      delay (10);
      } // end of for
    } // end of for each array item

  } // end of loop

thanks! so i just copy and paste this whole thing in and it will work? or do i add it to my existing code? im very new to this.

Also just to clarify i need it to go around in a circle and fill up the neopixel circle. (think like a magic circle).

To use that exact code you need my library. Also the NeoPixels have to have their data pin connected to D11 (digital pin 11) on the Uno.

That particular code fades in the colours shown (red, green, blue etc.) in sequence.

ah i just need white.

ok so @nick gammon your program works but all it does it fade. the lights dont move around the circle at all. i dont know how to make them move in a circle.


text:
Connect to ch340 on MacOS Mojave
I recently upgraded my MacBook Pro to Mojave. Now I'm not able to connect to my Arduino board with ch340g usb-to-serial chip. It is a Arduino board with AtMega 328 and ESP8266 integrated. I downloaded the drivers from the Chinese website for the ch340 and also removed old installations, like some tutorials tell me. I just can't get a /dev/cu.* port (besides the /dev/cu.Bluetooth-Incoming-Port.
I do have an external FTDI usb to serial board. I didn't get to it to try to connect it.
Does someone know how to get the ch340 to work on MacOS Mojave, or as a last resort: use the FTDI to program/monitor the Arduino board?

Ok, this is the solution for me:
remove all old drivers:
sudo rm -rf /Library/Extensions/usbserial.kext
sudo rm -rf /System/Library/Extensions/usb.kext

Now reboot the computer.
And then (very important, because it took me 10 cables to find the right one) use a fully connected cable ;-)
Now I have these ports:
/dev/cu.wchusbserial1410
/dev/cu.usbserial-1410

Sven's answer is 100% correct the fully connected cable is what hung me up for a few hours. Took 6 cables to find the right one.

What do you mean with "fully connected cable"? Is this a specific kind o USB cable or what?

It is a USB cable with also the data lines connected. Most cables you get with phones and devices just have the +5 and GND connected so they don't pass data.

this my problem too.
i found these solutions

mac-usb-serial app
a topic in arduino forum

make sure delete old usb driver in these path
/Library/Extensions/usbserial.kext
and
 /System/Library/Extensions/usb.kext

then install it again download link

When I experienced this problem, installing the latest driver still failed, but when I removed the old drivers and did not install anything new, it worked fine.


text:
How to get the encoder position while the rotary motor is moving
I have a question with encoder and the rotary motor. When the motor is moving, I can't access the position of the motor.  I have run the code separately, it is perfectly fine. But when I combine, these two codes, the motor is able to move but there was no position data.
Any suggestion on how can I get the motor moving and get the encoder position at the same time.
The combined code I have drafted is there:
  #include <Stepper.h>

    const int stepsPerRevolution = 4000;  // 4000 steps for one circle with 10mm increment.
    const int motorPitchPerCircle = 10;     // 10mm per circle for the linear ball screw guide for motor.

    int val;
    int encoder0PinA = 3; // Pin 15 of the cable.
    int encoder0PinB = 4; // Pin 13 of the cable.
    int encoder0Pos = 0;
    int encoder0PinALast = LOW;
    int n = LOW;

    // initialize the stepper library on pins 8 through 11:
    Stepper myStepper(stepsPerRevolution, 9, 8, A3, A5);

    void setup() {
      // set the speed at 60 rpm:
      myStepper.setSpeed(100);
      // initialize the serial port:
      Serial.begin(9600);

      pinMode (encoder0PinA, INPUT);
      pinMode (encoder0PinB, INPUT);
      Serial.begin (9600);
    }

    void loop() {
      // step one revolution  in one direction:
      myStepper.step(6*stepsPerRevolution);
      delay(2000);

       n = digitalRead(encoder0PinA);
      if ((encoder0PinALast == LOW) && (n == HIGH)) {
        if (digitalRead(encoder0PinB) == LOW) {
          encoder0Pos--;
        } else {
          encoder0Pos++;
        }
        Serial.print (encoder0Pos);
        Serial.print ("/");
      }
      encoder0PinALast = n;

    }

You could use interrupts for the rotary encoder

https://arduino.stackexchange.com/questions/40285/problem-with-tachometer-using-attachinterrupt-and-servo/56874

While your delay() function is running, you won't be able to read any data. Suggestion is to use interrupts, which basically guarantee that whenever your pin state changes (low edge, high edge, or any change, feel free to select it), some action will be performed. This action can be reading your encoder position.
Read about it here https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
I am sure it will answer all your questions, it is quite well documented


text:
Why is there no hex file generated when I "build binary output" from the Arduino IDE?
I want to obtain the .hex file from my Arduino sketch. I have followed various guides but there is no .hex file in my output folder.
How can I obtain my hex file?
Here are my preferences:

This is the contents of my output folder

Based on your setting with the URL for esp8266 package and bin file name with "...generic" I assume you want it for esp8266.
esp8266 doesn't use hex format and "Export compiled binary" creates bin. You can upload it with esptool.
For AVR boards "Export compiled binary" generates hex. You can upload it with avrdude.

Ah, good catch :-)

Current versions of Arduino IDE
Use the menu option in the Arduino IDE:
Sketch ► Export Compiled Binary
See post #6 from the thread How to get hex file from arduino files ?:

Well, since it was bumped it's worth mentioning there is a new way to
  do this added in Arduino IDE 1.6.5:

Sketch > Export Compiled Binary
If you are doing this with an example then you will be prompted to save the sketch in another location.
Wait until the sketch has finished compiling.
Sketch > Show Sketch Folder
The .hex file will be in the sketch folder

Here is a screenshot for OS X:

There is no need to fully compile, a simple verify will suffice. From post #10:

Reopen Arduino, and open a sketch of your choice (use the Examples->Digital->Blink if you have no other sketches). Hit the Verify button to compile the sketch. Now, navigate to the build.path folder. You should see a bunch of files including one with a .hex extension.

Older versions of Arduino IDE
If using an older version of the Arduino IDE, from post #12:

Try this if using an older version of Arduino
Taking out HEX file from Arduino in 3 simple steps

Open Arduino IDE
File ► Preferences menu

Find "Show verbose output during " and check the "compilation" box
Locate the preferences.txt file and open it
Add the following line (this is the path to the directory where the hexfile will be stored):
build.path=C:\Users\<username>\Desktop\hexfile

Change the following line
export.delete_target_folder=true

to
export.delete_target_folder=false

Quit the Arduino IDE and restart it.
Now when you compile, the directory specified in build.path will contain the .hex file (along with other files which can be ignored)

did you read my answer?

Yeah, I had upvoted it... but I missed the ESP bit! I need to pay more attention :-)

Hi Greenonline, thanks for your thorough answer. Indeed it was the detail about ESP8266 spotted by Juraj that was the key to my issue, but i really appreciate your effort :)


text:
Can you help me combining these sensor sketches as one in Arduino
I want to combine these three sketches into one.
RAIN SENSOR:
int rainPin = A0;
int greenLED = 6;
int redLED = 7;
// you can adjust the threshold value
int thresholdValue = 500;

void setup(){
  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
}

void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(rainPin);
  Serial.print(sensorValue);

  if(sensorValue < thresholdValue){
    Serial.println(" - It's wet");
    digitalWrite(greenLED, LOW);
    digitalWrite(redLED, HIGH);
  }
  else {
    Serial.println(" - It's dry");
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, LOW);
  }
  delay(500);
}

LIGHT SENSOR:
int ldrPin = A0;
int greenLED = 6;
int redLED = 7;
// you can adjust the threshold value
int thresholdValue = 500;

void setup(){
  pinMode(ldrPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
}

void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(ldrPin);
  Serial.print(sensorValue);

  if(sensorValue < thresholdValue){
    Serial.println(" - light");
    digitalWrite(greenLED, LOW);
    digitalWrite(redLED, HIGH);
  }
  else {
    Serial.println(" - dark");
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, LOW);
  }
  delay(500);
}

SMOKE SENSOR:
int smokeD0 = A5;
int greenLed = 11;
int redLed = 12;
// Your threshold value
int sensorThres = 300;

void setup() {
  pinMode(smokeD0, INPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(redLed, OUTPUT);
  digitalWrite(greenLed, LOW);
  digitalWrite(redLed, LOW);
  Serial.begin(9600);
}

void loop() {
  int analogSensor = analogRead(smokeD0);
  Serial.println(analogSensor);

  // Checks if it has reached the threshold value
  if (analogSensor < sensorThres)
  {
    Serial.println(" - Smoke");
    digitalWrite(redLed, LOW);
    digitalWrite(greenLed, HIGH);
  }
  else
  {
    Serial.println(" - No Smoke");
    digitalWrite(redLed, HIGH);
    digitalWrite(greenLed, LOW);
  }
  delay(100);
}

I want to combine those codes as one with only two outputs:

the greenLED and;
the redLED.

What is your problem with combining them? You haven't asked an actual question

The only issue are the same names for sensorValue, thresholdValue and same pins for red and green led and analog pin A0. All in the first two snippets.

Variable renaming

Rename thresholdValue in the first two sketches to rainSensorThreshold, and lightSensorThreshold respectively, and sensorThres to smokeSensorThreshold in the third sketch.

Rename sensorValue in the first two sketches to rainSensorValue, and lightSensorValue respectively, and analogSensor to smokeSensorValue in the third sketch.

Change the Analog pin
Use A1 (or some other analog input other than A0 or A5) for ldrPin in the second sketch, for example:
int ldrPin = A0;

Consistant LED pins
Use the same pins in the third sketch, as are used in the first two sketches, for the two LEDs and note the change in case:
int greenLed = 11;
int redLed = 12;

to
int greenLED = 6;
int redLED = 7;

Recompile each sketch
To check that the each sketch still works, recompile each one separately.
Combine the code
Finally... Splice the code together appropriately, keeping the three parts separate:

Global variables
setup()
loop()

I've got a problem with this --- int sensorValue = analogRead(rainPin);

Ah, I missed that. I have updated my answer.

Don't forget to upvote :-)


text:
Playing MP3 Shield tracks
I have an MP3 shield on a Arduino Uno. When using "File Player" I can get the tracks to play by keyboard entry with three digits (001-009).
The problem is that I want to use (SFEMP3Shield > examples > MP3ButtonPlayer2) that is looking for files 1-9. Any file numbers other than 1,2,3,4,5,6,7,8,9 doesn’t work. Any suggestions?

Welcome to Arduino:SE.  Please post the code that you are trying to use.  You might find this post on our Meta site helpful: How to ask a good question for Arduino Stack Exchange.

The playTrack function used in MP3ButtonPlayer2 example plays file with name created with printf format "track%03d.mp3". %03d creates a number prefixed with zeros to lenght 3. For example track005.mp3 or track042.mp3 or track999.mp3.
implementation of the playTrack function:
uint8_t SFEMP3Shield::playTrack(uint8_t trackNo){

  //a storage place for track names
  char trackName[] = "track001.mp3";
  uint8_t trackNumber = 1;

  //tack the number onto the rest of the filename
  sprintf(trackName, "track%03d.mp3", trackNo);

  //play the file
  return playMP3(trackName);
}

change it to:
uint8_t SFEMP3Shield::playTrack(uint8_t trackNo){

  //a storage place for track names
  char trackName[13];
  int trackNumber = trackNo;

  //tack the number onto the rest of the filename
  sprintf(trackName, "track%03d.mp3", trackNumber);

  //play the file
  return playMP3(trackName);
}

Thank you, makes sense, but I'm not a programmer, I don't know how to edit the SFEMP3Shield > examples > MP3ButtonPlayer2 to make it work.

put the SD card in a computer and rename the files. You should buy an MP3 player, not an Arduino, if you don't want to code

It's part of a larger program that uses code that I have worked out. This is the only thing I haven't been able to work, although Sparkfun says it should out of the box. It just need to play 3 tracks when things happen. I have renamed the tracks may times. Does the code you gave go on the SD card or into the MP3ButtonPlayer2 code?

it doesn't go anywhere. it is in the library. (and it's a shame for the author of the library, because it should not be coded as it is)

The SFEMP3Shield library is included in the sketch. What am I supposed to rename the tracks to? When I run File Player I get;

Received command: l
Music Files found :
00001: SndoSil.mp3
00002: Stmup.mp3
00003: Blndblt.mp3
I have renamed the files 001,002,003 with no change.

The 5 digit number is not on the SD card. It is generated in file player.

it should be track001.mp3

It’s not, that’s my point.I have renamed it track001.mp3 and somewhere in the upload it appears as track00001.mp3. Sparkfun tech support told me to input two leading zeros and since I proved the shied works they're done and told me to figure it out myself. Do you know how to add two leading zeros @ int8_t track = 0; in the MP3ButtonPlayer2 sketch?

C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp: In member function 'uint8_t SFEMP3Shield::vs_init()':
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp:292:34: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
if(VSLoadUserCode("patches.053")) return 6;

function playTrack will add two leading zeros, if you have the same library. call it as playTrack(1), playTrack(2), playTrack(3),

It needs to add two "ADDITIONAL" zeros. The library is SFEMP3Shield and I have downloaded it from many places and having different dates. here is what I get from "FilePlayer"
Received command: l
Music Files found :
00001: SndoSil.mp3
00002: Stmup.mp3
00003: Blndblt.mp3
00004: track001.mp3
Sparkfun told me that they noticed it was adding additional zeros and to input two additional zeros via keyboard in "FilePlayer"  and it would work which it does but I want to use MP3ButtonPlayer2 which generates it's own number and doesn't work.

The MP3ButtonPlayer2 sketch does call for playTrack(1), playTrack(2), playTrack(3) it should cal for playTrack(001), playTrack(002), playTrack(003) or the SFEMP3Shield library need to be fixed.

the parameter of function playTrack is int. the function builds the name as you see in my answer. read the answer again

I've read your answer several times.I understand the sketch does add two zeros. it needs to add two MORE zeros or the SFEMP3Shield library needs to be fixed.

but SD card supports only 8 characters long names (plus file extension)

from where do you have the library?

The names are 8 characters or less. The five digit number shouldn't be there. I didn't put it there. Like I said, I have downloaded from several places older & newer versions all with the same result. Could you send me a link to where you believe I can get a right one?

https://github.com/madsci1016/Sparkfun-MP3-Player-Shield-Arduino-Library

Thank You, I'll download and replace existing library.

Did it. No change!

so MP3ButtonPlayer2 example doesn't play track001.mp3? is the file a valid mp3 file? or you have some other sketch? if yes, add it to Question

Yes MP3ButtonPlayer2 example doesn't play track001.mp3 that is a valid mp3 file. As explained above it does play using "File Player" when I serial input  0000X.

and you have buttons connected to A0, A1, A2? And when you press button on A2 it prints "B_NEXT pressed, Start Playing Next Track #1" and doesn't play?

Yes, buttons are connected to A0, A1, A2? And when A2 is pressed it prints "B_NEXT pressed, Start Playing Next Track #1" and doesn't play

can you make a small modification to playTrack function in library? change char trackName[] = "track001.mp3"; to char trackName[13];

Where? Examples, keywords, SFEMP3Shield.cpp, SFEMP3Shield.h, SFEMP3ShieldConfig.h, SFEMP3Shieldmainpage.h

SFEMP3Shield.cpp

next you can try to change the parameter type from uint8_t trackNo to int trackNo, because that is right for sprintf.

Okay, I found it in SFEMP3Shield.cpp and can only open in wordpad or notepad When I change it it won't let me save because I don't have administrator permission

uint8_t trackNo to int trackNo is that in the sketch?

I changed uint8_t track =0; to int track =0; in the sketch. No change.

Okay, I opened SFEMP3Shield.cpp with visual studio and changed char trackName[] = "track001.mp3"; to char trackName[13]; No change.

Do you know what this means? C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp: In member function 'uint8_t SFEMP3Shield::vs_init()':
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp:292:34: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
if(VSLoadUserCode("patches.053")) return 6;

variable track is unused. you should change the parameter trackNo

I'm sorry, I don't know what that means.

There is no trackNo in the sketch

the snippet in my answer. first line

uint8_t SFEMP3Shield::playTrack(uint8_t trackNo){ to uint8_t SFEMP3Shield::playTrack(int trackNo){

There is no "trackNo" in the sketch are you referring to somewhere else?

in SFEMP3Shield.cpp playTrack

will not compile. 'uint8_t SFEMP3Shield::playTrack(int)' does not match any in class 'SFEMP3Shield'

sorry, I forgot that it will require change in the .h. I add to answer a modified version of the playTrack function. try this

I'm sorry, I can cut and paste, but I need to know what & where.

from the Answer to SFEMP3Shield.cpp

I don't know what the Answer to SFEMP3Shield.cpp is.

copy/paste from answer, here on SE. my Answer to your Question. I edited it. scroll up

I'm lost, Where is here on SE?

https://arduino.stackexchange.com/questions/57147/playing-mp3-shield-tracks/57148#57148

still lost, I went through that before, you said will require change in the .h.

which we do not make, instead we use the unused variable to have type int. sprintf doesn't like uint8_t

I'm not a programmer, I don't know what any of that means, sorry.

I'm sure I made all the changes you specified with the following result; C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp: In member function 'uint8_t SFEMP3Shield::vs_init()':
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp:292:34: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
if(VSLoadUserCode("patches.053")) return 6;
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp: At global scope:
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp:1025:9:

error: prototype for 'uint8_t SFEMP3Shield::playTrack(int)' does not match any in class 'SFEMP3Shield'
uint8_t SFEMP3Shield::playTrack(int trackNo){
In file included from C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.cpp:9:0:
C:\Program Files (x86)\Arduino\libraries\SFEMP3Shield\SFEMP3Shield.h:691:13: error: candidate is: uint8_t SFEMP3Shield::playTrack(uint8_t)
uint8_t playTrack(uint8_t);
exit status 1
Error compiling for board Arduino/Genuino Uno.

yes. the parameter must be uint8_t. revert this change. the first 'error' is only a warning. it was always there

It seems I'm going in circles, we're right back where we were. Are you able to make the changes you want to SFEMP3Shield\SFEMP3Shield.cpp and give me a link to it so you can be sure it's the way you want it? I still believe the problem is the 5 digit index. Where is that generated?

it is generated in FilePlayer example with SerialPrintPaddedNumber(count, 5 );

I cannot find SerialPrintPaddedNumber(count, 5 ); in FilePlayer example.

I do find it in SFEMP3Shield\SFEMP3Shield.cpp Line 184& Line 621

I would expect the index to change when I change the 5 to 3 but it does not.

Are you able to make the changes you want to SFEMP3Shield\SFEMP3Shield.cpp and give me a link to it so you can be sure it's the way you want it?

in the Answer is the original and the modified version of playTrack function

SerialPrintPaddedNumber is the last function in the sketch. this numbering is nothing general. it is the way the sketch uses to get user's choice

Where is the Answer?

we are commenting it here. scroll up

reloaded SFEMP3Shield\SFEMP3Shield.cpp modified playTrack function from above. No progress, MP3ButtonPlayer2 does everything but play. I asked you before, do you know how to add leading zeros to a string?

yes. the playTrack function does it as you can see in Answer and the SerialPrintPaddedNumber function in FilePlayer example does it too


text:
RGB LED strip 100m

Hello all,
I'm working on RGB LED strip SMD 5050 5m
This all setup is working on 12v 2A with about diagram.
I want to use same connection with 100m of LED strip using Arduino.
Please support regarding this topic.
H/W details :
Arduino uno
Hc-05 bt module
12v 1.2 amp supply
Td140 pnp transistor
SMD 5050 LED strip 60 LED/m

Where do you want the 100m of wire? Between the PSU and the LEDs? Between the Arduino and the transistors? Between the transistors and the LEDs? Between the Arduino and the bluetooth transceiver?

I want to use 100m LED strip

100m of 60LED/m? i.e. 6000 RGB LEDs or 18000 LEDs?

You cannot drive 100m of LED strip from one side. That would be 200A. Even at only 5m I needed to provide the power at both sites to prevent the strip from getting too hot. So you would have to provide power also every few meters into the strip.

there's a limit to how many LEDs you can address w/WS2812, i don't recall, but it's far less than 6000

100 Meters of 5050 SMD strip LEDs will require roughly 120-200 amps. However, you cannot drive a 100 meter strip from a single power supply. The thin copper traces in the LED strip can only handle so many amps before they become too hot (your LED strip would melt like ice cream on a hot summer day). This is why led strips are usually limited to 5 meters (~5A). You would need separated strips and power supplies for the 100 meters worth.
You have the correct idea with your circuit for turning the leds on/off (in fact the wiring is correct) but the transistors you plan on using are the wrong type. To switch the LEDs to ground you would need a low side switch, which would be a NPN transistor. Be careful however, transistors typically switch currents less than 1 amp. For higher power applications I would suggest using a N-channel Mosfet. A quick search on Sparkfun turns up the FQP30N06L, which is capable of handling 30A (with a heatsink, probably less than half without), and is also logic-level, meaning it can be driven with a 5 volt source (Arduino I/O pin).
Keep in mind, whatever current your LED strip draws, the ground switch (NPN transistor, N-Channel MOSFET, relay) must be able to handle the same current.
Good luck with your circuit!


text:
Changing PWM on Arduino Mega, pins 9 & 10 to 20 to 25 KHz
I'm trying to run a Nema 17 motor with a l298N motor Driver for a school project. The issue is that I am running the motor with PWM to avoid overheating of the driver, however the resulting noise at the default frequency is extremely aggravating.
How can I change the frequency for pins 9 & 10 to 20-25 KHz? Any tips tricks and code examples would be highly appreciated (emphasis on code examples).

Fortunately, the timer for PWM on both pins 9 and 10 on the Arduino Mega (but not necessarily other boards) is timer 2, so changing the PWM frequency of one will change the PWM frequency of the other.
You should also check that changing the the timer frequency does not effect any other libraries (eg Servo, from memory typically uses timer 2).
The frequency for the timer is set by the TCCR2B register (bits CS22, CS21 and CS20) see p 185 of the datasheet for the Mega2560 IC http://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf
As far as code goes, try the following (just tested with a small speaker, appears to change to pitch as expected, but I don't have a motor to try it on:
Each line sets the frequency for timer2 (PWM 9 and 10), should be ok to do during setup, and settings will remain. Note that the first line is equivalent to normal default values:
  TCCR2B=(TCCR2B&248)|4;    //prescaler=64, f=977Hz

  TCCR2B=(TCCR2B&248)|3;    //prescaler=32, 1953Hz

  TCCR2B=(TCCR2B&248)|2;    //prescaler=8, 7812Hz

  TCCR2B=(TCCR2B&248)|1;    //prescaler=1 62500Hz

Also check that your motor driver can handle the frequency.

Thanks. That helps a bit but I really need to get to 20-25 kHz. That is the only frequency I've had luck using with this motor and not getting any audible artifacts. Any ideas?

Those dividers and frequencies are based on a 16MHz clock and 256 step PWM range. If you can change the basic processor frequency, that would help, but will probably break a lot of other things.
Changing the number of PWM steps is possible, but not something I've tried. You would need to change the value at which the PWM counter wraps around back to zero. This is normally 255, but if you used prescaler=8 and got the wrap around to occur at 85, you should get 23.4kHz, but your useful PWM range would be 0-84 instead of 0-255 steps.

That helps some but I am still having a lot of difficulty understanding why getting a PWM range at the correct frequency is such a battle. I'm getting ready to look at hardware solutions. Is there really no effective procedure for making these kinds of changes? One that doesn't break other things or restrict functionality?

The short answer to why it's so hard is that 'Arduino isn't designed to do that', and for the most part, it seems most people don't need it. And for pretty much any other language apart from Arduino, you're going to have to deal with tweaking the registers at this level (even to set up PWM to work at all, let alone customise it).


text:
How to connect a MPU-6050 to an Arduino that already has a CNC Shield V3 on top of it?
I have a CNC Shield on top of an Arduino Uno (GRBL pinout) that controls 2 stepper motors through a4988 drivers and it is working like a charm.
Now I want to add an accelerometer to it. From my humble research, the MPU-6050 seems a good pick.
If I purchase stacking headers to lift the CNC shield, can I connect the accelerometer to the unused/reserved A4 and A5 from the Arduino, but power it using CNC's Ground and 5V pins?
I'm open to other approaches if I'm not doing it the proper way.

Minduca, some feedback? you know how SE sites work

Sorry for the delay. I found on the CNC shield v3 the same SCL and SDA pins that you mentioned for the Arduino. Right now I'm gonna test the accelerometer connected directly to it and I comme back later! Thanks ;)

MPU6050 can use only I2C. Those are pins A4 and A5 on an Uno. 5V and ground are 5v and ground, no matter from which pin

Thanks for the info. Altough pins A4 and A5 are available to I2C connection at the arduino, the CNC shield expose these very same SCL and SDA pins and it's simpler to just use them. Same for ground and VCC.

of course, those are the same pins

This may be a bit harder to implement than it might seem. The grbl code uses all but one pin, so you would have to change that in the library. So I checked out the the code for the shield, and under the cpu_map tab it defines the pins. I would first try setting the unused pins to arbitrary values to enable the pins previously used by the code. For instance, if you are not using the Zed axis, try changing
#define Z_STEP_BIT      4  // Uno Digital Pin 4
to something like
`#define Z_STEP_BIT      0`.

This should clear up pin 4 to be setup as a input/output in your main sketch. Another pin definition associated with the Zed axis is
`#define Z_DIRECTION_BIT   7  // Uno Digital Pin 7`

Clear that one out, and you should be able to use pin 7 as an I/O.
I haven't personally tested the code so give it a try. Also just a heads up will probably run into errors while trying to use the MPU6050 library as well as grbl library, the grbl library is a LOT of code (I didn't spend enough time trying to compile so I don't know how much space it's actually using, but it's a lot). You might also run into timer errors as both libraries most likely reconfigure timers to work with each.
I hope this was a bit helpful!

EDIT:
I realized I didn't specify how to exactly free up A5. It has been assigned to the probe in the cpu_map.

MPU6050 uses I2C on pins A4 and A5


text:
Are there any Wi-Fi modules for the Arduino Uno that may connect to an external Wi-Fi Antenna?
I have an Arduino Uno I need to connect to Wi-Fi to make HTTP POST Requests to a Raspberry Pi Web Server.
The Arduino is located only about 30 feet from the AP, but there is a brick wall in the line of sight, and it is in a metal outdoor enclosure. For that reason, I wanted to attach an external Wi-Fi Antenna which would stick out a sealed hole in the enclosure.
I was contemplating using an ESP8266 Wi-Fi module, but it does not look like there is an easy way to attach the antenna.
What would be the best Wi-Fi module to which I could attach an external antenna for an Arduino Uno?

https://robotdyn.com/wifi-d1-mini-esp8266-dev-board-usb-cp2104.html do you see the antenna connector?

@Juraj Thanks. That might be a better option. It's a lot more self-contained, it's cleaner, and I won't need a load level converter.

the same in Uno format https://robotdyn.com/wifi-d1-r2-esp8266-dev-board-32m-flash.html. but I can't recommend it. both, the on-board antenna and the connector are connected. I think, it causes problems and there are no instructions how to cut connection to one of them

on the mini version the external antenna connector is not connected. you would need to re-solder the 0 ohm 'resistor' that connects the on-board antenna to soldering points connecting the external antenna connector

There are variants of ESP8266-based modules which include a connection for an external antenna. The ESP-02, ESP-05 and ESP-07 modules all feature a U.FL socket.
Effectively, they are an ESP8266 mounted on a carrier board with a U.FL socket.
If you already have some code to suit an ESP8266-based module, this will avoid having to rewrite for a different unit.


text:
How to convert this sketch to keep only one if-else statement?
int ldrPin = A0;
int rainPin = A1;
int smokePin = A2;
int greenLED = 6;
int redLED = 7;

// you can adjust the threshold value
int thresholdValue = 500;
int LightSensorThreshold = 500;
int RainSensorThreshold = 500;

void setup() {
  pinMode(ldrPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);

  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);

  pinMode(smokePin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
}

void loop() {
  int lightSensorValue = analogRead(ldrPin);
  Serial.print(lightSensorValue);

  if(lightSensorValue < LightSensorThreshold){
    Serial.println(" - light");
    digitalWrite(greenLED, LOW);
    digitalWrite(redLED, HIGH);
  }
  else {
    Serial.println(" - dark");
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, LOW);
  }
  delay(500);

  int rainSensorValue = analogRead(rainPin);
  Serial.print(rainSensorValue);

  if(rainSensorValue < RainSensorThreshold){
    Serial.println(" - It's wet");
    digitalWrite(greenLED, LOW);
    digitalWrite(redLED, HIGH);
  }
  else {
    Serial.println(" - It's dry");
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, LOW);
  }
  delay(500);

  int smokeSensorValue = analogRead(smokePin);
  Serial.print(smokeSensorValue);

  if (smokeSensorValue < thresholdValue) {
    Serial.println(" - Smoke");
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, HIGH);
  }
  else
  {
    Serial.println(" - No Smoke");
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);
  }
  delay(100);

}

Sure:
Change these int's to byte, none have values more than 255:
int ldrPin = A0;
int rainPin = A1;
int smokePin = A2;
int greenLED = 6;
int redLED = 7;

Take these out of setup(), analog input pins don't need this:
pinMode(ldrPin, INPUT);
pinMode(rainPin, INPUT);
pinMode(smokePin, INPUT);

Take out the duplicates of these lines, pinMode() and turning them off (if LOW is off) only needs to be called once for each
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
digitalWrite(greenLED, LOW);
digitalWrite(redLED, LOW);

Get rid of two the Serial.begin(9600) lines, calling it once is enough.
Within loop(), get rid of the int's. Those variables were already globally declared, you don't need to re-declare them as type int.

how to edit those if else statement as one.

First find the duplicated code.
E.g. the fragment
  int lightSensorValue = analogRead(ldrPin);
  Serial.print(lightSensorValue);

  if(lightSensorValue < LightSensorThreshold){
    Serial.println(" - light");
    digitalWrite(greenLED, LOW);
    digitalWrite(redLED, HIGH);
  }
  else {
    Serial.println(" - dark");
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, LOW);
  }
  delay(500);

is repeated three times.
Then find within the duplicate code fragments, the differences, which are:

the pin number
the value to check against.
the two texts

Then make a new function containing one duplicated code fragment, and replace the differences, by variables which you pass in the function as arguments:
void checkSensor(int pin, int sensorLimitValue, char* okText, char* warningText)
{
  int sensorValue = analogRead(pin);
  Serial.print(sensorValue);

  if(sensorValue < sensorLimitValue) {
    Serial.println(okText);
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, LOW);
  }
  else {
    Serial.println(warningText);
    digitalWrite(greenLED, LOW);
    digitalWrite(redLED, HIGH);
  }
  delay(500);
}

And call respectively:
checkSensor(ldrPin       , LightSensorThreshold, " - light"   , " - dark");
checkSensor(rainSensorPin, RainSensorThreshold , " - it's wet", " - it's dry");
checkSensor(smokePin     , thresholdValue      , " - Smoke"   , " - No Smoke");

I switched the green/red values, because I assume when the value is lower than the limit, the green LED should be on, and otherwise the red LED.
Btw, why not use smokeSensorThreshold instead of thresholdValue to keep it consistent with the other duplicated code fragments?

I've got a problem with those sketches. The greenLED is turned on and when those sensor sense something it will just turn to redLED. The sketch output is those LED is alternating. Can you help me edit my skectch?

I don't understand what you mean exactly, but I now see the Red light is on when the sensor value is too high, maybe you want to switch green and red, I will do it in my answer

You're welcome!

I'd suggested the smokeSensorThreshold yesterday, not sure why OP hasn't used it...


text:
How do I know if my Arduino is connected to my LEDs?
I have an Arduino Uno and a string of WS2811 LEDs. I am still trying to get started on this project, which is creating a Stranger Things wall. I've installed FastLED and uploaded the sample program "Blink" to the Arduino, which appears to upload correctly. However, the lights don't blink.
Notes:
 - When I plug the string of lights into a power source (when disconnected from the Arduino), they briefly light up red and then turn off. I don't know if this means there's something wrong with the power setup. (I don't know if they are supposed to stay on.)
 - Here's a photo of my connection from the Arduino to the LEDs

Here's the setup I'm trying to follow.

Thanks in advance for any help!

The FastLed Blink sketch uses pin 3 as the data pin. Did you change that to 6?

THANK YOU. These noob roadblocks can be so silly. I'm off and running now!

Great. Just in time for Halloween. Make sure you don't plug it in "upside down" q-;

Haha - I'll be careful :)

i was going to say; a flash and red is a good sign, sounds like the pin config is just off...

The sample code sets the data pin to 3, but I was using 6. Noob mistake.


text:
Mac shortcut for next window - IDE 1.8.7 problem
How do I use the keyboard to cycle through Arduino windows on a mac?
In my System preferences, I have (default):
Keyboard -> Shortcuts -> Move focus to next window =  Cmd ⌘   `
It works perfectly in all other programs, but in the Arduino IDE, it only swaps between the last two windows. If I have three(or more) windows open, it is a real pain to find the one in the background.
I am using fully updated MacOS 10.14 and Arduino IDE 1.8.7

That shortcut works for me. Which version of the IDE and OSX are you using?

@VE7JRO: See edit. Have you tried to cycle through three or more windows?

Yes, I am able to cycle through 3 or more windows. I am using an old version of OSX and an old version the IDE.

@VE7JRO: Thank you for your help. I now found that by adding shift (normally used for reverse cycle), I can get all windows.

In MacOS 10.14 and Arduino IDE 1.6.12, cmd` cycles through 5+ IDE windows properly, for me.
Update:

When you upgrade to Arduino 1.8.7,

I won't be. I've tried a couple of its point releases and have given up on it because its launch performance is so p...-poor. Maybe 1.9 will finally fix it.
Sloeber/Eclipse is my serious code-crunching IDE. I keep the A-IDE around for reference and for quick knock-off experiments because it's quick to launch.
Update 2:
The OP asked me to note that he

found that  Cmd ⌘   Shift   `  cycles
  through all windows (maybe in reverse).

Update 3:

In older IDE the reverse cycling with Shift doesn't work?

It works in both directions for me (shifted/unshifted).

My comment is gone. I did not delete it myself - I have no idea what is happening. Could you add the workaround for IDE 1.8.7 - for completeness?

In older IDE the reverse cycling with Shift doesn't work?

Just by trying, I found that  Cmd ⌘   Shift   `  cycles through all windows (maybe in reverse).

So cmd doesn't work on current IDE but cmd shift does? Shift should only change direction.

@Juraj: I do not know why you find it hard to understand, or why you reject a well meant edit. JRoberts and I found the same thing: in the new IDE 1.8.7 cmd+ does not work(as expected) while cmd+shift+ does. Now JRobert has made the change, that collects and completes the answer.

JRobert has only old IDE, he can't confirm your problem with new IDE, where according to you only the reverse cycling works as expected. (you should add the update about reverse cycling to the question)

@Juraj: I can not figure out if you are trolling. Please go ahead and change what you want - I will not be spending more time on this.


text:
How to build a robot that can stop at a certain point using an altimeter
I am thinking about creating a robot that climbs vertically and stops at a certain point. I thought about using an altimiter in order to measure the distance, however, I dont know how to create a code for it. Where would you start with it, can it be done with MATLAB?
Thanks for everything :)

You can use an barometer/air pressure sensor for height, or an acceleromater for relative (height) changes. I don't see where MATLAB comes in.

you are asking the wrong question .... your question should be how do i measure altitude?

Before you consider code, you'll need a way to measure altitude changes. Barometric altimetry (air-pressure based) is probably too crude for the scale of robot you're likely interested in. The change in atmospheric pressure with altitude is (very) appx 1 in-hg/1000ft near sea-level or ~1/2 psi/1000ft. If you want 1 foot altitude precision, you'd need .5/1000 or a pressure measurement good to within 0.0005 psi. A sneeze in the same room could crash your robot! :) ...

... Other means of measurement are likely to be more successful with existing and affordable technologies. If you can work with elevation instead of altitude (height above a surface, like a floor), radar, sonar, or even a sounding line (a fishing line with a weight you drop to the floor and measure how much line you let out) are going to be much easier. You'll need to make these kinds of design decisions before you'll be ready to write code.

have fun playing with the Arduino and some sensors! It is a great platform to learn. For your task, look into the Bosch sensor modules BME280 (pressure with temperature and humidity) or BMP280 (just pressure). You can expect maybe +-1 meter of accuracy. Or check the precision version BME388 that could give you +-50cm. Go to the adafruit shop and try a few of the breakout boards. They provide great library and documentation support.
In order to get absolute altitudes, you need to factor in ambient air pressure. A good source for that are METAR reports issued for aircraft. There are many online sources where you can get the so called altimeter setting for an airport close to you. Airplane altimeters actually just show the altitude above a standard pressure plane, so you need to compensate for whatever pressure the current weather gives you.
For higher precision, you pretty soon have to integrate barometric pressure, GPS altitude, and maybe other sensors, with some serious math. This is where MATLAB fits in.


text:
Bridging the wifi networks on nodemcu: how to set the esp8266 as wifi extender, simplest case
It seems to me that humidity is getting high in one room in the basement in my house. To monitor the situation temporarily, I would like to build a very small wifi-mesh network to exchange these humidity data to a locally installed raspberry pie server. Most of the time the networking would be in idle state, every some 5 minutes sending the humidity sensor data over mqtt to the server.
What is the simplest code that sets up an esp8266 to connect to an existing wifi network and act as an access point and wifi extender a couple of yards further?
I tried this code:
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

const char* ssid = "SSID_Internet";
const char* password = "qaz12345";

const char* newssid = "SSID_Extender";
const char* newpassword = "qaz12345";

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

  // set both access point and station
  WiFi.mode(WIFI_AP_STA);
  WiFi.softAP(newssid, newpassword);

  Serial.print(newssid);
  Serial.print(" server ip: ");
  Serial.println(WiFi.softAPIP());

  WiFi.begin(ssid, password);
  int wifi_it = 0;
  int wifi_status;
  while ((wifi_status = WiFi.status()) != WL_CONNECTED) {
    Serial.println("Trying to connect to wifi");

    wifi_it++;
    delay(500);
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  long rssi = WiFi.RSSI();
  Serial.print("Signal strength: ");
  Serial.print(rssi);
  Serial.println("dBm");
}

void loop(void){

}

It successfully registers the esp8266 to the wifi, sets up an AP, but if I connect to SID_Extender with my mobile phone, the internet traffic is not forwarded further.
There are projects that allows to configure multiple esps in user friendly manner, but I am wondering how to setup such an esp myself.

it's not a router, it's just something hooked up to two networks. I've never been able to get IO from both in such a situation (ap+sta), though i was trying to access an internal server, not internet. The only way i've been able to "bridge" is via a 2nd ESP and serial comm between them, but maybe there's something I don't know...

The esp8266 will not bridge the networks. You can perhaps bridge the communication from your other ep8266 on the TCP level with WiFiServer and WiFiClient. Send the sensor value to middle esp8266 running AP and it sends the value to Raspberry.
With MQTT you could create some MQTT proxy. Receive the data with WiFiServer and forward it with WiFiClient. without parsing or anything, only copying the chars between servers client and local client in booth directions
something like this (not tested):
void loop() {

  if (!serverClient || !serverClient.connected()) {
    serverClient = server.available();
  }
  if (!serverClient || !serverClient.connected()) {
    if (client.connected()) {
      client.stop();
    }
    return;
  }

  if (!client || !client.connected()) {
    if (!client.connect(raspiIP, MQTT_PORT)) {
      Serial.println("Can't connect to MQTT");
      delay(1000);
      return;
    }
  }

  while (serverClient.available() > 0) {
    client.write(serverClient.read());
  }
  while (client.available() > 0) {
    serverClient.write(client.read());
  }
}

https://www.youtube.com/watch?v=NH1rjk3Q_MU this is what most probably you mean. Do you maybe have the nodemcu C code for that?

how do you send and receive the sensor value?

How do I sent the sensor value? Over MQTT. I have a TLS enabled broker on an internal server (raspberry) inside the "home network"

then you could create some mqtt proxy. receive the mqtt message by WiFiServer and forward it with WiFiClient. without parsing or anything, just copying the chars between servers client and local client in booth directions

great idea. Do you think you have an example code for that ready maybe?

I added a  code snippet to answer

nice!!!! (I know I should not write only nice, but I cannot stop myself)

@arthur, did it help?

on the process :-)


text:
UART connection between Arduino Nano and NodeMCU
I'm trying to create an UART connection between a Nano and an NodeMCU, running MicroPython.
Code for trying is meaningless - Arduino says "HI", and ESP8266 should receive and print msg value.
Connections :
Nano Rx --> ESP Tx
Nano Tx --> ESP Rx
Nano USB -- > Mac running repl
ESP USB --> Linux running Arduino IDE
BUT- when I physically connect as described the ESP BOARD freezes, in a way I can't even connect it using repl. Only after disconnecting wires (not only powering off the Nano), ESP unfreezes.
Appreciate any help.

io 1 of esp8266 is RX, io 3 is TX. clear the wiring description

do you connect ground? which esp module you have?

hi @Juraj - Tx on Nano connects to Rx on ESP, and RX on Nano, connects to Tx on ESP

@Juraj no ground is connected. should it ????. connected to a NodeMCU

@Juraj - please explain what to clarify

You can't connect the same Serial to a computer over USB and to a Nano at the same time. Not only because the Nano is on 5 V which disturbs the 3.3 V side of the USB converter.
Disconnect the NodeMCU from computer, try to power it from Nano's 3.3 V pin (not for WiFI) and don't forget to connect ground between the MCUs.
Nano has one Serial, which is connected over USB to computer too. So there too you can't use the USB and RX TX pins at the same time. You could use SoftwareSerial to connect to NodeMCU.
The Nano TX to esp8266 RX should have logic level conversion to not to send 5V to esp8266 3.3V pin.


text:
Where does the sound come from this board?
As the question says, i can't figure out where the sound comes from on this board that i bought, nothing on the manuals and can't see any speaker on the board... It is a "RFID Proximity Entry Door Secure Lock Access Control System"
Thanks.

What component is under the "Remove Seal After Washing" seal? Is it a buzzer?

@VE7JRO Updated the post :)

all you have to do is to put your finger on the component when it is making a sound and you will quickly discover if you are touching the correct component

this is a PCB mountable piezo buzzer. it makes sound in your "RFID Proximity Entry Door Secure Lock Access Control System"

That looks like a piezo buzzer, the component that had the sticker on it. It's likely louder now, with the sticker removed.


text:
Is there a key switch for Arduino?
I am trying to make a launch controller, which will turn on with a key. Like the one in this photo below:

this is not an arduino related question and shopping questions are frowned upon here

Check for example here for a key switch (see picture below).
As you can see it has two pins. If the pins are connected the switch is closed (same like a normal switch). So you can just connect one wire to VCC / 5V and the other via a high value resistor to a GPIO pin and check for LOW or HIGH.
(note: in practice it's possible to use almost any (electric/mechanical) component as long as the number of pins is not too high to be reasonably used by an Arduino).

Re “one wire to VCC / 5V and the other [...] to a GPIO pin”: for reading the state of the switch, you will need either a pullup or a pulldown resistor. You can use the internal pullup if you connect the other end of the switch to GND.

A key switch is just a normal switch. What you do with it depends on how you wire it and code for it.

Sorry I wasn't clear enough. I meant where can I find one and buy it.

Not really well seen to provide buy link here. Any shop that cRry switches should also stock there. Ask your favorite local or online shop.


text:
How to integrate nRF24L01 to esp8266 nodeMCU?
I can't seem to integrate an nRF module to my nodeMCU.
I just want to verify my code but an error message keeps popping up
Below is the sketch:
#include <SPI_Class.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <ESP8266WiFi.h>
#define PIN_CE D4
#define PIN_CSN D3
RF24 radio(PIN_CE, PIN_CSN);

struct package{
  int id = 1;
  int location = 1;
  char timeStamp = "date/time"
};

typedef struct package Package;
Package data;

public int data1=data.id;
public int data2=data.location;
public char data3=data.timeStamp;

byte  address[][6] = "00001"

const char* ssid = "Jino";
const char* pass = "myinternet";

char server[] = "cdgresearch.000webhostapp.com";

WiFiClient client;

int led = 2;

void setup() {
  Serial.begin(9600);
  WiFi.begin(ssid,pass);
  pinMode(led,OUTPUT);
  digitalWrite(led, HIGH);
  delay(500);
  Serial.println("Connecting to: ");
  Serial.println(ssid);
  Serial.print("Connecting");
  while(WiFi.status() != WL_CONNECTED)
  {

    delay(1000);
    Serial.print(".");
  }

  delay(300);
  digitalWrite(led, LOW);
  Serial.println();
  Serial.println("Successfully connected to the network");
  Serial.print("NodeMCU IP Address: ");
  Serial.println(WiFi.localIP());

  delay(1000);

  radio.begin();
  radio.setChannel(115);
  radio.setPALevel(RF24_PA_LOW);
  radio.openWritingPipe(address[0]);
  delay(1000);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(9000);
  sendData();
}

void sendData(){
  Serial.println("Sending Data...");
  delay(1000);
  if (client.connect(server, 80)){
    WiFi.printDiag(Serial);
    Serial.println("Connected to server");
    client.print("GET /tag2.php?");
    client.print("incoming=Id ");
    client.print(data1);
    client.print("&incoming2=Loc");
    client.print(data2);
    client.println(" HTTP/1.1");
    client.println("Host: cdgresearch.000webhostapp.com");
    client.println("Connection: close");
    client.println();
    Serial.println();

    while(client.connected()){
      while(client.available()){
        Serial.write(client.read());
       }
      }
    radio.write(&data,sizeof(data));

    Serial.print("\nPackage: ");
    Serial.println(data1);
    Serial.print("Location: ")
    Serial.println(data2)
    Serial.println(data3)
    data1+=1;
    data2+=1;
    delay(1000);

  }

  else{
    Serial.println("Failed to Connect to server...");
    }

  client.stop();
  Serial.println("Disconnected from Server");
  while(client.status()!=0){
    delay (10);
   }
  }

and this error comes up in the console:

even if I use the #include, still this pops out

The library you're currently using probably doesn't support ESP8266, try using https://github.com/nRF24/RF24. Just as a preemptive measure to avoid issues: 1. Make sure you decouple the 3.3V output - an 1000uF electrolytic capacitor - to GND and + to 3.3V. 2. Do not use ribbon cables, duponts should be okay, soldered is best. 3. When in high noise environment (electric motors etc.) also add a ceramic capacitor to the power rail.

The error is because you don't have that library on your computer.  Correct?

@Avamander I edited the post, still, doesn't seem to work

@JeanoDuhaylungsod Use only one of the libraries at once. Open Examples->RF24->PingPair and build on that.

You also have to make sure your ESP8266 core is up to date. Boards manager allows you to do that.

Your error is: .../packages/esp8266/hardware/esp8266/2.4.2/libraries/SPI/src/SPI.h:1:23: fatal error: SPI_Class.h: No such file or directory...
You have some wrong SPI library there. The original folder packages/esp8266/hardware/esp8266/2.4.2/libraries/SPI doesn't contain src subfolder.

I can confirm that it's possible to connect the two with TMRH20's RF24 library, which seems to be what you are using (judging by the name of the library). I'm currently building something with those very two components.
Instead, the error is that SPI_Class.h can't be found by the IDE. I can't recognize the name either, but if that is from attempting to include SPI to interface with the NRF24L01, you'd want SPI.h instead.

I also tried the #include<SPI.h.> but the same error still pops out

Was that after removing the SPI_Class library, or was it still present?
Also, have you tried with a fresh standalone non-admin install or with odd libraries removed/disabled?

the spi problem's fine now. but is there a way to get in touch with you? I want you're help with my project because you said you're working with similar hardware. If that's ok with you?

I'm glad that I or one of us could help, but I haven't actually gotten that far with this yet. I've gotten one of the test sketches that came with the library working, so I know it's possible, but I haven't done anything else yet. Aside from that, it's for a college project (and I have many other classes at the same time), so I need to devote my time to getting that working and I don't have much time to help with another.

I should mention that in my case, it still only works some fraction of the time and tends to crash on me; I think there's some place in the library that tends to hang when using an ESP8266. I'd love to hear about other peoples' experience; it could also be that my chips are counterfeits...

I reinstalled Arduino IDE and the libraries that I need, it works fine now. It must be because someone used my laptop and installed some rfid libraries which caused some problems in the libraries folders.


text:
Why does attaching Nokia 5110 LCD make my otherwise fine MKR1000 disconnect USB after 15 secs?
This problem just started after 3 days of working on a project.
I am using Arduino IDE in Windows 10.
When I go to upload "Blink," everything works fine. I connect the USB (sometimes I have to change the port from COM6 to COM5) and upload and it blinks. All good. Well, one weird thing: sometimes I'll upload Blink when it's COM5 and then after the upload I'll notice that the Arduino has switched to COM6. So I have to go in and manually update the Port.
But after I switch to whichever Port has MKR1000 listed on it and go to upload my other more complicated program that uses WiFi and the Nokia 5110 LCD, it seems to throw the Arduino for a loop. All of a sudden it either won't upload properly or say port cannot be found and starts disconnecting from the port about 15 seconds after I connect it, and I'm not able to upload anything.
Anyone have any clues what might be going on? Thank you.
Adding some information about the connections from NOKIA 5110 (also using a breadboard in between):
RST: to pin 6  on MKR1000
CE: to pin 4 on MKR1000
DC: to pin 7 on MKR1000
Din: to pin 3 on MKR1000
Clk: to pin 5 on MKR1000
VCC:to VCC on MKR1000
BL: to VCC on MKR1000
GND: to GND on MKR1000

The MKR board connects to computer over native USB support of the MCU. The handling of the USB is done by Arduino core functions linked at build to your sketch.
A consequence of using the native USB port is, if your sketch has a problem, it influences the USB communication. In this case you can activate the bootloader to handle the USB port and the upload. It is done by double clicking the reset button on board.
This applies to other SAMD boards (Zero, M0) and to AVR boards with native USB port (Leonardo, Micro) too.

I've tried doing that and still run into the same problems. The error says: "Port name - COM6; Method name - openPort(); Exception type - Port not found."

the reset changes USB port. set in IDE the first port that the board usually uses. if the upload doesn't start do the double reset again while the IDE attempts to upload. the bootloader waits after reset for upload almost 10 seconds

Are you powering MKR1000 via USB? That only gives you about 1/2 amp of total current. I wonder if you're exceeding the available current of your power source. Add up the peak current requirements of your Arduino, (with WiFi active) the LCD, etc.


text:
how to increase the range of KY-005?
I am using a KY-005 with an Arduino Uno. I have the knowledge that Arduino can provide a forward current of 40 mA. How can I make it to 55 mA or above upto 60 mA to unlock its full potential, so as to get efficient IR communication without data being distorted at the KY-022 IR receiver?

First, I think 40 mA to output from a GPIO is not a wise idea, because those are Arduino Pin Current Limitations.
What you can do is:

The VCC pin can handle 200 mA. So you can use this pin to power your KY-005 and use a transistor to switch it via a GPIO (much less than 40 mA is needed for that).
Or (high likely not needed): use an external power source and use a transistor in the same way.

For knowing all details about using a transistor this way, google for "transistor as switch".


text:
Pull-down resistor value for interrupts
I wonder how to calculate pulldown resistor to make interrupt work?
I need to connect 5 buttons to A0 and get pressing event via interrupts.
Using different resistors, finally, I made work only 4 buttons. On 5th interrupt does not fire.
Currently I use the following resistors for the buttons:
R1      Vout
0       5,00
2,7K    4,45
5K      3,70
10K     2,77
22K     1,78

And Pulldown Resistor = 22K.
If pulldown Resistor = 10K I can get event for 1-3 button only.
Looks like the voltage 1,78V is quite low.
But I’d liked make it work with 1V at most.
I use RISING mode.
PS. Arduino Nano

An Arduino running at 5V needs at least 3.0V on the pin to read it as rising high.  You probably want to go a little more than that.  So that means your lowest voltage has to be like 3.3V or so.
Note that the analog pins don't have an external interrupt, you'll have to use pin change interrupts and then read with analogRead in the ISR.  So you can't use "RISING".  The pin change interrupts act on any edge.  So they'll trigger when falling as well.
That's a pretty poor way to handle these buttons.  Normally one would just poll buttons like this.  If your loop takes so long that you might miss a human pressing a button then perhaps you should look at that instead.


text:
WS2812B LED Stripe going crazy with Arduino and External Power Supply
I have a simple connection here:

A WS2812B 5m 300 leds strip 5V;
A Power Supply MS-150-5 150W 5V;
Arduino with a simple code to blink 10 first leds;

TEST:
If I connect my power supply to my LED with a wireless controller with some saved presets, everything works fine. Colors, red, blue, white ( some voltage downhere ), but ok, working.
If take off the wireless controller and connect the LED to the Arduino, GND,+5, DATA, with a simple code, it's ok, 10 leds blinking, working fine.
BUT if I connect only the data to Arduino and connect the power to my power supply, now all the stripe go crazy, show no sense colors.
The Arduino code is ok, voltage is ok. Power supply is big enough. Even say to blink only one light is turning on all leds.
I was with a differente power supply before, same but 70w and was working ok. Now with 150w is not working. Why is not working with this one that is bigger? Maybe any noise ?
I'm connecting the power supply directly to the LED and only using the Arduino Data.

So... you don't connect the grounds together?

The Arduino GND and the power supply? No.

Well there is your problem, they need a common ground forthe signal to get through correctly.

Tks guys. I'm using the USB power for the Arduino and the external power supply for the LED. I'll try to use all the same source power and post here the result.

the source need not be the same, and usually isn't, the ground (aka common) needs to be, well, common.

Just make sure the Gnd from the Arduino and power supply are connected together - otherwise it would cause a common issue. Another recommendation would be to include a capacitor, usually a size of 1000uf is recommended.

Tks! Now is working like a charme. Was the GND between Arduino and the Strip.

Tks for reply guys. Thats correct. I have connected the GND of the external power supply with the GNC of Arduino and everything is fine.


text:
Circuit diagram for ACS712 and ZMPT101B with ESP8266 using ADS1115
This is probably a cry for help for a circuit diagram which involves connecting ESP8266 with ADS1115 with ACS712 and ZMPT101B(voltage sensor). Since both of them uses analog pins, and using a diode separator is not a proper idea in real-life. Therefore I ended up using the ADS1115 for more analog pins, which should be working fine. I am not a electrical engineer so I am having real trouble as to how to fix all Four of them together. Can any one help me with a circuit diagram for this? Any links or research papers links, etc. Thanks

I hope you have modules not bare chips. Add links. The ADS1115 use I2C a.k.a. Wire to communicate with MCU. Default Wire pins on esp8266 are io 5 SCL and io4 SCA. I recommend to use this pins. Of course te module needs 3.3 V and ground.

If you can make your comment as an answer then I will mark it.

The ADS1115 use I2C a.k.a. Wire to communicate with MCU. Default Wire pins on esp8266 are io 5 SCL and io4 SCA. I recommend to use this pins. Of course the module needs 3.3 V and ground.

Step one is to get the ADC working.  Once that is done everything else will fall pretty much into place.
The ADC you have chosen is an I2C device.  The ESP8266 doesn't have I2C as such, but it does provide a software-emulated I2C implementation.  This can be used on any pair of pins, but the default ones are GPIO4 for the data (SDA) and GPIO5 for the clock (SCL) (this corresponds to the Arduino Uno using pins A4 and A5 for I2C, so it should be easy to remember).
Once you have that working the wiring for the rest is the same as for any other system. The only thing that differs is that your analogue inputs are on the ADC chip, not the main module.
Here's a block diagram to get you started:

simulate this circuit – Schematic created using CircuitLab
This is assuming:

Single voltage output from each of your sensor modules
I2C pullup resistors provided by either ESP8266 or ADS1115 (add your own if not)
All modules providing the required support components for the chip

ok, sorry i was inactive on this post, I did reply a comment to Juraj, dont know who deleted that.. Thank you so much for the circuit, I have been able to follow Juraj's instruction and come up with a circuit of my own. But your schematics help a lot as I am now confirmed that my circuit is correct. Although I am having another problem.But I will ask later, Thank you so much for the Help.

Majenko, can you share your code please

@LêHùng What makes you think I went to the effort to write any code? This is just a block diagram to show how it works.


text:
How to connect Sparkfun M6E Nano UHF Rfid reader and ESP8266 NodeMCU 0.1
I am using an ESP8266 NodeMCU v0.1 and Sparkfun M6E Nano UHF Rfid reader. How to connect NodeMCU to M6E Nano UHF Rfid reader?

did you see my answer?

sorry for late reply, yes i saw your answer.

@Juraj can you tell me that is there any way to post an array (20 byte) using nodemcu on MySQL data base which is on my localhost. because i am getting my RFID tag id into an array! Like this
FF, DE, 3E, X, X, X....... till 20 bytes

it is possible, but that is a different question. you would need to have a server on a computer to write the data to MySQL. and you would send data from esp8266 to this server.

Thanks, yes i already have a server(xampp) on a computer. Could you provide the resource/link that how to insert array into a single cell of database?

Yes i had insert  the temperature sensor data into a MySQL database using nodemcu, but don't know how it could be done for an array!!

The interface of Sparkfun M6E Nano UHF Rfid reader is Serial TTL. So you should connect it to Serial pins of the NodeMcu. Don't use USB then, because it is connect to Serial too.

worked fine with Arduino Uno when I am trying to use with Uno+Rfid reader+NodeMcu it doesn't work!

how did you wire it to nodemcu?

Like this
(Reader->NodeMCU),
GND ->GND,
VIN->VIN,
RST->RST,
2->D2,
3->D3,

this answer above says you should connect it to RX and TX

use the pins on the short side of the reader board, VCC, Gnd, RX and TX and connect to Gnd, 5V, Rx and TX of NodeMcu

https://learn.sparkfun.com/tutorials/simultaneous-rfid-tag-reader-hookup-guide/all#hardware-hookup

You are saying about TX/RX pins which are used for Arduino Shield, not for FDTI.

it is not only for FTDI. it is Serial. and you need Serial. With Uno, you used pins 2 and 3 with SoftwareSerial. you can't do that with NodeMcu. you could connect the NodeMcu to pins 0 and 1, but why. those are the same RX and TX pins as 'for the FTDI'