text:
Powering L298N drivers from mains power supply
I am powering 2 stepper motors with an L298N driver each (from a 9V 2A external power supply powered from the mains: https://www.amazon.co.uk/BERLS-Power-Adapter-Elegoo-Connectors/dp/B07GSM6YLX/ref=sr_1_5?ie=UTF8&qid=1550859082&sr=8-5&keywords=AC%2FDC+Power+Adapter+for+Arduino).
I am wondering how I can connect the driver 5V and GND pins to the power supply?
Thanks in advance!

You would not connect the +5V lead to the power supply. Connect the ground between the driver, the Arduino, and the power supply. Connect the 9V from the power supply to the driver. Connect the logic lines from the Arduino to the inputs on the driver.

Thanks Duncan for your advice. However, given that the external 9V DC adaptor is connected through the barrel jack to the Arduino Mega, how could i connect this to the driver directly? Similarly, how would the ground connect to this power supply adaptor?

If you're going to use the same power supply for both you should probably build a splitter out of a female power jack and 2 male cables. You'd connect one to the Arduino and the other to the motor driver. The Arduino would regulate the 9V down to 5V and the motor driver would use the 9V directly. They would have common grounds.

You might need to add a fairly large electrolytic capacitor between 9V and ground right near the barrel connector for the Arduino. This would serve to even out dips in voltage as the motor driver turns the motor coils on and off, and prevent the Arduino from dropping out. (That would really only be needed if the voltage to the Arduino's barrel connector drops below around 7V at peak current demand from the motor driver, and would likely only happen if your peak current gets close to the 2A limit of your power supply.)

i see many thanks for your advice ille take a look into that

You'll need another supply, or a step-down supply for the 5v; same ground for all.
Also H-bridges are really inefficient to drive steppers, you should get a dedicate stepper driver.

Thanks for your advice. How exactly would the step-down supply be connected from the power supply to the driver, given that the 9V DC adaptor is connected to the Arduino barrel jack?

@Anonymous well in that case you are actually using the arduino's voltage regulator, IIRC as long as your under the power budget you can power the driver boards logic from the 5v line of the Arduino, and connect 9v to both the Arduino and the motor in on the driver.


text:
Accessing 2 dimensional array in PROGMEM inside loop
I am unable to access elements of a 2D PROGMEM array from inside a loop. Please see the following example:
const byte a1[] PROGMEM = {'a', 'b', 'c', 'd'};
const byte a2[] PROGMEM = {'e', 'f', 'g', 'h', 'i'};
const byte a3[] PROGMEM = {'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'};
const byte a4[] PROGMEM = {'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

const byte * const arr[] PROGMEM = {a1, a2, a3, a4};

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

  Serial.println(pgm_read_byte(&(arr[0][0])));
  Serial.println(pgm_read_byte(&(arr[1][0])));
  Serial.println(pgm_read_byte(&(arr[2][0])));
  Serial.println(pgm_read_byte(&(arr[3][0])));
  for (int i = 0; i < 4; i++) {
    Serial.print(i);
    Serial.print(":");
    Serial.println(pgm_read_byte(&(arr[i][0])));
  }
  int j = 0;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 1;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 2;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 3;
  Serial.println(pgm_read_byte(&(arr[j][0])));
}

void loop() {

}

The output is:
97
101
106
114
0:12
1:174
2:12
3:148
97
101
106
114

I verified and re-verified the syntax so many times. could not find anyone facing similar issue. I am at my wits end why it would not print correct values inside the loop. Any ideas?
EDIT: expected output is:
97
101
106
114
0:97
1:101
2:106
3:114
97
101
106
114

the constant uses like arr[1][0] are replaced at compile time with the items value. they are not read from the array in runtime. even with j with constant value the compiler evaluates it at compile time and replaces with the value

I think you are right.. is there any way I can achieve accessing the elements from inside the loop?

https://www.arduino.cc/reference/en/language/variables/utilities/progmem/

I had already gone through it.. after you put it here, i took some ideas and made it work.. giving below as answer.. thanks..

@Juraj sorry, i guess i don't have option to upvote you since i am new here..

You can make it easier. For example when each array is a zero terminated string, or when all the arrays have the same fixed size, or one long string with markers. A two-dimensional array with a different number of elements without knowing how many elements are valid, that seems so very weird.

const byte a1[] PROGMEM = {'a', 'b', 'c', 'd'};
const byte a2[] PROGMEM = {'e', 'f', 'g', 'h', 'i'};
const byte a3[] PROGMEM = {'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'};
const byte a4[] PROGMEM = {'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

const byte * const arr[] PROGMEM = {a1, a2, a3, a4};

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

  for (int i = 0; i < 4; i++) {
    Serial.print(i);
    Serial.print(':');
    for (int j = 0; j < 4; j++) {
      Serial.print((char) pgm_read_byte_near(pgm_read_word(arr + i) + j));
      Serial.print(',');
    }
    Serial.println();
  }
}

void loop() {

}

output
0:a,b,c,d,
1:e,f,g,h,
2:j,k,l,m,
3:r,s,t,u,

at runtime the size of the arrays is unknown, so I print the first 4 items

After going through link given by Juraj above again, I could make it work as follows:
const byte a1[] PROGMEM = {'a', 'b', 'c', 'd'};
const byte a2[] PROGMEM = {'e', 'f', 'g', 'h', 'i'};
const byte a3[] PROGMEM = {'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'};
const byte a4[] PROGMEM = {'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

const byte * const arr[] PROGMEM = {a1, a2, a3, a4};

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

  Serial.println(pgm_read_byte(&(arr[0][0])));
  Serial.println(pgm_read_byte(&(arr[1][0])));
  Serial.println(pgm_read_byte(&(arr[2][0])));
  Serial.println(pgm_read_byte(&(arr[3][0])));
  for (int i = 0; i < 4; i++) {
    Serial.print(i);
    Serial.print(":");
    Serial.println(pgm_read_byte_near(pgm_read_word(&(arr[i])) + 0));
  }
  int j = 0;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 1;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 2;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 3;
  Serial.println(pgm_read_byte(&(arr[j][0])));
}

void loop() {

}

Now it shows the expected output and access from inside loop using variable index is possible. Thanks.

source: Stack Exchange

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

sort: votes


text:
Arduino Genuino UNO
I have Arduino Genuino Uno and 'Extra PC' Debian Linux USB dongle. I can get board data S/N etc., but TX LED permanently lit and data showing on TX line with an oscilloscope. I get the following error message:
avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied

An error occurred while uploading the sketch.
Any body know how to create this device?

what is Extra PC?

I think it means XTRA PC https://www.xtra-pc.com/ - which are these PC on a dongle thing, for windows XP, Vista, 7 .... not for connecting to a UNO

access rights https://www.arduino.cc/en/Guide/Linux#toc6

That is a overpriced and overrated usb flashdrive with linux installed on it. They ask 5 times more than the current prices for fast usb flashdrives. Grab an old usb flashdrive you already have, download the iso of your choice and use Rufus to put it on the flashdrive. Install it on a second fast flashdrive. Or try puppylinux which is loaded into ram for extra speed. All for free if you already have a flashdrive. Even a used ssd drive is cheaper than XtraPC. That will make a 10 year old computer run like a 3 year old computer. M Saunders, can you return it and get your money back?

Try it with sudo

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


text:
Choosing a motor for my project
Sorry For my bad English.
I will start to make a mini conveyor (100 cm x 30 cm) with an Arduino Uno.
What is the best motor should I choose for my project ?
- Stepper Motor ?
- DC Motor ?
Etc.
Please help me, I am Newbie.

If you want to control how much the conveyor moves and want to move it a fix distance then stop and move again stepper would be better as you know that each step is equivalent to a certain amount of displacement. Stepper have the disadvantage that is more complicated to control so you will need a special driver.
If you want the conveyor to move continuously at a approximately speed or moving approximately, then DC motor is a good option. It's easier to drive. But if you want the conveyor to go back and forward then you will need a H bridge for the DC motor(similar to the driver for the stepper motor). Also you can get very accurate positioning with a DC motor using a rotary encoder, but it requires a complex software to drive it properly.

I second the suggestion that a stepper motor might be a more suitable drive mechanism.  There are a lot of stepper motors for sale on line for very low cost that can provide great accuracy.  They are an amazing value, probably because of so many robotics projects to supply.  Their native accuracy can be enhanced many times by use of what is called a "micro-step" driver.  The micro-step driver can transform a stepper motor that has 200 native steps per revolution to one that effectively has 2000 or more steps per revolution. I have found repeatability to be excellent.  They are used commonly to drive precision CNC machines.
And you are correct that if you don't need the fastest motion, a gear reduction can enhance accuracy even more.  There are small stepper motors with affixed gear boxes sold as sets.  Consider a size NEMA 17 stepper motor for a small and inexpensive, but well engineered, motor.
A coupled worm gear box has the advantage that it serves as a natural brake if there is any tendency for system weight to move the laser in certain positions, but gear reduction means that fast motion require higher motor rpm's.
The Accel_Stepper library has worked well for me in helping to get them to function smoothly.  It helps a lot to make it easy to integrate the stepper with Arduino, and it is fairly user-friendly.


text:
Real-time Pub/Sub thru MQTT between JoyStick and OnBoard Drive units [both ESP8266] - Connection issues
I looked around for solutions to my issue by searching on the forum and elsewhere and haven't seen similar issues - (https://arduino.stackexchange.com/search?page=2&tab=Relevance&q=MQTT%20ESP8266)
I am describing below what I am trying to achieve: (I am relatively new)
I would like to pass streaming joystick data from a "Remote Control" through MQTT to a "OnBoard" unit to drive my robot. Both the "Remote Control" and "OnBoard" units are NodeMCUs ESP8266.
I am able to separately send data from my Joystick to the MQTT broker and also separately read streaming data from the MQTT broker on any MQTT client. However, the moment I connect the "Remote Control" and the "OnBoard" Units to run their respective code, I keep receiving a Lost Connection to MQTT server error. I also observe this happens right after my Joystick ESP8266 connects.
I suspect this is related to one of the following -

0>> I am doing something fundamentally wrong [Syntax, usage of libraries, logic?]
connection parameters to the MQTT client [keep alive?, QoS?, delay?] b) there
is something to with sequence of Sub & Pub?
the version of ESP MQTT libraries i am using??
this is not the best way to stream data to
control devices? WebSockets?

I am copying my code for both units below:
RemoteControl Unit: [Joystick input is given through Serial]
#include <PubSubClient.h>
#include <EspMQTTClient.h>

void onConnectionEstablished();

EspMQTTClient client(
  "mywifi",           // Wifi ssid
  "somepwd!",           // Wifi password
  "iot.eclipse.org",  // MQTT broker ip
  1883,             // MQTT broker port
  "usr",            // MQTT username
  "mqttpass",       // MQTT password
  "test1",          // Client name
  onConnectionEstablished, // Connection established callback
  true,             // Enable web updater
  true              // Enable debug messages
);

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

void onConnectionEstablished()
{
  Serial.println("Remote Connection Established");
}

void loop()
{
  if (Serial.available() > 0) {
    Serial.println("Inside Serial");
    char bfr[101];
    memset(bfr,0,101);
    Serial.readBytesUntil('\n',bfr,100);
    client.publish("DriveChannel", bfr);
  }
  client.loop();
}

OnBoard Unit:
#include <PubSubClient.h>
#include <EspMQTTClient.h>

void onConnectionEstablished();

EspMQTTClient client(
  "mywifi",           // Wifi ssid
  "somepwd!",         // Wifi password
  "iot.eclipse.org",  // MQTT broker ip
  1883,             // MQTT broker port
  "usr",            // MQTT username
  "mqttpass",       // MQTT password
  "test1",          // Client name
  onConnectionEstablished, // Connection established callback
  true,             // Enable web updater
  true              // Enable debug messages
);

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

void onConnectionEstablished()
{
  client.subscribe("DriveChannel", [] (const String &payload)
  {
    Serial.print("In Connection payload---> ");
    Serial.println(payload);
  });
}

void loop()
{
  delay(3000);
  client.loop();
}

try different client names

@Juraj perfect... missed that. Thank you for pointing out.

was it the cause?

Yes @juraj. I think that was the issue. Since the other mqtt clients (app or browser based) assign their own client id I wasn't having an issue subscribing to it but these two had the same client ids and that seemed to conflict. I have a steady stream of data flowing now with no loss of connection. However, I am seeing a significant delay, it almost feels like instructions being sent to Mars Rover :) , about 10 to 20 second delay for the signals to reach my Onboard unit from the joystick unit.

and the 3 secs delay in loop?

@Juraj the 3 seconds was only during test , i had removed it but continue to see the delay. Maybe my network or a free version of the broker that's causing the delay.


text:
Distributing power evenly to multiple pins
It's an arduino board, model UNO R3. I have 3 5cmx10cm heating pad power required 5V DC up to 1A and can withstand up to 12V DC. These 3 heating pad are wired up onto arduino board with red wires connected to pin 8 pin 9 and pin 10 on the digital side of the arduino and the black wire connected to GND (ground). Lastly I have a toggle on and off switch connected to the arduino with the red wire attached to digital pin 2 and the black wire to 5V. The arduino uno R3 withstand 20voltage and the 5V heating pads can withstand 12V. I would like my 20V external power to heat up all 3 heating pads evenly, how can I do this? Is it possible? Thank you!

You could put the three pads in series, so they run on 15-36 Volt. But I suspect there's more wrong here. You can't connect a 1A heating pad to an Arduino pin directly, as it can't deliver that much current, and will likely get damaged. The on-off switch also needs a (pull-down) resistor to work reliably.

Do not connect these heating pads to your Arduino. You will overload the Arduino. Also don't connect AC power to the Arduino.

To be clear, you should not try to draw power from Arduino pins. An arduino is made to output very low power control signals out of it's pins, NOT power. (You should draw at most 20 milliamps from each pin on the Arduino. That's 20 thousandths of an amp.)

