text:
Arduino DS3231 error: no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'
I am building a arduino based bicycle speedometer with time and temperature display.
Im currently stuck with the DS3231 (zs-042) chip. I found online a lot of library issues, i tried using
multiple libraries (Rinky-Dink, ds3231-master) but nothing works. I found a simple code online to test the chip but when I upload it the following error shows up: "no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)"
#include <Wire.h>
#include <DS3231.h>
DS3231  rtc(SDA, SCL);

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

  // Initialize the rtc object
  rtc.begin();
  rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014
}

void loop()
{
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");

  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());

  // Wait one second before repeating :)
  delay (1000);
}

The error occurs in the third line (rtc (SDA,SCL)) - I have checked the pins and switched the battery on the chip. I also tried using A4 and A5 instead of SDA and SCL pins...
Any type of help would be awesome.
Best regards,
Marin

Alright I found the problem.
https://www.youtube.com/watch?v=BM3A7w3bhqM&ab_channel=MERTKILIC
In this video at 5:00 you can see the following:
First you have to download the library, unzip it and copy the files inside.
You will have to paste it to your Arduino/Libraries/DS3231 folder.

On the left is the current DS3231 Library which I added through the arduino library manager. Its not the same as the one the right, it should be, but its not, copy the files from the unzipped DS32321 library into the Arduino/library/DS3231.
Works fine now !

Any reason why you did not simply install it via the Library Manager?

I did and it didnt work


text:
ESP 8266 HTTP Client Data is not changing correctly
I'm Trying to control a pin "D1" from HTTP API everything was working fine but when i'm going to change the data from server it's done on the server but on device it's takes so long time almost 20 minutes i also checked the Serial Monitor the data is not updating please help me.
My Device: Node MCU V3,
Here is my code:
/**
   BasicHTTPClient.ino

    Created on: 24.05.2015

*/

#include <Arduino.h>

#include <Arduino_JSON.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#include <WiFiClient.h>

ESP8266WiFiMulti WiFiMulti;

void setup() {

  Serial.begin(115200);
  // Serial.setDebugOutput(true);

  Serial.println();
  Serial.println();
  Serial.println();

  pinMode(D1, OUTPUT);

  for (uint8_t t = 4; t > 0; t--) {
    Serial.printf("[SETUP] WAIT %d...\n", t);
    Serial.flush();
    delay(1000);
  }

  WiFi.mode(WIFI_STA);
  WiFiMulti.addAP("Maruf Hasan", "marufhasan");

}

void loop() {
  // wait for WiFi connection
  if ((WiFiMulti.run() == WL_CONNECTED)) {

    WiFiClient client;

    HTTPClient http;

    Serial.print("[HTTP] begin...\n");
    if (http.begin(client, "http://marufhasan.net/api/test.txt")) {  // HTTP

      Serial.print("[HTTP] GET...\n");
      // start connection and send HTTP header
      int httpCode = http.GET();

      // httpCode will be negative on error
      if (httpCode > 0) {
        // HTTP header has been send and Server response header has been handled
        Serial.printf("[HTTP] GET... code: %d\n", httpCode);

        // file found at server
        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
          String response = http.getString();
          //Converting response object;
          Serial.println(response);
          JSONVar myObject = JSON.parse(response);

          if (JSON.typeof(myObject) == "undefined") {
            Serial.println("Parsing input failed!");
          }else{
            if (myObject.hasOwnProperty("status")) {
              String status = (const char*) myObject["status"];

              if(status=="on"){
                    Serial.println("ON");
                    digitalWrite(D1, HIGH);
              }else{
                    Serial.println("OFF");
                    digitalWrite(D1, LOW);
              }

            }
          }
        }
      } else {
        Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
      }

      http.end();
    } else {
      Serial.printf("[HTTP} Unable to connect\n");
    }
  }

  delay(5000);
}

Your server has a cache control of 10-min. Cache-Control: max-age=600.

source: Stack Exchange

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

sort: votes


text:
Arduino Bluetooth upload problem HC-05 v4.0
I upload code into arduino nano using a self-made PCB with bluetooth using this method. I was initially using Arduino Nano (chinese Clone, the one with CH340G) and Bluetooth module HC-05 (version 3.0) (Lets assume this bluetooth is BT1)
At command response for BT1
AT+NAME?
+NAME:H-C-2010-06-01
OK
AT+POLAR?
+POLAR:1:1
OK
AT+VERSION
VERSION:3.0-20170601
OK
AT+UART?
+UART:9600,0,0
OK

All the things were working perfectly till the new nano as well as latest version of bluetooth arrived.
Bluetooth problem: I was trying to configure the newer bluetooth BT2 and I faced the error highlighted in code.
AT Commands response for BT2
    AT+NAME?
    +NAME:HC-05
    OK
    AT+VERSION?
    +VERSION:4.0-20190815
    OK
    **AT+POLAR**
    **ERROR:[0]**
    AT+UART?
    +UART:9600,0,0
    OK

The problem I am facing is I am unable to change the state pin with AT+POLAR command. I think this version of bluetooth has different AT Commands. If anyone knows about this particular problem please help.
Also I tried uploading code using old bluetooth to a newer version of Arduino Nano (New bootloader OPTIBOOT) and it was successful. Needed to change the baud rate of program as well as Bluetooth to 115200.

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


text:
Unable to compile SimpleTimer code - Exit status 1
I downloaded the SimpleTimer library from the Arduino's library manager and navigated to Arduino Playground website for some sample code for testing - SimpleTimer - Arduino Playground. After copying the following code into the Arduino IDE:
#include <SimpleTimer.h>

// the timer object
SimpleTimer timer;

// a function to be executed periodically
void repeatMe() {
    Serial.print("Uptime (s): ");
    Serial.println(millis() / 1000);
}

void setup() {
    Serial.begin(9600);
    timer.setInterval(1000, repeatMe);
}

void loop() {
    timer.run();
}

I receive the following error:
exit status 1
no matching function for call to 'SimpleTimer::setInterval(int, void (&)())'

Please help me out here as I am doing everything according to the instructions given in the arduino playground page of SimpleTimer.

Did you install the library?

int setInterval(long d, timer_callback f) the function needs a long value, you're trying to pass an integer.

There are quite a few Arduino libraries called “SimpleTimer”. According
to arduinolibraries.info, the one you get through the
library manager is Alexander Kiryanenko's SimpleTimer. The
one described in Arduino Playground is Marcello Romani's
version. You should try the examples that come with the
specific library you install.


text:
how to combine two code of arduino uno
int mamank=13;
void setup() {
  pinMode (mamank,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  if(sensorValue>550)digitalWrite(mamank,HIGH);
  else if(sensorValue<500)digitalWrite(mamank,LOW);
  delay(100);
}

-----------------------------------------------AND this code----------------------
int red=2;
int green=3;
int blue=4;

void setup () {
  pinMode (red,OUTPUT);
  pinMode (green,OUTPUT);
  pinMode (blue,OUTPUT);
  Serial.begin (9600);}

void loop() {
  // read the input on analog pin 0:
  int value = analogRead(A1);

  if (value > 500) {
    Serial.println("Very heavy Rain");
    digitalWrite (red,HIGH);
    digitalWrite(green,LOW);
    digitalWrite(blue,LOW);}
  else if ((value > 300) && (value <= 500)) {
    Serial.println("AVERAGE Rain");
    digitalWrite (green,HIGH);
    digitalWrite (red,LOW);
    }
  else{
    Serial.println("Dry Weather");
    digitalWrite (blue,HIGH);
    digitalWrite (red,LOW);
    digitalWrite (green,LOW);
  delay(100);
  }
  }

Put the stuff before setup() together, fix any duplicates:
int mamank=13; <<< pin assignment? If yes, this can be byte
int red=2; <<< pin assignment? If yes, this can be byte
int green=3; <<< pin assignment? If yes, this can be byte
int blue=4; <<< pin assignment? If yes, this can be byte

Put the stuff in setup() together, fix any duplicates
void setup() {
pinMode (mamank,OUTPUT);
Serial.begin(9600);
pinMode (red,OUTPUT);
pinMode (green,OUTPUT);
pinMode (blue,OUTPUT);
Serial.begin(9600);  <<< duplicate, so delete this line
}

Put the stuff in loop() together, then check the desired functionality:
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
if (sensorValue>550) {
digitalWrite(mamank,HIGH);
}
else if (sensorValue<500) {
digitalWrite(mamank,LOW);
}
delay(100);
// read the input on analog pin 0:
int value = analogRead(A1);
if (value > 500) {
Serial.println("Very heavy Rain");
digitalWrite (red,HIGH);
digitalWrite(green,LOW);
digitalWrite(blue,LOW);
}
else if ((value > 300) && (value <= 500)) {
digitalWrite (green,HIGH);
digitalWrite (red,LOW);
}
else {
Serial.println("Dry Weather");
digitalWrite (blue,HIGH);
digitalWrite (red,LOW);
digitalWrite (green,LOW);
delay(100);
}

}

What happens when sensorValue is 500 to 550? No change on the output?

it change  ,which is not functioning is the one after it

Thank you this works well, thank you very much man


text:
Why does a 4 digit 7 segment cathode display wired to an Arduino not need to be connected to ground?
As a circuit neophyte I thought for a circuit to conduct current it had to be grounded.

Who says it's not connected to ground? https://majenko.co.uk/blog/what-exactly-gpio-pin

Inside the Arduino there are transistors that connect the pin to ground, when calling dititalWrite(<pinNr>, LOW).

