text:
AnalogRead from voltage divider ladder
I'm building a MIDI guitar, using an Arduino, sound synthesising and wood.
To properly know which note I'm pressing, I built a voltage divider with 12 equal resistors (10K). One side is connected at +5V and the other end at GND, so each of the 6 strings connects the right tap to the ADC.
I had just calculated the expected value w/ a bit of math considering I also needed a pullDown resistor(1M) and capacitor for every analog channel to keep the readings stable when no key is pressed.

When measuring with my multimeter the readings are stable, and there are variations of less than 0.02V, and since the difference from tap to tap is about 0.4V that's quite good.
The problem is when reading the 6 channels together: channels supposed to be pulled down to gnd read voltages caused by nearby channels, readings are shaky and similar errors.
This mess disappears on one channel when I connect the multimeter to that one.
Instead of buying 6 multimeters, I figured I could ask you if someone has an idea on why this happens, my guess is on the pulldown resistor, but I'm not sure about Arduino's ADC; I'm also worried about having 6 wires half of a meter each so close, so any other idea on finding the keys is welcome.
EDIT
@EdgarBonet was right, I used 12x220ohm resistors, and at first the results were absolute garbage, then I made it so the code would read each channel about 10 times, discard the readings, wait a millisecond and finally read and store the value. Now it is perfect.
Thanks again.

Circuit link doesn't work.

Excuse my naiveté but... why 12 taps for 6 strings? And why can't you wire those switches the usual way into digital inputs?

@EdgarBonet each string makes 12(+1 open) notes, and there are 6 strings; this means 72 inputs. That's too many switches

Oh, I see. Your circuit now makes perfect sense to me. You could simply reduce the resistances, e.g. R1 = ... = R12 = 1 kΩ and R_PD = 10 kΩ.

The datasheet of the ATmega328P (the main chip of the Uno) states:

The ADC is optimized for analog signals with an output impedance of
  approximately 10 kΩ or less.

The Thevenin equivalent output impedance of most taps of
your voltage ladder is higher than 10 kΩ. You 1 MΩ pulldown is
way beyond that limit. Cross talk from previously read channels is
exactly the symptom you expect from excess output impedance.
Taking each reading multiple times, until the value stabilizes, should
help. A buffer (e.g. an OP-amp set as a unit gain amplifier) is the
usual solution to this kind of impedance problems.

Actually, the whole works perfectly with R as 220 and pull downs as
  10K. The problem comes when connecting more than 3 strings at the same
  time, on any tap, as the pull down resistors become part of the
  ladder (i belive).

The pull down resistors will indeed have an effect on the potentials of
the voltage ladder, especially if you connect several strings. This
could be minimized by having the pull-downs be a lot more resistive
than the resistors along the ladder, but then you would need very low
resistances along the ladder, which is not desirable because of current
consumption and heating.
Here is an idea for an alternative solution: If you can spare 6 digital
pins, you could build for each analog input a pull-down circuit that is
switchable between a “strong pull” mode and a “weak pull” mode. Assuming
D0 is the “pull strength control” pin for A0, it would look like this:
A0 ---+--- 1 kΩ --- D0
      |
     1 MΩ
      |
     GND

Whenever you want to read A0, you:

set D0 to OUTPUT LOW, which creates a strong pull-down to ground
take a couple of analogRead()s
set D0 as INPUT, which leaves only the weak 1 MΩ pull down
take a couple of analogRead()s, keep the last one.

If A0 is not connected to the ladder, then the first reads will
discharge the internal sampling capacitor of the ADC. The final read is
done with only a weak pull-down, but this should be OK since the
capacitor has already been discharged.
The potentials along the voltage ladder will be disturbed by any string
connecting a tap to its strong pull-down, but this disturbance will
disappear when you switch to weak pull-down, so it will not affect the
readings.

I'm well open to changes in the circuit, and I used the first resistors I had.

Actually, the whole works perfectly with R as 220 and pull downs as 10K.
The problem comes when connecting more than 3 strings at the same time, on any tap, as the pull down resistors become part of the ladder(i belive). Would raising R from 220 to 1k ohm solve anything?

@sassoPera: Connecting several pull-downs to any tap will indeed affect the potentials along the ladder. Raising R can only make this worse. See the amended answer.


text:
ArduinoDue - Matlab: SerialUSB.write() sends ASCII?
I'm trying to get some binary data from an Arduino Due to Matlab.
Basically this is the setup:
Due:

byte usbMsg[33]= {0};
// filled with dummy as example
usbMsg[1] = '00000001';// in[3];
usbMsg[2] = '00000001';//in[4];
usbMsg[3] = '00000001';//in[5];
.
.
.
SerialUSB.write(usbMsg, 33);

And on the Matlab side, I open the corresponding COM port and use a command like this one:
 a = fread(serialPort,3)

this gives me:
 a =

    49
    49
    49

which is the ASCII representation of the data I sent.
Can anyone explain to me why this happens and what I could do? As I understood serial.write sends binary data and fread reads binary data.

You do you intend with the statement; usbMsg[1] = '00000001'? Check what this means in C/C++.

Damn i confused different languages. Thanks ....

source: Stack Exchange

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

sort: votes


text:
Question of proper usage for F Macro
Here are three use cases. Are all preferred or is the use of the F() macro pointless on some?
1.
Serial.println(F("some string"); // definitely useful here

2.
String str = F("some string");
Serial.println(str);

3.
int num = 5;
String str = F("some string with int ");
str += (String)num;
Serial.println(str);

Note that in case 3. you can just use two Serial.print commands like so: Serial.print(F("some string with int ")); Serial.println(num);

@Gerben are there any performance benefits to doing it this way?

You don't need to use a String object. And you don't need to have a variable for storing the entire string.

Any time String is involved F() becomes pointless. Avoid String like the plague if you value your memory integrity.

Does this apply to c++ in general? I just finished replacing String with char* through my Arduino program's code.

No. String is a custom Arduino class that does dynamic allocation. F() is also Arduino-specific. When you assign anything to a String it is copied into RAM (dynamically allocated in the heap), so it wastes RAM when you don't need to.

I have never used String in a program, and I never will use String in a program. It's all char * or const char *, the latter with PROGMEM when needed, though I don't often use platforms that need it.

@Majenko, Should I use F() everywhere or with Serial.print* only?

Use it whenever you have a string literal and a function that will take a FlashString. Anything that inherits Print is a good candidate.

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


text:
Arduino only addresses 3 LED at a time
I am running the following sketch on an Arduino Uno using Arduino 1.6.8.
Strip is a WS2811 12V.
#include <Adafruit_NeoPixel.h>
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show();
}

void loop (){
   strip.setPixelColor(0, 255, 0, 255);
   strip.show();
}

The problem is that the LED’s light in (Green) groups of three and what I want is individual control.
strip.setPixelColor(0, 255, 0, 255); Illuminates Pixels 0,1,2
strip.setPixelColor(1, 255, 0, 255); Illuminates Pixels 3,4,5
strip.setPixelColor(2, 255, 0, 255); Illuminates Pixels 6,7,8

And so forth.
Although this code uses NeoPixel I get exactly the same issue if I use the equivalent in FastLed.
Any pointers to what I am doing wrong would be appreciated.

LED strips with WS2811 and 12V are the ones with one driver and 3 RGB LEDs on it. These are interconnected so you just can't control less than whole group of three.
If you need individual control, you have to get 5V variant with WS2812.

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


text:
Reverse DC motor direction every second automatically
I have the Arduino Starter Kit and I'm on project 10 Zoetrope. I've removed the switch that changes the direction as I don't want the reverse to happen when I press a switch. I want the reverse to happen based on time.
For example using code, I want the reverse to happen every second (the motor moves clockwise for the first second, counterclockwise for the next second, clockwise for the third second etc.)
I've search for solutions but I haven't found anything yet. I had no luck with the millis function as well.

Consider code of the following form.
// Declare some globals
byte direction=0, second, prev=0;

