text:
Reading a varying voltage into Arduino
Using an Arduino Nano and a current transformer  (CT), I'm trying to sense the current flowing through a 120 V 60 Hz line.
Circuit
CT outputs 0-1 V according to its specifications. This output is biased AREF/2 = 2.5 V.

analogRead Values
The x-axis represents the index number of the ADC sample, while the y-axis represent the ADC value (0-1024). Sampling rate is about 9 kHz. Peak-to-peak difference is about 1026 samples.

Is this waveform what you would expect from the CT? Why are there regions where the values are flat, rather than varying continuously?
Furthermore, if we look at the curve part of the plot, why is Arduino reading values both above 512 and below 512 alternately? It reads a value above 512, then a value below 512, then a value above 512 and so on.
Time taken for an analogRead was measured to be 110 microseconds for my setup and there are 1026 samples between the waveform peaks. That means there will be about 9 peaks in 1 second, although I would expect 60 peaks since we are sensing a 60 Hz line. What do you make out of this? There's a capacitor, C1, in the circuit, would it have anything to do with this?
Are these analogRead values suitable to be used to calculate the RMS voltage, and hence the RMS current passing through the wire being sensed? The final goal of this is to calculate the power usage after determining the RMS current flowing through the wire.
Sketch used to get values for plot
void setup() {
    Serial.begin(9600);
}

void loop() {
   double sensorValue = analogRead(1);
   Serial.println(sensorValue)
}

Actual analogRead data points in the bump regions
487
534
487
535
488
537
484
536
487
538
486
536
484
540
484
539
485
540
483
540
484
541
481
539
481
540
484
540
480
543
484
539
481
540
484
541
486
542
485
538
485
538
488
535
489
534
491
530
491
529
493
531
492
526
498
526
499
524
499
520
503
518
502
518
507

Plot of analogRead values
The analogRead values are now stored in a buffer before being transmitted over Serial. There are now 55 ADC datapoints making up 1 period. Considering the analogRead time is 110 µs, each cycle takes 6.05 ms, giving us a frequency of 165 Hz! What may have gone wrong?

void loop() {
    double sensorValue = analogRead(1);
    char buf[32];

    dtostrf(sensorValue, 8, 2, buf);
    value = buf;

    if (stop == 0) {
        if (i < 10000) {
            message += ',';
            message += value;
            i++;
        }
        else {
            stop = 1;
            Serial.println(message);
        }
    }
}

Can you post your code? This doesn't look right at all. When you say "Assuming that 100ms passes", why do we assume that?

@Cybergibbons Posted the code used to generate values for the plot. Sorry, I've just measured the time taken for an analogRead() and found it to be 110 microseconds. Updated the question.

What is the load you are using for the mains. Ideally you want something fairly stable like an incandescent bulb. If you have something complex like a laptop switchmode power supply which may have a varying load you might expect a complex result.

The bulk of the time in the loop will be spent sending serial at 9600bps. You will only shift 960 char/s i.e. each reading takes 4ms.

@Salixalba The load is a desktop computer with a switching power supply. I will try measuring a different load, such as a heater.

Looking at a plot of the data, you might be seeing beat frequency from two very close frequencies possibly 60Hz and 61Hz.

@Cybergibbons Thanks for the hint. Now I'm storing the analogRead values in a buffer before sending it over Serial. Updated the question with the new plot. The ferquency is now 165Hz!

@Salixalba Updated question with a plot that's probably more accurate, changed based on suggestion by Cybergibbons. What would the interpretation of the plot be now?

Maybe it is a switch mode device which is drawing current only part of the time. The first 25 ticks no current, then its switched on for 7 tick, off for 25 tick, on for 7 ticks.

It might actually be quite a clever device, timing its on and off states to coincide with the cycles in the mains and balancing things so you get a top half of a cycle and a bottom half of a cycle. In effect its switched so its drawing current 1/5 of the time. Try doing some heavy processing with 100% CPU and see what happens.

A switch mode power supply is a bad place to start. Use a purely resistive load to see if things are working.

My experience with using Serial.println at a baud rate of 9600 is that each output is about 10 milliseconds. This is too great for the first plot to work. Kick the baud rate up to 115200 and see what you get.