The Uno is grounded. Current flows into the A-G and DP pins (that is: D2, D3, D4, D5, D6, D6, D8, and D9 on the Uno) when one of those pins is LOW and one of the display's digit pins is also low.
There is one "Common" pin for each of the 4 digits, labeled D1, D2, D3, and D4 on the display. Those common pins are connected to the Anodes (positive pin) of all segments in the specified digit. When 5V is applied to the base of the transistor, the NPN transistor is off. When 0V is applied to the base of the NPN transistor, current flows from the 5V source, through the transistor, and into the Anode of the digit.
When a segment pin (A-G, DP) is HIGH, it is at 5V. The Anode is also at 5V, so no current flows. When a segment pin in LOW, it s at 0V, and current flows from the Anode to Ground through the segment pin into the Uno.
This kind of display is meant to be multiplexed by digit. To light the first digit, The D1 transistor is turned on, and the segments to light up are set to LOW. All other transistors are off. Then, the first digit transistor is turned off and the 2nd digit transistor is turned on, and the segment pins are re-adjusted so that the desired output on the 2nd digit is displayed. Each digit is only on for a fraction of a second, but they are rotated through all 4 so quickly, that it gives the appearance of all 4 digits being on at the same time, without requiring 8x4=32 IO pins. Multiplexing means you only need 8+4=12 IO pins.
Search "multiplexed common anode 7-segment display" for more info.

Wonderful.  Thank you for answering my question in such detail.  You have added to my understanding on how the 4 digit seven segment display interfaces with the Arduino.

Current limit resistors are needed, one for each segment (A-G, DP) to avoid burning out the LEDs or uC IO pins:
(5V - Vce of transistor - Vf of the LED)/current = resistor value

So making some assumptions:
Vce = 0.7V in saturation (full on)

Vf = 2.5V (approx. for Red, check your datasheet)

10mA (so not blinding bright to start)

Then
(5V - 0.7V - 2.5V)/.01 = 180 ohm


text:
sensor for illegal parking detection
I want to create a system that will detect illegal parking. I will place the sensor s to specific locations and when a car parks there the system will send a message to local authorities. My question is if a PIR is the suitable sensor for this project.
thanks in advance.

probably not - because people walking would trigger it

i think that it is a suitable sensor ..... some testing would be required to make sure that it is actually suitable for the specific application .....a question remains whether the local authorities would act on the message received

really thank you for the quick response and help. Do you think that propably  ultrasonic sensor would be a better choice or a  Laser tripwire?..

I'm assuming it will be communicating wirelessly. YellowBrick used to have transmitters under the parking spot. They would send a signal (to a satellite) every minute. But when there was a car parked on top, the signal would be blocked by the car. So they would know there's a car based on the missing signal.

Another option would be machine vision: https://hackaday.com/2019/02/04/sudo-find-me-a-parking-space-machine-learning-ends-circling-the-block/

Don't get discouraged, there are many ways to do this, but I would rate a PIR as being one of the worst options because even a bird or a squirrel could set it off. Plus, once the car has stopped you can't detect it's presence anymore with a PIR sensor, it has to be moving. I would recommend either using something like a webcam and OpenCV for this or if you're set on using an Arduino and physical sensors, multiple laser or multiple ultrasonic sensors placed 5-10 feet apart so that they both have to trip at once for positive detection of a vehicle instead of something else. You're going to have to spend some time experimenting and tuning. If you want something very reliable and you own the place, you could always do what the public street works does and cut a loop into the pavement and install a large steel cable and use inductance, but that may be overkill. ;)
Some other ideas:

Paint a pattern on the ground using high contrast paint and detect
when the pattern is completely covered.  Maybe there is something you
can do with IR reflective paint and use a camera with no IR filter,
this way you could make a pattern invisible to the eyes.
A carbon monoxide detector - Detects dinosaur powered vehicles, but
is nice to the environmentally conscious.

About a decade ago now I created my own parking detection using a Raspberry Pi and a webcam and some Perl code I wrote (non-opencv). I basically just detected the shadow contrast under the car and it worked very well. Originally I tried detecting red colors in the tail lights, but this was more troublesome due to other lighting in the environment. Especially at night. In my case, I didn't have direct access to set up physical sensors and lasers would have been too intrusive, so visual analysis made sense.


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

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

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

This tutorial I found has the same wiring.

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

What perplexes me the most is the sentence

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


text:
restart counter of elapsed millis willingly with read
When I trigger high it will count for as long as I ask it while I am high then shut off. I am able to start counting again whenever I want by triggering low and going back to high and it starts from the beginning as long as the time in low is not within the time I asked it to be high. The problem is I go low mid count then quickly back to high the count picks up where millis left off without starting from the beginning. Is there a way to make this better.
unsigned long induceTime = 0;
unsigned long elapseTime;
long setTime = 10000;
int openClose;
int openClosePin = 2;
int writeToPin = 3;
void setup() {
Serial.begin(9600);
}

void loop() {
  int openClose = digitalRead(openClosePin);
  elapseTime = millis();
  if (openClose == HIGH && elapseTime < induceTime + setTime){
    digitalWrite(writeToPin, HIGH);
    Serial.println(' ');
    Serial.println(elapseTime);
    Serial.println(' ');
    Serial.println(induceTime);
    Serial.println(' ');
}
  if (openClose == LOW && elapseTime > induceTime + setTime){
    induceTime = elapseTime;
    Serial.println(elapseTime);
    Serial.println(induceTime);
}

delay(500);
}

Thanks for the help, this code is closer to what I was looking for. This is for a water level pump, when the trigger is high it turns on, when the water rises the trigger goes low and stays on during the timer as a failsafe and then turns off with when the elapsed time is greater than the set time and also not in my code it turns off with a additional trigger. Here is my working code.

unsigned long induceTime = 0;
unsigned long elapseTime;
long setTime = 10000;
int openClose;
int openClosePin = 2;
int writeToPin = 3;
void setup() {
Serial.begin(9600);
}

void loop() {
  int openClose = digitalRead(openClosePin);
  elapseTime = millis();
  if (openClose == HIGH){                //reset count
    induceTime = millis();
    digitalWrite(writeToPin, HIGH);
    Serial.println(induceTime);
}
  if (openClose == LOW){
    elapseTime = millis() - induceTime;  //induceTime is set when leave high
    if (elapseTime < setTime){
      digitalWrite(writeToPin, HIGH);
      Serial.println(elapseTime);
      Serial.println("within setTime high");
}
    if (elapseTime > setTime){
      digitalWrite(writeToPin, LOW);
      Serial.println(elapseTime);
      Serial.println("within setTime for low");
}
    Serial.println(' ');
    Serial.println(elapseTime);
    Serial.println(' ');
    Serial.println(induceTime);
    Serial.println(' ');
}
delay(1000);                              //so that I can see serial monitor
}

It's OK to accept your own answer as the solution to the problem.

First make your code rollover safe and second add an other condition:
So as I understood LOW/HIGH changes should start a timer from zero irrelevant if a running timer is over or not - so timer is still running HIGH/LOW -> and LOW/HIGH should restart
// repalce / paste before setup
unsigned long startTime = 0;
bool timerIsOn = false;
//unsigned long elapseTime;

 // replace your loopwith this
void loop() {
  int openClose = digitalRead(openClosePin);
//  elapseTime = millis();
  if (openClose == HIGH && timerIsOn = false){
       timerIsOn = true;
       startTime = millis();
       digitalWrite(writeToPin, HIGH);
       Serial.print(' ');
       Serial.print(millis());
       Serial.print(' ');
       Serial.print(startTime);
        Serial.println(' ');
   }
   // This condition is for time is up
  if (timerIsOn = true && millis() - startTime > setTime){
     digitalWrite(writeToPin, LOW);
     timerIsOn = false;
     Serial.print(setTime);
     Serial.print(' ');
     Serial.println(millis()-startTime);
  }
   // This condition is for going low before time is up
  if (openClose == LOW && timerIsOn = true){
    digitalWrite(writeToPin, LOW);
    timerIsOn = false;
    Serial.print('timerIsOn = ');
    Serial.println(timerIsOn);
    Serial.print(' ');
    Serial.println(millis()-startTime);
  }
 // If you go LOW after time is up it does nothing waits for the next HIGH
}

For starters, millis should be used relatively to avoid rollover.  Simple fix is to subtract the induceTime over to the same side of the comparison.
Example:
    elapseTime - induceTime > setTime
This also brings up the issue that your 'counter' is always elapseTime aka millis instead of (elapseTime - induceTime) so it never truly stops counting.
You are also never calling
    digitalWrite(writeToPin, LOW);
So it goes high and stays high.  I suspect you meant to set it to low in an else statement somewhere.
Now for the issue regarding quickly changing signals:
Beyond that you could use an interrupt and timer so that your sample rate (determined by the delay(500)) doesn't come into play.  This will give the best possible timing at the cost of restricting which pins you can use for openClosePin and you should also check that you sufficiently debounce the signal (in hardware).
Alternatively you can reduce the 500 to an acceptable #. But you would then want to have another counter to prevent spamming your serial output.
Below example only implements ISR and reduction of 500.  Does not implement timer (which would be required for precise use of setTime to shut the writeToPin off to LOW).
volatile unsigned long induceTime = 0;
volatile unsigned long elapsedTime;
unsigned long setTime = 10000;
//volatile int openClose; //may want to toggle this in isr...
int openClosePin = 2;
int writeToPin = 3;

