text:
Cant upload sketches
I started using the arduino as a hobby and it really is quite fun. I took a break for a bit and when I came back I wasnt able to upload a sketch to my UNO. I checked to see if I was using the correct port and programmer and everything seemed fine. Not exactly sure what to do so I was hoping someone could help me.
Thanks in advance.
Here is the error message I receive every time I try to upload a sketch:
Arduino: 1.8.13 (Windows 7), Board: "Arduino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\User\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\User\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\User\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10813 -build-path C:\Users\User\AppData\Local\Temp\arduino_build_36096 -warnings=none -build-cache C:\Users\User\AppData\Local\Temp\arduino_cache_693101 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avrdude.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -verbose C:\Users\User\Desktop\Arduino\Blink\Blink.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\User\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\User\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\User\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10813 -build-path C:\Users\User\AppData\Local\Temp\arduino_build_36096 -warnings=none -build-cache C:\Users\User\AppData\Local\Temp\arduino_cache_693101 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avrdude.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -verbose C:\Users\User\Desktop\Arduino\Blink\Blink.ino

Using board 'uno' from platform in folder: C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3

Using core 'arduino' from platform in folder: C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3

Detecting libraries used...

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\sketch\\Blink.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

Generating function prototypes...

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\sketch\\Blink.ino.cpp" -o "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\preproc\\ctags_target_for_gcc_minus_e.cpp" -DARDUINO_LIB_DISCOVERY_PHASE

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

Compiling sketch...

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\sketch\\Blink.ino.cpp" -o "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\sketch\\Blink.ino.cpp.o"

Compiling libraries...

Compiling core...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Using previously compiled file: C:\Users\User\AppData\Local\Temp\arduino_build_36096\core\core.a

Archiving built core (caching) in: C:\Users\User\AppData\Local\Temp\arduino_cache_693101\core\core_arduino_avr_uno_cac111a68e84b6e7f84741aaeecd4f29.a

Linking everything together...

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.elf" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096\\sketch\\Blink.ino.cpp.o" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/core\\core.a" "-LC:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096" -lm

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.elf" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.eep"

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.elf" "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.hex"

"C:\\Users\\User\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-size" -A "C:\\Users\\User\\AppData\\Local\\Temp\\arduino_build_36096/Blink.ino.elf"

Sketch uses 924 bytes (2%) of program storage space. Maximum is 32256 bytes.

Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

Hope you will be able to help

It's a generic communications error between the Arduino and your PC, there can be many reasons for this, going through the steps outlined in Juraj's link above may get you closer to the cause. Another thing worth trying is holding down the Arduino reset button until uploading starts then releasing it.

Still nothing.  I tried everything except trying a new computer or arduino because I only have one of each.  I'm thinking of ordering a new Arduino. Still deciding if it should be another UNO or maybe a Micro or Nano. Thank you so much for helping.


text:
MQTT connection not being recognised in void loop()
I am trying to publish MPU 9250 readings in the Adafruit IO sending the data from ESP32. The WiFi connection is being established, but the code is not going inside the if(mqtt.connected()) inside the void loop() whereas it's going inside the same command inside the void setup().
I am sure there are no connection issues because once I change if(mqtt.connected()) to while(mqtt.connected()) inside setup(), code is going inside the while loop continuously.
Why is the code not going inside the if command and how can this be solved?
#include <WiFi.h >
#include <Adafruit_MQTT_Client.h>
#include <MPU9250.h>

#define wifi "********"
#define password "********"
#define server "io.adafruit.com"
#define port 1883
#define username "*******"
#define key "********"

WiFiClient esp;
MPU9250 IMU(Wire,0x68);
Adafruit_MQTT_Client mqtt(&esp, server, port, username, key);
Adafruit_MQTT_Publish feed = Adafruit_MQTT_Publish(&mqtt, username"feeds/accelerodata");

void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.println("Adafruit MQTT Demo");
  Serial.println("Connecting to");
  Serial.println(wifi);
  WiFi.begin(wifi,password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting...");
  }
  Serial.println("Connected");
  Serial.println("IP Address: ");
  Serial.println(WiFi.localIP());
  Serial.println("Connecting to MQTT");

  if (mqtt.connect()) {
    Serial.println("MQTT Connected");
  }
}

void loop () {
  Serial.println("Test line to check if code reaches inside loop");
  delay(1000);

  if (mqtt.connected()) {
    int data=IMU.getAccelX_mss();
    Serial.println("\nSending accelero data");
    Serial.println(data);
    Serial.println("....");
    if (feed.publish(data)) {
      Serial.println("Success");
    } else {
      Serial.println("Fail");
    }
    delay(800);
  }
}

I believe there should be a / betweeen the username and the "feeds/..." portion in your feed definition. I.e.: Adafruit_MQTT_Publish feed=Adafruit_MQTT_Publish(&mqtt,username"/feeds/accelerodata");

I think it should not matter as long as they are inside "   ". Anyways I tried changing that too...

It does matter because username and the quoted string form a (longer) single string. Adafruit IO uses the first part of the string (up to the first / ) to identify the individual users using their service. The part after the first / is used to find the feed you (as an Adafruit IO user) have defined yourself. Look at the examples provided with the Adafruit IO library. They all use the /.

I believe your problem is that you are attempting to use the MQTT connection before it's actually connected.  So your check:
if(mqtt.connected())

is always FALSE since it's not really connected.  The Adafruit library information here:
Adafruit MQTT
Says to initialize MQTT as:
// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
  int8_t ret;

  // Stop if already connected.
  if (mqtt.connected()) {
    return;
  }

  Serial.print("Connecting to MQTT... ");

  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       Serial.println(mqtt.connectErrorString(ret));
       Serial.println("Retrying MQTT connection in 5 seconds...");
       mqtt.disconnect();
       delay(5000);  // wait 5 seconds
  }
  Serial.println("MQTT Connected!");
}

Thanks for the link.. But the connection is not being established. The above function outputs "connection failed". What could be the possible issues? How to troubleshoot the problem

Did you use the correct username and key? Try some of the example code from the Adafruit IO library.

If you have a free Adafruit IO account, also take care not to exceed the maximum data rate (30 data points per minute).

The key is correct.. In-fact the collection frequency was higher initially(higher than 30 points per minute) which I reduced. No improvement in the state though.

source: Stack Exchange

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

sort: votes


text:
What's the best way to operate a remote control circuit board?
What would be the best way of using an Arduino to operate the pictured remote control circuit board? My initial instinct would be to leave the batteries in the remote and use a separate transistor for each of the five switches, connecting wires (solder or electrical tape) to the two sides of each button and the base to an Arduino output pin. I'm certainly not an expert, so I wanted to confirm whether (a) that would work and (b) if there's a much better way. The control is normally powered by two AAA batteries.

Edit: There's also a small capacitor on the underside of the circuit board, if that changes anything.

Thanks in advance for your help
Note: I've tried to simply record and emit the IR signals from the remote using my Arduino, but have thus far been unsuccessful, so want another way of using the Arduino to control my fan: Unable to control fan with IR circuit despite capturing and reproducing the IR transmissions

All the right sides of the buttons are connected to the negative of the battery (that is ground). So you connect the remotes GND to the Arduinos GND.
Next solder five wires to the left side of the buttons. You can do this by scraping away a bit of the green solder mask that's on top of the trace going to that button pad. Or find out which pin on the IC goes to the button, and solder a wire to that leg.
I wouldn't mess with the black stuff (graphite?) on top of button pad. That way you can always return the remote to it's original function.
Then connect those wires to the Collectors of NPN transistors. The Emitters all connect to GND. The Bases (via a resistor) to the Arduino pins.
Alternatively, you can connect them directly to the Arduino pins. But you'd have to be careful to never set the pin to HIGH, as the remote won't like 5V on it's input pins while it is itself running on only 3V. You "press" the button by setting the pin to OUTPUT. After a "press" you set it back to input.
To prevent accidentally supplying 5V to the button pin, you can also use diodes (instead of transistors described above). Put the diode between the Arduino pin, and the button wire, pointing towards the Arduino. That way current can only go towards the Arduino. Then you can safely use digitalWrite.

Thanks so much for the detailed response @Gerben! I don't have time to wire it up tonight, but plan to tomorrow.
Also, I can't believe that I forgot this before, but there's a capacitor on the underside of the circuit board (added a picture to the main post). Does that change anything?

No. The capacitor is across the batteries. It smooths out the voltage.

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


text:
ESPTOOL not recognizing ESP32-S2 chip for SPIFFs transfer
I have a spiff file that uploads fine using a regular esp32, but when I try on the esp32-32, with a fresh installation, I get:
esptool.py v3.0-dev
Serial port COM3
Connecting....
A fatal error occurred: This chip is ESP32-S2 not ESP32. Wrong --chip argument?
SPIFFS Upload failed!
Any ideas??
Thanks

you forgot to show the executed esptool command in question

Arduino does it for you, but I also tried: esptool.py -chip esp32s2 -port COM3 -baud 115200 write_flash -z ox110000 filename.spiffs.bin

maybe you have to specify the S2 for the spiffs tool

I tried, but no luck

Look at the espressif documentation here: https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-guides/build-system.html#selecting-idf-target and see if this provides a workable solution. MN

Actually we are at v3.1, cannot you upgrade to it? Maybe it's a bug..

Is the missing double dash?
esptool.py --chip esp32s2 --port COM3 --baud 115200 write_flash -z 0x110000 filename.spiffs.bin


text:
how to control 2 sensor and 3 relay with fuzzy
i'm using fuzzy to decide how long the relay on pump on and i got some trouble for it he just looping on relay how should i do thats my code
    //---------Fuzzy 2.1 prelauch----------

