text:
Dshot implementation on Arduino (ESC protocol)
Does anyone one know if it's possible to implement Dshot on Arduino? I want to interface the Arduino with ESCs (electric speed controllers). These ESCs use Dshot,
 (https://oscarliang.com/dshot/) a digital protocol. From what I read online, you can make PWM follow a duty cycle. However, I want to change the duty cycle after each pulse and not just repeat the same duty cycle. I understand this requires DMA (direct memory access) but it's a bit over my head.

There is no technical specification of "dshot" at your link, only an advertisement

The more important question however is how you would get any actual benefit - this is a high performance protocol for fast control loops run on fast modern processors, not slow, limited ATmegas.  Pretty much any ESC that supports this supports other things too, either automatically or with a different build of the open firmware it is using to support this in the first place.

I mainly want dshot for everything except the performance aspect (send commands, beeping, telemetry,  leds, parity bits). I don't mind using pwm but since I'm getting this esc anyway, why not use the functionality to the fullest. I think this is a better link: https://blog.seidel-philipp.de/dshot-digital-esc-signal/

I would like to use flight controllers but I'm not using these escs for quadcopter usage. I can use PWM to interface with the flight controller (or are there other ways) but in that case I might as well connect directly to the escs.

In short, I ended up creating a library capable to drive multiple DShot600 ESCs:
DShot-Arduino
It still need a lot more polish, but the bit-banging works really well.

SPI method
I tried the method @dannyf mentioned, which involved combining 3 SPI bytes to form 1 dShot bit and it actually works.
But there's a few problem with SPI:

It takes up the valuable SPI port, in theory you can still connect other SPI devices, but;
maximum 1 dShot ESC can be connected
During transmission of the packet, the CPU need to wait for the whole task, assume we are sending DShot300, each packet is about 54us long so CPU is halt for that amount of time. If you are doing this in 1000Hz, that is 5% CPU time.
The timing is not very accurate to the DShot protocol standard

e.g. for DShot300, each bit is

1.25us High - 1.25us H/L - 0.83 Low
for a 16MHz Arduino, 1.25us will be 20 CPU cycles which is not accurate to transmit with a SPI byte

I end up with the following codes to send a bit:
inline void dshot_0(){
  SPDR = 0xFF;
  NOP;
  while (!(SPSR & _BV(SPIF))) ;
  SPDR = 0x60;
  NOP;
  while (!(SPSR & _BV(SPIF))) ;
  SPDR = 0x00;
  NOP8;
  while (!(SPSR & _BV(SPIF))) ;
}

inline void dshot_1(){
  SPDR = 0xFF;
  NOP;
  while (!(SPSR & _BV(SPIF))) ;
  SPDR = 0xFF;
  NOP;
  while (!(SPSR & _BV(SPIF))) ;
  SPDR = 0xF0;
  NOP8;
  while (!(SPSR & _BV(SPIF))) ;
}

Above code is for DShot150, the SPI was set to 4Mbps, to adhere to the correct timing, I cannot transmit a full DShot byte as all on or all off, here's how the calculation done:

4Mbit SPI, each bit 0.25us. Thus for 16M clock arduino:

DShot 0 sequence: 10 bits of 1, 14 bits of 0
DShot 1 sequence: 20 bits of 1, 4 bits of 0

Those NOPn are just macro for the number of NOPs. I avoided using SPI library code here since the overhead of making library call is quite a lot.
Pure software bit-banging
This is the method resulted in my library, since using hardware SPI won't give me any advantages of releasing CPU time, and doing some Math gives me that a DShot600 require total 27 CPU cycle on 16MHz UNO. Which the pattern is the following:

10 Cycle High -> 10 Cycle H/L (depending on bit 1/0) -> 7 cycles low

Which gives total of 1.6875us per bit or 27us per packet. To allow the very tight timing those are coded in assembly.
Also by applying bit-masking the library is capable of driving at most 8 ESCs on the same hardware port (on UNO, Digital pin 0-7, PORTD).
Update cycle
One last note about DShot is during my test, I found it is quite strict on the update frequency. It must be updated at exact time interval and I found the slowest update frequency will be around 500Hz. To provide the correct timing for that, the library used Timer 1 and by default update in 1000Hz frequency.

Have you try STM base Arduino and bidirectional D-Shot?
You library look great I will try it soon. Thank you for you participation.

for bi-directional, do you mean receiving D-shot signal using Arduino? If so, I believe it is impossible for these 8 bit CPUs.

Not sure why, but it does not work. My ESC beeps to tell me that there is a signal coming but the motor does not work. Any ideas on how to troubleshoot? I am really not confident that the interrupt works at this frequency. I use Arduino Nano which, by spec, should have 16MHz

@xandy indeed receiving the response of a Bidirectional DShot packet is very difficult for 8-bit AVRs! I recently got a prototype working.  It's a bit complicated but I tried to comment it well. Take a look!

you can make pwm follow a duty cycle.

single shot pwm would be difficult to do on an avr.
much better to use hardware spi. Looks like you can do use 3 spi bits for every dshot bit. So 6 bytes of spi transmission would enough for every dshot frame (16 dshot bits).
running hardware spi at 3*0.6Mhz = 1.8Mhz or where about on a 16MIPS avr would be quite doable.

Sounds promising! i want to connect 4 escs though, while the audrino only has 1 mosi. One idea is to use a demuxer. Any thoughts?

it will depend on how the esc firmware reacts to long periods of no (input) signal. if it requires the constant presence of an input signal, that wouldn't be a viable solution.

"pause between frames of at least 2 microseconds to indicate a frame reset" and "PID loop this pause is actually considerably longer"  . As mentioned here: https://blck.mn/2016/11/dshot-the-new-kid-on-the-block/. This might actually work!

How do I wire SPI, though? My ESC only has ONE data port... I cannot find information on that


text:
Wireless Shield Not being detected w/ Arduino Uno R3
Wireless Shield is not being detected by arduino, not MAC address is displaying.
 Not sure what to try next, there is nothing noticeably wrong with the shield at first glance.
Green LED under status is on.
Shield Type: CC3000 WiFi Shield
Board Model: UNO R3

No Mac Address is being detected (my output in Serial Monitor)
Initializing Wifi...
MAC: 0:0:0:0:0:0
Scanning available networks...
** Scan Networks **
number of available networks:0

My Script:
#include <SPI.h>
#include <WiFi.h>

void setup() {
  // initialize serial and wait for the port to open:
  Serial.begin(9600);
  while(!Serial) ;

  // attempt to connect using WEP encryption:
  Serial.println("Initializing Wifi...");
  printMacAddress();

  // scan for existing networks:
  Serial.println("Scanning available networks...");
  listNetworks();
}

void loop() {
  delay(10000);
  // scan for existing networks:
  Serial.println("Scanning available networks...");
  listNetworks();
}

void printMacAddress() {
  // the MAC address of your Wifi shield
  byte mac[6];

  // print your MAC address:
  WiFi.macAddress(mac);
  Serial.print("MAC: ");
  Serial.print(mac[5],HEX);
  Serial.print(":");
  Serial.print(mac[4],HEX);
  Serial.print(":");
  Serial.print(mac[3],HEX);
  Serial.print(":");
  Serial.print(mac[2],HEX);
  Serial.print(":");
  Serial.print(mac[1],HEX);
  Serial.print(":");
  Serial.println(mac[0],HEX);
}

void listNetworks() {
  // scan for nearby networks:
  Serial.println("** Scan Networks **");
  byte numSsid = WiFi.scanNetworks();

  // print the list of networks seen:
  Serial.print("number of available networks:");
  Serial.println(numSsid);

  // print the network number and name for each network found:
  for (int thisNet = 0; thisNet<numSsid; thisNet++) {
    Serial.print(thisNet);
    Serial.print(") ");
    Serial.print(WiFi.SSID(thisNet));
    Serial.print("\tSignal: ");
    Serial.print(WiFi.RSSI(thisNet));
    Serial.print(" dBm");
    Serial.print("\tEncryption: ");
    Serial.println(WiFi.encryptionType(thisNet));
  }
}

Try using a library for the CC3000 instead of the one for the Arduino Wifi (W5100) board. You may have a little bit more luck.

Which wifi shield are you using?

Your problem:

You have a CC3000 WiFi shield
You are using the WiFi library for the Arduino WiFi Shield
The Arduino WiFi Shield is a HDG204 based shield, not CC3000

Get the right library for your shield, install it, and try the examples and tutorials that come with it.

Using CC3000 Libraries seem to work.  Thanks

source: Stack Exchange

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

sort: votes


text:
CH34x board fails with avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00 Atemel Mega328P AU1640
I have been given a board(Atmel ATmega328P-AU 1640) to program. I googled and found category of board Arduino Uno/ CH34x-based clone.
But when I program an empty program:
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

I get this error:
Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

These are all the ports that are available to me. I have connected my Arduino with one of the USB ports on my Macbook running MacOS Sierra

Why do u thing that is an arduino

Because I was told @PeterJ I might be wrong

Why do you want to connect it via Bluetooth?

that's the only port available. Hey, I see this is Atmel's board....Do I need Atmel Software to code it? I'm not an electronics guy. Please fix(edit) this question if wrong

Can we see a picture of the board?

yes I can edit the question

check now @uhours

Why do you have the ICSP header coming off the bottom of the board?

You have an Arduino nano clone using a CH340G chip for serial communication. You to down load and install a driver for your computer to recognize it. I don't use OSX, so there's not one I can recommend.

tell me for Windows

I also have windows installed in Bootcamp

I have installed both CH340G & CH341G but still, no other USB ports are showing except Bluetooth one

Sorry, I use Linux, and have the driver built in. If it's still not showing up, you either did it wrong, or the device is damaged.

The board is an Arduino Nano clone, not an Uno.

Plug the Nano's USB cable into your computer.
Download and install the CH340 driver from here: http://www.wch.cn/download/CH341SER_MAC_ZIP.html
In the Arduino IDE, select the port of your Nano from the Tools > Port menu.
Tools > Board > Arduino Nano
Sketch > Upload

If the port of your Nano doesn't appear in the Tools > Port menu (and no, dev/cu.Bluetooth-Incoming-Port is not the correct port) then you may have a damaged or charge-only USB cable. Try using a known-good cable or verify that your cable works for data on another device. If you have it plugged into a USB 3.0 port on your computer then try a USB 2.0 port instead.

Yes usb 3.0 doesn't work I'll try with 2.0

That looks like a clone of an Arduino Nano to me, with a CH340G chip as the USB interface chip.  You need to:

Install the CH340G drivers
Ensure that the ATMega328PU chip has a bootloader installed on it

The last Nano I bought from China didn't have a bootloader installed. There are many tutorials online for teaching you how to install the bootloader using another Arduino as the programmer.

can you post some links how to fix bootloader on MacOS? Also I have already installed CH340G. I saw a youtube video but it's still no showing me other ports. Please confirm what board category should I select thanks :)

how to check if bootloader installed on it or not....please provide me with some direction. I've no experience with electronics & Arduino stuff @Majenko

The led L should blink rapidly a few times when you press the reset button.

Try this instructions from install driver. https://github.com/adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver
Installation with Homebrew-Cask.
Then try this, and all work fine  ;)
http://www.instructables.com/id/How-to-fix-bad-Chinese-Arduino-clones/