void pinChangedISR(){
  if(digitalRead(openClosePin)){ //rising
    digitalWrite(writeToPin, HIGH);
    induceTime = millis();
  }
  else{//falling
    digitalWrite(writeToPin, LOW);
    elapsedTime = millis() - induceTime;
  }
}

void setup() {
  pinMode(writeToPin, OUTPUT);
  pinMode(openClosePin, INPUT); //may want INPUT_PULLUP depending on hardware
  attachInterrupt(digitalPinToInterrupt(openClosePin), pinChangedISR, CHANGE);
  Serial.begin(9600);
}

void loop() {
  static int frameCount = 0;
  unsigned long delayTime = 100;
  openClose = digitalRead(openClosePin);
  if (openClose == HIGH){
    elapsedTime = millis() - induceTime;
    if(elapsedTime >= setTime) digitalWrite(writeToPin, LOW);
    else if(setTime - elapsedTime < 100) delayTime = setTime - elapsedTime;
  }
  if(framecount >= 5){ //time to print...
    framecount = 0;
    if(digitalRead(writeToPin) == HIGH){
      Serial.println(' ');
      Serial.println(elapsedTime);
      Serial.println(' ');
      Serial.println(induceTime);
      Serial.println(' ');
    }
    else{ //this part's a bit different
      Serial.println(elapsedTime); //reporting duration of last pulse when pulse inactive
      Serial.println(millis()); //reporting current time for inducetime comparison
    }
  } else ++framecount;
  delay(delayTime);
}


text:
HC-05 Bluetooth module does not send or receive data when its on-board light blinks(light blinking after its connected to a device)
HC-05 Bluetooth module does not send or receive data when its on-board light blinks(light blinking after its connected to a device)
as soon as the on-board led starts glowing it does not send or receive data but when the light turns off it works perfectly.

do you have a question?

I have a HC-06 (which is the same chip as HC-05, just a different firmware), whose light turns off, when a device is connected. Generally the LED should show the connection state, thus only one of the LED states corresponds to a successfull connection


text:
Behaviour of tone() not as expected within while loop
I have a smoke detector with a piezo buzzer. I want to operate the arduino in low power mode so that it will last on a 9V battery. I've attached an interrupt, and when the digital output of the MQ-2 sensor goes high, it switches to a monitor function.
In the while loop, I check to see if the analog sensor has reached the threshold value, and I output to serial to see if I am in the conditional. If I use:
digitalWrite(buzzer, HIGH);

then the piezo sounds, however if I use
tone(buzzer, 1000,200);
delay(200);

it does not. I'm confused as to why this would be the case.
Full code as follows:
#include "LowPower.h"

int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
// Your threshold value
int sensorThres = 50;
int smokeD0 = 2;

void setup() {
  pinMode(redLed, OUTPUT);
  digitalWrite(redLed, LOW);
  pinMode(greenLed, OUTPUT);
  digitalWrite(greenLed, HIGH);
  pinMode(buzzer, OUTPUT);
  pinMode(smokeA0, INPUT);
  pinMode(smokeD0, INPUT);

}
void switchToMonitor() {
  Serial.begin(9600);
  int digitalSensor = digitalRead(smokeD0);
  if (digitalRead(smokeD0) == HIGH)
  {
    digitalWrite(redLed, HIGH);
    digitalWrite(greenLed, LOW);
  }
  else {
    digitalWrite(redLed, LOW);
    digitalWrite(greenLed, HIGH);
  }
  //This will be updated later to use the analog input
  //Using digital to make debugging easier
  while (digitalSensor == HIGH) {
    int analogSensor = analogRead(smokeA0);
    Serial.print("Pin A0: ");
    Serial.println(analogSensor);
    Serial.print("Pin D0: ");
    Serial.println(digitalSensor);
    // Checks if it has reached the threshold value
    if (analogSensor > sensorThres) {
      digitalWrite(buzzer, HIGH);
      //tone(buzzer, 1000,200);
      Serial.println("here");
      delay(1000);
    }
    else {
//      digitalWrite(redLed, LOW);
//      digitalWrite(greenLed, HIGH);
      noTone(buzzer);
      Serial.println("also here?");
    }
    //delay(100);
    digitalSensor = digitalRead(smokeD0);
  }
  noTone(buzzer);
}

void loop() {
  //delay(100);
  //LowPower.standby();
  attachInterrupt(0, switchToMonitor, CHANGE);
  LowPower.powerDown(SLEEP_FOREVER, ADC_ON, BOD_ON);
  detachInterrupt(0);
}

@Juraj The tone function works when used within void loop() and not switching between low power and operational. It's only not working in the code example given

connect the buzzer to a battery ... does it make a sound?

You can't use delay() or timer based tone() function in interrupt handler. Set a flag in interrupt and run the code  in loop() conditionally based on the flag state. Do not forget to have the flag variable volatile.

Took it out of the interrupt handler and it worked. Thanks


text:
MB-102 BreadBoard Power Supply Limitation

Does the MB-102 can handle Arduino Uno, SIM900 and 3 other modules that requires 5v? If yes, does 9v battery is enough? If no, please suggest me what should I use that uses only 1 barrel jack(if possible).

Im afraid that I might fry it if I try cause I dont have enough knowledge about electric currents.

breadboards can handle a few amps. the limit is the socket, not the busbar, so you can use 2+ wires per column to increase power handling or lower dropout if needed.

Does the MB-102 can handle Arduino Uno, SIM900 and 3 other modules that requires 5v?

You mean because the current requirements? The answer is yes and no. No, because the needed current must not flow through the Arduino. The SIM900 draws up to 2A, that current would fry the protection diode/voltage regulator on the Arduino (though you may get away with a bit less than that by using a big capacitor to accommodate current spikes). Depending on the version of the Uno, it can provide 200mA or 1A (in case of rev3)(including what is needed for the Uno to operate). You need to provide the 5V of these modules from outside of the Arduino, via an extra voltage regulator, which can handle the big current.

does 9v battery is enough?

If you mean the standard 9V block battery, then no, never. These batteries are meant for low power applications and are almost never a good choice for an Arduino project (unless you have really a low power application). You need to use different batteries, for example a series of AA batteries or a LiPo pack (including the needed circuitry for such a pack).

I'am connecting Arduino Uno into MB-102 power supply(usb socket) and also the other 5v modules and SIM900 so it is consider that I connect the 5v modules outside of Arduino Uno. The problem is does the MB-102 can handle that?

Yes, thats outside the Arduino. You need to google the maximum output current (or check with your supplier). This site states an output cutrrent of only 700mA. Don't know, if this os the same as yours. Also you need to make sure, that your USB port can provide enough current. USB ports of a PC only provide up to 500mA.


text:
Where are the traces connected to RESET-EN leading?
Once again, I am following this schematic, and I am confused as to where RESET-EN connects:

This is how I have it mocked up it Fritzing, but I feel like this is incorrect:

This is the DTR output of the ATmega16u2 which is connected to RESET pin of the ATmega2560 for reset by avrdude over DTR signal before upload of the sketch. There is a trace by default. Cutting the trace disables the auto-reset. Soldering a bridge on  RESET-EN pads re-enables the auto-reset.

the schematics part you quoted in question misses the long unconnected line for the RESET label. It leads here:

So this connects RESET to gnd?

not directly. this enables the USB chip (an ATmega16u2 with a firmware) to pull-down the reset pin of the ATmega2560.

So where does the other side of the trace connect in the diagram linked above?

I enhanced the answer

Ah, so the reset pin of the Atmega 2560 is connected to the reset pin of the Atmega16u2?

And also doesn't the 16u2 come loaded with firmware or would I have to flash it myself via ICSP?

The DTR output from the 16U2 is used to Reset the 328P, 2560, etc.  The 16U2 runs the USB interface program, which can be found in one of the Arduino folders.

Again, so are the reset pins of the Atmega 2560 and the 16u2 connected?

if the reset were connected the 16u2 would reset itself too while resetting the 2560.

So then where does the RESET pin of the 2560 go, and where does the RESET pin of the 16u2 go?

@3ddavies a line with a loose end and a label in electrical schematics goes to other line(s) with a loose end with the same label

to me that would mean that the two reset pins are attatched.

RESET pin of 16u2 has a line labeled RESET2


text:
Digispark clone not recognised when plugged in
When I plug in my digispark clone the computer doesn't make any sounds or some kind of acknowledgement that it has been plugged in. Anyone know why this may be or is it just a dodgy clone?

possibly not pre programmed

The Digispark does not use a "standard" USB-to-Serial chip but is dependent on a special bootloader called "micronucleus" that makes it (sort of) act like a USB device.
Below is a description of the steps you need to perform for a Windows system and the Arduino IDE.

First, you will need to install a Windows driver for Micronucleus: Zadig USB driver

If your ATTiny is recognized by Windows after performing the driver installation, then all is fine and you can skip to step 4.
If Windows still does not recognize your Digispark clone, its ATTiny processor might not have come with micronucleus pre-programmed and you need to perform steps 2 and 3. Unfortunately this is for advanced users and might be difficult if you're inexperienced with electronics and/or Arduino.

Download Micronucleus from Github
Follow This tutorial from Digispark to install micronucleus on your ATTiny. You will need another Arduino (Uno, Nano, Mega, Mega2560, ... or clone) for that.
Then follow This tutorial from Digistump to enable the Arduino IDE to program your Digispark clone directly from USB.

I assume one wants t85_default.hex for an ATTiny85 IC?

