text:
Unexpected accident of my board, CH341 issue for Linux or Dead ESP?
I have early midnight accident of my Lolin/Wemos boards. I tried uploads my sketch with a assembly VIN to GND as my reset button, when i uploads my sketch at more one hundred times, i get my boards cannot be online again or my port cannot readable to my Ubuntu as /dev/ttyXXX. usually when i plugged the Usb3.0 cable, the blink led should be turn on at my boards but i didn't get it. How  i can re-flash my boards to be online again?
Thanks in advance.

Am I understanding right, that you shorted Vin to Ground? Have you tried another USB port? Maybe you have blown it's driver.

@chrisl yap it just as reset button, i tried too but i didn't get my port again, perhaps my driver have blown but when i bought it ,i didn't need to installed the drivers.

@chrisl do i need a esp8266 firmware flasher to get it back?

the port has nothing to do with the esp8266. USB is handled by the USB converter chip. You used short circuit as reset?

I meant the electronic parts inside the USB port of your PC. Sorry for being unaccurate. So you can try another USB port or another PC. Also look at the board, if you can find any parts that look damaged. Currently I cannot investigate further

Juraj yap!! ,christ i tried to change another usb port and another pc but i didn't get it back

@chrisl how i can i find any parts that look damaged? perhaps USB converter chip issue but Lolin/Wemos didn't need driver for linux

Precisely which board do you have?

@Majenko Lolin/Wemos D1 Mini absolutely

Thanks to @Majenko my pal, from him advice i get a alternative ideas for fixed my issue.
What i tried :

I found this and I took my Uno, i pined 5v (Uno) to 5v (Esp) and i declared 13 pinout as the led blinky and then i uploaded "BlinkyWithoutDelay" sketch, it's seems doesn't work.
I pined 5v (Uno) to 5v (Esp), Gnd (Uno) to Gnd (Esp) and i declared 13 pinout (Uno) to D3 pinout (Esp) and then i uploaded "BlinkyWithoutDelay" sketch, it's seems doesn't work.
I tried from Majenko advice to provide a Usb phone charger and connected white wire to 5v (Esp) and black wire to Gnd (Esp) without Uno board, and then i uploaded "BlinkyWithoutDelay" sketch, it's seems doesn't work.
From the 2nd point and the 3rd point, i run 2nd point without declared D3 pinout as the led blinky, and i changed from 5v to 3v3 (Uno and Esp), and after uploaded the sketch, it's seems the dim light (Esp) works like dim light (Uno) but i still cannot get my port for my esp, i had idea to unplugged my Uno and i changed from 5v to 3v3 and i uploaded my sketch, it's seems works to me. but i still cannot 5v properly or really death.

The Solution
From the 4th points , the solution is i provide a external power to 3v3 (esp) and i plugged to Usb2.0, i also plugged Usb3.0 as serial communication. when i uploaded "BlinkyWithoutDelay" sketch, it's seems works. The conclusion is my 5v pinout really death cause the diode for 5v pinout is blown up therefore i changed to 3v3 pinout.
See my damaged board below

That's also solved another my Esp boards. hope anyone didn't make a shorted between 5v to Gnd like me.
Thanks.

this should be an answer?

@Juraj that's solved my issue, i get my port again, why you provide me down vote man?

this is not how an answer should be written and I don't understand the solution.

@Juraj perhaps my bad English man, I editing!!

leave out the dead ends. write down the working wiring

@Juraj that's the steps what i did, and the solution really short sentences!!

@Juraj is my language correct man?

so you used an external USB-to-TTL-Serial adapter instead of the damaged USB circuit of the NodeMCU. You connected the adapter to Rx,TX,3.3V and ground pins. Without the USB part, the NodeMCU is simply an ESP-12. No USB communication and power and no autoreset for flashing

@Juraj i'm not used an external USB-to-TTL-Serial adapter and RX TX pins, i just used a external power like Majenko advice , if i use 5v pin i get No USB communication and power and no autoreset for flashing.

ok, so USB like normal, only 3.3 V external power, because Majenkos's advice to use 5 V pin was wrong since it uses the same damaged circuit as the USB power.

@Juraj USB abnormal for my damaged boards because my diode for blown up, if i unplugged usb3.0 as serial communication or usb2.0 as external power, i didn't get my port, it requires both. at this morning i buy a new esp and my USB like normally.

@Juraj hope you can get it man!

I understand that everything works if you power the board over 3.3V pin

@Juraj see my little picture man!! why my answer is still considered wrong as down vote?

@Juraj am i answered section is correct man?

the picture is poor. and what is that about D3 pin?

@Juraj no, i didn't used D3 pin as the led blinky, just used "LED_BUILTIN".

what has that to do with all this?

@Juraj what's your talking about? ,with my alternative solution, i can get my port again from a external power 3v3 pin instead 5v pin which the diode is blown up

what has the D3 pin mentioned in you answer to do with the solution?

@Juraj in 4th point, i didn't used D3 pin as led blinky, but if you used D3 pin as led blinky on "BlinkyWithoutDelay" sketch with a external power and a serial communication, that's same to me

@Juraj is there anything else wrong man?

no improvement at all. but I remove the downvote for your effort

@Juraj thanks, how i can improvement at all?

@Juraj thanks, what i do to improvement at all?

Shorting VIN to GND will over-stress the diode that is in-line with the power coming in from the USB.
The result

The diode will blow and you will not get power from the USB to power the board.
The PC may detect "over-current" and shut down the USB port
The USB port on the computer may be damaged

How do you fix it?

Replace the diode if blown.
Use a different USB port.

How do you work around it?

Provide an external 5V power source to VIN & GND if the diode is blown

How do you avoid it happening in future?

NEVER short VIN to GND, even for a short time.  There is a reset pin RST provided for the purpose of resetting the board.

i found it https://forum.arduino.cc/index.php?topic=504901.msg3446033#msg3446033 ,do i took another boards and connect 3.3v output to my esp?

That's a different issue.  Get a USB phone charger, butcher a USB cable, and connect the red wire to VIN and the black wire to GND.  It may work.

okay i trying, do i plug usb3.0 port to esp connector too?

You will need to for it to communicate with the computer.

alright i trying

sorry, it doesn't works sir.

Then throw it away and get another. They're cheap enough. And don't do it again.

if the diode is damaged, the 5 V pin will work?

@Juraj i think you can try connected white jumper wired 5v (uno) to gnd (esp) and black jumper wired gnd (uno) to 5v (esp) then uploaded your sketch. if your saw a brown smoke, your blown out it. and then check your port again. if you cannot get your port, you can try my mine.

If the device still blinks and boots and whatnot, but doesn't connect to the computer, you've probably only broken the USB part of the NodeMCU.
Use the USB-TTL of another MCU. If you have an Uno, it's RST>GND, GND>GND, TX-RX, RX-TX. Mind GPIO 0+15 for programming. You can also use a USB TTL adapter, aka "an FTDI", the kind they used to use before everything had cheap built-in USB chips.

my device not blinks and cannot detect my port, do i Majenko advice?

well my suggestion is low-effort and free to try. If I was looking at replacing parts on a NodeMCU, i would just get a new NodeMCU, they are only a few dollars, and fixing it could take hours. If you find the ESP half still working, there's a lot of projects you can still use the board for, especially if you enable OTA updates...

i try to understanding my issue without a few dollars, and to get work around it, thanks

how i can enable OTA updates for esp8266?

this is the simplest method, since it's just an include and one extra line of code on top of an existing server config: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266HTTPUpdateServer/examples/WebUpdater/WebUpdater.ino  There's a few other ways to do it as well, through the ardunio IDE and through an external HTTP server, but this one is simple.


text:
Elechouse Voice Recognition v3 module not responding when I send command using Access port serial tool
I have this challenge of receiving data when I send a command to voice recognition v3 module. The UART connections are okay, but when I send a command I don't receive a response on the terminal.
The prolific USB-TTL with drivers installed blinks when I send a command but still I get no response. Please help with debugging.

Can you be more specific about what you have done.  E.g. show your code, circuit and the "commands" used.

I am using ACCESS PORT in trying to train the module as per the manual commands. But haven't achieved any success. Any suggestions please?

The module can't communicate with Serial Monitor over a USB to TTL Serial adapter. It uses binary communication. Use Arduino, Arduino library and one of the example sketches of the library to communicate with the VR module.
And read the manual.

source: Stack Exchange

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

sort: votes


text:
Voltage Regulator getting too hot
I have an Arduino mega that is being used to control relays and ultrasonic sensors.  The relays that I am using is a 4 DPDT Signal Relay Module Model: D-256 Series and the other is a 4 channel Single pole Relay for Arduino. I am only using 3 channels of each relay. At any given time I only output to 2 channels from each relay at a time. I tested the relay to ensure they worked with the Arduino and they ran fine.
Once I connected the Ultrasonic sensors to the board as well, the board would not power and the voltage regulator got extremely hot. I would assume the total current draw was too high from the outputs and VCC of the Arduino.
I think that if I take my 9V battery and run it through a voltage regulator 7805 then I can run the VCC power of the relays with the battery instead of the VCC from the Arduino. This would result in me only running a VCC to the 4 ultrasonic sensors, the triggers for the ultrasonics from the Arduino, and the output signals fora maximum of 2 channels per relay board resulting in 4 relays. Most of the time it is only 2 relays.
Would I be able to power the relay boards VCC with the 9V running through a 5v regulator instead of the arduino so that I can reduce the current running through the Arduino?

yes, that will work as you think. you'd be better of with a buck regulator though. a lot better off...

What could be going on here apart from what @JRobert has suggested, is, LM7805 could be generating a lot of heat loss.
4 X Ultrasonic sensors (SR HC-04) would draw 60mA.
2 X Relays (SRD-05VDC-SL-C) would draw 71.4 X 2 i.e 142.8mA.(Depends on from where you signal it)
The Arduino mega would draw anywhere between 200 - 500 mA.(even more)
The amount loss you will have is (9-5)V * (202.8 + 250)mA
i.e. around 2 Watts. This is a lot of heat. I'm not even sure the LM7805 would be able to handle it.
Solution: use a switching regulator like the one mentioned here: https://electronics.stackexchange.com/questions/21131/efficient-low-power-regulation-i-e-9-5-volts

This is what I was thinking. The relays and sensors pulled in pulled too much current through the voltage regulator. My current setup that I have and it seemed to work was put a 9V battery that runs through a regulator to power the VCC of the relays. I also have a seperate battery pack that runs the Arduino. Now the only things that run out of the output terminals from the Arduino are the sensors and the output signals for the relays.By removing the VCC load from the Arduino, I am no longer overloading the voltage regulator on the board. It stayed cool while I was running yesterday

It sounds like a power-to-ground short circuit, either a fault in the Ultrasonic sensor or in the connection to the Arduino.
Check your connections, and if you have an Ohm-meter, check the resistance between the sensor's power and ground pins.
Current consumption is a function of the device being powered, not of the power-supply, unless the supply lacks the capacity to provide as much current as the device needs.
Note that 9v batteries (the small brick aka a "transistor battery") is not well suited to supplying much current and probably will not power your Mega, or not for long, anyway. They are much better suited for long-term powering of very low current devices, such as a smoke detector.

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


text:
How can I connect nodemcu with laptop wifi
Question is odd, but I want to know that how I connect nodmcu with a laptop wifi without using any router. Is it possible if yes then how?

Configure and activate the access point mode on NodeMCU. It creates a WiFi network and you can connect to this network with your computer.

@HasnainRaza, did this help? if yes accept the answer to mark the question solved