void loop() {
  second = millis()/1000;
  if (prev != second) {
    prev = second;
    direction = second & 1; // Direction is 0 or 1
    OutputTheNewDirection(direction);
  }

More generally, suppose you want to make a pattern of clockwise for j time units, alternating with counterclockwise for k time units.  Suppose a time unit is m milliseconds long.  You can use code as in the following example, where m is 500, j is 10, and k is 1.
// Declare some globals and constants
byte direction=0, tunit, prev=0;
enum { m=500, j=10, k=1 };

void loop() {
  tunit = (millis()/m) % (j+k);
  if (prev != tunit) {
    prev = tunit;
    direction = tunit < j; // Direction is 0 or 1
    OutputTheNewDirection(direction);
  }

As my coding skills are not the best i think i can figure this out. What if i want to change the direction as the time passes by. For example i want the direction to be clockwise when i press the on/off switch then after 5 seconds change it to counterclockwise then after half a second change to clockwise etc.

@paul, see edited answer for 5 seconds CW alternating with half a second CCW


text:
Can I power my Arduino Uno with a 9V / 990mAh battery?
I have a 9V Lion 990mAh battery. I am not sure if I can use it to power an Arduino externally?
Can you please guide me how to understand current specifications of any device?
Thanks and Regards,
Manish

How much current does your Aduino consume? 9V batteries have very limited current capabilities.

While this answer addresses the specific question it should also prove useful as a link to resources relating to current reduction in other microcontroller projects.
Short:
The "C" rate for a cell is a current in mA numerically equal to the capacity in mAh
eg 1000 mA for a 1000 mAh cell.
In the absence of a specific data sheet a LiIon or LiPo cell is probably safe for maximum charge and discharge rates of C/2 and C.
ie 500 mA max charge rate for a 1000 mAh cell and
1000 mAh max discharge rate for a 1000 mAh cell.
In many cases double those rates will be safe.
Charge rates are seldom higher than C but discharge rates of substantially higher than 2C MAY be safe - see data sheet!.
In your example case, the operating time will be approximately mAh/average_current. Consult the data sheet for your microcontroller and/or measure current drain.
A typical "bare" Arduino with processor, USB IC, LEDs and "glue" components probably draws typically 50 mA and maybe up to 100 mA. Adding external loads can increase this - depending entirely on the load.
At say 100 mA average drain you'd get approximately 900/100= 9 hours operation. Running just the processor and on board components / peripherals you'd probabaly get twice times as long. By targeting low current methods (see refs ate end) you could get MUCH longer.

Most LiIon batteries are rated to charge at up to the "C" rate - ie 990 mA for a 990 mAh battery and to safely discharge at several times as much. Some manufacturers rate their batteries for lower maximum charge rates and this also can vary with the intended cell application. A "high energy" cell is liable to have lower charge and discharge rates than a "high power" cell. This relates to means of construction and to be safe the manufacturer's data sheet should be consulted.
The battery "capacity" rises somewhat as rates decrease below 'C' and fall significantly for rates above C.
Here is an excellent example data sheet for selected Sanyo LiIon cells . These are only examples but give a reasonable idea of what can be expected from a reasonable quality product.

Arduino per pin current limitations
Typical current draw](http://gadgetmakersblog.com/arduino-power-consumption/)
Excellent - Methods of reducing Arduino power consumption  & Related & more
Stack exchange discussion - How much current do you require in Arduino and embedded systems projects?

It says 7-12v on the site, so it should work https://www.arduino.cc/en/Main/ArduinoBoardUno
You can look at the datasheet for the Atmega328, but the current largely depends on what you connect to the Arduino. So it all depends what you do with it. It can certainly power and idle Arduino, driving motors and dozens of LED's maybe less so.

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


text:
I need to power some coils sequentially, can someone help me with the code?
int coilSetOne = 0;
int coilSetTwo = 1;
int coilSetThree = 2;
int coilSetFour = 3;
int switchInput = 4;

void setup()
{
  pinMode(coilSetOne, OUTPUT);
  pinMode(coilSetTwo, OUTPUT);
  pinMode(coilSetThree, OUTPUT);
  pinMode(coilSetFour, OUTPUT);
  pinMode(switchInput, INPUT);
}

void loop()
{
var switchMode = digitalRead(switchInput)
    if ( switchMode == HIGH ) {
        digitalWrite(coilSetOne, HIGH);
        delay(20);
        digitalWrite(coilSetOne, LOW);
        delay(10);
        digitalWrite(coilSetTwo, HIGH);
        delay(20);
        digitalWrite(coilSetTwo, LOW);
        delay(10);
        digitalWrite(coilSetThree, HIGH);
        delay(20);
        digitalWrite(coilSetThree, LOW);
        delay(10);
        digitalWrite(coilSetFour, HIGH);
        delay(20);
        digitalWrite(coilSetFour, LOW);
}}

If the arduino detects that the switch is powered, it should power the coils. They  should stay on for 20m and the delay between coils turning on should be 10ms.

Include your code in the post, not out on a link.  After you paste the code into your post, select it and click the code icon (or press ctrl-K) to get code-formatting.  In your post, tell us what is going wrong, not just that something is wrong.

Are you saying there should be a 10ms delay between switching each coil on, or a 10ms after the previous coil is switched off before the next is turned on?  You haven't said what the problem you are seeing is so I'm going to vote to close until you can explain the problem.

I ran your code, and the problem seems to be the "var" you declare, which is not an Arduino type. Use int instead. Also if you have PINs 0 and 1 as output, Using the Serial might prove difficult.
    int coilSetOne = 0;
    int coilSetTwo = 1;
    int coilSetThree = 2;
    int coilSetFour = 3;
    int switchInput = 4;

    void setup()
    {
     // Serial.begin(9600);
      pinMode(coilSetOne, OUTPUT);
      pinMode(coilSetTwo, OUTPUT);
      pinMode(coilSetThree, OUTPUT);
      pinMode(coilSetFour, OUTPUT);
      pinMode(switchInput, INPUT);
    }

    void loop()
    {
      int switchMode = digitalRead(switchInput); //Use int
     /* Serial.print(digitalRead(switchInput));
      Serial.print(" ");
      Serial.print(digitalRead(switchInput) == HIGH);
      Serial.print(" ");*/

      if ( switchMode == HIGH ) {
        Serial.print("#Triggered");

        digitalWrite(coilSetOne, HIGH);
        delay(20);
        digitalWrite(coilSetOne, LOW);
        delay(10);
        digitalWrite(coilSetTwo, HIGH);
        delay(20);
        digitalWrite(coilSetTwo, LOW);
        delay(10);
        digitalWrite(coilSetThree, HIGH);
        delay(20);
        digitalWrite(coilSetThree, LOW);
        delay(10);
        digitalWrite(coilSetFour, HIGH);
        delay(20);
        digitalWrite(coilSetFour, LOW);
      }
     // Serial.println();
    }

You didn't explain us the problem so I'm sorry if I missed the point.

So I should just switch PINS 1 and 0 to 5 and 6?

yes, if you need to use the serial port; Also the program now compiles, but I can't know if it does just what you need.


text:
Using arduino uno as a battery charger timer
My question is, can I use a Arduino as a battery charger timer, I have a 3.7 v 1200 mah lithium battery that I have been charging with a 4.2 450 ma charger for quite some time, I normally just use gator clamps to connect the leads to charge it, but today I was charging it and forgot about it and let it over charge. I don't want to ruin the life of the battery or possible have it blow up, so I got the idea of using my Arduino as a timer so it will shut off when it is done (or close to done).  My plan was to connect a transistor to it and have the Arduino running to the base pin to control when it will turn on or off and add a diode for both feedback and voltage droppage. I am aware that I will have to add a resistor/diode, so its not charging at around 6 volts.
But I want to know if I can run a program through my Arduino that will have it charge for say 2 hours?  If anyone knows if the uno is capable of doing this please let me know.
Also will I be able to connect a standard phone charger which I believe is 5 volts 2 amp to power my arduino?
Thank you for ur replies, if there is a program please link it
P.S. If anyone would like to know more information or would like to me fix any information please just comment and I will have it fixed shortly.

But I want to know if I can run a program threw my ardino that will have it charge for say: 2 hours.? Yes you can use the Uno to make a battery charger timer circuit. And also, will I be able to connect a standard phone charger witch I believe is 5 volts 2 amp to power my arduino? Yes, if its 5v regulated DC psu, and has the same barrel socket (uses 2 wires) and same has polarity. Next question?

Please get a proper charger! Lithium batteries are pretty specific about the way you charge them, or they can catch fire.

Yes I know they r sensitive when charging, but I believe this charger was preveiwlesly used to charge a lithium battery.

What are "ur replies" and how do I make them?

I mwnt comments

This might be a little off topic but it still a part of the same project, is there a way that I can have my ardino uno automatically shut off when the batteries r fully charged? I was thinking something like using a analog to read the input voltage from the battery and when the input voltage hots a sertain voltage it just end the program

Can you use an Uno to switch something on and off?  Yes.
Should you?  No.
In this case you are talking about controlling something that if it is not controlled could have serious safety implications.  Are you confident enough in you ability to code not to get this wrong?  What if the hardware fails, the Uno freezes?
Yes you could do it, but I think you would be better off buying a tried and tested COTS solution.

As others have already said, you could time the charge, but your idea has some major flaws;
First, since you can more easily read voltages than you can keep track of time, you should stop the charge once a certain voltage is reached, so you could also charge other batteries or half charged ones.
MORE IMPORTANTLY,
Lipos always need fairly complex charging circuits (compared to other rechargeable types). This is an area you should read up on extensively before tinkering, since LoPo's respond explosively to mistakes.
A good starting tutorial;
 http://learn.adafruit.com/li-ion-and-lipoly-batteries/overview
I would suggest using a commercial charger, so that you are sure to be protected from over charge, over voltages, shorts, and fires, and will stop charging when the battery is charged. This one should also have a connector so you can connect it to your phone charger, and costs 0.90$.
http://www.electrodragon.com/product/tp4056-lithium-battery-charging-board-1a/
Please note this is a reference, you should find more economic offerts.


text:
Difference between DS1307 and IN1307N, I am using RTClib for making rtc module using IN1307N getting RTC is not running
#include <Wire.h>
#include "RTClib.h"

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {

#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif

Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}

if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}

void loop () {
DateTime now = rtc.now();

Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();

Serial.print(" since midnight 1/1/1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");

// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now + TimeSpan(7,12,30,6));

Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();

Serial.println();
delay(3000);
}

If i use 57600 i'll get random symbols in one line 1 line.
I have connected PIN5 IN1307N to A4, PIN4 IN1307N to A5

What about pull-ups on SDA/SCL?

yup applied. 10k to vcc

Maybe try to use 4k7 (or two 10k in parallel) and shorter wires but it's a wild guess. And you can try I2C scanner if RTC is even found. BTW value 165 is not so random as you think. It's 0xF*10 + 0xF e.g. 0xFF to BCD code.

Scanning...
No I2C devices found

Check your wiring: A4 = SDA -> PIN5,  A5 = SCL -> PIN6 (PIN4 is GND terminal)

yup thats connected..

Following this circuitry solved my issue but still i've not understand the difference between DS1307 and IN1307N.

There shouldn't be any difference. Just different factory making the chip.


text:
Way to use other baud rates in console or different input/output rates
I want to send some test codes to a MIDI synthesizer, so I wrote a program that lets me just type in hex codes on the serial monitor and send it over serial as the byte value. For example typing "90 45 63" should turn on note 0x45 with a velocity of 0x63.  This part works ok and I have the arduino hooked up to a midi connector and from there to a midi synth. I've verified that this works ok with some test code.
Where I'm having trouble is that MIDI requires a rather unorthodox baud rate of 31250.  The problem is then that on an Arduino Uno, I don't see how I can enter serial data when the Arduino's serial monitor doesn't allow that baud rate. Also trying to set that baud rate under Linux using stty generates an "stty: invalid argument ‘31250’" error.  So is there a way to use a different baud rate for input than for output or some other solution here?  I do have a Teensy 3.1 with multiple Serial ports, but its kinda tied up at the moment and I just thought I could use an Uno for this.
UPDATE: It works now. Something to keep in mind when working with complex external components like a professional synthesizer. The Roland JV-880 that I'm interfacing with wasn't receiving program changes even though I was sending the 0xC0 0x03 codes or whatever. This is why I made this debugging program to begin with. After searching around and being stumped, I looked around the system settings on the synthesizer and discovered a setting called "System MIDI Rx switch Program change=OFF". After I changed that to ON the program change codes worked. Sometimes the problem is nothing in your code or circuit.

Have you considered using a MIDI port?

@IgnacioVazquez-Abrams Sorry I should have mentioned. I have the arduino hooked up to a female midi connector and from that up to the midi port on a synthesizer. That aspect is working fine and I've been able to play notes using a simple test program.

So... do you then have two serial connections, one to the host and one MIDI?

No, I was just using the TX (pin 1) on the arduino to send data over the midi port and then the usb connection to the computer.  Maybe the serial port can't be shared like this?

The Arduino Uno is powered by an ATmega328P microcontroller. This
microcontroller has only one UART which is not capable of using
different baud rates for sending and receiving.
You could look into the different software serial port implementations
for the sending side. Another solution would be to continually change
the baud rate: each time you get a complete message from the serial
monitor,

you switch the baud rate to 31250 bps
you send the packet to the midi synth
you Serial.flush() to make sure the bytes have actually been sent
you switch back the baud rate to whatever you used in the serial
monitor

You will probably see some garbage on serial monitor as it receives the
bytes at the wrong rate, but that should not be an issue.

Software serial! That's brilliant and was easier than I expected.  So far it works fine, although its a bit slow to send the codes. Not sure why. But it works for my purposes. Thanks.

Well, I was actually thinking about the alternatives to SoftwareSerial, like AltSoftSerial (there are others). The standard SoftwareSerial is not very good, as it tends to block interrupts for too long. But if it works fine for you, then it's all that matters.

I tried AltSoftSerial and it is about the same, but if I use stty to setup the serial and just write to it with echo "904540" > /dev/ttyACM0 its much faster. Instantaneous even. If I use the Arduino IDE serial console the messages take about half a second to arrive on the synth.


text:
Weird Arduino LED behaviour
I noticed something when I was trying something with leds;
  pinMode(13,HIGH); // giving +5V to pin 13.
  delay(1000);      // waiting for 1 sec.
  pinMode(13,HIGH); // giving +5V to pin 13 again.
  delay(1000);      // waiting for 1 sec again.

  //loops forever.

But I couldn't light the led. What is the reason behind this? Shouldn't it be lit forever?

Is that the whole program?

@Ignacio Vazquez-Abrams no,the pin is initilized before setup func. and this is in the loop func.

Maybe you should post the whole program then?

pinMode is not the function to use to set a level on a pin, it's used to setup the pin as input, input with pullup, or output. Use digitalWrite in your loop.

As already in the comments, you are using pinMode(...) where you should be using digitalWrite(...)
The code should look like
void setup() {
  pinMode(13, OUTPUT); // sets the pin to an OUTPUT, it can now source or sink current
}

void loop() {
  digitalWrite(13, HIGH); // sets the pin to +5V
  delay(1000); // waits 1 sec
  digitalWrite(13, HIGH);
  delay(1000);
}

When you use pinMode(13, LOW) you are actually writing pinMode(13, INPUT) as LOW and INPUT are two aliases for the same value (0, by the way).
When in INPUT mode the PIN doesn't source or sink any considerable current, so I can't say much more about why the LED is turning on unless you provide a schematics of your circuit (but I have idea you are doing something really wrong).
It might be useful to have a look at this simulation:

on the left the LED is connected directly to voltage source without control from Arduino
in the middle, the LED is controlled by Arduino on the high side: click on the letter to toggle the pin state
on the right the LED is controlled on the low side


text:
How do I repeat a piece of code
For a school assignment I need to make a LED blink on/of 3 times then stop.
Now I have come up with the following code:

I think it's ''clean'' enough for what it has to do, but I have a feeling that here must be a easier way to make the LED blink 3 times.
Question is: Is there a way to reapeat the part of code 3 times without copy&pasting it?

Other than with a loop?

Google "for loop C++".

@IgnacioVazquez-Abrams The thing is that it has to stop after 'blinking' 3 times. And there is no way to stop the loop, correct me if i'm wrong.

And? There are loops that can do that. Or have you not looked at any C++ tutorials yet?

@IgnacioVazquez-Abrams Only thing I found so far is a Exit(0); which makes the program stop. But then I still have to copy paste the code 3x becuase the loop otherwise stops after 1 on 1 off loop.

Thank you for his code.. just some follow-up.
If i want to stop the flashing when button press, what code need to add.
ex: LED flashing for 30s then when i press the button it will stop. thanks

Here you can use a loop. a classic for loop in C++ looks like this
for (int i = 0; i < n; i++)
{
    // content in between these brackets
}

where n is the amount of times you want to loop
you can also instantiate the i before the loop.
int i;
for (i = 0; i < n; i++)
{
    //content here
}

The code below should work. Toy around with it and see what you get.
int ledPin = 13;
int delayPeriod = 500;

void setup(){
    pinMode(ledPin, OUTPUT);

    for (int i = 0; i < 3; i++){
        digitalWrite(ledPin, HIGH);
        delay(delayPeriod);
        digitalWrite(ledPin, LOW);
        delay(delayPeriod);
    }

another approach you can do is using a while loop. These kinds of loops will loop until a given parameter has been met. In your case you want an LED to stop blinking after 3 times.
int start = 0;
int stop = 3;

while (start <= stop){
    //content here
}

While loops will continue to go as long as the parameter is true. This means something like while(1) will continue to run forever.

Thanks! I tried the Int i; function and it works perfectly!

@tisaconundrum have you missed an increment or decrement in your while loop?

How can I change to code to work with if and else statements, so it wil work in the loop.

Another way is to declare a function. This method will give you more chance of using it in various ways.
    int LED_PIN = 13;

    void flashing(size_t times=1) { // By default it will flash once, you can chance this into your desire
        int delayPeriod = 500;
        for (size_t loop = 0; loop < (times*2); ++loop) {
          digitalWrite(LED_PIN, (loop % 2)?HIGH:LOW);// Use Modulus
          delay(delayPeriod);
        } // Thanks to [Matt][1] and [Edgar Bonet][2] for their comments
    }

    void setup() {
        pinMode(ledPin, OUTPUT);
        flashing(3);
    }

    void loop() {
        // Do something here
    }

I also came up with the idea of using a function, but you have to consider the overhead of calling it,  In this case I don't think its worth the cost.  Normal coding standards frown upon placing two statements on a single line.  Off the top of my head I couldn't say if a while or for was more efficient, but personally for a fixed number of iterations I would go for a for loop, if I had to do a while loop then I would set I to zero so I could do (i<times) which would be quicker than what you have.  All that said, its still a good answer.

A for loop is definitely better in terms of legibility.

You could also look at optimising the 4 lines of code inside you loop:
const int ledPin = 13;
const int delayPeriod = 500;
const size_t count = 3;

void setup()
{
    pinMode(ledPin, OUTPUT);
    for (size_t loop = 0; loop < (count*2); ++loop) // size_t because variable is never negative.
    {  // Two time count, because you only have half the code
        digitalWrite(ledPin, (loop % 2)?HIGH:LOW);// Use Modulus
        delay(delayPeriod);
    }
}

Sorry for the late respons! Thanks you for helping out, I will try this methode later tonight! I already made my code work with the previouse answer. This methode may be easier to read for others. Def going to take a look at it. Thanks again, Really appreciate the time and effort you took for responding!


text:
Arduino SPI Communication with H3LIS100DL accelerometer
I'm having trouble getting information off the accelerometer I'm trying to use. What code should I use to read the X,Y, and Z axis?  I've read the data sheet but I don't have any experience with SPI communication.
Spec sheet

The basic SPI operations looks like this. First read single register:
uint8_t readRegister(int index)
{
  digitalWrite(CS, LOW);
  SPI.beginTransaction(SPI_SETTING);
  SPI.transfer(READ | index);
  uint8_t res = SPI.transfer(0);
  SPI.endTransaction();
  digitalWrite(CS, HIGH);
  return (res);
}

And second write single register:
void writeRegister(int index, uint8_t data)
{
  digitalWrite(CS, LOW);
  SPI.beginTransaction(SPI_SETTING);
  SPI.transfer(WRITE | index);
  SPI.transfer(data);
  SPI.endTransaction();
  digitalWrite(CS, HIGH);
}

Some more details:
const uint8_t WRITE = 0x00;
const uint8_t READ = 0x80;

It is also possible to read/write a sequence of registers by providing the register index with the MS set. This will auto-increment the register index.
SPI_SETTING is left as an exercise (to be updated).
Cheers!


text:
Arduino programming through HC06
My goal is not upload sketch to Arduino Pro mini through bluetooth module HC06. I have made a breadboard version of DTR signal simulator which takes LED status pin as a source. The output from the detector goes to RST pin of Arduino. When connection is initiated the status LED stops blinking and output pin goes low and than high which leads to Arduino rebooting. This part works fine. Unfortunately avrdude from Arduino IDE does not see the bootloader and shows the following error in the console:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
I have noticed that HC06 stops blinking with some delay after a connection is initiated. I suspect that this might be a problem. To overcome this issue the boot loader should probably be changed. Unfortunately I am not familiar with the embedded C programming, thus if someone has experience in changing the bootloadder, please help me to solve this puzzle.
The following is a scheme of detector:

Did you set the same USART speed on HC06 as bootloader uses? (You have to use this speed in your program too)

BTW with HC05 it's much easier as there are two LED indicators and LED2 indicate successfull connection. So if you use AT+POLAR=1,0 to set active low mode for LED2, you can connect it as DTR input.

@KIIV, Thanks. I have set the BAUD rate through the TTL for HC60 and now the uploading works as expected. By the way for Arduino Pro Mini 5V 16mGhz the baud rate is 56700. At this speed the bootloader works, you can check it in the boards.txt file. With HC05 is simpler but also requires soldering, thus the difference is not big.

I do not know how to vote it or how to mark it as answered.

I'll make it as answer

http://makezine.com/projects/diy-arduino-bluetooth-programming-shield/

You should read the link above, it shows how easy it can be do to with the HC-06. Also, as noted by KIIV, the HC-05 is also very easy.

Setting serial speed on your computer side doesn't change speed on the HC-06 side. So you have to set the same speed for HC-06 interface (and in your sketches) as a bootloader is using.

authors: Артём Ильдяев


text:
Arduino relay. risks?
I just started working with arduinos recently. I'm really interested in working with relays. I would like to turn a desk lamp on and off using an ios app or a web browser button. I have no experience working with relays but I would love to experiment with relays in order to turn a desk lamp on or off based on an external switch in like an IOS app or a browser.
I am wondering what are the risks in relays with arduino ? I would like to switch a desk lamp on or off using a relay but I don't really understand the risks with creating a desk lamp powered using a wall socket and turned on or off using a arduino relay module . What is the worst case scenario if I screw up ? What are the risks and precautions I should take while working with relays and trying to build a relay controlled desk lamp?
I live in an apartment and I am trying to make sure that my entire building does not lose electricity or I don't screw up the electricity in my unit. What are protective measures that I can take to minimize damages while working on this project?

What is the worst case scenario if I screw up ? -- You are dead. Your apartment block has burned down. Your family are all dead. The neighbours are all dead.  MAINS ELECTRICITY IS DEADLY - YOU NEED TO KNOW WHAT YOU ARE DOING WITH IT

What are protective measures that I can take to minimize damages while working on this project? - Get some qualifications in working with mains electricity.

I'm sorry but your response is not helpful at all. I've been going over tutorials and it does not seem that difficult. I kind of wanted some tips and advice on common errors people make and maybe some good precautionary measures from people who have been working with relays for a long time. Please be more specific as to what constitutes as "qualifications with working in mains electricity". I am currently in upper year  for an undergrad program for electrical engineering and I am sure I will be able to follow through or search the web a little more to understand your tips or advice

I am currently in upper year for an undergrad program for electrical engineering - You're way more advanced than 99% of the people that visit here then. Most would succumb to "Darwinism In Action", hence the big warnings I post whenever mains is involved.

@vp1234 you could achieve almost the same results by working with safer power levels, as first attempt. For example by using LEDs.
And you could check if your installation has a residual current circuit breaker. It's not sufficient to mitigate any risk, but it does provide some protection. https://en.wikipedia.org/wiki/Residual-current_device
Depending on its presence or not,you could choose your course of actions.

I prefer to use wireless remote control outlet switches, and connect a 433mHz transmitter to the Arduino. That way I can switch AC appliances on and off, without ever having to touch any of the mains electricity stuff.

Thank you very much for your help everyone :) Really appreciate it

Get a 24VDC desklight :)

