text:
HC-05 bluetooth module not accepting AT commands
I have been attempting to program my HC-05 ZS-040 Bluetooth module for quite some time, and I cannot get the AT commands to return any values. I have searched google for quite some time, and I none of the answers seem to work for me. I have been following along with this website:
https://sites.google.com/site/wayneholder/inexpensively-program-your-arduino-via-bluetooth
I am using an Arduino Mega 2560 clone by Elegoo to program this Bluetooth module. Currently I have it wired up using this diagram
https://sites.google.com/site/wayneholder/inexpensively-program-your-arduino-via-bluetooth/HC-05-to-FTDI.png?attredirects=0
Currently I have it modified slightly to use a voltage divider between the Arduino's Tx and the HC-05 Rx, as the HC-05 works on 3.3v logic. The one possibility I think could be causing this problem is that the Arduino Mega is just interpreting all Tx incorrectly as I measured that it sounds ardoun 3.2 volts for a high voltage. According to multiple websites the HC-05 is in AT command mode when the LED flashes slowly, about once every 2 seconds, which is happening. I put it in command mode by holding down the button above the EN pin while providing power to the HC-05.
I have been using pin 14 and 15, which are Hardware Serial3 on the Arduino Mega. Here is the code I have written:
  /*
  Software serial multple serial test

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.
 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(15, 14); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("AT");
  // set the data rate for the SoftwareSerial port
  Serial3.begin(38400);
}

void loop() { // run over and over
  if (Serial3.available()) {
    Serial.write(Serial3.read());
  }
  if (Serial.available()) {
    Serial3.write(Serial.read());
  }
}

Any suggestions are much appreciated!
EDIT:
I have now received some unrecognizable responses from the controller after sending AT multiple times, here is the screenshot, included is a video of my circuit, which shows how the LED is flashing:
https://drive.google.com/open?id=1mc8PEEnhiKpPzzy5kL9QxTvoQA3NAH6b
The only modification to the code is adding a Serial.println("TESTING"); in the while loop that reads Serial3. I have tried using other Hardware serial ports as well, all with the same result as the above screenshot.

I looked more closely at your code and I believe I see the problem now.  I'll add the additional info in my answer, but did you notice that you set up the mySerial object, but you don't actually reference it in the code?  Your mySerial is analogous to my BTSerial object.  I'll write your code as it should be in my answer so you can copy it and try it.

Thanks for all the help! I had given up on getting Bluetooth module to work, however when working with a simple RGB LED, I noticed my mistake. I was using the ground from my breadboard power supply for the module instead of the ground from the Arduino Mega. I rewired my breadboard so the ground and power come from my Arduino Mega, and everything works perfectly! I ended up using the exact same code that I posted in my original question, so it was just that I was not using the ground from my Arduino Mega

###### Try This : Your Code Updated With Possible Fixes  ######
After examining your code and comparing it to my working code I believe I have found a definitive answer.  I'm altering your code so you can copy it and try it.  I'll add comments where I've changed it.
#include <SoftwareSerial.h>

SoftwareSerial mySerial(15, 14); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.println("Enter AT commands:"); // a prompt in Serial Monitor
  // Deleted while loop, unnecessary

  // set the data rate for the SoftwareSerial port
  // notice that your comment on previous line says SoftwareSerial port
  // but you are setting the Serial3 port -- this is where we use mySerial
  // Serial3.begin(38400); // commented your line of code
  mySerial.begin(38400);
}

void loop() { // run over and over
  //if (Serial3.available()) { // we don't use Serial3 any more
  if (mySerial.available()) {
    //Serial.write(Serial3.read());
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    //Serial3.write(Serial.read());
    mySerial.write(Serial.read());
  }
}

I am confident that if you use this newly modified code it will solve your problem.  I should've noticed this earlier.
Here's the rest of my original answer.
I have struggled with this myself.  As a matter of fact it took me a few months of owning some HC-05s before I finally dug up an answer.  It's been a while since I worked with it so I'll do my best to explain what to do.
Arduino Nano
Also, I use an Arduino Nano to do the programming of the HC-05.
This Setup Lets You Alter HC-05
Once you wire it up and run the program (included here) you will be able to send any of the HC-05 commands and they work great.  You can change the name of the device, the 4-digit pass-code and everything.
Crude Snapshot, But Enough To Build Simple Circuit
I also have a crude snapshot* of the circuit I used (at the time just for documenting it for my own memory) but I think we can work you thru it.  and I know those wires are all crammed together and it almost looks like they are in the same breadboardholes but they are actually hooked up properly.  I was so excited it finally worked I snapped the pic too fast.
*see image below
Here's the code I use:
#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup()
{
  //pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  //digitalWrite(9, HIGH);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
}

void loop()
{

  // Keep reading from HC-05 and send to Arduino Serial Monitor

  if (BTSerial.available())
    {
     //Serial.println("bt available...");
    Serial.write(BTSerial.read());
    }

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available())
    BTSerial.write(Serial.read());
}

Does Your HC-05 Have the Button?
Okay, so the first thing is to check to see if your HC-05 has the little button on it?  If it does that has to be held when you apply power to the circuit.  The HC-05 will blink and then it will be in COMMAND mode and you can let go.
If No Button
You can see that mine has the button.  That is why the first two lines the setup() method are commented out.  I don't need D9 to go high (it is not connected to the pin) because mine has the button. If yours has the button (most likely does) then you don't even have to worry about it.
Looking Back At Your Question
Now that I look back at your sample code it could be that you're not aware that you have to hold that button when you power up.  Or you don't know that you need to connect that wire to keep the HC-05 in command mode.
Pins For TX / RX
That's probably the problem you are having, because everything else looks the same -- except you are using 15 and 14 for TX / RX.  I am using D10 and D11 for mine and I remember something about those pins in the back of my mind so if yours still doesn't work, try switching to those and try using my code.
I remember the first time I finally got this working and I was dancing around the room. Good luck and I hope you are dancing soon.  :)

Thanks for the response! I tried your suggestion to use pins 10 and 11 however I got no response. I have been pressing down the button while applying power, and the indicator LED is one for two seconds, then off for two seconds. However when using the Hardware serial ports on my Mega 2560, I get responses now in the serial monitor, and managed to change the name of the HC-05, but the responses are still unreadable. Could it be that the HC-05 high (3.3v) is not enough for the Arduino Mega to interpret as a high value, thus sometimes the response appears okay and other times it doesn't?

@JustinVanderBerg  I think that is a good guess, but I'm not sure about it because I don't have experience with Mega.  It may be worth it to you to buy this pack of 3 Nanos https://amzn.to/2MOfHYE ($12.68USD) at Amazon and use one of them to program your HC-05.  Sorry i couldn't be more help with this. Like I said, I struggled with it for a few months trying off and on to resolve it.

@JustinVanderBerg I was thinking about this again and if you are getting garbled text that often means the speed does not match. I noticed yesterday that even though my Arduino was writing to serial port at 9600 (via setting in software) I actually had to set the Arduino IDE Serial Monitor to 19200 to get valid output.  My point is, have you tried setting the speed to different values in the Serial Monitor?  It may be that the HC-05 is defaulting to 9600 -- which is the default for regular data send mode.  It may be worth a try.


text:
DHT11 Reading Too High Values
When I run the program, there are no syntax errors or anything. All it does is give me values for the temperature in the hundreds. I don't know if there is a way to turn these abstract and unexpected values into the actual temperature.
I originally expected that it would print out the temperature around 20 Celsius, but instead, it prints around 600. This is my code:
#include <Adafruit_Sensor.h>
#include "DHT.h"

int sensor_pin = A0; // Analog Pin sensor is connected to
int output_value ;

void setup(){

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

}//end "setup()"

void loop(){
  //Start of Program

    output_value= analogRead(sensor_pin);

    Serial.println("temperature = ");
    Serial.println(output_value);
    Serial.println("*C");
    if (output_value < 60) {
    Serial.println("Increase temperature by ");
    Serial.println(output_value);
    Serial.println("*C");
} else {
    Serial.println("Temperature does not need to be increased.");
}

    delay(5000);

}// end loop()

My bad, I did not include my code. Here it is:

What should I do?

I changed that, but what should I do now

anyway, back to your problem .......... you  are not printing the temperature ..... you are printing the value that relates to the voltage at the input pin ....... the voltage goes from 0V to 3.3V (or 0V to 5V depending on the model of Arduino) ..... the reading of 0 equals 0V and maximum reading is equal to 3.3V(5V) ...... you have to refer to the sensor data sheet to determine how the reading relates to the temperature

I am giving the dht11 3.3V but I don't know how to find the sensor data sheet

if we only had a way to access vast amounts of information ..... we could find data sheets and tutorials .... hmmmm .... i wonder .......... lol ......... sorry, i could not help it

@StrawberryMilk you have a arduino uno? I'm not sure which temperature sensor you have. Can you give a link to it, or a photo?

The DHT11 is a digital device. You cannot read from it with analogRead().
While temperature is an analog value, that's not how the DHT11 communicates with an Arduino. There is a specific digital protocol.
In your code, it appears you have added the headers for the Adafruit Sensor library and DHT library, but you never actually call the functions provided therein.
The Adafruit repository for the DHT sensor library has an example:
https://github.com/adafruit/DHT-sensor-library/blob/master/examples/DHTtester/DHTtester.ino
You can see how to create an object from the DHT class, and how to call it's member functions, such as readTemperature() and so on.

source: Stack Exchange

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

sort: votes


text:
RS485 Wrong Results in Serial Monitor(Controllino) - Right Results with Logic Analyzer
After searching the internet and trying different examples, I always get the same wrong response in the serial monitor.
Picture 1 shows the wrong results. At first i thought it was decimal and I just had to convert it to ASCII. But that wasn't the problem.
Picture 2 shows the results that I expect. It's from the Logic Analyzer that sits on a breadbord to "sniff" the communication.
I expect N+0000.0\r
Picture 3 shows the settings or the logic analyzer. Please ignore the "SPI MISO" it's just an old description.
I have no other approach left in my mind.
I would appreciate any hint. :) Thank you in advance.
You will find the Arduino sketch below the pictures.

#include <SPI.h>
#include <Controllino.h>  /* Usage of CONTROLLINO library allows you to use CONTROLLINO_xx aliases in your sketch. */

const int numBytes = 20;
int incomingBytes[numBytes];   // for incoming serial data