@Scott Correct, you need to download it from the Github repository (linked to by the Digispark site), or from the zip file in the 3rd step (it's under firmware/releases).

yeah I got that part and found the repository but there were about 9 or 10 hex images in there with no documention I could see as to what was what

It sounds like a driver problem.
If you are on Windows, check your Device Manager and see if the new device is detected and has proper driver installed. If it is, you should see a COM port added when you attach the board.
There are different USB chips that manufacturers use (CH340G and FT232RL, as far as I know), and not all of them have their drivers already installed on Windows.
Check your board to see what chip it is, google for the drivers and the setup procedure for your OS.
You can also check Digispark Installation Instructions and try the driver they provide.


text:
Why do NRF24L01 modules only communicate in 1 direction
I have 2 NRF24L01 +pa +lna modules connected to 2 arduino mini pros. One of the modules is on a joystick and the other one is on a airplane. Everything worked perfectly until last week when they stopped communicating. So I wrote a simple receiver and transceiver code to see if they worked. The result is that if the module on the plane is the transceiver and the joystick is the receiver everything works fine. If they have the opposite roles then I only get empty messages onto the serial monitor way more often than the transceiver sends a message.
Receiver code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8);

const byte address[6] = "00001";

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

  radio.begin();
  radio.openReadingPipe(0, address);
  radio.startListening();

}

void loop() {
  if (radio.available())
  {
    char text[32] = {0};
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }

}

Transceiver code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7,8);

const byte address[6] = "00001";

void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.stopListening();

}

void loop() {

  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));
  delay (1000);
  // put your main code here, to run repeatedly:

}

There are a lot of Chinese clones of the nRF24L01+ chips around, and some work better than others.

switch the modules around

In receiving code....try only defining variable.
char text[32];
You change the datarate , palevel and channel in nrf24l01.
See datasheet for more info.
Or visit https://howtomechatronics.com/tutorials/arduino/arduino-wireless-communication-nrf24l01-tutorial/
You may have power issue because pro mini might not deliver sufficient....to neglect use a 10uf Cap in nrf.


text:
Could not find AHT? Check wiring! How do i connect an AM2315C - Encased I2C Temperature/Humidity Sensor to a STM32F103C8T6?
am a little new at this so i sincirely need your help.
So I have a temperature & humidity sensor i got from http://www.aosong.com/en/products-70.html which is probably based on the AM2315C - Encased I2C Temperature/Humidity Sensor https://learn.adafruit.com/am2315-encased-i2c-temperature-humidity-sensor?view=all
I am trying to get it to read the temperature and humidity values, via an STM32F103C8T6 that am using as my microcontroller.
So whats going on is when i try this code:
#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;

sensors_event_t humidity, temp;
void setup() {
  Serial.begin(115200);
  if (! aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");
    while (1) delay(10);
  }
  Serial.println();
  Serial.println("Temperature C || Humidity %rH");
}
void loop() {
  aht.getEvent(&humidity, &temp);// วัดค่าอุณหภูมิและความชื้น
  Serial.print(temp.temperature);
  Serial.print("                ");
  Serial.println(humidity.relative_humidity);
  delay(1000);
}

I got from this guy on YouTube and uploaded it in my Arduino Uno; it works perfectly, tried it with my ESP 32, works flawlessly and reads accurate values, BUT when i try to use the same code with my STM32 (STM32F103C8T6) Blue Pill it says "Could not find AHT? Check wiring" probably because of this line of course
  if (! aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");
  }

I'm not sure if it's something to do with the I2C pins and how  they are defined for each board, or maybe the STM32F103C8T6 requres a different library, am not sure. By the  way i also tried adding 2 10k pull-up resistors between the SDA & SCL (AM2315C) and the SDA & SCL (STM32F103C8T6), still no change.
My pinout is as follows:
STM32F103C8T6 >> AM2315C
5v >> VDD
GND >> GND
PB6 (SCL) >> I2C SCL (White Line)
PB7 (SDA) >> I2C SDA (Yellow Line)
I need this to work for a project am doing and i would apppreciate if someone pointed me in the right direction, please let me know if i need to share more info so aid in the solving process.


text:
Error compiling for Arduino Nano 33 BLE with LiquidCrystal library
I recently started coding in the Arduino IDE for the Arduino Nano 33 BLE I bought.
When I choose the Nano 33 BLE as my board, I get the following Error:
Arduino: 1.8.11 (Windows 10), Board: "Arduino Nano 33 BLE"

In file included from C:\Users\Niels\Documents\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.cpp:1:0:

C:\Users\Niels\Documents\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.h:45:36: error: expected class-name before '{' token

 class LiquidCrystal : public Print {

                                    ^

C:\Users\Niels\Documents\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.h:86:9: error: 'Print' has not been declared

   using Print::write;

         ^~~~~

exit status 1
Error compiling for board Arduino Nano 33 BLE.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I do not get this error when compiling for a normal Arduino nano board.
This is my code:
#include <Arduino_LSM9DS1.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);

//pins:
const int measurePin = 13, calibratePin = 14, xHighPin = 15, xLowPin = 16, yHighPin = 17, yLowPin = 18;

//constants:
const int interval = 10;
const float delta = 10;

//variables:
boolean measureSts = LOW, calibrateSts = LOW, xyOK = true;
int count = 0, timer = 0;
float measurements[100], current, x, y, z, xZero, yZero, zZero;

//programm:
void setup() {
  lcd.begin(16,2);

  pinMode(measurePin, INPUT);
  pinMode(calibratePin, INPUT);
  pinMode(xHighPin, OUTPUT);
  pinMode(xLowPin, OUTPUT);
  pinMode(yHighPin, OUTPUT);
  pinMode(yLowPin, OUTPUT);
}

void loop() {
  if ( IMU.accelerationAvailable() ) {
    IMU.readAcceleration(x, y, z);
    calibrate();
    checkXY();
    measure();
    current = z - zZero;
    printValues();
  }
  else lcd.print("--geen  sensor--");
}

void checkXY() {
  xyOK = true;
  if ( x < xZero - delta ) {
    xyOK = false;
    digitalWrite(xLowPin, HIGH);
    digitalWrite(xHighPin, LOW);
  }
  else if ( x > xZero + delta ) {
    xyOK = false;
    digitalWrite(xLowPin, LOW);
    digitalWrite(xHighPin, HIGH);
  }
  if ( y < yZero - delta ) {
    xyOK = false;
    digitalWrite(yLowPin, HIGH);
    digitalWrite(yHighPin, LOW);
  }
  else if ( y > yZero + delta ) {
    xyOK = false;
    digitalWrite(yLowPin, LOW);
    digitalWrite(yHighPin, HIGH);
  }
}

void measure(){
  if ( digitalRead(measurePin) == LOW && measureSts == HIGH && xyOK ) {
    measurements[count] = z - zZero;
    zZero = z;
    timer = interval;
    count++;
  }
  measureSts = digitalRead(measurePin);
}

void printValues() {
  if ( timer >= interval ) {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Meting: " + String(measurements[count]) + (char)223);
    lcd.setCursor(0,1);
    lcd.print("Huidig: " + String(current) + (char)223);
    timer = 0;
  }
  timer++;
}

void calibrate() {
  if ( digitalRead(calibratePin) == LOW && calibrateSts == true ) {
    xZero = x;
    yZero = y;
    lcd.setCursor(0,3);
    lcd.print("kalibreren");
    lcd.setCursor(1,4);
    lcd.print("voltooid");
    digitalWrite(xHighPin, HIGH);
    digitalWrite(xLowPin, HIGH);
    digitalWrite(yHighPin, HIGH);
    digitalWrite(yLowPin, HIGH);
    delay(100);
    lcd.clear();
    digitalWrite(xHighPin, LOW);
    digitalWrite(xLowPin, LOW);
    digitalWrite(yHighPin, LOW);
    digitalWrite(yLowPin, LOW);
  }
  calibrateSts = digitalRead(calibratePin);
}

For context: I am trying to create an angle-measuring device using the built-in accelerometer and a 2x16 LCD.
I hope someone can help me fixing this.
Thanks in advance.
-Niels

try in LiquidCrystal.h to replace #include <Print.h> with #include <Arduino.h> (I don't know what LiquidCrystal library do you use. there are many)

I replaced #include"Print.h" with #include"Arduino.h" as you said. Now it works. Thanks!

The Arduino core for Nano 33 BLE is based on Mbed and can be used in Mbed as library. To achieve this, the Arduino API classes in this core are put in a namespace arduino::. This causes problems for libraries which include individual includes of Arduino API historically copied into cores for different MCU architecture platforms. The Arduino.h file includes the API files in the right way so in this case replacing #include"Print.h" with #include <Arduino.h> in LiquidCrystal.h solves the compilation problem.


text:
How can I power an ESP8266 using a 9V 1A barrel connector power supply?
I have a Huzzah Feather ESP8266 (pinout) and due to the requirements of my project, I need to supply it with a 9V power adapter with a barrel connector, such as this one.  I'm REALLY new to all of this, so I am trying to figure out how to do this and understand reading dev board specs.
It looks like this development board has a regulator that will adjust a power source down to the appropriate voltage...  but how do I know what parameters it allows?
If I'm understanding correctly, on the pinout sheet above it looks like I would connect a power supply to the "VBUS" and "GND" (right?) pins.  It also says "500mA Max", so does that mean a 1A power supply won't work?  Also, why wouldn't it specify a maximum voltage?
If just connecting a barrel connector to those pins will not work, what am I missing that would get me there?

Have you seen this forum thread?

just use a cheap buck dc-dc converter to feed it 3.3v or whatever

You cannot. If you look at the datasheet:
https://cdn-learn.adafruit.com/downloads/pdf/adafruit-feather-huzzah-esp8266.pdf
you can read all details on page 25/26:

Alternative Power Options
The two primary ways for powering a feather are a 3.7/4.2V LiPo
  battery plugged into the JST portor a USB power cable.
If you need other ways to power the Feather, here's what we recommend:

For permanent installations, a 5V 1A USB wall adapter (https://adafru.it/duP) will let you plug in a USB cable for reliable
  power
For mobile use, where you don't want a LiPoly, use a USB battery pack! (https://adafru.it/e2q)
If you have a higher voltage power supply, use a 5V buck converter (https://adafru.it/DHs) and wire it to a USB cable's 5V and GND input
  (https://adafru.it/DHu)

Here's what you cannot do:

Do not use alkaline or NiMH batteries and connect to the battery port - this will destroy the LiPoly charger and there's no way to
  disable the charger
Do not use 7.4V RC batteries on the battery port - this will destroy the board

The Feather is not designed for external power supplies - this is a
  design decision to make the board compact and low cost. It is not
  recommended, but technically possible:

Connect an external 3.3V power supply to the 3V and GND pins. Not recommended, this may cause unexpected behavior and the EN pin will no
  longer. Also this doesn't provide power on BAT or USB and some
  Feathers/Wings use those pins for high current usages. You may end up
  damaging your Feather.
Connect an external 5V power supply to the USB and GND pins. Not recommended, this may cause unexpected behavior when plugging in the
  USB port because you will be back-powering the USB port, which could
  confuse or damage your computer.

If you read the docs on that Feather board, the barrel connector is meant for a LiPo battery.
It's a 3V unit, not meant for an external power supply, and 9V is too much for it. You would need to run your 9V supply through a buck converter (or a linear regulator) and drop it down to 5V, which you could feed into the USB connector. That does mean that when you want to connect it to USB to power it it will lose power, unless you also plug a LiPo battery into the barrel connector.


text:
Trouble with 4 digit 7 segment display
So I spent a bit trying to figure the wiring and I THOUGHT I had it working but something interesting happened. Displaying works for only the numbers 1, 3, 4, 7, 8, and 9, but are weird when it comes to the numbers 2, 5, 6. I am unsure why this is happening and tbh I am pretty new to arduino.
This is how it displays 2222:

Here is the code:
#include "SevSeg.h"

SevSeg sevseg; //Initiate a seven segment controller object

void setup() {

byte numDigits = 4;

byte digitPins[] = {2, 3, 4, 5};

byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};

sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);

sevseg.setBrightness(60);

}

int timer = 1000;
void loop() {

  sevseg.setNumber(2222);

  sevseg.refreshDisplay(); // Must run repeatedly

}

Any ideas on how this might be happening?

the wrong segment is being lit probably .... unplug wires one at a time to figure out which one is causing the problem

Well one is on that is not supposed to and one that is off when it should be, but the rest of the numbers work which I dont understand.

you may have more than one pair of segments interchanged ... the picture shows segments d and e interchanged

It's a binary display: only shows zeros and ones.

It seems that segment lines b and c are interchanged. This might explain why 0, 1, 3, 4, 7, 8, and 9 look correct, because they have both segments on. 2, 5, and 6 need only one of both on.


text:
DHT11 Humidity/Temp Sensor showing incorrect values
So I am trying to use a humidity sensor with an LCD, but have run into this problem I have yet to fix. My problem is that when it is turned on, it returns the values Humidity: 255% and Temp: 255C. I know for sure that I am getting a signal from the sensor and that is working 100% (I have tested it without an LCD display). I have asked about this in the Adafruit Discord server and someone brought up the possibility of the data being clipped somewhere in the data collection/signal processing/printing chain. Still very confused about how I can fix this, I ask for help.
Here is some code:
#include <dht11.h>
#include <LiquidCrystal.h>

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

dht11 DHT;

#define DHT11_PIN 7

void setup(){
  lcd.begin(16, 2);
}

void loop()
{
  int chk = DHT.read(DHT11_PIN);
  lcd.setCursor(0,0);
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity);
  lcd.print("%");
  delay(1000);
}

Obviously the DHT sensor has not acquired data to make sure do as follows:
void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t) ) {
   lcd.setCursor(0,0);
    lcd.println("DHT not ready!");
    return;
  }
 lcd.setCursor(0,0);
  lcd.print("Temp: ");
  lcd.print(t);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.print("%");
  delay(1000);
}