Regarding your measurements, I would completely disregard the first set with Serial.println() in the loop. I would exepect the timing of this to be unreliable.
Your second set of data that you captured in a buffer looks correct, but your Frequency Estimation / timing may be wrong. I would invert a Digital Output at each loop iteration. You can measure the frequency of that with a Multimeter and your ADC sample rate would be twice that value.
For a PC or laptop power supply that's quite a common current waveform.
Without effective Power Factor Correction the current signal shown below would be quite typical (source: http://www.nlvocables.com/blog/?p=300)

You will need to calculate RMS values and it would be wise to filter the signal.
Here's an instructable I wrote on how to build and code an Arduino Yun based Electricity Monitor with Cloud Support / Temboo and Google Drive. It should be of some help to you.

Thank you! The CT you've used outputs -1V to 1V. To make use of the 10 bit ADC, will you amplify the SCT output by 2.5 using an opamp? Or set your AREF to 2V and bias your CT signal by 1V

No I did not amplify it or change the Aref.

How could you get this graph plot? With what software?

if you are measuring a resistive load I would say that the burden resistor you have chosen is wrong, there are some cheap CT's on ebay (SCT-013-xxx) that have versions with and without the burden resistors, these work well for their price but you must read the datasheet. the SCT-013-000 requires a 20R resistor to get 1V out with a 100A load, if this resistor is wrong you can get a severely distorted waveform when measuring higher currents (similar to those you have provided), you would expect the signal to distort more the lower the burden resistor value but this is not the case with CT's.


text:
Pressure transducer / sensor (0.5 - 4.5V) innacurate analog pin readings
I have a relatively cheap 0-15psi pressure transducer. It has 3 pins - ground 5V and signal. The signal outputs a voltage of 0.5V to 4.5V based on pressure from 0psi to 15psi. I can verify it does respond to significant pressure increases so it works at least to a point.
The issue is that the reading from arduino can differ by over 50% when at ambient atmospheric pressure (resting on a table). It should be significantly more accurate if the sensor data are to be trusted. The code is basic:
void setup(){
  Serial.begin(9600);
}

void measurePressure(){
  int rawReading = analogRead(A0);   // Range : 0..1024
  //float rawVoltage = (rawReading * (4.5 / 1023.0)) + 0.5;

  Serial.print("Raw reading: ");
  Serial.println(rawReading);

}

void loop() {
  measurePressure();
  delay(1000);
}

The output variations are not entirely random, it seems that the reading goes down and up in intervals of roughly 5-15 seconds. Below is a sample output:
Raw reading: 61
Raw reading: 67
Raw reading: 70
Raw reading: 73
Raw reading: 74
Raw reading: 78
Raw reading: 75
Raw reading: 82
Raw reading: 85
Raw reading: 90
Raw reading: 89
Raw reading: 97
Raw reading: 103
Raw reading: 119
Raw reading: 146
Raw reading: 165
Raw reading: 171
Raw reading: 168
Raw reading: 163
Raw reading: 150
Raw reading: 143
Raw reading: 118
Raw reading: 88
Raw reading: 70
Raw reading: 62
Raw reading: 64
Raw reading: 72
Raw reading: 78
Raw reading: 80
Raw reading: 82
Raw reading: 88
Raw reading: 92
Raw reading: 102
Raw reading: 134
Raw reading: 160
Raw reading: 170
Raw reading: 172
Raw reading: 166
Raw reading: 158
Raw reading: 149
Raw reading: 132
Raw reading: 100
Raw reading: 73
Raw reading: 63
Raw reading: 61
Raw reading: 71
Raw reading: 77
Raw reading: 79
Raw reading: 84
Raw reading: 90
Raw reading: 90
Raw reading: 99
Raw reading: 134
Raw reading: 161
Raw reading: 170
Raw reading: 166
Raw reading: 161
Raw reading: 151
Raw reading: 133
Raw reading: 103
Raw reading: 81
Raw reading: 68
Raw reading: 63
Raw reading: 63
Raw reading: 71
Raw reading: 73
Raw reading: 81
Raw reading: 83
Raw reading: 85
Raw reading: 89
Raw reading: 98
Raw reading: 128
Raw reading: 161
Raw reading: 171
Raw reading: 166
Raw reading: 159
Raw reading: 145
Raw reading: 120
Raw reading: 85
Raw reading: 67
Raw reading: 57
Raw reading: 63
Raw reading: 72
Raw reading: 75
Raw reading: 83
Raw reading: 85
Raw reading: 89
Raw reading: 97
Raw reading: 130
Raw reading: 164
Raw reading: 172
Raw reading: 163
Raw reading: 155
Raw reading: 135
Raw reading: 101
Raw reading: 69
Raw reading: 60
Raw reading: 62
Raw reading: 72
Raw reading: 78

I tried adding 4.7k pull down resistor with no change but that was just a blind try. I have a multimeter connected as well and the reading seems to be more stable ranging from about 0.495V to 0.535V (variations do not seem to match arduino output).
What could be causing the issue?

Do you seem the same variation with a voltage divider that produces ~0.5V connected?

I didn't have a voltage divider connected, voltage is in range of arduino voltage so not sure why I would need a voltage divider..?

No, just a voltage divider, absolutely nothing else. i.e. with a constant 0.5V input, do you see the same behaviour.

Didn't try that. With nothing connected I see more random variations but only up to a few hundred as opposed to 0-1023 full range. Does that tell you anything or should I still build the voltage divider and test? I also tried another pin with same result. I am using Arduino Pro Micro btw.

A floating input will drift. What you need to work out is if it is the Arduino, your meter, or the sensor causing this. The voltage divider will isolate the sensor.

I connected 33k and 3.3k resulting in 0.45V (0.417 multimeter reading). Got similar results but then I removed multimeter cables and it was stable at 91 with occasional 90. Connected the sensor and nothing else but got same issue. What can I try next?

I don't think you can trust your meter then - it's input impedance should be several orders of magnitude higher than the voltage divider. Does the sensor show the problem without the meter?

Yes, the sensor has the same problem. As for the meter it's a cheapo so no surprises there.

Your code is fundamentally correct. If a resistive voltage divider is providing consistent readings then the issue is with the sensor and the meter. Without a working meter, it would be hard to work out what is going wrong.

Well the meter is working, it just adds some interference when connected together with arduino. The reading itself seems correct.

A multimeter that disturbs the device under test to that extent isn't working correctly. If you connect it to the sensor and Arduino, is it the meter or the sensor or both causing a problem?

I tried same setup with arduino uno and the problem is gone. It also works on micro as long as gnd and 5v pin is connected to uno. Uno measured voltage is 4.88V and micro 4.60V could a voltage difference this small cause this? What else could this be?

Ok, so I have a new multimeter (extech 505). Still getting variations with arduino reading despite a tiny variation in voltage. Multimeter does not disturb the signal any more. What else could I try?

What make and model of pressure transducer is it?

Also, the 5V supply input for the transducer, are you attaching that to Arduino's 5V supply?

@gwideman It's and unbranded chineese sensor. Yes I am attaching it to 5V of arduino (4.6V measured).

Can you point to any eBay or other link for this sensor?

I tried same setup with arduino uno and the problem is gone. It also works on micro as long as gnd and 5v pin is connected to uno. Uno measured voltage is 4.88V and micro 4.60V could a voltage difference this small cause this? What else could this be?

Reinstatement of incorrect edits by Annonomus Person
(AP: Please do not edit answers in such a way that you entirely change their meaning. In the current discussion "the board" is meaningless. We are trying to distinguish between symptoms seen in two different 'boards', an Arduino Uno, and an Arduino Micro.)
Looks to me like the problem is with the Arduino Micro's 5V supply then.
If you are powering the Micro from an external supply (not USB), then 4.6V on the Micro's "5V" output would indicate that the 5V regulator is not operating within its expected range.
If you are powering from USB, then the regulator is not in play. The 4.6V would indicate a problem with the USB's 5V supply.
Likely possibilities:, either the upstream supply is inadequate, or the micros and whatever is attached to it is drawing too much current.
I suspect that the transducer output is fluctuating in a way that's too rapid to be seen by your meter, but which is sampled by the Arduino Micro, giving your varying result numbers.
Either the "4.6V" is inadequate to run the transducer, causing erratic transducer output, or the 4.6V itself is fluctuating, with similar results at the trans output.
And you might also check the ground between micro and transducer -- are you sure that's wired correctly?

Will test it with a different arduino mini, will need to wait for my soldering iron to arrive though, will update then.

For the setup that produces the fluctuating numbers, please confirm that you have the transducer connected to the Arduino Micro's +5V output, and tell whether you are powering the Micro from USB, or from an external supply, and if the latter, what kind of supply?

If you are powering from external power, such as batteries, please be aware that the specs for the Micro show that the 5V regulator is not reliable below 7V input.

Both the Uno and Mini are powered from usb port so it's not the issue especially since I also tried a different port. Transducer should work with 4.5 to 5.5V but you never know with cheap stuff. Will do some more testing when I receive my soldering iron...

@DominicM Note that I listed several possible issues, not just a single 'it'. A voltage of 4.6V DC may be fine for the transducer. But: (1) a meter measurement showing 4.6V can also result from a voltage fluctuating around 4.6V which will cause erratic transduce. Or (2) 4.6V is below USB 2.0 minimum spec of 4.75V, which in itself suggests something wrong with the supply or the path from USB to transducer. (4.6V is apparently legit for 3.0 though.). And again, it's worth checking the ground path between Micro and transducer.

And if you test the Uno and the Micro powered from the same USB port, should get the same Gnd to +5V voltage reading from their "5V" outputs. 4.88V vs 4.6V is enough of a difference to suggest there's something going on with the power.

source: Stack Exchange

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

sort: votes


text:
Project Showcase '14

The logo is a derivative of the Arduino Community Logo licensed under Creative Commons license CC-SA-BY-NC 3.0

Update: Winners Announced
The winners of the contest have been announced. Please see the Meta post for details.
To celebrate 10 years of Arduino, we are proud to announce the first event ever on Arduino Stack Exchange.

Get your boards and soldering equipment out, dig out the ICs and
  resistors. The first Arduino Stack Exchange contest is just round the
  corner. We will be looking for interesting projects that are built
  using Arduinos. The contest is aimed towards sharing, discussing and
  providing feedback on projects that you and other members are working
  on. See announcement post

Details:

The prize is an official Stack Exchange t-shirt
Limit two entries per person. If more than two are provided, only the first two will be considered.
Clones are allowed.
Projects for consideration will be accepted through March 29th, 2014 at 4:00 UTC. The question will still remain open in case someone wants to show off their project they made on Arduino Day 2014.

Visit the Meta post for discussion about this event and further information.
Answer Format
You may post up to two projects (as two separate answers) as entries for the contest. All extra entries will be deleted. Consider following the following template for entries:

Project Title
Very Brief Description
Description
What is your project? What does it do? What problem does it solve?
Design
Things to include in this section:

Schematics and other design documentation. Fritzing is a good tool for drawing breadboard schematics like the one shown in the
  project logo above.
Components used to build the project
Pictures or video

Conclusion
Final thoughts. What did you learn from doing this project? What would
  you do differently if you had to start over?

You can copy/paste the following text if you want to use this template.
# Project Title
**Very Brief Description**

# Description
What is your project? What does it do? What problem does it solve?

# Design
Things to include in this section:

- Schematics and other design documentation. [Fritzing][8] is a good tool for drawing breadboard schematics like the one shown in the project logo above.
- Components used to build the project
- Pictures or video

# Conclusion
Final thoughts. What did you learn from doing this project? What would you do differently if you had to start over?

Prizes
There are two prizes! The winner will be the submission getting the maximum number of upvotes (downvotes do not count) and will get a Stack Exchange T-shirt*! There will be something for the runner-up as well. The runner-up will be decided at the discretion of the event organizers.
*Certain restrictions may apply. International shipping may take a few weeks.
Where do I submit my projects?
Post your projects as answers to this post.

What exactly is the qualification for being an "arduino" project? I use optiboot in lots of places, but I can't see that as being "arduino", since it's just a project that the arduino toolchain uses. Short of using a board in the arduino-form-factor, I can't see a clear way of delineating between "arduino" and "non-arduino", unless you explicitly require that the project be compiled using the arduino text-editor, and that will probably disqualify all the decent projects since the arduino editor is horrible, and all the good coders stopped using it long ago.

@FakeName let's take this discussion to the Meta Post

Stateful questbox
A GPS powered box that makes you visit a few spots before opening
Description
It is similar to questbox, but it stores a small amount state of information in EEPROM, so you have to visit two or three different places before it opens.
Design
Needed hardware:

Arduino Uno
Reverse Geocache Version 2 (or a protoshield)
GlobalSat EM-406A GPS module
2×8 blue LCD with connector header and cable
Hitec HS-55 servo motor
4-40 push rod and clevis for latch (some versions provide a Z-bend rod instead)
2 AA battery holder
Metallic push button with embedded blue LED and 4-pin cable
Pololu low voltage switch
Pololu 5 V boost regulator
JST connector for EM-406A GPS module
Straight and right-angle header pins for the display, servo, and pushbutton connectors
Two resistors for current limiting and display contrast adjustment
Two small capacitors for power smoothing
larger capacitor for display contrast circuit

Total hardware cost: 137$ + shipping
Aditional materials:

A nice box
Epoxy glue, wood to cover pieces, tools

You can find assembling instructions in sundial page (you can buy most materials from them)
I will upload stateful code and post a link here, unfortunately I wont get all need hardware on time, so this is just an idea :)
Code written so far:

Persistent state machine library

Inspiration:
Conclusion
Learned how to integrate many components and libraries all toghether, I'll have to travel a bit to test it :)
Budget can be cut quite a bit changing the concept a bit:

Change GPS with a numerical keypad: the 'player' has to guess/obtain a code instead of traveling to a location
Polulu switch and regulator can be exchanged for a latching relay with capacitance coupling

Energy saver for the absent-minded PC user
This device switches on/off my desk lights when it is dark(ish) and in sync with my PC screensaver.
Description
The project is little more than an combination of a light sensitive sensor, a relay and some smart code that monitors the screensaver on my PC. When it is dusk and when screen saver is not active, it switches on the lights over my desk. When I subsequently leave my desk the screensaver will activate, which will in turn trigger the desk light to be turned off. When there is enough light during day time, the lights are not switched on at all. The problem solved is to reduce the waste of energy due to the lighting in my office being switched on when I have left the room.
Design
Because the power of microcontrollers / Arduino only a little extra hardware is required to create a useful project. The same goes for this project where the hardware is little more than:

An Arduino
A couple of screw shields to connect the external components
An LDR in series with a resistor to measure ambient light
A relay card to switch on and off the mains powered lights
A 10 μF capacitor from GND to RST to prevent the board from being reset and accidentally being programmed.

simulate this circuit – Schematic created using CircuitLab
Conclusion
I learned how to interface the PC over the USB serial link with Arduino and how to read current state of the screensaver on my PC. If I would start over, I'd use a much smaller controller as I really only need a single digital output and a single analog input. Probably base the project on V-USB. Arduino however is excellent for the quick and easy proof of concept (PoC). (The PoC has been on my desk for at least two years already).

It'd be cool to see pictures of your final board and setup. What's the response time like? Instant? After a minute?