//-----iNPUT SETPOINT-------
float inputec;
float inputph;

//----INPUT ERROR---------------
float ph;
float hasilec;

//----------fuzzy declare-------------
#include <Fuzzy.h>
Fuzzy *fuzzy = new Fuzzy();

//----fuzzy input Error pH-----
FuzzySet *LN        = new FuzzySet(-2, -2, -1.5, -1);
FuzzySet *FN        = new FuzzySet(-1.5, -1, -1, -0.5);
FuzzySet *SN        = new FuzzySet(-1, -0.5, -0.5, 0);
FuzzySet *ZERO01    = new FuzzySet(-0.5, 0, 0, 0.5);
FuzzySet *sp        = new FuzzySet(0, 0.5, 0.5, 1);
FuzzySet *FP        = new FuzzySet(0.5, 1, 1, 1.5);
FuzzySet *LP        = new FuzzySet(1, 1.5, 2, 2);

//----Fuzzy input error EC----
FuzzySet *N6       = new FuzzySet(-2, -2, -1.8, -1.6);
FuzzySet *N5       = new FuzzySet(-1.8, -1.6, -1.6, -1.4);
FuzzySet *N4       = new FuzzySet(-1.6, -1.3, -1.3, -1);
FuzzySet *N3       = new FuzzySet(-1.2, -1, -1, -0.8);
FuzzySet *N2       = new FuzzySet(-1, -0.7, -0.7, -0.4);
FuzzySet *N1       = new FuzzySet(-0.6, -0.4, -0.4, -0.2);
FuzzySet *ZERO02   = new FuzzySet(-0.4, -0.2, 0, 0);

//----Fuzzy Output phD-----
FuzzySet *ZERO1       = new FuzzySet(0, 0, 0, 2);
FuzzySet *SEBENTAR1     = new FuzzySet(10, 20, 20, 30);
FuzzySet *SEDANG1       = new FuzzySet(20, 30, 40, 50);
FuzzySet *LAMA1         = new FuzzySet(40, 50, 60, 60);

//---Fuzzy Output phU------
FuzzySet *ZERO2        = new FuzzySet(0, 0, 0, 2);
FuzzySet *SEBENTAR2    = new FuzzySet(5, 10, 10, 15);
FuzzySet *SEDANG2      = new FuzzySet(10, 15, 20, 25);
FuzzySet *LAMA2        = new FuzzySet(20, 25, 30, 30);

//---Fuzzy Output ABMIX------
FuzzySet *ZERO3         = new FuzzySet(0, 0, 0, 2);
FuzzySet *SEBENTAR3     = new FuzzySet(20, 40, 40, 60);
FuzzySet *SEDANG3       = new FuzzySet(40, 60, 80, 100);
FuzzySet *LAMA3         = new FuzzySet(80, 100, 120, 120);

//---------- EC declare---------------
#include <Wire.h>
#include "DFRobot_EC10.h"
#include <EEPROM.h>
int EC_PIN = A2;
float voltage, ecValue, temperature = 25;
DFRobot_EC10 ec;

//-----------PPM declare --------------
#include <EEPROM.h>
#include "GravityTDS.h"
#define TdsSensorPin A1
GravityTDS gravityTds;
float temperatureppm = 25;
float tdsValue = 0;

//--------------pH declare---------------
#include <Wire.h>
#include <EEPROM.h>
float ph_H;
int pHSense = A0;
int samples = 5;
float adc_resolution = 1024.0;

//---------POMPA-----------
int pump1 = 5;
int pump2 = 6;
int pump3 = 7;
float pompa1;
float pompa2;
float pompa3;
unsigned long prev_pump1    = 0;
unsigned long prev_pump2    = 0;
unsigned long prev_pump3    = 0;
unsigned long initiate_start = 0;
int pump_state1 = false;
int pump_state2 = false;
int pump_state3 = false;

//-------Deklarasi Fungsi--------
#include "Fuzzy_Rules.h"
#include "Fuzzy_Set.h"
#include "PH.h"
#include "TDS.h"

void setup()
{
  Serial.begin(9600);
  //----FUZZY INITIATE-------
  sets();
  rules();

  //-----PH INITIATE---------

  //-----PPM INITIATE----------
  Serial.begin(115200);
  gravityTds.setPin(TdsSensorPin);
  gravityTds.setAref(5.0);  //reference voltage on ADC, default 5.0V on Arduino UNO
  gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
  gravityTds.begin();  //initialization

  //-----Pin Output-----
  pinMode(pump1, OUTPUT);// Ph Up
  pinMode(pump2, OUTPUT);// Ph Down
  pinMode(pump3, OUTPUT);// AB-MIX

  //---normally open------
  digitalWrite(pump1, LOW); // Ph Up
  digitalWrite(pump2, LOW); // Ph Down
  digitalWrite(pump3, LOW); // AB-MIX

}

void loop()
{
  //-------------Fungsi Read sensor-----------
  hasilppm();
  ph_s();

  ph = inputph-ph_H;
  hasilec = inputec - tdsValue;

  Serial.print("pH    ");
  Serial.print(ph);
  Serial.print("  ");
  Serial.print("EC ");
  Serial.print(hasilec);
  Serial.println("");
  Serial.print(ph);  Serial.print(" ");
  Serial.print(hasilec);   Serial.print(" ");
  Serial.println(" ");

  fuzzy->setInput(2, hasilec);
  fuzzy->setInput(1, ph);
  fuzzy->fuzzify();

  float pompa1 = fuzzy->defuzzify(1);//pHDOWN
  float pompa2 = fuzzy->defuzzify(2);//pHUP
  float pompa3 = fuzzy->defuzzify(3);//ABMIX

  //-----------PUMP ALGORITHM--------------------
  long int pompa01 = pompa1*1000;
  long int pompa02 = pompa2*1000;
  long int pompa03 = pompa3*1000;

  unsigned long intiate_start = millis();

  //pompa1
  if(intiate_start-prev_pump1 > pompa01)
  {
    pump_state1 = !pump_state1;

    if(pump_state1)
    {
      digitalWrite(pump1, HIGH);
    }
    else
    {
      digitalWrite(pump1, LOW);
    }
    prev_pump1 = initiate_start;
  }

    //pompa2
  if(intiate_start-prev_pump2 > pompa02)
  {
    pump_state2 = !pump_state2;

    if(pump_state2)
    {
      digitalWrite(pump2, HIGH);
    }
    else
    {
      digitalWrite(pump2, LOW);
    }
    prev_pump2 = initiate_start;
  }

    //pompa3
  if(intiate_start-prev_pump3 > pompa03)
  {
    pump_state3 = !pump_state3;

    if(pump_state3)
    {
      digitalWrite(pump3, HIGH);
    }
    else
    {
      digitalWrite(pump3, LOW);
    }
    prev_pump3 = initiate_start;
  }

  Serial.println("Result= ");
  Serial.println("");
  Serial.print(" Pompa1 pHDOWN: ");
  Serial.println(pompa01);
  Serial.print(" pompa2 phUP  : ");
  Serial.println(pompa02);
  Serial.print(" pompa3 ABMIX : ");
  Serial.println(pompa03);
  Serial.println("");
  Serial.println("");
  Serial.println("");
  delay (2000);

}

im using NO on my relay thx for helping me
my library

https://www.codepile.net/pile/4Nvovokl [Fuzzy_Rules.h]
https://www.codepile.net/pile/96x8EO6y [Fuzzy_set.h]
https://github.com/DFRobot/DFRobot_PH  [PH]
https://github.com/DFRobot/GravityTDS  [TDS]
Fuzzy.h its eFFl library

some library its a standar library for using censor

what is the problem? ... it is unclear what this means ... just looping on relay ..... also, what is the code supposed to do?

Link to the library please.

@jsotola its just a looping on relay not on the censor and fuzzy for reading and calculating again

@EdgarBonet its to long i think

that is my logic
Logic-->
Set pompa1,2,3 to zero
Get fuzzy values
Clean up - make zero if equal or under 0.67-->
Check if any pumps need to run-->
Convert the run time in milisecs-->
Get the present time in milisecs-->
add that to the runtime for each pump-->
Turn the pumps on that need to turn on-->
Find the longest run END time of all the pumps-->
Loop in while for the longest pump run time-->
Turn off pumps as they reach end time--->
but its not get the off just looping on pumps--->

Please, edit your question, and add a link to the particular library you are using. Do not worry about the URL being long.

okay no problem

Please, do not re-publish the code of the library. Instead, add a link to the existing official Web site. It has a Web site, right? Or did you author the library yourself and never published it? Or did you get it on a floppy from a friend?

like fuzzyrules and fuzzy set im minimalize using my library but the some library like TDS and ph from another site let me check it again

Its done maybe like that


text:
LCD shows wrong value from MQ-135 sensor and the txt is stuck on screen
i am using a MQ-135 gas sensor and 20x4 LCD screen and it shows different values on the serial
monitor it shows 756 PPM and on the LCD screen it is stuck below 320PPM the text BAD is also stuck on the screen and doesn't update on the
lowering of PPM value of CO2

this is my code
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define sensor A0
int gas, co2lvl;
#define updateDisplay();

void setup()
{
pinMode(sensor,INPUT);
Serial.begin(9600);
lcd.begin(20,4);
  lcd.clear();
}

