text:
Atmega 328p at 3.3v : Internal vs external oscillator
I am currently working on a pcb that uses smd atmega 328p (au).
I will be powering it through a lipo battery and a ldo regulator for 3.3v input. I am using the multiwii flight controller code.
I know that atmega runs at 8mhz at 3.3v and 16mhz at 5v without overclocking the chip.
The question is that should I use the internal 8mhz oscillator or external 8mhz?
I will definitely make the chip more accurate as given in some forums but still does this effects anything or not?

How much accuracy do you need for your project and is the internal oscillator accurate enough for this goal?

I'm guessing you have an unstated concern. I doubt it's power usage, since you're talking about a flight controller.  If you say what it is you'll probably get more useful answers.

If the 8 MHz oscillator is off by a handful of percentage points, it will affect timing measurements you make using millis() and micros(). It could affect the baud-rates of Serial or SoftwareSerial. If these are not of any concern, the only remaining difference would be how fast your code can be executed. It's unlikely that the code pushes the chip runs so close to its maximum capability that it would matter, even at ~8 MHz.
Update:

... I just want to know if clock frequency effects the code and if I need
to change code a bit like for example blink sketch runs at different
time intervals on 8mhz and 16mhz(I tested it).

If you do nothing else, then yes, millis() will appear to run at half speed. You need to add a board definition to the IDE for an Arduino Uno running at 8 MHz. Then millis() and micros will be adjusted for the slower processor clock. How you do this depends on whether you choose the internal and less accurate 8 Mhz oscillator, or an external 16 MHz crystal.
For the internal oscillator, there is a board-definition on Github with instructions to load it into your IDE.
For an external oscillator, this article describes how to select the board type as "Arduino Pro or Pro Mini" and then be able to select the board frequency, using the Tools menu twice.

I don't know how much accuracy I need for this purpose but I know that the project will use i2c protocol  for mpu6050 accelerometer and communication through nrf24l01 . I m a noob at coding but I just want to know if clock frequency effects the code and if I need to change code a bit like for example blink sketch runs at different time intervals on 8mhz and 16mhz(I tested it).

Thanks Robert for the answer . I will look forward for both internal and external oscillator


text:
Storing IR Sensor value not working
This is my first time working on Arduino for my project and I ran into an issue. I'm trying to make a very simple Vending Machine. Coin or any obstacle passes in front of the IR sensor and based on that, the user can either press button 1 or 2 and based on that motor 1 or 2 would run respectively.
The overall logic works exactly how I want it to, the issue I'm facing is that the variable (sensorStatus) storing the IR sensor value isn't working correctly. Whether anything passes in front of it or not, it lets me press the buttons anyways and the motor starts working.
void loop() {

  int sensorStatus;

  //this is where im having the issue
  if (digitalRead(inSensor) == LOW) sensorStatus = LOW;

  if(sensorStatus == LOW) {
      buttonStatus1 = digitalRead(inButton1);

      if(buttonStatus1 == HIGH) {
        digitalWrite(relayControl1_1, LOW);
      } else {
        digitalWrite(relayControl1_1, HIGH);
      }

      buttonStatus2 = digitalRead(inButton2);

      if(buttonStatus2 == HIGH) {
        digitalWrite(relayControl2_1, LOW);
      } else {
        digitalWrite(relayControl2_1, HIGH);
      }

      sensorStatus = HIGH;
   }
}

If I don't use this logic and store the value of the sensor directly into the variable (sensorStatus), the whole program seems to be working till I have an obstacle in front of the sensor continuously. I don't want this to happen, I want it to work in such a way that once an obstacle passes in front of the sensor it keeps the value (even after the obstacle is gone) until a button is pressed and after that, it gets rid of the value to repeat the process once again. It seems to be a code logic issue but I can't seem to figure out the logic behind it.
My Complete Source Code:
const int relayControl1_1 = 13; // relay 1 of 1 (input 1)
const int relayControl1_2 = 12; // relay 1 of 2 (input 2)
const int relayControl2_1 = 11; // relay 2 of 1 (input 3)
const int relayControl2_2 = 10; // relay 2 of 2 (input 4)

const int inButton1 = 9; //input button 1
const int inButton2 = 8; //input button 2

int buttonStatus1 = 0;
int buttonStatus2 = 0;

const int inSensor = 7;

void setup() {
  Serial.begin(9600);
  pinMode(relayControl1_1, OUTPUT);
  pinMode(relayControl1_2, OUTPUT);
  pinMode(relayControl2_1, OUTPUT);
  pinMode(relayControl2_2, OUTPUT);

  pinMode(inButton1, INPUT_PULLUP);
  pinMode(inButton2, INPUT_PULLUP);

  pinMode(inSensor, INPUT_PULLUP);

}

void loop() {

  int sensorStatus;

  //this is where im having the issue
  if (digitalRead(inSensor) == LOW) sensorStatus = LOW;

  if(sensorStatus == LOW) {
      buttonStatus1 = digitalRead(inButton1);

      if(buttonStatus1 == HIGH) {
        digitalWrite(relayControl1_1, LOW);
      } else {
        digitalWrite(relayControl1_1, HIGH);
      }

      buttonStatus2 = digitalRead(inButton2);

      if(buttonStatus2 == HIGH) {
        digitalWrite(relayControl2_1, LOW);
      } else {
        digitalWrite(relayControl2_1, HIGH);
      }

      sensorStatus = HIGH;
   }
}

Make sensorStatus static and give it a default value?

It does seem to stop it from taking garbage value and making it not work without input from sensor by setting it as static int sensorStatus = HIGH; but it stops it from how I want it to work. I want it to be able to store the value until I press the buttons for the motor even if the obstacle from the sensor is gone. Setting it as static ends up making it only work as long as I have an obstacle in front of the sensor, once the obstacle is gone it seems to lose the value.

So change the sensorStatus back to HIGH only when a button is pressed?

I set sensorStatus to HIGH right after the digitalWrite(relayControl1_1, HIGH); in the else part of the buttonStatus conditional statements. It seems to work this way but the motor keeps on working until I interrupt it by putting an obstacle in front of the IR sensor. I fixed it by adding delay(2000); digitalWrite(relayControl1_1, LOW); after it and it works exactly how I want. Thanks a lot for the help, kind stranger.

@Majenko can you post your comment as an answer so the OP can accept it? As it is now, I had to read the question and 4 comments to figure out that the problem has already been solved.

I posted the answer but I can only accept it as the answer after 2 days.

Thanks to the help from @Majenko♦ I was able to fix the issue.
1 - int sensorStatus; should have been set to static int sensorStatus = HIGH; to make the program remember the value of the sensor.
2 - sensorStatus = HIGH; should have been right after digitalWrite(relayControl1_1, HIGH); in the buttonStatus conditional else part to make the program set the sensorStatus back to HIGH correctly.
3 - Unrelated to the question posted, doing the above steps made the program run the motors continuously unless they were stopped by an obstacle from the IR sensor. This was fixed by adding delay(2000); digitalWrite(relayControl1_1, LOW); after the sensorStatus = HIGH; mentioned in the 2nd step.
Source Code after fixing:
const int relayControl1_2 = 12; // relay 1 of 2 (input 2)
const int relayControl2_1 = 11; // relay 2 of 1 (input 3)
const int relayControl2_2 = 10; // relay 2 of 2 (input 4)

const int inButton1 = 9; //input button 1
const int inButton2 = 8; //input button 2

int buttonStatus1 = 0;
int buttonStatus2 = 0;

const int inSensor = 7;

void setup() {
  Serial.begin(9600);
  pinMode(relayControl1_1, OUTPUT);
  pinMode(relayControl1_2, OUTPUT);
  pinMode(relayControl2_1, OUTPUT);
  pinMode(relayControl2_2, OUTPUT);

  pinMode(inButton1, INPUT_PULLUP);
  pinMode(inButton2, INPUT_PULLUP);

  pinMode(inSensor, INPUT_PULLUP);

}

void loop() {

  static int sensorStatus = HIGH;

  if (digitalRead(inSensor) == LOW) {
    sensorStatus = LOW;
  }

  if(sensorStatus == LOW) {
      buttonStatus1 = digitalRead(inButton1);

      if(buttonStatus1 == HIGH) {
        digitalWrite(relayControl1_1, LOW);
      } else {
        digitalWrite(relayControl1_1, HIGH);
        sensorStatus = HIGH;
        delay(2000);
        digitalWrite(relayControl1_1, LOW);
      }

      buttonStatus2 = digitalRead(inButton2);

      if(buttonStatus2 == HIGH) {
        digitalWrite(relayControl2_1, LOW);
      } else {
        digitalWrite(relayControl2_1, HIGH);
        sensorStatus = HIGH;
        delay(2000);
        digitalWrite(relayControl2_1, LOW);
      }
   }
}

couple of observations ... it appears that your code does not work as described ... you said obstacle passes in front of the IR sensor ... your code never checks for obstacle passing sensor, it only checks for obstacle blocking sensor ....... the program line digitalWrite(relayControl1_1, LOW); gets called regardless of the state of buttonStatus1 ... put digitalWrite(relayControl1_1, LOW); after the if block .... same kind of thing in the other if block

the code would be clearer if sensorStatus was boolean named coin or paid

source: Stack Exchange

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

sort: votes


text:
Which board's bootloader is on the microcontroller?
Currently I'm doing a project that needs an Atmega2560 standalone MCU. After I burned the bootloader with this method: http://www.gammon.com.au/bootloader . I set the Board as "Arduino/Genuino Mega or Mega 2560" and the Processor as "ATmega2560 (Mega 2560)". But, it just stuck at "uploading" and this message pop up: "avrdude: stk500v2_ReceiveMessage(): timeout". So, I'm guessing I'm choosing a wrong board. Is there a way to check which board to select in the Tool tab?

Do you have DTR connected via 0.1uF cap to create a Reset and start the bootloader code looking for a serial download?

It depends on which bootloader you loaded, when you write your bootloader with AVRDude you specify the hex file, Which Hex file did you specify?

I burned through this method: http://www.gammon.com.au/bootloader and I haven't use any Hex File with this method.

Nick Gammon's sketch for loading a bootloader holds 10 different bootloaders. The actual bootloader that is burned depends on the detected signature of the board being programmed. If this went well the following bootloader should have been programmed "Atmega2560 with fixes for watchdog timer problem (8192 bytes)". With Nick Gammon's sketch you can also verify the existing bootloader. Dit you try that?

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


text:
Issue with analog readings on Arduino atMega with YL-69 moisture sensors
I've connected four YL-69 sensors to my arduino at-mega2560 on analogs pins 0-3. This is combined with four DHT11 sensors that are in digital pins.
The DHT work fine, and I can work one YL-69 moisture sensor that gives correct readings.
But when I connected the others, the readings are just 100% for all. I'm sure I must have made a mistake in my code somewhere, just can't spot it.
I've posted the sketch I use below, and the results from serial monitor.
(BTW i added a short delay of 10ms between each reading thinking that may be the issue, but it had no effect).
Serial Monitor:

Sketch:
#include "DHT.h"
#include <SPI.h>        // Include SPI library (needed for the SD card)
#include <SD.h>         // Include SD library

File dataFile;

#define DHTPIN0 10     // what pin we're connected to
#define DHTPIN1 11     // what pin we're connected to
#define DHTPIN2 12     // what pin we're connected to
#define DHTPIN3 13     // what pin we're connected to

// Uncomment whatever type you're using!

#define DHTTYPE DHT11   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// How to connect sensors
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht0(DHTPIN0, DHTTYPE);
DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
DHT dht3(DHTPIN3, DHTTYPE);

int output_value ;
int output_value1 ;
int output_value2 ;
int output_value3 ;
int output_value4 ;

unsigned long time;

void setup() {
 Serial.begin(9600);
 while (!Serial)
    ; // wait for serial port to connect. Needed for native USB port only
  Serial.print("Initializing SD card...");
  if (!SD.begin()) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");
 Serial.println("DHTxx test!");
 dht0.begin();
 dht1.begin();
 dht2.begin();
 dht3.begin();
 delay(2000);
}

uint16_t line = 1;

void loop() {
 // Reading temperature or humidity takes about 250 milliseconds!
 // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
 float h0 = dht0.readHumidity();
 float h1 = dht1.readHumidity();
 float h2 = dht2.readHumidity();
 float h3 = dht3.readHumidity();
 float t0 = dht0.readTemperature();
 float t1 = dht1.readTemperature();
 float t2 = dht2.readTemperature();
 float t3 = dht3.readTemperature();

 dataFile = SD.open("DHT11Log.csv", FILE_WRITE);
 //  if any result below is NaN (not a number) then something went wrong!
 if (dataFile) {
   output_value= analogRead(A0);
   delay(10);
   output_value1= analogRead(A1);
   delay(10);
   output_value2= analogRead(A2);
   delay(10);
   output_value3= analogRead(A3);
   delay(10);
   output_value4= analogRead(A4);
   output_value = map(output_value,1024,0,0,100);
   output_value1 = map(output_value,1024,0,0,100);
   output_value2 = map(output_value,1024,0,0,100);
   output_value3 = map(output_value,1024,0,0,100);
   output_value4 = map(output_value,1024,0,0,100);
   Serial.print("Moisture : ");
   Serial.print(output_value);
   Serial.println("%");
   Serial.print(output_value1);
   Serial.println("%");
   Serial.print(output_value2);
   Serial.println("%");
   Serial.print(output_value3);
   Serial.println("%");
   Serial.print(output_value4);
   Serial.println("%");
   Serial.print("Humidity  : sensor 0, ");
   Serial.println(h0);
   Serial.print("  sensor 1, ");
   Serial.println(h1);
   Serial.print("  sensor 2, ");
   Serial.println(h2);
   Serial.print("  sensor 3, ");
   Serial.println(h3);
   Serial.println(" %\t");
   Serial.print("temperature  : sensor 0, ");
   Serial.println(t0);
   Serial.print("  sensor 1, ");
   Serial.println(t1);
   Serial.print("  sensor 2, ");
   Serial.println(t2);
   Serial.print("  sensor 3, ");
   Serial.println(t3);
   Serial.println(" %\t");
   dataFile.print(line++);
   dataFile.print(":    Temperature = ");
   dataFile.print(",");
   dataFile.print(t0);
   dataFile.print(",");
   dataFile.print(t1);
   dataFile.print(",");
   dataFile.print(t2);
   dataFile.print(",");
   dataFile.print(t3);
   dataFile.print(",");
   dataFile.print("°C,    Humidity = ");
   dataFile.print(",");
   dataFile.print(h0);
   dataFile.print(",");
   dataFile.print(h1);
   dataFile.print(",");
   dataFile.print(h2);
   dataFile.print(",");
   dataFile.print(h3);
   dataFile.print(",");
   dataFile.println("%");
   dataFile.print(",");
   dataFile.print("Moisture : ");
   dataFile.print(",");
   dataFile.print(output_value);
   dataFile.print(",");
   dataFile.print(output_value1);
   dataFile.print(",");
   dataFile.print(output_value2);
   dataFile.print(",");
   dataFile.print(output_value3);
   dataFile.print(",");
   dataFile.print(output_value4);
   dataFile.close();

  }
  // if the file didn't open, print an error:
  else
    Serial.println("error opening DHT11Log.txt");
    delay(10000);
}

Those YL-69 moisture "sensors" are not reliable at all. There is a voltage on the metals in the soil. They will maybe work for hours or days or weeks, and then you have to look for something better.

I think that the problem is here:
output_value = map(output_value,1024,0,0,100);
output_value1 = map(output_value,1024,0,0,100);
output_value2 = map(output_value,1024,0,0,100);
output_value3 = map(output_value,1024,0,0,100);
output_value4 = map(output_value,1024,0,0,100);

replace them with:
output_value = map(output_value,1024,0,0,100);
output_value1 = map(output_value1,1024,0,0,100);
output_value2 = map(output_value2,1024,0,0,100);
output_value3 = map(output_value3,1024,0,0,100);
output_value4 = map(output_value4,1024,0,0,100);

Thank you so much! I didn't spot that at all, I will update my sketch tomorrow, i'll post back here if it all works ok.                                                                                Thanks again

@Paddy You’re welcome! Please, If I helped you, remember to mark question as resolved. :)

Tested it there, and it works a treat. I'll now mark this as solved. Cheers!


text:
What is the difference using library of SoftwareSerial.h and ESP8266WiFi.h?
What is the library I should use to upload the sensor data (ultrasonic and Infrared sensor) to the localhost server.
Because I saw some of the online resources using ESP8266WiFi.h library for the ESP01 and some of resources use the softwareserial.h library. So, what is the difference between these two libraries?

one uses wifi ... the other is to create a second, software driven serial port - which is basically useless on an ESP01 because it has like 2 gpio's

The SoftwareSerial is used to communicate with the esp8266 from other MCU. The ESP8266WiFi library is for Arduino sketch running in esp8266.
The esp8266 can be used with firmware as 'network adapter' for your sketch running for example in Arduino Uno. MCU in Uno has only one hardware Serial which is used to communicate with the computer over USB (to upload and use Serial Monitor). To communicate with the esp8266 usually a second Serial interface is created with SoftwareSerial.
But esp8266 can be used as Arduino board with "esp8266 Arduino core". This 'core' contains Arduino libraries to access the WiFi functions of the esp8266 from a sketch running in esp8266.


text:
Syntax of binary Constants
I was trying to compile some Arduino code on the PC for testing when I noticed some strange syntax for numerical binary constants.
Convetion seems to be to declare them like so:
    static const uint8_t smiley[] = {
        B00111100,
        B01000010,
        B10100101,
        B10000001,
        B10100101,
        B10011001,
        B01000010,
        B00111100 };

However, when I try to compile this with g++ I get

error: ‘B00111100’ was not declared in this scope

Now when I exchange this for B for the standard C/C++ prefix 0B it works, but I don't want to change the code that I want so simulate!
Is there some clever macro magic at play here?

There is a file (binary.h) with every possible permutation of number between 0 and 255 represented as binary in it. They're stored as C-preprocessor macros:
#define B0 0
#define B00 0
#define B000 0
#define B0000 0
#define B00000 0
#define B000000 0
#define B0000000 0
#define B00000000 0
#define B1 1
#define B01 1
#define B001 1
#define B0001 1
#define B00001 1
#define B000001 1
#define B0000001 1
#define B00000001 1
#define B10 2
#define B010 2
#define B0010 2
#define B00010 2
#define B000010 2
#define B0000010 2
#define B00000010 2
... etc ...

Quite why Arduino decided to do this is anyone's guess.  It makes, as you have seen, for non-portable code.
Personally, I never use (and would never recommend any one else should use) those macros, and instead use the GCC standard binary literal representation 0b.....

1/2 a christmas tree ... lol

The reason they did that is because GCC didn't have the binary representation when Arduino got started. Now the macros still need to be there in order to avoid breaking old code written using them. At this point, I do agree that people should be using the standard binary representation. Yes, there are ancient IDE versions where that code won't compile, but you can only go so far with backwards compatibility.

@jsotola Half a Christmas binary tree ;)


text:
Lowest latency triggering multiple Arduinos using NRF24L01+
I'm building a rig with multiple DSLR cameras.  I need to synchronize the cameras to take a photos with lowest possible latency.  The only constraint is we want the ability to address each camera individually if needed.
I've seen in other posts:
Choosing wireless tech for lowest possible lag
NRF24L01+ seems to be a good choice.  An answer on that post states:
sending a 32 byte payload...283µs on 2Mbps mode.
Given the  esp8266 has a clock speed of 80MHz/160MHz I'm not too concerned about the lag involved in processing the signals.
Most multi-cast information out there is for sensor arrays, so multiple out single in.  I'm after resources on single out multiple in for NRF24L01+ networks.
Added bonus of esp8266 is that non timing critical tasks such as logging and error checking could be performed over wifi so NRF24L01+ would be purely for one -way triggering.
If each camera had it's own esp8266 based board with attached NRF24L01+ hardware and was given an address in software from 0-255, is it possible to broadcast a single 32 byte packet of data where each bit would represent a camera address and have all receiver devices receive the same signal, do an AND against it's address and trigger if needed?

From another answer to a similar question they mentioned the NRF24LE1 module.  Basically a programmable NRF24L01+.  I wonder why this never took off?  Seems super useful for simple triggering/data collection.

Yes, that should work, however also think about the following issues:

What if one (or more) camera does not receive the signal? You might need to add an ACK signal, but of course this will reduce the latency (a lot). If you don't want an ACK signal
To prevent an ACK, you can send the signal many times (and cameras who already processed the signal not react for a fixed amount of time). Of course it will received by the other cameras (at least) 283 us later.
If reliability is important, you could try using a less high speed, the latency will go up, but reality too.

Also you probably can fire the cameras even faster, if you first send the address bytes (4 bytes). And than send the shoot signal which can be in principle 1 bit. You can use one of the bits for that in case 128 cameras would suffice. Or send one byte extra which contains the signal to shoot.

Thanks!  So to get this working from a hardware POV all I need to do is make sure all receiver NRF24L01+ are using the same channel/address (not my software address) and disable auto acknowledge?  Good idea about splitting address and command.

Also, since configuring each receiver over wifi is not timing critical, are there any other simpler interfaces such as 433/900MHz?

I never worked with 433/900 MHz. I think you probably can better send the 'shoot' signal multiple times instead of a (complicated) ACK protocol. I think the protocol itself will not change if you use another frequency.