void setup() {

  /* Initialize serial port for debug messages. */
  Serial.begin(9600);

  /* Initialize CONTROLLINO RS485 direction control DE/RE pins and Serial3 */
Serial3.begin(9600,SERIAL_8N2); //Initialisierung Serial Controllino(RS 485)
  //Beim Mega oder Maxi Zugang zum /OVL pin und RS458 /RE DE Pins
  //Zuweisung /RE (PJ5) DE (PJ6) pins als Ausgang (1). Für /OLV (PE7) als Eingang (0)
  DDRJ |= B01100000;
  DDRE &= B01111111;

  //Controllino_RS485Init(9600);
  //Controllino_RS485RxEnable();

  Serial.println("Recieving RS485...");
}

void loop() {

DatenEmpfangen();
delay(1000);
DatenAnzeigen();
}

void DatenEmpfangen()
{
  static byte ndx = 0;
  int rc;
  PORTJ &= B10011111;//Empfangen MODUS
  //Controllino_RS485RxEnable();
  delay(1000);
  do
  {
    if (Serial3.available() > 0)
    {
     // digitalWrite(CONTROLLINO_D1, HIGH);
     rc = Serial3.read();

     incomingBytes[ndx] = rc;
     ndx++;
    }
  } while (Serial3.available() > 0);
}

void DatenAnzeigen()
{
  static byte count = 0;
  //int Xor = 0;
  //Xor = receivedIntegersA[0];
  Serial.println("Daten");
  for (count=0;count<9;count++)
  {
    Serial.println((incomingBytes[count]));
  }

}

first chage type of incomingBytes to byte (for printing). use println(incomingBytes [count] , HEX)

https://majenko.co.uk/blog/reading-serial-arduino

@ Juraj - that doesn't work. The Hex Values are completely different compared to the correct output of the logic analyzer.

@Majenko - i don't get any output at all. I uploaded the sketch here: https://github.com/AndreasNRW/WS_RS485

@Majenko - i'm sorry, your linked example works great. The terminating character in my case was \r not \n. Very nice blog post. Thanks a lot.

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


text:
Seeeduino V3.0 (Atmega 328P) and Rotary Angle Sensor Mystery Message
I am attempting to do a simple example with the Rotary Angle Sensor.
Here is my development environment:

Visual Studio 2013 Premium
Arduino Debug Tool

Board setup (Simple as can be single analog input):

Code:
const int ROTARYSENSOR = A0;

void setup()
{
    Serial.println("Setup Start...");
    Serial.begin(9600); //Set the serial communication frequency at 9600 bits per second

    pinMode(ROTARYSENSOR, INPUT);

    Serial.println("Setup End!");
}

void loop()
{
    Serial.println("Loop Start...");

    int value = analogRead(ROTARYSENSOR);
    Serial.println(value); //display on serial monitor
    delay(1000); //wait 1000ms before printing next value

    Serial.println("Loop End!");
}

Issue:
I have a single solution with multiple projects as my sensor playground. All other projects I have so far work flawlessly no issues.  Although with this project (RotaryAngleSensor) I am getting a strange message.
I am not seeing any of the Serial.println() messages. What is printed to the screen after a good 30 seconds is S?
Does anyone know what could be returning this S? to the standard output?

Did you not post all your code? The setup() function is only called once, at the very start of the program running. It's possible you're just missing them.

Also, to be precise, your "rotary angle sensor" is actually called a potentiometer.

Yeah I lost some code somehow, when I was editing. I will update it. Also yeah I know what it's called, I was just using the name that was on the container box. :p

One problem is that you try to generate serial output before you initiate Serial.  This could have odd results beyond just making that message fail.
Serial.println("Setup Start...");
Serial.begin(9600);

Should be
Serial.begin(9600);
Serial.println("Setup Start...");

And of course your posted code never reads the sensor...

It does, I must have lost the loop method when I reedited my question. Thanks.

So I flipped it around like suggested still didn't work. But when I remove the Serial.begin(9600); all together it works just fine, but just starts at 0.
Suggestions?

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


text:
How can the Arduino Uno support up to 12 servos if it only has 6 digital PWM pins?
According to this:

The Servo library supports up to 12 motors on most Arduino boards and
  48 on the Arduino Mega. On boards other than the Mega, use of the
  library disables analogWrite() (PWM) functionality on pins 9 and 10,
  whether or not there is a Servo on those pins. On the Mega, up to 12
  servos can be used without interfering with PWM functionality; use of
  12 to 23 motors will disable PWM on pins 11 and 12.

However, according to this:

Digital I/O Pins 14 (of which 6 provide PWM output)

So how can the Uno control more than 6 servos if it only has 6 digital I/O pins that can provide PWM output?

Although I haven't looked at the source myself, in these types of situations they usually use interrupt timer 1, which in PWM mode would have been associated with pins 9 and 10. This would explain why you can't use pulse width modulation on those pins. In fact, you can use any of the three timers for PWM on any digital pin, although it's not as good as the built in PWM options.

(source: bansky.net)

(Source)
The above image accurately describes how the signals are sent to the servo motor. Such a waveform is similar to a standard PWM. The servo library can translate a degree to a waveform that the servo's IC will be able to use to adjust the motor's position with it's motor and potentiometer.

So it essentially simulates PWM? What is the point of the digital pins with PWM channels then?

@user1265 More or less... it's using the timers that drive PWM. As far as the point of PWM, IIRC the ATmega328 has circuitry to make PWM more efficient.

@user1265, hardware PWM is "free", i.e. it does not affect the performance of the rest of your program at all (it just ties up a timer, or at least part thereof). Servicing interrupt routines for emulated PWM is comparatively costly. However, in this case, the PWM frequency is only about 50Hz, so this is not overly tragic (Standard Arduino PWM frequency is 31/62kHz, doing PWM for e.g. lighting applications at 50Hz would probably be rather flickery).

What is the point of the digital pins with PWM channels then? - you can get much higher frequencies (up to 8 MHz) and very precise duty cycles. This isn't possible when you are relying upon an interrupt to do this for you.

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


text:
Interfacing Arduino through USB or I2C?
I am planning to connect multiple Arduinos to my Raspberry Pi. There are basically two ways I can achieve that:

Use an USB hub. Each Arduino will then be available through ordinary serial commands both for reading and writing. The USB hub I have is powered and can handle both communications and powering the Arduinos.
Use I2C, so that the Arduinos are I2C slaves of the Raspberry Pi.

Since USB is used for updating the Arduino, I don't have the best feeling about using this same connection for "management" tasks.
Are there any known disadvantages to using the pre built USB socket on
the Arduino in "production", any best practises or similar saying that I should not do
this? Is this USB socket meant to be used for debugging and code deployment only?
The plan is to let the computer send commands to the Arduinos using a serial protocol. The computer will automatically detect whenever an Arduino is connected and immediately send a "hello" command over serial. The Arduino is then supposed to send back its "name" and a list of capability keywords. A capability may be "motion-sensor". The computer will then know that it can ask the Arduino if it has detected motion. Other capabilities may be "temperature-sensor", "barometric-sensor", "lights".
It's for a generic open source home automation system/robotics system I am working on creating a framework for.

Personally, I'd look at using a bused asynchronous serial scheme, a bit like RS485 but perhaps without the differential drivers/receivers if the distances are short, since you can software tri-state the ATMega's serial output pin. If you either use soft serial or bare ATmegas without the USB interface chips (or pull the series resistors to isolate them), this means the only hardware you need is a piece of wire - no hubs, no muxes, etc. Actually, this would work best with Leonardo's where you have the USB interface for programming and the hardware serial free for coms.

One complication you should be aware of is that in its default configuration, an Arduino Uno (and I assume that is what you’re talking about) will automatically reset whenever a serial connection is opened to it. This is easily bypassed with a capacitor between RESET and GND, but not taking it into account might make for hours of debugging fun.
The other complication is that just after a power up or RESET, an Arduino will delay for a second or two to listen for a programmer connection on the serial port, but that’s something you’ll have to take into account anyway.

I would go with USB rather than I2C for these reasons:

The Arduino can be powered via USB so there is no need for extra power supplies.
The system will work with PCs, making it easier to develop the code and the product more versatile.
USB cables are commercially available with standardised sockets. I2C cables would have to be made to specification (e.g. this app note) and would require some kind of additional socket for robust termination.
The Arduino Wire (I2C) library will hang if you disconnect the cable in the middle of waiting for a byte.

A good product will be robust and easy to use. One thing you may wish to consider is to create an internet of thing (IoT) type system. This involves the Arduinos sending sensor data to the web via the RPi. It could be that the RPi is a dumb conduit for the Arduinos, or it could collate the data and present itself as the end device. Check out Xively for details. I made a basic system to do the former, it is on github here.

The plan is to make a web app framework so whenever you hook something into a computer and that computer is running this software, the arduinos will add them self to the UI.