void loop()
{
co2lvl=gas-255;
co2lvl=map(co2lvl, 0,1024,400,5000);
Serial.print(co2lvl);
Serial.print("ppm");
Serial.println();
delay(200);
if(co2lvl>=699){
updateDisplay();
lcd.setCursor(0,0);
lcd.print("CO2 IN THE AIR");
lcd.setCursor(0,1);
lcd.print(analogRead(co2lvl));
lcd.setCursor(6,1);
lcd.print("EXCELLENT");
}
else if(co2lvl<=700){
updateDisplay();
lcd.setCursor(0,0);
lcd.print("CO2 PRESENT IN THE AIR");
lcd.setCursor(0,1);
lcd.print(analogRead(co2lvl));
lcd.setCursor(4,1);
lcd.print("GOOD");}
else if(co2lvl<=900){
  updateDisplay();
  lcd.setCursor(0,0);
lcd.print("CO2 PRESENT IN THE AIR");
lcd.setCursor(0,1);
lcd.print(analogRead(co2lvl));
lcd.setCursor(5,1);
lcd.print("FAIR");}
else if(co2lvl<=1100){
  updateDisplay();
  lcd.setCursor(0,0);
lcd.print("CO2 PRESENT IN THE AIR");
lcd.setCursor(0,1);
lcd.print(analogRead(co2lvl));
lcd.setCursor(5,1);
lcd.print("MEDIOCRE");
}
else(co2lvl<=1600);{
  updateDisplay();
  lcd.setCursor(0,0);
lcd.print("CO2 PRESENT IN THE AIR");
lcd.setCursor(0,1);
lcd.print(analogRead(co2lvl));
lcd.setCursor(5,1);
lcd.print("BAD");}
}

use CO2 level in the air to get better fit on the display ... CO2 level is probably enough

You made a mistake in the line:
else(co2lvl<=1600);

Because of the semicolon (;) it will not do anything for that condition. But instead the following lines will be executed always.
The following is a slight refactoring making your code more clear, removing also duplicated code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define sensor A0
int gas, co2lvl;

void setup()
{
  pinMode(sensor,INPUT);
  Serial.begin(9600);
  lcd.begin(20,4);
  lcd.clear();
}

void loop()
{
  co2lvl=gas-255;
  co2lvl=map(co2lvl, 0,1024,400,5000);
  Serial.print(co2lvl);
  Serial.print("ppm");
  Serial.println();
  delay(200);

  lcd.setCursor(0,0);
  lcd.print("CO2 PRESENT IN THE AIR");
  lcd.setCursor(0,1);
  lcd.print(analogRead(co2lvl));

  if      (co2lvl <=  300) { show(6, "EXCELLENT"); }
  else if (co2lvl <=  700) { show(4, "GOOD"     ); }
  else if (co2lvl <=  900) { show(5, "FAIR"     ); }
  else if (co2lvl <= 1100) { show(5, "MEDIOCRE" ); }
  else if (co2lvl <= 1600) { show(5, "BAD"      ); }
}

void show(int position, char* text)
{
  lcd.setCursor(position, 1);
  lcd.print(text);
}

thank you a lot

You are welcome... if it helped you please upvote the answer, and if the answer is correct to solve your solution, accept the answer (by clicking the checkmark next to the answer). Good luck with your project.