text:
AT Commands HM10 BLE Module - Not working
I got the ble module to work fine following online guide. However when i changed the baud rate: AT+BAUD1 which changed to 19200 however ever since i was not able to get at commands to work.
tried: arduino nano, FTDI programmer, software serial, normal tx, rx
#include <SoftwareSerial.h>

SoftwareSerial BTSerial(8,9); //RX|TX

void setup(){
  Serial.begin(9600);
  BTSerial.begin(9600); // default baud rate
  while(!Serial); //if it is an Arduino Micro
  Serial.println("AT commands: ");
}

void loop(){
  //read from the HM-10 and print in the Serial
  if(BTSerial.available())
    Serial.write(BTSerial.read());

  //read from the Serial and print to the HM-10
  if(Serial.available())
    BTSerial.write(Serial.read());
}

If you set it to 19200, why are you using 9600?

You changed the baud rate that the Bluetooth module uses to communicate with your Arduino but you forgot to change the baud rate that the Arduino uses to communicate with the Bluetooth module. These must match. From consulting the SoftwareSerial library's reference page, you can see that is set by this line of your code:
BTSerial.begin(9600)

That sets the software serial communication rate at 9600 baud. You need to change it to this:
BTSerial.begin(19200)

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


text:
Accesing the USART registers by Arduino
I'm having a hard time understanding how the Arduino libraries are defining the address for accessing the registers of the USART modules.
I cant find definition for udr(pointer) as used in the delegated constructor for Hardware Serial. So how does the class gets the underlying address? And what type of declaration is this?
HardwareSerial::HardwareSerial(
  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
  volatile uint8_t *ucsrc, volatile uint8_t *udr) :
    _ubrrh(ubrrh), _ubrrl(ubrrl),
    _ucsra(ucsra), _ucsrb(ucsrb), _ucsrc(ucsrc),
    _udr(udr),
    _rx_buffer_head(0), _rx_buffer_tail(0),
    _tx_buffer_head(0), _tx_buffer_tail(0)
{
}

It is handed the addresses when the object is constrcted:
 HardwareSerial Serial(&UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR);

&UDR is passed as *udr. That is then assigned to _udr in the initialiser list.

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


text:
Arduino not working on external power supply
First of all, my Arduino Uno R3 isn't genuine.
At some moment when I was playing with it, the Arduino stopped working. It was connected to a external 12V power supply on the 2.1mm plug. A single digital output was connected to a base of a BJT, which was being used as a switch. I checked all the voltage differences and amount of current around the BJT with my multimeter, and I made sure nothing ever exceeds the maximum rating.
One thing, I had a jumper wire connected to the 5V, and it might have accidentally got shorted with GND while poking around.
Currently, the Arduino won't start up when given external power supply soley, be it a 2.1mm plug or VIN pin. The ON light is not on. I tried to measure the current it consumes, but the value from the multimeter changes when I switch the measure range -- I suppose this is because the current is so small that the so-small resistance of the multimeter affects the current. The 5V pin, when connected to GND through a 1K ohm resistor, says about 50 mV.
However, when the USB is connected, the board works alright, regardless of whether external power supply is connected. The 5V pin says quite 5V, but I see from the schematic of Uno Rev. 3 that it is in fact just pulled from the USB power line, so it does not mean that the internal transformer circuitry is alright. When the USB gets disconnected while the USB and the external power supply is both connected, the board immediately turns off.
Am I good to regard this board as dead in some way? What do you think is broken?
And could there be any way to resusticate it?

what is the output voltage of the power supply?  .... there may be a fuse. where did you buy the board? is there a schematic on the website?

@jsotola Power supply gives 12V. I bought it from an online domestic(Korean) electronics shop. There are no other resources but that it is made in China, and it is functionally identical to the genuine Arduino board (ha!).

can you post a link to the online store? i would like to see a picture of the board

By shorting 5V to GND you have blown the 5V regulator on the board. Buy a new board unless you like reworking SMD components.

You probably have shorted 5V to the Ground and it broke the voltage regulator on the Arduino. You should by a new one. Original one have more security than non genuine and they are not expensive.


text:
boolean always false after 32 seconds
I have a boolean expression (I think it's called), and it will always return false after 32 seconds of running, and I'm very confused now.
if (millis() > stepTime+lightCmd[stepe][5]) {
  stepe = (stepe+1)%STEPS; //I'm bad at naming variables, sorry
  stepTime = millis();
  Serial.println("changing"); // debugging
}

This runs inside the main loop.
Also, I've tried using an exponent when trying to get some lights to appear to fade linearly and in about the same amount of time, 32 seconds, it would start fading in reverse.
EDIT:
millis(); wouldn't go backwards after it stopped working

Use the https://www.arduino.cc/en/tutorial/BlinkWithoutDelay example. You should not compare millis to a value and you should not add something to the millis value. If you have a problem, please provide a full working sketch, so we can test it.

@Jot please turn your comment into an answer.

Is stepTime an unsigned long ?

no, it's an integer, it's the same as previousMilliseconds in the blink without delay, link on first comment

@Jot I tried doing something similar to the example, but it seems to be returning true once it gets to 32 seconds, I'm going to look more carefully at the example

You code is nothing like the blink without delay. There is a specific way to use millis: "the current millis" - "a previous millis value" >= interval. And the current millis and the previous millis must be a "unsigned long". The current millis can also be a call to millis() of course. An integer? And the 32 seconds is perhaps 32767 milliseconds?

@Jot ok, I was going to try making stepTime an unsigned long just now, so thanks!

When you add a value to 'stepTime' and still use the '>' with millis, then you still have the rollover problem.

Glad you got it working. Just note that millis will overflow after about 50 days. So if you project has to run longer that that, the if-statement will fail after 50 days.

@Gerben I won't need to run it nearly that long, so it won't be a problem.


text:
Can 2 or more LED strobe Lights Flash in Sync?
I'm trying to build a strobe light that has at least 1 mode that can sync with another unit.
The strobe light has 2 colors, white and red which are driven by 2 qlite drivers which are controlled by an ATtiny13a processor.
The strobe light will be used on an ultralight aircraft. I want the ability to have the lights sync, so if there are a few aircraft flying, each strobe would be in sync and creating a better chance of being seen as a collective.
The easiest way to see this is from obstruction lights on windfarms. https://www.youtube.com/watch?v=bb7MWrBEZjU  They are mandated by FAA to be in sync. I believe they achieve this by matching internal processor clock speeds with the GPS clock data.
Or could I use a Real Time Clock to time the processors together?
If I'm already using Qlite flashlight drivers which use ATtiny13 chips, is there any way I can get the different lights to sync?
The body is a standard flashlight body.

Thanks in advance,

Using the 1PPS output of a GPS receiver seems to be the easiest way, just make sure to use an integral flash frequency.

Thank you! So would the GPS module interface my existing ATtiny13 processor via the 1PPS or would I need something else? Forgive my ignorance. Does the strobe pattern need to be simple flashes or would it be possible to sync any flashing pattern? Thanks again for your comment

Depends on whether the GPS modules need live interaction or if they can be preprogrammed to find satellites and output the signal. Any pattern, integral frequency.

Ah gotcha, so I'll need one that can connect automatically and send the pulse.

Something like this https://www.sparkfun.com/products/14239

"The S1315F performs all the necessary system initialization, satellite signal acquisition & tracking, data demodulation, and calculation of navigation solution autonomously." Sounds like it should do.


text:
Is it possible to use extra AVR Flash memory as non-volatile EEPROM-like Flash memory storage?
In STM32 microcontrollers it is possible to use a technique that ST calls IAP, or In-Application Programming, in order to write to the Flash memory from your running application. They even have a nice Application Note (ex: AN2594) to describe a really ingenious way to use two Flash memory pages to emulate EEPROM while using "wear-leveling" to reduce Flash memory wear during erase cycles.
I have wondered for years: can AVR do this? Ex: the ATmega328 mcu in the Arduino Uno, Nano, etc--can you write code to store data from your application into Flash memory, thereby increasing non-volatile storage space for data acquisition for instance?
If so, can you please point me to some resources or examples, including example code, reference manuals or datasheets, etc, that might help me implement this? I've done some looking in the datasheet and haven't found anything so far but maybe I'm just not looking hard enough or know well enough what I'm looking for.

The answer is "yes, you can use extra AVR Flash memory as non-volatile EEPROM-like Flash memory storage, very similar to an STM32 microcontroller."
One of these days I'm going to write an Arduino library to make this really easy for the beginner. For now, however, I'm going to simply post links to valuable references that contain the full answers and that I still need to thoroughly study myself.
Documentation on how to implement Flash memory reading/writing:
-This is frequently called "self programming" by Atmel (now owned by Microchip).
To find these resources I went to the main ATmega328 reference page then clicked the "Documentation" link, then I searched the web page for the word "flash".
Here's what I found (in order of importance--most pertinent references first):

AVR106: C functions for reading and writing to Flash memory on tinyAVR and megaAVR devices

"Description: This application note provides C functions for accessing the Flash memory using the Self programming Program memory which allows to reprogram the Flash memory during program run."
"Introduction: The Atmel® AVR® devices have a feature called Self programming Program memory. This feature enables an AVR device to reprogram the Flash memory while executing the program. Such a feature is helpful for applications that must self-update firmware or store parameters in Flash. This application note provides the details about the C functions for accessing the Flash memory."
This Application Note contains source code, including with the following ready-to-use C functions:

ReadFlashByte()
ReadFlashPage()
WriteFlashByte()
WriteFlashPage()
RecoverFlash()

AVR105: Power efficient high endurance parameter storage in tinyAVR and megaAVR devices Flash memory
AVR116: Wear Leveling on DataFlash
Atmega328 datasheet

Section 30: Boot Loader Support – Read-While-Write Self-programming (BTLDR), p. 328-344.
As pointed out by user SDF in his answer, especially pay attention to Section 30.8: Self-Programming the Flash, p. 334-342.
Also see Section 12.2: In-System Reprogrammable Flash Program Memory, p36
And Section 31.6: Page Size, p. 349.

Yes you can. This Arduino IDE add on lets you make calls to code store in the bootload of memory so you can make changes to the flash memory.
https://majek.sh/en/writing-to-internal-flash-on-arduino/
The number of times you rewrite a cell are limited.
I'd suggest you are better off with adding a FRAM memory chip.
Get a 5V part with SPI interface. Fast reads, virtually unlimitless writes (trillions)
https://www.digikey.com/products/en/integrated-circuits-ics/memory/774?k=fram+memory&k=&pkeyword=fram+memory&pv276=15&FV=ffe00306%2C1f140000%2C1fec000b&quantity=0&ColumnSort=0&page=1&stock=1&pageSize=25

Take a look at section 30.8 in the datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf
It has all the information to reprogram the bootloader section of the flash during runtime.
The bootloader partition size can be adjusted as well.

I'll take a look. What about the rest of the Flash? STM32 allows you to use any part of the flash to write in during runtime, rather than limiting you to one dedicated  part of Flash.

In STM32 You can even move your program to RAM and then erase the Flash you just copied from, for instance--not that I'd want to do that though, it just demonstrates the versatility I'm seeking to find out about for AVR.


text:
max current while using a shift register
In arduino's official page about ShiftOut https://www.arduino.cc/en/Tutorial/ShiftOut, a drawing with two 74HC595 powered by the arduino board, is displayed.
Since the resistors are 220Ω, the total current should be 5/220x16 = 0.36A which exceeds the maximum total current of 0.20A for the arduino device.
So, could someone turn on simultaneously 16 LEDs using two shift registers without damaging the device?
Thank you

BTW, there is also a voltage drop across each LED, so the voltage across each 220R is not 5V, it is 5V-1.5V (or so).  Different LEDs have different "forward voltage" drops.  So the current is actually (5-1.5)/220 * 16 = 0.254A.

0.20A is not the maximum current for an Arduino device.  0.20A is the maximum current for the chip that is on the Arduino.  Thus it is only relevant to devices that are directly connected to the Arduino's IO pins (that connect direct to the chip).
The shift registers take their own power from the +5V pin, which is limited to between 500mA and 800mA depending on how you power your board.  Each shift register has its own power limits that are completely separate to the Arduino's main chip's power limits.

You are right, 0.2A is the maximum current of the ATMega328 chip. Nevertheless, if someone power let's say four shift registers which drive LEDs, not from an external power but directly from the arduino board, would that be OK?

@user3060854 As long as the total current consumption of the Arduino board and all the items powered from it is less than 500mA (USB) or 800mA (barrel jack) then yes that is perfectly fine.


text:
which is the number of bits in a float variable
Since the maximum value of a float variable is 3.4028235E+38, shouldn't it represented with 128 bits instead of 32? (2^128=3.4028235E+38).

No, it is not integer, so you cannot calculate it that way. It have floating point (not in fixed place).
It is stored as
1.significand x 2 ^ exponent.
It takes one bit for sign (+/-), 23 for significand (0 is not stored it is implicit) and 8 more for exponent.
Because of this, you have fixed precision (number of significant digits) for very large numbers and also for numbers which are close to zero.
You have it all explained here:
https://en.wikipedia.org/wiki/Single-precision_floating-point_format

That is a completely different approach. Indeed the wikipedia article is very useful. Thank you.

The implicit bit is actually a 1.

@Edgar thanks, it was long time ago when I learned this :) Fixed.

