message:
Find external router IP from Arduino Yun inside router network

I want two Arduino Yuns in different private networks to communicate, i.e., behind two distinct routers of which at least one does *not* have dynamic DNS, so its external IP may change from time to time.

To be reachable, this Yun could forward its router's external IP to the other Yun which has a fixed DNS name. But for this to work, it must be able to determine its router's external IP.

- How can the Yun find out that the external IP of the router has changed? The Yun will be runnning all the time.

- If the external router IP has changed (i.e., my Fritz.Box disconnects in the night and may receive a different IP when it reconnects), how can the Yun determine the new external IP?

If this is not the right place to ask, I'm happy for pointers to somewhere else (Server Fault SE forum?).

body:
You can write a program that updates its own external IP every couple of minutes/hours, or when it doesn't get a response from another Yún/PC/server.

You can use this link (or find another site of the web that gives you your external IP address): http://www.realip.info/api/p/realip.php

This link has a beautifully formatted information that you can easily extract. I have a similar solution on one of my servers that have a dynamic IP...


sender: user

message:
Running C for arduino

Is there a compiler that I can use to run C on an arduino or any other way so that I can upload C programs to my arduino?

sender: assistant

body:
Perhaps you should look into here
https://github.com/arduino/Arduino/wiki/Build-Process

Arduino uses avr-gcc compiler. Basically, it is a C compiler.

There is an step by step on how to customize this process using an avr-gcc compiler of your own here
http://www.wikihow.com/Write-Arduino-Software-in-C

But I best recommend you downloading the arduino IDE on the official website to get things going. It has all the serial pairing stuff you don't really need to know to get started.

Hope it helps.


message:
Problem with deploying matlab simulink mode to Arduino UNO

I encounter a problem when deploy matlab simulink model to Arduino UNO

Following shows the error

    *The call to realtime_make_rtw_hook, during the after_make hook generated  the following error:
    The build failed with the following message: The system cannot find the path specified
    The build process will terminate as a result.
    The build failed with the following message: The system cannot find the path specified。
    Component: Simulink | Category: Block error*

When type >> getenv('path')

    ans =

    C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;E:\MathWorks\runtime\win64;E:\MathWorks\bin;E:\MathWorks\polyspace\bin;C:\Program Files\MATLAB\R2014b\runtime\win64;C:\Program Files\MATLAB\R2014b\bin;C:\Program Files\MATLAB\R2014b\polyspace\bin;C:\Program Files\Microsoft Windows Performance Toolkit\

I did not see anything wrong with the path. I tried to solve the problem following the "http://www.mathworks.com/matlabcentral/answers/168555-what-does-the-path-in-the-system-cannot-find-the-path-specified-refer-to". However it does not work.

Anyone know how to solve it?

OS:Win8.1 Matlab 2014b 64bit

body:
Right click on your MATLAB shortcut and click "run as administrator". See if helps. Then do all the necessary steps and see if it happens again.

Also test with x86 version. I have seen lots of these kinds of error with x64 version. Always had compiling related issues with MATLAB x64 and Simulink!


message:
How to use Induino R3 on Ubuntu 14.04

I have just got [Induino R3](http://www.induino.com/). I have installed Arduino on my Ubuntu. I tried blink example but it shows error `serial port COM1 not found`

I think i need to select proper option from *serial port*. But i can't click on it!

P.S. I am completely new to Arduino

body:
Not 100% sure of the specific differences between your board and a normal Arduino[clone], but I've never seen serial devices referenced in Ubuntu via COM# labels(Granted I've only used or needed to use serial type devices in the last year, so I could be a bit under experienced).

Anyhow, usually I find serial devices available at /dev/ttyXXX. On my Lubuntu 14.04 installs, my USB connected Arduinos all show up as /dev/ttyACM#. I have an FTDI programmer I usually use on wifi routers which generally shows up as /dev/tty#.

Rule of thumb in Linux, everything is a file somewhere.


body:
Did you by any chance, download the Windows version of the Arduino IDE and install it under Wine? Then I would expect it to seek a COM# serial port. In which case you will have to create a symbolic link from the relevant /dev/ttyUSBx to COMx for your Arduino IDE to work.

The right way is to download the Arduino for Linux tar.gz file and extract it to a path of your choice in your Home folder.


message:
Why use .h files with .cpp?

At school, our teacher always taught us to use .hpp (C++ Header files) with our .cpp (C++ files). But Arduino seems to use .h files (with .cpp links?).

----------

When someone is programming in C (without C++ compiler) they have the chance to get linked to a .cpp file through a .h file?

- So why isn't a .cpp file always with a .hpp file?
- What are the drawbacks of using .hpp files with your .cpp files?

This is not to start a discussion on what's best, please provide an answer with arguments that are not based on "what you like to do more".

body:
The extension you use for a header file doesn't technically matter because the compiler never sees it. You could name it with the extension `.this-is-a-header-file` and it would probably still work.

The compiler only handles the C/C++ source files, typically named `.c` and `.cpp`. However, before that happens, the preprocessor goes through and looks for any `#include` lines. When it sees one, it basically copies the entire contents of the included file into the source file before it gets compiled.

This is normally used to include header files. However, the preprocessor doesn't know or care about different programming languages. All it does is process the raw text so there's nothing stopping you from including any text file you like, with any name or extension.

Choosing to use `.h` or `.hpp` is mostly just personal preference. You could certainly argue that it lets you (as a programmer) distinguish between C/C++ code more easily.

However, the reason why `.h` is more common is probably that C and C++ code is mixed so freely. You can generally compile C code as C++ without any problems, in which case it's the context (rather than the file itself) that tells you if it's C or C++. It's also possible to write a library in C++ which only exposes a C interface, meaning it could be used by C programs.