text:
Arduino IDE c++ 11 raw string literal have issues with // in http://, complier thinks // is comment
char webpage[] PROGMEM = R"=====(
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/svg.js/2.6.6/svg.min.js"></script>
  </head>
  <body>
  </body>
</html>
)=====";

I found a problem when using the raw string literal in Arduino IDE.
My code cannot compile if i have http:// link inside the string.
I found that it should be related to how Arduino IDE thought the string after // are comments and during compile time those string are ignored and my codes break.
It looks like the arduino ide's compiler removes all //comment in the code first, before it try to compile the raw string literal and then cause the issue.
As a test I try to debug it by changing my code to https:/-/ the program can be compile as now there is no // in the raw string literal
Is there any workaround?

Escape the two quote marks inside the string using a backslash (literal quotes).
Without the escape characters, the URL is "outside" of a string because the quote marks are string delimiters.
char webpage[] PROGMEM = R"=====(
<html>
  <head>
    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/svg.js/2.6.6/svg.min.js\"></script>
  </head>
  <body>
  </body>
</html>
)=====";

thanks. interesting.
after escaping the " it can complie but the link doesn't work anymore
because in the html
the src link cannot point to the link location anymore, as it got the extra \ escape character before "

Escaping characters are not left into the end result, you have some other issue, for example you can't link to external content when serving directly from an ESP8266/ESP32 because it doesn't have internet connection that could enable your device to download the resources.

This is just a simplified snippet of the code. My original program will serve a javascript page. I will post my full code later.

For c11 raw string literal, the end result will contain the escape characters. Meaning " in the raw string literal will be still display as "

char webpage[] PROGMEM = R"=="==(
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/svg.js/2.6.6/svg.min.js"></script>
  </head>
  <body>
  </body>
</html>
)=="==";

inspired by answer provided by @jsotola  if i used the syntax like this R"=="==()=="==" the link will become inside the quote. and hence the ide's complier regards it as a string and won't think // is comment and now the code can complie and the link works.

The C & C++ compilers don't look for language syntax inside quoted strings (except for character-escapes such as '\n'). That is the point of quoting the string.
This program just compiled Ok for me:
const char webpage[] PROGMEM = R"=====(
<html>
  <head>
    <script src=\"https://cdnjs.cloudflare.com/ajax/libs/svg.js/2.6.6/svg.min.js\"></script>
  </head>
  <body>
  </body>
</html>
)=====";

void setup() {
}

void loop() {
}

'//' within the string did not cause any problem. Your example did get an error message that the variable 'webpage' had to be const to put it in Flash memory so I added the 'const' keyword, but that is the only change I made.
If you do that, and your compiler is still complaining, there is some other issue than the '//'.


text:
My Ultrasonic sensor is only showing 4cm range?
I am using an ultrasonic sensor SR04 with Arduino Uno and a sample program which I got from the library. However, my output reading is only 4 cm even when there is no object in front of it. I even used another sample program which had the same output. Is the problem in sensor or library?
#define TRIGGER_PIN  12
#define ECHO_PIN     11
#define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup() {
  Serial.begin(115200);
}

void loop() {
  delay(50);
  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm());
  Serial.println("cm");
}

Which sensor dude, we are not clairvoyants

sorry, its ultrasonic sensor SR04

Are you 100% positive you did not mix up trigger and echo pins? I know it is just 2 pins, but still. The example has 11 and 12, you got 12 and 13. Maybe you mixed them up. If not,try 11 and 12 as in example. here is the reason why your input echo might not work - https://www.arduino.cc/en/Tutorial/DigitalPins
Look up digital pin 13, it has LED on it. It is described in the link.

Yup, I changed the pins to 11 and 12. It works better than before but still shows the reading around the 4cm. Somethings it goes till 100cm. Its not accurate, is it normal or my sensor is defective?

I recommend, if you want reliability, that you upgrade to the HY-SRF05 sensor.  The problem with the SR04 is that when there is nothing in front of the sensor (or the target is beyond the limit) the sensor sometimes "locks up," and you have to reset it to get it working correctly again.  The SR04's are a few cents cheaper than the others; there's a reason for that.
Also, there's more than one library available for these sensors.  I recommend the NewPing library by Tim Eckel available from here:  https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
I am not affiliated with Tim in any way, but he's got a good library.

Looks to me like your powering the SR04 with 3.3v instead of 5v.

I have connected it to 5v


text:
How to copy IPAddress class into character buffer? Getting error: "inet_ntop' was not declared in this scope"
I am using the WiFi library and trying to store the IP address in a character buffer so that I can print it out to an lcd that only accepts character buffers. My code for doing this:
 char * IPAD = new char[40
 IPAddress ip = WiFi.localIP();
 Serial.println(ip);
 char * bufIP = new char[40]();
 sprintf(bufIP, "%s", inet_ntop(ip));
 lcd.string(ip);

But when I compile this I get the error:
"inet_ntop' was not declared in this scope"

Help?

try lcd.print(ip); lcd libraries use to implement Print and IPAddress implements Printable

My LCD library only accepts char* elements :(

then use numbers ip[0], ip[1], ip[2], ip[3]

Which arduino are you using?

An IPAddress is a class. You can't use it like a number (although in certain circumstances you can assign it to a uint32_t and it gives you the numeric representation).
Also, the inet_* functions are only really relevant on a POSIX system with a full network stack - i.e., a computer, not a little Arduino without a proper networking stack.
You can, though, easily access the individual bytes of the IP address through the [] operator and place them into a char array with the right format:
sprintf(bufIP, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);


text:
Arduino pins not working
I'm building my first arduino project and I encountered a strange problems;
I build a haunted house based upon that instructables tutorial:
https://www.instructables.com/id/Control-Your-Halloween-Decorations-With-Arduino/
Every prop works, I tried to light them on and off (it works), but when I try to use all of them, a few doesn't work.
There is my code; Is it something I'm doing wrong?
int propSqueDans = 4;
int propClownImmo = 5;
int propClownJambes = 6;
int propSqueBal = 7;
int propSqueMini = 8;
int propSpider = 9;
int propChauSou = 10;
int propFantChai = 11;

int SensorPin = 3; // sensor connected to analog pin 3
int SensorVal = 0; // variable to store the value read

void setup() {
  pinMode(propSqueDans, OUTPUT);// sets the digital pin as output
  pinMode(propClownImmo, OUTPUT);
  pinMode(propClownJambes, OUTPUT);
  pinMode(propSqueBal, OUTPUT);
  pinMode(propSqueMini, OUTPUT);
  pinMode(propChauSou, OUTPUT);
  pinMode(propFantChai, OUTPUT);
  pinMode(propSpider, OUTPUT);
  Serial.begin(9600);

  }

void loop() {
    SensorVal = analogRead(SensorPin); // read the input pin

    if (SensorVal >100) {
    Serial.write("Danse + Clown Immo \n");
    digitalWrite(propSqueDans, HIGH);
    digitalWrite(propClownImmo, HIGH);
    delay(10000);
    Serial.write("Spider + Fangtôme + Clown jambes \n");
    digitalWrite(propSpider, HIGH);
    digitalWrite(propFantChai, HIGH);
    digitalWrite(propClownJambes, HIGH);

    delay(5000);
    Serial.write("Squelette balance + sque mini \n");
    digitalWrite(propSqueBal, HIGH);
    digitalWrite(propSqueMini, HIGH);

    delay(5000);
    Serial.write("Chauve souris \n");
    digitalWrite(propChauSou, HIGH);

    delay(20000);

    digitalWrite(propSqueDans, LOW);
    digitalWrite(propClownJambes, LOW);
    digitalWrite(propSqueBal, LOW);
    digitalWrite(propSqueMini, LOW);
    digitalWrite(propChauSou, LOW);
    digitalWrite(propFantChai, LOW);
    digitalWrite(propSpider, LOW);
    digitalWrite(propClownImmo, LOW);
    delay(5000);
    }

  }

Thank you for your help !

Please show us your circuit (schematic). Also describe further, what is connected to the pins. Do you try to drive any motor or servo directly from the pins?

My best guess (not knowing what the pins are driving) is that your trying to draw too much current from the Arduino gpio.
Ref: https://playground.arduino.cc/Main/ArduinoPinCurrentLimitations

Hello Andre, I guess you're right; could you tell me if a better arduino will have more current ?

Uno and Mega are pretty much the same. I would suggest using a relay module.


text:
How to create objects with their own variables?
So i created a class and when i created objects and use them, they seem to share their variables between each other ( the currentReading, previousReading and the time variable). how can i create objects that have their own variables so that type of conflict cant happen?
code : ( read the buttons and print them in the lcd screen)
#include <LiquidCrystal.h>

LiquidCrystal lcd(6, 5, 3, 2, 1, 0);

class button {
  public:
    void SetupButton(int pino);
    int Read();

  private:
    int _pin;
};

void button::SetupButton(int pin) {
  pinMode(pin, INPUT_PULLUP);
  _pin = pin;

}

int button::Read() {
  static boolean currentReading, previousReading = 1;
  static unsigned long time;

  currentReading = digitalRead(_pin);// reading
  if (previousReading - currentReading  == 1) { // when reading gos from 1 to 0
    time = millis();
  }

  if (currentReading - previousReading == 1 && (50 < (millis() - time) < 500)) {     // when reading gos back to 1 before 500ms
    previousReading = currentReading;
    return 1;
  }

  if (3000 > (millis() - time) && (millis() - time) > 500 && !currentReading) { // when reading keeps in 0 after 500ms
    previousReading = currentReading;
    return 2;
  }

  if ((millis() - time) > 3000 && !currentReading) { // // when reading keeps in 0 after 3000ms
    previousReading = currentReading;
    return  3;
  }

  previousReading = currentReading; // current reading becomes the previous

  return 0;
}

button up;
button down;

void setup() {
  lcd.begin(16, 2);
  up.SetupButton(A0);
  down.SetupButton(A1);

}
void loop() {

  lcd.setCursor(0, 0);
  lcd.print(up.Read());
  lcd.print(down.Read());

}

ps :  i already know how to do this without using classes but doing it with classes makes the code much cleaner so i am trying to achieve this

you can test the code in https://www.tinkercad.com/things/8oXS6FQNK6A-dazzling-jaban

Your class has only 1 attribute _pin - which is private. If you want to have variables for each instance these should be in your class. Your code doesn't seem to create any class instances.

So if i create one more attribute for each variable ( like _currentReading,_previousReading, _time ) and use them in the fuctions will this solve my problem?

This would be the first step, but you need to create instances of your class e.g. up = button(4); It is normal to pass essential attributes in  the constructor.

thank you very much! i just created the new attributes and changed all the variables by it attribute counterpart and it worked flawlessy, post it as an answer so i can upvote it.

this question is not about Arduino. it is about C++

I was tempted to re-write your code (I am quite rusty on c++), but you may be better to start with an existing class.
There is a Button class on the Arduino site. See https://playground.arduino.cc/Code/Button
You could use this or study to see a more usual c++ implementation and adapt your code.
Virtually ALL c++ classes include a constructor. I would use instead of SetupButton
void button::button(int pin) {
  this->_pin=pin;
  pinMode(pin, INPUT_PULLUP);
}

and add uint8_t previousReading; and unsigned long time; to your class as private variables.


text:
Problem with Pulse Sensor signal
I'm making alarm with input from pulse sensor. When it detect high heart rate then it send a text message. Everything works fine when i am using potentiometer (as input) for simulating triggering SMS. I made several heart rate trigger options based on ages, so i'm using switch-case in my loop. I'm using PulseSensor Playground library and some sample skecth that came from with it, but when i put program that read beat per minute and put that value inside if statement it become doesn't work at all. Even if i put the BPM value to serial monitor it only display 0. What can i do to fix this problem? Thanks
Here is my program:
#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>
#include <SoftwareSerial.h>
#include <JC_Button.h>

const int OUTPUT_TYPE = SERIAL_PLOTTER;
const int PulseSensor = A0;
const int THRESHOLD = 550;

PulseSensorPlayground pulseSensor;
SoftwareSerial SIM800L(2, 3);  //(RX | TX)
const byte switchButton = 4;
int LED1 = 5;   //ages range 1
int LED2 = 6;   //ages range 2
int LED3 = 7;   //ages range 3
int greenLED  = 8;    //for normal heart rate
int yellowLED  = 9;   //for medium heart rate
int redLED = 10;      //for high heart rate

Button mybutton(switchButton);
boolean SMSsent = false;
int x = 0;

void setup(){
  mybutton.begin();
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(redLED, OUTPUT);

  Serial.begin(115200);
  pulseSensor.analogInput(PulseSensor);
  pulseSensor.setSerial(Serial);
  pulseSensor.setOutputType(OUTPUT_TYPE);
  pulseSensor.setThreshold(THRESHOLD);

  SIM800L.begin(115200);
  Serial.println("SIM800L ready");
}

void led_for_ages_range_1(){
  digitalWrite(LED1, HIGH);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, LOW);
}
void led_for_ages_range_2(){
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, HIGH);
  digitalWrite(LED3, LOW);
}
void led_for_ages_range_3(){
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, HIGH);
}

