text:
Arduino protecting analog input with internal voltage reference
Usually a common way to protect an analog input consists on reducing voltage and current in the following way:
Current limiting components, as Resistors or inductors and voltage limiting components as diodes, zener, tvs.
In this case for components availability I have used two resistors and a zener diode.
The circuits aims to accept a 0-10V input and read it with the internal reference voltage 1,1V.
The question is the following: Assuming I want to use a 2,2V zener diode as overvoltage protection and 1,1V internal voltage reference, can I consider it safe or the 2,2V of zener will be too much for the 1,1V reference?

simulate this circuit – Schematic created using CircuitLab
NOTES: I am using 2,2V zener diode because is the smallest size I can found.
I could use two normal diodes to reach 1,4V but maybe it will be too much for 1,1V reference and the result could be the same.
I could also add an external reference, but I would like to know if I can have problems with this configuration.

Yes, it is safe.  The reference voltage is only used as a comparison. The ADC is still powered by, and limited by, the chip's supply voltage (5V).
The AREF voltage has no bearing on what limits there are on voltages you can apply to a pin. All that will happen is that voltages above 1.1V will register as 1023. You can go right up to 5V safely.

As far as I know, no one uses a zener diode in a analog circuit that is used to measure a voltage. Well, at least no one who is serious and knows what he/she is doing.
The zener diode will start leaking at a lower voltage and it might introduce noise. I never use a zener diode in a analog input circuit that is used to measure something.
What is the maximum positive and negative voltage that you want to protect the Arduino against ?
Suppose using a 5V ATmega chip, with R1 = 100k, R2 = 10k, C1 = 10nF, with 1.1V as reference (and no extra ESD or clamping diodes and no zener diode). Then you are protected up to 160 V.
That is a constant voltage of 160 V that is allowed, as long as R1 can dissapate the heat.
That means without the zener and better choosen values of the resistors, it becomes more accurate and safer and more sturdy.
Calculation: A0 can be up to 5.5V. Then the internal diodes start to conduct, and it is allowed to push 1mA into the pin.
Current R2 = 5.5 / 10k.
Current into pin = 1mA.
Voltage over R1 = 100k * ((5.5/10k) + 1mA).
External signal = 5.5 + voltage over R1.
Suppose a leakage current for a 2.2V at 1V is 0.02mA. That seems a reasonable number from what I can find. That will influence your measurement by maybe 2 percent (I'm not sure, I didn't do the calculation). That would mean that of the 10-bit resolution you dropped to 6-bit resolution (I'm also not sure about this one).
To protect the analog input, instead of a 2.2V zener, a 5V zener would be more appropriate (that is: when going down the wrong path to use a zener). The 1N4733A has a leakage current of 10 µA at 1V, and that will still influence the analog signal and still cause a less accurate voltage measurement.

Nice to know that the leakage current can cause problems. For sure I can use a 5V zener diode, the 2,2V was for having something closer to 1,1V in the assumption that could cause a problem.
Zener diode was goot also for the reason that protects against reverse voltage. Finally I should use TVS or maybe two diodes (one from ground to analog line and the other from analog line to VCC?

@piertoni, the 5 V zener diode still leaks at 1V as I wrote, that still causes inaccuracy for the reading. Without a zener diode and with the right values for the resistors you are better protected !

@piertoni You are not going to use a zener diode, are you ? Why do it deliberately wrong, when it is easier to do it right ?

I think Zener will be sufficient for the following reasons:

Availability.
I only need to discriminate from 0-10V to 3 speed of a fancoil, so a minimum leakage will not be a problem neither the accuracy of readings.
DIP PCB.
When I will try to protect an ADC needing accuracy I will keep in mind your helpfull explanations. I will also keep it in mind for all the rest of my projects.

Without the zener diode (and with better values for the resistors) you are better protected.

Ok, I will choose different resistors/capacitor values and eliminate zener, thanks

It’s perfectly rational to use a zener to measure voltage. The leakage can be mitigated with a BC557 PNP + 2N7000 NFET, for example, so there is no current path unless it is first enabled on the MCU.

@Jot can you provide context as to how you are protected from 160V as you claim? Is this a property of the ATmega you use in your example? I'm not seeing how a circuit without a zener would protect "better" as well. How are you better protected?


text:
Dust sensor code with a few errors
I'm fairly new to this and I'm having trouble with a code for a dust sensor. Getting a couple of errors. I downloaded this code from GitHub.
Anyone have any idea how to fix any of these errors? Any help is appreciated.
Sorry if this formatted wrong, this is also my first post. Thanks for your time
// SDS011 dust sensor example
// -----------------------------
//
// By R. Zschiegner (rz@madavi.de).
// April 2016

#include "SDS011.h"
#include<SoftwareSerial.h>
SoftwareSerial myserial(0, 1);
SDS011(byte pin_rx, byte pin_tx)
float p10,p25;
int error;

SDS011 my_sds;

void setup() {
  my_sds.begin(0, 1);
  Serial.begin(9600);
  while (!Serial) {
    ;
  }
}

void loop() {
  error = my_sds.read(&p25,&p10);
  if (! error) {
    Serial.println("P2.5: "+String(p25));
    Serial.println("P10:  "+String(p10));
  }
delay(100);
}

here are the errors I'm getting
code:10: error: expected ')' before 'pin_rx'

 SDS011(byte pin_rx, byte pin_tx)

             ^

C:\Users\Nick\Desktop\code\code.ino: In function 'void loop()':

code:26: error: 'p25' was not declared in this scope

   error = my_sds.read(&p25,&p10);

                        ^

code:26: error: 'p10' was not declared in this scope

   error = my_sds.read(&p25,&p10);

                             ^

exit status 1
expected ')' before 'pin_rx'

You have to use the begin command. Instead of:
SDS011(byte pin_rx, byte pin_tx)

...

SDS011 my_sds;

Use
SDS011 my_sds;

(Thus remove the first line: SDS011(byte pin_rx, byte pin_tx)).
And in setup add:
my_sds.begin(0, 1);

This follows the library function of SDS011:
void begin(uint8_t pin_rx, uint8_t pin_tx);

Other errors: because you forgot the ; in
SDS011(byte pin_rx, byte pin_tx)

the next line:
float p10,p25;

is misinterpreted, and p10 and p25 are not known. Therefore errors are shown while trying to use p10 and p25.
These errors will go when changing the begin code as described earlier.

Your code should be like below; there are multiple syntax and semantic errors in the code you have posted;
Below is the edited and working code;
#include <SDS011.h>

float p10,p25;
int error;

SDS011 my_sds;

void setup() {
  my_sds.begin(0, 1);
  Serial.begin(9600);
  while (!Serial) {
    ;
  }
}

void loop() {
  error = my_sds.read(&p25,&p10);
  if (! error) {
    Serial.println("P2.5: "+String(p25));
    Serial.println("P10:  "+String(p10));
  }
  delay(100);
}

source: Stack Exchange

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

sort: votes


text:
Run Stepper with A4988 driver in highest resolution
I have a Bipolar Stepper Motor (12V, 350mA, 28oz-in NEMA-17) and would like to run it in the highest resolution (Sixteenth Step) with the A4988 Driver. According to multiple sources I read I need to "put 5V" to the MS 1,2,3 pins. What does this mean/How can I achieve this ?
Do I need to hook up the MS 1,2,3 to the digital pins of the Arduino and write Digital High. Or do I need to hook all of them to 5V together ? And should the code look like this ? Is this safe/good pratice ?
int MS1Pin = 8;                 // Set MS Pins
int MS2Pin = 9;
int MS3Pin = 10;

void setup()
{
  pinMode(MS1Pin, OUTPUT);      // sets the digital pin as output
  pinMode(MS2Pin, OUTPUT);      // sets the digital pin as output
  pinMode(MS3Pin, OUTPUT);      // sets the digital pin as output
}

void loop()
{
  digitalWrite(MS3Pin, HIGH);
  digitalWrite(MS2Pin, HIGH);
  digitalWrite(MS1Pin, HIGH);
<<MY CODE here>>

}

Sorry for these beginner questions, I just don't want to fry the Chip and this to work.
Thank you.

You can drive the MS pins from the Arduino if you want, but there is no need.  You can just hook them all up to 5V.
Have you seen this page, there seems to be load of details that you might find relevant.
https://www.pololu.com/product/1182

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


text:
redefining delay and delaymicros as personal function
Is it possible to redefine delay and delaymicros function with #define ?
I want to use timer2 interrupt instead of these.
Something like this:
#define delay(unisgned long ms) countMicros(uint16_t top, uint16_t storageVar)

setup(){}

loop(){
 delay();// function countMicros is called instead.
 }
void countMicros(uint16_t top, uint16_t storageVar){
//...}

Can you tell us why ? Have you heard about the XY-problem ? http://xyproblem.info/

@Jot Now I have !
I want to use timer interrupt for several time-sensitive calculations. One is to know when exactly to turn on TRIAC on 50 Hz AC system.
Second is time after turning it off.
The problem is with LiquidCrystal library which I have for LCD. It uses delay, so by initializing ISR with 1uS counter nothing works.

An ISR works also when a delay is busy. You should avoid Timer0, because the Arduino uses it. You can use Timer1 and Timer2 of an Atmega328p (Arduino Uno). If you need more timers, then use the Atmega32u4 (Arduino Leonardo / Micro). You are looking in the wrong direction for the wrong solution. I think this is indeed a XY-problem.

With timer2 set it does not work with liquidcrystal functions however, when the library with functions are commented out everything works fine. So I concluded that delay in LCD library is the cause.
The problem is following: red led flashes fast and LCD is frozen, when timer2 ISR is set.

The LiquidCrystal library does not use Timer2 and has nothing to do with it. Is your ram memory almost full ?

Is using Timer2 the real problem ? You have made a new question for that. That is okay. Let's continue there: https://arduino.stackexchange.com/questions/44889/lcd-library-and-timer2-ctc-interrupt-not-working-together

Not exactly like that. You will have to manage the different sets of
parameters, i.e. convert the incoming ms into the top and
storageVar that would be appropriate for calling countMicros().
Maybe something like this:
#define delay(ms) mydelay(ms)

void mydelay(unisgned long ms) {
    uint16_t top = some expression;
    uint16_t storageVar = another expression;
    countMicros(top, storageVar);
}

where both expressions are a function of ms.
If the expressions are really simple, you could even put the whole thing
inside a single macro, as in
#define delay(ms) countMicros(some expression, another expression)

Do parameters in original function have to match ones in a custom one, as you have shown in the beginning of your post ?
#define delay(ms) mydelay(ms)
I assume that in this case parameters passed in original function will get passed into custom function.  If that is so, what happens in case of your last example ?
#define delay(ms) countMicros(some expression, another expression)

@flowian: You should realize that the preprocessor only does textual substitution. If you #define delay(ms) countMicros((ms)*2, (ms)-4) and then you call delay(7), then the compiler will just see countMicros((7)*2, (7)-4).


text:
Get a LED to fade out
I want to light an LED in a sketch and then have it fade out.
I tried to use analogWrite and have it decrease from a value of 255 to 0 using a for() loop, but I can't seem to get it to work.
Using digitalWrite I can turn it on and off but cant get it to fade out.
Can anyone help please.
const int ledPin1 = 2;
const int ledPin2 = 3;
const int ledPin3 = 9;
int j = 0;

void setup() {
    pinMode(ledPin1, OUTPUT);
    pinMode(ledPin2, OUTPUT);
    pinMode(ledPin3, OUTPUT);
}

void loop() {
    j = 255;
    delay(1000);
    if (j >= 5);
    {
        analogWrite(ledPin3,j);
        delay(10);
        j = j - 5;
    }
    delay(1000);
}

Please show what code you have, along with your wiring. There is an example in the IDE that fades an LED. Did you get that to work?

Yes I did get that sketch to work. I am using pin 9

So please show us your code and better define "can't seem to get it to work".

What sketch did you get to work?

Yes my complaint is a bit vague. The LED comes on and stays on. It is in my code. I am missing what I doing wrong. Some sort of mental block. Wiring is just a LED and resistor from pin 9 to gnd.

Not all output pins are able to perform PWM ("AnalogWrite").

On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 - 13 and 44 - 46. Older Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11.

https://www.arduino.cc/en/Reference/AnalogWrite
Note that the PWM-enabled ports are marked by a "~" on the board.
If you try analogWrite, e.g., on port 4, you'll get your observed switch behaviour.

I am using pin 9

Well - if that's not the problem, I'm totally with @Majenko. Post code, wiring and tell us what boards you are using.

const int ledPin1 = 2;
const int ledPin2 = 3;
const int ledPin3 = 9;
int j = 0;
void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void loop() {
j = 255;
delay(1000);
if (j >= 5);{ analogWrite(ledPin3,j);
delay(10);
j = j - 5;
}
delay(1000);
}

New at this so my posts may be a mess. I am using an UNO.

Problems noted in comments:
void loop() {
    j = 255;             // Resets j EVERYTIME
    delay(1000);
    if (j >= 5);         // Semi-colon here makes this a null statement
    {
        analogWrite(ledPin3,j);  // j is always 255 (see line 1)
        delay(10);
        j = j - 5;       // No effect as j is reset in line 1
    }
    delay(1000);
}

Here's a simple fix:
int j = 255;   // Start at 255

void loop() {
    analogWrite(ledPin3, j);   // Set the brightness
    delay(10);
    j -= 5;
    if (j <= 0) j = 255;       // Reset j?
}

of course. Thank you very much. Works like a charm. I must be getting old.

How about we double what we are paying you.


text:
Arduino core structure and timer usage
I needed to use TC1 for input capture, but also analogWrite() and an approximate 1 ms interrupt to poll the user interface (encoder, button).
The Arduino Nano's ATmega328p (datasheet, beware: a lot of bit symbol typos) has three timers:

TC0
TC1
TC2

It is not easy to find information on the "Arduino core" structure and it's use of peripherals. The Arduino Reference does not seem to refer to any information. Nor does Arduino Hacking.
Some info can be found on
https://arduino-info.wikispaces.com/Timers-Arduino
but I am not sure it's up to date. For instance, I find disabling TC2 also disables the analogWrite() PWM.
Trying to use TC0 results in an error, as TIMER0_OVF_vect is already being used ("multiple definition of `__vector_16'").
How can I use the timers (and their interrupts) that are already used for the core?

The overflow vector might be used, but both compare match vectors A and B are free. You can schedule comp interrupt anytime in period so it's not fired at the same time as OVF interrupt.

@KIIV Yes, but the CMs might be used by analogWrite on their respective output pin (the answers explain why).

Luckily it just changes "when" the interrupt happens. The period will be different once(or twice) after the change. But for polling buttons and encoder it doesn't matter.

Here is a summary of all this. On an ATmega328P (Arduino Uno, Nano,
etc.), the Arduino core library uses the timers as follows:

Timer 0

timing and delay functions, using the TIMER0_OVF interrupt
“fast” PWM at 980 Hz on pins 5 and 6 (PD5 and PD6)

Timer 1

“phase-correct” PWM at 490 Hz on pins 9 and 10 (PB1 and PB2)

Timer 2

“phase-correct” PWM at 490 Hz on pins 3 and 11 (PD3 and PB3)

All three timers have their prescalers set to 64. TIMER0_OVF is the
only timer interrupt enabled by default.
Note that libraries can use the timers for their own purposes. Servo
for instance uses Timer 1 for doing interrupt-based PWM.

"Reimplementing" the interrupt handlers to free Timer/Counter resources would require changes to the Arduino core firmware.
But there may be a workaround:
The source code shows how init() and loop() are used:
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/main.cpp
and the basic timer initialization is here:
https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/wiring.c#L45
and init() is there as well, which also configures all the other timers for phase-correct PWM...
analogWrite() is in https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/wiring_analog.c
I thought that at just 490/980 Hz it might use software-PWM, but in fact it selects the corresponding timer output compare pin (that also means the CPU can be powered down while the PWM still is being generated).
It does that via a runtime lookup in the board header's digital_pin_to_timer_PGM, e.g. https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/variants/standard/pins_arduino.h
which seems to be a (conditional) list of all pins.
So there is a limited, indirect choice on which timer is being used for PWM:
PD5 and PD6 are served by TC0, so using one of these as analogWrite() output pin frees TC2 for my purposes (~1 kHz polling).
Works for me!


text:
String to unsigned long conversion
I'm trying to use strtoul() to convert an Arduino String to an unsigned long (like the return of millis();) using the following code snippet:
unsigned long foo (String time)
{
  unsigned long mili;
  char Tim[9]="";
  uint16_t timsize = time.length()+1;
  char TIM[timsize];
  time.toCharArray(TIM,timsize);
  mili=strtoul(TIM,timsize,10);
  return mili;
}

The code seems to work. However, I'm getting the following warning:

invalid conversion from 'uint16_t {aka unsigned int}' to 'char**' [-fpermissive] mili=strtoul(TIM,timsize,10);

My question is twofold:

Is there a better way to convert a String to unsigned long without first converting to a C string?
If not, how can I eliminate this error?

unsigned long strtoul(const char *str, char **str_end, int base ); The 2nd parameter is char **. Can be nullptr.

I believe that char TIM[timsize] is bad code.  The size of arrays need to be know at compile time and since the value of time is not constant its length can't be known.  I think you'd need to do a new, if you were still doing it which you aren't because you are using .c_str()

It may be poor code. I do know that it works though (however for a 2D or greater array, only the last value can be a var)

@CodeGorilla char TIM[timsize] usually works on newer compilers:  Declaring an array with a non-constant size variable

VLAs are not part of the C++ standard. They work here because of a compiler extension.

Arduino String class provides method c_str(). So you don't have to convert it to C string, as it's already stored as a C string internally.
And as mentioned in comments, the second parameter of strtoul is:

endptr
      Reference to an object of type char*, whose value is set by the function to the next character in str after the numerical value.
      This parameter can also be a null pointer, in which case it is not used.

Basically you can reduce whole foo to the:  return strtoul(time.c_str(), NULL, 10);

Can you tell me more about how to access the c_str() method of a String? just using sec=strtoul(tim,endptr,10); did not work.

@ATE-ENGE Added to the answer.

Also be aware that strtol() can return 0 or ULONG_MAX if there is a problem, so the calling function should check for these because if you do a delay(ULONG_MAX); you'll think it has locked up :)

@CodeGorilla That would be a problem! Hypothetically, is there a good way to differentiate if a problem occurs? You know, in case a user actually does want to halt the program for 50 days :)

@ATE-ENGE You can use that endptr to check if whole string was parsed. However it returns 0 if there is nothing to parse and ULONG_MAX if the value is out of range so it must be even bigger than 32bit number.

0xFFFFFFFF in decimal is 10 digits, and you were looking at 9 for the size of Tim[] so you could have an issue.  You could look at endptr or you could enforce sensible limits, i.e. if (t < 100) t = 100; if (t>100000) t = 100000;


text:
Arduino Uno simple LED example with pointers
I am new to Arduino and I have recently started off by trying to turn on an LED connected to pin 13 on my Arduino Uno using pointers.
I opted to do this with pointers because this would give me a better understanding on what really goes behind when I use predefined Arduino functions.
My simple code looks like this,
uint8_t *data = (uint8_t *) 0x05; //PortB data register ptr (Since pin 13 is PB6)
uint8_t *dir = (uint8_t *) 0x04;  //PortB dir register ptr (Since pin 13 is PB6)

void setup() {
    *dir = 0x40;  //PB6 direction set to O/P
    *data = 0x40; //PB6 data set to 1 to turn on the LED
}

void loop() {
  *data = 0x40;
}

I tried the same program using   pinMode(13, OUTPUT) and digitalWrite(13, LOW) functions and it works fine. But I do not understand what could be wrong with my pointers. If you find anything wrong, kindly let me know.

"I opted to do this with pointers because this would give me a better understanding on what really goes behind when I use predefined Arduino functions." No it won't.

I would like to really access the registers on my own rather than through functions. I know it would be easier with functions but I want to do this to understand register access better. Moreover behind a function like pinMode, I do beleive that all it does is write a bit onto a register which I would like to do on my own for starters.

But using pointers won't help with that.

You made two small mistakes:

The addresses of the I/O registers are 0x24 for DDRB and 0x25
for PORTB. The numbers you used are I/O port numbers, but since
pointers are supposed to point to memory, you have to use the
memory-mapped addresses instead.
Pin 13 is PB5, not PB6.

With these two mistakes fixed, your code works as expected. There are
still two issues however:

Under some circumstances, the compiler can optimize away some writes
to these registers. You have to qualify the pointers as “pointer to
volatile data” in order to avoid this. Even if your simple example
does not show this problem, it is always safer to use the qualifier.
The compiler generates inefficient code. Not as inefficient as
digitalWrite(), but still... It knows how to optimize, but it is
prevented to do so by the fact that your pointers are modifiable. You
should qualify them as const if you want to benefit from compiler
optimizations.

With those fixes, your pointer definitions would look like:
volatile uint8_t * const data = (uint8_t *) 0x25;
volatile uint8_t * const dir  = (uint8_t *) 0x24;

and access to them gets compiled into efficient in ans out assembly
instructions.
That being said, if you want to do direct port access, I would recommend
doing it the avr-libc way:
void setup() {
    DDRB  = _BV(PB5);
    PORTB = _BV(PB5);
}

void loop() {
    PORTB = _BV(PB5);
}

The way the AVR-libc defines the I/O registers is roughly equivalent to
#define PORTB (* (volatile uint8_t *) 0x25)

Thank you so much ! I was a bit confused with the address of the register. But once I used a main function and the proper register address it all started working without library variables like PORTB ! :) And also thank you for the volatile and constant suggestions.

Port definitions in AVR-Libc are done via black magic. Don't attempt to replicate them as a beginner. That being said...
"How do I pass an IO port as a parameter to a function?"
volatile uint8_t *data = &PORTB;
volatile uint8_t *dir = &DDRB;

Thank you so much ! After I checked your 'black magic' link it was a bit clear. I implemented what you had suggested and used a main function. There on it worked fine.


text:
How to have code/sketch that's easily toggleable to work on different nodes
i have a question about best practice to achieve what i want to do. I would like to have a sketch setup, and then to be able to deploy to different devices of the same type, but each device/node will have a few different parameters, like ip address and mqtt topic etc,
What would be the quickest way to be able to upload new changes to all of my nodes without having to track my changes and update each seperate sketch for each node?
I was thinking about using some IFDEF statements if i can figure out how to? would that be the best way to go or is there something better?
Thx in advance

Why not just store the parameters in EEPROM?

I don't really know how to do that or how it would work in solving my problem.. it's not something i've done before.. can you point me to further info?

You can put the per-node parameters in a external EEPROM and load them during setup(). For example the IP address is the first 16 bytes of the eeprom (IPv6), the next bytes would the the topic, etc..
That way every node has exactly the same sketch and the customization is in the eeprom that you could put in a socket and possibly have a separate programmer for them.
EEPROMs with I2C interface are easy enough to get and can store 64kB. Which should be more than enough for most things.


text:
Max Sample Rate of an Arduino Uno
I am using the FFT library from Open Music Labs and I am trying to analyze frequencies up to 40 kHz. Now I don't understand fully but know that my sample rate has to be at least twice as much, but my question is with the example code fft_adc_serial, how can I adjust the sample frequency to 80kHz? Is it even possible to sample at these high frequencies.

112 us, 8.9 k samples per second max on an arduino uno. And that is if you do extreme programming.

Trying to get 80kHz from an Uno will reduce the samples to unusable garbage.

From the datasheet: "Up to 76.9kSPS (Up to 15kSPS at Maximum Resolution)"

Nick Gammon has some ADC tests that show the accuracy as a function of the prescaler setting. From his data, prescaler = 16 (which gives a sampling rate of 76.9 kS/s) seems still almost accurate, whereas prescaler = 8 (153.8 kS/s) seems to leave only 3 – 5 bits of effective resolution.


text:
Using an ESP8266 with an Arduino Uno - can't get AT command to work
I am trying to connect an ESP8266 to my Arduino Uno.

Connections:
RX -> RX
TX -> TX
CH_PD -> 3.3v (Arduino 5v using voltage regulator)
VCC -> 3.3v
GND -> GND

I am running the RX and TX pins through a logic converter, dropping those down to 3.3v. Also, I have read that normally RX goes to TX and vice versa, but since I am trying to communicate with the chip using my computer (not the arduino) it needs to be the other way around.
I can't get the AT command to work on any baud rate. I was paying attention mostly to 9600, 115200, and 57600...I checked some others but it seemed like from reading these are the most common.
I used a multimeter to check the voltage of the RX/TX pins and after the logic converter my meter says it is outputting 3.2 volts (is this two low for serial to work?) Is their some +/- in the reading and it is actually 3.3v?

How do I go about troubleshooting this? Is it possible the AT firmware isn't loaded onto my chip? (I purchased it new, and recently).
UPDATE:
I'm reading about my logic level converter here, and I'm wondering if I have it setup right. My converter is labeled with HV -> HV4 and LV -> LV4 (you can see in the below picture). I'm wondering about where it says:
The middle section of the board is where the reference supply for your high and low voltages should go. Supplying voltage to all four of these pins is required. If you’re converting 3.3V to 5V (and vice-versa), for example, you’d run 5V into the “HV” side, and 3.3V into the “LV” input. Make sure each is grounded too!
So I need to provide power ("reference" power)? Some diagrams I have seen do this but I wasn't sure why:

UPDATE
I provided the reference supply and it up'd my voltage reading from 3.2 to 3.27 (I can assume it has enough voltage now?). I still can't connect with AT - on one of the baud rates I was getting stuff like !? as output.
UPDATE
I changed what pins were being used by RX/TX on my logic level converter, and now when I type AT on baud 115200, it outputs AT. Below is what it looks like for this configuration:

Do the soldered connections look good on the logic level converter?

Try loading the ESP8266-01/12F firmware once more from the Espressif and see if it's working correctly. Hope you know how to change to firmware/programing mode?
(GPIO 0->ground)->rest->burn program->GPIO0->high->power reset)

