text:
serial data transfer on gps shield duinopeak
I'm using an arduino uno r3 with a gps shield duinopeak.

The shield is configured using RX pin 3 and Tx pin 2, as image below:

I'm using the TinyGPSPlus library to read NMEA data. This is my code:
/******************************************************************************
  This example uses SoftwareSerial to communicate with the GPS module on
  pins 8 and 9, then communicates over SPI to log that data to a uSD card.

  It uses the TinyGPS++ library to parse the NMEA strings sent by the GPS module,
  and prints interesting GPS information - comma separated - to a newly created
  file on the SD card.

  Resources:
  TinyGPS++ Library  - https://github.com/mikalhart/TinyGPSPlus/releases
  SD Library (Built-in)
  SoftwareSerial Library (Built-in)

  Development/hardware environment specifics:
  Arduino IDE 1.6.7
  GPS Logger Shield v2.0 - Make sure the UART switch is set to SW-UART
  Arduino Uno, RedBoard, Pro, Mega, etc.
******************************************************************************/

#include <SPI.h>
#include <SD.h>
#include <TinyGPS++.h>

#define ARDUINO_USD_CS 8 // uSD card CS pin (pin 8 on Duinopeak GPS Logger Shield)

/////////////////////////
// Log File Defintions //
/////////////////////////
// Keep in mind, the SD library has max file name lengths of 8.3 - 8 char prefix,
// and a 3 char suffix.
// Our log files are called "gpslogXX.csv, so "gpslog99.csv" is our max file.
#define LOG_FILE_PREFIX "gpslog" // Name of the log file.
#define MAX_LOG_FILES 100 // Number of log files that can be made
#define LOG_FILE_SUFFIX "csv" // Suffix of the log file
char logFileName[13]; // Char string to store the log file name
// Data to be logged:
#define LOG_COLUMN_COUNT 8
char * log_col_names[LOG_COLUMN_COUNT] = {
  "longitude", "latitude", "altitude", "speed", "course", "date", "time", "satellites"
}; // log_col_names is printed at the top of the file.

//////////////////////
// Log Rate Control //
//////////////////////
#define LOG_RATE 5000 // Log every 5 seconds
unsigned long lastLog = 0; // Global var to keep of last time we logged

/////////////////////////
// TinyGPS Definitions //
/////////////////////////
TinyGPSPlus tinyGPS; // tinyGPSPlus object to be used throughout
#define GPS_BAUD 9600 // GPS module's default baud rate

////////////////////////////////////////////////
// Arduino GPS Shield Serial Port Definitions //
////////////////////////////////////////////////
// If you're using an Arduino Uno, Mega, RedBoard, or any board that uses the
// 0/1 UART for programming/Serial monitor-ing, use SoftwareSerial:
#include <SoftwareSerial.h>
#define ARDUINO_GPS_RX 3 // GPS TX, Arduino RX pin
#define ARDUINO_GPS_TX 2 // GPS RX, Arduino TX pin
SoftwareSerial ssGPS(ARDUINO_GPS_TX, ARDUINO_GPS_RX); // Create a SoftwareSerial

// Set gpsPort to either ssGPS if using SoftwareSerial or Serial1 if using an
// Arduino with a dedicated hardware serial port
#define gpsPort ssGPS  // Alternatively, use Serial1 on the Leonardo

// Define the serial monitor port. On the Uno, Mega, and Leonardo this is 'Serial'
//  on other boards this may be 'SerialUSB'
#define SerialMonitor Serial

void setup()
{
  SerialMonitor.begin(9600);
  gpsPort.begin(GPS_BAUD);

  SerialMonitor.println("Setting up SD card.");
  // see if the card is present and can be initialized:
  if (!SD.begin(ARDUINO_USD_CS))
  {
    SerialMonitor.println("Error initializing SD card.");
  }
  updateFileName(); // Each time we start, create a new file, increment the number
  printHeader(); // Print a header at the top of the new file
}

void loop()
{
  if ((lastLog + LOG_RATE) <= millis())
  { // If it's been LOG_RATE milliseconds since the last log:
    if (tinyGPS.location.isUpdated()) // If the GPS data is vaild
    {
      if (logGPSData()) // Log the GPS data
      {
        SerialMonitor.println("GPS logged."); // Print a debug message
        lastLog = millis(); // Update the lastLog variable
      }
      else // If we failed to log GPS
      { // Print an error, don't update lastLog
        SerialMonitor.println("Failed to log new GPS data.");
      }
    }
    else // If GPS data isn't valid
    {
      // Print a debug message. Maybe we don't have enough satellites yet.
      SerialMonitor.print("No GPS data. Sats: ");
      SerialMonitor.println(tinyGPS.satellites.value());
    }
  }

  // If we're not logging, continue to "feed" the tinyGPS object:
  while (gpsPort.available())
    tinyGPS.encode(gpsPort.read());
}

byte logGPSData()
{
  File logFile = SD.open(logFileName, FILE_WRITE); // Open the log file

  if (logFile)
  { // Print longitude, latitude, altitude (in feet), speed (in mph), course
    // in (degrees), date, time, and number of satellites.
    logFile.print(tinyGPS.location.lng(), 6);
    logFile.print(',');
    logFile.print(tinyGPS.location.lat(), 6);
    logFile.print(',');
    logFile.print(tinyGPS.altitude.feet(), 1);
    logFile.print(',');
    logFile.print(tinyGPS.speed.mph(), 1);
    logFile.print(',');
    logFile.print(tinyGPS.course.deg(), 1);
    logFile.print(',');
    logFile.print(tinyGPS.date.value());
    logFile.print(',');
    logFile.print(tinyGPS.time.value());
    logFile.print(',');
    logFile.print(tinyGPS.satellites.value());
    logFile.println();
    logFile.close();

    return 1; // Return success
  }

  return 0; // If we failed to open the file, return fail
}

// printHeader() - prints our eight column names to the top of our log file
void printHeader()
{
  File logFile = SD.open(logFileName, FILE_WRITE); // Open the log file

  if (logFile) // If the log file opened, print our column names to the file
  {
    int i = 0;
    for (; i < LOG_COLUMN_COUNT; i++)
    {
      logFile.print(log_col_names[i]);
      if (i < LOG_COLUMN_COUNT - 1) // If it's anything but the last column
        logFile.print(','); // print a comma
      else // If it's the last column
        logFile.println(); // print a new line
    }
    logFile.close(); // close the file
  }
}

// updateFileName() - Looks through the log files already present on a card,
// and creates a new file with an incremented file index.
void updateFileName()
{
  int i = 0;
  for (; i < MAX_LOG_FILES; i++)
  {
    memset(logFileName, 0, strlen(logFileName)); // Clear logFileName string
    // Set logFileName to "gpslogXX.csv":
    sprintf(logFileName, "%s%d.%s", LOG_FILE_PREFIX, i, LOG_FILE_SUFFIX);
    if (!SD.exists(logFileName)) // If a file doesn't exist
    {
      break; // Break out of this loop. We found our index
    }
    else // Otherwise:
    {
      SerialMonitor.print(logFileName);
      SerialMonitor.println(" exists"); // Print a debug statement
    }
  }
  SerialMonitor.print("File name: ");
  SerialMonitor.println(logFileName); // Debug print the file name
}

Basically the code get the values os lat, long, alt, etc and log into csv file on sdcard. Unfortunately I'm always get no gps data. What's wrong with my code?
Update:
Test serial connection with this code:
#include <AltSoftSerial.h>

// AltSoftSerial always uses these pins:
//
// Board          Transmit  Receive   PWM Unusable
// -----          --------  -------   ------------
// Teensy 3.0 & 3.1  21        20         22
// Teensy 2.0         9        10       (none)
// Teensy++ 2.0      25         4       26, 27
// Arduino Uno        9         8         10
// Arduino Leonardo   5        13       (none)
// Arduino Mega      46        48       44, 45
// Wiring-S           5         6          4
// Sanguino          13        14         12

AltSoftSerial altSerial;

void setup() {
  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor to open
  Serial.println("AltSoftSerial Test Begin");
  altSerial.begin(9600);
  altSerial.println("Hello World");
}

void loop() {
  char c;

  if (Serial.available()) {
    c = Serial.read();
    altSerial.print(c);
  }
  if (altSerial.available()) {
    c = altSerial.read();
    Serial.print(c);
  }
}

I just receive the menssage "AltSoftSerial Test Begin", so the problem may be the serial port?

Hi How do you adjust the date and time to be the same in my country? I am from the Philippines. thanks!

The comments in the AltSoftSerial Test say that you have to connect the GPS to pins 8 (RX for GPS TX) and 9 (TX for GPS RX).  Your shield does not have jumpers for those pins, but you could use a jumper wire to connect any of the TX pins (0-7) to Arduino pin 8 (on the edge of the shield).
I would also recommend looking at my NeoGPS library.  It's smaller, faster, more accurate and more reliable than all other GPS libraries.  Even if you don't use it, there are lots of tips on the Troubleshooting page.
Be sure to read about choosing a serial port for the GPS device.  That's especially important.  In your case, you could use pins 0 and 1.  SoftwareSerial is the worst choice and is NOT recommended.
There is also an NMEASDlog example.  Unlike examples from other libraries, the NeoGPS examples will reliably work at high update rates and with slow SD cards.
NeoGPS is also available from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries.

Please see my update with a image of my shield, so the pin 0 and 1 already are connected, ok? I opened the file GPSPort.h in the NeoGPS library and uncomment the line #include <NeoHWSerial.h>    // NeoSerial or NeoSerial1 Interrupt-style processing, but a receive the menssage h:159:84: fatal error: NeoHWSerial.h: No such file or directory

The images above show pins 2 & 3 are connected.  That would require downloading NeoSWSerial for all examples.  If you want to use Arduino pins 0 & 1, most examples should work on Serial.  Start with NMEA.ino and NMEAorder.ino.  Before trying to run the NMEASDlog example, you should try NMEA_isr.ino.  You will need to download NeoHWSerial and enable NMEAGPS_INTERRUPT_PROCESSING in Arduino/Libraries/NeoGPS/src/NMEAGPS_cfg.h.  When that works, you can try NMEASDlog.ino

Thank you for help, I'm very newbie on arduino, in my case I don't know how to do the connection/wiring on ports 0 and 1 using that shield.

