text:
Boil water inside a small container with an arduino
I am currently working with a sciene/electronic project where i need "steam". In order to create steam i need to boil water and i plan to boil it inside a very small container [around 5cmx5cmx5cm]. What i want to do is to control this with an arduino but I am very unsure on what step i currently need to make. Are there any "heating-up" modules out there? Or would I need to order a mini-mini kettle and connect that to my arduino?
I am very grateful for every advice i can get because as u can tell i am a bit confused as of right now!

You need a little pot and a flame.  Or some small electric heater.  What role will the Arduino play in all of this?

@Delta_G Ok. It will be the one controlling when the heating should start and also im getting a module that will monitor the temperature

So there is for example not a "heating plate" module that u can connect to an arduino that u know of? @Delta_G

Just use a thermocoupler. No need for an arduino here.

I you only want the steam/smoke effect, I'd suggest using ultrasonic air humidifier (like this one). Example usage

Try to find a boiler pot on electricity (I doubt you can heat water to boiling temperature with like 5V (unless you use many amperes).
Use a relais to switch it on with an Arduino.
Use a temperature sensor (0-150 degrees or so) to decide when to switch it off.
Warning: Get first some electrical knowledge before you start with >200 volts projects since it can be deadly. And boiling water can be devestating for skin and your Arduino.

Okok. I see there are some heating pads out there that u can connect straight to an arduino but they seem to only reach a deegre of 40 degrees. I might put this project to rest since my electrical knowledge aint that high and i dont plan to die anytime soon! Thx a ton for ur answer

Good luck ... Probably 40 degrees is what can be maximaly achieved by regular/normal 5V adapters, especially those from Arduino. It's always best to give such 'high power' devices separate power as from the Arduino.

https://www.banggood.com/Waterproof-Silicone-Flexible-Heating-Pad-6060MM-DC-12V-10W-p-972464.html That product looks pretty interesting

You can try, but even for this you need a relais, so the answer will still be similar (except for the electricy / high power warning).


text:
Why connect a diode between the reset pin of Arduino and 555 timer?
I am trying to create a watchdog timer using 555 IC and I am following this.
I do not understand why a 1N4148 diode is connected between the reset pin of Arduino and the output of the 555 timer.

As far as I understand, the reset pin of the Arduino should be high, and when it is pulled low, the Arduino resets. But why should we add a diode over here? What purpose does it serve?

After reading @Majenko's answer, I can see how your schematic would not have made it obvious since it doesn't show any of the other connections on a typical Arduino.

Yeah. And that was the reason, why I did not understand the use of the diode over there.

It's called a "Wired Or" arrangement.
The Arduino's RESET pin has a pullup resistor in it (10KΩ). That keeps the RESET pin normally HIGH. To invoke a reset that pin needs pulling low, and that is done from a number of sources:

The RESET button
The DTR pin (through a 100nF capacitor) of the USB interface chip
The 555 watchdog circuit above

The critical one there is the DTR pin.  That, because it's a brief pulse with quite a high output impedance, needs the reset pin to be easy to pull down. If you connected the output of the 555 directly to RESET it would be constantly trying to pull the RESET pin up to 5V with quite a low output impedance. The DTR circuit would have no chance of overcoming it.
So by adding a diode in there you get Wired Or, using an arrangement direct from the 1950s - DRL - Diode-Resistor Logic.  When the output of the 555 is HIGH the diode is reverse biased (or neutrally biased) and doesn't conduct, so the RESET pin's own resistor pulls the RESET pin up.  However, when the output of the 555 is LOW the diode can then conduct (it's forward biased) and that pulls the RESET pin LOW.

Thanks for the information @Majenko. It was really helpful. I have a small confusion. The RESET pin is not a source of voltage or current, right? So how does the RESET pin become LOW as soon as the 555 is low with the diode conducting? I mean how does current flow from the RESET pin if its not a source of current?

Yes, it is a source of voltage and current. It is connected to +5V through a 10K resistor. Connect it to ground and (5/10,000) 5uA will flow from it to ground.

Every pin is either a source or sink (or both) of current. It's all a matter of how much current (the output impedance) the pin can sink or source.

source: Stack Exchange

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

sort: votes


text:
UID value arduino uno
How to read UID value in arduino uno to PHP language?
before, thanks for a lot

Use this library: https://github.com/rubberneck/php-serial
On GNU/Linux, you may need to be a member of the ‘dialout’ group. Ubuntu solves this problem by making its users members of every group, so you may not need to edit /etc/group
Once you have connected via a USB or USB-TTL cable (the latter will not force a reset upon connect), use a buffer to store all the reads, then parse them.

I using OS Windows sir, How?

@AsepERoni Nevermind, try that library. It will work on Linux, OSX, Windows.

wheter have his way? step by step, because I fairly new for this is..

@AsepERoni Connect to COM1 (or whatever port is used), read data into a buffer, parse it, use it.

@AsepERoni Is the question answered? If yes, please mark it as such.

i having trouble, at the time of convert Heksadecimal to normal number? how?

@AsepERoni It’s internally just in binary. Define a format with e.g. sprintf( bar, “%i”, foo ), or if using serial, Serial.print( foo, DEC ). Split the UID into a 7-byte array with strtok(). There’s no reason to use decimal for the UID...

do you have example?

@AsepERoni for ( int i=0; i<7; i++) Serial.println( uid[i] ) ... it will be null-terminated so try while ( uid[i++] != ‘\0’ ) Serial.println( uid[i] ) as well. I don’t remember the type used in the PN532 example, IIRC char array. It doesn’t matter... format the output to be adequate for your PHP script, and if you need it to be non-blocking, look in the PN532.cpp file. Change the timeout.

why 7 in looping for?

@AsepERoni use the variable uidLength instead of 7. The variable uid is a char array IIRC, so will have no problem with it. PHP is like Perl, so just use join() and split() equivalents.

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


text:
ADS1262 and 2.2 SPI TFT (Two SPI Slave) with Arduino
I am interfacing two SPI slave module i.e. ADS1262 and 2.2 SPI TFT with the Arduino Ethernet board.
When I test each device on its own it works. Initially, I interfaced the TFT to the Arduino and it is working fine. Likewise, the example code of ADS1262 is working fine when I am running it alone.
So after successfully running the TFT alone, I then wire-up the ADS1262, add the corresponding code, however the ADS1262 doesn't seem to respond.
I think the issue may be related to the ADS1262_CS or ADS1262_START or ADS1262_DRDY pin sequence to access the ADS1262.
I have used the ProtoCentral_ads1262 library from GitHub and have used the example code.

From Comments:
We have already reserved D10 for Ethernet Controller and D4 for SD Chip select. The issue is, how to communicate both of them, one by one. I can access one of them only when code is prepare for both devices.

// Portion of the code is given here

// https://github.com/adafruit/Adafruit_ILI9341 library used for TFT

// Code start from here

for(j=initvalue;j<=finalvalue;j+=x)
{

      dacvalue=((j*5)/65535);

      writeValue(j);

      tft.fillRect(30,150,70,28,ILI9341_BLACK);

      tft.setCursor(30,150);

      tft.println(dacvalue,3); // dac value is showing on TFT

      Serial.println(dacvalue,3);

// ADS1262 is need to communicate here as per https://github.com/Protocentral/ProtoCentral_ads1262 library

// Which pins are need to control here to communicate with ADS1262???

      volatile int p,data;

      if((digitalRead(ADS1262_DRDY_PIN)) == LOW)               // monitor Data ready(DRDY pin)
     {
       SPI_RX_Buff_Ptr = PC_ADS1262.ads1262_Read_Data();      // read 6 bytes conversion register
       Responsebyte = true ;
     }

      if(Responsebyte == true)
      {
       for(p = 0; p <5; p++)
      {
        SPI_RX_Buff[SPI_RX_Buff_Count++] = *(SPI_RX_Buff_Ptr + p);
      }
      Responsebyte = false;
      }

       if(SPI_RX_Buff_Count >= 5)
      {
        ads1262_rx_Data[0]= (unsigned char)SPI_RX_Buff[1];  // read 4 bytes adc count
        ads1262_rx_Data[1]= (unsigned char)SPI_RX_Buff[2];
        ads1262_rx_Data[2]= (unsigned char)SPI_RX_Buff[3];
        ads1262_rx_Data[3]= (unsigned char)SPI_RX_Buff[4];

        uads1262Count = (signed long) (((unsigned long)ads1262_rx_Data[0]<<24)|((unsigned long)ads1262_rx_Data[1]<<16)|(ads1262_rx_Data[2]<<8)|ads1262_rx_Data[3]);//get the raw 32-bit adc count out by shifting
        sads1262Count = (signed long) (uads1262Count);      // get signed value
        Serial.println("sads1262Count:");
        Serial.println(sads1262Count);
        resolution = (double)((double)VREF/pow(2,31));       //resolution= Vref/(2^n-1) , Vref=2.5, n=no of bits
        Serial.println(resolution,15);
        volt_V      = (resolution)*(float)sads1262Count;     // voltage = resolution * adc count
        volt_mV   =   volt_V*1000;                           // voltage in mV
     tft.setCursor(166,150);
     tft.println(volt_mV,3); } //not printed on TFT

In above code, ADS1262 is not activated so not giving value on serial window or TFT.
How to activate the ADS1262 module.

Did you use two different pins for the CS? Can you show the electrical connections you used and the code which uses the TFT?

If you are using an Arduino Ethernet board you need to reserve and set the Ethernet Controller and SD chip selects (D10 and D4).

We have already reserved D10 for Ethernet Controller and D4 for SD Chip select. The issue is, how to communicate both of them, one by one. I can access one of them only when code is prepare for both devices.

Could you please give you a link of the partcular display you used? There hundreds of 2.2" SPI TFT modules. Some of them lack proper level translation circuitry.

I would suggest that
1) you debug individual code and to make sure that they work separately before integrating them.
2) you put those code pieces in logical blocks. for example, you are likely going to read something from the adc and displaying it on the lcd. so your code flow should be something like this:
  vol_adc = ad1262_read(ADC1_CH); //read analog from ADC1_CH
  vol_mv = adc2mv(vol_adc); //convert the adc results to mv
  lcd_display(vol_mv);  //display vol_mv on the lcd

this approach allows for much easier programming and debugging for you and your readers.


text:
Adding new programmer to Arduino IDE
I want to use the Arduino IDE using a raspberry pi with raspbian OS because it's the only way I can read a Digispark usb (I don't have 2.0 usb ports in my laptop so I can't read the usb with it).
I installed arduino IDE 1.8.13 so I can add the Digistump package. The problem I got is that when I try to add the drivers from the link http://digistump.com/package_digistump_index.json, it returns Tool micronucleus is not available for your operating system..
I donwloaded micronucleus using
git clone https://github.com/micronucleus/micronucleus

and installed it. Now I have it but I don't know how the arduino IDE could detect it. Could someone help me on how to make the arduino IDE understand I have it (micronucleus) installed?

The question could be answered directly, but it's probably easier for you to just insert a USB 2.0 HUB in the path to your device rather than messing around with the Pi and trying to fix the board support to work on the Pi.   Also, my understanding is that micronucleus can work on USB 3.0 if you get the correct version installed.

Which is the correct version ? I’m new in this stuff, so any answer that could help is really useful :-)