After writing such a long question, hopefully this is useful to someone else: After changing the logic converter channels (not sure why the first two weren't working) I was receiving AT as output - the only thing I needed to do after that was change No line ending to Both NL & CR and I am receiving AT OK now.

Please, accept your own answer to close this question.


text:
Break loop/restart program at any time
maybe my problem is just that my thinking is wrong. I hope you can help me.
First of all I will point out what I think in general, then I show you some code to work with.
In general my problem is to wrap me head around a push-button (or any other input) that stops (or better restarts) a running program at any time.
If i use the digitalRead(pin-whatsoever)-statement don't I have to tackle the exact mili/microsecond my MC is working on that specific line of code?
I don't want to use an interrupt either, i want to restart the program, not to interrupt it.
My project is some kind of turn-indicators for a bicycle.
The lights shall "run" from right to left on left-turns and vice versa.
But i want to stop the sequence at any point (or at least after one loop-run) if I push the corresponding button again.
After that the MC shall wait for another button-push to run the indicator either till the for-loop is finished or i press the same button earlier.
Another (general) question: Is there a way to get rid of delay-statements and achieve similar results?
Thank You so far.
   // Var-Setup
  const int mtime = 120; // Time between lights lighting up
  const int ftime = 100; // Time between lights turning out

void setup() {
  // put your setup code here, to run once:
  // Pin-Setup
    // LED-Pins
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);

  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

    // Button-Pins
  pinMode(12, INPUT);
  pinMode(13, INPUT);

}