Yes, of course it is possible.  But if all you need to do it to turn these heat pads on and off, an Arduino is perhaps not the most suitable technology.
But presuming these heat pads are a component of some more complex system that responds to other inputs or outputs to/from the Arduino, you will need a few more components.  You need to accomplish two things that the UNO R3 cannot accomplish by itself, because your heat pads are very much too large a load for your UNO to power directly.  (The power for a single LED bulb is about the most that you can draw from an output pin.)

You need to reduce your 20-V external power source down to something less than 12 volts to supply your heating pads.
You need to switch on and off up to 1 amp of current to flow to each of the three heating pads.  The UNO cannot do this directly.

There are a lot of ways to reduce your 20-volt supply down to less than 12 volts.  Some are much more efficient than others.  Probably the lowest cost efficient way is to use your 20-V source as the input a small DC to DC voltage down stepping converter.  These are available online from Chinese vendors for very low cost.  Just search for "DC-DC converter down".  A quick search finds one rated at 20 amps, with adjustable voltage output can be purchased for less than $10.  These are pretty efficient devices that don't waste the power that a simple voltage dropping resistor would waste.
Then you need either one or three 5-volt relays of some type to switch the power on to the heat pads.  The UNO pins output of 5-volts would not provide current to heat pads, put only enough current to energize the relay(s).  The relay(s) can be either solid state, or coil energized.  Just be sure the relay "contacts" are rated to handle well more than 1 amp if there are three of them, and more than 3-amps if only one.   An Arduino relay shield with four relays, each rated for 10 amps, can be purchased for less than $5.
If you only every want all three heat pads energized at the same time, you only need one relay, and one Arduino output to energize it.
The very simplest solution, if you only want all the pads heating simultaneously, would be to wire the three heat pads in series.  Then you could apply your 20-volts directly across all three heat pads, and you would not need any device to reduce your supply voltage.  Each heat pad would have 1/3 of 20 volts across it, which is well under their 12 volt tolerance.  And you would only need one relay.

Yes, I want to do exactly what you wrote in the last paragraph on my arduino uno r3 so I can connect 20volt (to power jack). When you say wire the three heating pads in a series. How does that look, am I to connect/attach all 3 red wires of heating together to each other?
Heating pads: https://www.adafruit.com/product/1481
Arduino: https://store.arduino.cc/usa/arduino-uno-rev3
Transistor: https://www.creatroninc.com/product/tip120-npn-darlington-power-transistor-60v-5a/?search_query=TIP1

Is a TIP120 - NPN Darlignton power transistor: the current flow between the collector and the emitter of is controlled by the current flow through the base The same thing as a DC-DC voltage down stepping converter?

Rebecca, I don't mean to be dismissive, you need to do some study on the difference between wiring components in series compared to wiring them in parallel.  If you are building this thing, you need to understand the wiring if something fails.  Just google "series vs parallel wiring".  I cannot explain without drawings, but it is like hoses connected end to end to make one long hose.  Those heat pads have no polarity, no "plus" and no "minus" so the color of the wire probably makes no difference.

https://www.creatroninc.com/product/tip120-npn-darlington-power-transistor-60v-5a/?search_query=TIP120&results=3

The transistor is not the same as a DC-DC converter.  You don't need this transistor.  It is not suitable technology for your application.  Perhaps someone told you to make a power switch out of it . . . Just get a relay.

The 5x10cm 5V operating heating pad (hand size) are already wired parallel and placed inside a chair. So I cannot re-wire and will have to get a DC-DC step down converter and relay to distribute heat to each of my 3 heating pads.

Rebecca . . why are you trying to use Arduino?  If all you want it to turn all 3 pads on and off at same time, just wire the 20-volt source, the switch, and all 3 pads in series, and disregard all else.  Google "series switch circuits" to understand this simple wiring.

Since heat pads are now wired in parallel, all additional that you need is the DC-DC converter.  The heat pads would be in parallel with each other, and in series with (or "connected to") the output of the DC-DC converter.  You would wire the switch in series with the 20-volt supply and the input side of the DC-DC converter . . .    You don't use Arduino, or relays, or transistor..

Or if the 20-volt supply has a built-in ON/OFF switch, you don't need to add another switch.  Just wire the input side of the DC-DC converter to the 20-volt supply.  Then just turn on the 20-volt supply when you want heat.  Adjust the output of the DC-DC converter to something between 5 volts and 12 volts.  A higher voltage (like full 12 volts) will make more heat, but the heat pads might burn out quickly, especially if they are surrounded by fabric that limits heat conduction away from the pads.

Rebecca . . . on more thing . . . you need to be sure whether your 20-volt source puts out AC voltage, or DC voltage.   If it is AC, then then you need to buy a step-down converter that will work with either AC or DC as input.  They are about the same price.  As you may know, the heat pads are designed to be power by DC voltage.   I'm sorry to all that this is so far off Arduino topic, but why not try to help?.

Yes its AC 20V adapter, but does the DC-DC converter have a power jack to plug in the adapter?

If your 20V supply is AC then you can use a 1:2 step-down transformer to drop the voltage to 10V. That's cheap and easy. You can't use AC to power an Arduino, nor can you run your heater from the Arduino. As others have said, it sounds like an Arduino doesn't have any place in this project. You just need switch and a way to lower your 20V to something in the 5V to 12V range, and since it's AC a step-down transformer would be perfect.

It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.https://store.arduino.cc/usa/arduino-uno-rev3
the arduino is serving as an outlet to plug in my 20V AC Adapter. How else would I attach?

John P. My 20volt AC Adapter won't be able to attach the DC-DC converter because the end of the adapter is not a wire it's a plug, what other options are there?

Buy one of these from this or another vendor.     https://www.ebay.com/itm/3ft-DC-Power-Socket-to-Bare-Wire-5-5x2-1mm-DC-Female-to-Open-End-18AWG/161822453332?hash=item25ad5eae54:g:EDEAAOSwiLdV8kCn:rk:9:pf:0

Duncan C the arduino can withstand up 20V and my 3 heating pads are 15V all together. It's not a heater it's a heating pad and the electronic store and the teacher never said that the heating pad aren't allowed or else I would of created a different project.

Rebecca, if this is an Arduino class project, I take back what I said about the Arduino not being appropriate.  Many learning projects are not exactly appropriate Arduino technology, but we still can learn from them.  But you will just be using it as a switch, and you need to go back to using the Arduino to energize a relay that will turn on/off power to the pads.  I hope the teacher can help confirm your wiring.

So I need to get a relay and also the DC-DC conveter, that's the rest that I need?

You need to get an AC to DC converter.  Previously I did not understand that your 20 volts is AC.  And a relay shield like this.  https://www.ebay.com/itm/One-1-Channel-Relay-Module-Shield-5V-Control-250V-10A-w-Optocoupler-for-Arduino/121936150139?epid=1275973984&hash=item1c63f5fe7b:g:SYMAAOSw3RZaN-5D:rk:22:pf:0   . . . And the adapter plug.

Or more simple to discard the 20-volt power and buy a different power that is already 5 volts like this which is not expensive:    https://www.ebay.com/itm/5V-1A-2A-3-4A-5A-DC-Power-Supply-Charger-Adapter-ID-OD-2-5mm-x-5-5mm-Center-PSU/351139392368?hash=item51c189eb70:m:m8cFepWThEUsYT1wGkrQ5Eg:rk:9:pf:0   You can cut the end off with the connector and connect wires to the relay contacts.  This is a different size plug than Arduino

5V barely heats up the one pad even though its it's a 5V heating  pad, it just feels warmish. With 5V the 3 heating pad connected to the arduino dont even get any heat because the arduino is also using power to be on. I think I'll use the ac adapter and buy a DC-DC converter.