v2.01 (or newer), I think.  Although, the comment seems to suggest it should not have fixed the problems I've seen it fix.  So, dunno.  Sometime in the next week I'll have one of these myself, which is ironic, because I don't recommend them.

@iam_agf, I found this when looking up "laucher", in the process of doing pretty much exactly what's written there.  I compiled micronucleus under Raspbian, but that's about as far as I went.  Kind of looks like they got it working, so I'm not sure what the point in me continuing with it would be.

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


text:
Arduino RTC SD Card problem
I am using a script on an Arduino to record BME280 data onto an SD card and to display it on a lcd display. To have a valid time stamp I am also using a DS3231 RTC module. I set the time succesfully and can manually read it and write it to the serial monitor.
Writing the sensor data to the SD card works fine as well. But as soon as I try to include the time from the RTC into the file onto the SD card the script jumps back to the else statement in the setup() where I try to open the file for writing the header line.
Without using the RTC time it works fine, as soon as I put it in using the corresponding function, it fails.
Here is the script I am using:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define BME_SCK 8
#define BME_MISO 6
#define BME_MOSI 7
#define BME_CS 5

#define SEALEVELPRESSURE_HPA (1013.25)
#define RTC_I2C_ADDRESS 0x68 // I2C Adresse des RTC  DS3231

Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long lastReadRTC = -1;
boolean sd_ok = 0, sensor_ok = 0;
File dataLog;
String dat_time;

LiquidCrystal_I2C lcd(0x27, 20, 4);  //Hier wird das Display benannt (Adresse/Zeichen pro Zeile/Anzahl Zeilen)

void setup()
{
  Wire.begin(); //Kommunikation über die Wire.h bibliothek beginnen.
  Serial.begin(9600); // open serial communications and wait for port to open
  // SD Card Initialization
  if (SD.begin())
  {
    Serial.println("SD card is ready.");
    sd_ok = true;
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
  //if( SD.exists("test.txt") == 1 ){
  dataLog = SD.open("test.txt", FILE_WRITE);
  if(dataLog) {                               // if the file opened okay, write to it:
     Serial.println("OK, writing header");
     // write some texts to 'test.txt' file
     dataLog.println("DATE | TEMPERATURE | HUMIDITY | PRESSURE");
     dataLog.close();   // close the file
  }
  else {
    Serial.println("error opening testfile.txt");
  }
  unsigned status;
  status = bme.begin();
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
    Serial.print("SensorID was: 0x");
    Serial.println(bme.sensorID(),16);
    Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
    Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
    Serial.print("        ID of 0x60 represents a BME 280.\n");
    Serial.print("        ID of 0x61 represents a BME 680.\n");
    while (1) delay(10);
  }else{
    sensor_ok = true;
    Serial.println("OK, sensor recognized");
  }
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Temp. = ");
  lcd.print(bme.readTemperature());
  lcd.print(" *C");
  lcd.setCursor(0,1);
  lcd.print("Press. = ");
  lcd.print(bme.readPressure() / 100.0F);
  lcd.print(" hPa");
  lcd.setCursor(0,2);
  lcd.print("Alti. = ");
  lcd.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  lcd.print(" m");
  lcd.setCursor(0,3);
  lcd.print("Hum. = ");
  lcd.print(bme.readHumidity());
  lcd.print(" %");

  delay(1000);
}

//Reads the current datetime from rtc module
String rtcReadTime(){
  Wire.beginTransmission(RTC_I2C_ADDRESS); //Connect to address 0x68
  Wire.write(0);
  Wire.endTransmission();
  Wire.requestFrom(RTC_I2C_ADDRESS, 7);
  int sekunde    = bcdToDec(Wire.read() & 0x7f);
  int minute     = bcdToDec(Wire.read());
  int stunde     = bcdToDec(Wire.read() & 0x3f);
  //weekday not included
  /* wochentag  =*/ bcdToDec(Wire.read());
  int tag        = bcdToDec(Wire.read());
  int monat      = bcdToDec(Wire.read());
  int jahr       = bcdToDec(Wire.read())+2000;

  char timestamp[30];
  sprintf(timestamp,"%02d.%02d.%4d %02d:%02d:%02d",tag,monat,jahr,stunde,minute,sekunde);
  return timestamp;
}

//Converts binary to numeric
byte bcdToDec(byte val){
  return ( (val/16*10) + (val%16) );
}

void loop()
{
  unsigned long currentMilliseconds = millis();
  if((lastReadRTC + 1000) < currentMilliseconds){
    lastReadRTC = currentMilliseconds;
    lcd.setCursor(0,0);
    lcd.print("Temp. = ");
    lcd.print(bme.readTemperature());
    lcd.print(" *C");
    lcd.setCursor(0,1);
    lcd.print("Press. = ");
    lcd.print(bme.readPressure() / 100.0F);
    lcd.print(" hPa");
    lcd.setCursor(0,2);
    lcd.print("Alti. = ");
    lcd.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    lcd.print(" m");
    lcd.setCursor(0,3);
    lcd.print("Hum. = ");
    lcd.print(bme.readHumidity());
    lcd.print(" %");
    //Serial.println(rtcReadTime());
    if(sd_ok){
      dataLog = SD.open("test.txt", FILE_WRITE);
      //dataLog.print(rtcReadTime());
      dataLog.print(" |  ");
      if(sensor_ok) {
        dataLog.print(bme.readTemperature());
        dataLog.print("°C   |  ");
        dataLog.print(bme.readHumidity());
        dataLog.print("  | ");
        dataLog.println(bme.readPressure() / 100.0F);
        dataLog.close();
      }
      else{
        dataLog.println("  Error    |  Error   |  Error");
        dataLog.close();
      }
    }
  }
  delay(1000);
}

So when I run the script without the RTC time included it gives me the output:

SD card is ready.

OK, writing header

If I include the line dataLog.print(rtcReadTime()); towards the end (in the script commented out) it jumps to the beginning of the setup section into the else statement giving me:

error opening testfile.txt

and nothing is written into the file on the SD card.
I tried to find the mistake for multiple hours yesterday and was hoping to find it today after a good night of sleep, but nope. It is probably an easy fix that i can't see. The code is probably far from perfect or good. I am a beginner in c++, so keep that in mind. :)
EDIT:
As I was not able to find a solution using rtcReadTime(), I used the RTClib.h directly and created the time manually in the writing process for the SD card:
void loop()
{
  unsigned long currentMilliseconds = millis();
  if((lastReadRTC + 1000) < currentMilliseconds){
    lastReadRTC = currentMilliseconds;
    lcd.setCursor(0,0);
    lcd.print("Temp. = ");
    lcd.print(bme.readTemperature());
    lcd.print(" *C");
    lcd.setCursor(0,1);
    lcd.print("Press. = ");
    lcd.print(bme.readPressure() / 100.0F);
    lcd.print(" hPa");
    lcd.setCursor(0,2);
    lcd.print("Alti. = ");
    lcd.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    lcd.print(" m");
    lcd.setCursor(0,3);
    lcd.print("Hum. = ");
    lcd.print(bme.readHumidity());
    lcd.print(" %");
    if(sd_ok){
      dataLog = SD.open("test.txt", FILE_WRITE);
      DateTime now = rtc.now();
      dataLog.print(now.day(), DEC);
      dataLog.print(' ');
      dataLog.print(now.month(), DEC);
      dataLog.print(' ');
      dataLog.print(now.year(), DEC);
      dataLog.print(" ");
      dataLog.print(now.hour(), DEC);
      dataLog.print(':');
      dataLog.print(now.minute(), DEC);
      dataLog.print(':');
      dataLog.print(now.second(), DEC);
      dataLog.print(" |  ");
      if(sensor_ok) {
        dataLog.print(bme.readTemperature());
        dataLog.print("°C   |  ");
        dataLog.print(bme.readHumidity());
        dataLog.print("  | ");
        dataLog.println(bme.readPressure() / 100.0F);
        dataLog.close();
      }
      else{
        dataLog.println("  Error    |  Error   |  Error");
        dataLog.close();
      }
    }
  }
}

Probably far from ideal, but enough for me.

timestamp in rtcReadTime() is a local variable. When you return from that function it ceases to exist - so what you have returned is nothing. You can't print nothing, so the Arduino crashes.
You either need to make the timestamp variable static so that it's not lost when you leave the function, make it a global variable, which has a similar effect, or pass a buffer variable to rtcReadTime() which is then filled instead of returning a pointer to a char.
The simplest of these is just to make timestamp static. Also you should use snprintf instead of sprintf to avoid the possibility of buffer overflows:
String rtcReadTime(){
  Wire.beginTransmission(RTC_I2C_ADDRESS); //Connect to address 0x68
  Wire.write(0);
  Wire.endTransmission();
  Wire.requestFrom(RTC_I2C_ADDRESS, 7);
  int sekunde    = bcdToDec(Wire.read() & 0x7f);
  int minute     = bcdToDec(Wire.read());
  int stunde     = bcdToDec(Wire.read() & 0x3f);
  //weekday not included
  /* wochentag  =*/ bcdToDec(Wire.read());
  int tag        = bcdToDec(Wire.read());
  int monat      = bcdToDec(Wire.read());
  int jahr       = bcdToDec(Wire.read())+2000;

  static char timestamp[30];
  snprintf(timestamp, 30, "%02d.%02d.%4d %02d:%02d:%02d",tag,monat,jahr,stunde,minute,sekunde);
  return timestamp;
}

