body:
I was looking at arduino nano boards [here][1]. Description says the arduino board is without welding plate. What does it mean for the user? If I buy this product will there be any issue? I understand that this board does not come with two headers soldered and I am OK with that.

  [1]: https://www.dhgate.com/product/new-5pcs-the-2014-version-arduino-nano-v3/388302235.html#s1-7-1b;searl|3376853976

title: what is welding plate?

Answers: 1

body:
Probably a mistranslation of soldering. As far as I can tell, it just means that the headers are not soldered on.

(see https://www.aliexpress.com/store/product/Nano-V3-0-ATMEGA328P-improved-welding-plate-without-wiring-module-board/630494_32807228948.html for one with "welding plate")


body:
I bought a batch of ESP8266-01 and DHT11 on ebay.

The sensors give data, but the datasheet say +/- 2 degrees. Who can live with that? Well, they claim the repeatability is 0.2 degrees, so I guess they could be calibrated.

But thet are not stable. They start a few degrees over room temperature, but gradually the reading is up to 33 degrees, more than 10 degrees too high.

Could it be the proximity of the ESP8266 giving off heat? Or are the sensors themselves heating up when reading at one read every two seconds?

title: Can the DHT11 give reasonable readings?

Answers: 1

body:
It could be the ESP8266, try physically separating the DHT11, but I'm guessing that that will only help slightly.

Do you have some way of reliably calibrating the sensors? If not, then even if you are getting consistent readings, you'll have a hard time knowing how accurate your readings are.

While they're typically more expensive, it might be prudent to buy an infrared temperature sensor. If you have the budget, replacing the DHT11s with IR temperature sensors might just be a better solution, I saw that Sparkfun's MLX90614 was accurate within +/- 0.5 degrees Celsius. If you don't have the budget to replace your DHT11s, or don't want to be wasteful, perhaps you just buy one IR temperature sensor to use as a sanity check. These should be more reliable than DHT11s and you could even write a sketch to calibrate them based on the IR temperature sensor's readings.


body:
My question might seem one of the million questions out there "Can't upload to arduino uno and receive error avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x01" but as I probably read all the million questions and didn't find the answer I am looking for I decided to write my own.

So my arduino is properly detected in device manager and in the arduino IDE but cant upload sketches to it. The main chip (atmega328p) seems well (13-pin LED blinks 3 times on reset) but the usb chip (ATmega16u2) is what I suspect as the RX and TX LEDs don't blink while uploading (and don't blink in any other situation) but again the arduino is detected and I am sure I chose the right board and port.

The serial monitor is always empty and I tried the loopback test and didn't get any echo at all or even any error message but I think that what I should have expected as the RX and TX not blinking means that there is no data transmission in the first place. Or am I wrong?

So is the USB chip broken or maybe corrupt? How can I be sure? And if not then what could the problem be?

I saw a tutorial in the answer of [this question][1] to test the usb chip using another arduino but I don't have that in hand right now or an ICSP programmer for that matter.

  [1]: https://arduino.stackexchange.com/questions/13292/have-i-bricked-my-arduino-uno-problems-with-uploading-to-board

title: Can the arduino be recognized if the usb chip is broken?

Answers: 1

body:
It depends on the exact arduino product. An Arduino Uno has a USB programmer chip, that then programs the AtMega 328 Chip. If the programmer is broken, it will likely not register any device when you plug in an arduino uno to your PC.

if the micro-controller is dead, but the programmer is operational, you will get a device in your device manager, but not be able to reprogram the micro controller.

If both the programmer, and the micro-controller are broken, then figuting that out could be difficult. The AVR microcontrolers support other programing methods, and the AtMega 328 IC, supports DebugWire. you could attempt to reprogram the MCU out side of the programmer, if you thought the programmer, was defective.

Here is a great article on using DeBugWire.
https://awtfy.com/2010/02/21/modify-an-arduino-for-debugwire/

another nifty trick I learned, is to take your Digital MultiMeter, set it to diode test, or continuity. then, measure between the ground pin, and the positive voltage pins on the MCU.  If you get a shot, the chip is busted. You will expect to get roughly 0.7Volts, although an OL reading might indicate more about your multi-meter, than the MCU.

Other Arduino devices, that have integrated USB programing, may behave differently. Features of the specific MCU dictate how it can be debugged. You might want to read the datasheet for a specific MCU if you're having trouble.


body:
I'm building a simple circuit that takes data from an IMU (using MPU6050), sends it to a microprocessor (Arduino Pro Mini 5V) to apply data smoothing and averaging, and then this data is sent using an HC-08 BLE module for the data to be further processed on a mobile. The circuit is powered by a 9V battery (6LR61) connected to RAW (Vin on other Arduino boards).

