text:
Arduino Uno not turning on
I have bought an arduino uno but when i plugged in the arduino to my laptop its not turned on (the built-in LED was off) and at the arduino IDE I wasnt able to change the port (the port button was unavalible)
what should I do for the arduino uno board to work?

Check your USB cable first. If that is fine, check your USB port. If that is fine then, if it's a genuine Arduino return it for a replacement or refund. If it's a cheap Chinese clone then throw it in the bin and buy a real Arduino.

If you have an Arduino clone with a CH340G chip, you need to install a CH340G driver.

Not having the driver won't keep it from powering on tho, that will just prevent comm's.

@CrossRoads, true indeed.

I second @Majenko; cheap clones are very prone to fail out-of-the-box. That said, what laptop do you have? What Operating System? How is your laptop powered (ie. perhaps USB isn't able to handle the electricity needed)? What happens if you power it from a power supply connected to your household mains voltage?

You could check (measure with a DMM) whether you see 5V at the 5V pin.


text:
use of spec sensor in arduino uno
i have been trying to use NO2 spec senor in arduino UNO. how to write the code for it to get the output in terms of 'ppm' and how to give connection.with the helo of cross-sensitivity given in datasheet how to detect the interference gases from this sensor itself..the datasheet URL:
https://www.spec-sensors.com/wp-content/uploads/2016/10/3SP_NO2_5F-C-Package-110-508.pdf

Have you considered the sensor requires additional hardware to interface with an embedded processor?  The development kit sold for this sensor costs about $350.  While you may be able to build your own for a fraction of the price, I doubt you will be able to use this sensor with only a stock Arduino and some code.

In the specification sheet linked to in the post we find this:

-30+/-10nA/ppm

This is a very small amount of current.  The Arduino ADC is a voltage sensing device and (unless modified) has a range of 0 to the operating voltage of the Arduino.  Usually 3.3V or 5V.
Converting nano Amps to that range of voltage will require additional hardware.  A stock Arduino and code are unlikely to make use of such a sensor.
The conversion of such small amounts of current to voltages measurable by a stock Arduino is not trivial. And most answers do not fit into the short format of stack exchange.  Here is an Engineering Design News article on the subject.

source: Stack Exchange

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

sort: votes


text:
Strange compiler error (Segmentation Fault)
You're getting a compiler error. It happens in strange parts of code that really shouldn't be having a problem.  The error looks something like:
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp:203:1: internal compiler error: Segmentation fault

}

^

Please submit a full bug report,

with preprocessed source if appropriate.

See http://gcc.gnu.org/bugs.html for instructions.

lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.15.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

What is it, and how do you fix it?

Restarting the Arduino IDE may be helpful.

This is a known fault with the compiler in Windows.  The annoying thing is that it's the version of the compiler that is included in the Windows Store App version of the Arduino IDE.
It also snuck into the Windows version of the IDE from version 1.8.6 from the Arduino.cc website, with the bundled version of the Arduino AVR core.
There are numerous Github issues open for the problem and navigating the tangled web of them is a bit of a chore, but this one seems to be the most promising for digging into the root cause:

AVR core 1.6.22 (IDE 1.8.6) crashes avr-gcc compiler (5.4.0) when F() string is assigned to a static variable

The simplest fix is to downgrade your compiler to 4.9.2.  This can be done by using the Boards Manager to install version 1.6.21 of the Arduino AVR Boards.  This should give you compiler version 4.9.2-atmel3.5.4-arduino2 which doesn't suffer from the problem.

This is the central issue report for this problem:
https://github.com/arduino/Arduino/issues/7949

and DO NOT press "Update" button before pressing "Close" !!

Works like a charm, thanks. Had this is issue with a Arduino/Genuino Micro with the IRremote library.

I've been having this kind of error off and on lately for no apparent reason. What eliminated it for me was going into the IDE preferences and changing compiler output to verbose and also show all warnings. What??? I know it's crazy. I was just trying to get more information about the error, but I haven't gotten it since. And I was getting it a lot before.

Worked for me too. Thank you

Sometimes it seems like I have to reboot my PC, as exiting from Arduino and rerunning still doesn't always allow me to compile again.

"changing compiler output to verbose and also show all warnings"

This worked for me too.

I put back the settings to its default state again, after a restart and compile. It worked. Not sure whats under this?

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


text:
Two libraries collide. Ambiguous functions/variables?
I get several errors once I try to include these two libraries:

error: expected unqualified-id before '{' token
     #define DEBUG_PRINTLN(...) {}

#include <DHT.h>
#include <DGS.h>

void setup() {
}

void loop() {
}

Apparently DEBUG_PRINTLN is causing the problems, because it is defined as a private function in DGS.h and as a constant (#define) in DHT.h.
Including DGS.h before DHT.h does not throw errors. But is this a safe workaround or might I run into errors later? How can I deal with that, without modifying the libraries?
DGS.h:
/*
  DGS_25SEP17.h - Library for reading KWJ Engineering with SPEC Sensors on Digital SDK with firmware date 25SEP17.
  Created by David E. Peaslee, Mar 29, 2018.
*/

#ifndef _DGS_h
#define _DGS_h

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#elif defined(SPARK)
//#include "application.h"
#else
#include "WProgram.h"
#endif

#include "Stream.h"

class DGS
{
  private:
    Stream *_mySerial;
    long dataArray[11]; //Multipurpose array
    //void unlock(void);
    void DEBUG_PRINTLN(long x);
    void DEBUG_PRINTLN(float x);
    void DEBUG_PRINTLN(String x);
    void DEBUG_PRINT(long x);
    void DEBUG_PRINT(float x);
    void DEBUG_PRINT(String x);

  public:
    DGS(Stream &mySerial); //Class that represents DULP with Stream as class for Serial
    DGS(Stream *mySerial); //Class that represents DULP with Stream as class for Serial

    bool DEBUG;

    int setToff(float offset);  //Sets a temperature offset
    int setBC(String BC);  //Initializes DGS with all information from barcode, only way to set Span
    String getFW(void); //Returns the Firmware Date

    int getLMP(void); //Loads LMP[3] with register values from LMP91000
    int LMP[3];  //LMP Registers, needs to be loaded with getLMP
    int setLMP(int R1, int R2, int R3); //Sets new LMP registers and reintializes LMP

    int zero(void); //Zeros to current reading, Zero only in a clean air environment
    int setXSpan(float); //ReCalibrates device, only should be used after zero, and using a calibrated gas

    int getData(char c); //Gets the data and loads into variables
    long getConc(char x = 'p');  //Reads concentration from current data array 'p' ppb or 'c' counts
    long getTemp(char t = 'C');  //Reads temperature from current data array 'C' for Celsius or 'F' for Fahrenheit
    long getRh(char r = 'r'); //Reads Rh from current data array 'r' for Rh and 'c' for counts

    void getEEPROM(void); //Loads variables into EEPROM E[5] and e[14] arrays, outputs EEPROM if DEBUG is true
    String eepromStr[5]; //Stores the character based EEPROM data
    long eepromInt[13];  //Stores the integer based EEPROM data
    float Sensitivity_Code;  //Stores the sensitivity coefficient in nA/PPM
};

#endif

DHT.h:
/* DHT library

MIT license
written by Adafruit Industries
*/
#ifndef DHT_H
#define DHT_H

#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

// Uncomment to enable printing out nice debug messages.
//#define DHT_DEBUG

// Define where debug output will be printed.
#define DEBUG_PRINTER Serial

// Setup debug printing macros.
#ifdef DHT_DEBUG
  #define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
  #define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
#else
  #define DEBUG_PRINT(...) {}
  #define DEBUG_PRINTLN(...) {}
#endif

// Define types of sensors.
#define DHT11 11
#define DHT12 12
#define DHT22 22
#define DHT21 21
#define AM2301 21

class DHT {
  public:
   DHT(uint8_t pin, uint8_t type, uint8_t count=6);
   void begin(uint8_t usec=55);
   float readTemperature(bool S=false, bool force=false);
   float convertCtoF(float);
   float convertFtoC(float);
   float computeHeatIndex(bool isFahrenheit=true);
   float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true);
   float readHumidity(bool force=false);
   bool read(bool force=false);

 private:
  uint8_t data[5];
  uint8_t _pin, _type;
  #ifdef __AVR
    // Use direct GPIO access on an 8-bit AVR so keep track of the port and bitmask
    // for the digital pin connected to the DHT.  Other platforms will use digitalRead.
    uint8_t _bit, _port;
  #endif
  uint32_t _lastreadtime, _maxcycles;
  bool _lastresult;
  uint8_t pullTime; // Time (in usec) to pull up data line before reading

  uint32_t expectPulse(bool level);

};

class InterruptLock {
  public:
   InterruptLock() {
#if !defined(ARDUINO_ARCH_NRF52)
    noInterrupts();
#endif
   }
   ~InterruptLock() {
#if !defined(ARDUINO_ARCH_NRF52)
    interrupts();
#endif
   }
};

#endif

The DEBUG_ functions in the DGS class are private and used only in DGS.cpp. They will not collide with the macros from DHT.h
If DHT.h is included before DGS.h, the preprocessor replaces the DEBUG_ function names with the content of the macros from DHT.h and the result doesn't make sense for the compiler.
You could do #undef DEBUG_PRINT and #undef DEBUG_PRINTLN after DHT.h to undefine the macros for the rest of the sketch. DHT.cpp includes DHT.h and will have the macros defined.

Thanks! I assume by 'GBS' you mean 'DGS'?


text:
Libraries not included correctly
I stumbled upon the following unexpected behaviour and am curious about its cause.
header.h:
#include <Time.h>
[...]

main.ino:
#include "header.h"
#include <Time.h>
[...]

My code is working correctly with this setup. However, if I comment out the Time.h library in my main.ino, my code is working not correctly anymore:
#include "header.h"
//#include <Time.h>
[...]

I can still access the functions of Time.h, but they are returning garbage time.
Why do I have to include the library in my *.ino, although I am already including it in my header file?
Is there a best practice, on where to include libraries? Shall I simply always include all libraries in my *.h and *.ino file?

you want time.h or TimeLib.h? Time.h is ambiguous

Firstly you should be including TimeLib.h not Time.h - the library header name has been changed to avoid conflicts on case-insensitive systems (Windows) and the internal time.h header in many compilers.
Secondly you should always include all your libraries in your INO file directly.  This is because the IDE parses the INO file before compiling looking for any included libraries. It then adds these found libraries to the list of libraries that need to be compiled. Without this you won't get the source code for your libraries compiled properly.

Yes! This (Secondly) also often applies to #include <Wire.h>, if another library uses I2C.

@DataFiddler And SPI, etc.

I don't include includes of libraries. the Arduino builder can handle it. I use Ethernet.h without SPI.h in sketch, UnoWiFiDevEdSerial1.h without Wire.h in sketch, ...