Put one jumper block connecting the TX / Digital at column 0, and one on the RX / Digital to column 1 (or vice versa).  From your picture, just move the 2 yellow jumper block rectangles to the right by 2 spaces.

This is the problem, there is no the pins check in the image

"There is no the pins" ?  Please edit your original post and insert the image.

The RX/TX pins do not line up with the Arduino pins, so RX/TX pins 0 and 1 are the two columns at the right side, under Arduino pins 2 & 3.  That's confusing, but that should connect the GPS to Arduino pins 0 and 1, as I described earlier.


text:
Conncet Bluetoth module HC-05 to Arduino Uno Using UART Usb to enter in AT command
I have connected Arduino Rx(pin 0) to Bluetooth module Rx pin. Tx od Arduino to Tx of Bluetooth . I am able to send command to Bluetooth module using Serial Monitor of Arduino on my PC.
I have uploaded the empty code in Arduino.
I want to know why we connected Tx to Tx and Rx to Rx i.e one to one connection?
If I send command "AT" from my PC using serial Monitor of Arduino , How is it flowing to Bluetooth module.
Why not we connect Rx to Tx pin in AT Mode of Bluetooth module?
Pls explain using diagram.

By using SoftSerial you can connect the HC-05 module to another pin than D0 and D1. Example connect HC-05 to D2 and D3 and define SoftSerial to use D2 and D3.
---------                        -----------                        ------
| HC-05 +---(SoftSerial)---(D2/3)+ Arduino +(D0/1)---(Serial USB)---+ PC |
---------                        -----------                        ------

source: Stack Exchange

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

sort: votes


text:
LED matrix question light up H or 4
Just a basic query;
On my understanding of LED Matrix's, The following would light up 4 LEDs.
But what if I only wanted to light up just 3 of those LEDs? The circuit still needs the same inputs, since power will continue across all columns/rows
Thanks
Tom

Multiplexing means you are powering only one of them and you have to set corresponding columns (in this case more like reset). If you're doing it for all rows fast enough, your eye won't see flickering (only if you move display)

BTW, you took this picture out of some place where multiplexing is explained. I deduce this by the leftover of the image title "What is multiplexing": did you actually read that article?

I was trying to find out on the internet and it looks like I was close to the answer. Maybe I didn’t think multiplexing would work over large LED arrays. Or let’s assume LED screens with 255 levels of brightness for each colour. The number of cycles or computing needs to be quick to support the display.

Multiplexing is the answer.

If you want to, as an example, light up only LEDS 1, 3 and 4, you will:

activate line A
activate line X
de-activate line X
de-activate lines A and B (yes, B was not active)
activate line A and B
activate line Y
de-activate line Y
de-activate lines A and B
start again from top

Do this so that the loop takes less than 10 milliseconds and you are actually refreshing the entire matrix at 100Hz, fast enough to trick the eyes of any human being as if the LEDs 1,3 and 4 are lighted up at the same time: persistence of vision is your friend.

This is very simple. You can turn on each LED one at a time and repeat this over and over again. The easiest way of achieving this is to put this code in the loop section.

Persistence of vision is defined as "the retention of a visual image for a short period of time after the removal of the stimulus that produced it" - dictionary.com

Even though the LED is on for only 1/3 of the time, it is fast enough that the human eye will not be able to tell that each LED turns off. Hence the viewer sees 3 LEDs on at the same time.
This allows any combination of LED patterns in your LED matrix.
7-segment displays also use this technique. You probably have some in a microwave or DVD player that you never realized that they were cycling through each digit, using persistence of vision.
Resources:
http://www.circuitstoday.com/interfacing-8x8-led-matrix-with-arduino (recommended)
http://tronixstuff.com/2013/10/11/tutorial-arduino-max7219-led-display-driver-ic/
https://playground.arduino.cc/Main/LEDMatrix
http://forum.hobbycomponents.com/viewtopic.php?f=43&t=1489

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


text:
What happens if I don't use a relay for 5V pump
I am trying to build an automatic watering system by following some examples. However, I don't have all the components for the entire system, therefore I have built it in Fritzing using only the components that I have (see scheme below):

I didn't build the physical version yet, because I am not sure that such a system would work without burning anything. In many examples, people connect the pump to a Relay Module, but since I don't have it yet, I would like to build it like this until I set up the watering system.
Can anyone help me understand why a relay would make it better or worse?
P.S. I have a JPC-3F relay, but I can see that the Relay Module contains multiple components. Is it possible to add the JPC relay to the pump without having the entire Relay Module? Would I need extra components for that?
Thank you!
EDIT: Thanks to the answer from ratchet freak, I have added resistances and a transistor. It works fine, but the same question stands. Do I still need a relay in this case?

You should put a resistor in series with the led to limit the current.
The IO pins cannot source enough current to run the pump without damaging themselves. That's why you need a buffer of some kind.
The extra components in the relay module are a transistor to do the actual switching and a reverse-biased flyback schottky diode in parallel with the relay coil. The flyback diode is required to absorb the voltage spike generated by the coil getting switched off and acting like an inductor.
You can use a transistor to switch the motor directly assuming you can find one that can handle the current draw. If you do then you absolutely will need a flyback diode on the motor to avoid damage to the transistor.

Thank you very much for the explanation. Can you please tell me which transistors should I use? In my kit I have one IRF520N, one ST8050 and one S8550  . Would any of these work? I can see that only S8550 can work with 5V, but negative. And will I have to supply extra energy for the pump or it'll work through the IO pins?

You'll need extra energy.

Thank you all. I have tried with only the IRF520N and it works perfectly. Is there any danger in this?

Doesn't the IRF520N already have an internal diode?

this is not an answer to the question you asked, but you need to understand this:
generic DC relay advice. Use commutating diodes. this is not a special kind of diode, it is a particular use of a generic diode. you want 2:
one across the coil, reversed biased - cathode to +VDC. The coil throws a huge spike of negative DC when power to the coil is cut and the magnetic field collapses. this diode eats that spike
second one from the load to ground, reverse biased. this eats any spike from the load to ground - the fat blue arc you see when you disconnect a load by yanking the wire
https://www.allaboutcircuits.com/textbo ... -circuits/
https://www.allaboutcircuits.com/textbo ... ing-diode/
https://en.wikipedia.org/wiki/Flyback_diode
G

The relay have a coil resistance of 70 ohm for the 5 Volt version.
Ohms law, U = I x R
I = U/R = 0.071 Ampere, and now you have to find out, can an Arduino I/O pin drive a load of 71 mA? If not you have to add a driver aka most commonly a transistor.
And now you should ask yourself, can I drive the motor directly with a transistor driver and skip the relay? So do you have any data on the pump?
And if you look at the datasheet for IRF520, fig 3 and fig 4 have the data for planning if it will work or not.
Ref.: https://www.infineon.com/dgdl/irf520npbf.pdf?fileId=5546d462533600a4015355e340711985

Thank you for the answer. The pump is AD20P (5V). It works very nice with transistor only (and a 5V power supply), but I don't know if this is a good idea.

Datasheet for the AD20P ? To post only the AD20P mean that I have to search for the datasheet...

Sorry: Input Voltage: DC 3.5-9V, Power: 1-3W, Qmax = 120L / H (44GPH). This is what I could find.

Worst case is 3 W and 5 Volt:  I = P/U = 3/5 = 0.6Amp then will the IRF520 handle the pump without problem.


text:
check if a fuse is good or bad in an ac circuit using arduino
I have a fuse in a ac circuit of which i want to check if the fuse is ok or not. I'm wishing to wire up two nodes of the fuse holder and determine the fuse status. I have a plan of notify user if the fuse is ok or not.
How can I do that using arduino?

AC and what is the voltage?

Bluntly, don't do that.  The serious challenges of doing so safely are far beyond the scope of the Arduino site.  At best, there might be some existing property of the powered equipment which you could non-invasively monitor, for example, gluing a light sensor to the exterior of the enclosure over an existing power light.  Do not attempt to make any connections from an Arduino to mains circuitry.

@MatsK 220V. I'm wishing to check the fuse of an IPS.

easy: just use a hall-effect current sensor; if the fuse is ok, there will be current.


text:
How important is the INT pin of the MPU6050 (GY-521)?
I want to wire multiple MPU6050 (at least 16 of them) to an arduino UNO for development (then nano for production). So I first started wiring one MPU6050 to an arduino like shown on the diyhacking website or in the picture below:

as you can see in the picture above the INT pin is used.
I then wearched for a way to wire multiple MPU6050 to an arduino using a multiplexer and I found a way on horizonlab's website or see the picture below:

As you can see in the second picture the INT isn't used at all. I'd like to know how important it is and what I'm missing out by not using it.

You are connecting a 3.3V sensor to a 5V Arduino board. That means the I2C signals are not fully compatible. With many modules and each module having a pullup resistors from SCL to 3.3V, that might be too much. What is the value of the pullup resistors on the MPU-6050 module ? What sample rate do you want to achieve ? Can the Arduino Uno handle all that data ?

@Jot the two resistors next to the SCL say "222". I'm not sure how to calculate the sample rate I want to achieve but I would like to read each module at least 60 times per second (at most 120 times per second). Can the arduino handle that much data? I hope so. Otherwise I'm gonna have to add an SRAM to the circuit or use a second arduino and a third and so on and divide the MPUs between them until they all can handle the data.

The 222 means 2k2. That is a low value. The maximum current is specified as 3mA. Since those 2k2 are tied to 3.3V, the current is 3.3/2k2 = 1.5mA per module. When you want more than two modules, you have to desolder the pullup resistors. You also need a I2C level converter. The Arduino Uno can not do that many modules at that high datarate. Sorry. It doesn't even come close. Beside that, the total length of all pieces of wire of SCL and SDA can be 50 cm. That is the rule of thumb, only 50 cm.

@Jot 50 cm that's short. Is there no way to extend the length of the cable. (I can still work with that by using more arduinos. I just feel like it's a shame it can't be longer)

That's the rule of thumb. Some say they can get up to 3 meters, but that has a lot requirements for: the kind of wires or cable, the pullup resistors, the voltage levels, the i2c clock speed, and so on. Could you add to your first question what kind of project it is ? How many sensors ? How far apart ? Cost restrictions ? If you want to use many Arduino boards, how will you connect them to a computer ?

I'd rather not mess with the question right now. In my experience changing the scope of a question makes people mad. I'll ask another question if I encounter any issues next.