In my opinion, think USB on the Arduino is stable enough for production use.* There are ways to rename your Arduino if someone would connect it to a computer.
I think the real problem with this approach is people tampering with it. I know it's open source and all, but do you really want users (if it does get produced on a big scale, which is unlikely, but possible) without much tech knowledge plugging it into their computer?
If none of that sounds like a problem to you (and the delay/reset problems outlined by others isn't a big deal), I'd say go for USB. It's pretty easy to use, and it's universal, thus someone could connect the system to their computer if you developed the software for PC.
*Assuming you're using a full Arduino in a production environment, you won't care about if it shows up to the computer as "Arduino Uno."

This is an open source project so being open for tampering is no problem whatsoever. I want people to take the framework and make their own stuff.


text:
How can i increase the range of values that a light sensor gives?
I have constructed 2 ceptometers that measure light intensity. Each ceptometer consists of 50 photodiodes that are connected to 2 copper wires (+ and - of the photodiodes are on the same orientation). Those wires are soldered with cable (+ to the copper wire where the positive side of the photodiodes is and the ground wire soldered to the copper wire where the negative side of the photodiodes is). Then, pins were soldered to the cables so as to can be connected to the breadboard.
The paper where the protocol for the construction is present, states that a 1.5 ohms resistor needs to be connected to the copper wires so as to enhance the range of the signal that the ceptometers will give. However, it mentions that this step can be followed later and the resistor can be connected to the wires (that is something that makes sense). I need to mention that one more ceptometer is present that was constructed by another person the previous year and it has the 1.5 ohms resistor soldered on the copper wire. It is something very important to keep in mind for the rest of the text!
I decided to use an arduino uno for my experiment and I connected the 3 ceptometeres (the old from the previous year and the 2 that were constructed by me) to a breadboard. Firstly, I applied light to the ceptometers with a projector and I tried different resistors from 470R to 5K but the values I got were the same. I thought that a kind of signal disturbance or noise may has been caused and I made 3 opAmp circuits in 3 different breadboards. When the breadboards were connected to the Arduino I tried the same resistors again but the values I got were the same. For the old ceptometer that has the 1.5 ohms resistor soldered to the copper wires the change of resistors altered a lot the signal and it gave a wide range of values. Here I have to say that when I applied to the 1.5 ohms resistor to the new captometers I got a pure 0 as a value. And it was the same when I placed them under sunlight.
When I converted the output of the Arduino to voltage signal by multiplying it with 5 and then divide it with 1023 I had the same voltage signal as when I measured it with the multimeter. And it was the same under both artificial and sun light. So, I can imagine that it is something that depends on the resistor that is not applied to the copper wires. I mean that maybe this is the case that I do not get a wide range of values like the old ceptometer but only 20 units
My question is: Do you know any way to enhance the range of the output or do you have any recommendation? Thank you a lot in advance!
With kind regards,
Dimitrios

Can you amend your question to include a copy of your schematic? A sketch would do if necessary. It is hard to visualise a circuit which is done purely by description in words.

A schematic would really help. Have you been able to confirm the voltage output range of your setup outside of the Arduino, by measuring them with a multimeter for example?

Hi Nick and StarCat. Yes StarCat I measured the voltage with a multimeter and it was the same that the Arduino gave me after the conversion of the Arduino output to volts. For example, when I got a value of  90 (from the Arduino) and then did the conversion ((90*5)/1023) what I got was 0.44 that was the same that the multimeter show in voltage. But when I did the calibration with a quantum sensor the value of 90 corresponded to 600 to 690 μmols.

This is something that will affect my experiment since 100 μmols of PAR is an important range but from the arduino it is described as one value.

I have uploaded the schematic on my question. Thank you a lot both of you!

The circuit is a current-to-voltage converter.  The - input to the op-amp is held at 0 (the voltage at the + input, since it is grounded) so there will be no voltage across the diodes.  The current drawn by the diodes is supplied by the op-amp output through the feedback resistor, so the larger that value, the greater the output voltage will be at any given current.  The short answer is that to increase the output voltage, you need to increase the feedback resistor. (7 ohms seems pretty small to me, unless your diodes draw a LOT of current.)
The other complicating issue is that this circuit depends on the op-amp having a low input offset voltage, since its value (~2 mV for the LM358) causes output errors.  Normally a low-offset-voltage op-amp would be used here, but maybe the use of so many diodes makes a large enough current to swamp the offset error.  If increasing the feedback R doesn't help, you might try a different op-amp (even another LM358) in case the offset of the one you have is trying to force a negative output and that's why you see 0.
Edit 11-8-20:  I looked up the sensor used in the PAR-BAR article that seems to be the source of your circuit.  It pulls about 10 microamps at 1000 lux, so 50 of them would give 500 microamps.  If you want to get (say) a 5V output at 1000 lux, you'd need a feedback resistor of 5/0.0005 = 10 kOhms.  That's without the 1.5 ohm shunt.  Also, are you applying your test illumination evenly over all 50 sensors?  The above calculation assumes that all get 1000 lux.
If you have a single sensor available, I'd recommend breadboarding with just that and a 500 kOhm feedback resistor, and no shunt.  That way there will be no issue about equal illumination.  If you still have problems, and you are committed to the LM358 for some reason, try using a simple circuit to compensate for input offset.  These typically involve a potentiometer (could be a trimmer in the final unit) that adjusts a very small voltage applied to the + input.  In your tests you may find that it needs to be negative, which you would have to apply from some external source (since there is no - supply on the Arduino).  If that's needed to resolve your problem, consider a better op-amp or a different circuit configuration.
Edit 11-9-20: Had another look at the PAR-bar article and noticed that they are measuring differential voltage across the photodiode array, which is not the same as your current-to-voltage converter (although that is indeed typical of photodiode circuits).  The voltages that they get are 30 mV or less.  I suggest you get a DMM and measure the voltage across the array, without any connection to other circuitry.  Cheap DMMs have 200 mV full-scale, which should at least show you what's going on.  The article used an expensive datalogger and only suggests that Arduino-type solutions may be possible, but gives no circuits.  You probably don't need a true differential amp, since the photo voltage is always in the same direction.

I have tried multiple resistors. Even when I use a 10R or 2200R the output does not change. It seems that the breadboard does not respond to the resistors. But, I have not changed the opAmp yet to see what happens. It is something that I have to do. Thank you a lot!


text:
What is this shield? (AST Space Arduino Kit)
I recently got a box with Arduino components from someone who didn't want it (in part, because the manual was (probably) in Chinese). However, to my surprise, I could not find this kit on the internet. I would like to know: is this a copy of another kit?  Or, is there documentation available for this particular kit?
Box contents:

Arduino Uno
Unknow shield "by AST Space" with

AI-THINKER wi-fi module
Songle relais
YLB3641AH 4-digit LED display
DHT-11 relative humidity, temperature sensor
IR receivers, switches, microphone/buzzer, light sensor, connectors to the other components

MPU6050 accelerometer
HC-SR04 ultrasonic rangefinder
QAPASS LCD unit
"Car MP3" IR remote
2x green, 2x red LED, 5x resistor
17x10 green breadboard
2x DC motor, 1x geared stepper motor
40-wide female-female jumper ribbon cable
USB connector cable (black)

It came in an intricate folding box, bright orange. The QR code links to http://weixin.qq.com/r/2kgtNVXEKwhUrRFW9x3I (which did not get me anywhere - visiting this link is at your own risk). Pictures:

Did you try scanning the QR code? I can't because your picture is too blurry.

@Majenko Yeah, it was a broken link; further inspection revealed it was a link to a sponsor. I checked the internet archives, but nowhere was any reference to anything related to this kit or Arduino in general.

It looks like "AST Space" is the online name of a Chinese blogger...

You could just backwards engineer the shield.  Other than what appears to be a WIFI at the top and, maybe, a bluetooth at the bottom - everything else appears to be simply hanging off the Arduino Uno's pins.  But it is hard to tell as the  picture is not all that clear. Guessing, there is no single point to this shield.  It is a collection of different devices. So other then for teaching, its use (mainly because it's huge) is rather limited.

@st2000 That's what I've been doing, but there's a few components whose function I don't know, and I am afraid I could miss a few things. I was mostly wondering whether this was a known board, but given these reactions, it's probably a one-off.

Looks like a great shield. Maybe something here https://translate.googleusercontent.com/translate_c?depth=1&hl=en&prev=search&rurl=translate.google.co.uk&sl=zh-CN&u=http://www.yiweibiying.com/p/J9MPkxx.html&usg=ALkJrhg47ONSQlf2deaRdrkbCgRtG6qgOA

Take a close up of the bits that are confusing you. There are plenty of people here who enjoy backwards engineering hardware.  Just try to ask one question per post.  Try to make it as specific as possible.  And alter your question in order to clear up any misunderstandings or to clarify the question.

@st2000 I will in due time. But, as for now, I was hoping to avoid having to ask various bits and pieces if there was a comprehensive overview for this particular shield. Thanks for your time, nevertheless!

There are no links that I can find to the PDF or the downloads or anything else anymore. I was given one of these kits at work and asked to look into it. Does Anyone have a working link to English Manual or link to the Download site above etc.. Thanks in Advance. Scott

@ScottPinard I made a rough translation of a PDF found in the RAR linked in dda's answer. I uploaded it here for you: https://we.tl/5j77KOe99E Feel free to upvote this question if you find it useful!

My name is Bing Zhu. I the host of ASTSpace a community open lab sponsored by Zhejiang Association for Science and Technology(ZAST). AST is situated inside the Zhejiang Museum of Science and Technology. We are non-profit. The Kit you have gotten must be from someone got it free at one of ASTSpace's events. I remembered that we had brought some with us to the Manchester Science Festival where we did a tinkering activity for the public, 3 years ago.
This kit was designed by one of our members who is currently a Ph.D. student of automation at Zhejiang University. It was developed for the purpose to increase public experiences in a 90 minutes session. Therefore, in order to shorten the time of wiring while most times participants with no backgrounds or exposures to electronics make no sense anyway, we purposely had most of the functioning parts soldered on. In this way, we think it would be more manageable as well for teaching as most times one instructor has to manage more than a room full of over 25 participants. Making sure that parts are connected and in place can be a life-saver. We had it designed this way so the kit can be used in classes by schools in remote areas. These kits are given away and the introduction sessions are free to the public, and we intended to provide online help to those who decide to venture on with this kit at their own time. But, it never took off for time and resource restriction.  With this kit we have gone through two major cities in the Zhejiang Province and 4 remote rural areas.
All our expenses are supported by ZAST through two projects, one to make it and one to distribute it. When we did what we did, it was always for the public to know electronic control and coding was made easy by Arduino where it was first invented by an Italian who wanted to teach artists electronics.
This kit was used to demo how easily and readily everything can be controlled and through these electronics, we can take the parts of the physical world into our hands to follow our wills. We did use it to demo the on and off lighting system of the entire science center and controls of a remote camera inside the security room.
So, ASTSpace Arduino kit is a tailor-made kit for a specific purpose. We did not change anything but redesigned the wiring of the sensors for easy use for our events.

Hi Bing, thanks for your answer. I indeed got it from a young student who attended one of your sessions. They gave it away due to a lack of skills and interest in programming (which can seem very daunting to novices). The board is now part of an Internet of Things project, and I'm planning to use some of the peripherals as a robotics demonstrator.

AST stands for Art, Science and Technology. The learning kit is produced by AST Space who also run maker competitions.

I'm Xiaotian, the designer of this arduino learning Kit. We designed that for people who love DIY but without electronic backgrounds. In the past events, we found everybody (12-16 year old kids usually) could start wiring and coding and finish a little projects with the kit and its examples in 90 mins. All of hardware and software are modular, you could assembly them you want and make your great ideas real quickly.
If you want to know more details about it, feel free to let me know. My email is xtchen@zju.edu.cn.
Thanks for your attention!
Xiaotian

On http://astspace.org/ you can download a PDF related to this AST Space Kit[rar archive].