@Juraj As long as you're using a version of the IDE that uses Arduino Builder - or UECIDE of course which does it natively. For everyone else in the world (like those fools that apt-get install arduino, or idiots that use plugins to eclipse or VS ;) ) it won't work. So best to include them anyway since there's no down side, only up sides.  Of course, if no one else uses your code that's fine...


text:
How to prevent the application code from getting stuck in forever loop when using SerialFlash library in Arduino-Adafruit framework
I have been working on a project that runs on Adafruit's Bluefruit nRF52 board. I used the SerialFlash library for Arduino provided by Paul Stoffregen: https://github.com/PaulStoffregen/SerialFlash.The Flash chip used here is the Winbond 25Q128J. This library uses SPI protocol to communicate with the hardware flash memory connected to the Feather. The issue I'm facing is that sometimes (like 1 in 10 chance) during runtime, the code crashes and device gets reset due to watchdog trigger. I suspect this is due to the timer interrupt that I have set to trigger every 200us to generate a pulse wave and this interrupts the SPI's write functionality which the program calls in the main loop every 15 ms, causing some sort of race condition.
I observe that SerialFlash waits until the data is transmitted and received to/from the flash through SPI before leaving the subroutine and the timer interrupt setup in the code is causing invalid state (potentially race condition) and crashed the code. Is there a good way to debug this runtime error? Stepping through Debugger doesn't help since it introduces more timing issues.


text:
to increase the reading and writing/printing speed of data from Arduino Nano to Raspberry Pi 3B+
In my project, I have to read the input pin number(send by RPi), where 8 sensors are attached to Arduino Nano, after reading Arduino Nano send the real-time values of all sensors through serial USB communication. All is fine, but my problem is that I need to speed up the sending of data since it takes to long to read from Rasberry pi.
I put the delay of 70 milliseconds but if I try to reduce more than that, I encounter a problem i.e data overwrites. My baud rate is 115200.
Kindly help me with the code to make it fast.
int analogInputPin;
float voltage;

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(115200);
}

void loop() {
  // if any data on the serial port are available
  // read it and try to update the analogInputPin
  // based on the number that was read on the serial
  if (Serial.available() > 0) {
    analogInputPin = Serial.parseInt();
  }

  // read the analog value:
  int analogInputPinValue = analogRead(analogInputPin);
  voltage=(5./1023.)*analogInputPinValue;

  // print the results to the serial port:
  // the output should have the following form: INPUTPIN:VALUE
  // followed by a newline character
  Serial.print(analogInputPin);
  Serial.print(":");
  Serial.print(voltage);
  Serial.println("");

  // wait 50 milliseconds before the next loop
  delay(50);
}

Hint: Look at the source code for Serial.parseInt(). Consider reading to a buffer instead.

Don't use parseInt. Ever. It's rancid. Read serial properly : https://majenko.co.uk/blog/reading-serial-arduino

parseInt reads digits and stops after a non-digit characters occurs or the function times out because no next characters arrives. The timeout is at default 1 second. So this is where you loose time.
Simplest solution for your code is to send some non-digit character after the number sent from Raspberry. This will terminate parseInt immediately. Usual is to send a new line character. It will separate the numbers nice if you debug the communication with prints to serial terminal.
Not a very good option, but I mention it, is to set the timeout of blocking read functions like the parseInt to a smaller time with Serial.setTimeout(ms).
To really speed up the communication you would send the numbers in binary form and not as text like you do now.


text:
Error: "'lcd' does not name a type" using LiquidCrystal library
I'm following an online Arduino tutorial/course and trying to make a simple moving character on an LCD screen, but for some reason I get the following error: "error: 'lcd' does not name a type". I'm using the Tinkercad simulator because my PC's USB ports died recently.
Here's my code:
#include <LiquidCrystal.h>

byte character[8] {
   B01111,
   B01111,
   B01111,
   B00110,
   B01111,
   B01111,
   B01001,

} ;

  LiquidCrystal lcd(12, 11, 2, 3, 4, 5);

  lcd.createChar(0, character); //error is on this line

const int Lbtnpin = 6;
const int Rbtnpin = 7;
int Lbtnprev = HIGH;
int Rbtnprev = HIGH;
int pos = 0;

void setup(){
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
}

void loop(){
  lcd.clear();
  int Lbtnstate;
  Lbtnstate = digitalRead(6);
  int Rbtnstate;
  Rbtnstate = digitalRead(7);

  if ((Lbtnprev == HIGH) && (Lbtnstate == LOW) && (pos > 0)) {
     pos--;
  }
  if ((Rbtnprev == HIGH) && (Rbtnstate == LOW) && (pos < 16)) {
     pos++;
  }
  lcd.setCursor(pos, 1);
  lcd.write(byte(0));
  Lbtnprev = Lbtnstate;
  Rbtnprev = Rbtnstate;
}

You cannot call methods outside of a function.
Move lcd.createChar(0, character); into setup.


text:
Using ESP32-CAM (with ov2640 camera image sensor) to send image via USB
I was trying to obtain image from ESP32-CAM (with ov2640 camera image sensor).
I obtained the image through camera web server by connecting the ESP32-CAM and PC to same wifi network. A USB to TTL module was used to interface ESP32-CAM to PC.
Program was uploaded to ESP32-CAM using arduino IDE
Reference video: https://www.youtube.com/watch?v=U5uvl6kDFJY
ESP32-CAM development board and ov2640 CMOS image sensor: https://i.sstatic.net/0Fa2W.jpg
CP2102 USB to TTL module:  https://i.sstatic.net/Zr0YV.jpg
Since this system involved wifi I had some serious trouble in obtaining the image:

Entering wifi credentials
Connecting the ESP32-CAM and PC to same wifi network
with variations in wifi speed image display lags which is the main problem

So I was hoping to transfer the image from ESP32-CAM to PC via USB just like connecting a USB webcam to PC.
Can anyone please help to find a solution?

You would have to write some special software for your PC to receive the camera data over the USB UART connection - then send it over the USB UART connection from the ESP32 in the format that you have decided upon.  It can never be a webcam, since the CP2102 is a UART adaptor.

Why not just use a webcam?

Thank you for your suggestion.

I'am not using webcam since its form factor and cost is not reasonable. Do you have any suggestion regarding the special software that you mentioned?

Did you make it out eventually?


text:
Understanding datasheet of a HCHO gas sensor
I have a gas sensor whose datasheet is attached:
DS-HCHO
Now it says that UART communication is needed (P2P) where it (module) waits for Data Frame before tx the data frame to host which I need.
All i know is that I can send start bit in I2C but how shall I proceed.
Also if I have multiple sensors how shall I connect them to ESP-32?

UART is used for rs232 type communication ... it is not I2C

Datasheet says sensor waits for bytes before sending, show shall I proceed with the coding. I could not receive data values.

Step 1: Send the correct data bytes. Step 2: Receive the data from the module. Step 3: Profit.

https://www.arduino.cc/reference/en/language/functions/communication/serial/

First, you need to be communicating by UART, not I2C.  That means using Serial or some similar object (On ESP32 you can define your own on whatever pins you want).  However, the datasheet omits one vital piece of information: the baud rate it communicates at - so you will have to guess that and try various different standard baud rates until you find the one that works.
Then you have to send the "Give me the data" instruction.  The module then responds with the data.
For example (untested):
HardwareSerial mySerial(1);

#define PIN_RX 21
#define PIN_TX 22

void setup() {
    Serial.begin(115200);
    mySerial.begin(9600, SERIAL_8N1, PIN_RX, PIN_TX); // This is the one you need to guess since the DS omits it...
}

void setup() {

    // Once a second send the request to get the data

    static uint32_t ts = millis();
    if (millis() - ts > 1000) { // Once a second
        ts = millis();
        // "Give me the data"
        mySerial.print("\x42\x4d\x01\x00\x00\x00\x90");
    }

    // When 10 or more bytes have arrived then assume that they are correctly
    // framed and print them.  Really it should read one byte at a time and
    // look for the correct start sequence of 0x42 0x4d 0x08 and read only
    // from there, but this will server for demonstration purposes.

    if (mySerial.available() >= 10) { // We expect 10 bytes returned
        uint8_t packet[10];
        mySerial.readBytes(packet, 10);
        Serial.print("ID:   ");
        Serial.println(packet[3]);
        Serial.print("UNIT: ");
        Serial.println(packet[4]);
        Serial.print("VH:   ");
        Serial.println(packet[5]);
        Serial.print("DHH:  ");
        Serial.println(packet[6]);
        Serial.print("DLL:  ");
        Serial.println(packet[7]);
        Serial.print("LRCH: ");
        Serial.println(packet[8]);
        Serial.print("LRCL:   ");
        Serial.println(packet[9]);
    }
}

Thanks. Well it helped a lot.


text:
Is it possible for Arduino as ISP board to flash an ISP master board?
I have a setup of 2 Arduino Leonardo boards. Let's refer to them as Board A and Board B.
Board A is a master SPI board that is constantly communicating via SPI to an array of sensors. At some point, board A will need to be flashed with a new sketch.  That's where Board B comes in.
I want to use Board B go use an Arduino as ISP sketch to go and flash a new sketch onto board A. Problem is that Arduino as ISP uses SPI, which conflicts with the code on board B since board B is a master device communicating to other sensors via SPI.
Is it possible for board B to flash board A via ISP?

the ISP flashing is done in reset state. there is no SPI used then. but the connected SPI slave can interfere

Your code is not running when your new code is uploaded.

Yes, you can flash an MCU using ISP even if the MCU acts as an SPI device (be it master or slave). The programmer puts the MCU into reset mode, so at the time the sketch is uploaded, SPI will be disabled anyway.
Another thing you need to think of are the other SPI devices (the sensors or what ever the MCU controls). They can pick up the SPI signals sent by the programmer and occasionally write on the bus themselves, therefore disturb communication on the MISO line, which would be critical. There are two options to handle this:

Simply disconnect any SPI slaves during code upload
Make sure there are pullups on the CS lines so they have a defined state (they might be floating while the MCU is in reset). Some slaves might require pulldowns to be deactivated, but that's uncommon.

Thanks for the detailed reply! Questions: when you say CS lines, are you referring to the slave select lines? And are pull ups resistors where one end goes to vcc, and the other goes to the slave select port on the sensor? Right now I'm imagining that somehow the pull up resistor is keeping the slave select line high during reset. I guess because it's common for slaves to be active low. If a pull-up keeps the SS high, how does board A in normal operation drive the SS line low to say "hey sensor, send me data"?

the SPI protocol says that the selected slave has SS LOW and slaves with SS HIGH should not access the bus

@SomeGuy yes, I'm referring to slave select lines. yes, pullups are connected between Vcc and the line to be pulled up. if all of your slaves have pullups anyway, you should have no problems to upload code


text:
Custom 328P-AU board not responding via ICSP
I created a custom PCB based on a 328P. The design is mainly based on the Arduino Nano schematic (3.0). The boards have arrived some days ago, and I can't get avrdude to recognize them via USBASP (or any other mean for that matter). When trying to program the board is powered via the ICSP connector. What I have tried so far:

only soldering the essential components: CAPs for 5V rail
soldering the Oscillator or leaving it off
on one board I even cut all lines except 5V, GND, RST and SPI.

Still the 328p won't respond, all I get is :
#avrdude -u -c usbasp -P COM1 -b 57600 -B 0.5 -p m8

 WARNING: Unable to detect MCU
 avrdude.exe: set SCK frequency to 1500000 Hz
 avrdude.exe: error: program enable: target doesn't answer. 1
 avrdude.exe: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.
 avrdude.exe done.  Thank you.

I will attach my schematics and my board design, I know it is not the cleanest for now... It is my first one and I am currently trying to clean it up/make it better. I also added 1k resistors in line to RX and TX, but they are not present in the board design for now.
I am thankful for any help and/or advice
I can provide the board design if needed:)

I can't see anything obvious in your design. Have you tested a board with a DMM to look for shorts and test continuity of relevant traces, and confirmed correct voltages?

yes I did, continuity is fine, resistance GND to 5V is about 15kOhms, so that may be fine too...There are no obvious shorts that I am aware of... Is it possible that the 328p's are all dead?

SCK frequency to 1500000 Hz  Whatever else you do, I'd lower that.  If you chip is fresh from the factory, that may even be the problem.

@timemage you are my hero!!! set it to 8k solved it:) thanks so much!!!!!

If you want you can post it as an answer.

Alright, well, I posted an answer so that it has one.

@timemage sorry saw it too late, thanks again !

So you had:

SCK frequency to 1500000

And I suggested lowering to the point where you:

set it to 8k solved it:)

Good deal.  The thing that you were likely running afoul of is the maximum ISP clock rate, which according to the datasheet for the ATMega328P (or practically any other AVR for that matter) is determined by some rules:

Low:> 2 CPU clock cycles for fck < 12MHz, 3 CPU clock cycles for fck ≥ 12MHz
High:> 2 CPU clock cycles for fck < 12MHz, 3 CPU clock cycles for fck ≥ 12MHz

So your maximum ISP clock rate is dependent on the chip's clock rate.  And is either at most a quarter of a sixth of that, depending on whether or not the chip operating below or above 12MHz.
Most ordering codes of AVRs of the type that do this kind of ISP programming ship from the factory at on the internal 8 MHz oscillator with the divide-by-8 fuse enabled; So they're at 1 MHz with a maximum ISP clock rate of 250 kHz.  Had you been working with a the typical Arduino arrangement when it had already been set up for and running with a 16 MHz clock, the 1.5 MHz ISP clock rate might have worked.  I'd have still slowed it down, since it will only be more likely to work when doing that.
Most programmers default to a low clock rate, closer to your 8k figure.  Usually, if people have a problem with hitting the maximum ISP clock rate, it's because they have a very low system clock, either using a watch crystal or fusing for the internal 128 kHz, or either in combination with the divide-by-8-fuse.  Often when trying to go too-fast, what's holding them up is crappy wiring.
When you're programming there's a limit to how useful it is to crank the clock rate up anyway, because eventually there's going to be a lot of hurry-up-and-wait while the chip flashes sectors and the timing of that isn't dependent on the clock rate.


text:
How to transmit data from a sensor using SIM800L?
I am using soil sensor with Arduino UNO. I wish to transmit data coming from sensor to a server using sim800l.
I am unable to find any help on this. please guide me.

which part of the project are you able to do now?

I read about basic interfacing like send and read SMS and calling methods.I am able to read the data from sensor but I am unable to find a code/ function to upload it.

try this... https://exploreembedded.com/wiki/GSM_SIM800L_Sheild_with_Arduino


text:
Interface gps and ultrasonic sensor simultaneously
I am able to interface  gps and the ultrasonic sensor and obtain data successfully for individual interfacing with the Arduino UNO. When I combined the code for these two, I only get the data values from gps but no measurement values are obtained for the ultrasonic sensor.In the variable data, I have stored the gps data packet. I have read the solution for the same problem but none of them worked. I have attached the code below:
    #include <SoftwareSerial.h>
    #include "TinyGPS++.h"

    SoftwareSerial serial_connection(8, 9);

    TinyGPSPlus gps;
    TinyGPSCustom Trackingangle(gps, "GPRMC", 8);
    TinyGPSCustom Dir_NS (gps, "GPRMC", 4);
    TinyGPSCustom Dir_EW (gps, "GPRMC", 6);

    String data,tr,ew,ns,d1;
  int a=0;
    const int trigPin = 6;
    const int echoPin = 7;
    long duration;
    int distance;
    int buttonPin = 12;
    String s="",str_dist="",str_button="";
    int buttonPushCounter = 0;
    int buttonState = 0;
    int lastButtonState = 0;

    void setup()
    {
      pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    pinMode(buttonPin, INPUT);
      Serial.begin(9600);
            serial_connection.begin(9600);
    }

    void loop()
    {
      data="";tr="";d1="";
    serial_connection.listen();
     dat_gps();
       if(data!="")
    {
    Serial.println("GPS DATA= "+data);
    ultra();
      }
   }
        void ultra()
    {
distance=0;duration=0;
         digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    //if(duration!=0)
    {
      distance= duration*0.034/2;
        Serial.print("Distance= ");
    Serial.println(String(distance));
    }
    }

    void dat_gps()
    {
     {
      while(serial_connection.available())
      {
        gps.encode(serial_connection.read());
      }

    if (Trackingangle.isUpdated())
    {
        tr=String(Trackingangle.value()); //    Serial.println(tr);
    }
    if (Dir_EW.isUpdated())
    {

     ew=String(Dir_EW.value());
    }
    if (Dir_NS.isUpdated())
    {

      ns=String(Dir_NS.value());
    }
    if(tr!="")
    { if(gps.location.isUpdated())
     {       delay(2000);
        data=String(gps.satellites.value());
       data+=",";
       if(data!="0,")
       {
        data+=String(gps.location.lat(), 6);
        data+=",";
        data+=String(gps.location.lng(), 6);
        data+=",";
           data+=String(gps.speed.mph());
              String a=String(gps.altitude.feet());
         if(a!="")
       {   data+=",";
       data+=a;
         data+=",";
          data+=String(gps.hdop.value());
         data+=",";
         data+=tr;
         data+=",";
         data+=ns;
         data+=",";
         data+=ew;
         data+="";
            }
       }}
      }
     }
    }

You need to explain your hardware setup and your code.
What type of communication do your different devices use? I2C? SPI?
What pins do they use for their interfaces?
What model of GPS and ultrasonic sensor are you using? Where can your readers find documentation and specs on those devices? What do the different commands to the devices do?
Also, you need to fix the formatting on your code. The indentation is a mess, and makes it very hard to follow the flow.

You can't.  An Arduino Uno is a a single processor.  It can do only one thing at once.  Please can you have a go at formatting your code, because its not very reader friendly.

Put Serial.println("GPS DATA= "+data); right after the call to dat_gps() and tell us what it prints.

I am using HC SR04 as ultrasonic sensor and Quectel L80 as gps. I want serial comunication on pins 8&9.

@SimSon, some values are shown as 0 as gps takes time to set. Once  its set, all the values are printed

Can anyone help?


text:
Communication between three NodeMCUs such that one in in AP mode, second one in AP+STA mode and the third NodeMCU in STA mode
I am able to establish a connection between first and second NodeMCU, but unable to do so for the third nodeMCU. I used the IP  address to establish connection.
Should I assign a different IP to each nodeMCU so that communication can take place?
In the code that I had written, i have taken the same IP for all three NodeMCUs, so   communication was possible between 1st nodemcu(in AP mode) and 2nd nodemcu(in STA+AP mode).
For the 3rd node mcu the IP taken was different. Can any one suggest what to do next.

The two network interfaces (station and SoftAP) of the middle esp8266 must have different IP address range. If the top esp8266 has SoftAP with 192.168.4.x, set for the SoftAP of the middle esp8266 IP for example 192.168.5.1. Because with same IP address ranges the esp8266 doesn't know to which network do you want to connect a TCP socket or send an UDP message.

does it mean that the IP should be same for first and second nodemcu  is same?Also, the IP should be same for second and third nodemcu? Do I need two different IPs for the second nodemcu?

you have no clue about IP addresses? the STA must have the IP in the range of the AP it connects to. no matter if the AP is a box or a esp8266


text:
Communicate between 3 nodeMCU
How should I verify the communication between three node MCUs where one behaves as server and the other two as clients such that data of each node mcu is obtained on all three?

you would verify the communication by transmitting pre determined data ... if the data arrives correctly, then the communication is working correctly ... if the data is incorrect, then the communication has an issue

communication between 3 nodemcu can be done instead dont assume one nodemcu as server other two as client. Mqtt is a message protocol which is used to transfer messages. Connect all the three nodemcus in the same network and host a mqtt server separately in the same network. Mqtt has to flexibility to send data from one nodemcu to other nodemcus which are in the same network. Publish and subscribe method can be used to get data or post data.
Go through this link
http://mqtt.org/

i want to communicate using the IPs of the nodemcu and not by the mqtt protocol.


text:
Issues controlling servo motors with serial monitor while using 16 channel servo Shield
I am making a 6-axis robotic arm that uses multiple servo motors.The goal is to create a program that accepts degree values from the serial monitor to control multiple servo motors.
I have just started programming with the Arduino, so I need help debugging a program that I have piece together from guides throughout the internet. The program will compile and upload, but when I input values into the serial monitor the servo will not move like I would like it to. At the moment, the servo motor will move 50 degrees. I have calibrated my servo but it still won't work properly. Furthermore, I kept the program for one servo just for testing I know that I will have to create an int motorA=0; motorB=1; etc. Any help will be appreciated
reference links:
https://forum.arduino.cc/index.php?topic=242458.0
https://www.youtube.com/watch?v=y8X9X10Tn1k
Hardware:
Arduino Uno
16 channel Arduino Servo shield
5v external power supply
MG995 Servo
Notes:
No connectivity issues
Motor is connected properly
No hardware issues
Program:
enter code here
String readString;
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

#define SERVOMIN  650
#define SERVOMAX  2350
#define FREQUENCY 60

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

int motorA = 0;
int motorB = 1;

void setup()
{ // put your setup code here, to run once:
  Serial.begin(9600);
  pwm.begin();
  pwm.setPWMFreq(FREQUENCY);
}

void moveMotor(int ang, int motorOut)
{

 int angle = map(ang,0, 180, SERVOMIN,SERVOMAX);
 for ( uint16_t pulse_width = 0; pulse_width < angle; pulse_width++)
 {
   pwm.setPWM(motorOut, 0, pulse_width);

 }
}