No, because IEEE 754 floats use a decimative compressed format. 64-bit floats allocate 1 bit to the sign, 11 bits to the exponent, and 52 bits to the mantissa, 32-bit floats allocate 1, 8, and 23, and so on.
You convert from it by adding an offset to the exponent, multiplying the mantissa by the exponent to the power of 2, and then applying the sign.

Just adding a little piece of information to the previous answers: it's
worth noting that a float can represent exactly all integers from
−224 to +224 (i.e. ±16777216).
The next integer, namely 16777217, is not representable as a float. A
calculation giving this value would suffer a rounding error.

Another way of looking at it is that a float variable is actually a list of 4294967296 numbers. That's far less than the possible range of numbers and fractions that a float can represent, so only a subset of the numbers are actually represented. Any number you try and use that's not in that list of numbers is rounded to the nearest one.


text:
square wave with serial plotter
I have this code which produces a square wave:
int output_state = 0;
unsigned long start;

void setup() {
  Serial.begin(1200);
  start = millis();
}

void loop() {

  if((millis() - start) >=1000){
    output_state = ! output_state;
    //output_state *= 1023;
    start = millis();
  }

    Serial.println(output_state);
}

but should I multiply the signal by 1023:
output_state *= 1023;

this signal is produced by the Serial Plotter:

Mind that the timing is right, just the x axis speeds up in zero values. Why is that happening, and how can be solved?
Any thoughts would be appreciated.

It takes twice as long to print "1023" (6 bytes, including the CRLF line
terminator) than to print "0" (3 bytes). Thus, in the same time, you are
printing twice as many "0" than "1023".
If you want the data points to be printed at a consistent rate,
you can impose the printing timing just like you did on the
output_state. Keep in mind that you cannot print more than 20 samples
per second at 1200 bps. You could also pad the strings so that they
always have the same length:
char s[5];  // one byte for the NULL terminator
sprintf(s, "%4d", output_state);
Serial.println(s);

I would prefer the first solution (explicitly control the timing).


text:
problem with bitwise OR
I have this code, in which I try to "glue" four bytes in order to construct an unsigned int. I shift left the bytes and "add" them using the OR operator.
unsigned long number1;
unsigned long number2;
unsigned long number3=0;

byte byte0 = 1;
byte byte1 = 40;
byte byte2 = 107;
byte byte3 = 238;

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

void loop(){
  number1 = byte1 <<8 | byte0 ;  //(=10.241 O.K.)

  //(should be 4.000.000.001, it produces 10.241)
  number2 = byte3 <<24 | byte2 <<16 | byte1 <<8 | byte0;

  //(should be 4.000.000.001, it produces 4.016.777.217)
  number3 = number3 | byte3;
  number3 = number3<<8;
  number3 = number3 | byte2;
  number3 = number3<<8;
  number3 = number3 | byte1;
  number3 = number3<<8;
  number3 = number3 | byte0;

  Serial.print("number1 = ");Serial.println(number1);
  Serial.print("number2 = ");Serial.println(number2);
  Serial.print("number3 = ");Serial.println(number3);
  Serial.println(" ");
}

The problem is that the OR operator applies only to byte1 <<8 | byte0 and ignores the rest. That is number1 and number2 appear to have the same value (10241).
I also tried "adding" them up separately, as shown with number3, but it also produces a wrong result as well.
I tried the same code in python, and it works fine.
byte3, byte2, byte1, byte0 = 238, 107, 40, 1
print byte1 <<8 | byte0
print byte3 <<24 | byte2 <<16 | byte1 <<8 | byte0

number3 = 0;
number3 = number3 | byte3;
number3 = number3<<8;
number3 = number3 | byte2;
number3 = number3<<8;
number3 = number3 | byte1;
number3 = number3<<8;
number3 = number3 | byte0;
print number3

So, the question is:
Why both number2 and number3 produce a false result?

Correction from another answer for number2:
number2 = (unsigned long)byte3 <<24 | (unsigned long)byte2 <<16 | byte1 <<8 | byte0; // = 4.000.000.001

And in the first round of loop number3 is correct, all others are wrong as number3 holds a result from previous loop.
  number3 = byte3; // all magic lays here
  number3 <<= 8;
  number3 |= byte2;
  number3 <<= 8;
  number3 |= byte1;
  number3 <<= 8;
  number3 |= byte0;

Correction for number two works fine. As for number3, I should be more careful and reset number3 in every loop. Thank you.


text:
How can I include examples in library?
I have written a library for Arduino, my_library, consisting of my_library.h and my_library.cpp, both included in my_library folder. Actually the library is recognized from IDE Arduino and works fine.
I want to add some examples, let's say Example1 and Example2. How is that possible?
Should the examples be included in my_library folder?
or should be included in another folder inside my_library folder?
I tried several combinations but none worked. Do I miss something?

You need to create a folder called "examples" in your library folder. Within there, each in its own folder, you place your examples.
For example:
MyLib/
MyLib/MyLib.h
MyLib/MyLib.cpp
MyLib/examples/
MyLib/examples/Example1/
MyLib/examples/Example1/Example1.ino
MyLib/examples/Example2/
MyLib/examples/Example2/Example2.ino

Be sure to name the example's folder the same as the name of the example.


text:
programming via ISP
A short question:
I wonder weather I can program an AVR chip (ATMega328, ATMega664, ATMega1284, ATTiny etc.) using the Arduino IDE, via ISP, without needing to bootload first.
Does programming via ISP clear the bootload, if installed previously in the chip?

A very similar question was asked on the Arduino forum.

As Ignacio mentioned, using ISP does not require a bootloader, however, it is also very nearly mutually exclusive with retaining one.

Does programming via ISP clear the bootload, if installed previously in the chip?

Indeed, it does.  The ISP interface on the ATmega cannot erase individual pages but only the entire chip.  This is distinct from the SPM instruction used by a bootloader running on the chip itself, which can perform a partial erase.  It is also distinct from the ATxmega, which does apparently offer an ISP page erase capability.
So in order to end up with both a bootloader and sketch on the ATmega, you would need to erase the full chip, and then load both the bootloader and the sketch, either in a unified hex file or by loading one and then the other to distinct already-blank memory regions while using the -D option to tell avrdude not to perform an automatic erase.
I do not believe the the Arduino IDE supports this, rather its menu option to program a sketch via a programmer is intended to set up a chip for operation with a sketch alone and no bootloader.  There does not appear to be any way at GUI-level to configure it to do otherwise.
Someone determined enough could probably craft a customized board configuration that built a functional bootloader into every sketch (or merged or additionally programmed a pre-built one), allowing one shot installation of both an operable sketch and an operable bootloader that could field upgrade it.  However, the Arduino IDE would be a poor choice for production programming...

Chris Stratton is quite right. As I noted under the question, this was also asked on the Arduino forum a day or two ago. The ICSP process can only erase the whole chip. You can't therefore keep the bootloader and replace the code, or even keep the code and replace the bootloader. A unified file is one approach (production Arduinos would be shipped that way). However re-installing the bootloader afterwards, when wanted, is quite simple.


text:
how does serialEvent work?
I have come across several examples about serialEvent() function, which look like this:
void serialEvent(){
  if(Serial.available()){
    \\do something
  }
}

The serialEvent() function is called when data is available, so which is the necessity of the if (or while) structure since that would be always true?
(In several cases I have excluded the if structure, and the code works fine)

As far as I understand, using an if statement wouldn't make any difference, but using a while statement would.
The serialEvent() function is executed within each execution of your loop() function if there is data available, so it would be something like:
while (true)
{
    loop();
    if(data_available)
        serialEvent();
}

If you only have one byte of information in the buffer, then you wouldn't have any problem at all.
But if you want to read multiple bytes at the same time, you would have to wait until the loop() is executed again to read the next byte.
You will solve that problem if you write your  serialEvent()  like this:
void serialEvent()
{
    while (Serial.available())
    {
        // do something
    }
}

That way, you will read all the information available at once and then return to the loop.