void right(){
  for(int i=0; i<5; i++){
      // Indicator right with running light (like a "half-knight-rider" ;) )
      // Rise
      digitalWrite(11, HIGH);
      delay(mtime);
      digitalWrite(10, HIGH);
      delay(mtime);
      digitalWrite(9, HIGH);
      delay(mtime);
      digitalWrite(8, HIGH);
      delay(mtime);
      digitalWrite(7, HIGH);
      delay(mtime);
      delay(mtime);

      // Fade
      digitalWrite(11, LOW);
      delay(ftime);
      digitalWrite(10, LOW);
      delay(ftime);
      digitalWrite(9, LOW);
      delay(ftime);
      digitalWrite(8, LOW);
      delay(ftime);
      digitalWrite(7, LOW);
      delay(250);
    }
}

void left (){
  for(int i=0; i<5; i++){
    // Indicator left with running light
    // Rise
    digitalWrite(2, HIGH);
    delay(mtime);
    digitalWrite(3, HIGH);
    delay(mtime);
    digitalWrite(4, HIGH);
    delay(mtime);
    digitalWrite(5, HIGH);
    delay(mtime);
    digitalWrite(6, HIGH);
    delay(mtime);
    delay(mtime);

    // Fade
    digitalWrite(2, LOW);
    delay(ftime);
    digitalWrite(3, LOW);
    delay(ftime);
    digitalWrite(4, LOW);
    delay(ftime);
    digitalWrite(5, LOW);
    delay(ftime);
    digitalWrite(6, LOW);
    delay(250);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorL = digitalRead(12);
  int sensorR = digitalRead(13);
  if(sensorL == HIGH){
    left();
  }else if(sensorR == HIGH){
    right();
  }
}

replace each delay chain with a switch statement where each delay is replaced by saving the current millis counter, a increment of the state, a case label for the new state and a if(millis()-timestamp  < timeout) return;
switch(state){
case 0;
      // Indicator right with running light (like a "half-knight-rider" ;) )
      // Rise
      digitalWrite(11, HIGH);
  timestamp = millis();
  state++;
case 1:
   if(millis()-timestamp  < mtime) return;

      digitalWrite(10, HIGH);
  timestamp = millis();
  state++;
case 2:
      digitalWrite(9, HIGH);
//etc.

The for loop around the entire thing will need to be replaced. Make i global and incrementing it in the last state and resetting it as needed. When i has been incremented to beyond 5 you always return.
This means that the left and right functions only do a few things: set the led, check a timestamp against the current time, and increment a state before returning.
This means that they will take very little time to execute and that you can check the button in the main loop() body and if pressed initiate the statemachine or end it (and putting out the LED when needed).


text:
Two data outputs to be displayed on one 16x1 lcd display
Before pursuing this very far, I would like to know if I can get two different data outputs (one on the left 8 and the other data on the right 8).  And if so, are there any requirements on the display or any other thing that might be needed.  I'm thinking that as far as the proper Arduino platform being the Mega 2560.  My idea is to put together an FSX navigation radio for my flight simulator.

You can do anything you can write code for.

lcd.setCursor(0,0); lcd.print("val1"); lcd.setCursor(8, 0); lcd.print("val2");. Try reading the manual and examples.

https://www.arduino.cc/en/Reference/LiquidCrystalSetCursor

don't forget extra spaces on the right when drawing multiple numeric data: lcd.print(String(v1,2) + "      ") which allows negatives and more digits without leaving the previous draw's numbers behind.

You can use
lcd.setCursor(x, y);

To set the cursor.
Than you can output text with
lcd.print("Text");

Make sure you add spaces in case there is already text written to overwrite older text.
You can also use
lcd.clear();

to clear the display, but this might result in flickering if you do it too often.
Another possibility is to create a 16 character string
char lcdText[16];

and write characters in this string and set it at once with:
lcd.setCursor(0, 0);
lcd.print(lcdText);


text:
USB or external power
I have an arduino mega that i am using as a clock. I would like it to detect if it is connected to a USB or external power supply (e.g. a battery). I then want to set a variable to different values depending on the result, so i can display it on an OLED.

Use a simple transistor where the Vin (external power) is connected to the base, which switches the transistor. Than connect the collector to +5V, and the emitter to a GPIO input pin and read the status with the Arduino. If it receives a HIGH you know external power (via Vin) is used.
See the useful 'good' answer as comment of Majenko below ... I will leave the answer above as is, to keep his remarks clear.

Slightly more involved than that - you want to have the transistor (NPN or N-channel FET) between the GPIO and Ground, not +5V, and a pullup resistor (or enable the internal pullup resistor of the GPIO pin) and look to see if it's reading LOW for "External Power Applied". Also a resistor in the base of an NPN is needed.


text:
Blink a LED between servo pulses
Apparently using delay() commands locks the Arduino during the delay period and there are better ways to control a servo that free the Arduino to do other things at the same time as running the servo.
At this point my code consists of a servo going forwards and backwards like this:
void setup()
{
  pinMode(1, OUTPUT); // makes pin 1 an output
}
void loop()
{
for(int i = 0; i<31; ++i) { //keeps in this position for about 400ms
  digitalWrite(1, HIGH); //turns the servo pin to HIGH
  delayMicroseconds(1000); //sets the servo to move clockwise
  digitalWrite(1, LOW); //turns the servo pin to LOW
  delay(19);
}

for(int i = 0; i<31; ++i) { // keeps in this position for about 400ms
  digitalWrite(1, HIGH); // turns the servo pin to HIGH
  delayMicroseconds(2000); //sets the servo to move anti-clockwise
  digitalWrite(1, LOW); //turns the servo pin to LOW
  delay(19);
}}

Where and how will I add some code that will allow the arduino to carry out another task for example blinking an led light during the approximately 20ms between servo pulses.
NOTE: The arduino is using the ATtiny 85 Processor.

Before and after the delay of 19 ms?
In setup add:
pinMode(2, OUTPUT); // LED pin output

Than changen in both cases:
  delay(19);

into
  digitalWrite(2, HIGH); // LED on
  delay(19);
  digitalWrite(2, LOW); // LED off

When you say digitalWrite(2, HIGH); // LED on, you use pin 2 but when you say digitalWrite(1, LOW); // LED off, you use pin one. Is this a typo or what?

@Utsav ... it was a type and I updated it, thanks for the notification

Short answer: don't use delay() if you want to do anything other than waiting, so rewrite your code without that call.
Long answer follows.
Instead of asking the Arduino to go to sleep (1) until a certain amount of time has passed, you should write your code to run continuously and do certain things whenever enough time has passed since the last time they have been executed.
If the previous statement makes sense to you, then the following piece of code translates to C language what I just stated in English:
unsigned long time; // stores the time when the last motor movement happened, in ms
boolean clockwise; // stores the wanted direction: true CW, false CCW
unsigned byte counter; // stores how many time the wanted movement has occurred so far

unsigned long ledTimer; // stores the last time we changed the LED state
boolean ledIsOn; // stores the current LED state
void setup() {
  pinMode(1, OUTPUT); // makes pin 1 an output
  pinMode(13, OUTPUT); // makes pin 13 (onboard LED pin) an output
}

void loop() {
  if (time - millis() >= 19) { // has enough time passed since the last time we executed a step motor movement?
    time = millis(); // reset the timer for next pass
    if (counter < 31) { // have we moved in the same direction enough?
      if (clockwise) {
        moveCW();
      } else {
        moveCCW();
      }
      counter++;
    } else { // we moved enough times in the same direction: reset the counter and switch direction
      counter = 0;
      clockwise = !clockwise;
    }
  }
  // do anything else, but don't use delay()!!!
  // the following does the same as above, but on the LED
  // blinking at 1Hz (500 ms on, 500ms off)
  if (millis() - ledTimer >= 500) {
    if (ledIsOn) {
      digitalWrite(13, LOW);
    } else {
      digitalWrite(13, HIGH);
    }
    ledIsOn = !ledIsOn;
    ledTimer = millis();
  }

  // need to do something more? go ahead and try
  // but remember not to use delay() and not to waste too much time
  // in complex calcs or the loop will take too long to wrap
}

void moveCW() {
  digitalWrite(1, HIGH); //turns the servo pin to HIGH
  delayMicroseconds(1000); //sets the servo to move clockwise
  digitalWrite(1, LOW); //turns the servo pin to LOW
}

void moveCCW() {
  digitalWrite(1, HIGH); // turns the servo pin to HIGH
  delayMicroseconds(2000); //sets the servo to move anti-clockwise
  digitalWrite(1, LOW); //turns the servo pin to LOW
}

There is a beautiful library called elapsedMillis (reference) which can reduce a bit the boilerplate code regarding subtracting millis() and all that stuff, but the code above is practically the same and, probably, more straightforward to begin with.

(1) The term sleep it's incorrect as it implies some sort of power reduction. Instead sleep() is just wasting time at full power.

I'm not sure exactly what you mean with "between servo pulses" but I am assuming it means you want to blink the led while the servo is turning.
Use the Arduino Timer library: https://playground.arduino.cc/Code/Timer
Add this at top of the sketch:
#include "Timer.h"

Timer t;
#define BLINK_TIME 20

in setup, add:
t.oscillate(LED_PIN, BLINK_TIME, HIGH);

inside the two for-loops, add:
t.update();

This will make the led on LED_PIN turn on and off every 20 milliseconds.


text:
Having a problem where the previous letter flashes after a space
im currently working on a stranger things letter board with an arduino and ws2811 leds and im having an issue where ever there is a space, the previous letter will be displayed. Ive tried going in and finding where it makes this duplicate, but i am rather inexperienced. Heres my code:
#include <FastLED.h>

#include <HashMap.h>

#define DATA_PIN 6 //this is the data pin connected to the LED strip. If using WS2801 you also need a clock pin

#define NUM_LEDS 50 //change this for the number of LEDs in the strip

#define COLOR_ORDER RGB

CRGB leds[NUM_LEDS];

CRGB colors[5];

int myleds[25];

int last_letter = 0;

CRGB white = CRGB(255, 255, 255);

CRGB red = CRGB (255, 0, 0);

CRGB green = CRGB (0, 255, 0);

CRGB blue = CRGB(0, 0, 255);

CRGB off = CRGB(0, 0, 0);

const byte HASH_SIZE = 28;

HashType<char, int> hashRawArray[HASH_SIZE];

HashMap<char, int> charToLed = HashMap<char, int>( hashRawArray , HASH_SIZE );

void setup() {

  FastLED.addLeds<WS2811, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); //setting up the FastLED

  randomSeed(analogRead(0)); //seeding my random numbers to make it more random.

  myleds[0] = 47;//A

  charToLed[0]('a', 47);

  myleds[1] = 45;//B

  charToLed[1]('b', 45);

  myleds[2] = 43;//C

  charToLed[2]('c', 43);

  myleds[3] = 42;//D

  charToLed[3]('d', 42);

  myleds[4] = 40;//E

  charToLed[4]('e', 40);

  myleds[5] = 38;//F

  charToLed[5]('f', 38);

  myleds[6] = 37;//G

  charToLed[6]('g', 37);

  myleds[7] = 34;//H

  charToLed[7]('h', 34);

  myleds[8] = 32;//I

  charToLed[8]('i', 32);

  myleds[9] = 16;//J

  charToLed[9]('j', 16);

  myleds[10] = 18;//K

  charToLed[10]('k', 18);

  myleds[11] = 20;//L

  charToLed[11]('l', 20);

  myleds[12] = 22;//M

  charToLed[12]('m', 22);

  myleds[13] = 24;//N

  charToLed[13]('n', 24);

  myleds[14] = 26;//O

  charToLed[14]('o', 26);

  myleds[15] = 28;//P

  charToLed[15]('p', 28);

  myleds[16] = 29;//Q

  charToLed[16]('q', 29);

  myleds[17] = 31;//R

  charToLed[17]('r', 31);

  myleds[18] = 15;//S

  charToLed[18]('s', 15);

  myleds[19] = 13;//T

  charToLed[19]('t', 13);

  myleds[20] = 11;//U

  charToLed[20]('u', 11);

  myleds[21] = 9;//V

  charToLed[21]('v', 9);

  myleds[22] = 7;//W

  charToLed[22]('w', 7);

  myleds[23] = 4;//X

  charToLed[23]('x', 4);

  myleds[24] = 2;//Y

  charToLed[24]('y', 2);

  myleds[25] = 0;//Z

  charToLed[25]('z', 0);

  colors[0] = white;

  colors[1] = red;

  colors[2] = green;

  colors[3] = blue;

  colors[4] = off;

  reset();

  abcs();

}

void loop() {

  type("My world would be upsidedown if i went to homecoming without you");
  delay(3000);
  type("andificant");
  delay(100);
  jog();

}

void beforejog() {
  FastLED.clear();
  leds[0] = CRGB (0, 255, 255); //aqua
  leds[10] = CRGB (0, 255, 255); //aqua
  leds[20] = CRGB (0, 255, 255); //aqua
  leds[30] = CRGB (0, 255, 255); //aqua
  leds[40] = CRGB (0, 255, 255); //aqua
  leds[1] = CRGB (153, 50, 204); //dark orchid
  leds[11] = CRGB (153, 50, 204); //dark orchid
  leds[21] = CRGB (153, 50, 204); //dark orchid
  leds[31] = CRGB (153, 50, 204); //dark orchid
  leds[41] = CRGB (153, 50, 204); //dark orchid
  leds[2] = CRGB (255, 255, 0); //yellow
  leds[12] = CRGB (255, 255, 0); //yellow
  leds[22] = CRGB (255, 255, 0); //yellow
  leds[32] = CRGB (255, 255, 0); //yellow
  leds[42] = CRGB (255, 255, 0); //yellow
  leds[3] = CRGB (0, 255, 127); //spring green
  leds[13] = CRGB (0, 255, 127); //spring green
  leds[23] = CRGB (0, 255, 127); //spring green
  leds[33] = CRGB (0, 255, 127); //spring green
  leds[43] = CRGB (0, 255, 127); //spring green
  leds[4] = CRGB (255, 165, 0); //orange
  leds[14] = CRGB (255, 165, 0); //orange
  leds[24] = CRGB (255, 165, 0); //orange
  leds[34] = CRGB (255, 165, 0); //orange
  leds[44] = CRGB (255, 165, 0); //orange
  leds[5] = CRGB (65, 105, 255); //royal blue
  leds[15] = CRGB (65, 105, 255); //royal blue
  leds[25] = CRGB (65, 105, 255); //royal blue
  leds[35] = CRGB (65, 105, 255); //royal blue
  leds[45] = CRGB (65, 105, 255); //royal blue
  leds[6] = CRGB (76, 0, 153); //dark purple
  leds[16] = CRGB (76, 0, 153); //dark purple
  leds[26] = CRGB (76, 0, 153); //dark purple
  leds[36] = CRGB (76, 0, 153); //dark purple
  leds[46] = CRGB (76, 0, 153); //dark purple
  leds[7] = CRGB (255, 105, 180); //hot pink
  leds[17] = CRGB (255, 105, 180); //hot pink
  leds[27] = CRGB (255, 105, 180); //hot pink
  leds[37] = CRGB (255, 105, 180); //hot pink
  leds[47] = CRGB (255, 105, 180); //hot pink
  leds[8] = CRGB (0, 128, 0); //dark green
  leds[18] = CRGB (0, 128, 0); //dark green
  leds[28] = CRGB (0, 128, 0); //dark green
  leds[38] = CRGB (0, 128, 0); //dark green
  leds[48] = CRGB (0, 128, 0); //dark green
  leds[9] = CRGB (255, 0, 0); //red
  leds[19] = CRGB (255, 0, 0); //red
  leds[29] = CRGB (255, 0, 0); //red
  leds[39] = CRGB (255, 0, 0); //red
  leds[49] = CRGB (255, 0, 0); //red
  FastLED.show();
  delay(50);
  FastLED.clear();
}

void jog() {
  beforejog();
  delay(100);
  BLACKOUT();
  beforejog();
  delay(100);
  BLACKOUT();
  beforejog();
  delay(100);
  BLACKOUT();
  beforejog();
  delay(100);
  BLACKOUT();
  beforejog();
  delay(100);
  BLACKOUT();
  beforejog();
  delay(100);
  BLACKOUT();
  beforejog();
  delay(100);
  BLACKOUT();
  beforejog();
  delay(100);
  BLACKOUT();
  leds[31] = CRGB (255, 0, 0);
  FastLED.show();
  delay(2000);
  FastLED.clear();
  leds[11] = CRGB (255, 0, 0);
  FastLED.show();
  delay(2000);
  FastLED.clear();
  leds[24] = CRGB (255, 0, 0);
  FastLED.show();
  delay(2000);
  FastLED.clear();
}

void abcs() {

  for (int i = 0; i < 25; i++) {

    int t = myleds[i];

    leds[t] = white;

    FastLED.show();

    delay(250);

  }

  delay(10);

}

CRGB randomColor() {

  int t = random(4);

  return colors[t];

}

void reset() {

  for (int x = 0; x < NUM_LEDS; x++) {

    leds[x] = off;

  }

  FastLED.show();

  last_letter = 0;

}

void displayLetter(char letter) {

  if (isWhitespace(letter)) {

    last_letter = 0;

    delay(2000);

  }

  int lednum = charToLed.getValueOf(letter);

  if (lednum >= 0 && lednum <= 50) {

    if (last_letter == lednum) {

      delay(2000);
    }

    leds[lednum] = white;

    FastLED.show();

    last_letter = lednum;

    delay(2000);

    leds[lednum] = off;

    FastLED.show();

  }

}

void type(String message) {

  reset();

  message.toLowerCase();

  for (int i = 0; i < message.length(); i++) {

    displayLetter(message[i]);

  }

  reset();

}
void BLACKOUT() {
  int r = 0;
  int b = 0;
  int g = 0;

  for (int x = 0; x < NUM_LEDS; x++) {
    leds[x] = CRGB(r, g, b);
  }

  FastLED.show();
  delay(100);

}

Any help is appreciated. thanks.

What does lednum equal when letter is a whitespace character?
`int lednum = charToLed.getValueOf(letter);`

This will not fix your problem!
You said you were inexperienced, so I have taken you code and with no knowledge of what it does (that mean I may have made mistakes) I have refactored it slightly.
#include <FastLED.h>

#define DATA_PIN (6) //this is the data pin connected to the LED strip. If using WS2801 you also need a clock pin
#define NUM_LEDS (50) //change this for the number of LEDs in the strip
#define COLOR_ORDER RGB
#define HASH_SIZE (28)

CRGB Leds[NUM_LEDS];

int last_letter = 0;

enum ColourNames {White, Red, Green, Blue, Off};
const CRGB Colours[] = { CRGB(255, 255, 255), CRGB(255, 0, 0), CRGB(0, 255, 0), CRGB(0, 0, 255), CRGB(0, 0, 0) };

struct LED
{
    int myled;
    int led;
    char letter;
    LED(const int& m = 0, const int& l = 0, const char& let = 0)
        : myled(m)
        , led(l)
        , letter(let)
    {}
};
LED LedData[HASH_SIZE];

void setup()
{
    FastLED.addLeds<WS2811, DATA_PIN, COLOR_ORDER>(Leds, NUM_LEDS); //setting up the FastLED
    randomSeed(analogRead(0)); //seeding my random numbers to make it more random.

    LedData[ 0] = LED(47, 47, 'a');
    LedData[ 1] = LED(45, 45, 'b');
    LedData[ 2] = LED(43, 43, 'c');
    LedData[ 3] = LED(42, 42, 'd');
    LedData[ 4] = LED(40, 40, 'e');
    LedData[ 5] = LED(38, 38, 'f');
    LedData[ 6] = LED(37, 37, 'g');
    LedData[ 7] = LED(34, 34, 'h');
    LedData[ 8] = LED(32, 32, 'i');
    LedData[ 9] = LED(16, 16, 'j');
    LedData[10] = LED(18, 18, 'k');
    LedData[11] = LED(20, 20, 'l');
    LedData[12] = LED(22, 22, 'm');
    LedData[13] = LED(24, 24, 'n');
    LedData[14] = LED(26, 26, 'o');
    LedData[15] = LED(28, 28, 'p');
    LedData[16] = LED(29, 29, 'q');
    LedData[17] = LED(31, 31, 'r');
    LedData[18] = LED(15, 15, 's');
    LedData[19] = LED(13, 13, 't');
    LedData[20] = LED(11, 11, 'u');
    LedData[21] = LED( 9,  9, 'v');
    LedData[22] = LED( 7,  7, 'w');
    LedData[23] = LED( 4,  4, 'x');
    LedData[24] = LED( 2,  2, 'y');
    LedData[25] = LED( 0,  0, 'z');
    LedData[26] = LED();
    LedData[25] = LED();

    reset();
    abcs();
}

void loop()
{
    type("My world would be upsidedown if i went to homecoming without you");
    delay(3000);
    type("andificant");
    delay(100);
    jog();
}

void beforejog()
{
    static const int MaxColours = 10;
    const CRGB colours[MaxColours] =
    {
          CRGB(0, 255, 255)         //aqua
        , CRGB(153, 50, 204)        //dark orchid
        , CRGB(255, 255, 0)         //yellow
        , CRGB(0, 255, 127)         //spring green
        , CRGB(255, 165, 0)         //orange
        , CRGB(65, 105, 255)        //royal blue
        , CRGB(76, 0, 153)          //dark purple
        , CRGB(255, 105, 180)       //hot pink
        , CRGB(0, 128, 0)           //dark green
        , CRGB(255, 0, 0)           //red
    };

    FastLED.clear();
    for (int col = 0; col < MaxColours; ++col)
    {
        for (int r = col; r < NUM_LEDS; r += MaxColours)
        {
            Leds[r] = colours[col];
        }
    }

    FastLED.show();
    delay(50);
    FastLED.clear();
}

void jog()
{
    for (int l = 0; l < 7; ++l)
    {
        beforejog();
        delay(100);
        Blackout();
        delay(100);
    }

    static const MaxLights = 3;
    const int lights[MaxLights] = { 31, 11, 24 };
    for (int l = 0; l < MaxLights; ++l)
    {
        Leds[lights[l]] = Colours[Red];
        FastLED.show();
        delay(2000);
        FastLED.clear();
    }
}

void abcs()
{
    for (int i = 0; i < 25; i++)
    {
        Leds[LedData[i].myled] = Colours[White];
        FastLED.show();
        delay(250);
    }
    delay(10);
}

CRGB randomColor()
{
    const int t = random(4);
    return Colours[t];
}

void reset()
{
    Blackout();
    last_letter = 0;
}

void displayLetter(char letter)
{
    if (isWhitespace(letter))
    {
        last_letter = 0;
        delay(2000);
    }
    const int lednum = charToLed.getValueOf(letter);
    if (lednum >= 0 && lednum <= 50)
    {
        if (last_letter == lednum)
        {
            delay(2000);
        }
        Leds[lednum] = Colours[White];
        FastLED.show();
        last_letter = lednum;
        delay(2000);
        Leds[lednum] = Colours[Off];
        FastLED.show();
    }
}

void type(String message)
{
    reset();
    message.toLowerCase();
    for (int i = 0; i < message.length(); i++)
    {
        displayLetter(message[i]);
    }
    reset();
}

void Blackout()
{
    for (int x = 0; x < NUM_LEDS; x++)
    {
        Leds[x] = Colours[Off];
    }
    FastLED.show();
}

What I have tried to do is group similar variables into arrays (Colour).  I have also created a structure to hold your LED data, it makes it easier to read if it all appears on a single line.  I have added loops to some of the functions to reduce the line count.  And if you aren't changing a variable make it const, it will make no difference to the compiler, but its easier to read and understand.
I haven't compiled this, so there is probably a howler in there, but hopefully it will give you a different perspective on your code and a different (not better) way of doing things.  Oh and it should still have the problem you are asking about, which I think is you need to add an else into that function.

You can use the colors by name CRGB::White, CRGB::Red, CRGB::Lime, CRGB::Blue, CRGB::Black, etc.


text:
LCD library and timer2 CTC interrupt not working together
I want to set up real time counter along with lcd functions from LiquidCrystal library. But they don't work together. However, they work fine separately.
The code is working by itself, but by implementing counter function, LCD just freezes with other functionality.
Part of code:
    #include <LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7, 8, 9, 13, 12, 10);

volatile boolean timerFlag = false;
volatile unsigned long int tmr2Count = 0;

void setup(){

    timer2Init();
}
void loop(){
    checkState();

}
//everything works by commenting out ISR and timer2Init
//===================================================
ISR (TIMER2_COMPA_vect){
  if (timerFlag)
    tmr2Count++;
}
void timerStart(void){
  if ( !timerFlag )
    timerFlag = true;
}
void timerReset(void){
  timerFlag = false;
  tmr2Count = 0;
}
void timer2Init(void){
    //Timer 2 interrupt service routine CTC settings, 1 uS:

    TCCR2A = 0;
    TCCR2B = 0;

    //set CTC mode
    TCCR2A |= (1 << WGM21);
    //prescaler 1 for timer2
    TCCR2B |= (1 << CS20);

    // prescaler for 1 uS.
    OCR2A = 15;
    //set compare match for register OCRA
    TIMSK2 |= ( 1 << OCIE2A);
}
//========================================================

// menu
void checkState(void)
{
  // if button is pressed without menu being displayed
  if (userSettings.currentState == STATE_IDLE && encButton == true){
    userSettings.currentState = MENU_CHOICE;
    lcd.clear();
    lcd.setCursor(3,1);
    lcd.print("<Settings>");
    encButton = false;
  }

  int menuState = userSettings.currentState;

  switch(menuState)
  {
    case STATE_IDLE:
      timeDisplay();
      dateDisplay();
      break;

    case MENU_CHOICE:
      menuSettingDisplay();
      break;

    case MENU_CONTRAST:
      contrastSetting();
      break;

    case MENU_TIME:
      timeSetting();
      break;

    case MENU_DATE:
      setDate();
      break;

    case TIME_DISPLAY:
      timeDisplayOnOff();
      break;

    case DATE_DISPLAY:
      dateDisplay();
      break;

    default:
      break;
  }
}

I digged in LiquidCrystal.cpp and found that there is DelayMicroseconds function, I'm thinking that it could be the cause. If it's not, what can be done otherwise ?

This question comes from the other question: https://arduino.stackexchange.com/questions/44847/redefining-delay-and-delaymicros-as-personal-function

@Jot Thanks for redirecting. The ram is not full and I am aware that Timer2 has nothing to do with the library. I assume it could be delay within the library.

You're getting interrupt every 16th CPU clock cycle. The ISR handler might be even longer than that and your code and lower priority ISRs suffers by "starvation" as MCU can't do anything else than processing ISR.
If you use prescaler value 8, then you have 1/2us resolution of TCNT2 and overflow interrupt (in normal mode) occurs every 128us, so there will be enough time to do something else. However, if you want atomic value of TCNT2 and counted value from ISR handler, you'll have to stop Timer2 for a while.

How to set timer2 for overflow interrupt at 1/2 us ?
I have not used TCNT2 before for ISR.


text:
How to jump outside the loop? in below Programme how to use goto or any other Jump related Programme
const int analogPin1 = A1;
const int analogPin2 = A2;
const int analogPin3 = A3;
const int ledPin = 13;
const int ledPin2 = 7;
const int thresold = 400;
unsigned int x1, x2, x3, fault = 0;
void setup()
{
    pinMode(ledPin, OUTPUT);
    Serial.begin(9600);
}
void Config()
{
    delay(1000);
    Serial.print("ATE0r");
    Response();
    Serial.print("ATr");
    Response();
    Serial.print("AT+CMGF=1r");
    Response();
    Serial.print("AT+CNMI=1,2,0,0,0r");
    Response();
}
void Response()
{
    int count = 0;
    Serial.println();
    while (1) {
        if (Serial.available()) {
            char data = Serial.read();
            if (data == 'K') {
                Serial.println("OK");
                break;
            }
            if (data == 'R') {
                Serial.println("GSM Not Working");
                break;
            }
        }
        count++;
        delay(10);
        if (count == 1000) {
            Serial.println("GSM not Found");
            break;
        }
    }
}
void loop()
{
    int analogValue1 = analogRead(analogPin1);
    int analogValue2 = analogRead(analogPin2);
    int analogValue3 = analogRead(analogPin3);

    if (analogValue1 < thresold) {
        x1 = 1;
        fault = x1;
    }
    if (analogValue2 < thresold) {
        x2 = x1 + 3;
        fault = x2;
    }
    if (analogValue3 < thresold) {
        x3 = x1 + x2 + 5;
        fault = x3;
    }

    switch (fault) {
    case 1:

        digitalWrite(ledPin, HIGH);
        Serial.print("AT+CMGF=1\r");
        delay(1000);
        Serial.print("AT+CMGS=\"+919\"\r");
        delay(1000);
        Serial.print("PHASE 1 HAS GONE");
        delay(1000);
        Serial.write(0x1A);
        delay(1000);
        goto nsr;
        break;

    case 3:

        digitalWrite(ledPin, HIGH);
        Serial.print("AT+CMGF=1\r");
        delay(1000);
        Serial.print("AT+CMGS=\"+919\"\r");
        delay(1000);
        Serial.print("2 HAS GONE");
        delay(1000);
        Serial.write(0x1A);
        delay(1000);
        goto nsr;
        break;

    case 4:
        digitalWrite(ledPin, HIGH);
        Serial.print("AT+CMGF=1\r");
        delay(1000);
        Serial.print("AT+CMGS=\"+919\"\r");
        delay(1000);
        Serial.print("1 AND 2 HAS GONE");
        delay(1000);
        Serial.write(0x1A);
        delay(1000);
        goto nsr;
        break;

    case 5:

        digitalWrite(ledPin, HIGH);
        Serial.print("AT+CMGF=1\r");
        delay(1000);
        Serial.print("AT+CMGS=\"+919\"\r");
        delay(1000);
        Serial.print("3 HAS GONE");
        delay(1000);
        Serial.write(0x1A);
        delay(1000);
        Serial.print("AT+CNMI=2,2,0,0,0");
        goto nsr;
        break;

    case 6:

        digitalWrite(ledPin, HIGH);
        Serial.print("AT+CMGF=1\r");
        delay(1000);
        Serial.print("AT+CMGS=\"+919\"\r");
        delay(1000);
        Serial.print("1 AND 3 HAS GONE");
        delay(1000);
        Serial.write(0x1A);
        delay(1000);
        goto nsr;
        break;

    case 8:

        digitalWrite(ledPin, HIGH);
        Serial.print("AT+CMGF=1\r");
        delay(1000);
        Serial.print("AT+CMGS=\"+919\"\r");
        delay(1000);
        Serial.print("2 AND 3 HAS GONE");
        delay(1000);
        Serial.write(0x1A);
        delay(1000);
        goto nsr;
        break;

    case 10:

        digitalWrite(ledPin, HIGH);
        Serial.print("AT+CMGF=1\r");
        delay(1000);
        Serial.print("AT+CMGS=\"+919\"\r");
        delay(1000);
        Serial.print("ALL 3 HAS GONE");
        delay(1000);
        Serial.write(0x1A);
        delay(1000);
        goto nsr;
        break;

    default:
        x1, x2, x3, fault = 0;
        digitalWrite(ledPin, LOW);
        break;
    }

    x1, x2, x3, fault = 0;
    digitalWrite(ledPin, LOW);
    do {
        int analogValue1 = analogRead(analogPin1);
        int analogValue2 = analogRead(analogPin2);
        int analogValue3 = analogRead(analogPin3);
    } while (analogValue1 < thresold || analogValue2 < thresold || analogValue3 < thresold);
}

do {
    int analogValue1 = analogRead(analogPin1);
    int analogValue2 = analogRead(analogPin2);
    int analogValue3 = analogRead(analogPin3);
} while ((analogValue1 > th) && (analogValue2 > th) && (analogValue3 > th));
}