Make sure you connected the DHT the right way and initialized
DTH11

    Pin1 --> 5v and 10k ohm resistor

    Pin2 --> Arduino Pin7 and 10k ohm resistor

    Pin3 --> no connection

    Pin4 --> Gnd

Initialize correctly
    DHT dht(DHT11_PIN, DHT11);

and in setup() you have to start like
 dht.begin();

Now test and report back

I checked and it is telling me it that it cant read from the sensor. I beginning to think that this might be a hardware malfunction. I tried the sensor without the LCD and it worked fine, but the addition of it gives me errors. Is there a reason for this?

See my edit above

As Codebreaker mentions, it looks like you are missing a call to  dht.begin() in your setup function (and you need to check for NAN values)

This is better because I have a visual feedback message. It just constantly says DHT not ready. It makes me think it might be a hardware issue (with the Arduino I think). I just want to rule out every other possible problem before I assume it is an Arduino hardware issue.

Have you initialized correctly See my edit DHT dht(DHT11_PIN, DHT11); AND dht.begin(); IN setup() AND check wether you use resistors see above its unlikely that the sensor is NOT working

So I tried to do the same thing, but this time I used an LCD with an I2C bus on it. It only takes two analog signal connections, 5v, and ground. I tried it with the DHT11 and it worked. I think it may be a something with connections because with the original LCD I had a lot of connections which could be interrupting the DHT11.


text:
Reading 4-20ma signal on arduino
I want to read a 4-20 mA analog signal from a 24V flowmeter. I've read the simplest way is to convert it into 1-5V signal using a 250 ohm resistor. The thing is I want my reading to be precise so my question is; is there any resolution loss when converting it to 1-5V?
I've also looked up on current to voltage converting boards similar to this one: https://www.sparkfun.com/products/14544
but I don't think they can detect 4mA signal.
I am a beginner in this so need some guidance here.

"resolution loss" compared to what?

compared to current. basically if it has enough sensitivity (to differentiate between 5mV and 15mV). 1023 (10 bit) divisions are spaced out in 4-20mA as compared to 1-5V.

10-bit divisions are only spaced between 4 and 20mA if you can somehow subtract 4mA from everything and then arrange it to work from 0-16mA. Subtracting current is hard.

Using a resistor is the "Normal" way, yes. 250Ω will give you 1-5V, yes, which means that you get 4/5 of the actual resolution of the ADC at your disposal.
That means instead of 0-1023 you're actually reading 204-1023, or 819 possible values. Spread over 16ma (or 4V, which are the same thing) that gives you about 20µA resolution.
If you really really care about that extra 1/5 of the resolution you can instead use a 300Ω resistor to give you 1.2 to 6V, then pass that through a subtracting amplifier (see this post) and subtract 1.1V from it (you need to create that 1.1V, of course).  That will give you 0.1 to 4.9V, which then covers more of the ADC's available range (20-1002, or about 16µA resolution).
Is it worth it? Probably not. Any increase in resolution will likely be swamped by the inaccuracy of the resistor and potential drift though self heating.

self-heating and resistor in-accuracy will also prevail with a 250 ohm resistor. how is that different?

@SumitMann it's not. My point is that you will be getting a tiny bit more accuracy or of a system that is inherently inaccurate.

if this is an inaccurate way, can you suggest me another way to read that analog sensor? Thanks.

https://www.maximintegrated.com/en/design/technical-documents/app-notes/8/823.html

How accurate is the flow meter?  No matter how precise or accurate you make the current to voltage conversion, or how well you utilize the Arduino native A/D resolution, you can't do any better than the flow meter's accuracy/precision?  If the flow meter is only providing +/- 10%, then I wouldn't worry too much about errors introduced by using a +/- 5% 250-ohm resistor.


text:
How can I make the Serial Monitor work with the Serial Commands library?
I am using the library SerialCommands and I am just trying to print the first text message in the Serial Monitor. But this code does not work for some reason.
The expected result is that the Serial monitor prints a message ("Hello world !!") when I write "hello" and press "enter" as input. Is there something wrong or is this not working like I was expecting? Is there another way to check if these commands work? Is there anythin that I am missing?
#include <SerialCommands.h>

char serial_command_buffer_[32];
SerialCommands serial_commands_(&Serial, serial_command_buffer_, sizeof(serial_command_buffer_), "\r\n", ",");

void cmd_hello(SerialCommands* sender) {
  sender->GetSerial()->println("Hello world !!");
}

SerialCommand cmd_hello_("hello", cmd_hello);

void cmd_unrecognized(SerialCommands* sender, const char* cmd) {
  sender->GetSerial()->print("ERROR: Unrecognized command [");
  sender->GetSerial()->print(cmd);
  sender->GetSerial()->println("]");
}

void setup() {
  Serial.begin(9600); // Serial comm begin at 9600bps
  serial_commands_.AddCommand(&cmd_hello_);
  serial_commands_.SetDefaultHandler(&cmd_unrecognized);
  Serial.println("Ready");
}

void loop() {
  serial_commands_.ReadSerial();
}

Have you chosen the correct line ending in the serial monitor?

Ah that was my mistake, thanks @chrisl. I had to chose "Both NL & CR" ("\r\n"). If you want to post it as answer I will accept it