I'm using mpu6050 with 5v, using few of them at once without disordering any resistors. Most of the time keep them on for quite a long each tome. It never fried anything for me. Also my wiring is much longer than what you're saying. 50cm are you kidding me? I've connected 2 of them in a single old cat5 that is way much longer than that.

The INT is the interrupt signal, usually open-drain output and you can connect many of them to the single MCU interrupt line (but you have to check all devices which ones are ready). The LOW level from MPU device signalize that data are ready (conversion was finished). So you don't have to periodically read status register to find it out (no polling is necessary).
In short, using INT is optional.

At first level they are optional, and at least half the code out there if not more never uses them.  If you do connect them together, then you have to poll all of them to see which is ready.


text:
Referencing Serial output
I'm confused with what I'm reading.
I have Serial communicating with my PC (USB) and SoftwareSerial over RS485 to a remote PC. I don't want to duplicate all of my print statements to be able to send output to either (or both) terminals. What I want to do is have a single set of print statements (think of a list of error messages) and then be able to output a message to either Serial or SSerial depending on which needs it. Does this make sense?

Almost all of those things you do which involve functions like print, println, and write all derive from the Print class.  You could have an array of Print objects and print to whichever you like.
Print* outs[] = {&Serial, &Serial1, &mySoftSerial};

//  Later somewhere in code:

outs[0]->println("This prints to Serial");
outs[1]->println("This prints to Serial1");
outs[2]->println("This prints to mySoftSerial");

for(int i = 0; i < 3; i++){
  outs[i]->println("This prints to all 3.  You could even make this bit a function");
}


text:
Motor on transistor causes arduino to reset
I have a motor hooked up to the emitter of a NTE24 transistor and ground, the collector is hooked up to 3.7V, and the base is connected through a 10ohm resistor to a PWM pin on an arduino mega, which is powered by 3.7V through Vin. I use analogwrite on the pin to control the motor speed.
When i turn it on, the arduino just resets. I think it’s because the base is drawing too much current from the arduino pwm pin, but if I replace the 10ohm resistor with 330ohms, it is far too slow. Any ideas? I have tried a TIP3C transistor as well to no avail.
Edit: I suppose my question now is I’m losing too much power in the transistor. Would a mosfet help with that? In addition, what’s a good small board that uses 3.3V that also has some sort of usb connection?
Edit 2: Read latest comment, tried MOSFET and fly back diode, now it just clicks and restarts :/

The NTE24 is an NPN transistor, so the emitter needs to go to ground and the collector to the load.  You could also be causing your lipo to sag too much.  I wasn't aware that there was any Arduion Mega specified for 3.3v operation, but even if there is the cell may sag under load to below a 3.3v regulator's input requirement, so it's often better to use a 2.8v or 3.0v regulator for such an application to provide more headroom.  And today people would use an NFET rather than a bipolar transistor.

@ChrisStratton the configuration he is using is the common collector one; it is perfectly valid in the analog domain, but I think that the OP should switch to the common emitter version like you suggest; the PWM wave will then power correctly the motor. As for the base resistor, 150-200 ohms is the minimum value the OP should put (otherwise the uC will fry its output). As for the arduino-mega at 3.7V, you are right; it is out of spec. At those voltages better use a 3.3V board (usually arduino micro can come in 3.3V variants, or other ones like the STM32 based ones)

@ChrisStratton I switched to common emitter, and I tried putting two 330ohms in parallel to drop resistance to around 165ohms, but the arduino starts resetting again, 330 is about as low as I can get. When I plug both ends of the motor straight into the power source it goes much faster than through the transistor. Should I try Mosfets? I know 3.7V isn’t good for the mega, so I’ve been trying to look for 3.3V arduino boards, but I can’t find one that have a usb B or A Port, which is really helpful. Any suggestions?

Did you remember the flyback diode?

@IgnacioVazquez-Abrams Where would I put that? Wouldn’t that only help with protecting the transistor? That doesn’t seem to be the problem, it seems like something with the transistor dissipating too much power at 330ohms, and drawing too much base current from the pwm pin with less ohms

You need to add more facts like, motor data, battery data. As the question is now it could be a  number of reasons. And regarding flyback diode, read this: https://en.wikipedia.org/wiki/Flyback_diode

Why you shouldn't do it, chances are that shorting an ATmega output pin to ground will not cause the process or reboot, so "drawing too much current from the PWM pin" is probably not the issue.  You do need the diode, unless you are using a MOSFET of the sort which implicitly contains one.

Try measuring the battery voltage with an oscilloscope... I think that you will see it going pretty low until the board resets when you start driving the motor....