text:
Multiple peripherals using SPI with a Mega
I am using a Mega 2560 and 2 x AD9833 programmable waveform generators.
The AD9833's use a SPI protocol and I have used vwlowen's code as a jumping off point (I'm not usng the display just the generators). I added a channel variable to select the slave device.
It all works fine until I try to add a second AD9833. I saw this post about more than 1 peripheral using SPI & a Mega, that says I can use any pin for slave selection (SS) but the following code only ever works if I use pin 53. The upshot if which is that I can send the same data to both i.e. both share the same SS pin as long as that pin is 53. Any other SS pin selection is ignored by the devices. I tried pin 49 for both & no change, I''ve tried 53 & 49 yet only the device on 53 changes.
So what's going on here? What's so special about pin 53 that it cant be replicated by another output pin?
/*
Amended code for AD9833 Waveform Module originally from vwlowen.co.uk
Common SPI terminology & pinout on AD9833
MOSI - DATA
SCLK - CLK
SS   - FSYNC
MISO - not implemented i.e. ther is no MISO pin on the AS9833
*/

#include <SPI.h>

const int SINE     = 0x2000;                // Define AD9833's waveform register value.
const int SQUARE   = 0x2028;                // When we update the frequency, we need to
const int TRIANGLE = 0x2002;                // define the waveform when we end writing.

const float refFreq = 25000000.0;           // On-board crystal reference frequency

const int FSYNCA = 53;                       // Standard SPI pins for the AD9833 waveform generator.
//const int FSYNCB = 49;
const int CLK    = 52;                       // CLK and DATA pins.
const int DATA   = 51;

unsigned long freq = 1000;                   // Set initial frequency.

void setup() {

  pinMode(FSYNCA, OUTPUT);
  // pinMode(FSYNCB, OUTPUT);

  SPI.begin();
  SPI.setDataMode(SPI_MODE2);
  delay(50);

  AD9833reset();                                   // Reset AD9833 module after power-up.
  delay(50);
  AD9833setFrequency(freq, SQUARE, FSYNCA);        // Set the frequency and Sine Wave output
 // AD9833setFrequency(freq, SINE, FSYNCB);

}

void loop() {

// TODO: PC control via USB

}

// AD9833 documentation advises a 'Reset' on first applying power.
void AD9833reset() {
  WriteRegister(0x100, FSYNCA);   // Write '1' to AD9833 Control register bit D8.
  delay(10);
 // WriteRegister(0x100, FSYNCB);
 // delay(10);
}

// Set the frequency and waveform registers in the AD9833.
void AD9833setFrequency(long frequency, int Waveform, int channel) {

  long FreqWord = (frequency * pow(2, 28)) / refFreq;

  int MSB = (int)((FreqWord & 0xFFFC000) >> 14);    //Only lower 14 bits are used for data
  int LSB = (int)(FreqWord & 0x3FFF);

  //Set control bits 15 ande 14 to 0 and 1, respectively, for frequency register 0
  LSB |= 0x4000;
  MSB |= 0x4000;

  WriteRegister(0x2100, channel);
  WriteRegister(LSB, channel);                  // Write lower 16 bits to AD9833 registers
  WriteRegister(MSB, channel);                  // Write upper 16 bits to AD9833 registers.
  WriteRegister(0xC000, channel);               // Phase register
  WriteRegister(Waveform, channel);             // Exit & Reset to SINE, SQUARE or TRIANGLE

}

void WriteRegister(int dat, int channel) {

  digitalWrite(channel, LOW);         // Set FSYNC low before writing to AD9833 registers
  delayMicroseconds(10);              // Give AD9833 time to get ready to receive data.

  SPI.transfer(highByte(dat));        // Each AD9833 register is 32 bits wide and each 16
  SPI.transfer(lowByte(dat));         // bits has to be transferred as 2 x 8-bit bytes.

  digitalWrite(channel, HIGH);        //Write done. Set FSYNC high
}

What's so special about pin 53

Pin 53 is the slave select pin of the SPI peripheral. As such it has a bearing on how the SPI peripheral operates.
It is intimately tied to the master/slave operation in that when it's an input SPI works in slave mode, and when it's an output it runs in master mode.
So to use SPI in master mode, whether you use pin 53 or not, it must be in OUTPUT for SPI to work at all.
There is nothing much wrong with your methodology, but one thing is missing: the initial state of the chip select pins.
You should always start with all chip select pins disabled (i.e., HIGH) rather than in an unknown (probably low - I'd have to check the datasheet) state - the exception might be pin 53 which SPI might itself set HIGH for you.
So if you add:
digitalWrite(FSYNCA, HIGH);
digitalWrite(FSYNCB, HIGH);

right after setting the pinMode for your pins and still use both pins 53 and 49 then it should work.

SPI.begin() sets the SS pin (53) as output and HIGH


text:
Adding a common activation pin to a group of buttons
I'm working on an Uno, which has only two interrupt capable pins, but i need at least three buttons to wake it up from its power saving mode.
Is there a way to wire buttons such that, in addition to their individual pin, they will also activate a common pin (in this case, the interrupt one)?

Why not using the PinChange Interrupt instead? That can also wake the Arduino from sleep modes. And it works with nearly every pin. Though you have one interrupt for a group of max 8 pins and you need to check, which button was pressed, inside the ISR.

Thanks! Will this also work while in CPU sleep mode from the avr/sleep.h library?

You could use diodes to "or" multiple buttons together. But in this case I'd go with the pcint solution proposed by chrisl.

You can connect all the buttons to a single interrupt pin by ORing them via diodes (like Gerben wrote in the comments). That would look like this:

simulate this circuit – Schematic created using CircuitLab
The diodes isolate each input pin from the other, but allow the buttons to pull down the interrupt pin.
Though that is not the way, that I would suggest. Instead you could simply use the PinChange interrupt. That is a different type of interrupt, which can react to all pins of a port in a single ISR for the whole port. You can mask unused pins of the port away, so that the interrupt doesn't trigger for them. Nearly every pin is usable that way.
If you want to use the Arduino framework for this, you can just use the attachInterrupt() function, which can use the PinChange interrupt in the background.
If you want to go more down into the hardware side and configure the interrupt yourself, you should look into the corresponding sections of the datasheet. The Uno uses the Atmega328p. From 12.2.4 on you see the registers used for the PinChange interrupt (aka PCINT).

With the bits in PCICR you can enable the PinChange interrupt for the ports (3 distinct interrupts for the Uno).
The PCMSKn (n meaning number between 0 and 2) is used to mask unused pins of the port away. You should set the bits for the used pins to 1, the others to zero.

Then you need to define the actual Interrupt Service Routine (ISR) in your code:
ISR (PCINTn_vect) // handle pin change interrupt for D8 to D13 here
{
    ...
}

Here again substitute the n for the number of the PinChange interrupt, that you are using. Inside the ISR you need to read all the input pins of the buttons, that are connected to this PinChange interrupt, and execute your code accordingly. Note: As the name states, the interrupt is triggered on every change of the pin. Inside the ISR you need to sort out, what change that was. It comes down to just reading the pin, but you should keep that fact in mind.
Also make sure to never do long things inside an ISR; it has to be as short as possible; Do long things inside the main code, which can get triggered via a flag variable from the ISR)
If you google for something like "Arduino pin change interrupt" you can find detailed tutorials for this, which can go way deeper, than I can on this Q&A site.

Will this also work while in CPU sleep mode from the avr/sleep.h
library?

According to Table 9-1 in Chapter "9.1 Sleep Modes" in the datasheet, the PinChange interrupts are on the same level as the External Interrupts INTn in regard of sleep modes. So this should work just like with the INTn interrupts.


text:
DFPlayer Mini with its standard library does not being initialized
I have a DFPlayer Mini bought from AliExpress.
The player works correctly in standalone mode, but I am having troubles while using it with the following components:

Seeduino v4.0;
2GB Smartbuy MicroSD card.

When I try to use this standard sketch for Arduino to connect my Seeeduino V4 to the player:

if I set the serial like mySoftwareSerial(11, 10), the player's tiny LED turns on for 2 seconds, then it switches off, and after that, the board tells me the error message below (video here);
if I set the serial like mySoftwareSerial(10, 11), the player`s tiny LED switches on and remains being switched on, while the board tells me the error message below (video here):

DFRobot DFPlayer Mini Demo
Initializing DFPlayer ... (May take 3~5 seconds)
Unable to begin:
1.Please recheck the connection!
2.Please insert the SD card!

This module's image:

The circuit diagram:

simulate this circuit – Schematic created using CircuitLab
I have tried almost everything I could. I changed the filenames on my SD card, tried to use different pins, tried to use different wires..! I even tried to disconnect the speaker from the player!
I also had seen this message on the manufacturer`s forum:

I found that the solder joint on the TX pin was bridged to the SD card holder, effectively bridging the pin to the ground. Try a continuity test between the TX and ground. If they are connected you have a bad joint.
I was able to remove the excess solder and it worked fine after that. It's a medium difficulty soldering task.

Maybe, it`s my case?

The module functions as a stand-alone player.  If you find a tutorial where someone is controlling it with buttons and you have success with that, you can eliminate any concerns you may have about the sdcard, its formatting,  the sound files, and their formatting.  You can then edit your question to remove those concerns, put the actual code your using, and clear images of the actual wiring.

You didn't show, how you connected the player to the Arduino

@chrisl, edited the question.

@timemage, fixed everything I could

The comment I left suggested you try it without an Arduino, with only the button signals as a diagnostic test to be certain that your file and card formats and names are correct.  Did you in fact do this test?

The player works correctly in standalone mode, @timemage.

You can edit that fact into your question early on, since it will answer a bunch of questions straight off.

You seem to be confused about what the correct TX/RX pin wiring is.  If you aren't confused, then you should remove that from your question.  If you are still confused, then I would recommend convincing yourself by checking the TX and RX pins in question.  With nothing else attached to them, you can measure with a meter.  See what number you get.  Then connect a 1k (or so) resistor from the pin to 5V, see if the number changes significantly.  Try 1K to GND, see if it changes again.  It it doesn't change significantly you're looking at a driven pin, presumably TX; if it does, presumably RX.

Does it look like the manufacturer's connecting instructions are incorrect? Do you think that RX and TX pins are messed up on my DFPlayer or on my Seeeduino?

I don't have specific reason to think that.  I just note that you don't seem sure.  And if it were me being unsure which pin was which, I would perform that sort of test to eliminate that variable in question.

After simply switching RX and TX wires on my Seeeduino, I got the player online! This question is solved.

Please check if the RX/TX pins are messed up. In my case, simply RX and TX wires' places' switching did help!

I simply removed the test for the return value of the constructor and assumed it initialised correctly.  It then ran properly every time I started it.  I have no explanation for this, but it worked.


text:
Remove a sudden pulse on pin d3 of nodemcu when powering it up
I am using node mcu and a 2 channel relay connected to the motor via pin d3.
When I power on the circuit, it shoots a pulse to the relay and i think it will damage the motor.
Please suggest me how to stop that pulse from turning on the motor.

Please share how you have the relay connected to your NodeMCU.  A schematic drawing would be very helpful.

Just use a different pin. Pins D1, D2, D5, D6 and D7 (GPIO's 5, 4, 14, 12, 13) are safe to use with a relay on a NodeMCU.

D3 is GPIO0, which is used as an active low input to signal the ESP8266 bootloader to expect programming after a reset.
Use a different pin.

all esp8266 io pins are pulled up at boot

@Juraj, If that were true, and I'm not sure that it is, it's a non sequitur.  I'm curious as to why you bothered leaving this on a closed question.

pins 4+5 are the only "silent" pins on bootup


text:
Broken USB connection
When I connected an external power supply to my Arduino Uno R3 (it was connected to PC via USB cable too), I heard Windows disconnected device sound and the device isn't visible since then (nothing happens when I plugin the USB). Cable is ok, because it works with the second Arduino. TX/RX LEDs don't blink anymore.
Following this guide, I checked two things:

I was able to flash ATMEGA328 with LED blinking program using external ICSP programmer and it worked
I was able to flash ATMEGA16U2 with the official firmware and it completed without any error

Is there anything else I can check? I'm not really desperate to fix it - I just want to know which component is broken.

Is it possible that the voltage on your external power supply exceeded the limits of the Uno's input?  The range is 6-20V DC with (+) at the center.  If you exceeded 20V or if the polarity was reversed the Uno may be damaged.

Does the power LED come on?

Power supply is 12V. Yes, the power LED is on (both with USB or power supply). The board itself works just fine. The only problem is with missing USB signal.

trace usb lines on arduino board.  could be dead usb-tty chip.

Is it possible you connected the 12V to the 5 volt pin. This would probably blow the port on windows and destroy the arduino but it appears you got lucky with the arduino. Try something else not related to the Arduino stuff after powering down and restarting the windows computer. If that does not work the odds are high the Windows port is blown. If it now is working try again you may be all set.

USB port in PC is ok. I checked it with my 2nd Arduino.

Good Job, I am glad the PC is OK, I am a Linux person so about the only thing I know about windows is I look through them. At this point without the board and proper tools I cannot be of any more help, good luck.


text:
Arduino Leonardo - Setting up bluetooth - AT command from terminal does not return anything
I am trying to setup bluetooth with a board that contains Arduino Leonardo chip.
My full setup is:
The main board: https://www.dfrobot.com/product-1148.html
The base shield: https://coolcomponents.co.uk/products/grove-base-shield-for-arduino-v2
The bluetooth module: https://wiki.seeedstudio.com/Grove-Serial_Bluetooth_v3.0/
The bluetooth module is connected to D8 port of the base shield.
The reason is "not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI)." as explained here: https://www.arduino.cc/en/Reference/SoftwareSerial
Here is the full code.
#include <SoftwareSerial.h>   //Software Serial Port

/*Connect your Bluetooth Module to D8 otherwise it will not work due to Arduino Leonardo */

#define RxD         8
#define TxD         9

SoftwareSerial blue(RxD,TxD);

void setup()
{
    Serial.begin(9600);
    blue.begin(9600); //anything other than 9600 will not work

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

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

    Serial.print("Started\n");
    setupBlueToothConnection();

}

void loop() {
char recvChar;
    while(1)
    {
        if(blue.available())
        {//check if there's any data sent from the remote bluetooth shield
            recvChar = blue.read();
            Serial.print(recvChar);

        }
        if(Serial.available())
        {//check if there's any data sent from t he local serial terminal, you can add the other applications here
            recvChar  = Serial.read();
            blue.print(recvChar);
            delay(400);
        }
    }
}

void setupBlueToothConnection()
{
  //blue.begin(9600);

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

  blue.print("AT+ROLES");  // set the role as slave
  delay(400);

  blue.print("AT+NAMESlave");   // set the bluetooth name as "Slave" ,the length of bluetooth name must less than 12 characters.
  delay(400);

  blue.print("AT+AUTH1");
  delay(400);
  blue.flush();
}

The output from the Serial Monitor (set as BOTH NL & CR, 9600) as follows:
Started
OKOK+Set:SOK+Set:SlaveOK+Set:1

The problem is when I send AT commands from terminal I get nothing in return.
However if I send AT command from the IDE, I am getting feedback from the bluetooth.

get rid of the almost 1/2 second delay in loop() .... also get rid of the while(1) ... loop() is already a while(1)

why do you use SoftwareSerial and not Serial1? use Serial.write(recvChar);. maybe you don't send a line end character to terminate the command

@jsotola - I will need two while loops that is why I left it like that. Reducing it 1 loop and removing delay did not fix the issue. I will be also adding a Zigbee module that is why I used software serial. I have also tried with "Serial1" but nothing changed. Just to clarify - sending AT command via code works such as "Serial1.print("AT"), however if I send it from Serial Monitor nothing returns.

I was going to ask you what exactly you're sending from the terminal, specifically what line termination. But now I see you have no termination on your AT commands in setupBlueToothConnection.  Is this really the code you're testing with?

Yes @timemage it is the exact same code that I am testing.

The issue is fixed.
Note: This is the version includes Serial1 rather than SoftwareSerial. The rest is the same.
Serial.read()

Returns the first byte of incoming serial data available.

So, when I send AT command from terminal, it does send "A" and then "T" rather than "AT" as a string which Bluetooth expects as stated in the product's documentation:

AT Command format: Uppercase AT command format. string format, without any other symbol. (e.g. \r or \n).

Hence, I have added the following function:
String SerialString() {   // Function to generate string from chars sent via Serial Monitor

  String inputString = "";  // to hold the string

  while (Serial.available()) {

    char inputChar = (char)Serial.read(); // get the new byte:
    inputString += inputChar;             // add it to the inputString:
    }

    return inputString;     // returns completed string
}

Then inside void loop():
String WholeCommand = "";
if(Serial.available() > 0){
    WholeCommand = SerialString();
    Serial1.print(WholeCommand);
  }

Now, when I send AT from Serial Monitor, I can get OK from Bluetooth.

This is bizarre to me.  Normally when devices accept AT-commands they will give you all the time in the world to complete the command and completing it means sending '\r'.  I wonder if there isn't a setting that will make this thing behave in a normal way.

I definitely agree your point, this is why I struggled. However in their documentation: link this is how they state it.

I found the reference "Uppercase AT command format. string format, without any other symbol. (e.g. \r or \n)."  For future readers you might put that quote and the datasheet link into your answer.  If it were me, I'd toss this thing and get a different module though.

Included them as you suggested. Unfortunately these are bought in bulk, so I need to figure out the best way to utilise them.

Yeah I understand.  It's good that your question/answer exists and can be found and understood regardless.


text:
RFID reading function returning null
I have a function that reads an RFID card and returns the RFID string. The function reads the string well but I am using the ArduinoJson library to generate JSON.
This is the function that I am using to read RFID cards:
String rfidOku() {
  String kartid= "";
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      kartid.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
      kartid.concat(String(mfrc522.uid.uidByte[i], HEX));
    }
    kartid.toUpperCase();
    //Serial.println(kartid);
  }
  kartid.trim();
  return kartid;
}

And in the loop function, if a button is pressed I am getting an RFID and I am creating json using it.
const size_t capacity = JSON_OBJECT_SIZE(4);
DynamicJsonDocument doc(capacity);
const String str_rfid = rfidOku();
doc["id"] = odeme.id;
doc["fiyat"] = odeme.fiyat;
doc["rfid"] = str_rfid;
serializeJson(doc, Serial);

When I look at serial monitor the RFID field is null. Why does this happen? I tried to write another string there, and it works well with the other string. Why doesn't it work with str_rfid?
I also printed the value of str_rfid using Serial.print, str_rfid is getting the RFID card id from the function well.

Your function create a local variable and return it value at end of the function, a local variable will out of Scope upon exiting the function and no longer available. Furthermore, String object uses dynamic memory allocation in the heap, and get free up when it is out of scope. Read a book about C++ programming and try not to use String object if you are new to Arduino/C++ programming.

@hcheung sir how can fix this, what should i do to fix this problem.

@hcheung: The function returns a String, and that return value is used and present, according to the OP. Variable scope has nothing to do with it.

@ocrdu the function works and returns string, i output it using serial print. It is correct. But when i assign it to doc["rfid"], the in the json output the field is null. I created a string to test String a = "example" i assign it to the doc["rfid"] , in the json i show this value it works well with other strings.

@Enver-Pasha: It could be your JSON object capacity is too small because of string duplication when you deserialise to print it. You could try a capacity like JSON_OBJECT_SIZE(3) + 500 for deserialising, just for testing. Have a look at https://arduinojson.org/v5/assistant/ for more. Also see https://arduinojson.org/v6/how-to/determine-the-capacity-of-the-jsondocument/ . Not sure it is the problem, but worth a try. Also: you could try: doc["rfid"] = str_rfid.c_str(); to see if that works better (CString instead of String object).

@ocrdu Sir tank you so much it worked.

Which one worked?

@ocrdu The second one , doc["rfid"] = str_rfid.c_str();  this worked.

So maybe ArduinoJson doesn't play nice with String objects, or there is some other reason I don't know about. I'll write an answer based on my comment; please accept it (if you accept it 8-).

It could be that your JSON object capacity is too small because of string duplication when you deserialise it to print it.
You should try a capacity like JSON_OBJECT_SIZE(3) + 500 for deserialising, and see what happens.
Also, try: doc["rfid"] = str_rfid.c_str(); to see if that works better (CString instead of String object).
More information on object capacity can be found here; there's a calculator here.


text:
Else Statement Never Functions As Expected
I've been working on a rather simple Arduino-breadboard project, that is supposed to imitate a traffic light intersection. There are two sets of lights, one called the North-South lights, and then the East-West lights (quite similar to the traffic lights your would see at an intersection on the road). The goal is to get the traffic lights to turn their correct colors at the correct times; however, one of my yellow lights is not turning on at all, and the breadboard LEDs I'm using completely skip over the yellow light in question and go straight to the red-green configuratin that is supposed to happen after.
Here is the code I have:
void setup() {

  pinMode(2, OUTPUT); //R-ns
  pinMode(3, OUTPUT); //Y-ns
  pinMode(4, OUTPUT); //G-ns
  pinMode(5, OUTPUT); //R-ew
  pinMode(6, OUTPUT); //Y-ew
  pinMode(7, OUTPUT); //G-ew

}

void loop() {

  for(int count = 0; count<16; count++) {

    if (count<7) {
      digitalWrite(2, HIGH);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      digitalWrite(7, HIGH);
      }

     else if (count==7) {
      digitalWrite(2, HIGH);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
      digitalWrite(7, LOW);
      }

     else if (7<count<15) {
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      digitalWrite(7, LOW);
      }

     else {
      digitalWrite(2, LOW);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      digitalWrite(7, LOW);
      }

    delay(1000);
    }

}

As you can see, the North-South traffic light is supposed to turn on at the 16th second, except I don't see it happen on the physical LED. I don't understand why this is happening; can anyone explain what is happening?

use serial.print() to debug your code

7<count<15 is interpreted as (7<count)<15.  7<count will result in a false or true, which will be interpreted as 0 and 1 when later involved in the < 15 part of the expression, which means 7<count<15 is always true.
What you're probably looking for is 7 < count && count < 15.


text:
I can't find what I did wrong
int lightPin = 13;
int buttonPin = 2

void setup() {
  pinMode(lightPin, OUTPUT); //red
  pinMode(buttonPin, INPUT);
}

void loop() {
  int buttonValue = digitalRead(buttonPin);

  if (buttonValue == HIGH) {
    digitalWrite(13, HIGH);
  }  //red

  digitalWrite(13, LOW);//red
}  //red

Are you getting some sort of error message?  Please provide more information.  Also, please edit your question and use the formatting tools to format the code as code.

why do you think that you did something wrong?

What is going wrong? Only thing I can see is that your LED will only light for a very brief period when you press the button because you immediately turn it off. That is addressed in @rjuzzle’s answer. Or maybe something else is wrong. You have not given any details so we can only guess.

See rjuzzle's answer. Your code will only set the LED pin to high for less than a millisecond on each pass through your loop when the button is pressed - the flickering will be so short that you probably won't be able to see it.

Your question needs work. See how to ask.

In this example your missing a semi-colin after int buttonPin = 2, and your if statement should probably look like this
if (buttonValue == HIGH){
  digitalWrite(lightpin, HIGH);
}//red

else{
  digitalWrite(lightpin, LOW);//red
}//red/*

Also if you go into the examples in the Arduino IDE, under "digital", this sketch is called button.

Assuming the problem is that the LED doesn't appear to light at all, the answer is moving the code that turns the LED off to the else clause as you have shown in your answer. Otherwise the LED will only be lit for less than a millisecond - probably such a short time that it wouldn't be visible to the human eye.


text:
Reading Serial Data sent from PC to Arduino with help of another Arduino
I am trying to sniff the Serial Communication between the PC and Arduino MEGA 2560. For trying to check what my PC is sending to my Arduino. I am using another Arduino MEGA 2560 to read this data since my serial monitor is busy.
To this I have connected RX pin of my arduino to RX Pin of my second arduino and both have common ground. In this way i thought i can use serial monitor of my second arduino to see the data what my pc is sending to Arduino.
But when i upload the program to Arduino, I am getting the following error

avrdude: stk500v2_ReceiveMessage(): timeout avrdude:
stk500v2_ReceiveMessage(): timeout avrdude: stk500v2_ReceiveMessage():
timeout avrdude: stk500v2_ReceiveMessage(): timeout avrdude:
stk500v2_ReceiveMessage(): timeout avrdude: stk500v2_ReceiveMessage():
timeout avrdude: stk500v2_getsync(): timeout communicating with
programmer

I dont have any problems when i use only one Arduino.
One Arduino uses COM Port 4 and other uses COM Port 5. I am not sure what is going wrong. I googled this problem and found few things but none of them were quiet working for me.
The main issue which i am not sure is if i can use Arduino IDE instance twice(one for each arduino with different com port) and check what my pc is sending to first arduino with the help of second arduino.
Can anyone suggest some other alternative on how to see serial data when serial monitor is busy or when we cant use serial monitor?

Can you program them one at a time, with the other disconnected?

@Edgar Bonet I already tried to program one at at time with other disconnected. It worked fine when the other is disconnected and Arduino did what it was supposed to do.

Use a separate program to read the serial data. Something like putty.


text:
Making HTTPS requests using ESP8266 AT commands
I am trying to make HTTPS GET/POST requests to the following server using AT commands.
AT+CIPSTART="TCP","54.166.71.140 ",443

I get errors when i use port 443 but on port 80 the requests are successful.
How can i get around this issue ? what could be potential solutions ?

read the reference, please

are you referring to this docuement ?  https://docs.espressif.com/projects/esp-at/en/latest/AT_Command_Set/TCP-IP_AT_Commands.html

it depends. that is for AT 2.1. for AT 1.7 this https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf

HTTPS requires that you make an SSL connection not a TCP connection.  To do that you need to use
AT+CIPSTART="SSL","54.166.71.140 ",443

You also need to configure SSL itself.
However the SSL support is not great and struggles with some sites (no SNI support by all accounts).
So you're better off programming the ESP8266 directly with your own sketch to make any HTTPS requests and process the data for you.

How do i configure the SSL, is there any reference ?

From the examples I've seen it looks like it's just setting the SSL buffer size. There's configuration commands but I haven't seen them being used.

That solved it :) the buffer size was 2048 by default


text:
Arduino Due: JTAG and SWD do not work after pressing erase button
I have an Arduino Due board. I can successfully upload code to it using Arduino upload via USB.
However I am also exploring another approach, which is to upload code via Atmel studio using an Atmel ICE and JTAG connection. Usually this works fine (the code uploads, and a simple "blink" sketch makes the onboard LED flash).
However when I press the erase button, and then try to upload the same sketch via Atmel Studio and JTAG, something strange happens. The code uploads fine:
Erasing device... OK
Programming Flash...OK
Verifying Flash...OK

But then the program on the Due does not actually execute. The LED does not start to 'blink'. If I then again upload via USB (programming port) and the Arduino IDE, the blink program does work. And when I then upload via Atmel Studio and JTAG again without pressing the erase button, everything happens as expected too (LED blinks etc).
Does anyone have any idea what might be going on? The reason I ask is because I would like to design a board using only a JTAG connection. Do you think the above problem could cause issues when using a 'blank' factory SAM MCU as well?
EDIT: the same problem applies to SWD.
Blink sketch that i am uploading:
#define led LED_BUILTIN

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

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(600);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(600);               // wait for a second
}

After uploading via Microchip Studio, go to the GPNVM bits section of "device programming" window. Make sure boot mode is set to "boot from flash". Also check that GPNVMBITS register is set to 0x00000002. Then press "program". The sketch you uploaded to the MCU should now work.
So it seems what happens is that pressing the erase button resets the GPNVM bits so that the MCU boots from ROM, but then Atmel ICE + JTAG/SWD does not set the boot mode back to flash after (succesfully) programming the MCU.


text:
FastLED-driven strip acts weird when using PN532
A LED-strip (WS2812B, 46 pieces, PIN 8) and an Adafruit PN532 RFID shield (IRQ 2) are attached to my Arduino Mega 2560.
The GRB based strip seems to be working fine with FastLED in the beginning, I can confirm this by cycling through all three base colours in setup().
Once I call nfc.readPassiveTargetID(...) and use an NFC tag on it, things start to get weird. Whenever I comment out the line, it works properly again.
The colors RGB are randomly swapped (as if I had passed a different color ordering), brightnesses may change randomly as well, and sometimes a few LEDs in the beginning or end of the strip have different brightness/color as the rest.
As I have put the brightness down to 32, I'm sure it's not a power problem.
My assumption is that there is either some memory corruption, or some PIN interference with the two libraries, although I don't know why it would do it. Please find my code below, any help is appreciated.
  #include <FastLED.h>
  #include <Adafruit_PN532.h>

  #define LED_COUNT 46
  #define LED_DATA_PIN 8
  CRGB leds[LED_COUNT];

  #define PN532_IRQ (2)
  #define PN532_RESET (3) // Not connected

  Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

  void setLeds(CRGB color) {
    Serial.print("setLeds("); Serial.print(color.r, DEC ); Serial.print(","); Serial.print(color.g, DEC ); Serial.print(","); Serial.print(color.b, DEC ); Serial.println(")");
    for (int i = 0; i < LED_COUNT; i++) {
      leds[i] = color;
    }
    FastLED.show();
  }

  void ledStartSequence() {
    setLeds(CRGB::Black);
    for (int crtLed = 0; crtLed < 23; crtLed++) {
      leds[crtLed] = CRGB::Blue;
      leds[crtLed + 23] = CRGB::Blue;
      FastLED.show();
      delay(20);
    }
    Serial.println("Red");
    setLeds(CRGB::Red);
    delay(1000);
    Serial.println("Green");
    setLeds(CRGB::Green);
    delay(1000);
    Serial.println("Blue");
    setLeds(CRGB::Blue);
    delay(1000);

    Serial.println("Off");
    setLeds(CRGB::Black);
  }

  void initLeds() {
    FastLED.addLeds<WS2812B, LED_DATA_PIN, GRB>(leds, LED_COUNT);
    FastLED.setBrightness(32);
  }

  void initSerial() {
    Serial.begin(9600);
    Serial.println("Hello!");
  }

  void initNFC() {
    nfc.begin();
    uint32_t versiondata = nfc.getFirmwareVersion();
    Serial.print(versiondata);
    if (! versiondata) {
      Serial.print("Error: Didn't find PN53x board");
      while (1); // halt
    }
    // Got ok data, print it out!
    Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
    Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
    Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);

    nfc.SAMConfig();
  }

  void setup() {
    initSerial();
    initLeds();
    initNFC();
    ledStartSequence();
  }

  void loop(void) {
    Serial.println("Waiting for an ISO14443A Card ...");
    setLeds(CRGB::Red); // only displayed correctly in the first iteration
    uint8_t success;
    uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
    uint8_t uidLength;

    success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
    /*
     *  Here's where things start to go nuts!
    */
    delay(1000);
    setLeds(CRGB::Green); // usually not displayed correctly
    delay(1000);
    setLeds(CRGB::Blue); // usually not displayed correctly
    delay(1000);
  }

You have an array uid with 7 bytes. If after nfc.readPassiveTargetID the uidLength value is > 7 you'll have a buffer overflow. Do you know how many bytes the UID of the RFID card containes? Another possibillity is that the PN532 driver uses a timer (e.g. for Hardware I2C) that the LED lib also uses. Then it possibly might help if you reinitialize the LEDs initLeds() after die call to readPassiveTargetID. Both are just guesses.

What happens when after the delay and before setLeds(CRGB::Green); you disable interrupt 2? Or when you don't connect the interrupt line of the RFID shield at all? Just out of curiosity. See https://www.arduino.cc/reference/en/language/functions/external-interrupts/detachinterrupt/

After spending way too much time on the code, I figured that it had to do with something entirely different:
The RFID reader created an RF interference on the data wire towards the LED strip... Shielding it properly did the trick, no matter which pin is being used.
Thanks for the help anyway.


text:
What's wrong? FastLED and WS2812B simulation works, physical build doesn't
I'm new to Arduino coding and FastLED. When it comes to coding, I'm a complete novice, however, I've been watching YouTube tutorials to help my knowledge. I have successfully run my code on Wokwi, however, when I upload my code to my Arduino, it uploads without error, yet the WS2812B doesn't run the code correctly and appears to freeze after the first pattern.
The LED strip works just run with my Adafruit code, running a very basic set of patterns I created (different than the below code).
Any help would be greatly appreciated! The code below is what I wrote up in Wokwi and the simulation works flawlessly. The only change when uploading to my Arduino is: NUM_LEDS  135
#include <FastLED.h>
#define NUM_LEDS  16
#define LED_PIN   5
#define BRIGHTNESS  255
#define caseCount 7
CRGB source1[NUM_LEDS];
CRGB source2[NUM_LEDS];
CRGB output[NUM_LEDS];

DEFINE_GRADIENT_PALETTE (christmasBlue_gp) {
  0, 0, 0, 255,
  64, 0, 0, 135,
  127, 255, 255, 255,
  191, 0, 0, 135,
  255, 0, 0, 255
};
CRGBPalette16 bluePal = christmasBlue_gp;

uint8_t blendAmount = 0;
uint8_t patternCounter = 0;
uint8_t source1Pattern = 0;
uint8_t source2Pattern = 1;
bool useSource1 = false;

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(output, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop() {

  EVERY_N_MILLISECONDS(5) {
    blend(source1, source2, output, NUM_LEDS, blendAmount);
    if (useSource1) {
      if (blendAmount < 255) blendAmount++;
      } else {
      if (blendAmount > 0) blendAmount--;
      }
  }

  EVERY_N_SECONDS(5) {
    nextPattern();
  }
  runPattern(source1Pattern, source1);
  runPattern(source2Pattern, source2);
  FastLED.show();
}

void nextPattern() {
  patternCounter = (patternCounter + 1) % caseCount;
  if (useSource1) source1Pattern = patternCounter;
  else source2Pattern = patternCounter;
  useSource1 = !useSource1;
  }

void runPattern(uint8_t pattern, CRGB *LEDArray) {
  switch (pattern) {
    case 0:
      movingDots(LEDArray);
      break;
    case 1:
      whiteFill(LEDArray);
      break;
    case 2:
      greenFill(LEDArray);
      break;
    case 3:
      whiteFill(LEDArray);
      break;
    case 4:
      redFill(LEDArray);
      break;
    case 5:
      greenBlueTwinkle(LEDArray);
      break;
    case 6:
      greenRedSplit(LEDArray);
      break;
  }
}

void movingDots(CRGB *LEDarray) {
  uint16_t posBeat = beatsin16(30, 0, NUM_LEDS -1, 0, 0);
  uint16_t posBeat2 = beatsin16(60, 0, NUM_LEDS -1, 0, 0);
  uint16_t posBeat3 = beatsin16(25, 0, NUM_LEDS -1, 0, 127);
  uint16_t posBeat4 = beatsin16(45, 0, NUM_LEDS -1, 0, 127);
  LEDarray[(posBeat + posBeat2) / 2] = CHSV(0, 255, 255);
  LEDarray[(posBeat3 + posBeat4) / 2] = CHSV(120, 255, 255);
  LEDarray[(posBeat3 + posBeat2) / 2] = CHSV(120, 255, 255);
  LEDarray[(posBeat2 + posBeat4) / 2] = CHSV(0, 255, 255);
  LEDarray[(posBeat2 + posBeat4 + posBeat) / 3] = CHSV(0, 0, 255);
  fadeToBlackBy(LEDarray, NUM_LEDS, 1);
}

void whiteFill(CRGB *LEDarray) {
  fill_solid(LEDarray, NUM_LEDS, CRGB::White);
}

void greenFill(CRGB *LEDarray) {
  fill_solid(LEDarray, NUM_LEDS, CRGB::Green);
}

void redFill(CRGB *LEDarray) {
  fill_solid(LEDarray, NUM_LEDS, CRGB::Red);
}

void greenBlueTwinkle(CRGB *LEDarray) {
  EVERY_N_MILLISECONDS(50){
    LEDarray[random8(0, NUM_LEDS-1)] = ColorFromPalette(bluePal, random8(), 255, LINEARBLEND);
    }
  fadeToBlackBy(LEDarray, NUM_LEDS, 1);
  FastLED.show();
}

void greenRedSplit(CRGB *LEDarray) {
  for(int i = 0; i < NUM_LEDS; i++) {
    LEDarray[i] = CHSV(0, 255, 255);
    LEDarray[(NUM_LEDS-1-i)] = CHSV(120, 255, 255);
    FastLED.show();
    delay(100);
    LEDarray[i] = CHSV(0, 255, 255);
  }

  for(int i = NUM_LEDS - 1; i >= 0; i--) {
    LEDarray[i] = CHSV(120, 255, 255);
    LEDarray[(NUM_LEDS-1-i)] = CHSV(0, 255, 255);
    FastLED.show();
    delay(100);
    LEDarray[i] = CHSV(120, 255, 255);
  }
}

Does it work with, say, NUM_LEDS 15? Could well be a memory problem.

Good question and suggestion. I'll have to try it when I get home, I'm at work and my Chromebook doesn't support Arduino's IDE.

It might also be that your power supply is not powerful enough (see @st2000's answer). You could try reducing the brightness to reduce power consumption and see if that makes it work more reliably.

I reduced brightness to 100, which didn't solve the issue. However, I broke the code down more.
Ocrdu's suggestion of a memory issue might have been the issue. I removed 3 parts from the blend, so their is only 4 cases running on all 135 LEDs.
My "void greenRedSplit(CRGB *LEDarray)" code appears to have been freezing the Arduino anytime it "ran".

Consider what would happen if your power supply is not powerful enough.  Depending on the number of WS2812B you are lighting at the same time you may be exceeding the current rating of your power source.  Using the following quote from this source:

... consider how much current your LED strip is going to pull. With every
single LED on at full brightness, each breakout board can pull about
60mA (20mA per color channel).

We can calculate for a string of 15 WS2812 set to full brightness it would take 15 x 60mA or almost 1 Amp of power.  People commonly source power supply which can handle twice the expected high current load.  So, in this case you would need a supply which can source at least 2 Amps
Also consider not using the Arduino's linear voltage regulator for large current loads.  Not only does it have current limitations but it is also not as effective as a switching power supply. Instead use a power supply of the correct voltage and capable current rating for large current loads.
Try lighting only 1 LED at a time in the strip and stick to one color at a time.  If this works it is likely your power supply is not capable of supplying the necessary current to operate your project as expected.

Great thought since I would have overlooked this, had it not been for the videos I watched. I made sure I had enough power to run the strip on full bright white prior to the coding.

Another thought - you should avoid usig the Arduino's linear power regulator to power large loads.  Not only does it have current limitations but it is also not as effective as a switching power supply.

It would be very telling if you performed the test described in this answer.  Either result would be interesting.  If it works or if it does not work.


text:
SIM7000E 0 voltage at SIM_VDD
I have problem with my SIM7000E. My PCB scheme and design is aveliable here https://easyeda.com/jaka87/new-vetercek While sending AT commands I get error as if sim card is not connected.
I also put oscilloscope on SIM_VDD and did some measurement. To my surprise i always measure 0V even or reset and when changing from AT+CFUN=0 to AT+CFUN=1.
It should at least send some bursts right ?
Any idea why this is happening?
Scheme:

Please edit your question and include your schematic as an image and your code formatted at "code" in this question.

After weeks i finally found the source of the issue. It turns out i mixed two labels on the PCB and therefore had wrong capacitors on VCC and data...


text:
Which sensor bus best to use?
I am working on a project which requires a dozen VL53l0X I2C-TOF sensors to be polled by one master MCU over a few meters of cable.
Thus, I decided to accompany each TOF by an Atmega8 acting as a gateway between the TOF and a Modbus (using a MAX485), which is managed by an ESP32 (the master). Since I require fairly low latency (~10 reads / sensor / second) I am a bit disappointed by the Modbus RTU performance (mostly caused by the forced 1.75ms delay between frames).
My question: Is there any quicker, more suitable, Atmega-bearable bus protocol for long distances? Ethernet is sadly not an option due to the limited slaves computing power and cost...

MODBUS is just a communication protocol that runs on an existing physical layer - RS485. You don't have to run MODBUS over RS485 - you can run whatever you like over RS485, it's just serial.

CAN for the Phy (physical) layer would be good for several thousand feet. You can use whatever baud and protocol on the CAN layer you like within reason. I am assuming (maybe in error) that they all communicate on the same bus. This CAN Phy was designed for this. It would be possible for you to write your own protocol and simply address each by a unique number or whatever. There is also the option of using a CAN controller but I think that would be a lot of time not needed to design your solution. By placing a Atmega8 at each sensor opens up a lot of possibilities for you.

So, am I understanding it right that each slave would need it's own Object-ID?

Not sure what you are asking. Each simply needs a unique identifier so you can address them individually. You can do an 'all call if' you like. The address can be as simple as A, B, C etc then you can see it on the bus monitor. For example, when you address 'A' it responds with its data. You may have to add a preamble so the slaves know it is a command not data. No suggestions as I do not know what the data stream will look like. Keep It Simple it is much easier to troubleshoot.


text:
What is the advantage of higher priced arduinos to cheaper ones?
I just got an Arduino Mega ADK (which seems to be functional, based on my limited testing and knowledge) at a yard sale for under $5. I don't have any Arduino experience, but I'm into DIYing, so who not try it.
I noticed that this specific board has a noticeably higher price than the other models. That would be, comparing brandname models to others brandname models, OR offbrand to offbrand.
My question is, why would someone prefer the higher priced models over the more simple/cheaper ones? My guess would be power consumption, I/O, capabilities, or processing speed. But I think I heard that the processing speed of the slower boards is already enough to run most projects, or am I wrong?

why different cars, different computers, different phones, different houses ...

You are right in your guesses. The Mega specifically is often used for its many pins and for the 4 hardware serial interfaces. The Pro Micro is often used, because it has a native USB interface (can act as different USB devices) in contrast to the Uno, Nano and Mega. So the different boards have different capabilities, use different microcontrollers, have different forms, and are thus better for one purpose than for the other

People buy the board that does the job they want it to do and provides the support and reliability they need for their project.

the higher price of Mega ADK is because of ADK

Usually because they don't understand I2C or SPI and want to hook up mounds of the absolute cheapest parallel interface gear to the MCU without writing any code themselves.


text:
Help with millis to get accurate timing
I'm essentially trying to create a music box which is light activated using an LDR. When it's open a song plays, while a servo rotates a figurine back and forth, and an LED dims and illuminates in sync with the servo. The code sort of works when I don't include the analogWrite for the LED, but even then the music timing is not great. When I do include analogWrite for the LED the music is completely distorted and doesn't work whatsoever. Is there some obvious mistake I've made? Is millis just bad for keeping time? I'm sure there is a better way to approach this overall, but I'm still an amateur at arduino. My code works by using an array for the notes and the duration of each. I refer to the duration array and use it as dynamic intervals for my millis to keep time. Hopefully that makes sense, my coding jargon is pretty basic!
    #include <Servo.h>

//defining the value of the notes
#define NOTE_C4  262
#define NOTE_D4  294
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_G4  392
#define NOTE_A4  440
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_D5  587
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_G5  784
#define NOTE_A5  880
#define NOTE_B5  988

//order of the notes
int melody[] = {
   NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0,
   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0,
   NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0,
   NOTE_A4, NOTE_G4, NOTE_A4, 0,

   NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0,
   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0,
   NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0,
   NOTE_A4, NOTE_G4, NOTE_A4, 0,

   NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0,
   NOTE_A4, NOTE_C5, NOTE_D5, NOTE_D5, 0,
   NOTE_D5, NOTE_E5, NOTE_F5, NOTE_F5, 0,
   NOTE_E5, NOTE_D5, NOTE_E5, NOTE_A4, 0,

   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0,
   NOTE_D5, NOTE_E5, NOTE_A4, 0,
   NOTE_A4, NOTE_C5, NOTE_B4, NOTE_B4, 0,
   NOTE_C5, NOTE_A4, NOTE_B4, 0,

   NOTE_A4, NOTE_A4,

   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0,
   NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0,
   NOTE_A4, NOTE_G4, NOTE_A4, 0,

   NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0,
   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0,
   NOTE_C5, NOTE_D5, NOTE_B4, NOTE_B4, 0,
   NOTE_A4, NOTE_G4, NOTE_A4, 0,

   NOTE_E4, NOTE_G4, NOTE_A4, NOTE_A4, 0,
   NOTE_A4, NOTE_C5, NOTE_D5, NOTE_D5, 0,
   NOTE_D5, NOTE_E5, NOTE_F5, NOTE_F5, 0,
   NOTE_E5, NOTE_D5, NOTE_E5, NOTE_A4, 0,

   NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, 0,
   NOTE_D5, NOTE_E5, NOTE_A4, 0,
   NOTE_A4, NOTE_C5, NOTE_B4, NOTE_B4, 0,
   NOTE_C5, NOTE_A4, NOTE_B4, 0,

   NOTE_E5, 0, 0, NOTE_F5, 0, 0,
   NOTE_E5, NOTE_E5, 0, NOTE_G5, 0, NOTE_E5, NOTE_D5, 0, 0,
   NOTE_D5, 0, 0, NOTE_C5, 0, 0,
   NOTE_B4, NOTE_C5, 0, NOTE_B4, 0, NOTE_A4,

   NOTE_E5, 0, 0, NOTE_F5, 0, 0,
   NOTE_E5, NOTE_E5, 0, NOTE_G5, 0, NOTE_E5, NOTE_D5, 0, 0,
   NOTE_D5, 0, 0, NOTE_C5, 0, 0,
   NOTE_B4, NOTE_C5, 0, NOTE_B4, 0, NOTE_A4
};

// duration of each note
int duration[] = {
  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 375, 125,

  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 375, 125,

  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 125, 250, 125,

  125, 125, 250, 125, 125,
  250, 125, 250, 125,
  125, 125, 250, 125, 125,
  125, 125, 375, 375,

  250, 125,

  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 375, 125,

  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 375, 125,

  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 250, 125, 125,
  125, 125, 125, 250, 125,

  125, 125, 250, 125, 125,
  250, 125, 250, 125,
  125, 125, 250, 125, 125,
  125, 125, 375, 375,

  250, 125, 375, 250, 125, 375,
  125, 125, 125, 125, 125, 125, 125, 125, 375,
  250, 125, 375, 250, 125, 375,
  125, 125, 125, 125, 125, 500,

  250, 125, 375, 250, 125, 375,
  125, 125, 125, 125, 125, 125, 125, 125, 375,
  250, 125, 375, 250, 125, 375,
  125, 125, 125, 125, 125, 3000
};

Servo myservo;  // create servo object to control a servo

int servoPin = 9;
int ledPin = 11;
int buzzerPin = 3;
int sensorPin = A4;
int sweep = 0; // variable to control which direction the servo is moving
int sensorValue = 0;
int counter = 0; //a counter to keep track of which note the song is up to
float tempo = 1; // a variable for the tempo - lower number = faster temp (2 =  double speed)
unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
int threshold = 500;

void setup()
{
  myservo.attach (servoPin);
  pinMode (ledPin, OUTPUT);
  pinMode (buzzerPin, OUTPUT);
  pinMode (sensorPin, INPUT);
  Serial.begin(9600);
}

void loop(){

sensorValue = analogRead (sensorPin);
if (sensorValue > threshold)
{

  if (sweep == 0)
  {

    for (int pos = 0; pos <= 180; pos ++) // goes from 0 degrees to 180 degrees in steps of 1 degree
    {
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      analogWrite(ledPin, map(pos, 0, 180, 0, 255)); //mapping the value from the for loop to get the full range of PWM for led fading

        currentMillis = millis();
        if (currentMillis - previousMillis > duration[counter]/tempo)
        {
          tone(buzzerPin, melody[counter], duration[counter]/tempo);
          counter++;
          previousMillis = currentMillis;
        }

          if (counter == 196)
          {
            counter = 0; //reset the counter so the song starts again
          }

            if (pos == 179)
            {
              Serial.println("SWEEP 1");
              sweep = 1;
            }

              sensorValue = analogRead (sensorPin);
              if (sensorValue < threshold)
                {
                  break;
                }
     }
  }

  if (sweep == 1)
  {

    for (int pos = 180; pos >= 0; pos --)  // goes from 180 degrees to 0 degrees
    {
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      analogWrite(ledPin, map(pos, 0, 180, 0, 255));

       currentMillis = millis();
       if (currentMillis - previousMillis > duration[counter]/tempo)
        {
          tone(buzzerPin, melody[counter], duration[counter]/tempo);
          counter++;
          previousMillis = currentMillis;
        }

          if (counter == 196)
          {
            counter = 0;
          }

            if (pos == 1)
            {
              sweep = 0;
              Serial.println("SWEEP 2");
            }

              sensorValue = analogRead (sensorPin);
              if (sensorValue < threshold)
                {
                  break;
                }
    }
  }
}

   if (sensorValue <= threshold) //if the light is low turn the servo back to starting point and stop doing anything
   {
    Serial.println("OFF");
    noTone(buzzerPin);
    myservo.write(0);
    counter = 0;
   }
}

What board are you using? Try moving the LED to pin 5, 6 or 10 (on Uno), tone and analogWrite would be using the same timer on pins 3 and 11 on a Uno, which sounds problematic.

What Mat said.
Also, the music timing is inside the for loop that drives the servo; you could also decouple those and set up a millis timer for the music and a millis timer for the servo and let the loop do its work without the for loop. That won't solve the timer problem, but the code would be much shorter and easier to read, and the music and servo timings would be independent (but tuneable). I'll post code that shows how to do that in an answer if you want.

@Mat Arduino pin 10 uses the same timer for PWM as the servo library does (timer 1). So I'd stick with Arduino pin 5 or 6 for the LED.

@Gerben: ah good point. Or maybe just put the LED on the same pin as the servo if that's it is just supposed to be on when the servo moves. Frees up a timer :-)

If you're still interested in refactored code, here is your code with for loops removed and restructured so state is tracked/updated appropriately in the void loop() as below:
[your variable declaration code as given]
...
unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
int threshold = 500;

int pos = 0;
int dir = 1;

void setup()
{
  myservo.attach (servoPin);
  pinMode (ledPin, OUTPUT);
  pinMode (buzzerPin, OUTPUT);
  pinMode (sensorPin, INPUT);
  Serial.begin(9600);
  pos = 0;
  dir = 1;
  previousMillis = millis();
}

void loop(){

    sensorValue = analogRead (sensorPin);
    if (sensorValue > threshold)
    {
        pos += dir;
        if (pos == 180) || (pos == 0)
        {
            dir *= -1;
        }

        myservo.write(pos);
        analogWrite(ledPin, map(pos, 0, 180, 0, 255));

        currentMillis = millis();

        if ((currentMillis - previousMillis) > duration[counter]/tempo)
        {
            tone(buzzerPin, melody[counter], duration[counter]/tempo);
            counter += (counter > 195) ? -196 : 1;
            previousMillis = currentMillis;
        }
    }
    else
    {
        Serial.println("OFF");
        noTone(buzzerPin);
        myservo.write(0);
        counter = 0;
        pos = 0;
        dir = 1;
    }
}


text:
FreeRTOS library (AVR_ATmega328PB_Xplained_mini_GCC) versus FreeRTOS for Arduino boards
I am researching different IoT development boards and found that Espressif uses the IDF framework. When I looked at the source code it uses FreeRTOS libraries.
I have an Arduino Uno and I want to use FreeRTOS for programming it. I found that FreeRTOS has multiple libraries that support different microcontrollers. Arduino Uno has an ATmega328P and FreeRTOS has libraries for it.
I also found libraries for the Arduino family of boards.
What is the difference between these two libraries?

One is a demo, the other is a library. One is not for Arduino but for "bare metal" programming, the other is for Arduino. They're both FreeRTOS.

Thank you Majenko for the clarification

ATmega328PB is not the same MCU as used by Arduino boards. Those use ATmega328P (no B). ATmega328PB is a mostly compatible successor and offers more timers, built-in touch functionality and more but does not come in large DIP packages. Arduino uses the older ATmega328P.


text:
What would be the best way to sniff an established serial connection?
I am studying a system running a serial connection and looking not to intercept its packets, but merely to inspect the traffic as it passes.
Option 1
Hook the RX and TX wires to the RX of two serial channels on my Arduino. Read the messages sent in either direction separately. Don't know the baud rate so this might be experimental?
Option 2
Split the connection, absorb both sides of the break into a RX TX serial connection on the Arduino, and set up forwarding from each to the other while inspecting the content.
In either option I can see the need to inspect the connected wires and establish the highest observed baud rate to match to. In the second option until I inspect enough data to reliably get the baud rate, data will be lost unless it is buffered.
Has anyone got any experience with a situation like this?

Use a logic analyser so you can find the baud rate visually. They can also decode the raw data into values, and some even know about common protocols already.

option 1 is preferred ... option 2 makes an assumption that voltage levels are not important to the exchange of data .... you could have a system that sends bogus serial data and uses voltage levels to transmit the true data covertly

I would suggest spending more time studying it and updating the information you presented. There are thousands of serial communications formats and most have both a transmit and receive connection. Is it a sync or async format. Could it be I2C or SPI? Maybe it's VPWM, you will need to know before you can spi on the data going to and fro. Once you have this you can use a few Op Amps and resistors as a high impedance connection so you do not damage the data stream.

Keep in mind even if it is RS232-like asynchronous serial protocol you don't need to know the baud rate beforehand. You can write an algorithm to measure and detect the baud rate of traffic passing by. This is what "autobaud" means for higher level systems which support it. They have just written algorithms to figure out the baud rate by listening to traffic for a moment first.

FYI I highly recommend Saleae logic analyzers. Several hundred $$ but worth it. https://www.saleae.com/. For an oscilloscope, go Rigol.

There are also lots of logic analysers, that only cost like 10$. Surely they are not as capable as the top tier ones, but that most likely will be enough.