void led_indicator_1(){
  digitalWrite(greenLED, HIGH);
  digitalWrite(yellowLED, LOW);
  digitalWrite(redLED, LOW);
}
void led_indicator_2(){
  digitalWrite(greenLED, LOW);
  digitalWrite(yellowLED, HIGH);
  digitalWrite(redLED, LOW);
}
void led_indicator_3(){
  digitalWrite(greenLED, LOW);
  digitalWrite(yellowLED, LOW);
  digitalWrite(redLED, HIGH);
}

void range_1_indicator(){
  int BPMval = pulseSensor.getBeatsPerMinute();

  if (BPMval > 60 && BPMval < 85){
    led_indicator_1();
    SMSsent = false;
  }
  else if (BPMval > 86 && BPMval < 100){
    led_indicator_2();
    if(SMSsent == false){
      text_message_1();
      SMSsent = true;
    }
  }
  else if (BPMval > 101){
    if(SMSsent == false){
      text_message_2();
      SMSsent = true;
    }
  }
  else {
    SMSsent = false;
  }
}

void range_2_indicator(){
  int BPMval = pulseSensor.getBeatsPerMinute();

  if (BPMval > 60 && BPMval < 75){
    led_indicator_1();
    SMSsent = false;
  }
  else if (BPMval > 76 && BPMval < 90){
    led_indicator_2();
    if(SMSsent == false){
      text_message_1();
      SMSsent = true;
    }
  }
  else if (BPMval > 91){
    if(SMSsent == false){
      text_message_2();
      SMSsent = true;
    }
  }
  else {
    SMSsent = false;
  }
}

void range_3_indicator(){
  int BPMval = pulseSensor.getBeatsPerMinute();

  if (BPMval > 60 && BPMval < 70){
    led_indicator_1();
    SMSsent = false;
  }
  else if (BPMval > 71 && BPMval < 80){
    led_indicator_2();
    if(SMSsent == false){
      text_message_1();
      SMSsent = true;
    }
  }
  else if (BPMval > 81){
    if(SMSsent == false){
      text_message_2();
      SMSsent = true;
    }
  }
  else {
    SMSsent = false;
  }
}

void text_message_1(){
  int BPMval = pulseSensor.getBeatsPerMinute();
  SIM800L.write("AT+CMGF=1\r");
  delay(100);
  Serial.println("SIM800L set destination number.");
  SIM800L.write("AT+CMGS=\"0123456789\"\r");
  delay(100);
  Serial.println("Sending text message...");
  SIM800L.write("Your heart rate are: ");
  SIM800L.write(BPMval);
  SIM800L.write(" BPM");
  SIM800L.write("\r");
  Serial.println("Your heart rate are: ");
  Serial.print(BPMval);
  Serial.println(" BPM");
  SIM800L.write((char)26);
  delay(100);
  Serial.println("SMS sent.");
}

void text_message_2(){
  int BPMval = pulseSensor.getBeatsPerMinute();
  SIM800L.write("AT+CMGF=1\r");
  delay(100);
  Serial.println("SIM800L set destination number.");
  SIM800L.write("AT+CMGS=\"0123456789\"\r");
  delay(100);
  Serial.println("Sending text message...");
  SIM800L.write("Warning! Your heart rate are: ");
  SIM800L.write(BPMval);
  SIM800L.write(" BPM");
  SIM800L.write("\r");
  Serial.println("Warning! Your heart rate are: ");
  Serial.print(BPMval);
  Serial.println(" BPM");
  SIM800L.write((char)26);
  delay(100);
  Serial.println("SMS sent.");
}

void loop(){
  //int BPMval = pulseSensor.getBeatsPerMinute();
  static enum {OPTION_ONE, OPTION_TWO, OPTION_THREE} condition;
  while (x == 0){
    mybutton.read();
    switch (condition){
      case OPTION_ONE:
      led_for_ages_range_1();
      range_1_indicator();
      if (mybutton.wasReleased()){
        condition = OPTION_TWO;
      }
      break;

      case OPTION_TWO:
      led_for_ages_range_2();
      range_2_indicator();
      if (mybutton.wasReleased()){
        condition = OPTION_THREE;
      }
      break;

      case OPTION_THREE:
      led_for_ages_range_3();
      range_3_indicator();
      if (mybutton.wasReleased()){
        condition = OPTION_ONE;
      }
      break;
    }
  }
}

examine you code carefully ... for example, you get no warning at 90bpm  (there are more like that)

That just an example value, i intend to use >= and <=.

do you have a test sketch or some example sketch for the pulse sensor? does it work? or it doesn't work only in a sketch with SIM800 and SoftwareSerial

@Juraj. Yes i have, and it works perfectly when i use example sketch from the PulseSensorPlayground library. Also it works with SIM800L and SoftwareSerial when it still in simple sketch, i'm not adding switch-case for switching for the ages range and LED status at that time, because i don't insert any ages options program. Is it because of my faulty switch-case logic? But that switch-case logic also works for changing LED status and 3 different range values when i use potentiometer for changing the analog input value that change the LED indicator. And the text message also works.

add this to question

I'm getting fluctuations in BPM (it varies from 40 to 250). Most of the times, its in the 200s. Sometimes, it comes down to 90 or 80. pulse sensor

You forgot pulseSensor.begin() and you don't use pulseSensor.sawNewSample(). See the examples of the library.
The library uses interrupts to measure the pulse. (It takes time, which would otherwise block the loop execution). The begin() function starts this interrupts.
The value measured by interrupts is accessible with getBeatsPerMinute() and sawNewSample() function indicates that new value is available.
The library can work without interrupts (PulseSensor_BPM_Alternative.ino), but even then the begin() function initializes the library and sawNewSample() is then the function which reads the sensor.

Did you see that in "Getting BPM_to_Monitor" sample sketch? In that sketch pulseSensor.begin() run only once and it's to print text inside Serial.println. Why i need to use pulseSensor.sawNewSample()? Its only return true or false because it's a boolean.

without begin the library doesn't read the sensor. getBeatsPerMinute is only a getter which reads a variable in library.

I enhanced the answer.

Oh i see.  I will try that.

I added pulseSensor.begin() and it works. But it getting error when i write pulseSensor.sawNewSample(), some of the LEDs always fast blinking and not in full brightness. But overall it works by adding pulseSensor.begin(). Thanks


text:
Problem with Arduino driver! Port option not visible. How to resolve it?
I am not able to upload sketch because my Windows 8.1 PC is not able to recognise it. It used to work fine but suddenly my driver disappeared from my device manager and no light is shown on the Arduino uno led also.
I tried to uninstall and install the Arduino IDE again but still didn't work.
Note:- whenever I connect the USB cable to my PC, I see a dim light glowing for few milli seconds.
Update:- Also my Arduino board is not dead since it worked when connected to other pc but not working with my windows pc.
What could be the problem? How do I install the port driver back?

Is it a Genuine Arduino or a cheap Chinese clone?

cheap Chinese i think

If you bought it off Amazon or eBay then it will be. Chances are it's dead. Get a new one.

got if from souq, yea have to check. or maybe problem in usb cable?

i think you have unsigned drivers see https://forum.arduino.cc/index.php?topic=205837.0

"dim light glowing" says "dead board" to me.  Probably CH340G. Probably breathed on it wrong.

I changed my pc setting to allow unsigned driver but still not working. Board is not dead since it worked when connected to other pc.

but then, the power LED is lit?

its working now

Problem solved
I connected the arduino with my motor shield on top of it which stopped the power supply from pc. Now its working fine.

Sometimes Windows will disable a given USB port if it think's the attached device is malfunctioning.  Try using a different USB port on your PC.  If that does't work try
rebooting your PC.

I think that's the problem. I connected the Arduino to another PC and it worked so problem is not in the board but in my pc driver. Even using different usb port didn't work. How do I reboot the pc exactly?

No LED = no power being supplied. That would imply a bad port, a bad cable, or a damaged board (open circuit due to a damaged trace or part).
A brief LED can mean the board was drawing too much current and the computer shut down that port to protect itself. That would imply a damaged board (short circuit due to burned out part, bad wiring if you have any on the board, or something conductive touching your board where it shouldn't (anywhere!).
Try substituting ports, cables, & Arduinos - one thing at a time - until something changes to give you a clue to what component is faulty.
You might also have a driver problem, but a good board/cable/port should power up anyway.

Problem is in driver. I connected the Arduino board to another PC and it started working but not working in my pc.


text:
TimeAlarms stops working when using setSyncProvider(RTC.get) DS1307
Been working on this project for some time now, like title states when I un-comment setSyncProvider(RTC.get) in the setup the program fails to get any of the Alarm.timerOnce to run.
I have been stuck for a while and couldn't find anything while just googling so I thought I might enlist the minds of stack.
#include <Wire.h>
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t

//#define DS1307_I2C_ADDRESS 0x68 // the I2C address of Tiny RTC
//byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

int curPin = 7, //  Current sense (middle terminal) connected to analog pin A7
  prePin = 6,     //  Pressure sense (green terminal) connected to analog pin A6
  ignPin = 7,     //  Igniter output pin D7
  solPin = 8,     //  Solenoid output pin D8
  genPin = 9,     //  Generator output pin D9
  tonePin = 11,   //  Tone output pin D11
  ligPin = 3,     //  Light sense pin A3
  intPin = 3,     //  Interupt pin D3 runs double bang

  runTime = 20,   //  minutes to run for

  state = 0;      //  state of operation

bool operate = false, // True if within operating time
   timeIsSet = false; // true if time till next opperation is set
double cur;

void setup() {
  Wire.begin();
  pinMode(13,OUTPUT);
  pinMode(ignPin, OUTPUT);
  pinMode(solPin, OUTPUT);
  pinMode(genPin, OUTPUT);
  Serial.begin(9600);
  //setSyncProvider(RTC.get);  //******************************************
  Alarm.alarmRepeat(dowMonday,7,30,0,OnAlarm);
  Alarm.alarmRepeat(dowTuesday,7,30,0,OnAlarm);
  Alarm.alarmRepeat(dowWednesday,7,30,0,OnAlarm);
  Alarm.alarmRepeat(dowThursday,7,30,0,OnAlarm);
  Alarm.alarmRepeat(dowFriday,7,30,0,OnAlarm);
  Alarm.alarmRepeat(dowSaturday,8,30,0,OnAlarm);
  Alarm.alarmRepeat(dowSunday,10,0,0,OnAlarm);
  Alarm.alarmRepeat(20,0,0,OffAlarm);
  tone(tonePin, 31, 1000);
  randomSeed(analogRead(0)); // nothing connected to 0 so read sees noise

  OnAlarm();
}

void loop() {
  if ((analogRead(ligPin) > 30) && operate == true)
  {
    if (timeIsSet == false)
    {
      tone(tonePin, 58, 500);
      int randm = random(27,36);
      Alarm.timerOnce(randm,operation);
      Serial.println(randm);
      timeIsSet = true;
    }
  }
  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
}

void operation(){
  tone(tonePin, 100, 1000);
  Alarm.timerOnce(12,after20m);
  digitalWrite(genPin, HIGH);
}

void after20m(){
  digitalWrite(genPin, LOW);
  Alarm.timerOnce(5,after5s);
  digitalWrite(solPin, HIGH);
  tone(tonePin, 494, 1000);
  timeIsSet = false;
}

void after5s(){
  tone(tonePin, 200, 1000);
  digitalWrite(solPin, LOW);
  Alarm.timerOnce(1,after1s);
}

void after1s()
{
  digitalWrite(ignPin, HIGH);
  Alarm.delay(500);
  digitalWrite(ignPin, LOW);
}

void OnAlarm() {
  operate = true;
}

void OffAlarm() {
  operate = false;
}

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}

