text:
Debouncing Multiple Buttons
I'm creating a binary calculator with my Arduino. This will take two different binary numbers and add them together. I am focusing right now on the Byte One Input screen. For this, I can use two buttons, the left to change to selected bit to either 0 or 1 when pressed, and the right button to move to the next bit, or when at the end, to move to the next screen. I am having difficulty with the debouncing of the buttons.
Right now, the debouncing is not working and the position changes from 1 to 8 or 16 instead of to the second bit when I hit the right button.
Any help would be great!
Fixed Code: See accepted answer below.
       #include <LiquidCrystal.h>
/*(RS, E, D4, D5, D6, D7)*/
LiquidCrystal lcd(12,11,5,4,3,2);
#include <Button.h>

int page = 0;
int binary[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int con = 80;
char btn_push;
int pos = 0;

const int button1Pin = 8;
const int button2Pin = 9;
int button1State = HIGH;
int button2State = HIGH;
int lastButton1State = HIGH;
int lastButton2State = HIGH;

unsigned long debounceDelay = 50;

//****************************************************************setup*****************************************
void setup() {
  pinMode(button1Pin, INPUT_PULLUP);
  pinMode(button2Pin, INPUT_PULLUP);

  Serial.begin(9600);
  analogWrite(6,con);
  mylcd.begin();
  lcd.print("Welcome");
}

//************************************************************loop************************************************

void loop() {

  int reading1 = digitalRead(button1Pin);
  int reading2 = digitalRead(button2Pin);

  if (reading1 == lastButton1State &&
      reading2 == lastButton2State)
    return;  // do nothing if no change

  delay (debounceDelay);  // debounce

  // re-read so we can catch both buttons down at once
  reading1 = digitalRead(button1Pin);
  reading2 = digitalRead(button2Pin);

  // save for next time
  lastButton1State = reading1;
  lastButton2State = reading2;

  if (reading1 == LOW && reading2 == HIGH)     // first one down
    btn_push = 'D';
  else if (reading1 == HIGH && reading2 == LOW)  // second one down
    btn_push = 'U';
  else if (reading1 == LOW && reading2 == LOW)  // both
    btn_push = 'S';
  else
    return;  // nothing interesting

 Serial.print("btn_push = ");
 Serial.println(btn_push);

    // page select
    switch (page) {

    case 0:
      page0();
      break;
    case 1:
      page1();
      break;
    case 2:
      page2();
      break;
    case 3:
      page3();
      break;
    case 4:
      page4();
      break;
    }

}

// The rest is the same, excluding the functions that are no longer needed

Are you sure those last two if's are interpreted by the compiler the way you mean? I would use some more ()'s ! And instead of foo() == false you can use ! foo(), which makes things more readable. (at least to me)

@WoutervanOoijen == takes precedence over && - but I too consider it bad practice to rely on C++ operator precedence.

Note that == has a higher precedence than the logical and (&&), so in the first test only the button.2() statement is evaluated. http://en.cppreference.com/w/c/language/operator_precedence

@PeterSmith that is not true - it takes precedence, so it will evaluate if the second button is not pressed and do a logical AND with first button pressed. So it's if first button is pressed and second button is not pressed.

I don't get why you use a for loop - won't it run through that loop so fast that you cannot push the buttons fast enough anyways? I'd much more vote for an event based approach to a problem like this. Have a look at state machines and use button presses as input into the state machine.

It's a good approach to learn for many problems, that skill will certainly not go to waste in the future - glad I could help you, even if I didn't provide an answer to your question.

note: you can reduce your code like if (button1.isPressed() && button2.isPressed() == false){ by using the ! not operator, as in  if (button1.isPressed() && !button2.isPressed()){

also simplify if(binary[i] == 0) { binary[i]=1;} to binary[i]=!binary[i];

There is no debouncing in the code.  Debouncing is a matter of time.  A simple method, is that after acting on any input you ignore all the buttons for a fraction of a second.  If you don't need to do much else, that can be a blocking delay.  If you do need to do other things, you'll need to check elapsed time.

@ChrisStratton I have just implemented some debouncing based on time, but I'm struggling with getting any valid input as it is still looping through fairly quickly.

It seems like your code will trigger on both press and release.

@ChrisStratton hmmmmm any suggestions of where I'm going wrong?

Your first problem is here:
char ReadKeypad(){
  if(button1.isPressed() && !button2.isPressed()){
    return 'D';
  }
  else if(button2.isPressed() && !button1.isPressed()){
    return 'U';
  }
  else if (!button1.isPressed() && !button2.isPressed()){
    return 'N';
  }
  else if (button1.isPressed() && button2.isPressed()){
    return 'S';
  }
}

The compiler gives a warning, which you should pay attention to:
In function 'char ReadKeypad()':
warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

The warning basically is that if no button is pressed you are returning an undefined value. It would be better to add to the end:
return 0;  // no button pressed

Then later on in page1 function:
  for (int i; i<16; i++){
    lcd.print(binary[i]);
  }

Another compiler warning:
In function 'void page1()':
warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
       for (int i; i<16; i++){

You haven't initialized i so it could have any value. That should read:
  for (int i = 0; i<16; i++){
    lcd.print(binary[i]);
  }

Ditto further down.

If I add some debugging here:
void MainmenuBtn(){
  btn_push = ReadKeypad();
  Serial.print ("btn_push = ");
  Serial.println (btn_push);
 // WaitBtnRelease();
}

And then press a button, I see:
btn_push = D
btn_push = D
btn_push = D
btn_push = D
btn_push = D
btn_push = D
btn_push = D
btn_push = D
btn_push = D
btn_push = D
btn_push = D
btn_push = D

So that is registering as many presses, not just one. You should test for "has the button state changed?". That is:

Is the button closed now?
Was it closed before?
If the two are different, then the button has just been pressed.

Adding debugging prints is very helpful in general when things aren't going to plan.
If you had added those extra prints to your MainmenuBtn function you would immediately have seen that it looked like the button was pressed hundreds of times (until you let go) rather than once.

the position changes from 1 to 8 or 16 instead of to the second bit when I hit the right button

Exactly. Since it is treating a button press as a multiple press you would expect exactly that to happen. Effectively you have built in a very fast auto-repeat (unintentionally).

Edited to add:
Your code is so confusing I've rewritten the state change stuff.
#include <LiquidCrystal.h>
/*(RS, E, D4, D5, D6, D7)*/
LiquidCrystal lcd(12,11,5,4,3,2);
#include <Button.h>

int page = 0;
int binary[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int con = 80;
char btn_push;
int pos = 0;

const int button1Pin = 8;
const int button2Pin = 9;
int button1State = HIGH;
int button2State = HIGH;
int lastButton1State = HIGH;
int lastButton2State = HIGH;

unsigned long debounceDelay = 50;

//****************************************************************setup*****************************************
void setup() {
  pinMode(button1Pin, INPUT_PULLUP);
  pinMode(button2Pin, INPUT_PULLUP);

  Serial.begin(9600);
  analogWrite(6,con);
  mylcd.begin();
  lcd.print("Welcome");
}

//************************************************************loop************************************************

void loop() {

  int reading1 = digitalRead(button1Pin);
  int reading2 = digitalRead(button2Pin);

  if (reading1 == lastButton1State &&
      reading2 == lastButton2State)
    return;  // do nothing if no change

  delay (debounceDelay);  // debounce

  // re-read so we can catch both buttons down at once
  reading1 = digitalRead(button1Pin);
  reading2 = digitalRead(button2Pin);

  // save for next time
  lastButton1State = reading1;
  lastButton2State = reading2;

  if (reading1 == LOW && reading2 == HIGH)     // first one down
    btn_push = 'D';
  else if (reading1 == HIGH && reading2 == LOW)  // second one down
    btn_push = 'U';
  else if (reading1 == LOW && reading2 == LOW)  // both
    btn_push = 'S';
  else
    return;  // nothing interesting

 Serial.print("btn_push = ");
 Serial.println(btn_push);

    // page select
    switch (page) {

    case 0:
      page0();
      break;
    case 1:
      page1();
      break;
    case 2:
      page2();
      break;
    case 3:
      page3();
      break;
    case 4:
      page4();
      break;
    }

}

// The rest is the same, excluding the functions that are no longer needed

I made the buttons INPUT_PULLUP so that they normally read HIGH if not pressed, thus LOW means pressed (therefore the switches should be wired from the digital pin on one side to Gnd on the other side).
It still isn't perfect but that should give you something to play with. Add some more debugging prints to see what is going on in the other functions.

Wow! Thank you for catching all of my errors, I guess I've just been looking at the code too long. I agree I should have used debugging prints. I am working right now to figure out debouncing for the buttons to see if the state has changed. Just a question about that first problem you found, are you saying I should return 0 at the end of the function or instead of returning 'N' if neither button is pressed?

I've updated my code in an attempt to implement debouncing and detect a state change, but it seems I've only made the loop worse. Any ideas on what I'm doing wrong?

If 'N' means neither button, then sure.

You still aren't looking at the warnings. Your new function ButtonOne does not return anything when it "falls out" the bottom.

See amended answer with some suggested code changes.

Thank you! I was getting very confused trying different methods and it all just turned into a mess.

As an alternative to using two inputs, consider using a single analogue input with several momentary buttons - each with differing resistor values in series - this will let you avoid debouncing altogether. Just 5/3V3->resistor->btn->analogInput.
At worst, you will need to smoothe out jitter on analog reads. Have a look at https://www.codeproject.com/Tips/709109/ADKeyboard-Library-for-Arduino


text:
C++ Adding Two 16 bit binary numbers together
I am trying to add two 16 digit binary numbers together. Each binary number will have been entered by the user and saved as: int binaryOne[16] and int binaryTwo[16]. Originally,
int binaryOne[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int binaryTwo[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

are the values declared. Then, the user has the option to change these values using buttons that I implement before the Solution() function. So, once the used gets to the Solution() function, the numbers may be stored as:
int binaryOne[16] = {0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1};
int binaryTwo[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};

This is what I have so far:
void Solution() {
  /*
    Rule of binary addition:
    0 + 0 = 0
    1 + 0 = 1
    0 + 1 = 1
    1 + 1 = 1 and carry = 1
   */
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print("Solution");
   lcd.setCursor(0,2);

    int a[16] = binaryOne[16];
    int b[16] = binaryTwo[16];
    int i = 0;
    int remainder = 0;
    int sum[32];

    while(a[16] != 0 || b[16] != 0){
      sum[i++] = (a[16] % 10 + b[16] % 10 + remainder) % 2;
      remainder = (a[16] % 10 + b[16] % 10 + remainder) / 2;
      a[16] = a[16] /10;
      b[16] = b[16] / 10;
    }
    if(remainder != 0){
      sum[i++] = remainder;
    }
    i--;
    while(i>=0){
      lcd.print("%d", sum[i--]);
   }
   return 0;
}

I believe I am doing something wrong with calling the arrays since I am renaming them to a[16] and b[16] within this function. I'm also curious, since I only have 16 bits of space on the screen, what if the user enters a binary number such as 1111111111111111 + 1000000000000000 and therefor there is going to be a carry on that first digit? Would it be best just to have an error message?

Why not just turn the array bits into an int number, and then add them?

int result1 = (a[15]<<15) | (a[14]<<14) | ... (a[2]<<2) | (a[1]}<1) | a[0];

do the same for result2.  Probably better if both are unsigned int.

then  unsigned long = result1 + result2;

@CrossRoads I need to output the solution as a binary number, sorry if I was not clear.

You say "I am renaming them to a[16] and b[16]", but int a[16] = binaryOne[16]; does not rename the array. When declaring an array, you have the option to initialize the array with a curly-braced list of values, or a string literal. Your code won't compile.

lcd.print(result, BIN)

@josecanuc I apologize, I added more description of the binaryOne and binaryTwo ints above for clarity on what I meant.

It doesn't change the fact that int a[16] = binaryOne[16]; does not rename the array or copy the array from binaryOne to a. int a[16] declares an array of 16 ints. binaryOne[16] doesn't refer to anything, because binaryOne is defined as an array of 16 ints, indexed from 0 to 15.

You're making a mountain out of a molehill.
You're trying to manually manipulate binary digits in an array, but C can already manipulate binary digits. Everything is binary already - you just need to represent it as such.
All you need to do is convert the contents of your array into an actual number, then do simple mathematics on that number.  One of the simplest ways of doing that is to shift the bits into a variable:
For instance:
int binaryOne[16] = {0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1};
int binaryTwo[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};

uint16_t binOne = 0;
uint16_t binTwo = 0;

for (int i = 0; i < 16; i++) {
    binOne <<= 1;
    binOne |= binaryOne[i];
    binTwo <<= 1;
    binTwo |= binaryTwo[i];
}

Now you can add them together, since they're just numbers:
uint32_t result = binOne + binTwo;

And you can output it as binary:
Serial.println(result, BIN);

If you want to convert back into an array again (why?!) you can just do the opposite as before:
bool resultBin[32];

for (int i = 0; i < 32; i++) {
    resultBin[i] = (result & (1 << (31-i))) ? 1 : 0;
}

it is probably a school assignment

I tend to think things are a lot harder than they actually are unfortunately haha. I don't know why I didn't see this easy solution. Thank you!

Read the part of my answer that starts with: "And you can output it as binary..."

@Majenko Oh duh, it was right there, sorry. I will check your answer as accepted. I really appreciate your help!

A few issues here:

The way you “rename” the arrays is wrong, and furthermore there is no
point in doing such renaming.
There is no reason to divide by 10 (ten, in decimal) within your
code: as everything you do is binary, the number ten has nothing to
do with what are trying to accomplish.
While doing the addition, you forgot to loop over the bits.
You shouldn't return 0 in a function of type void. In fact, you
shouldn't return any value.

Fixing those issues should give you something similar to this:
void Solution() {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Solution");
    lcd.setCursor(0, 2);

    // Compute the sum.
    int sum[16];
    int remainder = 0;
    for (int i = 0; i < 16; i++) {
        int s = binaryOne[i] + binaryTwo[i] + remainder;
        sum[i] = s % 2;
        remainder = s / 2;
    }

    // Print it.
    for (int i = 15; i >= 0; i--) {
        lcd.print("%d", sum[i]);
    }
}

Note that there is no point in computing a 32-bit result if you can only
print 16 bits: just accept that the computation is done modulo
216, just like a 16-bit ALU would do, or the unsigned int
data type in the Arduino.
Of course, the whole idea of doing the computation one bit at a time is
highly inefficient. See Majenko's answer for a more idiomatic and
efficient way of managing numbers bit-wise in C and C++.

source: Stack Exchange

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

sort: votes


text:
Looking for a sensor that measures heart/pulse rate
I am looking for a sensor which is able to measure heart/pulse rate. Apart from the common pulse sensor from here, are there any others?
I have seen people recommending this as well, and it seems more accurate. Should I get the piezo vibration sensor or are there better sensors? Hoping for something that is easy to use (Like the pulse sensor where you can just place your finger onto the sensor)
Cross-post from: https://www.reddit.com/r/arduino/comments/8f051k/looking_for_a_sensor_which_measures_heartpulse/ and https://forum.arduino.cc/index.php?topic=543857.0

sensor which is able to measure heart/pulse rate means that the sensor calculates the pulse rate and outputs the final value to the microcontroller ............. are you sure that is what you actually want?  .... or do you want a sensor that detects a heartbeat?

@jsotola yeah detects heartbeat. Sorry about that.

The commonly used approach is to use an infrared source and sensor pressed against the skin.  Usually the finger tip is all that is needed. In addition to pulse, many have also incorporated an Oxygen measurement feature.
The 1st sensor you linked to appears to use this approach.  But instead of buying a ready made sensor, many have made a project of building their own...
This project has been done and published many times on the Internet.  There are well documented projects such as this one from Rutgeurs.  As well as this complex one from a journal called EDN.  And this one and this one from various independent hackers.

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


text:
Using an Arduino as a Human Interface Device that sends analog inputs
I would like to have an arduino board act as a human interface device that can send analog inputs like joysticks.
As it currently stands I see two aproaches to this issue:

Use the arduino hid library and program all the reports in myself. This should be fairly simple but I can't seem to find any recourses that I actually understand. I get the idea of reports but I dont get how the report format is described to the OS. I also dont understand how drivers on the pc side of things play into this whole equation.
Write some software that makes a serial connection with the arduino and uses java's robot functionality (or similar) to controll a joystick, if even possible. This method would be much easier but would feel overall less polished.

Thank you for your help in advance!

Option 3: Use a different board that supports hid joysticks out of the box.

https://github.com/MHeironimus/ArduinoJoystickLibrary does my first aproach. The limitations one what board it can be will not be an issue because I have an extra 32u4 board.

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


text:
Arduino Uno R3 (with Atmega 16U2) and macOS 10.11 not working
So,
I have the newest Arduino IDE (1.8.5) installed and the newest release of Arduino AVR Boards 1.6.21.
My OS: macOS 10.11.6.
Usually I only use Nano's china clones with an CH340 USB-Serial chip, I have installed the wch driver and it worked fine !
My Nano's have the newest bootloader (Arduino AVR Boards 1.6.21).
And now the really annoying problem:
I recently ordered Elegoo Uno R3 boards, they have the original 16U2 chip for USB-Serial, no FTDI and no CH340 it's a Atmega 16U2.
And of course nothing works..
When I connect the Elegoo Uno to the mac (over the USB cable), it will show up in the system report - > USB as Arduino, but the IDE won't found it.
Sometimes it will be found by the IDE, but when I click upload (the Blink sketch) it print following:
    avrdude: Version 6.3, compiled on Jan 17 2017 at 12:01:35
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/Users/USERNAME/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino9/etc/avrdude.conf"
         User configuration file is "/Users/USERNAME/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.usbmodem5D21
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         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    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
         Hardware Version: 3
         Firmware Version: 4.444305
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
         Vtarget         : 322122183.2 V
         Varef           : 49804.8 V
         Oscillator      : 548.816 Hz
         SCK period      : 3495249366.4 us

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: stk500_recv(): programmer is not responding

avrdude done.  Thank you.

So it receives the board information, but then the programmer does not respond, then he responds again and then not, a back and forth.
I have already made it by repeatedly clicking that the program has been uploaded.
Now the possible sources of error:

USB cable
Atmega328
Atmega16U2
My thought: something with the auto reset

Sidenote: I also update the 328 and 16U2(over DFU and USBasp) bootloader with an USBasp, no success (the bootloaders have been uploaded successfully, but I still can't upload a sketch)
Now the things I tried:

Other USB cable -> no success
Upload bootloader to the 328 -> success, program it via an TTL adapter over RX TX -> success, the led start blinking.
Upload bootloader to the 16U2 -> success, but simultaneously not an success, because the bootloader was uploaded successfully, but I still can't upload a sketch.
I read read read over 5 hours now, and the only helpful articles were:

Same problem as me, he has/had an mac with 10.11.06
He did it with an update of the USB drivers via MultiBeast (hackintosh driver installer) I also try it with no success (I also know that their is now driver for the 16U2, because normally there are built in CDC/ACM drivers, exception windows.)
..................
Arduino IDE serial ports not working on EL Capitan OSX
A big Github thread, with no real solution.
..................
The 80% solution
That gave me the idea to test it in a virtual windows machine and surprise surprise it worked, it uploaded without any errors (that I did not figure it out sooner, my fault).
So now I know that the usb cable, the 328, the 16U2 are fully working and nothing is damaged, the only thing that is not working is my mac.
Sometimes the UNO's are not recognized.
Sometimes the sketch is only uploaded to 90 percent, then the board doesn't respond.
The Nano's are fully woking, I thought maybe the CH340 driver for the NANO's make problems ?
So because of that my mac have problems with the UNO boards.
Honestly after that, I have no idea, I just want it to work.

A hackintosh is not a supported platform. Either Linux or Windows on a PC or OS X on a Mac. A frankensteinian combination of the two, well, it's anyone's guess what may work and what won't.

@Majenko Sorry this is absolute nonsense.

Using an operating system designed for Mac hardware on a pc (yes, the CPU is the same, but so what?) is asking for trouble. There are no guarantees that hardware drivers will function right. That includes things like the USB subsystem.

Do you come here to discuss or help?

If you had an Arduino problem then sure, we'd help. You have already proved that your Arduino is fine and that the problem is with running osx on a pc. We don't support that configuration. We know nothing about that kind of thing. Osx on a Mac, sure, you have a chance of support, since many here use a Mac. A real Mac. (Poor fools). I know of no one else that uses osx on a pc.

Ok i updated my question with "macintosh", because i think you don't understand that also the ones who have a "real mac" could help me very well, because many have the same issue and maybe someone fixed it.

From what I can see it's either problems with el crapitan (it's known as that for a reason) or hackintosh USB drivers. The Arduino is just a class-compliant CDC/ACM device. No drivers needed, no magic to get it working. Unless the OS is buggy as hell or you're running it on unsupported hardware.

No magic, hmm.. why so many people have the problem ?
Github Blog
With a OS that is stable as hell.
I will wait on answers, that give me more information, so that I can explore new solutions paths.

"Stable as hell..."...  (howls of derisive laughter...)

It sounds to me like the whole USB subsystem in El Crapitan is completely borked. For example, it's not just CDC/ACM that suffers: "Some users report that audio output devices attached via USB will spontaneously disconnect, with audio output reverting to internal speakers. "

Here's one nice review quote: "While the Apple faithful want users to focus on the benefits of upgrading to El Capitan, what I'm seeing is the rockiest, most buggy OS X release I can ever remember, and the first time since OS X has been available for download that I've not upgraded all my systems on day one."

My suggestion: Either upgrade or downgrade. Like I said: it's called "El Crapitan" for a reason.

No, I don't have such problems, my machine is rather stable.
It is only the port problem.
Oh, and to the "It's the Hackintosh's fault", whenI run the virtual machine, it is working just fine ,the mac even redirects the port to the vm.
It's also listed in the system report, it's not a real hackintosh problem.
It's a problem in macOS 10.11,
that's what i know.
And I think that a few people fixes this problem very well !

No, people with a real mac fix a problem that sounds similar to yours. You have an OS with known USB faults running on foreign hardware using third party USB drivers. Your problem is reasonably unique to you, because very few other people use the same combination as you. Which is why the fixes that work for other people don't work for you.

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


text:
Arduino pro micro might be bricked
I bought an Arduino pro micro (looks like this) from a Chinese seller over E-Bay, for its HID interface.
I installed the Arduino software on my Linux machine (Kali Linux), and started writing a USB Rubber Ducky script, and converted it to Arduino using Dckuino.js, which usually works just fine.
I may have used either:

The wrong programmer, or
The wrong board type

because when I uploaded the sketch, it said it failed, but HID script still worked when I plugged it into my Mac.
The Mac came up with a Keyboard Assistant, because it couldn't recognize the keyboard being use. So I plugged it back into my Linux machine, and it wouldn't recognize.

lsusb and dmesg -w didn't show any updates when re-plugging the Arduino.
Changing USB chords didn't work.
Switching over to windows, Device Manager didn't do the normal "refresh" when you plug in a new device, and there was nothing under COM Ports.
The HID input didn't work on the Mac anymore, when plugging it in again.
The inbuilt LED lights up when connected.

Is this a brick?
I can't seem to find any reset button or header on the board, so I cant connect the ground and reset.
There is an RST header, but I don't know what that is.
Any help would be greatly appreciated!

RST = ReSeT.  Have you tried re-flashing the bootloader through ICSP?

Be sure to check out the answers on a very similar question: Have I bricked my Arduino Uno Problems with uploading to board

Connecting the RST header to ground (GND) with a wire should be the same as pressing the reset button on other arduinos.

Do I need to solder on the wire, or can I just kind of hold it there?

Don't play with RST. Get another arduino. Load programmer sketch. And try to load bootloader over icsp. Select programmer "arduino as isp"


text:
TMP36 not working with arduino uno?
I have an Arduino Uno hooked up with a TMP36 and an ESP8266 to send the temperature reading to a PHP file which receives the post request and stores it in a text file.
The ESP8266 and PHP works fine and I'm positive of that. But the temperature my code gets are ridiculous and change a lot. I'll include my code and a Fritzing sketch and the URL to the data.txt (you can see the results real time). It might be a problem with my code or something else I'm not sure I've fiddled around to no success and hopefully some fresh eyes will help.

Most of the code is copypasta as I've never used ESP8266 before.
#include "SoftwareSerial.h"

String ssid ="correctssid";
String password="correctpwd";

float val=0;
int temppin = 2;
float volts=0.0;
float tempC=0.0;

SoftwareSerial esp(6, 7);

String data;
String server = "www.elijahdur.co.uk";
String url = "/arduino/esp8266/file.php"; //I've changed this just well because

void setup() {
  esp.begin(9600);
  Serial.begin(9600);
  reset();
  connectWifi();
}

void reset() {
  esp.println("AT+RST");
  delay(1000);
  if(esp.find("OK") ){
    Serial.println("Module Reset");
  }
}

void connectWifi() {
  String cmd = "AT+CWJAP=\"" +ssid+"\",\"" + password + "\"";
  esp.println(cmd);
  delay(4000);

  if(esp.find("OK")) {
    Serial.println("Connected!");
  }

  else {
    connectWifi();
    Serial.println("Cannot connect to wifi");
  }
}

void loop () {
  val = analogRead(temppin);
  volts = val * 5.0;
  volts /= 1024.0;
  tempC = (volts - 0.5) * 100;

  String string = (String) tempC;
  data = "data=" + string;
  httppost();

  delay(30000);
}

void httppost () {
  esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",80");//start a TCP connection.

  if( esp.find("OK")) {
    Serial.println("TCP connection ready");
  }

  delay(1000);

  String postRequest =
  "POST " + url + " HTTP/1.0\r\n" +
  "Host: " + server + "\r\n" +
  "Accept: *" + "/" + "*\r\n" +
  "Content-Length: " + data.length() + "\r\n" +
  "Content-Type: application/x-www-form-urlencoded\r\n" +
  "\r\n" + data;

  String sendCmd = "AT+CIPSEND=";//determine the number of caracters to be sent.

  esp.print(sendCmd);
  esp.println(postRequest.length());

  delay(500);

  if(esp.find(">")) {
    Serial.println("Sending..");
    esp.print(postRequest);
  }

  if( esp.find("SEND OK")) {
    Serial.println("Packet sent");
  }

  while (esp.available()) {
    String tmpResp = esp.readString();
    Serial.println(tmpResp);
  }

  esp.println("AT+CIPCLOSE");

}

The txt file is located at http://elijahdur.co.uk/arduino/esp8266/data.txt
Sometimes is will straight up give -50 and it's because it reads 0 and takes away the 5V from the analog.
Any help is greatly appreciated thank you!
EDIT: Apologies, but I had mixed up my sensors and was using an LM35, it still does not work however so I'm still stuck :/

Have you tested the temperature sensor by itself, without the ESP8266?

First off, as a general debugging tip: Always use a minimal example to only test one component to make sure it works. You should have tested the temperature sensor on its own, then the ESP8266 WiFi connection.
Second, regarding this code:
  /* as global variable */
  float val=0;

void loop () {
  val = analogRead(temppin);
  volts = val * 5.0;
  volts /= 1024.0;
  tempC = (volts - 0.5) * 100;

  String string = (String) tempC;
  data = "data=" + string;
  httppost();

  delay(30000);
}

The line String string = (String) tempC; looks very suspicious to me. You are casting a float to a String object, i.e., you re-interpret it with a cast operator. That should not work because a float is not a String object.
What should work is creating a new String object using its constructor, i.e., write
 String string(tempC);

If this is does not work, use the sketch at https://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor, change sensorPin to 2, double check your wiring and remove the ESP8266.
And as 3rd note: You are hooking up your Arduino's TX directly to the ESP8266's RX pin, according to your schematic. This will damage the ESP8266 module, because it is a 3.3V device and should only receive 3.3V signals -- your Arduino Uno outputs 5V as a logic 'high'. You need a voltage divider or a logic level shifter between them.

Thanks, as i edited i was actually using an LM35 (apologies) but it still doesnt work and i get results like these https://hastebin.com/isifakiwef.ini. That is with 5 second intervals and they seem just to bounce between 0 and 40?

I changed around some cables and now i consistently get 120C, what on earth is happening? I thought this could be fahrenheit but thats still 46C?

@ElijahD-R Did change GND and VCC? Reverse polarity kills your sensor. You seem to be confused about your sensor. Are you absolutely sure it's an LM35 and no TMP36? Can you edit the question to show a picture and your current code? Does this example sketch work for you?

I'm going to say that I probably at one point reversed the polarity... Time to find a new temperature sensor, got any recommendations?

Pretty much any 'Arduino' labeled temperature sensor works, if you don't special requirements on temperature range or accuracy. Maybe something like a DHT11, DHT22 will work for you too? Your old sensor type would also be okay, just make sure you've got the wiring correct and run a minimal test sketch as first thing.

If you don't need the arduino for learning purposes you could also just get a module for the ESP8266-01 with a DHT-11 for less than $5 and program the ESP8266 directly

This instructables does the TMP36 part very similar using tempPin=0 instead 2 ,
I'd try that code because there shouldn't be a negative value as long you are measuring room temperate and the TMP36 is not defective.
According to these curves

and table from the TMP35/36/37 data sheet

you should measure 700-750mV (with VS 3V)

Your coment suddenly vanished partly. If the returned voltage is lower than expected, could it possibly be a TMP35/37 sensor and not a TMP36?

Apologies, i just noticed its a LM35 and the sheet i was given with my package was incorrect (it was a bundle and in my box it said TMP36 and online it says LM35)

I'm now using some LM35 code but i still get fluctations? https://hastebin.com/okakudifel.makefile The first number is the number recorded by analogRead and the second one is when that is multiplied by 0.48828125.

The analogread should return an integer between 0 and 1023 for voltages between 0V and 5 V the diagram is for a Vs of 3V. What do the readings say if output to serial?


text:
Servo speed in a Toggle Code
I am new to Arduino and am trying to figure out servos. Right now I have a toggle button code for the servos. Although I want to know how to speed them up. Is there a way to do this?
Currently, this is my code:
#include <Servo.h>
int button = 5; //button pin, connect to ground to move servo
int press = 0;
Servo servo_7;
Servo servo_8;
Servo servo_9;
Servo servo_10;
boolean toggle = true;

void setup()
{

  pinMode(button, INPUT); //arduino monitor pin state
  servo_7.attach(7); //pin for servo control signal
  servo_8.attach(8);
  servo_9.attach(9);
  servo_10.attach(10);
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press = digitalRead(button);
  if (press == LOW)
  {
    if(toggle)
    {

      servo_7.write(180);
      servo_8.write(180);
      servo_9.write(180);
      servo_10.write(180);
      toggle = !toggle;
    }
    else
    {

      servo_7.write(0);
      servo_8.write(0);
      servo_9.write(0);
      servo_10.write(0);

      toggle = !toggle;
    }
  }
  delay(100);  //delay for debounce
}

Please add your code, since we cannot help you without it. Edit your question accordingly and format the code correctly (There is also a shortcut for it: Strg + K)

Stop changing the whole question. It is frustrating, that you solved the problem yourself during me writing an answer, and then just changing the question to a complete other problem. If you can solve your problem in this short time, you should not ask a question here. It is not in the scope of this site, to answer questions, that can be easily answered by googling or thinking about it.

You cannot change the servos speed with the Servo library. It just outputs the value you give as a PWM wave. It is up to your servo to follow it as fast as it can.

why do you have the servo_7.write(), servo_8.write(), etc code twice ... you only need to have it once

Normal servos have a speed. It's their speed, and you can't change it. You can make it appear slower by moving in small increments, but you can't actually change the speed it moves.
With constant rotation servos the "angle" dictates the rotation speed, but even with those there is nothing you can do to change the relationship between "angle" and rotational speed.
Other than buying a different servo with a different degrees-per-second rating.


text:
Need Input: Wait for voltage input to begin script & when voltage maintains 0V for X amount of time Reset and wait for Voltage Input
So I'm currently working on an automotive set up.
I'm using a 555 timer to emulate a turn-signal alternating voltage pulse (12V to 0V and repeat) for debugging purposes which is output to turnPin/A1.
Here's the goal: When voltage is greater than 1V arduino is to supply constant power to output pin (pin 13) until input voltage is returned to constant 0 (or end of turn signal input) for x-time or as I'll refer to as Timeout.
It seems I've gotten the constant power to apply when input is applied and then turn off constant output when voltage is back to 0V. However I'm having difficulty getting the timeout function to work properly as the LED still remains HIGH.
EDIT: I've reworked the code to use millis(); rather than purely using sensor inputs. I've also added comments to help walk you through what I believe is happened/what I want to happen.
// Constants won't change
const int ledPin = LED_BUILTIN; //using built in led + pin13
const int turnPin = A1;         // the input pin (turn signal alternating 5V/0V/5V/0V & so-forth)

// Variables will change
int ledState = LOW;             // the current state of the output pin
int prevLed = ledState;
int lastVoltage = 1;            // the previous reading from voltage source
int state = 1;                      // the current "state" (see below)
                                // State = 1++: LED OFF -- State = 0: LED ON

// The following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.

long previousMillis = 0;    //the last time the voltage reached 0
long waitTime = 100;    // the wait time

void setup()
{
  pinMode(ledState, OUTPUT);        //set output pin
  pinMode(turnPin, INPUT);          //set input pin NOTE: SIGNAL ALTERNATES
5V/0V/5V/0V & so forth to emulate a turn signal for this application
  Serial.begin(9600);               //begin serial
}

void loop()
{
  int sensorValue = analogRead(turnPin);        // Read voltage at input pin
  float voltage = sensorValue * (5.0/1023.0);   // Convert
  unsigned long currentMillis = millis();    // set currentMillis as current
 time

  if (voltage > 1)      //if Voltage greater than 1V
  {
    ledState = HIGH;    //turn led on
    state = 0;          //set state to 0
  }

  if (voltage < 1)      //if voltage less than 1V
  {
    currentMillis;      //set currentMillis as current time

    if ((millis() - currentMillis) > waitTime) // if (current time minus time voltage was less than 1) is greater than wait time
    {
        ledState = LOW;     //set LED to off
        Serial.print("OFF - TIMED OUT - WAITING FOR INPUT: ");  //output message for debug
        Serial.println(state);//current state
        state++;              //increment state (time passed)
    }
        else if ((millis() - currentMillis) < waitTime) // if (current time minus time voltage was less than 1) is less than wait time
        {
            ledState = HIGH;    //set LED to on
        }
  }
  digitalWrite(ledPin, ledState);   //send LED status to output
}

When voltage > 1  .... larger than one what? potato? .... it is really unclear what you are asking, a few commas in some of your sentences would help

@jsotola "Voltage > 1 Volt" - My apologies thought it was assumed. And No. I didn't read it after I wrote it! My bad! Haha. Updated.

if (sensorValue < 1 > currentMillis + 500)  What the heck is this line supposed to mean?

@Delta_G if sensorValue greater than 1 for greater than current time + 500 then ->
Was a late-night I'm-done-for-the-night hoo-rah.

@jsotola Volts.

So you're saying that late at night you try to invent your own syntax?  That won't work.  Try coming back early in the morning and studying how the language works.  That will work a lot better.

@Delta_G code updated. Any input?

the question is looking better .... removed the downvote .... what is it that you are building?

you assign this variable float voltage = sensorValue * (5.0 / 1023.0); , but you do not use the variable voltage anywhere in your code

To start the timer when the input drops, you need another state variable that remembers the last state of the input. I would rather not use the global ledState or the local status for that, but I would add an extra global variable. Meanwhile, you are crawling towards an infinite state machine.

Hello everyone. Comments under questions are for clarifying the question, not to make a "mini answer". If you want to answer the question please type something into the "Your Answer" box and then submit it. Answers can then be voted on, and the best answer floats to the top of the answer chain, as Stack Exchange intended.

In a nutshell here is a summary of my goal.
Launch: Wait for voltage input from turnPin (turn signal).
Voltage Received: Supply constant V to output pin then wait for Voltage to drop to 0V for 500ms.
When Voltage = 0V for 500ms: Stop constant voltage to output pin and wait for input from turnPin (turn signal) again.

updated question/reworked code to help everyone better understand what I'm trying to do.

Thanks for everyone's input. I've come up with the solution.
Using the while function I was able to create two "states" for the code to be in. A timed-out state and not timed-out state, respectively. While in the timed-out state the output will be 0 and vice-versa for the latter and wait for the voltage to reach 0 for "X" amount of time.
I also integrated a "learn" feature to set the delay based on the alternating input voltage if necessary. Otherwise it will default to the value within the timeoutWait variable.
Code is below. Please let me know if you have any input/suggestions.
/*
  PURPOSE: This application was built for an automotive application. Client replaced OEM turn signal's with aftermarket multicolor
  LED strips controlled by an unknown controller. In order for the turn signal function of the LED strips to work the
  controller had to be powered on. It was undesired to run the LED's every time the vehicle was driven. Therefore, the
  controller needed to be supplied constant power when an input from the OEM turn signal wiring (which alternates 16V/0V/16V/0V...
  and so-forth was applied.

  OVERVIEW: In a nutshell: this application will supply constant output to any specified output (pin 13 in this case) when 5 Volts is
  applied to any specified Analog input (pin A1 in this case). When voltage to the input pin is discontinued after 250milliseconds
  the constant output will be terminated. The application will then wait for voltage to be resupplied to the input pin.

  This application will also support an alternating input source (turn signal in this case). The amount of time to wait before returning
  the output pin to an OFF state is determined one of two methods.

  METHOD 1: Setting a default by amending the timeoutWait variable.
  METHOD 2: Using the Learn Button to time voltage drops and adjust the time-out wait time accordingly (+ 50 milliseconds for any variations in timing)

  USING THE LEARN BUTTON: At any point in time, press and hold the push button for approximately 6-seconds (real time - non simulation). This will
  time the difference in time between Voltage > 1 and Voltage < 1 and set it as the timeoutWait time. NOTE: The variable timeoutWait is not updated!
  The variable blinkRate is updated with this data.

  CIRCUIT: For emulation purposes a circuit was built using a 5V Power Supply connected to an ATTINY microprocessor (to emulate the alternating
  turn signal of 5V/0V/5V/0V alternation every 250milliseconds) connected to pin A1 on an Arduino UNO R3. An LED with a 1kΩ resistor was connected to pin 13.
  The learn button is powered and grounded from the arduino board with a 10kΩ resistor and connected to Digital Pin 2 on the arduino board.*/

// Constants won't change
int output = 13;            // Pin to output voltage
int input = A1;             // Pin to receive voltage
int learnButton = 2;        // Pin to receive signal for learn mode
int waitTime = 500;         // Time to wait in milliseconds
int timeoutWait = 250;      // Time to wait in milliseconds

// These variables will change
int relayState = LOW;       // Track what state the relay is in
bool timeout = false;       // Track if we're timed-out or not
bool learnMode = false;     // Track if we're supposed to be in learn mode or not
int blinkRate = 0;          // Store blink interval in millis (obtained from learn mode)
int lastButtonState = 0;    // Track the last state of the learn button
int buttonState = 0;        // Track the current state of the learn button

// The following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long timerStart = 0;        // Track when timer started
long timerStop = 0;         // Track when timer stopped
long passedTime = 0;        // Track time elapsed =(timerStop - timerStart)
long blinkStart = 0;        // Track when blink HIGH (learn mode)
long blinkStop = 0;         // Track when blink LOW  (learn mode)

void setup()
{
  pinMode(relayState, OUTPUT); // Set output pin
  pinMode(input, INPUT);       // Set input pin
  pinMode(learnButton, INPUT); // Set input pin (learn mode)
}

void loop()
{
  int sensorValue = analogRead(input);          // Read voltage at input pin
  float voltage = sensorValue * (5.0 / 1023.0); // Convert
  buttonState = digitalRead(learnButton);       // Read the learnButton pin
  Serial.begin(9600);                           //  Begin serial communication

  if (buttonState == HIGH)  // If the learnButton is pressed
  {
    learnMode = true;   // Enter learnMode
  }
  delay(50);        // Debounce

      if (voltage > 1)    // If Voltage is Greater Than 1 Volt
  {
    timeout = false;  // Set timeout state to FALSE since there's no reason to timeout
    passedTime = 0;   // Reset passedTime variable
    timerStart = 0;   // Reset timerStart variable
    timerStop = 0;    // Reset timerStop variable
  }

  if (voltage < 1)  //If Voltage is Less Than 1 Volt
  {
    timerStart = millis();                 // Start the timeout timer
    delay(waitTime);                       // How long should we wait until it times out?
    timerStop = millis();                  // Stop the timeout timer
    passedTime = (timerStop - timerStart); // Calculate how much time we waited

    if (passedTime >= waitTime) //If the calculated time is greater than or equal to our wait time
    {
      sensorValue;      // Re-check the Voltage first

      if (voltage < 1)  // If the voltage is still Less Than 1 Volt
      {
        timeout = true; // Set timeout state to TRUE since the voltage has been less than 1 Volt for >= our Wait Time
        timerStart = 0; // Reseet timerStart variable
        timerStop = 0;  // Reset timerStop variable
        passedTime = 0; // Reset passedTime variable
      }
    }
  }

  while (timeout == true)                    // If TIMEOUT = TRUE
  {
    relayState = LOW;                        // Set the relay state to LOW/OFF
    sensorValue = analogRead(input);         // Read voltage at input pin
    voltage = sensorValue * (5.0 / 1023.0);  // Convert
    digitalWrite(output, relayState);        // Tell the relay to turn off

    if (voltage > 1)    // if the voltage is Greater Than 1 Volt
    {
      timeout = false;  // Set timeout state to FALSE since there's no reason to timeout
      timerStart = 0;   // Reseet timerStart variable
      timerStop = 0;    // Reset timerStop variable
      passedTime = 0;   // Reset passedTime variable

    }

    if (voltage < 1)
    {
      timeout = true; // Set timeout state to TRUE since the voltage has been less than 1 Volt
      timerStart = 0; // Reseet timerStart variable
      timerStop = 0;  // Reset timerStop variable
      passedTime = 0; // Reset passedTime variable
    }
  }

  while (timeout == false)  // If TIMEOUT = FALSE
  {
    sensorValue = analogRead(input);        // Read voltage at input pin
    voltage = sensorValue * (5.0 / 1023.0); // Convert
    relayState = HIGH;                      // Set the relay to ON/HIGH since we're not timed out
    digitalWrite(output, relayState);       // The the relay to turn on
    buttonState = digitalRead(learnButton); // Read the learnButton pin

    if (buttonState == HIGH)  // If the learnButton is pressed
    {
      learnMode = true; // Enter learnMode
    }
    delay(50);        // Debounce

    if (voltage < 1)  // If the voltage is Less Than 1 Volt
    {
      timerStart = millis();                // Start the timeout timer

      if (blinkRate > 100)          // If blinkRate is Greater Than 100
      {
        timeoutWait = blinkRate + 50; // Set timeoutWait to blinkRate value + 50 milliseconds for any variations in timing
      }
      else                // If blinkRate is not Greater Than 100
      {
        timeoutWait = timeoutWait; // Leave default value alone
      }

      delay(timeoutWait);                     // How long should we wait to timeout in this state?
      timerStop = millis();                   // Stop the timeout timer
      passedTime = (timerStop - timerStart);  // Calculate how much time we waited

      if (passedTime >= timeoutWait)  //If the calculated time is greater than or equal to our assigned wait time
      {
        sensorValue;        //Re-check the sensor first

        if (voltage < 1)    //If the sensor read less than 1 Volt
        {
          relayState = LOW; //Set the relay state to OFF/LOW.
          timeout = true;   //Keep us in the timed out state.
          timerStart = 0;   //Reset timerStart variable.
          timerStop = 0;    //Reset timerStop variable.
          passedTime = 0;   //Resed passedTime variable.
        }
      }
    }
  }
  while (learnMode == true)  // If LEARNMODE = TRUE
  {
    sensorValue = analogRead(input);        // Read voltage at input pin
    voltage = sensorValue * (5.0 / 1023.0); // Convert
    Serial.println("LEARN MODE ACTIVE");  // Print to Serial Monitor

    while (voltage > 1)
    {
      sensorValue = analogRead(input);        // Read voltage at input pin
      voltage = sensorValue * (5.0 / 1023.0); // Convert
      blinkStart = millis();          // Set blinkStart as running millis();
      Serial.print("Start: ");          // Print to Serial Monitor
      Serial.println(blinkStart);       // Print to Serial Monitor
      delay(50);                // Debounce
    }
    while (voltage < 1)
    {
      sensorValue = analogRead(input);        // Read voltage at input pin
      voltage = sensorValue * (5.0 / 1023.0); // Convert
      blinkStop = millis();           // Set blinkStop as running millis();
      Serial.print("Stop: ");         // Print to Serial Monitor
      Serial.println(blinkStop);        // Print to Serial Monitor
      delay(50);                // Debounce
    }

    blinkRate = (blinkStop - blinkStart);   // Calculate blinkRate
    Serial.print("Blink Interval: ");     // Print to Serial Monitor
    Serial.println(blinkRate);          // Print to Serial Monitor
    delay(50);                  // Debounce
    learnMode = false;              // Exit learnMode
  }
  digitalWrite(output, relayState);       // Send relayState
}

It's hard to know where to start here. :)

 if (currentMillis + 500)

OK, what is that doing? It is adding 500 to currentMillis so that will be true almost all the time.

if (status = 3)

That is assigning 3 to status and then checking if it is non-zero, which it will be (it will be 3).

int turnPin = A1;
...

  int sensorValue = analogRead(A1);

Why not write:
  int sensorValue = analogRead(turnPin);

float voltage = sensorValue * (5.0 / 1023.0);

You calculate voltage but never use it. Why bother?

As for your question regarding if (currentMillis + 500) I wanted this statement to take the current time and add 500 to it and then check ...

OK, then this is the way to do that:
// see if 1/2 a second is up
if (currentMillis - previousMillis >= 500)
   {
   previousMillis = currentMillis;  // reset previousMillis
   ... do something ...
   }

BTW, previousMillis is also a variable you weren't using anywhere else.

Thanks for the input Nick!
I've cleaned the code up a bit more - just a few minor oversights I missed. Thanks for pointing them out.
As for your question regarding
if (currentMillis + 500)
I wanted this statement to take the current time and add 500 to it and then check if the voltage is still less than 1V - if it is then execute the ledState = LOW

See my amended answer.


text:
Relay Board making Output Signal Weak
I am using an Arduino Uno and Relay Shield (http://www.seeedstudio.com/blog/2013/02/28/shield-evolution-flexible-add-ons-for-arduino/relay-shield/), and using a code similar to the Teapot Demo, in which an LED blinks when movement is detected. When I connect the shield, the LED blinks at the normal brightness when uploading the code, but blinks extraordinarily dimly when indicating movement. This is both the external and internal LED display for the Arduino.
This is my current setup:

I think it must be a code issue because the LED clearly has the ability to blink on and off normally.
Any suggestions as to what is wrong or what I should do?
Below is my code:
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include "Wire.h"
#endif
MPU6050 mpu;
// uncomment "OUTPUT_READABLE_REALACCEL" if you want to see acceleration
// components with gravity removed. This acceleration reference frame is
// not compensated for orientation, so +X is always +X according to the
// sensor, just without the effects of gravity. If you want acceleration
// compensated for orientation, us OUTPUT_READABLE_WORLDACCEL instead.
#define OUTPUT_READABLE_REALACCEL

// uncomment "OUTPUT_TEAPOT" if you want output that matches the
// format used for the InvenSense teapot demo
#define OUTPUT_TEAPOT

//----------------------------------------------------------------------------------------------

const int LED_PIN = 13; // (Arduino is 13, Teensy is 11, Teensy++ is 6)
const int buzzerPin = 12;

bool blinkState = false;

// MPU control/status vars
bool dmpReady = false;  // set true if DMP init was successful
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer

// orientation/motion vars
Quaternion q;           // [w, x, y, z]         quaternion container
VectorInt16 aa;         // [x, y, z]            accel sensor measurements
VectorInt16 aaReal;     // [x, y, z]            gravity-free accel sensor measurements
VectorInt16 aaWorld;    // [x, y, z]            world-frame accel sensor measurements
VectorFloat gravity;    // [x, y, z]            gravity vector
float euler[3];         // [psi, theta, phi]    Euler angle container
float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector

// packet structure for InvenSense teapot demo
uint8_t teapotPacket[14] = { '$', 0x02, 0,0, 0,0, 0,0, 0,0, 0x00, 0x00, '\r', '\n' };

// ================================================================
// ===               INTERRUPT DETECTION ROUTINE                ===
// ================================================================

volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high
void dmpDataReady() {
    mpuInterrupt = true;
}

// ================================================================
// ===                      INITIAL SETUP                       ===
// ================================================================

void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
        TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

    // initialize serial communication
    // (115200 chosen because it is required for Teapot Demo output, but it's
    // really up to you depending on your project)
    Serial.begin(115200); // this is a "Baud" rate
    while (!Serial); // wait for Leonardo enumeration, others continue immediately

    // initialize device
    Serial.println(F("Initializing I2C devices..."));
    mpu.initialize();

    // verify connection
    Serial.println(F("Testing device connections..."));
    Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

    // wait for ready
    Serial.println(F("\nSend any character to begin DMP programming and demo: "));
    while (Serial.available() && Serial.read()); // empty buffer
    while (!Serial.available());                 // wait for data
    while (Serial.available() && Serial.read()); // empty buffer again

    // load and configure the DMP
    Serial.println(F("Initializing DMP..."));
    devStatus = mpu.dmpInitialize();

    // supply your own gyro offsets here, scaled for min sensitivity
    mpu.setXGyroOffset(220);
    mpu.setYGyroOffset(76);
    mpu.setZGyroOffset(-85);
    mpu.setZAccelOffset(1788); // 1688 factory default for my test chip

    // make sure it worked (returns 0 if so)
    if (devStatus == 0) {
        // turn on the DMP, now that it's ready
        Serial.println(F("Enabling DMP..."));
        mpu.setDMPEnabled(true);

        // enable Arduino interrupt detection
        Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
        attachInterrupt(0, dmpDataReady, RISING);
        mpuIntStatus = mpu.getIntStatus();

        // set our DMP Ready flag so the main loop() function knows it's okay to use it
        Serial.println(F("DMP ready! Waiting for first interrupt..."));
        dmpReady = true;

        // get expected DMP packet size for later comparison
        packetSize = mpu.dmpGetFIFOPacketSize();
    } else {
        // ERROR!
        // 1 = initial memory load failed
        // 2 = DMP configuration updates failed
        // (if it's going to break, usually the code will be 1)
        Serial.print(F("DMP Initialization failed (code "));
        Serial.print(devStatus);
        Serial.println(F(")"));
    }

    // configure LED for output
    pinMode(LED_PIN, INPUT);
    pinMode(buzzerPin, INPUT);
}

// ================================================================
// ===                    MAIN PROGRAM LOOP                     ===
// ================================================================

void loop() {
    // if programming failed, don't try to do anything
    if (!dmpReady) return;

    // wait for MPU interrupt or extra packet(s) available
    while (!mpuInterrupt && fifoCount < packetSize) {
        // other program behavior stuff here
    }

    // reset interrupt flag and get INT_STATUS byte
    mpuInterrupt = false;
    mpuIntStatus = mpu.getIntStatus();

    // get current FIFO count
    fifoCount = mpu.getFIFOCount();

    // check for overflow (this should never happen unless our code is too inefficient)
    if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
        // reset so we can continue cleanly
        mpu.resetFIFO();
        Serial.println(F("FIFO overflow!"));

    // otherwise, check for DMP data ready interrupt (this should happen frequently)
    } else if (mpuIntStatus & 0x02) {
        // wait for correct available data length, should be a VERY short wait
        while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

        // read a packet from FIFO
        mpu.getFIFOBytes(fifoBuffer, packetSize);

        // track FIFO count here in case there is > 1 packet available
        // (this lets us immediately read more without waiting for an interrupt)
        fifoCount -= packetSize;

        #ifdef OUTPUT_READABLE_REALACCEL
            // display real acceleration, adjusted to remove gravity
            int Mag;
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetAccel(&aa, fifoBuffer);
            mpu.dmpGetGravity(&gravity, &q);
            mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
            Serial.print("areal\t");
            Serial.print(aaReal.x);
            Serial.print("\t");
            Serial.print(aaReal.y);
            Serial.print("\n");
            Mag = sqrt((aaReal.x*aaReal.x) + (aaReal.y*aaReal.y));
            Serial.print("Accel. Mag. is ");
            Serial.print(Mag);
//            Serial.print("\t");
//            Serial.println(aaReal.z);
        #endif

        #ifdef OUTPUT_TEAPOT
            // display quaternion values in InvenSense Teapot demo format:
            teapotPacket[2] = fifoBuffer[0];
            teapotPacket[3] = fifoBuffer[1];
            teapotPacket[4] = fifoBuffer[4];
            teapotPacket[5] = fifoBuffer[5];
            teapotPacket[6] = fifoBuffer[8];
            teapotPacket[7] = fifoBuffer[9];
            teapotPacket[8] = fifoBuffer[12];
            teapotPacket[9] = fifoBuffer[13];
            Serial.write(teapotPacket, 14);
            teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
        #endif

        // blink LED and sound buzzer to indicate activity
        if (Mag > 120) {
          blinkState = !blinkState;
          digitalWrite(LED_PIN, blinkState);
//          delay(1000);
          tone(buzzerPin, 100);
        }
        else if (Mag <= 120) {
          digitalWrite(LED_PIN, LOW);
          noTone(buzzerPin);
        }

    }
}

If it gets dimmed when you're trying to switch the relay on, you don't have power supply powerfull enough to drive it. USB is too weak for this.

I thought this may be the case - I am also using a wall wart to supply 12V of power. It is not changing the output brightness though. Is there another component missing?

Without seeing your code, it is hard to tell you directly what the problems is. If you can, please post your code.
Based on the information in your question, I can see two possible causes for this.
Firstly, it could be that there isn't enough power from your supply to power everything. So when the Arduino tries to turn on the relay, it doesn't have enough grunt and the voltage drops too low and the Arduino resets, de-energising the relay. This happens many times a second and shows up as a dull LED.
This can be proven by disconnecting the relay from the Arduino output. Run the sketch again, and if everything works at full brightness without the relay connected, then it is almost certainly not enough power.
My second theory is that it is a bug in your code. Some cycles it detects movement and so it turns the LED on.  Others cycles it doesn't detect a change in movement so it turns the LED off. This happens many thousand times a second. It would be visible on an oscilloscope if you have one.
The simple thing you could do for this scenario is to add a delay (eg delay(1000);) straight after the LED is turned on when movement is detected. This should leave the LED on for at least a second after movement is detected.

You're probably right. I added a delay and the LED was dimly glowing even when using the wall wart. I have another wall wart that has bare wires so that I can use it as an external power source. Do you think this would work? If so, should I just hook the LED up directly to one end and ground the other?

What is the current output of the wall warts? What you suggest is what I would look into. I would just be cautious doing so. Examine the schematics of each to make sure that one doesn't feed into the other.

The current output is 800mA. I got the larger LED to glow, which was the main goal, so it may have just been due to faulty wiring on my part. Thank you for your help!


text:
IR receiver starts giving nonsense readings in LED colour change setting
First of all, I'm very new to this so sorry if it's a dumb question.
I have an IR module which I'm using to control an LED strip. I have set buttons 1–3 on the remote to select three basic static colours and up and down to adjust brightness. So far so good.
I have set button 4 to gradually shift through different colours. Once I activate this code, the IR receiver appears to stop working, and Serial.print shows that it's now reporting random values whatever button I press on the remote.
I have tried Vishay TSOP4838 and KY-022 type receivers, and tried varying combinations of resistors and capacitors on the receiver power supply. I've tried powering it from 3.3V and 5V.
The code that I'm using is only changing numerical values to adjust the colour, so short of there being 'noise' somewhere in the hardware I'm at a loss as to why only this code breaks it. The LED is powered by a 12V adaptor. The IR receiver is the only thing powered by the Arduino.
My full code is as follows, I know it's untidy. I am a noob:
Thank you
#include "IRremote.h"
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

//To change the LED/IR reciever pins, you just need to change these values
#define PIN 13 //LED strip
int receiver = 10; //IR receiver

unsigned long debouncing = 0;
unsigned long rotatedelay = 6;
unsigned long fadegap = 5;
byte state = 0; //maintains function based on last button press
byte red = 0;
byte blue = 0;
byte green = 0;
byte brightness = 250;
byte rotate = 0; //used for cycling through colours in state 4

Adafruit_NeoPixel strip = Adafruit_NeoPixel(50, PIN, NEO_GRB + NEO_KHZ800);

//Declare IR objects
IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

//Setup IR buttons with names
void translateIR() // takes action based on IR code received

// Naming remote IR codes and assigning a 'state'

{

  switch(results.value)

  {
  case 0xFFA25D: state = 10; Serial.println("POWER"); break;
  case 0xFF629D: state = 11; Serial.println("VOL+"); break;
  case 0xFFE21D: state = 12; Serial.println("FUNC/STOP"); break;
  case 0xFF22DD: state = 13; Serial.println("FAST BACK");    break;
  case 0xFF02FD: state = 14; Serial.println("PLAY/PAUSE");    break;
  case 0xFFC23D: state = 15; Serial.println("FAST FORWARD");   break;
  case 0xFFE01F: Serial.println("DOWN");    break;
  case 0xFFA857: state = 17; Serial.println("VOL-");    break;
  case 0xFF906F: Serial.println("UP");    break;
  case 0xFF9867: state = 19; Serial.println("EQ");    break;
  case 0xFFB04F: state = 20; Serial.println("ST/REPT");    break;
  case 0xFF6897: state = 0; Serial.println("0");    break;
  case 0xFF30CF: state = 1; Serial.println("1");    break;
  case 0xFF18E7: state = 2; Serial.println("2");    break;
  case 0xFF7A85: state = 3; Serial.println("3");    break;
  case 0xFF10EF: state = 4; Serial.println("4");    break;
  case 0xFF38C7: state = 5; Serial.println("5");    break;
  case 0xFF5AA5: state = 6; Serial.println("6");    break;
  case 0xFF42BD: state = 7; Serial.println("7");    break;
  case 0xFF4AB5: state = 8; Serial.println("8");    break;
  case 0xFF52AD: state = 9; Serial.println("9");    break;
  case 0xFFFFFFFF: Serial.println("REPEAT");break;

  default:
    Serial.println(" other button   ");

  }// End Case

} //END translateIR

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the IR receiver
  strip.begin();
  colorBlock(strip.Color(0, 0, 0));
  strip.show(); // Initialize all pixels to 'off'

//Fades LED strip light in at startup
for(uint8_t b = 0; b <255; b++) {
     for(uint8_t i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, 255 * b/255, 255 * b/255, 255 * b/255);
     }

     strip.show();
     delay(5); //speed of fade in (20 x 255 = total time)
  };
}

void loop() {

//IR detection code
//if (irrecv.decode(&results) && millis() - debouncing > 1000) // have we     received an IR signal? ignores button press if less than a second after previous
if (irrecv.decode(&results)) // have we received an IR signal?
{
    translateIR();
    irrecv.resume(); // receive the next value
    Serial.println(results.value, HEX);

if (state == 1){
  rotate = 0;
  red = 0; blue = 255; green = 0;
colorBlock(strip.Color(red, blue, green));
}

if (state == 2){
  rotate = 0;
  red = 0; blue = 0; green = 255;
colorBlock(strip.Color(red, blue, green));
}

if (state == 3){
  rotate = 0;
  red = 255; blue = 0; green = 255;
colorBlock(strip.Color(red, blue, green));
}

//brightness
if (results.value == 16769055 && brightness > 0){
  brightness = brightness - 10;
  strip.setBrightness(brightness); strip.show();
  Serial.println(brightness);
}

if (results.value == 16748655 && brightness < 241){
  brightness = brightness + 10;
  strip.setBrightness(brightness); colorBlock(strip.Color(red, blue, green));     strip.show();
  Serial.println(brightness);
}
}

//rotating colours
if (state == 4){
  //Serial.println (state);
  //Serial.println (rotate);
  //Serial.print ("red"); Serial.print (red); Serial.print ("blue"); Serial.print (blue); Serial.print ("green"); Serial.println (green);
  //Serial.println (rotatedelay);
}

if (state == 4 && rotate == 0 && red < 255 && millis() - rotatedelay > 1){
  red = red + fadegap;
  if (blue >= 1){
    blue = blue - fadegap;}
  if (green >= 1){
    green = green - fadegap;}
  colorBlock(strip.Color(red, blue, green));
  rotatedelay = millis();
}

if (state == 4 && rotate == 0 && green > 0 && millis() - rotatedelay > 1){
  green = green - fadegap;
  colorBlock(strip.Color(red, blue, green));
  rotatedelay = millis();
}

if (state == 4 && rotate == 0 && red == 255 && green == 0 && blue == 0 &&         millis() - rotatedelay > 1){
  rotate = 1;
}

if (state == 4 && rotate == 1 && blue < 255 && millis() - rotatedelay > 1){
  blue = blue + fadegap;
  if (red >= 1){
    red = red - fadegap;}
  if (green >= 1){
    green = green - fadegap;}
  colorBlock(strip.Color(red, blue, green));
  rotatedelay = millis();
}

if (state == 4 && rotate == 1 && red == 0 && green == 0 && blue == 255 &&     millis() - rotatedelay > 1){
  rotate = 2;
}

if (state == 4 && rotate == 2 && green < 255 && millis() - rotatedelay > 1){
  green = green + fadegap;
  if (red >= 1){
    red = red - fadegap;}
  if (blue >= 1){
    blue = blue - fadegap;}
  colorBlock(strip.Color(red, blue, green));
  rotatedelay = millis();
}

if (state == 4 && rotate == 2 && blue == 0 && red == 0 && green == 255 &&     millis() - rotatedelay > 1){
  rotate = 0;
}
}

//Solid colour
 void colorBlock(uint32_t c) { //This seems to be the way to colour the whole strip
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    }
 }

Perhaps build two alternate test setups: one where the IR receive can "see" the LED strip but there is no electrical connection of any sort (ie, a second setup with another Arduino on a different computer).  Another with your typical electrical connections, but where the IR receiver is fully shielded from any sight of the LEDs - wrapped in multiple layers of electrical tape or something like that.

remove all code from inside of if (state == 4 && statements and insert Serial.println( statements for debugging

tip: you can use code like this if (blue >= 1) blue -= fadegap;

I've had some problems of the LED's PWM interfering with the IR signal. Or so it seemed at least. In theory, the receiver should have a 38 kHz band pass filter. Also, your code doesn't compile: there's a missing '}' at the end of your loop function.

Thank you for the ideas. I tried isolating the light from the receiver and no luck. Perhaps it's PWM, I need to read up on how the filter works. Oh and the code compiles, it was just a copy/paste error. Thanks

Before the lines
//rotating colours
if (state == 4){

You have an extra closing brace.  IF that is in you real code, I'm not sure how it is compiling.
Assuming it isn't that then you might want to change you code to make it more readable.  This is just part of you code from the same place mentioned before:
if (state == 4)
{
    if (millis() - rotatedelay > 1)
    {
        if (rotate == 0)
        {
            checkFadeGap (red, blue, green);

            if (green > 0)
            {
                green -= fadegap;
                colorBlock(strip.Color(red, blue, green));
                rotatedelay = millis();
            }//if (green > 0)
            if (red == 255  && green == 0 && blue == 0)
            {
                rotate = 1;
            }//if (red == 255)
        }
        if (rotate == 1)
        {
            checkFadeGap (blue, red, green);
            if (red == 0 && green == 0 && blue == 255)
            {
                rotate = 2;
            }//if (blue == 255)
        }
        if (rotate == 2)
        {
            checkFadeGap (green, reb, blue);
            if (red == 0  && green == 255 && blue == 0)
            {
                rotate = 0;
            }//if (green == 255)
        }
    }//if (millis() - rotatedelay > 1)
}    // end of if (state == 4)

This function removes some of the complexity in the code above.
void checkFadeGap (byte& inc, byte& dec1, byte& dec2)
{
    if (inc < 255)
    {
        inc += fadegap;
        if (dec1 > 0)
            dec1 -= fadegap;
        if  (dec2 > 0);
            dec2 -= fadegap;
        colorBlock(strip.Color(red, blue, green));
        rotatedelay = millis();
    }
}


text:
Timer Countdown to control relay (multiple functions in void loop)

I'm trying to build this project with a simple code.
Object is to hit up button to increment minutes or down to decrement minutes then hit start to start countdown,
while its counting relay will turn On light till counting is done will turn light off and if I hit end button while counting it will end counting and turn off relay.
Here is my try I would appreciate if you could support me.
i can not move to countDown() function in the loop if i press start
I need help to figure out a good technique of declaring functions in void loop in arduino

#include <LiquidCrystal.h>

LiquidCrystal lcd(1,2,4,5,6,7);

#define numberOfSeconds(num) ((num/1000) % 60 )
#define numberOfMinutes(num) (((num/1000) / 60) % 60)

//unsigned long timeLimit = 3600000; // 1000 ms in 1sec, 60secs in 1min, 60mins in 1hr. so , 1000x60x60 = 3600000ms = 1hr

const int upBtn = 8;
const int downBtn = 9;
const int startBtn = 10;
const int endBtn = 11;

int btnPushCounter = 0;
int minutes;
int seconds;
unsigned long minutesGiven;
unsigned long timeLimit;
unsigned long timeRemaining;

int upBtnState = 0;
int lastUpBtnState = 0;

int downBtnState = 0;
int lastDownBtnState = 0;

int startBtnState = 0;
int lastStartBtnState = 0;

int endBtnState = 0;
int lastEndBtnState = 0;

bool bPress = false;

void setup() {

 lcd.begin(16,2);
 pinMode(upBtn, INPUT_PULLUP);
 pinMode(downBtn, INPUT_PULLUP);
 pinMode(startBtn, INPUT_PULLUP);
 pinMode(endBtn, INPUT_PULLUP);

 lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Minutes : ");
 lcd.print(btnPushCounter);
}
void loop() {

    checkUp();
    checkDown();
//    countDown();
    if(bPress){
      bPress = false;
      displayNumber();
    }
}

void displayNumber(){
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Minutes : ");
    lcd.print(btnPushCounter);
}

void checkUp(){
  upBtnState = digitalRead(upBtn);
  // compare the buttonState to its previous state
  if (upBtnState != lastUpBtnState) {
    // if the state has changed, increment the counter
    if (upBtnState == HIGH) {
        bPress = true;
      btnPushCounter++;
    }
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastUpBtnState = upBtnState;
}

void checkDown(){
  downBtnState = digitalRead(downBtn);

  // compare the buttonState to its previous state
  if (downBtnState != lastDownBtnState && btnPushCounter != 0 ) {
    // if the state has changed, increment the counter
    if (downBtnState == HIGH) {
        bPress = true;
      btnPushCounter--;
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastDownBtnState = downBtnState;
}

void checkStart(){
  startBtnState = digitalRead(startBtn);
  if(startBtnState != lastStartBtnState){
    if(startBtnState == HIGH){
      bPress = true;
//      lcd.
    }
  }
}

void countDown() {
//  unsigned long timeLimit = 3600000;
  minutesGiven = btnPushCounter;
  timeLimit = minutesGiven * 1000 * 60;
  timeRemaining = timeLimit - millis();
  while(timeRemaining > 0){
    seconds = numberOfSeconds(timeRemaining);
    minutes = numberOfMinutes(timeRemaining);
    lcd.setCursor(2,7);
    lcd.print(minutes);
    lcd.print(" ");
    lcd.print(seconds);
    delay(50);
    timeRemaining = timeLimit - millis();
  }
}

what is your question?

just updated have a look please , thanks

still no question being asked .... let me say it differently .... you posted i am working on project ABC, here i my code .... we need to see something like this  i am working on project ABC, here i my code. i expect the program to do XYZ, but it does ZYX. how do i debug a problem like that?

I think you are not searching for a way to declare function, but for the logic code, that you need to call them in the right situations. Is that correct?

And why don't you simply put countDown() into checkStart()?

moving functions above setup solved the issue , Thanks a lot guys

I think what you're looking for is to declare your functions near the top of your file, usually before the first function you write, setup(), in this case. So add this just above your setup() function:
// Forward function declarations
void displayNumber(void);
void checkUp(void);
void checkDown(void);
void checkStart(void);
void countDown(void);

C compilers (and thus, C++ because it was derived from C) read the source code only once through, so any function must become known to the compiler ahead of where it is first called. This would require you to place all low-level functions first, then all functions that call those, then the functions that call those, ..., etc. And there are some cases that even this arrangement won't solve, e.g., functions that call each other (oww, my brain hurts!!). So function declarations are used to avoid this inconvenience.
Declaring a function just means informing the compiler of its name, the parameter types, and the return type -- the actual function code isn't required at this point.


text:
Robot car speed issue

If I'm connecting it in this way I have no issue and I can control the speed.
here is a video

const int speedMotorA = 9;
const int speedMotorB = 3;
const int motorPin1  = 4;
const int motorPin2  = 7;
const int motorPin3  = 12;
const int motorPin4  = 13;

void setup() {
  Serial.begin(9600);
  pinMode(speedMotorA, OUTPUT);
  pinMode(speedMotorB, OUTPUT);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}
void loop(){
  TurnMotorA();
  TurnMotorB();
}

void TurnMotorA() {
  int Speed = analogRead(A2);
  Speed = Speed*0.24926686;
  Serial.println(Speed);
  analogWrite(speedMotorA,Speed);
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
}

void TurnMotorB() {
  int Speed = analogRead(A2);
  Speed = Speed*0.24926686;
  analogWrite(speedMotorB,Speed);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
}

now I'm trying to expand my mini-project with servo and ultrasonic sensor
with this code and wiring, I have tried many ways to control speed but it's not working properly while increasing speed motor A respond but motor B stay off till I reach maximum speed 255 motor B start working.
here is a video

#include <NewPing.h>
#include <Servo.h>

#define TRIG_PIN A4
#define ECHO_PIN A5
#define MAX_DISTANCE 200
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);
Servo myservo;

const int laser = 8;
int distance = 0;
const int speedMotorA = 9;
const int speedMotorB = 3;
const int motorPin1  = 4;
const int motorPin2  = 7;
const int motorPin3  = 12;
const int motorPin4  = 13;

int hitlaser(){
  digitalWrite(laser, HIGH);
  delay(200);
  digitalWrite(laser, LOW);
}

void setup() {
  pinMode(laser, OUTPUT);
  pinMode(speedMotorA, OUTPUT);
  pinMode(speedMotorB, OUTPUT);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  myservo.attach(5);
  myservo.write(65);
  delay(2000);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
}

void loop() {
 int distanceR = 0;
 int distanceL =  0;
 delay(40);
 digitalWrite(laser, HIGH);
 if(distance<=50)
 {
  moveStop();
  delay(100);
  moveBackward();
  delay(300);
  moveStop();
  delay(200);
  distanceR = lookRight();
  delay(200);
  distanceL = lookLeft();
  delay(200);

  if(distanceR>=distanceL)
  {
    turnRight();
    moveStop();
  }else
  {
    turnLeft();
    moveStop();
  }
 }else
 {
  moveForward();
 }
 distance = readPing();
}

int lookRight()
{
    myservo.write(5);
    delay(500);
    int distance = readPing();
    delay(100);
    myservo.write(65);
    return distance;
}

int lookLeft()
{
    myservo.write(150);
    delay(500);
    int distance = readPing();
    delay(100);
    myservo.write(65);
    return distance;
    delay(100);
}

int readPing() {
  delay(70);
  int cm = sonar.ping_cm();
  if(cm==0)
  {
    cm = 250;
  }
  return cm;
}

void moveStop() {
    analogWrite(speedMotorA, 0);
    analogWrite(speedMotorB, 0);
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
  }

void moveForward() {
    int Speed = analogRead(A2);
    Speed = Speed*0.24926686;
    Serial.println(Speed);
    analogWrite(speedMotorA,Speed);
    analogWrite(speedMotorB,Speed);
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);
}

void moveBackward() {
    int Speed = analogRead(A2);
    Speed = Speed*0.24926686;
    Serial.println(Speed);
    analogWrite(speedMotorA,Speed);
    analogWrite(speedMotorB,Speed);
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, HIGH);
}

void turnRight() {
  int Speed = analogRead(A2);
  Speed = Speed*0.24926686;
  Serial.println(Speed);
  analogWrite(speedMotorA,Speed);
  analogWrite(speedMotorB,Speed);
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delay(300);
  moveForward();
}

void turnLeft() {
  int Speed = analogRead(A2);
  Speed = Speed*0.24926686;
  Serial.println(Speed);
  analogWrite(speedMotorA,Speed);
  analogWrite(speedMotorB,Speed);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delay(300);
  moveForward();
}

update :
after removing servo from the project it seems working but how can i use servo with this project
Thanks to  Majenko♦
update 2
after attaching servo to pin 9 i can now controle speed but still some issues as when Robot car have obsticles it should make backword >> issue is >> one motor only go backword!.
#include <NewPing.h>
#include <Servo.h>

#define TRIG_PIN A4
#define ECHO_PIN A5
#define MAX_DISTANCE 200
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);
Servo myservo;

const int laser = 8;
int distance = 0;
const int speedMotorA = 11;
const int speedMotorB = 3;
const int motorPin1  = 4;
const int motorPin2  = 7;
const int motorPin3  = 12;
const int motorPin4  = 13;

int hitlaser(){
  digitalWrite(laser, HIGH);
  delay(200);
  digitalWrite(laser, LOW);
}

void setup() {
  pinMode(laser, OUTPUT);
  pinMode(speedMotorA, OUTPUT);
  pinMode(speedMotorB, OUTPUT);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  myservo.attach(9);
  myservo.write(65);
  delay(2000);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
}

void loop() {
 int distanceR = 0;
 int distanceL =  0;
 delay(40);
 digitalWrite(laser, HIGH);
 if(distance<=50)
 {
  moveStop();
  delay(100);
  moveBackward();
  delay(1000);
  moveStop();
  delay(200);
  distanceR = lookRight();
  delay(200);
  distanceL = lookLeft();
  delay(200);

  if(distanceR>=distanceL)
  {
    turnRight();
    moveStop();
  }else
  {
    turnLeft();
    moveStop();
  }
 }else
 {
  moveForward();
 }
 distance = readPing();
}

int lookRight()
{
    myservo.write(5);
    delay(500);
    int distance = readPing();
    delay(100);
    myservo.write(65);
    return distance;
}

int lookLeft()
{
    myservo.write(150);
    delay(500);
    int distance = readPing();
    delay(100);
    myservo.write(65);
    return distance;
    delay(100);
}

int readPing() {
  delay(70);
  int cm = sonar.ping_cm();
  if(cm==0)
  {
    cm = 250;
  }
  return cm;
}

void moveStop() {
    analogWrite(speedMotorA, 0);
    analogWrite(speedMotorB, 0);
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
  }

void moveForward() {
    int Speed = analogRead(A2);
    Speed = Speed*0.24926686;
    Serial.println(Speed);
    analogWrite(speedMotorA,Speed);
    analogWrite(speedMotorB,Speed);
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);
}

void moveBackward() {
    int Speed = analogRead(A2);
    Speed = Speed*0.24926686;
    Serial.println(Speed);
    analogWrite(speedMotorA,Speed);
    analogWrite(speedMotorB,Speed);
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, HIGH);
}

void turnRight() {
  int Speed = analogRead(A2);
  Speed = Speed*0.24926686;
  Serial.println(Speed);
  analogWrite(speedMotorA,Speed);
  analogWrite(speedMotorB,Speed);
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delay(300);
  moveForward();
}

void turnLeft() {
  int Speed = analogRead(A2);
  Speed = Speed*0.24926686;
  Serial.println(Speed);
  analogWrite(speedMotorA,Speed);
  analogWrite(speedMotorB,Speed);
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delay(300);
  moveForward();
}

Appreciate your support

Some ground connections are missing.

yeah but in the video, it's connected, forgot to add this on drawing.( servo ground wire)

The problem here is a conflict of resources.  Both the Servo library and the PWM for pin 9 require the same timer.

The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.

You should choose a different PWM pin (not pin 10) instead of pin 9.

for servo I'm using only one pin myservo.attach(5);

myservo.attach(8); (I have changed it to pin 8 but still not working).

Ok i have removed servo from the project and it seems working , so how can i fix this issue and let it work with servo .. Question updated Thanks ! @https://arduino.stackexchange.com/users/4143/majenko

Another update2 please check

@ahmedyounes It doesn't matter where the servo is. It's the pin 9 pwm for the motor you must change - like my answer states quite clearly.

yes I'm not using pin 9 for motor anymore, I updated the code in the update section, the only issue is when it's doing backward , one motor only works will upload video

If you cut out all the code from your program except code to make it always run backwards, does it work?

Thanks alot Majenko its working now , is there any documentation for these pins disabled when servo library is used ?


text:
Arduino IDE giving a blow to battery back-up of PC
When I have serial plotter open in the Arduino IDE with serial communication going on, the fans of my PC go full speed. On checking I found that Java(TM) Platform SE binary(32 bit) is using about 29% of the CPU.
This gives a big blow to the PC's battery back-up. Is there some way to reduce the CPU usage ?

The IDE version I use is Arduino 1.8.4

OS : Microsoft Windows 10 Home (64 bit)

PC : HP Au620 TX (laptop)

processor : Intel i5 7th gen (7200)

RAM : 8GB

What sort of computer?  What OS?  You've left out a ton of detail here.

That's Java for you...

what battery backup?

@Majenko I doubt Java is to blame. One could write a busy loop in any language.

@DmitryGrigoryev Indeed, but Java makes it easier for dumbass programmers to write terrible code.

try restarting Ardunio and not compiling anything before using the serial plotter.

Run Arduino IDE in a virtual machine which allows CPU allocation. Set a strict limit on CPU resources in that VM, like 200..500 MHz.


text:
Get 5V output from NodeMCU
I have a sensor that requires used of 5V as input to Vcc. But I dont see any 5V output pins on the NodeMCU 1.0(12E). Is there a way I could get 5V output pins?
Its not a duplicate question. I want a 5V output and not provide 5V input to NODEMCU.

Its not a duplicate question. I want a 5V output and not provide 5V input to NODEMCU.

I also did not know the Vin pin could be used for output; read the accepted answer from Majenko.

Got it. Thanks.

The VIN pin outputs 5V approximately (dependent on USB input voltage) from the NodeMCU board.

Comments are not for extended discussion; this conversation has been moved to chat.

thank you @VE7JRO!

On my boards, the Vin pin outputs 4.76V because there's a Schottky diode between Vusb and the Vin pin which drops the voltage (see the circuit diagram). This Vin is also quite noisy and is a poor power source for analog circuitry.


text:
How to acheive fast and reliable communication between NodeMCUs?
I have two NodeMCU which have to send data to a server (also a NodeMCU). I want to acheive speed of atleast 10Hz because the sensor sends it at that rate. I have  tried websockets and couldn't get transfer rate of more than 1Hz and the data was being put in the buffer.
Any ideas how could I can acheive speed of 10Hz via WiFi?
Thanks for any help.

the symbol for the unit of frequency measurement is Hz, not hz ... please correct your question

WiFiClient object wraps a TCP socket. A normal TCP socket is connected to IP address and port. WiFiServer starts a listening socket on a port. If server on listening socket is contacted by a remote client socket, it creates a local socket connected with the remote client socket on a free port and returns a WiFiClient object wrapping the socket. Everything you write or print to a WiFiClient is send to that one remote socket.
If one of your client boards creates a WiFiClient and connects it to IP address and port of the WiFiServer on your 'server' board, then you get there a WiFiClient from server.available() and this two WiFiClient objects are connected. What you write/print on one side you read from the WiFiClient object on the other side.
client socket
if (client.connect(serverIP, PORT)) {
  client.print("request\n");
  String response = client.readStringUntil('\n');
  Serial.println(response);
  client.stop();
}

server side
WiFiClient client = server.available();
if (client && client.connected()) {
  String request = client.readStringUntil('\n');
  Serial.println(request);
  client.print("response\n");
  client.stop();
}


text:
Problem uploading code to ESP 8266-01 adapter
I feel like I've tried just about everything and it still doesn't work. There must be something I'm not seeing. I am using an Arduino uno, an ESP8266-01 wifi module, and an ESP-01 Adapter. The arduino is connected to the laptop, and I'm using 4 AA batteries as external source (they are brand new) because I wanted to check if my Arduino wasn't supplying the necessary power.
I keep getting the following error:
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed
I changed my preferences to add to the boards http://arduino.esp8266.com/versions/2.4.1/package_esp8266com_index.json
This is how I set up tools. I keep trying every upload speed whenever I make a change to see if that makes it work but nothing still.

I also tried using this tutorial but it also didn't work.
Any help would be appreciated :)

using Uno instead of USBtoTTL adapter is a workaround that doesn't work with some Unos

Try this: https://tttapa.github.io/Pages/Arduino/ESP8266/Flashing/Flashing-With-an-Arduino.html

I tried it but it still didn't work. Has anyone actually build that themselves? like... any tips? I feel like I followed the instructions by the letter.

@KennethYoung, you think Pieter (tttapa) wrote it in the tutorial without trying?

@Juraj well, the idea was to ask if anyone that did it had any tips, like common problems or easy to miss details or something

I tried it for fun it and it didn't work at all. And I am an experienced troubleshooter. I tested with Seeeduino Lotus with CH340 and with Uno WiFi which in this case should be equivalent to original Uno R3 Made in Italy with ATmega16U2. But normally I use an USBtoTTL adapter to program an esp8266 module.