You defined, that every command will end with \r\n. So you need to choose "Both NL & CR" as line ending in the Serial monitor, so that it appends the line ending to your command. If you don't send the correct line ending, the library will think, that the command hasn't finished yet, and thus will do nothing, until it receives the correct line ending.


text:
Serial monitor reading input strings, but cannot stop a while statement
I have just learned something called 'communication protocols' in Arduino, while I was testing this code, it appears to me that every time I input a string "YELLOW_ON" while statement works perfectly fine, however after that the serial monitor input cannot receive strings anymore. after inputting the string "YELLOW_ON", I cannot input another string which is "YELLOW_OFF" may I know why that is the case?
#include"Display.h"
const int YELLOW_LED = 7;

void setup()
{
  pinMode(YELLOW_LED, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  if (Serial.available())
  {
    INPUT_SERIAL();
  }
}

void INPUT_SERIAL()
{
  String INPUT_INFO = Serial.readStringUntil('\n');
  Serial.println(INPUT_INFO);

  while (INPUT_INFO == "YELLOW_ON")
  {
    Display.show("ON");
    digitalWrite(YELLOW_LED, HIGH);
    delay(250);
    digitalWrite(YELLOW_LED, LOW);
    delay(250);
  }
  if (INPUT_INFO == "YELLOW_OFF")
  {
    Display.show("OFF");
    digitalWrite(YELLOW_LED, LOW);
  }
}

Do you have your line endings set to "Both CR&NL" in the serial monitor?

@mejenko, what do you mean by set to both CR and NL, do you mind clarifying it?

In the Serial Monitor in the IDE there is a dropdown box that sets the "line endings". What is that dropdown box set to?

Aha! yes now I got it, it was set to a new line. However, when I changed it to both CR AND NL, the serial monitor receives input strings but does nothing ;/

Ok, New Line is what you want, actually. "CR and NL" will cause problems.

@Majenko , unfortunately if I put a new line it only works for one string and it stops receiving strings ;/

how could INPUT_INFO change in the while loop?

@Juraj Well spotted. Yes. while (INPUT_INFO == "YELLOW_ON") should really be if (INPUT_INFO == "YELLOW_ON").

@Juraj, i don't know what you mean by that, but I want the while loop to be there and I somehow want to stop it, is that possible? I want a permanent blinking of LED and then stop it by inputting a string into serial monitor

@Majenko , then there were no reason for OFF. I don't know how to answer questions with wrong logic. this sketch has so many problems. some are formal like using all uppercase for a variable name, function name etc. OP should take a coding course

From your comments:

I want the while loop to be there and I somehow want to stop it, is
  that possible?

=> yes - press the reset button.When I started programming some decades ago one of the basics was NEVER use while loops.Why? Because you might run into deadlocks like your code does. Options:

Check inside the while for a state change/input to break the while loop (worst choice)
Get rid of blocking code (while/delay() ) and work with if clauses (medium)
Get rid of blocking code (while/delay() ) and implement a state machine with switch case (better)

How to get rid of delays - IDE-file-examples-2 Digital - blinkwithoutdelay


text:
LCD not displaying any character with I2C or when used separately
I have an arduino uno and pin connection for I2C are -
SDA --> A4
SCL --> A5
VCC --> 5v
GND --> GND

This the code i am uploading taken from the examples -
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
    // initialize the LCD
    lcd.begin();

    // Turn on the blacklight and print a message.
    lcd.backlight();
    lcd.print("Hello, world!");
}

void loop()
{
    // Do nothing here...
}

The LCD shows nothing after upload . I have tried adjusting the potentiometer on I2C; just the blank characters come up.

This looks correct. You could try lcd.setCursor(0, 0) before the print. Is the backlight coming on as expected?

There is also a chance that the display is having a different address than0x27; see this answer: https://arduino.stackexchange.com/a/28508/53450

Running the I2C scanner sketch (https://playground.arduino.cc/Main/I2cScanner) would be the first thing to do to check if the I2C is detected on the bus and with which address.

Use the I2C scanner sketch to verify the I2C address of the display. I also have a non-standard LCD that has different pin mappings between the I2C module and the LCD itself, and I had to use a version of the LiquidCrystal_I2C constructor that let me specify the pin assignments.

Thank you all i found the problem, some of the pins were not properly soldered and had to use LiquidCrystal_I2C lcd(0x27, 20, 4)

Which LCD display model are you using? There are quite a few variations.

#Duncan using 2 x 16 display with I2C serial board. I am having another major issue if you guys could help.Go to https://arduino.stackexchange.com/questions/62587/esp-01-responding-to-some-codes-not-all-like-of-adafruit-mqtt?noredirect=1#comment134355_62587


text:
ATTiny85 I2C connection with Arduino Nano
I am trying to send and receive data using I2C between an Arduino Nano and an ATTiny85.
The ATTiny is mounted on this board:
Link
I've tried to reach the slave with the simple I2C scanner, but I don't find anything.
Those are the codes:
Master (I2C scanner):
// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

void setup()
{
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}

void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(500);           // wait 5 seconds for next scan
}

And this is the code of the ATTiny85 (slave):
#include <TinyWire.h>

#define led_pin 1

byte own_address = 10;

void setup() {
  // config led_pin as Output for driving an LED
  pinMode(led_pin, OUTPUT);

  // config TinyWire library for I2C slave functionality
  TinyWire.begin( own_address );
  // sets callback for the event of a slave receive
  TinyWire.onReceive( onI2CReceive );
}

void loop() {

}

/*
I2C Slave Receive Callback:
Note that this function is called from an interrupt routine and shouldn't take long to execute
*/
void onI2CReceive(int howMany){
  // loops, until all received bytes are read
  while(TinyWire.available()>0){
    // toggles the led everytime, when an 'a' is received
    if(TinyWire.read()=='a') digitalWrite(led_pin, !digitalRead(led_pin));
  }
}

Once I've programmedo both the boards I've connected SCL and SCK pins of the boards together.
If i open the serial monitor of the master this is what i get:

I2C Scanner Scanning... Unknown error at address 0x20 Unknown error at
  address 0x21 No I2C devices found
Scanning... Unknown error at address 0x78 No I2C devices found
Scanning... No I2C devices found
Scanning... Unknown error at address 0x08 Unknown error at address
  0x09 Unknown error at address 0x60 No I2C devices found
Scanning... Unknown error at address 0x70 No I2C devices found

And so on.
Can someone explain me were I'm doing errors?

did you wire ground together?

@Juraj you're right, i've forgot to wire them to the same ground.
But now i only read
"No I2C devices found"

Problem solved!
I've modified the code, this is the final one:
#include <TinyWire.h>

#define led_pin 1
#define I2C_SLAVE_ADDR  0x11

void setup() {
    // config led_pin as Output for driving an LED
    pinMode(led_pin, OUTPUT);

    // config TinyWire library for I2C slave functionality
    TinyWire.begin( I2C_SLAVE_ADDR );
    // sets callback for the event of a slave receive
    TinyWire.onReceive( onI2CReceive );
}

void loop() {

}

/*
I2C Slave Receive Callback:
Note that this function is called from an interrupt routine and shouldn't take long to execute
*/
void onI2CReceive(int howMany){
    // loops, until all received bytes are read
    while(TinyWire.available()>0){
        // toggles the led everytime, when an 'a' is received
        if(TinyWire.read()=='a') digitalWrite(led_pin, !digitalRead(led_pin));
    }
}

Like this the I2C scanner sees the board at the address 0x11.
The wirings are the following:

Arduino pin SCL to ATTiny85 pin SCL (P2)
Arduino pin SDA to ATTiny85 pinSDA  (P0)
Take care of wire to the same ground both the boards.

The I2C address is 7 bits long, followed by the direction bit. So 10 or 11 are the same address but the direction bit is different. 0x10 is reserved address. https://www.i2c-bus.org/addressing/

@Juraj Your are right in the address being 7 bits long. But the address for the TinyWire library (and also the Wire library) does not include the direction bit. It is added to the address byte by the library depending on the used functions. So 10 and 11 are not the same address here.

@chrisl, yes. decimal 10 is very different from 0x11

Also 0x11 and 0x10 are not the same address, since this does not include the direction bit

@chrisl, how would you set the direction bit on 0x10 and 0x11 to be different addresses?

You don't set the direction bit here. The OP uses the Wire libraries. The address, that you use with any of their functions does not include the direction bit. The libraries use the lower 7 bit of the provided address and builds the I2C address byte by shifting the provided address one bit to the left and setting the least significant bit (which is now zero) to the correct value depending in the requested operation. The address value, that is used in the sketch is not identical with the I2C address byte. The addresses will be converted to I2C address byte like 0x20/0x21 and 0x22/0x23


text:
Help with sending data to MIT app inventor through bluetooth

I'm trying to connect my arduino bluetooth sensor to an MIT App Inventor app I made, and in doing so display the readings of two of my sensors. Whenever I test the sensors in the serial monitor, I get normal readings, but sending them to MIT APP Inventor makes them glitch out and give me the error "Select list item: Attempt to get item number 2 of a list of length 1". I've reviewed all of my code for both the Arduino and the MIT App Inventor, and I haven't been able to find anything that may be hindering me. The timer interval for the MIT App inventor code is correct.
My Arduino code is below; the MIT app inventor code is shown in the above image
#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.

//  Variables
const int PulseWire = A1;       // PulseSensor PURPLE WIRE connected to ANALOG PIN A1
int Threshold = 550;           // Determine which Signal to "count as a beat" and which to ignore.
                               // Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
                               // Otherwise leave the default "550" value.