@ChrisStratton I added a fly back diode, and I switched to 30N06L MOSFET, with 330 ohms between gate and pin with a 10k pull down resistor to ground, source to ground, and 3.3V to motor to drain. The moment it turns on the motor clicks and the arduino resets :(

As I've been saying all along, a lithium battery under load may well drop below the regulator's input voltage requirement.  It could also trigger the ATmega brownout detector.


text:
ESP8266 blink sketch not blinking LED
After flashing the blink sketch to the ESP8266, I removed all the unnecessary wires from flashing - and my setup to try and run the sketch looks like this:

Something to note about flashing - it would take anywhere from 10-50 tries before it would flash successfully, the other times it just failed to upload and spit out the espcomm failure to connect message, or it got halfway through the upload and quit. This is the only clue to me that maybe my board is just bad, and it won't be able to run any sketch - I ordered another ESP8266, but I'm still wondering if I could be doing something wrong, it seems fairly straight forward, and I have done a lot of research about this up until this point. This is my first arduino project, other than the starter projects.
Also not represented in the diagram are the female to male jumper cables I am using to connect to the ESP8266. Those connect to the breadboard, and then I plug another wire into the breadboard on the same row to attach it to what it needs to be attached to. I figure none of this stuff matters - as long as it is powered (red LED) it should be working.
Any ideas why the onboard LED isn't blinking? Or is the sketch not running at all? Does the upload problem matter...could it be producing a false positive result? The only other idea I have where something could be different is an output capacitor for the voltage regulator, I have been told that a 10mF capacitor is what I would use (but I have also been told it doesn't matter...and neither does the filter capacitor, I just put it in anyway).
CODE (straight from Arduino IDE / ESP8266 examples):
/*
 ESP8266 Blink by Simon Peter
 Blink the blue LED on the ESP-01 module
 This example code is in the public domain

 The blue LED on the ESP-01 module is connected to GPIO1
 (which is also the TXD pin; so we cannot use Serial.print() at the same time)

 Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
                                    // but actually the LED is on; this is because
                                    // it is acive low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}

Mike pointed out my regulator matters (because of dropout voltage) - I am using this one:
http://www.nteinc.com/specs/1900to1999/pdf/nte1904.pdf

not all esp-01's ive used correctly map led_builtin, or you have a pin mode that conflicts with it. the board may also be flaky or have thermal issues.

The ESP8266 is power hungry, the Arduino may not have enough output current to power it.  Also, which voltage regulator you're using matters, as some have higher dropout than others.

Thanks for your answer, the red LED is on...so its getting power? I am using the NTE1904 http://www.nteinc.com/specs/1900to1999/pdf/nte1904.pdf - what is dropout?

Could lack of power be causing my upload problem? (infrequent success)

dropout voltage is very low (0.45V) so shouldnt be an issue? how can i test if the arduino is giving enough current?

@ewizard Okay, yeah, the dropout on that v-reg is low.  Are you able to run the ESP from a real power supply?  Normal current draw is around 100mA, which might be too much for the Arduino.  And peak current draw can be three times that.  How are you powering the Arduino?...That matters.

Power hungry, I have measured 270mA in the peeks and the Arduino can't supply near that. I have had the same issue!

so you guys are saying I need to power from something else? would a 9v battery work (I'm aware its not economic, just want to solve the problem)? I don't have a legit power supply really, I'm running the arduino from USB (my computer). If 9v doesnt work...would AA or AAA be enough?

for some reason the 9v on my arduino board isn't working, I plug it in and the board doesn't turn on so that isn't an option, I do have a 9v battery snap, or I could get a cheap power supply?

@ewizard A standard 9V battery cannot supply much current at all.  Use several AA (or C or D) batteries in series if you have have nothing else.

I just tried with 3 AA batteries and no blinking led...it was being powered though...i'm thinking maybe my chip is defective

@ewizard 3 AA batteries and the voltage regulator?  If you used the batteries directly without the regulator you probably destroyed the chip.  Otherwise, try reprogramming it.

yah with the regulator...ill try reprogramming it while battery powered - i read that the arduino uno puts out 500mA on the 5V, shouldnt that be enough?

I just tried reprogramming and it is still just as hard to upload

Here's how you test your voltage regulator setup:

Disconnect the ESP8266.
Connect a 10 ohm 1 W (or higher) resistor across the output of the v-reg.  One end goes to the output, the other goes to ground.
Measure the voltage across the resistor.  If it stays regulated close to the expected 3.3V, then you're fine.  If not, then this setup can't supply enough current for the ESP8266.

so do you think that there isnt enough power after the power goes through the regulator?

Ive tested the voltage coming out of the regulator (+ side on voltage regulator output, - side on ground coming out of esp8266) and it reads 3.3v  or 3.27 maybe...is that close enough?

@ewizard Yes, that's close enough.  But is that with a load on it?  That's why I suggested the test above.

so the resistor simulates the load? how close does it have to be to 3.3v? im going to go get a 10 ohm 1 watt resistor

@ewizard It has to be at least the minimum voltage required for the ESP8266 to run.  You'll have to find that spec.

Does trying two AA batteries rule out having to do this test?

@wizard Two AA batteries don't have enough voltage to correctly power the ESP8266 and probably even the voltage regulator.

sorry i meant 3 batteries ... anyway, i did the test and it is fine...stays right at 3.3v across the resistor

@ewizard Then your problem is not the power supply.  I would have a capacitor on the v-reg output, though.  I have a 330uF on mine to handle surges in current draw.  I would also triple-check all connections.

ok ... a someone suggested i use a 10uF for the regulator i have...does that make sense?

i tried a 10uF output capacitor and nothing changed...also triple checked wires,I'll be able to see if it is the module tomorrow...seems like there is something wrong with the flash (ram) on this one

Some ESP8266 - V01 boards won't blink integrated led (only works with GPIO2), so connect it to a resistor (~150 ohms), in series with an external led to ground. I don't know why... is just the way that it is...

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


text:
Temperature Controlled fan using arduino project regarding - LCD not displaying anything
I have connected the circuit as per the diagram below and I have got the LCD to display boxes and nothing else. What could be wrong here? Please help!
Circuit diagram below -

Code as follows -
#include<DHT11.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
#define dht11pin 12
dht11 DHT11;
#define pwm 9
byte degree[8] =
{
  0b00011,
  0b00011,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};
void setup()
{
  lcd.begin(16, 2);
  lcd.createChar(1, degree);
  lcd.clear();
  lcd.print("   Fan Speed  ");
  lcd.setCursor(0, 1);
  lcd.print("  Controlling ");
  delay(2000);
  analogWrite(pwm, 255);
  lcd.clear();
  lcd.print("Our Project ");
  delay(2000);
}

void loop()
{
  DHT11.read(dht11pin);
  int temp = DHT11.temperature;
  lcd.setCursor(0, 0);
  lcd.print("Temperature:");
  lcd.print(temp);
  lcd.write(1);
  lcd.print("C");
  lcd.setCursor(0, 1);
  if (temp < 26 )
  {
    analogWrite(9, 0);
    lcd.print("Fan OFF  ");
    delay(100);
  }
  else if (temp == 26)
  {
    analogWrite(pwm, 51);
    lcd.print("Fan Speed: 20%   ");
    delay(100);
  }
  else if (temp == 27)
  {
    analogWrite(pwm, 102);
    lcd.print("Fan Speed: 40%   ");
    delay(100);
  }
  else if (temp == 28)
  {
    analogWrite(pwm, 153);
    lcd.print("Fan Speed: 60%   ");
    delay(100);
  }
  else if (temp == 29)
  {
    analogWrite(pwm, 204);
    lcd.print("Fan Speed: 80%    ");
    delay(100);
  }
  else if (temp > 29)
  {
    analogWrite(pwm, 255);
    lcd.print("Fan Speed: 100%   ");
    delay(100);
  }
  delay(3000);
}

I used the default LiquidCrystal.h library for this project. Is that wrong?

The boxes on the display is either a contrast problem or a wrong wire. Keep only the display connected to the Arduino Uno, and remove everything else. Use a sketch that only uses the display. How do you control the contrast ? Compare your project with one of the examples: https://www.arduino.cc/en/Reference/LiquidCrystal

Your constructor doesn't match your wiring:
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

You have:
RS = 7
E = 6
D4 = 5
D5 = 4
D6 = 3
D7 = 2

Yet your wiring has:
RS = 2
E = 3
D4 = 4
D5 = 5
D6 = 6
D7 = 7

I.e., completely backwards.
The constructor prototype is:
LiquidCrystal(rs, enable, d4, d5, d6, d7)

Yet you seem to have chosen to ignore (or misunderstand) that.
Instead you need to specify your pins correctly:
LiquidCrystal(2, 3, 4, 5, 6, 7);

Also, as a side note, you don't have a ground connection to that little 9V circuit off to one side - so you will never be able to control it.  Read this.


text:
SIM900A showing Starting modem test...ERROR, no modem answer. Checking IMEI...Modem's IMEI: 0

Edit:
Solution can be found HERE

I am trying to interface Simcom SIM900A GSM (SIM900a Mini DEV Board v3.9.2) and I tryed interfacing it with Arduino UNO. I have connected as:
Pins:
SIM900A - Arduino
=================
VCC     - VDC (+5V)
GND     - GND
5VR     - Connect to Arduino TX (Pin 1)
5VT     - Connect to Arduino RX (Pin 0)

Power Supply (External):
5V 2A

Problem
When I upload sketch of:
Example > GSM > TestModem:

to Arduino, I got this output from Serial Monitor:

Starting modem test...ERROR, no modem answer.
Checking IMEI...Modem's IMEI: 0
Reseting Modem... Modem is functioning properly: IMEI: 0

Other info:

By supplying 5V, 2A the SIM900A Power LED ON continuesly and Signal LED blink with certain period of time which mean I am okay with signal.

I connected SIM900A and Arduino with Male to Male + Female to Female as I don't have Male to Female wires. I tested the wires with Multimeter and it's prefectly working.

I tested uploading other sketches of sending sms but not successful. Note that, I have load + free sms on SIM.

Power supply is actually Adapter (no transformer but circuit) with output of 5.1 Volts

My previous post can be checked HERE
PS:
Yesterday just for a minute I noted: Both LEDs (Power + Signal)  of SIM900A were blinking at same time. But then by restarting it gets Okay again.
Please help. I am likely to die becuase of tension.

Some points: 1. You can't use pins 0/1 for both the GSM and your debugging at the same time. You will have to use SoftwareSerial (ugh) on another pair of pins. 2. The GSM library is for the Arduino GSM Shield, not the SIM900A.

Hello @Majenko, Thank You very much for your comments. With due respect if you allow to let me clarify before flaging my post as duplicate, despite the title being same we have different content, also by following the instructions in mentioned post I applied that but nothing happened * (actually they say you have to use different, mine is already in place) * I know rules of SO and I will never spam it with questions by bombording it with same content. I never ask, but I research before very thoroughly. Thank You.

@Majenko Thank You. 1: As you said: I can't use 0/1 I am using SoftwareSerial mySerial(9, 10); Still nothing happening (I mean not sending msg). 2: If I can't use GSM Library what should I use to make this SIM900A Mini work? What I want to accomplish is Send Text Message. Please post Answer, so that help universe solve this problem. (As many people are facing same problem and I found no solution)

You already asked this question at SIM900a Mini Modem, IMEI 0, Help with TX RX pins  and have now indicated that the answer is found there.   You should not have re-posted your already asked question.

@ChrisStratton I agree, and I apologize for my ignorance. Actually I wait for answer and every second I used to refresh my page but go no answer. For the sake of attention and more clarity I asked again with little different context. BTW the "answer there" is also mine. I give link just for ease if in case someone like me needed. Anyways Thank You very much. If anyone want to delete this post I am okay with it. I am okay with every SO rules. Once again accept apologize.

Re-posting to get extra attention is pretty much exactly what is prohibited.

Note:
Detailed Solution can be found Here

Excerpt:
My Pins connections were wrong, it should not be: 0 and 1 it should be 2 & 3
Also SoftwareSerial.h is not working with SIM900A
Pins:
All connections should be like this:
SIM900A - Arduino
=================
VCC     - VDC (+5V)
GND     - GND
5VR     - Connect to Arduino TX (Pin 3)
5VT     - Connect to Arduino RX (Pin 2)

Details Here


text:
Arduino port grayed out for Fake Board with CH340
I have downloaded and used Arduino IDE v1.8.4 from official site (needs no install) for windows10, and connected my random board with a ch340, but it's LED is only blinking and I can't select the port (ie. it's grayed).
I did test all USB ports and restarted my laptop but that didn't work!
I tried to install 1.6.9 IDE that I had before, but again the port option is unselectable!
This is my board:
http://uupload.ir/files/xgv_uno.jpg

What OS are you on? Is it a Genuine Arduino board?

Which LED is blinking? Any chance of a screenshot?

Have you tried a new cable? or a different laptop? If you have is its possible you have the wrong board selected?

What OS are you using?

@Majenko: windows10, I don't know is this genuine or not? how can I find this? (I only see the microcontroller is SMD)

@sa_leinad: i have edited my question

@CodeGorilla: Cable is OK, and I have no computer at know to test it

Simplest possible thing would be that you do not have CH340g driver installed and you should try installing it first; These boards use CH340 for usb to serial and they need the driver to be installed; Please give it a try by getting the driver from the following link http://www.wch.cn/download/CH341SER_EXE.html or any other reliable source if there is any problem with the link;
If the board is not recognized even after that, it could be a bad USB port or a bad USB cable or even a board with the CH340 chip dead;


text:
How to connect a simple wall switch to arduino GPIO
I am trying to create a smart doorbell, but my problem is that doorbell makes ring any time when nobody touch the button.
I think that the problem is caused for the incorrect way to connect the analog wall button to arduino GPIO.
Basically my wiring diagram is:
Analog Input (A0) to 1 pin of the button.
Ground of the Arduino (GND) to the other pin of the button.
When the button is pressed, the circuit is closed, and doorbell makes ring!
But surely this is not the way to connect a button on the wall because the doorbell sounds on its own.
I leave a picture of the button

Your problem is the lack of pullup/pulldown resistor. Search and read about it.

Can you provide a schema over the button, power source (AC or DC and voltage) and doorbell (current consumption), preferable with type of component. Or just more data is needed.

jose can u c is absolutely right, you need a pullup. No need to change your wiring however: the Arduino has built-in pullups on all the inputs. You just have to activate them:
const uint8_t buttonPin = A0;  // or any other pin for that matter

void setup()
{
    pinMode(buttonPin, INPUT_PULLUP);
}

This is true. But in some cases where the wires are long, induced noise can overpower the relatively weak internal pull-up resistors. If this happens with external pull-ups, you can decrease the resistance value to increase the pull strength, but with internal pull-ups, you cannot change them.

You need to have a pull-up resistor, see circuit below.
You do not need to connect it to an Analog pin, but a digital pin. Without a pull-up or pull-down resistor, the voltage on the input pin "floats" anywhere, and can give false triggers. This circuit forces the pin to either be 5V or 0V.

simulate this circuit – Schematic created using CircuitLab

This is a good answer; but @santiago-dantuoni should clearly mention if its an AC powered doorbell or a DC powered doorbell;


text:
Avrdude Verification Error while flashing Arduino Mega code
I'm working with an Arduino Mega 2560 and am getting the following error at compile time:

avrdude: verification error, first mismatch in byte 0x0000 0x14! =
  0x25 avrdude: verification error; content mismatch

I've already changed the COM port and also restarted an IDE.

This is not a compilation error but an error when verifying the programmed memory.

Do you have the Board set correctly? Tools->Board.

Do you have an old Mega2560 and have !!! somewhere in your code?

First mismatch in byte 0x0000. Is that the first byte that goes wrong ? That means that not even a single byte passes the verification ? Perhaps the cause is one of these: 1) A cheap clone with a bad bootloader. 2) An old bootloader. 3) A bug, perhaps a bug with the size of the code or ram, for example the code at the border of 32k or 64k. 4) Maybe the voltage of the Arduino board is too low. Measure it. It must be above 4.5V. 5) Maybe a bad usb cable. 6) Wrong usb driver. 7) Board is too cheap and is missing decoupling capacitors.

I have seen this myself. It turned out that coms were a little distorted. If you have access to one, use an oscilloscope to view the waveforms of the 4 ISP pins.

Similar to: https://arduino.stackexchange.com/q/52798/19409 https://arduino.stackexchange.com/q/30946/19409 https://arduino.stackexchange.com/q/59837/19409

I have made Jot's comment into an answer in the hope that it helps someone.

First mismatch in byte 0x0000. [This is] the first byte that goes wrong. That means that not even a single byte passes the verification.
Perhaps the cause is one of these:

A cheap clone with a bad bootloader.
An old bootloader.
A bug, perhaps a bug with the size of the code or ram, for example the code at the border of 32k or 64k.
Maybe the voltage of the Arduino board is too low. Measure it. It must be above 4.5V.
Maybe a bad USB cable.
Wrong USB driver.
Board is too cheap and is missing decoupling capacitors.


text:
Problem with load cell and ADS1262
I'm using PROTOCENTRAL ADS1262 32-BIT PRECISION ADC BREAKOUT BOARD to read the voltage in simple a load cell.
The connections follows the instructions on its library
But I cannot make it work, the readings has lots of spikes and i cannot discover what is happening.
Can someone help?

That is a very hard question to answer. Every pulse is followed by a slope, that means it could be an analog charge that is released. Can you do more tests ? Beside the spikes, can you actually measure the analog signal ? What happens if you shortcut the inputs ? Do you use the library provided by ProCentral ? Have you enabled the right 50Hz or 60Hz noise suppression ? How large are those spikes ? Have you tried a different power supply ? The ADS1262 has test modes, perhaps you can try one of them. The datasheet is very long. It will not be easy to fix.

This problem was solved on Texas Instruments Forum.
Thanks.
http://e2e.ti.com/support/data_converters/precision_data_converters/f/73/p/627185/2344271#2344271

From the TI forum:

I noticed that you are polling data ready and then performing the data processing/serial output. The serial output operation is likely taking a long time and preventing you from capturing data at the faster data rates. You can try disabling the serial output and using an oscilloscope to see if you're able to reading data at the full throughput; however, when outputting this data over a serial interface you might not be able to capture and display all of the data...
I would try capturing data to memory and outputting the serial data in batches (for example, output 10 samples of data at a time). This might give you a little more data throughput.


text:
Not sure why eeprom isn't reading back correctly
I'm new to saving data on eeprom and I'm obviously doing something wrong but I'm not sure what.  I have one program which both writes to and reads the internal eeprom on a attiny85 and this seems to work.  However when I try to use this program to write and then remove the power from the attiny, then reprogram it with another program to read the eeprom it gives values of -1 for time and NAN for temperature.
My program which works is as follows, the program to read the eeprom only is the same however I deleted all the sections which write.  If you want me to add that program let me know.
I am using at attinyavr programmer from sparkfun and I have connected pins 3 & 4 on the attiny to an arduino uno which is connected to the serial monitor so that I can see the output (described here:  http://www.instructables.com/id/Easy-ATTiny-Serial-Communication-with-Tiny-AVR-Pro/#CP78RMAJ76GI6JQ)
Feel free to direct me to another answer if someone else has had the same problem, at the moment I think I will figure this out eventually but I suspect it will take me a few days so thought I would ask hopefully it's obvious to someone else.
(I'm aware that the time won't be correct since it should be unsigned long not an int, was just changing it round to test if that was the problem which it seems not to be).
Any help is really appreciated!!! Thanks :)
    /*
ATTINY85 pin 3 -> Arduino Uno pin 0
ATTINY85 pin 4 -> Arduino Uno pin 1
Program choose 1MHz clock
 */