nsr : if ((analogValue1 > th) && (analogValue2 > th) && (analogValue3 > th))
{

    digitalWrite(ledPin, HIGH);
    Serial.begin(9600);
    Serial.print("\r");
    delay(1000);
    Serial.print("AT+CMGF=1\r");
    delay(1000);
    Serial.print("AT+CMGS=\"+919\"\r");
    delay(1000);
    Serial.print("ALL 3 Phase Restored");
    delay(1000);
    Serial.write(0x1A);
    delay(1000);
    Serial.print("\r");
    delay(1000);
    Serial.print("AT+CMGF=1\r");
    delay(1000);
    Serial.print("AT+CMGS=\"+919\"\r");
    delay(1000);
    Serial.print("ALL 3 Phase Restored");
    delay(1000);
    Serial.write(0x1A);
    delay(1000);

    do {
        int analogValue1 = analogRead(analogPin1);
        int analogValue2 = analogRead(analogPin2);
        int analogValue3 = analogRead(analogPin3);
    } while ((analogValue1 > th) && (analogValue2 > th) && (analogValue3 > th));
}

Please format your code properly. I can't follow what goes with what there.

Yes, nasty piece of spaghetti code (really nicely said).

And after using C++ formatter it's pretty obvious why it can't be working

Just for the curriosity x1, x2, x3, fault = 0; is supposed to set those variables to zero? I have bad news for you.

