text:
Code for four road junction
This is the Arduino code for a four road junction. In the below code, the if case must be tested after every road without delay. Can any one guide me?
int redLed1 = 7;
int yellowLed1 = 6;
int greenLed1 = 5;
int redLed2 = 4;
int yellowLed2 = 3;
int greenLed2 = 2;
int redLed3 =8 ;
int yellowLed3 =9;
int greenLed3 =10;
int redLed4 = 14;
int yellowLed4 = 15;
int greenLed4 =16;
int THRESHOLD=700;
int soundvalue=0;
void setup()
{
    pinMode(redLed1, OUTPUT);
    pinMode(yellowLed1, OUTPUT);
    pinMode(greenLed1, OUTPUT);
    pinMode(redLed2, OUTPUT);
    pinMode(yellowLed2, OUTPUT);
    pinMode(greenLed2, OUTPUT);
    pinMode(redLed3, OUTPUT);
    pinMode(yellowLed3, OUTPUT);
    pinMode(greenLed3, OUTPUT);
    pinMode(redLed4, OUTPUT);
    pinMode(yellowLed4, OUTPUT);
    pinMode(greenLed4, OUTPUT);
}

void loop()
{
    digitalWrite(redLed2,HIGH);
    digitalWrite(redLed3,HIGH);
    digitalWrite(redLed4,HIGH);
    digitalWrite(redLed1,HIGH);
    digitalWrite(yellowLed1,HIGH);
    delay(5000);
    digitalWrite(redLed1,LOW);
    digitalWrite(yellowLed1,LOW);
    digitalWrite(greenLed1,HIGH);
    if(analogRead(A0)>=THRESHOLD)
    {
        digitalWrite(greenLed2,LOW);
        digitalWrite(greenLed1,HIGH);
        delay(10000);
        digitalWrite(greenLed1,LOW);
    }
    delay(30000);
    digitalWrite(greenLed1,LOW);
    digitalWrite(redLed1,HIGH);
    digitalWrite(yellowLed2,HIGH);
    delay(5000);
    digitalWrite(redLed2,LOW);
    digitalWrite(yellowLed2,LOW);
    digitalWrite(greenLed2,HIGH);

    delay(30000);
    digitalWrite(greenLed2,LOW);
    digitalWrite(redLed2,HIGH);
    digitalWrite(yellowLed3,HIGH);
    delay(5000);
    digitalWrite(redLed3,LOW);
    digitalWrite(yellowLed3,LOW);
    digitalWrite(greenLed3,HIGH);

    delay(30000);
    digitalWrite(greenLed3,LOW);
    digitalWrite(redLed3,HIGH);
    digitalWrite(yellowLed4,HIGH);
    delay(5000);
    digitalWrite(redLed4,LOW);
    digitalWrite(yellowLed4,LOW);
    digitalWrite(greenLed4,HIGH);
    delay(30000);
    digitalWrite(greenled4,LOW);

    }
}

It's hard to tell what you're asking. Can you edit your question to explain it more clearly please?

I'm not sure what a “road” condition is, so I don't know where the “after every road” points in your code are located.  However, you can write a properly-parameterized function to do tests, or a subroutine to do tests and perform actions.  Then place a function or subroutine call whereever you need to perform the test.
Note, the first 14 lines of your code (which define 14 variables that you probably should have defined as constants) could be replaced by an enum statement (which defines integer constants) like
enum { redLed1=7, yellowLed1=6, greenLed1=5, redLed2=4, yellowLed2=3, greenLed2=2, redLed3=8, yellowLed3=9, greenLed3=10, redLed4=14, yellowLed4=15, greenLed4=16, THRESHOLD=700, soundvalue=0 };