const int PIEZO_PIN = A0; // Piezo output

PulseSensorPlayground pulseSensor;  // Creates an instance of the PulseSensorPlayground object called "pulseSensor"

void setup() {
  Serial.begin(9600);          // For Serial Monitor
  // Configure the PulseSensor object, by assigning our variables to it.
  pulseSensor.analogInput(PulseWire);
  pulseSensor.setThreshold(Threshold);
  }
void loop() {
  int piezoADC = analogRead(PIEZO_PIN); //Get the analog value of the Piezo sensor
  float piezoV = (piezoADC / 1023.0 * 5.0);  //Get the voltage of the Piezo sensor
  int myBPM = pulseSensor.getBeatsPerMinute(); //Get the BPM detected of the user

  Serial.print((double)piezoV); // Print Piezo voltage

  Serial.print("|"); //Use this character to separate the vibration from the heartbeat

  if (pulseSensor.getBeatsPerMinute() == 0){
  Serial.println("N/A");
 }
 else{
  Serial.println((int)myBPM); //Print the BPM
 }
  delay(5000);

}

the split text at "|" ... is that "|" or " | "?

The split text is |, not an capital i or a lowercase L. The thing where you click shift and the backslash key.

start by writing a minimal sketch that sends a single fixed byte every 5 seconds or so. ..... write an app to receive that byte

I'm not asking if it's "l" or "I" or "1" - I'm asking if it's "|" or " | " .... the difference being SPACES

Ah, I'm sorry. No spaces, its just "|"

My guess is that BytesAvailableToReceive > 0 is true after Serial.print((double)piezoV) but before Serial.print("|") ... hence the issue ... try changing your input processing to only process input once it receives end-of-line ... i.e. \n .... alternatively Serial.printf("%f|%s\n", (double)piezoV, myBPM ? "N/A" : String(myBPM)); may work for you

I'm sorry, but I'm a bit new to Arduino and I don't quite understand how I would change the example code you gave me to put it into my sketch. I understand the issue you're pointing out, though. Could you please rephrase the code somewhat? Again, I'm sorry and I hope this won't annoy you too much.
EDIT: It's because whenever I paste your code into my sketch, it gives me the error "HardwareSerial has no member named printf", despite working with different inputs.

Scratch that, printf never works.

To clarify on what I meant by the first comment: putting the example code you gave me into the sketch causes a lot of errors, so I was wondering if you could please reformat it so it would work with the code without any issues?

oh ... I'm spoiled by having printf on ESP8266 Arduino :p - if you can't print using printf then use char buffer[80]; sprintf(buffer, "%f|%s\n", (double)piezoV, myBPM ? "N/A" : String(myBPM)); Serial.print(buffer); perhaps

The error still occurs; perhaps I need to place it in a specific place in the code, or do I maybe have to replace something?

Yeah, I'd say the only fix is to make sure the receiving side doesn't "parse" the received data until it gets all of it

How would I do such a thing? I tried editing the MIT App Inventor so that it would only display the data if the length of the list was 2 (the amount of individual readings I should get), but instead the app now never shows the data, almost like it's not receiving readings at all.

Another thing: I think I might be able to use the solution you gave me, I just need to know where I should place that line of code and what I should replace with it.


text:
Initializing variables of a function
By playing with some examples I found the following construct:
void Show(int nav = 0) // -1 top, 1 bottom
and I wondered what effect it has to initialize the handover parameters in the function declarations, I never noticed such an construct consciously.
So I made a small demo:
#include <M5Stack.h> //necessary for my board
  int a;
  int b;
  int c;

int addFunction(int x = 3, int y = 3){
  int result;
  result = x + y;
  return result;
}

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

  // testcase 1
  a = 1;
  b = 2;
  c = addFunction(a, b);
  Serial.println("testcase 1:");
  Serial.println((String)a + " + " + b + " = " + c);

   // testcase 2
  a = 1;
  b = 2;
  c = addFunction();
  Serial.println("testcase 2:");
  Serial.println((String)a + " + " + b + " = " + c);

   // testcase 3
  a = 1;
  b = 2;
  c = addFunction(a);
  Serial.println("testcase 3:");
  Serial.println((String)a + " + " + b + " = " + c);
}

void loop() {
}

The output was:

So I learnd:

if you hand over parameters, the initialization is ignored, if you call the function without handing over paramters, the functions works with the init values.
if you handover only one parameter it will be assigned to the first in the declaration.

Question:
Is there a syntax possible to only call the function with the second parameter, so that for the first paramter the intialized value of the declaration is used? Spoken for this example with a = 1, b = 2 you only handover b and the expected result would be 5.

Should a single parameter always be for the second parameter (add a overloaded function) or do you want to choose for which parameter?

It is just a general question to understand the syntax.  So I would be interested in an answer of how to do it in general, which means also with more parameters and the possiblity to choose any parameter depending on the purpose (m out of n)

An overloaded function is one option to be able to accept different number of parameters. A pointer can be made nullptr (or NULL) and in the code you could check for nullptr. There must be other options as well.

@Jot tanks for the hint.  I had a look into that, I guess this is for my not working, since x and y are of the same type. I will check if I get it working, maybe with different types.

This is (unfortunately) not an Arduino question. It is actually about the syntax of C++ which is a rather complex language.
The mechanism you have discovered is called default arguments. The function prototype or definition may contain the default values of the arguments. As this is a list the default values are restricted from right to left. It is not possible to use a default parameter for argument to the left of a given argument. The order is strictly right to left.
f(int x = 0, int y = 1, int z = 2)

f(1,2,3) binds x = 1, y = 2, z = 3
f(1,2) equals f(1,2,2) binds x = 1, y = 2, z = 2
f(1) equals f(1,1,2) binds x = 1, y = 1, z = 2
f() equals f(0,1,2) binds x = 0, y = 1, z = 2

There is a syntax for struct initialization (aka aggregate initialization) in C++ that allows naming of struct field values. This type of naming is not allowed for function calls.
Please read https://en.cppreference.com/w/cpp/language/default_arguments, https://en.cppreference.com/w/cpp/language/aggregate_initialization and https://en.cppreference.com/w/cpp/utility/functional/bind for more details. And a good C++ book.
There are languages that allow default arguments and named parameters e.g. C#, Python, Ruby and Smalltalk. Please see https://en.wikipedia.org/wiki/Named_parameter.
Cheers!
(Update)
Below is a rewrite of @VE7JRO Add function class using cast operator to perform the evaluation:
class Add
{
public:
  Add(int x, int y) : m_x(x), m_y(y) {}
  operator int() { return m_x + m_y; }
  void x(int x) { m_x = x; }
  void y(int y) { m_y = y; }
  int print(Print& outp) {
    int res;
    res = outp.print(F("Add(x="));
    res += outp.print(m_x);
    res += outp.print(F(",y="));
    res += outp.print(m_y);
    res += outp.print(F(")"));
    return res;
  }
private:
  int m_x, m_y;
};

Add func(1,2);

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

  func.print(Serial);
  Serial.print(F("="));
  Serial.println(func);

  func.x(12);
  func.print(Serial);
  Serial.print(F("="));
  Serial.println(func);

  func.y(13);
  func.print(Serial);
  Serial.print(F("="));
  Serial.println(func);
}

void loop() {
}

Good explanation and material for further Investigation, thanks also for the extension of @VE7JRO, adds some more interesting details for me. (after I checked that you are using a different baud rate ;-))

Missed the baud rate difference. Changed that to avoid confusion, debugging, etc, between the sketches.

BW: If the member data is made public the syntax func.x = 12 would be allows (after removing the prefix m_).

If your function is inside a class, you can set either variable, both variables or use the defaults.
class Add{

    int a, b;

  public:

    Add(): a(1), b(2){}

    int AddTwoIntegers(){
      return a + b;
    }

    void SetInt1(int int1){
      a = int1;
    }

    void SetInt2(int int2){
      b = int2;
    }

};

Add Test1;

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

  Serial.print("Test default values = ");
  Serial.println(Test1.AddTwoIntegers());

  Test1.SetInt2(4);
  Serial.print("Set b = 4 then add to a = ");
  Serial.println(Test1.AddTwoIntegers());
}

void loop(){}

got it, thanks for the example, helped me a lot in understandig while trying it out


text:
Arduino bluetooth HC-05 data reading problem
I have a problem with bluetooth module HC-05 and servos. If I type in bluetooth terminal 4,1 I want that servo1 turns 60 degrees 3 times. Briefly servo1 turns 60 degrees and then servo2 goes 180 and turns back and again servo1 turns 60 degrees and so on.
The bluetooth mixes the numbers. If I type "1" it gives me "49" and that's why the system is not working properly. How do I fix this data problem?
#include <Servo.h>
#include <SoftwareSerial.h>

Servo myservo1;
Servo myservo2;
long players, cards;
int pos1 = 0;
int pos2 = 0;
int servo;
int pos = 0;
int deal = 0;

SoftwareSerial BT(2,3);

void setup() {
  Serial.begin(9600);
  BT.begin(9600);
  myservo1.attach(10);
  myservo2.attach(11);
  servo = 90;

}

void loop() {
  if(BT.available()>0) {
    players = BT.read();
    cards = BT.read();

    Serial.println(players);
    Serial.print(cards);

    pos = 180/(players-1);
    for(deal = 0; deal < cards; deal++) {
      for (pos1 = 0; pos1 <= 180 ; pos1 += pos ) {
          delay(20);
          myservo1.write(pos1);

          for (pos2=0; pos2<=180 ; pos2 +=1){
            myservo2.write(pos2);
            delay(10);
          }

          for (pos2=180; pos2>=0 ; pos2 -=1){
            myservo2.write(pos2);
            delay(15);
          }

    }
      for (pos1 <= 180; pos1 >= 0; pos1 -=1 ) {
          pos2=0;
          myservo1.write(pos1);
          delay(10);
      }
    }

  }
}