You want to create separate function nsr and use it instead of goto.
void nsr(void){
  if ((analogValue1 > th) && (analogValue2 > th) && (analogValue3 > th))
  {

    digitalWrite(ledPin, HIGH);
    Serial.begin(9600);
    Serial.print("\r");
    delay(1000);
    Serial.print("AT+CMGF=1\r");
    delay(1000);
    Serial.print("AT+CMGS=\"+919\"\r");
    delay(1000);
    Serial.print("ALL 3 Phase Restored");
    delay(1000);
    Serial.write(0x1A);
    delay(1000);
    Serial.print("\r");
    delay(1000);
    Serial.print("AT+CMGF=1\r");
    delay(1000);
    Serial.print("AT+CMGS=\"+919\"\r");
    delay(1000);
    Serial.print("ALL 3 Phase Restored");
    delay(1000);
    Serial.write(0x1A);
    delay(1000);

    do {
        int analogValue1 = analogRead(analogPin1);
        int analogValue2 = analogRead(analogPin2);
        int analogValue3 = analogRead(analogPin3);
    } while ((analogValue1 > th) && (analogValue2 > th) && (analogValue3 > th));
  }
}

Instead of using
goto nsr

Use a boolean to skip parts you do not want to execute. It is (almost) never a good idea to use goto.
Due to the misalignment of { and } I do not know what you exactly want to execute.