Basic safety precautions:

Always fully unplug the lamp before working on any wiring, even when working with the low-voltage side of things.
Invest in a proper enclosure and follow the rules of insulation and earthing: if the enclosure is metal or has exposed metal they have to be earthed. If it is plastic it is insulated and there is nothing to earth (plastic is best).
Use nylon bolts etc when situated near mains voltages.
A proper relay module with good screw terminals is recommended.
Do not tin your mains wires when screwing them into a terminal block
Do your mains wiring with your left hand in your pocket (an old electrician's trick: if you should get a shock the path to earth is down the side of your body and through your foot. If you have your left hand touching something the path to earth could well be straight across your chest, through your heart, and down your other arm, killing you. It has saved my life a few times...)
Keep mains voltages and low-voltage areas separate. Cable ties and self-adhesive nylon cable tie pads are great for keeping cables where they should be.
Shield any exposed mains connections from touch. Things like the underside of the relay module where the terminal blocks are soldered, that sort of thing.
Don't let the relay module wave around loosely. Keep it well secured in the enclosure.

I'm sure I could find more tips if I tried :)
The main thing to remember is that mains electricity is deadly and should be treated with the utmost respect.
For the ultimate in safety though you could get an isolating transformer. This separates your work from the main supply and means that the only way of getting a shock is by actively touching both outputs of the transformer at once - something you're not really likely to do - and even then it's usually a very localised path for the electricity (through a finger or two).
Adding an ELCB to the lamp's plug (if it is earthed) can be a good precaution while you are working too - and making sure the socket is connected to a ring main that is protected by an RCD is pretty much essential (in the UK it is the law that all ring mains are protected by an RCD - I would hope the same is the case where you live).

Thank you very much for your help :) Really appreciate it

