text:
DS1307RTC Outputting cryptic 165/165/2165 date. What are some possible fixes?
My board.

I think I have it wired correctly (the lights aren't, but the board is).
I've read through the first few Google results to no avail.
My sample code to test the chip:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

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

void setup () {
  while (!Serial); // for Leonardo/Micro/Zero

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

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

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

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

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

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

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

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

Serial output:
`RTC is NOT running!
2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

2165/165/165 (Tuesday) 165:165:85
 since midnight 1/1/1970 = 1551138385s = 17952d
 now + 7d + 30s: 2019/3/5 12:16:31

Had the same issue, however, my RTC was 1302 (not 1307) and yours seems to be as well, please check.
If it's 1302, use this library:
https://github.com/msparks/arduino-ds1302
Also, make sure you connect pins like this:

Arduino Pin 7 goes to CLK
Arduino Pin 6 goes to DAT
Arduino Pin 5 goes to RST
Arduino 5+ goes to VCC
Arduino GND goes to GND

Your picure shows also another device on the bread board. Remove that and ensure that:
Uno Ground --> 1307 Ground
Uno 5Volt --> 1307 +5v
Uno A4 --> 1307 Data
Uno A5 --> 1307 Clock
If the 1307 has a power led indicator, it should be lit.
If that still does not work, then in the code, comment this line out:
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

and uncomment this line to set the 1307 with a specific time stamp:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));

Put in the following line in void setup():
Wire.begin();

(Assuming Wire library has been included.)
This will set up the I2C connection between the Master (Arduino) and the Slave (RTC).
For more generic use, the syntax is: Wire.begin(address);
The complete code is:
void setup () {
  Wire.begin();
  Serial.begin(9600);
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // UNCOMMENT TO SET TIME & DATE TO THAT AT COMPILATION.
  //rtc.adjust(DateTime(2017, 8, 31, 14, 45, 14 )); // UNCOMMENT TO SET TIME & DATE MANUALLY. (YEAR, MONTH, DAY, 24-HOUR, MINUTE, SECOND)

}

On the DS3231 seems like the device can get unsynchronized with the microcontroller. Not sure if the same problem with DS1307 I think worth trying.
My complete solution on stackoverflow for the same question

The I2C interface is accessible whenever either VCC or VBAT is at a
  valid level. If a microcontroller connected to the DS3231 resets
  because of a loss of VCC or other event, it is possible that the
  microcontroller and DS3231 I2C communications could become
  unsynchronized, e.g., the microcontroller resets while reading data
  from the DS3231. When the microcontroller resets, the DS3231 I2C
  interface may be placed into a known state by toggling SCL until SDA
  is observed to be at a high level. At that point the microcontroller
  should pull SDA low while SCL is high, generating a START condition.

I had the same "165" problem.  Very intermittent.  Turns out that I was drawing too much power from the Arduino rails for the circuit I was controlling.  I was being lazy by not powering it independently when I started.  Nick Gannon on arduino.cc showed where the 165 came from and solved my problem.  He included the bcd math.
https://forum.arduino.cc/index.php?topic=184908.0

With the Arduino Due, the 165 problem came up intermittently with a knock off DS3231 (compatible with 1307 supposedly).  Tried switching to a different RTC but it didn't help.  Switching to an Arduino Mega 2560 seems to have resolved it.  The Mega 2560 is a lot slower so maybe it was a clock speed issue?  In any case, it was useful for resolving the intermittent issue.
That said, if you always get 165:165 it means your Arduino is not communicating with your RTC.  This is a different problem and won't be solved by switching Arduinos.

I can verify that the 1302 does not work with the 1307 library.  Very different chips.  No I2C on the 1302.  I'm trying to setup an autosync with the 1302 by studying how the 1307 does it... not having a lot of success.
I did it once before, and it is driving me bonkers that I can't figure it out again.

I had the same exact issue and discovered that the Tiny RTC 1307 board.  I found that the board I had was operating at 3.3v.  Once I moved the board to a 3.3v pin on my Arduino Nano.

I had same issue.
Put in setup rtc.begin();

rtc.begin is already in the OP's setup method.

I had the same problem 165/165.
I change the Crystal 32 kHz which solved my problem.

At best, this answer is extremely cryptic and hard to understand.  Can you explain why changing the crystal solved the issue?


text:
Scanning for I2C addresses
I'm trying to find the I2C address of an IMU plugged into my Arduino using the code from this URL: http://playground.arduino.cc/Main/I2cScanner.  However, the program stalls at this stage:

Why could this be happening?

Pull-up resistors present?

In all likelihood it's a hardware problem. Without more details it is hard to say what that might be. You might mention what device you are using exactly, and exactly what wiring you are using, including pull-up resistors.

When the I2C scanner stops, it halts in the function Wire.endTransmission. The cause is a hardware problem of the I2C bus. For example the SDA or SCL are shortcut to something or pull-up resistors are missing (as already mentioned by TisteAndii) or the sensor module is not powered.
I assume that the IMU module has already pull-up resistors for SDA and SCL on the module. Which IMU module is it ? How did you connect it ? Do you have other I2C modules to test the I2C bus ?

source: Stack Exchange

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

sort: votes


text:
Voltage changes but digitalRead always HIGH

I developed a simple push button project
I used a wemos D1 mini
I connected  D3 pin to a pull down 1K resistor.
I used a multimeter to measure D3 pin voltage.

When I push the button, D3 pin voltage changes from 0.x volt to 4.x volt. But digital read on D3 always return HIGH.
Please help me find the problem.
This in my sketch :
    int ledPin = D2; // choose the pin for the LED
    int inPin = D3;   // choose the input pin (for a pushbutton)
    int val = 0;     // variable for reading the pin status

    void setup() {

      pinMode(ledPin, OUTPUT);  // declare LED as output
      pinMode(inPin, INPUT);    // declare pushbutton as input
    }

    void loop(){

      val = digitalRead(inPin);  // read input value
      if (val == HIGH) {
        digitalWrite(ledPin, LOW);
      } else {
        digitalWrite(ledPin, HIGH);
      }
    }

How can it be that you measure > 4V at D3 if you're just pulling down the pin. Either you provide us with schematics on what's at D3 or we won't be able to do anything else than speculate, let alone help you.

you should use the INPUT_PULLUP mode if you want to activate by connecting the GPIO to GND; otherwise your input state will be inverted.

The problem is that when the button isn't pressed, the voltage at pin D3 is just floating. Since there is nothing attached, the voltage at the pin can be anything. To prevent this, you use a pull-down resistor, so that when the button isn't pressed, the voltage at D3 is pulled to ground, and you will get a LOW using digitalRead.

simulate this circuit – Schematic created using CircuitLab

First of all - read your post before you actually post it. This code is no readable. And if you have problems with electronics add picture of schematics how you connected your board. There can be problem too.

D3    IO, 10k Pull-up GPIO0

Source: https://www.wemos.cc/product/d1-mini-pro.html
Your D3 pin have internally pull-up so no doubt that it reads HIGH all the time. Connect your board like on picture below or change your reading pin to D0 for example (It has no other function than simple IO).

simulate this circuit – Schematic created using CircuitLab
For this case you can trust internal pull-up but in more complicated projects you should add your own one.
For more information about pull-ups and pull-downs check this article: http://www.electronics-tutorials.ws/logic/pull-up-resistor.html

Thanks for your advice Adam Rosiek, i choose D3 for some packaging space issue. Yes i move to D8 it solve the problem. And i.m sorry for inconvenient code and no picture

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

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


text:
MIDI and DMX together
I am fully new to Arduino (even don't have one ... yet), however, I'm looking into possibilities to use both MIDI in/out and DMX together. If I understand correctly the MIDI library (re)uses the UART/COM while the DMX does the same.
I am wondering if it can be used together (e.g. use MIDI in to control MIDI out and/or DMX out).
(Also still checking if I would need some simple MIDI/DMX components or 'full' MIDI or DMX shields/boards.)

Here's a web page I created with photos, code, and detailed instructions: http://lights4music.com/instructions.html

@Lights4Music Thank you very much .... because of memory usage I decided to move to STM32, but later when I also want DMX I'm sure I can use some of the information of your project. Cool project you have btw. and thanks for the link!

Yes you can use multiple UART/Serial devices with a single Arduino.
However, there are some things to consider:
The Arduino Uno supports a single hardware serial connection (which is used for programming and debugging with the Serial Monitor). The Arduino Mega supports 4 hardware serial connections.
The arduino environment has a software Serial library that allows for additional Serial connections. However it is worth noting that software serial is slower than its hardware counterpart.
Also, if you want to use software serial, be sure to verify that any shields you want to use will support using a software serial connection.

note that since DMX needs 250kbps and MIDI uses only 31kbps, the MIDI should be the software one...

Thanks for the answer and note, this is very helpful ... I guess I have to get used to Arduino, and maybe buy a starter kit to test if a software MIDI Serial solution would work well enough. Just wondering if I can use the hardware serial connection for debugging another way but I will add a new question for that.

The DmxSimple/DmxMaster library does not use serial and will work simultaneously with the MIDI library by 47 Effects.  I have used the Sparkfun MIDI shield with the Tinkerkit DMX shield.  The trick to stacking them is using tall headers on the MIDI shield and not soldering the XLR connectors on the DMX shield.
Or you can use a Teensy which has multiple hardware serials and more RAM at a good price but requires building a couple basic circuits.

Thanks for the answer, good to know both MIDI and DMX can be used.


text:
Multiple push buttons
I am behind a problem of controling multiple leds with multiple push buttons. Lets say that I have 5 push buttons and 3 leds. Led1 turns on if at least 1 out of the 5 push buttons is pressed. Led2 turns on if at lest 3 push buttons are pressed and Led3 turns on if at least 4 push buttons are pressed.
How can this be solved ? With if else ?arrays?
here is my code that i have
 const int led1 = 2;
 const int led2 = 3;
 const int led3 = 4;
 const int bp1 = 9;
 const int bp2 = 8;
 const int bp3 = 7;
 const int bp4 = 6;
 const int bp5 = 5;
 int state;

void setup()
 {
 Serial.begin(9600);
 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT);
 pinMode(led3, OUTPUT);
 pinMode(bp1, INPUT);
 pinMode(bp2, INPUT);
 pinMode(bp3, INPUT);
 pinMode(bp4, INPUT);
 pinMode(bp5, INPUT);
}

void loop()
{
 state = digitalRead(bp1);
 state = digitalRead(bp2);
 state = digitalRead(bp3);
 state = digitalRead(bp4);
 state = digitalRead(bp5);
if (state = HIGH)
{ digitalWrite(led1, HIGH); }

if (state = 3 )
{ digitalWrite(led2, HIGH);
if (state >= 4);
{ digitalWrite(led3, HIGH); }
}
else { digitalWrite(led1, LOW); }
}

Please format your text so it can be readen

i did it but i don't know exactly how to edit it very nicely

When including code in a stackexchange question or answer, first paste the code into the question or answer editing box; then in that editing box, highlight the code and press ctrl-k.  Or highlight the code and click the {} icon in the toolbar at the top of the editing box.  To highlight text click-drag across it or use the arrow keys while holding the shift key.

Your code won't work as is. Each time you assign a value to state you're overwriting it in the next line. You could, for example have multiple int state variables such as state1 for the first line in the loop then state2 in the second etc. Then you need to compare values (don't use = on its own in a compare as it will assign the value being tested - use == instead). This way you gather all the button states first.
Or you could test the state of a button and if pressed add 1 to state:
if (digitalRead(bp1)) {
    state++};

Then you compare the number of button presses counted in state as you were doing and light the LEDs based on that.
However you will likely have a problem with contact bounce on the switches. This happens when a switch is closing and the voltage is not steady for about 20ms (imaging a switch sparking as it is closing). To get around this you'll need either some additional components or add a time delay in your code for each button press to check it several times until the voltage is stable. Do a Google search for 'Arduino contact bounce' for solutions.
R3.

To get the functionality you want the code should be:
void loop()
{
 state = 0;
 if (digitalRead(bp1) == HIGH)
   state = state + 1;
 if (digitalRead(bp2) == HIGH)
   state = state + 1;
 if (digitalRead(bp3) == HIGH)
   state = state + 1;
 if (digitalRead(bp4) == HIGH)
   state = state + 1;
 if (digitalRead(bp5) == HIGH)
   state = state + 1;

 if (state >= 1)
   digitalWrite(led1, HIGH);
 else
   digitalWrite(led1, LOW);

 if (state >= 3 )
   digitalWrite(led2, HIGH);
 else
   digitalWrite(led2, LOW);

 if (state >= 4) // you had a ; here.
   digitalWrite(led3, HIGH);
 else
   digitalWrite(led3, LOW);
}

There are more shorthand ways to write this e.g.if (digitalRead(bp4) == HIGH) state = state + 1; could be replaced with digitalRead(bp4)?state++; but until you are familiar with programming it's often best to use the longer but clearer way of writing things.
If all you are doing is lighting LEDs then de-bouncing the buttons isn't necessary, any LED flicker caused by the contacts bouncing won't be visible to your eye.
If however at a later date you want to trigger other logic in your program to run once per button press then you will need to worry about that. All buttons and switches bounce a little when you close them, without something in the electronics or software to cope with that a single button press can look like a dozen very quick presses to your software.

I would do this:
 state = (state & ~STATE_MASK1) | ((digitalRead(bp1)==HIGH)?STATE_MASK1:0); //assuming buttons are active high
...

if (state & STATE_MASK1)
{ digitalWrite(led1, HIGH); }

it holds up to 8 button states for a uint8_t type.
edit: here is a quick implementation.
//state = 0;                                            //reset the state

//read the buttons - all active high
state = (digitalRead(bp1)==HIGH)?STATE_BP1:0;
state|= (digitalRead(bp2)==HIGH)?STATE_BP2:0;
state|= (digitalRead(bp3)==HIGH)?STATE_BP3:0;
state|= (digitalRead(bp4)==HIGH)?STATE_BP4:0;
state|= (digitalRead(bp5)==HIGH)?STATE_BP5:0;

//process the buttons
digitalWrite(led1, (state & STATE_BP1)?HIGH:LOW);   //active high - led1 is high if bp1 is high
digitalWrite(led2, (state & (STATE_BP2 | STATE_BP4))?LOW:HIGH); //active low - led2 mimics bp2|bp4 => led2 high if both bp2+bp4 are low
digitalWrite(led3, ((state & STATE_BP3) && (~state & STATE_BP5))?HIGH:LOW); //active high -> led3 is high if bp3 is high and bp5 low

the code controls 3 leds:

led1: it mimics bp1;
led2: it goes high if both bp2/bp4 are high;
led3: it goes high if bp3 is high and bp5 is low.

I picked the output logic for no particular reason.
here is the output:

you can check the waveform against the logic, :)
again, this is just one particular implementation and you can write your own code / logic to produce your desired outcome. the principle is the same.

Thank you all very much for your time and help, much appreciated ! Now I am going to read and to study everything.

I read everything, tested both codes and still not working :(

My programming level unfortunately is not yet so good to fully understand above written: (

I solved my problem by myself with if..else structures. I am happy that I got this working and I learned something new. Thank you all for help and inputs.
int led1 = 2;
int led2 = 3;
int led3 = 4;
int bp1 = 9;
int bp2 = 8;
int bp3 = 7;
int bp4 = 6;
int bp5 = 5;

void setup()
 {
 Serial.begin(9600);
 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT);
 pinMode(led3, OUTPUT);
 pinMode(bp1, INPUT);
 pinMode(bp2, INPUT);
 pinMode(bp3, INPUT);
 pinMode(bp4, INPUT);
 pinMode(bp5, INPUT);

}

void loop()

{

if (digitalRead(bp1)== HIGH or digitalRead(bp2)== HIGH or digitalRead(bp3)== HIGH or digitalRead(bp4)== HIGH or digitalRead(bp5)== HIGH )
{
  digitalWrite(led1, LOW);
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);
 }
else
{
  digitalWrite(led1, HIGH);
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);

 }

if (digitalRead(bp1)== HIGH and digitalRead(bp4)== HIGH and digitalRead(bp5)== HIGH or digitalRead(bp1)== HIGH and digitalRead(bp2)== HIGH and digitalRead(bp3)== HIGH or digitalRead(bp1)== HIGH and digitalRead(bp2)== HIGH and digitalRead(bp4)== HIGH or digitalRead(bp1)== HIGH and digitalRead(bp3)== HIGH and digitalRead(bp5)== HIGH or digitalRead(bp1)== HIGH and digitalRead(bp2)== HIGH and digitalRead(bp5)== HIGH or digitalRead(bp2)== HIGH and digitalRead(bp4)== HIGH and digitalRead(bp5)== HIGH or digitalRead(bp3)== HIGH and digitalRead(bp4)== HIGH and digitalRead(bp5)== HIGH or digitalRead(bp2)== HIGH and digitalRead(bp3)== HIGH and digitalRead(bp5)== HIGH or digitalRead(bp2)== HIGH and digitalRead(bp3)== HIGH and digitalRead(bp4)== HIGH)
    {
    digitalWrite(led1, HIGH);
    digitalWrite(led2, LOW);
    digitalWrite(led3, HIGH);
    }
else
  {
   digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   }

if (digitalRead(bp2)== HIGH and digitalRead(bp3)== HIGH and digitalRead(bp4)== HIGH and digitalRead(bp5)== HIGH or digitalRead(bp1)== HIGH and digitalRead(bp2)== HIGH and digitalRead(bp4)== HIGH and digitalRead(bp5)== HIGH or digitalRead(bp1)== HIGH and digitalRead(bp2)== HIGH and digitalRead(bp3)== HIGH and digitalRead(bp4)== HIGH or digitalRead(bp1)== HIGH and digitalRead(bp2)== HIGH and digitalRead(bp3)== HIGH and digitalRead(bp5)== HIGH)
   {digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, LOW);
}

else
 {  digitalWrite(led1, HIGH);
   digitalWrite(led2, HIGH);
   digitalWrite(led3, HIGH);
   }

}

Your solution works, that's nice. But it's far from efficient. You check the state of the button for ridiculous amount in each loop. You may want to consider another algorithm, as seen on another answer here. And since the problem is solved, don't forget to accept an answer :)


text:
Arduino whack-a-mole game not working
Everyone, I am new to this. Currently I am trying to make a Whack-a-mole game for my school project. There will be a total of 6 moles (corresponding to 6 LEDs, which will light up randomly). At each moment, there will only be one LED lit up. The whole game duration is 30 seconds. At the end of the game, the score will be displayed.
I use a piezo electric sensor to detect the knock of the user. I program it in such a way that if the reading of the piezo sensor is greater than 50, it will take it as knock, and if the user knocks it correctly, one point will be awarded.
But unfortunately my code isn't working. The score displayed appears to be random numbers, doesn't work as it is supposed to be.
Here is my code, please hep me to have a look and provide me with some guidance. Thank you.
unsigned long time_since_reset;
int previousNum=0;
int currentNum =0;
int randomGenerator (void);
void light(int port);
int checker(int port);
int score =0;

void setup() {
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  time_since_reset = millis();
  while((millis()-time_since_reset)<30000) {
    randomSeed(analogRead(0));
    currentNum = randomGenerator();
    light(currentNum);
    checker(currentNum);
  }
  Serial.println("End Game");
  Serial.println(score);
}

int randomGenerator(void) {
  int cNum;
  cNum = random(3, 8);
  if(cNum!= previousNum) {
    return cNum;
  }
}

void light(int port) {
  digitalWrite(port,HIGH);
  delay(1000);
}

int checker(int port) {
  jump:
  int mole1 = analogRead(0);
  int mole2 = analogRead(1);
  int mole3 = analogRead(2);
  int mole4 = analogRead(3);
  int mole5 = analogRead(4);
  int mole6 = analogRead(5);
  while(mole1<10 && mole2<10 && mole3<10 && mole4<10 &&mole5<10 &&mole6<10) {
    goto jump;
  }
  if(mole1>50 && port == 3) {
    score++;
    digitalWrite(port, LOW);
  }
  if(mole2>50 && port == 4) {
    score++;
    digitalWrite(port, LOW);
  }
  if(mole3>50 && port == 5) {
    score++;
    digitalWrite(port, LOW);
  }
  if(mole4>50 && port == 6) {
    score++;
    digitalWrite(port, LOW);
  }
  if(mole5>50 && port == 7) {
    score++;
    digitalWrite(port, LOW);
  }
  if(mole6>50 && port == 8) {
    score++;
    digitalWrite(port, LOW);
  }
}

When including code in a stackexchange question or answer, first paste the code into the question or answer editing box; then in that editing box, highlight the code and press ctrl-k. Or highlight the code and click the {} icon in the toolbar at the top of the editing box. To highlight text click-drag across it or use the arrow keys while holding the shift key.  This will make code appear as code.

Could you add some sample serial output?

light() prevents checker() from reading anything for 1 second because of delay(1000);

if I don't include the delay(1000), the led will lights up and off very quickly, the players are unable to respond that fast. any suggestion to improve it?

The code as shown has a bunch of problems; the probably-most-important are as follows.
• score is not initialized.  Add score = 0; after
 time_since_reset = millis();
• As noted in a comment, the delay(1000) statement in light() prevents checking for whacks during the first second of a light being on.  This probably is undesirable – most people expect to whack a mole much sooner than a second after it appears.  If you want a delay there, make it at most 20 milliseconds. [See edit 2]
• The sequence randomSeed(analogRead(0)); currentNum = randomGenerator(); has a good chance of generating the same value of currentNum several times in a row, which may result in multiple counts for a given whack.
• Instead of saying randomSeed(analogRead(0)); within the inner loop, say it just after time_since_reset = millis(); or (probably better) in setup().  If analogRead(0) changes slowly, the same random seed may get used over and over, resulting in the same sequence of numbers from the random(3,8) expression.
• Your randomGenerator() routine has undefined behavior:  It doesn't return a valid result if the current random  number is the same as the previous one.  You could add a loop that calls random() again if the value is the same as before; but not returning a value results in  undefined behavior.
Edit 2:  When you turn a light on, record the current millis() time reading, say in onTime[i] for light i, and set flag isOn[i] true.  Later, when isOn[i] && (millis()-onTime[i] > targetDelay[i]), turn the light off and clear the flag (via isOn[i] = false).  Within checker(), a condition like port == 6 translates to isOn[6], an expression which is true when light 6 is on, else false.
The approach of using arrays like onTime[] and isOn[] and targetDelay[], variable subscripts, and recorded on-times has several benefits:  It lets you loop through lights, getting rid of that needlessly repetitious code in checker(); it enables other processing in the main game loop (such as whack-testing) to proceed independently of light control; it allows multiple moles to pop up at the same time; and it allows different moles to have different or varying up times.

in cryptography you want to re-seed only once per session. use a timer to get more than 255 seeds.

if I don't include the delay(1000), the led will lights up and off very quickly, before the players are able to respond to it, any suggestion on how to improve this? thanks

If you don't have a delay the LED will stay in the last state you set it to. Why would it turn off?

Others have already mentioned the issues with the timing, score initialization and random number generation.
On your checker function you have 2 errors and one ugly piece of code.
Ugly code first - goto is BAD. About the only time it's acceptable is under an error condition, the rest of the time if you find yourself needing to use a goto then look at how you can improve the code structure.
Errors - You exist after an analog input is > 10 but only count >50 as a hit. As they hit it the value will ramp up so they hit a target you could see a value of 10, exit your loop and not score anything. You need to use the same threshold for both. (Another style point, if you have the same magic number in two places (e.g. 10 or 50) consider making them constants or #defines rather than hard coded numbers. It makes it a lot easier to change them without forgetting one of the locations).
The second error is that you only turn the LED off if they hit the correct target, if they get the wrong one you light the next target but never turn the first LED off.
The code below should solve all of these issues.
int checker(int port){

  char exit = 0;
  int mole;
  while (!exit) {                // until we get a hit
    for (int i = 0; i<5; i++) {  // check each mole in turn
      mole = analogRead(i);      // read the sensor
      if (mole < 50) {           // if over the threshold
        exit = 1;                // exit the while loop after this check
        if (i + 3 == port)       // see if they got the correct target. i goes 0-5, port goes 3-8
          score++;
        digitalWrite(port,LOW);  // turn the LED off
        break;                   // break out of the for loop
      }                          // end if hit
    }                            // end for loop
  }                              // end while loop
}

after amending my code with your suggestions, it still don't work. after I removed the delay(1000) for the LED, it turns on and off very fast and the score showed at the end is a random number. please provide more guidance. Thanks


text:
Control time without delay() Arduino
For the last couple of day I've been trying and failed many times just to not use the delay() funtion in Arduino. I have to admitted that my coding skill are extremely bad.
What i trying to do is:
If button is pressed:
Motor A and B move for 1 second at slow speed == > Motor A keep moving but at fast speed and motor B stop.
else:
Motor A and B both stop.
I managed to wrote the code by using delay function for that 1 second. However i got no idea how to do it WITHOUT DELAY() there will be sensor reading as well at the same time, i cant afford that 1 second delay of sensor reading).
Here is my code:
int dir1PinA = 2;
int dir2PinA = 3;
int speedPinA = 9; // Needs to be a PWM pin to be able to control motor speed

// Motor 2
int dir1PinB = 4;
int dir2PinB = 5;
int speedPinB = 10; // Needs to be a PWM pin to be able to control motor speed

int button = 6;

void setup() {  // Setup runs once per reset
// initialize serial communication @ 9600 baud:
Serial.begin(9600);

//Define L298N Dual H-Bridge Motor Controller Pins

pinMode(dir1PinA,OUTPUT);
pinMode(dir2PinA,OUTPUT);
pinMode(speedPinA,OUTPUT);
pinMode(dir1PinB,OUTPUT);
pinMode(dir2PinB,OUTPUT);
pinMode(speedPinB,OUTPUT);

// Define button pin
pinMode(button,INPUT);

}

void loop() {
  if( button == LOW){           // if button is pressed
    // Motor A (move slow) and B  moving
    analogWrite(speedPinA, 100);//Sets speed variable via PWM
    digitalWrite(dir1PinA, LOW);
    digitalWrite(dir2PinA, HIGH);
    analogWrite(speedPinB, 255);
    digitalWrite(dir1PinB, LOW);
    digitalWrite(dir2PinB, HIGH);
    delay(1000);

    // After 1 second Motr A (move fast)and B stop every time button pressed
    analogWrite(speedPinA, 255);//Sets speed variable via PWM
    digitalWrite(dir1PinA, LOW);
    digitalWrite(dir2PinA, HIGH);
    analogWrite(speedPinB, 0);
    digitalWrite(dir1PinB, LOW);
    digitalWrite(dir2PinB, LOW);
  }
  else
  {
    // Both motor not moving
    analogWrite(speedPinA, 0);//Sets speed variable via PWM
    digitalWrite(dir1PinA, LOW);
    digitalWrite(dir2PinA, LOW);
    analogWrite(speedPinB, 0);
    digitalWrite(dir1PinB, LOW);
    digitalWrite(dir2PinB, LOW);
  }
}

Please point me out the direction or give me an example of code. And I have already try the Blinkwithoutdelay Arduino example but it does not work for this case.
Very much appreciated.

Did... you... just misspell else as esle!?

This has been asked many times, both here and on the Arduino Forum. For one treatment (by me) see this.

Thanks for the link. Ill have a look and will try my best. Ha:)

Also posted on Arduino Forum

you need a state machine with two states (unpressed, pressing). You also save a timestamp each time the state changes. You can compare the last change's timestamp with the system time to determine if it's time to move to the next state. "unpressed" changes to "pressing" upon a button press (if state is unpressed). "pressing" changes to "unpressed" if it's been 1000ms since the last change AND the button is not pressed.

Just got the whole thing working with if statement. Its very messy but its works like a charm.
I did try to approach thet FSMachine method. But i think my brain just not good enough for it, LOL

Assuming the button isn't held down for 50 days straight, you can use the millis() function and basically set a marker of the current time when the user pushes the button down. To do this, you need to detect when the user switches from off to on, not when while the button is pushed or you'll be resetting the marker every time.
Then you record the time every loop while the button is pushed down. If the current time is more than one second after the time recorded by the marker, you switch motor B off and make motor A as fast speed like you said. When the button is off, like you said set both motors to off.

The 49.71-day  millis() rollover is relevant only if button presses longer than that are allowed.   For any shorter interval, unsigned long arithmetic works ok, even if a rollover occurs during the interval.

Well i said that just incase he's pressing the button down for 50 days straight ^.^

I got the thing working. So thanks.
The things is gonna run 3650 day. But the button only pressed for maximum 1 min. So it should be fine i guess. Anyway thanks for the advise guys

You might want to use a timer. There are some libraries available for Arduino that precisely do that.
You can either use a library that implements a software timer (something similar to comparing millis(), but with powerful additional built-in features such as button debouncing, timed pulses, etc.) or use a library that deals with the hardware interrupts of the MCU.
As an example take a look at this particular library: Timer. I think you'll love it!

Thank youn I got the code working. Using millis() and a bunch of if. But i definitely have a look at the timer library.

If button is pressed: Motor A and B move for 1 second at slow speed == > Motor A keep moving but at fast speed and motor B stop. else: Motor A and B both stop.

I would do a quick state machine:

STATE / button released: do nothing;
      STATE / button pressed: run motors a+b;
      STATE / run motor a+b: run motor a+b; if 1 second has passed, advance to just run motor a;
      STATE / run motor a: run motor a at fast speed and stop motor b.

fairly easy to code as well.


text:
USB DEVICES WITH THE 32U4?
I have an Arduino Pro micro and I need to know if it is possible to use an USB device like a camera or things like that Since the processor is a 32U4. the USB Shield is for the Arduino Uno and I don't want to buy more stuff.

no; you can't get a "driver" for a normal USB camera for the MCU. you would need something closer to a Pi...

Some important facts:

The 32U4 cannot act as a USB master, only a USB device (it doesn't have a USB OTG interface).
The USB shield is an SPI based device. It can communicate with any host MCU that can use SPI, as long as you can wire it in properly.
The Arduino doesn't have the processing power or memory to deal with the sheer onslaught of data a USB camera sends.

So yes, you could use the USB shield with a 32U4 based board if you can work out the right wiring. However you will not be able to use things like cameras with it since you lack the processing power to do it.
For camera work you need something more like a Raspberry Pi.

or a serial/ftp camera...


text:
Arduino board as USB/serial for a Nano with broken USB
I broke the USB connector on an Arduino Nano and I am trying to use my Uno board as a USB/serial adapter to be able to upload sketches. The broken Nano came with a customized bootloader (avrdude -c arduino compatible), which I do not have a copy of. The content in the HEX files I have is encrypted, it has to go through the bootloader for the plain code to be flashed. This rules out ISP.
I came up with this:

Please note that the ATMega on the Uno board is removed. As I am proxying the Nano through the Uno board, I am wiring RX to RX and TX to TX.
The problem I face is that it seems the Nano board is not receiving data from the PC. Everything else works:

pressing the reset button on either board resets the Nano
TX from the Nano goes back to the PC (the current sketch on the Nano prints some stuff on boot), TX leds blink accordingly on Nano and Uno boards
RX led on the Uno board blinks when PC sends something, but RX led on the Nano board does not blink in that case
connecting the RX/TX Nano pins to a USB/serial cable lets me send and receive data to/from the sketch

I tried with another, non-broken, Nano (standard bootloader) and I have the same issue, so I think the broken Nano is fine. If I upload a sketch that continuously writes to the serial port, the PC receives it. If I upload an "echo" sketch, I do not get anything back (the "echo" works well over direct USB connection).
I am a software guy, my apologies if I am doing something obviously wrong. I read several pages on the topic, I couldn't spot a fix. The boards are not official Arduino products, but I am not sure this is relevant. I wonder if part of the answer is related to the fact that the USB/serial conversion is handled by a Mega16U2 chip rather than something like a CH340, now useless on the broken Nano.
Some links that I checked:

Arduino UNO as USB to serial TTL converter
Arduino Uno as an FTDI RS232 to Serial Adapter
Using an Arduino or Seeeduino for its FTDI chip
Use an Arduino UNO as a USB-to-Serial converter

You probably need to remove the USB interface chip from the broken board, or else cut its connection to the target processor, so that the external interface can drive it instead.  Sometimes there is a 1K or so resistor to permit something else to take over, but your source Arduino is even more likely to have that resistor, so the wrestling match may end in a draw.  If there is such a resistor on the target board, removing it is probably the best solution.

I am measuring 1kOhm between the CH340G TX/RX pins (2 & 3) and the Nano RX/TX pins (0 & 1). If I understand correctly, I have 1kOhm on the Uno board with the real stuff I want going through it, and the CH340G still working despite the missing the USB port and generating some noise which also goes through a 1K resistor. I have three questions: why would TX work but not RX? Is cutting the power from the CH340G enough? Can I get the RX on the Uno board before the 1k resistor and feed this instead to the Nano? Thanks for the quick reply.

The target's disused USB serial chip is not generating noise, but arguing about the proper signal level, only on the side where it would be transmitting - you can have both serial interfaces receive from the target ATmega without conflict.  Cutting power to disused chips is generally not a sound solution - they may draw power from I/Os instead, both stressing the chip and loading those I/Os to the point where the signal levels are invalid.  You really should remove the resistor on the target, but if you can get the signal upstream of the resistor on the source that might work temporarily.

I found a metallic hole (test point?) by following the track connected to pin 9 of the Mega16U2, before a component that nicely showed 1kOhm on my multimeter. I wired everything as shown on my picture, except for the RX wire, now going from the hole to the Nano. As expected, it worked. Thanks again, for your quick reply and for teaching me something!

You may want to connect +5v to +5v not to VIN.

@Majenko I don't think I should do so. As stated in the Arduino documentation (https://www.arduino.cc/en/Main/ArduinoBoardUno) the 5V pin outputs a regulated 5V.

No, that is wrong. Do not believe everything you read on the Arduino website. The 5v pin is connected to the regulated 5v rail. It neither outputs nor inputs. It just is. Since you don't have a high enough voltage going in to vin for the regulator to work properly you don't have a regulated 5v rail on the nano. So link it to the regulated 5v rail of the Uno to make it a regulated 5v rail.

As explained in comments by Chris Stratton, both the Mega16U2 on the Uno and the USB/serial chip on the Nano are competing for the signal level. Removing the resistors on the RX/TX lines between the USB/serial chip and the ATMega on the Nano board will prevent it from interfering with the signals exchanged with the Uno.


text:
Bot not activating after button press
This bot is supposed to begin moving forward when the button is pressed, and stop after counting 3 lines of tape on the ground. Currently it is set up to scan the color of the floor at the beginning and count any major differences as a line of tape. Unfortunately I can't test its tape-sensing capabilities due to not being able to get it to actually start. It will only move if I hold the button down continuously, and stops as soon as I release it. Here is the code and images (It uses the Arduino Pro Mini 3.3v):
#include <SFE_ISL29125.h>
SFE_ISL29125 RGB;
unsigned int master2;
unsigned int detect2;
boolean isOn = false;
unsigned int accumulator = 0;

void setup() {
  RGB.init();
  pinMode(7, INPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  master2 = RGB.readGreen();
}

void loop() {
  if(isOn) {
    if(accumulator < 3) {
      detect2 = RGB.readGreen();
      digitalWrite(8, HIGH);
      digitalWrite(9, LOW);
      if(detect2 <= (master2 - 10) || detect2 >= (master2 + 10)) {
        accumulator++;
      }
    } else {
      accumulator = 0;
      isOn = false;
      digitalWrite(8, LOW);
      digitalWrite(9, LOW);
    }
  } else if(digitalRead(7) == HIGH) {
    isOn = true;
  } else {
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
  }
}

Could you replace the various hard-coded GPIO numbers with constants (e.g. #defines) please? It's hard(er than I can be bothered with) to guess what the various pins do.

Pin 7 is the button, pins 8 and 9 are the motor. I really can't be bothered with using constants since I'm rushing to get this done.

Possibly it accumulates so fast that it will immediately stop when you release the button?

Could I solve it by increasing the color tolerance? Or switching to one of Parallax's Line Follower Kit sensors that I have lying around?

Rip out the detector code and test it. I strongly suspect your readings are causing problems, and the code to count the three lines is broken anyway.

I already tested the components individually. What do you mean by the count code is broken?

Do it step by step. For starter, make it move after button is pressed without using sensor. I agree with @MarkSmith , its highly possible that your sensor reading algorithm is the problem

I strongly suspect the main problems with your code are in these lines:
  if(detect2 <= (master2 - 10) || detect2 >= (master2 + 10)) {
    accumulator++;
  }

If I understand correctly, with this code you are attempting to tell whether you have been over a line of tape, which will be indicated by a change in reading from RGB.readGreen(); - say high, low, high.  If so, accumulator++.  (I have no opinion on whether this is a valid way of sensing it, or how well your sensor will work.)
This is definitely broken in one way, and probably broken in another.
First the definitely-broken way:
You want to sense down-up-down-up-down-up (or up-down-up-down-up-down).  Your code senses simply three higher or lower readings.  Your loop() takes no time at all, so when your buggy moves onto the tape, it will immediately read (say) high, then loop round, read high again, loop round and read high again, and again. accumulator is now 3 and we stop the motor.
Second, the maybe-broken way:
What value does master2 have?  Consider that it is an unsigned integer.  You are subtracting 10 from it.  What do you get if its value is 5?  It can'be be -5 because it is unsigned.  How you solve this depends on the possible range of values from RGB.readGreen();.  The implementation looks like it could give a value anywhere in the range, so we have to be careful.
Here's my reworking of your code.  It assumes the concept of checking for values which vary by 10 from the original value is sensible - I've no idea if it is.  (I don't understand what this "middle" values means, but you say you've "already tested the components individually" which I don't believe because your code could never have worked but, assuming you saw something similar working...)  It also makes a very big assumption that the value will change cleanly - from higher to lower exactly once per edge of strip, with no wobbling.  Log out some values to find whether it really does.
#include <SFE_ISL29125.h>
SFE_ISL29125 RGB;
int master2;
boolean isOn = false;
int changes = 0;

#define BUTTON 7
#define MOTOR_A 8
#define MOTOR_B 9

#define LOWER 0
#define HIGHER 1
int last_state = 0;

void setup() {
  RGB.init();
  pinMode(BUTTON, INPUT);
  pinMode(MOTOR_A, OUTPUT);
  pinMode(MOTOR_B, OUTPUT);
  master2 = (int)(RGB.readGreen()/2);
}

void loop() {
  if(isOn) {
    // Wait for 6 changes: up-down or down-up, three times.
    if(changes < 6) {
      int detect2 = (int)(RGB.readGreen()/2);
      digitalWrite(MOTOR_A, HIGH);
      digitalWrite(MOTOR_B, LOW);
      // Count _changes_ in state only
      if(last_state == HIGHER && detect2 <= (master2 - 5) {
        last_state = LOWER;
        changes++;
      } else if (last_state == LOWER && detect2 >= (master2 + 5)) {
        last_state = HIGHER;
        changes++;
      }
    } else {
      accumulator = 0;
      isOn = false;
      digitalWrite(MOTOR_A, LOW);
      digitalWrite(MOTOR_B, LOW);
    }
  } else if(digitalRead(7) == HIGH) {
    isOn = true;
  } else {
    digitalWrite(MOTOR_A, LOW);
    digitalWrite(MOTOR_B, LOW);
  }
}


text:
Can I monitor data of variables while simulating Arduino on Proteus?
I simulate Arduino UNO on proteus 8 Pro. I use Arduino software for writing a program.
Is it possible to trace or know the data that are stored in valuables while running the code on Proteus?
I would like to know how the code is running step by step so that I can find logical errors.
Thank you,

It is possible. By using several tools on "Virtual Instruments Mode" such as SPI-Debugger, I2C-Debugger, Virtual Terminal, or Logic Analyser.

I would like to know how the code is running step by step so that I can find logical errors.

For example, you can use Virtual Terminal and print the value of variables you want to examine


text:
Can't communicate my 2 Xbee modules using API mode
I want to create a network with 10 routers/end devices and one coordinator with my Xbee Pro S2C devices. For That I know I have to do it in API mode. I configured one as a coordinator (DH=0, DL=FFFF, CE=1, AP=1) and one as a router (DH=0, DL=0, CE=0, AP=1) and then I tried making them communicate with the xbee-library for Arduino.
I used this for the coordinator:
XBee xbee = XBee();
uint8_t *payload= "Hello!";

//XBeeAddress64 CoordinatorAddr64 = XBeeAddress64(0x0013A200, uint8_t *payload= "Hello!";0x40C8CA96); //Put the address of the node explicitly.
//XBeeAddress64 CoordinatorAddr64 = XBeeAddress64(0x0013A200, 0x4125f767); //The address DH:DL = 0 for coordinator always
XBeeAddress64 CoordinatorAddr64 = XBeeAddress64(0, 0); //The address DH:DL = 0 for coordinator always
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
ZBTxRequest zbTx = ZBTxRequest(CoordinatorAddr64, payload, 7);
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
ModemStatusResponse msr = ModemStatusResponse();

void setup()
{
  Serial.begin(9600);
  Serial1.begin(9600);
  xbee.setSerial(Serial1);

  Serial.println(("ZB Node-" + String(NODE_TYPE)+ " FW Version:"+ String(NODE_VERSION)));
  Serial.println(("Arduino Setup Finished on " + String(NODE_NAME) + ". Console should show up!"));
  Serial.println("------------------------------------------------------------------------------");
}

void loop()
{
  // put your main code here, to run repeatedly
  String sample;          //Our incoming messages from coordinator will be collected in this variable.
  uint16_t senderShortAddress;

  xbee.send(zbTx);

  delay(5000);
}

And for my router, I'm simply trying to receive the data and I'll send data to the coordinator when I am able to read data.
XBee xbee = XBee();

uint8_t *payload= "Hi!";

//XBeeAddress64 CoordinatorAddr64 = XBeeAddress64(0x0013A200, 0x40C8CA96); //Put the address of the node explicitly.
XBeeAddress64 CoordinatorAddr64 = XBeeAddress64(0x0013A200, 0x4125f755); //The address DH:DL = 0 for coordinator always
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
ZBTxRequest zbTx = ZBTxRequest(CoordinatorAddr64, payload, 4);
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
ModemStatusResponse msr = ModemStatusResponse();

void setup()
{
  // put your setup code here, to run once:
  pinMode(STATUS_LED, OUTPUT);
  pinMode(ALIVE_LED, OUTPUT);

   //initialize timer-1 (16 bit timer) for normal timer overflow mode
  Timer1.initialize(500000); //defined in value/1000000 toggleStateFn called every 500 milliseconds.
  Timer1.attachInterrupt(toggleStateFn);

  Serial.begin(9600);
  Serial1.begin(9600);
  xbee.setSerial(Serial);

  Serial.println(("ZB Node-" + String(NODE_TYPE)+ " FW Version:"+ String(NODE_VERSION)));
  delay(3000);
  Serial.println(("Arduino Setup Finished on " + String(NODE_NAME) + ". Console should show up!"));
  Serial.println("------------------------------------------------------------------------------");
}

void loop()
{
  uint16_t senderShortAddress;
  xbee.readPacket();

  if(xbee.getResponse().isAvailable()){
    Serial.print("Available ");
    Serial.println(xbee.getResponse().isAvailable());
    Serial.print("Api ID: ");
    Serial.println(xbee.getResponse().getApiId());

    XBeeAddress64 senderLongAddress = rx.getRemoteAddress64();
    senderLongAddress = rx.getRemoteAddress64();
    Serial.print(senderLongAddress.getMsb(),HEX);
    Serial.println(senderLongAddress.getLsb(),HEX);

    //Get the 16bit address of source node from incoming packet.
    Serial.print("Source Node short address:0x");
    senderShortAddress = rx.getRemoteAddress16();
    Serial.println(senderShortAddress,HEX);
  }
}

When I run the code I get nothing on the router.

I checked my connections (OK, Tx1 for MEGA connected to DIN, pin3, and Rx1 connected to DOUT, pin 2);
I verified that the signal is getting to the Xbee
Verified the packet. Connected it to serial 1 and just printed it to the serial console and I see that the packet goes correctly to the Xbee (7E 00 15 10 01 00 7D 33 A2 00 41 25 F7 67 FF FE 00 00 48 65 6C 6C 6F 21 00 63) and I can see that the same packet is going in the signal
When I first got the modules I just started printing from one side to the other and it worked. It was in transparent mode and not in API mode.

The thing is that I can't even get one coordinator and one router to communicate and I want to create a coordinator-10router network. Which means I'm in trouble. Could there be something wrong in my configuration? Is there something wrong in my code? Perhaps I'm using the wrong XbeeAddress64? Is it a problem with the library I'm using?

I'm struggling with XBEE communication myself, but should xbee.setSerial(Serial) be xbee.setSerial(Serial1)?

The library didn't work so i built my own much simpler library. It started working just by coincidence. The problem was in my physical connections to the xbee module. The signals were either not getting to the module or to the arduino (I wasn't using a shield, I simply solderedwires to the pins and then to a protoboard and I found out that the protoboard was faulty)


text:
New Arduino Motor Shield Short Circuiting my board?
I just got this today, plugged it in my arduino, and the arduino light starts dimming until you cannot see it any more over the course of 5 seconds. The Computer disconnects the arduino when the light is off (Ding Dong Sound). I found pulling the VIN Connector Jumper/Power Jumper will stop the short circuit and work, but that defeats the purpose, as the board wouldn't even powered.
Here is the video:
YouTube
Is the motor board broken? If so in what way? are the wires on the board simply broken? Is it due to bad soldering?(I checked solder, looks fine).
Arduino Model: Arduino UNO by Elegoo
Motor Driver Model: L293D Driver Board
Ebay Listing For Item
(I tried using this with a MEGA also, would short it as well).

Please edit your question to include the name, model number, and a link for the  motor shield.  Otherwise we're just guessing

post is edited.

Does the board work ok if you pull that jumper and supply motor-power externally?  If so, maybe the Uno's power is marginal.  If not, maybe a chip or a capacitor is bad on the shield.  Looks like the chips are socketed, so you could take them out (sequentially) and see if shorting problem goes away.  If one of two LM293's is bad you could still use the other.  But before removing any chips or capacitors, get a really bright LED flashlight and carefully look all over the board for solder splashes, wire fragments, etc

I pulled all the chips out. They all work in the middle slot. The left and right slot will immediately short it, even if I place one

Have you tried it with nothing connected to the board and the jumper removed?  At the end of the day its a $2 board, from what you have described it has a fault and the seller would have a hell of a problem denying it.  Buy another from a different seller and see if you can get this one replaced although it might cost more to send back than its worth.  If you carry on testing it, trying to diagnose the fault you may trash you Arduinos.  Keep the board for spare parts, chances are you'll fry the chips. :)

Yep it's a 2$ chip. The problem is it takes 3 months to ship X_X

George, the flaw with a “all work in the middle slot” test is that the middle socket is wired for a 74HC595 shift register, vs LM293.  Note, for parts list of original Adafruit 74HC595 + 2 LM293 board  board, see Adafruit motor shield, from a 15-page tutorial on this type of board.  Also see Adafruit's mshieldv12schem.png schematic  that may allow you to check your board's wiring

I just checked. All 3 chips are identical. Is that a problem? The markings at the top are all 74HC595

Thanks to @jwpat7, I have discovered that the reason it is not working is that the seller has messed up and sent me 3 of the same chip, 74HC595N. After doing some research, I have purchased the LM293D Chips.

That's really horrible.  Though it's worth noting that the L293, even if you actually got them, isn't a great solution to begin with.  If you are facing down long shipping delays you might want to consider preemptively ordering a more modern solution overall rather than waiting for the L293's only to perhaps be dissappointed by them.  Especially at lower voltages something using a TB6612FNG or similar may be preferable.  Do note also that you really shouldn't be powering your motor drivers from the Arduino's logic supply or regulator.


text:
Square LED vs Round LED
I'm trying to choose between square or round LEDs.  I would like to select an LED that will "project" light and I cannot find any information comparing the two types.
Which style of LED will project light better?
Projection, for the purposes of this question, means casting light "in-line" with the LED.  For example, an LED right out of the box with straight leads plugged into a breadboard on a flat table will stand vertically.  In this case, I would like to project as much light onto the ceiling as possible.  I hope this makes sense.
If it matters, I'd like to use water clear blue LEDs.

Go with the round ones. The curved top acts like a lens, making it shine light in a bundle.

Many of the square or rectangular LEDs with leads  – that is, not surface mount devices (SMD)  –  that I've seen are intended for use as panel indicator lights, so are not very bright.   On the other hand, among SMD devices square, rectangular, and round lights run the whole gamut of brightness.  Of course many white LEDs, square or round, are extremely bright because of being intended for illumination.
For projecting a beam against a ceiling, adding optics to the LED may be the best approach.  For example, buy some 99¢ flashlights like “Waterproof 3500LM Pocket LED Flashlight Zoomable LED Torch Mini Penlight Light” on ebay, and either add a blue filter in front of the lens or replace the LED with an ultrabright blue LED, using the zoomed-out flashlight lens to concentrate the light.  Also, search for 10° or 15° “PMMA LED lens” on ebay, Amazon, aliexpress, etc.
Note, for determining if any given LED will project a tight bright beam, look at the angles of its beam pattern.    This diagram (from Led Buying tips at sunriseled.us) contrasts the intensity of a 30°-beam LED with that of a 70°-beam LED.  The diagram at left below (from dimmable-gu10.com) is typical of intensity-vs-angle diagrams, which usually are shown on a polar plot like that, with a narrower oval corresponding to a tighter beam.  The diagram at right below shows the same information, in a perhaps more easily comprehended form.


text:
Read frequency to voltage with Arduino
How to read frequency into voltage with Arduino with an external source of frequency of 0-1Khz max?

Wait, first of all what are you trying to achieve? Second, "what chip ... with arduino". Do you want an external IC or you want to do it with arduino?

yes external IC , im sorry for my english

What's wrong with using the Arduino to just measure the frequency directly?

i'm new with this things, but i found this pjrc.com/teensy/td_libs_FreqMeasure.html a library work with arduino for my range 0,1 - 1 KHz i think this will be fine , thank's for reply

I found this link. This is a library and will work with Arduino for my range 0,1 - 1 KHz. I think this will be fine.

In the past I used the LM2917 for this purpose:
http://www.ti.com/lit/ds/symlink/lm2907-n.pdf
That IC is a frequency to voltage converter, so it perfectly suits your need. According to some quick calculations I made it can go to some tens of kHz, so if your signal is up to 1kHz it should be fine.
Now, this is the answer to your question. But... You can easily read the frequency directly with the arduino... If your purpose was to read the frequency, I suggest you to read something about the X-Y problem

i found this https://www.pjrc.com/teensy/td_libs_FreqMeasure.html a library work with arduino for my range 0,1 - 1 KHz i think this will be fine , thank's for reply

@FrancescoValla ok, so you simply asked the wrong question. Now, please edit your question (but do not remove the original part) saying that your purpose was not to convert, but rather to read the frequency, so with that library you managed to solve your problem..


text:
Why does the Arduino Uno WiFi network connection drop when requesting a page?
I see frequent errors where the network connection to my Arduino Uno WiFi drops when I am requesting a web page. I wrote a simple REST server, and some of the pages will load as expected, but others will fail after loading half of the the text, and I notice that the network connection drops in the middle of these events. Why is the network connection dropping like this?

Hard to tell without code.

I saw this error when I was running low on RAM. The Arduino Uno WiFi appears to drop the network connection in low memory situations. One fix that made a significant difference for my program was to wrap all of the string literals in the F() macro. This moves the strings from ram to flash storage, and in my case quickly freed 500 bytes of SRAM (25% of the available RAM on this board).
For example, replace:
client.println("HTTP/1.1 200 OK");

with
client.println(F("HTTP/1.1 200 OK"));

Some other memory optimization may also be necessary.
Another possible cause of these symptoms would be low voltage, possibly from trying to draw too much power from the board to power external devices, but in my case there were no external connections, and I confirmed it was a low-memory issue.


text:
Using same pins number in different arduino?
I'm new beginner in programming arduino, and I want ask a question about arduino code, this is the problem " i used two arduino to build a robot, but i don't know how to set the code that for two arduino uno that pins in first arduino i used them all and now i wanna use the pins in second arduino, and how write code for the second arduino, which it is the same pin number i used  in first arduino, how to creat a code? thanks a lot guys for answer my question... (sorry for my bad english)...

Do both Arduinos run the same sketch, but with different pins? If the sketches are different there is no problem. If the sketches are the same, #define ARDUINONUMBER 1 and #if ARDUINONUMBER == 1, #else, and #endif can make the pin numbers change by changing just the #define statement. If that isn't the problem, please explain more.

I also do not fully understand the question.
If the 2 arduinos run independently, there should be no problem?
If you are saying you want 1 Arduino to be the MAIN ONE.. but you have run out of pins.. and want to add another Arduino (to have more I/O pins).. but have the MAIN ARDUINO still 'control' the second Arduino.. then you'd need to set up a way for the MAIN Arduino to communicate with the SECONDARY Arduino.
I suggest using Serial Comm (Software Serial) to do so.

this is simple problem, I have two arduinos, 1st arduino all pins is connected to their functions, now i have the second arduino, in 2nd arduino i wanna use the pins for other function, both arduinos is in same sketch, how to write the code for the both arduinos, how do i connect between them? (thanks for respons my question before, sir)

You want two Arduinos, running the same sketch, to use the same pins for different purposes? How will that work? Why do you want to do that? Is this an X-Y problem?

You could look at GPIO expanders like the MCP23017, cheaper and easier than a second Arduino.

The notion that “both Arduinos are in the same sketch” is slightly off.  Each of the Arduinos will contain a program; their programs might be identical if you do some fancy programming, but it is simpler to write one sketch per Arduino.
Thus, your first Arduino will run a sketch designed to control the devices it is connected to, and your second Arduino will run a sketch designed to control the devices that it's connected to.  Conceivably, you might have some devices that both Arduinos connect to.
Calling the two sketches S1 and S2, the device on pin number n as referred to in S1 will typically be a different device than the one on pin number n as referred to in S2.  Most but not all of the pin usage assignments for each pin number will be different in one sketch versus the other.
It's likely the two Arduinos will need to communicate with each other.  For a range of methods, see for example  How to have an Arduino communicate with 3 other Arduinos.  For additional detail see Arduino-to-Arduino serial communication and How to network many Arduinos with sensors using I2C.
If you decide to use I2C, then also see MasterWriter Tutorial and Wire Library webpages at arduino.cc.

To expand on my comment, if you begin your sketch with conditional definitions, you can compile it for different sets of pin assignments just by changing the #define ARDUINONUMBER xxx statement:
#define ARDUINONUMBER 1

#if ARDUINONUMBER == 1
#define FRONTMOTORPIN 7
#define REARMOTORPIN  8

#elif ARDUINONUMBER == 2
#define FRONTMOTORPIN 12
#define REARMOTORPIN  13

#else
#error Board number must be 1 or 2.
#endif

void setup(void)
{
   pinMode(FRONTMOTORPIN, OUTPUT);
   pinMode(REARMOTORPIN, OUTPUT);
   ; // etc
}

void loop(void)
{
   ;
}


text:
Voltage and Current and Arduino
I put a LED into 3.3V of the arduino and Ground, and it blew my LED violently, smoke was everyone, the whole half top of the led blew up across my room.
However, when i program the arduino with Pin13 HIGH per say, it will not blow up. Will be lit brightly. (Both using no resistors). However, if I plug mroe stuff in the board, for example, a lcd screen, rotary switches, and pushbuttons for my program, the LED dims to such a low brightness I cannot see.
Why is this? How Do I fix it?
Schematic:

Note, that i am using a mega, and some of it is slightly changed, and LED is being powered from A0 (Or Pin 54 on Mega)

You have pin 13 tied to ground in that schematic. Are you really settling pin 13 to high output? It would be very useful to have the schematic for your actual circuit, not some other circuit which bears some loose resemblance to your circuit ☺

yep this is the circuit i am using, just with addition to the led, and some pin changes. Yes I am plugging 13 to ground according to this schematic, found it suspicious but that is what it said on schematic.

I'm surprised it's still working then. Don't tie high outputs straight to ground. Without seeing the code it's difficult to say what the right thing to do is, but probably just disconnect pin 13 and leave the switches connected to ground.

@MarkSmith does say at the bottom pin 13 stops flutter on the schematic

It also says it's configured as input. Don't set it as output then.

You must use a resistor. See The care and feeding of LEDs

How Do I fix it?

Use a current-limiting resistor.

The question is, that i have more electronics attached to it, and without a resistor it is already dim to the point i can barely see it. Adding a resistor would make it worse, i wont be able to see it at all.

No it won't. Try it.

For one thing, not using a resistor effectively channels almost all available current through your LED. That is taking power from other things that need it. Perhaps if you post a schematic?

You are Right @MarkSmith, however, it dosent improve brightness at all. I can barely see it, just like before.

What value resistor did you use, and what type of LED is it?

Used a yellow diffused led, 500ohm resistor that came with it

“I put a LED into 3.3V of the arduino and Ground, and it blew my LED violently ... the whole half top of the led blew up ...” –

Current through the LED was so high that a tiny interconnect wire blew up.  In typical LEDs, an almost-invisible wire connects from the anode lead frame to the LED chip on the cathode lead frame (at left and right, respectively, on each of the three lead frames pictured below).  That wire acted like a fuse and blew up.  With such a fine wire, it doesn't take particularly much current to pop it.
The diagram below shows how current through an LED increases exponentially as voltage across it rises.  The diagram is from "mikesflightdeck.com LED dimmer" webpage, a page which may be useful in helping you understand why LEDs need series resistors or some other form of current limiting, eg a constant-current circuit.

When an LED is powered by an Arduino port output, the port's internal resistance is enough to limit LED current to non-lethal (to the LED) values.  (However, the port itself may get burned out by delivering current beyond its 40 mA absolute max current rating.)

“However, if I plug more stuff in the board ... the LED dims to such a low brightness ...” –

The stuff being plugged in apparently is drawing enough current to drop the system voltage.  This can happen if your Arduino is powered by a low-power source like a 9-volt transistor-radio battery, or a laptop USB port that can't deliver the 500 mA that a standard USB port is rated at.
If either of those causes is behind the problem, use an external power supply, plugged into the power jack or connected to Vin and Ground.  You can buy suitable “wall-warts” online, or at an electronics store, or quite cheaply at second-hand or thrift shops.
But if neither of those causes is the problem, you may have a clone of an Arduino using substandard parts, and unable to deliver reasonable current through its regulators.  In this case, find a well-regulated 5 V supply to connect between +5V and Ground or to the USB's power pins.  Such supplies are available not only at the aforementioned venues, but also whereever USB phone-chargers are sold, since 5.0 V is what a USB phone-charger should deliver.

Good explanation, but the main point which is missed here is that you MUST use a current-limiting resistor in series with your LED. You are lucky not to have cooked the Arduino, and if you beef up the power supply attempting to stop the dimming, you WILL cook it. Different LEDs need different resistors, but 330R will probably get you started.

so what i dont get is why it is exactly doing this. To my understanding, dosent voltage affect whether or not my led blows?

@MarkSmith, the answer mentions those points.  Paragraph 3 says “LEDs need series resistors or some other form of current limiting” and paragraph 4,  “the port itself may get burned out”

@GeorgeJones, yes, voltage is involved.  As shown in that graph of LED current vs voltage, LED forward current increases exponentially with voltage instead of a linear Ohm's Law increase


text:
how to wrap/scroll text with U8G2
Does anyone know how to wrap and or text using the U8G2 Libary?   I know there are other libraries that do this for you, but I'd like to use U8G2.
Thank you!
my code's here for reference.  It's not clean, but it works for now https://create.arduino.cc/editor/shaiss/0a2736f4-fb79-4e12-b9d7-fb15ff6757b7/preview

You have to do it manually. Scrolling is a simple matter of printing substrings and padding with spaces. Wrapping is a simple matter of printing substrings on different lines.

The Arduino Uno has very limited amount of memory to implement scrolling and wrapping of text for an LCD driver in general. The sketch has to do this, e.g. calculate line breaks, sub-section of text to be displayed, update when focus changes (i.e. scroll), save text, etc. Your sketch seems to be only a limited amount of text so you should be able to do this calculations, save of state, text box projection, etc.

You can do something like
void loop(void) {
    u8g2_uint_t x;

    u8g2.firstPage();
    do {

        // draw the scrolling text at current offset
        x = offset;
        u8g2.setFont(u8g2_font_inb30_mr);       // set the target font
        do {                                // repeated drawing of the scrolling text...
            u8g2.drawUTF8(x, 30, text);         // draw the scolling text
            x += width;                     // add the pixel width of the scrolling text
        } while( x < u8g2.getDisplayWidth() );      // draw again until the complete display is filled

        u8g2.setFont(u8g2_font_inb16_mr);       // draw the current pixel width
        u8g2.setCursor(0, 58);
        u8g2.print(width);                  // this value must be lesser than 128 unless U8G2_16BIT is set

    } while ( u8g2.nextPage() );

    offset-=1;                          // scroll by one pixel
    if ( (u8g2_uint_t)offset < (u8g2_uint_t)-width )
        offset = 0;                         // start over again

    delay(10);                          // do some small delay
}

this is taken from here.
It is an excellent lib, but it is can require big amount of memory, fit very well on ESP8266 (tried on nodeMCU) / ESP32.
Of course on ESP32 it is faster.
Used for small OLED 0.98" screen


text:
Arduino serial controlled tone generator only working with single digit ints?
I'm writing a small program for my arduino which allows me to send two int values over serial to be interpreted. The first is a frequency Hz value and the second is a a length milsec value.
The code works, and plays the correct tone for the correct amount of millis, but only for single digit integers. If a double or more digit integer is sent then the arduino loops through the code several times and plays the wrong tone.
Here is my code:
const byte LED = 13; /* LED Pin */
const byte SPK = 12; /* Speaker Pin */
const int BAUD_RATE = 19200; /* Baud Rate of Input */

void setup(){
  pinMode(LED, OUTPUT);
  pinMode(SPK, OUTPUT);
  Serial.begin(BAUD_RATE);
  Serial.setTimeout(0);
  tone(SPK, 1000);
  delay(200);
  noTone(SPK);
  Serial.println("System ready for data");
}

void loop(){
  Serial.println("tone");
  while(Serial.available() == false){
    delay(0);
  }
  int toneToPlay = Serial.parseInt();
  Serial.println("delay");
  while(Serial.available() == false){
    delay(0);
  }
  int delayValue = Serial.parseInt();

  tone(SPK, toneToPlay);
  delay(delayValue);
  noTone(SPK);
}

Expected result is the ability to enter any tone and delay and the arduino plays it then asks for another tone and delay.
Any help is much appreciated.
EDIT: Here is my new code. It does what I want, the only issue is there is a pause after I type the tone value before it asks for the delay value, and a pause after the delay value before it plays the tone. I can't have this delay as data will eventually be sent by a piece of software to the arduino. How can I fix this delay? New code:
const byte LED = 13; /* LED Pin */
const byte SPK = 12; /* Speaker Pin */
const int BAUD_RATE = 19200; /* Baud Rate of Input */

void setup(){
  pinMode(LED, OUTPUT);
  pinMode(SPK, OUTPUT);
  Serial.begin(BAUD_RATE);
  tone(SPK, 1000);
  delay(200);
  noTone(SPK);
  Serial.println("System ready for data");
}

void loop(){
  Serial.println("tone");
  while(Serial.available() == false){
    delay(0);
  }
  int toneToPlay = Serial.readString().toInt();
  Serial.println("delay");
  while(Serial.available() == false){
    delay(0);
  }
  int delayValue = Serial.readString().toInt();

  tone(SPK, toneToPlay);
  delay(delayValue);
  noTone(SPK);
}

What do you mean by delay(0)? 2) Have you tried typing faster?

Try non-blocking read to a buffer instead. Build a string to convert to an integer. And check how parseInt() works. There is a timeout! This might not be sufficient.

@EdgarBonet the delay(0) is a time filler which make the arduino do something while it waits for serial data. I can't type fast enough, I get five requests within a fraction of a second.

@MikaelPatel Non-blocking read buffer?? Whats that?

@MikaelPatel I know there is a timeout. I tried to turn off the timeout at the start of the code with Serial.setTimeout(0). I'll try the string thing now.

This “filler” serves no useful purpose. You can just remove it, your code will only be cleaner. 2) If you really did setTimeout(0), then of course you cannot type fast enough! You have just asked Serial to wait no more than 0 milliseconds for you to type the digits.

The Arduino readString, parseInt() etc functions are inherently flawed in the way they work. Don't use them if you value your sanity. Read this for how to do it properly: https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/

Hint: How does it know when you've fished typing your number and there are no more digits to follow?

@Majenko I'll try this later


text:
How can I see if volume buttons of Apple earphones are pressed?
I need to be able to see if the volume controls and the middle button of Apple earphones are pressed.
I am using an Arduino Uno. I was thinking about using the analogRead function.
I tried connecting the ground of the audio jack to the ground of the Arduino, the micro of the audio jack to the analogPin 0 on the left and right of the audio jack to the 3.3 volt output of the Arduino, but the results of the analogRead are not really useful. They are constantly changing.

So guys i have this code that constantly gives a bunch of numbers. They are never constant.
int analogPin = 0;
int ledPinBlue = 8;
int ledPinRed = 9;

int val = 0;
int times = 0;
int clickTimes = 0;

void setup()
{
  pinMode(ledPinBlue, OUTPUT);
  pinMode(ledPinRed, OUTPUT);
  times = 0;
  Serial.begin(9600);
}

void loop()
{
  val = analogRead(analogPin);
  if (val == 0) {
times = times + 1;
  }
  else if (!val == 0) {
times = 0;
  }
  if (times == 500) {
times = 0;
digitalWrite(ledPinBlue, HIGH);   // sets the LED on
delay (500);
digitalWrite(ledPinBlue, LOW);    // sets the LED off
Serial.println("Click");
  }
}

When I press the button of the microphone (the middle button) of the apple earphones, the numbers change to a constant 0.
But when I press the volume buttons, nothing seems to change. Any ideas?

If you can't work out how the Apple ones work, would using Android ones be an option? They are much simpler and the information is public domain.

@MarkSmith android ones are good for me, i did not really know there is a differance between them. But how should I do it with android earphones?

MAYBE the buttons change greatly the voltage on the mic input.. try to map them; maybe (just a dumb example) the values you read when the button is not pressed vary between 0 and 300, while the button pressed is around 600... or maybe try with an oscilloscope: if the voltage can go below zero maybe you are just losing some data when sampling only positive values..

Here is an update. I did some test and i will soon set up a version of something I found while testing. It works with the middle button but not with the volume buttons.

Here is an article that explains the inner working of the Apple headphones:
http://tinymicros.com/wiki/Apple_iPod_Remote_Protocol

Have you tried searching Apple Earphones Schematic or something similar? You probably won't find a schematic, at least not from Apple, but I did find this discussion of someone's attempt to figure out what the buttons do, on some kind of Apple earphones or other (you didn't say which ones you have). There must be others who have also experimented with this.

I am looking for so long now. I really cant find anything usefull

But i must be possible i think, smartphones and such can detect when the buttons are pressed so why shouldnt it work with a arduino ;)

Wasn't the article I linked to a good starting point?

Its helpful but they want a button to simulate the controls. I just need to be able to see when the buttons are pressed with an arduino...

Can you check my answer?

Post #5 in the thread I linked has some ideas about detecting the way those buttons affect the circuit characteristics as measured from the phone plug. It will probably take a little bit of support circuitry and some software to assist the detection. Since Apple doesn't publish specs for things like this, it will be a small R&D project to confirm the speculation about the buttons and design a simple circuit or two to do the detection. Measuring a voltage or resistance change might get you one button; getting all three will be a little more work.

Since you say that an Android headset would be an alternative....
Google have published the specs for how headset controls work on Android: in short, (up to) four different values of resistor connected between mic and gnd represent the four buttons.
If you just need to read the controls, use a potential divider between Vcc and ground, and read the mid point with an analogue input to tell you which (if any) key is being pressed.

simulate this circuit – Schematic created using CircuitLab
(Wow, that's big... Dunno how to make it smaller :-) )

Could you give me a picture of how to connect the pins to the arduino? Sorry, i dont really have much knowledge of electronix. I just know the basics.

If that schematic doesn't get you started, i I think you're going to struggle to be honest. Is there something in particular about that picture which doesn't make sense which I can explain?


text:
Why won't my iMac recognize my Mega32u4 Arduino Pro Micro board (I've tried several cables)?
I bought this Pro Micro on eBay a while back, and I never really got around to using it. But now that I do my iMac won't recognize the board. I plug it into my iMac and open Arduino and go to the board tab, and it doesn't even have a Pro Micro choice, so I just choose Micro.
In ports it isn't showing up like my other boards do. Is it my computer, because my Chinese clone Uno and Mega weren't being recognized a while ago? I downloaded the CH340 chip driver for them because they used the CH340 chip and now they are recognized and work perfectly!
The thing is the Pro Micro does not use that chip so is there something else I have to do like another driver to download? It is not the cable because I have tried 5 cables and some had the symbol with the circle triangle and square connected on them, which is the usb serial symbol I think, so they aren't just power cables. If anyone knows what the problem is, that would be awesome! Here is the error it gives me when I try to upload it.
 Arduino: 1.6.9 (Mac OS X), Board: "Arduino/Genuino Micro"

failed MSpanList_Insert 0x31dea0 0x29ab70fa1fa 0x0
fatal error: MSpanList_Insert

runtime stack:
runtime.MSpanList_Insert(0x2c70d0, 0x31dea0)
/usr/local/go/src/runtime/mheap.c:692 +0x8f
runtime.MHeap_Alloc(0x2c6d20, 0x6, 0x10000000034, 0xf989)
runtime.MCentral_CacheSpan(0x2d10d8, 0x30c270)
/usr/local/go/src/runtime/mcentral.c:85 +0x167
runtime.MCache_Refill(0x308000, 0xc200000034, 0x30c270)
/usr/local/go/src/runtime/mcache.c:90 +0xa0

 goroutine 1 [running]:
 runtime.switchtoM()
/usr/local/go/src/runtime/asm_amd64.s:198 fp=0xc2082b7468          sp=0xc2082b7460
 runtime.mallocgc(0x2200, 0x19ff80, 0x0, 0xc2080d68e9)
/usr/local/go/src/runtime/malloc.go:178 +0x849 fp=0xc2082b7518     sp=0xc2082b7468
 runtime.newarray(0x19ff80, 0x20, 0xa5ca)
/usr/local/go/src/runtime/malloc.go:365 +0xc1 fp=0xc2082b7550    sp=0xc2082b7518
 runtime.hashGrow(0x1b4300, 0xc2080dc150)
/usr/local/go/src/runtime/hashmap.go:744 +0x86 fp=0xc2082b7580    sp=0xc2082b7550
 runtime.mapassign1(0x1b4300, 0xc2080dc150, 0xc2082b7698, 0xc2082b7688)
/usr/local/go/src/runtime/hashmap.go:456 +0x568 fp=0xc2082b7620  sp=0xc2082b7580
  arduino.cc/builder/props.PropertiesMap.Merge(0xc2080dc150,      0xc2082b7748, 0x1, 0x1, 0x3)
/Users/jenkins/jenkins/workspace/arduino-builder-     macosx/src/arduino.cc/builder/props/properties.go:162 +0x153     fp=0xc2082b7718 sp=0xc2082b7620
 arduino.cc/builder/props.PropertiesMap.Clone(0xc20803ce40, 0xb2f5f)
/Users/jenkins/jenkins/workspace/arduino-builder-    macosx/src/arduino.cc/builder/props/properties.go:170 +0xad fp=0xc2082b7770     sp=0xc2082b7718
 arduino.cc/builder.(*RecipeByPrefixSuffixRunner).Run(0xc20801e300,     0xc208068000, 0x0, 0x0)
/Users/jenkins/jenkins/workspace/arduino-builder-    macosx/src/arduino.cc/builder/recipe_runner.go:53 +0x2c4 fp=0xc2082b78e8    sp=0xc2082b7770
arduino.cc/builder.runCommands(0xc208068000, 0xc2082b7af8, 0x1c, 0x1c,     0xc208038001, 0x0, 0x0)
/Users/jenkins/jenkins/workspace/arduino-builder-   macosx/src/arduino.cc/builder/builder.go:181 +0x139 fp=0xc2082b7978    sp=0xc2082b78e8
 arduino.cc/builder.(*Builder).Run(0xc2082b7ce0, 0xc208068000, 0x0,   0x0)
/Users/jenkins/jenkins/workspace/arduino-builder-  macosx/src/arduino.cc/builder/builder.go:116 +0xe8e fp=0xc2082b7cc0   sp=0xc2082b7978
 arduino.cc/builder.RunBuilder(0xc208068000, 0x0, 0x0)
/Users/jenkins/jenkins/workspace/arduino-builder- macosx/src/arduino.cc/builder/builder.go:212 +0x49 fp=0xc2082b7ce8  sp=0xc2082b7cc0
 main.main()
/Users/jenkins/jenkins/workspace/arduino-builder-   macosx/src/arduino.cc/arduino-builder/main.go:316 +0x171b fp=0xc2082b7f98    sp=0xc2082b7ce8
 runtime.main()
/usr/local/go/src/runtime/proc.go:63 +0xf3 fp=0xc2082b7fe0   sp=0xc2082b7f98
 runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1 fp=0xc2082b7fe8    sp=0xc2082b7fe0
arduino-builder returned 2
Error compiling for board Arduino/Genuino Micro.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Click the apple logo in the top left corner ; click About This Mac; click More Info…; click System Report…; then under Hardware click USB and see if anything gets added when you plug in the Arduino. Let us know if or if not. It could be a bare board without bootloader.

No nothing shows up what do i do?

Try and upload the bootloader to the Arduino. You might need to use a second Arduino to do this.

Ok how do i do that?

https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader

Your error appears to be with compilation not uploading.  To make sure, try the verify button rather than the upload one.  If it still fails, the problem is the sketch and/or Arduino install, not the board or USB.

no it's with uploading

you cannot upload until the device is recognized by the Mac, so do not waste your time with uploading. .... try another USB cable. ... check if the device is recognized on another computer

From what you say here:

I plug it into my iMac and open Arduino and go to the board tab, and it doesn't even have a Pro Micro choice, so i just choose Micro.

and from the dump you provide:

Arduino: 1.6.9 (Mac OS X), Board: "Arduino/Genuino Micro"

It looks to me like you're selecting the wrong board. Instead of just picking a "similar" board from the Tools menu, what you should do is add the Sparkfun board manager package and then select the Pro Micro from it.
Here you can find the procedure step by step. Follow it and you should be all set.
EDIT:
If you tried to upload a sketch with a wrong board selection, then your your Pro Micro may have become "bricked". In order to unbrick it, follow this procedure (same link as above, different section).
Once you unbrick it, upload the specific blink example code for Pro Micro that you can find in another section of the same link.
If it keeps not working, READ THE ENTIRE ARTICLE linked and try out all troubleshooting instructions before anything else.

Let us know whether it worked or not. :)

Ok i downloaded the sparkfun thing and choose the correct board, and I downloaded the boot loader to it using an Uno and it still doesn't show up in my serial port tab!!

no port is even coming in not only is it not working it isn't existent!!

Please help me :(

If its any help i downloaded the boot loader to the pro micro and the two red lights that were on it turned off and only a green light is present now, what does that mean??

Have you tried to upload the blink example from the link in my answer?

what blink example??

Please read the full article that I have linked to you. There is a section with a Pro Micro specific "blink" example code. Copy it to a new sketch, try to upload it and see what happens.

There not even a port to connect to on my computer, it doesn't show up on my computer that's the problem.

If i upload anything it just says there's no board but I have one plugged in and it won't show up in the serial com tab.

I've updated the answer with additional information regarding how to unbrick your board. And, for God's sake, READ THE FULL ARTICLE.

C'mon... It seems you're not following the procedure. Does the serial port show up when you force the bootloader mode? Don't use another Arduino, but the USB port of your Mac. Once you force the bootloader mode, you have an 8 seconds window to check whether it appears or not in "Tools -> Serial Port", so be quick!

It does not show up on the serial port, How do I force boot loader mode?

Are you trolling me or what? How can you ask how to force bootloader mode, when I've pointed that information to you several times. I've got tired of this, sorry. You've shown no effort to follow any single piece of advice, starting by ignoring the article I linked to. Good luck!

OK thanks i'm not trolling, just confused. I'll try my best hopefully

Ok sorry for being lazy, i did what you have told me to do I wired up a button to the reset and ground of the pro micro and clicked it twice then looked at the port tab and there was still nothing it didn't do anything! :( What's the problem, because I should just buy more at this point, but I still want to fix these I paid for :(

Let us continue this discussion in chat.


text:
NodeMCU serial port - use with computer and device at the same time
I'm trying to understand how serial communication for ESP8266 in NodeMCU actually works. I found a quote saying that normal Serial is mapped to ports GPIO 1 (TX) and GPIO 3 (RX). They are even labeled on the board like this, so I believe this is true.
However I'd like to understand the relationship between those pins and serial communication over USB. Does this work the same way as in normal Arduino where you can use either communication over USB or hardware serial on pins 0 & 1?
I did some tests and if I run simple program like:
Serial.begin();
//.......
Serial.println("Hello world");

I can see that in serial monitor on my PC. How does that impact serial communication on GPIO 1 & 3 ?

Yes, it is the same as Arduino. The TX and RX pins connect to a CH340G chip to convert the serial into USB. If you use USB serial you can't use the pins for anything else.


text:
Automatic subtle colour changing on ws2812b with arduino
I'm creating a wordclock and I'd like to change the ws2812b led strip color slowly, so that it fades from one colour to another. However, I'm new to arduino and I can't get it done and I also could not find anything on this anywhere (probably because of using the wrong keywords)
Currently I have a colour hardcoded like this:
void SwitchLED(int MyArray[], int n) {
     for (i = MyArray[0]; i < MyArray[0]+n; i++) {
          leds[i].setRGB((161,57,0);
     }
}

(The array in this code are the LEDs that will light up depending on the time I get from a ds3231).
So I would like a (random) starting colour to slowly change to another colour and so on. This in such a way that you will notice it only after a couple of minutes, so very slow and subtle.
I'm using the FastLED libary. I bit of help on this would be appreciated very much.

Something like leds[i].setHSV(millis()/1000, 255, 255);?

That's great, exactly what I needed. Thank you.

For the color, you can use the time (millis()) as a hue parameter.
void SwitchLED(int MyArray[], int n) {
    CRGB color = CHSV(millis()/1024, 255, 255);
    for (i = MyArray[0]; i < MyArray[0]+n; i++) {
        leds[i] = color;
    }
}

I used 1024 here to scale the time, so it takes 4 min 22 sec, to go through the hue cycle. And a power of two, should solve a visual glitch on millis() overflow.


text:
How to have compiler know whether Arduino or ESP8266?
I am doing some work for both Arduino Mini Pro and for a NodeMCU style ESP8266 board. Within the Arduino IDE I tell it what board I am compiling for and downloading to.
How do I access which board in my scripts?
Some sections are for one or the other exclusively. Right now I'm using a #define at top of the script, but changing this to switch between boards not the best. For example, version control keeps on thinking I'm in a new branch when I'm not.

There are a number of macros defined to help you with this:

__AVR__ for any board with AVR architecture.
ARDUINO_AVR_PRO for the Arduino Pro or Pro Mini selection in the Tools > Board menu.
ESP8266 for any ESP8266 board.
ARDUINO_ESP8266_NODEMCU for the NodeMCU 0.9 (ESP-12 Module) or NodeMCU 1.0 (ESP-12E Module) selections in the Tools > Board menu.

This allows you to do things like this:
#if defined(__AVR__)
// AVR specific code here
#elif defined(ESP8266)
// ESP8266 specific code here
#endif