You could definitely include a C++-specific header file in a C program by mistake. All that would happen is that the compiler wouldn't understand the contents of that header file. Sensible development environments don't link to a project/library when it sees a `#include` directive (the Arduino IDE is the only one which does this, as far as I'm aware).


message:
How to power Arduino only when light is on

I want Arduino to conserve energy and turn it on automatically only when the lights is on. Can I use some kind of light sensor and put it in between power supply and arduino somehow? Ideally light sensor will power from the same power source, if possible.
I'm not an electrical engineer - just enthusiast, so please explain your idea as detailed as possible. Many thanks!

body:
If it's OK for it go off (not just to sleep) when the light is off, power it from the lighting circuit. These two parts will do it without messing with the electrics:

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

The light socket adapter with two outlets is a hardware-store part, probably about USD$3, and the USB charger makes a compact and useful Arduino 5v power supply, USD$6 at Amazon right now. (Apple's little USB power cube might fit better but is more expensive). I use the Nokias for Arduino power supplies and their no-load voltage is just barely over 5v. If you substitute a different one, that would be a worthwhile test to make before you connect it to your Arduino.

  [1]: https://i.stack.imgur.com/fZnYv.png
  [2]: https://i.stack.imgur.com/2SR5X.png


body:
Conserve energy?

There are many ways to conserve energy in an Arduino(e.g. Use a USB adapter that does not waste energy as heat, instead of using Battery power)

But if you want to save energy by only switching on the Arduino when light is on, it depends on the intensity of the light.

If it is supposed to switch on only during the day, use Solar Panels to power the Arduino.

Else, use an LDR.


body:
For a chip like the basic Arduino's ATmega, you don't really "turn it off" to save power, rather you put it into a low-power sleep mode.

First, make sure you aren't consuming more power than needed normally.  Make sure unused peripherals like the ADC are off.  If your program spends most of its time waiting for external events, try reducing the clock speed either with a slower crystal or the 8 MHz oscillator, and with the clock prescale register.

Next, implement a sleep cycle.  Turn off everything you can, and program a hardware timer to generate an interrupt at some point in the future.  Enter sleep mode, so the processor stops and only the logic in the counter is still running.  When the interrupt fires, the ATmega CPU will wake up and continue operating, at which point you enable the ADC, use a GPIO to drive your light sensor, and take a reading from it.  If it doesn't meet your conditions, turn it all off again and go back to sleep until it's worth checking again.

In low power design you must be very careful of things outside the processor stealing power.  Watch out for any resistors pulling signals, if the signals are actively drive against the resistor.  LEDs are an obvious issue.  Also watch out for voltage regulators which may have high quiescent current.  And finally beware of peripheral chips - a stock Arduino has an entire second processor sitting there in the USB-serial adapter wasting power.  So you will either need to customize the firmware of that to shut down too, or else use a simpler board that doesn't have one (don't just hold it in hardware reset, as the reset pin has an internal pullup which will then consume power).


body:
You may keep your Arduino powered, but have it sleep when the lights are
off. During sleep, it would periodically awake to check the light level:
if it's low enough, it goes back to sleep, otherwise it resumes its
work. Here are the detailed steps:

1.  Try to find a power-efficient Arduino or clone (no ON LED, no USB
    bridge...) or learn how to build and program a barebones one. If you
    can live with a 8 MHz clock, a bare ATmega, or even ATtiny, may
    be a good option.
2.  Get an LDR (light-dependent resistor) and an ohmmeter.
3.  Measure the resistance of the LDR at the relevant light levels, and
    decide for a value of resistance that will serve as a threshold for
    switching on and off. I will call this `LDR_THRESHOLD_RES` in the
    code.
4.  Get a plain resistor with a value close to the previous threshold
    (within a factor 10 should be OK), but not lower than 1 kΩ.
    This will be your "pullup" resistor, and its resistance will be
    `LDR_PULLUP_RES`.
5.  Decide how often the program will check for the lights being turned
    on. This delay, in milliseconds, will be `LDR_CHECK_DELAY`.
6.  Assign both a digital and an analog pin for measuring the LDR. These
    will be `LDR_DRIVE_PIN` and `LDR_SENSE_PIN` respectively.
7.  Connect the LDR between `LDR_SENSE_PIN` and ground; connect the
    pullup resistor between `LDR_SENSE_PIN` and `LDR_DRIVE_PIN`.
8.  Update the code below (the first 5 #defines) and include it in your
    sketch.
9.  Add `pinMode(LDR_DRIVE_PIN, OUTPUT);` to your `setup()`.
10. Call `wait_for_lights()` inside `loop()`, wherever you want your
    program to pause if the lights are off.

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

    #include <avr/sleep.h>

    #define LDR_THRESHOLD_RES 25e3  // 25 kOhm
    #define LDR_PULLUP_RES    10e3  // 10 kOhm
    #define LDR_CHECK_DELAY    200  // 200 ms
    #define LDR_DRIVE_PIN        2  // digital 2
    #define LDR_SENSE_PIN        0  // analog 0

    #define LDR_THRESHOLD_RATIO (1.0*LDR_PULLUP_RES/LDR_THRESHOLD_RES)
    #define LDR_THRESHOLD_READING ((int)(1024 / (1 + LDR_THRESHOLD_RATIO)))

    /* Sleep until the light is on. */
    void wait_for_lights() {
        for (;;) {
            // Sense light level.
            digitalWrite(LDR_DRIVE_PIN, HIGH);
            int reading = analogRead(LDR_SENSE_PIN);
            digitalWrite(LDR_DRIVE_PIN, LOW);

            // Low reading means the light is on.
            if (reading < LDR_THRESHOLD_READING) return;

            // Wait for a few milliseconds.
            unsigned long start = millis();
            do sleep_mode();
            while (millis() - start < LDR_CHECK_DELAY);
        }
    }

This should already get your power consumption pretty low. If you want
to save further power, you will likely have to dig into your
microcontroller's datasheet. You can try the various `power_*_disable()`
functions and turn off all the peripherals you do not need. You can also
try a deeper sleep mode than the default one (IDLE), but then your
`millis()` clock will freeze during sleep, and you will have to set up
some wake up source if you do not want to sleep forever. The watchdog
timer is a good option.


message:
Alternative Way to Power Components on an Arduino

I have very limited knowledge regarding electronics. Please help me cure my ignorance on the subject of robotics.

I want to power the Arduino Uno R3, US-015 ultrasonic sensor, and the L298N motor controller from a single power source (7.2v). However, I'm not sure if this diagram is correct. If it is functional, will it last that way?

![enter image description here][1]

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

If this diagram is deemed wrong, please suggest alternatives with one power source.

Advance thanks to those who would reply. Elaborate answers would be very much appreciated. :D

**Edit:** Since it's deemed incorrect, I'm going to power Arduino through the DC barrel jack and power the L298N motor controller through the Vin and the ultrasonic sensor from the Arduino 5v output. Is it wise to do this?

body:
Using a motor controller to power an Arduino or analog peripherals is probably unwise as the source is liable to be noisy.

Better, probably, is to power the Arduino from the 7.2V supply via a noise filtering resistor into the Arduino's **Vin** terminal.
**NBNBNB** 7.2V input **MUST** be to Arduino Vin.

Use a small series resistor from 7.2V to Vin and a large filter cap at Vin to ground. Then power the sensor from Arduino 5 V output.

Voltage drop in series resistor from 7.2V to Vin must drop under 2V.
Rmz is <= Vdrop / Iload
For say 50 mA load Rseries = V/I = 2V max / 0.05 = 40 Ohms .
For 100 mA R <= 2/.1 20 Ohms.
So probably try about 22 Ohms to start.
If Vdrop is > 2V a smaller R is needed.
If Vdrop is << 2V increase R.

For the capacitor at Vin - the larger the better.
100 uF good. 1000 uF better.

Resistor power dissipation is I^2 x R.
So at even 100 mA Pres = 0.1^2 x 22R = 0.22W
A 1/2 Watt resistors would suffice.
A  1 W resistor would do no harm and would tolerate the heat better.

___________________

The 22 Ohm resistor and large capacitor form an RC (Resistor + Capacitor) noise filter.
This greatly reduces motor noise which appears on the 7.2V line.
This is very standard practice in real world installations like this.
An inductor based filter can be better but RC should suffice.


message:
Issues with PIR Sensor triggering by itself

I am currently working on my first Arduino project and I am having some issues that I am seeking help with. The robot I am building must have human following capabilities and to do so I am using 3 PIR sensors (One on the front, one on the left and one on the right) and an Ultrasonic Sensor so the robot won't run into a wall or a person it is following. To handle the motors I am using the Adafruit Motor Shield (V.1)

The way I am trying to make this work is as follows.

The robot's main PIR sensor is the one attached to the front. If this sensor reads HIGH then the robot will move forward while checking its distance from any objects in front of it in which case it stops and reverses until there is at least 30cm of space between itself and the object in front. The radius of this sensor had to be reduced so that it only reads HIGH if the person is exactly in front of the robot. This was done using carton paper and black duct tape. Two images of this have been provided below in case this has something to do with my issue.

![][1]

![][2]

The other 2 PIR sensors attached to the sides will tell the robot if it should turn left or right. If the left PIR is triggered then the robot will start turning left and keep doing so until the front PIR finally reads HIGH, and then it moves forward. The same thing is done with the right PIR except that it moves right. These PIR sensors are handled using interrupts on the Arduino Mega 2560 board as can be seen in the provided code.

The code I am using can be found below:

    #include <AFMotor.h>
    #include <NewPing.h>

    #define trigPin 34
    #define echoPin 32

    NewPing sonar(trigPin, echoPin);
    int minimumDistance = 30;
    int currentDistance = 0;

    int calibrationTime = 60;
    int redLED = 22;
    int greenLED = 24;

    int PIR = 26;
    volatile int PIR_val = 0;
    int PIR_left = 19; // (interrupt 4)
    int PIR_right = 18; // (interrupt 5)

    AF_DCMotor motorL(1, MOTOR12_64KHZ);
    AF_DCMotor motorR(2, MOTOR12_64KHZ);

    void setup()
    {
      pinMode(redLED, OUTPUT);
      pinMode(greenLED, OUTPUT);

      pinMode(PIR, INPUT);
      pinMode(PIR_left, INPUT);
      pinMode(PIR_right, INPUT);

      pinMode(trigPin, OUTPUT);
      pinMode(echoPin, INPUT);

      digitalWrite(redLED, HIGH);
      // Calibration for PIR sensors
      for (int i = 0; i < calibrationTime; i++)
      {
        delay(1000);
      }
      digitalWrite(redLED, LOW);
      digitalWrite(greenLED, HIGH);

      attachInterrupt(4, turnLeft, RISING);
      attachInterrupt(5, turnRight, RISING);
    }

    void loop()
    {
      delay(50);
      currentDistance = sonar.ping_cm();

      if (currentDistance < minimumDistance && currentDistance > 0)
      {
        moveBackward();
      }
      else
      {
        PIR_val = digitalRead(PIR);

        if (PIR_val == HIGH)
        {
          moveForward();
        }
      }
    }

    void moveForward()
    {
      motorL.run(FORWARD);
      motorL.setSpeed(180);
      motorR.run(FORWARD);
      motorR.setSpeed(200);
    }

    void moveBackward()
    {
      motorL.run(RELEASE);
      motorR.run(RELEASE);
      motorL.run(BACKWARD);
      motorL.setSpeed(190);
      motorR.run(BACKWARD);
      motorR.setSpeed(225);

      while (currentDistance < 30 && currentDistance > 0)
      {
        currentDistance = sonar.ping_cm();
      }

      motorL.run(RELEASE);
      motorR.run(RELEASE);
    }

    void turnLeft()
    {
      motorL.run(BACKWARD);
      motorL.setSpeed(150);
      motorR.run(FORWARD);
      motorR.setSpeed(150);

      // While front PIR is reading LOW
      while (PIR_val == LOW)
      {
        PIR_val = digitalRead(PIR);
      }
      // After front PIR reads HIGH
      moveForward();
    }

    void turnRight()
    {
      motorR.run(BACKWARD);
      motorR.setSpeed(150);
      motorL.run(FORWARD);
      motorL.setSpeed(150);

      // While front PIR is reading low
      while (PIR_val == LOW)
      {
        PIR_val = digitalRead(PIR);
      }
      // After front PIR reads HIGH
      moveForward();
    }

The first issue I am having is that as soon as the PIR sensors are done calibrating, the robot starts moving forward by itself. Even if I leave the robot alone inside a room with the door closed, after the calibration time passes the robot automatically moves forward on its own.

The other issue I am having is also with the front PIR sensor. While the robot is turning and looking for a human as seen in the 'turnLeft()' and 'turnRight()' methods, the robot will sometimes move forward toward a random direction instead of towards me.

I have already tried replacing the front PIR sensor twice and the sensor itself does not seem to be the issue.

The PIR sensors I am using are the 'HC-SR501' model.
For all PIR sensors, the delay time is set to the lowest possible time (5 seconds) and the sensitivity is set to full.

I welcome any input or suggestions whatsoever. If you would like me to provide any additional information about this project please ask and I will do so.

  [1]: https://i.stack.imgur.com/q8R9m.jpg
  [2]: https://i.stack.imgur.com/3CcxR.jpg

body:
Try:

 - turn sensor OFF when robot is moving
 - turn sensor ON while robot is standing still
 - look for some prey
 - repeat from 1 one

Same schema goes with rotating :

 - rotate to some angle,
 - stop rotation
 - detect

xD I was wondering bout it too, but only thinking, not implemented yet!

I think that simple is best, but something advanced with faster reaction would be better!


message:
Detect movement on moving robot? PIR Sensor

I am working on a human following robot project and I am trying to achieve this with 1 Ultrasonic sensor that makes sure the robot won't crash into something and 3 PIR sensors that will detect human movement.

The robot has an Ultrasonic Sensor and a PIR sensor attached to the front and a PIR sensor attached to the right side and another PIR sensor attached to the left side.

If the front PIR reads HIGH, then the robot will move forward. If the left or right PIR reads HIGH, then the robot will start turning in a 360 degree motion to the left/right side and will keep on doing so until the front PIR reads HIGH, and the robot moves forward again.

I am currently working with this build and I am having issues with the sensors. Sometimes they read HIGH when they shouldn't and sometimes they read LOW when they should be reading HIGH.

So my question is, what can I do to help the PIR sensors with getting the correct reading and is it possible to do so while the robot is turning?

Also, how will calibration work here? Am I able to let the robot turn slowly in 360 degree motion so the 3 PIR sensors will be calibrated with the rooms surrounding or is this a dumb question? If so I'm sorry, I am pretty new to PIR sensors.

----------------------------------------------------------------------------------

UPDATE:

Thanks for the help everyone. I have now replaced the side PIR sensors with Ultrasonic sensors. I have kept the front PIR sensor though. It is working a lot better than with the side PIR sensors and I thank you all for your input.

body:
Basically you have a robot and sensors that can detect movement.
There is one caveat though. For the PIR sensors to (non false-positive) detect motion, they have to be stationary (as far as I know).

So with only these PIR sensors it's unlikely that you can track something well.
Tracking something would be done best by using a range/proximity sensor.

----------
The image below, seems to be a cute robot, with eyes.
You could take 3 sensors and place them under an angle (one forward, one forward/left and one forward/right) [picture 2]. Or just have one that rotates (will be more difficult) [picture 1].

You would want the robot to start following anything that comes close (or when one of the sensors sees a difference in distance. And then the robot will try to keep that distance, brake when he gets closer, drive when he gets further.

If that's working, you can implement the sensors at the side, that if suddenly he loses track of the object/person, he'll adjust his alignment so that the middle sensor sees it again. This could also be done by simpler sensors [picture 3]

When the robot gets to close, and the other object doesn't try to run for quite a time, you can make him check for another target. (With a PIR or by rotating and stopping rotating to check range/pir)

I believe this solution is more applicable as with only PIR sensors, as it's usefull to know the range when you're following something. You don't want to bash into it.

![Cute robot][1]

![3-directional ping][2]

![proximity sensor][3]

  [1]: https://i.stack.imgur.com/0ll83.jpg
  [2]: https://i.stack.imgur.com/9YGWD.jpg
  [3]: https://i.stack.imgur.com/hCzN5.jpg


body:
Try using heat detectors(technically speaking, Infrared sensors) (along with >1 Ultrasonic sensors and PIR motion sensors for greater accuracy) with 1 ultrasonic sensor.
Comment if you want more help.


message:
What board to use to send a text message via an arduino board

I am fairly new to arduino boards and I was wondering which board to use. I was looking into the edison board because it has built in wifi and bluetooth.

body:
The [GSM Shield](http://arduino.cc/en/Guide/ArduinoGSMShield) will suit your needs. This is a *shield*, meaning that is a board that will go **on top** of another Arduino board (e.g UNO, Leonardo, ..., choose whatever you'll need).

This is what it will look like:

![Arduino UNO and the GSM Shield stacked][1]

To send SMS you'll also need a working **SIM card** and the **GSM library** to program the shield. On the previously linked page there are some tutorials to follow in order to check the basic functioning of the setup.

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


body:
Another option is the [Spark Core or Photon][1].  It's not an Arduino but it's very close.  I have Arduino sketches that I have ported right over with no modification.

The Spark boards are internet-connected and you can send text messages or emails using IFTTT.  It's also going to be a lot more cost effective than an Arduino plus wifi shield, particularly if you can wait until June for the $19 Photon to ship.

You could also use a Raspberry Pi connected to the internet to just do the email part but that's a little more trouble than it's worth.

  [1]: https://store.spark.io/?product=spark-core


body:
Actually, you should use a Raspberyy Pi if your project involves complex processing in it.

But if the project is very simple, just use one of those Spark Core or Photon.

Using an Arduino and a Sheild to do it is certainly not a good idea, as the Pi is much faster in processing and costs about the same.


message:
Is it possible for a HC-05 Bluetooth module to have multiple slaves

For a project I am interested in using the HC-05 Bluetooth module to control five LEGO Mindstorms Bricks simultaneously. For this to work the Bluetooth module will obviously have to be paired / connected with the five bricks at the same time. This means that the HC-05 Bluetooth module will have to be master in the piconet and the five bricks the slaves.

Is there anyone who has any experience with using the Arduino Uno and HC-05 Bluetooth module to send data to multiple, connected, slaves? If not, are there any alternative Bluetooth modules? And if Bluetooth modules compatible with the Arduino Uno cannot connect to multiple slaves at the same time, are there other ways that an Arduino can control multiple Bluetooth slaves at the same time?

body:
After some research, it looks like multiple slaves aren't possible with this particular module.

According to [Wikipedia](http://en.wikipedia.org/wiki/Bluetooth#Implementation) the Bluetooth technology allows a master to communicate with 7 slaves, but this option isn't implemented in the HC-05.


message:
7-Segment Common Anode

I accidently bought a "Common Anode" 7-segment display instead of a "Common Cathode".

I understand that the polarity of the leds within the display is 'reversed'. So instead of putting the common pin on GND I have to put it to 5v (with current limiting resistor)

My questions on this are:

 1. Can I still use only one current limiting resistor on the common pin? Instead of a resistor on every segment pin.
 2. Can I use the pins from arduino to drive it (withouth pull-up/pull-down?) By making the signal `LOW` the current will flow from 5V common anode to the arduino and thus the segment wil light?
 3. Can I still use a shift register to drive the segment led? (By inversing the outputs (in software))

----------

**Obviously I would like to have wiring more like this** (but then I would ofcourse change  the GND line to a 5V line.

![Better wiring][2]

----------

**The wiring below is the worst-case wiring I can think of.**

![Wiring][1]

 ^ So can I avoid this, when using a `Common Anode 7-segment display` or am I forced to buy a `Common Cathode 7-segment display`?

  [1]: https://i.stack.imgur.com/t9mfh.png
  [2]: https://i.stack.imgur.com/S6MnF.jpg

body:
You can use a single resistor on the common pin if you want. The problem is that lighting up multiple segments at the same time will substantially reduce the brightness of each one. You could work around that by lighting each segment one at a time in very quick succession though.

It should be possible to control the display directly from the IO pins by setting them LOW. In this configuration, they will be **sinking** current (rather than **sourcing** it). It depends on the specification of the display and on what resistor you use though.

Basically, try to keep the current **below 20mA** and it should be OK (assuming you're using a standard 5V Arduino). For example, if each segment has a forward voltage drop of 2V, you would want to use a resistor of around 180 Ohm.

Controlling the display directly from a shift register is probably not possible, although once again it depends on its specification. Shift registers usually aren't designed to sink enough current so you'll need something like a transistor on each output.


body:
Sorry about the crudity of my image, but you don't always need those transistors. Peter has already said so, but I wanted to explain a bit further.
![schematic][1]

The only thing is that you need to set a pin to LOW to light up the led, and HIGH to turn it off. Just use a `!` to make your code more intuitive if your like. So e.g. `digitalWrite(segmentA, !HIGH)`

Some limitations. A pin can sink up to 40mA (no problem here), but the total sink current for the digital pins `0` to `4` shouldn't exceed 100mA. The same goes for pins `5` to `13`. And the same goes for the analog pins. So either limit the current through the leds to around 10mA, or make sure no more than 5 leds are lit at the same time, or connect half of the segments to on of the above mentioned groups, and the other half another (f.y.i. analog pins can be used just like digital pins).

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


body:
Peter and Gerben have already said what is needed , but I wish to explain things even further.

A normal small 7-Segment display consumes only 70-80mA when all segments are HIGH.So you can use the Arduino directly without damaging it. Also note, depending on the quality of the project, you could either use a common resistor for all segments, or use separate ones. Separate ones will give much brighter light and better quality.

A medium size one will require max consumption of around 400mA current, so use cheap transistors.

A large size one will require max consumption of upto 1.5-2A current , so use MOSFETS or other high current Transistors.

An Extra Large one will require max consumption of upto 10-25A current, so use good MOSFETS or maybe even Relays.

Usage

Small- Wrist watches

Medium- Small clocks

Large- Big clocks

Extra Large- Very big clocks like ones in Railway stations


message:
Arduino voltage drop while communicating with another Arduino

I have an Arduino Uno rev 3 and an Arduino Nano in my Setup. I want to create a proof of concept, where one Arduino triggers the other via the Digital IOs.
Arduino 1 sets a blinking signal on a digital pin (500ms delay between high/low), which is received by arduino 2. If the signal is high, Arduino 2 triggers a LED (digital pin to LED+; LED- over 330 Ohm resistor to ground), so the signal gets looped through somehow. The grounds of the two Arduinos are connected, too.

![Schematic][1]

Code Arduino #1:

    void setup() {
      DDRD |=_BV(PD7); //Sets Digital Pin 7 as Output
    }

    void loop() {
     PORTD |=_BV(PD7); // equivalent with digitalWrite(7, HIGH);
     delay(500);
     PORTD &=~_BV(PD7); // equivalent with digitalWrite(7, LOW);
     delay(500);
    }

Code Arduino #2:

    void setup() {
      DDRD &=~_BV(PD7); //Sets Digital Pin 7 as Input
      DDRD |=_BV(PB0); //Set Digital Pin 8 as Output
    }

    bool set = false;

    void loop() {
      if((PIND&_BV(PD7))==_BV(PD7)) { //true if digital pin 7 is set
        if(!set) {
          //PORTB |= _BV(PB0);
          digitalWrite(8, HIGH);
          set = true;
        }
      } else {
        //PORTB &=~_BV(PB0);
          digitalWrite(8, LOW);
        set = false;
      }

    }

But instead of emitting a bright light, which can be seen if connecting the blinking signal directly to the LED, it emits a faint light. The voltmeter also shows an significant Voltage drop. Whilst the digital pin should have a voltage of ~5V when set to HIGH (never reached because of inner resitance inside the arduino), it measures about 1.6-1.8V.
I also switched the both Arduinos which showed the same result, so it shouldn't be a hardware defect.

Thanks in Advance!

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

body:
A couple of delays in the Arduido #2 if(!set) { } else { } might allow the LED to stay on long enough to be seen.

At the moment this is rapidly switching the LED whenever the digital pin7 is set.


body: the line `DDRD |=_BV(PB0);` should be `DDRB |=_BV(PB0);` currently PB0 is set as an input so when you set it high it is just turning on the pull-up resistor, which is basically adding another ~10k in series with the LED, hence the dim light.


message:
SoftSerial freezes on comparing getInt to int

I have a robot application on my Arduino which basically takes values from a SoftSerial instance on my 0/1 pins (connected to a Bluetooth board).

From the 'driver station' I send speed values to the Arduino through the aforementioned Bluetooth controller. The freezing happens when I compare the data (an integer) to a local integer (i.e 500). If I send the reverse command, I'm actually sending the int 500. If I compare my SoftSerial data like so:

    if(softSerial.parseInt() == 500)
    {
     //Reverse
    }else{
     //Forward
    }

it freezes. It only happens when I'm using my SoftSerial stack over Bluetooth, over USB it doesn't freeze. What are my options?

body:
There is no point in using SoftwareSerial on pins 0 and 1, as you have HardwareSerial for that. Whatever the sketch does once it starts will not affect whether or not it uploads. If you have something connected to pins 0 and 1, during the upload, that may well stop the upload working, but what the sketch does afterwards does not.

It is hard to tell from your snippet, but if you also have activated HardwareSerial - eg. `Serial.begin(9600);` - then the hardware takes over those two pins and SoftwareSerial won't work anyway.


message:
Questions Concerning Arduino Compatible Boards

I've seen an Arduino-compatible board called Bluno from DFRobot. I'm curious if a shield, specifically the DFRobot motor shield can be connected to the Bluno.

Can anyone confirm if it can be connected with a shield?

body: The Bluno is identical to the Uno, except the USB-to-serial chip, also supports BT. So it won't be a problem.


message:
Dallas Temperature Sensor DS18B20 not showing correct Result with Ethernet Shield

I am using Arduino Uno R3 board and a wiznet W5100 ethernet Shield. The temperature from the One wire sensors before using Ethernet Shield was showing correct. However later after connecting the shield, the temperature is showing to be 85. The server and everything else works fine, but the data is all wrong. Now I am pretty sure the connections are correct and it is not in parasite mode. Any suggestions of how I might get the accurate reading ?

    /*
      Web Server

      A simple web server that shows the value of the analog input pins.
      using an Arduino Wiznet Ethernet shield.

    */

    #include <SPI.h>
    #include <Ethernet.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>

    #define ONE_WIRE_BUS 2

    // Enter a MAC address and IP address for your controller below.
    // The IP address will be dependent on your local network:
    byte mac[] = {
                0xF0, 0xBF, 0x97, 0x67, 0xF6, 0x98
            };
    IPAddress ip(192, 168, XXX, XXX);

    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    EthernetServer server(80);

    void setup() {
        // Open serial communications and wait for port to open:
        Serial.begin(9600);
        sensors.begin();
        while (!Serial) {
            ; // wait for serial port to connect. Needed for Leonardo only
        }
        // start the Ethernet connection and the server:
        Ethernet.begin(mac, ip);
        server.begin();
        Serial.println(sensors.getTempCByIndex(0));
        Serial.print("Siddhartha Temperature ");
        Serial.print("server is at ");
        Serial.println(Ethernet.localIP());
    }

    void loop() {
        // listen for incoming clients
        EthernetClient client = server.available();
        if (client) {
            Serial.println("new client");
            // an http request ends with a blank line
            boolean currentLineIsBlank = true;
            while (client.connected()) {
                if (client.available()) {
                    char c = client.read();
                    Serial.write(c);
                    // if you've gotten to the end of the line (received a newline
                    // character) and the line is blank, the http request has ended,
                    // so you can send a reply
                    if (c == '\n' && currentLineIsBlank) {
                        // send a standard http response header
                        client.println("HTTP/1.1 200 OK");
                        client.println("Content-Type: text/html");
                        client.println("Connection: close");
                        client.println("Refresh: 2");
                        client.println();
                        client.println("<!DOCTYPE HTML>");
                        client.println("");
                        // output the value of each analog input pin
                        for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
                            float sensorReading = sensors.getTempCByIndex(0);
                            client.print("Temperature ");
                            client.print(analogChannel);
                            client.print(" is ");
                            client.print(sensorReading);
                            Serial.println(sensorReading);
                            client.println("
");
                        }
                        client.println("");
                        break;
                    }
                    if (c == '\n') {
                        // you're starting a new line
                        currentLineIsBlank = true;
                    }
                    else if (c != '\r') {
                        // you've gotten a character on the current line
                        currentLineIsBlank = false;
                    }
                }
            }
            // give the web browser time to receive the data
            delay(1);
            // close the connection:
            client.stop();
            Serial.println("client disconnected");
        }
    }

body: The Solution was actually much simpler. Apparently the Ground on the voltage I/O ports wasn't the right place to connect the ground terminal of the sensor. rather The Ground of the Digital I/O should be connected. Mistake retrieved by trail and error!! Its working just fine now.


message:
Overriding main function in Leonardo

I've trying to write my code in plain C++ dropping out the Arduino's IDE. Although I've succeed in compiling the code, whenever I try to upload it to the board it doesn't run, seems that it stucks at some unknown point.

After that, everytime I try to upload a new code to the board it stops responding and avrdude throws this message:

    $ ino upload -m leonardo -p /dev/ttyACM1
    /dev/ttyACM1 doesn't exist. Is Arduino connected?

It doesn't matter if I unplug and then plug again the board, that message is still showing up.

In order to restart the board, I open the Arduino IDE and then I upload any sketch, then the board comes to live again.

The first time I tried overriding the main() function and the program didn't run I thought it was the tool I was using at that moment, *arduino.mk*, the one that was doing something strange.

Then I tried the *ino* tool, but the result was the same.

I don't think *avrdude* is failing because it actually uploads the .hex to the board.

My original main() code was:

    #include <Arduino.h>

    const int LED_PIN = 13;

    int main(void)
    {
     pinMode(LED_PIN, OUTPUT);

     while (1)
     {
      digitalWrite(LED_PIN, HIGH);
      delay(100);
      digitalWrite(LED_PIN, LOW);
      delay(900);
     }
     return 0;
    }

Then I tried to mimic the one that comes with Arduino:

    #include <Arduino.h>

    const int LED_PIN = 13;

    int main(void)
    {
     pinMode(LED_PIN, OUTPUT);

    #if defined (USBCON)
     USBDevice.attach();
    #endif

     while (1)
     {
      digitalWrite(LED_PIN, HIGH);
      delay(100);
      digitalWrite(LED_PIN, LOW);
      delay(900);

      if (serialEventRun) serialEventRun();
     }
     return 0;
    }

Sadly, with both codes the board gets stucked at some point.

While I figure out how to solve this issue I've been exercising this solution inside a sketch:

    const int LED_PIN = 13;

    void setup() {
    }

    void loop() {
     pinMode(LED_PIN, OUTPUT);

     while (1)
     {
         digitalWrite(LED_PIN, HIGH);
         delay(100);
         digitalWrite(LED_PIN, LOW);
         delay(900);
     }
    }

Any ideas that led me to a solution? Thank you!

body:
**Solved!**

It was a (big) silly mistake of my own. I overloocked the init() function right after entering the main() function. I'm shure it initializes the hardware and the entire system, so my board stucks when I skipped it.

So my code now looks like this:

    #include <Arduino.h>

    const int LED_PIN = 13;

    int main(void)
    {
     init();

    #if defined (USBCON)
     USBDevice.attach();
    #endif

     pinMode(LED_PIN, OUTPUT);

     while (1)
     {

      digitalWrite(LED_PIN, HIGH);
      delay(100);
      digitalWrite(LED_PIN, LOW);
      delay(900);

      if (serialEventRun) serialEventRun();
     }

     return 0;
    }

BTW, the mix: Arduino + Vim + ino, rocks! Now I can do whatever I want from the console :)


message:
Not able to upload any code to Arduino Uno

NOTE: Using the Arduino Uno

I am WORKING on a project that I have to submit in a few days. My arduino was all set up and was working fine.

Project:Arduino controls a 9v motor depending on the command given. As the arduino only provides 5v , i added a 9v battery to it through a transistor

I decided to add new code into the arduino but when I tried it failed. I have uploaded code thousands of times before (successfully) all of a sudden the IDE keeps giving the following message

 >avrdude: ser_open(): can't open device "\\.\COM3": Access is denied.

I have looked up for a lot of solutions on this forum and elsewhere. Here are the things I have tried so far:

1. Changing the COM port
2. Disabling all the other devices CONNECTED to COM
3. Tightening the CONNECTIONS
4. Re installing all the drivers and the IDE
5. Rebooting the system
6. Using another laptop to upload code

All the above have given me the same output for some reason. The built in LED light and the power LED switch on when the board is CONNECTED to a power source (my laptop). Could the board have been damaged by any chance ? How can I check if the board is spoilt ? Should I buy a new board ?

body:
 1. Remove all device connect to uno, and upload code to uno. Because,
    your device like motor will confuse uno.
 2. Check you usb to serial device.
 3. Check your uno


body:
Have you tried changing the Microprocessor in the Arduino Uno?
An AtMega320P is much cheaper than new Arduino, and usually only the microprocessor gets spoilt, rest of the board remains intact.


body:
Check the device that the IDE says you're connected to.

http://forum.arduino.cc/index.php?topic=51489.0


body: Could be the OS not allowing the application to access the COM ports, there is a terminal command to give the Arduino IDE access to the specific COM port.


body: I have a post <https://arduino.stackexchange.com/questions/13292/have-i-bricked-my-arduino-uno-problems-with-uploading-to-board> - that describes various tests you can carry out to isolate where the problem is.


message:
Ultimate GPS Logger Shield : Soft Serial Sketch Error

Im using a OSEPP Uno R3 Plus to connect with a Ultimate GPS Logger Shield. I am currently working through the Adafruit Ultimate GPS Logger Shield pdf. When connecting in Soft Serial Mode and loading a parsing sketch. In the com window my values are showing but unreadable. I have included an image. Any help is appreciated.

![enter image description here][1]

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

body: jfpoilpret > My apologies for not including enough information and details. But your comments did lead to me resolving my issue. I did not change my baud rate to match the baud rate of the source code and the script is working now. Appreciated.


message:
How exactly is voltage measured on an Arduino?

*How do the analog pins on an Arduino measure voltage?*

Do they either measure current and calculate the voltage with Ohm's law? (If so, why can we only read voltage and not current directly?)

Or do they compare the unknown input voltage with a known internal one? (If so, how does that work? What's the known voltage?)

body:
Known voltage is usually provided by a diode or similar reference. The atmega328p chip has a separate aref pin so you can choose your own reference.

An ADC or analog to digital converter http://en.m.wikipedia.org/wiki/Analog-to-digital_converter is a collection of comparators. A comparator is a logic gate that simply tells which of two inputs has more voltage. This aref voltage is divided evenly into 2^10 values (it's a 10 bit ADC). Then the incoming signal is compared against all of these and the largest comparator which triggers is the reading you get in your arduino code.


body:
The Arduino uses a analog-to-digital converter. For instance on the Arduino Uno there is a 10-bit ADC. Therefore the resolution is 2^10 bits which is 1024 different representations. As the Uno runs at 5V, each step represents 4.9mV.

The actual inner workings of the ADC can be quite complex and I don't exactly know which specific type it uses, but there can be many ways. One example is measuring time to discharge of a known capacitor. Another is comparing the voltage to the running voltage and using a counter.


body:
The Arduino uses a 10 bit Analog to Digital Converter(ADC). A good ADC  is made such that it has only as many comparators as is the resolution of the ADC (in BITS) . Therefore the Arduino should have only ten comparators.

More detailed:

Comparator Number      Trigger voltage

        1.(LSB)..............................       (5/1024)V

        2........................................             (5/512)V

        3........................................(5/256)V

       ..........and so on till

        4.(MSB)..............................(5/2)V

So, for a voltage of say 2.75V, you will get a value of 768(11000000 in Binary)

Update:If you choose to give and use a separate Ref Voltage to the Arduino, It replaces the 5V with the new ref voltage.

Update 2: Sometimes a single comparator may be used in exchange of all 10 comparators.i.e., it is used to trigger all the bits .But the voltage at which each bit is triggered remains same.


body: I'm not sure what the answer is or why no one has addressed the second part of your question. To calculate current you need to know voltage and resistance (I=E/R). The ADC is giving you the voltage but I don't know what value to use for resistance in order to calculate the current. I do better with digital electronics but I suspect you might be able to use a resistor divider network to measure the voltage drop across a known resistor to measure current but do not take my word for this.


message:
TCCR1A and TCCR2A on Leonardo

I'm trying to use the [TTS library for Arduino][1] on an Arduino Micro board, which is based on the Leonardo. When I try to compile my sketch I get some errors;

 /libraries/TTS/TTS.cpp: In function 'void soundOff()':
 /libraries/TTS/TTS.cpp:355: error: 'TCCR2A' was not declared in this scope
 /libraries/TTS/TTS.cpp:355: error: 'COM2B1' was not declared in this scope
 /libraries/TTS/TTS.cpp: In function 'void soundOn()':
 /libraries/TTS/TTS.cpp:382: error: 'TCCR2A' was not declared in this scope
 /libraries/TTS/TTS.cpp:382: error: 'COM2B1' was not declared in this scope
 /libraries/TTS/TTS.cpp:382: error: 'WGM20' was not declared in this scope
 /libraries/TTS/TTS.cpp:383: error: 'TCCR2B' was not declared in this scope
 /libraries/TTS/TTS.cpp:383: error: 'CS20' was not declared in this scope
 /libraries/TTS/TTS.cpp:383: error: 'WGM22' was not declared in this scope
 /libraries/TTS/TTS.cpp:384: error: 'OCR2B' was not declared in this scope
 /libraries/TTS/TTS.cpp:385: error: 'TCNT2' was not declared in this scope
 /libraries/TTS/TTS.cpp: In function 'void sound(byte)':
 /libraries/TTS/TTS.cpp:424: error: 'OCR2B' was not declared in this scope
 /libraries/TTS/TTS.cpp:425: error: 'TCNT2' was not declared in this scope

Googling revealed that the Leonardo uses different timers. And other things I don't understand! But I couldn't piece together an answer beyond that.

What are the correct constants to use for Leonardo boards, and is there a way I can update the library to work across both?

  [1]: https://github.com/jscrane/TTS

body:
Apparently the library in [the OP's link][1] has been updated to support the Leonardo, so this problem should now be solved.

  [1]: https://github.com/jscrane/TTS


message:
MP3 Shield stacked on DMX Shield - Arduino Uno

We are using Arduino Uno revision 3, with TinkerKit DMX Shield rev. 4 and Sparkfun Mp3 Shield.

We uploaded the Mp3 Shield example called FilePlayer and after we open the serial monitor, the interface is there and working. The problem is that it won't output the music from the SD card.

If we ONLY stack the Mp3 Shield onto Arduino, it works.

Is there some king od incompatibility between the DMX and Mp3 Shield, and if there is, what would be the solution, maybe some kind of bypass, since we aren't that familiar with what pins the DMX shield uses for it's purpose. ATM the Tinkerit site is down so we can't acess the TinkerKit DMX Shield datasheet.

body:
Yes, overlapping is a problem, by default the MP3 Shield uses digital pins 2(DREQ),6(mp3CS),7(mp3DCS),8(RST),9(SD-CS),11(MOSI),12(MISO),13(SCK)

The Tinkerkit DMX Master Shield R4 uses 2(RE-ENn),3(VTX),4(VRX),5(DE-EN),6(D6)

So there are conflicts with D2 DREQ vs RE-ENn and D6 mp3CS vs D6.

The DMX Master Shield basically converts the UNO's serial to DMX. If nothing is at first included into the Sketch for this, then the problem is with only D6. Leave this jumper OFF. And I suspect the MP3 Shield will work stacked.

To use them together you can move the pins, as demonstrated at https://www.youtube.com/watch?v=behMgV3tUr4. Noting that is for different pins. And of course you will need to subsequently change their definition, in the sketch.


message:
Modify the call stack of interrupts on Arduino

I'm working with Arduino's libraries. And my interest in the possibility to change the call stack of the SPI interrupt, this because I want: after the interrupt happen, the program could jump to other function and not to the interrupted address.

I mean:
This is the Main code.

    void loop ()
    {
        func();
    }

    void func()
    {
       // code
       // here happens the ISR interrupt
    }

ISR happens inside `func()`

    ISR(SPI_STC_vect)
    {
        // code
        // SPDR = 0x00; // MY ANSWER to SPI
        // MODIFY CALL STACK TO GO TO LOOP()
    }

**Now, after answering the SPI, I want to go back to `loop()` instead of continue `func()`.**

**How can I do this?**

Thanks for your help.

body:
Arduino is open source, so just modify the ISR to set a global flag when ran. Within func() just check for this flag and return when the condition is met. Little can be offered as little contextual information is given. To modify the stack you would have to work with avr assembly, but either way you must modify the ISR

Something like the following would work, but performance depends heavily on your application.

    #define SPI_ISR_RAN 0x00
    static volatile uint8_t flagByte;

    void loop(){
        func();
    }

    void func(){
        uint8_t indicator;
        do {
            // Do something

            //Check for SPI condition
            ATOMIC_BLOCK(ATOMIC_RESTORESTATE){ //Atomic access is required
                indicator = flagByte;
            }
        }while( !(indicator & 1<<SPI_ISR_RAN) );

        ATOMIC_BLOCK(ATOMIC_RESTORESTATE){
            flagByte &= ~(1<<SPI_ISR_RAN); //Don't forget to clear the flag!
        }
    }

    ISR(SPI_STC_vect){
        // Do ISR necessities

        // Set flag when appropriate
        flagByte & 1<<SPI_ISR_RAN;
    }


body:
You can achieve almost what you are describing with the `setjmp()` and
`longjmp()` functions. Here is an example, using INT0 to interrupt a
function calling `delay()`:

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

    /*
     * Test non local return from ISR:
     *   - wire a pushbutton between digital 2 and GND
     *   - monitor the serial port at 9600/8N1
     *   - pressing the button should skip "func() ending" and immediately
     *     write "func() returned"
     */

    #include <setjmp.h>

    jmp_buf saved_context;

    /*
     * ISR triggered by low level of INT0 = PD2 = Arduino digital 2.
     * Should only be allowed to trigger while inside loop().
     */
    ISR(INT0_vect) {
        EIMSK &= ~_BV(INT0);        // disable further interrupts
        longjmp(saved_context, 1);  // return to loop()
    }

    void func() {
        Serial.println("  func() beginning");
        EIMSK |= _BV(INT0);   // enable INT0 interrupt
        delay(3e3);           // wait 3 s for an interrupt
        EIMSK &= ~_BV(INT0);  // disable INT0 interrupt
        Serial.println("  func() ending");
    }

    void setup() {
        pinMode(2, INPUT_PULLUP);  // pin 2 is INT0
        Serial.begin(9600);
    }

    void loop() {
        Serial.println("Calling func()");
        if (setjmp(saved_context) == 0) func();
        Serial.println("func() returned");
        Serial.println();
        delay(2e3);
    }


body:
> Now, after answering the SPI, I want to go back to loop() instead of continue func().

This is an extremely bad idea, and not what ISRs are for.

It is all very well wanting to go back to loop, but you would also have to discard whatever is on the stack, since loop started. The suggested method of using `setjmp` / `longjmp` may possibly achieve that, but almost certainly you are doing this for the wrong reason.

Jumping back to `loop` is like saying:

* I don't care what was happening when the interrupt occurred
* I don't care if it is half-way through sending some message
* I don't care if it is half-way through turning on or off some device

In addition to this memory which was allocated (eg. by String objects) might not be freed. In fact the interrupt might occur during memory allocation in which case variables used by the memory allocation routine could be in an indeterminate state.

I strongly disagree with any suggested work-arounds. You simply should not be "jumping out of" an ISR and going somewhere else. Re-think the design.


message:
EEPROM value reverting to 255

When I write '13' to the EEPROM and read it straight after it works correctly.

However when I comment out the write part of the code and try to just read the data, the value is no longer 13 as it used to be but reverts back to 255. Whats going on?

I am running a standalone atmega328 on a breadboard with a 16mhz crystal, programmed by a Nano R3.

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

    //EEPROM.write(1,13);
    }

    void loop() {
    scoreBinary();

    }

    void scoreBinary(){

    int score= EEPROM.read(1);

    if(score==13){
    digitalWrite(2,HIGH);
    }
    delay(10000);
    }

body: By default the EEPROM in the MCU is erased (to 0xff) when the chip is erased before flash is written to. If you want to prevent this then you will need to program EESAVE in the fuse bits, which is bit 3 in the high fuse byte of the '328.


message:
Communicate with custom usb slave device with DUE?

I have a arduino due which i know has usb host mode. The usb library that comes with the due supports mouse and keyboard.

I have another usb device (diacnostic tool) id like to talk to, it use a:
USB Com Board Driver ( Multi-instance )
TI USBN9604
"Universal Serial Bus Full Speed Node Controller with
Enhanced DMA Support"
datasheet: www.ti.com/lit/ds/symlink/usbn9603.pdf

Ive also logged the raw byte usb traffic between windows and it when operating and would like to try sending some of those same calls to the device with the due.

Where do i start ?

Example Capture:

        000000: PnP Event: Device Connected (UP), 12.04.2015 09:14:51.390 (1. Device: USB Com Board Driver ( Multi-instance ))
    The USB device has just been connected to the system.
    000001: Bulk or Interrupt Transfer (DOWN), 12.04.2015 09:15:14.953 +23.562 (1. Device: USB Com Board Driver ( Multi-instance ))
    Pipe Handle: 0x8639885c (Endpoint Address: 0x6)
    Send 0x1b bytes to the device
     40 05 17 C0 00 09 02 00 AA 00 00 00 00 00 00 00
     00 00 00 00 00 00 00 00 16 06 12

body:
i found what i needed here: http://arduino.cc/en/Reference/USBHost
and
https://github.com/felis/USB_Host_Shield_2.0


message:
float precision in arduino

I am reading a string which i have to convert into a float with a maximum of precision.I didn't want to use toFloat() function since it make a truncation so i made my own code.
My problem is that the final result is also approximated.
I need a precision of 4 digits after the float.I read the documentation about float in the arduino website.They say it should be maximum 7 digits of precision but i don't get it.When i test my code on the value of '23,459' ,all i get is 23,46.
Any suggestions?

    void setup() {

     Serial.begin(9600);

    }
    int longu=0;
    char data='2';
      String data2="23,459";
      float val=0;
      int posVir=0;
      int t=0;
      float postVir=0;
      float preVir=0;
      int lonPostVir=0;
      int lonPreVir=0;
      float posvir2=0;
      void loop()
    {

       lonPostVir=(data2.substring(posVir+1)).length();
       lonPreVir=(data2.substring(0,posVir)).length();

       longu=data2.length();
       posVir=data2.indexOf(",");
       preVir=(data2.substring(0,posVir)).toFloat();
       postVir=(data2.substring(posVir+1)).toFloat();
       posvir2=postVir*pow(10,-lonPostVir);
       val=preVir+postVir*pow(10,-lonPostVir);

      Serial.println(val);

        }

body:
The simplest way to get more decimal places to print is this:

    Serial.println(val,NUMBER_OF_DECMIAL_PLACES);

This will print out any number of digits after the decimal place. Regular print without the number of digits specified will default to 2 decimal places. for example, here is some code and the result that gets printed:

    float val = 23.459;
    Serial.println(val);
    Serial.println(val, 4);
    Serial.println(val, 10);

> 23.46
>
> 23.4590
>
> 23.4589996337

You may notice that with 10 decimal places printed you can start to see how much the actual value of 23.459 needs to be approximated to fit within a floating point number. This is similar to how 1/3 can not be represented 100% accurately in a finite number of decimal digits; 459/1000 cannot be represented 100% accurately in a finite number of binary bits, so it is approximated.

Also, note that for non-floating point numbers the optional second argument to `print` and `println` is the base it should be printed in (dec, hex, oct, ...) and has nothing to do with precision.


body:
Just write the amount of numbers you want to get float here Serial.println(val); after the val.
example:
Serial.println(val, 5);
It will give 5 digits after the decimal point


message:
How to make universal remote controller?

I am trying to make simple TV remote using Arduino.

I got [this](http://www.zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/) link from Google for making a remote.

Code uploaded perfectly on my device. But all it does is blink a the LED on pin 13.

I hope I have got right code. I have tested it on my TV at home. Is that the correct way of testing it?

IR receiver I have is TSOP-15

P.S. I am completely new to Arduino

The below shown is my Arduino board(induino r3)

![enter image description here][1]

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

body:
As you've stated in your question, the TSOP-15 is a receiver. That means it detects infrared signals rather than sending them out.

To make a remote control with that code, you need a simple infrared light emitting diode.

It's also important to note that you need to know what signals to send. Different TVs will have different IR codes, depending on the manufacturer. That information can be detected using your receiver module along with your TV's proper remote control.


message:
Getting started

so I am not a newbie to computers or programming. I regularly program in C# and Java, know quite a bit about computer hardware and operating systems. But I am bored of writing stupid calculators or game bots. I want something exciting and something that involves physical hardware. So I want to get into electronics and micro-controllers. I was wondering how I should go about this? Any topics I should read first? How electrics work maybe? Any guides I should skim over? I plan to buy the Arduino starter kit and a load of components, along with a soldering iron etc soon; but want to get reading now. I do not need to go right into the advanced stuff but I like to know how things work before I use them; not just "plug this wire here to do this". Any help is much appreciated.

body:
A quick search on Amazon found a number of basic books on electronics. I'm not familiar with any of them to recommend one of them. But "plug this wire here to do this" isn't a bad way to start - you'll probably have some questions about what this component is for or why they had you connect it the way they did. That will give an immediate direction to your studying which in turn will bring in some more questions and more information.

If you really want some basics ahead of time (noting that I don't know what will be basic for you), you might search for Ohm's Law (voltage and current through a resistor), and Kirchoff's Laws (voltage and current in electric circuits), and follow any leads that look interesting. Look up some common components that you'd find in a starter kit, like resistors, capacitors, and LEDs. But things will begin to get "real" for you once you have parts in hand and start using them to make some basic stuff like making lights blink or fade, motors turn, and buzzers buzz.


body:
The best way to get started is surely by reading a book, I would recommend

 - [Getting Started with Arduino][1]
 - [Exploring Arduino][2]

Besides, there are many tutorials on YouTube also to start with.

But books are just one thing. Arduino or electronics is more about getting a hands on experience. Even if you have read a hundred times on how to blink a LED it is difficult to do it when doing it on hardware. So the best thing for you is to work with small small codes.

Say initially just blinking a LED(thats like the HelloWorld of electronics) and then moving on two patterns with LED. As you get used to the IDE and the hardware move on to more challenging projects like simple DC motor control or servo control. Try and make your own projects with your imagination. The challenges which you face teaches you more than any book. Then move on to serial and wireless communication and try working with a few sensors on the ADC and start making small projects.

  [1]: http://www.amazon.com/Getting-Started-Arduino-Make-Projects/dp/B008SMKPW0
  [2]: http://www.amazon.com/gp/product/1118549368?ie=UTF8&camp=213733&creative=393185&creativeASIN=1118549368&linkCode=shr&tag=jeremybcom-20&creativeASIN=1118549368


message:
Arduino Uno + 2 Monster Motor Shields

I've got an Arduino Uno and two Sparkun's Monster Motor Shields.
The aim is to control 4 motors.

There is no problem to control 2 DC motors with single motor shield. There's a [manual](https://www.sparkfun.com/products/10182) on how to do it .

But how can I control all of motors (address commands to each of them) when I stack motor shields one on one?

Thanks in advance.

body:
Not really the answer to your question, but an alternative solution, which has proven to work in my case.
We were working on a line-following robot with an ATMega 328P (Same as arduino, but withouth shields) and thus we wired an shield directly. For the shield we used, we only needed 4 inputs (pwm left, pwm right, direction left, direction right). Try to find out what your shield is using, on which pin, and you can drive the shield directly withouth stacking them (as they then would use the same pin).

----------
My alternative solution would be to use 1 driver. And wire the motors parrallel.
If you choose to use 1 shield, you can stack it. But for other shields you have to check which pins to use. There is no drawback on using one shield, the only thing is that the motor driver will draw more current, but they're basically designed for this.
![motor driver schematic][1]

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


message:
Can I connect a PWM pin on one Arduino to an analog input on another?

I was considering several different ways to send simple data from one Arduino to another when I though, why not connect a PWN pin of one Arduino to the analog pin on another?  I could send simple messages for one to the other by setting different values on the PWM pin.  This seems like it would work, except for the fact the the PWM pins mimic voltages with pulses.

Is this a reliable way to link two Arduinos, If I only want to communicate 4 states?  Also, will I need to include some additional components in the connection (resister, capacitor, etc.)

All it needs to do is send a 2v pulse for yes and a 5 v pulse for no. It needs to do this about 6 times an hour.

body:
It is possible, but not the best idea. The analog inputs require a reasonably stable input - this can be achieved with a RC filter to smooth the PWM output. This would work for reasonably slow data rates.

You would be better to use one of the many communication protocols supported by Arduino (serial, SPI, I²C).


body:
Yes, you can do this with "a little programming"  or more easily by adding two cheap components.

If you connect a say 47k resistor from PWM_Out to Analog_In and a say 100 uF capacitor from Anaolg_In to ground you will be able to read the equivalent analog value to an accuracy of around 1%. Read it N times (maybe 10 times) with a delay of say 12 ms between reads and average it for a better result. This works because the PWM period is **about** 1 mS so delaying for a period of multiple cycles but not an exact multiple means you sample semi randomly.

For the sort of resolution that you want (4 levels) a MUCH smaller capacitor could be used (maybe 1 uF.) But even a 100 uF capacitor is cheap.

You could instead use PWM out (analogWrite) and a digitalRead.
Perform say 100 digital reads with say 12 ms between reads (so about 1.2 seconds total) and keep two counts - PinWasHigh and PinWasLow for (obviously) high or low conditions. The contents of PinWasHigh tells you what % of reads was high. Due to random sampling you cannot rely on this for 100 levels but determining say 10 levels should give good accuracy. The sum of PinWasHigh and PinWasLow should total 100 as a sanity check.

While use of a serial port (hardware or software) or SPI allows more data transfer per time and without much effort, this simple analog method is good enough for many applications.


body:
For greater precision, less code, faster execution and no need for capacitors read the PWM "analog" signal on the other Arduino from a **digital input** pin with

`pulseIn(pin, HIGH, timeout)`

The timeout is optional (1 second by default). As soon as the line goes high, a timer engages and automatically stops the instant the line goes low.

The primary reason to use PWM communcation (as opposed to i2c, SPI, etc.) is to broadcast to an unlimited number of devices simultaneously without the need for a clock signal or acknowledgement.

We are currently using this method of communication for neural networks composed of separate tiny processors for each neuron substructure (one processor for each synapse and activation function).


body:
Full solution to receive **PWM** signal and convert **to** a like **analogRead()** one. Its based on @Cortex_systems answer and Id like to share it to help others with a more comprehensive answer.

    int var = pulseIn(digitalPin, HIGH, 4200);
    if (var == 0 && digitalRead(digitalPin) == 1) {
        var = 2100;
    }
    var= map(var, 0, 2100, 0, 1023);
Here is the why:

 - You can not just read PWM signal to analog pin in arduino. We will
   receive the PWM in a digital pin with its *pinMode set to input* and read it with pulsIn(pinNum, high/low, timeout).
 - pulseIn() records the length of the pulse. Longest pulse in PWM is 2100 microseconds.
 - Timeout is set to 4200 for 2 cycles of PWM. Without this
   it will wait for a new high and freeze the code in cases that PWM is
   0 or 255.
 - At max and min this will read 0, so in that case check with digitalRead() to determine and adjust.
 - Finally, map the result so it appears like an analogRead().

Note! This adds a delay of up to 4.2 milliseconds to code.


message:
Memory Problems on Arduino Uno

I am doing a project using Arduino UNO, cc3000 WIFI chip, micro SD card shield, and a TTL serial camera in order to make a security system that will post a picture online (not enough processing power for video) when motion is detected on the camera.

Thankfully, the hardware works after a few shortcomings, but my program seems to be taking up 97% of the Flash storage.

Also, I am looking for a better way to transfer the image than saving it 32 bits at a time and then waiting about 10 sec so the HTTP request will send it to the server.

One thing I do know is that I have tested all the hardware and those functions are working. My problem is in the logic.

Any help appreciated! (Image is around 13KB and UNO only has 2kb of dynamic memory).

My full code is here: [https://www.dropbox.com/s/arxa253mxwvqtg1/HomeProj.rtf?dl=0][1]

    void loop(void)
    {
        cam.setMotionDetect(true);

        while (1) {
            if (cam.motionDetected()) {
                Serial.println("Motion!");

                cam.setMotionDetect(false);
                if (! cam.takePicture())
                    Serial.println("Failed to snap!");
                else
                    Serial.println("Picture taken!");

                uint16_t jpglen = cam.frameLength();
                Serial.print(jpglen, DEC);
                Serial.println(" byte image");

                char filename[13];
                strcpy(filename, "IMAGE00.JPG");
                for (int i = 0; i < 100; i++) {
                    filename[5] = '0' + i/10;
                    filename[6] = '0' + i;
                    // create if does not exist, do not open existing, write, sync after write
                    if (! SD.exists(filename)) {
                        break;
                    }
                }

                File imgFile = SD.open(filename, FILE_WRITE);
                while(jpglen > 0) {
                    uint8_t *buffer;
                    uint8_t bytesToRead = min(32, jpglen);
                    buffer = cam.readPicture(bytesToRead);
                    imgFile.write(buffer, bytesToRead);

                    //Send Request
                    Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
                    if (client.connected()) {
                        Serial.println("Connected!");
                        client.println("POST /upload HTTP/1.0");
                        client.println("From: Arduino");
                        client.println("Host: fierce-chamber-5675.herokuapp.com");
                        client.println("Content-Type: image/jpeg");
                        client.println("Content-Length: " + 32);
                        client.print("Connection: close");
                        client.println();
                        for(int i = 0; i < 32; i++) {
                            client.print(buffer[i], HEX);
                        }
                        client.println();
                    } else {
                        Serial.println(F("Connection failed"));
                        return;
                    }
                    client.close();

                    Serial.println(F("-------------------------------------"));
                    jpglen -= bytesToRead;
                }
                imgFile.close();
                cam.resumeVideo();
                cam.setMotionDetect(true);
            }
        }
    }

  [1]: https://www.dropbox.com/s/arxa253mxwvqtg1/HomeProj.rtf?dl=0

body:
You are running a wireless TCP stack, an SD card interface, and a web camera with some sort of motion detection, on a less than $20 computer?  I think you should congratulate yourself and move on to the next project.

I believe you are asking too much to add more to it. At $20 a pop, I would think about adding another UNO if you really do want to add more functionality. Let the 2 talk via serial, with one processing the video, the other processing the wireless.  The TCP part uses a considerable amount of resources, both memory and processing power.


message:
Problems with L293D

![L293D Connection.. Pin refers to pin of the Arduino][1]

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

The motor are not rotating in the above circuit . Or rather the Voltage between the two Motor Terminal is zero. I have checked the Pin 10 & 11 and Pin 12 & 13. They are fine and produces desired Voltage.

When I have earlier connected the circuit only to one motor then it worked[ there were no motor right, Pin 12 and Pin 13]. But now, it's not.

What's the problem? The code in the arduino is as follows:

    const int echo = 7;// connected to ultrasonic sensor's echo
    const int trig = 8;// connected to ultrasonic sensor's trig
    const int Right1 = 10;
    const int Right2 = 11;
    const int Left1 = 12;
    const int Left2 = 13;
    void setup() {
      pinMode(echo, INPUT_PULLUP);
      pinMode(trig, OUTPUT);
      pinMode(Right1, OUTPUT);
      pinMode(Right2, OUTPUT);
      pinMode(Left1, OUTPUT);
      pinMode(Left2, OUTPUT);
      Serial.begin(9600);
    }

    void loop() {
      digitalWrite(trig, LOW);
      delayMicroseconds(2);
      digitalWrite(trig, HIGH);
      delayMicroseconds(5);
      digitalWrite(trig, LOW);
      int duration = pulseIn(echo, HIGH);
      int cm = microsecondsToCentimeters(duration);
      if (cm > 4)
      {
        digitalWrite(Right1, HIGH);
        digitalWrite(Right2, LOW);
        digitalWrite(Left1, HIGH);
        digitalWrite(Left2, LOW);
      }
      else
      {
        digitalWrite(Right2, HIGH);
        digitalWrite(Right1, LOW);
        digitalWrite(Left1, LOW);
        digitalWrite(Left2, HIGH);
      }
      delay(50);
      Serial.println(cm);
    }
    long microsecondsToCentimeters(long microseconds)
    {
      return microseconds / 29 / 2;
    }

body:
Try these steps

1. Increase the delay of 50ms to a longer time.

If that fails to work try,

2.Running the motor by just directly connecting the terminal to the 9V battery which you are using.

If the motor runs then most probably the motor requires more current than what the L293D can output which as per the data sheet is 600mA. A solution to this would be using a higher current motor driver like L298N.

If the motor doesn't run directly by the battery then well change the battery to one which can supply enough current.


message:
General Question about fast Serial Communication and Arduino

I'm looking for a fast (and safe, in terms of stability) way to send sensor data from an Arduino UnoR3 in real time to a Computer (in my case a MacBook Pro) with a sample rate of at least 1kHz.

I tried following:

- Sending sensor values with the related timestamp (in microseconds):
I use 7 bytes for each sample [1 Header byte, 2 bytes for the sensor value (10/(16)bit-Int), and 4 bytes for a 32-bit unsigned long (time in microseconds)] and send them right away.

- On the receiving end i mainly use Processing (Im relatively new to Processing though): Reading the bytes in, converting them in integers and safe them in a file or plot them.

For sampling rates of 1sample/10ms my code runs smooth and i even can plot the data in "real-time".

For higher frequencies i ran into following problems:

- If i want to plot things, my peripherals freeze and program stops after some time. I have no clue why... maybe serial buffer overflow??

- If i just save the data in a text file (without plotting) it works but with a delay of around 20-30seconds on total sampling times of 10seconds (10000 samples).
Meaning that somewhere seems to be a bottleneck and i cant keep up with the sent samples from the Arduino.
Is it possible that the serial bus is the bottleneck here? How can i speed things up? (I'm working with a baudrate 115200bits/s and also 230400bits/s)

How can i improve this while still be able to process data in almost real-time (e.g plotting). Is this even possible or do you recommend logging the data in a text file first and then plot?

Will it helps to send the data in packages (10samles = 70bytes)?

I added a timestamp on each sample, since i observed some delay between the actual sensor measurement and the input on the receiving end. I thought that would allow me to plot and postprocess accurately in "real"-time (with a little delay). Any other ideas?

I would appreciate some input and advice!

Thanks in advance!

body:
You are sending data at ~70kbps. Provided you use serial rate greater than this (115.2 kbps or faster on the Arduino) there should be no problem, assuming you samples are processed quickly enough. This seems to be the case.

Your problem seems to be on the Mac. With a quad core CPU on a fast multitasking machine this should not be an issue. If you are having problems this would be in how you are processing the data. I am not familiar with `Processing` but you could do this in any language. You need to separate the data logging from the processing and display task. This could be as simple as running a logger and piping the data into a display program.

This is not an Arduino issue (or even a Mac issue), you should ask on https://stackoverflow.com/. NOTE if you want help there you will need to give more detail of the code you are running in the Mac.


message:
How to send the MFRC522 RFID module into sleep mode?

I'm trying to get the power consumption of a MFRC522 RFID module down, currently while running it consumes about 4mA. There should be a way to put it into sleep mode, I just can't find any documentation on it. I'm using the module with a arduino currently if that helps; and this is the module itself : [MFRC522][1]

  [1]: http://www.amazon.com/SunFounder-Mifare-Antenna-Proximity-Arduino/dp/B00E0ODLWQ/ref=pd_cp_p_1

body:
http://www.nxp.com/documents/data_sheet/MFRC522.pdf

Look at section `8.6.2   Soft power-down mode`.


message:
Infra Red Send Hex Code

I am using an arduino nano with the standard arduino IR remote library. For now I am using the Irrecord sketch. However, I want to have some pre - programed codes for remotes I don't have. I found this [site][1] which apparently has the hex of an endless number of remotes. When I use the regular IR decode, the hex of any remote I use, is only a couple of characters.  However at this site the typical amount is at least 100.

This is the hex for a Toshiba model's sleep command:

0000 006c 0022 0002 0157 00ab 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0040 0016 0016 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0016 0016 0040 0016 0040 0016 0016 0016 0040 0016 0016 0016 0040 0016 0016 0016 0016 0016 0016 0016 0016 0016 0040 0016 0016 0016 0040 0016 0016 0016 0040 0016 0040 0016 0040 0016 05f0 0157 0055 0016 0e52

So, finally after all that if you are still with me my question is, how would I send that command with the IRRemote library.

  [1]: http://www.remotecentral.com/cgi-bin/codes/

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


message:
How to learn enough C++ to program Arduino?

I am an experienced web developer, but my C++ skills are very basic. I struggle with the concepts because it is so different from something like Javascript (which I already know). I do not have a lot of time to learn C++, and I only need to know enough to play with Arduinos.

Are there any good resources out there for learning C++ that is specifically geared towards Arduino programming, and is there anything interactive like [Codecademy][1]?

  [1]: http://codecademy.com

body:
Since you have programming experience and you say you only want to learn enough to play with Arduinos, I think a resource worth mentioning is the built-in example programs. I've seen Arduino itself used as a learning tool for C/C++; their examples are very basic and intended for complete novices. If you keep hacking on progressively more complicated examples and googling specific things you don't understand, you will probably be able to get a good handle on things IMHO.

That isn't to say it's necessarily a good tool for learning C++ in general, since the limited memory resources and 8-bit CPU make some capabilities of the language commonly used on desktops (and the whole standard library) rarely used or unavailable on Arduino.


body:
If I were you I'd take the high road.

I was in your shoes a while ago and I didn't know how to approach Arduino. I was very lucky that I came across a book written by the famous Jack Purdum, "Learn C programming for the Arduino". It is written by a retired Purdue University professor who is well known for his extremely easy to learn teaching method. He has another

I only knew MATLAB and Simulink before starting this book. This book is amazing. It was extremely easy to follow. I now have no difficulty programming Arduino in the correct way. This book trains you to optimize everything which is very crucial with the limited resources on Arduino boards.

I suggest C instead of C++. It is the language of choice for programming embedded system. It is said to be low level, but as a MATLAB user I should tell you that syntaxes are extremely easy and intuitive. I didn't find anything hard about them.

Remember:

1. There isn't any problem to use C in Arduino IDE.

2. You don't need to worry about libraries. You only need to load them in the beginning of the code. You do not need to know how was the code written in the library.

3. Check the comments about the book on Amazon if you are not convinced.

Good Luck


body:
Another way to approach the problem is to come up with a project that you want to do with an Arduino and look for code samples.  Since you already have some programming experience you should be able to pick up what's going on pretty quickly and you will have a vested interest in what the code is doing.

For Example: [Read temperature from a sensor][1] and [display to an LCD][2].

Arduinos are really good for reading from a sensor and there's a huge arduino community.  So, if you start with just reading from different types of sensors you'll find a lot of examples and learn a lot about Arduinos at the same time.

  [1]: https://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor
  [2]: https://learn.adafruit.com/character-lcds


body: A very good book: Beginning C for Arduino:Learn C Programming for the Arduino, by Ph.D. , Jack Purdum


body:
[Beginning C for Arduino:Learn C Programming for the Arduino, by Ph.D. , Jack Purdum][1]

  [1]: http://www.lakos.fs.uni-lj.si/images/Predmeti/MK/2014/Beginning C for Arduino.pdf