It is necessary that the DC-DC converter and the AC/DC adapter have to be seperate from my arduino or can I have it connected to the arduino? On the arduino website it says the limit of input voltage of arduino is 20voltage

Looking at UNO datasheet, it shows that the UNO can be powered from the same 20 volts AC source, but the power for the heat pads cannot go THROUGH the UNO.  The UNO R3 and the AC-DC converter must be connected to the 20-volt supply in parallel.  Connecting your UNO to the 20-volt supply might tax the UNO R3 voltage regulator heavily and it might run hot, and might fail early for that.  It will work, but probably is not the best wayy

Okay, so I will keep the two seperate.

To use one power source, it might be better to power the UNO from the output of the AC to DC converter at the lower voltage of the heat pads.  The UNO will accept 20 volts, but that might be a lot for the built in voltage regulator to handle.  It may be okay either way.  It depends on the quality of the voltage regulator, and the safety factor in the 20 volt rating of the UNO.

Rebecca . . . I don't mean to discourage you, but those heat pads are very small in heat output if you really want to feel any warmth from them on a chair cushion, or back.  They only put out 5 watts each at 5 volts,  And perhaps 12 to 15 watts of heat output when supplied with 12 volts DC.  That isn't a lot. You should be prepared to possibly not feel much heat.  You are designing serial number one of this device, and sometimes the first version isn't quite optimum.

Rebecca . . .I look for an AC-DC step down converter to link here, but I can only find for sale from China, which means a month or more to arrive.  If you need sooner, you can eliminate the 20-volt supply all together, and use this instead with 120 volts AC input, but with fixed 12 volts DC output for heat pads.   https://www.ebay.com/itm/12V-5A-60W-DC-Power-Supply-Switching-Adapter-Transformer-For-5050-LED-Strip-CCTV/253783039111?hash=item3b16a5dc87:g:T4kAAOSwEetV8jJL:rk:28:pf:0

I also have a 120volts AC input with fixed 12volts AC output. Should I use that instead of the 20volts AC input? Will it heat up the 3 heating pad?

Perhaps it would work, but the heat pad manufacturer says to apply DC voltage only, so there might be some problem with it over time.  And with "seats" on the line, you probably don't want to take a chance.

I got 120V AC input to 12V DC output that can work. Do I still need a relay and step down converter? Will the arduino be using some of that power to power it self?

Yes, a 120VAC to 12VDC power supply that provides enough current for all 3 heating pads and the Arduino would work to power everything. Add up the current requirements of all 3 heating pads and the arduino (although the current used by the Arduino will be very small) . Yes, you will still need a relay module so that the Arduino can turn the power to the heating pads on and off.

Can you state the full goal of the project? Are you supposed to be turning the heating pad on and off with the Arduino? (The rest of my answer assumes that that is what you want to do.)
You will need a source of DC power to drive the Arduino. (You can't power an Arduino with AC.)
You will need a 5V relay so you can turn off the power to the heating pad from a logic pin on the Arduino. There are various relay modules made to be controlled by microcontrollers like Arduinos. This one, for example: https://www.jameco.com/z/VMA406-Velleman-Arduino-Compatible-5V-Relay-Module_2255306.html?CID=GOOG&gclid=EAIaIQobChMIr9bSioLT4AIVkpOzCh3X7gqbEAQYBSABEgLf1PD_BwE
Then you will be able to rig the Arduino to turn the relay on and off. You'll wire the power for the heating pad through the relay. You will also need a way to lower the voltage of your power supply to the 5V - 12V range you mentioned. A 1:2 step-down transformer would be a good choice for that.

I can power arduino with an AC-DC which I have. I got 120V AC input to 12V DC output that can work. Do I still need a relay and step down transformer? Will the arduino be using some of that power to power it self?

You still have not explained what you are trying to do very clearly, so it's really hard to answer your questions.

YES YOU NEED A RELAY, assuming your goal is to control the heating pad from the Arduino. An Arduino cannot drive high power devices like heaters. You need to set up the relay as a switch. A digital line from the Arduino will turn the relay on and off.  The relay will switch power to your heating pad on and off.

Note that feeding 12V into the Arduino's barrel connector will put a lot of strain on it's voltage regulator. A linear voltage regulator like the one in the Arduino takes excess voltage and converts it to heat. So the Arduino's power supply will have to "burn off" 12-5, or 7 volts as heat. The voltage regulator will get quite hot.


text:
NRFlite Question
I'm trying to use NRFlite library to facilitate a simple wireless remote incorporating a 3x4 keypad and nRF24L01 modules.  I have it all working well except for one programming puzzle.
All of the example NRFLite receiver sketches that I can find online show the entire main program loop within a while statement:
while (_radio.hasData())
Such as:
void loop() {

while (_radio.hasData())

{

    _radio.readData(&_radioData); // Note how '&' must be placed in front of the variable name.

    String msg = "Radio ";

    msg += _radioData.FromRadioId;

    msg += ", ";

    msg += _radioData.OnTimeMillis;

    msg += " ms, ";

    msg += _radioData.FailedTxCount;

    msg += " Failed TX";

    Serial.println(msg); }}

But my sketch is obviously much more complicated than these examples.  I would like to pass the data received to a variable to use outside of this "while" loop to do a bunch of other stuff not related to the wireless remote.  However, whenever I try to do that, the conditional argument of this "while" function
"(_radio.hasData())"
seems to test as TRUE, and the old data just received is treated again as new data with each pass through the program loop.
How can I pass the data packet outside of the "while (_radio.hasData())" function and get it to subsequently ignore that last data packet received?
Looking at the cpp file, it seems as if perhaps just calling the function "_radio.readData(&_radioData)" is intended to do just that by reseting a "data received flag", which makes sense as a way to accomplish just what I need.  But it doesn't seem to work that way.  Here is that "_radio.readData(&_readData)" function from the .cpp file:
void NRFLite::readData(void *data) {

// Determine length of data in the RX FIFO buffer and read it.

uint8_t dataLength;

spiTransfer(READ_OPERATION, R_RX_PL_WID, &dataLength, 1);

spiTransfer(READ_OPERATION, R_RX_PAYLOAD, data, dataLength);

// Clear data received flag.

uint8_t statusReg = readRegister(STATUS_NRF);

if (statusReg & _BV(RX_DR))

{

    writeRegister(STATUS_NRF, statusReg | _BV(RX_DR));
}
}

I would sure appreciate any suggestions, because otherwise, the NRFlite library seems very efficient for my simple need.

Seems like you need to add your code at the end of the while, not after it. PS If you also need to add some code that isn't packet-data dependent, you might want to change the while to an if

Gerben, thanks for the suggestions.  I previously tried replacing the "while" with an "if" condition, but the result is the same.  My sketch does kind of 'work' if it is all within the 'while' condition, but that isn't really workable because it would mean that the sketch would be dead until the first packet of data is received, and there are lots of other things the sketch does that don't depend on the wireless remote.

Could you add the sender side sketch or at least add how often packages are sent.

Put the stuff that depend on the incoming packets inside the while, and the rest outside of the while.


text:
Trying to use an LCD 1602 to display, but I don't have a 10 KOhm potentiometer
I'm following this tutorial page and I don't have a 10k ohm potentiometer on hand. Could I replace it with resistors to simulate a manual setting and replace the resistors to adjust to a new settings.
From what I was reading this pin is for contrast and I'm sure I could manually set the contrast once and be happy with it for quick prototyping. I'll be ordering a 10k ohm potentiometer on Monday.

Yes. All a potentiometer is, is two resistors end to end.  The "wiper" is the join between the two resistors.
It doesn't matter too much what value potentiometer (and hence what value resistors) you use, as long as it's "around" the 10kΩ mark (100kΩ should be fine, 50kΩ, 1kΩ etc - anything below 1kΩ may not work) - what matters is the ratio of the values of the resistor.

Would this work + ---[10K]--[connection to wiper]--[100K]--- -

It may. It depends if that is the resistor ratio that you need. You will have to try it and see. If it's not right then change the resistors. But that arrangement of resistors is the right idea, yes.

Yes, you always can do that, depending on the resistors you have at hand, you can combine them to make e.g. 1 KOhm, 2 KOhm etc resistors.
Probably you need a linear potentiometer (which means halfway is 5 KOhm).
In a linear potentiometer, you can use the following resistance (made up by a single or a combination of resistors in series or parallel):

Yes, but you need only one resistor to GND. The display has already one resistor inside the display. I forgot what the value should be and I don't have a display at hand right now, so you have to try which value is best.
In most examples with a LCD display, a potentiometer is used for the contrast. Not many people know that only a (variable) resistor to GND is needed.
With a fixed resistor, you are not able to quickly adjust the display when the temperature changes.

If I'm just prototyping where the temperature doesn't change am I right to understand that I could simply go. [GND] ---- [Resistor] ---- [LCD Pin for contrast]

@Tolure, yes, correct, that is all that is needed to set the contrast.


text:
MPU6050 Acc and Gyro readings swapped
I have been trying to figure out this MPU6050 for a bit but the RAW readings are confusing me. It seems to me that the accelerometer readings and the gyro readings are getting swapped... and I don't really see how.
Here is the code reading the raw data in:
#include "Wire.h"

const int MPU_ADDR = 0x68; // I2C address of the MPU-6050.
const int ACCEL_XOUT_H = 0x3B; // starting register: high byte to accelerometer X High

int16_t accelerometer_x, accelerometer_y, accelerometer_z; // variables for accelerometer raw data
int16_t gyro_x, gyro_y, gyro_z; // variables for gyro raw data
int16_t temperature; // variables for temperature data

void setup() {
  Serial.begin(115200);
  Wire.begin();
  Wire.beginTransmission(MPU_ADDR); // Begins a transmission to the I2C slave (GY-521 board)
  Wire.write(0x6B); // PWR_MGMT_1 register
  Wire.write(0); // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
}

void loop() {
  Wire.beginTransmission(MPU_ADDR);
  Wire.write(ACCEL_XOUT_H); // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false); // connection is kept active.
  Wire.requestFrom(MPU_ADDR, 7*2, true); // request a total of 7*2=14 registers

  // Read high byte, shift up one byte then OR with low byte
  accelerometer_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x3B (ACCEL_XOUT_H) and 0x3C (ACCEL_XOUT_L)
  accelerometer_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x3D (ACCEL_YOUT_H) and 0x3E (ACCEL_YOUT_L)
  accelerometer_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x3F (ACCEL_ZOUT_H) and 0x40 (ACCEL_ZOUT_L)
  temperature = Wire.read()<<8 | Wire.read(); // reading registers: 0x41 (TEMP_OUT_H) and 0x42 (TEMP_OUT_L)
  gyro_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x43 (GYRO_XOUT_H) and 0x44 (GYRO_XOUT_L)
  gyro_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x45 (GYRO_YOUT_H) and 0x46 (GYRO_YOUT_L)
  gyro_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x47 (GYRO_ZOUT_H) and 0x48 (GYRO_ZOUT_L)

  // print out data
  Serial.print(""); Serial.print(accelerometer_x, DEC);
  Serial.print("|"); Serial.print(accelerometer_y, DEC);
  Serial.print("|"); Serial.print(accelerometer_z, DEC);
  Serial.print("|"); Serial.print(temperature/340.00+36.53, DEC);
  Serial.print("|"); Serial.print(gyro_x, DEC);
  Serial.print("|"); Serial.print(gyro_y, DEC);
  Serial.print("|"); Serial.print(gyro_z, DEC);
  // the following equation was taken from the documentation [MPU-6000/MPU-6050 Register Map and Description, p.30]

  Serial.println();

  // delay
  delay(100);
}

I am expecting some pipe-delimited data in the format:
'aX|aY|aZ|T|gX|gY|gZ'
and indeed looking at the serial data that is what I thought I had:
%matplotlib notebook
import serial
from collections import deque
import pandas as pd
import matplotlib.pyplot as plt
ser= serial.Serial('COM6', 115200, timeout=2.5)
ser.readline()

gives me a good line of data: b'4008|-1792|18376|26.3182334899|-1084|274|-380\r\n'
This certainly looks plausible -- but I was confused by why the accelerometer values were so high at rest... maybe that is just how it is. But when I moved things around I was more and more confused - I have to see this. So I plotted all the values in Jupyter/matplotlib and it made sense -- the first three numbers are not accelerometer data but gyro data:
fig = plt.figure()
ax = fig.add_subplot(111)
plt.ion()

fig.show()
fig.canvas.draw()

ser.reset_input_buffer()
ser.readline()
data = deque(maxlen = 100)
try:
    while True:
        line_of_data = [float(x.strip()) for x in (ser.readline().decode("utf-8")).split("|")]
        data.append(line_of_data)
        ax.clear()
        for n in range(7):
            ax.plot([x[n] for x in data], label='x['+str(n)+']')
        ax.legend(loc='upper left')
        fig.canvas.draw()
except KeyboardInter

I slowly turned the robot chassis and the x[0] and x[2] (should have labeled those better) values changed and then held their values as I held the rotation. This is what I expected to see from the gyroX and gyroZ (the MPU6050 is at the top of the chassis so as I rotate the body about the wheels the X axis changes the most but the Z does as well).
I don't see how the code could be swapping to two sets of data. I have looked at a number of other examples of reading the raw values and their numbers look similar to mine (i.e. they show the first three values as rather large, and the last three as rather small).
When the MPU is not moving I would expect the accelerometer values to be small.
Do I just not understand how the MPU6050 is working or am I somehow swapping the values in my code?

The accelerometer measures the earth gravity and the gyro measures a change in rotation. Can you try to tilt the object in all 6 directions and check if you can see the accel_x,y,z values from a large negative to a large positive value for each axis. To get gyro values, you have to rotate the object fast, and only during a change of the rotation, the gyro values get larger.

So... if I think of the three accelerometer values as a vector with Z pointing towards the center of the earth (which is why it initially the highest value when the chip is laying flat) then as I flip the chip over I will see the Z value flip... this is making much more sense to me. So the values are not swapped I just didn't know what I was looking at! (i.e. all is right in the world again).


text:
Comparing byte array with multi-dimensional array
I am having a byte array let us say
byte arr[7]={123456};

How to compare this array with a list of of other array like this for example
byte  buffers[5][7] = {123456,654321,987654,456789,765432};

if this method is wrong how can I declare that ?

what do you think byte arr[7]={123456}; actually does?

so how can i make a list of arrays to compare with ?

what do you WANT arr to be? 1,2,3,4,5,6,0? or 64,0,0,0,0,0,0

i want it to be 1,2,3,4,5,6

well, you're doing it wrong

so what do u suggest for doing it correctly?

to learn how to initialise an array - see answer

How is this an Arduino question? This is more a "help me understand basic C/C++ programming"-question.

byte arr[7]={123456};

sets arr[0] = 64 - which is 123456 % 256 - and arr[1-6] are left at 0
And you also only want 6 (not 7) values - so the code would be
byte arr[6]={1,2,3,4,5,6}; // this is how to initialise an array
byte  buffers[5][6] = {{1,2,3,4,5,6},{6,5,4,3,2,1},{9,8,7,6,5,4},{4,5,6,7,8,9},{7,6,5,4,3,2}}; // this is how to initialise a 2d array

void setup() {
  Serial.begin(74880);
  delay(100);
  // this code will find a match, the vlaue of `i` will be the matched index
  int i;
  int j;
  for(i = 0; i < 5; i++) {
    for(j = 0; j < 6; j ++) {
      if(arr[j] != buffers[i][j]) {
        break;
      }
    }
    if(j == 6) {
      break;
    }
  }
  if (i < 5) {
    Serial.print("Found at index ");
    Serial.println(i);
  }

}

@JaromandaX Might want to make this an Arduino QA by adding how to use program memory for a constant value vector/array.

not sure what you mean @MikaelPatel


text:
Outputting 400 mV using Arduino Nano PWM pin

I am trying to output analog voltage (400 mV) using Arduino Nano PWM pins. Is it okay to directly connect (using jumper wires) the PWM pins to the Vin+ of the INA219 current sensor?
I badly need it for my graduation project. Thanks for the help.

I think adding several capacitors of different sizes between the arduino PWM pin and ground would smoothout the PWM signal into constant voltage. Could you show us how yor circuit works?

I inserted my circuit connection above. Can you help me?

So you just want the INA219 to show value of 400mV? There is no circuit that actually uses that voltage? You can achieve that in simpler ways then using an Arduino.

It's unclear why exactly you want this 400mV voltage (or other voltages as well)? You can build a voltage divider from 2 resistors to get 400mV from 5V and GND. Or for general voltages, you want to build a DAC (https://www.youtube.com/watch?v=Y2OPnrgb0pY)

Yes, why do you think you want to generate 400mV?

@FilipFranik please don't use just capacitors. You'd need a resistor as well, or you'll end up destroying the Arduino pin.

@FilipFranik I think you were thinking of a low pass filter. It has a resistor and capacitor as mentioned by Gerben. You can add a second low pass filter to the output of the first filter if needed.

@sa_leinad i guess you are correct. A low pass filter is used to make a simple DAC https://create.arduino.cc/projecthub/Arduino_Scuola/build-a-simple-dac-for-your-arduino-4c00bd

PWM pins don't output analog voltages. They output pulses of 5V. You then need to average the output in order to get an actual analog voltage out of it. You should be able to use a capacitor and resistor to average out the voltage of the PWM pin, making a low-pass filter. You won't get exactly to 400mV. If I remember correctly the PWM pin has a value of 0 - 255, and 1/255 is 0.0196 V after a good low-pass filter, or 19.6 mV, so analogWrite(pin,20) should get close to the 400mV you want.
Another option would be to use a voltage divider to the output to get the output you want. That way you can use the full range of analogWrite() in producing the 400 mV and smaller voltages, thus gaining precision. Then again, if all you want is a fixed 0 or 400mV you could accomplish that with a digital output pin and a fixed voltage divider - no need for PWM.

Of course it's possible !
Duncan you made a little error of 10^2 ;)
5V / 1023 = 0.004887.. = 4.88mV
For 400mV you got 400/4.88 = 81.9.
So in the arduino a value of 82 (0-1023) will send you an output of 400.16mV after beeing redressed by a RC filter.