When I build this circuit on a breadboard, it works well, but the Arduino is power hungry as expected. It runs for over an hour in this setting (I haven't tested it for longer), but I've build this circuit twice using protoboards and it can't stay on. One circuit is able to send data for a while, but the LED on my BLE module dims and eventually turns off after ~5m, and requires me to wait 30+m before I try to power the circuit again. The other circuit has all LEDs shine when power is switched on, but the IMU doesn't send any data (an LED on the Pro Mini blinks whenever I2C data is received).

The shitty thing is that, whenever I power these circuits via USB, they work as intended, just like when I power them using 9V to RAW on the breadboard.

I tested the circuit on the breadboard later and after BLE has connected and is sending data, the whole circuit draws 42.9mA, the BLE module draws 1.5mA, and the IMU draws 5.4mA.

**What is the most effective way to fix this problem? Should I focus on finding a different battery, or focus on power-savings within the circuit?**

These are my ideas so far:

 - replace all boards with 3.3V versions
 - reduce clock speed (might not be viable, I need a lot of IMU data?)
 - use external voltage regulator, connect Vout from regulator to 5V of pro mini
 - replace 9V battery with Lithium Ion battery
 - replace Pro Mini with an ATtiny85

I'd like to take the least time to maximize power savings, so while I could go through all these ideas, I just need the circuit to work at the end of the day.

title: Circuit works on breadboard but has power problems on protoboard

Answers: 1

body:
I have [a page about power saving](http://www.gammon.com.au/power).

To summarize some of the techniques you can use:

* Run the processor at a lower frequency
* Run the processor at a lower voltage
* Turn off unneeded internal modules in software (eg. SPI, I2C, Serial, ADC)
* Turn off brownout detection
* Turn off the Analog-to-Digital converter (ADC)
* Turn off the watchdog timer
* Put the processor to sleep
* Don't use inefficient voltage regulators - if possible run directly from batteries
* Don't use power-hungry displays (eg. indicator LEDs, backlit LCDs)
* Arrange to wake the processor from sleep only when needed
* Turn off (with a MOSFET) external devices (eg. SD cards, temperature sensors) until needed

I've got a [temperature and humidity sensor](http://www.gammon.com.au/forum/?id=12106) which has been running for **years** on 3 x AA batteries.

---

> The circuit is powered by a 9V battery (6LR61) connected to RAW (Vin on other Arduino boards).

That's not a great choice for a start, as the voltage regulator has to turn the 9V into 5V (in the form of wasted heat). You'd be better off with 3 x AA batteries (around 4.5V) and put them straight into the 5V pin.

Those 9V batteries have notoriously low mAh because they are basically 6 coin cells stacked on top of each other.


body:
If I have data coming into an Arduino in an ASCII serial format from some external device (or from a PC, or whatever) and I want to extract binary values from that data and log it or put it on a little display or react to it or whatever there are a few ways I can do it. But it seems like there should be a reversed version of sprintf, mashed up with regexp, mashed up with Perls pack/unpack that would make it easy and configurable.

For example, let's say I'm getting hex numbers from a data logger. something like
`c,03,1234,5678,9ABC`
where c is just a code telling me this line is channel data, there are 3 channels installed, and then there are the 3 sets of data. I can use split or something like that and then extract the values, convert the hex to binary, apply Y=mX+B and display the channel readings. If a channel goes flat, I can sound an alarm, etc... No worries.

But then I have a different data logger plugged in, and this one uses a different format. Like decimal raw ADC counts. It spits out
`2342 1313 234236`
Now I gotta recode.

But wait, what if I just had a regexp in eeprom and I used that to extract the data? Something like `/^c,\X+,(\X+),(\X+),(\X+)$/` for the first logger and `/^(\d+) (\d+) (\d+)$/` for the second. That would be really cool because I could pretty much extract data from any serial device for local display. No need to reprogram, just update the regexp. And there is a nice regexp library:
https://github.com/nickgammon/Regexp
although it uses the LUA regexp syntax.

Oh, but that won't work... because although my program in the Arduino gets back 3 values from the regexp, it doesn't know that the first set are hex strings, and the second set are decimal.

Now, if I was doing this in Perl, I'd just apply a pack string to the binary data. But then pack can't reject a bad match, it always returns a result, even if the input wasn't valid.

Doesn't it seem like the regexp should be able to return /binary/ values instead of just the string? It knows those values are hex. And shouldn't pack be able to do matching against the other characters in the string and reject the value if it's not a match?

Seems to me like there is a hole in our standard libraries. Something that does both simple matches, and converts data to binary return values on the fly.

Or is that too much to ask from an engine? Perhaps few people would use it; better to just hardcode for the rare times you need something like this?

title: Extract binary data from text string. Like Perl pack, not just regexp

Answers: 2

body:
Yes, but it doesn't really *know* something is hex. What about the patterns:

    [\dA-F]
    [0-9A-Fa-f]

And so on. The regexp library is simply a way of extracting out substrings of a target string. It doesn't make a heap of sense for it to try to auto-detect the type of the returned string. For example, a GUID might be a lot of hex digits. Do you want something like `182676d07497c511f850` to be somehow converted into binary? And then what? Compressed into an `int`?

In fact it doesn't return (decimal) numbers anyway, it returns a string which may or may not be convertible into a number. Chris Stratton's suggestion of using `atoi`, `sttol` and so on is the logical way to go. Just have a flag in your EEPROM that tells the decoding routine what format the input data is. Also, for simple string sequences, don't forget `strtok`.

body:
> Something that does both simple matches, and converts data to binary
> return values on the fly.

You are describing [`sscanf()`][sscanf]. It is way less powerful than
regexps when it comes to pattern matching, but it seems to closely match
your requirements.

Dummy example:

<!-- language: lang-c++ -->

    const int FORMAT_COUNT = 2;
    const char * formats[FORMAT_COUNT] = {
        "c,%*x,%lx,%lx,%lx",  // first data logger
        "%lu %lu %lu"         // second data logger
    };

    // Here goes the data.
    unsigned long channels[3];

    // Try to parse using all the known formats.
    void parse(const char *message)
    {
        for (int i = 0; i < FORMAT_COUNT; i++) {
            int ret = sscanf(message, formats[i],
                    &channels[0], &channels[1], &channels[2]);
            if (ret == 3) {
                Serial.print("Message \"");
                Serial.print(message);
                Serial.print("\" matched with format \"");
                Serial.print(formats[i]);
                Serial.println("\"");
                return;
            }
        }
        Serial.println("Could not parse message.");
    }

Sample output:

    Message "c,03,1234,5678,9ABC" matched with format "c,%*x,%lx,%lx,%lx"
    Message "2342 1313 234236" matched with format "%lu %lu %lu"

[sscanf]: http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#ga5507d0e1bbfd387fbb2ffcfd8f5dca6f


body:
I have a BYJ48 stepper motor and an ULN2003A motor driver shield shield.

In many tutorials I read:

> do not to draw current from the 5V on the Arduino rail, but use an
> external power source, since the motor can draw quite some current

Which of these options to they mean by this?

> Connect an external power adapter to the Arduino and connect the
> ULN2003A board to the Vin pin and GND on the Arduino

or

> Connect the motor shield itself to an external power adapter and connect it to the + and - pin on the motor shield

or perhaps both are valid solutions?

The board I use is [this one](https://www.ebay.nl/itm/5V-4-Phase-Geared-Stepper-Motor-with-ULN2003A-Driver-Board-28BYJ-48-Arduino/121433812858).

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/qfFmi.jpg

title: Where to connect an external power source for an Arduino motor driver shield to?

Answers: 1

body:
There are two things you need to do:

1. Prevent the motor drawing its power from the micro-controller board.
2. Make sure that all the grounds are connected but avoiding motor current return through the micro-controller board.

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/h0eDm.png)

<!-- End schematic -->

*Figure 1. A good wiring configuration. The heavy wires carry the motor current.*

Note that there is one ground connection between the micro-controller and the motor system. The return current for the 12 V supply does not pass through the micro-controller board.


body:
I am using an [Arduino DUE][1]. Using the `analogWrite(DAC0, X)` command I am writing an analog value to this pin. X = 0 - 255 as I understand it.

I am observing that when X is lower, the voltage on DAC0 is higher nad when X is higher the voltage is lower.

Is that expected?

My code is simple:

<!-- language: lang-cpp -->

    void setup()
    {
      analogWriteResolution(12);
    }

    void loop()
    {
      analogWrite(DAC0, 10 );
    }

  [1]: http://www.robgray.com/temp/Due-pinout-WEB.png

title: analogWrite(DAC0, X), Analog voltage on DAC0 pin is higher for lower X value - is this normal?

Answers: 1

body:
That doesn’t sound right. Try setting **x** to 0 and measure with DC. You should get ~0.56 V. Repeat with 4095, and you should get ~2.76 V.

Also, note that with `analogWriteResolution(12)` your range is not 8-bits (0-255), but 12-bits (0-4095).

The output should follow:

Vout = Vref * Xin⧸(2N-1) + Voffset

where

 - Voffset = 0.56 V
 - Vref = 2.2 V
 - 0 ≤ Xin ≤ 4095


body:
I made an program so if I turn on my rotary encoder the position and the rotation comes on a LCD screen. But I need to change it a bit up for my teacher, she wants to see the graph of the pulses on the serial monitor. I searched it up and can't find a solution? Any help?

My program:

    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x27,16,2);
    #define outputA 2
    #define outputB 4
    int counter = 0;
    int angle = 0;
    int aState;
    int aLastState;
    int lastAngle = 0;
    String rotationDirection;
    String savedRotationDirection;

    void setup() {
      pinMode (outputA,INPUT);
      pinMode (outputB,INPUT);

      aLastState = digitalRead(outputA);
      lcd.begin();

         }

    void loop() {
      aState = digitalRead(outputA);
      if (aState != aLastState){
         if (digitalRead(outputB) != aState) {
           counter ++;
           angle ++;
         }
         else {
           counter--;
           angle --;
         }
         if (counter >=30 ) {
          counter = 0;
         }

         if (angle < lastAngle){
          rotationDirection = "CCW";
         }
         else {
          if (angle > lastAngle){
            rotationDirection = "CW";
          }
          else {
            rotationDirection = savedRotationDirection;
          }
         }
         lcd.clear();
         lcd.setCursor(0,0);
         lcd.print("Position: ");
         lcd.print(int(angle)*(-1));
         lcd.print((char)223);
         lcd.setCursor(0,1);
         lcd.print("Rotation: ");
         lcd.print(rotationDirection);
         savedRotationDirection = rotationDirection;
         lastAngle = angle;
      }
      aLastState = aState;

    }

title: Arduino Rotary Encoder Pulses?

Answers: 1

body:
Add Serial.begin(115200); in setup() and use Serial.println() or Serial.print() to print to Serial.

In Arduino IDE open Serial Monitor and set baud rate to 115200.

EDIT: The question turned out to be about Serial Plotter. Maximilian Gerhardt answered in a comment :
> If you want multiple data streams (graphs) you need to seperate them
> by a comma: Serial.println( String(digitalRead(outputA)) + "," +
> String(digitalRead(outputB)));


body:
i have an arduino UNO with RS485 module.

I have made this connection:[![RS485 module connection][1]][1]

And i have an problem with communication of this module with power meter
"InePro PRO-1Mod"
([datasheet][2]) over ModBus protocol. I want for example read an **L1 Voltage value**, which i know from the manual (page 24 & 25) that this value is stored in "read holding register" with adrress **5002**. I should communicate with these paramaters:

 - Baud rate 9600
 - 8 data bits
 - even parity
 - 1 stop bit

There is also mention about 120 ohms resistor placed by the power meter (but it is 15cm long cable, and even with the resistor there is no change)

I have tried using many of ModBus libraries and for now none of them doesn't work. I have tried "[Modbus-Master-Slave-for-Arduino][3]" , "[ModbusMaster][4] and now at last i am using this "[simple-modbus][5]".

I think that with that simple modbus library i went far as i can, but it is still doesn't working, but i see on the display of power meter that there is some try to communication (i see a black dot which shows modbus communication)
but i don't receive any useful data.

I am using this code:

        #include <SimpleModbusMaster.h>
    #include <AltSoftSerial.h>

    #define TxEnablePin 2                    // RS485 modbus direction control pin:
    #define baud 9600                           // modbus port speed:
    #define timeout 1000                        // modbus timeout in mSec:
    #define polling 500                         // modbus scan rate in mSec:
    #define retry_count 15

    #define TOTAL_NO_OF_REGISTERS 1// number of registers to poll for:

    AltSoftSerial altSerial;

    enum
    {
     PACKET1,
     TOTAL_NO_OF_PACKETS                       // leave this last entry
    };

    Packet packets[TOTAL_NO_OF_PACKETS];        // array of Packets to be configured

    //struct packetPointer packet1 = &packets[PACKET1];
    unsigned int regs[TOTAL_NO_OF_REGISTERS];   // master register array
    long previousMillis = 0;
    long interval = 1200;
    unsigned long currentMillis;

    void setup() {
     Serial.begin(9600);
     altSerial.begin(9600);
     altSerial.println("Hello World");
     modbus_construct(&packets[PACKET1], 5, READ_HOLDING_REGISTERS, 5000, 2, 0);  //initialize packet
     modbus_configure(&Serial, baud, SERIAL_8E1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
    }

    void loop() {
     modbus_update();

     float Power;
     unsigned long temp = (unsigned long)regs[1] << 16 | regs[0];
     Power = *(float*)&temp;

      currentMillis = millis();
     if (currentMillis - previousMillis >= interval)
     {
       altSerial.print("Exception errors: ");
       altSerial.println(packets[PACKET1].exception_errors);

       altSerial.print("Failed requests: ");
       altSerial.println(packets[PACKET1].failed_requests);

       altSerial.print("Successful requests: ");
       altSerial.println(packets[PACKET1].successful_requests);
       altSerial.print("Low byte: ");
       altSerial.println(regs[0]);
       altSerial.print("High byte: ");
       altSerial.println(regs[1]);
       altSerial.print("Power ");
       altSerial.println(Power);
       altSerial.println("----------");

       previousMillis = currentMillis;
     }

    }

And i have got only this output in the pc (its repeating of course):

    ----------
    Exception errors: 0
    Failed requests: 5
    Successful requests: 0
    Low byte: 0
    High byte: 260
    Power 0.00
    ----------

Altserial library i am using together with USB2TTL convertor on pins 8 & 9,
to see output.

I should mention that there is only A and B screw terminals on power meter, so i have no option to make common ground connection. I also using an 15cm twisted pair cable UTP.

Can someone help me to make it work ?
I have tried to change adrress of holding register to 0x5000 or 5002, tried changing number of registers.

I have tried to connect rs485 module with USB2TTL to pc and run software called "qModMaster" and it works, but with arduino it doesn't work.

Slave ID (power meter) is 5.

Thank you, for your help.

  [1]: https://i.stack.imgur.com/CWJVM.jpg
  [2]: http://www.ineprometering.com/images/pdf/catalogue/PRO1-user-manual-V2.18.pdf
  [3]: https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino
  [4]: https://github.com/4-20ma/ModbusMaster
  [5]: https://code.google.com/archive/p/simple-modbus/

title: Arduino ModBus RTU master communication with Power Meter problem

Answers: 2

body:
**I have made it. Now it is working. I only checks A & B cables (tried a new one) and change address of register from 5000 to 0x5000 and now it works. I thought that this library already give 0x before address, because i didn't see it anywhere with 0x before.**

An advice for people with the same problems:
Most of the devices which is using RS485 and ModBus protocol (and have an some kind of display) shows an communication (over 485 & modbus) on display by some kind of mark, for example in my case it was an "dot" which blinks when there's an communication. When this mark is shown, it is sign of that the communication settings is right, so data, parity bit, stop bit & baudrate is OK (data has successfully reached the dest. device).

After that, these devices send you an error message back on its line. So if you have problems with getting data, you should send your message (ask) from the arduino to that device, over an Transmit pin from arduino (of course trough an converter, for example max485) and the Receiving pin (side) connect to your PC through again some kind of converter from UART to USB. (Warning: you should have the same ground potential, so wire all grounds together)

Install some software to communication for modBus on PC (i am using this soft: https://www.simplymodbus.ca/ | you can use demo ) After that let arduino sent an message and receive it by PC. (in simplymodbus look at the "response") read that code and look to the manual for the device you using, where there should be an description of error codes, if not look at this doc.: http://www.simplymodbus.ca/exceptions.htm or [THIS][1]).After that you will have an better look on what is going on and where there is a problem.

  [1]: https://forum.hosteng.com/wndm/HTMLHelp1/Instruction_Set/Modbus_Exception_Codes.htm

body:
I'm using a mp5w pulse meter, the settings:

 - Baud rate : 9600
 - Address : 02
 - Parity : none
 - Stop bit : 1

Modbus memory map table for measurement value /(PV) :

 - Modebus : 31002
 - Address  : 03E9
 - Size    : 5


body:
I have tried to install a better bootloader in some chinese Arduino pro mini boards. I have tried the OptiLoader application via an ArduinoAsISP. I failed in some way. The boards got unstable, I can not repeat boot installation, I can not upload any application. They both time out.
This is the result from Atmega_Board_Detector most of the time.

    Atmega chip detector.
    Written by Nick Gammon.
    Version 1.20
    Compiled on Feb 24 2018 at 10:27:05 with Arduino IDE 10805.
    Attempting to enter ICSP programming mode ......................................
    ................
    Failed to enter programming mode. Double-check wiring!
    Programming mode off.

Below is the result from Atmega_Board_Detector after many tries when it suddenly gave one answer. Nothing is changed in hardware or software between the test above and this test.
**Question:** Anything in this dump that says what I did wrong?

    Atmega chip detector.
    Written by Nick Gammon.
    Version 1.20
    Compiled on Feb 24 2018 at 10:27:05 with Arduino IDE 10805.
    Attempting to enter ICSP programming mode ...
    Entered programming mode OK.
    Signature = 0x1E 0x95 0x0F
    Processor = ATmega328P
    Flash memory size = 32768 bytes.
    LFuse = 0xE2
    HFuse = 0xDA
    EFuse = 0xFD
    Lock byte = 0xFF
    Clock calibration = 0x48
    Bootloader in use: Yes
    EEPROM preserved through erase: No
    Watchdog timer always on: No
    Bootloader is 2048 bytes starting at 7800

    Bootloader:

    7800: 0x0C 0x94 0x34 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C
    7810: 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C
    7820: 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C
    7830: 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C
    7840: 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C
    7850: 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C
    7860: 0x0C 0x94 0x51 0x3C 0x0C 0x94 0x51 0x3C 0x11 0x24 0x1F 0xBE 0xCF 0xEF 0xD8 0xE0
    7870: 0xDE 0xBF 0xCD 0xBF 0x11 0xE0 0xA0 0xE0 0xB1 0xE0 0xEA 0xE8 0xFF 0xE7 0x02 0xC0
    7880: 0x05 0x90 0x0D 0x92 0xA2 0x30 0xB1 0x07 0xD9 0xF7 0x12 0xE0 0xA2 0xE0 0xB1 0xE0
    7890: 0x01 0xC0 0x1D 0x92 0xAD 0x30 0xB1 0x07 0xE1 0xF7 0x0E 0x94 0x2D 0x3D 0x0C 0x94
    78A0: 0xC3 0x3F 0x0C 0x94 0x00 0x3C 0x98 0x2F 0x95 0x95 0x95 0x95 0x95 0x95 0x95 0x95
    78B0: 0x90 0x5D 0x8F 0x70 0x8A 0x30 0x7C 0xF0 0x28 0x2F 0x29 0x5A 0x80 0x91 0xC0 0x00
    78C0: 0x85 0xFF 0xFC 0xCF 0x90 0x93 0xC6 0x00 0x80 0x91 0xC0 0x00 0x85 0xFF 0xFC 0xCF
    78D0: 0x20 0x93 0xC6 0x00 0x08 0x95 0x28 0x2F 0x20 0x5D 0xF0 0xCF 0x98 0x2F 0x80 0x91
    78E0: 0xC0 0x00 0x85 0xFF 0xFC 0xCF 0x90 0x93 0xC6 0x00 0x08 0x95 0xEF 0x92 0xFF 0x92
    78F0: 0x0F 0x93 0x1F 0x93 0xEE 0x24 0xFF 0x24 0x87 0x01 0x80 0x91 0xC0 0x00 0x87 0xFD
    7900: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    7910: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    7920: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    7930: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    7940: 0xFF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 0xFF
    7FF0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF

    MD5 sum of bootloader = 0x53 0x33 0x0F 0xF5 0x82 0xCF 0x52 0x64 0x02 0x8E 0x50 0x1A 0xB8 0x6A 0x0D 0x2C
    Bootloader MD5 sum not known.

    First 256 bytes of program memory:

    00: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    10: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    20: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    30: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    40: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    50: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    60: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    70: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    80: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    90: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    A0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    B0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    C0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    D0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    E0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
    F0: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF

    Programming mode off.

title: Installing Optiboot loader for pro mini 3.3V 8MHz

Answers: 0


body:
Looking for some help here. I have written out some code to add propane injection for my forklift. It is supposed to read three analog inputs, add them together and multiply the sum by three. There is an interrupt which is triggered by a hall effect sensor which is supposed to fire a solenoid valve for a duration of microseconds. I have mocked this up on a breadboard with a attiny85 pulsing the hall effect pin and nothing happens. Would appreciate some one having a look at the code and letting me know where I went wrong. Thanks.

    const byte interruptPin = 2; //this is the interrupt pin hall sensor//
    int mpPin = A3; //manifold pressure sensor//
    int tpsPin = A4; //throttle position sensor//
    int tunePin = A5; //tune pot 10k//
    volatile byte inj; //this will end up being the duration of the injector pulse//
    int mpValue = 0; //setting manifold variable to zero//
    int tpsValue = 0; //setting throttle positon sensor value to zero//
    int tuneValue = 0; //setting tune value sensor variable to zero//
    int injValue = 0; //setting injection variable to zero//

    void setup() {
     pinMode(12, OUTPUT);  //this is the pin that fires the injector//
     pinMode(interruptPin, INPUT_PULLUP); //set the interrupt pin to high pull up //
     attachInterrupt(digitalPinToInterrupt(interruptPin), shot, LOW);  //set the interrupt to trigger shot isr on low//
    }

    void loop() {
     tpsValue = analogRead(tpsPin); //read the throttle positon sensor//
     mpValue = analogRead(mpPin);//read the manifold pressure sensor//
     tuneValue = analogRead(tunePin); //read the tune sensor//
     injValue = (tpsValue + mpValue + tuneValue) * 4; // add the three sensors together and assign the value to inj//
    }

    void shot() {
     digitalWrite, 12, HIGH; // initilize injector powerup//
     delayMicroseconds(inj); //delay the calculated value  in microseconds//
     digitalWrite, 12, LOW; //shut down the injector//
    }

title: Propane injection software compiles, uploads, doesn't work

Answers: 1

body:
I can see two things wrong with your code at first glance.  First is the kind of interrupt you're using:

    attachInterrupt(digitalPinToInterrupt(interruptPin), shot, LOW);

A `LOW` interrupt keeps triggering over and over again *all the time the input is low*.  It's a special interrupt type that is seldom used for anything except waking up the MCU or handling external peripherals with *persistent* interrupt indication.  Instead you should be using `FALLING` which will trigger once and once only when the input transitions from `HIGH` to `LOW`.

    attachInterrupt(digitalPinToInterrupt(interruptPin), shot, FALLING);

Secondly you have two variables that seem to be intended to do the same thing - store the delay time for your output pulse.  And that's caused confusion:

    injValue = (tpsValue + mpValue + tuneValue) * 4; // add the three sensors together and assign the value to inj//

... and then later ...

    delayMicroseconds(inj); //delay the calculated value  in microseconds//

In your comments you reference the second variable, but the code uses the first one. Change that so it uses just one (volatile) variable:

    inj = (tpsValue + mpValue + tuneValue) * 4; // add the three sensors together and assign the value to inj//

Alternatively, and perhaps much safer, is to assign the result of the calculation inside a *critical section*, in which case having two variables is useful:

    injValue = (tpsValue + mpValue + tuneValue) * 4; // add the three sensors together and assign the value to inj//
    noInterrupts();
    inj = injValue;
    interrupts();

This will prevent your interrupt triggering whilst the value is being calculated and placed into the `inj` variable which could result in the `inj` variable containing gibberish, which could cause your engine to explode.


body:
I'm trying to split up a large project of mine into separate tabs in the Arduino IDE and I'm having more than a few troubles with it. My main trouble is finding a way to have routines in extra tabs access the Serial object; because it's really hard to debug things with `Serial.println()` otherwise. All I get, though, is "'Serial' was not declared in this scope".
There appears to be some kind of trick to this? I've noticed that "byte" or "bool" needs to be declared in .cpp tabs and .h tabs but not on the main one?
Is there some kind of easy way to set this up so that I don't need to constantly `#include <stdbool.h>` and `typedef unsigned char byte;`?

Current issue: Main file:

    void setup() {
      Serial.begin(500000);
      PrintMessage();
    }

    void loop() {
    }

driver.ino file:

    byte PrintMessge () {
      Serial.println("printin");
    }

and on compiling:

    error: 'PrintMessage' was not declared in this scope

EDIT: Found a silly typo. Problem solved.

title: Properly using separate tabs with Arduino IDE

Answers: 2

body:
Tabs are actually quite simple:

* If it's named `<something>.ino` it will get merged with the main tab. It's just like working in one big file and you don't need to do anything special.
* If it's named `<something>.cpp` or `<something>.c` it's a completely separate *translation unit* and has to be manually "enroled" into the Arduino system by including the `Arduino.h` header.

So it's simplest to just name them as INO files not CPP files and you don't have to do anything special:

[![enter image description here][1]][1][![enter image description here][2]][2]

  [1]: https://i.stack.imgur.com/BjL38.png
  [2]: https://i.stack.imgur.com/luNa2.png

body:
This question is more about C/C++ header basics rather than Arduino. Anyways, you should have the following file structure: Code in `.cpp`files, Header in `.h` files. Main sketch either `.ino` or `.cpp` (for cpp remember that you must explicitly write out the function prototypes!)

So for your small example that would be:

`main.ino`:

    #include "driver.h"
    void setup() {
      Serial.begin(500000);
      PrintMessage();
    }

    void loop() {
    }

`driver.cpp`

    #include "driver.h"
    byte PrintMessage () {
      Serial.println("printin");
      return 0; //previously had no return although returning 'byte'.
    }

`driver.h`

     //Always use include guards
     #ifndef DRIVER_H
     #define DRIVER_H

     #include <Arduino.h>
     //All function prototypes from driver.cpp.
     byte PrintMessage();

     #endif /* DRIVER_H */

Also corrected a typo from `PrintMessge` to `PrintMessage`. This is the "professional" way to do it, seperate implementation and header files.


body:
I am new to Arduino so please give me some advice on this really simple problem. I am currently using an Arduino Mega in a school project to make 4 capacitive sensors which are supposed to receive an input when you touch the sensors, and I have programmed the arduino such that you will light up an LED upon touching the sensors.

Now the problem is after I light up the LEDs the serial data monitor gives me many different numbers when I am touching the sensors. Is it actually possible for me to tweak my program such that outputs of my sensor will show up as a single line of '0' when the sensor is not being touched and '1' when the sensor is being touched? This would really help me in the quantifying of some of the data I would wish to collect from my experiments with the sensors.

My code is

    #include <CapacitiveSensor.h>

    CapacitiveSensor   cs_2_4 = CapacitiveSensor(2,4); // 1M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
    CapacitiveSensor   cs_5_7 = CapacitiveSensor(5,7);
    CapacitiveSensor   cs_8_10 = CapacitiveSensor(8,10);
    CapacitiveSensor   cs_11_13 = CapacitiveSensor(11,13);

    void setup()
    {
       cs_2_4.set_CS_AutocaL_Millis(0xFFFFFFFF);// turn off autocalibrate on channel 1
       cs_5_7.set_CS_AutocaL_Millis(0xFFFFFFFF);
       cs_8_10.set_CS_AutocaL_Millis(0xFFFFFFFF);
       cs_11_13.set_CS_AutocaL_Millis(0xFFFFFFFF);

       Serial.begin(9600);
       pinMode(3,OUTPUT);
       pinMode(6,OUTPUT);
       pinMode(9,OUTPUT);
       pinMode(12,OUTPUT);
    }

    void loop()
    {
     long sensor1 =  cs_2_4.capacitiveSensor(50);
     long sensor2 =  cs_5_7.capacitiveSensor(50);
     long sensor3 =  cs_8_10.capacitiveSensor(50);
     long sensor4 =  cs_11_13.capacitiveSensor(50);
    Serial.print("\t");
    Serial.println(sensor1, BIN);  // print sensor output
    Serial.print("\t");
    Serial.print(sensor2, BIN);
    Serial.print("\t");
    Serial.print(sensor3, BIN);
    Serial.print("\t");
    Serial.print(sensor4, BIN);

        if(sensor1 >= 1000)
       {
        digitalWrite(3,HIGH);
       }
       else{
        digitalWrite(3,LOW);
       }
         if(sensor2 >= 1000)
       {
        digitalWrite(6,HIGH);
       }
       else{
        digitalWrite(6,LOW);
       }
        if(sensor3 >= 1000)
       {
        digitalWrite(9,HIGH);
       }
       else{
        digitalWrite(9,LOW);
       }
        if(sensor4 >= 1000)
       {
        digitalWrite(12,HIGH);
       }
       else{
        digitalWrite(12,LOW);
       }
       }

and the output that I end up receiving is

[![enter image description here][1]][1]

Hence it would be really great if I could tweak my code such that the output on the serial monitor would be '0' when there is no output(Not touching sensor) and '1' when there is an output (touching sensor)

Thanks a lot for the help once again!

  [1]: https://i.stack.imgur.com/AK7Yb.jpg

title: Changing Arduino Outputs into Binary

Answers: 2

body:
It sounds like what you want isn't really "binary", nor the bit-to-characters expansion of the touch readings.

Rather it sounds like what you want to do is to print the character '0' or '1' for the state of each button.  You already have the decisioning code for your outputs, so you can simply extend it for the serial prints:

    if(sensor1 >= 1000) {
       digitalWrite(3,HIGH);
       Serial.print("1");
    } else{
       digitalWrite(3,LOW);
       Serial.print("0");
    }

and so on, with the next set having tabs and the last a newline.

Worth noting, intermixing the printing and digital outputs will put some time delay between the outputs (potentially quite a bit if the evaluation gets ahead of the serial buffers), so another option could to do all the outputs and then all the prints, or store the decisions in a bit mask for later printins, etc.

body:
`capacitiveSensor` returns an analog value so you need to set a threshold for the point where 0 (AKA `false`) becomes 1 (AKA `true`):

<!-- language-all: lang-c++ -->

    long touchThreshold = 123;  // Adjust this according to your application

...

    boolean sensor1 = (cs_2_4.capacitiveSensor(50) > touchThreshold) ? true : false;

If you don't recognize that syntax, it's the [conditional operator](http://www.cplusplus.com/doc/tutorial/operators/#conditional) but you could just as well use `if`.


body:
I'm just beginning to understand Arduino. Please bear with me. I have a collision avoidance car running on Arduino Uno, WB291111 L298N motor driver, SG90 servo, Arduino Shield v5, and HC-SR04 ultrasonic sensor. Also, I have the entire setup running on 8.4v batteries. If I just use HIGH/LOW on the motors, it will run without any problems. But if I use the PWM to run the motors on different speeds, it will NOT run at all. The sensor and servo works, but not the motors.  See my codes below. Let me know if you need further details. Any help is greatly appreciated.

    #include <Servo.h>
    #include <NewPing.h>

    //our L298N control pins
    const int enA = 10;
    const int in1 = 6;
    const int in2 = 7;

    const int enB = 9;
    const int in3 = 4;
    const int in4 = 5;

    //sensor pins
    #define trig_pin A2
    #define echo_pin A1

    #define maximum_distance 500
    boolean goesForward = false;
    int distance = 100;

    NewPing sonar(trig_pin, echo_pin, maximum_distance);
    unsigned int uS;

    #define SERVO_PIN 11
    Servo servo_motor;

    void setup(){
      Serial.begin(115200);
      pinMode(enA, OUTPUT);
      pinMode(enA, OUTPUT);
      pinMode(in1, OUTPUT);
      pinMode(in2, OUTPUT);
      pinMode(in3, OUTPUT);
      pinMode(in4, OUTPUT);

      servo_motor.attach(SERVO_PIN);

      servo_motor.write(115);
      delay(2000);
      distance = readPing();
      delay(100);
      distance = readPing();
      delay(100);
      distance = readPing();
      delay(100);
      distance = readPing();
      delay(100);
    }

    void loop(){

      int distanceRight = 0;
      int distanceLeft = 0;
      delay(50);

      if (distance <= 20){
        moveStop();
        delay(300);
        moveBackward();
        delay(200);
        moveStop();
        delay(300);
        distanceRight = lookRight();
        delay(200);
        distanceLeft = lookLeft();
        delay(200);

        if (distance >= distanceLeft){
          turnRight();
          moveStop();
        }
        else{
          turnLeft();
          moveStop();
        }
      }
      else{
        moveForward();
      }
        distance = readPing();
    }

    int lookRight(){
      Serial.print("Look Right");
      servo_motor.write(50);
      delay(500);
      int distance = readPing();
      delay(100);
      servo_motor.write(115);
      return distance;
    }

    int lookLeft(){
      Serial.print("Look Left");
      servo_motor.write(170);
      delay(500);
      int distance = readPing();
      delay(100);
      servo_motor.write(115);
      return distance;
      delay(100);
    }

    int readPing(){
      delay(70);
      int cm = sonar.ping_cm();
      if (cm==0){
        cm=500;
      }
      return cm;

    }

    void moveStop(){
      Serial.print("Stop");

      digitalWrite(in3, LOW);
      digitalWrite(in1, LOW);
      digitalWrite(in4, LOW);
      digitalWrite(in2, LOW);
    }

    void moveForward(){

      //if(!goesForward){

        //goesForward=true;

        Serial.print("Forward");

        digitalWrite(in1, HIGH);
        digitalWrite(in3, HIGH);

        digitalWrite(in2, LOW);
        digitalWrite(in4, LOW);

        analogWrite(enA, 250);
        analogWrite(enB, 250);

      //}
    }

    void moveBackward(){

      //goesForward=false;

      Serial.print("Backward");

      digitalWrite(in2, HIGH);
      digitalWrite(in4, HIGH);

      digitalWrite(in1, LOW);
      digitalWrite(in3, LOW);

    }

    void turnRight(){
      Serial.print("Right");

      digitalWrite(in1, HIGH);
      digitalWrite(in4, HIGH);

      digitalWrite(in2, LOW);
      digitalWrite(in3, LOW);

      delay(200);

      digitalWrite(in1, HIGH);
      digitalWrite(in3, HIGH);

      digitalWrite(in2, LOW);
      digitalWrite(in4, LOW);

    }

    void turnLeft(){
      Serial.print("Left");

      digitalWrite(in2, HIGH);
      digitalWrite(in3, HIGH);

      digitalWrite(in1, LOW);
      digitalWrite(in4, LOW);

      delay(200);

      digitalWrite(in1, HIGH);
      digitalWrite(in3, HIGH);

      digitalWrite(in2, LOW);
      digitalWrite(in4, LOW);
    }

title: DC motors not running using PWM and L298N motor driver

Answers: 1

body:
According to the [Servo reference page][1] it's not possible to use Servo library and PWM outputs on the pins 9 and 10.

> On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.

  [1]: https://www.arduino.cc/en/Reference/Servo


body:
I have a tutorial to finish and I don't know the code I have to use to make all (4 LEDs) to turn on in order. So this is my code and my simulation. Thanks in advance!

[![Figure 1][1]][1]

My Code:

    void setup() {
      pinMode(13, OUTPUT);
      pinMode(12, OUTPUT);
      pinMode(9, OUTPUT);
      pinMode(6, OUTPUT);
    }

    void loop() {
      digitalWrite(13, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(6, HIGH);
      delay(100); // Wait for 100 millisecond(s)

      digitalWrite(13, LOW);
      digitalWrite(12, LOW);
      digitalWrite(9, LOW);
      digitalWrite(6, LOW);
      delay(100); // Wait for 100 millisecond(s)
    }

EDITED:
I have to follow this one. I guess my simulator is correct.

[![Figure 2][2]][2]

  [1]: https://i.stack.imgur.com/3UGDd.jpg
  [2]: https://i.stack.imgur.com/OIQmy.jpg

title: Turn on each of the LEDs in order, by setting the cycle delay to 100 milliseconds

Answers: 3

body:
Your code switches them all ON and OFF simultaneously.

What I read from your question is you want to turn them on in order.
In this case, use a simple state diagram. This means you have to create variable (preferably an enumeration), e.g.:

    enum EState { FIRST_ON, SECOND_ON, THIRD_ON, FOURTH_ON };

    EState _state;

You can better use better names than FIRST_ON, ..., but I do not know what your lights mean.

In the setup, you initialize _state, e.g.

    _state = FIRST_ON;

Than in the loop you check and change the state:

    switch (_state)
    {
    case FIRST_ON:
        digitalWrite(13, HIGH); // Assuming this is the first light
        digitalWrite(12, LOW); // Put the others off
        ...
        ...
        _state = SECOND_ON; // Set the next state
        break;

    case SECOND_ON:
        digitalWrite(13, LOW); // Assuming this is the first light
        digitalWrite(12, HIGH); // Put the second LED on
        .. // Put the third/fourth off
        _state = THIRD_ON; // Set the next state
        break;

        // Do the same for THIRD_ON and FOURTH_ON

    default: // in all other cases
         break; // Should not happen
    }

    delay(100: // Wait for 100 milliseconds

Note, to not complicate the example, I've written out (mostly) the lines like you:

    digitalWrite(13, HIGH);
    digitalWrite(12, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(6, HIGH);

However, since these are almost copies (4 in the state diagram), it is best to write a separate function:

    void SwitchLedsOn(int led1State, int led2State, int led3State, int led4State)
    {
      digitalWrite(13, led1State);
      digitalWrite(12, led2State);
      digitalWrite(9, led3State);
      digitalWrite(6, led4State);
    }

Now you can use in the first state case:

    case FIRST_ON:
        SwitchLedsOn(HIGH, LOW, LOW, LOW); // Switch only first on
        break;

And do similar with the other states.

body:
add this to loop() end

     digitalWrite(13, HIGH);
     delay(100);
     digitalWrite(12, HIGH);
     delay(100);
     digitalWrite(9, HIGH);
     delay(100);

body:
I see in your second diagram that you are controlling the ground side of the LEDs. digitalWrite(PinNumber, HIGH) will turn an LED OFF, digitalWrite(PinNumber, LOW) will turn an LED ON. Using delay() in a sketch should be avoided.

    void setup(){
      pinMode(13, OUTPUT);
      pinMode(12, OUTPUT);
      pinMode(9, OUTPUT);
      pinMode(6, OUTPUT);
      digitalWrite(13, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(6, HIGH);
    }

    void loop(){
      digitalWrite(13, LOW);
      delay(100);
      digitalWrite(12, LOW);
      delay(100);
      digitalWrite(9, LOW);
      delay(100);
      digitalWrite(6, LOW);
      delay(100);
      digitalWrite(13, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(6, HIGH);
      delay(100);
    }


body:
I'm new to Arduino and am working on a project with my son.  We are using the [LillyPad USB][1] board ([schematic][4]) to drive a bunch of [LEDs][2] ([LED Datasheet][5]).  Our project is based loosely off of the ['Turn Signal Biking Jacket'][3].

Our project calls for 7-11 LEDs in parallel on a single circuit.  In the 'Turn Signal' project the LEDs are driven off of a **pair** of output pins (1 HIGH and 1 LOW).  In a circuit that looks like this...

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/nTDrd.png)

<!-- End schematic -->

Is this ideal?  Would it make more sense to connect the LED-chain to Vcc and have the return line connected to a single output set to LOW (to turn on the lights)?

If we were to have 3-4 of these LED-chains on at once, do I have to be concerned with total draw on the microcontroller?

Help? Thoughts?

  [1]: http://www.pighixxx.com/test/portfolio-items/lilypad-usb/
  [2]: https://www.sparkfun.com/products/13902
  [3]: http://www.instructables.com/id/turn-signal-biking-jacket/
  [4]: https://cdn.sparkfun.com/datasheets/E-Textiles/Lilypad/Lilypad_Arduino_USB_v12.pdf
  [5]: https://www.sparkfun.com/datasheets/DevTools/LilyPad/APT3216QWF-D.pdf

title: Designing around Output pin limitations

Answers: 1

body:
If you know the forward voltage of the LEDs you can easily do some calculations.

For a typical red LED the forward voltage is around 2V.  Other colours vary.  So we can work out that, at 5V supply, each LED with its own 150R resistor, would take:

         V    5-2
    I = --- = --- = 20mA
         R    150

With 11 LEDs in parallel on at once that would be 0.02 * 11 = 220mA.

**That is far more than the 25mA an IO pin is able to supply, so you will damage the Arduino doing it like that.**

Instead you will need to switch each chain of LEDs with a transistor of some form.  I'd choose a logic-level N-channel MOSFET as a "low-side" switch:

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/NnjzS.png)

<!-- End schematic -->

Now your Arduino doesn't care about the current - all it sees is the MOSFET.

If your LED forward voltages are less than 2.5V you can also chain them together to halve the current:

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/CJGP1.png)

<!-- End schematic -->

Since the forward voltage is now double you use a smaller resistance to set the current (R=V/I, where V is 5-2Vf).


body:
Here's my code after editing the measurement had error. Now the ultrasonic measurement is working but the vibration motor is not vibrating.

    #define trigPin1 8
    #define echoPin1 7
    #define motorPin1 13

    long duration, distance, UltraSensor;

    void setup()
    {
      Serial.begin(9600); // to use the serial monitor.
      pinMode(trigPin1, OUTPUT);
      pinMode(echoPin1, INPUT);
      //pinMode(motorPin1, OUTPUT);

    }

    void SonarSensor(int trigPin, int echoPin)
    {
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
      duration = pulseIn(echoPin, HIGH);
      distance = (duration / 2) / 29.1;
      delay(100);
    }

    void loop()
    {
      SonarSensor(trigPin1, echoPin1);
      UltraSensor = distance;
      Serial.print(distance); // print out the distance on Serial Monitor
      Serial.println("cm");
    //
      if (distance <= 60 && distance >= 45) // Checking the distance, you can change the value
      {
        digitalWrite(motorPin1, HIGH); // motor on
        delay(200);
        digitalWrite(motorPin1, LOW); // motor off
        delay(200);
      }
      else if(distance < 45 && distance >=30)
      {
        digitalWrite(motorPin1, HIGH); // when greater than 100cm
        delay(100);
        digitalWrite(motorPin1, LOW);
        delay(100);
      }
      else if(distance < 30)
      {
       digitalWrite(motorPin1, HIGH);
       delay(50);
       digitalWrite(motorPin1, LOW);
       delay(50);
      }
      else
      {
        digitalWrite(motorPin1, LOW);
      }
    }

title: Arduino with Ultrasonic sensor integrated but vibration motor not working according to the code

Answers: 1

body:
I think you have to uncomment the line that defines the motor as an output device.

 //pinMode(motorPin1, OUTPUT);


body:
I need a program created that will both run a DC motor and an LED sequence at the same time. The image is what the DC motor code should do.

    /*
    -==:: 3 Volts DC Motor Driver with Dual 555 Timer IC ::==-
      * Control Pin from 555 IC is needed to STOP the motor
      * Trigger Pin from 555 IC is needed to drive forward or backward
      * PWM on Trigger Pin is used to set the speed
      * Note : Forward and Backward is interchangeable via Motor connection.
     */

    int controlPin = 2; // 555 pinout 5
    int triggerPin = 3; // 555 pinout 2

    // the setup routine runs once when you press reset:

    void setup()  {
      pinMode(controlPin, OUTPUT);
      pinMode(triggerPin, OUTPUT);
    }

    // the loop routine runs over and over again forever:
    void loop()  {
    //  move FORWARD;
        digitalWrite(controlPin, HIGH);
        digitalWrite(triggerPin, HIGH); //full speed
        delay(3000);
    //    PWM testing to control motor speed
    //    analogWrite(triggerPin, 128+70); //minimum speed (128+70)
    //    delay(3000);

    //  STOP;
        digitalWrite(controlPin, LOW);
        digitalWrite(triggerPin, HIGH);
        delay(3000);

    //  move BACKWARD;
        digitalWrite(controlPin, HIGH);
        digitalWrite(triggerPin, LOW); //full speed
        delay(3000);

    //    PWM testing to control motor speed

    //    analogWrite(triggerPin, 128-70); //minimum speed (128-70)
    //    delay(3000);

    //  STOP;
        digitalWrite(controlPin, LOW);
        digitalWrite(triggerPin, HIGH);
        delay(3000);
    }

As for the LED code I have no idea. I just found this code on the web. The important thing is that the codes execute at the same time continuously.

title: Create a sketch that allows me to run a DC motor and LED sequence at the same time

Answers: 1

body:
As stated in the comments, the Arduino can only execute 1 command at a time. There is no real multi-threading on this hardware. But you can to the work in sequence so fast, that you won't notice the difference with motors or LEDs. Here it is important to use non-blocking code, which doesn't block the execution of other code, when it is only waiting (the `delay()` function is just busy waiting).

For doing anything non-blocking (as setting LEDs or changing the state of a motor) you can use the `millis()` function. Refer to the `BlinkWithoutDelay` example from the Arduino IDE. For a very simple sequence (as blinking) you can directly use the code from the example. Basically you use a timestamp, which holds the last time, the blink code was executed. On every iteration of the `loop()` function you check, if a certain time has passed since the timestamp have been taken. If so, execute the code again and update the timestamp:

    unsigned long timestamp=0;
    void loop(){
      if(millis()-timestamp > 500){
        digitalWrite(led_pin,!digitalRead(led_pin));
        timestamp = millis();
      }
    }

This code would toggle the led_pin each 500ms.

For coding complex sequences you can make a state machine. For this you create a numeric state variable. In the `loop()` function you use a `switch`-`case`-statement, to execute the right code for each state of your programm. Also directly in the `loop()` function you change the state variable depending on the time through the above code. This would look somewhat like this:

    int state = 0;
    unsigned long timestamp = 0;
    void loop(){
      if(millis() - timestamp > 1000){
        state++;
        timestamp = millis();
      }

      switch(state){
        case 0:
          digitalWrite(led_pin,!digitalRead(led_pin));
          //  move FORWARD;
          digitalWrite(controlPin, HIGH);
          digitalWrite(triggerPin, HIGH); //full speed
          break;
        case 1:
        case 2:
          digitalWrite(led_pin,!digitalRead(led_pin));
          break;
        case 3:
          digitalWrite(led_pin,!digitalRead(led_pin));
          // stop moving
          digitalWrite(controlPin, LOW);
          digitalWrite(triggerPin, HIGH);
          break;
        case 4:
        case 5:
          digitalWrite(led_pin,!digitalRead(led_pin));
          break;
        case 6:
          digitalWrite(led_pin,!digitalRead(led_pin));
          //  move BACKWARD;
          digitalWrite(controlPin, HIGH);
          digitalWrite(triggerPin, LOW); //full speed
          break;
        case 7:
        case 8:
          digitalWrite(led_pin,!digitalRead(led_pin));
          break;
        case 9:
          digitalWrite(led_pin,!digitalRead(led_pin));
          // stop moving
          digitalWrite(controlPin, LOW);
          digitalWrite(triggerPin, HIGH);
          break;
        case 10:
        case 11:
          digitalWrite(led_pin,!digitalRead(led_pin));
          break;
        case 12:
          state = 0;
          break;
      }
    }

This code would toggle the led_pin every second and also doing the moto sequence `3s forward, 3s stop, 3s backwards, 3s stop`. This sequence loops forever.

When you only want to let the led blink continuously, it would be easier to exclude this part of the code from the state machine, but I wanted to show how this principle would work (for example if you want to include a complex blinking sequence).


body:
I am trying to write a pice of code which send to a receiver the frequency to listen.

As per its documentation, it should receive the following sequence:

> Example with **123.456** MHz
>
>  Command to send (frequency converted in 4 bytes, followed by 2 instruction bytes
>
> 0x**12** 0x**23** 0x**56** 0x00 0x01

To be able to memorize six frequencies, I fill an array:

    uint32_t mem_freq[6] = {
       0x121050,
       0x126500,
       0x120500,
       0x121700,
       0x121825,
       0x118700,
    };

My concern is that when I do :

    Serial.write(mem_freq[mem_index]);
    //Serial.write(0x00);
    //Serial.write(0x01);
Only 1 byte is sent, and it's hard to debug as the serial console displays only ascii characters.

When I use Serial.print instead, mem_freq[2] shows correctly 0x120500

After Majenko's answer, I tried this:

    Serial.print(0x123456 >> 16,HEX);
    Serial.print(0x123456 >> 8,HEX);
    Serial.print(0x123456,HEX);
    Serial.print(0x00,HEX);
    Serial.print(0x01,HEX);

And it outputs:

> 12123412345601

Is this normal ?

title: Array, hexadecimal and serial write

Answers: 2

body:
You need to manually split your values into bytes. You can either do that by storing them as individual bytes (as shown by Ignacio), or by using bit shifting:

    Serial.write(mem_freq[mem_index] >> 16);
    Serial.write(mem_freq[mem_index] >> 8);
    Serial.write(mem_freq[mem_index]);

That sends the bits 16-23 (0x12) then bits 8-15 (0x10) followed by bits 0-7 (0x50).

body:
That's because you need to use an array of arrays, and send three bytes.

    uint32_t mem_freq[6][3] = {
      {0x12, 0x10, 0x50},
       ...
    };

     ...
      Serial.write(mem_freq[mem_index], 3);
     ...


body:
Im a student and working on a arduino project for IoT competition and me and my team have built a house and I made this code below.
For some reason when I upload it to my Arduino MKR1000 it constantly turns D6 and D8 on and right after their both on it turns them off and so on for ever. I cant figure out why is it doing that because its only these 2 but not the rest of them.

Quick help would be appreciated.

Please note that I'm by any means a PRO at this but I do know my share about programming.

            //Definiramo ispis na serial port
    #define BLYNK_PRINT Serial

    //Ucitavamo biblioteke
    #include <SPI.h>
    #include <WiFi101.h>
    #include <BlynkSimpleMKR1000.h>

    // Autorizacijski kod za aplikaciju Blynk
    char auth[] = "Token";

    // Podatci za WiFi
    char ssid[] = "SSID";
    char pass[] = "PASSWORD";

    // ----- Inicializacija ledica -----
    const int ledBorDim = 2;
    const int ledKuh = 6;
    const int ledTrp = 7;
    const int ledKup = 8;
    const int lediceUlaz = 9;
    const int ledSpav = 10;

    // ----- Inicializacija gumbova -----
    const int gumbKuh = 11;
    const int gumbKup = 12;
    const int gumbSpav = 13;
    const int gumbBor = 14;

    // ----- Kontrolne varijable -----
    int stanjeLedKuh = 0;
    int stanjeLedKup = 0;
    int stanjeLedBor = 0;
    int stanjeLedSpav = 0;

    int gumbStanjeKuh = 0;
    int gumbStanjeSpav = 0;
    int gumbStanjeBor = 0;
    int gumbStanjeKup = 0;

    //Led kuhinja
    BLYNK_WRITE(V3)
    {
      int pinValue = param.asInt(); //Pinvalue postavljamo da bude vrijednost ono sto postavimo na aplikaciji
      Serial.print("ledKuh = "); //Ispis na ekran trenutno stanje
      Serial.println(pinValue);
      if (pinValue == 1)
      {
        digitalWrite(ledKuh, HIGH);
        stanjeLedKuh = 1;
      } if (pinValue == 0)
      {
        digitalWrite(ledKuh, LOW);
        stanjeLedKuh = 0;
      }
    }

    //Ledica za kupaonicu
    BLYNK_WRITE(V5)
    {
      int pinValue = param.asInt(); //Pinvalue postavljamo da bude vrijednost ono sto postavimo na aplikaciji
      Serial.print("ledKup = "); //Ispis na ekran trenutno stanje
      Serial.println(pinValue);
      if (pinValue == 1)
      {
        digitalWrite(ledKup, HIGH); //Promjena stanja na izlazu arduina
        stanjeLedKup = 1;
      } if (pinValue == 0)
      {
        digitalWrite(ledKup, LOW); //Promjena stanja na izlazu arduina
        stanjeLedKup = 0;
      }
    }

    //Paralelni spoj ledica na ulazu
    BLYNK_WRITE(V6)
    {
      int pinValue = param.asInt(); //Pinvalue postavljamo da bude vrijednost ono sto postavimo na aplikaciji
      Serial.print("lediceUlaz = "); //Ispis na ekran trenutno stanje
      Serial.println(pinValue);
      if (pinValue == 1)
      {
        digitalWrite(lediceUlaz, HIGH); //Promjena stanja na izlazu arduina
      } if (pinValue == 0)
      {
        digitalWrite(lediceUlaz, LOW); //Promjena stanja na izlazu arduina
      }
    }

    //Dimmer za Boravak
    BLYNK_WRITE(V1)
    {
      int pinValue = param.asInt(); //Ucitamo vrijednost
      Serial.print("Dimmer vrijednost: "); //Ispisemo na serial
      Serial.println(pinValue);
      analogWrite(ledBorDim, pinValue); //Na izlaz postavljamo vrijednost
      if (pinValue == 0)
      {
        Blynk.virtualWrite(V50, 1);
        stanjeLedBor = 0;
      } else if (pinValue > 0)
      {
        Blynk.virtualWrite(V50, 0);
        stanjeLedBor = 1;
      }
    }

    BLYNK_WRITE(V50)
    {
      int pinValue = param.asInt();
      if (pinValue == 1)
      {
        analogWrite(ledBorDim, 255);
        Blynk.virtualWrite(V1, 255);
        stanjeLedBor = 1;
      } if (pinValue == 0)
      {
        digitalWrite(ledBorDim, LOW);
        Blynk.virtualWrite(V1, 0);
        stanjeLedBor = 0;
      }
    }

    void gumbKuhinja()
    {
      gumbStanjeKuh = digitalRead(gumbKuh);
      if (gumbStanjeKuh == LOW)
      {
        if(stanjeLedKuh == 1)
        {
          digitalWrite(ledKuh, LOW);
          Blynk.virtualWrite(V3, 0);
          Serial.println("Ledica na V3/D6 je LOW");
          stanjeLedKuh = 0;

        } else if (stanjeLedKuh == 0)
        {
          digitalWrite(ledKuh, HIGH);
          Blynk.virtualWrite(V3, 1);
          Serial.println("Ledica na V3/D6 je HIGH");
          stanjeLedKuh = 1;

        }
        delay(500);
      }
    }

    void gumbKupaonica()
    {
      gumbStanjeKup = digitalRead(gumbKup);
      if (gumbStanjeKup == LOW)
      {
        if(stanjeLedKup == 1)
        {
          digitalWrite(ledKup, LOW);
          Blynk.virtualWrite(V5, 0);
          Serial.println("Ledica na V5/D8 je LOW");
          stanjeLedKup = 0;

        } else if (stanjeLedKup == 0)
        {
          digitalWrite(ledKup, HIGH);
          Blynk.virtualWrite(V5, 1);
          Serial.println("Ledica na V5/D8 je HIGH");
          stanjeLedKup = 1;
        }
        delay(500);
      }
    }

    void gumbSpavaca()
    {
      gumbStanjeSpav = digitalRead(gumbSpav);
      if (gumbStanjeSpav == LOW)
      {
        if(stanjeLedSpav == 1)
        {
          digitalWrite(ledSpav, LOW);
          Blynk.virtualWrite(V6, 0);
          Serial.println("Ledica na V6/D10 je LOW");
          stanjeLedSpav = 0;
        } else if (stanjeLedSpav == 0)
        {
          digitalWrite(ledSpav, HIGH);
          Blynk.virtualWrite(V6, 1);
          Serial.println("Ledica na V6/D10 je HIGH");
          stanjeLedSpav = 1;
        }
        delay(500);
      }
    }

    void gumbBoravak()
    {
      gumbStanjeBor = digitalRead(gumbBor);
      if (gumbStanjeBor == LOW)
      {
        if(stanjeLedBor == 1)
        {
          analogWrite(ledBorDim, 0);
          Blynk.virtualWrite(V1, 0);
          Serial.println("Ledica na V1/D2 je 0");
          stanjeLedBor = 0;
        } else if (stanjeLedBor == 0)
        {
          analogWrite(ledBorDim, 255);
          Blynk.virtualWrite(V1, 1);
          Serial.println("Ledica na V1/D2 je 255");
          stanjeLedBor = 1;
        }
        delay(500);
      }
    }

    void setup()
    {

      pinMode(ledBorDim, OUTPUT);
      pinMode(ledKuh, OUTPUT);
      pinMode(ledKup, OUTPUT);
      pinMode(lediceUlaz, OUTPUT);
      pinMode(ledSpav, OUTPUT);

      pinMode(gumbKuh, INPUT);
      pinMode(gumbKup, INPUT);
      pinMode(gumbSpav, INPUT);
      pinMode(gumbBor, INPUT);

      // Debug console
      Serial.begin(9600);
      //Povezivanje na WiFi i na aplikaciju Blynk
      Blynk.begin(auth, ssid, pass);
    }

    void loop()
    {
      Blynk.run();
      gumbKuhinja();
      gumbKupaonica();
      gumbSpavaca();
      gumbBoravak();
    }

Serial outpout:

    Ledica na V6/D10 je HIGH
    Ledica na V1/D2 je 255
    Ledica na V6/D10 je LOW
    Ledica na V1/D2 je 0
    Ledica na V6/D10 je HIGH
    Ledica na V1/D2 je 255
    Ledica na V6/D10 je LOW
    Ledica na V1/D2 je 0
    Ledica na V6/D10 je HIGH
    Ledica na V1/D2 je 255
    Ledica na V6/D10 je LOW
    Ledica na V1/D2 je 0
    Ledica na V6/D10 je HIGH
    Ledica na V1/D2 je 255

[![Breadboard schematic][1]][1]

Little label reading D14 means that that pin isnt suppoast to go to D4 but to D14 of the MKR1000 but since i dont have that board in the program im stuck with arduino Uno.<br>
Short explanation of the code...
We build a house out of styrofoam and placed 6 Led's around and almost all can be controlled from the Blynk app on my device. Also there are 4 buttons controlling 4 Led's. I have it setup so that when i press a button it changes the state of a particular LED and then sets the appropriate value on the app (If LED is on then set app value to 1). Pretty much that that about this code. Sorry if you cant understand but I had to write it in my native language since this is going to be a compettition and I was told that they wouldn't like if the code was in english for some reason.

  [1]: https://i.stack.imgur.com/Dtt5I.png

title: Changing outputs infinitely for no reason

Answers: 1

body:
You had the following general problem:

The code you were using was configuring a pin into `INPUT` mode and reading the value on it. On this pin you conencted a button **without extern pullup or pulldown resistor**. This means that if the button is **not pressed**, it is not connected to anything and thus a **floating pin**. You cannot realibly read the value of the floating pin, as its voltage level may be on pretty much anything. It picks up interference like an antenna.

To solve this the button pin must be pulled to known voltage level if it is not connected (aka button is not pressed). We achieve this by using a resistor which is on one end connected to the button pin and on the other end connected to either VCC (+5V) or GND (0V). This has the effect that when the button is not pressed, the resistor pulls the voltage level of this pin up (if connected to VCC), or down if connected to GND.

We can either attach a resistor (e.g. 10K Ohm) in the circuit or active the internal (weak) pull-up resistors in our microcontroller. In Arduino, this is achieved by using `pinMode( buttonPin, INPUT_PULLUP)`.

[![enter image description here][1]][1]

In this circuit with `INPUT_PULLUP` on D2, we have:

* if the button is not pressed down, no connection to GND is made. The activated pull-up resistor will pull the voltage level of D2 to HIGH
* if the button is pressed down, it makes a connection to GND and overrides the pullup resistor. Pin D2 now reads LOW.

The logic can of course also be inverted -- you can use a PULLDOWN resistor and instead of connecting the button to GND on the other side connect it do 5V. This make the button read LOW when unpressed and HIGH pressed.

So the modified code must be changed from

      pinMode(gumbKuh, INPUT);
      pinMode(gumbKup, INPUT);
      pinMode(gumbSpav, INPUT);
      pinMode(gumbBor, INPUT);

to

      pinMode(gumbKuh, INPUT_PULLUP);
      pinMode(gumbKup, INPUT_PULLUP);
      pinMode(gumbSpav, INPUT_PULLUP);
      pinMode(gumbBor, INPUT_PULLUP);

and the logic which detects a button pressed must be changed to trigger an action when the pin is LOW (because a PULLUP is used, button reads LOW when pressed, HIGH else).

So from code of the form

    void gumbBoravak()
    {
      gumbStanjeBor = digitalRead(gumbBor);
      if (gumbStanjeBor == HIGH)
      {
        /* LED toggling and debouncing */
        delay(500);
      }
    }

To

    void gumbBoravak()
    {
      gumbStanjeBor = digitalRead(gumbBor);
      if (gumbStanjeBor == LOW)
      {
        /* LED toggling and debouncing */
        delay(500);
      }
    }

Also I recommend you to watch this youtube video to learn more about floating pins and pullup/pulldown resistors: [Pull up Resistor Tutorial][2]

  [1]: https://i.stack.imgur.com/yq9bD.png
  [2]: https://www.youtube.com/watch?v=wxjerCHCEMg


body:
So I've got three boards that I'm using to test this ([modified][1]) code:

    int sensor1Pin = A0;
    int sensor2Pin = A1;
    int sensor3Pin = A2;

    float sensors[] = {0,0,0};

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

    void loop(){

    sensors[0] = analogRead(sensor1Pin);
    sensors[1] = analogRead(sensor2Pin);
    sensors[2] = analogRead(sensor3Pin);

    Serial.print(sensors[0]);
    Serial.print(",");
    Serial.print(sensors[1]);
    Serial.print(",");
    Serial.println(sensors[1]);
    }

An Uno, a Feather M0, and an MKR1000.
The code will only work on the Uno because it's AVR-based whereas the other two boards are SAMD. When running on a feather, you get this error:

    /home/ghylama/Arduino/libraries/SoftwareSerial_master/SoftwareSerial.cpp:260:2: error: #error This version of SoftwareSerial supports only 20, 16 and 8MHz processors
         #error This version of SoftwareSerial supports only 20, 16 and 8MHz processors

However, the resolution of the Uno is too low for my purposes (its DAC has a resolution of 10, whereas I need a resolution of 12, minimum). Are there any libraries/workarounds that I can use for this purpose?

I've tried SoftwareSerial, NeoSWSerial, and [this one][2].

  [1]: http://www.hackerscapes.com/2014/11/how-to-save-data-from-arduino-to-a-csv-file-using-processing/
  [2]: https://github.com/arduino-org/Arduino/commit/1364019868e2ad044c87dd0f143052a92eebda98

title: A SoftwareSerial library for SAMD boards

Answers: 1

body:
I will restate the problem as I have understood it: You want more Serial objects, aka more UART ports.

On your Adafruit Feather M0 with its SAMD21G18 Cortex-M0+ MCU, you have six SERCOM peripherals which you can arbitrarily configure to be a UART, I2C or SPI port. Each peripheral can have its connections routed to several different pins on the board. It is a very versatile piece of hardware.

Don't use a SoftwareSerial library made for AVR MCUs when you have the hardware. Adafruit's guide shows how you can reconfigure those SERCOMs to get additional `Serial` objects.

https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports?view=all#creating-a-new-serial


body:
I've got a mini weather-station with a Davis Anemometer Vantage Pro that uses a reed switch to detect rotations. Using the rotations it then can convert to MPH. When using it alone, I have no problem measuring the wind speed. It measures the rotations over a 3 second period, and finds the average wind speed over those 3 seconds; however, when implemented into a group of code that also writes Temperature, Humidity, and Accelerometer data to an SD card, it crashes my code. For the sake of keeping this comment shorter, I am using code from http://cactus.io/hookups/weather/anemometer/davis/hookup-arduino-to-davis-anemometer-wind-speed, and am implementing into the code below. It's a big chunk, but the important stuff should be the ISR_rotation and enabling interrupts at the start of the loop.

    // going to include all the libraries we need and definitions
    #include "SD.h" //sd card
    #include"SPI.h" //sd card
    #include "SHT1x.h" //temp/humid
    #include <Wire.h> //accelerometer
    #include <Adafruit_MMA8451.h> //accelerometer
    #include <Adafruit_Sensor.h> //accelerometer
    #include <math.h> //for wind speed
    //define pins and functions
    #define dataPin 6 //data pin for temp/humid
    #define sckPin 7 //serial clock for temp/humid
    #define WindSensorPin (2) //pin for wind sensor
    SHT1x th_sensor(dataPin, sckPin); //caling sht1x.h
    Adafruit_MMA8451 mma = Adafruit_MMA8451(); //calling the accelerometer library

    //WindSpeed stuff
    volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
    volatile unsigned long ContactBounceTime=0; // Timer to avoid contact bounce in interrupt routine
    float WindSpeed; // speed miles per hour

    //SD card stuff
    const int chipSelect = 10;
    String dataString =""; // holds the data to be written to the SD card
    File sensorData;

    //Temp/Humid stuff
    float humid; // humidity value
    float temp_c; // temperature value

    void setup(){
      // Open serial communications
      Serial.begin(9600);
      Serial.print("Initializing SD card...");
      pinMode(chipSelect, OUTPUT); //sd writing
      pinMode(WindSensorPin, INPUT); //wind data
      attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);//""wind interrupt""

      // see if the card is present and can be initialized:
      if (!SD.begin(chipSelect)) {
        Serial.println("Card failed, or not present");
      // don't do anything more:
      return;
      }
      //accelerometer setup
      if (! mma.begin()) {
        Serial.println("Couldnt start");
        while (1);
      }
      Serial.println("MMA8451 found!");
      mma.setRange(MMA8451_RANGE_2_G);
      Serial.print("Range = "); Serial.print(2 << mma.getRange());
      Serial.println("G");
    }

    //
    void loop(){
      //This interrupt portion is for incrementing Rotations
      Rotations = -22; // Set Rotations count to 0 ready for calculations
      //interrupts(); // Enables interrupts
      //delay (3000); // Wait 3 seconds to average
      //noInterrupts(); // Disable interrupts
      //convert to mp/h using the formula V=P(2.25/T) where T is the delay in seconds
      //V = P(2.25/3) = P * 0.75
      //WindSpeed = Rotations * 0.75;

      //read the temperature/humidity sensor
      humid=th_sensor.readHumidity();
      temp_c=th_sensor.retrieveTemperatureC();

      //read the 'raw' data in 14-bit counts for accelerometer
      //mma.x for x direction, mma.y for y direction, mma.z for z direction
      mma.read();
      //Convert 14 bit to SI units (m/s^2)
      sensors_event_t event;
      mma.getEvent(&event);
      delay(3000);
      WindSpeed = Rotations * 0.75;
      //read the wind speed data

      //build the data string
      dataString = String(temp_c) + "," + String(humid) + "," + String(event.acceleration.x) + "," + String(event.acceleration.y) + "," + String(event.acceleration.z);// + "," + String(WindSpeed); //to CSV
      saveData(); // save to SD card
      //for testing with serial monitor to see if we are obtaining correct values
      Serial.print("Temperature: ");
      Serial.print(temp_c);
      Serial.print(", Humidity: ");
      Serial.println(humid);
      Serial.print(" X: ");
      Serial.print(event.acceleration.x);
      Serial.print(" Y: ");
      Serial.print(event.acceleration.y);
      Serial.print(" Z: ");
      Serial.println(event.acceleration.z);
      Serial.print("Rotations: ");
      Serial.println(Rotations);
      delay(3000);
    }

    //
    void saveData(){
    if(SD.exists("data.csv")){ // check the card is still there
      // now append new data file
      sensorData = SD.open("data.csv", FILE_WRITE);
      Serial.println("Data written");
        if (sensorData){
        sensorData.println(dataString);
        sensorData.close(); // close the file
        }
      }
    else{
      Serial.println("Error writing to file/Card removed");
      }
    }

    // This is the function that the interrupt calls to increment the rotation count
    void isr_rotation () {
    if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
      Rotations++;
      ContactBounceTime = millis();
      }
    }

When any wind information and interrupts are commented out, I have no problem at all with writing to SD card and getting the correct data from the accelerometer and sht10. I must be doing something wrong with the interrupt, but I'm not sure. I've read to not include any serial prints, delays, keep em short, etc. and it works alone. It crashes right after running the setup (before it can serial print any information), which makes me believe it's something with the interrupt. I've tried commenting out noInterrupts() and it returns trash data for rotations, so that's not usable. In case it's important, the memory usage is in the 60% range, so that shouldn't be relevant.

Thanks for any help or advice you have.

EDIT: After totally removing the interrupt() and noInterrupts() portion, I get trash data for rotations that changes depending on the debounce timing (higher debounce limit=fewer triggered rotations). I seem to get a constant Rotations range of 20-23 that does pretty accurately depict how many rotations I add (for example spinning 8 times gets me around 30). I also prettied it up the code a little bit.

title: Interrupt crashes code when implemented

Answers: 1

body:
Your basic flaw is that you turn interrupts off (prior to commenting those lines out), and then attempt to use the SD card which almost certainly will want to use interrupts.

Your technique of turning interrupts on, and then doing a big delay, is not one I like. I comment on that sort of thing in [my page about interrupts](http://www.gammon.com.au/interrupts), in particular in [reply #10](http://www.gammon.com.au/forum/?id=11488&reply=10#reply10). The essence of that reply is:

---

## Timing an interval

I have seen example code suggesting you count things for a second by turning interrupts off for a second and then on again. I don't recommend this, because for one thing, you can't do serial prints if interrupts are off.

### Example (not recommended):

<!-- language: lang-c++ -->

    volatile unsigned long events;
    const unsigned long INTERVAL = 1000;  // 1 second

    void eventISR ()
      {
      events++;
      }   // end of eventISR

    void setup ()
      {
      Serial.begin(115200);
      attachInterrupt (digitalPinToInterrupt (2), eventISR, FALLING);
      }   // end of setup

    void loop ()
      {
      events = 0;       // reset counter
      interrupts ();    // allow interrupts
      delay (INTERVAL); // wait desired time
      noInterrupts();   // stop interrupts

      Serial.print ("I counted ");
      Serial.println (events);
      }  // end of loop

(This is effectively what your code does).

That may work for simple situations, but turning interrupts off means that the Serial prints won't work until they are turned on again (which they may not be in a more complex sketch).

It is better to use the millis() result and just detect when the time limit is up.

### Improved sketch:

<!-- language: lang-c++ -->

    volatile bool counting;
    volatile unsigned long events;

    unsigned long startTime;
    const unsigned long INTERVAL = 1000;  // 1 second

    void eventISR ()
      {
      if (counting)
        events++;
      }  // end of eventISR

    void setup ()
      {
      Serial.begin (115200);
      Serial.println ();
      attachInterrupt (digitalPinToInterrupt (2), eventISR, FALLING);
      }  // end of setup

    void showResults ()
      {
      Serial.print ("I counted ");
      Serial.println (events);
      }  // end of showResults

    void loop ()
      {
      if (counting)
        {
        // is time up?
        if (millis () - startTime < INTERVAL)
          return;
        counting = false;
        showResults ();
        }  // end of if

      noInterrupts ();
      events = 0;
      startTime = millis ();
      EIFR = bit (INTF0);  // clear flag for interrupt 0
      counting = true;
      interrupts ();
      }  // end of loop

In loop() here we wait for the interval (1 second in this case) to be up, otherwise we return, effectively doing nothing. You could of course do other things instead of just returning.

If the time is up we display the count.

If counting is not currently active (and presuming we want it to be active) we remember the start time, reset the counter to zero, and let it start counting up.

That code seemed to work OK up to 100 kHz, although the counts were getting a bit inaccurate. You can do more precise timings by using the hardware counters / timers. Details at [my Timers and counters page](http://www.gammon.com.au/timers).


body:
My question is about maximum current allowed by Arduino.

I know it's 200mA in Arduino and 40mA in every pin (lower in arduino mini). Just wondering if simultaneously read 16 hall sensor (than can be all activated at the same time) is too much.
My calculation is 200 / 16 = 12.5 mA máximum current I can drive to a pin from a sensor, but it's enough to read the sensor? Specs from 3144 hall sensor says it outputs 25mA when activated. Can I put a resistante between output's sensor and Arduino pin?

I'm planning to use Arduino mini and sensor hall 3144.

Sorry for my english, and thanks in advance!

p.s: The original idea was read all 64 sensors with one Arduino, but breaking it into several arduinos is easiest as my electronics knowledge is seriously limited :)

title: simultaneously read 16 hall sensor and maximum current allowed by Arduino

Answers: 2

body:
Since this sensor doesn't need to be driven directly from a pin, the maximum current for one pin is not important here. The hall sensor uses two of it's pins as supply voltage. The output pin is an Open-Collector pin. So it will be connected to GND trough a transistor depending on the magnetic field. If you use an external pullup resistor (as connection between OUTPUT and positive supply voltage), you get somewhat like a voltage divider. Since the hall sensor seems to behave as a switch, there will only be two possible states. When the magnetic field is low, the transistor doesn't let the current flow. The pullup resistor can pull the pin to the positive supply voltage (5V -> 1 as digital value). If the magnetic field is high enough, the transistor will open the connection to GND. Now a maximum of 25mA of current can flow throw it to GND. The voltage of the pin is now determined by the voltage divider the transistor and the pullup resistor build. You can calculate the virtual "resistance" of the transistor in this state with Ohm's law

> R = U/I

(R is resistance, U is voltage and I is current) With 5V supply voltage and 25mA current you get a resistance of 200 Ohm. Since you just want to use the sensor as a switch, you only have to ensure, that the pin cannot be pulled to a significantly greater value than 0V. **So grab a resistor, that is significantly higher than 200 Ohm and use it as pullup resistor.** Keep in mind, that you always must use the pullup resistor with the supply voltage, that runs the Arduino. A higher voltage can fry the Arduinos components.

Then you connect this pin to a digital pin of the Arduino, which you configure as INPUT. In this state the pin has a high impedance, so that the current, that flows into it, is really small (it CAN source 25mA, but it does not have to. The current depends on your external circuit). So this isn't something you have to bother about.

This leaves us with the supply current, that the sensor needs to work. In the datasheet it says, that at a supply voltage of 8V the supply current is at maximum 9mA. For 16 sensors this gives us a total of 144mA, which is still comfortable inside the 200mA the Arduino can provide. So you should be able to drive all of them safely.

That said, if you want to add more components, that draw current, it might be better so source the current you need not over the Arduino but directly from your power source (if this is possible for you). Depending on the current you may need, it can also be good, to get an external voltage regulator (if your supply doesn't directly give you 5V), that can provide enough current.

body:
As Gerben mentioned in a comment, you could set up a [matrix of the sensors](https://nerdclub-uk.blogspot.com.au/2015/08/multiplexing-array-of-hall-sensor-inputs.html).

Since the 3144 effectively is a switch to ground (when the magnet comes close it pulls the data line low) you would wire them up like a keypad matrix. I recently did [an answer](https://arduino.stackexchange.com/a/49888/10794) about a keypad matrix. If you wanted 64 sensors you would only need 16 Arduino pins (8 for the rows and 8 for the columns).

The keypad matrix I described already drives the rows low, so that is the right polarity for the sensors. You would just need a pull-up for the columns, say 10k. The sensor then just has to sink 5/10000 amps (0.5 mA) which is well within spec.

The supply voltage to the sensors can be provided independently of the Arduino (however 5V would be reasonable). Since the sensors apparently usually consume 4.4 mA, then 64 would consume 282 mA, which is probably quite reasonable to supply from the Arduino 5V pin.

The diodes mentioned in the keypad matrix answer are probably a sensible precaution if you are likely to have more than one sensor activated at once.