Thx for the input, sadly that doesn't work. Don't ask me why though^^

Even taking the content out of the function and put it directly into the if(sd_ok)-statement gives me the same result

Btw. I can print the time to the serial monitor by using Serial.println(rtcReadTime());. I would have thought that means returning the variable from the function does work?

It "works" because you have other variables in the function's stack frame acting as a buffer to the timestamp variable - subsequent functions that you call happen to not quite encroach their stack frames far enough through that buffer of old variables in memory to corrupt the string. Purely by chance.

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


text:
Converting an int to an unsigned char for display on a Nokia 5110
I've been working on a small project getting some images displayed in a Nokia 5110 screen via an Arduino. I've been getting it working, but one of the issues I have is that I would like to have a list on integers and convert that an unsigned char array that the display requires. Generally I have something like this which works out of the box.
unsigned char src [] PROGMEM = {0x00, 0x00}

Surprisingly, I found that this also works
unsigned char src [] PROGMEM = {255, 255}

But when I have a list like this
int src [] = {255,255}

and try to convert it to an unsigned char array, things don't display correctly
unsigned char new_src[2];

for (int i=0; i<2; i++){
    new_src[i] = (unsigned char) src[i];
}

When I try to display this, it's clearly broken. I thought simply casting the int to an unsigned char would be enough (it doesn't work even if I don't cast it).
Here's how I display the array (for 84x48, the above arrays were just an example) :
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
display.drawBitmap(0, 0,  src, 2, 48, BLACK);
display.display();

On more note:
The end game is to have a file with a list of ints. I would then read that list of ints into an array and convert it into an unsigned char array and then display that.

How do you display src?

@EdgarBonet edited into the original post

What do you mean by “works”? 2. Why arrays of length 2? For an 84×48 bitmap you need an array of 528 bytes. 3. Does it still work if the PROGMEM arrays are const? 4. Why do you want to have a list of int? Other than wasting RAM, what does that give you that a list of uint8_t doesn't?

"works" as in displays the image properly. 2. This was just an example for simplicity sake. 3. Yes it still works. 4. Because I'm reading the integer values out of file. 4. My C skills aren't as sharp as your so I'm sorry for wasting RAM. @EdgarBonet

Besides mentioning it, I don't think @EdgarBonet's point was the extra RAM (or Flash), but on the fact that storing your data as 'unsigned char src [] PROGMEM' works for you - why do not use that?

@JRobert I'm unable to put them in the Arduino code at compile time. The idea is that I would read a list of ints from a file ( I have several files that I would iterate through) and convert that list to the unsigned char array on each loop iteration. If there's a way to store a unsigned char array in a file and read that directly, I could just as well do that.  I'm trying to automate the process of having to go to a website to convert my bitmap, and then copy the result into my Arduino code. I have the conversion part complete via a Python script and now I'm tryin to get it over to Arduino.

The idea is that I would read a list of ints from a file ( I have
several files that I would iterate through) and convert that list to
the unsigned char array on each loop iteration.

The file could be a stream of bytes just as well as a stream of ints (or uints). If it were, no conversion would need to be done - just read a byte & store it, read a byte & store it, ....  If instead, it is a character representation of values, "37, 150, 8, ...", again, read the characters of one value, convert them to int8_t or  uint8_t and store them in your byte array. Look up the atoi() or sscanf() functions to do the conversion.


