text:
anyone heard of MCUDEV_TFT1.44 display? I can't figure out how to connect it to Arduino
I bought this tft display on Aliexpress:
https://www.aliexpress.com/item/1005001579367288.html?spm=a2g0s.9042311.0.0.72164c4doyqAub
it says "MCUDEV_TFT1.44" below the display.

I can't find online how to connect it to Arduino.
The pins are as follows:
BLK RS RST CS SC DI GND VCC
on Aliexpress it says "Drive IC: ST7735" but I googled ST7735 displays and they have different pins.
Anyone has any idea?
Thanks!

BLK is probably Back Light (K)Cathode. RS is Register Select. RST is RESET. CS is Chip Select. SC is SCK. DI is MOSI.

@Majenko THANK YOU! I made it work :)

can you share you setting anh scheme connect

@DầuĐậuPhụ I posted it as an answer if you are still interested

If anyone else have the same display and wondering how to make it work, here is how I connected and the script I used.
I couldn't find my display model so I just used this in Fritzing and added the pins names as a note.

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <SPI.h>

#define TFT_CS        10
#define TFT_RST        9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC         8

#define TFT_MOSI 11  // Data out
#define TFT_SCLK 13  // Clock out

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

float p = 3.1415926;

void setup(void) {
  Serial.begin(9600);
  Serial.print(F("Hello! ST77xx TFT Test"));

  // OR use this initializer (uncomment) if using a 1.44" TFT:
  tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab

  Serial.println(F("Initialized"));

  uint16_t time = millis();
  tft.fillScreen(ST77XX_BLACK);
  time = millis() - time;

  Serial.println(time, DEC);
  delay(500);

  // large block of text
  tft.fillScreen(ST77XX_BLACK);
  testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE);
  delay(1000);

  // tft print function!
  tftPrintTest();
  delay(4000);

  // a single pixel
  tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN);
  delay(500);

  // line draw test
  testlines(ST77XX_YELLOW);
  delay(500);

  // optimized lines
  testfastlines(ST77XX_RED, ST77XX_BLUE);
  delay(500);

  testdrawrects(ST77XX_GREEN);
  delay(500);

  testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
  delay(500);

  tft.fillScreen(ST77XX_BLACK);
  testfillcircles(10, ST77XX_BLUE);
  testdrawcircles(10, ST77XX_WHITE);
  delay(500);

  testroundrects();
  delay(500);

  testtriangles();
  delay(500);

  mediabuttons();
  delay(500);

  Serial.println("done");
  delay(1000);
}

void loop() {
  tft.invertDisplay(true);
  delay(500);
  tft.invertDisplay(false);
  delay(500);
}

void testlines(uint16_t color) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, 0, x, tft.height()-1, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, 0, tft.width()-1, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, 0, 0, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(0, tft.height()-1, x, 0, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
    delay(0);
  }

  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
    delay(0);
  }
  for (int16_t y=0; y < tft.height(); y+=6) {
    tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
    delay(0);
  }
}

void testdrawtext(char *text, uint16_t color) {
  tft.setCursor(0, 0);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(text);
}

void testfastlines(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t y=0; y < tft.height(); y+=5) {
    tft.drawFastHLine(0, y, tft.width(), color1);
  }
  for (int16_t x=0; x < tft.width(); x+=5) {
    tft.drawFastVLine(x, 0, tft.height(), color2);
  }
}

void testdrawrects(uint16_t color) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
  }
}

void testfillrects(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST77XX_BLACK);
  for (int16_t x=tft.width()-1; x > 6; x-=6) {
    tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
  }
}

void testfillcircles(uint8_t radius, uint16_t color) {
  for (int16_t x=radius; x < tft.width(); x+=radius*2) {
    for (int16_t y=radius; y < tft.height(); y+=radius*2) {
      tft.fillCircle(x, y, radius, color);
    }
  }
}

void testdrawcircles(uint8_t radius, uint16_t color) {
  for (int16_t x=0; x < tft.width()+radius; x+=radius*2) {
    for (int16_t y=0; y < tft.height()+radius; y+=radius*2) {
      tft.drawCircle(x, y, radius, color);
    }
  }
}

void testtriangles() {
  tft.fillScreen(ST77XX_BLACK);
  uint16_t color = 0xF800;
  int t;
  int w = tft.width()/2;
  int x = tft.height()-1;
  int y = 0;
  int z = tft.width();
  for(t = 0 ; t <= 15; t++) {
    tft.drawTriangle(w, y, y, x, z, x, color);
    x-=4;
    y+=4;
    z-=4;
    color+=100;
  }
}

void testroundrects() {
  tft.fillScreen(ST77XX_BLACK);
  uint16_t color = 100;
  int i;
  int t;
  for(t = 0 ; t <= 4; t+=1) {
    int x = 0;
    int y = 0;
    int w = tft.width()-2;
    int h = tft.height()-2;
    for(i = 0 ; i <= 16; i+=1) {
      tft.drawRoundRect(x, y, w, h, 5, color);
      x+=2;
      y+=3;
      w-=4;
      h-=6;
      color+=1100;
    }
    color+=100;
  }
}

void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(0, 30);
  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(1);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_YELLOW);
  tft.setTextSize(2);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_GREEN);
  tft.setTextSize(3);
  tft.println("Hello World!");
  tft.setTextColor(ST77XX_BLUE);
  tft.setTextSize(4);
  tft.print(1234.567);
  delay(1500);
  tft.setCursor(0, 0);
  tft.fillScreen(ST77XX_BLACK);
  tft.setTextColor(ST77XX_WHITE);
  tft.setTextSize(0);
  tft.println("Hello World!");
  tft.setTextSize(1);
  tft.setTextColor(ST77XX_GREEN);
  tft.print(p, 6);
  tft.println(" Want pi?");
  tft.println(" ");
  tft.print(8675309, HEX); // print 8,675,309 out in HEX!
  tft.println(" Print HEX!");
  tft.println(" ");
  tft.setTextColor(ST77XX_WHITE);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setTextColor(ST77XX_MAGENTA);
  tft.print(millis() / 1000);
  tft.setTextColor(ST77XX_WHITE);
  tft.print(" seconds.");
}