void digitalClockDisplay() {
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  //Serial.print(operate);
  Serial.println();
}

void printDigits(int digits) {
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

Problem existed in the TimeAlarms library,
Q: How many alarms can be created?
A: Up to six alarms can be scheduled.
The number of alarms can be changed in the TimeAlarms header file (set by the constant
dtNBR_ALARMS,
note that the RAM used equals dtNBR_ALARMS  * 11)

so how I fixed it was to edit #define dtNBR_ALARMS 6  // max is 255 to #define dtNBR_ALARMS 14   // max is 255 in the TimeAlarms.h file.

should this be an answer or add-on? you can edit the question

Looks like an answer to me. :)


text:
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x17
Every time I try to upload code to my arduino I always get this error : avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x17. How do i fix it ?

@Juraj Mine is 0x17 the other one is 0x00

nothing special for 0x17

@Juraj Different responses = different error

it is not an error code. it is a random value received instead of expected value

Welcome to the community! I'm not able to comment yet so i'll answer here.
Try changing the connection to other USB port.
If that doesnt work check this question, the solutions can be similar (Juraj is right in the comments) :
avrdude: stk500_getsync(): not in sync: resp=0x00," aka Some Dude Named Avr Won't Let Me Upload My Program
Good Luck!

Comments are not for answering, so you did the right thing by posting an answer. :)


text:
How to boil down analog input to just three cases?
I am investigating the use of a 3-position-switch for one of my projects to switch between different settings using just one analog input pin. For the three positions I am using ground/0V, ~2.5V (via 2x10k voltage divider) and full 5V. I am doing this also because I am planning to use a 5-position rotary switch in a similar way in the future.
Due to tolerances and noise, the readings on the analog pin are not precisely 0, 511, 1023, but rather 0-1, 509-512 and 1021-1023. To take this into account, I am using the map function like this:
const byte alarmSwitchPin = A0;
int alrmSwState;
byte alrmSet;
byte alrmPrevSet;

void setup() {
  Serial.begin(9600);
  pinMode(alarmSwitchPin, INPUT);

}

void loop() {

  alrmSwState = analogRead(alarmSwitchPin);       // Read input

  byte alrmSet = map(alrmSwState, 0, 1023, 0, 2); // Boil input down to three cases

  if (alrmSet != alrmPrevSet) {                   // Only if state of switch has changed
    switch (alrmSet) {
      case 0:
        Serial.println("Low");
        break;
      case 1:
        Serial.println("Medium");
        break;
      case 2:
        Serial.println("High");
        break;
    }
    alrmPrevSet = alrmSet;
    delay(200);                                   // For testing purposes
  }
}

I only want the setting to change (or, in this case, the console to print) when the state has actually changed. This does not work, though, because the map function is doing its math in integer, which fails in mapping the High position (in this case).
What are my options if I want to stick with the switch method? I am curious if it is possible to get this done without if statements and conditions or, as a more general question, what the best option is to properly map the 10 bit analog input to just 3 cases/numbers.
PS: I thought analogReadResolution() might be an option but I am working with Arduino UNO where this is unavailable.

Solve it with the analog value, not with the map function. The tilting points are at 256 and 768. Below 256 is 0, between 256 and 768 is 1 and above 768 is 2.

You have chosen a tricky method.  Likely you will need to use both hysteresis and averaging.  Averaging will slow down the response - no matter how fast the processor is.  If dead set on using a rotary input device, most would choose a rotary encoder which is digital in nature.

map will do alrmSwState/512, returning 2 only for 1023

The simplest fix to your problem is to change the map() call to
byte alrmSet = map(alrmSwState, 0, 1024, 0, 3);

In the call above, the mapped intervals are of the semi-open type, e.g.
[a, b), where the start values (namely 0) are understood as being
inclusive and the end values (1024 and 3) are exclusive.
Although not clear from the documentation, this is the proper way to use
the map() function. Otherwise, the truncated division gives you very
uneven intervals. Compare:
     x       map(x, 0, 1023, 0, 2)
----------------------------------
   0 –  511     0
 512 – 1022     1
1023            2

     x       map(x, 0, 1024, 0, 3)
----------------------------------
   0 –  341     0
 342 –  682     1
 683 – 1023     2

The result you get is very close to Jeff Wahaus’ answer.
What I find annoying about this approach is that a 32-bit integer
division, which map() uses internally, is a very expensive operation
on the small 8-bit Arduinos. If instead of 342 and 683, you use 256 and
768 as thresholds, then you can make the decision by just looking at the
high byte of the analog reading:
uint16_t alrmSwState = analogRead(alarmSwitchPin);

alrmSet = alrmSwState / 256;

if (alrmSet != alrmPrevSet) {
    switch (alrmSet) {
        case 0:
            Serial.println("Low");
            break;
        case 1:
        case 2:
            Serial.println("Medium");
            break;
        case 3:
            Serial.println("High");
            break;
    }
    alrmPrevSet = alrmSet;
    delay(200);
}

Note that the division by 256 is optimized by the compiler into a much
cheaper bit shift, but this is the case only if alrmSwState is of an
unsigned integer type. That's why it is declared above as uint16_t.

Thank you very much for pointing out how to properly use the map function (never heard of semi-open type before in this context). Also thanks for pointing me to a more efficient method.

I just tried using the uint: In mid position the case sometimes switches between 1 & 2 due to noise like touching an insulated wire (alrmSwState ~ 509-514). Therefore the if condition won't work as intended. As a workaround I am dividing by 250 with resulting usable cases 0, 2 & 4. This is not as efficient as you intended. Considering I am using an odd number of switch positions (meaning one position very close to the center / break point) am I right in my assumption that there is no way for me to get the division done as elegant as you suggested without adding a substantl amount of code?

@fertchen: The switching between 1 and 2 in the mid position is normal and expected. That's why case 1 and case 2 lead to the same statements in the example code above. If you have more than three cases, the simplest option may be to use map(). Otherwise, a chain of else if, though less elegant, is likely more efficient than map().

Replace the line:
byte alrmSet = map(alrmSwState, 0, 1023, 0, 2);
with
byte alrmSet = alrmSwState / ((1023 / 3) + 1);
And this should do what you want.  Note that in C fractional results are truncated (not rounded)

this is wrong. it will give 3, 2, 1, 0

It is correct.  The max value returned is 1023 when divided by 342 = 2.991... which will give the integer division result of 2.

sorry, I forgot that Calc rounds to the nearest. I upvoted

and map will do alrmSwState/512 which is not correct

Why 342 and not 343? I like to see comments in the code that explains all the numbers.

343 would work as well, but 342 gives the most even spread.  The number is derived by:  (1023 / 3) + 1  or  (Max_return_value / number_of_states) + 1

I agree with Jot here. It would be good if your code read byte alrmSet = alrmSwState / ((1023 / 3) + 1);. Then there are no magic numbers whose value is a mystery. The compiler will optimize out the division so this won't be inefficient.

Just three lines of code are needed for the conversion.
almSet=0;
if (alrmSwState>300) almSet++;   // increment almSet
if (alrmSwState>600) almSet++;

You might also consider reading the value several times and summing them, then base your decision on the sum.
This is equivalent to averaging the values but without dividing by 'n', since you don't care about the actual number, just the band it falls into. This will have the effect of improving the signal to noise ratio, since we assume that high-reading errors are as likely as low-reading errors, so their sum tends toward zero as the sum of the real value, V, tends toward (n*V).
Use an int or larger variable for the sum, depending on how many readings you choose to take each time.