#include <EEPROM.h>
#include <SoftwareSerial.h>
// Definitions
#define rxPin 3     // Make pin 3 on the
#define txPin 4

SoftwareSerial mySerial(rxPin, txPin);

int currentTime;
int getTime;

int sensorPin = 7; // This is the 7th pin on the ATtiny85,
                         // it is an analog input when reading as digital
call it 7? analogpintochannel function
                          // (On the HLT tutorial it is labelled as Pin2: Analog input 1, SCK )
float temperature = -500.00f;     // Create a new float called temperature and give it the value -500 to start with
float getTemperature = -500.00f;
int eepromAddress = 0;       // initialize variable for position in eeprom to store data collected
int getEepromAddress = 0;

// the setup routine runs once when you press reset:
void setup() {
  pinMode(sensorPin, INPUT);    // make pin 7 on the ATTiny an input pin
  mySerial.begin(9600);         // begin software serial at rate of 9600

}

// the loop routine runs over and over forever:
void loop() {

  static int countDataCollected = 0;  // initialize a count variable to count the data collected, static int should set to 0 only first time, second time loop goes round it shouldn't reset to 0

  if (countDataCollected==0) delay(90000); // put delay here so it gives me time to load the read eeprom program if required before it changes the eeprom in case that was the problem.

  if((countDataCollected>=0) and (countDataCollected < 10)) {

    currentTime = millis();
    temperature = analogRead(sensorPin)*5.0/1024.0;  // read value on pin 7, multiply it to find temperature
    temperature = temperature - 0.5;
    temperature = temperature / 0.01;

    mySerial.print("\n\nData number: ");
    mySerial.print(countDataCollected);
    mySerial.print("\tTime: ");
    mySerial.print(currentTime);
    mySerial.print("\tTemperature: ");
    mySerial.print(temperature);
    mySerial.print("\tCurrent eeprom address: ");
    mySerial.print(eepromAddress);
    mySerial.print("\t");
    mySerial.print(getEepromAddress);

    EEPROM.put(eepromAddress, currentTime);
    EEPROM.get(getEepromAddress, getTime);
    mySerial.print("\tGot time: ");
    mySerial.print(getTime);

    eepromAddress = eepromAddress + sizeof(currentTime);
    getEepromAddress = getEepromAddress + sizeof(getTime);
    mySerial.print("\teeprom address: ");
    mySerial.print(eepromAddress);
    mySerial.print("\t");
    mySerial.print(getEepromAddress);

    EEPROM.put(eepromAddress, temperature);
    EEPROM.get(getEepromAddress, getTemperature);

    eepromAddress = eepromAddress + sizeof(temperature); //Move address to the next byte after float 'myfloat'.
    getEepromAddress = getEepromAddress + sizeof(getTemperature);
    mySerial.print("\tGot temperature: ");
    mySerial.print(getTemperature);
    mySerial.print("\teeprom address: ");
    mySerial.print(eepromAddress);
    mySerial.print("\t");
    mySerial.print(getEepromAddress);
    mySerial.println();

    }

  // wait two seconds so as not to send massive amounts of data
  delay(2000);
  countDataCollected=countDataCollected+1;

  mySerial.print("\n\nNext data number =");
  mySerial.print(countDataCollected);
}

See https://stackoverflow.com/questions/36623186/attiny85-eeprom-erase-after-power-lost for an explanation to why eeprom is erased.