It's a burdon how incomplete and hidden a lot of things are in the IDE of Arduino.
It took me five hours to discover how the serialEvent() function works for other ports (as serialEvent2() for the serial-port #2.
It's the same with how the function itself works. I still don't know...
As an example just insert a delay in the above answer and it proves that: "That way, you will read all the information available at once and then return to the loop." is NOT true.
void serialEvent()
  {
    while (Serial.available())
      {
        // do something
      }
    delay(1000);
  }

don't use serialEvent it has no advantage over if (Serial.available()) in loop()


text:
Bluetooth transfer problem with big files
I want to send some data from an Arduino Mega to an android device via bluetooth (HC-06). I have installed some sensors whose values are frequently written in an SD card. Every time a new string line is added in a text file of the SD card. This is the format of the line
27/5/2015,11:55:00,34.00,27.00,42.50,26.80,47.80,26.00,24.62,24.12,26,0,0,708,1023,1023,1023,1023,10.5,10.5,10.5,10.5

and this is part of the code. I send from a bluetooth terminal the string "download" and after that the text file is opened and every line is readed and sent to the android device via bluetooth.
void loop(void){
    while(Serial1.available()) {
       character = Serial1.read();
       content.concat(character);
     }

if (content == "download") {
    Serial.println(content);
    content = "";
    read_from_SD_Card();
    }
    ........................
    ........................
    ........................
}

void read_from_SD_Card(){
    myFile = SD.open("test.txt");
    if (myFile) {
        Serial1.println("test.txt:");

        while (myFile.available()) {
            Serial1.write(myFile.read());
      }
      myFile.close();
    }
else {
  Serial1.println("error opening test.txt");
  }
}

The problems are:

the data are downloaded only after an upload of the sketch has been done. (I can't upload the sketch once and download the data from time to time)
No more than 10-20 lines can be downloaded. With bigger files the downloading seems to slow down and finally stops after a few lines.

Any thoughts would be appreciated.

I suspect that this is a String class heap-fragementation issue (again). To test this you could sending a fixed string buffer (vector of characters, "Hello world" :). Do not use String and SD/FAT in the test. Just send a large number of lines with dummy data.
If this works replace the String usage with a character buffer. Fill it from the SD file (buffer size at a time) and write to Serial.
Cheers!

@user3060854 -- were you able to resolve this? A higher baud rate for communicating with the HC bluetooth module can help with your speed/slowdown problem. But have noticed baud rates above 115200 dont work well. I believe the problem is the receiver baud rate %error, which should not happen at 250k baud. But I havent figured out how to set a baud rate of 250k in the BT module. The question with details is here ---  Setting non-standard baud rate (250k) for the HC-05 bluetooth module

String content;
void loop()
{
    while(Serial1.available()) {
       character = Serial1.read();
       content.concat(character);
     }

if (content == "download")
{
    Serial1.println(content);
    content = "";
    read_from_SD_Card();
    }

........................
    ........................
    ........................
}//end of loop()

read_from_SD_Card(){
    myFile = SD.open("test.txt");
    if (myFile) {
        Serial1.println("test.txt:");

        while (myFile.available()) {
            Serial1.print(myFile.read());
      }
      myFile.close();
    }
else {
  Serial1.println("error opening test.txt");
  }
  Serial1.readString()//to flush the serial buffer.
}

Sorry, I changed Serial.write() to Serial.print() and added Serial.readString() in order to flush the buffer, but it didn't seem to solve the problem.


text:
ATMega1284 and Relative Humidity libraries
I am trying to use some Relative Humidity sensors (DHT11 and DHT22) with the ATMega1284 processor on a breadboard. I use libraries from Arduino playground (dht.h), Adafruit (DHT.h) and others. Even though both sensors and libraries work fine with Arduino Uno and Mega, they fail with ATMega1284, which produces an INVALID_VALUE error.
Connections are double checked, and other libraries such as Wire, OneWire etc work fine.
Does anyone have any experience with the ATMega1284 processor, or any suggestions?

Did you try reading the libraries to see if they special case on the '328P and/or '1280?

Actually I did, but they looked quite simple, no definitions of processors there.

Are you sure you have your pin assignments correct?  The 1284 has a few different pin assignments as it isn't a standard Arduino board.  I haven't had any issues using the DHT22 with the Mighty1284 setup.

What pins are you using?

Per the library instructions, you will receive INVALID_VALUE in the following situations:

The readXX() functions return:

DHTLIB_OK (0) : if the sensor sample and its checksum is OK.
DHTLIB_ERROR_CHECKSUM (-1) : if the checksum test failed. This means that data was received but may be incorrect.
DHTLIB_ERROR_TIMEOUT (-2) : if a timeout occured, communication failed.

In case of a DHTLIB_ERROR_TIMEOUT, humidity and temperature will both get the value DHTLIB_INVALID_VALUE. In case of DHTLIB_ERROR_CHECKSUM the values of humidity and temperature are left unchanged as it is impossible to determine which byte failed in the checksum. It is up to the programmer to decide what to do. One can compare with previous value, but better reread the sensor.

So read the value returned by the read11() or read22() functions to verify that it's an DHTLIB_ERROR_TIMEOUT condition, and if so try to figure out why the library is having trouble talking to the device.

It is a DHTLIB_ERROR_TIMEOUT (-2), but I can not understand the reason.


text:
use only one input pin in L293?
I have an L293 motor driver chip, in which the two input pins are used in order to turn the motor forward or reverse, or stop it. So I wοnder if I could use only one input pin, ...
For running mode: Since Input1 should be the opposite of Input2, why not sending a signal from Input1 to Input2 via a hex inverter?
For stop mode: why not just sending analogWtite(Enable, 0) to Enable pin?
That way I could save an extra Output pin from Arduino. Do I lack some important detail?
My question goes the same for all the L29x family.

A H-Bridge has 3 modes of operation in addition to disabled. The ENable pin, when driven low, disconnects the power and stops the motor from being actively driven it is true. However that is not the same as the STOP mode of the H-Bridge.
The logical internal connections in the H-Bridge for the three modes are like this:

When in STOP mode the motor is effectively short circuited and the power supply is disconnected. When the motor is spinning and not being actively driven it is generating power. By feeding that power into a load you increase the load on the motor itself, slowing it down. The bigger the electrical load the slower the motor will go - and you can't get bigger than a dead short. So this mode effectively stops the motor in its tracks. It puts the breaks on.
Conversely, if you just disconnect the power, there is nothing much to stop the motor spinning, so it will keep going depending on the amount of friction, wind resistance, inertia, momentum, etc.
If you are happy with that kind of operation then yes, your method will work fine, since you will have access to forward, reverse, and a way of controlling the power to the motor. You just won't be able to apply the brakes, and you will have to either rely on the natural slow-down of whatever you are driving, or do something clever involving using just enough reverse to stop the motor before cutting the power.


text:
send mixed data over serial
I want to launch a communication between two Arduinos, in which case the first Arduino (S) sends data to the second one (R). The type of the data is mixed, consisting of integers, longs, floats and maybe some text. For example:
{125, 1250, 12500, 125000, 1.25, 12.5, 125.0, "some text"}

I thought about converting each one value to string, adding up all strings to a big one, and send the final string with  Serial.print(Big_string).  In that case I reckon that it would be difficult for the Receiver to extract the string to the exact substrings and convert them to real values.
A second thought was to convert all values to bytes and create a byte (or char) array, but each value would be limited to 0-255 (let alone floats and text)
A third thought was to convert them to word type (let alone the text), but I think that Serial.print( ) sends only bytes, not words.

In any case, which is the best way to send mixed data over serial?
Any thoughts would be appreciated.

Please, tell us a little bit more about those data types. Are they always the same (e.g. always 2 ints, 2 longs, 3 floats and 1 string)? Do you know the maximum possible length of the string? Is it small enough that padding to that length would not be too wasteful? Can you guarantee that the string will have no embedded comma (or semicolon, or other char that you could use as a field separator)?

I didn't have enough reputation to make a comment! you can check out the answer to this post. Ask me if you had any questions.

@ Edgar Bonet Yes, alwayws the same. Small string. No commas or other "strange" character.

I think the easiest way to solve your problem is using a separator and transmit the array values one after the other. That means having a for loop and in every iteration sending one value of the array with
Serial.println(array[i]).
The function will

convert numbers into Strings so you will get "125", "1250", ...
append a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n')

On the receiver side you can simply wait for Serial.read() to equal the number 13 and (immediately afterwards) 10 and split the messages there. That works unless your transmitted strings contain new lines.
The disadvantage is, that numbers are of course transmitted in an unefficient way. If you want to transmit them as real numbers instead of strings you have to write your own protocol. This video "Wireless Module Multiple Receivers" goes into that direction, it's using a fixed packet length but it gives an idea of how such a thing works.

I didn't expect so many answers, thus I need some time to work them out. Thank you.

If you want to communicate between 2 arduino's with similar cpu (for instance uno and mega) I would go for binary data in a struct.
When using a struct you can not use the String class but you can use a char array.
Consider this struct as example
struct SerialDataPacket
{
        int someIntegerData;
        long someLongData;
        int someMoreIntegerData;
        char aString[20];
};

You can send this struct as follows:
String myString;
SerialDataPacket transmissionPacket;
transmissionPacket.someIntegerData=1;
transmissionPacket.someLongData=millis();
transmissionPacket.someMoreIntegerData=2;
strncpy(transmissionPacket.aString,myString.c_str(),min(20,myString.length()));
Serial.write((uint8_t *) &transmissionPacket, (uint16_t) sizeof(SerialDataPacket));

you can receive the struct at the other side as follows:
Serial.readBytes((uint8_t *) &transmissionPacket, (uint16_t) sizeof(SerialDataPacket));
myString=transmissionPacket.aString;

Again this method will only work if you have possessors with the same memory byte order. If the processors have a different bit (8 16 32 bit) you lust use processor independent types for it to work.

@jante I didn't expect so many answers, thus I need some time to work them out. Thank you.

Thanks for this approach. I've been able to successfully implement it for communication between two Teensy 4.1 boards. However, it seems that as soon as the read or the write buffer is even used (not overflowed), the connection only transmits garbage. Consistently, though, like there has been a shift in bits or something like that. It doesn't give out changing random numbers but always the same wrong one. Do you perhaps have an explanation for that, even with this rough problem description? Thanks in advance!

@GeraltvonRiva Once you get out of sync between the 2 CPU's you will never recover.
To add "stability" send a number of sync bytes in between the packages.

I'd probably best use the readBytesUntil() function instead of reading a fixed number of bytes?

In a binary stream 1 character will not do the job.

Yeah I was wondering about that. As per your example, I'm transferring the data in byte-sized packages. If I were to use the single character "x" as a sync byte, it would be possible that an unsigned integer I'm sending coincidentally has the same binary representation as "x", thus falsely being recognized as the sync byte and shortly bugging the communication. So I would need to use multiple sync bytes as per your suggestion, perhaps 3 or 5. The readBytesUntil() function only allows for a single character however. Do you have experience on how to best handle that?

I have no Arduino code to demonstrate it.

I have a library that does exactly what you want. It can also work with RS-485 and RS-422 multi-drop networks.

https://github.com/MajenkoLibraries/ICSC

You can even get it communicating with a Linux computer (such as a Pi or BeagleBone Black) with the Linux library:

https://github.com/MajenkoLibraries/icsc-linux

You can use it to send data of any kind between nodes and trigger specific functions to be executed (like RPC) at the remote end.

I didn't expect so many answers, thus I need some time to work them out. Thank you.

If your primary concern is transmission speed, you might consider turning everything into bytes and reversing the process at the other end.  If speed is not important, you can use sprintf() to create a character string and sscanf() to parse out the character string at the other end.
Turning everything into bytes is a very custom / specific approach.  A character would turn into 1 byte, an integer into 2 bytes, ect.  You would have to write custom code to encode this and remember to write code at the other end to do exactly the reverse process.  The advantage is that you would only be sending your data and no other information.  But this approach is not vary flexible.  If you were able to fit your data into 1 byte then suddenly needed 2 bytes (for example, a value once always less than 255 was now 300), you would have to re-write your code at both ends of the connection.
Turning everything into a string with sprintf() is very similar to printing out all your data.  You will be including extra characters like commas and / or space for delineation. At the other end sscanf() is used to parse out the character string.  At both ends, if done properly, all string assembly and parsing should be done by only these 2 calls.  And some issues are taken care of automatically.  For instance, the number 100 is 3 characters long and the number 10 is 2 character long.  But the sprintf() and sscanf() calls automatically compensate for these (reasonable) variations and continue to work as expected.
added later...
FYI: Even though sscanf() is available for the Arduino, it is not clear to me if it is well supported.  You might try testing (create and parse a string in the same sketch) what you want to send / receive before actually committing to this method.

If you are going to send binary between two Arduinos, no need to encode anything: just send the data as it is in memory. This is explained in jantje's answer.

@st2000 I didn't expect so many answers, thus I need some time to work them out. Thank you.


text:
ATMega I/O maximum current
According to the ATmega328P datasheet, the total current from all I/O pins must not exceed 200mA.
Let's say that an Output pin sources 30mA and an Input pin sinks 10mA. The total current should be 30+10=40mA or 30-10=20mA?

Neither. First, inputs don't draw current. Whether you're sourcing current or draining it, it will always be an output pin.
The 200 mA rule is probably determined by the bonding wires for the Vcc and ground pins on the die. That means that all outputs which are sourcing current shouldn't source more than 200 mA combined, as this current will have to enter the device through the Vcc pin.
Likewise all outputs sinking current shouldn't sink more than 200 mA combined, as this current will drain through the ground pin.

Could you possibly explain the "sourcing - sinking" difference?  I thought than Output pins are sourcing current and Input pins are sinking.

@user3060854: in an input pin there doesn't flow any current. If an output pin is high it can provide current to a load connected to ground. It then sources current (which comes from the microcontroller's Vcc). When the output is low, it can draw current from a load connected to Vcc. It then sinks the current (and drains it to ground).

Usually you sum the magnitudes of the currents - so
|+30| + |-10| = 30 + 10 = 40 mA in your example.
Predictably but unfortunately. the principle of TANSTAAFL  usually applies in such matters :-).
Such limitations are often (but not solely) dissipation based.
A low level output pin is dissipating ~= (Vo_low) x I low and
a high level pin dissipates (Vdd-Vo_high) x I_high.
For low currents versus I_pin_max, Voutlow is ~= 0  and Vouthigh is ~= Vdd.
As currents approach design capacities Voutlow starts to rise and Vouthigh starts to fall (due to the internal 'switch' not being able to handle the current) and dissipation rises.
IF you pulled a high pin fully low or a low pin fully high then
at 5V and 200 mA IC dissipation = 1 Watt.
Under that sort of abuse other bad things may happen.
There MAY be some specialist cases where you can treat SOME high and low currents as semi independent but this would need a good understanding of the IC and probably still lies outside specification.