or (because enum will advance by 1 unit when a value isn't specified) you could say
enum { greenLed2=2, yellowLed2, redLed2, greenLed1, yellowLed1, redLed1, redLed3, yellowLed3, greenLed3, redLed4=14, yellowLed4, greenLed4, THRESHOLD=700, soundvalue=0 };

For a short sketch like this, the compiler can detect that some of your variables actually are constants, but in general using constants as constants and variables as variables will produce smaller and safer code.

NOTE: all the code below is thrown together; it is there to show you what to do. It will probably require some fixing before it works. The intent should be clear.
From what I read in your code, mostly what you are doing is setting the traffic lights in particular combinations, several times over, with delays in between.
In general, any time you do the same thing, conceptually, several times, it should either be in a loop, or in a function.
In this case, the first thing that (to me) looks like it belongs in a function is: set all the lights in a particular pattern, and wait for a while. I would call this function something like set_lights_and_delay (or, perhaps setLightsAndDelay depending on your coding style). It would take 5 parameters: the state of each light (red, green, or yellow/red, which I would just call yellow), and the time to delay (which may be 0). In this function, you would set ALL the pins, high or low, as appropriate (since your function shouldn't assume the previous state), then delay the appropriate amount of time.
enum colors {yellow, red, green, yellowred};

void loop()
{
    set_lights_and_delay(yellow,red,red,red,5000);
    if(analogRead(A0)>=THRESHOLD)
    {
      set_lights_and_delay(green,red,red,red,40000);
    } else {
      set_lights_and_delay(green,red,red,yellowred,30000);
    }

... and so forth (or whatever light combinations you want).
Now, how would you write this function? This function does the same thing for each light, so it sounds to me like you would want to make a function that takes a color, and the 3 pins to use:
void setLightsAndDelay(color northlight, eastlight, westlight, southlight; int delaytime)
{
    setOneLight(northlight, redLed1, yellowLed1, greenLed1);
    setOneLight(eastlight, redLed2, yellowLed2, greenLed2);
    setOneLight(westlight, redLed3, yellowLed3, greenLed3);
    setOneLight(southlight, redLed4, yellowLed4, greenLed4);
    delay(delaytime);
}

Now, setOneLight is pretty simple to write:
void setOneLight(color thisLight; int redled, yellowled, greenled)
{
    if (thisLight==green) // always do the easiest one first.
    {
        digitalWrite(greenled,HIGH);
    } else {
        digitalWrite(greenled,LOW);
    }

    if (thisLight==yellow) || (thislight==yellowred)
    {
        digitalWrite(yellowled,HIGH);
    } else {
        digitalWrite(yellowled,LOW);
    }

    if (thisLight==red) || (thisLight==yellowred)
    {
        digitalWrite(redled,HIGH);
    } else {
        digitalWrite(redled,LOW);
    }
}

In practice, there would be a lot of other things I'd do: I'd put all the things I know about a single traffic light into a struct; this means I could pass the struct to a function, in one go. I'd put the four traffic lights in an array; this means I could go through them in a loop, rather than calling the same function 4 times individually (great when your city ends up with 1,000 traffic lights!). I would probably put the pattern of lights (green/30000, yellow/10000, red/30000, yellowred/10000) into an array (made a little more difficult by the sensor).


text:
Attiny85 with arduino as ISP
After serveral attempts, I can't make my arduino UNO to program an attiny85, no matter what I do. I've tried under windows 7 and also under ubuntu 14.04, to no avail. I've followed instructions on hi low tech site and similar ones on arduino site. Even some youtube video. Nothing. The wiring of my arduino is as described in those sites, so it should be correct. I'm using the 10uF capacitor too.
This is the output running avrdude manually, extra verbose:
    zop@mikasa:~$ sudo /usr/share/arduino/hardware/tools/avrdude -C/usr/share/arduino/hardware/tools/avrdude.conf  -q -pattiny85 -cstk500v1 -P/dev/ttyACM0 -b19200 -Uflash:w:/tmp/build2861466093518309047.tmp/Fade.cpp.hex:i -v -v -v -v -v -v -v -v

    avrdude: Version 6.0.1, compiled on Oct 21 2013 at 15:55:32
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2009 Joerg Wunsch

             System wide configuration file is "/usr/share/arduino/hardware/tools/avrdude.conf"
             User configuration file is "/home/zop/.avrduderc"
             User configuration file does not exist or is not a regular file, skipping

             Using Port                    : /dev/ttyACM0
             Using Programmer              : stk500v1
             Overriding Baud Rate          : 19200
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [10]
             AVR Part                      : ATtiny85
             Chip Erase delay              : 4500 us
             PAGEL                         : P00
             BS2                           : P00
             RESET disposition             : possible i/o
             RETRY pulse                   : SCK
             serial program mode           : yes
             parallel program mode         : yes
             Timeout                       : 200
             StabDelay                     : 100
             CmdexeDelay                   : 25
             SyncLoops                     : 32
             ByteDelay                     : 0
             PollIndex                     : 3
             PollValue                     : 0x53
             Memory Detail                 :

                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               eeprom        65     6     4    0 no        512    4      0  4000  4500 0xff 0xff
                 Memory Ops:
                   Oeration     Inst Bit  Bit Type  Bitno  Value
                   -----------  --------  --------  -----  -----
                   READ               31     VALUE      7      1
                                      30     VALUE      6      0
                                      29     VALUE      5      1
                                      28     VALUE      4      0
                                      27     VALUE      3      0
                                      26     VALUE      2      0
                                      25     VALUE      1      0
                                      24     VALUE      0      0
                                      23     VALUE      7      0
                                      22     VALUE      6      0
                                      21     VALUE      5      0
                                      20    IGNORE      4      0
                                      19    IGNORE      3      0
                                      18    IGNORE      2      0
                                      17    IGNORE      1      0
                                      16   ADDRESS      8      0
                                      15   ADDRESS      7      0
                                      14   ADDRESS      6      0
                                      13   ADDRESS      5      0
                                      12   ADDRESS      4      0
                                      11   ADDRESS      3      0
                                      10   ADDRESS      2      0
                                       9   ADDRESS      1      0
                                       8   ADDRESS      0      0
                                       7    OUTPUT      7      0
                                       6    OUTPUT      6      0
                                       5    OUTPUT      5      0
                                       4    OUTPUT      4      0
                                       3    OUTPUT      3      0
                                       2    OUTPUT      2      0
                                       1    OUTPUT      1      0
                                       0    OUTPUT      0      0
                   WRITE              31     VALUE      7      1
                                      30     VALUE      6      1
                                      29     VALUE      5      0
                                      28     VALUE      4      0
                                      27     VALUE      3      0
                                      26     VALUE      2      0
                                      25     VALUE      1      0
                                      24     VALUE      0      0
                                      23     VALUE      7      0
                                      22     VALUE      6      0
                                      21     VALUE      5      0
                                      20    IGNORE      4      0
                                      19    IGNORE      3      0
                                      18    IGNORE      2      0
                                      17    IGNORE      1      0
                                      16   ADDRESS      8      0
                                      15   ADDRESS      7      0
                                      14   ADDRESS      6      0
                                      13   ADDRESS      5      0
                                      12   ADDRESS      4      0
                                      11   ADDRESS      3      0
                                      10   ADDRESS      2      0
                                       9   ADDRESS      1      0
                                       8   ADDRESS      0      0
                                       7     INPUT      7      0
                                       6     INPUT      6      0
                                       5     INPUT      5      0
                                       4     INPUT      4      0
                                       3     INPUT      3      0
                                       2     INPUT      2      0
                                       1     INPUT      1      0
                                       0     INPUT      0      0
                   LOADPAGE_LO        31     VALUE      7      1
                                      30     VALUE      6      1
                                      29     VALUE      5      0
                                      28     VALUE      4      0
                                      27     VALUE      3      0
                                      26     VALUE      2      0
                                      25     VALUE      1      0
                                      24     VALUE      0      1
                                      23     VALUE      7      0
                                      22     VALUE      6      0
                                      21     VALUE      5      0
                                      20     VALUE      4      0
                                      19     VALUE      3      0
                                      18     VALUE      2      0
                                      17     VALUE      1      0
                                      16     VALUE      0      0
                                      15     VALUE      7      0
                                      14     VALUE      6      0
                                      13     VALUE      5      0
                                      12     VALUE      4      0
                                      11     VALUE      3      0
                                      10     VALUE      2      0
                                       9   ADDRESS      1      0
                                       8   ADDRESS      0      0
                                       7     INPUT      7      0
                                       6     INPUT      6      0
                                       5     INPUT      5      0
                                       4     INPUT      4      0
                                       3     INPUT      3      0
                                       2     INPUT      2      0
                                       1     INPUT      1      0
                                       0     INPUT      0      0
                   WRITEPAGE          31     VALUE      7      1
                                      30     VALUE      6      1
                                      29     VALUE      5      0
                                      28     VALUE      4      0
                                      27     VALUE      3      0
                                      26     VALUE      2      0
                                      25     VALUE      1      1
                                      24     VALUE      0      0
                                      23     VALUE      7      0
                                      22     VALUE      6      0
                                      21    IGNORE      5      0
                                      20    IGNORE      4      0
                                      19    IGNORE      3      0
                                      18    IGNORE      2      0
                                      17    IGNORE      1      0
                                      16   ADDRESS      8      0
                                      15   ADDRESS      7      0
                                      14   ADDRESS      6      0
                                      13   ADDRESS      5      0
                                      12   ADDRESS      4      0
                                      11   ADDRESS      3      0
                                      10   ADDRESS      2      0
                                       9     VALUE      1      0
                                       8     VALUE      0      0
                                       7    IGNORE      7      0
                                       6    IGNORE      6      0
                                       5    IGNORE      5      0
                                       4    IGNORE      4      0
                                       3    IGNORE      3      0
                                       2    IGNORE      2      0
                                       1    IGNORE      1      0
                                       0    IGNORE      0      0
                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               flash         65     6    32    0 yes      8192   64    128  4500  4500 0xff 0xff
                 Memory Ops:
                   Oeration     Inst Bit  Bit Type  Bitno  Value
                   -----------  --------  --------  -----  -----
                   READ_LO            31     VALUE      7      0
                                      30     VALUE      6      0
                                      29     VALUE      5      1
                                      28     VALUE      4      0
                                      27     VALUE      3      0
                                      26     VALUE      2      0
                                      25     VALUE      1      0
                                      24     VALUE      0      0
                                      23     VALUE      7      0
                                      22     VALUE      6      0
                                      21     VALUE      5      0
                                      20     VALUE      4      0
                                      19   ADDRESS     11      0
                                      18   ADDRESS     10      0
                                      17   ADDRESS      9      0
                                      16   ADDRESS      8      0
                                      15   ADDRESS      7      0
                                      14   ADDRESS      6      0
                                      13   ADDRESS      5      0
                                      12   ADDRESS      4      0
                                      11   ADDRESS      3      0
                                      10   ADDRESS      2      0
                                       9   ADDRESS      1      0
                                       8   ADDRESS      0      0
                                       7    OUTPUT      7      0
                                       6    OUTPUT      6      0
                                       5    OUTPUT      5      0
                                       4    OUTPUT      4      0
                                       3    OUTPUT      3      0
                                       2    OUTPUT      2      0
                                       1    OUTPUT      1      0
                                       0    OUTPUT      0      0
                   READ_HI            31     VALUE      7      0
                                      30     VALUE      6      0
                                      29     VALUE      5      1
                                      28     VALUE      4      0
                                      27     VALUE      3      1
                                      26     VALUE      2      0
                                      25     VALUE      1      0
                                      24     VALUE      0      0
                                      23     VALUE      7      0
                                      22     VALUE      6      0
                                      21     VALUE      5      0
                                      20     VALUE      4      0
                                      19   ADDRESS     11      0
                                      18   ADDRESS     10      0
                                      17   ADDRESS      9      0
                                      16   ADDRESS      8      0
                                      15   ADDRESS      7      0
                                      14   ADDRESS      6      0
                                      13   ADDRESS      5      0
                                      12   ADDRESS      4      0
                                      11   ADDRESS      3      0
                                      10   ADDRESS      2      0
                                       9   ADDRESS      1      0
                                       8   ADDRESS      0      0
                                       7    OUTPUT      7      0
                                       6    OUTPUT      6      0
                                       5    OUTPUT      5      0
                                       4    OUTPUT      4      0
                                       3    OUTPUT      3      0
                                       2    OUTPUT      2      0
                                       1    OUTPUT      1      0
                                       0    OUTPUT      0      0
                   LOADPAGE_LO        31     VALUE      7      0
                                      30     VALUE      6      1
                                      29     VALUE      5      0
                                      28     VALUE      4      0
                                      27     VALUE      3      0
                                      26     VALUE      2      0
                                      25     VALUE      1      0
                                      24     VALUE      0      0
                                      23     VALUE      7      0
                                      22     VALUE      6      0
                                      21     VALUE      5      0
                                      20    IGNORE      4      0
                                      19    IGNORE      3      0
                                      18    IGNORE      2      0
                                      17    IGNORE      1      0
                                      16    IGNORE      0      0
                                      15    IGNORE      7      0
                                      14    IGNORE      6      0
                                      13    IGNORE      5      0
                                      12   ADDRESS      4      0
                                      11   ADDRESS      3      0
                                      10   ADDRESS      2      0
                                       9   ADDRESS      1      0
                                       8   ADDRESS      0      0
                                       7     INPUT      7      0
                                       6     INPUT      6      0
                                       5     INPUT      5      0
                                       4     INPUT      4      0
                                       3     INPUT      3      0
                                       2     INPUT      2      0
                                       1     INPUT      1      0
                                       0     INPUT      0      0
                   LOADPAGE_HI        31     VALUE      7      0
                                      30     VALUE      6      1
                                      29     VALUE      5      0
                                      28     VALUE      4      0
                                      27     VALUE      3      1
                                      26     VALUE      2      0
                                      25     VALUE      1      0
                                      24     VALUE      0      0
                                      23     VALUE      7      0
                                      22     VALUE      6      0
                                      21     VALUE      5      0
                                      20    IGNORE      4      0
                                      19    IGNORE      3      0
                                      18    IGNORE      2      0
                                      17    IGNORE      1      0
                                      16    IGNORE      0      0
                                      15    IGNORE      7      0
                                      14    IGNORE      6      0
                                      13    IGNORE      5      0
                                      12   ADDRESS      4      0
                                      11   ADDRESS      3      0
                                      10   ADDRESS      2      0
                                       9   ADDRESS      1      0
                                       8   ADDRESS      0      0
                                       7     INPUT      7      0
                                       6     INPUT      6      0
                                       5     INPUT      5      0
                                       4     INPUT      4      0
                                       3     INPUT      3      0
                                       2     INPUT      2      0
                                       1     INPUT      1      0
                                       0     INPUT      0      0
                   WRITEPAGE          31     VALUE      7      0
                                      30     VALUE      6      1
                                      29     VALUE      5      0
                                      28     VALUE      4      0
                                      27     VALUE      3      1
                                      26     VALUE      2      1
                                      25     VALUE      1      0
                                      24     VALUE      0      0
                                      23     VALUE      7      0
                                      22     VALUE      6      0
                                      21     VALUE      5      0
                                      20     VALUE      4      0
                                      19   ADDRESS     11      0
                                      18   ADDRESS     10      0
                                      17   ADDRESS      9      0
                                      16   ADDRESS      8      0
                                      15   ADDRESS      7      0
                                      14   ADDRESS      6      0
                                      13   ADDRESS      5      0
                                      12    IGNORE      4      0
                                      11    IGNORE      3      0
                                      10    IGNORE      2      0
                                       9    IGNORE      1      0
                                       8    IGNORE      0      0
                                       7    IGNORE      7      0
                                       6    IGNORE      6      0
                                       5    IGNORE      5      0
                                       4    IGNORE      4      0
                                       3    IGNORE      3      0
                                       2    IGNORE      2      0
                                       1    IGNORE      1      0
                                       0    IGNORE      0      0
                                      Block Poll               Page                       Polled
               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
               signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
                 Memory Ops:
                   Oeration     Inst Bit  Bit Type  Bitno  Value
                   -----------  --------  --------  -----  -----
                   READ               31     VALUE      7      0
                                      30     VALUE      6      0
                                      29     VALUE      5      1
                                      28     VALUE      4      1
                                      27     VALUE      3      0
                                      26     VALUE      2      0
                                      25     VALUE      1      0
                                      24     VALUE      0      0
                                      23     VALUE      7      0
                                      22     VALUE      6      0
                                      21     VALUE      5      0
                                      20    IGNORE      4      0
                                      19    IGNORE      3      0
                                      18    IGNORE      2      0
                                      17    IGNORE      1      0
                                      16    IGNORE      0      0
                                      15    IGNORE      7      0
                                      14    IGNORE      6      0
                                      13    IGNORE      5      0
                                      12    IGNORE      4      0
                                      11    IGNORE      3      0
                                      10    IGNORE      2      0
                                       9   ADDRESS      1      0
                                       8   ADDRESS      0      0
                                       7    OUTPUT      7      0
                                       6    OUTPUT      6      0
                                       5    OUTPUT      5      0
                                       4    OUTPUT      4      0
                                       3    OUTPUT      3      0
                                       2    OUTPUT      2      0
                                       1    OUTPUT      1      0
                                       0    OUTPUT      0      0
                                      Block

             Programmer Type : STK500
             Description     : Atmel STK500 Version 1.x firmware
    avrdude: Send: A [41] . [80]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [02]
    avrdude: Recv: . [10]
    avrdude: Send: A [41] . [81]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [01]
    avrdude: Recv: . [10]
    avrdude: Send: A [41] . [82]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [12]
    avrdude: Recv: . [10]
    avrdude: Send: A [41] . [98]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [00]
    avrdude: Recv: . [10]
             Hardware Version: 2
             Firmware Version: 1.18
             Topcard         : Unknown
    avrdude: Send: A [41] . [84]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [00]
    avrdude: Recv: . [10]
    avrdude: Send: A [41] . [85]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [00]
    avrdude: Recv: . [10]
    avrdude: Send: A [41] . [86]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [00]
    avrdude: Recv: . [10]
    avrdude: Send: A [41] . [87]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [00]
    avrdude: Recv: . [10]
    avrdude: Send: A [41] . [89]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [00]
    avrdude: Recv: . [10]
             Vtarget         : 0.0 V
             Varef           : 0.0 V
             Oscillator      : Off
             SCK period      : 0.1 us

    avrdude: Send: A [41] . [81]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [01]
    avrdude: Recv: . [10]
    avrdude: Send: A [41] . [82]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [12]
    avrdude: Recv: . [10]
    avrdude: Send: B [42] . [14] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] @ [40] . [02] . [00] . [00] . [00]   [20] . [00]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [10]
    avrdude: PAGEL and BS2 signals not defined in the configuration file for part ATtiny85, using dummy values
    avrdude: Send: E [45] . [05] . [04] . [d7] . [a0] . [01]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [10]
    avrdude: Send: P [50]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
zop@mikasa:~$

I don't know what else to try, so suggestions are very welcome.
Thanks.
PS: I had to strip out some of the output text because it was bigger than 30000 chars, I hope the info is good enough.

Some key information is missing; what board configuration did you target while uploading the sketch? High Low offers boards.txt with 3 different configurations, make sure to use the 1Mhz (ATtiny85 default). Also, please share your connections from the Arduino to the ATtiny

Try removing the capacitor, and add a wire between 5v and reset on the UNO. You did upload the ArduinoISP example sketch right? (before adding the cap/wire)

@Gerben, the fact that the responses to the first number of requests to the programmer were received is pretty clear evidence that the arduino reset was not a problem and the right sketch was loaded.

avrdude has some weird error messages so I'm not confident enough to say that Send and Recv messages indicate it's working. But it might. Could you post a picture of your wiring? Or maybe the fuses are incorrect. Is it a brand new chip?

Thanks for your answers. The wiring of the Attiny85 is correct. No misidentifications with pin 1 to 5: Dot mark is pin 1. The attiny85 are fresh as they came from the (local) store. The ISP sketch was loaded previously, then using the attiny 1Mhz for the board when trying to upload the blink example (changing pin 13, obviously). Using arduino as ISP as a programmer for the upload to the attiny's (tried 2 different chips). I have to say that I'm sure I'm using a CLONE, eventhough it says "arduino" all over and has the whitish color on the back of the PCB. I don't know if that could be the probl

I have had reliability problems with ArduinoISP until I reduced the baudrate to 9600.

Your log demonstrates that

Your programmer settings were correct.
You have the right sketch loaded on the Arduino
You have the Arduino auto-reset properly disabled.

The failure occurs at the point at which you're trying to enter programming mode. The two most likely error sources are:

Your ATtiny85 is not wired up correctly (e.g. you misidentified pin 5 as pin 1, you used a wrong pin on the Arduino, you crossed two signals, etc).
Your ATtiny85 is in a mode that prevents ISP reprogramming (programming the RSTDIBL fuse is the toughest of these mode, but merely setting the clock source to something odd will also cause this). Does your chip have a past, or is it fresh out of the box?

I spent days with exactly the same problem (well, trying to program a 328p). Then I purchased a USBISP (aka USBICSP), and all my problems went away. I got one which had a "program slowly" jumper - setting this jumper will do the equivalent of -b19200, but without needing to explicitly set it, so you can do it from the Arduino IDE. Just my 2c worth.

source: Stack Exchange

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

sort: votes


text:
Device manager sees my nano as FT232 USB UART not as COM port
Until yesterday I had 2 arduino nanos (atmega328, 16Mhz, 5V), and they worked fine,when  I changed the cable and was able to upload code to them. Then I tried to make a breadboard arduino, but my PC (win8.1) was unable to see my FDTI 232RL USB2Serial converter as a COMPORT, so I tried to download drivers but nothing worked out.Anyway I decided to reinstall windows and now one of my Nano works just fine, but the Other appears as a FT232 USB UART at the device manager,so I stepped back... Can anyone help me with that?

Are they genuine Arduinos?

@IgnacioVazquez-Abrams may be related: http://hackaday.com/2014/10/22/watch-that-windows-update-ftdi-drivers-are-killing-fake-chips/

@AnnonomusPenguin: Hence the question.

Thanks everyone who answered me, the hackaday post solved my problem. I was able to unbrick my nano-clones.Now they work just fine.

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


text:
How best to power down an Arduino for ~5 minutes at a time?
Reading over the datasheet it appears the longest it can shutdown for is 8s so should I just keep a counter in the loop method that checks if it's run 38 times and then execute the code I want? Would this wakeup every 8s hurt battery life much if it's doing nothing but incrementing a counter?

Yes, if you want to wake an ATMEGA (the chip in the Arduino) spontaneously (no outside trigger) from Power Down mode at periodic intervals, the you will need to rely on an interrupt generated by the watchdog timer, which has a maxim timeout of 8s.
Your goal should be to wake, increment and check the timer, and get back to sleep as quickly as possible since the amount of time you are awake will dominate your average power usage while asleep.
Some things to keep in mind...

The arduino uses a power regulator which always draws current. If you are going for long battery life, you will need to replace or eliminate this regulator. Much better to have an ATMEGA connected directly to a battery.
Turn off as much of the chip as possible before going to sleep. Take a look at the power control registers.
Make sure you are not driving any unnecessary loads with the GPIO pins when sleeping.

BTW, common wisdom has been that it is best to wake up and run at as fast a clock speed as possible to get your work done and get back to sleep as quickly as possible. However, Jack Ganssle recently published an article that makes a great case for doing the opposite. You will actually get longer battery life if you wake up to a slow clock speed, since this means you can run down the battery to lower voltage (this assumes you don'y need higher voltages for some other part of your circuit). Lots of other great info for designing long running battery-powered systems here...
http://www.ganssle.com/tem/tem275.html
Here is another relevant article about long running Arduinos...
http://www.openhomeautomation.net/arduino-battery/

Looks like you've got some great answers already. For a great deal more info and details on the matter, check out what Nick Gammon has written here too: http://www.gammon.com.au/forum/?id=11497 - Power saving techniques for microprocessors


text:
Arduino Uno WebClient program not returning the exepected output
I have connected the Ethernet Shield to the Arduino Uno Board and do get the following error when I execute the WebClient program. Look like it's getting connected to the internet, because I am getting a response back. But, this is not the response I was expecting in the Serial console.
Can someone please help me?
connecting...
connected
HTTP/1.0 302 Found
Location: http://www.google.co.in/search?q=arduino&gws_rd=cr&ei=ap_2VJL0JqW_mwWc7IG4DQ
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Set-Cookie: PREF=ID=8d5e7471bdf891d2:FF=0:TM=1425448810:LM=1425448810:S=-gaX4w3RUPOn7YjK; expires=Fri, 03-Mar-2017 06:00:10 GMT; path=/; domain=.google.com
Set-Cookie: NID=67=WNjkn45lMWxFTVOlW_qv6YQonIaJjd3_Aakemy7ddZ7_JqmPgaZPv_aGdqE8OptRIeV2vrYlFZRo1us7JgmnSJlmO0mfGdSNxEckDkAsqXcL7r-S7jU04eiH_zl8Q39_; expires=Thu, 03-Sep-2015 06:00:10 GMT; path=/; domain=.google.com; HttpOnly
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Date: Wed, 04 Mar 2015 06:00:10 GMT
Server: gws
Content-Length: 281
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic,p=0.08

<meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE>

302 Moved

The document has moved
here.

disconnecting.

You should learn HTTP protocol: you get a 302 status that gives you a new URL Location that will give you the expected result.

@jfpoilpret I should have been a bit more explicit in the OP. The requested URL and the new URL in the response are all the same.

OK, then did you copy the cookies set in the first response into the headers of the second request? Not sure how Google uses them but they are probably here for something...

nope - I am not setting the cookies - just calling the url

Well I guess this is what's missing: your program should first perform the normal request, then if response is 302, get the new location AND the cookies, prepare a nrew request to this location and send along the previous cookies; I think the last response should be OK then.

@jfpoilpret would you care to add an answer explaining how to do that? Thanks!

I wish I could, but my knowledge of Arduino Ethernet API is too limited (near 0) to provide a full answer with sample code; that's why I only provided some hint here as a comment. Anyone who can provide sample code to do that is welcome to post it as an answer. I guess that should be pretty easy for someone who knows the Ethernet API well.


text:
Error while sending message using gsm sim900a module interfaced with arduino uno
The code used for interfacing the gsm module with arduino for sending a message is as follows :-
#include <GSM.h>

#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;

// char array of the telephone number to send SMS
// change the number 1-212-555-1212 to a number
// you have access to
char remoteNumber[20]= "12125551212";

// char array of the message
char txtMsg[200]="Test";

void setup()
{
  // initialize serial communications
  Serial.begin(9600);

  Serial.println("SMS Messages Sender");

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  Serial.println("GSM initialized");
  sendSMS();
}

void loop()
{
// nothing to see here
}

void sendSMS(){

  Serial.print("Message to mobile number: ");
  Serial.println(remoteNumber);

  // sms text
  Serial.println("SENDING");
  Serial.println();
  Serial.println("Message:");
  Serial.println(txtMsg);

  // send the message
  sms.beginSMS(remoteNumber);
  sms.print(txtMsg);
  sms.endSMS();
  Serial.println("\nCOMPLETE!\n");
}

the error is found on the 3rd line
    GSM_SMS sms;
as GSM_SMS is not a name type.
what point am i missing here...??
thank you in advance.

Which version of the Arduino IDE are you using?

Update your IDE software. You need IDE 1.0.4 or later.
I copied your code into my 1.0.5 IDE and compiled it without any error. So it is most probably your version of the Arduino IDE.


text:
Powering LCD Displays without a Breadboard
I hope that this is not a silly question. I may be hoplelessly optimistic in asking, but is there any way to power & display information onto a LCD Display from an Arduino Uno.... Without the breadboard? I am working on a hardware project that has very strict space constraints, and the breadboard is simply not an option.

It will highly depend on the kind of LCD you consider connecting to your Arduino: some LCD displays can be directly wired to the UNO, others need extra components (typically for level shifting) that will need a breadboard, a stripboard or a PCB.

I presume you're looking at this page - the breadboard is merely a convenience, you can just hard-wire the LCD directly - most don't even come with that header plug soldered on.


text:
TFT and SD don't work together
I use a 2.8" TFT Touch Shield v1 and I want to read some data that were stred in sd and plot them with the tft.
When the following code is ordered, to access the data. TFT freezes.... but the code's execution is continued...
    pinMode(SS, OUTPUT);
    // see if the card is present and can be initialized:
    if (!SD.begin(chipSelect)) {
       Serial.println("Card failed, or not present");
    // don't do anything more:
       while (1) ;
    }

    Tempfile = SD.open("DATALOG.TXT",FILE_READ);
    if (! Tempfile) {
       Serial.println("error opening datalog.txt");
    // Wait forever since we cant write data
       while (1) ;}

I tested the code on the example of the tft graphics test... and the result was a freezed tft...
I tried also to run the example: tftbmp but the tft remains black. Once again the code is executed in the loop as i receive results from the Serial monitor but tft is black...
I use an Arduino Uno R3.
Any tip is welcomed

The solution to getting data from SD to TFT may depend on the type of data stored.  See examples included in software for your TFT.  Also it might be possible to solve this issue with 2 Arduinos using Software Serial, which, I believe, is included in the Arduino IDE.  Assume you have stored analog data from a sensor on an SD.  During the recording, you were able to visualize incoming data on your serial plotter and  your sketch also allowed you to see the live data on your TFT.   You now wish to visualize the  data recorded on your SD on the TFT once more. To accomplish this with Software Serial,  the SD card could be mounted on one Arduino and  the TFT on another.  The Tx and Rx pins of the 2 Arduinos must be connected as described in the Arduino Software Serial guide.  This technique should allow user to "fool" the Arduino with TFT into thinking it is receiving live analog data from a sensor.  Since the user has already written the sketch to visualize data from a sensor on TFT , the modifications should be easy.

old topic, but since I'm having the same issues I'll share what I found.
chipSelect is usually 10 for arduino uno, some exemples have other pin setted.
also I found a guy claiming he fixed his issues setting after
pinMode(SS, OUTPUT);
digitalWrite(SS, HIGH);

chip select is 10 if Uno is SPI slave. if Uno is master 10 must be OUTPUT. that is way it is usually used as chip select for one of the SPI slaves. the SPI library sets the SS pin as OUTPUT and HIGH in begin()

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


text:
Web Server Options
I want to give my project a simple web GUI to change config options. I know I could get a shield and write some horrible HTML in C but I'm wondering if there is a better way. Is there another IC I could get to help with this? What's the recommended solution for an embedded web server?

I'm currently using the ESP8266 modules. They are available for little money on eBay and the like and they provide a pretty nice Wifi-Module. You can even (and I would recommend that) be programmed by the Arduino IDE using some clever core that a few people built here: https://github.com/esp8266/Arduino
Using that you got a Wifi-Server built into the delivered Libraries that can provide basic functions. It can also output files from an SD card if available, there is an example for that.
Aside from that the module has a lot of Flash and you might not even need the Arduino if you don't need a lot of I/O, if you need a lot of I/O then you might want to communicate across a serial link. You will need to make sure to lower the voltage for the ESP, either use a 3.3V Arduino or build a level converter between the Arduino and the ESP, like this: http://www.hobbytronics.co.uk/mosfet-voltage-level-converter
It's not as easy as using a Wifi-Shield but it's very cheap to use.

The Arduino in combination with a wifi/ethernet module will not give you a lot of options to work with. There are currently no libraries that will give you features like including stylesheets, AJAX or websockets. If your project allows it, due to the number of I/O pins you need etc: replace your Arduino with a ESP8266
If you want to produce something fancy: go with the ESP8266. Getting everything setup and working will be a bit harder than with the Arduino, but it will be worth the effort. You can program it in Lua, but that will only give you access to some basic functions. Just write your program in C like you did on the Arduino. There is a thing called Sming framework which allows you to import Arduino libraries with only changing in few lines of code. The Sming framework also includes a HTTPserver with AJAX, websocket, POST/GET, pre-processing, and style/js-file inclusion features.
The web framework is easier than it is in most webframeworks for the pc! The hard part is installing the toolchain and uploading your first bit of code, but once you've got that done it will be easy to figure out the rest. The Sming framework also contains examples for everything you think of.
If you are planning on buying an ESP8266 I recommend you get a few. The basic ESP-01 cost around $2,40 on ebay, but get a fancier one too with a few extra IO pins. I have also got a development version which can be programmed with a USB cable. It is really usefull for developing your program since you don't have to connect a USB-serial device every time just plug a USB cable. When I think my program is done, I upload it to a more basic and replaceable version of the ESP8266 and fix it in my project.
So a summary: It will be harder to figure everything out, but once you've got everything done it will be worth the effort! Here are a few links:
This will show you the power of a ESP8266:
ESP8266 oscilloscope with websockets video
The Sming framework:
Sming framework github repo

You can buy an ethernet shield of any kind, ENC28J60, wifi module etc etc, and NOT do the html on the chip, just set it up as a server (usually specific the the shield/module you use).
Then you can actually create a local html file on your computer, or even use any webserver on your network or even online. As long as you send the commands to the local address of your arduino.
So if your Arduino ethernet module has the IP-address: 192.168.1.123 then the following form will send a command to the arduino that you can handle in the arduino code:
<form action="http://192.168.1.123/acommand=1">
<input type="submit" value="click to send command">
</form>

So if you create a simple web form to send a command to the arduino you can put this page anywhere, as long as the action is pointing at your arduino IP-address. If you want to go into the whole jquery standard it might be a bit different, unsure how asyncronious submits are handled.
I want to point out that IF you put your simple html page online you dont need to and SHOULDNT open anything in your firewall or router. The code will work as long as the device you are accessing the page from is on the same network as your arduino.

I personally find that one of the simplest solutions to a web server is one of the two following options.

Buy a serial cable, and transmit data using the Serial port on your Arduino. You can transmit data to a PC, and use PHP to read the serial port and display the data you would like.
Buy a Raspberry Pi. You will be doing the same as step 1, however you don't need a serial cable to use serial between Pi and Arduino. However you might need a 3.3V / 5V converter, which depends if the arduino serial port outputs data at 3.3V or 5V.

GENERAL IDEA:
I would recommend getting a simple Wi-Fi and/or Ethernet module.
Then simply set up routes to receive and send data to Arduino (assuming arduino_ip to be your Arduino's IP), and GET and POST being HTTP verbs:
Receive data from Arduino:
GET  http://arduino_ip/data
Send data to Arduino:
POST http://arduino_ip/data
Now use any Web development Framework/Language (PHP, Node.js, Python) to receive and send data.
NO ADDITIONAL MODULES SOLUTION:
The above method will allow the arduino and server to communicate if they're on the same network. However, if you can constrain the server to be connected by USB to Arduino, you can use Node.js, Python (even PHP) to directly communicate to Arduino.
ANOTHER SOLUTION:
Add a Raspberry Pi, have it connected to Arduino by USB (Arduino's Serial), and the use Raspberry's Ethernet to bring in networking (Raspberry Pi can host a server itself)


text:
Arduino Requirements
I have downloaded the arduino Environment on my windows XP and also set the driver properly.
I discovered the arduino uno device on the device manager display list disappeared whenever I unplugged the arduino UNO. I want to know if there are extra things needed to set up the device as none of my sketches has ever gotten flashed to the board.
Someone told me I need Java (Compiler and Runtime) to use arduino is this true?
I only have JVR

Watch this video https://www.youtube.com/watch?v=YWY_Is0L7fE

or Watch this video
https://www.youtube.com/watch?v=4HqXAmV_Ock

I have watched the two movies Sir but it did not resolve the issue.

This is exactly what I get 'Arduino: 1.0.6 (Windows XP),  Board: "Arduino Uno" C:\New Folder\New\arduino-1.0.6\hardware\tools\avr\bin\avr-objcopy: 'Blink.cop.elf' : No such file

Are you getting an error when you program the board? What's wrong, exactly? P.S. it should disappear from device manager when it is unplugged; that is normal behavior.


text:
Integrating Freescale Multi Sensor board with Arduino
I recently bought Freescale's FRDM-FXS-MULTI-B, and have been trying to integrate it with an Arduino UNO. The board descriptions say that it has the shield layout that matches that of an Arduino shield. So in theory, I should be able to integrate it fine.
The problem comes when I plug it in and try to program the Arduino. As soon as I plug it in, the board resets and hangs. If I try to upload a simple code (just reading the analogue signal from the light sensor), the IDE hangs when uploading. Sometimes, I can fix it by removing the shield and pressing the reset button, but sometimes that doesn't work: the computer doesn't recognise the Arduino on the port, and the IDE removes the port from the Port Selection option. When I do remove it and it resumes functioning normally, and I re-attach the shield, the board resets and hangs again, until I go into the Serial Monitor.
With this board, I realised the Bluetooth module is connected to the Serial Receive pin, which explains the hang in the IDE, but I cannot understand why it resets and hangs when I plug it in.
Does anyone have any experience with this board, and can help me out? Why can I not find any tutorials online? With the multitude of sensors on this shield, I'm guessing you can access them via normal I2C and SPI communications, right? How do you use the Bluetooth module on the board?

What are you using to tell that the sketch is hanging even when it isn't connected to the serial monitor?

@BrettAM The sketch compiles fine, but when it is uploading, it freezes and stays in the same spot for ages. If I do press the reset button on the board, I get the 'avrdude: stk500_getsync()' error, but sometimes the code uploads, sometimes not.

So... 20 months later I stumbled upon this question, only to find out I wrote it. Awkward! Anyway, for anyone who stumbles across this question in the future, here is the answer.
The Rx pin is connected to the Bluetooth module, and as such the module will keep the pin in an idle state (either idle-high or idle-low). The Rx pin of the Arduino UNO (or the Rx0 pin on the Mega/Due) requires to be free of anything that may interfere with the upload. The Arduinos rely on the Rx pin for the sketch upload. If anything is connected to it, the IDE will freeze and nothing will be uploaded. Simply disconnect the FRDM board, upload the code, and put the board back in place. Then it should work.


text:
How to accept user input (array, variables,...)
I am working on a project using my Arduino mega2560 that triggers a solenoid (maximum of three solenoids), my camera and my flash (maximum of two flashes). The core routine is there, and working.
Now I want to refine this by adding a menu and 16x2 LCD with 6 buttons (up/down/left/right/select/reset). This is meant to be so the user can change the default values for:
- the amount of solenoids to be used (max 3),
- the amount of drops per solenoid (max 3),
- the time between drops and
- the time between active solenoids.
The layout of the menu is there, but not yet coded.
My default values for solenoids used, droplet size, droplet timing, solenoid timing, camera delay and flash(es) delay(s) are put in an array. Through the menu the default values will be presented to the user. He can accept (select button) or change the value within certain limits using the up/down buttons.
The question is, what is an easy (for a beginner like me) to program way to accept user input and store this in the array, overwriting the presented default value? I also would like to have the possibility for the user to back out of a menu option and leave the default setting of the specific submenu value.
I was thinking of creating a shadow array with blanks, to be filled in by the user and copy all the values to the array that will be used by the core routine. Another line of thinking leads me to just abandoning the array and making use of a bunch of variables. As you will probably see, I need some advice here.
Thanks very much for reading and your advice, happy to answer questions that may help clarify the issue.
Regards, Kiezel

Your hardware side for the user to use can be based on an ADC type keypad pictured below, this only uses one pin and is pretty reliable. Note that not all code is given or design as it would be useless for learning and I also put effort into the code this came from, logic helps with the rest of each part...

The code is pretty simple:
You would write a function like so~
char keypad(int in){

if(in < 949){
    if(in > 935){
        return 's'; //select
    }
}

//......

else return = 0;
}

Next would be the code for the menu, you could hold the default values in an array and then modify them in the code, with set positions for defaults, considering

My default values for solenoids used, droplet size, droplet timing, solenoid timing, camera delay and flash(es) delay(s) are put in an array.

Example from one of my projects
//Menu levels
#define level0 0
#define level1 1
#define level2 2
//master level of current point
#define mlevel 6
#define msub_level 7
//\\\\\\\\\\\\\\\\\\\\
#define sub_level1 0
#define sub_level2 1
#define sub_level3 2
#define sub_level4 3
#define sub_level5 4
// default level on boot
uint8_t current_level = mlevel;

Next would be to push the data to
int navigate(char key){
if(key == 'u'){
        if(current_level == mlevel){
        if(count == 3){ //roll-over

            count = 0;
            //update LCD....
        }
        else count++;
        //update LCD....
    }

    if(current_level == msub_level){

        if(count == 5){//roll-over

            count = 0;
            //update LCD....
        }
        else count++;
        //update LCD....
    }
}

//..... other ones here

    return count;
}

You would use the returned count to find the relative place in your array. e.g:
int default[n] ={x,y,z,...};

get the key > put into navigate() > put into dafault[count];

You would also change the default after

It has been changed or,
The key has been debounced, i.e. use logic to determine if the key has changed state or,
The user has chosen 'accept'

Update of the LCD can be done at the points you want it done

His Arduino has 54 digital I/O pins. Doesn't really need your pin-saving ADC trick.

@edgar - Meh I see your point,  user wanted 'simple'. He can search google for IO scanning libraries. And the method of the rest of the UI could still stand.

Okay, this is good! I use one of the common libraries for the 1602 LCD shield with buttons, so that part is covered. I also have found (and digested) a debounce routine. It works.
Same goes for the menu part, I like the solution for presenting the input/changed values.
I don't understand the part for pushing the input data into the array. Would you please be so kind and elaborate on this?
Thanks a lot!

@Kiezel - the returned variable count from navigate() is an int therefore it is put into the array to index a specific point in the array. You would use another if,else set to change if the user is in the main or sub menu (if you used the same method presented). That way you would need to create the two arrays, sub, array and main` array. please let me know if this helped, I might have confused it more ;)

@RSM - Thanks, I understand the concept, input is grasped as a variable count and put into a sub-array. I guess I can use the sub-array with the changed variables to deliver the input for my main routine.  But how to handle the situation where the default value is correct and not changed or committed by the user?  In my preferred situation I know exactly where the user is in the menu. And when a value changes the new value will be put into the array in the correct "slot" for later use.  It could be that your solution is doing just that, but I don't get it yet.

@Kiezel - the way the routine works is that it will go to the point in the array where the user chooses and then you would insert the changed variable there selected by the user, if not it would pass over that, the insertion of the chosen value is not done by the function, it only creates a "pointer", to the desired place. If need be, you can have a default array, and when the user has finished with there choice you can compare it to the default and decide to make a change or not.

@Kiezel - I just read through my answer again. Is it where I sad: "push the data to" before the navigate function which caused the confusion. I meant the char from the keypad function.


text:
How to make the motor car move left-forward / left-backward/ right-forward/ right-backward
I'm using an Arduino Uno to make a motor car. And I successfully made it move forward / backward / left / right.
void forward(void) {
  analogWrite(EA, 254); //speed 0 - 255
  analogWrite(EB, 255); //speed 0 - 255
  digitalWrite(EN2, LOW);
  digitalWrite(EN3, HIGH);
  digitalWrite(EN4, LOW);
  digitalWrite(EN5, HIGH);
}

void backward(void) {
  analogWrite(EA, 255); //speed 0 - 255
  analogWrite(EB, 255); //speed 0 - 255
  digitalWrite(EN2, HIGH);
  digitalWrite(EN3, LOW);
  digitalWrite(EN4, HIGH);
  digitalWrite(EN5, LOW);
}

void left(void) {
  analogWrite(EA, 180); //speed 0 - 255
  analogWrite(EB, 180); //speed 0 - 255
  digitalWrite(EN2, LOW);
  digitalWrite(EN3, HIGH);
  digitalWrite(EN4, HIGH);
  digitalWrite(EN5, LOW);
}

void right(void) {
  analogWrite(EA, 180); //speed 0 - 255
  analogWrite(EB, 180); //speed 0 - 255
  digitalWrite(EN2, HIGH);
  digitalWrite(EN3, LOW);
  digitalWrite(EN4, LOW);
  digitalWrite(EN5, HIGH);
}

The problem is, I found it is quite strange if I need to first press left/ right and press forward to turn around. I would like to make 4 extra buttons for left-forward / left-backward/ right-forward/ right-backward. Any ideas to create 4 extra functions for that?
Thanks for helping.
Update: Connection
int EN2 = 14;
int EN3 = 15;
int EN4 = 16;
int EN5 = 17;
int EA = 3;
int EB = 5;

Update: Attempted code and hardware connection
void left_top(void) {
  analogWrite(EA, 128); //speed 0 - 255
  analogWrite(EB, 255); //speed 0 - 255
  digitalWrite(EN2, LOW);
  digitalWrite(EN3, HIGH);
  digitalWrite(EN4, LOW);
  digitalWrite(EN5, HIGH);
}

void right_top(void) {
  analogWrite(EA, 255); //speed 0 - 255
  analogWrite(EB, 128); //speed 0 - 255
  digitalWrite(EN2, LOW);
  digitalWrite(EN3, HIGH);
  digitalWrite(EN4, LOW);
  digitalWrite(EN5, HIGH);
}

void left_down(void) {
  analogWrite(EA, 128); //speed 0 - 255
  analogWrite(EB, 255); //speed 0 - 255
  digitalWrite(EN2, HIGH);
  digitalWrite(EN3, LOW);
  digitalWrite(EN4, HIGH);
  digitalWrite(EN5, LOW);
}

void right_down(void) {
  analogWrite(EA, 255); //speed 0 - 255
  analogWrite(EB, 128); //speed 0 - 255
  digitalWrite(EN2, HIGH);
  digitalWrite(EN3, LOW);
  digitalWrite(EN4, HIGH);
  digitalWrite(EN5, LOW);
}

Left top / right top seem not to move at all, and right top / down is just similar to right / left.
And for hardware, I am using
Arduino  AR 293d

For the motor connection, it's like this:

What are the EA, EB, EN2-5 connected to?

Regarding the pins - I wanted to find out the physical (hardware) connections.
Pending an updated answer I presume the EA and EB will set the speed for two motors and EN2/EN3 and EN4/EN5 control the direction of the motors. If that's the case you could make the car turn sideways but changing the speed of only one of the motors. For example:
void forwardLeft(void) {
  analogWrite(EA,128); //speed 0 - 255
  analogWrite(EB,255); //speed 0 - 255
  digitalWrite(EN2,LOW);
  digitalWrite(EN3,HIGH);
  digitalWrite(EN4,LOW);
  digitalWrite(EN5,HIGH);
}

I assume that EA is the left motor and EB is the right motor. This will make the right one rotate twice as fast as the left one so the car should go forward, but also turn left. If you keep this running the car should end up going in a circle. By making the 128 lower you will change how fast the car is turning.
The other functions should be similar.
Caveat emptor - of course this will mean nothing if the beginning assumptions are incorrect.
EDIT
Can't figure out why it doesn't work without having the thing in my hands. Have not found a schematic for that board, but intuitively it should work as described above.
Things you can do to try to figure out - try different numbers instead of 128, the speed of the motors might not vary linearly with the voltage. What you need to obtain is to have one motor go twice as fast as the other one and in the same direction. That should turn the car around.

sorry just return from work , updated question , would you mind have a look? thanks

yes , the reason fail is because it reads only one character in arundio , the fuction itself has no problem

just go to this link.
Visit to
https://www.arduino.cc/en/Tutorial/PWM
At first use PWM to both right side and left side motor.
When right side motor spin/rotate at 255 value make leftside motor rotation speed at about 100 then you will see that it goes left-forward like wise you do rest of other.
Eg.
void setup()
{
  //LEFT MOTOR
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT); // connect pwm pin of left motor at pin9

  //right motor
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT); motor // connect pwm pin of right motor at pin12
}

void loop()
{
  digitalWrite(7, HIGH);
  digitalWrite(8, LOW);
  analogWrite(9, 100);
  delay(1000);
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  analogWrite(12, 255);
  delay(1000);
}


text:
How to return a message when calling by a TCP connection?
I am working on a communication between Android and Arduino board.
The Android makes a TCP connection with the board and successfully sends some strings to the board.
The problem is, there is an int in my Arduino code (e.g. int distance) and I would like to pass that back to my Android device.
I have handled the Android side already, but I do not know how to return a message from Arduino.
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

                //in this while the client listens for the messages sent by the server
                while (mRun) {
                    serverMessage = in.readLine();

                    if (serverMessage != null && mMessageListener != null) {
                        //call the method messageReceived from MyActivity class
                        mMessageListener.messageReceived(serverMessage);
                    }
                    serverMessage = null;

                }

This is the Android side code but I think that it is not a specific Android problem, there should be some way for Arduino to make a response of an integer variable (without concern what is the source device)?
What I should do in Arduino for making that response?

is serial.println(distance); correct? thanks

The binary representation of integers varies between Arduino (16 bit) and Android (32) bit, and while both an Arduino and most native-level Android implementations are little-endian, Android java code is big-endian.  So transferring your values in a string format may ease compatibility, as well as making it easy to debug the system by substituting a terminal emulator.

I'm assuming that you are using an Ethernet shield, as nothing about this is stated. But solution is really similar between many network solution.
Once a TCP connection has been established, it can be used like you would use the Serial;
you'll probably end up having something similar to:
EthernetClient client = server.available(); //accept a new connection
if (client) { //if valid connection
  client.print(distanceValue);
  client.close(); //close connection
}

look at the official API reference for a more detailed list of available command.


text:
Storing data (strings) if ethernet fails to send it
Flow goes something like:
Read sensors
Send data
If send fails store the data in eeprom/flash/sd
If sent check if any previous ones have failed and send those
So my question is what's the best storage option to save the data? Is there an easy way to save strings or am I going to have to write it byte by byte?

Depends on how many data you want to save.
And do you have something like a backup battery?
In my current project, I save some RFIDkeys to EEPROM when it has no internet connection and low battery, otherwise it just waits for internet connection.
Writing byte-by-byte isn't actually that difficult, you can use a struct to pack your bytes and then write the bytes of the struct to your memory.
Put it in a for loop, and it'll save them all.

In my opinion SD would be the best way because it is cheap, small, relatively fast and easily portable on a PC, using FAT (but it uses a lot of resources) or even raw; but then you have to use some more trick to get to the raw data from a OS, its not just "plug n read".
The SD library uses FAT under the hood, and it gives you a nice and easy interface. Just remember that SD works at 3.3V, and connecting them directly to arduino will break them fast, even if often not immediately.

SD would mean a bigger footprint though, right? a 1Mbit SO chip is pretty small but supporting an SD slot takes up a lot of space. I only use 3.3v arduinos now. :-)

well, you can use a microSD, they have the same interface. beat that :P
I normally buy microSD with adapter, and i use to solder directly on the adapter, so i can easily swap the card when needed (please pay attention to remove them when the micro is NOT writing. i use a "unmount button" or a temporized write every seconds, with a led that light up when writing)

Other than SD (see @lesto's answer), you can also store the data locally on your Arduino's EEPROM. You can store a byte at a time. The amount of storage varies from chip to chip, the AtMega328p that powers Arduino UNOs has 1kb. The eeprom is persistent over resets, I suspect not if you're reprogramming it, so think how you're going to get the data off before you start storing valuable info.
At 1kb, size is at a premium, so you probably don't want to use text strings, just the raw data. Remember that, if your chip resets, you will lose any memory variables with info about e.g. where you're up to. I would probably include some sort of checksum of each record, to test if the data is yours or not. I would include a counter or timestamp, so when you are starting up, you can read all memory to find the newest (valid) record; the next record is one greater, and at the next memory address. When you get to the end of the memory, restart at 0. If you store a one-byte counter, a one byte checksum, and 2 bytes of data, you can store 256 records. You could mark records off as you send them, or keep a counter in memory of which ones you have already sent - if your chip is reset, it may resend old records (very rarely), which your server would need then need to handle.
If using eeprom, try to spread your writes - you get a certain number of writes PER MEMORY LOCATION, so if you always write to address 15, then 15 will wear out before the others. I think I saw a reference to "100,000 writes", but am unable to find that now to confirm. 100,000 writes at 1 write per second to the same address will have your eeprom fail after about 27 hours; 4 writes per second spread over 1K will cause a fail after about 10 months.
Test what happens when you write past the end of memory - some possible scenarios include failed write, write to a different location (e.g. trying to write to address 1024+1 will write to address 1024), not writing at all and reading it back will return 0, 255, or another number (consistent or otherwise)
See http://arduino.cc/en/Reference/EEPROM on how to write to eeprom.
To find out how many bytes of memory your EEPROM has, use E2END. Addresses run from 0 to E2END, so E2END might be 1023 (0 to 1023=1024 bytes).

The reference to "100,000 writes" can be found in the ATmega datasheet: “The EEPROM has an endurance of at least 100,000 write/erase cycles.”


text:
DFRobot Bluno + Relay Shield
I'm a new to all things electronics and I'm having trouble using a DFRobot Bluno V2 with a DFRobot Relay Shield for Arduino V2.1. For testing purposes I've done the exact same circuit as represented in this diagram:

http://www.dfrobot.com/wiki/index.php/Relay_Shield_for_Arduino_V2.1_(SKU:DFR0144)#Connection_Diagram
But it is not working. If I send HIGH signal to D10 or press the S4 button on the shield, the circuit does not close and the LED doesn't turn on (even though the LED4 next to the relay on the shield lights up). If I do same circuit connecting the LED to D10 directly (ie., without using the relay) it works fine. I've also tested this with the other relays on the shield and the results were the same.
Does anyone know what might be the issue? What am I doing wrong?
Thanks in advance.

I do not know much about these boards as well, but did you try powering the board through the Vin pin?

Could you try using a wire directly connect PIN10 with 5V? then try it with GND. if you hear a sound like "Te" that means the relay board is work fine. the problem is from your arduino board or code.


text:
Which thermometer for home brewing
Hello,
I have an Arduino Yun and I brew beer.
I would like to log the temperature of the beer at all time during the fermentation process (final stage).  This means the thermometer would have to remain in the beer during this time (10 days).  The temperature would be < 40 degrees Celsius (probably around the 20 degree mark).
Question: What temperature sensor would be best suited to this task?
It must be:

Food grade
Can be used in alcohol for extended periods
Can be hooked up to Arduino (i.e. add a library and ready to go)

Thanks, Dan.

http://www.adafruit.com/products/381 and/or http://www.adafruit.com/products/1020

You can relax the immersion requirement if you tape the thermometer to the side of the fermenter and cover it with some insulation--I cover the stick-on thermometer on my carboy with a rag to make it match the contents more than the ambient temperature.

I am not a brewmaster but from what I understand the temperature will change slowly. Your problem is not to contaminate the beer, you can use a stainless possibly even a plastic tube that is sealed on the immersion side and use a
DS1820B sensor commonly used on Arduinos as well as other platforms. The response will be slower then if the sensor is inserted directly but since the change is slow it should work AOK. This keeps it simple and probably something you have done before.

You are looking for a thermocouple.
They need some specific chip to be read, so you'll probably want to spend a bit more and get a chip with a digital interface, there are some witch has arduino library, like MAX6675 (output at 1Hz, 0.25° precision).
As this chip read "C type" thermocouple, you just have to find the right probe for your needing, with probably can be found in many specialized store.
You may even buy a normal k probe, and then wrap it up in some protective case. Obviously that case should be designed to let the heat flow easily, but without short circuiting the probe; a food plastic bag;
or just spend a little more money and buy a stainless steel probe

Thanks - I will take a look at thermocouples (new term for me thanks). I don't mind spending a little bit of money.  I would prefer not to use plastic bags due to the fact there will be an aquarium heater in the container also.

yeah, the chip can be found for 10-15$, the probe i think others 30-30$, because you need to be sure it is food grade.
Please try to spend a bit more but stay safe.
And remember to calibrate it putting in ice and boiling water, and/or using a better quality thermometer; it is fine to have to compensate for a bit of error

A Thermistor is what you are really looking for, I would downvote this answer but I don't have the rep here to do so.  A thermistor is a type of resistor whose resistance varies significantly with temperature, more so than in standard resistors.  On the other hand, a thermocouple is a temperature-measuring device consisting of two dissimilar conductors that contact each other at one or more spots, where a temperature differential is experienced by the different conductors (or semiconductors).  Two differnt technologies, for your usage you are really looking for the thermistor.

A thermocouple generates a few millivolts of current, and is most typically used in the flame of a pilot light and connected to a fail-safe gas valve.  On the other hand a thermistor must be powered by it's circuit and is much more useful at 20-40C than a thermocouple.

@tyson write it as your own answer, not as comment. I don't think a thermistor is better as it is slower and with less precision.

First, speed doesn't matter in a long term monitoring application with a lot of its own thermal mass like this.   Next, a thermocouple is not more accurate, but less.  Thermocouples do not measure temperatures directly, but rather compare them. Therefore to use one you need to establish a reference temperature.  That can be done literally, by means such as dunking the reference junction in an ice-water bath, or virtually by measuring the temperature of the other junction or isothermal terminal block where it is located - typically with a thermistor or other type of resistance-based sensor.


text:
What type of connector does the GROVE system use?
What type of connector does GROVE use?
I'm interested in wiring some old sensors so they're compatible with GROVE, so I first need to identify the connector so I can buy the housing and pins to crimp. It looks to be some type of JST connector, but there are many different sizes, each with incompatible pitches and a lot of retailers often advertise them incorrectly. Unfortunately, I can't find any documentation of the connector on Seeedstudio's site.

The link to the GROVE has changed: http://wiki.seeed.cc/Grove_System/

I was about to ask the same question. This was driving me crazy, it seems the information is written nowhere!

It looks like the Grove connector is proprietary. I emailed Seeedstudio, and they directed me to this datasheet. Unless I'm reading it incorrectly, it doesn't appear to correspond to any type of JST connector, although it's similar. It has 2mm pin spacing, which would make it closest to the JST-PH type, but all the other dimensions are slightly different.

Unfortunately, the link appears to have died.

It is indeed proprietary and Grove's decision to use proprietary connectors deserves nothing but criticism.

Here is the updated link on the seed website.
http://wiki.seeedstudio.com/wiki/File:3470130P1.pdf
Also note that Digikey now stocks seeedstudio stuff.
http://www.digikey.com/product-detail/en/seeed-technology-co-ltd/110990030/1597-1082-ND/5482560
http://www.digikey.ca/product-detail/en/seeed-technology-co-ltd/110990037/1597-1083-ND/5482561

The first link gives me a 404 error, do you mean https://statics3.seeedstudio.com/images/opl/datasheet/3470130P1.pdf? As this is a bit of a link only answer, including an image of the contents of the pdf would be a great idea.

I believe the OEM part is NS-Tech 1125S-4P: Wire to Board connector > PITCH 2.00mm > 1125 Series
Good luck finding a vendor!

Not sure why you're downvoted, when Grove's link to OPL for the 4-pin connector has NSTech datasheets, and references the 1125S family in T/H and SMD.
https://www.seeedstudio.com/opl.html
https://statics3.seeedstudio.com/images/opl/datasheet/3470130P1.pdf
https://statics3.seeedstudio.com/images/opl/datasheet/3470140P1.pdf
While it has similarities to the JST PH series, it is not the same.  The prominent latching features on the NSTech/Grove do not exist in the JST.

It is not a JST connector. There are ramps on the side of the connector that won't allow the grove/seeed cables slide into the connectors. After I shaved/cut off the ramps, to allow them to fit into the connector, I found that the pins are slightly offset in there vertical alignment.
This appears to be a custom connector. However, if anyone knows better, I would be interested, but the answer is not JST.

@Greenonline Not really.  Gerben made a statement, but that statement is obviously wrong as the pin pitch does not even match.

@ChrisStratton - I received some definitive information from Seeed's tech support, as posted in my answer.

It is proprietary.  It makes it hard to build your own custom length cables. But then if you are, you probably don't need Grove modules in the first place.  I would use them more if I could build a cable.  The JST PH 2.0 definitely doesn't work well, even if you shave it down.  The PH also doesn't have the locking tab that the Grove connector does. It's interesting that some of the Grove boards have both JST PH 2.0 as well as Grove connectors for different purposes (e.g. LiPo battery connector)

These look like equivalents to the Molex Sherlock-series connectors (www.molex.com/molex/products/family?key=sherlock). I've ordered a Grove-compatible board that should get here Monday. I'll try connecting a Sherlock connector to it, and if I remember I'll give an answer back here as to whether it mates and locks properly. The pin pitch and pin dimensions are the same, I can tell that already, and it sure "looks like" a Sherlock connector.

It mates with a Sherlock connector, but the latching mechanism doesn't latch. Oh well...

It's definitely not a jst-connector - please have a look at them here http://www.amazon.com/Seeedstudio-20-pack-Grove-Connectors/dp/B00BB0I7V2 (the seeed website seems to be down at the moment). I Eagle you would search for a TWIG-4P-2.0.
These guys have 4PINs which are connected to ground and VCC + the data lines depending on the sensor you want to use.

Here there are GROVE connectors in SMD and a drawing is included: Grove - SMD Universal 4 pin connector (10 Stück).

Unfortunately, the diagram in the link shows a three pin connector, and not a four pin connector as used by the Grove system.

Following up from Cerin's answer, as the link to the datasheet on Seeed's website appears to have expired, I also contacted the technical support team at Seeed.
They sent me, I assume, the same datasheet. Here is a link to it, 110990030-model, and here is a screenshot, should the link die in the future:

Along with the datasheet, I also received the following information:

11006005(OLD) -->110060161(NEW)
Grove - Light Sensor change to V1.2, which had another light sensor.
Others same.
101020040(OLD)-->101020175(NEW)
Just some performance optimization.

From MCU's answer, and the linked eBay item for the Grove - SMD Universal 4 pin connector (10 Stück), the diagram below also shows the dimensions. However, it is quite clearly only a three pin connector, and not the four pin connector used in the Grove system:

See also Grove connector.

Have a look at:
YEONHO_ELECTRONICS_20037wr
YEONHO_ELECTRONICS_SMH200
YEONHO_ELECTRONICS_YST200
or
CJT CONN A2008 WR S 4P / A2008 H
......

This connector A2005(PHB-SMD) Series has become common in China, I have not found a supplier in the USA that carries it yet.
There is a similar connector, the A2008 series here.
A2005 images without-latching-plug:

I might have found at least one of the many possible manufacturers that make these types of connector. The manufacturer is Boom Precision Electronics and you can buy the connectors through LCSC.
Here are the links to four of the connectors on LCSC.
Vert. THT 4-Pin 2.00mm
RA THT 4-Pin 2.00mm
Vert. SMD 4-Pin 2.00mm
RA SMD 4-Pin 2.00mm
Disclaimer: I never bought these connectors listed above so I never got the chance to try and mate the grove cable housing with it. It however does seem to fit the dimension and shape based on the drawings.


text:
Interfacing accelerometer LSM303DLH with Arduino UNO using I2C
I am trying to connet a tri axis accelerometer LSM303DLH to arduino UNO using the libraries taken from the following links (https://github.com/adafruit/Adafruit_LSM303DLHC and/or https://github.com/ryantm/LSM303DLH) but none of them work.
Using the following connection:
SCL on A5,
SDA on A4,
Vin on 5V,
Gng on Gnd.
I should be able to see the values of the accelerometer but the serial monitor is empty.
I've tried inserting a few print in the libraries to understand where the execution stops, basically after a Wire.endTrasmission() the program doesn't go forward.
How can I connect the accelerometer using I2C?

Please post the code

Are you using one module bought from Adafruit?
Make sure the connection is correct between the sensor and Arduino, then make sure that the script doesn’t get stuck when the Wire is begun.
Another thing that you need to make sure, is to have the correct address, it depends from board and each one can have a different one or a selector.
This can be helpful to figure out what the wiring is


text:
Arduino ADC read bad value
I have an Arduino device and I'm trying to read two voltages. The first one is the Arduino Vcc by using the bandgap value 1.1V (this requires raw access to registers since it's not implemented in analogRead). The other one is checking the battery voltage using the badgap as a reference. I want both of them because I'm doing a study on the battery life when using a step-up converter.
I'm using these pieces of code:
// Read bandgap with Vcc as reference - this will give use the Vcc
ADMUX = DEFAULT << 6 | 14;
delayMicroseconds(250);
bitSet(ADCSRA, ADSC);
while(bit_is_set(ADCSRA, ADSC))
    ;
word x = ADC;
Serial.println(x);

// Read A1 with 1.1V bandgap as reference - this will give battery voltage
ADMUX = INTERNAL << 6 | 1;
delayMicroseconds(250);
bitSet(ADCSRA, ADSC);
while(bit_is_set(ADCSRA, ADSC))
    ;
word x = ADC;
Serial.println(x);

The problem that I have is that separately they seem to work well, however when using them together the first piece of code ruins the reading for the second one. The culprit is the line ADMUX = DEFAULT << 6 | 14. This sets up the default reference (chip voltage) and reads channel 14 (which is the 1.1V). I can't figure out why after using this line changing back with ADMUX = INTERNAL << 6 | 1 doesn't work.

Did you try taking the reading twice? The datasheet says: “The first ADC conversion result after switching reference voltage source may be inaccurate, and the user is advised to discard this result.”

Yes, I ran them in a loop and get consistent results. The first one read correctly, but then the second one won't work. If the first one is commented, the second one works OK.

Actually you are right, I didn't understand your comment clearly the first time. I loop both reads one after another so it doesn't help. Looping the second one gets to the right value after a while (~5 ms) so I need to read once then wait 5 ms and read again. Please put your comment in an answer so I can accept it.

The datasheet says:

The first ADC conversion result after switching reference voltage
  source may be inaccurate, and the user is advised to discard this
  result.

Then you could try to take each reading twice, looping over four ADC
readings:

Read bandgap with Vcc as reference, discard the value.
Re-take the same, keep the value.
Read A1 with 1.1V bandgap as reference, discard the value.
Re-take the same, keep the value.

I also want to add this as reference - I found some more info in this thread: http://forum.arduino.cc/index.php?topic=22922.0 which confirmed my suspicion that the Aref capacitor discharge time might be messing up with the reads. They got values very close to my 5 ms wait time.


text:
Continuous servo not setting speed correctly
I have two continuous servos connected to my Uno, and I'm running this code on it:
leftServo.write(91);
rightServo.write(102);
delay(3000);

leftServo.write(112);
rightServo.write(81);
delay(3000);

leftServo.write(91);
rightServo.write(102);
delay(3000);

int i;
while(1) {
  i++;
}

When I run the code, the wheels stop for three seconds (91 and 102 are the zero values for these servos) then they spin for three seconds, then the left servo stops, but the right one only slows down about half way, it doesn't stop, even though the exact same number is used as before.
I can't figure out why this is?

My first piece of advise would be to dump that function (without the "while(1)" part) into the end of setup() and see what happens.

Same effect unfortunately

Have you swapped the motors round to check it's not the hardware? If that's the same try swapping the order of the final leftservo/rightservo commands.

I have added a delay of 100 ms between servo writes, and that seems to have helped, the zero point for the right servo seems to have moved now though, 106 moves slowly counter-clockwise, and 107 moves slowly clockwise

I'm leaning toward the conclusion that the problem is with the hardware, probably some noise effecting the servo. Are the motors running on a different supply to the Uno? Have you made sure the grounds are tied together? Have you tried some decoupling caps on the servo power supply? If you have access to one take an oscilloscope to the circuit and check for unwanted noise.

This is for an assignment, we are given a pre-made shield which we aren't allowed to modify. I'm using a 3A mains adaptor to power the board. Grounds are tied.

Any chance of getting a scope on the board to check the noise theory? If it's confirmed as definately not noise related I'm running out of ideas. I should be able to spend some more time on this evening, if I find anything relevent I'll get back to you.

It is possible your zero values are incorrect, but still manage to stop the motors under some circumstances if coming from a previous value which causes the servo amp to decide it is in an anti-hunting "dead band".  Another possibility could be heating from running the motor moving the neutral point, though it seems less likely.  Fundamentally, these continuous-run modifications can be temperamental, as they take something that is supposed to be closed loop and cut the loop open.

Issue was fixed by adding a delay of 100ms between servo writes, smaller values may work, but I haven't tried yet

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


text:
Timer1 arduino makes Serial not work
Running the code below, when I send any character in the Serial arduino is not printing "a" back. I think it's something wrong with the timer1 code but it should work cause this code was given by my teacher in C class.
ISR(TIMER1_COMPA_vect){

}

void setup() {

    Serial.begin(115200);

    //http://www.instructables.com/id/Arduino-Timer-Interrupts/?ALLSTEPS
    noInterrupts();
    TCCR1A = 0;// set entire TCCR1A register to 0
    TCCR1B = 0;// same for TCCR1B
    TCNT1  = 0;//initialize counter value to 0
    // set compare match register for 1000000hz increments with 8 bits prescaler
    OCR1A = 1;// = (16*10^6) / (1000000*8) - 1 (must be <65536)
    // turn on CTC mode
    TCCR1B |= (1 << WGM12);
    // Set CS11 bit for 8 prescaler. Each timer has a different bit code to each prescaler
    TCCR1B |= (1 << CS11);
    // enable timer compare interrupt
    TIMSK1 |= (1 << OCIE1A);
    interrupts();

}

void loop() {

    if (Serial.available()) {

     Serial.println("a");

    }

}

does it work when you take all the timer register code out?

yes it works fine.

OCR1A = 1 is a really really low value. This will mean almost all the time is spend inside the ISR routine (called once every 16 clock cycles). Try with something higher first (e.g. 255).

Another question is: what will go inside your ISR? Its empty here but what do you have planned for it. Spending too long in an ISR is bad news

This is a more complicated question than the standard Arduino questions, so I took a lot of time to look into it and find out the exact answer--since I was also curious. I have posted a very thorough answer to your question here on Stack Exchange, so please look there: https://stackoverflow.com/questions/28880226/timer1-arduino-makes-serial-not-work/28887781#28887781
I should also note that Gerben's comment is spot-on. I recommend a value no less than 20, since you configured the counter to increment once per 0.5us. This way, a value of 20 only calls the ISR every 10us, which should keep the ISR from occurring so often that it locks up your code.  As you'll see in my link above, the other main problem is you forgot to define your ISR function that is required when you enable the interrupt.
If this meets your needs, please put a green check next to my answer to mark it as correct.


text:
How to fix error line number offset in Sublime Text when compiling for Arduino
When compiling for Arduino via the Stino plugin line numbers are not represented correctly in the output. For example, I have an error on line 117 however the output is: sketch_name.ino.cpp:136:1: error:

The #line preprocessor directive is used to tell GCC both what the next line should be numbered as and what filename should be reported, and the plugin is not generating them properly. This is therefore a Stino bug.

In that case, couldn't you just add a #line 1 at the top of the ino file?

Sure, but that shouldn't be the responsibility of the programmer.

Thanks for the suggestions. I tried the #line 1 suggestion @Gerben however the errors are still showing on the wrong line.

Also thanks @IgnacioVazquez-Abrams I've added this to the issues on the Stino github repository.