@MikaelFalkvidd, thanks!!!, that sounds like it's probably the problem.  I'm just trying to learn how to program the Attiny85 with a bootloader, when/if I do I will get back to confirm that was the reason. (might take a while as I'm in China and need to find out how to order the components I need to build the circuit)

Great that you found a solution. I think you have a better grasp of the solution than I do, so you'll be able to write a higher quality answer :)

@ Mikael Falvidd, I'm not sure, but thanks!! :)

@ Mikael Falvidd  Actually in the end found my comment above about the programmer was incorrect, (such a long time since I asked the question I forgot to try disconnecting the power and when I did the programmer made no difference. Have deleted the comment so as not to confuse other people) but you did direct me the correct answer, thanks!!!, it was fuses that made a difference. Will add answer below, so happy it's working!!

Fixed by resetting the attiny85 fuse to stop the EEPROM being cleared when the attiny was reprogrammed.
As far as I understand (I am a newbie at AVR programming so may be wrong)
The arduino bootloader (in the Arduino IDE) sets the attiny fuses.  One of the fuses that it sets (also the attiny85 default setting) clears the EEPROM when reprogramming.  To see how the bootloader is setting the fuses to you can turn on verbose comments in the Arduino IDE, and run the bootloader. When I ran the bootloader it set the fuses as follows: pattiny85 -cusbtiny -e -Uefuse:w:0xff:m -Uhfuse:w:0xdf:m -Ulfuse:w:0xe2:m
i.e. arduino bootloader settings,
     efuse: 0xff,
     hfuse: 0xdf (need to change to d7),
     lfuse: 0xe2 (affects the clock),
You can use a fuse calculator (http://www.engbedded.com/fusecalc/)
 to determine how to change the fuse settings so the the EEPROM is not cleared.  (In the fuse calculator tick the box for "Preserve EEPROM memory through the chip erase cycle, EESAVE=0").  When the box is ticked the hfuse setting is D7 rather than DF
Also note that the bootloader in Arduino sets the lfuse to 0xe2, this is different from the default (it affects the setting 'Divide clock internally by 8' if 0xe2 is used it's an 8Mhz clock, the default prior to loading the boatloader is 1Mhz). Noting this because I initally reset everything to default and then had clock problems.
The hfuse can be set to d7 by downloading and running the AVR programming software https://sourceforge.net/projects/winavr/ and then setting the fuse using avrdude in a command window.
(more information on AVR setting fuses here http://www.ladyada.net/learn/avr/index.html)
I ran avrdude in a command window with the instruction:
avrdude -c usbtiny -p attiny85 -U hfuse:w:0xd7:m
("-c usbtiny" specifies the programmer used so this may vary, the attiny was connected to my computer USB port using the sparkfun attiny AVR programmer).

The bootloader itself does not set fuses. However, the Arduino IDE's Tools > Burn Bootloader command does set the fuses according to the boards.txt configuration for the currently selected board in addition to flashing the microcontroller with the bootloader.

ok, thanks for the correction! I'm not very clear on how everything works.


text:
Water flow sensor unable to get readings
I connected my "arduino(nano)" to "water flow sensor" and wrote a code which simply prints the readings like 0-1023 and tested it. First i got the readings but now i'm not getting it.

My code looks something like this.
void setup(){
 Serial.begin(115200);
}

void loop(){
 int vla=analogRead(2);
 Serial.println(vla);
 delay(1500);
}

and my connection.

Sensor to Supply module
  Vcc -->  5v
  Gnd -->  Gnd
Sensor to Arduino(Nano)
  Sig --> D2

Also asked at http://forum.arduino.cc/index.php?topic=501527

posting details about your exact flow sensor and library being used along with your schematic and full code may get you better answers; I have used water flow sensors to a good extent for some prototypes but cant answer your question without better details since many people around simply down vote answers without understanding the question and the intent of the person who answered :-)

Sensor to Arduino(Nano)
  Sig --> D2

Your connections are wrong.
int vla=analogRead(2);

is reading from analog channel 2, which is pin A2 on your Nano, not D2
D2 is not an analog pin and thus you can't use it with analogRead().

I tried it but i'm getting only junk value, i even tried adding a pullup.

i think its 16 for a2 and 2 for d2

Use A0, A1, A2 and so on for analog pins. To avoid any confusion. For example: int vla=analogRead(A2);

"i think its 16 for a2 and 2 for d2". analogRead(A2), analogRead(2), and analogRead(16) all do the same thing. See the source code: https://github.com/arduino/Arduino/blob/1.8.4/hardware/arduino/avr/cores/arduino/wiring_analog.c#L38-L55

But @Jot is right, analogRead(A2) makes the intent of the code the most clear.

Okay. Now it's clear.


text:
Can I use my Arduino nano to upload sketch in Uno's ATmega328p chip?
I can not upload sketch to my UNO directly. My ATmega16U2 doesn't work.But the Atmega328P processor still work.
 I have an arduino nano lying around. Can I use it to upload sketches to Atmega328P directly.
Thanks in advance

Yes. You can. Either as a USB to UART adaptor and use the Uno's bootloader as you would with any bootloader-enabled breadboard Arduino, or as an Arduino ISP to program the chip directly through the ICSP pins as you would when putting the bootloader onto a blank chip.


text:
Communicating to arduino as fast as real-time
I'm trying to control some pneumatic cylinders with arduino. I want to do the calculations on pc and then send the command to arduino to control the air flow to pneumatic cylinders. It's very important that arduino receive these commands super fast (in real time if it's possible) so that I can control air flow in millisecond precision.
What is the fastest way to communicate to arduino (Read and write). I tested serial communication and it's very slow in compare to real-time. Is there any specific settings for serial communications that i need to do to increase it's speed? Should I use LAN connection? Or maybe I should use for example Arduino YUN with an OS?

Going over USB will add about a millisecond of jitter to your data in both the sensing and command directions.  Using a part with direct USB rather than then needing to go through a serial link from USB chip to processor could help limit what is added on top of that, but it will still be there.  If you could get a USB high speed solution that would reduce this as the polling interval is shorter, but there are few such solutions for simple microcontrollers.  Ultimately, USB is meant to move a lot of data in a reasonable amount of time - it is not designed to move small messages promptly.
True realtime systems put the processing and the actuation in tightly connected local circuitry. With the increasing isolation of PC processors from external I/O by multiple layers of intermediate architecture on the chip and motherboard, you see very little realtime use of PCs today.  An embedded board with a decent processor and good direct I/O (Beaglebone, maybe the Linux side of a Yun or comparable) would be better, but be aware that multi-tasking operating systems like Linux or Windows are fundamentally in conflict with real-time performance - it takes very complex hacks to make that work, for example running a realtime scheduler directly on the hardware  and having it run an ordinary operating system as a low priority task.
The architecturally cleanest solutions would be to find a way to fit your calculations on a fast single processor - in the realm of Arduino-style solutions perhaps one of the latest in the Teensy series.  Beyond that you are really out of the realm where this could be considered an Arduino question - trying for example to run a realtime scheduler on the Linux half of a Yun is really not related to "Arduino" at all.
One thing that is not clear however is if your system needs to react in real time, or merely to sequence with precise timing.  Mere sequencing is a far easier problem, as you can send the data a bit in advance of need and hold it in a buffer, so that communication latency doesn't delay operations.  A 3d printer could be an example of this - the really complex  calculations are done on a PC, then commands are drip-fed a bit in advance of need to a simpler executive traditionally running on a repackaged Arduino Mega, and that moves the motors with sub-millisecond pulse precision.  Given that there are no realtime inputs to the calculations, their results can also be stored on an SD card for use months later with no PC connection at all.  If your need does reduce to such pure non-reactive sequencing then things are a lot simpler; if it doesn't, then the rest of the explanation here applies.

You forgot to mention the Raspberry Pi. That is a computer running a (almost) normal version of linux with I/O.

@Jot I did not "forget", I quite specifically excluded the Raspberry Pi from this conceptual overview because it is architecturally ugly, with the undocumented proprietary coprocessor complicating things.  You also seem to be overlooking the difference between "Linux with I/O" and "Linux extended for realtime scheduling with low-latency I/O" - that may be possible on the pi with enough effort, but it's not your typical userspace write to /sys/class/gpio

You are right. Maybe EBAG can add more details to his question about a possible sequence and about the calculations.


text:
ESP8266 sketch worked a few times but now doesn't seem to run
When I flash my code:
/* Create a WiFi access point and provide a web server on it.

 Author: Lucio A. Rocha
 Last Update: 21 Aug 2016

*/

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

/* Set these to your desired credentials. */
const char *ssid = "MaisonBlanche";
const char *password = "7932gLBw";

ESP8266WebServer server(80);

const int led = 2;  //GPIO2

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
 * connected to this access point to see it.
 */
void handleRoot() {

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"\
  \
    <title>MicroCloud</title>\
    \
  \
  \

You are connected on MicroCloud #2!
\

Uptime: %02d:%02d:%02d
\

Status: Light ON

\

Turn ON

\

\

Turn OFF

\
  \
",

    hr, min % 60, sec % 60
  );
  server.send ( 200, "text/html", temp );

}

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");

  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);

  pinMode(led, OUTPUT);
  digitalWrite ( led, HIGH );

  //URLs available to query
  server.on("/", handleRoot);
  server.on ( "/on", turnON );
  server.on ( "/off", turnOFF );
  server.begin();
  Serial.println("HTTP server started");

}

void turnON(){

  digitalWrite ( led, HIGH );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"\
  \
    <title>MicroCloud</title>\
    \
  \
  \

Request: Light ON
\

Uptime: %02d:%02d:%02d
\

\

Status: Light ON

\

Turn ON

\

\

Turn OFF

\
  \
",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);

}

void turnOFF(){

  digitalWrite ( led, LOW );

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

"\
  \
    <title>MicroCloud</title>\
    \
  \
  \

Request: Light OFF
\

Uptime: %02d:%02d:%02d
\

Status: Light OFF
\

Turn ON

\

\

Turn OFF

\
  \
",

    hr, min % 60, sec % 60
  );

  server.send ( 200, "text/html", temp);

}

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

onto the ESP8266 with this setup:

For my serial output I get:
en 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld

I got it to work semi successfully before now. I was basically following along with https://create.arduino.cc/projecthub/luciorocha/esp8266-control-led-with-smartphone-8a59f3. I got to the point where the code was being run successfully - but then something unexpected happened, when I thought the LED would go on, when I selected the turn on button, nothing happened. When I selected turn off, the blue LED on the board turned on and stayed steady. Then, when I selected turn on again, the LED on board went off. I thought the sketch was supposed to manipulate pin 2, but it seemed to be manipulating the onboard LED instead, and in the reverse way that it should.
Now, I can upload it, but the only thing it does after that is spit out the above serial output. I have tried running it with:
GND -> GND
VCC -> 3.3v
CH_PD -> 3.3v

Other sketches seem to work, so maybe something I did triggered an ESP8266 setting which now conflicts with something in the code?
UPDATE
I double checked that other sketches are running - also running is a sketch that connects the ESP8266 to my network - it connects and gets assigned an IP. I made this simplified sketch of the one above, involving the connection process:
/* Create a WiFi access point and provide a web server on it.

 Author: Lucio A. Rocha
 Last Update: 21 Aug 2016

*/

#include <ESP8266WiFi.h>
#include <WiFiClient.h>

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");

  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP("MaisonBlanche", "7932gLBw");

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
}

void loop() {

}

The only thing it outputs (no connection) to serial is:
0, len 1384, room 16
tail 8
chksum 0x2d
csumcL⸮
~ld

So it seems as if the problem is with my code, or it is able to connect to a network as a client but not as a softAP?
UPDATE
I ran this code:
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server(80);

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

  Serial.print("Setting soft-AP ... ");
  boolean result = WiFi.softAP("MaisonBlanche", "7932gLBw");
  if(result == true)
  {
    Serial.println("Ready");
  }
  else
  {
    Serial.println("Failed!");
  }
}

void loop()
{
  Serial.printf("Stations connected = %d\n", WiFi.softAPgetStationNum());
  delay(3000);
}

The same garbled serial output appears, and then it started outputting:
Stations connected = 0
Then the output changed to:
Stations connected = 1
Does this just mean it is successfully connecting using softAP?
UPDATE
I think I have narrowed it down what is not working to the ESP8266WebServer. I used this code:
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server(80);

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

  Serial.print("Setting soft-AP ... ");
  boolean result = WiFi.softAP("MaisonBlanche", "7932gLBw");
  if(result == true)
  {
    Serial.println("Ready");
  }
  else
  {
    Serial.println("Failed!");
  }

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

void handleRoot() {

  int size=1000;
  char temp[size];

  int sec = millis() / 1000;
  int min = sec / 60;
  int hr = min / 60;

  snprintf ( temp, size,

    "\
      \
        <title>BEASTMODE</title>\
        \
      \
      \

You are connected on BEASTMODE!
\
      \
    ",

    hr, min % 60, sec % 60
  );
  server.send ( 200, "text/html", temp );
}

void loop()
{
  Serial.printf("Stations connected = %d\n", WiFi.softAPgetStationNum());
  //delay(3000);
  Serial.print("Soft-AP IP address = ");
  Serial.println(WiFi.softAPIP());
  server.handleClient();
}

When the loop starts it begins to output:
Soft-AP IP address = 192.168.4.1
Stations connected = 0