Please adjust your calculations based on this page: https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/


text:
Bypass a function error
I have a long code written in Arduino101 that works fine. I use a prepared function (connected to a library) in my code that I have not written it. My input to this function is an array. In 99.9999..% of the time, the function works great. However, it might stops due to an unknown reason, maybe because of my wrong input. This causes the program to stop.
My question is: how to bypass this function if it fails for any reason? Something like 'on error' function in normal programming.
Thanks a lot in advance,

If it is because of your input being bad, then you need to check and validate that input.

Please add more info to your question, mention that this is a follow-up of: https://arduino.stackexchange.com/questions/61867/problem-with-variables

Thanks, friends. I will focus on my code to find the root cause.

If your function is crashing then there is no way to recover. Arduinos are unprotected real mode devices. If your code does something invalid, your program crashes and the device will likely either hang or restart.
You need to debug your function, or find the invalid data you are passing into it.

Thanks for your comment, Duncan. I will do so.


text:
Parsing Data and Comparing two string in arduino
I am working on my final assignment. The problem is I want to make a prototype tool, with 2 string compare. If I send data "OK DISC DISCLOSED: 341513DB689AOK RSSI: -056 OK NAME: CarBT1 OK DISCE" will be parsed and bring up data "CarBT1 OK DISCE" if the data is correct then the LED will turn on, but my program isn't working? does anyone know the problem?
String dataIn;
String dt[10];
int i;
boolean parsing=false;
const int pinLED = 8;
String readString;

void setup (){
  Serial.begin(9600);
  pinMode(pinLED, OUTPUT);
  Serial.print("Sketch:   ");   Serial.println(__FILE__);
  Serial.print("Uploaded: ");   Serial.println(__DATE__);
  Serial.println(" ");
  while(!Serial){
    ;
  }
}

void loop (){
  if(Serial.available()>0) {
  char inChar = (char)Serial.read();
  dataIn += inChar;
  if (inChar == '\n'){
  parsing = true;
  }
}
if(parsing){
  parsingData();
  parsing=false;
  dataIn="";
}
while(Serial.available()){
  delay(3);
  char c =  Serial.read();
  readString += c;
}
readString.trim();
  if(readString.length()>0){
    if(readString == "CarBT1 OK+DISCE"){
      digitalWrite(pinLED, HIGH);
      Serial.println("Switching On");
   }
  if(readString == "off"){
      digitalWrite(pinLED, LOW);
      Serial.println("Switching Off");
   }
readString = "";
 }
}

void parsingData(){
int j=0;
Serial.print("data masuk : ");
Serial.print(dataIn);
Serial.print("\n");
dt[j]="";
for(i=1;i<dataIn.length();i++){
  if ((dataIn[i] == ':') || (dataIn[i] == ':')){
  j++;
  dt[j]="";
}
  else{
  dt[j] = dt[j] + dataIn[i];
  }
 }
}
Serial.print("data 1 : ");
Serial.print(dt[0]);
Serial.print("\n");
Serial.print("data 2 : ");
Serial.print(dt[1]);
Serial.print("\n");
Serial.print("data 3 : ");
Serial.print(dt[2]);
Serial.print("\n\n");
Serial.print("data 4 : ");
Serial.print(dt[3]);
Serial.print("\n\n");
}

i think you need to add more info than (does not work). perhaps try remove (\r) char with string.replace("\r",""). and its better to use (readUntil) function than your method.

Part of your assignment is to learn debugging skills. Ask yourself what DOES work and where does it start to go wrong? Build from there.