text:
ATmega328, arduino nano v3 code error saying insufficient ram memory
the code error says this and im not sure what to do please i need urgent help :(`
// Easy bluetooth controlled scrolling text

// by Yoruk for Instructable

// 26 02 15 : first code
// 03 03 15 : buffer updating
// 04 03 15 : faster version, both buffers
// 05 03 15 : cleaning and help

/*
WIRING :
 pin 12 - DataIn of the first led matrix module
 pin 11 - CLK of the first led matrix module
 pin 10 - CS of the first led matrix module

 pin 9 : RX pin of the bluetooth module
 pin 8 : TX pin of the bluetooth module

 5V : 5v of the matrix module, 5v of the bluetooth module
 GND : the two GND signals of the matrix modules and the bluetooth module

 WARNING : Use a 3v3 arduino card (nano...) or a level converter !!!

 Wire the matrix modules in serie. See the Instructable steps.

 */

//Librairie for the LEDs matrix
#include "LedControl.h"

// virtual serial lib, used with bluetooth
#include <SoftwareSerial.h>

//How many matrixes we have ?
int MatrixNumber =5;

//virtual serial port bluetooth configuration
SoftwareSerial BT(8, 9);   //pin 8 : virtual RX    pin 9 :  virtual TX

// the delay between each screen display (ms)
int SpeedDelay = 12;

//total string lenght. The first message is 25 characters long (including spaces)
int LongueurChaine=25;

char incomingByte; //incoming data from the BT link

// the two pixels arrays
char Buffer[200];   //contient tout les pixels de TOUTE LA PHRASE
char Buffer_inverse[200]; //contient tout les pixels de TOUTE LA PHRASE, mais symetrises pour affichage sur ecran inverses

// the message array
char Phrase[50];

//here we set up the led matrix
LedControl lc=LedControl(12,11,10,MatrixNumber);

// character lib
int fontDefinitions[480] = {
    0x00,0x00,0x00,0x00,0x00,/*space*/ // is 32 in ASCII
    0x00,0xF6,0xF6,0x00,0x00,/*!*/
    0x00,0xE0,0x00,0xE0,0x00,/*"*/
    0x28,0xFE,0x28,0xFE,0x28,/*#*/
    0x00,0x64,0xD6,0x54,0x08,/*$*/
    0xC2,0xCC,0x10,0x26,0xC6,/*%*/
    0x4C,0xB2,0x92,0x6C,0x0A,/*&*/
    0x00,0x00,0xE0,0x00,0x00,/*'*/
    0x00,0x38,0x44,0x82,0x00,/*(*/
    0x00,0x82,0x44,0x38,0x00,/*)*/
    0x88,0x50,0xF8,0x50,0x88,/***/
    0x08,0x08,0x3E,0x08,0x08,/*+*/
    0x00,0x00,0x05,0x06,0x00,/*,*/
    0x08,0x08,0x08,0x08,0x08,/*-*/
    0x00,0x00,0x06,0x06,0x00,/*.*/
    0x02,0x0C,0x10,0x60,0x80,/*/*/
    0x7C,0x8A,0x92,0xA2,0x7C,/*0*/
    0x00,0x42,0xFE,0x02,0x00,/*1*/
    0x42,0x86,0x8A,0x92,0x62,/*2*/
    0x44,0x82,0x92,0x92,0x6C,/*3*/
    0x10,0x30,0x50,0xFE,0x10,/*4*/
    0xE4,0xA2,0xA2,0xA2,0x9C,/*5*/
    0x3C,0x52,0x92,0x92,0x0C,/*6*/
    0x80,0x86,0x98,0xE0,0x80,/*7*/
    0x6C,0x92,0x92,0x92,0x6C,/*8*/
    0x60,0x92,0x92,0x94,0x78,/*9*/
    0x00,0x00,0x36,0x36,0x00,/*:*/
    0x00,0x00,0x35,0x36,0x00,/*;*/
    0x10,0x28,0x44,0x82,0x00,/*<*/
    0x28,0x28,0x28,0x28,0x28,/*=*/
    0x00,0x82,0x44,0x28,0x10,/*>*/
    0x40,0x80,0x8A,0x90,0x60,/*?*/
    0x7C,0x82,0xBA,0xBA,0x62,/*@*/
    0x3E,0x48,0x88,0x48,0x3E,/*A*/
    0xFE,0x92,0x92,0x92,0x6C,/*B*/
    0x7C,0x82,0x82,0x82,0x44,/*C*/
    0xFE,0x82,0x82,0x82,0x7C,/*D*/
    0xFE,0x92,0x92,0x92,0x82,/*E*/
    0xFE,0x90,0x90,0x90,0x80,/*F*/
    0x7C,0x82,0x82,0x8A,0x4E,/*G*/
    0xFE,0x10,0x10,0x10,0xFE,/*H*/
    0x82,0x82,0xFE,0x82,0x82,/*I*/
    0x84,0x82,0xFC,0x80,0x80,/*J*/
    0xFE,0x10,0x28,0x44,0x82,/*K*/
    0xFE,0x02,0x02,0x02,0x02,/*L*/
    0xFE,0x40,0x20,0x40,0xFE,/*M*/
    0xFE,0x60,0x10,0x0C,0xFE,/*N*/
    0x7C,0x82,0x82,0x82,0x7C,/*O*/
    0xFE,0x90,0x90,0x90,0x60,/*P*/
    0x7C,0x82,0x82,0x86,0x7E,/*Q*/
    0xFE,0x90,0x98,0x94,0x62,/*R*/
    0x64,0x92,0x92,0x92,0x4C,/*S*/
    0x80,0x80,0xFE,0x80,0x80,/*T*/
    0xFC,0x02,0x02,0x02,0xFC,/*U*/
    0xF8,0x04,0x02,0x04,0xF8,/*V*/
    0xFC,0x02,0x0C,0x02,0xFC,/*W*/
    0xC6,0x28,0x10,0x28,0xC6,/*X*/
    0xC0,0x20,0x1E,0x20,0xC0,/*Y*/
    0x86,0x8A,0x92,0xA2,0xC2,/*Z*/
    0x00,0x00,0xFE,0x82,0x00,/*[*/
    0x00,0x00,0x00,0x00,0x00,/*this should be / */
    0x80,0x60,0x10,0x0C,0x02,/*]*/
    0x20,0x40,0x80,0x40,0x20,/*^*/
    0x01,0x01,0x01,0x01,0x01,/*_*/
    0x80,0x40,0x20,0x00,0x00,/*`*/
    0x04,0x2A,0x2A,0x2A,0x1E,/*a*/
    0xFE,0x12,0x22,0x22,0x1C,/*b*/
    0x1C,0x22,0x22,0x22,0x14,/*c*/
    0x1C,0x22,0x22,0x12,0xFE,/*d*/
    0x1C,0x2A,0x2A,0x2A,0x18,/*e*/
    0x10,0x7E,0x90,0x80,0x40,/*f*/
    0x18,0x25,0x25,0x25,0x1E,/*g*/
    0xFE,0x10,0x10,0x10,0x0E,/*h*/
    0x00,0x12,0x5E,0x02,0x00,/*i*/
    0x02,0x01,0x01,0x11,0x5E,/*j*/
    0xFE,0x08,0x08,0x14,0x22,/*k*/
    0x00,0x82,0xFE,0x02,0x00,/*l*/
    0x3E,0x20,0x1C,0x20,0x1E,/*m*/
    0x3E,0x20,0x20,0x20,0x1E,/*n*/
    0x1C,0x22,0x22,0x22,0x1C,/*o*/
    0x3F,0x24,0x24,0x24,0x18,/*p*/
    0x18,0x24,0x24,0x3F,0x01,/*q*/
    0x3E,0x10,0x20,0x20,0x10,/*r*/
    0x12,0x2A,0x2A,0x2A,0x04,/*s*/
    0x00,0x10,0x3C,0x12,0x04,/*t*/
    0x3C,0x02,0x02,0x02,0x3E,/*u*/
    0x30,0x0C,0x02,0x0C,0x30,/*v*/
    0x38,0x06,0x18,0x06,0x38,/*w*/
    0x22,0x14,0x08,0x14,0x22,/*x*/
    0x38,0x05,0x05,0x05,0x3E,/*y*/
    0x22,0x26,0x2A,0x32,0x22,/*z*/
    0x00,0x10,0x6C,0x82,0x82,/*{*/
    0x00,0x00,0xFF,0x00,0x00,/*|*/
    0x04,0x02,0xFF,0x02,0x04,/*|, arrow*/
    0x82,0x82,0x6C,0x10,0x00,/*}*/
    0x08,0x10,0x18,0x08,0x10/*~*/
};

void setup() {

    //matrix modules init
    for(int adresse=0;adresse<MatrixNumber;adresse++) {
        /*The MAX72XX is in power-saving mode on startup*/
        lc.shutdown(adresse,false);
        /* Set the brightness to a medium values */
        lc.setIntensity(adresse,4);
        /* and clear the display */
        lc.clearDisplay(adresse);
    }

//    BufferBuilding("Hi ! Sent me a message...", 25);   //first message on the led screen

    BufferBuilding("text", 4);   //first message on the led screen

    Serial.begin(9600); //we also set the normal serial link, for debug

    BT.begin(9600);      // bluetooth initialisation

    //we sent a message on the phone to tell the user that he can do someting...
    BT.println("Hi ! I'm waiting for a message. Type it and press SEND.");

}

void loop() {

    DrawText( LongueurChaine); //draw the message, in a loop

    //or, if we get something on the virtual bluetooth port...
    if (BT.available() > 0) {

        LongueurChaine = BT.available(); //incoming string lenght

        for  (int i = 0; i < LongueurChaine; i++) {

            // read the incoming byte:
            incomingByte = BT.read();

            Phrase[i] = incomingByte; ///store the character into the string array

        }

        //debug features, to check :
        Serial.print("Display: ");
        Serial.println(Phrase);
        Serial.print("Length : ");
        Serial.println(LongueurChaine);

        //buffers cleaning, to store the new message
        for(int k = 0; k < 200; k++) {
            Buffer[k]=0;
            Buffer_inverse[k]=0;

        }

        //we create the new buffers, so the new message will be drawn when leaving the sub
        BufferBuilding(Phrase, LongueurChaine);
    }

}

void BufferBuilding(char * stringToDisplay, byte stringLength)
{
    int i =0;

    //loop on every characters (on the string)
    for(int k = 0; k < stringLength; k++) {
        //here we call the characters library
        int caract= k;
        Buffer[i+0] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 0];
        Buffer[i+1] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 1];
        Buffer[i+2] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 2];
        Buffer[i+3] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 3];
        Buffer[i+4] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 4];
        Buffer[i+5] =  B00000000;  //one blank column of leds between two characters
        i=i+6;
    }

    // here, we create a second buffer, to display the message on the switched matrixes
    for(int k = 0; k < stringLength*6; k++) {
        for(int i = 0; i < 8; i++) {
            bitWrite(  Buffer_inverse[k] ,i,  bitRead(Buffer[k] ,7-i) )   ;
        }
    }
}

void DrawText( byte stringLength) {

    for(int k = 0; k < stringLength*6; k++) {

        delay(SpeedDelay);

//delay(10000);
        //k is the column

        //buffer drawing
        for (int m = 0; m < MatrixNumber; m++) {  //loop on the matrix
            if (m % 2 ==  0) //check is the module is upside-down or not...
            {
                //here, the matrix is flipped upside-down
                for (int i = 0; i < 8; i++) {  //loop on the columns

                      lc.setRow(m,7-i,Buffer[i+k+8*m]);
                }
            }
            else
            {
                //classical
                for (int i = 0; i < 8; i++) {  //loop on the columns

                       lc.setRow(m,i,Buffer_inverse[i+k+8*m]);
                }
            }
        }
    }

}

It means you are using too much RAM on the microcontroller.  Follow Juraj suggestion.

"im not sure what to do": You need to reduce the amount of RAM space (variables, strings, constants, large or numerous arrays) by moving constants, especially large ones like strings, to program memory. But without seeing your code, we can only guess. With only 5K of code and nearly 2K of globals, it does seem likely that you have used a lot of space for strings, and those are often easy to move to program memory. Show us the code if it isn't too huge, or at least gives us some clues from which to help you better.

Please provide source code if you want help.

how do i post the code here? its too long to be posted in the comments

Edit your question and format it correctly by selecting the code portion and click the {} button, or press Ctrl+k

thanks and i have edited the code in the question

first try to change int fontDefinitions[480] to const byte fontDefinitions[480]

The font definition table takes 960 bytes of RAM - nearly 1/2 of the the total usage. You can regain 480 bytes just by declaring that array as uint8_t; 1 byte each entry instead of 2 bytes each for ints. You can regain the remaining 480 if you still need to, by moving that table to program memory. The Arduino.cc site has a good discussion with examples. Just pay attention to the data-types you use if you do that; the functions to read data out of program memory each return one specific type.

You can free up RAM by moving large arrays and strings into Flash.  By default all strings and arrays are placed into RAM.  The disadvantage to putting data into Flash is that you will not be able to modify it at runtime.
To place an array in Flash use the PROGMEM compiler directive:
static const unsigned char PROGMEM my_array[] = { 0x00, 0x01, 0x02 ... };

When doing this your likely to notice, besides more available RAM, that many library functions can longer access the array you've placed into FLASH.  The AVR microcontrollers have to use special instructions to read data out of Flash memory.  Some library functions handle this automatically but many do not.  In order to access the data you'll have to implement a function that copies the data out of Flash and into RAM.
Here is an example of a function to copy Flash data into RAM:
char *Get_Flash_String(const char *FlashString)
{
    static char buff[MAX_FLASH_STRING_LENGTH+1];
    int i, len;

    len = strlen_P(FlashString);
    for (i = 0; i <= len; i++)
        buff[i] = pgm_read_byte_near(FlashString + i);

    return(buff);
}

Note that the function above assumes you're reading a NULL terminated string out of flash.  If you're reading an array you don't want to use strlen() to determine the length.

this answer is too general but not general. confusing. show him how to use it for his case.

Perhaps it's better to teach a hungry man to fish, rather than hand him a fish?