It seems to go between 0 stations connected and 1 station connected. I go to 192.168.1.4 in my browser, and it never loads the page, it just times out. So if it has a softAP IP address - but it is not accessible, then maybe the server isn't working for some reason. Also I read how you can put the chip into different modes (STA/AP/etc

This works fine, doesn't use ESP8266WebServer which seems to be the culprit. It is the web server from ESP8266WiFi. At the bottom there is a link to a blinking LED example which works for me. You just type in <ip>/gpio/0 in browser for off, and change it to /gpio/1 for on.

Accept your own answer to close this question.


text:
String to Int Array
I have a string:
String cod=server.arg("codice");

where codice (an IR sequence) is retrieved from a webserver.
For example:
codice=1, 2,  3, 4
In which the syntax can be modified.
So, cod is a string that contains numbers separated with ", "
To send the IR code i use:
irsend.sendRaw(rawData, 67, 38);

I don't know how to convert the String to Int (rawData) as requested by rsend.sendRaw.

Your question has nothing to do with Arduino.

@darimos on Stack Exchange sites, solutions are not to be edited into questions.  Rather, accept an answer which provides the solution, or if none does, post your own answer and return to accept that once the few-days waiting period of self answers has elapsed.

Use strtok to split the char array into the different parts, then use atoi on each of the parts to convert it to an int. (atoi ignores whitespace)
char* str = "4532, 4488,  548, 1694,  574";

const size_t bufferSize = 5;
int arr[bufferSize];

char *p = strtok(str, ",");
size_t index = 0;

while (p != nullptr && index < bufferSize) {
  arr[index++] = atoi(p);
  p = strtok(NULL, ",");
}

for (size_t i = 0; i < index; i++)
  Serial.println(arr[i]);

Edit: You just edited your post, and it seems like you really need to use Strings (capital S).
There are two ways to go about it: you have to keep in mind that String::c_str() returns the actual pointer to the internal null terminated char array inside the String object, and that strtok is destructive (it replaces the delimiters with null characters).
If you need the String for other things after converting it to an array of ints, you'll have to make a copy first:
String cod = "4532, 4488,  548, 1694,  574";
char *str = new char[cod.length() + 1];
strcpy(str, cod.c_str());

Don't forget to free the memory afterwards:
delete[] str;

If you don't care about destroying the String, you can just use:
String cod = "4532, 4488,  548, 1694,  574";
char *str = cod.c_str();

Edit 2: The ESP8266 compiler doesn't allow implicit conversion from const char* (read only) to char* (as strtok argument). To get around it, the clean solution is to copy it, as explained in my first edit.
If you really don't need the String afterwards, and you don't want to waste memory on the copy, you can just use an explicit type cast:
String cod = "4532, 4488,  548, 1694,  574";
char *str = (char*)cod.c_str();

The AVR compiler doesn't have any problems converting String::c_str() to char*

Hello, thanks for the answer. I tried your solution but i got this error:  char  *_EXFUN(strtok,(char *, const char *));
    ^

exit status 1
invalid conversion from 'const char*' to 'char*' [-fpermissive]

Do you mean for (size_t i = 0; i < index; i++) { Serial.print(arr[i]); Serial.print('\t'); } Serial.println(); ?

Since i need to send irsend.sendRaw(rawData, 67, 38); i need an int array called rawData or whatelse is the name. I hope it is clear, thank you.

arr is the array of ints

yes, i tried to do Serial.println(arr); but i received "call of overloaded 'println(int [5])' is ambiguous" which is the problem?

You're not being clear here. To send the code over IR, use irsend.sendRaw(arr, index - 1, 38);, to print the array, use for (size_t i = 0; i < index; i++) { Serial.print(arr[i]); Serial.print('\t'); } Serial.println();


text:
How do I properly convert a pointer (uint8_t* or void*) to a "normal" integer?
I'm writing a program for arduino that needs dynamic memory allocation frequently, but as I don't want the memory to get fragmented, I'm also writing a "memory handler" for it. This memory handler would need to do calculations involving both pointers and size_t variables, like this (example code is not part of program, but the structure of the calculations is the same):
size_t freeMemSize = nextPointer - currentPointer - currentSize;

Which would calculate the size of free memory between two reserved spaces.
Of course, arduino doesn't want to swallow this code, as it compares incompatible types. My questions are:

Is a cast to the correct integer type enough to solve the problem?
If it is, what is the "normal integer" counterpart of a pointer?

I guess this varies from processor to processor, so I should look for something like size_t, but for memory indices instead of sizes.
Board: Uno, Nano
IDE version: 1.8.2

If you want to do ordinary math rather than pointer math, intptr_t is specified to be an integer type capable of holding a pointer.

I think you might get more answers if you moved this to stackoverflow since it not specifically an Arduino issue, once you have the solution you could run it on any processor.

Assume the following declarations:
uint8_t* nextPointer;
uint8_t* currentPointer;
size_t currentSize;

Then the expression is valid:
size_t freeMemSize = nextPointer - currentPointer - currentSize;

If any of the pointers are void* the compiler cannot calculate the expression (pointer or size).
Cheers!

Yes, that will be it. One of my pointers were void* type. Thanks.

Beware this mixing of pointers and size_t only makes sense for pointers to objects of size 1.

@ChrisStratton The code is REALLY alpha version, and needs a lot of work, including variable types. But thanks for the warning, each advice helps to understand programming arduino a bit more.