text:
DHT.h Library not being imported
I am trying to read the humidity and temperature using a DHT11 temperature sensor for an Arduino UNO using the DHT.h library. I have my code below:
#include <DHT.h>
#define dataPin 4
dht DHT;

void setup() {
  Serial.begin(9600)

}

void loop() {
  int readData = DHT.read11(dataPin);
  float t = DHT.temperature;
  float h = DHT.humidity;
  Serial.println("Temperature: ")
  Serial.print(t)
  Serial.print(" ºC")
  Serial.println("Humidity: ")
  Serial.print(h)
  Serial.print(" % ")
  delay(2000)
}

When compiling the program, it gives me an error:
fatal error: DHT.h: No such file or directory

I have also tried with lower case letters, but it will not work. Is there any reason why? Do I have to install it? I have tried to search for the library in the Arduino app Sketch - Include Library - Manage Libraries, but the library is not there.

Actually it is a custom library by adafruit. It is present at https://github.com/adafruit/DHT-sensor-library

adafruit/DHT-sensor-library is not the correct library for the code in the question. That code is written for a different library, which I have provided instructions for below.

it seems nothing problem with your library. Have you calibrate your formula(math eq inside coding)?

Download https://github.com/RobTillaart/Arduino/archive/master.zip
Copy the Arduino-master/libraries/DHTstable subfolder of the downloaded file to the libraries subfolder of your sketchbook folder. You can find the location of your sketchbook folder at File > Preferences > Sketchbook location in the Arduino IDE.
Change the first line of your sketch from:
#include <DHT.h>