from this answer he learns nothing. the link in JRobert's answer is usefull. first I added it as comment, but then I deleted it, to not to confuse OP. changing the type of array item gains him memory for now

And you've been granted permission to speak for another person?

no. I always comment why I down-vote


text:
cannot show free space of SD card with arduino nano
I'm using a nano v3, the SD module and a 64GB microSD card.
Writing to the card works fine.
But I can't print out the free space left on the card.
I'm using this code:
/*
  SD card read/write

 This example shows how to read and write data to and from an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */

#include <SPI.h>
//#include <SD.h>
#include "SdFat.h"
SdFat SD;

#define csPin 4
File myFile;
SdFat sd;

int startMillis;
int duration;

uint32_t freeKB;

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

  Serial.print("Initializing SD card...");

  if (!SD.begin(csPin)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
  if (myFile) {
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  myFile = SD.open("test.txt", FILE_WRITE);

  for (int j = 0; j < 1000; j++) {
    myFile.println(j);
  }
  myFile.close();
  startMillis = millis();
  ShowFreeSpace();
  duration = millis() - startMillis;
  Serial.print("Took ");
  Serial.print(duration);
  Serial.println("ms to calculate");
  delay(1000);
}

void ShowFreeSpace() {
  // Calculate free space (volume free clusters * blocks per clusters / 2)
  long lFreeKB = sd.vol()->freeClusterCount();
  lFreeKB *= sd.vol()->blocksPerCluster()/2;

  // Display free space
  Serial.print("Free space: ");
  Serial.print(lFreeKB);
  Serial.println(" KB");
}

What am I doing wrong?

this is a very poor description of what actually happens can't print out the free space ..... it provides no information that could be used to answer the question

aJazz, did you see my answer?

You have two instances of SdFat class. In setup() you begin the SD and for free space you try to use sd. Delete SdFat sd; line and in ShowFreeSpace use SD.vol().


text:
ESP32 Dimmable LED Panel with MOSFET
I want to use ESP32 to control and use a dimmer for 6 LED panels in my bedroom. The specification of each panel is mentioned in the diagram. Although in the diagram it shows ONLY 1 MOSFET and 1 LED Panel but in reality there are 6 LED Panels therefore I am guessing that each of the 6 LED Panel will need a separate MOSFET.

I would like to know:

What MOSFET (Part number or model number, company name,  etc) should I use for the above LED panel connected with ESP32 (I guess voltage of ESP32 is 3.3 v) ?
Will each LED panel need separate MOSFET (6 LED Panels will need 6 seperate MOSFET) or can 1 MOSFET be connected to all 6 LED Panel ?
If I am using 6 LED Panels what should be the specification of Power Supply (Voltage & Amps) ?
If I use 6 set of MOSFET & LED Panels, can all MOSFETs be connected to a single PWM pin in ESP32 or does each MOSFET needs to be connected to separate PWM pins in ESP32 ?
Is the above circuit okay, or would you suggest some other components to be added apart from MOSFET?
What will be connection between power supply, LED and MOSFET.
I am guessing that 'Positive of Power Supply --> Positive of LED Panel', 'Negative of LED Panel -->  Source of MOSFET' and 'Drain of MOSFET --> Negative of Power Supply'. Kindly correct me if I am wrong.

Thanks.

To add more information regarding the LED panel:

It is 15W LED Panel (note it is not LED Bulb or LED Strip).
Link to LED panel is 15W LED Panel

Below is the picture of Driver that came with the LED Panel, note the below driver is non-dimmable.

Kindly help.

please provide a link to the datasheet for the LED panel .... if that is not available, then make and model of the LED panel .... or a web link to where it is sold

how do you want to dim a LED bulb with working voltage from 150 to 260 V? It will turn off under 150 and have full light over 150 V. it has a switching AC/DC power supply inside. use DC LED strips for the panel

Hi Juraj,
It is not LED bulb, it is a LED ceiling panel. I have added below more detail of the LED panel and picture of the original driver that came with the LED Panel.
Note that the original Driver is non-dimmable.

bulb or panel, it is the same principle for 'AC LED' . the LED bulb has the driver build-in. for the panel you could replace the driver, but it is not easy to do it right and sure not a question for Arduino SE. perhaps it is easy, only connect the DC side with the MOSFET and use PWM, but I can't tell if the driver likes it

Your plan has more flaws. First as Juraj wrote in a comment, you can't dim a switching power supply of the LED bulb. But this would not work as you plan even if you use a classic incandescent light bulb with AC. You can't control it with PWM. AC is dimmed with phase control, which requires a zero crossing detection to turn off power for part of the AC wave.

Hi, it is not LED bulb, it is a LED ceiling panel. I have added below more detail of the LED panel and picture of the original driver that came with the LED Panel. Note that the original Driver is non-dimmable.


text:
why my arduino uno r3 restart when plugged in to a battery(9v)
i have a personal challenge that is to make a arduino avoidance robot it has a"hc-sr04 ultrasonic sensor, a servo, bread board(for the sharing of vcc and gnd), l9110s motor driver, and two dc motors, and also the arduino uno itself"
but when i assembled it and upload the code it works if it's plugged in my laptop but if i plugged it in to a battery it keeps on restarting and doesn't run

please provide more info.  Do you mean a 9V alkaline cell to power the whole system?  If so this is a common beginners problem where the battery does not provide enough power.

PP3 batteries are, to put it mildly, complete and utter rubbish. Only suitable for powering smoke alarms. Not suitable for use with Arduino under any circumstances.

a 9V battery contains six AAAA cells ..... those would barely work in a tv remote control, let alone powering a motor

Let me guess: the Arduino resets just as one of the motors starts (or should start) right?
The 9v battery is incapable of supplying enough current for much of anything but a few LEDs. When the Arduino first turns on a motor, it needs, and tries to draw, more current than the battery can supply, resulting in the battery voltage dropping below the Arduino's voltage-regulator's minimum input voltage, and the Arduino is shut off. That stops the current draw, the battery voltage recovers, power up the Arduino, which resets (as they always do on power-up), and the cycle keeps repeating.
Try powering it from a more capable battery of greater than 7 volts. 5 AA cells in series, for example would provide 7.5 volts. This won't last terribly long but should work for a while. A second (third, ...) string of 5 in parallel with the first should double the life. Using C or D cells instead will increase the life a lot more.


text:
How do I stop the slave from running the code until master sends a new value? I2C
I'm a total noob when it comes to Arduino. I'm slowly learning stuff. I was trying this code which basically gets input in Arduino1(master) and displays the character in serial monitor of Arduino2(slave). The code words just find but I just need the slave to wait until the master sends the next character. Right now, the slave is continuously printing the character.
Master code:
    #include "Wire.h"
    char ch;

    void setup() {

      Serial.begin(9600);
      Wire.begin();

    }

     void loop() {
      while(Serial.available()==0)
      {}
      ch=Serial.read();
      delay(1000);
      Serial.print("The character that you entered is ");
      Serial.println(ch);

      Wire.beginTransmission(9);
      Wire.write(ch);
      Wire.endTransmission();

        }

Slave code:
#include "Wire.h"
char x;

void setup() {

  Serial.begin(9600);
  Wire.begin(9);
  Wire.onReceive(Event);

}
void Event(char bytes){
  x = Wire.read();
}

void loop() {

  Serial.print("The character that you entered in the other Arduino is ");
  Serial.println(x);
}

I know that this will be simple but I just can't quite figure out what to do. Please help me out

Changed the code. Please check now

send more bytes, read more bytes. collect bytes into a buffer, send the whole buffer and receive a buffer

@Juraj Please translate this into noob language. Sorry. Is there any modification to the code that I can do so I can get the slave to do this?

see master_writer and slave_reader examples in IDE File menu

#include "Wire.h"
volatile char x;
volatile bool received;

void setup() {
  Serial.begin(9600);
  Wire.begin(9);
  Wire.onReceive(Event);
}

void Event(char bytes){
  x = Wire.read();
  received = true;
}

void loop() {

  if (received) {
    received = false;
    Serial.print("The character that you entered in the other Arduino is ");
    Serial.println(x);
  }
}

Make both volatile?

yes, it is called from interrupt of course.


text:
How to connect NRF24 receiver and Micro SD Card Module to Arduino UNO
I would like to know how to connect a NRF24 receiver and Micro SD card module to Arduino board. I have already connected the NRF24 module to the arduino board but now i can't connect the Micro SD card module since the ports like 13,12,11 are used by the NRF24 module. Is there a way to connect those two modules?. I'm trying to save the receiving data on the Micro SD card.

SPI is a multi-drop bus protocol. That means that multiple devices can share the same physical communication medium (wires).
The only thing that needs to be "unique" for a device is its chip select pin which the master device (Arduino) uses to choose which of the devices on the SPI bus it's talking to.
So you can share pins 11, 12 and 13, but choose a different chip select pin for each device.
However, SD cards are notorious for not working well with other devices (especially with some cheap breakout boards) and your mileage may vary.


text:
Can an ultrasonic sensor differentiate b/w objects?
Can we potentially use an ultrasonic sensor to differentiate between objects based on the reflective capacity of the object?
For example to differentiate between metals and biodegradable wastes.

yes, but not in the way that you are implying .... it is not the sensor that does the differentiation, it is the computer program that does it

No. No, you can't. All they sense is the "time of flight".
The closest you would come would be to have a sensor which can detect physical properties of the target.  That could be colour, sound absorption, etc.  You'd need something that sends out a "broad spectrum" signal (white light, white noise, etc) and detects the reflected spectrum (colour sensor, wide-band microphone) and do spectral analysis of it.  The signal would also have to be fairly tightly focussed to exclude signals from the environment.
All-in-all not something for a little Arduino to consider without lots of extra expensive hardware.

I guess I could definitely use sound absorption.


text:
Speed controller for Ceiling Fan 220V AC 100W
I would like to use ESP32 to speed control my AC ceiling fan which is 220V AC 100 W.
Will the below AC dimmer work with ESP32 to speed control the ceiling fan which is 220V AC 100 W?
If not, kindly suggest a commonly used PWN dimmer that works with ESP32 to speed control ceiling fan with 220V 100W?
This is the link to Speed controller available on Amazon.

here a sample sketch https://robotdyn.com/pub/media/0G-00005677==Mod-Dimmer-5A-1L/DOCS/Glow.ino

Hi, I follow the attached code very well !
What I would like to know if the model of dimmer okay to take speed control and is okay to take the load of 220v 100W ceiling fan?

it is for 2 A (5 A peek), so yes, it is good for 230V/100 W motor. the information about current is on the photo of the backside of the module. and it supports 3.3V logic for esp32

Thank you very much.
I appreciate your help.

I used robotdyn code it works well with esp8266 but I want to use it for esp32. But few libraries of timer.h not supportable with esp32. Anyone tried with esp32. Please help me.

In theory, it should work to control the speed of fan. The manufactures description mentions "fan regulator". One of the pictures shows on the backside of the module that it is for 2 A (5 A peek). This should be good for 230 V / 100 W motor.
The module gives you a basic circuit to control AC. It reports zero-crossing and has an optocoupler switch to turn AC on and off. The dimming does your sketch, by cutting parts of the AC wave out in precise timing.
The example sketch is not good. It has delay in interrupt. With this implementation the sketch will not be able to do much else.
EDIT: I tested it and it works with fan too. The delay in interrupt is to create a short pulse to turn on the triac. The triac then turns self off on next zero-crossing. And Robotdyn changed the specs to 10 A.

I want to use this dimmer in blynk along with other IoT devices. The code you metioned has delays, can you suggest a code without delay function?

sorry. no. perhaps a second interrupt to turn AC back on after some microseconds. at 50 Hz one oscillation takes 20 miliseconds. a half wave takes 10 millisecs. you turn AC off at zero-crossing at turn it back after time between 0 and 10000 microseconds. longer time - less electricity - slower motor. other method, perhaps better for motor, is to take out entire half oscillations (this is described on the manufacturers page for the module)


text:
Serial monitor doesn't work with piezo buzzer
So I can't see the distance of the proximity sensor anymore as soon as I type the code for the piezo buzzer. I've tried many things but it doesn't work.. Can anybody help me fixing this?
int trigPin = D7;
int echoPin = D8;
int BLUE = D3; //D3 zit in blauw
int GREEN = D4;
int RED = D5;
int piezoPin = D10;

void setup() {// deze code gaat maar 1 keer
  Serial.begin (115200);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  pinMode(RED, OUTPUT);

}

void loop() { //code wordt steeds herhaalt
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH); // trig zendt een signaal uit
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH); // kijkt hoelang het duurt totdat signaal heen en weer gaat
  distance = (duration/2) / 29.1;
  // omdat het signaal heen wordt gezonden moet het door twee gedeelt worden
  // snelheid van geluid door lucht is circa 29 microseconden per cm dus gedeelt 29.

    Serial.print(distance);
    Serial.println(" cm");

