body:
I am a new user of Arduino (I have a Arduino Due) and also I am a new user of BLE112 (Bluegiga module 112)

My teacher told me to make the BLE112 advertisable and furthermore he told me to look for information about UART@115K. (The Ble112 he gave me came with wires already soldered to the selected pins: I'm assuming I only need to use those.)

    PIN NUMBER [PIN NAME] for BLE112

        2         AVDD                    (Supply voltage 2-3.6V)
        3         AVDD                    (Supply voltage 2-3.6V)
        4        [P2_2]  DC- Debug clock  (DIGITAL I/O)
        5        [P2_1]  DD- Debug data   (DIGITAL I/O)
        9        VDD_USB                  (Supply voltage 2-3.6V)
        20        DVDD                    (Supply voltage 2-3.6V)
        23       [P0_5]  RXD(Rx)          (DIGITAL I/O)
        24       [P0_4]  TXD(TX)          (DIGITAL I/O)
        25       [P0_3]  RTS              (DIGITAL I/O)
        26       [P0_2]  CTS              (DIGITAL I/O)
        29        RESET
        30         GND

I put:

    BLE pins [2,3,9,20]    to     3.3v pin of Arduino
    BLE pin  [30]          to     GND pin of Arduino

Then I found a picture (attached at the bottom of this post) that describes that I should put CTS of BLE on RTS of Arduino and vice versa. Where is the CTS on an Arduino board? I think I have to program one of the Digital pins.

I tried some other connections. I put:

    BLE pin 26(CTS)   to    Arduino random digital pin 32, and
    BLE pin 25(RTS)         Arduino random digital pin 34.

    BLE pin 24(TX)          Arduino RX pin 0
    BLE pin 23(RX)          Arduino TX pin 1

I didn't connect `DC(Debug clock)`, `DD(Debug data)` and `Reset` on the BLE112.

So then I found some more info on the web that if I use USART than I should use a wake up pin which is by the default `P0_0`(??) more about that in [this PDF][3]. (Search `wake_up`)

Now I should mention sleep mode Ble112 (there are three kinds of it) and I believe that the one I am after is MODE 3 (that means that it consumes the minimum (power) of them all)

I found some example named UART@115K

> UART@115k
This example configures the BLE112 or BLE113 Bluetooth Smart module to expose the BGAPI protocol over UART interface with the following settings: 115200 bps, 8n1 and hardware flow control enabled. The power mode 3 is enabled in this example and the wake-up pin is configured to P0_0 pin (P0_0 button on DKBLE112
and DKBLE113). When the power mode 3 is enabled the device will not be able to receive commands or data over UART unless the wake-up pin is asserted.

> The example uses UART in the pin configuration channel 1 and alternate 1, which is the configuration used in the DKBLE112 and DKBLE113 development kits.
If you try this example with DKBLE112 or DKBLE113 make sure the UART interface is enabled and the device is NOT powered with a CR2032 battery as it’s not able to power up the level shifter or UART to USB converter.

> This is also the factory default configuration for BLE112 and BLE113 Bluetooth Smart Modules.

>![Connection shown][1]

*Source: [https://bluegiga.zendesk.com/entries/22412436][2]*

  [1]: https://i.stack.imgur.com/OwjIi.jpg
  [2]: https://bluegiga.zendesk.com/entries/22412436
  [3]: https://dl.dropboxusercontent.com/u/65932667/Bluetooth_Smart_Configuration_Guide_v33.pdf

title: How do I connect Arduino to a Bluegiga112?

Answers: 4

body:
To communicate with the Arduino, it is only necessary to connect the RX and TX pins between the module and the Arduino.

Source: http://www.mkroll.mobi/?page_id=386

body: I would connect TX and RX to one of the 3 extra serial ports on the Due. Pins 0 and 1 are used for the USB-Serial communication

body:
The most popular way to establish communication between an Arduino (I've used a Duemilanove) and a BLE module (I've used BLE113 that's on a DKBLE113) is through UART.

UART is a two wire interface (don't forget the common GND) with one RX and one TX.
You can use the SoftwareSerial library to define your communication object on the Arduino.
In contrast, the BLE113 uses four. The additional two are RTS and CTS (Request To Send and Clear To Send).

However, you can configure the UART in two ways using *hardware.xml*:

 1. Go to the <*usart* > tag and set *flow = "false"*. This "disengages" the RTS and CTS allowing a traditional two wire interface.
 2. Had you set *flow = "true"*, you need to connect the RTS and CTS as well, which I had a big problem with, though the two are both digital.

Further, in *hardware.xml*, you need to disable sleep mode by including <*sleep enable="false" /*> within the <*hardware*> tag. This will solve all your problems.
If you intend to use sleep mode, you need to skip the previous step and instead govern the module's mode through the P0_0 pin. Moreover, there are additional definitions to be included in *hardware.xml*, which are documented by BG. These work nicely for the BLE112 too.

In my exercise, I'd established communication at 9600 baud. It worked the same way when I increased it to 115200 baud (this is a plus in the BLE113).

body:
Well I found another way how to make it work, you just need to put CTS from BLE on GND, and RTS open "in the air" and that's it!

You can see these on this link: https://bluegiga.zendesk.com/entries/23143152--REFERENCE-Using-or-bypassing-flow-control-with-UART-communication


body:
I would like to be able to use a USB port at the same time as an RS-232 port with my Arduino Uno board. I unwittingly bought a shield that (I think?) overrides the USB port when it is mounted to the Arduino board:

http://www.dfrobot.com/wiki/index.php/RS232_Shield

Would anyone be able to give me any advice on how to connect the hardware so that I can have two serial ports accessible from my Arduino Uno? The format I was thinking was (Arduino => RS-232 Sheild):

GND => GND
5V => 5V
Digital Pin 2 => 232RXD
Digital Pin 3 => 232TXD

The accompanying code for initializing the serial port which I've written:

    const int rxpin = 2; // pin used to receive
    const int txpin = 3; // pin used to send
    SoftwareSerial Serial_rs232(rxpin, txpin); // new serial port

Any ideas as to why this may or may not be a good method of using the hardware I have available for the purpose I had in mind?

title: How to use RS-232 sheild as software serial port?

Answers: 1

body:
> GND => GND 5V => 5V Digital Pin 2 => 232RXD Digital Pin 3 => 232TXD

A better choice of board would be the Leonardo, since you could connect such a shield *and* use the USB port right out of the box. However, since you have the Uno, there is a solution.

*From [Arduino](http://arduino.cc/en/Reference/SoftwareSerial):*

> The SoftwareSerial library has been developed to allow serial communication on other digital pins of the Arduino, using software to replicate the functionality (hence the name "SoftwareSerial"). It is possible to have multiple software serial ports with speeds up to 115200 bps. A parameter enables inverted signaling for devices which require that protocol.

It then goes on to reccomend the library [AltSoftSerial](http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html).

Here is some example code from the link above:

    #include <AltSoftSerial.h>

    AltSoftSerial altSerial;

    void setup() {
      Serial.begin(9600);
      Serial.println("AltSoftSerial Test Begin");
      altSerial.begin(9600);
      altSerial.println("Hello World");
    }

    void loop() {
      char c;

      if (Serial.available()) {
        c = Serial.read();
        altSerial.print(c);
      }
      if (altSerial.available()) {
        c = altSerial.read();
        Serial.print(c);
      }
    }

It acts like a standard serial port, only you declare the connection as a variable first. This code is written for a board with an additional serial port, like you have.

## All is good, except for one problem:

The problem is the shield is wired to connect to pins 0 and 1: the ones used by the USB adapter. The AltSoftSerial library uses pins 8 for TX and 9 for RX. (Note: You cannot use PWM on pin 10 on the Uno... it should still work as a digital pin.) In that case you would **not attach the shield by plugging it into the Arduino**, and you would wire it like this:

> GND => GND | 5V => 5V | Digital Pin 8 => 232RXD pin 0 on the shield headers | Digital Pin 9 => 232TXD 1 on the shield headers

So then, you would be manually wiring the shield to the Arduino with jumpers. As long as it doesn't connect to any other Arduino pins I'm not aware of (it shouldn't besides maybe 13 for a LED or something like that), it should function like it would stacked and using pins 0 and 1.

Note: (Obviously) You cannot connect anything to the headers on the shield (You cannot connect to pin 5 and get a signal).


body:
new to arduino I'm struggling with what sounds like fairly n00b problem...
I've wired up a adafruit GPS-board to my Arduino and it is working as it spits out GPS data to the serial port with `Serial.print(GPS.latitude, DEC)`

I Now want to concat a string which I can process (read: I want to sent it via an ethernet client.)
This is what I got already:

    ......
    String vnnt = "$VNNT,";

    if (GPS.fix) {
       vnnt += "GPS,";

       //this works:
       vnnt.concat(GPS.fix);

       //but this not:
       vnnt.concat(GPS.latitude);

    }else{
       vnnt += "INFO,Acquiring Sats";
    }

    Serial.println(vnnt);

The error message is: `Call of overloaded 'concat(float&)' is ambiguous`
When I `Serial.print(GPS.latitude, DEC)` it results in: `4418.5937996050`

So it is probably to big or something...

**How can I concat the vars and create the long string?**

title: How to build (concat) a string with big numbers

Answers: 1

body:
The concat function does not implement a float version, but some of char, int, unsigneds...

    unsigned char String::concat(long unsigned int)
    unsigned char String::concat(unsigned int)
    unsigned char String::concat(int)
    ...

 so the compiler does not know how to cast (truncating probably the float) to integer, as there are several options.

You have to convert first your float to string, use dtostrf() or sprintf() then concat to your string.

    char outstr[25];
    sprintf(outstr, "%f", GPS.latitude);
or

    dtostrf(GPS.latitude, 6, 2, outstr);  //check docs for 6, 2 values, and set them for your needs

And then:

    vnnt.concat(outstr)

Also note that sprintf is very handy for compact creation of a (char) string:

    char msg[80];
    sprintf(msg, "$VNNT,GPS, %s %f", GPS.fix, GPS.latitude);


body:
I've been looking for a while inside Arduino's files to find the core library. However, I haven't found them yet. **Where on my hard drive can I obtain the core library files (.cpp and .h) necessary for all Arduino code?**

Looking around on Google, I couldn't find a way to find the above files. I did see something about getting an .a file while Arduino is compiling, however, that isn't what I want. I want to browse the code and look at functions such as delay to see how they would react when given the values not expected. (i.e. Will my code stall if I use `delay(-200);` by not being to exit the loop, or will it create a black hole and disrupt the space-time continuum?)

title: How can I get the source files for Arduino libraries?

Answers: 6

body: The base Arduino source files are in the Arduino installation, under [`cores/arduino/`](https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino). Source for additional libraries included are in [`libraries/`](https://github.com/arduino/ArduinoCore-avr/tree/master/libraries).

body:
On a Mac, the path to the source code folder is:<br>
`Arduino.app/Contents/Resources/Java/Hardware/Arduino/Cores/Arduino`. I'd expect it would be the same from `/Java/` on down in other OSes.

![Path to library sources (Arduino-Mac)][1]

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

body:
The code is also available online for those times you don't have the IDE installed:

https://github.com/arduino/Arduino

body:
There are multiple places where you can look. As at IDE 1.6.4 (Ubuntu version) some are in:

    (install location)/libraries

But these are the high-level libraries, in particular:

    Bridge
    Esplora
    Ethernet
    Firmata
    GSM
    LiquidCrystal
    Robot_Control
    RobotIRremote
    Robot_Motor
    SD
    Servo
    SpacebrewYun
    Stepper
    Temboo
    TFT
    WiFi

---

That does not cover the low-level libraries like Tone, Print, main, etc. These are in:

    (install location)/hardware/arduino/avr/cores/arduino

There you would find the Arduino core libraries like:

    abi.cpp
    Arduino.h
    binary.h
    CDC.cpp
    Client.h
    HardwareSerial0.cpp
    HardwareSerial1.cpp
    HardwareSerial2.cpp
    HardwareSerial3.cpp
    HardwareSerial.cpp
    HardwareSerial.h
    HardwareSerial_private.h
    HID.cpp
    hooks.c
    IPAddress.cpp
    IPAddress.h
    main.cpp
    new.cpp
    new.h
    Printable.h
    Print.cpp
    Print.h
    Server.h
    Stream.cpp
    Stream.h
    Tone.cpp
    Udp.h
    USBAPI.h
    USBCore.cpp
    USBCore.h
    USBDesc.h
    WCharacter.h
    WInterrupts.c
    wiring_analog.c
    wiring.c
    wiring_digital.c
    wiring_private.h
    wiring_pulse.c
    wiring_shift.c
    WMath.cpp
    WString.cpp
    WString.h

---

However even that does not locate things like strcpy. The **header** files for them can be found at:

    (install location)/hardware/tools/avr/avr/include/

There you will find:

    alloca.h
    assert.h
    ctype.h
    errno.h
    inttypes.h
    math.h
    setjmp.h
    stdfix-avrlibc.h
    stdint.h
    stdio.h
    stdlib.h
    string.h

---

Even that is not the full story. In a subdirectory (avr) you will find the avr-related things, with files for different processors, such as (in part):

    boot.h
    builtins.h
    common.h
    cpufunc.h
    crc16.h
    delay.h
    eeprom.h
    fuse.h
    interrupt.h
    io1200.h
    io2313.h
    ...
    iox64d4.h
    iox8e5.h
    lock.h
    parity.h
    pgmspace.h
    portpins.h
    power.h
    sfr_defs.h
    signal.h
    signature.h
    sleep.h
    version.h
    wdt.h
    xmega.h

---

As for the source of strcpy, I don't think it is in the distribution. They include the standard libraries, pre-compiled. For example, if you look in:

    (install location)/hardware/tools/avr/avr/lib

You will see various pre-compiled libraries, for example:

    libc.a
    libm.a
    libprintf_flt.a
    libprintf_min.a
    libscanf_flt.a
    libscanf_min.a

To find the source you would need to find where the AVR source of libc is (possibly at <http://www.nongnu.org/avr-libc/>).

---

As for the Mac, all this stuff is a few levels down in the "Application Package" which you can view by right-clicking and selecting "Show Package Contents". Look in the `Contents/Resources/Java` folder.

---

**None** of these places are where you should put your **own** libraries (ones you write or download). They should go into the `libraries` folder which is a subdirectory of your `sketchbook` folder. Create the `libraries` folder if it does not exist. That way user-installed libraries persist from one version of the IDE to the next.

body:
The arduino source files can be found on Github at [https://github.com/arduino/Arduino][1], however the libraries [have been moved][2] to their own repositories:

* https://github.com/arduino/ArduinoCore-avr
* https://github.com/arduino/ArduinoCore-sam
* https://github.com/arduino/ArduinoCore-samd

  [1]: https://github.com/arduino/Arduino
  [2]: https://github.com/arduino/Arduino/tree/master/hardware#cores-have-been-moved

body: I think this may have changed in newer versions. On my Mac Big Sur, Arduino 1.8.15 they are here: `/Applications/Arduino.app/Contents/Java/libraries`


body:
I am using the arduinconnector ANE to connect to an arduino baord in an AIR application. https://code.google.com/p/as3-arduino-connector/

Can anyone tell me if its possible to connect to more than 1 board, simply by instantiating additional instances of the ANE and passing in unique port #'s?

Or is there some reason why this isn't possible and a unique AIR application is required for every arduino you connect to?

title: Connect to more than one Arduino with Adobe AIR

Answers: 1

body:
This seems to be possible with `as3Glue` as per the [docs][1]:

> as3Glue is an ActionScript 3 library that enables communication between Flash/Flex/AIR applications and Arduino boards. **It can together with one or several Arduino boards** be used to monitor sensors (such as rotary encoders and motion detectors), control actuators (such as LEDs and motors) and interface other electronics (such as RFID readers) from Flash, Flex and AIR applications.

`as3Glue` can be used with `as3-arduino-connector` as mentioned in the [docs][2]:

>Using with as3Glue
>
>Download either the SWC or Source Code from the Downloads section of this project for a patched version of as3Glue. This patched version has the exact same interfaces as v20, with a notable exception of the constructor. When you instantiate a new "Arduino" object, replace the IP address and port with the COM port and baud rate. For example :
>
>    public var myArduino:Arduino = new Arduino("COM10", 57600);

  [1]: https://code.google.com/p/as3glue/
  [2]: https://code.google.com/p/as3-arduino-connector/


body:
I have an Arduino Mega 2560 and it was working fine until about lunch time when I started getting this error:

    avrdude: stk500v2_ReceiveMessage(): timeout
    avrdude: stk500v2_getsync(): timeout communicating with programmer

I know it isn't the code I'm running as I tried to load it onto an Uno and it seemed to load without issue. I need to use the Mega as it has more ports, though.

From what I have read this is potentially an issue with the bootloader and is possibly related to the current version of Arduino. I know virtually nothing about the bootloader; all I know is that it is used to upload code to the Arduino (I think...), therefore I have a fear of just messing around with related files unknowingly.

These pages are the ones I've been looking at, but like I said, I don't really know enough to feel comfortable with just messing around with the files.

 - [Mega2560: timeout communicating with programmer....][1]
 - [Upload Timeout Error on Mega 2560 - Not Sure What Changed][2]

I tried uninstalling my Mega totally, then reinstalling it. I also downloaded an older version of Arduino (0022) and neither option seemed to work.

I don't know what to do, or how to change the 'AVR' files if necessary.

  [1]: http://forum.arduino.cc/index.php?topic=135451.0
  [2]: http://forum.arduino.cc/index.php/topic,83079.msg659993.html#msg659993

title: Arduino Mega timeout communication with programmer error

Answers: 3

body:
The bootloader on an arduino is just a piece of software written to enable you to update your sketches using the usb connection. Without the bootloader you can't upload sketches using just the arduino ide.

More information about the bootloader can be found here: http://arduino.cc/en/Guide/Environment?from=Tutorial.Bootloader
Look under the heading entitled uploading which explains the part the bootloader plays in uploading sketches.

When you use the "Burn Bootloader" button in the arduino ide it will attempt to write a new copy of the bootloader onto the attached Arduino board. To do this the board must be attached in a specific manner - that is - using the icsp/isp header rather than the usb cable.

Now to program the avr chip directly you have to use an external (hardware) programmer. Fortunately you don't have to buy one if you have a second arduino because the second arduino can be used as a programmer. Instructions for doing so can be found here: http://arduino.cc/en/Tutorial/ArduinoISP

Even more info about the bootloader: http://arduino.cc/en/Hacking/Bootloader?from=Main.Bootloader

body:
Unfortunately this error refers to many different issues and there are so many posts here and on other platforms none with a definite answer. Maybe Arduino team should try to give better errors to differentiate. But I have tried to answer the same question here in this [SO post][1].

what solved my issue was to go to Tools>Boards>Board Manager... select "updatable" for "Type" on top left and then select the updatable packages below and click on update.

  [1]: https://stackoverflow.com/questions/19645441/avrdude-stk500v2-receivemessage-timeout/45167540#45167540

body: I got this same error when my Arduino COM port was busy with other apps. I closed that app and upload Arduino sketch and error disappeared.


body:
When messing around with code and uploading a sketch to my Arduino board, I almost accidentally pulled out the USB cord. Everything is fine, but then I started thinking what would've happened if I had pulled it out.

How safe is avrdude? Could it damage or brick the board? I'd imagine that you would just have to upload code to it again... but what would happen before you upload the new code? I've seen something about how you can always upload new code if the bootloader is intact, but I would imagine that there would be some problems. If this were to happen, should I unplug everything connected in case Arduino writes a HIGH to an input (or similar) that would damage the component?

title: Can I corrupt my Arduino if it's unplugged during an upload?

Answers: 3

body:
It should be fine.

Most boards don't require you to reupload the bootloader every time you upload a sketch, so your program will be corrupted but your bootloader won't. I assume the bootloader is similar to the bootloader on other chips I have seen*, it will stop execution if the code doesn't work properly. I would also think that the micro would not accept a transmission if it's checksum is missing.

I wouldn't try it if I were you, but you can be a little less cautious about this sort of thing.

\*: the Propellor chip, among others

body:
AVRDUDE does not actually *perform* the write, it merely *directs* it. The actual writes are performed either by the bootloader or by the ISP firmware/hardware within the MCU itself.

With the bootloader it depends on how itself is coded, but at worst it would finish off the flash byte or page or EEPROM page zero- or one-filled and then fail to communicate further with AVRDUDE, aborting programming.

With ISP, the page write command would never be received and the programming would be aborted at the last full page. Fuse bytes are done singly and so programming a single fuse can be viewed as an atomic operation.

In either case, a chip erase operation should reset the MCU to a known working state, fuse changes excepted.

body:
One safety feature that hasn't been mentioned so far is that the ATmega328 has a set of lock bits that prevent read/write access to certain areas. To the best of my knowledge, the way Arduinos are set up, those bits are always set to prevent writing to the boot loader area unless the "Burn Bootloader" command is currently active, and since you can only use that command with an external programmer, you can always write a new bootloader if something goes wrong.

I think the only way of bricking the board (in the sense of leaving the MCU in a state that is functional, yet almost irrepairably unresponsive) is writing bad fuse settings.


body:
I've been browsing Aliexpress and eBay for decent Arduino enclusures, but I've found out they are even pricier then boards themselves.

Then I've realized that there are multiple firms that offer cheap laser cutting - I can buy 1 sq.m acrylic sheet and order cutting multiple parts of boxes at once.

Obviously I am not the first one who came up with this idea. Has anyone seen downloadable vector layouts I can use as something to start from? Thanks.

title: Acrylic enclosure for Arduino

Answers: 1

body: Making your own is quite possible, especially if you own a router (or even better a router table). You need a V shaped 90 degree router bit, a tube of proper perspex glue and some acrylic sheet. The glue is hard to find, but plastic sign manufacturers generally will sell it. Unless you are a DIY expert, I suggest the gap filling type of glue rather than the watery product that only fills perfectly matched surfaces. Try searching Youtube on "acrylic box making". There are several videos. My first two efforts were pretty bad, but the last couple are fine, and are of course exactly the right size.


body:
The Arduino boards provide an analog input range of 0V to 5V which translates to 0 to 1023 integer values. The range is determined by the on-board ADC, which in the case of the Uno is a 10 bit ADC (2^10 = 1024).

Do any of the official boards have a larger (>10 bits) ADC? Do any boards provide a wider range of analog input values?

title: Does any board provide more than 1024 analog input values?

Answers: 3

body: AVR-based Arduinos only have 10-bit ADCs, but the ATSAM3X in the Due has 12-bit ADCs. Additionally, it is possible to interface to higher-resolution external ADCs via I2C or SPI.

body:
How much accuracy do you really need? If it's just 1 or 2 extra bits of resolution you are after, you might be able to achieve that with a bit of oversampling.

Basically, you take a ton of readings and average them. It only works if there is at least a few mV of random noise in your signal or in your ADC, and if your input signal bandwidth is low enough to be averaging samples together.

Otherwise, go with a dedicated ADC chip.

body: They all do with oversampling. You can evaluate the quality of doing this for your own use.


body:
Using an [Arduino Nano][1] and a [current transformer ][2] (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.

![Enter image description here][3]

**`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.

![Enter image description here][4]

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][5] 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?

![Enter image description here][6]

    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);
            }
        }
    }

  [1]: http://arduino.cc/en/Main/ArduinoBoardNano
  [2]: http://www.seeedstudio.com/depot/Noninvasive-AC-Current-Sensor-30A-max-p-519.html
  [3]: https://i.stack.imgur.com/tgpsQ.png
  [4]: https://i.stack.imgur.com/2Gdcc.png
  [5]: http://www.arduino.cc/en/Tutorial/Sketch
  [6]: https://i.stack.imgur.com/Wjw7T.png

title: Reading a varying voltage into Arduino

Answers: 2

body:
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][1])

![http://www.nlvocables.com/blog/?p=300][2]

You will need to calculate RMS values and it would be wise to filter the signal.

[Here's an instructable][3] 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.

  [1]: http://www.nlvocables.com/blog/?p=300
  [2]: https://i.stack.imgur.com/oAAF2.gif
  [3]: http://www.instructables.com/id/Yun-based-Electricity-Monitor-with-Cloud-Support-T/

body: 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.


body:
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?

title: Pressure transducer / sensor (0.5 - 4.5V) innacurate analog pin readings

Answers: 1

body:
> 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?


body:
>

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

# Update: Winners Announced
The winners of the contest have been announced. Please see the [Meta post for details][3].

To celebrate [10 years of Arduino][4], 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][5]

# 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][6] 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][7] 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.

  [1]: http://arduino.cc/en/Trademark/HomePage?from=Main.Trademark
  [2]: http://creativecommons.org/licenses/
  [3]: https://arduino.meta.stackexchange.com/questions/184/project-showcase-14-winners
  [4]: http://day.arduino.cc/
  [5]: https://arduino.meta.stackexchange.com/questions/153/project-showcase-14-is-coming-to-arduino-stack-exchange-updated-3-19-14
  [6]: https://arduino.meta.stackexchange.com/questions/171/project-showcase-14-detailed-information
  [7]: http://fritzing.org/home/
  [8]: http://fritzing.org/home/

title: Project Showcase '14

Answers: 14

body:
# 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][1]<br>
* [Arduino Library][2]

![Schematic][3]
![OSH Park render][4]
![Unsoldered Board][5]

# 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.

  [1]: http://oshpark.com/shared_projects/LKBJyhOP
  [2]: https://github.com/jamolnng/Arduino/tree/master/libraries/ShiftLCD
  [3]: https://i.stack.imgur.com/3nETo.png
  [4]: https://i.stack.imgur.com/aXSfc.png
  [5]: https://i.stack.imgur.com/DqIuw.jpg

body:
# 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][1] 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.

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

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

<!-- End schematic -->

# 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][2]. 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).

  [1]: https://en.wikipedia.org/wiki/Photoresistor
  [2]: http://www.obdev.at/products/vusb/index.html

body:
# <small>(fake)</small> 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
---

![zoomed out pic][1]

![clse up screen][2]

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 `if`s 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.

  [1]: https://i.stack.imgur.com/cgzPU.jpg
  [2]: https://i.stack.imgur.com/L9PmB.jpg

body:
# 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.

body:
# 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

![enter image description here][1]

### 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][2], (one fried)
     - [4 wheel motors][3], (24v, 360mA with no load)
     - 4 wheels, (plastic jar lids)
 - [Easy Button][4]
 - Arm:
     - [Servo][5], (continuous rotation)
     - [Motor driver][6], (fried)
     - Motor, (12v, found in teacher's junk pile)
     - Eraser
     - Counterweight, (homemade paper bag filled with pennies)
 - [2 battery packs][7], (12V, 1300mAh, Ni-MH rechargeable)
 - 2 solderless breadboards
 - Laser, (5mW)
 - Bluetooth:
     - [mdfly Bluetooth module][8], (5v, 30ft)
     - [Bluetooth adapter][9], (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

![enter image description here][10]
![enter image description here][11]

### 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.

  [1]: https://i.stack.imgur.com/w7Gs6.png
  [2]: http://www.pololu.com/product/2136/
  [3]: http://www.allelectronics.com/make-a-store/item/dcm-395/3-24vdc-gear-motor-used/1.html
  [4]: http://www.staples.com/Easy-Button/cat_CL163314
  [5]: http://www.parallax.com/product/900-00008
  [6]: http://www.pololu.com/product/2136/
  [7]: http://compare.ebay.com/like/140474546940?var=lv&ltyp=AllFixedPriceItemTypes&var=sbar
  [8]: http://www.mdfly.com/index.php?main_page=product_info&cPath=&products_id=769&zenid=2qgknl98q9kppt6q14hk70rlr3
  [9]: http://www.aziocorp.com/en/connectivity/16-usb-micro-bluetooth-adapter-v21-edr.html
  [10]: https://i.stack.imgur.com/XoTWl.png
  [11]: https://i.stack.imgur.com/pWIw8.jpg

body:
# 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](http://antoinettejcitizen.files.wordpress.com/2011/03/piezo.jpg) 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
![Photo][1]
*Image taken with webcam hanging over monitor... eek!*

![Fritzing Diagram][2]

**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.

  [1]: https://i.stack.imgur.com/KxflQ.png
  [2]: https://i.stack.imgur.com/yScgU.png

body:
# Stateful questbox
**A [GPS][1] powered box that makes you visit a few spots before opening**

# Description
It is similar to [questbox][2], but it stores a small amount state of information in [EEPROM][3], so you have to visit two or three different places before it opens.

# Design

Needed hardware:

* [Arduino Uno][4]
* 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][5] (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][6]

Inspiration:![Original questbox][7]

# 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](http://forum.arduino.cc/index.php/topic,64596.0.html)

  [1]: http://en.wikipedia.org/wiki/Global_Positioning_System
  [2]: https://www.sundial.com/
  [3]: http://en.wikipedia.org/wiki/EEPROM
  [4]: http://arduino.cc/en/Main/ArduinoBoardUno
  [5]: https://www.sundial.com/quest-box/notes-for-builders/
  [6]: https://www.biicode.com/hithwen/blocks/hithwen/statemachine/branches/master#.UzSTlmR5NUk
  [7]: https://i.stack.imgur.com/864pF.jpg

body:
![MySensors][1]

*- 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.
![Arduino + NRF24L01+][2]

1. 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.

![The sensor network][3]

In the middle you place an Arduion or Raspberry gateway that collects the information from your sensors.
![Raspberry Controller][4]

![Arduino Gateway][5]

# 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.
![enter image description here][6]

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.

![Hello][7]

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.

  [1]: https://i.stack.imgur.com/UKSL4.png
  [2]: https://i.stack.imgur.com/VfWYX.png
  [3]: https://i.stack.imgur.com/ETVDA.png
  [4]: https://i.stack.imgur.com/s8GkQ.jpg
  [5]: https://i.stack.imgur.com/35AcP.jpg
  [6]: https://i.stack.imgur.com/DE5oE.jpg
  [7]: https://i.stack.imgur.com/VYgX4.png

body:
**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!

![Controller Image 1][1]
![Controller Image 2][2]

  [1]: https://i.stack.imgur.com/yYGiv.jpg
  [2]: https://i.stack.imgur.com/raCwl.jpg

body:
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](https://www.u-blox.com/de/lea-6t.html) 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!
![enter image description here][1]
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.

---

![enter image description here][2]
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.

---

![enter image description here][3]
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.

---

![enter image description here][4]
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.

---

![enter image description here][5]
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!
![enter image description here][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.

![enter image description here][7]
And bonus Nyan-Cat!

![enter image description here][8]

(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 systems/
(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.

  [1]: https://i.stack.imgur.com/Zt8N8.jpg
  [2]: https://i.stack.imgur.com/m40P9.jpg
  [3]: https://i.stack.imgur.com/PjfGb.jpg
  [4]: https://i.stack.imgur.com/18PyD.jpg
  [5]: https://i.stack.imgur.com/qLfpS.jpg
  [6]: https://i.stack.imgur.com/zdher.jpg
  [7]: https://i.stack.imgur.com/fdMJZ.jpg
  [8]: https://i.stack.imgur.com/lJSUA.png

body:
# 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:

![3d mockup of the Serial Box design][1]

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][2] 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.

![Preliminary circuit layout][3]

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.

![The prototype in action][4]

# 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! :)

  [1]: https://i.stack.imgur.com/m8Les.jpg
  [2]: https://github.com/avid-insight/LiquidCrystalEAX
  [3]: https://i.stack.imgur.com/plAfe.png
  [4]: https://i.stack.imgur.com/9xlB6.jpg

body:
# 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).

![display board with counter][1]

# 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][2] 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!

![Board Schematic][3]

During my tests, I have found a useful [Arduino library for working with MAX-7219][4] which I decided to reuse. I have built my [own library][5] 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][6] 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:

![STRIPBOARD DESIGN #1][7]

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:

![STRIPBOARD DESIGN #2][8]

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

![PICTURE][9]

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

  [1]: https://i.stack.imgur.com/XAvXo.png
  [2]: http://datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf
  [3]: https://i.stack.imgur.com/PnB3n.jpg
  [4]: http://playground.arduino.cc/uploads/Main/LedControl.zip
  [5]: https://github.com/jfpoilpret/arduino-libraries/tree/master/DisplayDriver
  [6]: http://www.abacom-online.de/uk/html/lochmaster.html
  [7]: https://i.stack.imgur.com/iE37V.png
  [8]: https://i.stack.imgur.com/3dTgz.png
  [9]: https://i.stack.imgur.com/MiLnL.jpg

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

![enter image description here][1]

# 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:

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

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

![enter image description here][4]
![enter image description here][5]
![enter image description here][6]

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.

![enter image description here][7]

# 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:

1. 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.

1. Crimping KK molex and modu connectors takes A LOT OF TIME!!

1. Laser cut acrylic pieces are the future. They add a lot of quality to the device even if you are clumsy.

  [1]: https://i.stack.imgur.com/T0XE7.jpg
  [2]: https://i.stack.imgur.com/TAqPM.png
  [3]: https://i.stack.imgur.com/yIV4x.png
  [4]: https://i.stack.imgur.com/tnZ5K.jpg
  [5]: https://i.stack.imgur.com/7AtQ4.jpg
  [6]: https://i.stack.imgur.com/r6aQR.jpg
  [7]: https://i.stack.imgur.com/iicCN.jpg

body:
# 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,

![behind TV][1]
![Arduino w/ IR receiver up front][2]
![Close up of box and bearing][3]
![Swiffer handle][4]
![These two buttons don't do anything on the TV anyways][5]

# 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.

  [1]: https://i.stack.imgur.com/KyUOA.jpg
  [2]: https://i.stack.imgur.com/4q8mv.jpg
  [3]: https://i.stack.imgur.com/t4len.jpg
  [4]: https://i.stack.imgur.com/n80OR.jpg
  [5]: https://i.stack.imgur.com/hAevo.jpg

Edit:  sorry about the picture being sideways!  It's right side up on my computer, I have no idea why it's sideways online.


body:
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][1] 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?

  [1]: http://www.digikey.com/product-detail/en/LM324N/296-1391-5-ND/277627
  [2]: http://www.ebay.com/itm/SOP14-SSOP14-TSSOP14-to-DIP14-PCB-SMD-to-DIP-Adapter-plate-Pitch-0-65-1-27mm-/231183888806?pt=LH_DefaultDomain_0&hash=item35d3a231a6

title: Opamp for amplifying 1V signal voltage to 2V

Answers: 2

body:
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.

body:
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/#$+1+5.0E-6+81.92041607667615+50+5.0+50
r+304+160+304+224+0+1000.0
r+304+224+304+304+0+5000.0
R+304+304+256+304+0+0+40.0+5.0+0.0+0.0+0.5
R+304+160+208+160+0+1+40.0+1.0+0.0+0.0+0.5
w+304+224+400+224+0
x+368+208+456+214+0+24+To+ADC
o+3+64+0+35+2.5+0.00625+0+-1
o+4+64+0+35+2.5+9.765625E-5+1+-1

Left click the output, use view in scope.


body:
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:

![breadboard wiring][1]

[Link to product](https://www.foxytronics.com/products/181-4-pin-female-to-female-cable)

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!

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

title: Ultrasonic Sensor scanning too often resulting in a whirring noise

Answers: 1

body:
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;


body: 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?

title: Is there a way to make wiring a bare microprocessor to a shield easier?

Answers: 2

body:
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.

body:
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

![enter image description here][1]

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](http://forum.arduino.cc/index.php/topic,146315.0.html))
![enter image description here][2]

Another similar solution is a small printed sticker placed on top of the AVR
([image source](http://makezine.com/2011/01/12/free-print-and-stick-pinout-label-f/))

![enter image description here][3]

  [1]: https://i.stack.imgur.com/LdseD.jpg
  [2]: https://i.stack.imgur.com/gNAJG.png
  [3]: https://i.stack.imgur.com/AMuWs.jpg


body:
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

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

    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);
    }

title: Reading three signals sent serially on Simulink from Arduino

Answers: 1

body:
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:
<!-- language-all: lang-cpp -->

    Serial.write(sensorValue1, sensorValue2, sensorValue3);

However, as you can see from the [Serial Write documentation][1] it does not work like that. The function cannot accept 3 arguments.

Try this instead:

    Serial.write(sensorValue1);
    Serial.write(sensorValue2);
    Serial.write(sensorValue3);

  [1]: https://www.arduino.cc/reference/en/language/functions/communication/serial/write/


body:
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?

title: How to find out whether an arduino can control a servo motor

Answers: 2

body:
An Uno most definitely cannot directly control that motor. According to the specs [here][1],

> 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.

  [1]: http://arduino.cc/en/Main/ArduinoBoardUno

body:
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.