to:
#include <dht.h>

Now when you try to compile the sketch you will still encounter many errors. However, these are caused by a paucity of semicolons, not by the DHT library, and thus off-topic for this question.

Thanks, @per1234, now it is not showing an error. But, the readings of humidity and temperature are not correct. Here the temperature is nearly 20-degree Celsius with humidity nearly 60%. But Arduino shows the temperature of 2.3-degree Celsius and humidity of 13%. Why so? How to correct this?

I have had problems using some DHT library versions.  I suggest that you try using a different version of dht.h
This version works for me (there are newer versions, but I recommend starting with this oldie but goldie):
dht.h (606B 6/12/2012)
//
//    FILE: dht.h
// VERSION: 0.1.00
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
//
//     URL: http://arduino.cc/playground/Main/DHTLib
//
// HISTORY:
// see dht.cpp file
//

#ifndef dht_h
#define dht_h

#if ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#define DHT_LIB_VERSION "0.1.00"

class dht
{
public:
    int read11(uint8_t pin);
    int read22(uint8_t pin);
    double humidity;
    double temperature;

private:
    uint8_t bits[5];  // buffer to receive data
    int read(uint8_t pin);
};
#endif
//
// END OF FILE
//

try to download this library in this link and insert it to your ide, it works for me.
https://github.com/adafruit/DHT-sensor-library

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


text:
Reading pressure sensor using Arduino analog
I'm using a Arduino Uno to read pressure and I want to know if I have wired/coded the sensor correctly. I'm not sure I'm getting the correct readings (it could be the right readings - I just want to check I have done everything right). The sensor I am using is an OsiSense™ XMLP pressure sensor that reads between 0 and 100 bars and gives out a 0v (zero bars) to 10v (100 bars) charge. Due to the Arduino Uno only being capable of reading up to 5 volts, I've used a voltage divider to reduce the maximum voltage the Arduino receives to 5v.
I've attached a hand-written diagram. Let me know if you need any more information. I've attached the wiring and also the code.

/*
  ReadAnalogVoltage from a OsiSense XMLP presure sensor

  Reads an analog input on pin 0, converts it to voltage and then bar pressure, and prints the result to the Serial Monitor and also MQTT.
  Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).

  Todo
  Static ip. set it to request IP from network
  Work out best way to average readings

*/

#include <SPI.h>  //Serial Peripheral Interface (SPI)
#include <Ethernet.h>  //  These libraries are designed to work with the Arduino Ethernet Shield (Ethernet.h)
#include <PubSubClient.h>  // This library provides a client for doing simple publish/subscribe messaging with a server that supports MQTT

// sets the MAC address and IP address for the network
byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(192,34,98,221);  // IP Address of the client
IPAddress server(192,34,98,201); // The IP address of the MQTT server

void callback(char* topic, byte* payload, unsigned int length) {
  // handle message arrived
}

EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);

void setup() {
  Serial.println("Begin setup");
  Ethernet.begin(mac, ip);
  // Note - the default maximum packet size is 128 bytes. If the
  // combined length of clientId, username and password exceed this,
  // you will need to increase the value of MQTT_MAX_PACKET_SIZE in
  // PubSubClient.h

  // connects to MQTT and says hello world.  Probably change this later on to something more appropriate
  if (client.connect("ArdRigTest")) {
    client.publish("outTopic","Ard Rig Test");
    client.subscribe("inTopic");
  }
  // start serial port
  Serial.begin(9600);
}

void loop() {
  // Note - the default maximum packet size is 128 bytes. If the
  // combined length of clientId, username and password exceed this,
  // you will need to increase the value of MQTT_MAX_PACKET_SIZE in
  // PubSubClient.h

  // read the input on analog pin 0:
  int sensorValue1 = analogRead(A0);
  delay(2); // read twice with small delay to get accurate reading.
  int sensorValue2 = analogRead(A0);

  Serial.println(sensorValue2);
  //Test code. using map function
  int MapBarPressure;
  MapBarPressure = map(sensorValue2, 0, 1023, 0, 100);
  if (client.connect("ArdRigTest" )) {
    client.publish("MapBarPressure",String(MapBarPressure).c_str());  //logs the pressure of the RigTest
    client.subscribe("MapBarPressure");
  }
  delay(100); // Pauses the program for the amount of time (in miliseconds) specified as parameter. (There are 1000 milliseconds in a second.)
  client.loop();
}

Thanks in advance.

Assuming that you are using analogRead() with 0 for 0V and 1023 for 5V it is a question of mapping the range 0-1023 to the pressure range 0-100 bar (map(0, 1023, 0, 100)). See https://www.arduino.cc/en/Reference/Map. Or use float to keep the resolution.

Which pressure sensor is it ? The output voltage is probably not 0.0 to 5.0V, but rather 0.5 to 4.5V. How good and stable is your Arduino 5V which is used to power the sensor ? That is important to know. Is the pressure sensor ratiometric ?

Its a OsiSense™ XMLP.  It kicks out a 10v output so I've built a circuit with a voltage divider so the output to the Arduino is a maximum of 5V.   The power source to the sensor is 24v and is stable.

I'm using analogread.  I don't understand the maths behind map but I guess thats the beauty of the function.  It simplifies the maths so I dont need to.

Using the map function is okay. Just use it. However, you have a problem with the accuracy. What is your voltage divider made of ? Please tell everything, the resistor values and so on. If that sensor was the 0.5-4.5 ratiometric version, then you would have a good accuracy. With the 0-10V sensor you don't. How good and stable is your Arduino 5V ? Do you need the full 100 bar range ? If you only need to measure up to 50 bar, then only a protection resistor would be needed.

2 x 10k resistors. one leads to ground and the other leads to the Arduino analogue in.  i don't think i need the the full 100 bar, i will know more after measuring the pressure.  When you say how stable is the arduino 5v, can you expand on what you mean?

Please update your question. Rewrite it completely, mention the sensor, the resistors, and which Arduino board, and the result that you want (if you want a float value, then you can't use the map function). The sensor you have is not ratiometric and outputs a absolute voltage. When the Arduino reads that, the 5V of the Arduino is default used as a reference. If that 5V changes, so will the resulting measured pressure change, even if the sensor outputs the same voltage. Using the internal reference is better, but it can be 1.0 to 1.2 V and is different for every Arduino board.

Added all the details of the project as requested.  Hope all the information is there for you.  If not, ask away :-)

The Arduino and the sensor need to share a common ground: connect the negative terminals of the power sources together.

You can use map, ref. : https://www.arduino.cc/en/Reference/Map

Re-maps a number from one range to another. That is, a value of
  fromLow would get mapped to toLow, a value of fromHigh to toHigh,
  values in-between to values in-between, etc.

With the caveat that "The map() function uses integer math so will not generate fractions, when the math might indicate that it should do so. Fractional remainders are truncated, and are not rounded or averaged."

so sometimes it's worth thinking in decibars internally and only convert to bars when you need to show it to the user.

@josecanuc did the OP ask to get decimals?

Indeed the OP did not specify any requirements in that regard, but if he or she uses map(), I only wished to clarify the limitation.

Please use a more constructive way to explain it then!

Thanks for letting me know about integer, truncates and thanks for the map function :-)  The truncations may cause us a problem, I may need more accuracy.

@resolver101 If you need accuracy I would use an op-amp scaled to 1/2 instead of the voltage divider.  And make sure you use 1% or better resistors.

If you need to use fractional pressure values, then the formula is
float MapBarPressure;
MapBarPressure = sensorValue2 / 10.24;

This was obtained by seeing that the maximum reading from AnalogRead(A0) is 1024, which corresponds to 5V on A0 (and which also means 10V output from the sensor.) If you read 1024 from A0, it means you are measuring 100bar, so
bar = (A0 / 1024) * 100

Alternatively, you could maintain 1 decimal place of accuracy in bar if you keep with int values:
int MapDeciBarPressure;
MapDeciBarPressure = map(sensorValue2, 0, 1023, 0, 1000);

Then your variable is holding "tenths of bar" (deciBar) and you only convert it to bar by dividing by 10.0 (not 10, which is an int, but 10.0, which is a float and does floating point math and returns a float response.)
One other note: you write:
// read the input on analog pin 0:
int sensorValue1 = analogRead(A0);
delay(2); // read twice with small delay to get accurate reading.
int sensorValue2 = analogRead(A0);

Just reading twice doesn't gain accuracy -- you have to average the values:
int sensorValAvg = (sensorValue1 + sensorValue2) / 2;

Then, use sensorValAvg for your less noisy value.
Edit:
Also, make sure you connect all ground lines together, both from the sensor and the Arduino!

The conversion factor is 1024, not 1023.

Caught me again! Edited.

About accuracy.
I assume you have read @edgar-bonet about connecting the GND's.
I assume you understand the other answer to calculate the pressure. I would write it like this:
// This is for the DEFAULT 5V analog reference.
// v = the voltage at the pin in Volts.
// p = the pressure in bar.
// Note that 'bar' is the pressure relative to the
// normal atmospheric pressure at that moment.
float v = (float) analogRead(A0) / 1024.0 * 5.0;
float p = v / 5.0 * 100.0;

The analogRead uses default the 5V as reference.
That means that if the project is powered by a USB cable, the 5V could vary between 4.5 and 5.0 V. That 10% difference will be seen in the resulting calculated pressure. In that case you can not measure more accurate than 10%.
If the project is powered with a power supply to the power barrel jack, then the resulting accuracy depends on the accuracy of the voltage regulator on the Arduino board.
The analog reference can be set with analogReference.
The internal voltage reference of the Arduino Uno is 1.1V. That is reasonably stable, but it depends a little on the voltage of VCC and the temperature. The main problem is that it is different for each Arduino Uno, and it can be between 1.0 and 1.2 V. Therefor you have to measure it, and use the measured value in the calculation in the sketch.
The input range is between 0V and the analog reference. Therefor you have to adjust the voltage divider to get 0..10V down to 0..1.1V. You could try: R1 = 100k and R2 = 10k.
const int pressureSignalPin = A0;

void setup()
{
  analogReference( INTERNAL);
}