void mediabuttons() {
  // play
  tft.fillScreen(ST77XX_BLACK);
  tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
  delay(500);
  // pause
  tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);
  tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN);
  delay(500);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE);
  delay(50);
  // pause color
  tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
  tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
  // play color
  tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN);
}```

LIBRARIES:

Go to Sketch -> Include Library -> Manage Libraries
Search for Adafruit GFX Library and install the latest version and install all the dependencies as well when it asks
Search for Adafruit ST7735 and ST7789 Library and install the latest version and install all the dependencies as well when it asks


text:
Arduino Nano Every I2C PORTMUX
Arduino Nano Every schematic informs us that we can use ATMega4809's pins PF03 and PF02 to communicate via I2C.
ATMega4809 manual says in page 19 that in order to use those pins as I2C we need to use PORTMUX.
I'm not really an expert and I don't understand how to do that.
Any help would be approciated.

In the Nano Every schematic, PF2 and PF3 are connected over to PA2 and PA3 respectively.  That is, Arduino pin A5 and ATMega4809 pins PF03 and PA03 are connected together by PCB traces such that there's no distinction between them, PF03 doesn't have its own header pin anywhere distinct from PA03.  They're both A5.  Likewise for Arduino pin A4 and ATMega4809 pins PF02 and PA02.
The Nano Every was designed to be compatible with the original Nano boards that used the ATMega328P.  On these boards the A5, analogRead-capable pin, is also the I2C/Wire clock signal.  Likewise,
A4, analogRead-capable pin, is also the I2C/Wire data signal.
On the ATMega4809 the I2C/Wire Master/Slave signals on PORTA routed to the A5 and A4 pins are not also analogRead-capable.  That is, they are not connected to the analog-to-digital converter in the chip as they were in the Atmega328P on the old Arduino Nano boards.
To mirror the workings of the original Nano, where A4 and A5 were both analogRead pins and I2C/Wire Master/Slave pins, they connected A4 and A5 to pairs of ATMega4809 pins.  One of these pins on PORTF is connected to make the Arduino pin analogRead-capable and the other pins on PORTA are connected to make the Arduino pin Wire/I2C Master/Slave capable.  In other words, they used two AVR pins to synthesize a single Arduino pin capable of both functions that were available on that pin on the older Nano boards.
When it comes to using PORTMUX to switch choice of I2C pins, practically speaking, you won't be able to if you're looking to get alternate pins for TWI Master.  PORTMUX lets you switch the I2C Master/Slave or just Master peripheral onto pins PC2 and PC3 instead of PA2 and PA3.  But, in the Nano Every schematic, you can see these are not connected to anything.  So if you wanted to do that, it would mean something like soldering wiring-wrap wire directly to the MCU pin, which would be difficult.  And PC2 and PC3 are the only two other ATMega4809 pins that PORTMUX will route the hardware I2C Master/Slave peripheral to.    So, practically speaking, if you want I2C any pins other than A4 and A5 on a Nano Every, it means using a software (bit-banged) implementation of I2C.
You asked (in comments) about the TWI support indicated on PF2 and PF3 in the ATMega4809 datasheet.  I think I'd either been looking at an older datasheet or maybe disregarded those pins because of how they're hardwired over to PORTA on the Nano Every.  The ATMega4809 has a "Dual TWI" mode apparently, where you can have just master mode on the pins that are normally both, and just slave mode on an alternate set of pins.  In two configurations of PORTMUX under Dual TWI, the PF2 and PF3 are where the slave-only capability of the peripheral are broken out.  With PORTC's TWI pins unconnected and PORTA's TWI pins hardwired to PORTF's TWI pins, it's unclear to me what advantage you could get out changing PORTMUX on an Arduino Nano Every.

Ok, thanks for the info. Even so, how can I force the I2C communication to use pins PF2 and PF3 instead of PA2 and PA3?

I probably wasn't clear enough in this part.  In the Nano Every schematic, you can see that those pins are hard-wired together.  That means, for example, Arduino pin A5 and ATMega4809 ports PF03 and PA03 are all the same node in the circuit connected together with copper traces.  That is the significance of having the A5/SCL label applied to all three things.

I understand that. I know that they are both connected but I'm doing some tests and I want to test an I2C communication from PF2 and PF3 pins. I think that it must be a way to swap the pins that will be used by, for example, the Wire library. That is what I'm searching for.

I get the impression that there's still something I haven't made clear.  I did go back and reword things to try to things more direct, specifically that there are only two sets of pins that can have the I2C hardware support routed to, and only one of those sets is soldered to the chip.  This is something I updated in the last paragraph.

Ok, thanks. But in that case why does the ATMega4809 datasheet informs in page 19 that PF2 and PF3 are I2C capable?

Interesting, I think I've been looking at several different editions of the datasheet.  In the one you have liked above I see (S) and (MS), which I'm guessing are "slave" and "master".  Will get back to you on it, maybe update the answer with what I find.

Let us continue this discussion in chat.

source: Stack Exchange

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

sort: votes


text:
Use AGPS functionality with Arduino and GPS module
Recently, we developed the UTRAQ L100 GNSS Module base board for testing all the capabilities of the GPS receiver.
https://www.elementzonline.com/blog/utraq-gps-l100-module-based-on-irnss-supported-by-gagan-navic
But we couldn't find a way to use the AGPS functionality. Is there any AGPS server available that can be used to download the satellite ephemeris data and feed that to the GPS module?
I got a reference that uses Skytraq AGPS, but not sure if the same is applicable for all receivers with AGPS functionality.
https://github.com/r0ro/skytraq
The above reference uses python code, but hopefully, it can be ported to an Arduino library if the functionality actually works well.

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


text:
WDT ISR not called when SPI ST7789 module initiated
Using the .init function for the ST7789 TFT screen prevents my WDT ISR from firing. What explains this behaviour, and is there something I can do? Any other timer ISR I could use instead?
#include <Adafruit_ST7789.h>    // Includes Adafruit_GFX.h

#define TFT_CS 10 // define chip select pin
#define TFT_DC 9  // define data/command pin
#define TFT_RST 8 // define reset pin, or set to -1 and connect to Arduino RESET pin

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

void setup()
{
    //Serial.begin(9600);
    pinMode(13, OUTPUT);

    WDTCSR = (24); // Change enable and WDE - also resets
    //prescalers only - get rid of the WDE and WDCE bit.
    WDTCSR = (6); // 1 sec
    WDTCSR |= (1 << 6); //enable interrupt mode - WDT as an interrupt is useful to wake up from sleep
    sei();

    tft.init(240, 240, SPI_MODE2); // comment this out and WDT works fine
    tft.setRotation(0);
    tft.setTextWrap(true);
}

void loop()
{

}

ISR(WDT_vect)
{
  digitalWrite(13, (digitalRead(13) ^ 1));   // toggle LED pin
}

Thanks!

To be clear, you're saying pin 13 blinks if and only if the call to tft.init is commented out?

@timemage yes, exactly

You can't use the LED on pin 13 on Uno, Nano or Nano Every, if you use SPI . It is the clock pin of the SPI.
The init function of the display initializes SPI which dedicates the pin to SPI peripheral and disconnects it from pin IO peripheral.

Good point. Maybe I'd notice that if he mentioned about used pins like "using freaking 8 - RST; 9 - DC; 10 - CS; 11 - MOSI; 12 - MISO; 13 - SCLK; 13 - LED_BUILTIN"


text:
Arduino recieve sensor data from other arduino SPI
I have Arduino Uno (sender) and Arduino Uno Wifi rev 2 (receiver). I want to send the ping value to the other one via serial - jumper wires.
Arduino Uno is using the newping example, and I want the Uno Wifi to receive the sensor value and print it to serial.
I am using SoftwareSerial.h
jumper wires go TX<->RX , RX <->TX, GRD-GRD according to the pins in the sketch below.
The problem is the sketch code for the Uno WiFi (receiver), it keeps printing garbage and seems like no carriage return sometimes.
13
⸮10
⸮52
⸮5LC⸮1⸮H⸮10
5⸮H⸮51
13C⸮10
⸮5⸮H⸮5LC⸮13
10
⸮52
51C⸮13
10
⸮52
5LC⸮13
⸮10C⸮52
⸮51
13
10
⸮52
50

Code on Uno (sender):
// ---------------------------------------------------------------------------
// Example NewPing library sketch that does a ping about 20 times per second.
// ---------------------------------------------------------------------------
#include <SoftwareSerial.h>
#include <NewPing.h>

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
SoftwareSerial mySerial(9, 10); // RX, TX

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

 Serial.println("Hello World Serial");
 mySerial.begin(4800);
 mySerial.println("Hello World, mySerial");
}
void loop() {
  delay(500);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");
  mySerial.print(sonar.ping_cm());
  mySerial.println();
  }

code on uno wifi (reciever):
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  // set the data rate for the SoftwareSerial port
  mySerial.begin(4800);

}

void loop() { // run over and over

    Serial.println(mySerial.read());
    delay(1000);

}

I can see the Uno (sender) with NewPing is printing the correct data to it's serial but I can't get the Uno wifi (listener) to get the same value. Its just garbage. I am new to this, what am I doing wrong?

reduce the sender code ... only send fixed values ... remove all code that is not associated with sending mySerial data ... no Serial, no sonar

Try replacing the receiving Serial line with if(mySerial.available()) Serial.write(mySerial.read());

Well I have gotten a bit farther. I used Serial.write and on the recieving Arduino I get values just not the correct one. The serial on the sender is sending value- 32, on the recieving arduino with - SonarReading=(mySerial.read()); I get numbers like 240, 241, ...

Well had a bit of luck after spending all day on this.
Arduino UNO (sender): Like mentioned by chrisl, use Serial.write and not Serial.print
mySerial.write(sonar.ping_cm());

UNO Wifi (receiver):
Serial.println(mySerial.readString());

So, instead of mySerial.read I used mySerial.readString.
This is most likely a obvious mistake to almost everybody here; took me two days. Sigh.


text:
Error in program that measures distance from a ultrasonic sensor
I am trying to use an ultrasonic sensor in conjuncture with different devices like a proximity sensor and a solenoid and alarm.
This is how the project is supposed to work:
A container is placed on a fixture and the proximity sensor detects the placement of the container. Once the container is detected the ultrasonic sensor needs to be activated and the pulse time is measured and the distance is calculated. The container has unique features on each side and the aim of the ultrasonic sensor is to measure the distance and if the distance value is within the required spec then it should turn on a solenoid to allow the next operation or if it's outside the spec it should raise an alarm.
following is the code:
/*Objective of this project

1. To be able to detect when a container is placed in the wrong oreientation and cut of the supply to pneumatic system if so.
We will use the following devices to do so

1. Ultrasonic sensor to measure distance differences of both sides of the container
2. IR sensor to measure if the conatiner has been placed or not (This sensor will activate the ultra sonic sensor)
3. A soliend that will be controlled by the output of the ultrasonic sensor. The solenoid will control the air flow.

*/

int trigPin = 7;
int echoPin = 8;
int contSig = 2;
int solSig = 12;
int errSig = 13;
void setup() {

  Serial.begin(9600);
  pinMode(trigPin,OUTPUT);
  pinMode(contSig,INPUT_PULLUP);
  pinMode(echoPin,INPUT);
  pinMode(solSig,OUTPUT);
  pinMode(errSig,OUTPUT);

  }

void loop() {
  if (digitalRead(contSig) == 0){
    Serial.println(digitalRead(contSig));
    digitalWrite(trigPin,LOW);
    delayMicroseconds(10);
    digitalWrite(trigPin,HIGH);
    delayMicroseconds(10);
    int duration = pulseIn(echoPin,HIGH);
    Serial.println(duration);
    float dist = (duration/2) * 0.034;
    Serial.println(dist);
    if (dist >=20 && dist <= 60){
      digitalWrite(solSig,HIGH);
      digitalWrite(errSig,LOW);
    }
    else{
      digitalWrite(solSig,LOW);
      digitalWrite(errSig,HIGH);
    }
  }

}

I am facing a few issues.
1.The first If statement at the beginning does not seem to work properly.
2.The output on the serial monitor alternates between zeros and actual values.  I am not sure why this set of zeroes keeps coming inbetween but this will make the project fail.
Following is the output from the serial monitor:
0
0
0.00
0
2892
49.16

pulseIn returns zero if no pulse is detected within the default timeout period. The other zeros are ones that you print explicitly.

"The first If statement at the beginning does not seem to work properly"  Why do you say that?

I have simulated this program on tinker cad, I do not understand why the zeroes are still appearing. As per the logic, we should not be having zeroes.  The if the state does not seem to be working because when I change the contSig value from 0 to 1 I still get a reading from the ultrasonic sensor which should not be happening


text:
How can we remove unused feature in Arduino's standard SD library so we can reduce the sketch size?
With the ReadWrite example in Arduino IDE, the sketch size is 10980 bytes (34%) of an Arduino UNO's storage. How can we reduce the sketch size? There isn't any kind of #define to turn on/off features in SD.h. I only need read, write, append and seek features, not anything else.
I have found the PetitFS port for Arduino, but it doesn't support appending to a file. There is also TinySDLogger but I think it's for good for logging rather than normal file writing. I have found SdFat too.
My main work has used 26234+ bytes of flash and I cannot add more 10KB to the sketch!

the Arduino SD library is an old version of SdFat wrapped in arduino style API

The linker automatically removes code that is not used, so you do not have to care about that. If the size is this big that means that so much of the code is used. I assume the largest part of the library is the file system support, and that is required regardless of which functions you actually use


text:
Arduino buzzer code sequence not triggering
I have a problem with my arduino buzzer:
the code should be doing the following:
I have a security system where in order to open the door you have to enter a 4 digit code from the remote. If the code is correct the door opens. if not you can try again.
You have 3 chances to try to enter the pin before an alarm goes on. here comes the problem: the alarms code triggers but the buzzer isn't making any sound.
here is the code for the alarm sound:
if (tryCount>=3) { // if the pin is wrong 3 times we sound an alarm
    Serial.println("got in alarm");
    while(true) {
        Serial.println("got in while");
        noTone(buzzer);
        tone(buzzer,100,300);
        delay(300);
        noTone(buzzer);
        tone(buzzer,1000,300);
        delay(300);
    }
}

here is the proof the alarm code triggers:

here is the full code:
https://create.arduino.cc/editor/mihimbc/8ec2fe30-d812-45cc-b0ae-850b437eb05b/preview
and here is the hardware schematics:

Is the buzzer an active or a passive one? Only passive buzzers can be driven via tone(). Active buzzers can only switched on or off via digitalWrite()

it's an active one.
to mention: when i move the instruction for the buzzer inside the loop it works, but in that specific part of the program doesn't.
and it's strange that accordingly to the Serial.println that i've put inside the while it seems that its getting there but but no sound is coming from the buzzer

The problem was with the buzzer, somehow was a faulty buzzer, I've managed to replace it and the problem was solved.
Thanks everybody for your time trying to help me!


text:
ATTiny85 USB Troubleshooting. Device is not recognized when programmer asks to plug in device
I have bought this cheap AVR Programmer Board and I thougth that I would be OK just plugging it into my USB port. Then after I did that nothing happened so I passed last 4 hours trying to understand what was going wrong. I learned that ATTiny85 microchips often come with no bootloader.

So first I tested it with Arduino as ISP and simple blink code. It worked. Then I downloaded micronucleus and i flashed it via Arduino as ISP. I think this process worked pretty well as the output show
> avrdude -C ../etc/avrdude.conf -c arduino -p t85 -P COM3 -b 19200 -U flash:w:/micronucleus/firmware/releases/t85_default.hex

 avrdude: AVR device initialized and ready to accept instructions

 Reading | ################################################## | 100%
 0.01s

 avrdude: Device signature = 0x1e930b (probably t85) avrdude: NOTE:
 "flash" memory has been specified, an erase cycle will be performed
          To disable this feature, specify the -D option. avrdude: erasing chip avrdude: reading input file
 "/micronucleus/firmware/releases/t85_default.hex" avrdude: input file
 /micronucleus/firmware/releases/t85_default.hex auto detected as Intel
 Hex avrdude: writing flash (8166 bytes):

 Writing | ################################################## | 100%
 0.09s

 avrdude: 8166 bytes of flash written avrdude: verifying flash memory
 against /micronucleus/firmware/releases/t85_default.hex: avrdude: load
 data flash data from input file
 /micronucleus/firmware/releases/t85_default.hex: avrdude: input file
 /micronucleus/firmware/releases/t85_default.hex auto detected as Intel
 Hex avrdude: input file
 /micronucleus/firmware/releases/t85_default.hex contains 8166 bytes
 avrdude: reading on-chip flash data:

 Reading | ################################################## | 100%
 0.09s

 avrdude: verifying ... avrdude: 8166 bytes of flash verified

 avrdude: safemode: Fuses OK (E:FF, H:DF, L:62)

 avrdude done.  Thank you.

Problem that I'm now facing is that when I try to upload a code using ATTiny Development Board via arduino IDE (selecting Attiny85 digispark default 16.5mhz) and it asks me to plug in the device, device is not recognized.
I already installed drivers downloaded from github release section of DevicestumpArduino repository, tried installing micronucleus configuration driver via zadiag like i read in this question but nothing worked.
What am I missing?

From your AVRDude output:

avrdude: safemode: Fuses OK (E:FF, H:DF, L:62)

It does not appear that you have programmed the AVR configuration fuses.
One for thing, E:FF, is extended fuse value 0xFF, which is missing the SELFPRGEN (self-programming) fuse that would allow Micronucleus to load your code onto the AVR, that is allow the AVR to execute instructions to program itself.  So, assuming it managed to show up on USB, you wouldn't actually be able to use it to put code on your chip.
You can see what they should be where the makefile fuse target defers to your t85_default configuration:
FUSEOPT = -U lfuse:w:0xe1:m -U hfuse:w:0xdd:m -U efuse:w:0xfe:m

The fuses that are actually preventing it from showing up on USB are more likely the clock related fuse bits in the low fuse byte.  In particular CKDIV8 (factory default) is set to divide-by-8 where it is not in the makefile.  The CKSEL bits are set to 0x2 (factory default) for the 8Mhz internal RC oscillator whereas the makefile wants them to be set to 0x1, for internal PLL (phase locked loop) that generates higher clock rates from the RC oscillator.  In short, your chip is running at 1MHz rather than 16Mhz.  The Micronucleus code may also be written such that it needs PLL for bit-banging USB, though I haven't looked into that to be certain.


text:
what voltage level is a digital low for the interrupt mode LOW?
I am learning about interrupts and one of the interrupt modes is LOW which triggers anytime the pin is a digital low.
Can someone tell me what voltage that is for an Arduino nano? I did a google search and it said a LOW can be anywhere from 0 to 2V.
I am making a project using a nano and I am powering it with batteries. It would be great if I could set up an interrupt to turn on an LED when the batteries were getting weak so I would know when to change them.

triggers anytime the pin is a digital low ... this is bad thinking ... it should be triggers anytime the pin transitions from high to low ... there is a vast difference between the two

It would be great if I could set up an interrupt to turn on an LED
when the batteries were getting weak

That won't work. The thresholds for the pin registering LOW or HIGH
depend on the supply voltage. Very roughly:

a pin in guaranteed to register LOW if its voltage is below ⅓ Vcc
it is guaranteed to register HIGH if it's above ⅔ Vcc
nothing is guaranteed between ⅓ and ⅔ of Vcc.

For the exact voltage levels, you should check the datasheet.
Note also that those are guaranteed levels. The actual thresholds are
closer to ½ Vcc, with an hysteresis of roughly Vcc/10.
For detecting a low battery condition, you should use the ADC, combined
with either a voltage divider on Vcc or the internal bandgap reference.

Thank you Edgar! I didn't think it would work the way I was wanting it to. That is why I reached out to you folks who are much smarter than I am. I appreciate you answering my question.


text:
How to use LCD Screen and IR Remote to broadcast a countdown
I am trying to use an IR Remote to input date's and time's for a countdown, so then the LCD will display a countdown, like this:
LCD: Enter Year
Remote-Input: 2021
LCD: Enter Month
Remote-Input: 08
LCD: Enter Day
Remote-Input: 20
LCD: Enter Hour
Remote-Input: 08
LCD: Enter Minute
Remote-Input: 00
LCD: Enter Second:
Remote-Input: 00
LCD: You have __ Years, __ Months, __ Days, __ Hours, __ Minutes, __ Seconds.

How do I do this?

GLHF! (You forgot to ask a question). However, my advice would be to do one thing at a time before connecting them all together.

@Paul Thanks for letting me know :)

https://arduino.stackexchange.com/tour

I know how to ask a question. I was just in a rush.

Thanks for editing my question, @timemage

No problem.  As is, the question is more of a "how do I do my project" type question, which isn't what the site is meant for.  Presumably you've made an attempt at this and ran into at least one specific problem, ideally an Arduino specific problem.  If so, you can edit your question to make it about that one thing, and then the answer might be of use to others.

How do I do this?

I have no clue how you do that but I do know I would do that.

I know how to ask a question.

Apparently not, your question is far from perfect (and my answer above is technically the only correct answer to that specific question). It doesn't tell us what you've tried, it doesn't tell us what you haven't tried. It not specific nor practical. Doesn't state your experience with Arduino, doesn't state which hardware you (would) be using. (Though I must say your example output thing is quite nice)

I was just in a rush.

Isn't everyone nowadays? And why would we invest time in an answer on a question which has no effort put into it?

You're basically asking "How to do an Arduino project" (or any project), there's many ways but let's dive into it.
0. Split up your project into smaller projects.
Since it sounds as if you have no clue on how to get started or if you feel this project is daunting, it may help to make the 'problem' easier to get started. You can always add more complexity.
Make one Arduino program, which shows "Hello World" on the LCD.
Make one Arduino program, which receives IR codes and depending on which button pressed, shows "Hello" or "World" in your terminal.
1. Research
Search the internet, maybe there's projects like this. Try to google for "Arduino Countdown Timer". Check what design choices they made, what hardware they use and how they work in general.
2. Design
Make a design, not only about the aesthetic part, but also functionally. What happens if the timer depletes? Should it also have a buzzer? Does it need an enclosure?
And technically, how will it be powered?
3. Acquire hardware
As a starter; it can help to buy hardware from stores that also include example code.
Use the example code to test and verify your hardware and connections.
4. Software
If you're asking "How to write software", you're better off starting out with some example projects/tutorials which include the code and explain it.
But basically you should use the example code to drive the hardware, use examples on the internet combined with your own experience to create a program that matches your required behavior.

If, along this path, you have a practical question. We will be much more able to, and happy to, help.

I apologize for not meeting your criteria. I was just trying to get some help before my class started, hopefully someone like you would come across and help me. I appreciate your tips. I will follow these and then come back to re-ask the question if necessary. Thanks again!

I found this website, which seemed to help:
https://create.arduino.cc/projecthub/hugonator/simple-lcd-timer-with-arduino-uno-ff3376

I like the buzzer idea. Would I use the active buzzer or passive buzzer? I don't know the difference.

An active buzzer will generate a tone by itself, so for simplicity use an active one. If you'd like to adjust the tone by yourself, you need a passive one.

Thanks! I have both :)

So I found a create.arduino.cc project that I had thought it was a countdown, but when I create it and upload it to my board, I found out that it's a timer. Like a kitchen timer. :I

A countdown is only different by doing -1 second instead of +1 second. And that you start at the maximum value instead of 0

Nice! thank you


text:
Arduino Uno I2C two sensor connection Issues
I have been working on trying to get the MAXREFDES#117 PPG and the LIS3DH Accelerometer to run together. I am modifying the sample code found here to do so:
https://github.com/MaximIntegratedRefDesTeam/RD117_ARDUINO
However, when I add the line lis.begin(0x18) to the PPG code the code stops running correctly. There is no error and the only thing that will print to the Serial Monitor is “LIS”. I have gotten the accelerometer to run using acceldemo and the PPG sensor running using the code from GitHub (above), so I do not think it is a connection issue. I am not quite sure what the problem is and would greatly appreciate help.
//PPG

#include <Arduino.h>
#include "algorithm.h"
#include "max30102.h"

//Accelerometer

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>

#define MAX_BRIGHTNESS 255

#if defined(ARDUINO_AVR_UNO)
//Arduino Uno doesn't have enough SRAM to store 100 samples of IR led data and red led data in 32-bit format
//To solve this problem, 16-bit MSB of the sampled data will be truncated.  Samples become 16-bit data.
uint16_t aun_ir_buffer[100]; //infrared LED sensor data
uint16_t aun_red_buffer[100];  //red LED sensor data
#else
uint32_t aun_ir_buffer[100]; //infrared LED sensor data
uint32_t aun_red_buffer[100];  //red LED sensor data
#endif
int32_t n_ir_buffer_length; //data length
int32_t n_spo2;  //SPO2 value
int8_t ch_spo2_valid;  //indicator to show if the SPO2 calculation is valid
int32_t n_heart_rate; //heart rate value
int8_t  ch_hr_valid;  //indicator to show if the heart rate calculation is valid
uint8_t uch_dummy;

Adafruit_LIS3DH lis = Adafruit_LIS3DH();

// the setup routine runs once when you press reset:
void setup() {
   // initialize serial communication at 115200 bits per second:
   Serial.begin(115200);
   while (!Serial) delay(10);     // will pause Zero, Leonardo, etc until      serial console open

   Serial.println("LIS3DH initializing");
   lis.begin(0x18);
   Serial.println("LIS3DH initialized!");

   maxim_max30102_reset(); //resets the MAX30102
   pinMode(10, INPUT);  //pin D10 connects to the interrupt output pin of the MAX30102

   delay(1000);
   maxim_max30102_read_reg(REG_INTR_STATUS_1,&uch_dummy);  //Reads/clears  the interrupt status register

   while(Serial.available()==0)  //wait until user presses a key
   {

      Serial.write(27);       // ESC command
      Serial.print(F("[2J"));    // clear screen command
      Serial.println(F("Press any key to start conversion"));
      delay(1000);

   }

   uch_dummy=Serial.read();
   maxim_max30102_init();  //initialize the MAX30102
}

// the loop routine runs over and over again forever:

void loop() {
  uint32_t un_min, un_max, un_prev_data, un_brightness;  //variables to calculate the on-board LED brightness that reflects the heartbeats
  int32_t i;
  float f_temp;

  un_brightness=0;
  un_min=0x3FFFF;
  un_max=0;

  n_ir_buffer_length=100;  //buffer length of 100 stores 4 seconds of samples running at 25sps

  //read the first 100 samples, and determine the signal range
  for(i=0;i<n_ir_buffer_length;i++)
  {
    while(digitalRead(10)==1);  //wait until the interrupt pin asserts
    maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));  //read from MAX30102 FIFO

    if(un_min>aun_red_buffer[i])
      un_min=aun_red_buffer[i];  //update signal min
    if(un_max<aun_red_buffer[i])
      un_max=aun_red_buffer[i];  //update signal max
    Serial.print(F("red="));
    Serial.print(aun_red_buffer[i], DEC);
    Serial.print(F(", ir="));
    Serial.println(aun_ir_buffer[i], DEC);
  }

  un_prev_data=aun_red_buffer[i];

  //calculate heart rate and SpO2 after first 100 samples (first 4 seconds of samples)
  maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_spo2, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid);

  //Continuously taking samples from MAX30102.  Heart rate and SpO2 are calculated every 1 second
  while(1)
  {
    i=0;
    un_min=0x3FFFF;
    un_max=0;

    //dumping the first 25 sets of samples in the memory and shift the last 75 sets of samples to the top
    for(i=25;i<100;i++)
    {
      aun_red_buffer[i-25]=aun_red_buffer[i];
      aun_ir_buffer[i-25]=aun_ir_buffer[i];

      //update the signal min and max
      if(un_min>aun_red_buffer[i])
        un_min=aun_red_buffer[i];
      if(un_max<aun_red_buffer[i])
        un_max=aun_red_buffer[i];
    }

    //take 25 sets of samples before calculating the heart rate.
    for(i=75;i<100;i++)
    {
      un_prev_data=aun_red_buffer[i-1];
      while(digitalRead(10)==1);
      digitalWrite(9, !digitalRead(9));
      maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));

      //calculate the brightness of the LED
      if(aun_red_buffer[i]>un_prev_data)
      {
        f_temp=aun_red_buffer[i]-un_prev_data;
        f_temp/=(un_max-un_min);
        f_temp*=MAX_BRIGHTNESS;
        f_temp=un_brightness-f_temp;
        if(f_temp<0)
          un_brightness=0;
        else
          un_brightness=(int)f_temp;
      }
      else
      {
        f_temp=un_prev_data-aun_red_buffer[i];
        f_temp/=(un_max-un_min);
        f_temp*=MAX_BRIGHTNESS;
        un_brightness+=(int)f_temp;
        if(un_brightness>MAX_BRIGHTNESS)
          un_brightness=MAX_BRIGHTNESS;
      }
#if defined(ARDUINO_AVR_LILYPAD_USB)
      analogWrite(13, un_brightness);
#endif

#if defined(ARDUINO_AVR_FLORA8)
      LED.setPixelColor(0, un_brightness/BRIGHTNESS_DIVISOR, 0, 0);
      LED.show();
#endif

      //send samples and calculation result to terminal program through UART
      Serial.print(F("red="));
      Serial.print(aun_red_buffer[i], DEC);
      Serial.print(F(", ir="));
      Serial.print(aun_ir_buffer[i], DEC);

      Serial.print(F(", HR="));
      Serial.print(n_heart_rate, DEC);

      Serial.print(F(", HRvalid="));
      Serial.print(ch_hr_valid, DEC);

      Serial.print(F(", SPO2="));
      Serial.print(n_spo2, DEC);

      Serial.print(F(", SPO2Valid="));
      Serial.println(ch_spo2_valid, DEC);
    }
    maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_spo2, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid);
  }
}

Here is a picture of how the two sensors are wired:

You may find that if you Serial.flush(); after the message, but before the lis.begin(), that the entire message makes it out through serial and then it locks up.  I'm interested to know how it's wired.  You should run the I2C scanner and see if it doesn't also lock up in that as well, in which case you can at least temporarily not be concerned about your project or accelerator specific code.

Serial.flush(); did fix that line of output. I ran the I2C_Scanner and it picked up two sensors (0x18 and 0x57). Do you think that there is an issue with the wiring then? Before running the code with the combined sensors, I run the code for just the PPG and just the accelerometer to make sure both are wired correctly.

You need to solder those connections.  Otherwise you're going to go insane debugging this.


text:
How can I remove the delays in this code for sweeping the servo?
I know this is probably a very asked question, but I am building a fairly basic radar type thing which sweeps left and right and uses an ultrasonic sensor to determine the distance to an object and a buzzer is set off if something is detected.
The device itself works  but I've noticed that because I have used delay() to allow the servo to complete its full movements, it is holding up the rest of the code, and as a result the buzzer and returning of the distance is extremely unresponsive and sluggish.
So far I have looked at simply returning a value whenever the motor reaches a certain step but it doesn't achieve exactly what I'm looking for, and I have looked into using millis() for timing asynchronously, but I'm struggling to wrap my head around it a bit in terms of how it will work for a servo.
My current working but sluggish code:
//Servo Stuff
#include <Servo.h>
int servoPin = 12; // Pin for interacting with servo defined
int servoStart = 0; //Starting position of servo motor
int servoEnd = 90; //End position of servo means it rotates 90 degrees
int waitTime = 1000; // Allows servo to fully rotate before moving again
int servoPos = 20; // For incrementing the position of the servo
int servoStep = 20; //amount to increment servo position by
Servo myServo; // Creates an instance of a servo object

//Ultrasonic stuff
int trigPin = 9;
int echoPin = 10;
long duration;
int distance;
int maxDistance = 329; // The max range of the ultrasonic sensor

//Buzzer stuff
int buzzerPin = 11;
int buzzerWait = 200;

void setup(){

//Attach the servo object to the pin and begin serial monitor with
// polling rate of 9600
Serial.begin(9600);
  myServo.attach(servoPin);
  pinMode(buzzerPin, OUTPUT);

    pinMode(trigPin, OUTPUT); // Trig pin set as output
    pinMode(echoPin, INPUT); // echo pin set as i
      }

    void loop()
    {

      // Moving servo
      myServo.write(servoStart); //Moves servo to the starting pos
      //delay (waitTime); //allows servo to fully move before next move
      //myServo.write(servoEnd); //Moves to end position
      //delay (waitTime); // waits before reverting back to start pos

    //myServo.write(servoStart);
    //delay(waitTime);
    //myServo.write(20);
    //delay(waitTime);
    //myServo.write(40);
    //delay(waitTime);
    //myServo.write(60);
    //delay(waitTime);

     // Using ultrasonic sensor

      // Clears the trig pin
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);

    // Sets the trigPin on HIGH state for 10 microseconds
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);

    // reads echoPin and returns the travel time of the wave in microseconds
      duration = pulseIn(echoPin, HIGH);

    // Calculating distance
      distance = duration*0.0343/2;

    //Prints the distance to the Serial Monitor
      Serial.print("Distance: ");
      Serial.println(distance);
      Serial.println(distance);

      if (distance < maxDistance) {
      digitalWrite(buzzerPin, HIGH);
      //delay(buzzerWait);
      //digitalWrite(buzzerPin,LOW);
      //delay(buzzerWait);

      }else digitalWrite(buzzerPin, LOW);

    }

Any pointers to some good resources for this would be very appreciated, thanks.

From your code it seems like you are doing all the servo movement before you read the distance and report back. A lot of code is commented out, so it's a bit difficult to follow. What I would do is something along the line of:
[...]
int servoStart=0;
int servoEnd=90;
int servoPos=0;

[...]
void setup() {
    [usual setup stuff like you do it now]
    myServo.write(servoPos);  //start at pos 0
    // Maybe a delay here to make sure we are at pos. 0
}

void loop() {
    //Switch direction if we reach end
    if (servoPos+servoStep < servoStart || servoPos+servoStep > servoEnd)
        servoStep = -servoStep;
    servoPos += servoStep;
    myServo.write(servoPos);
    //Small delay?
    //Read distance
    //Send distance to seraial
    //Buzz buzzer if needed
}

Thank you for this, works perfectly!


text:
Servo starts spinning 360 degrees after a few minutes
I'm using my ESP8266 as a web server to tilt a camera with the servo Tower Pro Micro Servo 9G.
#include <Servo.h>
#include <ESP8266WiFi.h>

const char* ssid     = "SSID";
const char* password = "password";

Servo tilt;

WiFiServer server(8082);

void setup() {
  Serial.begin(9600);
  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());
  server.begin();
  Serial.println("Server started");
  tilt.attach(2);
  tilt.write(100);
}

void loop() {
  WiFiClient client = server.available();
  if (!client)
  {
    return;
  }
  Serial.println("Waiting for new client");
  while(!client.available())
  {
    delay(1);
  }
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

  int value = LOW;

  if(request.indexOf("/SERVO=UP") != -1){
        int t = tilt.read();
        if(t <= 125) {
          delay(10);
          tilt.write(t+8);
        }
  }
  if(request.indexOf("/SERVO=DOWN") != -1){
        int t1 = tilt.read();
        if(t1 >= 75) {
          delay(10);
          tilt.write(t1-8);
        }
    }

  client.println("HTTP/1.1 200 OK"); //
  client.println("Content-Type: text/html");
  client.println("");
  client.println("<!DOCTYPE HTML>");
  client.println("");
  client.print(" CONTROL Servo: ");

  if(value == HIGH)
  {
    client.print("ON");
  }
  else
  {
    client.print("OFF");
  }
  client.println("

");
  client.println("<button>ON</button>");
  client.println("<button>OFF</button>
");
  client.println("");
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
}

The first minutes it works fine but after a few minutes it starts turning 360° nonstop. Although, you can't turn this servo over 180°?!
Does anyone of you know what is going on here?
Thanks!

Edited your link into the question.  You can get rid of the message.   So, this has been modified for continuous rotation or not?

No I haven't modified it.

Without it having been modified, I'm unable to make sense of "it starts turning 360° nonstop".

Thats why I'm confused ^^
Maybe it is some cheap china stuff ^^
But do you know why it starts rotating randomly?

You could remove the two calls to tilt.write in loop to eliminate the basic logic of the program from consideration.  If it is still behaving oddly, consider removing all of the WiFi related code, even the header, and see if that changes the behaviour.  If you servo still acts weird with nothing but a virtually empty sketch with little more than a call to tilt.write (and prerequisites) in setup(), if nothing else it makes for a cleaner question.

tilt.attach(2);  Did you attach the servo signal pin to GPIO #2 or to pin "D2" (which is probably GPIO #4)?

Why the use of client.flush() during the receive?  flush block until all data is sent.  It has nothing to do with the receive buffer.

If it works and then doesn't, it makes this seem like a mechanical issue.
To check, write a simple program that just moves the servo around. Leave out all the extra web code. Wait to see if starts behaving erratically and you can save yourself the headache of hunting issues in your code that don't exist.


text:
Reproduce simulated temperature data with Arduino
I'm starting a test using Arduino to reproduce a set of temperature values in water each three hours and need some help with it.
I will use two ds18b20 sensors to control two thermostats connected to relays. The idea is that Arduino could access the data from a file in which there are simulated data for each day in the future. Something like this:
Date,Time,Temperature
01/01/2070,00:00:00,27.229211807251
30/12/2070,21:00:00,24.6133060455322
01/01/2070,06:00:00,22.1697025299072
01/01/2070,09:00:00,20.3209171295166
01/01/2070,12:00:00,27.7610721588135
01/01/2070,15:00:00,33.6277084350586
01/01/2070,18:00:00,34.5402450561523
01/01/2070,21:00:00,31.9973392486572
02/01/2070,00:00:00,26.2283573150635
02/01/2070,03:00:00,21.5823612213135
02/01/2070,06:00:00,18.6461429595947
02/01/2070,09:00:00,17.2126712799072
02/01/2070,12:00:00,24.8096561431885
02/01/2070,15:00:00,30.6440677642822
02/01/2070,18:00:00,33.8463973999023
02/01/2070,21:00:00,31.3529300689697
03/01/2070,00:00:00,25.2961673736572
03/01/2070,03:00:00,20.8135623931885

Based on this info the sensor will control the thermostat to decrease or increase the temperature within three hours (8 different temperatures by day). I'm going to start with 1 week (7 day x 8 temperatures = 56 simulations), but want to increment it till 3 months (720 simulations).
Considering the use of if/else if, it seems that would be a massive amount of conditionals.
Does anybody have a good solution to run this temperature simulation based on predefined data?
Thanks in upfront.

It is not clear to me, for what exactly you considered if/else if expressions. You have x data tuples with time and set temperature of the thermostat. So you could put these into an array, saving the current element index in a variable. Then you compare the time of the current element to the current time and set the setpoint of the thermostat accordingly. And you move on to the next element, if the time has come to do so. Is that, what you want?

Thank you for the answer @chrisl. It seems quite reasonable what you suggest and exactly what I'm looking for! I've never worked with this approach so need to find out some documentation and reference about it.

it makes no sense to store temperature using floating point values ... you are using 32 bits to store a 12 bit value

You can use an array to go through the times.
Create a struct with the fields time and temperature (you should think about saving time as unix epoch, meaning seconds since 1970, so that you save memory).
struct SetPoint {
    unsigned long time;
    float temperature;
};

Then you can declare an array of type SetPoint to hold the tubles of time and temperature:
#define DATA_SIZE  720
SetPoint data[DATA_SIZE] = {
    {<time1>, <temp1>},
    {<time2>, <temp2>},
    ...
    };

In the above, you need to replace <timeX> and <tempX> by your data. Then declare a position variable, which the element index, which will be invoked next:
unsigned int pos = 0;

We are starting with the first element (index 0) and compare its time to the current time. If it is equal (or current time is after the elements time), we will set the thermostat to the elements temperature and increment the position variable. Something like this:
if(pos < DATA_SIZE && current_time >= data[pos].time){
    set_thermostat(data[pos].temperature);
    pos++;
}

Note: I used the variable current_time here as standin for your way of getting the current time, and the set_thermostat() function as a standin for your way of setting the thermostat. Also I inserted a check into the if statement, to prevent the code going further, when it reached the data array end.

That said, depending on the used board you can easily get into memory trouble here. An Arduino Uno does not have enough memory to save 720 of the data points above. float and unsigned long both take 4 bytes each, so 8 bytes per element, which makes 8*720 = 5760 bytes. The Uno only has 2048 bytes total in RAM. There are enough boards, which have more RAM. The ESP32 for example would have way enough (though there are many others; the ESP32 is just the first to get into my mind here).
Or you can add an SD card module to your build and save the data points in a file. That would also make it way easier to get the data in your project or change the data. It would just involving writing the corresponding file on your SD card.
Then the workflow would be a bit different. Lets assume you save one data point per line as text:

Open file and read one line. Close file.
Parse read text into 2 variables (time and temperature)
Use these variables for the if statement from above
if the time of the loaded data point was reached, open the file again, read the next line and parse it into the variables
The if statement now uses the next datapoint

and so on. If there is no line left to read, you could go into an infinite loop, stopping the code from running further than your data.
There are ready to use SD card modules to buy out there, and you can find many tutorials about how to use them online.

As Edgar Bonet correct stated in the comments, you can greatly reduce the needed RAM, when assuming regular intervals (3h in your case). Then you don't need to save the time for each data point. You only need the one start time for the series. Also above I used float for the temperature (as I assumed, that at this point it would be the easiest for you). But since temperature settings for thermostats are mostly working only down to the 1 digit after the decimal point, you can save memory space by using a different representation. For example you could save the temperature as a single byte signed integer with the unit of 0.1°C and a reasonable offset (for example 25°C being zero). So some example values would be:
Temp | value
------------
18°C | -70
20°C | -50
22°C | -30
25°C | 0
27°C | 20
35°C | 100

That would give you the precision of one digit after the decimal point and a range from 12.3°C to 37.8°C. When changing the factor of 0.1°C, you can also change the range (and precision with it) as you really need it.
So with the above you would only need 720 byte for the actual data, which is good for the Uno.
BUT: I would still suggest looking into the SD card reader. You will have more work building the project, but you won't have the same hassle with including or updating the data. That can come in especially handy, if you want to use to further use the device after the 3 months. Just loading new data on it (maybe even way more data, like for a full year) is easier with an SD card.

Note that if the times are regularly spaced (one setpoint every 3 hours), they do not need to be stored. The temperatures can be stored in 16-bits with a resolution of 0.001 °C, which is most likely already overkill.

@EdgarBonet Thanks, I added a paragraph about that in my answer.

@s_tatus3 If you are going to connect the ESP32 to your wifi, you could also save the data in SPIFFS and write code, that lets you exchange the data over a website hosted on the ESP32. Might also be interesting for you.

Fantastic! Yes, definitely will replace Arduino with ESP32 and use the data in a SD card. Already set epoch time (way better to work with).
Just added the function set_thermostat() to control the relay and now will see the best way to set time to easily reuse it many times.
void set_thermostat() {   if (temperature < data[pos].temperature) {     digitalWrite (relay, HIGH);   }   else if (temperature > data[pos].temperature) {     digitalWrite (relay, LOW);   } }
Will back here to add whole code once is done.
Thank you all the comments and support

@chrisl just opened this question related to the sd file parsing. If you have some great insight about, they will be welcomed! :)


text:
Set up a motion sensor to turn on lights and record how long the lights are on
I'm doing a school project and I want to measure the difference in time that the lights are on in a classroom with and without a motion sensor controlling them. I haven't really found anything about recording how long sensors act or the time between activations. How could I possibly do this?

For what exactly have you googled? When using the terms "arduino measure time" you get pretty good results.

you don't need an arduino to do this ... get two electrically powered mechanical clocks ... one always runs ... the other is powered by the switched circuit

I would consider placing a light sensor close to one of the lights to signal when the lights are on. Placement is critical as you do not want a signal when the lamp is off. I am assuming they are permanent light fixtures and you are not allowed to tamper with the wiring.  Record the elapsed time when they are on.  Note the start time and then subtract that from the current time based on your watch. For elapsed time and subtract the ontime from that. With the sensor you can also record each time the light is turned on etc. That would all be in your software.


text:
WiFiManager - Combine NonBlocking portal AND addParameter
I wish to config WiFiManager and addParameter of MQTT topic and local server on its ConfigPortal.
Additionally in a case of a power outage or any, in case of losing WiFi, to continue in a NonBlocking way.
The problem is when combining both features in one sketch, I get some errors.
Entire code is ( please notice comments marked Marker[i] ):
#include <WiFiManager.h>
#define MQTT_SERVER "192.168.3.200"
WiFiManager wm;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  WiFiManagerParameter custom_mqtt_server("mqtt_server", "mqtt server", MQTT_SERVER, 40);
  WiFiManagerParameter custom_mqtt_user("mqtt_user", "mqtt user", "", 10);
  WiFiManagerParameter custom_mqtt_pwd("mqtt_pwd", "mqtt password", "", 10);
  WiFiManagerParameter custom_mqtt_topic("mqtt_topic", "mqtt topic", "", 10);
  WiFiManagerParameter custom_mqtt_group("mqtt_group", "mqtt group", "", 10);
  WiFiManagerParameter custom_mqtt_root("mqtt_root", "mqtt rootTopic", "", 10);
  wm.addParameter(&custom_mqtt_server);
  wm.addParameter(&custom_mqtt_user);
  wm.addParameter(&custom_mqtt_pwd);
  wm.addParameter(&custom_mqtt_topic);
  wm.addParameter(&custom_mqtt_group);
  wm.addParameter(&custom_mqtt_root);

  WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
  //  wm.resetSettings();

  //  wm.setConfigPortalTimeout(180);
  // wm.setConfigPortalBlocking(false);  // <--- Marker [#1]

  //  if (!wm.autoConnect("AutoConnectAP")) {
  //    Serial.println("failed to connect and hit timeout");
  //    delay(3000);
  //    //reset and try again, or maybe put it to deep sleep
  //    ESP.restart();
  //    delay(5000);
  //  }

  bool res;
  res = wm.autoConnect("test123", "password"); // password protected ap
}

void loop() {
  // put your main code here, to run repeatedly:
  //  wm.process(); //<--- Marker [2]
  Serial.println("hi");
  delay(100);

}

When Marker[1] & Marker[2] are commented out ConfigPortal works as expected, and in Blocked state - meaning there is no hi's on Serial monitor.

When only Marker[2] is commented out, ConfigPortal is reached, lacking all addParameter fields.

When Marker[1] & Marker[2] are not commented out, ConfigPortal is now reachable, but not having Non-Blocking feature...

What is the purpose of wm.process() ?

Guy

what errors do you get?

@jsotola see at the bottom of code. It is noted already

autoConnect will end the portal if WiFi can connect. use startConfigPortal to let the portal run. wm.process handles client of a started wm web server. see the OnDemandNonBlocking example's doWiFiManager function

@Juraj - thanks for clarifying. I saw the usage of wm.process() only in NonBlocking example, and as far as understood in use only when Portal in hosted while not connected to WiFi ( what is traditionally - Blocking mode ). Is it correct ?

@Juraj Can you explain about startConfigPortal and why it is not used in relevant built in example ?

The WiFiManger's autoConnect function starts the configuration web server (and AP) only if connection to configured WiFi network is not established.
If you want to run the WiFiManger's web server to reconfigure WiFi or to set other parameters, you can start the WM web server with the startConfigPortal function.
autoConnect and startConfigPortal are blocking by default. The library has a loop inside this functions which runs until the web server is stopped calling [Exit] action on the configuration web page or the timeout set with setConfigPortalTimeout is reached after last contact from browser.
To run the WM web server 'parallel' to your sketch you can configure it as not blocking with setConfigPortalBlocking(false). Then to allow WM handling of the web server the sketch must periodically call wm.process().
In not blocking mode the [Exit] action on the configuration wen page doesn't stop the web server. The server must be stopped in code.
The parameter definitions must by global in sketch, if you want to run WiFiManager with parameters outside of setup(). Parameters local in setup() don't exist after setup() finishes. WiFiManager detects this and doesn't use the parameters.
The OnDemandWebPortal example and OnDemandNonBlocking example demonstrate startConfigPortal in blocking and not blocking use.

If I didn't explain myself right - I'm looking on 2 scenarios: 1) first time boot, creditials have to be set ( including addParameter's ) 2) After some failure which WiFi is not found for some reason, I need my system continue running ( minus All WiFi + MQTT functionality ), during THIS time I rather have ConfigPortal accessible for some time ( 180 sec ).

@Guy.D, now you have the insight to do that

please review my answer below


text:
Convert from hexadecimal to binary

I need to simulate a pulse train. Everything is in order with this code, it solves its problem.
The question is: I need to change the keys, but it is too difficult to manually type in so many zeros and ones each time.
On the other hand, I know that my hexadecimal key looks much shorter: "B8C4F9".
Is it possible to create a string in such a way that the system itself translates to the binary system?
And the second question: How can you automatically measure the length of an array so as not to manually calculate KEY_LEN?
const int KEY_LEN = 24;
const char key[KEY_LEN] = {"101110001100010011111001"};

int T = 200; // Pulse repetition period in microseconds
int Zero = 80; //0.4*T; // Duration of zero in microseconds
int One = 120; //0.6*T;// Duration of a unit in microseconds

const int LED_PIN = 13; // Used digital pin 13 of the arduino to connect the transmitter

void setup()
{
  pinMode(13, OUTPUT);
}

void loop()
{
  for (int n = 0; n < KEY_LEN; n++)
  {
    if (key1[n] == '1') //If the bit read == 1
    {
      sendSignal(One);
    }

    else if (key1[n] == '0')//If the bit being read == 0
    {
      sendSignal(Zero);
    }
  }
}

void sendSignal(int duration)
{
  digitalWrite(LED_PIN, LOW);
  delayMicroseconds(duration);
  digitalWrite(LED_PIN, HIGH);
  delayMicroseconds(T - duration);
}

is this for a TV remote control?

This is to control the front door

There is really no reason to save the key as a string, as you are doing. You can just save it as a normal number. Then you can also use the hexadecimal representation on your code:
unsigned long key = 0xB8C4F9;

Then you need to send out each bit of that number:
for (int n = 0; n < KEY_LEN; n++)
{
    if (key & (1 << n)) { //If the bit read == 1
        sendSignal(One);
    } else {//If the bit being read == 0
        sendSignal(Zero);
    }
}

The following is happening in the if statement: (1 << n) will take the value 1 (binary 0b00000001) and will shift the bits to the left by n digits. For example: If n is 2, we get (0b00000001 << 2) = 0b00000100. With this we can select a bit in our number. Then we take that and do a bitwise AND & with the key. That will set all bits to zero, which are not currently selected. The resulting number is zero, if the corresponding bit in key is zero. If the corresponding bit is 1, this will return a number different from zero (which is interpreted as true. Thus we check, if the n-th bit of key is one or zero.

How can you automatically measure the length of an array so as not to manually calculate KEY_LEN?

Generally you can calculate the size of an array with the sizeof() function:
unsigned int size_of_array = sizeof(array)/sizeof(array[0]);

sizeof() returns the number of bytes. So to get the number of elements, we need to divide by the number of bytes in each element;
For the way shown above this is not that easy. Normally it is not really needed, since such keys normally don't change length very often. If you find a variable type, which exactly fits your key size, you could use sizeof(key)*8 to get the number of bits in it. But your current value 0xB8C4F9 only needs 3 bytes. I don't know a type with 3 bytes, but maybe somewhere you can get something like uint24_t. Honestly here I would just use a hardcoded size, just like you are using a hardcoded key value.

But in this case, the bits are output in reverse (from end to beginning). That is, if the key is in the form, for example "D", then 1011 will be displayed, but this is not true, you need 1101.

For the values to be read correctly, you need to do this, but it is very long and you can get confused:   if (key & (b100000000000000000000000>> n))

Or like this:: if (key & (0x800000>> n))

@Антон Actually no. If you want to change the endianess (from LSB first in my code to MSB first), you just need to  change the count direction in the for loop: for(int n = KEY_LEN-1; n>=0; n--) This would start at the KEY_LEN-1'th bit (MSB of your key) and count down to bit zero (LSB). No need to write that MSB directly as binary or hex.

Thank! Or you can ask another question:
How can you tell what the very last bit is?
key & (1 << KEY_LEN-1). So?

Or like this: key & 1

In general there is no "last bit". Instead the terms MSB and LSB (Monst/Least Significant Bit) are used. The numbers in C/C++ are right justified, having the LSB at the right, MSB at the left. key & 1 gives you the LSB. key & (1 << KEY_LEN-1) gives you the MSB. If you want to send the bits MSB first (then going down till LSB), you would start at key & (1 << KEY_LEN-1) as the first bit in your transmission and go down to key & 1 (aka key & (1 << 0)), which would then be the last in your transmission.

There was a problem. With a key length like this: unsigned long key = 0xB8C4, everything works fine, but with an increase in its length, for example: unsigned long key = 0xB8C4F9 everything breaks down. How can this be fixed ??


text:
Need help - skipping over some serial.print statements
I have a project I'm working on for a chicken coop.  I want to control the door with timing of the sunrise and sunset.  Also looking to a few other things but somewhere along the way, I must have screwed up the placement of setup(), loop() and other void statements.  I'm not longer getting Serial.print statements to print.  I've done quite a bit of borrowing from other codes (which might be apparent to those that are much better at this than me).  For some of those borrowed codes, I'm getting serial prints.  I'm using this as my debug, so I can verify the values that I'm passing and to determine if they are what I'm expecting, specifically for the times of sunrise and sunset, to control my door actuator.
Any ideas why these various serial.print lines are not printing?
I've indicated some of the serial.print lines with <------------------------.
/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  WARNING!
    It's very tricky to get it working. Please read this article:
    http://help.blynk.cc/hardware-and-libraries/arduino/esp8266-with-at-firmware

  This example shows how value can be pushed from Arduino to
  the Blynk App.

  NOTE:
  BlynkTimer provides SimpleTimer functionality:
    http://playground.arduino.cc/Code/SimpleTimer

  App project setup:
    Value Display widget attached to Virtual Pin V5
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include "DHT.h"
#include <Wire.h>
#include <time.h>
#include <TimeLib.h>
#include <Dusk2Dawn.h>
#include <DS1307RTC.h>

#define TIMEZONE    -6
#define LATITUDE    38.3970
#define LONGITUDE   -90.6412

//The type of DHT that is being used
#define DHTTYPE DHT11   // DHT 11
//Which pin the DHT output is connected to the Arduino
#define DHTPIN 5
DHT dht(DHTPIN, DHTTYPE);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "d*********************************0";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "P**********k";
char pass[] = "m*****************a";

int DisconnectCount = 0;
int ReCnctFlag;
int ReCnctCount = 0;

  Dusk2Dawn HouseSprings(LATITUDE,LONGITUDE, TIMEZONE);
  tmElements_t tm;
  //Changes Mins to the same format as Sunrise/Sunset (minutes after midnight)
  int Mins = tm.Hour * 60 + tm.Minute;
  int Sunrise = HouseSprings.sunrise(tm.Year, tm.Month, tm.Day, true);
  int Sunset = HouseSprings.sunset(tm.Year, tm.Month, tm.Day, true);

//char Str_door_status[] = "";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate: adjust per project
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

BlynkTimer timer;

//Section of code that will handle getting the humidity/temp data and where to send it
void send_sensor()
{
  //Set the variable h to the value for humidity
  float h = dht.readHumidity();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  //Set the variable f to the value for temp
  float f = dht.readTemperature(true);
  //delay(1000);
  //Perform a check if either h or f has no value
  if (isnan(h) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  //These would be used to send data to the serial window
  Serial.println(h); // <------------------------
  Serial.println(f); // <------------------------
  //Set the virtual pin 3 of the blynk to the temperature value
  Blynk.virtualWrite(V3, f);
  //Set the virtual pin 4 of the blynk to the humidity value
  Blynk.virtualWrite(V4, h);
}

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.

}

int in1 = 11;
int in2 = 12;

void motor_stop()
{
  digitalWrite(in1,LOW);
  digitalWrite(in2,LOW);
  Blynk.virtualWrite(V6,0);
  Blynk.virtualWrite(V7,0);
}

BLYNK_WRITE(V6)
{
  int pinValue = param.asInt();
  pinMode(in1,OUTPUT);
  pinMode(in2,OUTPUT);
  if (pinValue = 1);
  {
    digitalWrite(in1,HIGH);
    digitalWrite(in2,LOW);
    Blynk.virtualWrite(V0,1);
    //delay(35000);
    //digitalWrite(in1,LOW);
    //Blynk.virtualWrite(V6,0);
    timer.setTimeout(35000L, motor_stop);
    Blynk.virtualWrite(V0,2);
  }
}

BLYNK_WRITE(V7)
{
  int pinValue = param.asInt();
  pinMode(in1,OUTPUT);
  pinMode(in2,OUTPUT);
  if (pinValue = 1);
  {
    digitalWrite(in1,LOW);
    digitalWrite(in2,HIGH);
    Blynk.virtualWrite(V0,1);
    //removed this delay function as Blynk doesn't like it
    //delay(35000);
    //digitalWrite(in1,LOW);
    //Blynk.virtualWrite(V6,0);
    //Secondary method of delay that Blynk appears to prefer
    timer.setTimeout(35000L, motor_stop);
    Blynk.virtualWrite(V0,0);
  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);

  dht.begin();

  timer.setInterval(1000L, send_sensor);

  //RTC.read(tm);

}

BLYNK_CONNECTED() {
  Serial.println("Connected");
  ReCnctCount = 0;

}

  //Serial.println(Sunrise);  // 418
  //Serial.println(Sunset);   // 1004

void open_door()
{

}

void close_door()
{
  Serial.println("info"); // <------------------------
  Serial.println(Mins); // <------------------------
  Serial.println(Sunrise); // <------------------------
  Serial.println(Sunset); // <------------------------
  char time2[] = "00:00";
  Dusk2Dawn::min2str(time2, Sunrise);
  Serial.print("Sunrise: ");     // <------------------------
  Serial.println(time2); // 16:53  // <------------------------
  char time3[] = "00:00";
  Dusk2Dawn::min2str(time3, Sunset);
  Serial.print("Sunset: ");  // <------------------------
  Serial.println(time3); // 16:53 // <------------------------
}

void loop()
{
  Serial.println(Mins); // <------------------------
  Serial.println(Sunrise); // <------------------------
  Serial.println(Sunset); // <------------------------

  if (Blynk.connected())
  {
    Blynk.run();                                    // Starts Blynk connection
  }
  else if (ReCnctFlag == 0)
  {
    ReCnctFlag = 1;                                 // Set reconnection Flag
    Serial.println("Starting reconnection timer in 3 seconds...");
    timer.setTimeout(3000L, []() {                 // Lambda Reconnection Timer Function
      ReCnctFlag = 0;                             // Reset reconnection Flag
      ReCnctCount++;                              // Increment reconnection Counter
      Serial.print("Attempting reconnection #");
      Serial.println(ReCnctCount);
      Blynk.connect();                            // Try to reconnect to the server
    });
  }
  timer.run(); // Initiates BlynkTimer

  //if (Mins > Sunrise) {
    //Serial.println("Door is open");
  //}
  //if (Mins > Sunset) {
  //  Serial.println("Door is closed");
  //}

}

This is what I'm getting in the serial window:
[45108333] Ready (ping: 53ms).
Connected

Not sure why the code posted weird, sorry for the mess.  Everything ran together from separate lines.

You can see what I did in the edit history.  In short, backticks rather than single-quote characters.  I've changed your attempt at bolding the print statements to indicating them with an arrow in a comment because formatting doesn't place nice with code listings.

I notice in the code is the use of 3 in SoftwareSerial EspSerial(2, 3); which seems to be Serial's RX pin.  But a severely cut down version of your code doing nothing but this didn't seem cause the problem.  My only suggestion is that you start removing code from your question, starting with things that people who might try to help you are not going to want to deal with.  Blynk, the DHT sensor, whatever you can remove while still demonstrating the problem.

put in lots of serial.print statements to determine where the program hangs

you can call Serial.begin() again to "fix" it and see if something else breaks. I'm guessing something is trying to digitalWrite to the serial pin.

@timemage, this is a sketch for Uno

try #define BLYNK_NO_BUILTIN before #include <BlynkSimpleShieldEsp8266.h>

@Juraj, yeah, that does make more sense.  Without a pile of stuff removed, I'm not going to get much use out of that information though.


text:
ATTiny85 won't boot if PIN2 is not pulled high
I had some problem setting up a working ATTiny85 outside of its development board.Connection on my breadboard:
pulled high (10K R)  -- 1  PIN 8  -- VCC (+5V)
     trouble here!!  -- 2  PIN 7  --
                     -- 3  PIN 6  -- LED
               GND   -- 4  PIN 5  --

as you can guess pins are referred to actual chip's pins enumeration.My simple test code:
void setup() {
  pinMode(1, OUTPUT);
}
void loop() {
  if (analogRead(A1) > 512) {
    digitalWrite(1, HIGH);
    delay(250);
    digitalWrite(1, LOW);
    delay(250);
  } else {
    digitalWrite(1, HIGH);
    delay(1000);
    digitalWrite(1, LOW);
    delay(1000);
  }
}

I'm using Arduino IDE v1.8.13 with digistump avrboards v1.6.7.
I flashed t85_default micronucleus v2.5 bootloader in my chip with fuses set to lfuse:0xe1, hfuse:0xdd, efuse:0xfe.The problem is that if I power the chip with PIN2 not pulled high it won't start execution of the code, it won't blink.  If it’s started from pulled high, it will start code about 5s after power on. If it’s started pulled low code won’t execute until is pulled high. As I pull high, even just for a second, PIN2 it will start blinking and executing code.
Is it normal? I think I have missed something.

Well, I've made some headway.  I hope to update this with something more helpful though.
I don't have a digispark or even the correct Zener diodes to replicate the necessary parts of it.  However, I did install t85_default.hex on an ATTiny85 with some alterations to the hex file to place break instructions in a few strategic places.  And then I ran avarice/debugwire against it.
The basic problem is that it's trying to tune the internal oscillator against the USB frames by looking at the D- pin.  Basically, it's stuck in tuneOsccal.
988  00001d06 <tuneOsccal>:
   1     1d06:       b3 9b           sbis    0x16, 3 ; 22
   2     1d08:       fe cf           rjmp    .-4             ; 0x1d06 <tuneOsccal>
   3     1d0a:       07 d0           rcall   .+14            ; 0x1d1a <countFrame>
...

So if you want to avoid this, you need to compile with that feature off, and there is a feature to do that.
I have not yet run one with this feature disabled.  But I did compile t85_default once, using make CONFIG=t85_default and found it necessary to remove the START_WITHOUT_PULLUP from the first line of the t85_default/bootloaderconfig.h file.
The code mentions the existence of OSCCAL_SAVE_CALIB, which lets you specify your own OSCCAL value, assuming the factory one for the chip isn't good enough for whatever reason.  But there doesn't seem to be any guidance on how you're supposed store it or where.  Looking at the code though, if enabled, you can see it loads the OSCCAL value from just before where the bootloader starts.
A simple way to put it there without messing with command-lines and linker scripts would be to just edit the the t85_default.hex that results from building with OSCCAL_SAVE_CALIB enabled, and add an extra record for setting the osccal value at the correct address, which I guess would be 0x19FA, so:
:0119FA00XXSS
Where XX is whatever you've determined your OSCCAL value is and SS is the checksum value, or 0x100 - ((0x14 + XX) & 0xFF) in this case.  Or, if you want to be lazy, put whatever you want for SS and let AVRDude complain tell you what it's supposed to be when it tries to load the .hex file.  It will report the expected value in decimal, which you can convert to hex and patch into the file, and run AVRDude again.

Wow, this is very complicated for my level of understanding, but thanks to references you put in the answer I got the point. It would be kind of difficult for me to edit code given that I don't know assembly and I have a superficial knowledge of c++. For now I think I just start it with pin2 pulled high, then I will try to patch the hex file as you suggested. BTW I think you did a great job with this answer. Thank you.

I will look into making some short instructions.  You won't need to know assembly at all.  The first step would be to just use the standard osccal calibrations and see if that does the job, which wouldn't involve editing the hex file at all.  I may try to get set up to actually attach to USB, which may take quite a while.  Longer than you might think.

@ZenoDallaValle, I have what amounts to a digispark clone (or rather kit) coming that uses a socketed ATTiny85.  When I get it (which may be a while) and assemble it, I'll see about updating the answer with the process used.

I had the same problem, I changed to firmware micronucleus-1.11-upgrade.hex (from 2.3 to 1.11) and it was solved, you can find ir here https://github.com/micronucleus/micronucleus/tree/v1.11/upgrade/releases


text:
Is there a working combination of Arduino IDE + Ardublock?
I'm trying to set up Ardublock, but the last release they have is from 2014 and in a recent Arduino IDE it fails when I try to upload the program to the Arduino board:
Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: processing.app.Editor.setText(Ljava/lang/String;)V
    at com.ardublock.ArduBlockTool.didGenerate(ArduBlockTool.java:72)
   ....

I assume there is a different API in the recent Arduio IDE for copying the generated code into the editor. This is the block diagram I'm trying to upload. As you can see there are no libraries involved:

Is there a known combination of Arduino IDE and Ardublock which works? Or perhaps an addon similar to Ardublock which is maintained?

tinkercad has an online block editor in their circuits feature (drag out an uno to get to the editor).

@dandavis Looks pretty nice, too bad they don't seem to have support for subroutines. I struggle to find examples of programming environments with such a severe limitation, brainfuck interpreter and my first programmable calculator come to mind.

I found that Ardublock project was forked on Github, and the latest release indeed works with up-to-date Arduino IDE.