Please don't post URL answers, write the gist of it and refer to the URL.

Remove the old driver by issuing one of the following commands (depending on your installation):

sudo rm -rf /System/Library/Extensions/usb.kext
sudo rm -rf /Library/Extensions/usbserial.kext

Restart your Mac.
Install with Homebrew-Cask
Install the driver by the following commands

brew tap mengbo/ch340g-ch34g-ch34x-mac-os-x-driver https://github.com/mengbo/ch340g-ch34g-ch34x-mac-os-x-driver
brew cask install wch-ch34x-usb-serial-driver

Restart your Mac.
Try upload some code in your Arduino.
In some cases the board might still not work.
This is because there is no bootloader installed on the Atmel microcontroller ship. To solve this problem we need a working Arduino and the clone Arduino we want to fix.
![Make an ISP Programmer From Your Working Arduino
]1
First we connect the working Arduino to our computer and open the Arduino IDE.
We go to File -> Examples and click ArduinoISP and upload this to the Arduino. Ones uploaded disconnect the Arduino.
**
Connecting the Wires
**

Next we connect the wires from the working Arduino to the clone as follows.
Without 10 uF capacitor.
Go to Tools -> Board and select the chinese board that is not working. in my case it's an Arduino Genius/Uno
Next we go to Tools again -> Programmer and select Arduino as ISP.
Go to Tools again and select "Burn Bootloader".
Go back to Tools -> Programmer and set back to ArduinoISP.
Your clone should work just fine now. ;)

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

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


text:
How to call more than 10 different functions based on serial input?
I'm looking to basically call functions based on the serial ID I assign to it. For example, if I want to call function A I would type on the serial A and if I want to call function B then I would type B.
Now I have taken a look at some arduino.cc ASCII and other lookup tables but I'm still not getting my results. YES I can indeed make up serial calls 1 through 9 using char datatype but as you can see I'm only limited to 9 function calls and so this is where I'm looking for tips. How can I expand this serial ID as I'm calling it?
char id;
int led = 6; // the PWM pin the LED is attached to

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

void loop() {
  id = Serial.read();
  /*
    will only read the 1st bit on the buffer so
    no 10s...90s because the whole char so we
    need to use Strings datatype somehow but
    the thing is that the Serial.Read func only
    reads the first byte. R&D?
  */
  if (id == '1') {
    digitalWrite(led, HIGH);
  } else if (id == '2') {
    digitalWrite(led, LOW);
  }
}

So in my above example I'm using char to communicate. I know there are other datatypes but not sure which is the best suited for the 100's of functions I would like to call via terminal.
I thought about using the alphabet A-Z as well as a-z to double the function calls but I would like to come up with something a bit more formal rather than single numbers or single letters (char).

https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/

A char can be 256 different values. However, data is read in one byte at a time. You may want to develop your own communication protocol to send multiple bytes. It doesn't even have to be complicated: just read x bytes, and then stop.

@Majenko than you for your help once again pal! I'll get to the link and read it all.

@uhours are you suggesting a for loop in the conditionals?

@Frank, A for loop before the conditionals, reading x bytes into an array. Exit the loop when the array is full. Use strcmp() to evaluate the contents. Also, indent your code.

@uhours thanks for the advise, I will read mute on that function you mentioned as I have never used it before.

It looks like you want to write some sort of command interpreter. You may want to look, for inspiration, at this simple Arduino command line interpreter.

First, you could use a string for the commands. You just need to ensure there is some special char to mark the end of a command - like the newline char. Read the input from the port one char at a time, building the string as you go:
char buffer[256];
uint16_t buffer_index = 0;
void loop() {
  while (Serial.available()) {
    int c = Serial.read();
    if ('\n' == c) {
      buffer[buffer_index] = 0;   // Append EOS
      // Complete message - do something
      buffer_index = 0;   // Reset, ready for next message
    }
    else {
      // Append char to end of buffer
      buffer[buffer_index++] = c;
    }
    // Check for overflow
    if (256 == buffer_index) {
        buffer_index = 0;
    }
  }
}

There are plenty of examples like this on this site.
Next, I don't recommend using an if statement with a hundred or more conditions. Instead, you can store pointers to each function in an array:
// Use a typedef to simplfy
typedef void (*function_type)(); // A function with no params and no return, change as needed
// Fixed array size
const int max_functions = 200;
// Create an array of 200 function pointers
function_type all_functions[max_functions] = {0};

So to call function #11:
all_functions[10]();

Now you just need a way to marry the function pointers to a name. A hash table could work here. A hash function converts a string to a number. There are lots of examples on the web. Here's one:
uint16_t djb2_hash(const char *str)
{
    unsigned long hash = 5381;
    int c;

    while (0 != (c = *str++)) {
        hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
    }

    // Note: we use the mod operator to make sure value
    // is less than array size
    return hash % max_functions;
}

Create two functions, one to add a function and one to retreive:
bool add_function(const char *name, function_type f)
{
  // Convert name to number
  uint16_t index = djb2_hash(name);  //  0 <= index <= max_functions
  if (NULL != all_functions[index]) {
    // There is already a function stored at this index
    Serial.print("Adding ");
    Serial.print(name);
    Serial.print("failed. index = ");
    Serial.println(index);
    return false;
  }
  else {
    // Store the function in the array
    all_functions[index] = f;
    return true;
  }
}
bool run_function(const char *name)
{
  uint16_t index = djb2_hash(name);
  if (NULL == all_functions[index]) {
    // Name not found
    return false;
  }
  else {
    // Call the function
    all_functions[index]();
    return true;
  }
}

Last, create some functions and add to hash table:
void f1() {Serial.println("F1");}
void f2() {Serial.println("F2");}
void f3() {Serial.println("F3");}

void setup() {
  Serial.begin(9600);
  add_function("F1", f1);
  add_function("F2", f2);
  add_function("F3", f3);
}

All that's left is to modify loop() to call the functions when a complete message is received.
void loop() {
  while (Serial.available()) {
    int c = Serial.read();
    if ('\n' == c) {
      buffer[buffer_index] = 0;
      run_function(buffer);
      buffer_index = 0;
    }
    else {
      buffer[buffer_index++] = c;
    }
    // Check for overflow
    if (256 == buffer_index) {
        buffer_index = 0;
    }
  }
}

If you enter "F1", "F2", or "F3" in the serial monitor, those functions should execute. Just make sure you change the serial monitor to append a newline.
Some notes: the hash function may not create a unique id for each string. You need to handle this situation. Also, the names are case sensitive. If you don't want that, convert everything to all upper case or all lower.

Your code works great, but, What can I do to call a Funct with parameters void funct_X(char letterX, int numberX); ...... ?

@NavasEma You could change the typedef to typedef void (*function_type)(char,int);.  And the run function to all_functions[index](arg1, arg2);

a state machine would be the most efficient approach here.
first, you need to process each valid input - making sure that it is between 0..9.
then you need to form a 2-digit number with that. for that to work, you will need to be able to tell when the input ends - lots of ways to do that.
the heart of the code would be something like this:
current_input = valid_input();  //obtain valid input
input = cmd_2dig(current_input); //2-dig commands
switch (cmd_2dig) {
  case 0: do_cmd0(); break;
  case 1: do_cmd1(); break;
  case ....
  default: reset_cmd(); //invalid command, reset command buffer
}