//afstand wordt in cm weergegeven in serial monitor

  delay(500);

   if ((distance > 100) && (distance <= 150)){ //dit gebeurd er als de afstand vanaf sensor tussen groter dan 100 cm en gelijk aan of kleiner dan 150 cm is.
    analogWrite(BLUE, 0);
    analogWrite(GREEN, 255);
    analogWrite(RED, 0);

    tone(piezoPin, 1000, 1000); // toon duurt 1 seconden
    delay(2000); // 2 seconden geen geluid
    tone(piezoPin, 1000, 1000);
    delay(2000);

   }

   else if ((distance > 50) && (distance <= 100)){ //dit gebeurd er als de afstand vanaf sensor tussen groter dan 50 cm en gelijk aan of kleiner dan 100 cm is.
    Serial.println("Ga weg!");

    analogWrite(BLUE, 0);
    analogWrite(GREEN, 102);
    analogWrite(RED, 252);

    tone(piezoPin, 1000, 700); // toon duurt 0.7 seconden
    delay(1000); // 1 seconde geen geluid
    tone(piezoPin, 1000, 700);
    delay(1000);

  }

  else if ((distance >= 0) && (distance <= 50)){ //dit gebeurd er als de afstand vanaf sensor tussen groter dan of gelijk aan 0 cm en gelijk aan of kleiner dan 50 cm is.

    analogWrite(BLUE, 0);
    analogWrite(GREEN, 0);
    analogWrite(RED, 255);

    tone(piezoPin, 1000, 200); // toon duurt 0,2 seconden
    delay(100); // 0,1 seconden geen geluid
    tone(piezoPin, 1000, 200);
    delay(100);

  }

   else {
    analogWrite(BLUE, 0);
    analogWrite(GREEN, 0);
    analogWrite(RED, 0);

 }

}

I use a the NodeMCU

but there is no pin labeled D10 on NodeMCU

Can you explain what you have tried?

I have deleted some code and checked if anything was broken with my friend's code and redownloaded arduino

Pin D10 of NodeMcu is io 1 which is RX pin of Serial interface of the esp8266. Serial is on NodeMCU connected to USB. The pin is on board labeled RX.
D8 is boot config pin io 15. It must have pulldown on board. The pulldown can disturb the input on this pin. Use D6 (io 12) as echoPin.

I have changed the pin and it kind of works but not really good because it doesn't give the right distance it goes from 160 cm to 0 cm without moving anything...

but that is a different problem

D8 is io 15. it has a pulldown circuit on board. I don't know if it can disturb the measurement

I'm sorry but I don't know what io means. This is my first time programming with this program

try D6 (io 12) instead of D8

@TeddySmit, accept the answer to mark the question solved


text:
Motor not working when connected to motor driver shield?
My code is getting uploaded to arduino without problem but still my motor is not moving when i connect it to the motor driver shield. I am supplying 6V battery to the shield which is connected to dc motor at M2
What could be the problem?
Code:-
#include <AFMotor.h> //import your motor shield library

AF_DCMotor motor2(2,MOTOR12_2KHZ); // set up motors.
AF_DCMotor motor3(1, MOTOR34_1KHZ);

void setup() {
  Serial.begin(9600); // begin serial communitication
  Serial.println("Motor test!");
  motor2.setSpeed(105); //set the speed of the motors, between 0-255
  motor3.setSpeed(105);
}

void loop() {
   motor2.run(FORWARD);
   motor3.run(FORWARD);
  }

Do you have a picture of your setup?  You might also find this post on our Meta site helpful: How to ask a good question for Arduino Stack Exchange.

There is a large voltage drop to the motors. It is meant for 12v and (very) small 12v motors.

so it means if i supply 12v then it will work right? but the motor works with 5v also

The l293d outputs a voltage to a motor of 2.6v lower than the power supply. For 12v you need 12v motors.

When I power 12V to my motor shield for my 4 gear motor the arduino UNO is not turning on because of this my motors are not moving. What is the problem?