@sachleen The daemon on my PC that polls the screensaver runs every 30 seconds when the screensaver off (when I'm working on my PC) and every 5 seconds when turned on. I can increase that speed, but that influences CPU load and with that power use... There is also a capacitor attached to prevent the Arduino from resetting and accidentally being programmed.

@sachleen as dusk falls slowly over time, this 30 seconds isn't really an issue. Nobody notices the difference in darkness over 30 seconds. Within 5 seconds of moving my mouse or hitting my keyboard when I return the lights turn on. There is a slight hysteresis betweet what is considered dark and light, to prevent the lights from turning on/off every so many seconds when it is sloowwwwly getting dark enough to get activated.

You should modify it to dim it at 50% for 10-15 seconds so you're not in the dark completely and it gives you a little "warning"

@AnnonomusPerson I am switching the 240VAC side of a SMPS that is spec'd 100-250VAC input. Not going to happen I'm afraid as I don't want to switch secondary side. Nice idea though, maybe I can add a smart small white LED somehow.

(fake) Linux on Arduino
I recently acquired a small composite LCD screen, which I quickly began playing with using the Arduino TVout library. What came next? Linux!
Description
While playing around with my TV screen and the TVout library, I discovered there is a premade terminal handler for the TV. I soon began to experiment with using it as a TV terminal hooked up to a PS/2 keyboard. There were some problems with the PS/2 library I used, so I transitioned it to use the USB library on my Mega ADK along with a USB keyboard. That worked much better. Now for storage.
My SD card shield isn't compatible with my Mega, so I wired it up somewhat haphazardly to the SPI at the end of the board. I wrote command handling to preform a few tasks like listing files and finding disk size, free space, etc.. The entire assembly isn't by any means finished, but I am happy with the progress I have made.
The code will be relocated to Github eventually, watch the comments.
Design

Challenges
I had a lot of trouble concatenating the inputted charactars to the string storing the current command because I wasn't casting right. Once I got that figured out, I also needed to fix the problem where some keys printed random garbage to the screen. This was caused by reading memory before the letter definitions, so a few ifs cleared that up.
Conclusion
I am very satisfied with the code. Once I add a few more utilities to it, I will put it on Github, so watch the comments. Overall, it was a very fun project. I learned how to use Stino in the process.

This sounds interesting. I would really like to see your code soon!

Code!! Code!! https://github.com/red-green/fakeLinuxonArduino

Did the LCD cost a lot?

@AnnonomusPerson only $17: http://www.amazon.com/3-5-Inch-TFT-Monitor-Automobile/dp/B0045IIZKU/ref=sr_1_1?ie=UTF8&qid=1395696303&sr=8-1&keywords=mini+tv

@AnnonomusPerson i disassembled it because it was too bulky

Cool project. Idea for the future: make it as a flash drive that you can control via the Linux(like) console.

BTW the reason I deleted your comment (on ShiftLCD) was, although I knew that link, I wanted to verify he used the Arduino bootloader. If I would've said Hey did you use the Arduino bootloader on that link? If you didn't the entry is disqualified., most likely he'd say he used it, even if he didn't. It's a sticky situation, and actually I hate my mouse :P (Not button-happy) I appreciate your effort though...

Sonic Ray Gun
Two projects by kids
I'm working with a couple of home educated kids and we are having a lot of fun with an arduino. Their first project was a fake-bomb, like you see in the movies, with a LCD countdown timer and a classic "do you cut the red or blue wire?" type problem.
Project two started with showing them the toneMelody example and a small speaker. The quickly found out that if you turn the frequency up to 15kHz it was rather annoying to teenagers. An hour later they had improved the design with a cup, toilet roll and a switch made from a paperclip making a directional sonic ray gun.
Sadly no pictures.
Conclusion
Don't leave kids unattended with an arduino.

Can you describe it a bit more (code, Fritzing, etc?)?

I think this kind of barely fits within the rules, but it's interesting enough that I figure I'd post it anyways.
High-Precision, GPS-Synchronized timestamp generator for data-acquisition purposes.
This is a rather interesting project that is intended to be used for providing a easy way of synchronizing multiple independent data-acquisition systems.
Basically, I work in a research lab, and we often have instruments that have multiple independent data-acquisition systems, which can be physically separated by as much as 50 feet. We need to be able to correlate the time at which samples from each system were taken, which can be difficult if you want to resolve sampling-times to a great degree of precision. Using something like a USB data-acquisition system, just the USB latency can introduce several hundred milliseconds of unknown latency, that can vary from acquisition to acquisition.
The previous solution was a 24-bit parallel counter that was simply bussed everywhere, requiring an enormous wiring harness, and was kind of a pain in the butt.
This system uses a specialized timing GPS module that can synthesize arbitrary frequency clocks, that are phase and frequency locked to the atomic clocks in the GPS satellites.
The MCU is responsible for tying together the GPS data messages (I had to heavily extend and optimize a existing protocol parser for the GPS data). The GPS is configured to use a proprietary binary protocol, and it's all parsed by the parser I wrote.
The project has gone through a number of revisions (pictured below).
Design
Revisions!

Rev 1: Never worked, due to the fact that I was initially hoping to use a software dPLL off a much less expensive GPS, to synthesize a higher-frequency clock from only the 1 PPS output. It's probably possible to make it work, but the time-investment just made it not worthwhile. (and I'm too crappy a coder)
Used a parallax propeller MCU. The lack of decent compiled languages was a major issue as well.

Rev 2: Shifted to a ATmega2560. Worked, had lots of funky design aspects inherited from the first rev. Primarily, the continued use of shift-registers for the 32-bit output, despite the more then sufficient number of IO on the ATmega2560.
First board that ran Optiboot, and was actually programmed entirely using the standard Arduino toolchain, before I got irritated with it and started modifying the toolchain to better suit my purposes.

Rev 3: Also worked. The bodged wiring is because this board incorporated a built-in USB hub to reduce the number of required USB ports (the FTDI interface requires 1 USB, and the GPS has a USB interface as well). Unfortunately, the GPS wouldn't properly enumerate, though the FTDI device worked fine, and I've used this hub elsewhere without issue. Weird.
I don't have a proper USB debugger, so I just dropped the USB hub entirely, rather then trying to fix the issue. The GPS usb isn't really used much outside of set-up anyways.

Rev 4: Semi-final ATmega2560 version. Added a LCD for GPS status, fiddled with LEDs and so forth. Also, better footprints for the possible super-capacitors for maintaining the GPS status when not powered.
This is the last Optiboot version.
MStime is the MSTOW, or Millisecond-Time-Of-Week, which is the name of the GPS data value that is output on the timestamp out. It's a 32-bit variable that increments once per milliseond, and rolls over each week. It's a more obscure part of the GPS standard.
ITOW is another GPS-related value, being a value that corresponds to the 1PPS signal. The correlation between the two isn't properly reflected on the LCD, since I do not have the CPU time to update the LCD at the rate I'd like. This was actually one of the major things that improved in the upgrade to the Xmega devices.

Rev 5: Complete architecture switch. Now uses a ATxmega128A1U processor. Not really "Arduino" at all anymore, but the ability to have multiple interrupt levels on the xmega processor series allowed me to considerably improve the code structure.
The two bodge-wires are from me doing some experimentation, the board worked fine without them as well.
Looking forward:
Rev 6!

Add the ability to use different LCD sizes, more ESD protection on GPS antenna connection (that was an issue), ability to use a CR2032 battery for maintaining the GPS clock instead of super-capacitors.
Also, much better labeling of debug and status LEDs.

And bonus Nyan-Cat!