text:
I want to stream audio from an Arduino to a device on the wifi
I only started learning Arduino recently. This is my first project.
So the idea for the project is that there will be an Arduino board(Ideally an Uno but I don't know if another board would be better) and when you hold a button down it will transmit what you are saying to a device on the wifi. I know I will have to get a WiFi module and like a microphone and button, so can you help me figure out just the gist of how the project will go and what parts I should get.
Thanks!

You should ditch the Uno here. The wifi module (which is likely an ESP) wil already be a way more powerful microcontroller than the Uno. So just move to a boatd with buildin wifi, like an ESP32 or similar. They also have an I2S interface, where you should be able to connect a good ADC to for audio sampling

An Arduino can do this, but this is a very advanced problem on an Arduino. It sounds like perhaps you need something more plug-and-play. In that case, buy a Raspberry Pi 4 starter kit and a USB microphone, and start working on the problem from there. The Raspberry Pi 4 is a Linux computer, so everything you do will be writing scripts or programs (in any language: it's just a regular computer, so use Python, C, C++, Java, bash, whatever you want) to run on its Raspberry Pi OS (formerly called Raspbian) Linux operating system.
If you go this route, you'll want to ask your questions on the Raspberry Pi Stack Exchange as well.
Keep in mind the question you asked is too broad. You are generally expected to do your own background research and then ask more specific questions, demonstrating what you've already tried.
Getting an Arduino to send out microphone data is, like I said, a very advanced subject and project (think: professional level / expert hobby level) unless you can Google and find pre-made libraries and how-tos on the subject.
Essentially, for the Arduino Uno route you'd need to do some fancy high-rate ADC sampling with a modified ADC clock rate in a special ADC mode which takes repeated samples and then interrupts your code when a sample is ready, rather than just doing normal analogRead() since that is both blocking/polling-based which wastes clock cycles and creates sample jitter which causes audio distortion, and then you'd need to send this data via some Wifi shield (add-on board) or an ESP8266 or something, or via some other technology (wired or wireless) to a computer to pass it on to the internet. This may involve binary packetization/bit-packing, error checking, buffering, etc., all of which is its own special skill to acquire.
Some of my projects have taken me 3+ years to complete them, since I began complicated projects as a beginner. This is one of those multi-year type projects for a beginner for sure.
(Heck, if you give me two LEDs and two resistors and an Arduino Nano, with those items alone, I can send you on your way to work 8 hrs a day for 3 months straight on projects. It's easy to under-estimate the complexity of something until you're neck-deep in it.)
Update: if you want to go the Arduino route, here's some tips to get you on a search route more likely to get you to a solution faster. Again, no doubt an Arduino Uno can do this. It for sure can. But, a faster Arduino can do it easier and better. So:

Google search for projects on Adafruit which may do this. Ex: Google search for "adafruit stream audio". Their tutorials are 2nd to none--the best in the world--and their products top-notch.
Search for projects on Sparkfun which may do this. Ex: Google search for "sparkfun stream audio". They also are excellent and have world-class tutorials.
Search for projects which do this with a Teensy, Zero, Due, or other high-speed 32-bit microcontroller, instead of an Uno. Audio processing is more difficult for a slower 8-bit Uno than for any of those 3 Arduino/Arduino-compatible devices.
Also look on Instructables.com for tutorials and help.
One more thought: Google search for "atmega328 stream audio to wifi" (an Uno uses the ATmega328 microcontroller, so that's a good search term to use)

Update: also take a look at this tutorial by GreatScott (who is also super awesome) (https://www.instructables.com/id/Make-Your-Own-Spy-Bug-Arduino-Voice-Recorder/), which uses this AVR-based (for ATmega328: Arduino Uno, Nano, Pro Mini, etc., or ATmega2560: Mega) advanced audio library for both recording and playing back audio. See:

https://github.com/TMRh20/TMRpcm

Recording Audio
Audio streaming over NRF24L01+ radio link

Would it be easier if you just send an audio file.
So if you click the button it'll just send an audio file.

Yes. That removes the entire complexity of sampling the audio with the ADC.

You'll need to store the file on an SD card or in a non-volatile FRAM.

So the idea is that if my mom is downstairs and I'm in my room playing games or something, she can click the button and it will say, "come downstairs" to me on my headphones or whatever audio I'm using. Is that possible

You can use a ESP32 with built-in WiFi and Bluetooth. Record a wave-File to a SD-card using this library, send it over Blutooth and play it on the PC with a little script.

That link you have to https://www.instructables.com/id/Make-Your-Own-Spy-Bug-Arduino-Voice-Recorder/ relies on libraries built for the ATmega328 microcontroller (https://github.com/TMRh20/TMRpcm), and would likely require significant advanced modifications to run on an ESP32. But, you could always split the project and use 2 microcontrollers: one ATmega328 (Uno, Nano, or Pro Mini), and one ESP32.

Sorry, didn't recognized. Here is a library for the ESP32.

Nice! Please add that link to your answer too (while keeping in the Great Scott Instructables link too). Upvoted.

I just can't figure out how to transfer the file. Some people say that the only solution is transfering it byte by byte, but that could be quiet hard and I didn't find any library for it. You could record some sample files (like in your example "come downstairs"), assign to numbers and send just the numbers the PC so he can find out which file to play.

You can upload a wav to a webserver using the ESP32 and download it over Python. Or you upload a text file and read it over tts, which should be faster with a bad connection.


text:
I am looking into putting sound files onto an Arduino Nano without a microSD card
I figured out how to install the sound onto the card from this site
https://github.com/charliegerard/dev-notes/blob/master/arduino/wavFilesWithoutSdCard.md
It says I need to use pin 11 on the Uno but would pin 11 on the nano work or not? I am getting these boards.
https://www.amazon.com/gp/product/B0713XK923/ref=ox_sc_act_title_3?smid=A2WWHQ25ENKVJ1&psc=1
Also, does anyone have good speaker suggestions, I'm going with these right now(https://www.amazon.com/CQRobot-JST-PH2-0-Interface-Electronic-Projects/dp/B0738NLFTG/ref=sr_1_6?dchild=1&keywords=speakers+arduino%5D%5C&qid=1607285501&sr=8-6)
I'm not sure if I'm giving enough information so just tell me if I need to provide you with more information.

what's special about pin 11?

It just says to use pin 11 so I'm just going to use it.

what is your end use? ... why do you wish to use wav files?

So I am trying to play an audio file at the click of a button and I don't have to use .wav files it just says that in the thing. But the audio file is super short so I can put it on the arduino without a microsd card holder.

Uno and Nano uses the same Atmel MCU, so pin 11 is the same on both.
And a for the speakers, Arduino CAN'T driver 8ohms load! You need a amplifier.

To add to the above for those wondering why pin 11: The OP is apparently using the PCM library for Arduino which is hardcoded to use OC2A, that is timer 2 output compare A: https://github.com/damellis/PCM/blob/v1.0/PCM.c#L108   Which is Arduino Pin 11 for these 328P models.

Is there a way I could use another pin?


text:
Conflicting pins between the PCM library and speaker and the NRF24L01
The PCM library uses pin 11 and the NRF24L01 also uses pin 11. I am using an Arduino nano, and don't know if there is any way to change the pins of either the speaker or the transceiver.
https://github.com/damellis/PCM

No, you can't just change pins. Both systems use hardware that is specific to pin 11.
The best you could achieve would be to use a software SPI implementation on other pins to drive the nRF24L01, but that would mean changes to the library you are using to remove the SPI library usage and replace it with your own software SPI implementation.

So does that mean it's basically impossible?

Not impossible, just a lot of work, and the results won't be as fast as with hardware SPI.

Oh :(. Is there no way to edit the PCM library to use another pin? What makes pin 11 so special?

It's hard-wired to a specific timer to generate the PWM signal. You could re-write the PCM library to use different timers and their associated pins, but that would be more work and much harder to understand.

I might be wrong, but didn't pin 11 in the PCM library have also been pin 3? So could it be changed to that?

I don't know enough about AVR PWM. It may be possible if you can work out the register settings, for which you'll have to refer to the datasheet for the AVR chip. Personally I wouldn't even begin to consider doing audio on a little 8-bit Arduino. Choose a 32-bit MCU with I2S if you must do anything more than a beep.

I'm just playing a short 2-second audio file.

@Epicmania, you could try to replace OCR1A with OCR1B in PCM.cpp (and OCIE1A with OCIE1B) to use pin 3. do not change other 1A/1B

thank you, I have been trying to change it but I changed much more than that(TCCR2A to TCCR2B), I'll try it with just those changes.

It didn't work :(


text:
Using BLE via NRF24L01 to communicate with Android phone
I have been going through a tutorial about this, based on the example code for the "BTLE" Arduino Library.
This is my program:
#include <SPI.h>
#include <RF24.h>
#include <BTLE.h>

RF24 radio(9,10);
BTLE btle(&radio);

void setup() {
  Serial.begin(9600);
  while (!Serial) { }
  Serial.println("BTLE advertisement receiver");
  btle.begin("");
}

void loop() {
  if (btle.listen()) {
    Serial.print("Got payload: ");
    for (uint8_t i = 0; i < (btle.buffer.pl_size)-6; i++) {
      Serial.print(char(btle.buffer.payload[i]));
    }
    Serial.println("");
  }
  btle.hopChannel();
}

I saw a video of a person running this code, and then sending advertising information via the "nRF Connect" Android app.
In that video (https://www.youtube.com/watch?v=DGgjdBSId4Y) they would receive output in the Serial Monitor very regularly, as I would expect.
When I run my code, and start advertising, then I see the name of my phone only every other minute in the output, and between that time, there is a lot of garbage. I cannot copy the output because of too many special characters.
I would expect the string that I am advertising to show up approximately every 100ms, as that is the rate of the advertisement.
Any idea what I could be doing wrong, or how to debug this better?


text:
Strain Gauge with HX711 Load Cell Amp
I am trying to get a strain gauge working with the HX711 load cell amp. I posted about this a few months ago and got told to get some high precision resistors for the wheatstone bridge. I have now obtained these (https://www.digikey.fi/product-detail/en/vishay-foil-resistors-division-of-vishay-precision-group/Y0007350R000T9L/Y0007-350-ND/2609877).
My wiring and code are as shown below. The wiring is basically a wheatstone bridge with one arm replaced by the strain gauge and each of the corners of the wheatstone bridge connected to RED, BLK, WHT and GRN on the red HX711 (BLK and GRN are the ones connected to the strain gauge arm). On the other side, VCC is to 5V on the arduino, GND to GND on the arduino, DAT to digital pin 5 and CLK to digital pin 6.
#include "HX711.h"

#define calibration_factor -550.0 //This value is obtained using the SparkFun_HX711_Calibration sketch
#define DOUT  5
#define CLK  6

HX711 scale;

void setup() {
  Serial.begin(9600);
  Serial.println("HX711 scale demo");

  scale.begin(DOUT, CLK);
  scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

  Serial.println("Readings:");
}

void loop() {
  Serial.print("Reading: ");
  Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
  Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
  Serial.println();
}

The problem is that the values are not changing when I bend the strain gauge. Only random, short spikes in values are happening and they do not seem to correspond to the strain gauge being strained or unstrained (see below). Any ideas what could be causing this?

Any help is greatly appreciated.


text:
Built-in LED lighs up spontaneously
I'm trying to connect my ESP32 to this CO2 measurement device. I admit I am clueless about connecting devices with independent power sources to one another.
I connected ground to ground and CLK to PIN2. Just to be on the safe side, I put a resistor between CLK and PIN2.
I started with 4.8KOhm of resistance. ESP's ADC measured 2.1V and it seemed fine. But when I switched to 1K resistor, trying to get closer to the level of "logical 1" (the way I understand it), something unexpected happened. ADC measured 2.65V, which is still beyond 3.3V ESP should be able to handle, and the built-in LED lit up, although nothing in my sketch called for it.
Though the configuration worked stably for some minutes while I was testing it, and no smoke appeared, I am afraid the LED lighting spontaneously might be a sign of an electrical breakdown.
The both devices are sitting on the same USB hub.
Here is the sketch I am using:
#define PIN_CLOCK  2

void setup() {
  pinMode(PIN_CLOCK, INPUT);
  Serial.begin(4800);
}

bool last = 0;

void loop() {
  int x = analogRead(PIN_CLOCK);
  bool val = x > 1500;
  if (last != val)
    Serial.println(x*3.3/4095);
    last = val;
  }

Can someone explain why the LED lights up?
Can someone recommend a good article/video on basic rules about interconnecting such devices?

You do not need a resistor in the circuit. Just connect the devices together directly as shown in the tutorial you link to. They are both 3.3V devices and operate perfectly together with no additional components.
Reading an analog value from a clock signal is pretty meaningless anyway, so there's really no point in your experiments at the moment. They prove nothing.
As to why the light came on - that is most likely because the ESP is configured to use that LED to indicate the WiFi status or something similar.  The thing with an ESP32 is there is a whole lot more going on than just your code. Your code is just one thread in a complex system.

The clock pin is an output from the ESP to the nRF24L01. Could you expand on that? I have probably misled you, by calling it "CLK". I meant I connected what in the tutorial called ZG-C to D2. nRF24L01 is a part of a different setup. Still the question is: "why the built-in led"?

Ah, so you're using section 3.2 of the tutorial? It still stands that you don't want a resistor in there. As to the internal LED - that may be being controlled by the WiFi code and have nothing to do with what you are doing.

A schematic would be a big help and maybe links to the particular modules your using and there data sheets.


text:
How do I pause a loop just once?
I´m trying to make a pause in a loop, but just for the first time it loops. The next loops i would like the program to NOT do the pause. Just once time, each time a button is pressed. Does anybody knows how to do it?
Thanks!
This is the code i want to pause just once:
void loop() {
  if(digitalRead(switch_pin) == LOW){
    digitalWrite(led_green_pin,LOW);
    digitalWrite(led_red_pin,HIGH);
    lastMotionState    = currentMotionState;
    currentMotionState = digitalRead(MOTION_SENSOR_PIN); //
      if (currentMotionState == LOW && lastMotionState == HIGH) {
      servo.write(90);
      }
      else
      if (currentMotionState == HIGH && lastMotionState == LOW) { // pin state change: HIGH -> LOW
      servo.write(0);
      }
  }

Does anybody knows how to do it? is not a question that asks how to do it ... it is not a question about the arduino

what do you mean by pause? ... that implies that the code would somehow start up again, but you said nothing about what would stop it and what would start it again and where it should "pause"

Juan, https://stackoverflow.com/help/merging-accounts

The following code will pause (Give some delay) when it runs for the first time and also when you press the button.

void loop() {
  static int status = true;
  if(status){
    //Pause
    delay(15);
    status=false;
    return;
  }

  if(digitalRead(switch_pin) == LOW){
    digitalWrite(led_green_pin,LOW);
    digitalWrite(led_red_pin,HIGH);
    lastMotionState    = currentMotionState;
    currentMotionState = digitalRead(MOTION_SENSOR_PIN); //
      if (currentMotionState == LOW && lastMotionState == HIGH) {
        servo.write(90);
      }
      else if (currentMotionState == HIGH && lastMotionState == LOW) { // pin state change: HIGH -> LOW
        servo.write(0);
      }
  }
  else{
    status = true;
  }
}

Give delay according to your need.

I don't know what that continue; line does when there isn't a for/while/do-loop.

Better would be void loop() { static int status = true; ... } keeping the scope of status inside of loop() instead of global.

@Gerben and lurker thanks for pointing that out. I have made the changes accordingly. Instead of continue I have added return which will work as desired.

This is pretty simple, although you shouldn't see any difference, because loop() is running a lots of times in one second. But:
bool firstrun = true;
void loop() {
  if(firstrun == true){};
  else{
    if(digitalRead(switch_pin) == LOW){
      digitalWrite(led_green_pin,LOW);
      digitalWrite(led_red_pin,HIGH);
      lastMotionState    = currentMotionState;
      currentMotionState = digitalRead(MOTION_SENSOR_PIN); //
        if (currentMotionState == LOW && lastMotionState == HIGH) {
          servo.write(90);
        }
        else if (currentMotionState == HIGH && lastMotionState == LOW) { // pin state change: HIGH -> LOW
          servo.write(0);
        }
    }
  }
  firstrun = false;
}


text:
My LED display fails with MSGEQ7 output stuck
I have an Arduino setup with a pro-mini, a MSGEQ7, and a auto-gain mic. Even if I remove the audio input to the MSGEQ7 remains the same in the 890s (out of 1024). It's the same on each of two new MSGEQ7. I've checked the schematics, https://www.instructables.com/Music-Sync-Flashing-LEDs-Arduino-MSGEQ7/, multiple times and everything seems in order including components.
I'm using the #include <MD_MSGEQ7.h>, but I've tried it without.
Any ideas?
#include <Adafruit_NeoPixel.h>
#include <MD_MSGEQ7.h>

int LEDPIN = 12;
int MODEPIN = 10;

int mode = 0;
int lastState = LOW;

int NUMPIXELS = 50;

int DATA_PIN = 1; // read from multiplexer using Analog Pin 1, MSGEQ7 pin 3
int STROBE_PIN = 2; // MSGEQ7 pin 4
int RESET_PIN = 3; // MSGEQ7 pin 7

int spectrumValue[7];

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, LEDPIN, NEO_GRB + NEO_KHZ800);
MD_MSGEQ7 MSGEQ7(RESET_PIN, STROBE_PIN, DATA_PIN);

void setup() {

  Serial.begin(9600);
  pinMode(MODEPIN, INPUT);
  pixels.begin();
  MSGEQ7.begin();
}

void loop() {
  int currentState = digitalRead(MODEPIN);

  if (currentState == LOW && lastState == HIGH) {
    mode++;
    if (mode > 2) {
      mode = 0;
    }
  }
  lastState = currentState;

  MSGEQ7.read();

  for (int i = 0; i < 7; i++) {
    Serial.println(MSGEQ7.get(i));
  }
  if (mode == 0) {
    for (int i = 0; i < NUMPIXELS - 1; i++) {
      pixels.setPixelColor(i, pixels.Color(30, 60, 60)); // RGB
    }
  } else if (mode == 1) {/////////////////////////////////////////////////////////
    int height = (NUMPIXELS - 1) * MSGEQ7.get(1) / 1024;
    for (int i = 0; i < NUMPIXELS - 1; i++) {
      if (i < height) {
        pixels.setPixelColor(i, pixels.Color(60, 60, 0)); // RGB
      } else {
        pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // RGB
      }
    }
  } else if (mode == 2) { /////////////////////////////////////////////////////////
    pixels.setPixelColor(0, pixels.Color(120 * MSGEQ7.get(5) / 1024, 0, 0)); // RGB
  }
  pixels.show();
}

Not much to go on here. Where's your code? Are you saying you followed the schematic in that article exactly, including components? What does "...I remove the mic the output..." mean?

Edited. Thank you.


text:
Basic hardware debouncing
I was watching Jeremy Blum's Arduino tutorial series, and he explained the need for debouncing in a simple circuit involving a pushbutton. Pressing the button once should mean the led stays on, and pushing the button again should mean the led should stay off, and so on.
He implemented hardware debouncing on this circuit: using an RC circuit along with an inverting Schmitt trigger.
https://www.youtube.com/watch?v=CRJUdf5TTQQ&list=PLA567CE235D39FA84&index=10 2:45-8:45.
However, the circuit isn't performing as expected, when I implemented the denbuncing. Its behaving as if the debouncing has no effect:-

If anyone wants to see the simulation:-
https://www.tinkercad.com/things/dniOQmnxJPY
Where exactly have I gone wrong? I have checked all the connections multiple times, it seems to be what Jeremy blum had in his video...

I changed the "debugging" in the title to "debouncing", because obviously you meant that. Also "hardware debugging" has a specific meaning with microcontrollers. That would only lead to confusion

When following the link for your simulation I am required to log in. Maybe you need to make the simulation public somehow, before anyone can see it.

I see, thanks for letting me know

@chrisl I have made it public now.

@chrisl i have edited the link

@PythonSchlange I gabe edited the link/

@jsotola it means the circuit is behaving similar to how it behaved prior to debouncing.

You have shortened the lower and upper pins of 74HC14, no?

@SBF how have I shorted it?

what connects the top right resistor to the LED?

@jsotola I dont..get your question.... The cathode of the led is connected to ground through a resistor...

what makes the connection between the resistor and the LED?

@jsotola the metallic rails of the breadboard....?

yes, that is correct ... now look at where you plugged in your IC

@satan29 What SBF meant is the following: The 74HC14 has 2 rows of pins you have put it on one side of the breadboard. That means, that the first on the left pin row of the chip and the first on the right row are connection. Similar for all other pins. Such chips need to be placed right in the middle of the breadboard, so that there is no electrical connection between the sides. That is your problem.

You should look up a tutorial on youtube about how to use a breadboard. Your configuration has serious issues. Fyi, on your74hc14, pin 7 is ground, and pin 14 is Vcc (power). You have power going to pins 1 and 14, and ground going to pins 7 and 8. You have the other opposing pins connected to each other as well.

oh i see @chrisl, thanks.

@lurker tinkercad offers to let you know which pin does what in the IC. I know how to use a breadboard! but i haven't worked with IC's much, and I do understand the error crisl has pointed out.

You did not change the lastbutton, but you compared it to HIGH. Change your code to the one below.
You can more easily avoid such mistakes, if you put spaces around operators.
//sp is switchpin, lp is ledpin

int sp=2; //interrupt enabled pin (interrupt 0)
bool ledon=LOW;
bool lastbutton=LOW;
int lp=9;
void setup()
{
  Serial.begin(9600);
  pinMode(sp, INPUT);
  pinMode(lp,OUTPUT);
}

void loop()
{

   if (digitalRead(sp)==HIGH && lastbutton==LOW){
      ledon=!ledon;
      lastbutton = HIGH; // previously here was lastbutton==HIGH;
   }

   else {
     lastbutton=digitalRead(sp);
      }
   Serial.println(ledon);
   digitalWrite(lp,ledon);

     }

Ah yes. Thanks! The debouncing works perfectly now. But for some weird reason the LED turns on at the start of the simulation....without pressing the switch or anything....any idea why?

I think because of your filter. It takes some time to charge up that capacitor, that means your Inverting Schmitt Trigger input starts low, and at the first run of the loop, your pin 2 starts high. If you put a small delay in your setup(), the LED starts off.

indeed. delay(100) fixes this . Thanks a lot!


text:
how to make this work auto on off led with fading
I'm working on a project with Arduino to make LED timer with fading feature. After doing some research finally I wrote some code but it's not working until now
P.S i don't have any knowledge in coding at all T_T
Edit: Adding more details about the issue;
when trying to check upload this error is always shown.
Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

\SunRisetimer.ino: In function 'void loop()':

SunRisetimer:55: error: 'startOff' was not declared in this scope

     startOff();
\SunRisetimer.ino: In function 'void startOn()':

SunRisetimer:89: error: variable or field 'startOff' declared void

 void startOff

SunRisetimer:91: error: expected '}' before ';' token

analogWrite(uled, 1);

SunRisetimer:116: error: expected '}' at end of input

 }
exit status 1
'startOff' was not declared in this scope

Code:
#include <DS3231.h> //Include the clock library

// Changable Vars
int fadeTimeOn = 30; // How long the light will fade to max
int fadeTimeOff = 30; // How long the light will fade to min
int setHourOn = 9; // Set hours to wake (military time)
int setMinOn = 15; // Set minute to wake
int setHourOff = 9; //set off h
int setMinOff = 30; //
int uled = 9; // Set pinout with with PWM

// Set up Vars
DS3231  rtc(SDA, SCL);
Time t;
void start();

void setup()
{
  pinMode(uled, OUTPUT);
  Serial.begin(9600); // Match to serial monitor
  rtc.begin();
}

void loop()
{
  t = rtc.getTime(); // Make a time class called 't'

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

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

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

  if (t.hour == setHourOn && t.min == setMinOn) // Check if it's time to wake up!
  {
    startOn();
  }

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

 if (t.hour == setHourOff && t.min == setMinOff) // Check if it's time to off!
  {
    startOff();
  }

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

void startOn()
{
  // Fix for SB LED
  analogWrite(uled, 1);
  delay((fadeTimeOn * 60000)/50);
  analogWrite(uled, 2);
  delay((fadeTimeOn * 60000)/50);
  analogWrite(uled, 3);
  delay((fadeTimeOn * 60000)/50);
  analogWrite(uled, 4);
  delay((fadeTimeOn * 60000)/50);
  analogWrite(uled, 4);
  delay((fadeTimeOn * 60000)/50);
  analogWrite(uled, 5);
  delay((fadeTimeOn * 60000)/50);

for (int i = 6 ; i <= 255; i++)
    {
    analogWrite(uled, i);
    delay(((fadeTimeOn * 60000)/306));
    Serial.print(" mil sec ");
    Serial.print(((fadeTimeOn * 60000)/306));
    Serial.print(" PWM " );
    Serial.print(i);
    {
}

void startOff
{
  analogWrite(uled, 1);
  delay((fadeTimeOff * 60000)/50);
  analogWrite(uled, 5);
  delay((fadeTimeOff * 60000)/50);
  analogWrite(uled, 4);
  delay((fadeTimeOff * 60000)/50);
  analogWrite(uled, 3);
  delay((fadeTimeOff * 60000)/50);
  analogWrite(uled, 2);
  delay((fadeTimeOff * 60000)/50);
  analogWrite(uled, 1);
  delay((fadeTimeOff * 60000)/50);

  // Fade script
  for (int i = 6 ; i <= 255; i++)
  {
    analogWrite(uled, i);
    delay(((fadeTimeOff * 60000)/306));
    Serial.print(" mil sec ");
    Serial.print(((fadeTimeOff * 60000)/306));
    Serial.print(" PWM " );
    Serial.print(i);

  }

}

"it's not working" is not a useful description of the problem. Please edit your question to provide specific details.

sorry for not gifting the complete information :) error log put in the post now

Look at your function definitions:
void startOn() // works
void startOff    // doesn't work

You are missing the () after startOff.

great its work even tough its not dim out and off but it make me one step ahead. thanks


text:
How do I lower clock speed for MKR1000?
According to data sheets, the MKR1000 runs a SAMD21 Cortex-M0+ processor at 48 MHz. For a project I need to drop that down to 16MHz to get some accurate timing in us. How can I do this? Most of the suggestions on the internet involve the ATmega* boards.
Thanks in advance.

Because I'm interfacing with external hardware that can only handle 16MHz.

add the comment about interfacing 16MHz to your question, then delete your comment. ... replace the to get some accurate timing in us with the reference to external hardware .... i am deleting my comments.

48 MHz is a multiple of 16MHz. Why not just adjust the timing code to account?

As noted above, I am not certain this will work, because I'm interfacing with some external hardware whose max speed is 16MHz. I'm trying to slow down for that. Maybe I need some artificial delays inserted, then?

Elaborate on your external hardware, then.


text:
How to prevent the Serial Monitor from closing upon re-uploading sketch?
I'll be teaching a year 10 class on the Intel Galileo gen2 and there'll be a wide (but high-level) programming curriculum, which includes introduction to console printing, using Serial.
I'd like the students to be able to write their printing code in setup() so that it's only printed once and easily readable by them. However, it's impossible to be fast enough to upload a sketch and open the Serial Monitor (which flat out refuses to open before the sketch has started), and the Serial Monitor closes itself upon re-uploading code.
Without unnecessary (and potentially for the students, confusing) use of the delay function in setup(), it's impossible to read any output originating from setup(); only things printed in loop() (which are constantly re-printed) are ever discoverable.
So; is there a way to somehow keep the Serial Monitor open, or make it capture output from before it's opened, or delay the entire running of the sketch (rather than chucking in delays)?
We'll be using the standard Arduino IDE.
EDIT
This script was run in one of two conditions...
void setup() {
  Serial.begin(9600);

  // ensure Serial is ready
  delay(1000);

  for (int i=0; i < 10000; i++) {
    Serial.println(i);
  }
}

void loop() {
}

When the Serial Monitor was opened immediately after upload, all numbers from and including 0 to 9999 were recorded in the monitor.
When the Serial Monitor was opened around 5s after upload, only numbers upward of 2243 were observed. This suggests the sketch WAS being re-run (else no numbers would have been captured; the sketch runs in significantly less time than 5s) but that all numbers between 0 and 2243 were not captured by the monitor; as if opening the Serial Monitor late enough to cause a re-run causes some monitor overhead.
This strange loss of numbers is NOT time dependent: increasing the initial delay from 1s to 4s (and waiting longer after upload before opening the Serial) did not at all vary the soonest number recorded, suggesting it is some 'line' based overhead
(but of course, how could anything fail for 2243 lines?!)
With that mystery aside, this negates the automatic re-running of the sketch upon Serial Monitor opening from being actually useful.

Opening the serial monitor normally resets the Arduino anyway. I have no problem outputting stuff from setup on a Uno. Is this different with the Galileo?

Serial Monitor is only a convenience (although the need to close and reopen it is APITA). There is nothing stopping you from using any other serial program; e.g. I have used Minicom, but most often use a dedicated serial program for logging.

@RogerRowland On the Galileo, the sketch 'appears' to restart, but actually a lot of early Serial is not captured.
See my edit.

@Milliways The objective outcome of this question is to avoid confusion in highschool students, something that wouldn't be worsoned by only the most absolutely intuitive, minimal, usable serial program.

Have you tried hitting the reset button while the serial monitor is open?  I have done this on other Arduino boards to capture stuff in the setup loop that was occurring too fast.  Otherwise using Serial1 for output connected via a FTDI cable may be the way to go.

Of course! Pressing reset does not require a re-upload, keeping the Serial Monitor open to capture all printing (no buffer filling). Perf

I assume you are uploading the code over USB - the same USB that you want to monitor for output from the sketch? If so, the serial monitor has to release the port for the uploader to be able to use it, and vice-versa, as your computer's OS will only assign a USB port to one application at a time.
It may seem like the IDE is one application containing an uploader and a serial monitor, but the IDE is not much more than a "pretty face" that runs separate compiler and uploader applications on your behalf.
Several work-arounds are possible (although I think a delay() statement in setup() is the clearest of the choices):

Add a delay statement in the setup function. If you must this, you can put it in main() just before the setup() call, but you'd take away a learning opportunity.
Use a separate hardware or software serial channel for the monitor which you could leave connected and wouldn't interfere with uploading;
Use the loop() function instead, and put a forever loop at the bottom to prevent it returning, thus making it a runs-once function.

Does this really explain that strange 'missing lines' anomaly described in my edit? I can give the computer 10s of delay to switch back to the monitor after uploading, but it still misses information.

Also, there's nothing special about the setup function, right? If I made loop a runs-once with no delay in setup, I'd have the same symptoms wouldn't I?

The only reason to put the printing code in loop() is that it is conventional to use setup() for initializing stuff, and loop() for doing work. Otherwise, you're right - no difference. As to the missing lines, I suspect it's something to do with the serial buffer filling before you connect to let it empty, but I'm not sure, without some testing, what the interaaction is. But in my projects I typically print the revision # at start-up. Without a brief delay, my terminal usually displays a bunch of garbage at connect, before it gets synchronized.


text:
Arduino & RPi communication via GPIO
so I'm working on communication between arduino and RPi via GPIO pin.
It's basically connecting them by using a cable jumper. So I have a 2 channel relay shield attached to my arduino, and I've been wondered how do I connect them to RPi. I need help for this problem, any advice would be appriciated. I'll post the GPIO pin below.
Thankyou

Do you really need the arduino? you can attach the relays to the rPi directly.

@ratchetfreak Thankyou for your answer, yes I do need the arduino, the relay is attached on my arduino,  you can attach the relay to RPi by using the cable jumper, but I don't really know how it work

Why not just use the serial cable?  Have you considered using the Raspberry Pi to program the Arduino then for communications also?  That's what I do for my solar plant modults.

I assume you are using Arduino UNO. Pi's digital logic is at 3.3 V and that of Arduino Uno is at 5 V. Anyway to send data from Pi to UNO, you can connect the pins directly. UNO can recognise both the logic levels of Pi's output. But to receive data from UNO to Pi, make sure you build a voltage divider using resistors, that brings 5V output from UNO's pin to 3.3 V. Also the grounds of both Pi and UNO should be connected to each other.

Thanks, I really appreciate it. The thing is I've attached relay channel shield on top of my arduino. So i just connect them like
RPi           pin 1 to   Arduino GND 5v
Like that?

why are you using relay shield?

@tbh Using relay shiled so i can attach another device called xbee(cc2530) for wireless transmission

to send data from pi to arduino and then send that data wirelessly via zigbee?

What on earth does a realy shield have to do with connecting an xBee? I think you are a little confused about what you actually want to do and are suffering from a severe case of xy-problem.

using zigbee for wireless transmission to another device

If you want to use an xBee for Pi communication then connect the xBee to the pi. It uses UART communication (very simple to wire up) or you can use a USB "explorer" board to plug it in to the USB socket. They use simple AT commands to configure them that are well documented. There is no role for the Arduino here.

We actually don't understand what do you want to do. You said you want to use ZigBee for wireless communication. You are not mentioning what data have to be transferred from where to where.

@Majenko there's no role of xBee here, it just between arduino(attached with relay shield) and RPi

@MITURAJ sorry for missunderstand, I'm not using this xBee things now, I've just thinking how do I connect my arduino that was attached with relay shield to RPi by using GPIO port. Why I use relay shield? Because It's for my next project, and also what for xBee it's also for my next project

Okay, remove the shield from UNO, zigbee etc and connect Pi and UNO as mentioned in this answer to make them communicate. Connections depend on what are the components you use and what you want to do with it.

@MITURAJ so for example RPi will send pin 4 HIGH, and arduino will receive the information, I've write the code, the problem is , how do I pin the right GPIO port from my  RPi to arduino. The thing is my next project and this problem right still have some sort of relation , so I need to attach my relay shield to my arduino

Answer for that is what I have given here.

@MITURAJ thankyou , i really appreciate that, also thanks for your time for spending in here

What you are asking really makes no sense at all.
You are starting from the mid-point of your project and wondering how to communicate using bare GPIOs without really knowing what it is you want to communicate and what you want to do with that data - or at least you haven't made any of that clear to us.
It is unclear what you want to do with the shield from the Pi. Do you want to control the relays on it by sending instructions from the Pi? Do you want the Pi to send and receive data through the XBee? Either way the Arduino is pretty redundant in the system and in fact gets in the way more than is useful.
If it's just relays you want then it would be far simpler to wire cheap relay modules direct to the GPIOs of the Pi - then you don't have to worry about "how to communicate" - you just turn the relays on and off.
If you want to communicate with the XBee there are far simpler shields available that will plug directly into a Pi. Indeed, there are some good shields around for the Pi ("Hats" I think they call them) which give you an Arduino footprint and an XBee socket together.
The Arduino is completely pointless in this system. And anyway, if you wanted to make the two systems communicate there are far easier ways than with bare GPIO pins. Serial, for a start. The simplest ever method is to just plug the Arduino into the Pi's USB. That way it gets power and data all in one go. Just like using it with a computer.


text:
SIM800L starts sending garbage values to Arduino after random interval
I have a SIM800L module connected to Arduino Mega's Serial3. SIM800L is powered by 4.2V power supply and I have put a voltage divider between Arduino's TX3 and SIM800L's RX so that the voltage in the line stays about 2V. The TX line of the module is directly connected to Arduino's RX3.
The problem is that when I try to communicate with the module it responds fine but after some AT commands the module starts panicking and start sending random garbage. The code I'm using is a simple Serial to Serial code :
#include<SoftwareSerial.h>

#define mySerial Serial3
//SoftwareSerial mySerial(10, 11);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  mySerial.begin(38400);

}

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

Output :

[This is with serial monitor set to 115200 baud rate]

[The garbage values with serial monitor set to 9600 baud rate]
The solutions I have tried so far are :

Put a 220uF cap between SIM800L's VCC and GND. (a 470uF tantalum cap is already included on the module but still to be safe)
Tried various baud rates from 9600 to 115200 (the baud rate setting on the module is set to auto baud rate) but only 38400 works reliably.
Tried to pull the RX3 line up on Arduino with a 100k resistor so that it doesn't float.
Tried to put up to 5s delay between AT commands given to the module but it still goes into panic.

The thing I noticed is that if we enter some wrong command like ATD74xxxxxxxx (which calls a phone number) instead of with proper ending like ATD74xxxxxxxx; the module does the same thing which is spitting garbage values.
Can anybody help me with what is wrong with the module?

Crystal on Arduino might be misbehaving

Why are you limiting the Tx of the Arduino to 2V, I though the SIM800L used 3.7-4.2V?

As per this the Rx level of the module is less than 2.8V which I confirmed too (ran it with high voltage levels and it gave errors on AT commands). I don't know the exact reason why is it so but it does behave nice on lower voltage levels and wacky on higher levels.

I believe GSM modules needs about 2A current for few operations. One of them is calling. Are you providing proer current?

I'm supplying it with a 3A buck converter which in turns is supplied by a 12V 10A bench power supply. Also there's plenty of capacitance on the VCC to compensate for surges so I don't think the power supply is an issue.

It also doesn't depend on the operation. I just created a loop in which I send "ATI" command to get the module info and it runs for may be 5-10 times and then the error loop begins. I have also tried another SIM800L module of the same kind and it behaves the same so it's not a problem with that particular module. Another thing I tried is to use a similar module with SIM900A and it works fine(with 5V supply instead of 4.2V).
I also tried to call the number from another phone and the module rings just fine so receiving calls is not a problem.


text:
What is the best way to power the ESP32 from a battery?
I am making a temperature sensor that can go in a freezer and I am trying to figure out what the best method is.
My research has taken me all over the place an I can't seem to find a straight answer. Some sites recommend using LiFePo4, while others say absolutely not, because it needs to be regulated.
One question I have is: could I use more voltage, say 6V from a series of batteries and connect it to the 5V pin since it is regulated, or is it better to go with an external regulator for the 3.3V pin with less voltage?

For battery operation always use an external switching regulator (not an LDO regulator) to 3.3V. It will double your battery life over using the 5V pin. Also: will the whole thing be in the freezer? What temperature freezer?

Which ESP32 unit are you considering? Does it have an internal voltage regulator?

@Majenko, yes it is meant to be entirely in the freezer and the temp has been a consideration as well.

@DuncanC, I am using the ESP32 Dev KitC V4.  It has an internal voltage regulator on the 5V pin, not the 3.3V, which is why I was wondering if it would be easier to use the 5V rather than messing with the 3.3V pin and needing a regulator

Before you get too carried away figuring out how you're going to power it with batteries you might see if you can even get a signal through your freezer walls at all.  If you can't, it means your running wires anyway, maybe just a thermocouple wire.  So far as I can tell, you are basically asking about putting a wireless device inside of a Faraday cage.

@timemage, signal is a concern and wiring is the backup option, but I still want to find the best way to power it.  That was how we were planning to test it.

I appreciate that you may still like an answer to the question irrespective, but I don't believe you need a battery to effectively test how well your signal will travel through the walls of your freezer.  Besides just snaking in a power cable to do that test, you will know the answer to this rather quickly, to the point where you could plug it into a laptop and place the show inside the freezer for long enough (30 seconds, if that) to know how well (or not) the signal passes.  I mention the laptop to just point out that you don't even need so much as a USB/phone charger type battery pack.

I'm betting you won't get any radio signals through the walls of a metal freezer. As time mage says, it's basically a Faraday cage. Now if you put an antenna on the inside and one on the outside, connected with a piece of coax, that would carry radio signals through.

Since it is a freezer (operating temperature unknown) I am assuming it is connected to the mains why not do the same with the electronics. This will save you a lot work and time and when you find out it will not work in a  Faraday cage as stated by timemage.  Leave the sensor wire long enough to mount the electronics outside just in case. Also consider packaging, it will be cold, possibly below the operating range of some of the components requiring you to keep them warm (above minimum temperature). I would assume your freezer like ours has moisture concerns as ice will form when opened then removed by a defrost cycle. You will also have to protect for that. Then there is the operating temperature range of the batteries, are they capable of operating at your freezer temperatures. I would suggest you redefine your problem before starting the design, this process saves me a lot of grief.

Just wanted to let everyone know that I tested the signal and we had NO issues connecting to the WiFi from inside the freezer!  Still looking for advice for a battery solution.....

I would recommended that the best type of battery for the freezer are the lithium variety. Keep in mind these are 100% disposable. So as much as I normally recommend rechargeable batteries for just about EVERY application, these are better for use in very cold sub zero temperatures.


text:
Play audio on an ESP32 or an Arduino
I am in the process of making a talking robot and I have linked my ESP32 to a Google text-to-speech service. The service returns me a base64 8-bit audio response.
I need to play this audio and I can't figure out how to do it. I know that an audio playing library exist for PCM but the data that it requires is not base64.

Base64 is just an encoding to encapsulate 8 bit data into ASCII text. It has nothing to do with audio. Decode it first into your binary data then use a suitable library for your hardware to play it.

On the esp, there is also an offline version of text to speech. Just if you want to try it...

I don't know weather this will help you there is a guy who makes cool stuff in GitHub text to speech in esp8266 hope it will work in esp32 too https://github.com/earlephilhower/ESP8266SAM

Base64 has nothing to do with audio. It is merely a way of encapsulating binary data into ASCII text so that it can safely be included in text-based structures like JSON, or transmitted over a text-based communication channel.
There is no library to "play" base64 simply because base64 is not something you play.
First you decode the base64 text into raw 8-bit binary. It's then that data that you play through whatever library is most suitable for your hardware.
For example on the ESP32 you have the function base64_decode() available. You can read up on how to use it in this tutorial.


text:
I am trying to control a continuous servo (MG996R) with an RF remote but it's not working
I am trying to control a continuous servo (MG996R) with an RF remote, but it's not working; the servo just spins in one direction.
I am new to Arduino so I don't really know if the code is correct.
This is my code:
#include <Servo.h>

Servo servothumb;
Servo servoindex;
Servo servomiddle;
Servo servoring;
Servo servopinky;

void setup() {
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  pinMode(4,INPUT);
  pinMode(5,INPUT);
  Serial.begin(9600); // setting baud rate
  Serial.println(" Data 4 Ch Remote Control");
  servothumb.attach(9);
  servoindex.attach(10);
  servopinky.attach(11);
  servoring.attach(12);
  servomiddle.attach(13);
}

void loop() {
  if (digitalRead(2) == HIGH) { // Button B pressed
    Serial.println("B");
    servothumb.write(90);
    servoindex.write(90);
    servopinky.write(90);
    servoring.write(90);
    servomiddle.write(90);
  } else {
    servothumb.write(90);
    servoindex.write(90);
    servopinky.write(90);
    servoring.write(90);
    servomiddle.write(90);
  }

  if (digitalRead(3) == HIGH) { // Button D pressed
    Serial.println("D");
  }
  if (digitalRead(4) == HIGH) { // Button A pressed
    Serial.println("A");
    servothumb.write(0);
    servoindex.write(0);
    servopinky.write(0);
    servoring.write(0);
    servomiddle.write(0);
  } else {
    servothumb.write(90);
    servoindex.write(90);
    servopinky.write(90);
    servoring.write(90);
    servomiddle.write(90);
  }
  if (digitalRead(5)== HIGH) { // Button C pressed
    Serial.println("C");
    servothumb.write(180);
    servoindex.write(180);
    servopinky.write(180);
    servoring.write(180);
    servomiddle.write(180);
  } else {
    servothumb.write(90);
    servoindex.write(90);
    servopinky.write(90);
    servoring.write(90);
    servomiddle.write(90);
  }
}

the servo doesn't stop or go the other way if i use the rf remote it just spins clockwise

is it the servo or the RF remote? ... you really need to do some debugging by using the simplest code to test only one thing

Your code does not control a servo, but 5 of them. In the loop, the if statements do not exclude each other. That means either the if or the else branch is executed for each if block. That means you switch the speed values for the servos very fast, again and again, if one or more buttons are pressed.  If no button is pressed, then only the three else branches are executed and your servos stay at value 90. How this value is interpreted depends on the servo; some stop, some need another value to stop, some do not stop at all. BTW: The  mg996r is not a continous servo, did you modify it?

how do you add a stop statement for a continuous servo?
i didn't modify it I bought one online it was already continuous

If you bought a modified version, ask the vendor, how to stop it. This is not specified for the original. I do not know how it is modified. How could I? ;-) Modification is normally achieved with just removing the mechanical connection of the motor and the potentiometer that senses the position of the motor. It depends on the resistance of the potentionmeter that's now fix. You could try to write a program that iterates over all values from 0 to 180, sends this value  to the servo and also prints it to the Serial monitor. Then, with luck, you'll see the motor stop, and the monitored value.

If the motor does not stop, you could open the servo and try to turn the poti screw/wheel, perhaps it is in a unfortunate position. What I told you in the last comment can be achieved with a modified Servotester. Here is a link; a starting point. https://create.arduino.cc/projecthub/bbil40/automatic-servo-tester-with-arduino-nano-c694e0 . I assume that's really hard for you, but as you have the hardware, I can only advice you what to do.

If you had not already bought the servos, I would advice you to use Geared DC motors and H-BridgeDrivers. There are reliably stoppable and can change direction and speed.

What I still not understand: Where comes the RF remote control into play? I'm just curious why you mentioned it ;-).


text:
One LED in 4x4 matrix does not turn on
I'm an art student and absolute beginner to electronics/code  -  my broader goal is to learn how to control individual LEDs when there are many of them (like 64 or more even, so am learning about shift registers, multiplexing etc. also).
I have been working with a 4x4 matrix example by Jon Fox. I have breadboarded it as below and checked it multiple times.

For the most part it's successful; the code runs and I get the LED animations in his code. I am also able to anticipate which parts of the code refer to which LEDs when I test by commenting out parts of the code - for example r1c1() refers to the top row, right-most LED.

However, the top row, second from the left LED does not turn on.
I have tested the individual LEDs before starting, tested the connections of the wires in case they don't make good connection in the breadboard, and tried adding 330 Ω resistors to the rows (instead of the orange connection wire in the image), and tried with 1 kΩ resistors instead of 220 Ω. The reason I tried those values was that I have been successful when I've used another set up I have, image below.

The blue and the white LEDs draw similar voltage so as far as I understand this wouldn't affect anything. The code runs great on this also.
I understand I could still be making some human error, especially as I've been going crazy with this. However, because I really want to understand the factors involved in controlling LEDs, I'd love to know if at all there are other variables at play.
For one, I was looking into 'floating inputs' hence tried adding the other set of resistors, and tried colour LEDs (more bulbs were either off or dim) as well as 3 mm white LEDs (same result as 5mm). The most difficult thing in this process is wondering what I don't know, so if anyone can direct me towards things I should consider for my purpose, or help me solve my current problem, I'd be really grateful.

It is very difficult to be certain.  You state that the second from the left LED in to top row is not turning on as expected.  In the bread-board diagram this LED is plugged into holes D7 and D8.  However, in the image it appears this LED is plugged into holes D8 and E8.
The exact letter/number may not matter if you are not following your bread-board diagram precisely.  However all pins in a row (i.e. A8, B8, C8, ... , E8) are shorted together.  So plugging in an LED into holes D8 and E8 would prevent it from lighting up.
Also, you have added resistors to your matrix which are not in the bread-board diagram.  The column resistors appear correct but the row resistors are questionable.  In practice, if you are going to light only 1 LED in a column at a time, then you might get by with only column resistors.  For such a configuration (only column resistors) you may see the LEDs dim if you light more than 1 per column.  If you do want to light more then one LED per column, the trick is to let the software switch LEDs on and off such that there is only one lit per column at a time. But fast enough so that a human eye can not see it.  So a bit faster than 100ms.

Thanks for your reply. Just to confirm, the LED second from the left in the top row is plugged into D7 (cathode -) and D8 (anode +).

Then check if it is reversed bias (put in backwards).  LEDs are diodes that happen to give off light.  And diodes can only be inserted forward biased (in the correct direction).

Let me know if the "only use column or row resistors but consider not using both & use software to mitigate dimming from lighting too many LEDs at once" is not clear.  Even in your second "free-standing" display I imagine the more LEDs you light in a given column  or a given row the dimmer the individual LEDs will become.  If you don't want to mess with the software (i.e. you just want to be able to light any combination of LED w/o dimming problems) then you will need to add a resistor to each and every individual LED.

It is put in the correct direction. I can remove the row resistors, I tried them in the breadboard since they worked in the free standing version, and I wondered about needing a pull-up(down?) resistor because of this idea of the floating input? Maybe that's totally irrelevant. At the moment I'm not experiencing dimming, in either version. There is no current or voltage on this LED and I just wonder why.

I just figured out my mistake - misconnected one of the cathode wires -  the 2nd LED is on. But your feedback was useful and much appreciated.


text:
Using 4x1 MUX to control a servo
I was supposed to first create a 4x1 MUX using AND and NOT gates. The 4 input data lines (io,i1,i2,i3) were 4 PWM pins from the arduino (3,5,6,9), with analogWrite() values as 100,150,200,250 respectively, and the selection lines were taken from two slide switches.

int i0=100;
int i1=150;
int i2=200;
int i3=250;

void setup()
{
  pinMode(5, OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(3,OUTPUT);

  analogWrite(3,i0);
  analogWrite(5,i1);
  analogWrite(6,i2);
  analogWrite(9,i3);

  Serial.begin(9600);
}

void loop()
{

}

Simulation link: https://www.tinkercad.com/things/cRZNvuwhZYV
The voltmeter + is connected to the output of the MUX. Both selection lines are HIGH, so the output is i3, which has the pWM value 250. So the voltage should be (250/255)*5, i.e about 4.9 V, which is what the meter shows. (The servo is present but not connected.)
The voltmeter values are in accordance for all the 4 possible combinations. In short, the 4x1 MUX is working perfectly.
(it was important for me to clarify this as otherwise people might have thought of the MUX implementation as the problem with my lsubsequent circuit , and with the messy wiring, it would've been impossible to confirm whether or not this is the case. However, as I have clearly shown, the problem is NOT with the MUX).
Next, I tried to control the servo using this MUX. I connected the servo control pin to the MUX output:

#include<Servo.h>
Servo s1;
Servo s2;
Servo s3;
Servo s4;

int i0=100;
int i1=150;
int i2=200;
int i3=250;

void setup()
{
  pinMode(3,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(9,OUTPUT);

  analogWrite(3,i0);
  analogWrite(5,i1);
  analogWrite(6,i2);
  analogWrite(9,i3);

  s1.attach(3);
  s2.attach(5);
  s3.attach(6);
  s4.attach(9);

  Serial.begin(9600);
}

void loop()
{

 s1.write((i0*180)/255);
 s2.write((i1*180)/255);
 s3.write((i2*180)/255);
 s4.write((i3*180)/255);
}

For instance, I thought if both switches were on, then the output is i3,(which was coming from pin 9), so
only s4.attach(9); and s4.write((i3*180)/255); will work. (As, it is apparent that the control pin is connected to pin 9 in this case).
The servo does move around when I change the switches to on off combinations, however,something drastic has happened to the voltmeter values, which tells me that my code is messing with the MUX output. The output voltages fluctuate rapidly between 97 and 180 mV.
What exactly have I done wrong, and how exactly am I supposed to control the Servo, then?

Honestly I would think that none of the codes really work, at least at a real Arduino (don't know, how tinkercad is handling this). Calling analogWrite() or Servo.write() repeatedly in loop() without  anything to slow it down would restart the PWM wave again and agian. Please try to put these lines into setup() instead. Maybe tinkercad handles analogWrite() and the servo library differently.

one of the main things that you are doing wrong is using a voltmeter to measure a pulse train ... an oscilloscope is the appropriate instrument for that

@chrisl I changed the codes, the problem still persists. Any idea why? and any idea what exactly can I do to control the servo properly?

@jsotola what difference will that make? (I ask this politely ofcourse) The voltmeter is showing the correct values for the MUX, which means my MUX is working properly, that's all I wanted to confirm. When I add the servo, is when the voltmeter goes beserk, so something is probably wrong with the handling of my servo... I am not sure why using an oscilloscope will fix that

is it possible to control the servo with only one servo object?

What is the purpose of both analogWrite() and Servo::write() using the same pin? Do you need the former at all?

well the analogWrite() serves as data inputs to the MUX... You may be right that using the same pin may be causing the trouble.. But then what code do you recommend?


text:
LED not lighting up despite digitalRead displaying 1
As part of a project, I created a simulation of a juncture with 4 traffic signals. The time for the green signal is set based on a function that calculates it based on an algorithm (and it takes the no. of cars, motorcycles, buses and trucks as input).
The number of vehicles in the actual project is calculated using deep learning methods, however for the purpose of the simulation, I am using random() to generate these.
Layout of the entire process

The green light of the current signal stays on for gst(green signal time) seconds, and the red light stays on for the rest of the signals.
When gst seconds have elapsed, the green light of the current signal changes to yellow. Rest all are still red.
The yellow light is intended to stay on for 5 seconds. In these 5 seconds, the gst for the next signal is calculated.
5 seconds after step 3, the yellow signal turns to red, and the next signal turns from red to green, (for an amount that has been calculated).
This process keeps continuing. When we reach the 4th signal, the next signal should be set to 1.

Code explanation

gst has been initialised to 20, and sn (current signal no.) has been initialised to 1.

The if block for calculating the next signal number (and next2next,next2next2next) , is in lieu with point 5.

signal is an array that contains all the LED pins. The colours red,yellow,green have been attributed numbers 0,1,2 , so that the pin number of the "colour" LED of the "ith" signal can be given be signal[i-1][colour]

eg: "red" LED of the "2nd" signal is given by pin signal[1][0], i.e pin 5 .
Wiring and code

int gst=20; //green signal time
int ns=4;  //no.of signals
int sn=1; //current signal number

//pin numbers for LEDS: {{RYG for signal1},{RYG forr signal2}..}
int signal[4][3]={{2,3,4},{5,6,7},{8,9,10},{11,12,13}};

//indexes for the signal array
int red=0;
int yellow=1;
int green=2;

//pin number of "colour" of signal "i" is given by signal[i][colour]
//example: red led of signal 3: signal[2][0]

int c; //cars
int b; //buses
int m; //motorcycle
int t; //trucks

void setup()
{
  for(int i=2;i<=13;i++){
    pinMode(i,OUTPUT);
  }
  Serial.begin(9600);
  randomSeed(analogRead(0));
}

void loop()
{
    int next_sn= sn+1; //next signal
    if(next_sn==5)
      next_sn=1;

    int next2_sn= next_sn+1; //next2next
    if(next2_sn==5)
      next2_sn=1;

    int next3_sn= next2_sn+1; //next2next2next
     if(next3_sn==5)
      next3_sn=1;

   //current signal green (for gst seconds), rest all red.

    digitalWrite(signal[sn-1][green],HIGH);
    digitalWrite(signal[sn-1][red],LOW); //this line will make sense
                                      //for the 2nd iteration

    digitalWrite(signal[next_sn-1][red],HIGH);
    digitalWrite(signal[next2_sn-1][red],HIGH);
    digitalWrite(signal[next3_sn-1][red],HIGH);

    //for debugging purposes

    Serial.println(digitalRead(signal[sn-1][green]));

    delay(gst*1000);

    //gst seconds elapsed, now current signal should become yellow

    digitalWrite(signal[sn-1][green],LOW);
    digitalWrite(signal[sn-1][yellow],HIGH);

    delay(5*1000);

    //snapshot taken for calculating no. of cars, buses etc
    //for now, random numbers used

     c=random(10,17);
     m=random(5,10);
     b=random(0,5);
     t=random(0,5);

     //calculate gst

     gst=calc_gst(c,m,b,t);

  //make current signal red

    digitalWrite(signal[sn-1][red],HIGH);
    digitalWrite(signal[sn-1][yellow],LOW);

  //the next signal is our current signal for the next iteration
  //the green signal should turns on for gst seconds in the next
  //iteration,and the red signal turns off
    sn=next_sn;

  }

//function for calculating green signal time

int calc_gst(int c,int m,int b,int t)  //car bus motorcycle truck
{

int vehicle[4]={c,m,b,t};
int avgtime[4]={2,1,2.5,2.5};
int x=0;
for(int i=0;i<4;i++){
x+=vehicle[i]*avgtime[i];
int gst= x/(ns+1);
return gst;

}

}

Problems
At the start of the simulation, the green light of the first signal is not lighting up. (However Rest three are red, rightly so). After 20 seconds, the first signal turns yellow correctly. Then after 5 seconds, the second signal turns green correctly, but the first signal doesn't turn red. Subsequently, there are many instances where only 3 LEDs in total are lighting up instead of 4.
For testing why the green light is not lighting up, I added a line:
    //for debugging purposes
    Serial.println(digitalRead((3*(sn-1)+green)));

The serial monitor shows 1, so why is the LED not lighting up??
If there are any suggestions/corrections in my process, I will be obliged if someone can point it out.My code is heavily commented, and it explains it the entire process.
Tinkercad link if anyone wants to try out the simulation: https://www.tinkercad.com/things/1Le8m5ouHPc

alright, but any clue why the green LED isnt lighting up immediately? Your suggestion will definitely help "clean up the code", but even with my code, digitalRead()..is 1, and yet the LED does not light up..

following your advice, I have edited the code and have used a 2D array, hopefully that makes it easier..

reduce your code to light all of the LEDs  in setup() ... you will find that top left red and green do not light .... you did not connect the resistors to ground for those two LEDs ... this is a Tinkercad problem that would not happen in real life

I see...what fix do you suggest?

what do you mean? ... you did not connect the resistors at the top end ... there is only one fix for that

one thing that would clean up the code a bit more, would be to number the traffic lights 0, 1, 2, 3

ohh goshh thats a bad blunder. The resistors aren't connected. Thanks a lot @jsotola.