void loop()
{
 //expect single strings like 30c, or 90a, or 180d,
//or combined like 30c,180b,70a,120d,

if (Serial.available())
{
  char c = Serial.read();  //gets one byte from serial buffer
  if (c == ',')
  {
    if (readString.length() >1)
    {
     Serial.println(readString); //prints string to serial port out

     int angle = readString.toInt();  //convert readString into a number

     Serial.print("writing Angle: ");
     Serial.println(angle);
     if (readString.indexOf('a') >0) moveMotor(angle, motorA);

     readString=""; //clears variable for new input
   }
 }
else {
  readString += c; //makes the string readString
  }
 }
}

What are you sending over serial to control the motor?

Degree values like 110a, or 120a, . The a just means motorA  and the number means the degree value

I don't see an obvious error. You can do some things, to further narrow down the problem: 1. Remove the for loop from moveMotor(), since it is too fast for the motor anyway, or make it slower by putting in a delay. 2. Check, if a PWM signal is actually outputted from the shield. If you don't have an oscilloscope, you can connect an LED to the channel and driving the channel slowly from 0% to 100% duty cycle (be sure to include a delay there). If the LED is fading in, the PWM signal is correctly outputed. 3. Recheck the pulse width, that your motors is reacting to and be sure to use it.

That clears up a lot thank you. I will use your advice. If I remove the for loop the motor will not move at all


text:
Two sensors using I2C
We have two sensor one of them(MPU6050-gyro) is communicating using I2C, the other is via SPI(SD card reader). Now, we need an additional component as a sensor that the barometer which communicates via I2C.
Can we use all three modules without any problem? I wonder if two I2C modules is used in a hassle-free manner? Otherwise, what can be done?

Yes, that's the idea behind bus protocols like i2c. You only require the sensors on i2c to have different bus adresses. A sensor's address usually can be chosen by soldering a jumper (the mpu6050 provides this feature on pin AD0). If you can't avoid an address collision you could use an i2c multiplexer or a microcontroller in between the sensor and the actual mcu (but probably that's not neccessary when using only two sensors).
Using SPI and I2C at the same time is absolutely no problem on the atmega!

I2C is a bus. There can be many devices connected to that bus, each one having it's own address. Everytime you want to communicate with one of them, you have to send the address of the device. When you are using the Wire library, thats done by calling Wire.beginTransmission() or Wire.requestFrom(). Most slave devices have an adress, that is partly configurable, often by wiring special pins to Vcc or ground. Make sure, that every device on the bus has a unique address, or you will run into problems with corrupted data or a stuck bus.


text:
Updating Server using ESp8266 with Direction Button Pressed IN
I've connected a 5-way tactile switch to a ESP8266 module and am using the Arduino IDE to create an automatically updating web server that displays the direction that the button is pressed in when pressed. Currently the webpage displays the first direction that the button was pressed in but does not update the page after I press the button several more times. Below is my code:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

//ssid and password info, ommitted here for obvious reasons

int upPin = 5;
int leftPin = 4;
int centerPin = 0;
int rightPin = 2;
int downPin = 14;

ESP8266WebServer server ( 80 );

void handleRoot() {
    server.send(200, "text/html", "\
  \
    <meta http-equiv='refresh' content='1'/>\
  \
  \
  \
");   // Send HTTP status 200 (Ok) and send some text to the
browser/client
}