Read through the Sparkfun Beefcake Relay Hookup Guide.  It points out many things to keep in mind.
The kit is quite good, I just finished putting one together to control a humidifier off an Arduino with a DHT-11 to keep ambient humidity within a range.
As people have posted, don't ever do any work while the mains are plugged in!
In your project, you'll be able to test the relay without the mains being plugged in, the relay will make a nice "clicking" sound and if you use the "Beefcake" kit, an LED will light up when the relay is "on".
Be sure to have everything in a "housing" and not flopping around. They sell blue plastic junction boxes for about $1 which is what I used.  A GFI or GFCI socket is safer to use, though more expensive.
Good luck!

Thank you very much for your help :) Really appreciate it

this is andrew.
I saw your Question.
Relay's are not even risky Electronic device , it can be controlled by 5v or 12 v.
On behalf, you can just run your simple led blink program to Start up your relay.
Just use the Default (13th) pin for relay input. Run your Code. If your code runs successfully, the relay activates, led in the relay will light up and as well as Your default Led also light up in your arduino Board. After that you can give the output 220v power to control electronic Devices.
if any doubt just ping me.

Working with mains is not risky? Really?

Really, its not Risky. But Be Carefull On Dealing with Current.

But, screw it up well the power (110v-220v) to the relay On Common and Normally Open or Normally Closed Pin.

Be, Sure there is no short Circuit.


text:
Using two references in the same ADMUX
I'm making a project and I neee to use 2 different references on the same ADMUX. One reference is 0-5V and the other is 0-2.5V. I'm aware that I can use the reference of the Arduino to the 5V sensor. But how I put a 2.5V reference while using the 5V at the same time?

You can try to read 2.5V sensor twice, sum it and divide by two. Or you can double the input voltage by using non-inverting OP AMP with amplification factor 2. Or if you don't mind half resolution, you can use 5V reference voltage and just read it.

Do you really need 10-bit precision on both voltages?

First of all a reference is just a voltage, not a range.
If you use a reference of say 5V than your analogRead(...) calls will return a 10 bit number where 0 stands for 0V and 1023 stands for 5V.
Second, the AREF pin is there for that purpose: feed your 2.5V reference to that pin and use:
analogReference(EXTERNAL);
analogRead(...);

when you want to read using the 2.5V reference (0 stands for 0V and 1023 stands for 2.5V in this case), or
analogReference(DEFAULT);
analogRead(...);

when you want to read using the 5V reference (supposing your Arduino is powered by 5V).
UPDATE
Nothing can be done at the exact same time on an Arduino/ATmega328 because it has one single processing unit. In case of analog to digital conversion you can not even perform two conversions on two pins too fast because you have only one ADC which is multiplexed (shared) among all the analog pins.
You have no choice to perform one reading, wait, then perform the other reading. You can change the voltage reference between the two conversions though, but you need to ensure the internal ADC capacitor is properly discharged: if you read a 5V line and then read a 2.5V line without discharging the internal ADC you are more than probably going to always read the maximum value.
How long you will have to wait depends on the impedance of the line you are sampling: higher the impedance, longer the time you have to wait for the ADMUX capacitor to discharge/charge up (Arduino/ATmega328 ADC is a store and sample comparator).

But how? In the ADMUX, one pin needs to be configured to 5V and other is configured to 2.5, and I need to do the conversion at the same time. And also I need the code in AVR.

Are you using the ATmega328 internal ADMUX or an external component? In case it's an exaternal component, which is the EXACT part number?

If you have a 2.5 V reference connected to the AREF pin, then calling analogReference(DEFAULT) will short that to +5V, possibly destroying your voltage reference or the Arduino. C.f. the warning in the documentation of analogReference().


text:
Problems burning bootloader on custom ATMEGA2560 board for High-powered model rocketry
I've designed a custom board meant for high-powered model rocket telemetry & duel-deployment.  (More info upon request)
To do this, I've soldered a ATMEGA2560 (yes, overkill, but I needed multiple hardware serials), with the plan on using the ICSP programming header I designed on the board to burn the Arduino bootloader, and then use the super-easy ftdi-compatible serial connector to program the board....
Problem is, I have thus far been completely unable to burn the bootloader.  I've double-checked the wiring ten times, checked the labeling on my board, checked my board's schematic twice, and re-checked the chip's datasheet to make sure I didn't screw up the pinout, even held a jumper past my fancy reset circuitry that I largely copied from the official Uno schematic.
I've largely been using Nick Gammon's excellent "bootloader programmer" sketch Link on a Clone Arduino Mega.  But I've tested the connections and sketch by using it to program the bootloader on a Arduino Pro Mini successfully with no hitch at all.  :(
Attempting to enter ICSP programming mode..........................................
Failed to enter programming mode. Double-check wiring!
Here's a Board and (Schematic I can't post because I'[m new to the Arduino side of stack overflow...  so replace the URL with schematic.png) of my board, and I'll upload a picture of my soldered board soon, but I'm actually quite confident of my soldering job...
Really just completely out of ideas, and very demoralized because the project I've been working on for months isn't working, and I have nothing specific to even point at...

I have thus far been completely unable to burn the bootloader.

In what sense? What (error) messages did you get?
In your shoes I would be seeing if I can "talk" to the chip. My chip detector sketch will help you to see if the chip is "alive" or not. See my post about Have I bricked my Arduino Uno? Problems with uploading to board
You may possibly have inappropriate fuse settings for your clock source. If you get some sort of response from the chip using the chip detector sketch please post what it is.

Also to note is that this is a completely virgin chip from the manufacturer, so I'm not sure what the clock settings come as in that case

According to the datasheet, 8 MHz internal oscillator with CKDIV8 fuse set. That should work.
However you need to resolve that before going any further. I would be taking voltage readings at various points.