text:
Why did my pushbutton LED circuit work when my wiring was wrong?
I had a Coursera Arduino homewhere wherein you create a simple pushbutton-controlled LED circuit.
I used the example "button.ino" script that's builtin to the Arduino IDE, without modification. I'll reproduce it at the end of this question.
Here's what I did (wrong):
My circuit went from 5V Power to the top pin of a push button. The bottom of the pushbutton was (correctly) wired to Pin 2 on one side and a resistor was used to wire the other bottom pin to the anode of LED. The cathode of the LED was wired to ground.
The reason I think this is wrong is that I forgot that I was supposed to wire the LED to a pin corresponding to ledPin in the example script. The example script uses Pin 13, which has the builtin LED. I was using an external LED. Yet, the circuit worked perfectly.
Why did it work? Doesn't that mean the 5V power output was getting turned off (I'd guess you call that being set to LOW) when Pin 13 was set to LOW? Why would that be the case?
/*
  Button

 Turns on and off a light emitting diode(LED) connected to digital
 pin 13, when pressing a pushbutton attached to pin 2.

 The circuit:
 * LED attached from pin 13 to ground
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground

 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.

 created 2005
 by DojoDave <http://www.0j0.org>
 modified 30 Aug 2011
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

It worked because your button was controlling power to your led. The Arduino was doing nothing at all.

@Majenko Thanks. Yes, they did say that the Arduino was only supposed to supply power and ground for this homework, so I guess that was as it should be after all. Incidentally, the on-board LED seemed to read the state of the pin correctly, which was something I didn't even think to look at until just now. As simple as this was, I think it's a good beginner exercise.

The LED wired to the push button was turned ON by the push button closing the circuit, without any intervention from the micro controller.
That's a pretty simple circuit: a voltage source, a switch, an LED and a resistor, all in series. When you close the circuit the LED turns on. Simple.
The code on your microcontroller is watching the state change on the button and turning ON/OFF the on board LED: it has nothing to do with the LED in your circuit/breadboard.

The circuit you are describing seems to just have the button control whether the LED got the supply or not. Unless pin2 was grounded, you effectively supplied 5V to the resistor-LED as well as pin2 through the button.
This essentially gives you the standard LED circuit.
Have a great day!

Why did it work?

the button is shorting the led (turning it off) when it is closed. when the button is open, the led lights up from the resistor.
essentially your arduino is not involved with the led's operations.

Follow up question: what happens to the 5V when the button is open? It doesn't have a complete path so it just stays in the Arduino and the wire that leads up to the button?


text:
How to tune up a servo and add protective clauses?
I am working with an Arduino Uno, and have recently been given an assignment to use the servo motor.
The requirements are that I tune the pulse widths while comparing the 0 and 180 degrees. Secondly I must put in a protective clause to prevent it from going past the values. Any help at all is greatly appreciated. Thank you.
(Using the servo.attach(pin, minpulse, maxpulse) method, and writeMicroseconds() command.)

You may want to put in protective clauses in your code to prevent accidental driving of the servo beyond its intended range.
Write a simple program to tune up your servo’s min and max pulsewidths corresponding to 0° and 180°. Start by using 900 and 2100 in the attach() command, and perhaps sending the motor to 0°, 90°, and 180° delaying a couple seconds between moves for you to assess the quality of alignment.

My only ideas have been to manually fine tune it by checking when it does not turn any more.

Sounds like homework.  Asking here sounds like cheating.  Well, take a look at all the methods in the Arduino servo library.  See where you can simply write the delay in milliseconds?  See where you can simply read back the angle?  If it works, it's likely only an approximation, but you might be able to do your whole lab with no servo attached at all.  Of course you would have nothing to demonstrate.

You need to create some form of feedback system - something which, when you provide an angle to test will allow the Arduino (or you) to know the actual resulting angle and make the relevant adjustments. Automated could be a potentiometer that feeds back the angle (you will have to calibrate it yourself) or a simple protractor indicating the angle from which you read the value and feed it or the adjustments back in.  It's up to you how complex and automated you make it.

Thank you for your help, I misinterpreted the question, a manual calibration would be enough, though the potentiometer idea sounds pretty cool.


text:
Uploading Arduino bootloader to ATmega32U4 with another Arduino?
I am in a situation where it is useful if I can upload a bootloader into an ATmega32U4 using another Arduino like this, for ex:https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard. I have a different circuit though.
Is there a reason to believe that this can't be adapted to ATmega32U4?
Are there any important differences between the ATmega328P and ATmega32U4, that I have to take into account for this to work?

Which Arduino board are you using as the programmer?

I entend to use arduino uno

The only difference you have to take into account is that if you're using an ATmega32U4 board such as Leonardo the SPI pins are not broken out to the pin headers along the edge of the board as is the case with the Uno shown in the tutorial you linked. Instead you should connect the programmer board to the ICSP header pins on your ATmega32U4 board, where the SPI pins are broken out:

MISO: ICSP-1
MOSI: ICSP-4
SCK: ICSP-3

So this means you can't follow the wiring shown on the tutorial exactly but it should be very easy to adapt that tutorial to your needs.


text:
Standalone 328p Programming with CH340G programmer
I have made a standalone arduino board with a Atmega328p w/ Uno bootloader taking inspiration from this video https://youtu.be/sNIMCdVOHOM
However, when I try to program mine all I get is "Problem uploading to board".
I have confirmed that everything on the board works and that I could upload Blink through my arduino Uno via ArduinoISP but I would like to use this adapter to program the board instead.
Other things that I have tried:
Swapping Tx/Rx from adapter to board
Adding 100nF capacitor on DTR to RST
Trying without DTR
(The board also has a 10k pullup resistor on the RST line)
Burning a new bootloader after programming with Arduino as ISP
Any suggestions are greatly appreciated.
Thanks,

Verbose Upload Output
Sketch uses 928 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
C:\Program Files\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM7 -b115200 -D -Uflash:w:C:\Users\Admin\AppData\Local\Temp\arduino_build_446007/Blink.ino.hex:i
     Using Port                    : COM7
     Using Programmer              : arduino
     Overriding Baud Rate          : 115200

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xe8
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xe8
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xe8
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe8
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xe8
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xe8
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xe8
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe8
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xe8
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe8
avrdude done.  Thank you.
Problem uploading to board.

Please edit your question to include the verbose upload output (File > Preferences > Show verbose output during: > compilation (uncheck) > upload (check) > OK).

What crystal did you use?

The crystal is a 16Mhz

Well, one thing you should do is ISP load a sketch that actually uses the serial in both directions, and verify that you have that communication actually working.

I have previously tried using serial communication on the board via  ISP with the UNO however, I was unable to receive understandable data  - everything that came out was random symbols that wasn't what I was looking for.
This is why I had swapped to using this adapter as I thought it would be much simpler to function :P

Huh?  ISP is for programming, not asynchronous serial communication at runtime.  It sounds like you have a problem, bu you're going to have to be absolutely specific about exactly what you tried.

The problem I have currently is using the USB adapter to program the circuit, which I didn't think had anything to do with when I programmed the circuit through my UNO.
When I did that I tried hooking the RX/TX pins up from the UNO to my standalone board for serial communication (something I saw online which said that was how it was done). When this didn't work I switched to my USB adapter to try program the standalone board through that

Have you set the right fuse bits on your chip for the 16MHz crystal, or are you still running on the internal oscillator? If you are your bootloader and sketch serial baud rate will be completely wrong.

I have confirmed that everything on the board works and that I could upload Blink through my arduino Uno via ArduinoISP but I would like to use this adapter.

Because the ATmega family does not support a partial flash erase via ISP, loading a sketch via ISP removes the bootloader.
Therefore you must (re)load a suitable bootloader using the ISP connection, before you can perform a serial upload of a sketch using that bootloader.

Oh, I didn't know that.
Would I be able to flash the bootloader from my Uno to use on this board, using the same ISP connection that I did previously?

I just tried burning the booloader from my UNO onto my other board, then reconnecting the USB adapter and it still does not upload and I receive the same error.

There are two stages to programming a chip.  First is to get the firmware (the bootloader, for example) on there, which you have done.
Second is to configure the chip to operate in the way you have wired it up. Specifically to configure the oscillator and clock source.
The bootloader and your sketch all expect the chip to be running at 16MHz. It uses that constant value to calculate things like the baud rate for serial communications.  If the chip isn't running at 16MHz then all those calculations will be meaningless.
You have connected a 16MHz crystal, which is good, but unless you tell the chip to use it you will still be using the internal oscillator for your clock source as set in the factory.  This is an 8MHz oscillator with clock division down to 1MHz.
You need to configure the fuse bits on the chip using avrdude and your Arduino as an ISP.
This article details exactly how to do it and teaches you what the fuses are and what they mean.

Fuses should automatically be set appropriately when the IDE is used to burn the bootloader, unless the boards file is broken.

@ChrisStratton Maybe it is. Or maybe he had the wrong board selected. Going by the comments the baud rate is wrong, which points to a mismatch between the oscillator (or fuses) and F_CPU.

I just assumed that when I programmed it with Blink the first time on breadboard (with my UNO) it was all set up correctly as the timing looked correct. I will check that article and see.


text:
Controlling 10+x 5m led strips with 10+ individual analog floor switches
I am looking to control around 10 (exact number TBD) non-addressable 5m led strips with an Arduino. Each led strip will be activated when a corresponding DIY analog floor switch.
The idea is to have a hallway with a number of these led strips oriented vertically from the floor to the ceiling and when somebody walks on the corresponding floor switch under the strip, the strip will light up.
I have a number of questions:

How could I have a setup that is scalable from 10 led strips and floor switches to 20? (having enough analog and digital pins)
How should I best distribute power to all the strips and for each switch? This is how I understand to setup 1 of the switches:
How do I wire the one colored non-addressable LED strips to the Arduino?

Note: I have coded before and done some soldering and simple electronics but have never used Arduino.
Thank you!

You don't need an Arduino to light up LEDs from switches, you just need wires.

And maybe MOSFETs if the switches good be a higher resistance than you would like.

look into SPI/I2C "IO expander"s, or shift registers. 2. see #1. 3. use a logic level n-chan mosfet, like the irlz44n: drain to LED-, gate to MCU/IO, source to ground (both MCU and LED PSU).

I think that the best solution for you, unless you want a simple on/off control (if you want it just go with Majenko's solution) is to use port expanders.
Maybe this can be slightly overkill, but you can think of using a MAX7313.
This IC is I2C controlled and has 16 I/O; you can configure each as input or output, and with automatic PWM generation too. This means that the uC just has to send it the value of light you want to output and it automatically keeps the LED strips at the correct duty cycle.
This way you can connect a sensor to P0, P2, P4, ... and configure them as input, then a pull-up resistor and a MOSFET to P1, P3, P5, ... and configure them as output with PWM. From the arduino, you will just have to connect two pins (SDA, SCL) and, of course, GND, then you will have the ability to control eight sensor/led pairs to one sensor. You want to extend it? Just solder another IC and assign it another address (pins AD0..2 serve for this purpose). You can set 64 different addresses, thus being able to drive 512 sensor/led pairs.
Want more? Use RGB led strips. Connect P0 to sensor, P1 to R, P2 to G, P3 to B, and with each IC you'll be able to drive four sensor/led pairs. You'll be able to drive only 256 sensor/led pairs, but they will be rainbow colored...
This solution has only one drawback: I could not find any pre-made board with the MAX7313 on ebay. So you'll have to design your own PCB and solder it. If you are not able to do this, alternatives exist.
Adafruit has a PCA9685 16-channels port expander board (and a lot of other manufacturers made this). This has also integrated PWM and a lot of addresses possible, but the PCA has only outputs (so no inputs). You will be able to arrange them in a matrix (so with the 18 pins remainig you will be able to control 81 switches).
Another alternative is the MCP23017; this has inputs and outputs, but no automatic PWM; this means that if you want turn them on and iff ok, but if you want a variable light you will have to "manually" pull the pin high or low (very heavy on the I2C network).
Other solutions using SPI may have better performances (SPI is faster than I2C), and a lot of other ICs with SPI, I2C or other serial connections exist. You just have to find out the most suitable for you

Unless you want to do fancy things with the LED strips you really don't need an Arduino to accomplish this task.  You can just switch each strip with a powerful enough MOSFET and control the gate with the sensor:

simulate this circuit – Schematic created using CircuitLab
If you really want the Arduino (for example to add effects like delays, fading, blinking patterns, etc) it would basically go into the circuit at point A in the circuit. The sensor into an input and the MOSFET into an output.
Since these are just presence sensors (not pressure sensors, they don't sense pressure, only presence) you don't need an analog input to read them - a digital one will suffice and also make your programming simpler.
You can use shift registers or IO expanders to increase the number of input and output pins you have, or you can use a larger Arduino with more pins.

I have a number of questions:

use a transistor to turn on / off each leds. size the transistor based on the leds' voltage / current requirement.
make sure that your arduino has sufficient number of pins for the sensors + leds. if not, you can split the tasks among multiple arduinos.


text:
What is the proper way to make library pin mappings configurable?
I am working with some libraries that provide APIs for interacting with specific hardware chips (that makes these drivers?).  However, different custom boards or shields will have the chip mapped to different pins meaning the library needs to be modified for each case.  Needing to modify the library does not work well with the Arduino IDE Library Manager.
Are there preferred/recommended patterns for exposing this configuration so that the library itself does not need to be modified every time?
Here is an example where it is documented which part needs to be changed to match the pin layout of your board.

Many of the normal Arduino libraries already do this - start by familiarizing yourself with that method, even from a user perspective.

The method I use is to provide the pins as parameters to the constructor. Those pin numbers are stored in variables to use later in the .begin() function and elsewhere.
Most of the time I use initialization lists to keep things simple. For example:
class Something {
    uint8_t _cs;
    uint8_t _dc;

    Something(uint8_t cs, uint8_t dc) : _cs(cs), _dc(dc) {}
    void begin();
};

void Something::begin() {
    pinMode(_cs, OUTPUT);
    pinMode(_dc, OUTPUT);
}

Something mySomething(10, 8);

I would use either of the following two possibilities:
Use (class) variables and set them within the constructor.
Advantages:

Always initialized
Easy to use (constructor and pin setup at once)

Use a separate (e.g. Init) method.
Advantages:

Can be dynamically changed

Remarks
For pin settings, mostly static circuits are used so the first approach is probably better.
For settings, mostly the second method is better.
If many pins are involved (not likely), use a structure or separate pin settings class.
Macros
What I wouldn't advice is macros. When users need to change source code themselves, and new versions are installed, they either have to merge or redo the changes again. The advantages is a bit less (machine)code, a little bit faster probably and a bit less memory usage, but all three aspects are minimal.

In case you'd avoid the C++ constructor stuff that's quite commonly an overkill on Arduino, you could use #define's (object-like macros).
Like so:
#define PIN_ONE 1
#define PIN_TWO 2

The preprocessor will seamlessly replace PIN_ONE with the number 1 and PIN_TWO with 2 assuming those definitions are in the library header .h file. This will most likely takes the least amount of resources compared to the other possible solutions.
Alternative 1
If you have the opportunity to use modern-ish C++, you can use constexpr to define variables. Compared to macros you'll get type checking and it should be just as efficient.

The problem is that they need to be in a place where both the .ino file as well as the library source can get to them. This usually means a separate header file with everything that requires.

Are you sure? Pretty sure I can do #define switches in .ino's and they are used in libraries, but I might be wrong.

It can work if the code for the library is strictly in the header, but not if it's in a different compilation unit altogether.

Yeah, that makes sense, didn't know the exact limitations, added that disclaimer.

depending on your approach.
1) if you just provide the binary + header files, you will have to make the pins variables.
2) if you provide the source code and expect the user to recompile the source code, use macros.

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


text:
No Socket Available message floods serial monitor
Serial Monitor get's flooded with "No Socket Available" message.  This seems to occur even before I Try to communicate with my Hue bridge through my hub port.  Does anyone see why this is occurring after my wireless connection is established?
Serial Output:
Firmware needs upgrade
Attempting to connect to WPA SSID: ifiw_ym
connected to the networkSSID: ifiw_ym
BSSID: 0:B2:8F:6A:C4:28
signal strength (RSSI):-47
Encryption Type:4

IP Address: 192.168.1.7
192.168.1.7
MAC address: 78:C4:E:1:9F:B1
in loopin loopin loopNo Socket available
No Socket available
in loopNo Socket available
No Socket available
in loopNo Socket available
No Socket available
in loopNo Socket available
No Socket available
...

code:
#include <SPI.h>
#include <WiFi.h>

//  Hue constants
const char hueHubIP[] = "192.168.1.6";
const char hueUsername[] = "my_hue_app";
const int hueHubPort = 80;

boolean activated = false;

//  Hue variables
boolean hueOn;
int hueBri;  // brightness value
long hueHue;  // hue value
String hueCmd;  // Hue command

unsigned long buffer=0;  //buffer for received data storage
unsigned long addr;

// Wireless network
char ssid[] = "**********";
char pass[] = "**********";
int status = WL_IDLE_STATUS;
WiFiClient client;

//0:B2:8F:6A:C4:28

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

  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.println("Firmware needs upgrade");
  }

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  Serial.print("connected to the network");
  printCurrentNet();
  printWifiData();
}

void loop() {
  Serial.print("in loop");
  // printCurrentNet();
  alterHueColors();
}

void alterHueColors() {
  if(activated){
    client.println("Hue is activated");

     // A series of four sample commands, which colour fades two lights between red and pink. Read up on the Hue API
    // documentation for more details on the exact commands to be used, but note that quote marks must be escaped.
    String command = "{\"on\": true,\"hue\": 50100,\"sat\":255,\"bri\":255,\"transitiontime\":"+String(random(15,25))+"}";
    setHue(3,command);
    command = "{\"on\": true,\"hue\": 65280,\"sat\":255,\"bri\":255,\"transitiontime\":"+String(random(15,25))+"}";
    setHue(4,command);
    command = "{\"hue\": 65280,\"sat\":255,\"bri\":255,\"transitiontime\":"+String(random(15,25))+"}";
    setHue(3,command);
    command = "{\"hue\": 50100,\"sat\":255,\"bri\":255,\"transitiontime\":"+String(random(15,25))+"}";
    setHue(4,command);

    activated = true;
  }
  else{
      activated = false;
      client.println("deactivated");

      //was activated, so send a single off command
      String command = "{\"on\": false}";
      setHue(3,command);
      setHue(4,command);
  }
}

It's also interesting to not that my print calls in alterHueColors()  aren't triggering.
Full .ino file

For one thing, your logic is backwards. activated = false to begin with. So in alterHueColors() the if condition will never be true and only the else block gets executed because it keeps activated = false;.

Second, can you open 192.168.1.6:80 from any other pc on the network?

@johnnyMopp Thanks for finding that, i've noticed that as well.  Fixed it locally, I will update.  After update it does go through the else.  The 192.168.1.6:80 is accessible on my browser.  However, the No Socket Available message still occurs in serial monitor.


text:
How can I move an arduino library into my project repo and use it from there?
I've got this project that that is using the LiquidCrystal.h library. My import looks like this...
#import <LiquidCrystal.h>

I've tried making a 'libraries' folder in my repo, and copying the LiquidCrystal directory from arduino's global libraries folder to my_project/libraries and changing my import to...
#import "libraries/LiquidCrystal/LiquidCrystal.h"

and it explodes on me. I know the path is right, because it gives me a different error if I change the import path to be wrong... but even when it's right, I get this traceback...
Arduino: 1.8.1 (Mac OS X), TD: 1.36, Board: "Arduino/Genuino Uno"

/var/folders/sz/cdsmvqws6rq9839mhd802prm0000gp/T//cc4gIISN.ltrans0.ltrans.o: In function `__static_initialization_and_destruction_0':
/Users/chris/art/greenhouse/greenhouse/greenhouse.ino:36: undefined reference to `LiquidCrystal::LiquidCrystal(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)'
etc....

What's the deal? Aren't I supposed to be able to import libraries with an absolute path to the library? This is literally the same file.
What is the difference between #import <foo.h> and #import "my_libraries/myfoo.h" ?

What's the deal? Aren't I supposed to be able to import libraries with
  an absolute path to the library? This is literally the same file.

Yes you can use both absolute and relative paths, but "libraries/LiquidCrystal/LiquidCrystal.h" is a relative path because it doesn't start from C:\\ or / basically. Also make sure you get the LiquidCrystal.cpp file which actually contains all the functions LiquidCrystal.h specifies.

What is the difference between #import  and #import
  "my_libraries/myfoo.h" ?

#include "my_libraries/myfoo.h" specifies that myfoo.h is in a folder my_libraries first searched for in current_folder/my_libraries/myfoo.h then quote directories and rest of the search paths later, #include <foo.h> specifies that foo.h is a system header, it's only searched for in search paths.
Solution here would be saying inside your sketch that it is in a subfolder, that the folder is one folder below and then two folders deeper for ex. #include "../libraries/LiquidCrystal/LiquidCrystal.h" this here assumes your sketch is in root_folder/Sketch/Sketch.ino and library in root_folder/libraries/LiquidCrystal/LiquidCrystal.h.

Try it with this folder structure:
my_project
|_src
  |_LiquidCrystal

and change the import to:
#import "src/LiquidCrystal/LiquidCrystal.h"

Since Arduino IDE 1.6.10, recursive compilation of the sketch folder has been limited to the src subfolder (see Arduino/arduino-builder#148).
By the way, it's much more common to use #include instead of #import, which is deprecated and will cause a compiler warning. Any properly written library will not require the use of #import.


text:
someone can help please? am getting an error saying expected } at the end of input
    //set initial values
int x = 0; // set initail zero value for the counter
int preE = 512; // set initial value for light intensity in east direction
int preW = 512; // set initial value for light intensity in west direction
int predtime = 512; // set initial value for delay time
int pretol= 512; // set initial value for tolerance value
void setup() {
  Serial.begin(9600); // set the baud rate for the serial monitor

  // first set the relays off
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  digitalWrite(7,HIGH);
  digitalWrite(8,HIGH); // began the loop
}

  void loop()
  {
    // Read the first reading

    //read the east LDR
    int E1 = analogRead(5); //read the west LDR
    int W1 = analogRead(4); // read the delay time potentiometer
    int dtime1 = analogRead(1);
    //read the tolerance potentiometer
     int tol1 = analogRead(0); // Check if the readings reasonable, otherwise set them to previous ones.

if (E1 < 10 || E1 > 1000 )
{
  E1 = preE ;
  }
  if (W1 < 10 || W1 > 1000 )
  {
    W1 = preW ;
    }
    if (dtime1 < 10 || dtime1 > 1000 )
    {
      dtime1 = predtime ;
      }
      if (tol1 < 10 || tol1 > 1000)
      {
        tol1 = pretol ;
        }
        delay(100); // delay for one 0.1 second and take the next reading

        int E2= analogRead(5);
        int W2= analogRead(4);
        int dtime2= analogRead(1);
        int tol2= analogRead(0);
        if (E2 < 10 || E2 > 1000 )
        {
          E2= preE ;
        }

if (W2 < 10 || W2 > 1000 )
{
  W2= preW ;
  }
  if (dtime2 < 10 || dtime2 > 1000 )
  {
    dtime2= predtime ;
    }
    if (tol2 < 10 || tol2 > 1000 )
    {
      tol2= pretol ;
      }
      delay(100); // delay for one 0.1 second and take the third reading

      int E3= analogRead(5);
      int W3= analogRead(4);
      int dtime3= analogRead(1);
      int tol3= analogRead(0);
      if (E3 < 10 || E3 > 1000 )
      {
        E3= preE ;
        }
        if (W3 < 10 || W3 > 1000 )
        {
          W3= preW ;
          }
          if (dtime3 < 10 || dtime3 > 1000 )

{
  dtime3= predtime ;
  }
  if (tol3 < 10 || tol3 > 1000 )
  {
    tol3= pretol ;
    }
    int E4 = analogRead(5);
    int W4 = analogRead(4);
    int dtime4= analogRead(1);
    int tol4= analogRead(0);
    if (E4 < 10 || E4 > 1000 )
    {
      E4= preE ;
      }
      if (W4 < 10 || W4 > 1000 )
      {
        W4= preW ;
        }
        if (dtime4 < 10 || dtime4 > 1000 )
        {
          dtime4= predtime ;
          }
          if (tol4 < 10 || tol4 > 1000 )
          {
            tol4= pretol ;
            }

delay(100);
int E5 = analogRead(5);
int W5 = analogRead(4);
int dtime5= analogRead(1);
int tol5= analogRead(0);
if (E5 < 10 || E5 > 1000 )
{
  E5= preE ;
  }
  if (W5 < 10 || W5 > 1000 )
  {
    W5= preW ;
    }
    if (dtime5 < 10 || dtime5 > 1000 )
    {
      dtime5= predtime ;
      }
      if (tol5 < 10 || tol5 > 1000 )
      {
        tol5= pretol ;
      }
      delay(100);
      int E6 = analogRead(5);
      int W6 = analogRead(4);
      int dtime6= analogRead(1);
      int tol6= analogRead(0); if (E6 < 10 || E6 > 1000 )
      {
E6= preE ;
}
if (W6 < 10 || W6 > 1000 )
{
  W6= preW ;
  }
  if (dtime6 < 10 || dtime6 > 1000 )
  {
    dtime6= predtime ;
    }
    if (tol6 < 10 || tol6 > 1000 )
    {
      tol6= pretol ;
      }
      delay(100);
      int E7 = analogRead(5);
      int W7 = analogRead(4);
      int dtime7= analogRead(1);
      int tol7= analogRead(0);
      if (E7 < 10 || E7 > 1000 )
      {
        E7= preE ;
        }
        if (W7 < 10 || W7 > 1000 )
        {
          W7= preW ;
          }
          if (dtime7 < 10 || dtime7 > 1000 )

{
  dtime7= predtime ;
  }
  if (tol7 < 10 || tol7 > 1000 )
  {
    tol7= pretol ;
    }
    delay(100);
    int E8 = analogRead(5);
    int W8 = analogRead(4);
    int dtime8= analogRead(1);
    int tol8= analogRead(0);
    if (E8 < 10 || E8 > 1000 )
    {
      E8= preE ;
      }
      if (W8 < 10 || W8 > 1000 )
      {
        W8= preW ;
        }
        if (dtime8 < 10 || dtime8 > 1000 )
        {
          dtime8= predtime ;
          }
          if (tol8 < 10 || tol8 > 1000 )
          {
            tol8= pretol ;
            }

delay(100);
int E9 = analogRead(5);
int W9 = analogRead(4);
int dtime9= analogRead(1);
int tol9= analogRead(0);

{
if (E9 < 10 || E9 > 1000 )
{
  E9= preE ;
  }
{
  if (W9 < 10 || W9 > 1000 )
  {
    W9= preW ;
    }
{
    if (dtime9 < 10 || dtime9 > 1000 )
    {
      dtime9= predtime ;
      }
{
      if (tol9 < 10 || tol9 > 1000 )
      {
        tol9= pretol ;
        }
        delay(100);
        int E10 = analogRead(5);
        int W10 = analogRead(4);
        int dtime10= analogRead(1);
        int tol10= analogRead(0);

          if (E10 < 10 || E10 > 1000 )

        {
E10= preE ;
}
{
if (W10 < 10 || W10 > 1000 )
{
  W10= preW ;
  }
  {
  if (dtime10 < 10 || dtime10 > 1000 )
  {
    dtime10= predtime ;
    }
    {
    if (tol10 < 10 || tol10 > 1000 )
    {
      tol10= pretol ;
      }

      //Average the ten readings

   int E=(E1+E2+E3+E4+E5+E6+E7+E8+E9+E10)/10;

   //light intensityin east
   int W =(W1+W2+W3+W4+W5+W6+W7+W8+W9+W10)/10;

   // light intensity in west
   int dtime=(dtime1+dtime2+dtime3+dtime4+dtime5+dtime6+dtime7+dtime8+dtime9+dtime10)/10;

   int tol = (tol1+tol2+tol3+tol4+tol5+tol6+tol7+tol8+tol9+tol10)/10;// tolerance value
   int delaytime = (dtime *10);// increase the delay by magnitude of 10
   int tolerance = tol / 40;

   // display the readings through serial monitor
   Serial.println("Light intesity in the East");
   Serial.println(E);
   Serial.println(" ");
   Serial.println("Light intesity in the west");
   Serial.println(W);
   Serial.println(" ");
   Serial.println("delay time");
   Serial.println(delaytime);
   Serial.println(" ");
   Serial.println("tolerance");
   Serial.println(tolerance);

   //check the differenc and open the coresponding relays

   // check the diffirence of light intensity in east and west
   int diff = E - W;

   // check if the diffirence is in the tolerance else rotates the motor
   {
   if (-1*tolerance > diff || diff > tolerance)

   {
    if (E > W)// check if light intensity in east is greater than in west

    {
      if ( x <30)// check counter to ensure the motor does not run infinitely

    {
      Serial.println("Turn motors towards east");

   digitalWrite(7, LOW);// Turn ON Relay 1

   delay(2000);

   digitalWrite(7,HIGH); //Turn OFF Relay 1
   ++x;
   }
   }
   //check if light intensity in west is greater than in east
   else if (W > E) { if (x > -30)

   {
    }
    }
   }

Serial.println("Turn motor toward west");
digitalWrite(8, LOW);// Turn ON Relay 4
digitalWrite(9, LOW);
delay(2000);
digitalWrite(8, HIGH);//Turn OFF Relay 4
digitalWrite(9, HIGH);
--x;
// decrease counter
}
}
}
//store the values for the next loop

preE = 512;
preW = 512;
pretol= 512;
predtime = 512;
Serial.println(" ");
Serial.println("--------------------------------------------------------------------- ");
// delay the next loop
delay(1000);
}

Copy your code into an editor which does proper indentation for C++ and the error should be obvious.

In the Arduino IDE press Ctrl+T for auto-indent. You have mismatch with '{' en '}'.

You are missing five } at the end of your sketch.
As @Chris said, proper indentation will make your problem obvious. Use the menu Tools-AutoFormat (Ctrl-T) to format your sketch.
That's is looks like with the missing } added:
//store the values for the next loop

                        preE = 512;
                        preW = 512;
                        pretol= 512;
                        predtime = 512;
                        Serial.println(" ");
                        Serial.println("--------------------------------------------------------------------- ");
// delay the next loop
                        delay(1000);
                    }
//--- This } are missing in your sketch
                }
            }
        }
    }
}

I mean no offence by this but you have got in such a mess because you have written monolithic code.  As a new developer you aren't expected to know this, I sure as hell didn't know it 30+ years ago.  The fact that you have posted you code on here, shows that it is too big for a normal brain to manage.  You loop function is over 300 lines long!  A screen full is about all a normal person can manage.
What I think you should do is refactor your code, look at it and pick out common blocks and turn them into functions, this will reduce the number of lines, making in it easier to read and reduce the possibility of bugs.  So firstly I notice you have this block repeated:
if (E1 < 10 || E1 > 1000)
{
    E1 = preE;
}

If you wrote that as a function:
int CheckLimits (const int& value, const int& lowerBound, const int& upperBound, const int& default)
{
  if (value < lowerBound || value > upperBound)
    return default;
  return value;
}
// This means those 4 lines collapse to this one line.
E1 = CheckLimits (E1, 10, 1000, preE);

Those 4 lines of code appear at least 39 times in loop, that's 120 lines that have just bee removed!
The preE value (and its pre friends) is never changed, so make it a constant and that will remove another 4 lines at the end.
Using literal numbers for your pins makes it harder to change them if you ever need to rewire.  More importantly it makes the code harder to understand, so always #define them at the top of you code.
If you create two variables to hold the same sort of number you should be thinking about using an array instead.  When you create E1 to E10  to hold ten readings, you should have done it in an array.  The array size should be a constant, defined in a single place, so you can change it if necessary.  And guess what, the averaging code should have been a function.
ANYWAY
I rewrote you code and hopefully it will explain what I mean.  Loop is down to about 90 lines now and it would be easy to make it smaller.  Yes, get a decent editor, Notepad++ or Visual Studio or Visual Code are all free, but you have to learn to think in smaller blocks, if you ever copy and paste more than one line, it probably should be a function :)
I haven't compiled it, but it should work - Please don't copy it just look at it and make your code better than this.
//set initial values
int x = 0; // set initial zero value for the counter
static const int preE = 512; // set initial value for light intensity in east direction
static const int preW = 512; // set initial value for light intensity in west direction
static const int predtime = 512; // set initial value for delay time
static const int pretol = 512; // set initial value for tolerance value
// Define the PINS
#define APIN_E (5)
#define APIN_W (4)
#define APIN_DTIME (1)
#define APIN_TOL (0)
static const int MaxReadings(10);       // The number of readings used to form the average
int E_Reading[MaxReadings];             // Holds all the readings, not sure it is required any more, replaced by average variable.
int W_Reading[MaxReadings];
int dtime_Reading[MaxReadings];
int tol_Reading[MaxReadings];

void setup()
{
    Serial.begin(9600); // set the baud rate for the serial monitor

                        // first set the relays off
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH); // began the loop
}

/// Check that the given value is within the limits
/// value: The reading to check
/// lowerBound : The lowest acceptable value
/// upperBound : The highest acceptable value
/// defValue : The value to use if outside the range.
int CheckLimits(const int& value, const int& lowerBound, const int& upperBound, const int& defValue)
{
    if (value < lowerBound || value > upperBound)
        return defValue;
    return value;
}

/// Take a reading from the specified pi and check it is within the acceptable bounds.
/// pinNumber   : The Analog pin number
/// lowerBound : The lowest acceptable value
/// upperBound : The highest acceptable value
/// defValue : The value to use if outside the range.
int TakeReading(const int& pinNumber, const int& lowerBound, const int& upperBound, const int& defValue)
{
    return CheckLimits(analogRead(pinNumber), lowerBound, upperBound, defValue);
}

void loop()
{
    int Eaverage = 0;
    int Waverage = 0;
    int dtimeaverage = 0;
    int tolaverage = 0;

    // Read the first reading
    for (int index = 0; index < MaxReadings; ++index)
    {   // You don't actually need the values unless you want them, TakeReading could be assigned to the average variables.
        E_Reading[index] = TakeReading(APIN_E, 10, 1000, preE);         // read the east LDR
        W_Reading[index] = TakeReading(APIN_W, 10, 1000, preW);         // read the west LDR
        dtime_Reading[index] = TakeReading(APIN_DTIME, 10, 1000, predtme);  // read the delay time potentiometer
        tol_Reading[index] = TakeReading(APIN_TOL, 10, 1000, prepretol);    // read the tolerance potentiometer

        Eaverage += E_Reading[index];
        Waverage += W_Reading[index];
        dtimeaverage += dtime_Reading[index];
        tolaverage += tol_Reading[index];
        delay(100);
    }

    //Average the ten readings
    Eaverage /= MaxReadings;
    Waverage /= MaxReadings;
    dtimeaverage /= MaxReadings;
    tolaverage /= MaxReadings;

    const int delaytime = (dtime * 10);// increase the delay by magnitude of 10
    const int tolerance = tol / 40;

    // display the readings through serial monitor
    Serial.println("Light intensity in the East");
    Serial.println(E);
    Serial.println(" ");
    Serial.println("Light intensity in the west");
    Serial.println(W);
    Serial.println(" ");
    Serial.println("delay time");
    Serial.println(delaytime);
    Serial.println(" ");
    Serial.println("tolerance");
    Serial.println(tolerance);

    //check the difference and open the corresponding relays

    // check the difference of light intensity in east and west
    const int diff = E - W;

    // check if the difference is in the tolerance else rotates the motor
    if (-1 * tolerance > diff || diff > tolerance)
    {
        if (E > W)// check if light intensity in east is greater than in west
        {
            if (x < 30)// check counter to ensure the motor does not run infinitely

            {
                Serial.println("Turn motors towards east");
                digitalWrite(7, LOW);// Turn ON Relay 1
                delay(2000);
                digitalWrite(7, HIGH); //Turn OFF Relay 1
                ++x;
            }
        }
        //check if light intensity in west is greater than in east
        else if (W > E)
        {
            if (x > -30)
            {
                // MISSING CODE??
            }
        }
    }
    Serial.println("Turn motor toward west");
    digitalWrite(8, LOW);// Turn ON Relay 4
    digitalWrite(9, LOW);
    delay(2000);
    digitalWrite(8, HIGH);//Turn OFF Relay 4
    digitalWrite(9, HIGH);
    --x;
    // decrease counter

    //store the values for the next loop
    Serial.println(" ");
    Serial.println("--------------------------------------------------------------------- ");
    // delay the next loop
    delay(1000);
}

usually unmatched brackets.
run your code through astyle and it will be more clear to you.


text:
Can't move servo with my Nano
I'm new to this kind of thing. My code works on my Uno without problem with two separate servos. I've ensured that it's not any faulty leads, having tried a few other circuits with LEDs, buttons and potentiometers as well, simply switching between my Uno (which works fine) and the Nano.
I've chosen the correct port, chipset and board each time and the code uploads fine to the Nano. The Nano simply refuses to do anything I tell it.

Digital PIN of servo goes to designated D5 pin.
Ground goes to the GND near the Analog pins (shouldn't matter which I imagine).
Power goes to 5V.

The code above simply tells the servo to go to a certain degree when uploaded. Could anybody tell me why the servo will not move at all with the Nano? I just bought it and I haven't hooked up any power to it other than the USB, surely it isn't fried. It lights up and flashes as well.
#include <Servo.h>
Servo my_servo;

void setup() {
  my_servo.attach(5);
  // Pin definition
}

void loop() {
  my_servo.write(60);
  // No. of degrees
}

does the servo get enough power?

I know that the servo works fine through only the USB using the same schematic with the Uno. Do you think maybe the Nano could be providing less power through the USB to the 5V pin?

@ratchetfreak I checked the voltage (using a multimeter) going from the GND and 5V to the servo and I got 4.58V for the Nano and 5.06V for the Uno. Could that make that difference? The servos I'm using are rated at 4.8V +

If you're starving the servo of power then the internal controller may not function.

@Majenko perhaps I should figure out how to drop a 9V battery to 5v and power the Nano?

Or power the servo separately from the Nano.

@Majenko From the Uno, I've tried running 5V from a switchable (5V) power supply straight to the servo GND/Power and it doesn't move. If I take the GND/Power back to the Uno it works fine. What could I be doing wrong?

I bet you removed the ground from the Arduino when you added the external power supply, didn't you?

https://hackingmajenkoblog.wordpress.com/2016/12/06/the-importance-of-sharing-grounds/

@Majenko That was an error I made. However.. this is what I did now and the Nano still doesn't work. GND/Power from Servo to the supply GND/Power - then from the GND of those I took one lead to the Uno's GND and it worked fine. But if I switch it over to the Nano it doesn't move. Odd.

Connect a multi meter in series with the servo connection from the uno to the servo and see how much current it draws when working (probably less than 20ma, definitely less than 40ma). Then connect it in series with the nano and see what happens. If you get no current then you're activating the wrong pin.
If you see a current draw but the servo doesn't move then you need to use some sort of switch (transistor, FET, relay) to switch the servo. You could also compare the voltage and current read off the nano to the requirement in the datasheet for the servo. Again, this may lead you to needing a switch.
Edit based on comments above... Also try your 5v directly to the servo, then add a forward biased diode in series which should simulate the voltage drop to the level of your nano (0.4-0.6v). If the servo doesn't work with the diode and does without then you can be pretty sure the issue is insufficient volts (which is likely given the rating of 4.8v you mentioned in comments).

i will try this when I'm home. You also may be right, what if I'm activating the wrong pin...Could it be that the PWM of the Uno (I've used D9/10) are different to the Nano?

Your code says d5. Regardless it's possible and I'd check that it flips from 0 to 5v and that current is drawn by solenoid.

I has the same problem. Example: With Arduino Uno only conected to 5V from PC, the servos run perfectly, but with Nano no, maybe the servos try to move, but not. I charged the skecth on the arduino Nano and deesconect form pc, and then i supply Arduino Nano with baterry Li-ion 2s. In another words, for servos you must to supply over 6 volts. Be careful because the max voltage of servos,can be 6 volts, you can use the regulator of Arduino, severals servos produce overheating in this regulator. Yes my english is noob.


text:
Is a solenoid piston strong enough to lock a water tubling?
My question is about hardware that i'll control with my arduino... Not Arduino itself (So I don't know if I'm in the right section ... :s)
My project is to create a cocktail machine at the cheapest price.
I was wondering if this kind of solenoid piston would be strong enough to seals a plastic pipe like this one ?
My idea from now is to use only 1 water pump (as this one) and connect all the pipes from the bottles with some Y and control which one is giving the liquid by controling pistons that are going to compress the tube.
I'm open to all advices you could give me and new ideas ... I saw that there's also solenoid valves ... But I only find it in 12V ... Does it exist in 5V ?

Unlikely at best. You should either use proper valves or consider a geared motor / servo (not a model one) to rotate a cam to compress the tube.

If you can't find what you want in 5V then you will need to control them with the correct voltage. It's not rocket surgery.

You'll crack the pipe.

The pump you are looking at is to powerful for you application: 350 liters/hour, or little less than 5 ltr/min. It will fill a 250 ml glass in about 3 seconds!
The solenoid cost you $5 a piece, but you still need a valve and a way to attach solenoid, valve and tubing.
Also, your idea means liquids will get mixed inside the tubes. And nobody wants a trace of whiskey in his Vodka Screwdriver.
You must visit The Inebriator, a cocktail mixing machine. His design have one tube for every bottle pouring liquid into the glass.

As they note, they have in version 2.0

Switching mixers from a pressurised system with valves to using pumps
  – This slows the pouring, but vastly simplifies the machine as a
  whole. We have a capacity for 16 pumps

They don't use valves, but pumps. I recomend a peristaltic pump ($7 on Aliexpress), like this:

They don't touch the fluid, easy to mount, and are a very precise delivery mechanism, like in this video https://youtu.be/GdTUIwj5ros, showing an Arduino controlling a pump to 1ml precision:

What do you mean by "they don't touch the fluid" ? Fluid pass throught it no ?
But is there some way to use only 1 pump ? (cause 1 pump cost almost 8~10$ ... And if I want 6 diffents bottles I'll need 6 pumps so ... )

@Seba99 the soft pipe gets squeezed so a pocket of fluid moves along that way pump internals don't need to be touched by the pumped medium.

No ! There's no mix "inside" the tubes ! I just don't want to make a little train that moves the glass ... Imo it's just complicated for nothinhg ! I just want all my tube coming in the same place where the standing glass is ... And then just choose which tube to "activate" But seem's like complicated and I'm going for six ( for now the idea is 6 bottles) peristaltics pumps...

But there's is 3V / 6V and 12V pump ... Which one should I take ? Can I use the 6V one on the 5V output of arduino ?


text:
connection for hall sensor 4 pin and arduino nano
I'm not from electronics background so I don't know what should be the connections. My Hall sensor has 4 pins(AO, GND, +, DO)
So, I have connected hall sensor pins to Arduino nano pins in this order(connection)
AO(Sensor) <-> A4(Arduino)   [Changed from A0 to A4]
DO(Sensor) <-> D4(Arduino)   [Changed from D0 to D4]
+(Sensor) <-> 5V(Arduino)
GND(Sensor) <-> GND (Arduino)

What should be pseudo code? So that if the magnet passes close to the sensor. Arduino should get the output & I'll blink the led on Arduino
This below is my code that I have written so far
int sensorPin = 4; // this is for sensor in analog pin 4
int buttonPin = 4; // we are looking for digital 4
int val;

bool flag = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(buttonPin, INPUT); // defines digital pin 4 as input for LED
  Serial.begin(9600);
}

void loop() {
   int reading = analogRead(sensorPin);

   float voltage = reading * 5.0;
   voltage /= 1024.0;

  if(voltage > 3.0) {
   Serial.print(voltage); Serial.println("volts");
  }
   val = digitalRead(buttonPin);  // read data from digital Pin

   if(val == HIGH) // when the sensor detects a magnetic field
   {
      flag = !flag;
      if(flag){
         digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      } else {                 // wait for a second
          digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      }
      //delay(1000);                       // wait for a second
   }
   delay(100);
}

Expected output: It should turn On/Off the LED when voltage goes HIGH
Known issues: It works sometime. It doesn't work sometime. Also it works only when magnet is kept clone. Doesn't detect when I'm waving magnet close to the sensor

I guess you might have a bouncing button.  Have a search for "debouncing a switch", there are lots of different solutions.  The magnet has nothing to do with the LED, the analog reading is not used to trigger the LED in this code.

The board you have has two outputs - AO and DO (note, those are the letter O not the number zero - for output).
You can connect AO to any of the analog inputs on your board if you want to read a discrete analog value from the sensor.
You can connect DO to any of the digital inputs (or analog ones since they are also digital inputs) if you just want a simple "Something is there" signal.
The sensitivity of the "something is there" is controlled by the trimmer on the board.
The simplest way of doing what you want is to use DO and adjust the trimmer to suit. Then the sensor looks, to all intents and purposes, like a switch or a button (but you don't need the pull up / pull down resistor).  So you can leave AO disconnected.
Note that using D0 (zero) and D1 (one) on the Arduino is discouraged since they are connected to the USB interface and using them can affect your ability to upload sketches. It also means you cannot use any serial communication in your program.

yes done also please see my code. It works & doesn't work. Can you tell me why this strange behaviour. Detection should be very quick right?

Not with a 100ms delay in there it won't be - it will be slow.

Someone will probably post a comment saying this is not a code writing service, but I get the impression that you just need pointers, so here they are.
In the IDE you have an example on how to blink the LED, called blink, if you haven't already make yourself familiar with that.
I think there is an example on how to read from the analog pin, if not its int value = analogRead(A0);
Now print that value to the Serial monitor and see what happens when you start waving the magnet around.  The value will change say for 400 odd to 800 odd.
Now write an if statement that turns on the LED when the value you read is greater than (>) a certain value.
If you need any help on the code you need to write look in the Help->Reference section of the IDE, you might find the Bold words especially relevant :)
If you get stuck, post the code of how far you have got and people will help.

Hi @CodeGorilla can you please verify my code & what's wrong with the code. It's not behaving as expected


text:
Make Sure Digital pin is high before Serial.write()
I have the following code for a TTL to RS-485 Adapter Module
[...code]
digitalWrite(DE_PIN, HIGH); //directional control for adapter
Serial2.write(Message, Size);
Serial2.flush();
digitalWrite(DE_PIN, LOW);  // Set To Recieve
Serial2_reading_foo();
[code...]

I've noticed that DE_PIN does not seem to go High fast enough before Serial2.write() executes I confirmed this by adding a small delay(ms) which made the code function perfectly.
digitalWrite(DE_PIN, HIGH);
delay(100);
Serial2.write(Message, Size);
Serial2.flush();
digitalWrite(DE_PIN, LOW);  // Set To Recieve
delay(100);
Serial2_reading_foo();

Unfortunately, there's pretty much universal agreement that you shouldn't ever use delay() in programming. Plus doing any kind of wait function here seems to be insensitive to the real problem. Is there a better way to make sure that DE_PIN==HIGH before the Serial2.write() Function begins?

Short delays are fine. Consider using delayMicroseconds() and tuning it for the minimum delay that achieves what you want.

what is the actual time interval you need? 0.1 s is pretty long for circuits.

I don't know the true interval. Is there any good way to get it mathematically, or is it just guess and check?

check the spec sheet of the module

I couldn't find the spec sheet, but with guess and check, 9ms seems to be the magic number. Is that about right?

How can you not find the spec sheet? It's the first hit in google for MAX485 - or you go to Maxim's website, look for the MAX485, and click on the datasheet. Anyway, the maximum time you should need is a mere 50ns. Do you have the DE and RE pins tied together?

The Arduino's IO pins, with no pin load, takes 10.4ns to rise to the 2V needed to register as a HIGH on the DE pin. One clock cycle on the Arduino is 63ns, which is longer than the propagation time for DE. No delay should be needed.

It sounds like the problem is elsewhere.  Try moving the same amount of delay elsewhere in the loop - maybe what you actually have is a serial message rate or pacing problem.  What is your success/failure verification - are you actually looking at the RS485 on a scope, or are you counting on the unspecified piece of connecting equipment to serially respond or behave in some way as a result??

The MAX485 requires 2V on the DE pin to register a HIGH. It takes no more than an absolute maximum of 50ns for the DE pin to switch the buffers. The Arduino takes 10.4ns for an IO pin to rise to 2V.
That's an absolute maximum of 60.4ns.
One clock cycle of a 16MHz Arduino is 63ns.
That is longer than it takes for the IO pin to tell the MAX485 to switch the buffers.
You can increase that rise time by taking in to account the input capacitance of the MAX485 and the resistance of the connection between the Arduino and the DE pin, but it will still be microscopically small compared to the time between the pin going HIGH and the serial transmission starting.
So there must be something fundamentally wrong with your setup.  Two possibilities spring to mind:

You aren't controlling RE, only DE, so RE is floating and is being capacitively linked to DE through the parasitic capacitances of the board and circuitry, making it rise and fall very slowly.
You haven't set the IO pin on the Arduino to OUTPUT, so it switches between floating and HIGH through a very high resistance, causing slow rise to HIGH and maybe never getting to LOW at all.

Or a combination of the two.


text:
New to Arduino building
I am new to Arduino an working with the Uno.  My dream is to activate servos in a perticular order once some type of sensor recognizes a live person near it.  Is their a perticular easy to understand book out there I can read?  There are lots and lots of books but they all get very complex rather quickly.  I'd be curious as to fellow inventors in here telling me how they mastered the Arduino?  Maybe it was not a book but rather a complete course.  Will others please respond to help me.  ps... I do have an electronics degree so I don't need soldering or component understanding.  I know what Vcc is.  I need please some type of course book which will take me now beyond the self blinking light into robotic control if that easy to understand book or course is out there.
Thank you.  Michael in Palm Beach, FL

There are lots of examples on the official Arduino website.
My advice is you follow them, not only by reading, but buy the components you need (they are cheap) and practice and see how to handle them within the Arduino environment.
Do one component at a time (led, switch, Servo, Sensor), and focus on the servo/sensors you want to use.
Than try to combine multiple components, step by step until you have your dream project ready.
Also, try not to just copy sketches (programs), but understand them. And than adapt them a bit, make variations on the component 'tests'.
I have a whole folder where I test each component with Arduino (and for some complicated components multiple sketches). Save them, and add links etc, so you can easily reference back to it.
You can use books, but there is so much information for the Arduino that this forum, the official web site and google should be enough to get you going.
(note: for the Arduino I did not use books, since as above said, there is so much information. I'm now diving in to STM32 which is more complex and a book/PDF is more convenient).


text:
How to detect if LED is switched on in external circuit using Arduino NANO?
I want to detect when an LED is powered on using an Arduino NANO. The LED is part of an external circuit. The LED uses about 1.8V. Would the circuit below allow me to detect when the LED is switched on? Is this the correct method of doing it? (The LED in the diagram represents the external circuit).

What's that component hiding under that blue wire on rows 6 to 10, column B, on the breadboard? (this is just for my benefit, I can't see it)

You could use A0 to sense the actual voltage or use an light-depended-resistor (LDR) to measure if the LED is lit (but take environmental light into account).

@KingDuken a pushbutton, one of the single row types. (Which is why schematics are usually preferred)

@KingDuken It's a push to connect button switch.

@Paul How would the circuit be setup to use A0 to detect the voltage? Would the above method also work?

I'm afraid your circuit does not work.
In fact, the base of the transistor is always connected to the power, regardless the LED being ON or OFF. Therefore the BJT would be always in the ON-state. Also a current limiting resistor in series to the LED is missing (but I think that it was just for sake of simplicity).
Assuming that:

you can mount in series something to the LED
an additional 1.3-1.5V voltage drop will not cause too much issues (to be short: if the external circuit power supply is "large enough", and if you will not be too much upset if the LED luminosity will be smaller).
You want to sense a signal LED, i.e. let's say with a current smaller than 20 mA.

Then, the safest way would be to use an optocoupler, such as 4N25-4N35. Put the LED of the optocoupler (transmitter side) in series to the LED you want to "sense", and use the phototransistor side to sense the LED status: it's emitter goes to the GND to your Arduino Nano, the collector to any input, with pull-up (The pull-up is mandatory!).
In this way, when current flows across the LED, it will also flow in the optocoupler LED, therefore the optocoupler phototransistor will be ON.
Also, using the optocoupler the two systems are electrically insulated each other (and you won't need to share the grounds).
Below you can find an example.

EDIT:
If you cannot wire the optocoupler LED in series (e.g. not enough voltage headroom because the power supply is too close to the LED Vf, or your LED is already on a PCB), you can connect the optocoupler in parallel.
Assuming the LED current is much larger than 1mA, you can use the following circuit. Choose RO so that the current flowing on the optocoupler will be 1mA (390-470 Ohm in your case). Usage of high current-transfer-ratio (CTR) optocoupler is suggested, but this might work also with a 4N25 or 4N35 (you'll be pretty close to the limit...)

Unfortunately I am unable to mount anything in series to the LED, only in parallel as it is on manufactured PCB.

Then you could connect the series of a 470-Ohm resistor and the optocoupler's LED in parallel to the LED you want to sense. When the LED is ON, there will be 1.8V across it. 1.4 V fall across the optocoupler's LED, and the remaining 0.4V across the 470-Ohm resistor. You'll have therefore 0.85mA into the optocoupler's LED, and assuming a 0.2 CTR (current transfer ratio) for the 4N35, you'll get 170 uA out of the collector. If the internal pull-up is something about 30k, that should be enough. Instead of 4N35, I suggest using a SFH618A, which is low-input current and has far higher CTR values.

Would this prevent the LED on the actual device from illuminating?

No, as you're not directly connecting in parallel the optocoupler's LED to your LED (this would prevent the original LED from turning on, as the optocoupler has a lower forward voltage than your LED). Instead, you're connecting the series "resistor + optocoupler's LED" in parallel to the LED you need to sense. Of course, the LED you need to sense will be a bit dimmer, as 850 uA will flow in the optocoupler's LED instead of the original LED. However I assume that the LED you're sensing is driven with a much higher current (5-20mA), so 850uA make little difference.

Edited the answer to include the parallel connection.

The answer depends on your definition of "on".
An led is on if

There is voltage across I th or
There insufficient voltage across it, or
There is current through it, or
It generates light output, or
It generates sufficient light output.

...
Based on each of the above, there is an answer to your question.

No, you will not detect the LED state at all, as your transistor base is connected to the target circuit's supply rail, not a switched node.
Additionally, your circuit risks burning out the LED as it lacks a current limiting resistor.
Speaking more generally, the only safe way to do this with a fully unknown circuit is to have an optical sensor looking at the LED.
If you can determine that it is safe to make an electrical connection to the circuit (ie, that the internal ground is not riding on mains voltage) and that the point of the circuit you want to measure is within an allowed voltage above that, then you can connect the grounds and measure the switched side of the LED / resistor.  But until you have far more electrical engineering experience, you are probably not in a position to make this safety determination.  Even battery powered devices can generate dangerous voltages internally.
It's important that you not connect between the LED and resistor, but rather to whichever side of that series unit is not connected to a supply rail, as the voltage drop on the LED itself may not be sufficient to register.
Certain fancier LED drivers may give you problems, for example if they regulator current internally.  Also, LEDs with PWM brightness control may require filtered polling, or even interrupts / hardware pulse-in.


text:
SIM800L and Arduino Sleep - getting whimsy Serial output after 5 calls
i'm working on project where i'm trying to achieve that arduino parse caller ID so i can use it later to send SMS with sensor reading data.
Somehow i made that code (with much googling) and it works great... But when i include arduino sleep part, it does work at beginning, but after i call SIM800 4-5 times with distinct of 30 seconds, i get unusable data on Serial, so i can't no longer parse correct number.
I tried many things, dropping baud rate to 1200, changing delay, but still i get strange characters after few calls.
Can anyone help me?
P.S. ATMEGA328P ic MCU
Thank you,
Matija
#include <SoftwareSerial.h>
#include <avr/sleep.h>

SoftwareSerial SIM800(8, 7);

String buffer1;
unsigned int current_millis = 0;
String phone;

void setup() {
     buffer1.reserve(200);
     phone.reserve(20);

     Serial.begin(19200); //
     SIM800.begin(9600);
     delay(1000);
     SIM800.write("AT\r");  // because of SIM800L autobounding mode
     delay(1000);
     SIM800.write("AT+IPR=9600\r");  // set baud at 9600, i tried with 1200
     and  other, and with autobauding but still got same problem
     delay(1000);
     SIM800.write("AT+CMGF=1\r");  // set SMS mode to text
     delay(1000);
     SIM800.write("AT+CNMI=2,2,0,0,0\r");
     delay(1000);
     Serial.print(SIM800.readString());
     SIM800.write("AT+CLIP=1\r\n");
     delay(1000);
     SIM800.write("AT+SGPIO=0,7,1,0\r");
     delay(1000);
     SIM800.write("AT+CSCLK=2\r"); //power saving mode of SIM800L
     delay(1000);
     current_millis = millis();
}

void loop() {
   // put your main code here, to run repeatedly:
   if (SIM800.available() > 0) {
      buffer1 = SIM800.readStringUntil('\n'); //Saving string then parsing
           caller number from it
      Serial.println(buffer1);
      parse();
      current_millis = millis();
      }

    if ((millis() - current_millis) > 10000) { //Putting atmega tu sleep
       sleepNow();
       delay(1000);// tried many delays
       current_millis = millis();
     }

 }

void parse() {
    if (buffer1.indexOf("CLIP:") > 0) {
        phone = buffer1.substring(buffer1.indexOf("+CLIP: ") + 8,
        buffer1.indexOf("+CLIP: ") + 21); //parsing caller number
        Serial.println(phone);
        SIM800.write("ATH\r"); //hang out phone call
        delay(500);
        SIM800.write("ATH\r");
        delay(500);
  }

}

void sleepNow() { //PIN CHANGE INTERRUPT ON PIN 7,8 BECAUSE SOFTWARE SERIAL
                   LIBRARY USE IT AND IT WILL WAKE UP ATMEGA
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set herethe
                                          sleep bit in the mcucr register
    sleep_mode();            // here the device is actually put to sleep!!
                         // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
    sleep_disable();         // first thing after waking from sleep: disable
                                sleep...
    }

With SoftwareSerial it's anyone's guess what may be going on. Add some extra Serial.println() calls with static text in them to work out if the fault is PC => Arduino or Arduino => SIM800.

Hi Majenko, error is between Arduino and SIM800 (i know because phone call isn't ATH when it should be). I tried your solution but it didn't work...
I tried also SIM800.end() and SIM800.begin(9600) before putting arduino to sleep...It doesn't work...
Only thing that work for me is reseting arduino after doing the job. Adding void(* resetFunc) (void) = 0;  after setup function, and call it resetFunc(); after i send message to caller.
Thank you,
if you have any idea which solves thing problem better post it here, maybe it will help someone.

Give AltSoftSerial a try, it's hands down superior.
Reset might work but it does not actually solve your problem, it just swipes it under the mattress. Also, have you considered ditching that String? It is the source of many problems regarding memory. You could relatively easily substitute it for an array of chars instead. Something like this, taken from example#2:
void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;

    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}

When you use sleep mode SLEEP_MODE_PWR_DOWN you're turning off all of the microcontroller's timers, Including the timer SoftSerial is using.  I expect that turning off and then when wake from sleep turning back on the timers is affecting the timing of your serial communications.
Try using SLEEP_MODE_IDLE instead of SLEEP_MODE_PWR_DOWN and see if it corrects the problem.


text:
Wifi with ESP8266 and Arduino sketches
I have a NodeMcu Lua ESP8266 ESP-12E which i want to use to control to a relais via Wifi network.
The first step was to write an Arduino Sketch which scans networks and connects to the network. However, even the standard example from the examples menu didn't work (c.f.,https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiScan/WiFiScan.ino) .
To rule out hardware problems I tried the LUA version from the list API doc (see below), which worked.
 -- print ap list
function listap(t)
      for k,v in pairs(t) do
        print(k.." : "..v)
      end
end

wifi.sta.getap(listap)

Using a firmware build from http://nodemcu.com/index_en.html
I gave the INO version another try and it seemed to work as well. However, it turned out it only works if the previous firmware has been the firmware from http://nodemcu.com/index_en.html
To I need to include a library or something ?
Thanks in advance,
Cafebabe

What is this "std example" you speak of? Also, you're asking us to help you for free but you won't even take the time to type out the full word "standard"? What is this "LUA version" you speak of?

you need to play with arduino esp8266's wifi.disconnect() to make sure the internal wifi settings are correctly initialized, the lua stuff  likely set them in a way that happened to work when you later re-uploaded your C++.

How can I check whether they are correctly initialised? A simple disconnect doesn't change anything. :(

I had no trouble running the Arduino .ino example in a nodeMCU 0.9.

(By googling) I figured out the problem and a work-around. But not an executable solution. The problem seems to be that the RF module is not properly initialised when the device is powered on or awakes from reset.
Sadly there seems to be no manual mode to switch on the RF module.
However, I found a workaround. First I made the connection to enable deep sleep, for that, we need to tie the RST pin to D0/GPIO 16 on the ESP8266.
Then I added the following code to setup
extern "C" {
  #include "user_interface.h"
}

void setup(){
  if (resetInfo->reason != REASON_DEEP_SLEEP_AWAKE) {

      ESP.deepSleep(10, WAKE_RF_DEFAULT)
  }

Basically whenever the system comes into setup from something else than deep sleep, the system goes to deep sleep and when powering back on the RF module is enabled.


text:
User configuration file does not exist or is not a regular file, skipping
I am facing issues while uploading sketch to Adafruit Feature 32u4 Bluefruit LE devices. When i try to upload Blink demo it was working fine and my device also blinking, But bellow error i am getting every time when i upload sketch.
   System wide configuration file is "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf"
     User configuration file is "/Users/myMacmnin/.avrduderc"
     User configuration file does not exist or is not a regular file, skipping

I am using Adafruit Feature 32u4 Bluefruit Le device,Arduion 1.8.3 version, MacMini with macOs Sierra(10.12.3).

That's not an error. That's just mentioning that you don't have a custom configuration file (which not many people do have) and it doesn't care.

Are you actually experiencing a problem, or are you just moaning that avrdude is printing messages?

Actually i am trying to uploading Neopixel sketch , I am getting this error, and nothing happen in device side. If you know anything about this please help me.

Select the right port? As I say, that's not an error. If you're not getting anything else out of it then you should maybe look at the debugging output and for the command being run and make sure that it's all correct.

Yes i selected correct Port,Board and programmer and i fallow Adafruit app for uploading sketch.

Finally i found answer for my question, It happen because of uploading sketch in selected pin.
// Neopixel
//#define PIN            6   /* Pin used to drive the NeoPixels */
#define PIN            13   /* Pin used to drive the NeoPixels */

I Changed Pin 6 to 13 , it's worked for me.


text:
Flashing ESP8266 over WiFi whith samrtphone?
I'm working on a project in which an ESP8266 is the brain of the device. I want to add new features to the device controller later but this requires that the user open the controller and reprogram the ESP8266.
I want the user to be able to update the firmware with his smartphone (maybe through an application). How can I do that? Is this possible with this chip?

yes, you can use an http POST to push in a new firmware, look at the OTA examples

ESP8266 OTA can be performed through a web browser as detailed in the ESP8266 OTA information page.
Since a smartphone has a web browser I can see no reason why you can't use that.