text:
mcufriend SPI connection
Bought a cheap LCD form china (mcufriend, pictured below) and I cant understand which pin is which to use it with the SPI interface (starting to get worried that I can't use it), I've figured out this much:

LCD_RST; reset pin
LCD_CS; chip select
LCD_RS;
LCD_WR;
LCD_RD;

Which of those is MOSI, SCK, DC? Trying to use it with a ESP8266 (ESP-12).

You can't use that TFT screen with SPI. The SPI interface (SD_DI, SD_DO, SC_SCK and SD_SS) is for the SD card slot only.
All the pins starting LCD_ are the 8-bit parallel ("8080" style) interface for controlling the TFT screen.


text:
Controlling the Serial Monitor for 10 seconds
I am an amateur with Arduino and coding and I am learning in my lab class. My project consists of using a photoresistor to measure the brightness of a white LED. I have the following circuit built.

I am having problems with the code because I need the serial monitor to print every 1/10 of a second for 10 seconds. My professor started talking about the micros() function but never showed an example. I have an idea as to how I can utilize this function to control how long the Serial Monitor prints for but I have been unsuccessful. I know that setting a delay is good enough for reading every 1/10 of a second but how can I make the serial monitor print values for only 10 seconds?
I believe it should be a total of 100 readings.
This is my current code:
unsigned long start, finished, elapsed, total;
int analogInPin = A0;
int LEDreading;           // analog reading
int LEDpin = 9;           // LED on pin 9

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

void loop() {
  analogWrite(LEDpin,255);  // LED brightness
  start = millis();
  LEDreading = analogRead(analogInPin);
  Serial.println(LEDreading);
  delay(100);
  finished = millis();
  elapsed = finished - start;
  total = elapsed*100;

  if (total >= 10000){
    Serial.end();
}

You could count to 100...

If you can blink without delay(), then you can print without delay().

Using micros() is very much like boiling an egg.
When you want your egg to be cooked just right you know that it needs to be in the boiling water for a certain amount of time. There's three ways you can achieve that:

Use an egg timer to alert you when the time has passed,
Sit and stare at the boiling pot counting the seconds as they slowly tick by (booooooring..... ...zzzZZZzzz...)
Remember what time you put the egg in the water and glance at the clock every so often to see how much time has passed.

Using millis() is like option 3. It tells you how many milliseconds have passed since the board was turned on (or since the last millis() rollover at roughly 49 days). So when you put the egg in the water you record the current time. Then you periodically compare the recorded time to the current time (a simple subtraction will suffice) to see if enough time has passed. When it has you remove the egg and chow down.
So to put that more in a coding context - when you start some operation, or want to measure a period of time from a point, you just save the time in a variable:
start = millis();

(start must be uint32_t, aka unsigned long). To find if enough time has passed you just subtract that saved time from the current time and it gives you the elapsed time, which you can compare to your required elapsed time:
if (millis() - start >= 100) {
}

1/10 of a second is 100ms, so if you hit a difference of 100ms (or more) then your time has arrived and you can do something.
If you want it to do it again after that then just set the "start" time to the current time again.
For instance, for your requirements:
void loop() {
    // Record the start time - the static means it
    // only happens once the first time loop() is run and
    // it remembers the value between iterations
    static uint32_t start = millis();

    // Somewhere to store the number of values we
    // have given - again, static so it remembers across
    // iterations of loop()
    static uint8_t count = 0;

    if (count < 100) { // No more than 100 counts
        if (millis() - start >= 100) { // Tick
            start = millis(); // Do it again in 100ms time

            // Add whatever you need for your readings here

            count++; // Add one to the count
        }
    }
}

Using delay(100) will cause the sketch to wait at that line for 100 milliseconds.  That is not (quite) the same as DOING something every 100 milliseconds.  The difference is that other things take time too, so the time will be 100 milliseconds plus how ever long everything else takes.
The solution used by @Majenko still has that problem in a small way, because a new millis() value is used to set the new value of start.  In most situations, it will work fine, but it is possible that the either or both of the millis() results were more than 100 after the previous value of start.  That would happen if code that replaces the comment took more than 100ms some time.  The fix for that is very simple.  Just change start = millis() to start += 100.  That will attempt to speed up the following loop, if it was getting behind.
As a side note, it would be good to change the 100 millisecond references to a defined name.  Either a #define or a const.  Since the millis() function returns an "unsigned long" value, I would use the same data type for a related const value.  That just means that the compiler will not have to (invisibly) convert between different types when doing the math operations.
#define REPORT_CYCLE 100
const unsigned long REPORT_CYCLE = 100; // milliseconds between measurement and reporting cycles

If you are a beginner, you may not have seen static variables yet.  If you know about them, fine, but if not, they can be replaced by global scope variables.
The @Majenko code uses a fixed count of 100 iterations to do the measurement and reporting.  That works fine as long as neither the for 10 seconds or every 1/10 second changes.  If either of those change, the count limit would also need to be recalculated and changed.  Instead, I would use another defined name for how long to do measurement and reporting cycles, and let the compiler handle how many times that actually is.
Doing an analogWrite() sets the value (brightness here), which will stay constant until changed again.  Since your program only sets a single value, it only needs to be done once.  Move that statement to setup().
There is no need to do Serial.end() when the reporting is done.  That disables serial communication, but is unneeded, if no more Serial.println() commands are executed anyway.
To avoid calling millis() multiple times in the same 'pass' (in each if test), I like to call it once, and save the result.
Taking the @Majenko code, plus your starting sample, and described changes gets
// Intervals in milliseconds
#define REPORT_CYCLE 100
#define REPORT_INTERVAL 10000
unsigned long nextStart, endTime;
int analogInPin = A0;
int LEDreading;           // analog reading
int LEDpin = 9;           // LED on pin 9

void setup() {
  Serial.begin(9600);
  analogWrite(LEDpin,255);  // LED brightness
  nextStart = millis(); // Time for "right now"
  endTime = nextStart + REPORT_INTERVAL;
}

void loop() {
  unsigned long now = millis();
  if (now < endTime) { // still need to do more reporting
    if (now >= nextStart) { // time to get and report another reading
      nextStart += REPORT_CYCLE; // When the next reading should be done

      LEDreading = analogRead(analogInPin);
      Serial.println(LEDreading);
    }
  }
  // do other things, both while still reporting, and after reporting is done
}


text:
Problem with Arduino line follower
I am making a line follower robot. My code is like this
#define motI1 10
#define motI2 6
#define motI3 5
#define motI4 3

int left=9;   // left sensor
int right=1;  // right sensor

void setup() {
  pinMode(motI1, OUTPUT);
  pinMode(motI2, OUTPUT);
  pinMode(motI3, OUTPUT);
  pinMode(motI4, OUTPUT);
  pinMode(left, INPUT);
  pinMode(right, INPUT);
  Serial.begin(9600);
}

void loop() {
  if(((digitalRead(left))==HIGH)&&((digitalRead(right))==HIGH)) {
    digitalWrite(motI1, HIGH);
    digitalWrite(motI2, LOW);
    digitalWrite(motI3, HIGH);
    digitalWrite(motI4, LOW);
    Serial.println("FORWARD");
    delay(1);
  } else if(((digitalRead(left))==HIGH)&&((digitalRead(right))==LOW)) {
    // turn right
    digitalWrite(motI1,HIGH);
    digitalWrite(motI2,LOW);
    digitalWrite(motI3,LOW);
    digitalWrite(motI4,LOW);
    Serial.println("Right turn Right Sensor LOW");
    delay(1);
  } else if(((digitalRead(left))==LOW)&&((digitalRead(right))==HIGH)) {
    // turn left
    digitalWrite(motI1,LOW);
    digitalWrite(motI2,LOW);
    digitalWrite(motI3,HIGH);
    digitalWrite(motI4,LOW);
    Serial.println("Left turn Left Sensor LOW");
    delay(1);
  } else if(((digitalRead(left))==LOW)&&((digitalRead(right))==LOW)) {
    digitalWrite(motI1,LOW);
    digitalWrite(motI2,LOW);
    digitalWrite(motI3,LOW);
    digitalWrite(motI4,LOW);
    Serial.println("Stop");
    delay(1);
  }
}

Only pin 1 of the Arduino is working but other pins are not working for the IR sensor. But the pins for the motor are working just fine. What is the real problem?

Are you sure it's working? Pin 1 is used as Serial Tx line. Is there possibility that IR sensors requires pull up resistor?

Yes pin 1 is working. I don't think IR sensor requires pull up resistor.

Battery operated?  Disconnect the motors and measure to see if the sensor and motor control states are as you expect them when moving the sensors across the line.  Often people skip over the pitfalls of high current / low voltage problems when using batteries or even under powered wall supplies.

What kind of line-following sensor is it? If it's like the Sparkfun IR sensors, then they need to be connected to ADC pins and a digitalRead won't work on them.


text:
Unable to send IR command
I am trying to switch the TV on using Arduino. Following is my set of code
#include <IRremote.h>

IRrecv receiver(2);
IRsend sender;
decode_results results;

long repeatitions;
long count;
unsigned int durations[100];
void (*reset)(void) = 0;

void setup() {
  Serial.begin(9600);
  receiver.enableIRIn();
}

void loop() {
  if (Serial.available()) {
    repeatitions = Serial.parseInt();
    count = Serial.parseInt();
    for (int i =0; i < repeatitions; i++) {
      durations[i] = Serial.parseInt();
    }
    for (int i = 0; i < repeatitions; i++) {
      Serial.println("sending code");
      sender.sendRaw(durations, count, 40);
      delay(50);
    }
    reset();
  }
  if (receiver.decode(&results)) {
    Serial.println(results.value, HEX);
    Serial.print(results.rawlen - 1);
    for (int i =1; i <results.rawlen;i++) {
      unsigned int number = results.rawbuf[i] * USECPERTICK;
      Serial.print(",");
      Serial.print(number);
    }
    Serial.println("");
    receiver.resume();
  }
}

The code receiving part works fine. And it returned me following code:
A90
25,2400,600,1200,600,600,550,1200,600,600,600,1200,600,600,600,550,600,1200,600,600,600,600,550,650,600,600

But when I try to use the same code to switch the TV on after adding durations to the above returned code it doesn't work. I am entering following into the serial monitor
3,25,2400,600,1200,600,600,550,1200,600,600,600,1200,600,600,600,550,600,1200,600,600,600,600,550,650,600,600

I have attached a screenshot to show how I have installed the IR Transmitter LED.

I have two IR Transmitters. I have tried installing both in same manner 1 by 1. But unfortunately no success.
I am using IRRemote library by Shirriff https://github.com/z3t0/Arduino-IRremote

Where's your resistor?

This seems unlikely to work for many reasons.  Presumably you are following some guide but have gone somewhat astray, you need to include a link to that and the exact IR library you are using in the question.  In addition to the LED electrical issues (generally a transistor and series resistor are needed), pin 12 doesn't seem to be a usual output for IR sending on an ATmega328p - rather, it is usually pin 3 or 9.

I thought when using IR LED bulb the resistor wasn't required so I didn't include that in the circuit. Can you kindly share some circuit diagram that I should use in order to make the circuit work? Thanks

This would be in the instructions for whatever library you are using - I'd point out again that you have failed to identify which one you are using.

I have already mentioned the name of the library in the original question as you suggested. I am using IRRemote library by Shirriff https://github.com/z3t0/Arduino-IRremote

is the LED actually lighting up? use your smartphone camera to see IR light


text:
Send String to a function inside a class
I made a little class for handling menus. When creating a new instance, I pass a reference to the oled object made in main.cpp. Yet when I want to render a string using a variable, it throws an error. But I can pass a string directly to the render function with no problems. See comments in the code for what is working and what is not.

#include "Arduino.h"
#include "U8glib.h"
#pragma once

class Menu {
  U8GLIB_SSD1306_128X64& oled;

  public:
    Menu(U8GLIB_SSD1306_128X64& oled): oled(oled) {
      this->oled = oled;
    };
    void render() {
      this->oled.firstPage();
      do {
        String text = "test2";
        this->oled.setFont(u8g_font_unifont);
        this->oled.setPrintPos(0, 20);
        this->oled.drawStr(text); // not working
        this->oled.drawStr(text.c_str()); // not working
        this->oled.drawStr("works"); // works
      } while (this->oled.nextPage());
    }
  };

In the case of this->oled.drawStr(text); the error is:
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(String&)

In case of this->oled.drawStr(text.c_str()) the error is:
error: no matching function for call to 'U8GLIB_SSD1306_128X64::drawStr(const char*)

How I create the instance in main.cpp:
U8GLIB_SSD1306_128X64 oled(U8G_I2C_OPT_NONE);
Menu menu(oled);
menu.render();

I can find no mention of a drawStr function in the current U8glib library that takes only one parameter. What version are you using and where did you get it?

I udated to u8g2 lib, passed 3 parameters (int int c_str) and I'm still getting the same error

@MartinVelinský if you updated it, then edit the question and ADD the new code, otherwise it is impossible to properly answer

Try with the new version, U8g2lib.
With that version, you can write code like this:
String t1 = "Grow";
String t2 = "Room";
u8g2.firstPage();
do {
  u8g2.setFont(u8g2_font_logisoso24_tf);
  u8g2.drawStr(32, 24, t1.c_str());
  u8g2.drawStr(32, 60, t2.c_str());
} while(u8g2.nextPage());

even with a u8g2 lib, I'm still getting the same compile error

Post a complete updated sketch with u8g2lib to better resolve.

Forget the String class.  It wastes memory on a system that is already constrained by memory.  Define your strings as const char * and you won't have any problems.
const char* t1 = "Grow";
const char* t2 = "Room";
u8g2.firstPage();
do {
  u8g2.setFont(u8g2_font_logisoso24_tf);
  u8g2.drawStr(32, 24, t1);
  u8g2.drawStr(32, 60, t2);
} while(u8g2.nextPage());

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


text:
Ultrasonic HC-SR04 echo and trig pins
I am doing a watch with GPS tracker project. I am using an Ultrasonic HC-SR04 sensor. I don't know where to connect the Echo and trig pins with my Arduino. Please let me know how to connect it.

To any 2 free IO pins.
To quote sparkfuns datasheet:

(1) Using IO trigger for at least 10us high level s ignal,
  (2) The Module automatically sends eight 40 kHz and  detect whether there is a pulse signal back.
  (3) IF the signal back, through high level , time of high output IO duration is  the time from sending ultrasonic to returning.
  Test distance = (high level time×velocity of sound (340M/S) / 2,

In other words you send a short pulse to trigger pin and then wait for the echo pulse and measure how long it was high. Divide the number of microseconds it was high by 58 and you have the distance in centimetres ( use 148 for inches)

You can connect them to two GPIO pins. It does not matter much which ones (probably between 2 and 12 since these are not used by other functions like the builtin led or RX/TX).
In the following example pins 9 and 10 are used:
Example
Fragment related to the pins:

The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and the VCC pins of the module needs to be connected to the Ground and the 5 volts pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin on the Arduino Board.

Okay I will try sir . Another question that i want to ask is ,what is the red light indication in an arduino nano? and how to connect rx/dx from gps tracker with arduino nano ? please help me

I don't have a Nano. It's best to post it as a new question with a picture and a mark to the indicator you mean. Also the other question is best to ask as a separate question. I never worked with a GPS tracker.