void setup(){
 Serial.begin ( 115200 );
 WiFi.mode ( WIFI_STA );
 WiFi.begin ( ssid, password );

 server.on ( "/", handleRoot );
 server.on ("/", button );
 server.begin();

void loop(void){
  server.handleClient();
  button();
}

void button(){
  if (digitalRead(rightPin) == LOW)
  {
    server.send(200, "text/html", "
*RIGHT#
");
    delay(10);
  }

  if (digitalRead(leftPin) == LOW)
  {
    server.send(200, "text/html", "
*LEFT#
");
    delay(10);
  }

  if (digitalRead(upPin) == LOW)
  {
    server.send(200, "text/html", "
*UP#
");
    delay(10);
  }

  if (digitalRead(downPin) == LOW)
  {
    server.send(200, "text/html", "
*DOWN#
");
    delay(10);
  }

  if (digitalRead(centerPin) == LOW)
  {
    server.send(200, "text/html", "
*CENTER#
");
    delay(10);
  }

}

so / is root or button? do you hold a switch all the time?

I changed the code so that the button function runs with "/" and took out the server.on("/", handleRoot) line, thanks to @Juraj. Sigh


text:
Is there a real alternative now to using GSM for data sending?
I would like to create an Arduino system that sends the temperature in a place outdoors to a server.
I've read in Internet forums that there might be alternatives to GSM and GPRS technology for sending data remotely, but I'm not sure about them. In absence of WiFi, is GSM the best technology today, even that you have to use the SIM plan to use it?

what's the range? can you use LORA?

the range could be km-s and I don't live in Germany.

i don't know what germany has to do with anything, but lora can go several KMs, easily

ok, sorry, I was totally wrong. I thought that it only was valid in Germany. I'm trying to send some temperature data to a remote server. I'm seeing some tutorials in Arduino that do that, so I'm going to consider it. Do you see any problem in using LoRa for my application?

GSM (or more realistically now, LTE) is really the only option.
Simply put: you need some method of accessing the internet, and unless you create your own local infrastructure that means using the mobile phone system. It's the only system that is virtually everywhere and doesn't require you to install your own communication system.
So that means some modem device that can communicate with the mobile phone system. GSM is what it used to be, although some mobile companies are now deprecating the GSM system and only really providing UMTS (3G) and LTE (what will eventually be 4G), but LTE modems are quite expensive still.
So yes, you need a SIM to do it. You can't access a mobile phone network without one.
One option that could be a cheaper possibility would be to get a cheap second hand smartphone off eBay (or dig out your old one from the bottom of the desk drawer) and use that as your own mobile WiFi hotspot. Your Arduino device connects to the phone with WiFi, and the phone connects to the UMTS or LTE network using a cheap PayG SIM.

LoRA is a technology that is gradually becoming more popular and allows long range wireless communications at low power and low cost. There are areas where LoRA is becoming available, such as in Munich. Should LoRA become available in your area, or should you invest in your own infrastructure, that could become a viable alternative to using the mobile phone network.

Sigfox and NB-IOT are also two more technologies.

@MaximilianGerhardt So write an answer detailing them. Personally I have never heard of them.


text:
How to use RTC memory in NodeMCU to count awakes from deep sleep?
Problem: I need to retry at least 3 times (before giving up) to reconnect my NodeMCU if it doesn't get connected to Wifi, through deep sleep cycles in order to save batteries. I thought to use RTC memory to save a counter, but it doesn't work because content of RTC RAM is unpredicatble at first power up.
Following is a NOT WORKING code, but it gives the idea of what I need to achieve. The problem is: the kounter variable is persistent through cycles, but its very first value is unpredicatble.
#define DONEPIN 5
uint32_t kounter;

void setup() {
    digitalWrite(DONEPIN, HIGH);
    //WiFi setup functions...
    // .....
    if (WiFi.status() != WL_CONNECTED) {
        ESP.rtcUserMemoryRead(0, &kounter, sizeof(kounter));
        kounter++
        if (kounter > 3) {
            digitalWrite(DONEPIN, LOW);
        }
        ESP.rtcUserMemoryWrite(0, &kounter, sizeof(kounter));
        ESP.deepSleep(60e6);
    }
}

@Majenko interesting! Didn’t know that. I removed my comment.

@Gerben So did I :P

You can differentiate between first powerup and resets (after deep sleeps) by using rtc_get_reset_reason(0). If I’m not mistaken this should return a 1 on powerup. So when this returns 1 overwrite the RTC memory with zero. Otherwise read the memory.

The simplest trick is to use more than one memory location. Have one, as you have now, as a counter, and then have one or more as a "This has been configured" flag.
Ideally you want the flag to have a very low probability of occurring randomly, so using a combination of a number of memory locations would improve that.
For instance, if you read memory locations 1-4 and look for four specific bytes, that gives you about a 1 in 4 billion possibility of it happening randomly.
If you don't see those four bytes, you set the counter byte to 0 (or whatever you want your initial value to be) and set the other 4 memory locations to contain your 4 flag bytes.
Using 8 bytes for your flag would give you in the order of 1 in 1.8x1019 chance of it occuring randomly.
These "flag byte combination" are often called "magic numbers" and are used all over the place to identify either what something is, or if something is valid.

So, can I use a struct { byte counter; byte validation[7]} ?

Sure, you could do. I don't know what the functions allow you to easily pass though, so it may be simpler to just directly access the memory's bytes.

I realize this is really old, but it is still the top of the list when you search for RTCmem read/write. While it isn't maybe as "by the book" as the 'correct' answer above, there is a really simple way to deal with the "the rtcmem value is something ridiculous on first read" issue. When you first power on the esp8266 or after a button-based reset, the rtcmem value WILL be something insane. You can account for it in the code by ignoring anything that is outside the count you want. Since my application "sleeps" for 4 hours, which in esp8266 means 4, 1 hour loops, I simply say if the rtcMem value is outside that range, it is obviously bogus, set it to what I want, and go about your business:
void writeToRTCMemory() {
  if (rtcMem.count == MAXHOUR) {
    rtcMem.count = 1;
  } else {
    if (rtcMem.count < 1) {
      rtcMem.count = 1;
    }
    if (rtcMem.count > 4) {
      rtcMem.count = 1;
    }
    rtcMem.count++;
  }

As long as your device has not lost power, or you have not pushed the reset button, this will keep it looping the way you want for as long as it has enough juice to deep sleep. (My solar powered sensors with this loop last around 2/2.5 weeks in the mid winter and much longer in summer)


text:
NodeMCU v1.0 high power consumption in deepsleep
I am using a NodeMCU v.1.0 ESP-12 for a small project. It is powered by 3xAA batteries (4.5v) in Vin, but to reduce power consumption I need to put in in deepsleep every now and then.
Running this small sketch:
void setup() {
  Serial.begin(115200);
  Serial.setTimeout(2000);

  // Wait for serial to initialize.
  while(!Serial) { }

  Serial.println("I'm awake.");

  Serial.println("Going into deep sleep for 20 seconds");
  ESP.deepSleep(20e6); // 20e6 is 20 seconds
}

void loop() {
}

I have measured a consumption of 8mA when it goes to deepsleep, and this is not acceptable for my purpose. In order to wake up from sleep I have connected pin GPIO16 (D0) to RST, and it works. I knew that NodeMCU should have only few µA of consumption in deepsleep. How can I fix this?

Have you tried to remove the LED?

Which one? The board has just a tiny blu LED which flashes for a moment when you switch it on, then it turns off. No LEDs are on during operations.

Sorry forget the LED! Look at the LDO,  look at this https://electronics.stackexchange.com/questions/286249/replace-ams1117-5v-3-3v-ldo-on-nodemcu-for-lipo-with-low-quiescent-current

I will read that link, thanks. But I have also made a test powering it directly on the 3V3 pin by an external regulator and the results are the same.

I have read the article. So, you suggest me to remove the internal LDO and use an external MPC1700? I am not a soldering-meister, so I am afraid I will break the device...

how much is used by the usb serial that you don't need after flashing?

The usb serial is not used, after flashing. But I always have the opportunity to update the sketch!

The usb to serial still uses power, even when it isnt used.

Yes, I have replaced an LDO in a similar exercise with an Arduino UNO.

Consider the TI TPL5110 timer chip with power control MOSFET. Set the timer period with a resistor then the TPL5110 powers on the NodeMCU periodically. Deep sleep is not used. RTC RAM will be lost so use SPIFFS for persistent data.
Adafruit has a breakout board. Take a look in Adafruit's forum for user comments because it has a few limitations.

You worried me about your warning "look at comments..", but I can't find anything serious...


text:
Use SD-Card module in combination with MKR GSM 1400
I have bought a SD Module with the following Pin-Names: VCC,GND,MOSO,MOSI,CS,SCK. I've found many tutorials on how to use it with the Arduino Uno. But haven't found any on how to wire it with the MKR GSM 1400. Most of these Pin Names are written on the Board itself, but the CS-port isn't marked. (VCC and GND are obvious). So is there any tutorial on how to use them together or any more specific documentation?
Here is a Picture of the SD-Adapter I am using :

here is a table with SPI pins of the MKR  https://www.arduino.cc/en/Guide/MKRMEMShield

You can free choose pins used by SPI master to select slaves, but if possible use the default expected by the library.
With MKR and other SAMD Arduino boards use the same default SPI slave select pins as for AVR boards, because same libraries are used.
Ethernet library has default SS pin 10 and SD library pin 4.


text:
Build an improved GSM antenna for arduino mkr gsm 1400
I want to use an Arduino MKR GSM 1400 in my area wich has a bad connectivity on mobile internet. On my phone it's very weak and if i drive to the next village it works sometimes on the arduino with the given standard antenna but I want it to work in a wider range. Is there any antenna available specifically for mobile connections wich you can put on a arduino? And how do you call them and where can I buy such a thing or even build it myself? Do you have any suggestions for such an antenna? And is there something I can improve with just using software to strengthen the signal?

On one end of the MKR GSM 1400 is a U.FL antenna connector.  To that you need to connect a U.FL To Female SMA Adaptor.  That adaptor can then screw into an SMA GSM Antenna of your choice.

Do you have any suggestions for such an SMA antenna wich has a wide range? And where can I find that specific adapter??

I get the adaptors from eBay. I can't recommend a specific antenna, but the ones with a long cable and a magnetic mount (that are intended to go on top of cars, etc) would allow you to place the antenna in a high location where you can get better signal.

@The_javascript_King The connector is one thing, but antenna performance is dependent on antenna type and gain. Try to compare gain values (in dBi) of the antennas you're buying -- the higher, the better.


text:
Caluclate lux value from LDR
I am using an LDR (Iduino SE012) to measure light. It returns a 10-bit value of the incoming voltage and I don't know how to convert this into lux, lumen candela or any other light-intensity unit. I was googling for datasheets but nothing useful came up. So is there any way how I can extrapolate a light intensity from the voltage?
I mean one idea that I would have is to measure some things where I know the lux output, but since I don't have such things or a luxmeter I'm pretty stuck. It also returns 1024 pretty quick if you hold it into the sun (Altough the sun is very strong today and it has 36°C). Is there maybe a "minimal value" at wich it returns the full voltage? From that point I could calculate it for all the other values.
Here are some datasheets I found:

https://www.manualshelf.com/manual/iduino/se012/datasheet-english.html
https://wakamatsu.co.jp/waka/SE012.pdf

I'm in no way known on this subject, but if you have reference lights you could gauge/plot them to find the corresponding values for your sensor?

The cheapest lux sensor is the bh1750. If you buy a bh1750 you can make a table for the ldr to get the lux value. Maybe you can also add a ds18b20 temperature sensor to compensate the ldr value for the temperature. Then you can use the ldr...  wait, did the bh1750 do all of that already? A light sensor may not be used with direct sunlight. Neither the ldr or the bh1750.

You can't.
The LDR has a spectral sensitivity which is very different from the
human eye's. The definition of the lux, or any photometric unit for
that matter, pretty much requires that your sensor is filtered in such
a way as to have the human eye's spectral sensitivity.

Well maybe there's some interference of ultaviolet, radio waves and such things but these should be minor. And if you use it to measure sunlight the amount of visible light and UV-light should be relative to each other. So if I accept interference from other spectres would it then be possible?

@The_javascript_King: Most of the spectral response misfit will come from near IR, rather than UV or radio. And it's nowhere near “minor”. If the light you measure has always the same relative spectrum (same relative intensities at various wavelengths), then yes, you could calibrate this in lux. However, the vis/IR ratio of sunlight depends on the height of the sun over the horizon, so you cannot assume a constant ratio.


text:
Bluetooth Trancievers for arduinos
Would it be possible to use to of these on two separate arduino's, to send and receive information? I am having difficulties understanding the chinese-english descriptions and haven't seen any documentation on doing this. There would be no phone involved. There would only be two arduino's with a Bluetooth module on each of them sending and receiving data from each other.

The boards in your link look funny.  Typical boards like this include the "bluetooth circuit" which piggy-backs onto that board, and is soldered at all those little pads.
Have a look at say, the HC-05 board ~  https://www.google.com.au/search?q=hc05+bluetooth+module&tbm=isch
It's easy to see the part that's missing from the one in your link.
For these HC-05 boards, it's possible to pair two together.  They need to be configured as "Master" and "Slave" though.  Some bluetooth boards can do slave-mode only, so be careful before you purchase.

To add to this old thread, HC-05 is not the same as HC-06.  HC-06 is a "slave only" model, like @Kingsley mentioned.

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


text:
Arduino TRE Release Date and Cost
I have been awaiting the release date for some time for the Arduino TRE.  So, my question is simple does anyone know the release date or any hints about when it might come out?  Also, what do you think the cost will be?

Who is making the TRE? LLC or SRL? All the throwing-toys-out-of-cots going on at the moment will most likely delay all new releases of hardware by at least 5 years.

Looking at the price of the Due, and comparing to BeagleBone or Raspberry Pi, I'm afraid it will be a lot more expensive than the latter two.

@Majenko: I didn't understand what you meant until now...good point! Thats sad. :-(

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


text:
Cheap LCD with Few Pins
I am working on a project with an Arduino Nano that includes a keypad, screen, and the NRF4001 transceiver. The keypad requires 7 digital pins to operate, the wireless transceiver uses pins D9 - D13 with the RF24 library I am using. Now, that leaves me with 1 Digital Pin left for a screen unless there is an I2C screen I could use.
That would be easy enough to find except that I have some limitations. If at all possible I would like the screen to be under 5 dollars and about the size of a Nokia 5110. The Nokia uses to many pins and does not tolerate 5v logic levels I've heard. An OLED 0.96 inch is only a 4 bucks and is I2C, but it is too small. I could make a board for the keypad that used different values of resistors and one analog pin to detect different buttons but would rather not go that route if there is any easier way to get around this.
Are there any options out there that would suffice my pin, cost and size conditions or am I being too picky?

Has anyone seen a backpack for Nokia's that make them I2c capable for example?  I know its been done with the typical 16x2s.

You can also use the analog pins as regular digital pins. So you have 6 pins left. The Nokia 5110 seems to run fine on 5v, from what I've heard. But you could add a buffer chip to change the voltage levels (example).

How would you do that....use analog as digital?

Ok...I saw how they could be used as inputs 14 - 19 but can they be used as digital outputs too in the same way or do I have to say analogWrite(pin, 1023) to get the same result as a digital HIGH

http://www.avdweb.nl/arduino/hardware-interfacing/nokia-5110-lcd.html This link seems to suggest 3.3v opperation.

Just use pinMode(A3); and digitalWrite(A3, LOW); e.g.. 5v on the 5110 is out of spec, but appears to work with no problem. But use at own risk.

You can use a single analog pin to read an entire keypad.
First, read up on voltage dividers - they let you convert a resistance into a voltage. You will need to know this later on.
A keypad typically has 4 inputs, and 3 outputs (or vice-versa). Label the 4 pins A,B,C,D and the 3 pins E, F, G. You will be wiring A up to a voltage supply, and G up to an analog pin, and via a suitable resistor to ground. This becomes your voltage divider.
Then, put a resistor between A+B, B+C, C+D, and between E+F, F+G. So, if you press the button that connects A to G, there will be no resistance (=+5V). If you press the button that connects A to F, then the resistance will be that of the resistance F->G. If you press the button that connect D and E, the circuit goes: VCC-A-resistor-B-resistor-C-resistor-D-pushbutton-E-resistor-F-resistor-G - Arduino analog pin. With no button pressed, the voltage will be 0.
You will need to work out different resistors in advance, to give you as even a range as possible between 0 and 5 volts (the critical thing being the smallest difference). You can calculate the resistance of any combination here: http://www.calculator.net/resistor-calculator.html and you can use Ohm's law to calculate the final voltage. This depends on what you have in your kit. I ended up making a spreadsheet, and then trying random resistor values until I got a good spread.
DO NOT use any resistors under 1kOhm.
Once you have the right spread, make it up on a solderless breadboard. Measure the voltage with your arduino (use the "readanalogvoltage" sketch, take out * (5.0 / 1023.0) , and make up a table - press button 1, you get a reading if A, press button 2, get a reading of B. Include the reading when no button is pressed, which should be 0.
Then find the numbers exactly in between.
For example, if the lowest three readings are 0,20,37 for no button, A, and B pressed, respectively, then in your code, you will say: if the pin measures less than (half way between 0 and 20=) 10, then no button is pressed; else if the pin measures less than (half way between 20 and 37=) 29, then button A is pressed... and so forth.


text:
I want 2 output pins to working alternately
I have given pwm output on pin(9) and I Want pin(10) to be high when pin(9) is low and pin(10) to be low when pin(9) is high.  So what should i add to my code?

"So what should i add to my code"? Know how to use if ... else ...?

Do you care if for few microseconds they are the same?

That depends on how you achieved your PWM on pin 9. analogWrite? Manual timer manipulation?
I'd set up one of the timers for PWM (timer mode 1 or 3) and have it call its interrupts (OCIExx).
In the interrupt, you'd then alternate between turning each pin on and off.

You can set pin 10 to run in “inverted PWM” mode, and leave
pin 9 in the default non-inverted mode. Pin 9 is the “OC1A”
pin of the AVR microcontroller (output compare of Timer 1,
channel A), whereas pin 10 is OC1B (channel B of the same
timer). Inverting the PWM mode of channel B is a matter of changing
a single bit in one of the control registers of Timer 1:
TCCR1A |= _BV(COM1B0);

You can do this once in setup(), the setting should persist. Then just
analogWrite() the same value to both pins. For some background on how
all this works, see the datasheet of the ATmega328P
microcontroller (the MCU at the hearth of your Uno),
especially section 16 “16-bit Timer/Counter1 with PWM” and table
16-3 “Compare Output Mode, Phase Correct and Phase and Frequency Correct
PWM”.

would something like the following work?
digitalWrite(9,  !digitalRead(10));

like this: https://forum.arduino.cc/index.php?topic=128698.0

The link you gave, has set a particular pin as input, but in my case i am giving pwm output from pin9 and i want that when pin 9 output is Low make other pin high and when the pin9 again goes high turn pin10 Low.  But i can't write analogwrite and analog read on same pin9

it looks like they suggest you can, but also lower down in the forum there is also a suggestion to try and just use a script that sets them as opposites whenever you set one. eg.
void setLed(bool v)
  digitalWrite(9, v);
  digitalWrite(10, !v);
}```


text:
Counter program
I'm an absolute beginner, and lately I had some problem with this program I was trying to do.
Basically I wanted with the Arduino to count 3 pulses from an oscillator and store the time  of these 3 pulses, but as I said I am a beginner so I have no Idea on how to do it, I would appreciate your help.

Doing what you'd like to do well is an advanced topic that could take a long time to learn. What code have you written so far in your attempts? Please post your efforts (code) thus far. There are many many approaches, many of which are viable, depending on the width and frequency of the pulses you'd like to measure. What is their pulse width, duty cycle, and frequency?

What is "The time of these 3 pulses"? You may want to better define it and start with a simpler version. Like count the time between two 'high' signals. Also, how accurate will you need it to be? Milliseconds or microseconds?

Time counting is easiest done with millis() or micros() (tons of tutorials on the web about them). Though that does not work for high frequency. Please define your exact requirements. What frequency are we talking about? How are the pulses shaped? Do you need to do other things besides that?

get a pencil and paper .... write down what you would do if you had to do the task yourself ... pretend that the pulses are several minutes long and tens of minutes apart .... write down in small, clear steps what you would do ... that becomes pseudo code that can be translated to real code

I had some problem with this program I was trying to do - have you written a program then? Please post it so people can help you with it. (Edit your question to do that).  You might also find helpful this post: How to ask a good question for Arduino Stack Exchange.

While this is likely to need tweaks for your needs, it should get you looking at the right things - millis, interrupts, etc.
Official references at:
https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
https://www.arduino.cc/reference/en/language/functions/time/millis/

#define pulsesToStore 3
#define interruptPin 2
volatile unsigned char index;
unsigned long storedTimes[pulsesToStore];

void restartStorage() {
 index = 0;
 attachInterrupt(digitalPinToInterrupt(interruptPin), storeTime, RISING);
}

void storeTime() {
 storedTimes[index] = millis();
 index = index + 1;
 if(index >= pulsesToStore) { //stop storage
  detachInterrupt(digitalPinToInterrupt(interruptPin));
 }
}

void setup() {
 pinMode(interruptPin, INPUT_PULLUP);
 restartStorage();
}

void loop() {
  // does nothing for now.  this is where you would do something with the stored pulses, print to serial, etc.
}

Thanks, I will try it out

Simple code
int pin = 7;
unsigned long duration;

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

void loop() {
long duration = pulseIn(pin, HIGH);
 Serial.println(duration);
//delay(100);
}

Assuming that you are mentioning a squrewave this code mesures the time that squrewave pulse stays in HIGH and prints out in computer serial monitor.
You should send the signal to digital pin 7 (or put any pin you won't modify code int pin = 7;) 5 V HIGH and 0 V LOW.
The time unit measuring in here is in microseconds.
If you won't to measure low then pulseIn(pin, LOW);
I took the example from Arduino official site you can refer more here
https://www.arduino.cc/reference/en/language/functions/advanced-io/pulsein/
Remember this is the basic example there are other good methods than this...
Analog wave is bit too complex.

That could help, but is there any other way than using a blocking function?


text:
Uno - ESP32 SoftwareSerial communication won't work
I have two boards, Uno and ESP32 and my goal is to send data from the Uno to the ESP. I made a voltage divider so my ESP doesn't get fried and I use the communication only in ONE way, strictly UNO -> ESP32. I use PIN 9 from my UNO to send data and RX2 (16) from my ESP to receive the data. How ever, I get errors and can't make it work.
This is my Uno code:
#include <SoftwareSerial.h>

SoftwareSerial softPort(-1, 9);

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

void loop() {
softPort.print("100");
delay(2000);

}

and my ESP code:
#include <SoftwareSerial.h>

#define RXD2 16
#define TXD2 -1

SoftwareSerial Serial2(RXD2, TXD2); // RX, TX

void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);

}

void loop() {
Serial.println("Data received:");
Serial.println(Serial2.read());
delay(200);

}

I'm getting an error that says

no matching function for call to 'SoftwareSerial::begin(int, int, int, int)'

Um.... why would you use SoftwareSerial on the ESP32 to access the secondary hardware UART?

On the ESP32 you would never use SoftwareSerial except under exceptional circumstances.
The ESP32 has three hardware UARTs that can be mapped to any pin combination on the board.
The general usage is:
HardwareSerial Serial2(1); // Use UART channel 1

void setup() {
    Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}

UARTs are numbered 0-2 where 0 is pre-assigned to the TX/RX (USB connection) pins and is used for debugging and programming.  UARTs 1 and 2 are not normally assigned to anywhere and you can use them as you see fit.

Thank you for the answer sir. One question, in Serial2(1), 1 stands for RX1 and TX1? In my case, where I use RX2 and TX2, do I have to useSerial2(2)? And do I have to change my wiring in order to use HardwareSerial? This is my wiring right now: https://i.imgur.com/KvIZQdx.png @Majenko

No. 1 stands for UART 1. Where you connect it to is up to you. The UARTs don't have any standard pins (except UART 0 for the bootloader). It's only when you call begin() that you tell it which pins to use. Until then it has no pins. RX1 and TX1 are just labels that coincide with the bootloader / debug pins. You could use 1 or 2 in the constructor and it will make no difference - it'll just be using a different UART module inside the chip.

I get it now, thank you once again and sorry for my ignorance :) Lastly, can you please confirm if my wiring is correct and if I can use it for HardwareSerial?

GPIO3 is the default for UART0 RX. That's the bootloader / USB connection on most boards. You should pick something else. Not one of the RTC pins though. Anything between 13 and 33 are good choices.


text:
How to properly put a u8g2 handle in a class
I'm trying to create a small battery powered alarm clock using an Arduino MKRZero and a generic SH1106-controlled, 128x64 pixel oled.
I started out just dumping all code into a single file named Clock.ino. As the code got bigger, I started to split out functionality into separate classes. This went fine for timekeeping and alarms, but when I tried to do the same for the display functionality, I ran into an issue.
Now I wanted to split out my display code into a separate class. The working code before the refactor looks a bit like this:
Clock.ino
//Display stuff
#include <U8x8lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);

void setup(void) {
  u8x8.begin();
}

void print_clock([...]) {
  [...]
  u8x8.setCursor(0,3);
  u8x8.print("23:59:59");
  [...]
}

void loop(void) {
  [...]

  // Main clock
  print_clock(clk.datetime);

  [...]
}

I tried to split it out like this:
Clock.ino
#include "Display.h"

Display disp;

void setup(void) {}

void loop(void) {
  [...]

  // Main clock
  disp.print_clock([...]);

  [...]
}

Display.cpp
#include "Display.h"

Display::Display() {
  this->u8x8.begin();
}

void Display::print_clock([...]) {
  [...]
  this->u8x8.setCursor(0,3);
  this->u8x8.print("23:59:59");
  [...]
}

Display.h
//Display stuff
#include <U8x8lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif

class Display {
  public:
    Display();
    void print_clock([...]);
  private:
    U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
}

That didn't work, gave me a whole list of errors, all similar to these:
  5 In file included from /home/simon/Arduino/libraries/U8g2/src/U8x8lib.h:45:0,
  6                  from sketch/Display.h:9,
  7                  from sketch/Display.cpp:1:
  8 /home/simon/Arduino/libraries/U8g2/src/clib/u8x8.h:323:23: error: expected identifier before numeric c    \>onstant
  9  #define U8X8_PIN_NONE 255
 10                        ^
 11 sketch/Display.h:26:55: note: in expansion of macro 'U8X8_PIN_NONE'
 12      U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
 13                                                        ^~~~~~~~~~~~~
 14 /home/simon/Arduino/libraries/U8g2/src/clib/u8x8.h:323:23: error: expected ',' or '...' before numeric    \> constant
 15  #define U8X8_PIN_NONE 255
 16                        ^
 17 sketch/Display.h:26:55: note: in expansion of macro 'U8X8_PIN_NONE'
 18      U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
 19                                                        ^~~~~~~~~~~~~
 20 sketch/Display.cpp: In constructor 'Display::Display()':
 21 Display.cpp:8:9: error: invalid use of member function 'U8X8_SH1106_128X64_NONAME_HW_I2C Display::u8x8    \>(int)' (did you forget the '()' ?)
 22    this->u8x8.begin();
 23    ~~~~~~^~~~

So I tried rewriting it in such a way that the u8xu var is global like it was before, defining it in Display.cpp and getting rid of the this-> before the u8x8. method calls in the Display:: methods. That didn't work either. It compiles, but my display stays blank and the arduino gets stuck (does not interface with serial anymore until I hard-reset it).
At some point I rewrote the code such that I passes on the variable to the Constructur for Display, but I think I completely botched that as I couldn't get it to compile.
so, main question: how do I instantiate an object inside my class, so it becomes available as a private variable?
If anyone wants to look at the full code, it's right here:
https://github.com/ffective/wake-up/tree/master/Clock
The latest commit is the way of splitting up I described last: using a global variable. The previous commit is the working code with all Display methods just globally in Clock.ino. Unfortunately I didn't save my attempts for putting it as a private variable.

What you got is the method declaration, not member variable definition. The u8x8 is the private method returning U8X8_SH1106_128X64_NONAME_HW_I2C. And it's failing on that constant in parameter list.

First errors aren't much helpful, but the last one about member function explains it all. You are not creating member variable of that type, you are trying to create member function (with invalid parameter list) that returns U8X8_SH1106_128X64_NONAME_HW_I2C value.
This code is perfectly valid:
class Display {
  public:
    Display() { u8x8.begin(); }

    // you can also use different initializer for u8x8 object (default one is never executed in this case):
    Display(uint8_t resetPin) : u8x8{resetPin} { u8x8.begin(); }

  private:
    U8X8_SH1106_128X64_NONAME_HW_I2C u8x8 { U8X8_PIN_NONE };
};

and in the sketch:
// creating instance:
Display disp{ 5 };

// or with default constructor and reset pin value
Display disp2;

You need to create a "blank" object in your class and then instantiate it in your constructor initializer list:
class Display {
    private:
        U8X8_SH1106_128X64_NONAME_HW_I2C u8x8;

    public:
        Display() : u8x8(U8X8_PIN_NONE) {}
        void print_clock([...]);
};

The object in private is not instantiated until the constructor is called by the calling of the Display() constructor.
From then on you can use u8x8.whatever() as you would normally.

Also it's possible to use U8X8_SH1106_128X64_NONAME_HW_I2C u8x8 { U8X8_PIN_NONE }; and he doesn't have to use initializer list in the default constructor. It's important to use {} instead of () here


text:
WS2811 lights only turn red
I've connected a strand of WS2811 to a 5V power supply and an Arduino Uno and no matter what I do the lights are always red. I'm using the fast led library and for some reason, the WS2811 lights are only red.

Please show us the sketch you're using and a schematic of the component connections.

difficult to guess ... you provided no useful information

My guess is that you have too many leds for the 5V supply you are using. Having to many leds on will drawing too much current. This will make the voltage droop. Since red leds will run at a lower voltage, while green and blue won't, only the red leds turn on. To solve this, you could try a smaller section of led strip, or set them to a very low brightness in code.

I had this same issue, turns out I had 12v WS2811's. Changing power supply fixed it for me!


text:
How to convert my Arduino setup to a PIC setup?
I have an arduino setup with LCD, RTC, EEPROM, Reed Switch, AC/DC Buck Converter, 4X4 Keypad.
What PIC IC will let me connect with all these(40 Pins), and yet accept Arduino Code.
I don't want to rewrite the code. I learn Arduino only recently, So shifting to another coding language is near impossible, since am not a coder.

so, you go to an Arduino site to ask how to not use an Arduino? ... go to a Microsoft website and ask how to stop using Microsoft software ... see how they like your question

voting to close because the question is not about an Arduino

There is a pinguino project which allows you to program PIC MCUs on Arduino IDE like an Arduino.

There are also many chipKit-based boards that can be run under the Arduino IDE environment.

I am the head honcho for for current chipkit designs. It sounds like the MAX32 is what you want. Equivalent to the Mega. The uC32 may have enough pins too which is an uno equivalent. You should check them out. All PIC32 based.

@jsotola, I think this question is perfectly acceptable for this site. I support expanding beyond Arduino. Very few of the users here, no doubt, are using genuine Arduino boards which give money to Arduino anyway. The goal isn't to have a pure Arduino site, it's to have a site inspired by Arduino which opens up multiple avenues of creativity and productivity.

And yes, some PIC boards can be programmed like Arduino. Arduino has inspired a lot of progress in the industry as a whole, and literally changed the world of programmable electronics.

@hindisong.cc, Why do you want to use a PIC anyway? What are you seeking?

The PIC32 has full (or nearly full) support for the Arduino API through the chipKIT project.  If you want to use one of the smaller PIC chips (PIC16 / PIC18 etc) then you're out of luck. There just isn't a freely available C++ compiler for those chips, so the Arduino API can never really be ported to them.
I have, in the past, cobbled together an Arduino-style API layer for a handful of selected PIC18s which uses structs to emulate a couple of the Arduino C++ objects, but it only worked in a very basic way with no function overloading for things like Serial.print().
One of the problems from a low-end user's perspective is that the PIC32 only comes in harder to use TQFP and QFN etc packages in anything larger than 28 pins. That means you can't breadboard without a development board. Fortunately there are some breadboard friendly options in the chipKIT ecosystem, such as the Fubarino series of boards. For more pins though you'd be wanting one of the bigger boards, such as the MAX32 which is in a Mega footprint (but with even more pins).
It's important to note though that the PIC32 is a 3.3V device and, owing to physical differences in the way that some of the internals work, there are incompatibilities in some of the libraries and functionality (such as no "LOW" or "CHANGE" interrupt support, only "RISING" and "FALLING").


text:
How do I connect 4 or more Arduinos to a single shared GSM Module?
Is it possible to connect 4 or more Arduinos to a single GSM Module.?
All the Arduinos need to send SMS at a specific time daily.
How do I make sure thet don't time collide with each other, other than sending sms at different times for each Arduino?.
I want the SMS to be queued up, and be sent one by one.

connect the GSM to only one arduino

You should consider connecting one Arduino to the GSM module, and connect the 4 Arduinos together using SPI, I2C, or any other inter-hardware comms protocol. Before I knew these options existed, I once wrote a bit of code to send data between Arduinos by having one pin represent the data being sent and another pin changing every time a new bit was available. You could do something similar with an extra line per pairing, so an Arduino could tell the primary that it had new data to send.
Anyway, check out the "Wire Library" - it's basically for this kind of work. I think you'll be happier trying to have one Arduino "in charge" and connected to the CSM while the rest vie for its attention.

At the risk of arguing with myself, give the SPI library a look-in as well. Depending upon the situation, SPI can be easier to work with. It's the simpler of the two protocols.


text:
I want to connect my NodeMcu v3 to gsm
I have a problem with connecting my NodeMcu to gsm. I have bought GSM module but I have sim code on card which I can't and that is the problem because I've found some libraries but there are no examples how to connect with pin code. I have found one but not compatible with NodeMcu. How can I do It?

put the card in a phone and remove the PIN

It's not possible


text:
Mega 2560 pin output power and control question
I am trying to determine the total pin power requirements for my Mega 2560 project; it will connect to 3 1m Neopixel strips and 5 RGB laser fiberoptic lights, and control them via PWM. Each strip and light will have its own external power supply. The laser lights will be controlled by an Adafruit TLC5947 LED Breakout board with 3 (R,G,B) inputs. Further, each laser light is turned on by a logic high command.
My questions are:
How can I determine the total pin outputs? Can all this be controlled safely from the Mega, or will I need to add transistors? I have read 200mA is the maximum for the Mega, however I have found a seemingly definitive post on Arduino.cc that states 800mA is the maximum.
https://forum.arduino.cc/index.php?topic=327742.0
here's my rough schematic:

Thank you in advance!

Neopixels only need a control signal and Gnd when powered externally - connect the external power supply Gnd to the Mega Gnd as well.
The 2560 chip can definitely work with 800mA (200mA per VCC & Gnd pin, and there are 4 of each). The onboard supply can't cope with that - you get a max of 500mA from USB (due the 500mA PTC fuse, the big gold or green part next to the USB connector), or something under an 1000mA depending on how 5V is created. 12V into the barrel jack and high current will over heat the 5V regulator. 7.5V into the barrel will give you a better shot at high current. Then there is 1V rated reverse polarity protection diode between the barrel jack and the regulator.  You can't put 5V into the barrel and get 5V out, you need to overcome the diode and the regulator. 7.5V wallwarts work well for that. www.dipmicro.com used to carry 7.5V/1A wallwarts, I don't know if they still do.  If you decide to use an external 5V source via the power header, then the power headers are only rated for 1A current as well.
I use this one for 5V projects, 4A to power the Arduino, make yourself a power cord splitter and have 5V for other stuff as well direct from the wallwart, and not off the Mega board.
Are the lasers controlled by current into the R,G,B pins, or are they externally powered and R,G,B are just control signals? If their power comes from RGB, then you'll also want to power the TLC5947 seperately and just connect control signals and Gnd to the Mega.

Thanks Crossroads, this is very helpful. The lasers will be powered externally as well, so R,G,B are just control signals. My confusion was whether or not the pin outs were drawing 40mA if they were just signal, and it seems like the answer is no.
Given that the peripherals are all powered externally, will 5V power work, or should I use 7.5V?


text:
Help with placing a function please
I am trying to call a function that will turn a stepper motor a number of steps depending on the value submitted through the serial console. For an example, if I submit 50, the motor should turn 50 steps clockwise (and counter clockwise for  a negative value).
#include <Stepper.h>
#define STEPS 200
Stepper stepper(STEPS, 8, 9, 10, 11);

int serial_input = Serial.read();

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

void loop() {
}

void turnMotor(serial_input){
  stepper.step ( serial_input ) ;
}

And here are the errors I get:
Motor4.ino:12:28: error: variable or field ‘turnMotor’ declared void
Motor4.ino:12:16: error: ‘serial_input’ was not declared in this scope
Motor4.ino:117:28: error: variable or field ‘turnMotor’ declared void

Thank you

you can't call Serial.read() outside function

I see my error as you explained

As Juraj already explained, you cannot use Serial.read() outside a function.
What you probably want is to call it within the loop, or a function called from loop (via other functions).
Than you can call also turnMotor from Loop or a function called from loop. The value (int serial_input) probably doesn't have to be global anymore, but that depends on the time where you assign the value and where you call turnMotor.


text:
NodeMCU burned, did I something fundamental wrong?
I have a NodeMCU where I connected a LED strip (WS2812b, which operates at 5V).
NodeMCU is powered via USB 5V. The used power adapter can supply 2.5A max.
I don't have a separate power supply for the LED strip yet, so I connected it to VIN/GND of the NodeMCU.
That worked.
Yesterday, I took the NodeMCU (without led strip) to my PC and uploaded an updated sketch.
After that, back in the living room, I connected the NodeMCU with the led strip and the USB power supply.
I didn't need an ambilight at the moment so I left it off.
After 5 minutes, I smelled something burned. As you can see in the second image, the component below ground is burned.
I had this setup successful running for a week (with ambilight turned on for several hours) and had no issues at all.
Did I something fundamental wrong?
Any guess, why it works flawless and then suddenly burned after just 5minutes?
Any tip/suggestion is very appreciated!

The white component on the right is a DHT22 temperature sensor and has been added for completeness.

The resistor and LED on the right are not used, they were just plugged in from a previous setup.
Best regards
Casper

Yes, you did something fundamentally wrong.
The component that blew up is a diode.  It is designed to protect the USB from voltage being injected into the board.
That diode can handle an absolute maximum of 1A.
Any fault on your LED strip connection (a short to ground) will cause that diode to vacate the premises. As yours did.
The purpose of the VIN pin (as the label suggests) is as a voltage input. It's not really designed to provide power to other devices, especially as the ESP8266 itself can take more than half that 1A power budget when communicating.  You should not use VIN for powering anything more than maybe a couple of low power sensors. LED strips are a big no-no.

Something happened to me yesterday.  I had made sure that the diode & regulator could handle the stress of 14 V ( this unit is installed  in a voat).
The diode blew as soon as the ignition was turned on.  However I noticed that the 10 uF. capacitor was still smoldering away.   That should not have happened.
I removed both faulty components & tested the board.  All OK!
Replaced the diode and the capacitor with a 10uF/20VW diode and the board works fine with 14.4 V input (when battery is charging).
So, I reckon the prpblem is that the capacitor has insufficient voltage rating(6V?) and goes short circuit.  The schotky diode will try and pass AMPS and it fails.
Solution replace the 10uF de-coupling capacitors with capacitors of known rating.
There is no real way of knowing what rating capacitors were used in the manufacture.
Lee


text:
Uploading doesn't work on MKR1000
I received the error bellow when I tried to upload any sketch on my MKR100. I uninstall/reinstall de COM drivers and the arduino IDE and nothing solve the problem. I bought another MKR1000 thinking the ahrdare was the problem , but I got the same errors.
Also If I try to open the serial monitor I got :
Error opening serial port 'ÇOM12'(Port not found)
Can someone help me?
Sketch uses 47444 bytes (18%) of program storage space. Maximum is 262144 bytes.
Forcing reset using 1200bps open/close on port COM12
processing.app.debug.RunnerException
at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:152)
at cc.arduino.UploaderUtils.upload(UploaderUtils.java:77)
at processing.app.SketchController.upload(SketchController.java:732)
at processing.app.SketchController.exportApplet(SketchController.java:703)
at processing.app.Editor$UploadHandler.run(Editor.java:2055)
at java.lang.Thread.run(Thread.java:748)
Caused by: processing.app.SerialException: Error touching serial port 'COM12'.
at processing.app.Serial.touchForCDCReset(Serial.java:107)
at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:136)
... 5 more
Caused by: jssc.SerialPortException: Port name - COM12; Method name - openPort(); Exception type - Port not found.
at jssc.SerialPort.openPort(SerialPort.java:167)
at processing.app.Serial.touchForCDCReset(Serial.java:101)
... 6 more

did you select the correct port?

Thank for you answer. No, the IDE can find the board and port but I got those errs anyway.

read the answer, not the question. did you try the double reset mentioned in the answer?

I'm sorry my mistake, I tried the double tap on reset button and it works!!. Thanks for your help.


text:
Data Fluctuation with AJ-SR04M Sensor
I'm working on water level detector using lolin nodemcu v3 and AJ-SR04M Sensor, a water proof ultrasonic sensor. It is working fine at close distance less than one meter or so. However for long distance > 1 meter, I get varying results.

Using the following code:
void setup() {

  Serial.begin (115200);
  pinMode(TRIGGER, OUTPUT);
  pinMode(ECHO, INPUT);
  pinMode(BUILTIN_LED, OUTPUT);
}

void loop() {

  long duration, distance;
  digitalWrite(TRIGGER, LOW);
  delayMicroseconds(2);

  digitalWrite(TRIGGER, HIGH);
  delayMicroseconds(10);

  digitalWrite(TRIGGER, LOW);
  duration = pulseIn(ECHO, HIGH);
  distance= duration*0.034/2;

  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  delay(1000);
}

This is what I get in the monitor for the same distance 2-3 meters:
Distance: 141 cm
Distance: 135 cm
Distance: 225 cm
Distance: 195 cm
Distance: 226 cm
Distance: 226 cm
Distance: 129 cm
Distance: 135 cm
Distance: 134 cm
Distance: 146 cm
Distance: 136 cm
Distance: 129 cm
Distance: 154 cm
Distance: 123 cm
Distance: 147 cm
Distance: 226 cm
Distance: 181 cm
Distance: 137 cm
Distance: 134 cm
Distance: 136 cm
Distance: 137 cm
Distance: 145 cm
Distance: 227 cm
Distance: 179 cm
Distance: 226 cm
Distance: 226 cm
Distance: 101 cm
Distance: 134 cm
Distance: 270 cm
Distance: 294 cm
Distance: 266 cm
Distance: 281 cm
Distance: 146 cm
Distance: 279 cm
Distance: 128 cm
Distance: 579 cm
Distance: 138 cm

So, is there a way to make it right or that means my sensor is faulty.

try to put 4K7 resistance at triger pin to gnd

Outstanding! The 4k7 resistor works!

This sensor does not work on 3.3v but on 5V. Connect the red wire to Vin (=USB power = 5v)


text:
XH-M131 Photoresistor Relay Module NC position
I have purchased XH-M131 Photoresistor Relay Module to automatically light my outdoor yard at sunset and turn it off at sunrise. I'ts working as it is supposed to, However, if I power off the relay, the light goes off.
I want this to be a closed circuit in such way if the relay malfunction or loose power, the outdoor light stays on which I can manually switch off if I want to.
BTW, I tried connecting the light wires to the otherside, but the whole thing reversed, light goes on when light detected which defies the purpose. Any suggestion or modifications.

It is correct to connect the light wires to the other side (aka normally closed / NC), but then of course you also need to invert your program logic (turning the light off by activating the relay, turning it on by deactivating the relay). Have you tried that?

@chrisl the relay is self controlled by Light Dependent Resistor. Is there a way to reprogram it or reverse the trigger mechanism?

Oh, then only if you analyse the used circuit on that module and hack it. But where is the Arduino in your setup? If there is no Arduino, you are at the wrong site. This is Arduino SE

If you put an additional relay (Relay B) between the XH-M131 and the light and connect the light to the mains via the Normally Closed pole of Relay B, the light will be ON unless Relay B is activated or you turn off the light switch.
Then, connect the coil of Relay B (instead of the light) to the "other side" as you say, of the XH-M131, the logic will be such that when the sensor is exposed to light (daytime) the XH-M131 turns on. That will activate Relay B, switching it from Closed to Open and turn the light OFF.
If the XH-M131 fails, the light will be ON.


text:
Unstable analog results
I have a rock solid voltage on my analog input with ADC values jumping around by about 15% on the Serial monitor and LCD display
Never had anything like this before
Seeeduino V4.2
pinMode(A1, INPUT_PULLUP);
volt = analogRead(A1)
Am I the proud owner of a faulty board? ( wish I had a spare one to test )
regards
Wilfried

INPUT_PULLUP? explain. and how do you measure "rock solid"?

I think INPUT_PULLUP doesn't do anything here. Analogread does all necessary pin configuration. Have you measured the input voltage with an oscilloscope?

Probably not related but you should probably not use INPUT_PULLUP mode when you want to read an analog input. Just use INPUT mode. `INPUT_PULLUP mode internally connects the pin to +5V through a resistor, which is going to throw off your voltage readings.

I have seen this many times in the past on many different families/brands of microcontrollers.  A/D systems are extremely sensitive to electrical noise especially on the AREF pin.  Check the loading on your 5V supply, that, I believe is the source for AREF. Inductive loads are notorious for injection of electrical noise into an analog sub system. If you are powering any loads from the 5V supply eliminate them one by one and see if you get a solution. I have seen LEDs cause this problem especially with PWM.


text:
Multiple readings from one change on a light sensor with interrupts
I was trying to make a code which did something every time a light dependent resistor was covered up by using interrupts so I could be running a different code at the same time.
This was my finalised code:
#define LIGHT 2

void setup() {
    Serial.begin(9600);
    pinMode(LIGHT, INPUT);
    attachInterrupt(digitalPinToInterrupt(LIGHT), fall, FALLING);
}

void loop() {
    Serial.print("Hello");
    Serial.println();
    delay(1000);
}

void fall(){
    Serial.print("Light Covered!");
    Serial.println();
}

I have tested my ldr circuit (5V into the ldr with a 10k pulldown resistor) and it reliably sits over the digital read boundary so I don't need to use analog read. It also seems to have no bounce as if I read it by outputting a message every time it reads it as high and then waiting until it goes low it only reads once every time I cover it and uncover it. However for some reason the code above which uses interrupts seems to print light covered 3-7 times every time I cover it. I am quite new to arduinos and C although I have used python for a while so sorry if it is a silly noob mistake.

Don't use an interrupt. The arduino environment is not the same as an embedded system. Interrupts can often be avoided. Read the analog value in the loop. Add hysteresis. Do you want to detect a certain fixed value or a change in the value?

do minimum amount of work inside an ISR  ...... raise a flag only ...... print the message inside the loop() block whenever the flag is raised

@Jot I want to detect when the signal gets below a certain bound and the reason I want to use an interrupt is because then I can be monitoring serial while also detecting and doing something every time the signal falls

@jsotola But surely then the code inside the loop() still has to be checking to see if the flag has been raised so if it is doing something like continually checking serial it would not check it as often if it is checking the flag

i think that you have a misconception about how fast the arduino operates

@jsotola possibly as I'm used to python which is slow. If I was trying to pick up serial signals to tell it to send data back would it still be fast enough to do the monitoring inside loop()

basically, do not use any print statements or wait statements inside the ISR ................ do not use delay() in loop() either ........ refer to BlinkWithoutDelay example sketch that is included  in the Arduino IDE

I think, when you didn't use interrupts you achieved enough debouncing with the duration of your main loop. When using interrupts you might have to debounce the resistor yourself. Bit you have to do this in the loop, just raise a flag in the isr


text:
nRF24L01+ Unable to set address
I'm trying to communicate between Arduino Nano and Arduino Uno using nRF24L01+.
I tried using RF24 by ManiacBug and TMRH20, but when I open the serial monitor after uploading the Example Programs Getting Started from ManiacBug and pingpair Program from TMRH20, it does not change its address.
The addresses for reading and writing I'm using are 0xF0F0F0F0E1LL and 0xF0F0F0F0D2LL, but the response I'm receiving is as follows:

I check all the connection and tried different examples available on the internet, but nothing worked at all.

You can set addresses using SPI commands.  For example a 5-byte transmitter address could be written as (MSB first):
  digitalWrite(CSN_pin, LOW);
  SPI.transfer(0x30); // write TX_ADDR register
  SPI.transfer(tx_addr[0]);
  SPI.transfer(tx_addr[1]);
  SPI.transfer(tx_addr[2]);
  SPI.transfer(tx_addr[3]);
  SPI.transfer(tx_addr[4]);
  digitalWrite(CSN_pin, HIGH);

where tx_addr is an array of 5 bytes.  Similarly you can write to the RX_ADDR registers, see the nRF24L01+ datasheet, section 9 for the register map.
Furthermore, the following code allows you to read the TX_ADDR register:
  digitalWrite(CSN_pin, LOW);
  SPI.transfer(0x10); // read TX_ADDR register
  data_out[0] = SPI.transfer(0x0);
  data_out[1] = SPI.transfer(0x0);
  data_out[2] = SPI.transfer(0x0);
  data_out[3] = SPI.transfer(0x0);
  data_out[4] = SPI.transfer(0x0);
  digitalWrite(CSN_pin, HIGH);

  Serial.print("TX_ADDR=");
  Serial.print(data_out[0]);
  Serial.print(data_out[1]);
  Serial.print(data_out[2]);
  Serial.print(data_out[3]);
  Serial.println(data_out[4]);

@MichaeIT I tried this solution, but no luck. I've gone through  https://github.com/nRF24/RF24/issues/211 thread, but still no luck.

Try writing and reading, as suggested in the above example.  If this does not work, then there is some problem with the SPI.

I tried this, and getting the response 00000. SPI of arduino is problem or nRF? As I tried different nRF and Arduino.

@MichaeIT I am successful in making it work on Arduino Uno by connecting MISO, MOSI and SCK pins directly to the ICSP header pins, but not successful in Arduino Nano.