I took the schema in the PDF and translated in English. Looking at the examples (see below), it looks like the "Wifi Module" is an ESP8266.
The QR code in the PDF is actually readable, but you have to scan it in WeChat (a social platform that mixes chat, Instagram and shopping).
The QR code links to AST Space's account:

The download mentioned above contains schematics and sample code. Download that and you should have a much better understanding on how to use it.


text:
Feather32u4 device not accepting address 5, error -71
I'm using a Feather 32u4 bluetooth device connected
to a AM2302 temperature sensor via I/O pin
to my Linux PC via USB
Everything was working fine, uploading the code to the micro via Artuino IDE and reading the temperature on the Rapsberry PI connected via bluetooth to the Feather 32u4, until I decided to use the Raspberry PI3 to provide power feeding to the Feather (via USB).
After that attempt, I tried again to connect the Feather 32u4 to the Linux PC, but I've neve been able to do that. Everywhen I connect the Feather to the USB port of the PC it is not shown in the available serial ports of Arduino IDE and the dmesg is
[  358.028022] usb 8-2: new full-speed USB device number 6 using uhci_hcd
[  358.148026] usb 8-2: device descriptor read/64, error -71
[  358.372024] usb 8-2: device descriptor read/64, error -71
[  358.588029] usb 8-2: new full-speed USB device number 7 using uhci_hcd
[  358.708024] usb 8-2: device descriptor read/64, error -71
[  358.932024] usb 8-2: device descriptor read/64, error -71
[  359.148028] usb 8-2: new full-speed USB device number 8 using uhci_hcd
[  359.556026] usb 8-2: device not accepting address 8, error -71
[  359.668028] usb 8-2: new full-speed USB device number 9 using uhci_hcd
[  360.076038] usb 8-2: device not accepting address 9, error -71
[  360.076056] usb usb8-port2: unable to enumerate USB device

Is it possible that using the Rapsbery PI3 providing power feeding to the Feather destroyed its USB port? Why?
When I reset the Feather (using the reset button) the following is the dmesg
[53215.808027] usb 3-1: new full-speed USB device number 10 using uhci_hcd
[53215.993042] usb 3-1: New USB device found, idVendor=239a, idProduct=000c
[53215.993046] usb 3-1: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[53215.993049] usb 3-1: Product: Adafruit Feather
[53215.993051] usb 3-1: Manufacturer: Adafruit In
[53216.072814] cdc_acm 3-1:1.0: ttyACM0: USB ACM device
[53216.074154] usbcore: registered new interface driver cdc_acm
[53216.074157] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
[53225.664064] usb 3-1: USB disconnect, device number 10
[53225.904030] usb 3-1: new full-speed USB device number 11 using uhci_hcd
[53226.024024] usb 3-1: device descriptor read/64, error -71
[53226.248024] usb 3-1: device descriptor read/64, error -71
[53226.464024] usb 3-1: new full-speed USB device number 12 using uhci_hcd
[53226.584023] usb 3-1: device descriptor read/64, error -71
[53226.808022] usb 3-1: device descriptor read/64, error -71
[53227.024030] usb 3-1: new full-speed USB device number 13 using uhci_hcd
[53227.432025] usb 3-1: device not accepting address 13, error -71
[53227.544024] usb 3-1: new full-speed USB device number 14 using uhci_hcd
[53227.952021] usb 3-1: device not accepting address 14, error -71
[53227.952040] usb usb3-port1: unable to enumerate USB device

NEW EDIT
I tried the suggestion from @Majenko and the result is the following
Sketch uses 19,712 bytes (68%) of program storage space. Maximum is 28,672 bytes.
Global variables use 730 bytes of dynamic memory.
Forcing reset using 1200bps open/close on port /dev/ttyACM0
PORTS {/dev/ttyACM0, /dev/ttyS0, /dev/ttyS4, } / {/dev/ttyACM0, /dev/ttyS0, /dev/ttyS4, } => {}

<... a long list of similar PORTS rows>

Uploading using selected port: /dev/ttyACM0
/home/storassa/work/Arduino/hardware/tools/avr/bin/avrdude -C/home/storassa/work/Arduino/hardware/tools/avr/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:/tmp/build133016433f76cdf39b8ff61da42c5037.tmp/Antoz.ino.hex:i

avrdude: Version 6.0.1, compiled on Apr 14 2015 at 19:04:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/home/storassa/work/Arduino/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/home/storassa/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : avr109
         Overriding Baud Rate          : 57600
avrdude: ser_open(): can't open device "/dev/ttyACM0": No such file or directory
avrdude: ser_send(): write error: Bad file descriptor
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

I also tried with a
chmod 777 ttyACM0

with the same result

LAST EDIT
I tried again multiple times and eventually I was able to upload the sketch. Everything works fine now

The sketch on your Feather has no CDC/ACM interface - either because it was disabled in your code, or because the sketch has become corrupted somehow.
You need to re-flash the feather with a new sketch - but that's not going to be easy with no CDC/ACM device to access to start programming - except that you do for a short time.
You need to press reset and then upload in the few seconds you get while the CDC/ACM device is available:
\/\/\/ Reset pressed and bootloader entered \/\/\/
[53215.808027] usb 3-1: new full-speed USB device number 10 using uhci_hcd
[53215.993042] usb 3-1: New USB device found, idVendor=239a, idProduct=000c
[53215.993046] usb 3-1: New USB device strings: Mfr=2, Product=1, SerialNumber=0
[53215.993049] usb 3-1: Product: Adafruit Feather
[53215.993051] usb 3-1: Manufacturer: Adafruit In
[53216.072814] cdc_acm 3-1:1.0: ttyACM0: USB ACM device
[53216.074154] usbcore: registered new interface driver cdc_acm
[53216.074157] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
*** UPLOAD RIGHT NOW!!! ***
*** You get about 9 seconds, because... ***
\/\/\/ Bootloader times out and your corrupt sketch runs \/\/\/
[53225.664064] usb 3-1: USB disconnect, device number 10

you can find the result in my new edit. Can I use the RST pin in this case? I found this in the operating guide of the Feather "The RST pin is the factory reset pin, which is also rarely used, but you can use it to set the module back to the factory default settings if it gets really messed up".

As you can see on my last edit, everything works fine now. Thank you very much. I couldn't get to this solution without your help


text:
Error while boot loading Atmega 2560 using Arduino Mega 2560
I have developed custom board using Atmega 2560. I am doing boot loading process using the process of migrate from an Arduino board to a standalone microcontroller.

I have followed this steps...
1) Upload the ArduinoISP sketch onto your Arduino board.
2) Wire up the Arduino board and microcontroller as connections mentioned on Arduino Site.
3) Select "Arduino/Genuino Mega/ Mega 2560" from the Tools > Board menu.
4) Select "Arduino as ISP" from Tools > Programmer
5) Run Tools > Burn Bootloader
While doing this process I am getting this Error...

avrdude: Yikes!  Invalid device signature.
           Double check connections and try again, or use -F to override
           this check.
  Error while burning bootloader.

I have done connection like this...
MISO  -  D50
MOSI  -  D51
SCK   -  D52
Reset -  D53/Reset
+5V   -  Vcc
GND   -  GND

What wrong I am doing? Or any step I have missed?

Is that a clone of mega just without the FTDI IC ?

@SagnikPradhan Yes it is a clone without FTDI IC

Same connections worked for me. Just one connection have to change.
Reset - D10

You wired the whole thing backwards. The proper wiring is
Your board - Arduino
     MISO  -  D50
     MOSI  -  D51
     SCK   -  D52
     Reset -  D53
     Vcc   -  5V
     GND   -  GND

This is kind of obvious from the picture: you would normally use the ISP
connector of the target board.


text:
ESP8266 deep sleep and MQTT
I am working on a project were I am putting my board into deep sleep mode, and it wakes up with an interrupt from a sensor.  When it wakes from deep sleep I would like to send a message to my MQTT broker.  The wiring works, the interrupt works, however, the code does not.
When I use the posted code, everything looks fine in the console, I get all my print statements which would make me assume it is working.  However, my MQTT broker does not show any messages.  But, if I move "sendMQTTMessage()" to the loop function it works fine and the messages come through to my broker.
Any suggestions would be greatly appreciated
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const char* ssid = "*";
const char* ss_pswd = "*";
const char* mqtt_server = "*";
WiFiClient EspClient;
PubSubClient client(EspClient);

void wifi_setup() {
  Serial.print("Connecting to: ");
  Serial.println(ssid);
  WiFi.begin(ssid, ss_pswd);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
void reconnect() {
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    String ClientId = "ESP8266";
    ClientId += String(random(0xffff), HEX);
    if (client.connect(ClientId.c_str())) {
      Serial.println("connected");
      client.publish("outtopic", "hello world, finally");
      client.subscribe("/room/test");
    } else {
      Serial.print("failed, rc=");
      Serial.println(client.state());
      Serial.println("Try again...");
      delay(5000);
    }
  }
}
void sendMQTTMessage() {
  Serial.println("sending your message");
  if (!client.connected()) {
    reconnect();
  }
  client.publish("belmont/sensor/pir/hallway", "on");
}
void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived: ");
  Serial.println(topic);
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
}
void setup() {
  Serial.begin(115200);
  wifi_setup();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  sendMQTTMessage();
  Serial.println("going into deep sleep");
  ESP.deepSleep(10 * 1000000);
}

void loop() {
//  sendMQTTMessage();
//  delay(5000);
}

messages come through to my broker ..... so, what is the actual problem and what is your question?

They only come through my broker, when I place "sendMQTTMessage()" inside of the loop function WITHOUT putting it into a deep sleep.  The minute I start using deep sleep I get no messages on broker.

does any of Attempting MQTT connection... get output?

try a delay after send

The answer for this actually goes to Juraj.  It was the fact that I was missing a delay.  In hindsight it makes sense, as even though I am competing tasks in order, the system is shutting down, before the actual message is sent.  I added a delay(1000) between the "sendMQTTMessage()" and "ESP.deepsleep()" and it worked.


text:
Can I connect a DS3231 and an MPU6050?
Can I connect a DS3231 and an MPU6050 by an Arduino Mega 2560? I have connect it:
MPU 6050               Arduino Mega 2560
SDA           =        SDA
SCL           =        SCL
GND           =        GND
VCC           =        5V

And I have connected DS3231 to SDA and SCL beside AREF pin:
DS3231               Arduino Mega 2560
SDA           =        SDA
SCL           =        SCL
GND           =        GND
VCC           =        5V