void loop()
{
  // v = the voltage at the pin in Volts.
  // p = the pressure in bar.
  // Note that 'bar' is the pressure relative to the
  // normal atmospheric pressure at that moment.
  // The "(100.0 + 10.0) / 10.0" is the factor by the voltage divider
  // with 100k and 10k.
  // Measure the AREF pin, and fill the value in for "1.10".
  float v = (float) analogRead(A0) / 1024.0 * 1.10;
  float p = v * ((100.0 + 10.0) / 10.0);
}

Thanks. I've connect the grounds between the arduino and the sensor so they are all common.   I've not tried the internal reference yet.. The power in is from a POE converter to the usb cable.  I've attached a USB current/voltage reader and you can see the video hear : https://www.youtube.com/watch?v=Tb7qJXcJl9M&feature=youtu.be

Everything is just fine.
All you have to do is to provide the common ground (0 potential) to your Arduino and your Sensor.
The problem here is that they might be on a different potential.
So just connect the ground of your 5 volts and 24 volts together and everything will work perfectly.


text:
Arduino Mega Wifi Shield Timeout Error
I got an Arduino Mega(not original) and also a Wifi shield, when ever I try to upload my code to it, I get this error:
Sketch uses 5504 bytes (2%) of program storage space. Maximum is 253952 bytes.
Global variables use 704 bytes (8%) of dynamic memory, leaving 7488 bytes for local variables. Maximum is 8192 bytes.
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
An error occurred while uploading the sketch

Without the shield on it works perfectly, but as soon as I plug it in it stops working, I tried uploading the code without shield and placing the shield but this way the serial port didn't work.
The shield I bought is:
ESP8266 ESP-12E UART WIFI Module Wireless Shield Converter For Arduino UNO Mega

Edit:
If there is anything connected to the arduino it wont upload, it is not just the shield, I can't get my OLED to work either. Also tried using the shield on my UNO and I get the same result.

The error usually means that there is a basic comms problem between the board.  If the Mega works without the shield this implies that the shield is interfering with serial port 0.  I'm assuming that the "debug port" is linked to the ESP, is that correct?  Do the dip switches affect how the serial port is treated?

@CodeGorilla I tried changin the dip switch but nothing changes.

via Google I found this helpful site which has an answer that might help.  It is not the same question as yours, but it explains what the dip switches are for
How to connect Wi-Fi shield ESP-12E-ESP8266-UART-WIFI-Wireless-Shield with Arduino
It seems that IF you have what is pictured a 'shield' version of the board, as opposed to a 'shaild' version, then when you plug it in to an uno it will stop the uno working, because of the serial connection from the ESP on shield pins 0 and 1.  I don't know where these pins are going on your mega, but it might be the same issue.  This page recommends bending the pins out the way and wiring them to other pins - Which is at your risk.  You could trial it by wiring the whole shield to the mega and seeing if it worked.
https://claus.bloggt.es/2017/02/26/arduino-esp8266-wifi-shield-elecshop-ml-by-wangtongze-comparison/


text:
Powering a Nano with a 5v mini USB adaptor
I have made a simple temp sensing circuit that lights an LED when it reaches a certain point. It works perfectly when powered by a USB plugged in to the laptop but when I connect it to a 5V supply with a mini-USB connection nothing happens.
Is this correct and do I need to send power directly to the board on the 5V pin?
Many thanks,
Jack

You can use the computer or a 5V USB charger to power the Arduino via the USB connector. If it does not work, then something else is the problem. What kind of 5V supply is that ? Is there something weird with it ? Is it from a well known brand or a cheap unreliable power supply. Try another USB 5V charger, it should work.

Is that with a TMP36 ? And the 5V as reference ? That will never be accurate. The temperature could be 10 degrees wrong. Do you have a multimeter to measure the 5V ?

And how exactly are you connecting that mini-USB to your circuit?

@gre_gor the Arduino Nano board has a mini USB jack on one end, most likely the poster's is a workalike but they usually preserve this even if they use a CH340 rather than an FTDI.

@Jot The datasheet for the TMP36 states the accuracy as +/- 1C at 25C and +/- 2C over the full range, and that the power supply can be 2.7V to 5.5V.

@Mike the sensor outputs a voltage. That has to be measured (as if using a multimeter to measure the voltage). The Arduino used default the 5V as voltage reference. If the 5V changes, so will the resulating calculated temperature change. When the Arduino is powered via the USB cable, the 5V could change a lot. In such situations, I always use the internal analog reference of the Arduino, which is reasonably accurate. Even better is to avoid all this analog reference hassle and use a DS18B20 with a digital interface.

I'm voting to close this question because it was an hardware problem (bad USB adaptador), not an Arduino problem.

Thanks all. I found a different power source with a mini-usb connector and it works fine. I think when plugging it in to the PC the Nano makes some faint clicking noises but when direct to  5v plug it does not? I'm not sure so I'll re-test. It was the lack of clicking that lead me to believe it wasn't working as I can't see the on board LEDs using my enclosure.
I don't know about the accuracy but it seems to work for my situation - it is to be placed in a fridge that recently turned itself in to a freezer but has since fixed itself. This project is an early warning system in case it decides to do it again.
Thanks again.
Jack

Accept your own answer making click in the "approve" symbol to close this question.

"I think when plugging it in to the PC the Nano makes some faint clicking noises but when direct to 5v plug it does not?" ... more probably, the PC makes this noise when recognising the Nano's USB<->Serial converter chip as additional USB device.

I found that the noise may be from the little piezo speaker that I added in series with the USB. If it is this then it is gently chirps whilst the red LED on the Nano is flashing when connecting it to the USB. The red LED only flashes once and no sound from the piezo when connecting to an AC 5v adaptor.

This sounds like the 5v PSU didn't have enough amps to run the Nano and the few attachments.  The USB power doesn't generally have many amps, so that PSU mush have been dead/a dud or seriously under powered.


text:
ESP8266 Blink sketch - does not blink / or stays constant
I uploaded the Blink sketch (from the ESP8266 examples, in the Arduino IDE) successfully.
Depending on which wire configuration I am using two different things happen:
wiring 1:
CH_PD -> 3.3V
VCC -> 3.3V
RST -> GND
GPI02 -> LED
GND -> GND

wiring 2:
VCC -> 3.3V
RST -> GND
GPI02 -> LED
GND -> GND

There are TX/RX lines in the picture from when I was flashing - they aren't being used for running the sketch.
With wiring 1 the LED stays on (doesn't blink) - I was wondering if this was because I still had the VCC -> 3.3V connected. So I disconnected that, which gives way to wiring 2.
With wiring 2 the LED doesn't come on at all, it is the same as wiring 1 except without VCC -> 3.3V.
Why is it constant when 3.3V is going to VCC, and constantly off when I disconnect it? Why doesn't it blink using wiring 2?
UPDATE
A diagram as requested, sorry it was my first time doing this:

Code:
/*
 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)
}

The picture shows an Arduino Uno, and no ESP8266 -- where is your ESP8266?

its out of the picture - the wires that blur off the screen lead to it...i was trying to show wiring on board - all that is going on with it is the power light is on as it should be.

with a ESP-01S, all you'd need is GND+VCC+GPIO2...

yah it the extra wires are from flashing...would what im doing now not work for some reason? I disconnected the GPIO0 from ground and disconnected 3.3v from CH_PD...didnt bother with serial lines

You should connect Vcc to 3.3V, because that's how the ESP8266 is powered.
RST is active-low reset and should be pulled to 3.3V

I am sending to LV...its the green wire, it gets blocked out. So running standalone vcc should be 3.3v? what about ch_pd? Oh wait I messed up my pins...wiring 2 vcc is still connected

Just saw you have RST to GND, RST is active-low reset, so it needs to be pulled high to 3.3V otherwise the device is always in reset.

oh wow that could be it ill try...im new to this...to pull high where would i put the resistor? the leg on the switch across from the blue wire? (vertical)

You just put a resistor between RST and 3.3V directly. Instead of RST to GND, you RST to one side of resistor, then plug the other side of the resistor to 3.3V.

would i move my reset button to in between RST and resistor->3.3v. to switch it on and off that power?

Your reset button would go between ground and the RST line. The resistor that remains between 3.3V and RST will limit the current so you don't short out your power supply during reset.

ok thanks was wondering about where the ground came in

i re-flashed the code and still no blinking. just to be sure...for the reset button I have RST -> 3.3v and for the switch its RST -> switch -> ground

is it possible that the LED_BUILTIN variable in the code is referencing the wrong pin? its used like this void setup() {   pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output }

I can't comment as my karma is too low so if I am wrong please just someone let me know and I'll simply delete.
I thought that the RST pin being pulled to ground resets the chip, if this is the case surely in your setup you are constantly reseting your chip, so it won't do anything. My understanding is that you should have the reset pin pulled up to 3.3V with a 10K resistor.

thanks...where does the resistor go? this is my first time "pulling"...im guessing the leg on the bottom left to 3.3v?

I'm not sure if it's the leg on the bottom left... You havnt provided a picture of your esp8266 board. But it should connect your esp8266 RST pin to the 3.3V source!

instead of ground? so my switch could be in between RST and 3.3v?

Yes, exactly. Like what Jose says

I reflashed the code and no luck...see comment on below answer

I think it's best if you edit your original post with a picture of the esp8266 and how you've wired it. Also post your code in full. Thank you

I think it's best if you edit your original post with a picture of the esp8266 and how you've wired it. Also post your code in full. Thank you

Also you say you use LED_BUILTIN. Why, why not use pin 2 if that is what your Led is connected to? At the moment it should make the led on the esp8266 board flash. Not the external one, unless LED_BUILTIN is pin 2?

oh interesting...i uploaded how I have it wired above...i was thinking about trying this two ....just using 2 for gpio2...i guess I'll try it...i was just using LED_BUILTIN is what they use in the arduino esp8266 examples for blink sketch, I thought it represented one of the gpio2...so the blue led is what would flash with that variable?

And also the code?

i updated it its above

Why is the transitor there?

the voltage regulator?

Ahahahah. I'm tired jesus my bad!

haha no problem

Assuming you flashed it correctly, I see no reason it shouldn't not work now, other than wrong pin assignment, try pin 2? Also when it runs I'm assuming the voltage regulator isn't necessary as the arduino can provide 3v?

yah the flash was successful...went to 100% then unloaded bootloader, im about to try pin 2 now...ur right this sketch is to make the blue led blink...but it doesnt do that either

I read in one place that whatever is responsible for the flash upload is "flakey" and doesn't work everytime...have u heard this? defective models...because I can upload but it takes tons of tries before one works

Let us continue this discussion in chat.