I cannot tell all of your connections from the photo, but I'm guessing you're supplying power to the Arduino through its power connector and also to the motors, both from the battery. The power connector on the Arduino is specified for 7-12v because the kind of voltage regulator it has needs that 2v difference to operate properly. You're kind of at the edge by supplying 6v, and when the motors come on, their current draw will cause the 6v battery voltage to drop somewhat. It probably drops below the regulator's ability to supply 5v from it, shutting down the Arduino.
Adding one more cell to your battery will give you 7.5v (5x1.5v) and will may be enough to run the Arduino and the motors. Two more cells would work even better. (Don't make the mistake of trying the small 9v batteries with snap-clips on top - their utterly incapable of supply the current your motors need).

cool, i will try to supply more power and see. thanks


text:
Out of two logically similar sketches, one works while the other does not
I am currently making a project involving a self balancing bot & found this code online:
#include "PID_v1.h"
#include "LMotorController.h"
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include "Wire.h"
#endif

#define MIN_ABS_SPEED 20

MPU6050 mpu;

// MPU control/status vars
bool dmpReady = false;  // set true if DMP init was successful
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer

// orientation/motion vars
Quaternion q;           // [w, x, y, z]         quaternion container
VectorFloat gravity;    // [x, y, z]            gravity vector
float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector

//PID
double originalSetpoint = 178.57;
double setpoint = 178.57;
double movingAngleOffset = 0.1;
double input, output;
double Kp = 50;
double Kd = 1.4;
double Ki = 60;
PID pid(&input, &output, &setpoint, Kp, Ki, Kd, DIRECT);

double motorSpeedFactorLeft = 0.6;
double motorSpeedFactorRight = 0.5;
//MOTOR CONTROLLER
int ENA = 5;
int IN1 = 6;
int IN2 = 7;
int IN3 = 8;
int IN4 = 9;
int ENB = 10;
LMotorController motorController(ENA, IN1, IN2, ENB, IN3, IN4, motorSpeedFactorLeft, motorSpeedFactorRight);

volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high
void dmpDataReady()
{
    mpuInterrupt = true;
}

void setup()
{
    // join I2C bus (I2Cdev library doesn't do this automatically)
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
        TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

    // initialize serial communication
    // (115200 chosen because it is required for Teapot Demo output, but it's
    // really up to you depending on your project)
    Serial.begin(115200);
    while (!Serial); // wait for Leonardo enumeration, others continue immediately

    // initialize device
    Serial.println(F("Initializing I2C devices..."));
    mpu.initialize();

    // verify connection
    Serial.println(F("Testing device connections..."));
    Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

    // load and configure the DMP
    Serial.println(F("Initializing DMP..."));
    devStatus = mpu.dmpInitialize();

    // supply your own gyro offsets here, scaled for min sensitivity
    mpu.setXGyroOffset(262);
    mpu.setYGyroOffset(-29);
    mpu.setZGyroOffset(-10);
    mpu.setXAccelOffset(-2109);
    mpu.setYAccelOffset(394);
    mpu.setZAccelOffset(1341); // 1688 factory default for my test chip

    // make sure it worked (returns 0 if so)
    if (devStatus == 0)
    {
        // turn on the DMP, now that it's ready
        Serial.println(F("Enabling DMP..."));
        mpu.setDMPEnabled(true);

        // enable Arduino interrupt detection
        Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
        attachInterrupt(0, dmpDataReady, RISING);
        mpuIntStatus = mpu.getIntStatus();

        // set our DMP Ready flag so the main loop() function knows it's okay to use it
        Serial.println(F("DMP ready! Waiting for first interrupt..."));
        dmpReady = true;

        // get expected DMP packet size for later comparison
        packetSize = mpu.dmpGetFIFOPacketSize();

        //setup PID

        pid.SetMode(AUTOMATIC);
        pid.SetSampleTime(10);
        pid.SetOutputLimits(-255, 255);
    }
    else
    {
        // ERROR!
        // 1 = initial memory load failed
        // 2 = DMP configuration updates failed
        // (if it's going to break, usually the code will be 1)
        Serial.print(F("DMP Initialization failed (code "));
        Serial.print(devStatus);
        Serial.println(F(")"));
    }
}

void loop()
{
    // if programming failed, don't try to do anything
    if (!dmpReady) return;

    // wait for MPU interrupt or extra packet(s) available
    while (!mpuInterrupt && fifoCount < packetSize)
    {
        //no mpu data - performing PID calculations and output to motors

        pid.Compute();
        motorController.move(output, MIN_ABS_SPEED);

    }

    // reset interrupt flag and get INT_STATUS byte
    mpuInterrupt = false;
    mpuIntStatus = mpu.getIntStatus();

    // get current FIFO count
    fifoCount = mpu.getFIFOCount();

    // check for overflow (this should never happen unless our code is too inefficient)
    if ((mpuIntStatus & 0x10) || fifoCount == 1024)
    {
        // reset so we can continue cleanly
        mpu.resetFIFO();
        Serial.println(F("FIFO overflow!"));

    // otherwise, check for DMP data ready interrupt (this should happen frequently)
    }
    else if (mpuIntStatus & 0x02)
    {
        // wait for correct available data length, should be a VERY short wait
        while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

        // read a packet from FIFO
        mpu.getFIFOBytes(fifoBuffer, packetSize);

        // track FIFO count here in case there is > 1 packet available
        // (this lets us immediately read more without waiting for an interrupt)
        fifoCount -= packetSize;

        mpu.dmpGetQuaternion(&q, fifoBuffer);
        mpu.dmpGetGravity(&gravity, &q);
        mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
        #ifdef LOG_INPUT
            Serial.print("ypr\t");
            Serial.print(ypr[0] * 180/M_PI);
            Serial.print("\t");
            Serial.print(ypr[1] * 180/M_PI);
            Serial.print("\t");
            Serial.println(ypr[2] * 180/M_PI);
        #endif
        input = ypr[1] * 180/M_PI + 180;
        Serial.println(input);
   }
}

The repo is linked to https://github.com/kurimawxx00/arduino-self-balancing-robot
My code is as below:
    /* For documentation purposes
 *
 * #define MPU6050_INTERRUPT_FF_BIT            7
 * #define MPU6050_INTERRUPT_MOT_BIT           6
 * #define MPU6050_INTERRUPT_ZMOT_BIT          5
 * #define MPU6050_INTERRUPT_FIFO_OFLOW_BIT    4
 * #define MPU6050_INTERRUPT_I2C_MST_INT_BIT   3
 * #define MPU6050_INTERRUPT_PLL_RDY_INT_BIT   2
 * #define MPU6050_INTERRUPT_DMP_INT_BIT       1
 * #define MPU6050_INTERRUPT_DATA_RDY_BIT      0
 *
  */

#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#include "PID_v1.h"
#include "LMotorController.h"

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include <Wire.h>
#endif

#define MIN_SPEED 20

#define DEBUG_BUILD

MPU6050 mpu;

// Variables for MPU status and control
bool isDMPReady = false;
uint8_t dmpStatus; // 0 if initialization succeeds
uint16_t dmpPacketSize; // default = 42
uint16_t fifoCount;
uint8_t fifoBuffer[64];
uint8_t mpuIntStatus;

// Variables for calculated data from DMP
Quaternion q; // // holds QUAT_W, QUAT_X, QUAT_Y, QUAT_Z from FIFO
int16_t gyro[3]; // Holds rotation
VectorFloat gravity; // holds gravity vector calculated from DMP
float ypr[3]; // 0 = yaw, 1 = pitch, 2 = roll

// PID data
double setPoint = 178.57;
double input = setPoint, output;
double Kp = 50;
double Kd = 1.4;
double Ki = 60;
PID pid(&input, &output, &setPoint, Kp, Ki, Kd, DIRECT);

// Motor config
const int inA = 6;
const int inB = 7;
const int inC = 8;
const int inD = 9;
const int enA = 5;
const int enB = 10;
const double motorCorrectionA = 0.6;
const double motorCorrectionB = 0.5;
LMotorController motorController(inA, inB, inC, inD, enA, enB, motorCorrectionA, motorCorrectionB);

// =================================================
// ===         Interrupt Service Routine         ===
// =================================================
volatile bool mpuInterrupt = false;
void dmpDataReady() {
    mpuInterrupt = true;
}

// =================================================
// ===              Program Setup                ===
// =================================================
void setup() {
    // join the I2C bus
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
        TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

    Serial.begin(115200);
    while(!Serial);

    // Initialize mpu
    Serial.println(F("Initializing I2C Devices: "));
    mpu.initialize();
    dmpStatus = mpu.dmpInitialize();

    // Gyro and accel offsets
    mpu.setXGyroOffset(262);
    mpu.setYGyroOffset(-29);
    mpu.setZGyroOffset(-10);
    mpu.setXAccelOffset(-2109);
    mpu.setYAccelOffset(394);
    mpu.setZAccelOffset(1341);

    // Verify initialization
    #ifdef DEBUG_BUILD
        Serial.println(F("Testing MPU Status: "));
        Serial.println(mpu.testConnection() ? F("MPU6050 initialization success!") : F("MPU6050 initialization failed!"));
        Serial.println(dmpStatus == 0 ? F("DMP initialization successful!") : F("DMP initialization failed!"));
    #endif

    if(dmpStatus == 0){
        // Enable DMP
        mpu.setDMPEnabled(true);

        attachInterrupt(0, dmpDataReady, RISING);

        // Get interrupt byte
        mpuIntStatus = mpu.getIntStatus();

        // Get DMP packet size ; default = 42B
        dmpPacketSize = mpu.dmpGetFIFOPacketSize();

        // Verify DMP initialization
        #ifdef DEBUG_BUILD
            Serial.println(mpu.getFIFOEnabled() ? F("FIFO Enabled!") : F("FIFO Not Enabled!"));
            Serial.println(mpu.getXGyroFIFOEnabled() ? F("FIFO X Gyro Enabled!") : F("FIFO X Gyro Not Enabled!"));
            Serial.println(mpu.getYGyroFIFOEnabled() ? F("FIFO Y Gyro Enabled!") : F("FIFO Y Gyro Not Enabled!"));
            Serial.println(mpu.getZGyroFIFOEnabled() ? F("FIFO Z Gyro Enabled!") : F("FIFO Z Gyro Not Enabled!"));
            Serial.println(mpu.getAccelFIFOEnabled() ? F("FIFO Accel Enabled!") : F("FIFO Accel Not Enabled!"));
            Serial.print(F("DMP Packet Size: "));
            Serial.println(dmpPacketSize);
        #endif

        isDMPReady = true;

        // Setup PID
        pid.SetMode(AUTOMATIC);
        pid.SetSampleTime(10);
        pid.SetOutputLimits(-160, 160);
    }
    else{
        Serial.println(F("DMP Error!!!"));
    }
}

// =================================================
// ===            Main Program Loop              ===
// =================================================
void loop() {
    // Do nothing if DMP initialization failed
    if(!isDMPReady) return;

    while(!mpuInterrupt && fifoCount < dmpPacketSize){
        pid.Compute();
        motorController.move(output, MIN_SPEED);
    }

    mpuInterrupt = false;
    mpuIntStatus = mpu.getIntStatus();

    fifoCount = mpu.getFIFOCount();

    if(mpuIntStatus & 0x10 || fifoCount == 1024){
        mpu.resetFIFO();
        Serial.println("FIFO Overflow");
    }
    else if(mpuIntStatus & 0x02){
        while(fifoCount < dmpPacketSize) fifoCount = mpu.getFIFOCount();

        mpu.getFIFOBytes(fifoBuffer, dmpPacketSize);
        fifoCount -= dmpPacketSize;

        mpu.dmpGetQuaternion(&q, fifoBuffer);
        mpu.dmpGetGravity(&gravity, &q);
        mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
        // TODO: implement complementary filter
        input = ypr[1] * 180 / M_PI + 180; // Supposing at upright position, pitch is 180 degrees

        #ifdef DEBUG_BUILD
            Serial.print("Yaw/Pitch/Roll: ");
            Serial.print(ypr[0] * RAD_TO_DEG);
            Serial.print("\t");
            Serial.print(ypr[1] * RAD_TO_DEG);
            Serial.print("\t");
            Serial.println(ypr[2] * RAD_TO_DEG);
        #endif
    }
}

I am using the exact same libraries and classes as in the repo. Yet my code does not work at all, the motors move erratically. All the physical connections are ok since the code from the repo works flawlessly. I've no idea why this is happening. Help is very much appreciated.

Given that both libraries are the same.
The two sketches seem to set up the motorcontroller quite differently. Changing an "input pin" and "enable pin" around, would lead to errratic motor behaviour.
```
LMotorController motorController(ENA, IN1
LMotorController motorController(inA, inB
```
To me, an input pin would be an PWM signal to drive the speed of the motor.
An enable pin, would enable/disable the whole driver (both left/right).
But it's hard to tell, also, if the above sketch is working, why not use the above sketch and adjust that?

Oops! Totally missed that there. Should pay more attention to the header files :D

Another thing I noticed while tinkering, interrupts from the MPU6050 can only be caught by the Uno when serial comm is set to 115200 baud rate or higher. Anything lower causes the MPU interrupts to be never caught. Maybe this is a particular problem of my board (it's a cheap chinese one), but maybe this will help someone out somehow. :)


text:
Baud rate of Arduinos bootloader
I am learning UART  and the problem that i have is understanding what happens when i send serial data to my PC via USB which is built in to the Arduino uno board.
For incoming serial data i am using Terminal v1.9b and it basically lets me to set some parameters and listen to incoming data on Software serial port and or write to it.
The process:

Atmega328p's Baud rate is set to 9600
Terminal connects to it (it performs a reset) and i get my data in.

Very simple, it all works and i don't have a problem with it. What my question is: I assume that my PC doesn't talk to atmega328p directly since it has no USB interface. it talks to a bootloader chip which converts the USB to UART and then i receive that message on my atmega328p. How does that chip know which baud rate we agreed to. OR "Terminal" sends the baud rate to that bootloading chip via usb protocol and it sets its UART settings ?

The Arduino boards featuring a USB connector have a FT232RL converter chip. The PC has to tell the FT232RL through the USB which bitrate to use. It has to be the same as that the ATmega328 on the Arduino board is set to.

on my arduino it is not ft2332rl, i am using UNO, i thing it is atmega8 with U

Arduino UNO Rev. 3 CH340 Clone Board

Even Arduino website mentions the MegaU8 is used as a USB-to-serial chip, so what @Janka said still applies. Should be the answer.

@Justme Ok i found the device i was looking for and i got the concept. now another question. by defalt windows recognizes the device as a serial port. what if i wanted to write a driver for it where would u recomend to start ?

That's a completely different question. The MegaU8 is programmed to be a standard USB serial port, so it is a serial port and it will work with standard serial port drivers that come with Windows and every software compatible with serial ports can use it. If you want to write custom drivers, you would also need to rewrite the MegaU8 firmware so that it does not look like a USB serial port any more.

@Justme a comment above describes the situation as it is not mega, it is just USB to serial converter... Chinese clone board

https://cdn.sparkfun.com/datasheets/Dev/Arduino/Other/CH340DS1.PDF

The bootloader runs in the 328, and just as your application programs do, it sets a UART baud-rate for uploading programs to the Uno.
Current bootloaders use 115200 baud for upload; the most recent previous ones used 57600 baud. Setting that is part of the bootloader code. Whatever your application program last set for a baud-rate doesn't matter; if you reset the Uno, the bootloader sets the UART to the known upload baud-rate, and waits briefly for the PC to begin an upload, and jumps to the currently loaded application program if no upload is begun.
Your PC's Arduino IDE configuration is written to use the known bootloader baudrate (you can see that in the avrdude command). In fact, since I have some boards with soldered-in chips with the older, 57600 baud bootloader burned in them, I have two Uno-board configurations in my IDE; one for those older chips, and one for the current ones.

Thanks for the answer, yeah i figured what bootloader is, and my question was not asked correctly. Since i have another USB to serial converter it shows up as a COM device on my computer. What would it take to actually make this device appear as USB storage for example. would i need to write the driver for it ? and how would i apply the driver to the chip if i have no way of changing it's PID.

This is really a new question, but the short answer is, you'd have to reprogram the Uno's USB processor (Atmega 8U2) to act like whatever other kind of USB device.


text:
NODEMCU 1.0 HX711 Load cell reading weird text

Hi Guys! i have a problem with the reading with my NODEMCU where i tried this code on an arduino UNO it is working perfectly fine but until i tried to switch it to NODEMCU 1.0 which have a wifi function that i need, the reading turn out to have this type of error, i've tried looking for solution online and tried every single of them but apparently none of it help. The image is the error i have faced and the connection i have made from the nodemcu to hx711 is VCC --> Vin or 3.3v, GND --> GND, DT --> D2, SCK --> D3.
Here's the code that i found online to use:
#include <HX711.h>

// Scale Settings
const int SCALE_DOUT_PIN = D2;
const int SCALE_SCK_PIN = D3;

HX711 scale(SCALE_DOUT_PIN, SCALE_SCK_PIN);

void setup() {
  Serial.begin(115200);
  scale.set_scale(-47740);// <- set here calibration factor!!!
  scale.tare();
}

void loop() {
  float weight = scale.get_units(1);
  Serial.println(String(weight, 3));
}

Thanks in advance!!

Putting your whole code in comments is not helpful.  I edited your post this time, remember to select code and then ctrl+k

Sorry about that, would keep in mind about it! Appreciate your help thanks!

try D1 instead of D3. D3 is io 0, a boot configuration pin

Hi juraj! Thanks for the reply. i tried D1 and the Serial monitor now shows a reading of 0.000 all the way regardless of the weight i put on it.

Hi juraj, i have change the VCC connection from Vin to 3.3v and it work! thanks!! could you post your answer on the answer section so i could upvote? thanks for the help!!

Try D1 instead of D3. D3 is io 0, a boot configuration pin with pull-up on board.