You are mixing ASCII characters and integer values.
The serial data is a pure binary stream, a series of bytes. It is up to the programs on both sides to interpret, how these bytes are meant. When you type 1 into your bluetooth serial app, it already does this. It complies to the ASCII standard, which gives a meaning to every binary value between 0 and 127. Google "ASCII" to get a table of the mapping. Each character (alpha numeric and some special characters and control characters) has a binary value associated with it. That way we can interpret a binary data stream as text.
The ASCII character 1 corresponds to the decimal value 49. You are saving the read byte from the bluetooth serials as long, which is a big integer. So, when you are printing it, you will see the decimal value, which is 49.
What to do now? The easiest way is to subtract the ASCII value of '1' from the received byte:
players = BT.read() - '0';

'0' is the C/C++ representation of a single ASCII encoded character. It's the same as subtracting the decimal value 48, but it's a bit clearer to see, what happens here. We are shifting the numbers row (0 to 9) from position 48 to position 0. That way the ASCII '0' is transformed to a decimal 0, the ASCII '1' to a decimal 1, and so on up to 9.
Note: You might want to make sure, that only numbers are used for these variables, as the principle will result in garbled data, when the user inputs some other characters. You would need to read the binary data into a temporary variable (here called c) and then check, if they are numeric. Either by hand:
if(c >= '0' && c <= '9')

or by a convinient function
if(isDigit(c))


text:
Multidimensional array with date and numbers
I would like to create something similar to a multidimensional array.
I would like to get this effect.
setting = [
     0 => [// 0 is the day of the week, but it can be a number
         '1:25' => 25, // key is time. The value is a number (temperature)
         '7:12' => 22,
         '15: 30 '=> 21,
         '18: 00 '=> 23
         '22: 25 '=> 22
     ]
     1 => [
         '1:25' => 25,
         '7:00' => 21,
         '15: 00 '=> 22,
         '18: 00 '=> 25
         '22: 25 '=> 22
     ]
     2 => [
         '1:25' => 25,
         '7:00' => 21,
         '15: 32 '=> 21,
         '18: 40 '=> 25
         '22: 25 '=> 22
     ]
     .
     .
     .
     e.t.c
];

Then I would like to read these values. Days of the week and time are already downloading, but I do not know how to make such a board. I would like to download these values (temperature) to a variable.
Regards

what board are you talking about?

What exactly are you trying to do? It seems like you are suffering from an XY Problem and you're trying to solve a problem that stems from you trying to solve a different problem in the wrong way.

@jsotola Excuse me. I dealt with the project for work and forgot about my problem. I want to do this on Arduino UNO.

@Majenko This is not a problem of this type. The question is how to make such an array and how to read such values afterwards.

I would say you don't want to make an array like that.

@Majenko It may be different. I will download the temperature and the current time. I will fire the relay by time and temperature. I am taking the current time and temperature all the time. At 12 o'clock, if the temperature is less than 22 degrees, I would like the relay to turn on and heat until it reaches 22 degrees. By 16 o'clock I would like the relay to turn on when the temperature is less than 20 degrees, etc. And that's why I'm asking how to make such an array.
Regards

Then you should investigate struct and arrays (of fixed size) or linked lists (for variable size - not recommended on small Arduinos).

It just combines with struct, but I don't know how to "rewrite" the array I wrote in the first post to struct.


text:
Sound quality is poor using a piezo in TinkerCad
I did a quick search and couldn't seem to find this question posted already, but I'm sure it must have so forgive me if it's a repeat.
I'm using a piezo and Arduino on TinkerCad to produce notes using the tone function, and the quality is not great (it's as if I can hear beats while the note is playing). I vaguely remember a colleague telling me this was an issue with the way my computer speakers handle square waves (I have a Macbook Air if that makes any difference), but I'm not positive. Has anyone had success in using TinkerCad to produce nicer sounding notes? If not, can anyone explain what the issue is to me?
Thank you!

Seems to be more a Tinkercad problem, than an Arduino problem

Tinkercad is a simulation. It's merely an approximation of how an Arduino works. You can't expect it to be perfect. A bit of glitchiness in sound is nothing to even think about caring about.

To pack the comments into a proper answer to the question:
As Majenko stated in the comments, Tinkercad is a simulation. The codes doesn't get compiled and uploaded to hardware. Instead Tinkercad interprets the code on the fly. Simulations are not perfect clones of the real hardware, so you cannot expect the same performance from it as from the real Arduino. Also it is not build for producing high quality sound. The focus is entirely on simulating how the Arduino works.
If you are using this with a real Arduino you most likely will not have the glitches in sound.
What you are currently hearing is not a problem of Arduino, but of Tinkercad. You could file a problem with the developer, but probably they will not think this is an issue, or they will give it a very low priority.


text:
Arduino voltage connection pins
On the Arduino power connector jack, which is the positive terminal pin and the negative pin?

Center-positive. On the UNO there is a diode, to protect against wrong polarity.

Here is more info about Arduinos power jack, https://learn.adafruit.com/ladyadas-learn-arduino-lesson-number-0/power-jack-and-supply

Arduino's power connector jack's tip is positive while the sleeve is negative but the more important thing to know is what will you be using in powering Arduino? Please provide more information about your setup and possibly a schematic. This will help us understand more what you're trying to accomplish.


text:
On ATtiny84, why does delay() stop working properly when RadioHead ASK is used?
When I call the delay() function on the ATtiny84 micro, it delays for the expected time, until I call the init() function on an RH_ASK object. After this, the micro seems to freeze.
#include <RH_ASK.h>
RH_ASK driver();

void setup() {
    delay(100); // works ok
    driver.init();
    delay(100); // freezes a long time (or maybe forever?)
}

After reading the source code, RH_ASK.cpp, I found a commented out macro.
// RH_ASK on ATtiny8x uses Timer 0 to generate interrupts 8 times per
// bit interval. Timer 0 is used by Arduino platform for millis()/micros()
// which is used by delay()
// Uncomment the define RH_ASK_ATTINY_USE_TIMER1 bellow, if you want to use
// Timer 1 instead of Timer 0 on ATtiny
// Timer 1 is also used by some other libraries, e.g. Servo. Alway check
// usage of Timer 1 before enabling this.
// Should be moved to header file
//#define RH_ASK_ATTINY_USE_TIMER1

In other words, the default behaviour of RadioHead ASK init() is to use Timer 0, which causes delay() (which uses millis()/micro()) to behave incorrectly.
To fix: Tell RadioHead ASK to use Timer 1. Because the RH_ASK_ATTINY_USE_TIMER1 macro is in the source and not the header (for now), you have to modify the actual RadioHead ASK source file, RH_ASK.cpp*. Un-comment the line #define RH_ASK_ATTINY_USE_TIMER1 which will use Timer 1 instead of Timer 0. Re-compile your code, and delay() should start working properly again.
* RH_ASK.cpp can be found in %USERPROFILE%\Documents\Arduino\libraries\RadioHead on Windows, if you installed RadioHead via the Arduino IDE library manager.


text:
Detecting the difference between a deep sleep wake signal and a manual wake button press
When my ESP8266 wakes itself from sleep (i.e. D0 sends wake signal), I want it to do something different to when I manually wake the device with the reset button.
I have the RST and D0 pins connected, so that the device can wake itself from sleep. I also have a button connected to RST which pulls to ground when pressed, so that I can wake the device manually on demand.
How do I differentiate between the device being awoken by itself, or manually by the button press?
I tried using system_get_rst_info/getResetInfoPtr to determine what action has awoken the device, but it seems that if I reset manually after the device went to sleep, the REASON_DEEP_SLEEP_AWAKE reason is returned since that value is based on how the device went to sleep/reset rather than how it woke up.
Disclaimer: I already found a solution (answer below), but it's more complex than I wanted, so I am posting this question to see if anyone else can think of a simpler solution.

if you use ntp, you could cache the expected wakeup time in rtc ram or even spiffs and compare the stored value with the established time upon reboot. If you happen to manually reset right on schedule it would mis-report, but that should be rare and you have a work-around if such precision is needed.

Oh that's a good idea!

was thinking; if you subtract millis() from the net time upon reboot, you can get a really good idea of the utc time of reset by eliminating the wifi connection time. With logging you might also realize it takes say 10ms to reset, and add that into your formula to get it even more accurate/precise.

I came up with two solutions (3 if you count the combo), both involve connecting the manual reset button to another pin on the MCU (so I can check if it's still pressed when starting).
Solution 1: Generate a reset pulse
The problem with the manual reset button is that it's only on release that it resets, since while the RST pin is held low, the MCU won't start.
To solve this, I used a positive edge monostable circuit to pulse the RST pin when the manual reset button is pressed down.
That way, I can hold the button down and the device starts. In the setup() function, I can check if the button is still pressed.
Solution 2: Use an RC delay circuit
I also considered that I could simply wake the device on button release, and use a debounce cap (very slow discharge) to see if the button was pressed in the last second (by checking the pin on the MCU to which the charged cap is connected).
Solution 3: A combination of 1 & 2
Combining 1 and 2, allowed me to wake the device on button down, and use the debounce cap to see if the button was pressed recently (in the last second).