The problem is when I connect both of them MPU6050 prints nan, after opening the DS3231 pin from the arduino, MPU6050 prints the correct angles.
Can someone please help me?
Code:
#include "MPU6050.h"
#include "Wire.h"
#include <DS3231.h>
MPU6050 accelgyro;
int16_t ax, ay, az, gx, gy, gz;

DS3231 rtc(SDA, SCL);

double timeStep, time, timePrev;
double arx, ary, arz, grx, gry, grz, gsx, gsy, gsz, rx, ry, rz;

int i;
double gyroScale = 131;

void setup() {
  Wire.begin();
  accelgyro.initialize();
  Serial.begin(9600);
  rtc.begin();
}

void loop() {
  timePrev = time;
  time = millis();
  timeStep = (time - timePrev) / 1000;
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  gsx = gx/gyroScale;   gsy = gy/gyroScale;   gsz = gz/gyroScale;
  arx = (180/3.141592) * atan(ax / sqrt(square(ay) + square(az)));
  ary = (180/3.141592) * atan(ay / sqrt(square(ax) + square(az)));
  arz = (180/3.141592) * atan(sqrt(square(ay) + square(ax)) / az);
  if (i == 1) {
    grx = arx;
    gry = ary;
    grz = arz;
  }
  else{
    grx = grx + (timeStep * gsx);
    gry = gry + (timeStep * gsy);
    grz = grz + (timeStep * gsz);
  }
  rx = (0.1 * arx) + (0.9 * grx);
  ry = (0.1 * ary) + (0.9 * gry);
  rz = (0.1 * arz) + (0.9 * grz);
  Serial.print("X axis == ");
  Serial.println(arx);
  Serial.print("Y axis == ");
  Serial.println(ary);
  Serial.print("Z axis == ");
  Serial.println(arz);
  Serial.println(rtc.getTimeStr());
  i = i + 1;
  delay(1000);
}

run I2C scanner sketch

What DS3231.h library are you using, and why are you specifying the pins to use? That probably puts it into software I2C mode and breaks hardware I2C.

I am using this DS3231, Link = http://www.rinkydinkelectronics.com/library.php?id=73...

And how to run I2C scanner, what is it?

The DS3231 library you are using works (for some bizarre reason) exclusively with its own internal bit-bang implementation of I2C. This cannot be used on the same pins as the hardware Wire library which the MPU6050 uses.
Either move the DS3231 to a different pair of pins, or find a better DS3231 library that uses the Wire library for communication.

Yes. Using i2c, you need to change the address of the MPU6050 because the default is (0x68) which is also the default and only address the DS3231 can use.
Example of changing the address from a personal sketch:
MPU6050 mpu(0x69);
So try:
MPU6050 accelgyro(0x69);


text:
Atmega32u4 issue
I made a custom ATmega32u4 board for my project. Components came from clone of Arduino Pro Micro (with bootloader and code which I uploaded) from AliExpress. I soldered everything in to my board according to my schematic but the board doesn't work. I don't have any signal from that.
https://i.sstatic.net/qskHc.jpg

Did you buy the atmega32u4 with bootloader? Which bootloader? How can you be sure that it has a bootloader? Even the arduino micro has a icsp header. Can you solder wires to it for a icsp header? Then you can upload a sketch with a programmer without bootloader. For example a sketch to toggle a pin or blink a led. After that you can try to use tx and rx with a extra usb-serial module to a computer. After that you can try the bootloader and try to upload a sketch.

Firstly i upload code to orginal board and everything was working. Then i soldered everything and i dont have any response from my custom board.

It's hard to tell from those pictures, but do you actually have any power going into VCC?

Now I've got into whatever EDA that is you're using I can see that no, it would appear not.  You actually have to provide power to the chip for it to successfully run...

I connect this wire and everything is working nice right now. Thanks for fast help ;)

Please don't forget to accept the answer, or post one of your own and mark it as accepted 48 hours later, as this will help other people with the same issue.

You have an error in your schematic.
You have used the net name VCC for your main power circuit. However your USB incoming power is labelled as +5V.
That means you have two separate nets - +5V with power on it, and VCC isolated from it entirely.
You need to connect those two nets together - name them both VCC or both +5V so they form a single net (easiest is to adopt VCC since you use that on other connections too).
To "fix" your current PCB you could connect a small wire from the cathode of D2 to pin 44 AVCC on the main chip which will bridge the two nets together.


text:
Transmitting serial data over Wi-Fi
I have a device that outputs a TX RX RS232 serial string. Is there a way I can take this locally to an Arduino and send over Wi-Fi to another Arduino?
I'm relatively new to all of this so any advice will be greatly appreciated!

Serial-to-WiFi Tutorial using ESP8266

you need a RS232 to TTL Serial converter to connect a RS232 device to Arduino

Yes, and there are many tutorials how to do it.
Most popular one uses ESP8266 module. What is even more interesting you can use ESP module as an Arduino (and yes, you can program it using Arduino IDE).


text:
20 m LED WS2811 Pixel Stripe 12 V
i need some help for my masterthesis.
I plan an Light and Sound installation and for this I decided to use the shape of an Dodecahedron and I want to put LED RGB Pixel Stripes on the surfaces to light the space. Imagine it like a huge ceiling light in shape of a half Dodecahedron.
What I have:

1 x Arduino Starter Kit
4 x RGB LED Pixel Stripe: BTF-LIGHTING WS2811, 5M, 60 LEDs/m, 300LEDs RGB, DC12V

(0,3W/LED = 90W/5 M (1 LED Stripe) = 360 W/20 M an in total 40A (4 LED Stripes))

2 x LED Stripe: Minger SMD 2835, 5m, 300 LEDs, Dimmable, 6000K Kaltweiß, DC12V
(?)

The half of the Dodecahedron has 6 surfaces. Each surface gets like 300 to 350 cm RGB LEDs and 150 cm of Cold White.
My plan is to program the RGB LEDs with Strobe-Light (10 Hz) and changing colours and at the End of the installation the Cold White ("Daylight") is lighten up the space. (But this is another challenge for me ;))
How to connect all of them with my Arduino Uno? Any ideas?
Thank you very much!

So, addressable RGB LED strips.  You can drive each string from an Arduino output, or daisy chain the signal thru all of them and just pump out the needed data using Adafruit Neopixel library, or the FastLED library. Make multiple power connections to keep the amount of 12V current going thru any one strip to a reasonable level.

Connect one output pin to each strip you are using.  In this video I have 4 strips connected to 4 output pins.  https://www.youtube.com/watch?v=CGOxbehyoM4

Actually, it sounds really easy. :) But I´m still afraid to connect all of it.

Here's the datasheet for the WS2811  https://cdn-shop.adafruit.com/datasheets/WS2811.pdf

Your big challenge is going to be power. Sum up the current requirements of ALL of your LED strips. Find a power supply that puts out ≈20% more than that. Read up on the max power you can pass through each strip, You can daisy-chain the power on multiple strips up to the current handling ability of the strips. Say the docs say a strip can pass max 5A through it, and each draws 1A. So you could chain the power connections of 5 of them one to the next, but no more than that. Also make sure you use power wire that's rated for your current needs. Remember your ground wires need to be heavy enough for your current needs as well. (The signal wires can be much lighter gauge.)
The signal lines don't need to follow the same topology as the power connections, but it's simpler to wire up if they do. (You could make the control lines of ALL of the LED strips in one long "snake" but run the power wires in a star pattern so the power wires don't exceed the current carrying limits of the strips or of your power wires. You could also wire both the power and the signal lines in a star pattern, and drive each point of the star with a separate Arduino pin.) You should be able to find a chart online that gives you the current carrying ability of different gauges of wire. There, too, use wire that's rated a little over the current need, just to be safe. (That chart also talks about maximum length of wire to keep the voltage drop below 2%, which is a good idea.)


text:
Blink example compilation error
I just installed the Arduino IDE on Mac and connected the programming port to my Arduino Due. I selected the corresponding board from Tools (though not sure which ATMEL programmer I should choose) I click upload and it gives
In file included from /Users/deepayanbhadra/Library/Arduino15/packages/arduino/hardware/sam/1.6.11/system/CMSIS/Device/ATMEL/sam.h:198:0,
                 from /Users/deepayanbhadra/Library/Arduino15/packages/arduino/hardware/sam/1.6.11/system/libsam/chip.h:25,
                 from /Users/deepayanbhadra/Library/Arduino15/packages/arduino/hardware/sam/1.6.11/cores/arduino/Arduino.h:42,
                 from sketch/Blink.ino.cpp:1:
/Users/deepayanbhadra/Library/Arduino15/packages/arduino/hardware/sam/1.6.11/system/CMSIS/Device/ATMEL/sam3.h:59:37: fatal error: sam3xa/include/sam3xa.h: No such file or directory
   #include "sam3xa/include/sam3xa.h"

compilation terminated.
exit status 1
Error compiling for board Arduino Due (Programming Port)

I'm pretty bumped off as this was my first example. When I connect the USB to the board, the ON is green, the L above and TX below the programming port is yellow. Is this okay?

is there more to that error message? maybe have to scroll up in that bottom window

@ChadG: You're right. I've added what it says further.

Try and pin down whether or not your problem is specific to the Due by compiling for another board, e.g. UNO.  You don't need to have the physical board in order to compile, only upload.  The debug is showing you are missing a library file.

@MichaelT: It still gives different kind of errors with other boards. I'm wondering what the choice of Tools->Programmer-> ? should be

I use default AVRISP mkII from the IDE for UNO.  I'm not aware whether that is different on mac.

@MichaelT: When I choose AVRISP mkII from the IDE for UNO, it just gives 'Problem Uploading to Board' (which's okay because the board isn't connected) I only have a Due. So it seems specific to Due, right? Also, is this okay - the ON is green, the L above and TX below the programming port is yellow?


text:
Parsing example code in Adafruit GPS library with Ultimate Adafruit GPS
I've synced my Uno with the Arduino IDE and I'm using the below code to get the GPS coordinates.
// Test code for Adafruit GPS modules using MTK3329/MTK3339 driver
//
// This code shows how to listen to the GPS module in an interrupt
// which allows the program to have more 'freedom' - just parse
// when a new NMEA sentence is available! Then access data when
// desired.
//
// Tested and works great with the Adafruit Ultimate GPS module
// using MTK33x9 chipset
//    ------> http://www.adafruit.com/products/746
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>

// If you're using a GPS module:
// Connect the GPS Power pin to 5V
// Connect the GPS Ground pin to ground
// If using software serial (sketch example default):
//   Connect the GPS TX (transmit) pin to Digital 3
//   Connect the GPS RX (receive) pin to Digital 2
// If using hardware serial (e.g. Arduino Mega):
//   Connect the GPS TX (transmit) pin to Arduino RX1, RX2 or RX3
//   Connect the GPS RX (receive) pin to matching TX1, TX2 or TX3

// If you're using the Adafruit GPS shield, change
// SoftwareSerial mySerial(3, 2); -> SoftwareSerial mySerial(8, 7);
// and make sure the switch is set to SoftSerial

// If using software serial, keep this line enabled
// (you can change the pin numbers to match your wiring):
SoftwareSerial mySerial(3, 2);

// If using hardware serial (e.g. Arduino Mega), comment out the
// above SoftwareSerial line, and enable this line instead
// (you can change the Serial number to match your wiring):

//HardwareSerial mySerial = Serial1;

Adafruit_GPS GPS(&mySerial);

// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences.
#define GPSECHO  true

// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy

void setup()
{

  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  Serial.begin(115200);
  Serial.println("Adafruit GPS library basic test!");

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);

  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time

  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  // Request updates on antenna status, comment out to keep quiet
  GPS.sendCommand(PGCMD_ANTENNA);

  // the nice thing about this code is you can have a timer0 interrupt go off
  // every 1 millisecond, and read data from the GPS for you. that makes the
  // loop code a heck of a lot easier!
  useInterrupt(true);

  delay(1000);
  // Ask for firmware version
  mySerial.println(PMTK_Q_RELEASE);
}

// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
#ifdef UDR0
  if (GPSECHO)
    if (c) UDR0 = c;
    // writing direct to UDR0 is much much faster than Serial.print
    // but only one character can be written at a time.
#endif
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
    usingInterrupt = true;
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
    usingInterrupt = false;
  }
}

uint32_t timer = millis();
void loop()                     // run over and over again
{
  // in case you are not using the interrupt above, you'll
  // need to 'hand query' the GPS, not suggested :(
  if (! usingInterrupt) {
    // read data from the GPS in the 'main loop'
    char c = GPS.read();
    // if you want to debug, this is a good time to do it!
    if (GPSECHO)
      if (c) Serial.print(c);
  }

  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences!
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false

    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) {
    timer = millis(); // reset the timer

    Serial.print("\nTime: ");
    Serial.print(GPS.hour, DEC); Serial.print(':');
    Serial.print(GPS.minute, DEC); Serial.print(':');
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    Serial.println(GPS.milliseconds);
    Serial.print("Date: ");
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.println(GPS.year, DEC);
    Serial.print("Fix: "); Serial.print((int)GPS.fix);
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
    if (GPS.fix) {
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", ");
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print("Location (in degrees, works with Google Maps): ");
      Serial.print(GPS.latitudeDegrees, 4);
      Serial.print(", ");
      Serial.println(GPS.longitudeDegrees, 4);

      Serial.print("Speed (knots): "); Serial.println(GPS.speed);
      Serial.print("Angle: "); Serial.println(GPS.angle);
      Serial.print("Altitude: "); Serial.println(GPS.altitude);
      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
    }
  }
}

When I compile and upload, it successfully does and the serial output displays something like this:
Time: 23:5:8.0
Date: 6/7/2018
Fix: 1 quality: 1
Location: 3855.8869N, 7721.3422W
Location (in degrees, works with Google Maps): 38.9314, -77.3557
Speed (knots): 0.32
Angle: 211.87
Altitude: 177.90
Satellites: 7
$PGTOP,11,2*6E
$GPGGA,230509.000,3855.8869,N,07721.3423,W,1,7,1.10,177.9,M,-33.4,M,,*64
$GPRMC,230509.000,A,3855.8869,N,07721.3423,W,0.28,211.87,060718,,,A*7F
$PGTOP,11,2*6E
$GPGGA,230510.000,3855.8869,N,07721.3424,W,1,7,1.10,177.9,M,-33.4,M,,*6B
$GPRMC,230510.000,A,3855.8869,N,07721.3424,W,0.28,211.87,060718,,,A*70
Everything seems okay except that the time is also offset by 4 hours?

GPS is probably giving you universal time (UTC).  Your profile says that you're in College Park, MD, so that's currently 4 hrs different due to daylight savings time.

Oh, I didn't know it gives UTC. Is that the norm or can be customized?

You customize it by adding 4. :)  GPS gives UTC as a standard. (EST is UTC -5, EDT is UTC -4.)


text:
Wake up a PC from an Uno
I want to wake up a PC via a USB-connected Arduino. When using a Pro Micro (Leonardo) I can do it, as its HID interface can wake up a PC. That is, in the Device Manager, under "Keyboards", the relevant HID device under "Power Management" has an "Allow this device to wake-up the PC" checkbox.

However, I need to use an Uno for this project. There's a hack (see link below) which flashes the ATMega16U2 on an Uno to act as a HID keyboard. It works fine, but this HID keyboard on a flashed Uno does NOT have the "Allow this device to wake up the PC" checkbox, i.e. I can't wake up my PC. I tried, the PC doesn't wake up. I know I can use an Ethernet shield on an Arduino to send a Wake up on LAN packet, but I don't want to add any shields, if I don't have to. Any advice how to do this?
EDIT: I was pointed to 2 libraries, NicoHood and LUFA (links below) to code a HID keyboard for the ATMega16U2 on an Arduino Uno. The problem is that acquainting myself with the subject and (either) library, would take several days, which is why I'd prefer to find an already-compiled simple HID device that does what I want. If I can't find one, I have a "dumb" solution: since the Leonardo can wake up a PC, I can hook it up to the PC, power the Uno (with my code) off the Leonardo, link one digital pin between the Uno and the Leonardo, so that the Uno can trigger a USB keystroke on the Leonardo. This is kludgy, since it uses the Leonardo just to send one USB keystroke to wake up the PC, but it would work.
LUFA
NicoHook Keyboard API
HoodLoader
Relevant links:
Arduino Uno as a USB HID Interface
Wake a touchscreen using a Pro Micro

I don't think it's that simple. I think the device driver has to have the wake-up ability coded in, i.e. be able to send out the relevant message

The HID library by NicoHood uses a special bootloader in the 16U2, https://github.com/NicoHood/HID It can send media keys and the power key.

Thanks. I'll try to get in touch with the author, as I'm not sure what the minimal required setup would be.

Try a different USB port.

Can you explain the reason why you need to use UNO?

I need to use a shield which only fits the Uno

Got it working: my Uno can now wake up a PC. I followed the HoodLoader wiki and I used the HID-Bridge sketches (below). It took about 2-3 hrs.
HoodLoader
HID-Bridge

I spent way too much time trying to get this to work with arduino ide.  None of the OS settings seemed to work.  I then tried using Adafruit's circuitpython.   I assume the circuitpython HID library includes the right juju to let the mouse movement wake the pc. Changing nothing in OS ( windows and ubuntu) it worked.
You will need to add the adafruit_hid library to your CIRCUITPY usb library folder.
The code is then pretty trivial - pir connected to 3v power and sensor pin to D10.
# move the mouse when pir detects motion
# blink led and move mouse
#this wakes my pc when i enter the room
#may want to sleep a bit after waking it so mouse is not constantly moving...

import time
import board
import usb_hid

from digitalio import DigitalInOut, Direction
from adafruit_hid.mouse import Mouse

led = DigitalInOut(board.LED_INVERTED)
led.direction = Direction.OUTPUT
sensor_pin = DigitalInOut(board.D10)
sensor_pin.direction = Direction.INPUT
mouse = Mouse(usb_hid.devices)

while True:

    led.value = False
    time.sleep(0.5)

    if sensor_pin.value is True:
        mouse.move(x=10,y=10)
        led.value = True
        time.sleep(0.5)


text:
Input state is stuck HIGH when function called using input also uses same input to call another function
I'm writing a choose-your-own-adventure style project for a class project. My Arduino Uno is set up with a 16-digit LCD display and two pushbuttons with pulldown resistors. I'm wanting each function to display text on the LCD and then take two user inputs, Yes or No, from the pushbuttons, and then call another function respective of which input is pressed. Each successive function will also take the two inputs to then call the next function in the series, and so on.
My issue is that after the first time a pushbutton is pressed, its state does not change. When question1() is called, and the user presses button1, question2 is called. However, the function runs and never waits for user input, and question4 is called right away because the state of button1 seemingly stays HIGH after the first time it is pressed.
What am I missing? Is there a better way to be gathering the user input? My pushbuttons are properly wired with the resistor pulling down to ground so my issue must be with my code.
Thanks in advance for any help.
void loop()
{
  question1();
}

void question1()
{
  button1State = digitalRead(9);
  button2State = digitalRead(8);
  if (q1 == false)
  {
    text1();
  }

  if (button1State == HIGH)
  {
    question2();
  }

  if (button2State == HIGH)
  {
    question3();
  }
}

void question2()
{
  button1State = digitalRead(9);
  button2State = digitalRead(8);
  if (q2 == false)
  {
    text2();
  }

  if (button1State == HIGH)
  {
    question4();
  }

  if (button2State == HIGH)
  {
    question5();
  }
}

You're reading the (physical) button states in one location, inside loop() with button1State = digitalRead(9); .... Once you call question1() from loop(), the values of buttonState1 and buttonState2 are fixed and will not change until your code returns to loop() to re-read the physical button state into buttonState1 and buttonState2.

I was reading the button state at the beginning of each function and that wasn't seeming to do anything. Let me retry that though, thank you

Yeah the behavior is still the same. Since the state of the button is the condition of my if statement, perhaps that's what is holding this up?

think about this .... how do you detect two presses of one button?

@jsotola Yeah that's kind of what I'm trying to figure out

what is the sequence of events when you press a button twice?

If it's pressed twice nothing should happen unless the textX() function has ran, at which time it's time for user input again and the button press call the next function

You have to wait for the button to be released. Currently you wait for a button to be pressed in question1, which is fine. Once a button1 is pressed you go to question2, but since the button is still pressed it immediately goes on to question 4.

Do you suggest using the state of the button to assign a value to a variable, and then using that variable to call the respective function?