Thank you for your response. Actually I tried to parse the data entered through serial on Arduino, and it worked. The problem is when the data that has been parsed I compare it to the string. I take an example, if I enter a message past the Arduino serial in the form of ABC: DEF I will be parsed into two data. data1 = ABC, data2 = DEF. When one of my data compares for example if (data1 == "ABC") {digitalWrite (pinLed, HIGH)}. LED does not turn on

while(Serial.available()){   delay(3);   char c =  Serial.read();   readString += c; } readString.trim();   if(readString.length()>0){     if(readString == "CarBT1 OK+DISCE"){       digitalWrite(pinLED, HIGH);       Serial.println("Switching On");    }   if(readString == "off"){       digitalWrite(pinLED, LOW);       Serial.println("Switching Off");    } readString = "";  } and this is the problem code, I took it from the code above

your code is inconsistently indented ..... that makes it difficult to follow the program flow ..... please try to correct the indentation of your code

I think that the biggest problem that you are encountering is that reading a line from serial is not as straightforward as you would like. I don't have a quick and easy solution for you, but there is much on this issue that you can look at.
You have two serial read while loops. The first exits as soon as there are no characters to read (even though some may be on the way). When "\n" is read, you set parsing but it does not mean that \n is removed from dataIn.
The second serial read while loop is using a delay(3) after detecting that a character is available, but that character could have arrived after the first read and be the only character in the buffer, for example.
I suspect that the reason that your String comparison does not work is simply because the Strings are not equal.
Your String looks like something read from an HM-10/11 or something similar. I have had some success reading those transmissions by doing the following:
Make sure the serial buffer is empty. When a character is available, read it into your building String, but continue looking for characters that are available for a set amount of time (maybe a couple of seconds). Continue looking for characters until the time has elapsed and not as soon as there are no characters available (because more may be coming). Alternatively, keep building the string until you recognize the "DISCE" marking the end of that transmission.
A problem, however, is that, in my experience, if it is a very long line (that can occur when there are many devices out there), you will never get that "DISCE". I assumed that this was a firmware issue.
Hope it helps.


text:
The sketch burned two H Bridges, need help to find out how to modify
This is Arduino RC control car, the sketch tested good in a small motor, but burned two 60A drivers when put into 24V,500W motors, need help to find out whats wrong?
#include <VirtualWire.h>

//motor A connected between A01 and A02
//motor B connected between B01 and B02

int STBY = 2; //standby  // mod: was 10 --2 ??

int count;

//Motor A
int PWMA = 9; //Speed control   // need mod: was 3 change into 9
int AIN1 = 8; //Direction  // was 9
int AIN2 = 7; //Direction

//Motor B
int PWMB = 10; //Speed control   // need mod: was 5 change into 10
int BIN1 = 5; //Direction   // was 6
int BIN2 = 4; //Direction   ///was 16 put into p7 cause of Arduino uno no p16.

const boolean FORWARD = HIGH;
const boolean REVERSE = LOW;

float speed_Max = 252; //pwm usually goes from was:0-255 ////0-255 changed into 0-252

float speed_Min = 0;
float analogInput_Max = 1023;
float analogInput_Min = 0;
float analogInput_Middle_X = 515;//ideally it would be analogInput_Max / 2
float analogInput_Middle_Y = 495;//ideally it would be analogInput_Max / 2
float deadBand = 0;
float middleMax = (analogInput_Max / 2) + deadBand;
float middleMin = (analogInput_Max / 2) - deadBand;
boolean pastDirection = FORWARD;

void setup()
{
  // Configure Timer 2 for PWM @ 14 kHz.
  TCCR2A = 0;           // undo the configuration done by...
  TCCR2B = 0;           // ...the Arduino core library
  TCNT2  = 0;           // reset timer

  TCCR2A = _BV(COM2A1)  // non-inverted PWM on ch. A
           | _BV(COM2B1)  // same on ch; B
           | _BV(WGM20);  // mode 10: ph. correct PWM, TOP = ICR1

      TCCR2B = (TCCR2B & 0b11111000) | 0x01; //3.92116 [kHz] //** use this code got 3.9khz but joystick works not too good
    {

    Serial.begin(9600);  // Debugging only
    Serial.println("setup"); //Prints "Setup" to the serial monitor

    vw_set_rx_pin(6);       //Sets pin D12 as the RX Pin
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);      // Bits per sec
    vw_rx_start();       // Start the receiver PLL running

    pinMode(23, OUTPUT); //Relay one ////M1 added 2 was 2 -- 4
    pinMode(25, OUTPUT); //Relay two
    pinMode(27, OUTPUT); //Relay four
    pinMode(29, OUTPUT); //Relay five
    pinMode(31, OUTPUT); //Relay sex
    pinMode(33, OUTPUT); //Relay seven
    pinMode(35, OUTPUT); //Relay eight
    pinMode(37, OUTPUT); //Relay three
    pinMode(39, OUTPUT); //Relay three
    pinMode(41, OUTPUT); //Relay eight
    pinMode(43, OUTPUT); //Relay three
    pinMode(45, OUTPUT); //Relay three

    digitalWrite(23, HIGH);
    digitalWrite(25, HIGH);
    digitalWrite(27, HIGH);
    digitalWrite(29, HIGH);
    digitalWrite(31, HIGH);
    digitalWrite(33, HIGH);
    digitalWrite(35, HIGH);
    digitalWrite(37, HIGH);
    digitalWrite(39, HIGH);
    digitalWrite(41, HIGH);
    digitalWrite(43, HIGH);
    digitalWrite(45, HIGH);
     }

  pinMode(STBY, OUTPUT); //// pin: the number of the pin whose mode you wish to set; mode: INPUT, OUTPUT, or INPUT_PULLUP.

  pinMode(PWMA, OUTPUT);
  pinMode(AIN1, OUTPUT);
  pinMode(AIN2, OUTPUT);

  pinMode(PWMB, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);
}

void loop() {

button(); //// disable 'button', no work. remove '//' enable, button works good
joystick(); //// disable 'joystick', no work. remove '//' enable, joystick works good, but no motor control yet

 }

void joystick() {

  uint8_t buf[VW_MAX_MESSAGE_LEN]; // This declares a variable array. instead of 7 variables buf1, buf2 etc...
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    int i;
    int column = 0;
    String message;
    int commands[30];
    // Message with a good checksum received, dump it.
    for (i = 0; i < buflen; i++)
    {
      //DEBUG:
      //Serial.print(char(buf[i]));

      if (char(buf[i]) == '|') {
        commands[column] = message.toInt();
        message = "";
        column++;
      } else {
        message += char(buf[i]);
      }
    }

    //one more time to capture the last value since the message does not end with |
    commands[column] = message.toInt();

    // DEBUG
    //    Serial.print("X: ");
    //    Serial.print(commands[0]);
    //    Serial.print(" Y: ");
    //    Serial.println(commands[1]);

     motorControl(commands[0], commands[1]);

  }

}

void move(int motor, int speed, boolean direction) {
  digitalWrite(STBY, HIGH); //disable standby

   if (motor == 1) {
    digitalWrite(AIN1, direction);
    digitalWrite(AIN2, !direction);
    analogWrite(PWMA, speed);
  } else {
    digitalWrite(BIN1, !direction);
    digitalWrite(BIN2, direction);
    analogWrite(PWMB, speed);
  }
}

void motorControl(float x, float y) {
  boolean currentDirection = y >= analogInput_Middle_Y;

    //map(value, fromLow, fromHigh, toLow, toHigh);
  if (currentDirection == REVERSE) {
    y = map(y, analogInput_Middle_Y, analogInput_Min, speed_Min, speed_Max) ;
  } else {
    y = map(y, analogInput_Middle_Y, analogInput_Max, speed_Min, speed_Max);
  }

  int subtractFromLeft = map(x, analogInput_Middle_X, analogInput_Min, speed_Min, y);
  int subtractFromRight = map(x, analogInput_Middle_X, analogInput_Max, speed_Min, y);

  if (subtractFromRight < 0) {
    subtractFromRight = 0;
  }

  if (subtractFromLeft < 0) {
    subtractFromLeft = 0;
  }

  int Throttle_RIGHT = y - subtractFromRight;
  int Throttle_LEFT = y - subtractFromLeft;

  boolean currentDirection_LEFT = currentDirection;
  boolean currentDirection_RIGHT = currentDirection;

  if (Throttle_LEFT < 1 && Throttle_RIGHT > 1) {
    currentDirection_LEFT = !currentDirection;
    Throttle_LEFT = Throttle_RIGHT;
  }

  if (Throttle_RIGHT < 1 && Throttle_LEFT > 1) {
    currentDirection_RIGHT = !currentDirection;
    Throttle_RIGHT = Throttle_LEFT;
  }

  move(1, Throttle_LEFT, currentDirection_LEFT);
  move(2, Throttle_RIGHT, currentDirection_RIGHT);

  }

void button()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    int i;
    digitalWrite(13, true);  // Flash a light to show received good message
    // Message with a good checksum received, dump it.
    Serial.print("Got: ");

    for (i = 0; i < buflen; i++)
    {
      int c = (buf[i]);
      Serial.print(c);
      Serial.print(" ");
      if (c == 65 ) {
        digitalWrite(23, !digitalRead(23));  //// A--RELAY A1
      }

      if (c == 66 ) {
        digitalWrite(25, !digitalRead(25));  //// B--RELAY A2
      }

      if (c == 67 ) {
        digitalWrite(27, !digitalRead(27)); //// C--RELAY B1
      }

      if (c == 68 ) {
        digitalWrite(29, !digitalRead(29)); //// D--RELAY B2
      }
/*
      if (c == 69 ) {
        digitalWrite(37, !digitalRead(37)); //// E--
      }

      if (c == 70 ) {
        digitalWrite(39, !digitalRead(39)); //// F--
      }
*/
      if (c == 71 ) {
        digitalWrite(31, !digitalRead(31)); //// G--RELAY C1
      }

      if (c == 72 ) {
        digitalWrite(33, !digitalRead(33));  //// H -- RELAY C2
      }

      if (c == 73 ) {
        digitalWrite(43, !digitalRead(43));  //// I --
      }

       if (c == 74 ) {
        digitalWrite(35, !digitalRead(35));  //// J --
      }

       if (c == 75 ) {
        digitalWrite(37, !digitalRead(37));  //// K --
      }

      if (c == 76 ) {
        digitalWrite(39, !digitalRead(39));  //// L --
      }
      if (c == 77 ) {
        digitalWrite(41, !digitalRead(41));  //// M --
      }
      if (c == 78 ) {
        digitalWrite(35, !digitalRead(35));  //// N --
      }

    }
    count++;
    // Serial.print(count);
    Serial.println("");
    digitalWrite(13, false);
  }
}