text:
calculating the input current
I have been a bit confused about calculating the input current, so I'd be much obliged if someone could help.
Let's say that we have a potentiometer connected with an analog input as shown below. In a middle position the resistance of the potentiometer is spitted to R1 and R2.
How can I calculate the current in A0?
How much will be the current value if (R1=0, R2=Rmax), (R1=Rmax, R2=0), (R1 and R2 !=0,Rmax)?
 5V --------
           |
           R1
           |
 A0 --------
           |
           R2
           |
          GND

Just in case you didn't realise, it's maybe worth noting that the analog pins measure voltage rather than current.

You are right, I just want to know the current value which passes through the analog pin

When reading an analog voltage an analog pin has a very high resistance - usually very very much higher than the resistance of any potentiometer used, and input current to A0 can be regarded as zero for practical purposes.
For practical purposes the current drain from the supply will be that which flows from 5V to ground via R1 & R2.
I = V/R = 5V/(R1  + R2)
As for a potentiometer the sum of R1 + R2 is constant, the position of the pot-wiper makes no difference to current draw.
eg 10k pot. I_supply  = V/r = 5V/10K = 0.5 mA.
An I_A0 ~= 0

The upper value of a potentiometer which should be used for an analog input is covered by the uC (microcontroller) data sheet. The key parameter is uC input bias currents flowing in the potentiometer and causing small voltages which affect the analog reading. A rule of thumb is to keep such voltages under about one LSB (least significant bit) of the ADC.

The input current of the ADC is low enough not to change the potentiometer's characteristic (which won't be perfectly straight, anyway).
The only requirement is that the impedance of the potentiometer (according to Thévénin equal to R1 parallel to R2) shouldn't be greater than 10 kΩ. That's because otherwise it takes too long for the ADC's capacitor to get charged.


text:
I want a couple of servos to listen for P.C. input (data from OSC protocol), can I bypass having to use an Arduino?
...and whack a stripped usb cable straight into a prototype board?
by bypass having to use an arduino I mean any kind of sheild? polulu would be perfect but im trying to avoid needing any of this.
My issue for finding tutorials and documentation on the subject is not quite knowing what keywords to search for, could someone point me in the right direction?

Can you be more clear about what servos you want to control with what kind of signals? are you asking about just a shield no arduino? just the servos, nothing else? BTW just a stripped USB cable wouldn't have the USB to serial adapter built into most arduinos.

USB is a non-trivial interface which involves fairly tricky signaling, so while you don't need an Arduino, you do need a USB-enabled I/O chip or microcontroller.  There are indeed examples of such quite a bit cheaper than either an Arduino board, or even just the critical components on it which enable this functionality.

yes thats it, the least amount of money needed to create signalling from usb with an outside powersource then? to be clear about hardware, I want to know if I can use output from computer programs nameley OSC so im not to bothered with details about servos specifically, just recieving data from dahn the usb cable

by OSC, you mean the Open Sound Control protocol right?

yeah, I understand it im controlling a program listening for osc and that program is sending commands based on the input to say, a prototype board or micro controller, as I understand it, dmx is appropriate protocol for robots but I just want cheap computer to robot interface

If I understand your question correctly you're asking if you can control servos with OSC and no microcontroller.
OSC is a protocol used for networking and communication between synthesizers, similar to midi in that, but totally different in the way OSC sends data which looks a bit like XML.
There's a couple of problems here:
1. Servos will not respond to OSC-signals. You could use MAX/MSP to generate servo-pulses from the OSC. The problem arises whan you are going to send this to the servos using usb.
2. USB, a fast data-transmission technology, is not suitable to be connected straight into a servomotor.
Arduino uses an atmega16u to transform the data from usb to serial (called a usb to serial programmer) for programming and communication. Then the microcontroller (atmega168/328) takes this and creates a pulse and a signal for the servo-motors.
To control servos without a micro-controller using USB is impossible.
It is be possible to control electronics using the serial-port and low-level coding. Used to do stuff like that on a Commodore 64 a time ago. Before these affordable, stable, reliable avr, arm and pic programming cards came out.
A tip: It is possible to load a program onto an atmega168/328 using a Arduino UNO or similar. Take the chip off of the programming card(ie. the Arduino UNO) and create a stripped down version, containing the micro-controller chip, 16kHz crystal, some capacitors and an usb to serial converter/ftdi-cable.
Regards
Krister Borge

I wouldn't say it's impossible as there are USB-connected PWM generators, but a MCU would certainly be the best way.

Ok, I see where you are going. It isn't impossible, just really hard. Most usb connected pwm generators has mhave mcus btw..

Arduino does not utilize an FPGA.  However, state-machine based logic such as is often implemented in a programmable gate array would be a way of controlling a servo (including a common PWM hobby one) from a USB host without utilizing a stored-program microcontroller.  This is generally not done, because sufficient slices of programmable logic cost more than microcontrollers, and in a commercial-scale environment (such as an ASIC) tend to be a less flexible, and therefore more expensive, method.  It is speculated that even most fixed-function USB interface bridges are MCUs inside.

Uhm, you're right, it doesn't, my bad. I fixed it.

Okay, understood. theres no point getting an arduino and pulling it apart so I will stick to traditional setup... Control a program with OSC on a PC and that PC will communicate with an arduino via USB and the Arduino program will turn that data into servo commands.

What would you recommend as the simplest way to control a pan tilt machine with OSC?

Attiny and some mosfets.

A build-your-own-duino isn't hard to do and it is quite inexpensive. It will make your life (or the part it you're about to spend creating custom hardware) much, much easier! I have built Joao Alves' CSE-duino for example and it has everything an UNO has except for:

on-board USB (use an FTDI cable that has USB <-> Serial in the cable head)
a 3.3v power supply; and
an ISP (high-voltage programming) connector;

, none of which you should need to drive a servo.