(These boards are out for fabrication right now. When I get them, I'll add pictures of the real board.)

I did some long-duration testing between two of the ATmega2560 boards, and over 72 hours, the RMS time-error between the two units was ~20 uS. This was with two completely independent antennas too. My design goal was < 1 ms, so I'm pretty damn happy with that.
On the whole, I think this does a good job illustrating how Arduino can be a useful tool for
early prototyping for "real" products/systems. I use it for getting an initial test-version running with minimal effort, and when I'm confident the idea will work, I actually put the work in to migrate away to a completely custom, purpose-specific implementation.

Design files:
https://fake-server.no-ip.org/svn/FPGAStuff/DAQ%20systems/
(In the "GPS Timestamp" series of directories).
(Note: Files are from Altium Designer. The are not eagle files).
Source code:
https://fake-server.no-ip.org/svn/Programming/Code/AVR/
Again, in the "gpsTimeStamp" series of directories.
Sorry for the crappy cell-phone pictures.

Could you please reduce the number of pictures? 3-4 should be sufficient to get the idea across. It takes a fairly long time to load on slow connections.

@AsheeshR - I strongly disagree. I could drop one of the pictures from the last rev, but having the progression of system design I think is quite valuable.

Having fun with the silkscreen?

Oooh, 3D view PCB. Aww, it's Altium and pretty expensive? :$
Pretty fun to see these projects, or to see whatever projects others are doing..

TV Antenna Rotator
IR remote controlled antenna rotation
Can't get off the couch to adjust the direction of the TV antenna?  And even if you do, sometimes your proximity to the antenna changes the reception.  It would be nice to be able to adjust the antenna from the couch.  Using the TV remote.
Components
Arduino Uno,
IR receiver,
Stepper motor w/ driver board,
1" ID bearing,
Swiffer mop handle,
Plastic box,

Description
Use an old Swiffer mop handle as the antenna post. Got a 1" ID bearing from  my favorite online store, which the mop handle just squeezes into and stops.  I drilled a hole into the plastic box big enough for the mop handle to fit through, but not for the bearing.  I drilled a rectangular hole into the mop handle end to fit the shaft of a 28BYJ-48 stepper motor, and stuck the contraption into the box as shown.  The mop handle actually rests on the bearing, and the bearing is super glued to the top of the plastic box.
Used the stepper.h library to rotate the motor from an Uno.
I took apart an unused DVD player and salvaged the IR receiver from it.  You can take apart any consumer appliance that has a remote and use the IR receiver from it, it'll work.  The IR receiver uses the IRremote.h library.  Using the serial monitor, I printed out the hex code that corresponded to the two buttons on the TV remote that I want to use to operate the antenna motor.  One for rotating left, one for right.
To save energy, use the small_stepper.motorOff() function to turn off the coils after each movement.
Conclusion
This was a fun project that was also useful for my wife.  I didn't implement any acceleration/deceleration in the movement, which might be nice, especially if the antenna had more rotational inertia.
Edit:  sorry about the picture being sideways!  It's right side up on my computer, I have no idea why it's sideways online.

Digital Wall Clock with Radio Frequency (RF) Remote Control
A large (40x30cm / 16x12") 7-segment display wall clock with R/F remote control.

Description
This project features a large (40x30cm / 16x12") 7-segment display digital wall clock with R/F remote control. It has the following features:

It shows the current time and date (hours, minutes, seconds, day, month, year) in two formats (hours or date in the large digits).
It shows the current temperature in °C.
Has a user defined countdown which will sound an (annoying) alarm when it reaches zero.
All functions controlled remotely by an RF remote control.
Has a small cursor keypad for controlling its functions (when the remote control isn't available).
Brightness control independent for each display line.
It continues to keep the current time accurately even when off, thanks to a real time clock IC powered by a coin cell battery.

Design
The key aspects of this project were the following:

It's completely based on Arduino and AVR ATmega328 microcontroller.
It keeps current time even when off, thanks to DR1307 RTC powered by a coin cell battery.
The digits are never multiplexed. Instead, each digit has a dedicated 8-bit serial shift register IC (74HC595) that keeps selected segments on independently of what's being displayed on the other digits and what the MCU is doing.
Segments are powered by Darlington arrays due to current consumption that exceeds that of the MCU or the shift registers.
The clock is controlled by a keypad on the controller board and also by an RF remote control. Radio communication is performed by a pair of inexpensive 434MHz radio receiver and transmitter.
The project has a modular design in which a single controller can manage up 12 single digits. Controller also accepts expandable modules for unlimited number of digits (maximum number of digits is limited by timing delay due to daisy chaining of shift registers and the attenuation of their clock signal).
The design supports a number of ready-made 7-segment display digits or custom digits made with LEDs.

Below are the schematics for the controller and one of the 7-segments boards:

Here are some pictures of the boards that I designed, etched, and assembled, and the remote control:

And finally, here's a picture of another version of the clock. In this one, I'm making the 7-segment displays myself using rectangular LEDs and discrete components.

Conclusion
This project took me a lot of time, effort and learning to get to this stage (it's never finished, as I've learned), but it was lots of fun. A few things I've learned:

Study all the libs you're going to use in your project before you assign GPIO pins in your controller so you avoid potential conflicts. I've been unlucky to use the same PWM pin for brightness control that is associated with VirtualWire timer, so I had to patch the board to get brightness and RF working at the same time.
Crimping KK molex and modu connectors takes A LOT OF TIME!!
Laser cut acrylic pieces are the future. They add a lot of quality to the device even if you are clumsy.

How did you make the PCBs (etching and drilling)?

@sachleen I use the toner transfer method with ironing. I print the board design into ink jet photo paper in a laser printer, then I iron it onto the board, then I etch the board in FeCl. It takes a while to find the right paper and printer settings. I use a dremel drill press for drilling, but I only use phenolic boards and high speed drill bits. Fiberglass boards are much harder on the drill bits, usually requiring the more expensive and brittle carbide drill bits.

Where did you get those LEDs? I have some that look exactly like that!

@TheGuywithTheHat The green rectangular ones? Those are pretty common around here in Brazil. I got those at one of our online electronic components shop. Here are some links: at DigiKey, at eBay. Here's where I got them.

ShiftLCD
AVR based, Arduino compatible, board that mounts to the back of an 8x1 up to 20x4 Character LCD Screen.
Description
I just designed this board and the custom library to make it easier to use and LCD. Though they are pretty easy to use at the moment. It cuts down the number of output pins used from 6 to 3. It also has the option to expand the I/O by adding more shift registers on to the one that drives the display. The processor used is an ATTiny45 or ATTiny85 which has, after using the shift register, digital pins 1 (PWM) and 4 available and analog pin 2 (same pin as digital pin 4) available.
Design

OSH Park permalink which has parts listed
Arduino Library

Challenges
One unforeseen challenge I faced was when I started I was using digital pins 0-2 to run the shift register, these also happened to be the programming pins (MISO, MOSI, SCK). So every time I reprogrammed the device the LCD would get sent a whole bunch of gibberish messages where the power would have to be turned off in order to reset the display. I solved this problem by moving the shift registers latch pin to digital pin 3 which is not a programming pin. Solving this also solved another problem for me because when I moved the latch pin it opened up digital pin 1 which had PWM usage, allowing for more things to be done with the board.
Conclusion
Granted this may not be the coolest product or idea, it still has its uses. The answer the question directly, "What did you learn from doing this project" I learned how to design from start to finish a PCB board. If I could do anything differently it would have been to use surface mount parts instead of through hole, then again it is just a prototype, one-off board.

How did you program your ATtiny? What code was involved? IDE? (Please just comment, do not edit your post.)

@AnnonomusPerson Looks like the person who posted what I did before removed their comment, so this is the where I got the things needed (Arduino IDE files and programming schematic) to program the ATTiny. http://highlowtech.org/?p=1695

Why use surface mount? Soldering through-hole at home is much easier? I think SMD is only for production runs, or is there something else to it?

Button-pushing robot.
A four-wheeled eight-pound remote-control laser-shooting robot that pushes buttons.
Description
I made this project over the course of last school year. I was in robotics class, and we decided to have a competition. Each team would make a robot that has a large button and a way to push other buttons. At the end of the year, we would have the final contest, where the three robots would try to push each other's buttons.
By the end of the year, my robot only partially worked. Every part of the robot had at some point been working, but between a fried Arduino, fried motor drivers, terrible code organization, and me being the only person on my team to work on the robot for a total of more than five hours, I couldn't get it completely working.
I haven't touched my robot in almost a year, so I know that if I wanted to get it working again I would have to rewire the bot and rewrite the code. I may decide to do that some day, but for now I'm going to work on less ambitious projects.
Design
Overall Design

Information/electricity flow
+--------------------------+   +-------------------------------------------------+
|         Computer         |   |      Robot                                      |
|--------------------------|   |-------------------------------------------------|
|                          |   |                                                 |
| Keyboard +--> Processing |   |  Button +-------------+        Motor    Motor   |
|                          |   |                       |          ^       ^      |
|                    +     |   |                       |          |       |      |
|                    |     |   |  Batteries +-----+    |          +       +      |
|                    v     |   |                  |    |   +----> Motor Driver   |
|                          |   |                  v    v   +                     |
|               Bluetooth +-----> Bluetooth +--> Arduino Uno +--> Motor driver   |
|                          |   |                  +    +  +       +       +      |
+--------------------------+   |                  |    |  |       |       |      |
                               |                  |    |  |       v       v      |
                               |                  |    |  |    Motor     Motor   |
                               |                  |    |  |                      |
                               |                  |    |  |                      |
                               |                  |    |  +-----> Laser          |
                               |  +---------------|----|----+                    |
                               |  |       Arm     |    |    |                    |
                               |  |---------------|----|----|                    |
                               |  |     +---------+    v    |                    |
                               |  |     |      Motor Driver |                    |
                               |  |     v              +    |                    |
                               |  |  Servo             |    |                    |
                               |  |                    v    |                    |
                               |  |                  Motor  |                    |
                               |  +-------------------------+                    |
                               +-------------------------------------------------+

Components

Arduino Uno, (fried)
Transportation:

2 motor drivers, (one fried)
4 wheel motors, (24v, 360mA with no load)
4 wheels, (plastic jar lids)

Easy Button
Arm:

Servo, (continuous rotation)
Motor driver, (fried)
Motor, (12v, found in teacher's junk pile)
Eraser
Counterweight, (homemade paper bag filled with pennies)

2 battery packs, (12V, 1300mAh, Ni-MH rechargeable)
2 solderless breadboards
Laser, (5mW)
Bluetooth:

mdfly Bluetooth module, (5v, 30ft)
Bluetooth adapter, (USB, 300+ ft)

Lots of wires
Lots of scrap metal and plexiglass, (found in teacher's machine shop)

Code
I didn't organize my code very well, so I hope this is the right code.

Arduino: https://github.com/TheGuywithTheHat/robotics-2013/tree/master/Arduino
Processing: https://github.com/TheGuywithTheHat/robotics-2013/tree/master/Processing

More pictures

Terrible video of a slow, armless, buttonless, laserless, and bluetoothless early version of the robot.
https://www.youtube.com/watch?v=Q7MvE7-Xb0E
Conclusion
I'm really good at frying electronics.
This was my first experience in an actual machine shop. I got to use a CNC milling machine, manual milling machine, lathe, and bandsaw. If I started a project like this again, I would make much better documentation, so I could figure out what the heck I was doing a year later.

Nice work! Nothing is as valuable as experience and the important bit is that you now know how to do a better job next time.

The Knock-knock lamp
A lamp that toggles on/off when the desk is knocked on. Currently in alpha phase, still prototyping, but I think it's the most useful Arduino project in existence. Included corny joke generator... from previously recorded knock-knock jokes. Note: I know I can't win in the rules, but there's no rule about entering... I can show off my project, too.
Description
So far I've pretty much explained most of it. You knock, and the light turns on and off. I'm currently on breadboard. I'm using a piezo element to detect the knocks with vibrations. In parallel, I have a 1 megaohm resistor to protect my Arduino Uno SMD.
I thought of this design after nearly knocking (haha punny) my lamp off of my desk while searching for the little toggle switch. I'm not exactly... well adroit. It's nice just to knock on the desk and then have light. I'm also using a Power Switch Tail SSR (solid state relay: no noise) to control it with two of my Arduino's pins.
Design

Image taken with webcam hanging over monitor... eek!

Components used to build the project:

Piezo element ($3.00 USD)
Megaohm resistor ($0.30 USD each in 5pk)
Arduino Uno SMD (on hand)
Power Switch Tail SSR (~$25.00 USD with ship, but had on hand so no cost)
Breadboard and jumpers/extra wire (~$5.00 USD, but had on hand so no cost)

Cost to me: $3.30 USD + $0.02 USD (tax) == Only $3.32!
Conclusion
Overall, it is a simple project but it's actually useful. That's a struggle with my Arduino projects: can I build something that I would actually use? Blinking an LED isn't exactly going to help you in life. It's fun, but that's about it.
The biggest issue I faced (and kinda still do) is not getting a strong enough signal. I learned a lot about electrical signals: I figured out how to find the "peak" of a pulse and not just read the pin at a random interval and miss the higher voltage. I would try getting  more sensitive piezo element. A larger one would help. I'm trying to modify my circuit to not limit the voltage as much, but protect the Arduino. Some sort of fuse would help in this situation. I'm also playing around with resistor values. It'd help a lot to have a scope for this, but I guess not... :P
After I perfect the circuit, I'm going to work on getting it on a PCB with an ATtiny... and maybe even develop some kits. I'll try to publish my findings on how to make the element more sensitive without risking my board in the process.
Status update: I've been really busy recently. I'm going to order a zener diode (4.3V) here in a week or two to remove the megaohm resistor to prevent diluting the signal while protection the chip. I may build a simple voltage amp here if needed (alongside the zener) to try to make the sensor more sensitive.

Moving to something with differential and gain ADCs would help you get more sensitivity out of the piezo. And possibly using a TVS instead of a resistor.

Are you using ADC for detection or an interrupt? Any idea of how large the voltage peak is you want to detect?

@jipie ADC for detection, I have fairly efficient code: it loops and finds the peak for every 250 ms. No delays. For peak, IIRC it's around 14/1024 (too lazy to convert that now). I should look into the AREF pin too, but there might be problems with if it's dropped it can make ~9V.

Try this as input buffer. The transistor acts as a current amplifying half wave rectifier / peak detector. No need to detect a single peak with the ADC, the transistor / capacitor will strech it for you. As configured the output voltage has a 2.2V DC bias, but you can change that to anything you prefer by changing the resistive divider. That way you can make the input even more sensitive by selecting the 1V1 or 2V56 bandgap reference. The 10M resistor ensures the capacitor discharges over about a second and was in reality my DMM.

- Learn how to create your own low cost wireless sensors and connect them to the world.
http://www.mysensors.org
We call it "Internet of Your Things"
Description
We've combined the Arduino platform with a small radio transceiver into a fun, flexible world of low cost wireless sensors.
All the nitty-gritty details about the sensor communication has been packaged into a convenient software library so you don't have to worry about them.
It is as easy as 1, 2, 3.

Connect the parts. 2. Download the provided examples. 3. Start measuring and controlling the world!

Read more about how the sensor network is automatically being formed using our Arduino Library on the site. It basically forms a star network and can reach hundred of meters.

In the middle you place an Arduion or Raspberry gateway that collects the information from your sensors.

Design and schematics
Here is one of the prototype motion sensors I created to control the garden light outside of my house. The motions status is sent to my HA controller which turns on the light (via z-wave) when motion has been detected. A light sensor (not in the image) makes sure only to turn on the lights at night.

You will find all the build instructions here:
http://www.mysensors.org/build/
Othe site there is also easy-to-follow build instructions for a bunch of other wireless sensors and actuators. Here are some examples:
Distance Sensor, Motion sensor, Relay actuator, Humidity, Light, Pressure, Rain, Temperature, ...
Conclusion
The project is still in the starting blocks and we hope to provide plugins for a growing list of Home Automation controllers. The first thing on our list right now is to provide a DIY controller that provides a free cloud storage for your sensor data.

See you @ mysensors.org
/Henrik Ekblad (the creator of the Open Source Arduino Library used for the communication between the sensors)

UPDATE 27/3. Made the example more concrete and added my affiliation with the open source project.

Welcome to Arduino.SE! I'm afraid your website doesn't fit the criteria of our showcase. We're looking for specific projects which demonstrate a practical application of Arduino (as seen in the other examples here). Perhaps you could provide an example of a sensor project you've built?

Ok, maybe i'm missing the point ;). The "specific project" here is that we use Arduinos to create self healing wireless sensor network. To archive this we have created an Open Source Arduino library for the NRF24L01+ transceiver.

This sounds more like an advert than a project. Change the tone, maybe make it a bit more specific to a single application. I suspect that is why you got a down vote.

Welcome to Ard.SE! Based on your profile website, you work at or own the site being promoted above. It is SE policy that you disclose this in your answer. Please edit it to include that. Also, can you add an example of using this?

I've been developing this (Open Source) MySensors library for the past 6 months on my free time. To help other people use the library properly we (more people have joined the project the last couple of months) launched the build-instruction-page just 3 days ago. I thought it would be a good Arduino project to get feedback on in this "Project Showcase". I don't think I've tried to hide my participation in the project in any way and I'm sorry if the description is perceived as an advertisement. We are just very happy about the project!

It looks cool... however can you use the "edit" button to add your affiliation and maybe a practical application?

I'm pretty excited about this project.  I've been waiting for a Raspberry Pi implementation of a sensor network.  It's more of an enabling tool so others can focus more on getting stuff done.  I understand the other comments here about how it might not have fit within the Showcase thread objective, but in terms of letting others see how this tool can be used on their projects, I think it's valid.  Just think of all the cheap wireless sensors you can scale up to with this.

4-Digits LED display for Arduino
Small board with 4 7-segments LED digits, managed through 3 pins.
Description
When I started working with Arduino, I wanted a way to display values collected by various sensors I experimented, but I did not want to output these values through Serial to a PC.
I wanted a small board that I could easily reuse from one project to another and I wanted to spare a breadboard.
This board, along with its small library, currently allows 4-digits numbers display and does not source any Arduino current during display (current is sourced only when communicating to the board the new value to display from now on).

Design
The design is rather simple as I decided to reuse a MAX-7219 chip to drive my LED display (I had a few of them on hand).
Thanks to this chip, the schematic was much simple, but it was important to correctly understand how to use it; fortunately, its datasheet was pretty clear.
The original design was done on a breadboard and used 4 single LED 7-segment digits; but it required too much wiring for my taste (need to connect segments by groups of 4). Also, during my very first experiment with 7-segment LED digits, I have fried one: it had 2 Ground pins, but I connected only one to GND instead of both :-(
Then I decided to go for a 4x7-segment display, common cathode, with segment anodes already connected for 4 digits: that's only 4+8 pins!

During my tests, I have found a useful Arduino library for working with MAX-7219 which I decided to reuse. I have built my own library upon it, with a very simple API.
After breadboarding, it was time to make the design more permanent; since I had a bunch of stripboards on hand, I decided to go for it.
I searched and found an easy Stripboard designer for PC that I have used for designing my board.
The first stripboard design was not optimized in terms of space and I decided not to implement it:

Then I have reviewed the design to optimize the cost and size (just one small 50x75mm stripboard); that was easy with the stripboard designer I found before:

Once the board was ready, I decided to check it with an Arduino UNO and an Ultrasonic Sensor:

It seemed to work except I often had strange, inconsistent displayed values; after investigation, I found it was due to noise triggered by the display board, noise that interfered with the sensor. I just needed to add a decoupling cap as near the current supply pins of the sensor as possible and that worked perfectly (note that the display board already had decoupling caps for the MAX-7219 chip).
Parts list:

1 x LN5461AS:    common cathode 7-segments block of 4 digits
1 x MAX7219:     multiplexed LED driver chip
1 x IC support (24 pins)
1 x 22K resistor
1 x 10uF electrolytic cap
1 x 100nF cap
1 x male pin header (5 pins)
1 x 90x50mm stripboard
wires, solder...

Conclusion
30 years after my last electronics experiments, I could get the virus again with Arduino and with this very first project which, although rather simple, taught me several things:

interpret datasheets for the components used (MAX7219 and LED display)
learn how to use and be effective with stripboard design
all pins marked GND or V+ should be connected: you don't choose the one you feel like connecting!
if there's something that appears strange when you test your circuit and you don't understand why: don't search, it must be noise, try to add a decoupling cap and that should do it!
learn how to create an Arduino library (not just a sketch)

If I was to start this project again today, I would:

try to optimize further the stripboard design (probably I could reduce the size a bit further)
replace the straight pin headers on the board with right-angled headers so that wires connecting to Arduino are more protruding in front of the board

Heating Controller
You know how it is - you set the heating to come on at a certain time and how many days do you work late and it's been on full bore for hours, or you go away for a few days and forget to turn it off? Or the rare occasion that you get home early and the house is cold? I decided that the simple way to get around this was to build a device that would allow me to turn my heating on or off by text message / sms. It would be in addition to the existing control system so as not to lose the flexibility which that can provide.
The project consists of a few major parts: an Arduino Uno clone, a Seeedstudio GSM shield, a DHT22 temperature sensor and a 25 amp SSR.
How it works:
The existing heating controls are set to 'Off' and the new controller is wired up to override them. The Uno is programmed to respond to three different messages - On, Off and Query. In the case of the latter the unit will read the DHT22 and reply to the sender with the current temperature and the status of the unit (on or off). If the command is either On or Off then it will respond with a confirmation of the action carried out. Once messages have been acted upon they are deleted; any messages that do not conform to the specific message structure are left in the SIM card memory and can be examined later if desired.
Power to the unit is supplied by a five volt three amp switch mode power supply. As the power pins on the Arduino are simply exposing the board's internal 5v bus I decided to power the ensemble through these and configure the shield to draw  power from the Arduino.
The unit has three status LEDs. One green one to indicate that there is power, a blue one to indicate that the GSM board is 'live' and a red one to indicate the status of the heating. These are in addition to the status LEDs provided on the Arduino and shield. There is also a push button switch that allows manual control of the heating, with a 100nF capacitor to handle the debounce.
Next:
Much of the code relies upon good old delay() to give the shield enough time to perform its actions. I plan to improve the code so that it waits for confirmation from the shield rather than assuming that it has done what it was told to within the time allocated! I will also add a 'still alive' feature - at fixed intervals turn off the blue LED, send the AT command to the shield and on an acknowledgement turn the LED on again. The shield is under software control so if it fails to respond then turn it off and back on again.
The whole ensemble is to be mounted in a suitable enclosure and mounted adjacent to the existing controller. I have an internally illuminated push button switch that I will use instead of separate switch and red LED to handle the override.
Longer term I'm planning to add an RTC, a 20 x 4 LCD and additional push buttons to allow the unit to be programmed and act as a time switch as well.
Prototyping has already started!
Conclusion.
There is something slightly decadent about waking up on a cold winter's rest day, sending a text message / sms to turn the heating on, and rolling over and going back to sleep for an hour! And when you realise that you haven't turned it off on a night you can do so from the comfort of your bed!

Serial Box
A portable serial monitor in a box
Description
Sometimes it's useful for a device (Arduino or otherwise) to output some debug information via serial. That's great if you've got a computer on hand with an appropriate serial input. However, that's not always the case for a variety of reasons.
This project is my attempt to address that problem by creating a portable Arduino-powered serial monitor, which I can hook-up to other devices in the field.
By default, it will simply display text in a scrollback format; i.e. text appears on the bottom line, and everything scrolls up to make room when more arrives. This means it should work very neatly with all sorts of generic devices. However, it will also be possible to use escape sequences to control the display more precisely, so that devices can also be programmed specifically to take advantage of its capabilities.
Design
The design consists of a set of 4 alphanumeric LCD displays (16x2 characters each), aligned in a box something like this:

The displays are Epson EAX16027AR's, which unfortunately are not compatible with the standard Hitachi HD44780 driver. As such, I had to write my own library for them.
I chose to use these displays (rather than e.g. one large display) mainly because I just had them lying around, and wanted to do something interesting with them. I also thought it would be quite handy to be able to control each display independently for some applications (e.g. displaying different information on each one).
In terms of circuit design, the displays are connected in parallel, with chip select pins being used to direct data/commands to each one as needed.
An ATMega328 will be the brains of the final unit, with serial data coming from a TTL-level line (for connecting directly to the TX of a similar MCU), or optionally from an RS232 9-pin D-sub socket (for connecting to various other systems). The unit will also have a contrast dial, a button for clearing the display, and a button for initiating a self-test mode. In future, I'd like to add buttons which let the user move through a scrollback history too.
Below is a very preliminary circuit layout (I had a lot of trouble getting Fritzing to play nicely for some reason!). It includes an 8-bit SIPO shift register for driving the LCDs' data lines, which are shown in green. You can also see the chip select lines in orange.

At the moment, the project is still at the working prototype stage, driven from an Uno (clone) board. Below, you can see a photo of it in action, displaying text which was passed via serial from my computer.

Source code
I'm making my LCD library available on GitHub at the link below. Please note that it's at an early stage in development. In the near future, I intend to make it much more similar to the core LiquidCrystal library so that it's easier to transition between the two.

https://github.com/avid-insight/LiquidCrystalEAX

You can find some basic code for my Serial Box prototype in the "examples" folder.
Conclusion
I think the project is coming along very nicely, and I was extremely pleased to get the prototype working. My main challenge is going to be mounting the whole thing in a box. I've already made a start on cutting out suitable holes for the displays, but I'm not very experienced at that sort of thing, and am finding it quite tricky to line everything up.
I'll get there in the end though. It just may not look very pretty by the time I'm finished! :)

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


text:
Opamp for amplifying 1V signal voltage to 2V
I'm doing my first electronics project where a signal that varies between -1 to 1 V is going into an analog pin on the Arduino. The amplified signal has to be read as fast as possible by Arduino. The source signal is at 60 Hz.
Will this LM324 be a suitable 4-channel opamp for my needs? How concerned should I be about the 2 mV input offset and 20 nA input current bias?
To make full use of the 10bit ADC, would you recommend using an opamp with gain of 2 and biasing the signal by +2.5V? If so, will it be better to create the bias using a potential divider across +5V and GND, or using a 2.5V voltage regulator?
Or would it be better to set AREF to 2V and bias the signal by +1V? In this case, will it be better to use a 2V voltage regulator, or a voltage divider across Arduino's 3V3 and GND using 20M and 33M resistors?

A 2mV offset voltage will become a 4mV error after amplification. You haven't shown the schematic for your amplification, but the current bias will also become error after amplification.
That LM324 variant is surface mount, but there are other LM324 variants in a DIP package, which will work fine in a breadboard.

Thanks, would this 14-PDIP version of LM324 be a better choice? (http://www.digikey.com/product-detail/en/LM324N/296-1391-5-ND/277627)

It will have the same specs, it will just be better for breadboarding.

Is it possible to use the opamp to bias the amplified signal by 2.5V? Or will using a potential divider across the ground and +5V pins of the Arduino be the easier route?

It is definitely possibly to bias the signal. You won't want it at exactly 2.5V though, because of the current bias. And in fact, biasing it will remove it from the rails. This is a good thing.

Just an alternate idea I saw: If you dont need high accuracy, you can use a voltage divider to bias -1 to +1 into 0 to 1, and set the analog reference to 1.2, and get almost the same result but skip the op amp.
A voltage divider with 2 equal resistors will give you the voltage halfway between its two inputs. If the bottom of the voltage divider is at 1v, and the top input is at -1, you get 0 out.
If the bottom is at +1, you get 1 out.
I saw a really clever design using 2 1 megaohm resistors, and actually using the aref pin as an output to provide the bias for the divider, setting the reference to the 1.2v setting, putting the signal in the top of the divider and ground and connecting the adc to the output of the divider.
Aref wasnt meant as a current source, but they use 1meg resistors so the current draw will be at most a few microamps.
A filter cap on aref probably draws more than that if vcc is noisy(if there wasnt current to filter we wouldnt need the cap!) So a few uA should be fine.
They put a 1nf capacitor betcan the input and ground to fix the issues with the ADC input current causing voltage drop. It worked up to 100hz. They never tested accuracy because it wasnt needed though. I'd guess that the adc internal reference was the major error source, probably a few percent.
You can also actually bias with a voltage divider to the 5V supply, and get a 0 to ~1.6V output, it's just a little harder to understand.
This simulation explains the concept(5v version)
http://www.falstad.com/circuit/#%24+1+5.0E-6+81.92041607667615+50+5.0+50%0Ar+304+160+304+224+0+1000.0%0Ar+304+224+304+304+0+5000.0%0AR+304+304+256+304+0+0+40.0+5.0+0.0+0.0+0.5%0AR+304+160+208+160+0+1+40.0+1.0+0.0+0.0+0.5%0Aw+304+224+400+224+0%0Ax+368+208+456+214+0+24+To+ADC%0Ao+3+64+0+35+2.5+0.00625+0+-1%0Ao+4+64+0+35+2.5+9.765625E-5+1+-1%0A
Left click the output, use view in scope.

That's a really interesting approach that's simplier! Any chance that you still have the schematics for the 2nd idea you mentioned? I can't figure out what it means to put the signal in the top of the divider and ground.

To make full use of the 10bit ADC, would you recommend using an opamp with gain of 2 and biasing the signal by +2.5V using a potential divider across +5V and GND, or bias using a 2.5V voltage regulator?

Or would it be better to set AREF to 2V and bias the signal by +1V? In this case, will it be better to use a 2V voltage regulator, or a voltage divider across Arduino's 3V3 and GND using 20M and 33M resistors?

Edited to include the 5v bias way of doing it, with a link to a web based simulation.


text:
Ultrasonic Sensor scanning too often resulting in a whirring noise
I am using an HC-SRO4 ultrasonic sensor for a wall-avoidance, maze-solving robot. However, I have recently run into an issue where I am getting a whirring noise from the sensor because it is taking measurements way too often.
This is the code I have right now:
const int serialPeriod = 250;       // only print to the serial console every 1/4 second
unsigned long timeSerialDelay = 0;

const int loopPeriod = 20;          // a period of 20ms = a frequency of 50Hz
unsigned long timeLoopDelay   = 0;

// specify the trig & echo pins used for the ultrasonic sensors
const int ultrasonic2TrigPin = 8;
const int ultrasonic2EchoPin = 9;

int ultrasonic2Distance;
int ultrasonic2Duration;

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

    // ultrasonic sensor pin configurations
    pinMode(ultrasonic2TrigPin, OUTPUT);
    pinMode(ultrasonic2EchoPin, INPUT);
}

void loop()
{
    debugOutput(); // prints debugging messages to the serial console

    if(millis() - timeLoopDelay >= loopPeriod)
    {
        readUltrasonicSensors(); // read and store the measured distances

        timeLoopDelay = millis();
    }
}

void readUltrasonicSensors()
{
    // ultrasonic 2
    digitalWrite(ultrasonic2TrigPin, HIGH);
    delayMicroseconds(10);                  // must keep the trig pin high for at least 10us
    digitalWrite(ultrasonic2TrigPin, LOW);

    ultrasonic2Duration = pulseIn(ultrasonic2EchoPin, HIGH);
    ultrasonic2Distance = (ultrasonic2Duration/2)/29;
}

void debugOutput()
{
    Serial.print("timeSerialDelay: ");
    Serial.print(timeSerialDelay);
    Serial.println();

    if((millis() - timeSerialDelay) > serialPeriod)
    {
        Serial.print("ultrasonic2Distance: ");
        Serial.print(ultrasonic2Distance);
        Serial.print("cm: ");
        Serial.println();

        timeSerialDelay = millis();
    }
}

and my wiring:

Link to product
Does anyone know why the scanning is happening constantly? It should only be happening every 1/4 of a second, not constantly. The weird thing is that this wasn't happening earlier before I started using the cable.
I believe it has something to do with the 8.5" extension cable I have (needed because I can't mount three sensors, one facing to each side and one in front, on a single breadboard). This is because when I mounted the sensor directly onto the breadboard, the delay was correct and the whirring was not present. However, as I just mentioned, I need the extension cable to be able to have the three sensors.
Does anyone have a solution for this?
Thanks!

If loopPeriod = 20 then it should be sampling at 50Hz, like the comment says

Change loopPeriod to 250 for a quarter second sample rate

Okay, did that. It did slow down the rate, but I could still hear a faint clicking which got louder as it got closer to an object and it will pause if the value reaches 0cm. Why is this?

Most ultrasonic sensors emit a bit of sound in the audible spectrum. I have noticed this a lot in the Maxbotics EZ line.

So, it is just something I have to put up with? Okay. I suppose I can survive that. But why is the scanning pausing (and dropping to 1/4 second rates) when it reaches 0cm? Thanks for the quick response!

I guess. It is probably louder if it is closer because of the reflection of sound.

That would make sense. Again, why is the scanning pausing at 0cm and (if I keep it at 0cm) dropping to 1/4 second rates?

Probably because the sound is bouncing back too fast for the sensor to comprehend

Ah, that makes sense. Or, in the case that is looking at nothing the signal never returns. Anyways, thank you very much! I will mark that as answer as soon as I can :)

If you want to sample at 4Hz (4 times per second), you need to change your headers accordingly:
const int serialPeriod = 250;       // only print to the serial console every 1/4 second
unsigned long timeSerialDelay = 0;

const int loopPeriod = 250;          // a period of 250ms = a frequency of 4Hz
unsigned long timeLoopDelay   = 0;


text:
Is there a way to make wiring a bare microprocessor to a shield easier?
I currently do most of my AVR work on breadboards, but the large variety of Arduino shields and code out there makes me wonder if I'm not beating my head against the wall sometimes, and looking up port to pin mappings both wastes time and slows me down. Is there any convenient way to adapt AVRs (other than those pin-compatible with current Arduinos) to Arduino shields?

Are you asking: Is there a way to make wiring a bare microprocessor to a shield easier?

@Cybergibbons: That is exactly what I'm asking.

To that one, I don't have an answer. Honestly, my way of working around this is to almost exclusively use I2C or SPI devices so there are only a few pins to remember.

@JarrodRoberson You have replaced the AVR in the title with microprocessor, AVRs are not microprocessors, they are microcontrollers which is a microprocessor+memory+peripherals etc. You have also removed the word Arduino from the shields but the question refers to Arduino shields, not shields in general.

@alexan_e read the OP comments right about yours ...

You could (scrape off and) desolder the chip in an Arduino board and replace it with a '28 Pin IC Socket' (google that term to see what I mean).

You can make adapter boards (one for each mcu model).
The bottom side (male headers) would plug to the breadboard and the upper side would have female headers with the same pinout as an Arduino board (female hearers placed in the appropriate positions to match Arduino shields).
Such a board shouldn't be difficult to design.
Here is an image that resembles what I describe

It would adapt the pinout of a bare AVR to the pinout of a typical Arduino so that shields can by directly plugged on top of it.

Also a pinout diagram may come handy to speedup things when you use a bare chip with Arduino code.
(image source)

Another similar solution is a small printed sticker placed on top of the AVR
(image source)

+1 for the didatic effect of the adapter board picture AND VERY TIDY breadboarding.

@Ricardo Although I do agree it's a good picture, it is from another site (source listed). Otherwise, great answer! BTW: Be cautious if the shield connects to ICSP... the Ethernet r.3 does to add Mega compatibility.

The Arduino-way of doing that is making a lookup table that translates pin number to PORTn / DDRn / PINn SFR and the related bit. You can use the same trick and make GPIO pins count in a convenient way as they are in the package. Only special peripherals (like SPI / PWM) cannot be accounted for in this way because they are hard wired to a pin.
A good start is the below Arduino.h library sniplet if you want to re-use that concept.
// Get the bit location within the hardware port of the given virtual pin.
// This comes from the pins_*.c file for the active board configuration.

#define analogInPinToBit(P) (P)

// On the ATmega1280, the addresses of some of the port registers are
// greater than 255, so we can't store them in uint8_t's.
extern const uint16_t PROGMEM port_to_mode_PGM[];
extern const uint16_t PROGMEM port_to_input_PGM[];
extern const uint16_t PROGMEM port_to_output_PGM[];

extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];

// Get the bit location within the hardware port of the given virtual pin.
// This comes from the pins_*.c file for the active board configuration.
//
// These perform slightly better as macros compared to inline functions
//
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
#define analogInPinToBit(P) (P)
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )

The pinMode, digitalWrite and digitalRead functions are defined in /usr/share/arduino/hardware/arduino/cores/arduino/wiring_digital.c which can be used for further inspiration.

While this answer covers the software part, my question actually asks about the hardware part.

@IgnacioVazquez-Abrams can you elaborate a bit more in your question then? Not sure if I understand what you're asking.

I have bare AVR chips, and I want to use them with existing Arduino shields without having to add a couple dozen jumper wires.


text:
Reading three signals sent serially on Simulink from Arduino
I am sending three signals from one Arduino mega to another using xbees. On the receiving end I am using these signals in a Simulink code to control servo motors. Currently it is set up to read from analog pins without the wireless set up. With the wireless technology the signals are all being sent and received through one serial port. I believe I would need to change the inputs in Simulink to a serial receive block instead of an analog pin block. The problem is the documentation for the serial receive block says you can not assign more than one serial receive block to the same serial port. If anyone has a solution to this it would be greatly appreciated!
receiving code
int received1;
int received2;
int received3;
void setup() {
  Serial.begin(9600);
}
void loop() {
  if(Serial.available() )
  {
    received1, received2, received3 = Serial.read();
  }
}

transmitting code:
void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue1 = analogRead(A0);
  int sensorValue2 = analogRead(A1);
  int sensorValue3 = analogRead(A2);
  Serial.write(sensorValue1, sensorValue2, sensorValue3);
  delay(1);
}

How are the three signals encoded in the bitstream?

Here is my receiving end arduino code. Not sure if its correct yet.  I will add it to the question.

What does your sending code look like?

I will add that to the question as well

What is the result shown on the serial monitor?
Let the three values received on the receiver code be shown on the serial monitor. Tell us exactly what do you have? Is it a trash? or nothing is received?

Repost from SO: http://stackoverflow.com/questions/22599430/reading-three-signals-sent-serially-on-simulink-from-arduino

You need to put your data into a packet and then send the packet to Simulink.
You have tried this by this line in your transmitting code:
Serial.write(sensorValue1, sensorValue2, sensorValue3);

However, as you can see from the Serial Write documentation it does not work like that. The function cannot accept 3 arguments.
Try this instead:
Serial.write(sensorValue1);
Serial.write(sensorValue2);
Serial.write(sensorValue3);

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


text:
How to find out whether an arduino can control a servo motor
I have a servo motor with following specs
Torque - 1.08Nm
Max rpm - 3000
Current rating - 7.8 amp
Max voltage - 56V DC
Please tell me how to calculate whether an arduino board - uno rev 3 can control the servo motor? If not, how to find out how many such boards are required?

Is it a standard 3-pin servo?

Generally something this big isn't going to be a 3-wire hobby servo but a large motor with some form of position encoder built-in to it. A link to a data sheet would clear this up.

Do you hace exact refs of your servo? That could help people answer.

Yes its a 3 pin servo. This is the link to the data sheet of the encoder HEDS - 5540 - A12
http://www.avagotech.com/docs/AV02-1046EN

The datassheet you have provided is of the optical encoder that can work fine with Arduino, but that is just to provide feedback of the location of the shaft. What about the motor? That is the part that will need high current so unless there is a driver you;ll have to add one.

Sorry, I forgot to provide this the last time. The datasheet for motor is
http://www.parvex.com/fichesmot/english/rx/rx320e.pdf

One important point that is not obvious from your question is "what do you want to control on this motor: speed, torque, angular position?" Then how it can be done (voltage level?) does not look clear to me from the datasheet.

Also, I don't know where you're getting "three pin servo" from, but that encoder alone is a 5-pin device, and the motor has two additional pins. At minimum (ignoring all the required control and driver electronics), you'd need 7 pins.

An Uno most definitely cannot directly control that motor. According to the specs here,

They operate at 5 volts. Each pin can provide or receive a maximum of 40 mA

So your motor has needs about ten times the voltage and 200 times the amps that the Uno can supply. Of course, you can always get a driver of some sort for the servo.

Agreed. However, I'm not sure any of the common driver chips will be suitable for this situation. I guess a MOSFET is requested in this case.

The optical encoder you link to has 500 pulses per revolution. This means at 3000rpm , you will be generating pulses 25,000 times a second. You will also need to deal with overshoot (as there is nothing worse than a motor going overspeed and the feedback loop being unable to detect it).
Dealing with an optical encoder generating pulses this quickly is actually quite a challenge, especially with Arduino (which has rather slow native I/O using digitalRead and digitalWrite), and the ATmega328 (which doesn't have any dedicated hardware to deal with high speed optical encoders).
Driving a 56VDC, 7.8A motor isn't an easy challenge either - a motor driver for this isn't going to be easy to design.
I'd probably look for a dedicated servo or CNC motor controller to deal with something like this.

You could probably manage 25K interrupts/second without too much trouble. You'd just need to wire the encoder a/b into the INT1/INT0 pins (and maybe use the pin-change interrupt for index). You'd have to write a decent interrupt handler, though. The ATmega328P may be capable of handling the encoder and servo duties, but there isn't going to be much arduino left in your code at that point.

You really need to manage a fair bit higher than that - overspeed could be as much as 50% on some systems, so 4500rpm. Then you have two sets of pins on the optical encoder. It's not impossible, but it is a lot of work. Other micros have functionality designed to deal with optical encoders and servos.


text:
What happens if I power the Arduino with both the USB and external power voltage simultaneously?
I am a new Arduino user. I am not sure whether I can connect both USB and external supply through power adaptor to Arduino simultaneously. Would this burn the controller?
Basically, I want to automatically shut down the computer after saving all open documents before my UPS battery goes out whenever I am not there to manually shut it down. I am trying to notify the computer about the power failures of main supply - AC 220V 50 Hz (notification/signal sent when power goes out) via USB using Arduino. I am thinking that this can be done by using the external voltage power supply pin. Whenever power goes out in the mains, the external voltage power supply pin will drop to 0 V from 7 V. The value of the voltage can be read using software ( I am unclear about this: Can it be done? If yes, how?). The Arduino will still be powered up as it is connected to USB of computer and thereby communicates to the computer about the power failure.

From arduinoBoardUno:

Power
The Arduino Uno can be powered via the USB connection or with an external power supply. The power source is selected automatically.

Put the external power through a voltage divider or transistor-based inverter and into an analog (divider) or digital (inverter) pin and check the appropriate value from the pin. Note that this does not require powering the Uno from external power, only connecting the grounds.

Ok. Thank you for the answer. What will happen when I power them through both USB connection and external power supply. If it selects automatically, what source will it select?

According to the schematic external power will be chosen if it's above 7.4V or so, otherwise USB power.

Only connect the grounds. Won't  that be done automatically by the Uno? (Or are you referring to the voltage divider setup?)

@AnnonomusPerson: Neither of the voltage divider nor inverter configuration require the Uno to be powered by the external supply; it is only used for sensing.

The answer may be factually correct, but it seems confusing to me (as a novice user). Is misses some summary (can I have both at the same time or no?). What is this voltage divider talk about? Do I have to use a voltage divider to have both powers at the same time, or is this an experiment to prove someting?

I am a novice user of Arduino. I am not sure whether I can connect both USB and external supply through power adaptor to Arduino simultaneously. Would this burn the controller?

Lets study the schematic of Arduino UNO R3
The input from the power supply plug (PWRIN, the power jack) goes through a diode D1 (to prevent reverse polarity), and feeds a NCP1117 regulator that down converts it to the 5v supply that feeds the 5v parts.

The alternative supply comes from the USB plug (USBVCC). The relevant circuit is shown below

The USB power lines goes through a P-mosfet (T1) that operates as a switch and then goes to the +5V node (that is the +5v regulator output as shown in the first schematic).
The mosfet is controlled by an LMV358 operational amplifier (OPAMP) that operates as a comparator.
The negative input of the opamp is tied to 3.3V and the positive one fed through a voltage divider with half the Vin supply level.

When Vin >6.6V then the + input of the opamp become higher than the - input and the opamp turns the mosfet off.
When Vin <6.6V then the + input of the opamp become lower than the - input and the opamp turns the mosfet on.

Note that Vin is after the input diode so it's about 0.6V lower than the external connected power supply level. So when there is power supply connected to the power input that is higher than 6.6V+0.6V (where 0.6V is the diode D1 voltage drop), then the USB supply line is cutoff (because the mosfet turns off) and the power is provided from the power plug. Connecting or disconnecting the USB supply in this case will not make a difference, so you can have both power supplies connected simultaneously, only when the power input drops below the specified level (about 6.6V+0.6V=7.2V), the USB will start powering the board.

+1 Excellent answer: very detailed, precise and didactic.

Note that the M7 has a nasty Vf curve; adding a few shields (or one large one) will push its Vf to 0.8V or higher.

Note that while D1 adds protection for the PWRIN pin it does not protect from eg reverse polarity on Vin.

I know this is a bit old but isn't there a danger of damaging something (your Arduino or a USB port)? For example, while plugged in to USB for serial output and using a battery pack for powering a motor shield, if your battery pack drops below 7.2V, the Arduino would try drawing all that current through USB, either destroying your board or your USB port. I know it's not the exact situation the OP was asking for but I arrived here via Google for a different situation so I think the clarification is useful. Awesome answer, by the way!

@sraboy Motor Shield uses the 5V line only for the logic circuitry  section, the motors are powered from a separate line. You describe a  situation where the motors are powered by the raw supply line Vin (7.2v battery) and the rest of the circuit from the 5V line. If the battery is depleted then the 5V of the USB with just keep powering the logic circuitry of the motor shield and Arduino, the motors would not get any power because there is no path from the 5V line (which is after the 5V regulator) to Vin (which is before the regulator).

@alexan_e I appreciate the clarification!

@alexan_e If you connect a motor to the VIN pin after the barrel plug (after the diode), won't the motor become a load to the USB if the VIN source is unplugged from the barrel plug? I think I fried the voltage regulator on my arduino in this manner.

@Mark The only path I see for the motor to become a USB load would be through the 1117 regulator (U1) that has the USB voltage connected to its output and the motor load you describe at the input Vin. I don't know if 1117 would allow current to travel in reverse from the output to the input, I haven't tested it.


text:
Arduino Yun does it have a RTC?
Does the Arduino Yun does it have a RTC?
And if so is it connected to the Atheros AR9331 or the ATmega32u4?
If there there is no RTC, can I connect a DS1307 to the Atheros AR9331?

the Yún doesn’t have a real time clock IC on board, so it can’t keep time when is powered off. Instead, it synchronizes with time servers automatically when it powers up and connects to a network using NTP.

(Arduino Blog)
Therefore, the Yun does not have a onboard RTC.

If there there is no RTC, can I connect a DS1307 to the Atheros AR9331?

Probably not. It comes in a LPCC package, which has the solder joints on the bottom. This needs to be soldered by reflow. The Yun does not have any pins connected directly to that chip. You're probably thinking of the ATmega32u4, the actual Arduino chip. The other one is for a router.
To get the time, you have two options:

Use the time from the time server
A few notes:

The Yún must be connected to a network to get the correct time. If you used the web-based WiFi interface to configure the Yún for the network, make sure you've selected the proper time zone.

Connect it to a DS1307 (I find this Adafruit tutorial helpful) You'll need only two pins to use this board. One note: there is a way to connect up to 121 I2C devices using these two pins. However, that gets a little more complicated.

I was thinking about putting some high level logic code on the Linux side and the a tight control loop on the ATMega. Therefore it would be logical to have the rtc close to the logic code.

What happens with your Arduino YUN is that it has an internal clock which sincronizes with a computer (at least this is what I do).
However I have read that it can be automatically but I could not do that; have you got a probable solution?

How is this a answer to the question?


text:
Can I compile c/c++ code on the linux part of the Arduino Yun?
Can I compile c/c++ code on the linux part of the Arduino Yun?
How complete is the linux part of the Arduino Yun?
Can I scp some c/c++ code onto the Atheros AR9331 chip compile it?
Or must I first crosscompile all software and then put them onto the Atheros?

The Yun's OS (Linino) is based on OpenWRT, and the official toolchain from OpenWRT does not appear to have changed much. It could probably be done, the question is if you'd really want to though.
The limited resources (storage, RAM, CPU) means you would most likely not fit all the parts of the toolchain for C/C++ compilation (perhaps with the exception of very basic programs without many dependencies). The YUN's package manager (opkg) should contain pre-built packackes if they exist, but given that even the list of packages is only kept in RAM to conserve space, I doubt the entire toolchain with libraries needed to compile useful stuff would fit.
The official way to build things for OpenWRT appears to be cross-compilation on a much beefier machine, if only because it takes a fraction of the time needed by a native compiler. All in all, you're also very likely to save time and resources by cross-compiling and have more resources left on the YUN itself.

https://github.com/arduino/openwrt-yun


text:
Should a delay be expected to cause deadlock?
I have made a simple program using the int main() {} function. It has a delay in it. It is evident the code before the delay is running, but the delay never seems to time out and let the next instructions through. Is this by design?
If I rename the method and call it exactly once from the loop() {} function though, it does work.
Edit:
The code borrowed the 'main()' function and I suppose redefined it:
int main() {
    Forward();
    delay(3000);
    Reverse();
}

void Forward() {
    //...
}

void Reverse() {
    //...
}

I can see this redefinition of main() could cause some serious issues based on the answer below.

We would need to see the code in question in order to give a full answer.

main() suggest this isn't normal Arduino.

Arduino programs don't use main, they use loop

What value for delay are you using? delay(999999999999999999999999999999999999999999999999); will cause a fairly large problem (if the variable even is that big). | @Cyber It must be another language/bare C. It's weird that it compiled...

First, no, delay can't deadlock, because there are no threads to deadlock on the Arduino. Second, you wouldn't be able to build a sketch containing a redefinition of main (and you don't sound experienced enough to bypass the IDE). Show the simplest code that reproduces the problem. I'm guessing the problem will be very obvious to readers here.

If you don't use Arduino standard main() then you cannot expect using Arduino functions like delay() because these rely on timer initialization performed by main().

@jippie look at my answer below, you'll see the code of delay() depends on micros() which itself is based on Timer0. At least the code is so in Arduino 1.05 libraries. You must be talking about delayMicroseconds() which is a different beast.

@jfpoilpret Why would they do that? The standard and highly optimized delay (both ms and us) routines are in the standard AVR libraries :-s /usr/lib/avr/include/util/delay.h

@jippie Why? I have no idea; they must have a good reason I guess ;-)

@jfpoilpret I think it must have changed over software releases. The delay.h version can only be passed a static parameter, whereas 'your' Arduino.h version can be passed a changing parameter. I remember from when I was a young boy that you couldn't pass a variable to delay();. With this code you obviously can.

@annon this code won't compile as delay() expects an unsigned long which is "only" 32 bits. Also the OP mentioned that it worked in setup(), I guess this was with the same duration.

You don't seem to use standard Arduino stuff since you defined your own main() which is normally avoided when programming Arduino.
If you take a look at Arduino provided main() (in hardware/cores/arduino/main.cpp), you'll see how it is defined:
#include <Arduino.h>

int main(void)
{
    init();

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

    setup();

    for (;;) {
        loop();
        if (serialEventRun) serialEventRun();
    }

    return 0;
}

Did you notice the init() function call at the beginning?
Its code is defined in hardware/cores/arduino/wiring.c; what it does is setup all timers used by Arduino functions, in particular a timer that is needed by delay().
In the same wiring.c file, you can also find the definition of delay():
void delay(unsigned long ms)
{
    uint16_t start = (uint16_t)micros();

    while (ms > 0) {
        if (((uint16_t)micros() - start) >= 1000) {
            ms--;
            start += 1000;
        }
    }
}

This will turn into an infinite loop if micros() always return the same value, and it does so if init() has never been called before.
This is what happens with your code.

This means delay(); won't work with interrupts disabled.

@jippie yes, that's why you should never call it from an ISR or a function that has disabled interrupts.

Cheers jfpoilpret, I was actually surprised when I borrowed the name main and found it was recognised same as with general c programs so I ran with it, since, I only wanted this instruction run once anyway. Your answer has given a good hint as to the architecture and I'll be able to work from there. Apologies for taking such a hack approach..!

@JCollins no need to apologize, hacking is part of learning and experience eventually :-) Glad you can proceed from here.


text:
Serial port /dev/cu.usbmodemfa131 vs /dev/cu.usbserial-A702NY8S
On Mac OSX Mavericks, why does Arduino Uno uses serial port named /dev/cu.usbmodemfa131 while Arduino Nano uses /dev/cu.usbserial-A702NY8S?
Are they using different FTDI drivers?

Which revision of the Arduino board do you have?

@AsheeshR Arduino Uno R3 and Sainsmart Arduino Nano v3

To throw another spanner in the works, have you ever noticed what happens to the serial port identifier when you put the Arduino Uno R3 into a different USB? For me 131 <--> 121. But if you change the Nano between ports, the identifier is the same!

Drivers are different. On older boards, such as Duemilanove you may need to actually download serial drivers to talk to them at all in Lion, Mountain Lion, Mavericks.
There's some discussion of that problem here.

It's really down to the manufacturer and what they identify their USB side as. I have found that Arduino(tm) provide a more meaningful (to me) identifier, eg /dev/cu.usbmodemfa131 Whilst the boards that use the FTDI chip have the more serialised numbers /dev/cu.usbserial-A702NY8S.

The Uno is not using FTDI drivers at all, since it does USB through an ATmega16u2, not an FTDI chip.