My new driver is came, I just scare to use it, heard that DC motor will draw upto 300A at the start, what should I do to reduce the start current?

What kind of drivers?

this one: https://www.ebay.com/itm/60A-DC-Motor-Driver-Module-High-Power-motor-Speed-Control-Dual-Channel-H-bridge/122479397950?hash=item1c84574c3e:g:ZHAAAOSww9xZC0wa:rk:2:pf:0

There are lot of edits, what should I do with them?

how do you know that the sketch is the cause of the failure?

@jsotola I'm not sure, I checked online the driver was sold and used quite much, that's why I guess maybe wrong sketch resulted in the 'shoot through'?

it seems to me that your code is overly complicated for just a simple motor run test ...... for instance, what is the reason for all the relays?

It is. but the testing runs good in 12V out, it can control the two 12V motor's speed and direction. The all relays for relative to the Gamepad's button in Transmit side.

I can't resist: "Haven't you heard that you shouldn't burn bridges"

unfortunately. I guess the "Haven't you heard that you shouldn't burn bridges" saying come out after 100s burned. solution please.

As you wrote in comment you use this H bridge:
https://www.ebay.com/itm/60A-DC-Motor-Driver-Module-High-Power-motor-Speed-Control-Dual-Channel-H-bridge/122479397950
The description how to use it is clear:

But the listing doesn't say what will happen when you set state of A1,A2=1.1 to that H-bridge.
When you set value of A1,A2=1.1 to a unprotected (cheap) H-Bridge you get a direct short to ground through 2 transistors burning them instantly

Your code actually does not protect against that:
   if (motor == 1) {
    digitalWrite(AIN1, direction);
    digitalWrite(AIN2, !direction);
    analogWrite(PWMA, speed);
  } else {
    digitalWrite(BIN1, !direction);
    digitalWrite(BIN2, direction);
    analogWrite(PWMB, speed);
  }
}

If previous value of direction is 0 (A1,A2=0,1) and you want to set direction to 1 (A1,A2=1,0) when arduino runs the line digitalWrite(AIN1, direction); for few cycles you actually end up with A1,A2=1,1 and MOSFETs go bye bye.
Try setting AIN1, AIN2 (or BIN1, BIN2) to 0 before adjusting the direction
   if (motor == 1) {
    digitalWrite(AIN1, LOW);
    digitalWrite(AIN2, LOW);

    digitalWrite(AIN1, direction);
    digitalWrite(AIN2, !direction);
    analogWrite(PWMA, speed);
  } else {
    digitalWrite(BIN1, LOW);
    digitalWrite(BIN2, LOW);

    digitalWrite(BIN1, !direction);
    digitalWrite(BIN2, direction);
    analogWrite(PWMB, speed);
  }
}

This way you are guaranteed that you always have at least one 0 there.
EDIT:
You wrote that the module contains IR2103s it should protect you from the problem I described above. (But my suggested fix is not dangerous so you can use it just in case)
There is another possibility. Maybe the rapidly changing of the direction induces high voltage spikes in the motor, and that burns the circuit. Do you see any power diodes there? Look at the image I pasted above it has 4 diodes that should safely discharge those spikes. Make sure your code does not change direction every few milliseconds.

Thank you Filip Franik, you are right. I remember that burned after be tested a while. Can you help me modify the sketch to avoid this?

Or is that possible to avoid this by use the circuit below: https://www.mycontraption.com/wp-content/uploads/2013/06/Super-Simple-MOSFET-H-Bridge.png

Couldn't you repair the H-bridge by replacing the dead MOSFETs?

I guess it is possible, I checked the PCB plate was burned, the MOSFETs may be still usable, sure I can also replace new MOSFETs. I even purchased 2 pics new drivers on the way. Still I need the problem solved.  Thanks.

@laoadam If you can read the part numbers on the ICs from that driver i can check the datasheet if that's actually the case. Usually the H-bridge drivers are protected.

@  Filip Franik, the board used 8 pcs LR7843 / MOSFET 30V 161A  1 N-CH HEXFET  and  4 x IR 2103s / Half-Bridge Driver

Thank Filip Franik, I'll test it when my new order driver come.

Hi Filip Franik, The driver has 8 pcs ss32 schottky diode in the back.

This H bridge driver looks pretty well designed. Only reason for it failing would be possible rapid switches that turn motors for a moment into high voltage sources.

@Filip Franik Thank you , When checked the SOA of the MOSFET, the higher the current, the less the time, say 80A at 100us, is this means that I can use the cycle less than 100us PWM at 80A?

@Filip Franik  Hi Frank, My new driver came, and I modified the sketch. I heard that the died band may be useful here, can you help me how to sketch it here? I want to try as much as I can before hook the new drive up, Lot of thanks.


text:
DigiKeyboard - type a backslash (\)
I'm using digiKeyboard library to type to a powershell, but I need to type a backslash (a lot of them), but I can't figure it out.
I have been looking for the solution for about 3 hours and I still can't find it.
Please let me know how to make a backslash work.
The powershell command that I want to execute:
cmd /C "start /MIN powershell iwr -Uri https://tinyurl.com/WjnAU6 -OutFile c:\windows\temp\b.jpg;sp 'HKCU:Control Panel\Desktop' WallPaper 'c:\windows\temp\b.jpg';$a=1;do{RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True;sleep 1}while($a++-le59)"
It just changes the wallpaper with a downloaded image, try in on your friend.

this is what you are missing? it prints one backslash: print("\\")

You don't need a backslash. You can use forward slash for path separation in any version of Windows from Vista onwards (maybe even earlier).

@Juraj this somehow worked!

To include \ in a string so it can be printed you have to escape it.  \ is itself the escape character, so doubling it up "escapes the escape character" so it is interpreted as a normal character.
So to print "c:\windows" you would actually have to type "c:\\windows" and the \\ gets changed by the compiler into just \


text:
Can I use ESP8266 and OV7670 to video stream on a web?
OV7670 image sensor, small volume, low operating voltage, providing all functions of a single chip of VGA camera and image processor. so I am using and ESP8266 to connect to internet and stream the video from the OV7670 on a web, can I do so?

a quick search on the internet show that the camera can be used with an arduino, so the answer to your question is yes

@jsotola, but with esp8266 too? and can it be streamed on web, because most of the people are using the ESP32, but i want to do it with ESP8266, ESP32 can host a websocket, can ESP8266 do so too?

@jsotola and i am working with a NodeMCU

if it can be done on an arduino, its 99.9% sure it can be done on an ESP8266 when using arduino framework - also, the fact that you know you can do it on an ESP32 increases the probability of success to 99.99% - the only thing left is for you to do it - networking on ESP8266 is more mature than on ESP32, so in the case of networking, if it works in 32 it WILL work on an 8266

@JaromandaX and can i use the esp8266 to stream the ov7670 on web?

@JaromandaX , can you please give me any schematic on how to connect the Ov7670 to the nodemcu, because in an arduino we usually use 6 analog pins, where nodemcu only have one, so any idea? , thanks!

oh, sorry for leading you astray - I didn't think to look up the connections for you, thought you would've researched that yourself - it seems you can not connect that to an ESP, as there are far more pins to connect than the ESP actually has - I thought the question you had was about the functionality of the ESP, not the camera

@JaromandaX, no problem, so i cant use the esp8266 with the camera right?, ESP32 is only the way right?, can you please tell me , i need to know this, thanks!

google search esp32 ov7670 and there are literally hundreds of working results - so, my guess is "yes"

@JaromandaX , yeah i know that it is working with esp32, but just wanted to know if i can use it with a cheaper microcontroller which is the nodemcu, but it seems you cant, thank you!