text:
Problem in SIM900 GPRS connection
I make simple code to read web page by ITEAD Gboard. Here is my code:
  Serial.write("\nStarting..........\n");
  mySerial.print("AT+CSQ");
  delay(1000);

  while(mySerial.available()!=0)
    Serial.write(mySerial.read());

  Serial.write("\n-----1-----\n");

  mySerial.println("AT+CGATT=1");
  delay(1000);

  while(mySerial.available()!=0)
    Serial.write(mySerial.read());

  Serial.write("\n-----2-----\n");

  mySerial.println("AT+CGATT?");
  delay(1000);

  while(mySerial.available()!=0)
    Serial.write(mySerial.read());

  Serial.write("\n-----3-----\n");

  mySerial.print("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(1000);

  while(mySerial.available()!=0)
    Serial.write(mySerial.read());

  Serial.write("\n-----4-----\n");

  mySerial.print("AT+SAPBR=3,1,\"APN\",\"internet\"");
  delay(2000);

  while(mySerial.available()!=0)
    Serial.write(mySerial.read());

  Serial.write("\n-----5-----\n");

  mySerial.print("AT+SAPBR=1,1");
  delay(1000);

  while(mySerial.available()!=0)
    Serial.write(mySerial.read());

  Serial.write("\n-----6-----\n");

  mySerial.print("AT+HTTPINIT");
  delay(1000);

  while(mySerial.available()!=0)
    Serial.write(mySerial.read());

  Serial.write("\n-----7-----\n");

  mySerial.print("AT+HTTPPARA=\"URL\",\"xx.xx.xx.xx/my/web/site\"");
  delay(1000);

  while(mySerial.available()!=0)
    Serial.write(mySerial.read());

  Serial.write("\n-----8-----\n");

  mySerial.print("AT+HTTPDATA=100,1000");
  delay(10000);

  while(mySerial.available()!=0)
    Serial.write(mySerial.read());

  Serial.write("\n-----9-----\n");

  mySerial.println("AT+HTTPREAD");
  delay(1000);

  while(mySerial.available()!=0)
    Serial.write(mySerial.read());

  Serial.write("\nend.\n");

Which i get the following output:
Starting..........
AT+CSQ
-----1-----
AT+CGATT=1

ERROR

-----2-----
AT+CGATT?

+CGATT: 1

OK

-----3-----
AT+SAPBR=3,1,"CONTYPE","GPRS"
-----4-----
AT+SAPBR=3,1,"APN","internet"
-----5-----
AT+SAPBR=1,1
-----6-----
AT+HTTPINIT
-----7-----
AT+HTTPPARA="URL","xx.xx.xx.xx/my/web/site"
-----8-----
AT+HTTPDATA=100,1000
-----9-----
AT+HTTPREAD

ERROR

end.

AT+HTTPREAD return error. What wrong with me?
Note
xx.xx.xx.xx/my/web/site is my web page. The error is still there for all web page.

I think the problem started from step 3 which i dont see the OK output

The problem (I believe) is that half way through your program you switched from using println() to using print(), thus the commands from that point on aren't being executed until right at the end where you switch back to println(), so the whole of the text you send from point 3 onwards is being run as one single command - which of course is in the wrong format:

AT+SAPBR=3,1,"CONTYPE","GPRS"AT+SAPBR=3,1,"APN","internet"AT+SAPBR=1,1AT+HTTPINITAT+HTTPPARA="URL","xx.xx.xx.xx/my/web/site"AT+HTTPDATA=100,1000AT+HTTPREAD


text:
SIM900 AT command HTTP GET request not show the web page
I build a simple HTTP GET request by SIM900. Here is it:
-----1-----
AT+CSQ

+CSQ: 25,0

OK

-----2-----
AT+CGATT?

+CGATT: 1

OK

-----3-----
AT+SAPBR=3,1,"CONTYPE","GPRS"

OK

-----4-----
AT+SAPBR=3,1,"APN","indosatgprs"

OK

-----5-----
AT+SAPBR=1,1

OK

-----6-----
AT+HTTPINIT

ERROR

-----6.1-----
AT+HTTPPARA="CID",1

OK

-----7-----
AT+HTTPPARA="URL","http://www.minimalsites.com"

OK

-----8-----
AT+HTTPACTION=0

OK

-----9-----
AT+HTTPREAD

OK

-----10-----
AT+HTTPTERM

ERROR

+HTTPACTION:0,200,1240

-----10.0-----
AT+SAPBR=0,1

OK

The step 9 AT+HTTPREAD I supposed to see some html from http://www.minimalsites.com. But i dont see anything, What wrong with me?

Before you do anything HTTP you should do a "AT+SAPBR=2,1" and see if you are actually connected to the bearer. It should return "+SAPBR: 1,1,aa.bb.cc.dd"

It return +SAPBR: 1,3,"0.0.0.0". What is that said?

That means you are not connected.

From what I can see in your results, it seems AT+HTTPINIT returned an error. This means the HTTP service wasn't even successfully activated. So there's no way the commands you issued later would have been successful. From the AT command manual, AT+HTTPINIT is necessary before you can do any HTTP-related stuff.
You need to run the command AT+CGATT=1 to attach GPRS, even if your query shows its value is already 1.
It could also be that your APN requires authentication, using a username and password. So once you find out the username and password authorized by 'indosatgprs' (customer care?), you can use them in the following commands.
    AT+SAPBR=3,1,"USER","Enter the username here"
    AT+SAPBR=3,1,"PWD","Enter password"

Both commands should return OK if successful. To view all the parameters you have set, you can use AT+SAPBR=4,1. If all the parameters are satisfactory, and you have sufficient airtime in the SIM, then you can attempt AT+HTTPINIT. Only if this command returns OK, should you proceed to run AT+HTTPPARA-related commands.

You have to wait after AT+HTTPACTION=0 for a while until you see something like +HTTPACTION:0,200,1240
Then continue to AT+HTTPREAD, you will see the result.
Finally, terminate HTTP.

Check Your Connection Try Pinging the IP of Your Arduino and INstead of Using the AT commands use this library its easier and Nice https://github.com/amcewen/HttpClient

how to know my IP address? my device run by SIM card

after days fighting with asynchronous and limit serial buffer size (64Bytes). I found this one.
this link help me out, it uses the standard library SoftwareSerial and my big txt file 1100 bytes or my html file (5814bytes)  are  download again & again with no issue!!
https://www.youtube.com/watch?v=cpgQOmQwUL8&t=1263s
http://www.iforce2d.net/sketches/gsm_HTTPGet.zip
nb: I change it to AltSoftSerial, no problem neither.
Thanks iforce2d
ps: you can also use the "ModuleSerial-master" library, but I need to save the space for other code (which already uses 74% of 2KB RAM) so I stick to AltSoftSerial which already found in my sketch


text:
Program attiny13 with Arduino uno 1.6
I am looking for the boards.txt, platform.txt and core files needed for the programming of the ATtiny13 with the Arduino Uno. Those I find on the internet probably only works with Arduino 1.0 and not with 1.6.

Have you tried porting them yet?

You can use the library for IDE 1.6 https://github.com/damellis/attiny/

Except for the fact that it lacks support for the '13, of course.

Thanks for your answer.
I already did, but this files are only for the ATTiny 44-45-84 and 85 and the ATtiny 13 is not supported.


text:
Pro Mini 3.3v + Neopixel not working when disconnected from USB
I'm doing a project using an Arduino pro mini 3.3v and Adafruit's Neopixel.
I've flashed an example (strand example) from the Adafruit Neopixel's library sketch into the Arduino using the FTDI Basic Breakout 3.3v and everything went fine.
But when I disconnected the FTDI Basic Breakout from my laptop, the LEDs stop working. They light up with some different color and the animation stops.
I tried with other example sketches and everything seemed to work fine. I never experienced anything like this and I had no success searching for this issues in forums or google.
What might be the problem and how can I solve it?
Thanks!

How are you powering the board and the LEDs?

I've tried two solutions, both gave same results.
5v to the strip and to the Arduino on its regulated RAW pin.
3.6v (with three 1.2 NiMh batteries) to the strip and to the Arduino RAW pin.


text:
Relay built in to cable with arduino interface
To be able to switch 220 volt stuff on and off using arduino, I need a relay (I assume). Is there really no nice extention cable with built in relay so you dont need to cut and connect high voltage.
I imagine a Power strip With a simple input port that can be controlled from the andruino, just like a relay board. When I Google this I get a lot of USB controlled and remote controlled, but none that works with an andruino project.

PowerSwitch Tail is what you are looking for.


text:
Will the arduino power autoselection logic short the regulated 5V and the USB 5V?
From the reference design of the Arduino UNO r3, I find that USBVCC will be connected to +5V via mosfet T1 if Vin is below 6.6V.
Doesn't this short the two sources if Vin is just below 6.6V?
The datasheet for regulator U1 (NCP1117) mentions input range as low as 6.5V for the 5V version.
This question came to mind when researching if I can simultaneously power the arduino with USB and the 5V-pin. There are many warnings not to do so, and some say its ok anyway. I realise that this will short the USB 5V with my external 5V if Vin/PWRIN is not connected or less than 6.6V/~7.3V, but how bad is that considering that this may happen anyway by design (if the theory above is correct)?

The mosfet act like a diode. So only power can flow from the USB and not to the USB. Which should protect your computer backfeeding. Great question. I think you should look a the situation where USBVCC is high than your external 5v, and the reverse. I think it also depends on the type of power-supply.

If you connect a power supply directly to 5V pin on gpio it bypasses voltage regulator hence your board may be damaged if the power supply generates  spikes. But you can power it using 5V supply directly to 5V pin provided you are using a good quality power supply. If you are supplying the power via Vin or power jack there is additional voltage regulator in path giving extra security. Thus you need more 6.5v so as the output of the regulator is 5v. If you supply 5v to Vin the output is nearly 4v thus the board doesn't get enough power.

Do you often see 5V power supplies that generate spikes?

@Wirewrap: the farther away the power supply is from the target the more likely it is to pick up noise. A wall-wart, regulated, power supply over a 2m wire is generally not a good idea. It's always best to have the regulator as close as possible to the target, i.e. on the same PCB.


text:
Arduino Nano Max Current Draw best Motors
I know that the Arduino Nano cannot source more than 40ma per pin. My question is there any type of motor or continuous rotation servo that I could use four of to make a robot without making the Nano shutdown. I would prefer the price to not exceed $10 in total.

Just add an transistor or mosfet. That way you can switch more that 40mA.

How would I do that. Could you provide a diagram. Also, could I do that with a PN222A or another common transistor?

PN222A can go upto 500mA. Example with diagram.

@Gerben - you should put that as an answer.


text:
Infra Red Send Hex Code
I am using an arduino nano with the standard arduino IR remote library. For now I am using the Irrecord sketch. However, I want to have some pre - programed codes for remotes I don't have. I found this site which apparently has the hex of an endless number of remotes. When I use the regular IR decode, the hex of any remote I use, is only a couple of characters.  However at this site the typical amount is at least 100.
This is the hex for a Toshiba model's sleep command:
0000 006c 0022 0002 0157 00ab 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0040 0016 0016 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0016 0016 0040 0016 0040 0016 0016 0016 0040 0016 0016 0016 0040 0016 0016 0016 0016 0016 0016 0016 0016 0016 0040 0016 0016 0016 0040 0016 0016 0016 0040 0016 0040 0016 0040 0016 05f0 0157 0055 0016 0e52
So, finally after all that if you are still with me my question is, how would I send that command with the IRRemote library.

That seems to be pronto hex format for codes. A quick google showed this explanation: http://www.remotecentral.com/features/irdisp2.htm and this sample code: https://gist.github.com/probonopd/5793692

Is there some converter I could use to convert it into regular or do I have to deal with it directly.

I don't know what you mean by regular. The pronto codes are just durations of on and off. So you don't need to know which code is used exactly. The code that I linked has an example sketch (https://gist.github.com/probonopd/5793692#file-sendprontohex-ino) which takes codes from serial and sends them. This could be easily adjusted to send the codes from an array. The function that does the sending is ir_start in loop

I mean, is there a way I could integrate that into the example in the irremote library?

It can be made into its own lib or probably added to that library, but this is beyond the scope of this answer. If you make it work as a regular sketch then can read about creating libraries and make one. That would be the simplest way instead of integrating with the existing one.


text:
Arduino Nano Motor
If I had four of these motors and attached them to the Arduino Nano on four separate digital pins or analog pins without transistors and a 9v power supply attached to the regular power supply input would that work?

Yes, but don't expect to win any races.
If you use analogWrite(HIGH) on your digital pins (3, 5, 9, 10, and 11) your motors should receive 40 mA max at 5V (see http://arduino.cc/en/Main/arduinoBoardNano). So the motors will run, just not very fast.
A switching transistor would be a very simple addition that would allow you to achieve higher current input to the motors and get their full potential.
If you want to reverse the direction of the motors you'll need to investigate getting a cheap motor driver board.


text:
How does this Motor Circuit not ruin the Microcontroller
I came across this instructable about using no external hardware but two pwm pins to control a motor in both directions. Usually you would use an H bridge. However, ever since I have had my Arduino I have heard that you are not supposed to connect a pin to another pin. So how does this circuit works. It looks like he sends a signal from one pin and in my experience it would fry the board. So basically, my question is this circuit ok with an Arduino Nano and if so how does it work? Below is a picture of the setup he gave:

This is a bad idea, but not because two pins seem to be connected directly. They're not; there is a load (the motor) between the pins, and that motor will take care of different levels between the pins. High and low will make the motor turn one way, low and high the other way, and the same level on both pins will stop the motor.
Why is this bad? An I/O pin can only supply a limited current, and even for a small motor that will peak rather high. If you run the motor for some time this way you will damage the I/O ports. An H-bridge, like you mention, is the solution.
Note that electric motors cause a lot of noise in the power supply, which may cause the microcontroller to reset all the time, so that your program doesn't work. (The motor may seem to start/stop all the time.) You need to decouple the power supply with capacitors.

Does that mean put like a 10uf cap between 5v and ground? If I wanted to do this setup but correctly could I use a transistor instead of an h-bridge? I am trying to minimize external hardware.

If you want to have your motor turn both left and right an H-bridge is the only way. With discrete transistors you'll need more parts but it will be cheaper than an integrated H-bridge, where everything is in one component.

There's no such thing as too much decoupling. A 10 uF cap between ground and 5V is good, a 100 nF in parallel is better, real close to the microcontroller is best. Also place a capacitor across the connections of the motor, also as close as possible.

Your first comments are somewhere between mistaken and self-contradicting.  If your concern is simply over current, then what you are essentially saying is that the two I/O pins are very nearly directly connected, or at least connected with too low an impedance between them.   In practice, the bigger concern may well be inductive kickback spikes from when the motor is turned off, and from the brushes, which may be stronger than the protection diodes are designed to handle.

You are not supposed to connect one pin directly to another pin because the current will destroy the electronics connected to the pins. The motor provides a small impedance and limits the current flowing (although the amount of current will increase if the motor stalls).
As to the other reason you missed for the MCU possibly being damaged, the answer is that it is absorbed by the input protection diodes and subsequently the supply.

Another problem here is when running a motor you want to include a 'flyback diode' to prevent damage from voltage spikes, which is a problem with loads like motors.
See this article for details.

While you are correct about the need to deal with the inductive spikes, a flyback diode across the motor is only suitable if the motor is run in a single direction. It is more complex for bi-directional motor control, usually accomplished with 4 diodes (similar to the input protection diodes mentioned in Ignacio's answer).

Good point, thanks for the additional info.


text:
Difference between Arduino.cc and Arduino.org
Recently I have noticed that there are two arduino sites, arduino.cc and arduino.org.  They both have the Arduino logo and both sell what seems to be official Arduino boards. Also, arduino.org came out with the Arduino Zero board first. What is the deal here? Has Arduino partnered with another site? Any ideas appreciated.

Does arduino llc or .cc endorse products that are labeled such as UNO, but were made by others who are selling experiment kits with things like MAX7219 and 5461BS anode LED digit displays that are not compatible with each other? Or is this one of the issues that the arduino group together is trying to decide what to do with? The kit work, but some of the stuff isn't compatible with each other, according to the tutorials on the web.

ok understand the situation. QUestion is I have a Arduino motor shield with arduino.org stamped on it. I have a schematic for a board that was downloaded from the Arduino.cc web site. The two do not match and the .org board I have is not working the way it should. Anyone have any experience with this situation?

The short of it is that there was a falling out within the Arduino people and now there are two groups laying claim to the "Arduino" name.
Arduino LLC runs arduino.cc. They are the steward of the Arduino IDE and libraries and own the "Arduino" trademark in the United States, and also owns the "Genuino" trademark outside of the United States. Arduino SRL (fka Smart Projects SRL) is the company that assembles(assembled) the majority of Arduino boards for Arduino LLC, runs arduino.org, and owns the "Arduino" trademark inside Italy and all of the other countries they have registered the "Arduino" trademark.
Arduino SRL recently decided that they are no longer beholden to Arduino LLC and has stopped paying licensing fees for using the Arduino name. Whether this is justified or not has not been fully tested in court yet.

Story morality: don't make business with your friends, or do it properly, as you would with anybody else. Sad but true.

This is a sum up from Massimo Banzi: http://makezine.com/2015/03/19/massimo-banzi-fighting-for-arduino/

They have the exact same logo. That's weird. @user6569 I don't think they pretended like it never existed or that you're giving them credit for their tons of original contributions/content. They did create the Arduino IDE. Like every other piece of software, literature, math, and science, it stands on the shoulders of its predecessors.

This article can explain it better than I could paraphrase:
http://hackaday.com/2015/02/25/arduino-v-arduino/
Relevant excerpt:

Arduino LLC [arduino.cc] is the company founded by Massimo Banzi, David Cuartielles, David Mellis, Tom Igoe and Gianluca Martino in 2009 and is the owner of the Arduino trademark and gave us the designs, software, and community support that’s gotten the Arduino where it is. The boards were manufactured by a spinoff company, Smart Projects Srl, founded by the same Gianluca Martino. So far, so good.
Things got ugly in November when Martino ... renamed Smart Projects to Arduino Srl and registered arduino.org
According to this Italian Wired article, the cause of the split is that Banzi and the other three wanted to internationalize the brand and license production to other firms freely, while Martino ... [wanted] to list on the stock market and keep all production strictly in the Italian factory.

Please take a look at The Untold History of Arduino.

Update on the situation: on October 1st, 2016 a blog post at arduino.cc "Two Arduinos become one" announced that an agreement was found between arduino.cc and arduino.org. Two key points:

the creation of a foundation
the creation of a holding.

About the holding:

At the end of 2016, the newly created “Arduino Holding” will become the single point of contact for the wholesale distribution of all current and future products, and will continue to bring tremendous innovations to the market.

About the foundation:

In addition, Arduino will form a not-for-profit “Arduino Foundation” responsible for maintaining the open-source Arduino desktop IDE, and continuing to foster the open-source movement by providing support for a variety of scholarships, community and developer initiatives.

arduino.org is not only boards assembler, but is also who designs and engineers the arduino boards. They own the arduino trademark all over the world, except the USA, therefore arduino.cc owns the trademark only in the USA.

No; arduino.cc designs the boards and owns the tradmark everywhere except Italy.  arduino.org justmanufactures the boards (and owns the trademark in Italy) and recently forked Arduino's GitHub repo, registered the domain arduino.org, and is now pretending that they are the only ones who design and make Arduinos and that arduino.cc is an impostor.

@NobodyNada I'm sorry but you are wrong about the boards manufacturing. arduino srl or arduino.org came from Smart Projects, and Smart Projects is the company who always designs and engineers arduino boards.

.org owns the trademark all over the world except USA, just take a look at arduino.cc web site and you can see Arduino Only USA and Genuino Outside USA.
I never heard that arduino.org said that .cc is an impostor on the contrary .org always thanks to arudino project founders for their work.
often people see only what they want to see and say things influencing people. (sorry for this last non-technical line but I have read around the web a lot of things that are untrue and unfounded accusations)

@ThomasCeleron But still both could have instead improved Wiring.


text:
Arduino Robot Chasis
I am looking into building a robot with my Arduino Nano but I don't want to shell out more then 50 bucks. Does anyone have any suggestions for a four wheel robot chassis at this price that I could use to make my robot mobile?

I'm voting to close this question as off-topic because we do not give out shopping advice.

There's plenty of options on ebay, you will have to add a DC motor driver and optionally, sensors, but these are a good starting point.

I can only speak for my experience, which has been quite good so far.
A DIY approach works too, but generates lots of overhead.
Tools required to do a proper job usually do not come cheap.

The ones that are really cheap are from "Emgreat" ... simple and "good enough".  I'd suggest get a low end and play ... the model I bought can be seen here:
http://www.ebay.com/itm/Motor-New-Smart-Robot-Car-Chassis-Kit-Speed-Encoder-Battery-Box-For-Arduino-/361060892190?pt=LH_DefaultDomain_0&hash=item5410e7fe1e


text:
Running 5v and 12v strips together?
I want to run 5v and 12v strips and halos together, i read that with the 12v strips, give 12v to the strip but the data is always 5 volts, and tie the ground to the ground of the 5v controller?
I use SP105E bluetooth controllers off ebay, and i use a 10/20a 12v to 5v buck converter to get me to 5v as i use my lights in vehicle accessories so thats why i dont have a power supply or anything.
So would i just take the 12v strip, run the +12v to the +12v then data to the data wire and tie the 12v strip ground to the 5v ground on the controller/step down converter?

They aren't a lot of addressable led strips that use 12Volt. Are you sure that's what you have. PS don't use a 12V transformer for halogen bulbs to power led strips. Those transformers don't give a nice stable 12V, as halogen bulbs don't care if the voltage fluctuates or spikes.

In electronics, 99% of the time you will need to tie all the grounds together for a common ground. So yes, the - of the 12v strip needs to be connected to the - of the 5v strip.

Yes im sure they are 12v addressable strips. i have 5v and 12v, ws2811 and ws2812b. i dont know about a halogen transformer? but im using a step down buck converter very commonly used in automotive LEDs, which is where all my led work is based, also ive never really had any stability issues with these step downs, hopefully it doesn't start.

Please explain what halos are. In my opinion a halo is a titanium protection bar for f1 racing drivers. 12v led strips are often used for aquarium lights. Sometimes they have dc-dc converters included in the strips. There is no problem with 12v and 5v led strips to the same arduino or to the same bluetooth controller, but we like to see a drawing of all the wiring. This is the arduino section. Is there a hidden arduino somewhere?

Halo is a ring, a circle, a circle of leds. There is no arduino in this setup, just the SP105e controller and the strips/circle rings. I didnt know where else to ask about 5v/12v leds and wiring other than this forum because everyone seems to use the 5v addressable LEDs which is why its in this section.
I now have wired a 5v and 12v strip together and they work, however now my issue seems to be the blue and green colors are backwards, when i select green, the 5v strip is green and the 12v is blue or vice versa, and the same when i go to blue, however red is red on both.

here is a sketch of the wiring http://i63.tinypic.com/30lcsnn.png