You want to count each button press once. So you don't want to look for the button pin being HIGH (as it will stay high for quite some time, like tens of milliseconds, ages for a microcontroller), you want to look for the transition from LOW to HIGH. Also you need to consider the button bounce, thus you need debouncing (you can google that). I suggest you have a look at the Bounce2 library, which will help a lot with reading mechanical buttons. Try the examples to understand, how the library is used

This answer might also help you. There are sure many more questions about reading buttons on this site. You can just search for them.

reading a button is not so simple as it seams. and for multiple buttons and long press detection etc, the code in sketch gets complicated. I use a library. Bounce2 maintained by Thomas O Fredericks

There needs to be a delay() after the button state is read to allow time for it to return LOW, dumba**.
You already have enough delay() in your textN() functions, just check the button state after calling that function, not before. Code should be as follows:
void loop()
{
  question1();
}

void question1()
{
  if (q1 == false)
  {
    text1();
  }

  button1State = digitalRead(9);
  button2State = digitalRead(8);

  if (button1State == HIGH)
  {
    question2();
  }

  if (button2State == HIGH)
  {
    question3();
  }
}

void question2()
{
  if (q2 == false)
  {
    text2();
  }

  button1State = digitalRead(9);
  button2State = digitalRead(8);

  if (button1State == HIGH)
  {
    question4();
  }

  if (button2State == HIGH)
  {
    question5();
  }
}

This solves the issue completely.


text:
Is it possible to synchronize two SPI busses to send data out in parallel on the same clock signal?
We're working with these very odd driver chips which are sort of like shift registers except rather than latch the data at the end, the latch needs to happen over the last 'n' clock cycles in parallel with the data being shifted out.  Depending on the value of 'n', the data is 'latched' into different registers. Like I said, it's an odd protocol.
Here's an example sending six bytes of data (top row) synced to the latch (bottom row).  The latch is HIGH for the last two bits of the data as it's being shifted out.
Time-->
11001100 01010101 10011010 11001011 01001010 10010101
00000000 00000000 00000000 00000000 00000000 00000011

In this example, the latch is synced to the fifth and sixth bit of that last frame (as opposed to the 7th and 8th in the first example) which tells the chip to load this data into a different register.
Time-->
11001100 01010101 10011010 11001011 01001010 10010101
00000000 00000000 00000000 00000000 00000000 00001100

Like I said, it's an odd design, but it basically lets you shoot out data non-stop without having to pause to latch.
Because of having to 'sync' the latch with certain clock cycles in the data, we can't use the standard SPI bus and have to use normal GPIO pins, which of course are substantially slower.
BUT... if I could set up the data for a second SPI bus, then use a buffer to define where the latch is high/low accordingly, that would work.
The issue is I don't know how to, or if it's even possible to sync SPI busses together.
Only thing I can think of is to use one SPI bus as the master and another SPI bus (on the same processor) as a slave, then try to leverage the bi-directional nature of it.  But this is just a guess.
I was considering looking into DMA too, but I'm starting with SPI since I know my chip has four SPI busses on it. (Update: I'm starting to think DMA is the way to go here since I now know it is possible to sync two DMA controllers to the same clock.)

very odd driver chips ... if they do not have a part number and they have no datasheet, then don't use them

There from ST and they do have a data sheet, but that's separate from my question as I'm not asking about them. I'm specifically asking if I can somehow sync two separate pins to the same SPI clock.  If not, I'll have to give the synced-DMA route a try as I know that can be done.

i am sorry, it is difficult to visualize what you are asking ... can you draw a block diagram that describes what you are asking?

I have two buffers of data that I want to send out on two parallel pins on the same clock cycle.  Think standard SPI but with two MOSI pins. I've actually found out this is possible with DMA so I think that's the way I'm going to go, but if you can figure out how to do this via SPI, that would be cool too.

As the Wikipedia page on SPI shows (as introductory material), the SPI main device generates the clock. The SPI sub device waits for the leading edge on its CS (chip select) to start transmitting its data on the following clock edges.
So you can set up one of the senders as main device, and the other sender as sub device. Use MOSI of main as the first data output, and MISO of sub as the second data output, like this:

simulate this circuit – Schematic created using CircuitLab
You can add more SPI sub devices, if you need more synchronized outputs.


text:
Help with code not working
I built a button box, everything is wired up and all of the push buttons work using the code below, but for some reason my rotary encoders are not working, well 3 out of the 4 are not working. Is there something in my code that I messed up? Should rotary encoders not be linked to analog pins? Any guidance would be appreciated.
EDIT - Correct code replacing incorrect code.
#include <Keyboard.h>
#include <SimpleRotary.h>

#define NUMROWS 6
#define NUMCOLS 4

const int ModPin = A0;
int ModState = 0;

//define the symbols on the buttons of the keypads
char buttons[NUMROWS][NUMCOLS] = {
  {'7','5','3','1'},
  {'6','4','2','0'},
  {'r','e','w','q'},
  {'i','u','y','t'},
  {'f','d','s','a'},
  {'p','j','h','g'},
};

char buttonsMod[NUMROWS][NUMCOLS] = {
  {'7','5','3','1'},
  {'6','4','2','0'},
  {0xC9,0xC7,0xC5,0xC3},
  {0xC8,0xC6,0xC4,0xC2},
  {'f','d','s','a'},
  {'p','j','h','g'},
};