text:
OTA mDNS issues with ESP8266 and PlatformIO?
The common useage of the OTA library for this MCU is to have it connect to a network, and to then use a computer on that network to upload firmware across that network. Due to either issues with PlatformIO (my IDE of choice right now) or my router (administrated by my ISP) blocking discovery (mDNS does NOT work here either way, and getting the IP is very hard as a result*), I would like to use the SoftAP class to make an access point that I can connect to directly when uploading firmware.
However, I have attempted this, and it does work IF I specify an IP address. This is a bit more convenient, but it fails if I try using mDNS again (via upload_port = myesp8266.local). (As an aside, this means that OTA over SoftAP does work, at least to this degree. I'm sure some will find this useful.)
Has anyone else confirmed either of these issues? I understand that they may be unrelated (since problem one is (Network || PIO) and the second is (PIO || SoftAP) as the cause), but any information as to why this might fail in both cases would be useful.
So, for the first case, can someone who uses that IDE and has an ESP8266 board test if mDNS works with the IDE?
For the second, assuming that mDNS does work with the IDE in the first case (and it's thus the MCU's fault), can anyone determine why the SoftAP class either halts or fails to work with mDNS?
This will really help my abilities to easily get firmware onto the board, and also tell me if I need to get a new router that allows mDNS (if it's not PlatformIO in the first case).
*Since the ISP administrates the router, I am unable to log in and view the IP addresses currently connected. My only option is printing it via UART, which renders this pointless, or attaching a OLED or LCD screen to every single device I build, or get a new router, which is its own issue right now. I've now run the web server test again, and not only does OTA not work with mDNS, but apparently I can't access it at all unless I know its actual IP address.

1: I'm surprised the router can block mDNS, that's not how mDNS works - 2. PlatformIO works with mDNS 100% in my (Windows 10) experience ... what operating system are you using? Can you ping myesp8266.local - are you sure you have the correct host name for your ESP? 3. I've never attempted OTA using SoftAP

can anyone determine why the SoftAP class either halts or fails to work with mDNS - would've thought mDNS is redundant with SoftAP - since SoftAP means the ESP has a known fixed address, 192.168.4.1 (by default)

that's not how mDNS works - I guess a router could block mDNS if it wanted to, seems like an unlikley scenario though

I had to perform that experiment again, and apparently I remembered wrong -- the web server is also not accessible. I can't even access the esp8266.local address even if I can access its IP directly. That's apparently for any networking feature if it's attached to my home network.

So you can't access the esp by ip address either?

No, I cannot. Chromium simply says that it can't find the address. PlatformIO complains of the same issue, saying that esp8266.local cannot be found.


text:
Control Fan Speed Using ESP8266
Hello i am using ESP8266 to control my 220v AC ceiling fan.
I am able to do that easily with a 5v 10A relay module.
But i want to know is there any module to control the fan speed as well? i have checked many videos on YouTube but couldnt understand how can i do that. I just got one thing that it will require Pulse Width Modulation to control it.
Thank you!

I just got one thing that it will require Pulse Width Modulation to control it huh? what?

to control Celling fan speed

no, pwm will not help you. the trick is to turn the relay on and off fast. the mechanical relay cant do it, so you need a SSR (solid state relay)

@Juraj Thank you for amazing suggestion. But can you share any example code? Or any library which can help with this?

Blink example ?

code example..that can be any of the possible one. Just want to test it.

yes Blink. turn on, turn off, turn on, turn off, turn on, turn off,...

you can use "pwm", but not what us makers call pwm, which is a high-frequency DC thing, and you need a low frequency AC thing. It's called phase modulation, and uses a triac. it's a lot more complicated than DC PWM. Look into zero crossing SSRs to make your task half as difficult.

@dandavis do you think this will work? https://robu.in/product/5v-4-channel-ssr-solid-state-relay-module-240v-2a-output-resistive-fuse/


text:
Using ESP8266-01 via Arduino(no flash) without AT commands(using serial monitor)
I'm trying to build a smart Keychain using Arduino uno wifi(org, so Im using it like it's Arduino uno), ESP8266-01 And neo6m GPS device.
My esp8266 wasn't new, and it came without AT firmware. I flashed it so it could have AT commands but it's not completely working.
Anyway, the flash is using 115200 baud and I'd like to use serial monitor to communicate it using arduino(and blynk app).
Is there a way could I do it without flashing the esp for 9600 baud rate?
Thanks!

What do you mean? How can I use it? My Arduino uno wifi board is Arduino.org which means(I read online) that until Arduino won't provide proper TCP library I can't really communicate with it online

your information is obsolete. you can use it as any Uno with external esp8266 on SoftwareSerial. read the answer

Arduino Uno WiFi Dev Ed has the on-board esp8266 wired to additional Serial interface (I2C to Serial adapter). With UnoWiFiDevEdSerial1 library you can use the on-board esp8266 and have Serial free for Serial Monitor and sketch upload. The EspProxy tool enables upload to the on-board esp8266 over the ATmega (passing bytes between Serial and Serial1).
I am the author of the UnoWiFiDevEdSerial1 library.

The thing is, I'm not able to use this library in order to do exactly that. Maybe im not trying right, but I did try it, and my professor said I must use esp8266-01 module. I can't use it with software serial without reflashing because software serial is up to 9600 baud rate and my esp is using 115200 baud rate.

what did you try? AT firmware or WiFiLink or your own esp8266 sketch

Doing this exactly https://github.com/jandrassy/UnoWiFiDevEdSerial1

but that library is like SoftwareSerial. it is only the gate to esp8266

did you try WiFiLink firmware? with WiFiLink library it can Arduino networking like WiFi or Ethernet library

@MaorGorelik, did you solve it?


text:
Memory usage: #define vs. static const for uint8_t
I'm writing an Arduino library to communicate with an I2C device, and I'm wondering what the best way is to declare all the register addresses so as to save memory.
Using #defines:
#define REGISTER_MOTOR_1_MODE 0x44
#define REGISTER_MOTOR_2_MODE 0x47

Or using static const:
static const uint8_t REGISTER_MOTOR_1_MODE = 0x44;
static const uint8_t REGISTER_MOTOR_2_MODE = 0x47;

(Obviously I have more than just two registers I need to declare, but I thought two would illustrate the point just fine)

define's are just "find and replace"s, and can bit you, if you do anything other than numbers. For example #define LED_MASK  0x01<<2. A safe(r) way to write that would be  #define LED_MASK  (0x01<<2). See also https://stackoverflow.com/questions/6542270/what-is-the-standard-to-declare-constant-variables-in-ansi-c

You'll find no noticeable difference memory-wise between the two.
The only real difference is that the const method also imposes a type to the value, which can be useful for function overloading or mathematical operations.

Macros also have types. #define REGISTER_MOTOR_1_MODE 0x44 would cause REGISTER_MOTOR_1_MODE to have a type of int. The difference is more in the explicitness of the type.

@Pharap Almost...  Macros do not have a type. However, the content of the macro can have either an implicit or explicit type. That type is nothing to do with the macro.

The type of the expression that the macro substitutes for is for all intents and purposes the type of the macro. Unless the macro accepts arguments then the expression will always have the same type. You can stick a macro in a decltype and get a valid type. Strictly yes, the macro is gone by the time the actual compilation phase begins, and yes, not all macros will substitute for a valid expression with a type, but the point is that if you put a macro into the code and that macro substitutes for a valid expression then the resulting value won't be 'untyped'.

A #define is a preprocessor macro. As Gerben says in his comment, it's just an automated find-and-replace.
If you use it to hold things like C string constants, e.g. #define ERROR_STRING "You messed up, bud!" it could actually cause your program to take more memory, since that same string literal will be duplicated every time you reference it. In that case a static const would be both type-safe AND reduce memory usage.

Would it be duplicated? I mean, isn't it the job of the compiler to ensure "You messed up, bud!" occurs exactly once in the string constant table?

@juhist: C++ explicitly states that the compiler can choose to duplicate identical strings, or not.  Most compilers have a flag to either do this, or not. I think, by default, most compilers do not merge strings, in case the app relies on them being unique.

@MooingDuck I compiled a program having many std::printf("%p\n", "foo"); lines in it. All of them print the same address.

@MooingDuck: While few compilers will guarantee that strings will always be merged, I think the normal reason is that upholding such a guarantee may impose extra build-time costs and complexity, and the savings in storage from merging strings may or may not be worthwhile.

@juhist: Sure. In your compiler and your compiler flags.  With my compiler and my flags, I get different addresses.

@supercat: Possible, but I'm dubious, since they already have to have similar logic for all inline methods (including almost all templates) anyway.

@MooingDuck: At least historically, good compilers would often include logic so that if memory got low, they could jettison information that wasn't needed for correct compilation.  Compilers might try to hold onto information that would let them merge identical strings or inline functions, but that doesn't mean that they promise to hold such information and use it even when they would be short on memory.

Theoretically both approaches should consume the same amount of space and will probably result in the same code.

However, rather than that meaning "pick any one", what that actually means is that you should turn your attention to other factors when deciding which one to use.
As a rule of thumb you should generally avoid macros because they don't respect scoping rules due to how they work.
This can lead to some serious problems in certain cases.
See Why are preprocessor macros evil and what are the alternatives?.

However, I'd like to point out a third option: constexpr.
constexpr uint8_t motorMode1Register = 0x44;

constexpr implies const and is a better expression of the intent that the value should be capable of being evaluated at compile time.
constexpr literally means "this is a constant expression and thus can be evaluated at compile time".
As a result of this, constexpr variables can be used in situations where other variables cannot, such as template parameters.
See Constexpr vs Macros.


text:
STM32 Nucleo F401RE in Arduino IDE - how to enable more than 1 Serial?
I just received a Nucleo F401RE and can't get my sketch to work on it because the compiler says Serial1 is not defined.
My sketch uses multiple serials because I need to use the usb serial monitor while also communicating to another device on a different serial port.
Here is a screenshot of the flags I selected.

According to the F401 specs it has at least 6 different serials, so the real question is: is there an easy way to use Serial1 and so on straight out of the box in the Arduino IDE?
I'm quite new and unexperienced to this field, so please excuse me if this question is too trivial.

http://www.stm32duino.com/

could you elaborate more, please? I've looked for an answer on stm32duino.com forum before posting here, but couldn't find any. I also wanted to post my question there, but it seems like it's impossible to register as a new user, so I'm stranded at the moment

the options from Tools menu are evaluated in WSerial.h. SerialUSB and/or Serial are defined. the way described in answer is the right one to create additional Serial interfaces

Frederic Pillon on Github has been very helpful and suggested me the solution, which is to define the serial via:
HardwareSerial Serial1(PA10, PA9);

instead of just giving Serial1 for granted as you would do on a regular Arduino mega


text:
Serial plotter isn't displaying my supplied data
I want to use serial plotter feature of Arduino by using DHT11 as humidity sensor at a time. But I'm getting problem as plotter is not loading by the code I have. Please help me what is the problem because of which serial plotter is not loading.
Here is the Code I wrote:-
#include <dht.h>
#define dht_apin0 A0 // Analog Pin sensor is connected to

dht DHT0;

void setup() {

  Serial.begin(9600);
  delay(500);//Delay to let system boot
  Serial.println("DHT11 Humidity Sensor\n");
  delay(1000);//Wait before accessing Sensor

}//end "setup()"

void loop(){
  //Start of Program

    DHT0.read11(dht_apin0);

    Serial.print("Current humidity = ");
    Serial.print(DHT0.humidity);
    Serial.print("%  ");

    delay(5000);//Wait 5 seconds before accessing sensor again.

  //Fastest should be once every two seconds.

}// end loop()

https://learn.adafruit.com/experimenters-guide-for-metro/circ08-using%20the%20arduino%20serial%20plotter

The serial plotter has no idea what to do with the text in front of the humidity value, or the % after it.

You can't send arbitrary information (percent signs, text etc) to the plotter. The plotter only understands numeric values. You have to separate these number values from each other with commas, then do a println in your last value:
Serial.print(percent);
Serial.print(F(","));
Serial.print(tankPercent(depth));
Serial.print(F(","));
Serial.print(litres);
Serial.print(F(","));
Serial.println(tankLitres(depth));

In your case, it'd be simply:
Serial.println(DHT0.humidity);

You can go a bit further if you want to switch between either serial output, or serial plotter. In one case, I just set a constant variable for graph or plain data, then have a function for each (my above Serial statements are actually within a function called displayGraph()). The data function would be something like you had originally, example:

void displayData(float depth, float percent, float litres){

  // water level depth (inches)

  Serial.print(F("current missing inches: "));
  Serial.println(mixtureDistance());

  // cubic inches

  Serial.print(F("total cubic inches: "));
  Serial.println(TANK_TOTAL_CUBIC_INCHES);

  Serial.print(F("current cubic inches: "));
  Serial.println(tankCurrentCubicInches(depth));

  // litres

  Serial.print(F("total litres: "));
  Serial.println(TANK_TOTAL_LITRES);

  // ... etc
}

I also have projects where I use a switch that if on, sets a flag to output in serial graph format, and if off, uses the serial data routine.
Then, in your sketch loop(), you'd do something like:
graph
  ? displayGraph(depth, percent, litres)
  : displayData(depth, percent, litres);

...or a bit more verbose rather than using the tertiary operator:
if (graph){
  displayGraph(...);
}
else {
  displayData(...);
}

Here's a Q&D serial plotter example of my displayGraph() function above. In the top-right corner of the image, the four colours represent the four pieces of data I'm sending in, in order:

In my case, those represent the exponential moving average of the percentage of how full a liquid tank is, the second is the raw data I'm building that average on, third is the exponential moving average of how many litres are remaining in the tank, and lastly, again, the raw data for that average.
The sharp movements are simply me slapping the tank to get some variable and unstable readings for example purposes.


text:
NodeMCU V3 - Troubleshooting basic TMP36 circuit
If I follow this example using my Arduino Uno https://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor
(using the 3.3V code example at the bottom of the page), I get reasonable temperatures from the readings over serial.
However, if I try this w/ a LoLin NodeMCU V3 (same circuit layout), my readings seem to be consistently higher than what I get running essentially the same code on the Uno. (Only difference in code is omission of analogReference(EXTERNAL), as the Node V3 appears to run on 3.3V as standard )
I'm fairly new to the whole electronics thing, so any pointers are much appreciated...
Circuit is:
      ----- |---------------- GND on breadboard with jumper to MCU
     | TMP36|---------------- AD0 pin on MCU
      ----- |---------------- breadboard power w/ 3.3V jumper to MCU

if you have two sensors, try reading them one each on the uno and node v3 placed side by side. see if the readings are actually different. then swap the sensors around and recheck if it still consistent. also it might sound silly, but could the ambient temperature have actually changed between the two runs ?

also this might be relevant... https://arduino.stackexchange.com/a/54906/16898.

the link is not relevant. the NodeMcu has a voltage divider to read to 3.3 V on A0


text:
How do I provide a negative current?
I'm trying to use an ATMega328 board to control a board of a broken UPS device. I replaced all the internals of the UPS by custom components, so the only things which remain are the chassis and the front board.
On this board, there are five buttons, and three LEDs.

All those components are connected to the ground, each one through its own resistor. By connecting the different pins to the ground and to analog pins of the ATMega328 board, I can successfully detect when the buttons are pressed.

Things, however, get tricky when I want to turn the LEDs on. They have their anode connected to the ground (through a 47Ω resistor), and their cathode connected to a dedicated pin. This means that if I apply voltage to this pin, the LED remains off.
The LED, however, turns on if I connect the ground to a 5V pin on ATMega328 board and the cathode pin to the ground of the ATMega328 board. However, connecting the ground to 5V makes it impossible to read the state of the buttons (or should I wire them somehow specifically?)
Therefore, how do I feed negative current from the ATMega328 board?
There is a similar question on this subject, but while the author wants to “understand the underlying electronics of the arduino and microcontrollers in general,” I, instead, just want to know how to make it work. Reading the answers from the linked question, I have an impression that this is possible, but they don't explain how to do it.

what is negative current?

you may have mixed up the 5V and GND connections .... the buttons probably have pullup resistors, not pulldown  resistors ..... same with the LEDs

If the LEDs turn on when you apply 5V to ground then what you have identified as GND on the board is actually VCC.
There is no such thing as negative current: current is either sourced or sinked, depending if it’s exiting or entering into a node.
The diodes (LED) are one way valves, so you have a clear current direction: once that is established, identifying a button press can work either triggering when it gets LOW or when it gets HIGH, in other words that can be easily reversed.
If previously you where detecting a button press with digitalRead(BTN_PIN) == HIGH then just switch to digitalRead(BTN_PIN) == LOW and you have your solution.

The answer by Roberto Lo Giacco was helpful, but I still had hard time understanding what is happening and how should I wire the boards properly. Since others may encounter similar problems, I'll explain the solution in my own words.
Note that an answer to a similar question helped me as well.

When a digital pin is set to high with digitalWrite(LED_PIN, HIGH);, it's similar (probably not in electrical terms, but at least in terms of interface) to connecting to 5V what was previously connected to the pin.
Similarly, digitalWrite(LED_PIN, LOW); is similar to connecting to GND what was previously connected to the pin.
This means that when the LED is connected as usual, cathode to the GND and anode (through a resistor) to a digital pin:

digitalWrite(LED_PIN, HIGH); turns the LED on, and:
digitalWrite(LED_PIN, LOW); turns it off.

Now, if the cathode is connected to the digital pin, the anode (through a resistor) can be connected to 5V. In this situation:

digitalWrite(LED_PIN, HIGH); turns the LED off.
digitalWrite(LED_PIN, LOW); turns it on.

On the photo in my question, the black wire is connected to GND. Instead, it should be connected to 5V. Other wires remain unchanged.
When it comes to the buttons, in order to determine whether the button is pressed or not, I was doing this:
if (analogRead(ESC_PIN) == 0) {
    // The ESC button is pressed.
}

When the button wasn't pressed, the values from analogRead were quite random, ranging from 50 to 250, or something like that. A zero value would indicate that the button was pressed.
With the new wiring (5V instead of GND), the new values from analogRead range from 350 to 900 when the button is not pressed. When the button is down, the value becomes 1023. Therefore, the new condition is simply:
if (analogRead(ESC_PIN) == 1023) {
    // The ESC button is pressed.
}

Why using analogRead instead of digitalRead?!? Please consider analog sampling is a lot slower than reading a digital value... You said there are resistors connected to the buttons: those resistors should act as pull-down, forcing the non-pressed buttons to GND so that when you press the button the voltage jumps to 5V while the resistor limits the current flowing.

@RobertoLoGiacco: because digitalRead always returns 1, independently of whether the button is pressed or not.

Then the part in the question where you state all those components are “connected to ground with their own resistor” was wrong: there are no resistors in series with the buttons.

Interesting. I found that they have each a resistor by testing the board with a multimeter, but given my low experience with electricity, I may have made a mistake. I was also under impression that if I don't use a resistor, I'll burn the board if I set pinMode to INPUT instead of INPUT_PULLUP. I'm happy this impression is wrong (since the board is still alive).


text:
SPI Wiring Confusion
I am currently trying to learn about SPI and how it works on the Arduino. I want to wire a MAX7219 chip to it to drive an 8x8 LED matrix with. Normally, I would assume the wiring from Arduino to MAX7219 goes:

PIN 10 SS -> CS
PIN 11 MOSI -> DIN
PIN 13 SCK -> CLK

And indeed, this answer confirms my assumption.
However, after going through some other resources and guides I found some confusing and conflicting information about how the pins on the two devices should be connected.
For instance, the documentation that came with my Arduino kit has this schematic.

This tutorial I found has the same wiring.

Most surprisingly, this tutorial doesn't even use the SPI pins at all.

What perplexes me the most is the sentence

The VCC and GND of the module go to the 5V and GND pins of the Arduino and the three other pins, DIN, CLK and CS go to any digital pin of the Arduino board.

Is this true? If yes, then what is the point of the SPI pins at all? Why are the pins wired in so many different configurations?
I am really confused by this.

that looks like a bad instruction ..... you should not connect the 5V to the Vcc ...... i would not trust any tutorial that says otherwise ..... do not use the arduino as a power supply

with "software" SPI any pins can be used. with hardware SPI CS should not be wired to MISO

Max7219 can be powered from 5V of Arduino. I  did a project where 4 Max7219 were powered. With 9V into the barrel jack the 5V regulator would overheat after a while. With 7.5V things ran smoother.  It depends on how many LEDs are being lit at one time, and what current was being used. 10K for the Max7219 current limit resistor kept things reasonable.

Here are 4 of Max7219 powered by USB even  https://www.youtube.com/watch?v=hwYqgyMc5S4&pbjreload=10  I took this to work and powered it from barrel jack instead, that's when I saw the overheating/shutdown at 9V and had to drop to 7.5V instead.

SPI is a communication protocol, you can take advantage of some hardware optimizations by using the pins where that hardware is available or you can do everything by hand using any pin you like, with the disadvantage of a bigger and slower firmware.
In certain situations, like in the presence of a shield or a library already using those pins, the SPI pins might be unavailable and you have to resort to a software solution (aka bitbang, as you manipulate bits to generate the proper signals), otherwise use of the hardware SPI pins is strongly advised.

I2C should not interfere with SPI on an Uno, they are different pins.  I use SPI for Max7219 projects, much faster updates than software bit-banging of the signals. Defaults for SPI: 4 MHz clock, MSBFIRST, clock Mode 0, work fine, and using SPI.transfer to send data to a register is simple:  digitalWrite (ssPin, LOW);  SPI.transfer(registerAddress); SPI.transfer (dataToLoad); digitalWrite (ssPin, HIGH);   with SCK, MOSI, for clock and data, and D10 used for ssPin.  Or any other pin for ssPin, as long as D10 is an output in your sketch so the Uno is the SPI master all the time.

You are right, SPI and I2C do not conflict, my mistake: answer edited.
Not sure what you meant with all the additional comments, I also stated the hardware SPI is much faster than software port manipulation.

Yes, we are in agreement that SPI is the way to go.

So does that mean that none of the pin specifications are 'enforced'? E.g. can I do PWM on a non-PWM pin, or even I2C on any arbitrary digital pins?

Let’s put it this way: if it is absolutely necessary and you are willing to deal with plenty of hassles, yes, you can have serial comm, SPI or I2C on any general IO pin, with some limitations regarding speed. Also PWM can be achieved, with a lower frequency and sacrificing precious processor cycles just to output the square wave. Be warned: nobody has advised you to go down this route and we are explicitly stating it’s going to be a tough path if you decide to follow it.

@omnivrseal, There is specific hardware on the '328P, 1284P, 2560 for SPI, I2C, Serial comms, so you're better off using those pins. For PWM, there is also timer/counter/compare hardware to support PWM in a 'set and forget' mode, so they can free-run after you turn them on with no sketch involvement needed.  Yes, you can use software to fake what the hardware does, but it will run slower because the code is a lot more intensive.  Just look at SPI - you write to a register, the hardware sends the byte out, you get an interrupt back when it's done.  Doing that in software takes a lot.

For instance, the documentation that came with my Arduino kit has this schematic.

Pins 10 through to 13 are standard SPI pins on the Uno.

10 (SS)
11 (MOSI)
12 (MISO)
13 (SCK)

I have a tutorial here. I also have a Stack Exchange reference question and answer about SPI.

Most surprisingly, this tutorial doesn't even use the SPI pins at all.

It is certainly possible to "bit bang" SPI and in some cases this is desirable, for example if you have something like an SD card interface, and also want to use SPI for a display. On the page I linked, specifically at this post I describe how to bit-bang SPI.

What perplexes me the most is the sentence
The VCC and GND of the module go to the 5V and GND pins of the Arduino and the three other pins, DIN, CLK and CS go to any digital pin of the Arduino board.

For bit-banged SPI, yes you can use any pins.

Is this true? If yes, then what is the point of the SPI pins at all?

The hardware SPI is faster and easier, and you can do other things while SPI is sending/receiving but with bit-banging it is much more timing-dependent.

This video shows a project I did with a Duemilanove, 4 MAX7219s driving 4 8x8 LED matrices, and powered via 7.5V power supply.  https://www.youtube.com/watch?v=hwYqgyMc5S4
With a 9V supply, the 5V regulator overheated and shut down after some number of minutes. With 7.5V, there was no problem.
The SPI and power pins, 5V, Gnd, SCK, MOSI, go to all devices, and each chip has its own SS pin (I didn't want to deal with sending out a bunch of NOP commands to feed data thru daisy-chained chips).  Data to all 4 devices is refreshed as fast as 50mS, any faster and the display got too hard to read. I think I only used SPI at 4 MHz too, I have done other projects with SCK at 8 MHz, that can send out data really fast.