Make sure you have Vcc at all the appropriate places, and Gnd.
Note that there are multiple Gnd and Vcc pins. You should also have 5V at AVcc.
Check that /RESET is normally high (5V) and check that it drops to 0V during the programming attempt (and stays there).
Check you have decoupling capacitors between Vcc and Gnd where necessary.
Assuming you have the TQFP-pinout chip, make sure that you have your SPI connections at pins 19, 20, 21 and 22.
If you have a scope or logic analyser make sure that there is some "action" on SCK, MOSI pins during attempts to program it. There should also be a response on MISO.
There should not be a capacitor in series with /RESET as I have occasionally seen people do. The programmer has to hold /RESET low during the entire programming sequence.

Sadly, both the chip detector sketch & the board programmer sketch give up at the same point-
Attempting to enter ICSP programming mode ...................................................... Failed to enter programming mode. Double-check wiring!  So I'm assuming there's no response at all, which is a bit worrisome.  Also to note is that this is a completely virgin chip from the manufacturer, so I'm not sure what the clock settings come as in that case...

See amended answer.

Also make sure your circuit ground is connected to the PC/programmer ground; I went through almost all the troubleshooting listed in this answer when an ATMEGA 328p of mine suddenly couldn't be programmed, only to find i missed the connection between my PC ground and the circuit ground!

@Nick Gammon Thanks, this is helpful!  I think I'm good on all of these points except for 2:  Yes, it's TQFP, but do you need pin 19?  (/SS) I foolishly left it floating, which I suppose could cause some issues?  Also, I made the /Reset capacitor mistake.  (Different kind of reset, apparently)  but I've since connected a wire to the /RESET side of the capacitor, to pin 10 on the programming mega, with no difference.

@esoterik Yeah, the ground from the SPI is connected to the ground for everything else as well, and each of the 5 gnd's on the chip as well.  I only have one ground net.  :P   Good idea, though.

It probably won't hurt that /SS is floating, however that would have been a handy pin to have available. As for the ongoing problem, now is the time to hook up a scope and see if signals are getting where you think they are.