byte rowPins[NUMROWS] = {13,12,11,10,9,8}; //connect to the row pinouts of the keypad
byte colPins[NUMCOLS] = {7,6,5,4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
Keypad buttbxMod = Keypad( makeKeymap(buttonsMod), rowPins, colPins, NUMROWS, NUMCOLS);

SimpleRotary RotaryA(1,2,3);
SimpleRotary RotaryB(0,A5,3);
SimpleRotary RotaryC(A4,A3,3);
SimpleRotary RotaryD(A2,A1,3);

void setup() {
  Keyboard.begin();
  pinMode(ModPin, INPUT_PULLUP);
}

void loop() {
ModState = digitalRead(ModPin);
  if (ModState == HIGH) {
    CheckAllButtons();
  } else {
  CheckAllButtonsMod();
  }

byte i;

  // 0 = not turning, 1 = CW, 2 = CCW

  i = RotaryA.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  i = RotaryB.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  i = RotaryC.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  i = RotaryD.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
}

void CheckAllButtons(void) {
  char key = buttbx.getKey();
  if (key != NO_KEY)  {
    Keyboard.press(key);
    delay(150);
    Keyboard.releaseAll();
  }//Keyboard.write(key);
}

void CheckAllButtonsMod(void) {
  char key = buttbxMod.getKey();
  if (key != NO_KEY)  {
    Keyboard.press(key);
    delay(150);
    Keyboard.releaseAll();
  }//Keyboard.write(key);
}

In your loop you only ever check A and B.  You never do anything with C and D.  Were you copy-pasting and forgot to change the B's to C's and D's?  It looks like you read B three times.  Are C & D the ones not working?  If this is for gaming then you're going to find that with all the delay(150) in there it won't be very responsive.  Hope it's a slow game.

One more hint for you, avoid always naming things with single letters.  Single lower case letters just suck to read.  Single upper case letters are often used as macros by the core.  You can end up with some strange errors that are hard to debug when those two clash.  Name them encoderA and encoderB or something.  But just A, B, C, and D is something to avoid.

some of the code lines inside loop() are incorrectly indented ... that makes it difficult to see the end of the loop() block

It seems that copy paste is a bad idea, After correcting that error things seem to be working now, except for the encoder wired to 0/A5, which workes sometimes and other times it triggers the "p" code, I suspect a wiring fault, will have to go hunting.


text:
Why do my Hall sensor readings change when I write them to the serial port?
I have a small project where I connected a Hall sensor (see picture) to an Arduino Mega. The blue wire is connected to pin 45, the red wire to +5V, and the black wire to GND.

At the beginning I initialize the pin used to read the sensor as follows.
#define HALL_PIN 45

void setup()
{
  pinMode(HALL_PIN, INPUT);
}

I have written a function to read out the sensor. While there is no magnet nearby, the sensor returns HIGH. If a magnet approaches in the correct orientation, the sensor returns LOW. The function should return true if a magnet is nearby, i.e. if the read value is LOW.
I have noticed that my program logic sometimes does not work reliably after seemingly irrelevant changes to the code. After commenting out more and more code to narrow down the problem, I came across the following discovery.
Implementation 1:
In the first implementation, I initially read out the value of the Hall sensor. Next, I send the value to the serial port. The serial monitor in the Arduino IDE outputs the number 1 (HIGH). This is the expected behavior as during testing there is no magnet nearby. Based on the subsequent program behavior I can confirm that the function returns false. I can let the Arduino run for minutes and the behavior remains stable.
bool readHallSensor()
{
  int s = digitalRead(HALL_PIN);

  Serial.println(s); // The serial monitor outputs 1 (HIGH)

  return s == LOW; // Returns false
}

Implementation 2:
With the second implementation I do not write the read value to the serial port. As expected, the serial monitor in the Arduino IDE remains empty. The function, however, now returns true. Apart from commenting out the marked line and flashing the sketch to the Arduino, I did not make any changes (again no magnet nearby). Also in this case I can let the Arduino run for minutes and the behavior is stable.
bool readHallSensor()
{
  int s = digitalRead(HALL_PIN);

  // Serial.println(s); // No output to the serial monitor

  return s == LOW; // Returns true
}

My first suspicion was that the delay caused by writing to the serial port is what makes the difference. I asked an electrical engineer whether Hall sensors might need short breaks between successive readings. He denied my assumption, and indeed, if I simply insert a delay(300); after reading the value (without writing to the serial port) the behavior does not change and is identical to implementation 2.
I can switch back and forth between the two implementations and flash them to the Arduino as many times as I like. The behavior is always as described above for both cases. I cannot make any sense of this, as the behavior seems to lack any (programming) logic. Has anyone ever made similar observations and can give me a hint what might cause this? Thank you in advance.

I haven't found the problem yet, but I have come a step closer. The issue has reappeared in a similar project on the same Arduino. I use a new Hall sensor with pull-up, which is read out wrong again under certain circumstances (always read out as LOW, no matter if a magnet is nearby). The problem seems to occur only when I use a certain pin. The pin in question on my Arduino Mega this time is pin 37. If I connect the Hall sensor to another pin (I have tested 34 and 36), it works fine. If I connect a previously working Hall sensor to pin 37, it will not work anymore (always evaluated as LOW). The only explanations that make sense to me at the moment are that either the Arduino Mega is damaged or that there are side effects, maybe caused by external libraries using certain pins without my knowledge and incorrectly initializing them.

what happens if you use Serial.println('x');?

Do you have a pull up connected between 5 V and the digital output pin? Please check. is it the same with other digital pins too?

@goodarduinocode.com Good observation, but it looks like one may be present on the sensor board.

The problem could be in another part of the code.  When you run into situations where a seemingly unrelated change completely changes the behavior of the program then you are often times up against some issue causing undefined behavior like a buffer overrun or a memory issue or a bad pointer or something.  It can be in a completely unrelated part of the program.  But if memory is getting clobbered somewhere then there is no way to predict what the consequences will be.  Post a complete and compilable example that illustrates the problem.

Writing a string constant to the serial port (instead of the read value) results in the same behavior as in implementation 2 (no writing to the serial port at all). I added a pull-up since the output voltage was a bit low. However, this did not change the behavior. It seems that the sensor worked fine before and that the problem is software-related. Unfortunately, I still could not find the cause of the problem. I will make sure to update this thread if I should find out what it is. Thank you all for your suggestions!

The 3144 requires a pull-up resistor. It only sinks when a magnet is present. It doesn't source, so the pin is floating if no magnet is present.
You can use the internal pull-up resistor by using pinMode(HALL_PIN, INPUT_PULLUP);

The Hall sensor came already pre-mounted on a circuit board with a resistor (see picture in my first post). My assumption was that the pull-up was already there. But when we measured the voltage of the output signal, we found that it is only 3.8V (with 4.8V as input voltage). Adding a pull-up has increased the output voltage to the full 4.8V. However, this did not change the behavior of the Arduino so it does not seem to be a hardware problem. Nevertheless your advice is absolutely justified and it is certainly better to add a pull-up. So thank you for that.

I think that resistor is for the LED, not a pull-up. Though the net effect is that it will pull-up output pin to 5V minus the forward voltage of the led. The forward voltage of a red led is around 1V so that would give you the voltages you've measured.

Thank you for the clarification. My understanding of electrical engineering is still quite limited and I really appreciate your help.


text:
Are the GND pins of an Arduino identical to GND of its power supply?
What would happen if I connected a fan as shown in the following picture:

+12V is supplied by the power supply that also powers the Arduino.
GND, however, is connected to a GND pin of the Arduino instead of the power supply.

I guess that would not work? Or are GND from the Arduino and GND from the power supply identical in this case?

If you read the accepted answer, please also note the comments below. The power consumption of the consumer (fan) is important.

why are you not connecting it to the power supply ground?

The fan, together with other parts, is connected to the Arduino via a connector with a limited number of pins. GND from the Arduino is already connected there. I would save contacts if I could reuse this GND instead of also connecting GND of the power supply.

it is a good idea to avoid connecting external device grounds to the arduino ... the current that is drawn by the external device can create a voltage drop between the arduino ground and the power supply ground ... that would lower the voltage between the power pins at the arduino

Thank you @jstola. Could I just connect all consumers (no matter if they are powered by +12V of the power supply or +5V of the Arduino) to GND of the power supply (and not use the GND pin of the Arduino at all)?

yes, you definitely could do that ... anything that has a motor or a solenoid and things like LED strips should be grounded at the power supply ... sensors would be ok to ground at the arduino, unless they draw many tens of mA

"Ground" is just a lump of metal and each ground "pin" is connected to it. That includes the ground connection in the barrel jack. It's all one thing.
Wherever you connect your fan's ground to it's all ground.  That is, as long as all grounds external to the Arduino are connected, ultimately, to the Arudino.

To add to the above: Because wires and PCB traces are not perfect conductors, that is have resistance, there are practical differences between between different labeled "GND" points.  So it does matter where your current is traveling within the network of conductors that are labeled "GND".  High currents traveling on the ground must travel through GND conductors (traces, wires) capable of handling those currents.

Indeed, but given that the current limit of the headers is only 1A you won't be passing that much through the Arduino's ground pins...

Thank you for your comments. The fan is actually very powerful (originally intended for cooling server PCs - it draws 1A).  In this case, in consideration of your remarks, it would probably be better to connect GND of the fan directly to the power supply?

@xoric For that kind of current, yes, connect it to the power supply's ground for the lowest impedance and highest current handling.

Thank you @Majenko, your explanation was very helpful.

Another helpful remark from an experienced electrical engineer who advised me to connect GND directly to the power supply: In the picture above the fan current flows through the Arduino, which doesn't necessarily cause problems, but in any case doesn't have a positive effect either. It is also no mistake to leave the plus and minus cables of the fan close together. This minimizes electromagnetic interference that the fan may produce.


text:
Arduino Timer with increase time button
I have an Arduino project to do, which requires a countdown timer(which I've already done). I connected a push button, and when I press that button I need it to increase my countdown timer by +10 seconds.
Can anyone help me with adding the code for this button?
Here is the code so far(I declared the button, but I don't know if it's any good):
#include <LiquidCrystal.h>

int buttonPin = 7;
int buttonState = 0;
int seconds = 30; // count seconds
int minutes = 0; // count minutes
int hours = 0; // count hours
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // pins connected to LCD

void setup()
{
  lcd.begin(16, 2); //set up the LCD's number of columns and rows
  pinMode(buttonPin, INPUT);
}
void loop()
{
  buttonState = digitalRead(buttonPin);
  lcd.setCursor(1, 0);
  lcd.print ("Sosire in:");
  lcd.setCursor(6, 1);
  lcd.print(":");
  lcd.setCursor(9, 1);
  lcd.print(":");

  seconds--;
  delay(1000);

 if (seconds < 0)
  {
    minutes--;
    seconds = 59;
  }
 if (minutes < 0)
  {
    hours--;
    minutes = 59;
  }
 if (hours < 0)
  {
    hours = 0;
    minutes = 0;
    seconds = 30;
  }
 if (minutes > 9)
  {
    lcd.setCursor(7, 1);
    lcd.print(minutes);
  }
 else
  {
    lcd.setCursor(7, 1);
    lcd.print("0");
    lcd.setCursor(8, 1);
    lcd.print(minutes);
    lcd.setCursor(9, 1);
    lcd.print(":");
  }

 if (seconds > 9)
  {
    lcd.setCursor(10, 1);
    lcd.print(seconds);
  }
 else
  {
    lcd.setCursor(10, 1);
    lcd.print("0");
    lcd.setCursor(11, 1);
    lcd.print(seconds);
    lcd.setCursor(12, 1);
    lcd.print(" ");
  }

 if (hours > 9)
  {
    lcd.setCursor(4, 1);
    lcd.print(hours);
  }
 else
  {
    lcd.setCursor(4, 1);
    lcd.print("0");
    lcd.setCursor(5, 1);
    lcd.print(hours);
    lcd.setCursor(6, 1);
    lcd.print(":");
  }
 if (seconds == 0)
  {
    lcd.clear();
    lcd.print("Este in statie");
    delay(5000);
    lcd.clear();
  }

}

Your code is very hard to read, please align it (parenthesis under each other and code within indented properly).

You should always name your variables for readability. Instead of "H", "M" and "S", use English names like "hours", "minutes", and "seconds". It will make it a lot easier for other people to help you, and also help you read your own code!

My program works correctly , but i don't know how to make when i press the button to increase time with 10+ seconds.

Increase which time? You will need to be more specific, you have 3 different 'time' variables, hours, minutes, and seconds.

Seconds , increase S with 10 seconds when i press the button.

your code is un-necessarily complex  .... the LCD keeps track of the next print position .... for example, the display seconds code can be reduced to these four lines ....
lcd.setCursor(10, 1);
if (seconds < 10)     lcd.print("0");
lcd.print(seconds);
lcd.print(" ");

So look at the button example and the state change example that come with the IDE.  the first explains how to use an if statement to do something when a button is pressed and the second explains how to have that happen only once per press of the button.

I don't fully understand your program, but I hope to give some guidelines/tips:

Instead of using all kind of different variables, with hour, minutes and seconds, with with only one variable that keeps the time. E.g. a long integer value that contains 24 * 60 * hours + 60 * minutes + seconds as one value. E.g. 12:34:56 will be 24 * 60 * 12 + 60 * 34 + 56 = 19,376.
Subtracting one or 10 seconds will be as easy as subtracting a value 1 or 10.
To calculate back to seconds, minutes and hours, use 3 formulas (assuming time is the time value):

int hours   = (int) time / 60 / 24;
int minutes = (int) (time - hours * 60 * 24) / 60;
int seconds = time % 60;

Keep the code to display the LCD separate, probably it's easier to update every digit every second. You probably change it every second, or when the button has been pressed, which is very slow for a MCU.
When using a button (you already put it in a variable), just remove 10 seconds, and update the time.
However, check also the Blink Without Delay example on the Arduino website, since when you press a button, high likely the button will bounce and one press may result in several times 10 seconds will be subtracted.
And as said above, use good and English variable names, and English comments (except the GUI text to be displayed... O zi buna).


text:
How can big Arduino programs be analyzed easily?
I have an Arduino project code, but the problem is it has multiple functions and flow of control.
How could I convert this code into flowchart or control flow diagram?
Any software or online website?

Use doxygen and configure for full control and structure graphs.

Seems like you should be going the other way - create the flow chart first, then write the code to follow it.

Yes flow charts on function call level may be generated with doxygen (calls and callers). More details for instance here, https://romanegloo.wordpress.com/2012/03/29/generating-a-callgraph-by-using-doxygen-and-graphviz-13/

Another tool to quickly analyze code is Source Monitor. Allows a "statistic" approach to navigating the code. http://www.campwoodsw.com/sourcemonitor.html

With respect, how is this a question about Arduino?  The same question could be asked about almost any large program in C++.

Although there are programs who can automatically make some documentation (like doxygen), I haven't seen any software so far that can make USEFUL flowcharts or diagrams. The main reason is that such software does not know which are the important parts and which are not.
To do it manually:
Assuming your code contains multiple files, use an UML (Unified Modeling Language) application. Than if classes are used, you can easily port them to UML, otherwise assume each (.c) file is a 'class'.
By adding properties/fields and methods (functions) and drawing dependencies between the classes/files you get a good idea how everything works together.

this is not what he asked. he wants an automatically created flow chart

@Juraj ... true I will update my answer.