text:
Seamlessly loop through LED's - Shift Register
I am using the following code to create a snake-like affect (3 LED's wide) moving through 24 LED's using 3 shift registers:
 for(int i = 0; i < 27; i++){
    setRegisterPin(i, HIGH);
    writeRegisters();
    if(i >= 3){
     setRegisterPin(i-LEDLength, LOW);
     writeRegisters();
    }
    delay(100);
  }//end for

The problem with this is that the snake has to completely end before it starts again, instead of looking like one continuous snake going in circles.
So when the three LED's get to the end I want it to immediately begin to light the beginning again. If 2 are lit at the end then 1 should be lit at the start, etc. Like this pattern:

You mean something like this? (untested):
void loop() {
  // use static or global variables to remember positions (these are initialized only once):
  static uint8_t hi_pos = 0;  // where HIGH should be set
  static uint8_t lo_pos = 21; // where LOW should be set

  setRegisterPin(hi_pos, HIGH); // turn on led in head
  setRegisterPin(lo_pos, LOW);  // turn off led in tail
  writeRegisters();             // update registers

  // ensure it won't overflow:
  if (++hi_pos == 24) hi_pos = 0;
  if (++lo_pos == 24) lo_pos = 0;

  // or:  hi_pos = (hi_pos+1) % 24;  // but divisions are slower on AVR

  delay(100);
}

It will go in sequence:
ON  OFF
 0   21
 1   22
 2   23
 3    0
 4    1
...
22   19
23   20
0    21
...

forever

wow, I'm not sure how you did that but it works. Can you explain the code further please?


text:
Can I create a serial.read command with the arduino code alone?
I am trying to manipulate a project and the simplest way to do what I am trying to do would be to use the existing code.  This code is designed to take an input from the serial monitor using serial.read() and manipulate it.  For example if I type hello into the serial monitor's command bar, the code would read it and manipulate it.  I was wondering if there is any way to create a serial command to run in the code which would act in a way as to bypass the serial monitor since this project is not going to be connected to a computer when it is in use.  The command will be the same every time and will be in response to a single switch input.
#include <avr/pgmspace.h>
#include <MorseEnDecoder.h>
#include <stdio.h>

// Pin mapping
const byte morseInPin = 7;
const byte morseOutPin = 13;
String check = "";
String origin = "S";
const int maxItems = 3;
char myStr[] = "Help is Coming";
int x;
char myArray[maxItems], curChar;
char nextChar;
int i;
int y;

// Instantiate Morse objects
morseDecoder morseInput(morseInPin, MORSE_KEYER, MORSE_ACTIVE_LOW);
morseEncoder morseOutput(morseOutPin);

// Variables dealing with formatting the output somewhat
// by inserting CR's (carriage returns)
long lastTransmissionTime;
long currentTime;
boolean transmissionEnded = true; // Flag to mark old trans finished

// Minimum transmission pause time to insert carriage returns (CR)
// Adjust depending on Morse spd. IE 13 wpm = 646 ms btw words (no CR).
const long transmissionPaused   = 1000; // Suitable for 13 wpm?

void setup()
{
Serial.begin(9600);
Serial.println("Morse EnDecoder Geocache");

// Setting Morse speed in wpm - words per minute
// If not set, 13 wpm is default anyway
morseInput.setspeed(5);
morseOutput.setspeed(5);

lastTransmissionTime = (long)millis();

}

void loop()
{
currentTime = (long)millis();

// Need to call these once per loop
morseInput.decode();
morseOutput.encode();

// SEND MORSE (OUTPUT)
// Encode and send text received from the serial port (serial monitor)
if (Serial.available() && morseOutput.available())
{
// Get character from serial and send as Morse code
char sendMorse = Serial.read();
morseOutput.write(sendMorse);

// Not strictly needed, but used to get morseSignalString before it is      destroyed
// (E.g. for morse training purposes)
morseOutput.encode();

// Also write sent character + Morse code to serial port/monitor
Serial.write(' ');
Serial.write(sendMorse);
// Morse code in morseSignalString is now backwards
for (int y=morseOutput.morseSignals; y>0; y--)
{
  Serial.write(morseOutput.morseSignalString[y-1]);
}
}

// RECEIVE MORSE (INPUT)
// If a character is decoded from the input, write it to serial port
if (morseInput.available())
{

char receivedMorse = morseInput.read();
//Serial.print(receivedMorse);
// A little error checking
if (receivedMorse == '#') Serial.println("< ERROR:too many morse   signals! >");
morseOutput.write('#');
morseOutput.encode();

//Create Array out of receivedMorse Chars

    curChar = 0;
    nextChar = receivedMorse;
    curChar +=nextChar;
    myArray[i] = curChar;
    check.concat(myArray[i]);
    Serial.println(check);

  //Check input and respond
  if (check == origin)
  {
Serial.println("check = origin");

// Encode and send text set in myStr[x]

for (x = 0; x < sizeof(myStr) - 1; x++)
{
char sendMorse = myStr[x];
morseOutput.write(sendMorse);

// Not strictly needed, but used to get morseSignalString before it is destroyed
// (E.g. for morse training purposes)
morseOutput.encode();

// Also write sent character + Morse code to serial port/monitor
Serial.write(' ');
Serial.write(sendMorse);
// Morse code in morseSignalString is now backwards
for (int y=morseOutput.morseSignals; y>0; y--)
{
Serial.write(morseOutput.morseSignalString[y-1]);
}
}

  }

 if (receivedMorse == '#') Serial.println("< ERROR:too many morse signals! >");
 }
 // two strings not equal:
 if (check != origin) {

 }
 }

This is a morse code encoder and decoder.  I have adapted it to do a certain thing when a certain string of morse code is entered.  I am trying to get it to then encode and respond with a morse string, but the only way it is programmed to do such a thing is through the serial.read() command  There is a library that I am not sure how to attach, it can be found here
https://www.dropbox.com/s/eg21qmg0151gxz6/Morse_EnDecoder_2012.11.25.tar-2.gz?dl=0 this also includes all of the original codes.  My additions can be found directly under the comment //Create Array out of receivedMorse Chars and continuing to the bottom (The last 45 lines or so not including char, string, and int declarations).  I apologize if some of the edits I have made are hideous or "not in the spirit of the language".  I am a novice and a hobbyist.
The Code I have adapted will print my string exactly as it appears (myStr[]), however it will not encode it to Morse nor will it output it through the LED or the buzzer.  The 'serial.read()' command appears to work outside of my if statement, but really I have no idea how I would fix this.

Is the “switch input” (mentioned in last sentence) on your host computer or on an arduino?

The switch is an independent input into the arduino.  It is not on the computer, it will be built into the project assembly which includes the housing for the arduino board.

Perhaps you can edit your question. (1) Include the “existing code” in the question, using code-formatting to format it; (2) Say what the new program is supposed to do, rather than talking about “bypass the serial monitor”, which seems like a wrong approach; (3) indicate how many positions the switch will have or how many switches there are

I have added my code.  This code encodes and decodes Morse signals.  It will decode a morse input from a switch and output the text to the serial monitor.  It will also accept text from the serial monitor and output Morse code with and LED and Buzzer.  I have adapted the code to compare the input from the switch with a predetermined string and when they match to do XYZ.  In this case I want to output morse code through the LED and Buzzer, but I cannot figure out an alternative to the serial.read() command.  There is one switch, it is SPST switch in other words, it has on and off only.

The serial input is read into a variable.
You could comment out the serial read and assign whatever value you need directly to the variable.  By commenting out the serial read, you will have a marker of where you made the changes.
This should work since you are saying the inputs are known and do not change.

I'm afraid I forgot to mention that the response is several characters long, for example test could be a response or correct.  I am able to get the code to output a single character, but not the entire string.  I attempted to bypass this with a for loop which would increment a variable assigning it all values in the string, however it seems this did not work.  Could this be because the for loop runs entirely on a single loop of the main code?  Or does it only loop once per code cycle as well?

More importantly, this section is inside an if statement which is only triggered based on the switch input.  I believe this is why the code doesn't work.


text:
Serial ports(in 1.0.5 & Port in 1.6.11) is greyed out under tools
I am running a linux distro on my pc(Ubuntu 16.04). I have installed Arduino IDE(version 1.0.5 since it's the only one available on the store) from the Ubuntu Software Center and also using the .ZIP file from the official Arduino website(version 1.6.11). When I ran IDE(1.0.5) the "Serial Port" drop-down was greyed out. Next ran the IDE(1.6.11) and again the "Port" drop-down under Tools was greyed out. I have spent hours looking online for a solution but all in vain. A tried and tested working solution will be highly appreciated.

Are you in dialout group?

Well, every time I launch the IDE it shows me the following message:
`You need to be added to the "dialout" group to upload code to an Arduino microcontroller over the USB or serial ports.
Click "Add" below to be added.
You must log out and log in again before any group changes take effect.`
And then as instructed I clicked on the add button. Even then the Serial port remained greyed out. And besides, shouldn't the adding be a one time thing? Why do I have to do it every time I launch the IDE?

Maybe you don't have enough access rights to change it. Otherwise it should be one time action. Try to add this group for your account from root account (or with sudo).

Or launch the IDE from the root account and let it sort it out for you.

Information on a “Serial Port Setup” page at fedorahosted.org should be adequate to sort the problem manually.  Here are a few snippets from that page, along with notes about application to the current problem.
• Use command ls -l /dev/ttyUSB* to find out the serial port's group.  For example, on my Ubuntu system that shows
crw-rw---- 1 root dialout 188, 0 Aug 20 11:13 /dev/ttyUSB0

Note, substitute for ttyUSB if the port you're concerned about doesn't start with that.
• Use command groups to find out which groups you belong to.
• The fedorahosted page says to use command sudo adduser (username) dialout to add dialout to your groups list.  I haven't tried that approach, and would be more inclined to instead try sudo usermod -a -G dialout (username) [where  “(username)” represents your username].

One must then log out and log back in for the group membership change to take effect.


text:
where to get Arduino WIFO101 library that supports WiFi.beginAP() on board MKR1000
The sketch example from page "Wifi.beginAP()" causes compiler error because the return values are not defined for -WL_AP_LISTENING or -WL_CONNECT_FAILED.
Board: Arduino MKR1000 WiFi
Compiler:  Arduino IDE
Library: Github WiFi101 v0.9.1
Missing:  definition of "WL_AP_LISTENING" and "WL_CONNECT_FAILED"
ERROR....
beginAP.ino: In function 'void setup()':
beginAP:55: error: 'WL_AP_LISTENING' was not declared in this scope
if (status != WL_AP_LISTENING) {

              ^

Arduino WiFi101-MKS1000 examples\beginAP\beginAP.ino: In function 'void loop()':
beginAP:78: error: 'WL_AP_CONNECTED' was not declared in this scope
  if (status == WL_AP_CONNECTED) {

                ^

exit status 1
'WL_AP_LISTENING' was not declared in this scope

It is AP_SimpleWebServer.ino at Github Wifi101 release 0.9.1 examples.
It builds ok by using the old definitions for .beginAP return values.
Problem is Arduino .beginAP page has example that relies on the LATEST Github WiFi101 ("0.9.1++" not released yet).
Also example AP_SimpleWebServer is missing from Arduino Wifi101 page.


text:
Arduino code won't upload with Ethernet Shield attached
I've been playing with my Arduino Boards for a while. I have an Arduino Nano and a Duemilanove 328.
I've been able to program both of them without problems for weeks. Any example project I try will compile and upload with no issue.
I recently got an Ethernet shield... I'm trying some test sketches and no matter which board I try, with the shield attached I get:
avrdude: stk500_getsync(): not in sync: resp=0x00

As I said, without the Ethernet shield attached all is bliss....
Do I have a bad shield or am I just doing something stupid?

I don't know how it works but Go to the Device manager and Assign a different COM port to your Arduino over there! It worked for me :D

The Ethernet Shield uses the pins  D10, D11, D12 and D13 on the Arduino UNO. I presume there is a conflict and you use one or more of these digital pins in your setup already.
A nice overview of possible conflicts between shields and arduino boards can be found at:
http://playground.arduino.cc/Main/ShieldPinUsage


text:
where does access point's IP address come from for sketch AP_SimpleWebServer.ino in Github WiFi101 examples
I don't understand where the access point's IP comes from.
Sketch uses WiFi.beginAP( ssid )   ..to start the AP.
Then, printWifiStatus() gets the access point's IP with:
IPAddress ip = WiFi.localIP();

How does .beginAP() create the IP?  What does it use for a mask?
I'm creating network service on a MKR1000, and want to use .beginAP() to make it an access point, so I don't need a "middle man" (router).  Going to have mobile device (iPhone) connect directly to Arduino MKR1000.

If you look into that github source code, you can see startAP function and mainly rows with strM2MAPConfig.au8DHCPServerIP:
uint8_t WiFiClass::startAP(const char *ssid, uint8_t u8SecType, const void *pvAuthInfo, uint8_t channel)
{
    tstrM2MAPConfig strM2MAPConfig;

    if (!_init) {
        init();
    }

    if (channel == 0) {
        channel = 1; // channel 1 is the minium channel
    }

    // Enter Access Point mode:
    memset(&strM2MAPConfig, 0x00, sizeof(tstrM2MAPConfig));
    strcpy((char *)&strM2MAPConfig.au8SSID, ssid);
    strM2MAPConfig.u8ListenChannel = channel - 1;
    strM2MAPConfig.u8SecType = u8SecType;
    strM2MAPConfig.au8DHCPServerIP[0] = 0xC0; /* 192 */
    strM2MAPConfig.au8DHCPServerIP[1] = 0xA8; /* 168 */
    strM2MAPConfig.au8DHCPServerIP[2] = 0x01; /* 1 */
    strM2MAPConfig.au8DHCPServerIP[3] = 0x01; /* 1 */

    if (u8SecType == M2M_WIFI_SEC_WEP) {
        tstrM2mWifiWepParams* wep_params = (tstrM2mWifiWepParams*)pvAuthInfo;

        strM2MAPConfig.u8KeyIndx = wep_params->u8KeyIndx;
        strM2MAPConfig.u8KeySz = wep_params->u8KeySz;
        strcpy((char*)strM2MAPConfig.au8WepKey, (char *)wep_params->au8WepKey);
    }

    if (m2m_wifi_enable_ap(&strM2MAPConfig) < 0) {
        _status = WL_CONNECT_FAILED;
        return _status;
    }
    _status = WL_AP_LISTENING;
    _mode = WL_AP_MODE;

    memset(_ssid, 0, M2M_MAX_SSID_LEN);
    memcpy(_ssid, ssid, strlen(ssid));
    m2m_memcpy((uint8 *)&_localip, (uint8 *)&strM2MAPConfig.au8DHCPServerIP[0], 4);
    _submask = 0x00FFFFFF;
    _gateway = _localip;

    // WiFi led ON (rev A then rev B).
    m2m_periph_gpio_set_val(M2M_PERIPH_GPIO15, 0);
    m2m_periph_gpio_set_val(M2M_PERIPH_GPIO4, 0);

    return _status;
}

Ah, hah!   192.168.1.1    Look at the code:  I feel sheepish. I'm still getting used to EVERYTHING being available with open source, I guess.  Thanks!


text:
How to turn I2C Sensors on and off with an Arduino Mega 2560?
I want to turn on and off I2C Sensors with the Arduino Mega 2560.

I use one max. 0.4A NPN Transistor, which controls the Vcc line to the sensor.
When I plug my Arduino into my laptop and the sketch begins working everything is fine. The sensor is turned on and is working.
But when I set the Transistor Base to Low and cut the Vcc the sensor acts weird.
The LED on the sensor breakout board shines very weak. So the sensor/breakout board is getting electricity from somewhere else; probably from the I2C connections.

Same results with this small experiment:

Breakout board directly connected to the Arduino (without Transistor)
Vcc-3.3V pin wire disconnected from the Arduino female pin

How can i properly turn on and off an I2C sensor with an Arduino?
Do I have to use additional transistors for every I2C line? Are better circuit solutions available or maybe a software solution?
How should I design my circuit and my software if I have multiple I2C sensors connected to my Arduino and I want to use them independently from each other?

Used hardware: Arduino Mega, Sensor Breakout Board

Software excerpt for power control:
void setup() {

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

    ...

    delay(10000);
    digitalWrite(7, LOW);

    ...
}

Why not use MPU6050 low power mode? The power LED and power regulators on the Arduino board draws more current.

Remove the LED
and put it into low power mode as suggested.

Trying to understand your real requirement I believe what you wish to achieve is not power down the sensor but to share the same I2C line among multiple ones: am I correct? If that's the case please update your question accordingly, because otherwise you'll keep getting the same answers over and over: power your sensor down, don't turn it off

The Question is: "How to turn I2C Sensors on and off with an Arduino Mega 2560?" How to cut off their electricity, how to turn them completely off and on, controlled by the Arduino. How to turn multiple different I2C Sensors completely on and off,  independent from each other, using the Arduino.

The SDA and SCL pins have pull up resistors on them. So their voltage is 5V. By disconnecting Vcc on the sensor you are running the sensor out of spec. since the voltage on the SDA and SCL pins exceed Vcc.
Most chips have clamping diodes. So the chip is clamping the 5V on the I2C pins to Vcc. So you are powering the chip through the pull-up resistors on the I2C pins.
This would explain why the power led is lit, but not as bright.

if your sensor does not consume more that 20ma, you can power it's GROUND pin with an arduino pin by using pinMode(sensor, OUTPUT), analogWrite(sensor, 255) : at that stage no power flows to the sensor since all its pins are high. When you want to power back the sensor, you need to lower the value of "255" to 0 , if your sensor uses 5v or to around 40 , if your sensor uses 3.3v. I have been using this system for a while without any problem.    You might need a small delay(50), to give time for the sensor to power up.


text:
Use photocell as digital input
I need to use multiple photocells as input, but its more than the amount of analog pins that my arduino has.
I'm wondering if theres any way to use a photocell as a digital input, with the photocell triggering at a specific set threshold of light.
It doesn't seem quite possible but I thought I'd ask.

You might like to look at analog multiplexor ICs.  The 4051 is popular. It uses 3 digital lines to select 1 of 8 analogue inputs.  I found a page describing the 4051 on arduino.cc: http://playground.arduino.cc/Learning/4051   I hope this helps. Regards,

Yes, you can use LDRs(photocells) as an indirect digital input.
You can design a voltage divider circuit, which incorporates your LDR and gives LOW or HIGH digital readings based on your pre-calibrated threshold light values.
Your voltage divider circuit must reach a specific voltage for your wanted light threshold to give you a HIGH reading.

The following are the voltage thresholds guaranteed to be read as HIGH.

When a pin is configured as an INPUT with pinMode(), and read with
  digitalRead(), the Arduino (Atmega) will report HIGH if:
a voltage greater than 3 volts is present at the pin (5V boards);
a voltage greater than 2 volts is present at the pin (3.3V boards);

Source of Quote

The numbers you quote are not the voltage thresholds: they are the lowest voltages where the pin is guaranteed to be read as high. On the Uno, more than 3 V is HIGH, less than 1.5 V is LOW, anything in between is not guaranteed. The “typical” thresholds are 2.6 V for the LOW → HIGH transition and 2.1 V for HIGH → LOW. These are different thresholds because of the hysteresis introduced by the Schmitt trigger at the inputs.

I'd suggest using a potentiometer, so you can tweak at which light level the pin goes high/low.

You wrote: “Your voltage divider should observe this thresholds”. No, it should not. If it does, then the pin is guaranteed to read HIGH when you expect it to read HIGH (good), but it will also read HIGH across a significant range of voltages where you expect it to read LOW (bad).

I see two possible options for achieving what you want:
Voltage divider
This is the solution proposed by William Roy: you make a voltage divider
circuit and check whether it gives a voltage above the threshold of the
digital input. For example:
+5V ---+
       |
       R
       |
       +--- digital input
       |
      LDR
       |
GND ---+

There are a couple of issues with this approach though:

Every digital input is fitted with a Schmitt trigger which makes
it hysteretic, meaning the voltage threshold for switching from LOW
to HIGH is higher than the threshold for switching from HIGH to
LOW. If the pin voltage is between the two thresholds, it will read
either HIGH or LOW, as determined by the history of that voltage.
Depending on your application, this may not be a problem, and may
even be desirable. But if you want, as you wrote in your question, “a
specific set threshold of light”, it sure will be problematic.

You do not know what those threshold voltages are. The datasheet of
the ATmega328P (the main chip of the Uno) states that
they should “typically” be around 2.1 and 2.6 V, but it only
guarantees that the low threshold should be no less than 1.5 V
and the high threshold no more than 3 V. For any input voltage
between 1.5 and 3 V (which is a very significant range), the
chip manufacturer doesn't guarantee what the pin will read.

The first issue can be solved by using a write-before-read protocol:
first you set the pin to OUTPUT LOW, which will force the input Schmitt
trigger to the LOW state. Then you set it to INPUT and take a reading.
This way you will read HIGH if and only if the pin voltage is above
the high threshold. The low threshold becomes irrelevant. Example code:
/*
 * Read the given pin avoiding the input hysteresis.
 *
 * Returns HIGH if the pin voltage is above the upper (LOW to HIGH)
 * threshold, LOW otherwise.
 *
 * WARNING: The pin is set to OUTPUT LOW for a very short time.
 */
int anhystereticRead(uint8_t pin) {
    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW);
    pinMode(pin, INPUT);
    return digitalRead(pin);
}

The second point can be solved by calibrating your input using a trimpot
instead of a resistor. You would adjust the pot until the threshold is
exactly what you want. Using fixed resistors instead of a pot will make
it very difficult to achieve your “specific set threshold of light”,
unless you can live with a very rough precision.
Capacitive measurement
The second option is use the LDR as the resistor in an RC circuit, and
measure the charging time of the circuit, like this:
digital output --- LDR ---+--- digital input
                          |
                      capacitor
                          |
                         GND

Starting with a discharged capacitor, you set the output to HIGH and
measure how long it takes for the input to read HIGH. This time is
typically something like 0.73 R C, where R is the
resistance of the LDR and C the capacitance of the capacitor. The
exact numerical factor is not know, as it depends on the high threshold
voltage of the digital pin.
For details and example code, you could check the Capacitance Meter and
RC Time Constants Arduino tutorial, or search the Web for
“Arduino capacitance meter”. You will find material about how to measure
an unknown capacitance using a know resistance, but you can use the same
technique to measure an unknown resistance using a known capacitance.
And you should replace the waiting loop:
while (analogRead(input) < THRESHOLD) {}  // wait

by a similar loop using the digital input threshold:
while (digitalRead(input) == LOW) {}  // wait

The interesting thing about this technique is that you do not need a
trimpot to set the illuminance threshold: you will measure the
charging time and set the threshold in software. Also, this technique is
not affected by the input hysteresis. The main drawback is that the
measurement takes longer than the voltage divider technique.
Edit: I found a blog post describing this exact method in greater
detail: Measuring resistance or voltage with 1 digital I/O,
by Moser.

LDR in a Wheatstone bridge + OpAmp as a comparator
For more (temperature...) stability of your LDR threshold it could be better to use a wheatstone bridge instead of a simple voltage divider.
Then you can send the output of your wheatstone (or your divider) to a simple OpAmp comparator circuit that will output High or Low, which you can plug in any digital port.
To know more on Wheatstone and OpAmp:
(you can use directly the last schema by plugging the output of the Opamp to the digital pin of your arduino (instead of sending it to the transistor)
http://www.electronics-tutorials.ws/blog/wheatstone-bridge.html
Hope that can help,
Gaetan

authors: Дарина Бакута


text:
Controlling buzzer with assembly
I want to make a piezo buffer beeping with assembly code, but i haven't managed to yet. I have an Arduino UNO board (ATMega328p) and using avra and avrdude to build and load. The buzzer just stay silent. Here's my code:
.nolist
.include "m328pdef.inc"
.list

.equ _a = 141 ;(16000000 / 256) / 440(frequency of A) - 1

.cseg
  ;wgm02..0 = 7 (fast pwm, top = ocr0a)
  ;cs02..0 = 4 (N=256)
  ;com0b1..0 = 2 (clear on compare match, set at bottom)
  ldi r16, 0b00100011
  sts tccr0a, r16 ;need out!
  ldi r16, 0b00001100
  sts tccr0b, r16 ;need out!
  ;ocr0a = _a to obtain 440Hz
  ldi r16, 141
  out ocr0a, r16
  ;ocr0b = ocr0a/2 to obtain a duty cycle of 50%
  ldi r16, 71
  out ocr0b, r16
  ;enable output at D5 aka oc0b aka Arduino pin 5
  sbi ddrd, 5
  loop:
  rjmp loop

Wiring is good and the buzzer too, since it works with a C sketch
EDIT: I found my answer by myself (with the help of answerers). I was accessing IO ports (tccr0a and tccr0b) with sts, while i had to use out. (tccr0a and tccr0b are IO ports defined in "m328pdef.inc" as IO addresses, not as memory addresses)

A common way to gain more insight in these sort of cases is to:

compile with optimizations turned off:  -O0
tell gcc to preserve intermediate artifacts (the assembly file generated: -S or --save-temps)

I don't use gcc. I use avra

You said that the buzzer works with a C sketch. How did you compile it?

For compiling C sketches i use Arduino IDE, that uses gcc i think, but for asm compiling i use avra, the AVRStudio assembler

Right. My advice was to observe the intermediate file produced by gcc (you can tell it to preserve the assembly sources) and use them as reference for debugging your own asm program.

What does tccr0a mean? Is it an I/O address? Or a data address maybe? And what about ocr0a?

I want to make a piezo buffer beeping with assembly code - why?

Yes, tccr0a is an IO address, my error was to use sts
And I use assembly because code is faster and I save much memory, and I'm masochist

In this instance, assembly is not significantly faster. From the C program main(){TCCR0A=0x23; TCCR0B=0x0c; OCR0A=141; OCR0B=71; DDRD|=1<<5; for(;;);}, gcc generates almost exactly the assembly you wrote, except it uses out instead of sts. By writing directly in assembly, you only save the initialization done by the C runtime (13 cycles, done only once). That being said, being a masochist is a perfectly valid reason for writing assembly. Or at least I like to believe so. ;-)

I translated you program to GNU as syntax, and it works as expected: I
get a 440 Hz square wave on digital pin 5. Here is the
translated program:
#include <avr/io.h>

; I'm too lazy to always type the full name of these macros
#define io(reg) _SFR_IO_ADDR(reg)
#define mem(reg) _SFR_MEM_ADDR(reg)

_a = 141 ;(16000000 / 256) / 440(frequency of A) - 1

  ;wgm02..0 = 7 (fast pwm, top = ocr0a)
  ;cs02..0 = 4 (N=256)
  ;com0b1..0 = 2 (clear on compare match, set at bottom)
  ldi r16, 0b00100011
  sts mem(TCCR0A), r16
  ldi r16, 0b00001100
  sts mem(TCCR0B), r16
  ;ocr0a = _a to obtain 440Hz
  ldi r16, 141
  out io(OCR0A), r16
  ;ocr0b = ocr0a/2 to obtain a duty cycle of 50%
  ldi r16, 71
  out io(OCR0B), r16
  ;enable output at D5 aka oc0b aka Arduino pin 5
  sbi io(DDRD), 5
  loop:
  rjmp loop

As shown in my comment to your question, I suspect the problem is a
misunderstanding of the meaning of things like tccr0a and ocr0a.
In the translated version above, I admit I do not know what TCCR0A
and co. mean. And I need not to: I can treat these as opaque
identifiers, as the avr-libc recommends to always use them with the
macros _SFR_IO_ADDR() and _SFR_MEM_ADDR(), which provide the I/O
address and the data address of the register respectively.
I do not know how to use avra, so I cannot tell you how the get the I/O
or data address of a register. But there certainly must be a way. You
should always use the data address with sts and the I/O address with
out and sti.


text:
Creating a Library Help with errors
I am attempting to create a library out of an existing code to use inside of another code.  To clarify, I have one code, I need to add the functionality of another code to.  Instead of plopping the 400+ lines inside of my existing code, I would like to create a library to house the other code so I can make my code easier to read.  I followed the Arduino Library tutorial to get to where I am, but their code is simpler than mine.  Ironically, my code is also about Morse code.  I have included the library files and the code I am using to troubleshoot.  I have attempted to troubleshoot these errors on my own by googling problems, I managed to cut the list about in half, but I just can't seem to root out these last few.
I am posting in this order: Morse.cpp, Morse.h, Library Test Code, The errors I need help with (all of which relate to the above three files) and the functioning code as it was before I tried to create this library.
The Following is the Morse.cpp Library File
/* Morse.cpp - Library for flashing Morse code.
Created by Young on Sept. 1, 2016 */

#include "Arduino.h"
#include "Morse.h"

Morse::Morse(int LED);
{
pinMode(LED, OUTPUT);
_LED = LED;
}
Morse::Morse(int BEEP);
{
pinMode(BEEP, OUTPUT);
_BEEP = BEEP;
}

_note = 587;

_dotLen = 75;

_dashLen = dotLen * 7;

_elemPause = dotLen * 4;

_Spaces = dotLen * 10;

_wordPause = dotLen * 14;

void MorseDot();
void MorseDash();
void LightsOff(int delayTime);
void GetChar(char tmpChar);

void Morse::MorseDot()
{
digitalWrite(led13, HIGH);    // turn the LED on
tone(BEEP, note, dotLen);     // start playing a tone
delay(dotLen);                // hold in this position
}

void Morse::MorseDash()
{
digitalWrite(led13, HIGH);    // turn the LED on
tone(BEEP, note, dashLen);    // start playing a tone
delay(dashLen);               // hold in this position
}

void Morse::LightsOff(int delayTime)
{
digitalWrite(led13, LOW);     // turn the LED off
digitalWrite(BEEP, LOW);      // Silence the Beep
delay(delayTime);             // hold in this position
}

digitalWrite(led13, LOW);     // turn the LED off
digitalWrite(BEEP, LOW);      // Silence the Beep
delay(delayTime);             // hold in this position

void Morse::GetChar(char tmpChar)
{
// Take the passed character and use a switch to find the morse code for that character
switch (tmpChar) {
    case 'a':
        MorseDot();
        LightsOff(elemPause);
        MorseDash();
        LightsOff(elemPause);
        break;
    case 'b':
        MorseDash();
        LightsOff(elemPause);
        MorseDot();
        LightsOff(elemPause);
        MorseDot();
        LightsOff(elemPause);
        MorseDot();
        LightsOff(elemPause);
        break;
    case 'c':
        MorseDash();
        LightsOff(elemPause);
        MorseDot();
        LightsOff(elemPause);
        MorseDash();
        LightsOff(elemPause);
        MorseDot();
        LightsOff(elemPause);
        break;
/*This continues for the rest of the alphabet as well as numbers and characters,
however to save space and time I have only listed a,b, and c */

The following is the Morse.h Library file
/* Morse.h - Library for flashing Morse code.
Created by Young on Sept. 1, 2016 */

#ifndef Morse_h
#define Morse_h

#include "Arduino.h"

class Morse
{
public:
Morse(int LED, int BEEP, int delayTime, char tmpChar);

void MorseDot();
void MorseDash();
void LightsOff(int delayTime);
void GetChar(char tmpChar);

private:
int _LED;
int _BEEP;
int _delayTime;
char _tmpChar;
int _note;
int _dotLen;
int _dashLen;
int _elemPause;
int _Spaces;
int _wordPause;
};

#endif

The following is the test code
#include <Morse.h>

int delayTime;
int tmpChar;

Morse dot();
Morse dash();
Morse dark(int delayTime);
Morse set(char tmpChar);

char stringToMorseCode[] = "N 36° 00.19518   W 084° 13.88856";    //Final Coordinates

// Create variable to define the output pins
int LED = 13;      // blink an led on output 12
int BEEP = 14;      // output audio on pin 8
int i;

void setup()
{

}

void loop()
{
// Loop through the string and get each character one at a time until the end is reached
for (int i = 0; i < sizeof(stringToMorseCode) - 1; i++);
{
// Get the character in the current position
char tmpChar = stringToMorseCode[i];
// Set the case to lower case
tmpChar = toLowerCase(tmpChar);
// Call the subroutine to get the morse code equivalent for this character
set.GetChar(tmpChar);
}

// At the end of the string long pledause before looping and starting again

dark.LightsOff(8000);            // hold in this position

}

These are the errors I get when I run this code.
/Users/DMYoung1/Documents/Arduino/Morse_Library_Test/Morse_Library_Test.ino: In function 'void loop()':
Morse_Library_Test:33: error: request for member 'GetChar' in 'set', which is of non-class type 'Morse(char)'
   set.GetChar(tmpChar);
       ^
Morse_Library_Test:38: error: request for member 'LightsOff' in 'dark', which is of non-class type 'Morse(int)'
 dark.LightsOff(8000);            // hold in this position
      ^
exit status 1
request for member 'GetChar' in 'set', which is of non-class type 'Morse(char)'

In case this will also help, this is the original code which I know works.  Hopefully this could help someone else understand the transformation of a slightly more complicated morse reader code into a library, so please feel free to respond as though I know nothing.  It will help me and could help someone else.
/*
Morse Code Project
This code will loop through a string of characters and convert these to morse code.
It will blink an LED light and play an audible tone on a piezo speaker.
*/

char stringToMorseCode[] = "Convert to Morse"; //String to Convert

// Create variable to define the output pins
int led13 = 1;      // blink an led on output 12
//int led6 = 0;        // blink an led on output 6
int BEEP = 0;      // output audio on pin 8
int note = 587;      // music note/pitch

/*
Set the speed of your morse code
Adjust the 'dotlen' length to speed up or slow down your morse code
(all of the other lengths are based on the dotlen)

Here are the ratios code elements:
Dash length = Dot length x 3
Pause between elements = Dot length
(pause between dots and dashes within the character)
Pause between characters = Dot length x 3
Pause between words = Dot length x 7

*/
int dotLen = 75;     // length of the morse code 'dot'
int dashLen = dotLen * 7;    // length of the morse code 'dash'
int elemPause = dotLen * 4;  // length of the pause between elements of a character
int Spaces = dotLen * 10;     // length of the spaces between characters
int wordPause = dotLen * 14;  // length of the pause between words

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output for LED lights.
pinMode(led13, OUTPUT);
pinMode(BEEP, OUTPUT);

}

// Create a loop of the letters/words you want to output in morse code (defined in string at top of code)
void loop()
{
// Loop through the string and get each character one at a time until the end is reached
for (int i = 0; i < sizeof(stringToMorseCode) - 1; i++)
{
// Get the character in the current position
char tmpChar = stringToMorseCode[i];
// Set the case to lower case
tmpChar = toLowerCase(tmpChar);
// Call the subroutine to get the morse code equivalent for this character
GetChar(tmpChar);
}

// At the end of the string long pause before looping and starting again
LightsOff(8000);
}

// DOT
void MorseDot()
{
digitalWrite(led13, HIGH);    // turn the LED on
tone(BEEP, note, dotLen);   // start playing a tone
delay(dotLen);              // hold in this position
}

// DASH
void MorseDash()
{
digitalWrite(led13, HIGH);    // turn the LED on
tone(BEEP, note, dashLen);   // start playing a tone
delay(dashLen);               // hold in this position
}

// Turn Off
void LightsOff(int delayTime)
{
digitalWrite(led13, LOW);     // turn the LED off
digitalWrite(BEEP, LOW);      // Silence the Beep
delay(delayTime);             // hold in this position

}

// *** Characters to Morse Code Conversion *** //
void GetChar(char tmpChar)
{
// Take the passed character and use a switch case to find the morse code for that character
switch (tmpChar) {
case 'a':
MorseDot();
LightsOff(elemPause);
MorseDash();
LightsOff(elemPause);
break;
case 'b':
MorseDash();
LightsOff(elemPause);
MorseDot();
LightsOff(elemPause);
MorseDot();
LightsOff(elemPause);
MorseDot();
LightsOff(elemPause);
break;

//Again, this switch case would continue through the alphabet, but I am stopping
//here because that would dramatically increase the length of this page

The problem is that you are trying to call a class function without an object (hence the error). The original code works because the functions are created without a class. When you add the class (in the library), you need to create an object to perform those functions with it. To do this, use the constructor className object(parameters)
So in your case, you'd do Morse Object(LEDpin)
To use your functions you can now do Object.Function(parameters)

I read about this, I just couldn't figure out how to fix it!!  I understand everything you have told me except for the parameters.  What / how should I set those?

Let me rephrase, I understand conceptually everything you have told me and I really appreciate your response.  I'm afraid I just can't seem to make the connection from concept to my code.  I have been reading about objects and function parameters, I just can't seem to understand how to actually implement them.  For example, should I put this code in the library file?  Or does it go in my program code?  Either way, how should I proceed.  When I said treat me like I know nothing, I really don't know anything about this, but I can't learn if I don't try.

There is this thing called a 'class constructor'. You can look it up for a more detailed explanation, but basically you have a function without a type inside your class, named the same thing as your class. You have a couple of them, Morse() - I would combine them into one Morse() with a bunch of parameters. Basically, when you create the object Morse() will automatically run, using the parameters you put in where I said. I would look it up - I'm not sure I explained it that well!

Great, I will look it up and if I get stuck I will post back here, probably in a few hours.  Thanks for the help so far!!

I have fixed it would seem all the errors I had before, but I have two more they are both the same, but relate to different members in objects.  These seem to be common errors as I have been able to read a great deal about other people's troubles with them, but I seem to be unable to diagnose their problems or mine.  The errors are as follows:

I have edited the code and errors in the question to reflect the new issues.

So now we have an answer which is accepted but it's not any more related to the question as the question has been changed... I'm not sure this is the right way to use SE