text:
Differential voltage measurement with Arduino UNO
EDITED:
I bought a very sensitive (and expensive) pressure sensor which requires differential analog measurement. I am an amateur hobbyst and a total beginner in Arduino so I would like to ask some advice on how to connect the device so nothing would be damaged.
In the figure below is the scheme which I've got form the manufacturer along with schematic on how I am going to connect that:

the wire colours are as in the provided device,
the symbols are as they were attached to the wires,
the resistor was provided and connected by the manufacturer.

As far as I understood the sensor manual I should connect the device to analog pins as in the schematic below, and read the A0 and A1 and subtract the signal values. Is that fine? Should I connect the wire going to A1 to Arduino GND as well?

Or should I connect the GND instead of A0 line in the image below?

EDIT: Original connection scheme from the DS and link to the CL1A sensor www and  link to the sensor datasheet (only in Polish)
Yeah, possibly I misunderstood something.

I have a very detailed (and impressive) answer, but I'm not going to tell you what it is.

I'm a bit puzzled about the reason why you connected ground to the + terminal and +24 to the - terminal of the power supply... And why the A1 pin is connected to ground... I think you'd better search the datasheet better before flipping the switch

@frarugi87 that is from the connection scheme which was provided by the manufacturer. I only added the Arduino to what i've got from the device provider

Either the manufacturer is clueless or you misinterpreted what they were telling you. Either way I sense a Smoke Event on the horizon.

@Misery well, I'm a bit suspiciuos about this... maybe you read it in a wrong way, maybe the DS is wrong, or who knows. We don't have the datasheet or even just the sensor part number, since you did not provide any info... Majenko anticipated me but, as you can see, the reasons we thought of are the same... You should either provide more infos or... Well, Smoke Event is pretty easy to understand

Notice how your schematic doesn't match the original?

@EdgarBonet Instead of A1 there should be GND pin? Lol, I get it! Now

Supply + goes to "+24V", supply − goes to GND, the white sensor wire is labeled "+S" (S like "signal"), not "+5V".

Please avoid editing your original post  by deleting the older parts, otherwise the answers become useless. If you have to add something, edit at the bottom part of the questio (modifying what you have already written can be done only for improving the question, not for correcting it)

if you have an expensive sensor, it's kind of silly to use such a low res ADC on it, when you can get a full-range 16-bit (64k levels vs 1k) ADS1115 for under $5 that go rail-to-rail, up to 5.5-ish volts

@dandavis You're absolutely right. But now I am using Arduino for testing. If everything works properly I will switch to proffesional ADC

I'd suggest first using a multimeter to measure the signal voltage you get out of the sensor. Less chance of getting things wrong, that with a power Arduino.

Is there a question here?

According to the update, which shows the datasheet, you have one BIG mistake and one smaller mistake.
The big mistake is that you inverted the polarity! Look carefully. The +24V wire goes to the + pin of the supply, while the ground to the - pin.
Moreover the DAQ board has a differential one, but one of them is tied to ground.
So I suggest you to attach the wires in this way:

Thanks, that seems reasonable. I will check that on Monday, and if there is no "Smoke Event" I will let you know.

You do not need to do any kind of differential measurement here. The
Arduino analog input measures voltages relative to ground. Then, as long
as the Arduino and the power supply share a common ground, you should be
fine.
On the other hand, you may need a voltage divider. I have seen a few
sensors interfaced the same way (GND, +24V and signal), which output a
voltage between 0 and +10 V. That could fry the Arduin, and maybe
also the sensor. Check the datasheet to see the maximum voltage the
sensor can output, and use a voltage divider to get that safely into the
0 – +5 V range.

The output of that sensor is an industry standard "4-20mA" (known as a current loop). That means that the current output from the +S wire varies between 4mA and 20mA depending on the pressure. You need to convert that current into a voltage so that the Arduino can sample it.
Note that your attempt at a schematic is completely backwards. You must connect the +24V pin to +24V on a power supply. GND must be connected to GND on the power supply, and also GND on the Arduino.
Now for the signal. Yes, a resistor is the simplest way of converting a current into a voltage. Simply pass the current through the resistor to ground and a voltage will be dropped across it.
According to Ohm's Law, V=IR. Or, to turn it around, R=V/I.
Your maximum current is 20mA (0.02A) and your desired maximum voltage is 5V. So you can put those values into Ohm's Law and get a resistance:

R=V/I = 5/0.02 = 250Ω.

Now 250Ω resistors aren't that common, but 220Ω ones are. So what would that give us?

V = IR = 0.02 * 220 = 4.4V

Perfect. And at the lower (4mA) end of the range?

V = IR = 0.004 * 220 = 0.88V.

So with a 220Ω resistor you would get a voltage reading of between 0.88 and 4.4V on the Arduino.
(Note: the datasheet recommended 100Ω would be more suitable for a 3.3V Arduino - it would give between 0.4V and 2V).
For safety I would also include a small inline current limiting resistor and 5.1V zener diode. If the 220Ω resistor should fail or become disconnected you would get the full 24V (or somewhere about there) across the Arduino's A0 pin. It's limited to 20mA so may not be a problem, but you can't be sure, so best to add that to clamp the voltage to a maximum of 5.1V. After all, a zener diode is cheaper than a new Arduino.
And to clarify - the schematic:

simulate this circuit – Schematic created using CircuitLab

Which pressure transducer is it really ? The "CL 1A" can be made as version "R1" with strain gauge output of 10mV or with a processing unit inside for version "3I4" (4-20mA output), "3U1" (1V output), "3U5" (5V output), "3U10" (10V output).

@Jot Well, the circuit provided can only be for the 3I4 4-20mA version. It makes no sense with any of the others. Plus that will be the most common variant since it's industry standard.

We need a photo of the pressure transducer to be sure (assuming the type is written on the pressure transducer).


text:
Running out of pins in a 4x7-segment display clock
I've been playing around with the 7-segment displays and so far I've only been able to make 1 working display hooked up to a potentiometer that changes the number on the display with a switch that turns it into a counting-up timer
My main goal is to make a Clock but that uses 4 7-segment displays and I've already used up 7 pins for 1 display so now I either need to make more pins (I'm using Arduino Uno which has 14 Digital pins + 6 if you use the Analog In pins)
or use the 7-segment decoders
if I use the 7 segment decoder that will take up 4 per display which totals up to 16 which is well in range the required amount of Pins
so can someone teach me what is easier to do:
Making more pins using the 8-bit shift registers
or
Use the 7-segment decoders to make space
and if you think one is easier can you tell me how to use them because I have no idea and I've been tinkering with the decoder for the past hour or two
(btw the 7-segment displays are all Common Anode)

A 4-digit 7-segement display needs 4+7 (not 4×7) pins.

I don't have a 4-digit 7-segment display I only have the 4 individual 7-segment displays

You can wire them just like a 4-digit display is internally wired.

butt how tho...

See for example here and here, and read about using a driver circuit.

I still don't understand :P pardon me I'm still a beginner at all of this Arduino stuff
using the 2nd link you told me I can just hook up 7 pins to all A-G of all the 4 7-segment displays and then just activate the display that I will use and move on to the next from there?
Although I have a faint idea I will try to do some more tinkering with those in mind
Thanks for all your help :)

You generally use multiplexing to drive multiple segments. That way you only need 4 + 7 pins. Try googling "multiplexing seven segement".

The basic idea is this:
First, connect segment A of each display together, and all the segment Bs together, and all the segment Cs and so on.  Each "group" is driven by one pin on the Arduino.  For this you will need seven pins.
Your displays will have either a common anode or common cathode - perhaps you have that connected straight to +5v or straight to ground currently.  Instead, you connect the "common" pin from each display to a spare pin on your Arduino - so using another four pins.
Remember the resistors too.
Now, you can light up any segment on any display, by setting the appropriate segment pin and the appropriate common pin to the right values.
Make sense?

Thanks for giving out an Answer but I've already figured it out a while ago with Edgar Bonet's help :P thanks tho

source: Stack Exchange

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

sort: votes


text:
Arduino stopped working
my arduino uno stopped working. It shuts off itself every time i plug it in. This golden thing is ovetheating.
Do i have to replace it or buy a new uno or what.

That golden thing is the resettable fuse. You are drawing to much current which will trip ( and heat up) the fuse. Check you circuit for any shorts.

As Gerben has said, that "golden thing" is a resettable fuse (AKA polyfuse).
It's there to protect the USB port of your computer against excess current draw from a faulty board (which seems to be happening, by the way).
If nothing else is connected to the Arduino and the polyfuse keeps tripping, then the fault root cause is probably a short-circuit in the board. From here there are 2 possible scenarios:

Least likely: an external agent (metallic flakes, dirt, or something like that) might be causing the short-circuit. Inspect the board, clean it and electrically isolate it when plugging it again (avoid the solder joints getting in contact with a conductive surface, use a case or a mat).
More likely: a component has failed in short-circuit mode and is causing the excess current draw that trips the polyfuse. In that case you could try to debug the board (with at least a multimeter, and maybe other instruments) to locate the faulty component and replace it. That's not an easy task unless you precisely know what to do and where to look in the board. You might be better off buying a new board.

If you want to give the repair route a try, check this question. The schematic may be of some help to you. You might want to verify the integrity of the decoupling capacitor in first place.

If the OP has a socketed Arduino then he can remove the Atmega to see if it is the faulty component. Should help trace the short.

True. However, from the picture it looks like an CH340G arduino clone. Those usually have an SMD ATmega on board.

Oh! Sockets too expensive for that. :P

Yes, that's how they keep them cheap! :)

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


text:
Arduino Uno R3 stuck in DFU mode/Port not recognized
I have an Arduino Uno R3 that is simultaneously stuck in DFU mode and won't be recognized as a port in the Arduino IDE on my Macbook Pro (El Capitan). Upon receiving power, the Arduino is automatically in DFU mode (I can use dfu-programmer via Terminal to access it, even though the Arduino is not 'recognized'), and by using the process normally reserved for entering DFU mode (connecting the two pins on the left side of the ICSP) the Arduino actually exits DFU mode. However, by neither entering or exiting DFU mode, the Arduino is still not 'recognized' as a port by the Arduino IDE. Prior to this happening, I had been attempting to flash files to the bootloader with success (I got this same predicament in that process previously once, but I do not know what happened differently).
Thanks,
wblegoboy

And have you tried using DFU to reinstall the default CDC/ACM firmware for the ATMega16U2?

I just tried your suggestion, @Majenko, flashed Arduino-usbserial-atmega16u2-Uno-Rev3.hex and it worked beautifully! My DFU mode is now working properly and my Arduino port is now showing after a restart on my Macbook. Thanks!

Great, I'll put it as an answer then.

It sounds like your ATMega16U2 has lost its CDC/ACM firmware and is entering DFU mode by default to allow you to install firmware.
Installing the CDC/ACM firmware using dfu-programmer would get it working again.


text:
How can I make a rotary encoder change between neopixel programs?
I am making a program to use a rotary encoder instead of a button in the buttoncycler example in the Adafruit NeoPixel library.

I am using the US Digital S1-256-250-IE-B-D. Datasheet can be found here: https://cdn.usdigital.com/assets/datasheets/S1_datasheet.pdf?k=636466553771569761
#include < RotaryEncoder.h >
void setup() {
}
void loop() {
  static int change =  0;
  static int pos = 0;
  static int oldPos = 0;
  //Read the Encoder's state
  encoder.tick();
  int enc = encoder.getPosition();
  pos = abs(enc) % 2;
  change = oldPos-pos;
  if (change != 0) {

    switch (pos) {
      case 0:
      //do a program that lasts 5 seconds
      break;
      case 1:
      //do a program that lasts 5 seconds
      break;
    }
    oldPos = pos;
    change = 0;
  }
}

I was wondering if there is a way to change the program immediately after turning the rotary encoder, instead of having to wait for the program to complete.

Sorry @AnotherShrubbery but that's not your code.  Setup() is missing.  i is not defined.

I was wondering if there is a way to change the program immediately
  after turning the rotary encoder, instead of having to wait for the
  program to complete.

There is, but it's not completely trivial. The reason it is not trivial
is each animation is implemented as a function that takes a while to
execute. For doing what you ask, each of these animations should be
modified, with a way to exit early if needed.
One approach would be to manage the rotary encoder using an interrupt. I
let you investigate how to do that: you probably can find examples on
the Web. Once the encoder reading is interrupt-based, you would need to
do the following changes in your program:
At global scope, add
volatile bool stop_now = false;

This will be a sort of “flag” intended to inform the currently running
animation that it should return ASAP.
Then, inside the interrupt handler, add
stop_now = true;

In loop(), just after if (change != 0) {, add
stop_now = false;

In each animation, replace delay(wait) with:
uint32_t start_time = millis();
while (millis() - start_time < wait) {
    if (stop_now)
        return;
}

Your code (if it worked) is right.  All you need to do is turn the comments into function calls:
#include <RotaryEncoder.h>

// Define global variables
int pos = 0;
int oldPos = 0;

void setup() {
// Do stuff
}

void loop() {
  //Read the Encoder's state
  encoder.tick();
  pos = encoder.getPosition();
  const int change = (oldPos - abs(pos)) % 2;
  switch (change)
  {
      case 0:
        programOne();
        break;
      case 1:
        programTwo()
        break;
    }
    oldPos = pos;
  }
}

void programOne()
{
//Do Stuff
}
void programTwo()
{
// Do stuff
}


text:
How to switch on or off up to seven devices individually?
Is there a way to turn on or off the power supply of up to seven hard drives with the help of an Arduino? Or maybe there is another way to ultimately - but restorable - prevent read/write access to the disks.

To turn off a harddisk, you can give it a command to do so. Turning a harddisk off might not lengthen its lifetime, but it will reduce power.

Can't vote to close on the first day, so here is some advice for this question.  Do some quick research on how Arduino can be used to control 5V relays, then write some Arduino code.  Come back and edit this question to show that code and describe how you would put it together, then ask a specific question about Arduino wiring or code.  If you have some relays on hand, then actually put it together.  If there is a problem with the Arduino code then put that in the question very specifically.

Why ? Please explain why do you want to this. What is your goal ? Your question has a typical xy-problem aura hanging around it: http://xyproblem.info/

Switching power on and off to hard drives is not as simple as you may think.
First you have three voltages to control - 3.3V, 5V and 12V, and on top of that you have (ideally) pre-charging for the 5V and 12V pins. The power-on sequence would ideally be:

Power up 5V and 12V pre-charge
Power up 3.3V, 5V and 12V main power

That's 5 poles for one drive (although you can get away without the pre-charge).
So you would be switching at minimum 3 power signals per drive. For 7 drives that would be 21 power signals that need to be switched.
HOWEVER
Switching off power to a hard drive using mechanisms that aren't directly under the control of the operating system can cause file-system corruption and data loss.
The operating system caches data internally and writes it to the hard drive when able to. If the hard drive is turned off while there is still data cached that data will never get written to the hard drive. Worse still, if you turn it off whilst it is writing the file-system could become irrevocably corrupted (depending on the file-system in use and the resilience of it).
Most hard drives have the ability to power themselves down at a command from the operating system. I suggest you use this mechanism instead, since it is more reliable that blindly shutting off the power. Chances are your hard drives are already doing this, since most operating systems enable it by default.

Unmounting the drive will help to prevent data-loss. But I agree with you on the power-on sequence - will it be the same with SSD drives?

Sure, if you're on an OS that supports that. SSD AFAIK only has 5v and 3.3v, however powering those down would be completely pointless since they use next to no power when idle and produce no noise.

drives don't get 3.3v power, only the mobo does. drives use only red+yellow atx leads. the BIOS menu often allows for "power on HD delay", which is what i think you're hinting at in the "power up" notes...

@dandavis You should look at the specs of the SATA power connector. They have an orange wire (3.3V) as well as the red and yellow. True, 5V is (usually) optional, since most drives will regulate their own 3.3V (if needed) from one of the other rails, but the standard is to provide 3.3v.

@Majenko: not sata, that signaling 3.3v drives logic and needs not be switched; if you chop the molex power the drive will power down. use hot swaps...

@dandavis Check pins 1, 2 and 3: https://en.wikipedia.org/wiki/Serial_ATA#Standard_connector Those are power. 3.3 V is supplied along with the traditional 5 V and 12 V supplies. However, very few drives actually use it, so they may be powered from a four-pin Molex connector with an adapter. Few drives use it, but there are some. Not all drives work with an old Molex -> SATA adaptor since that doesn't provide 3.3V.

fair enough. i myself haven't seen such fancy drives. would switching the ground work or smoke?

The problem with switching ground is power likes to find its way through to ground through any other available route. So smoke is a possibility. That is why the SATA power connector staggers its pins so GND is connected before anything else.

An Arduino have 13 digital I/O pins so theoretically you can control 13 devices without any additional additional circuits.
You will probably need some circuits for the devices you want to control.

If you want to control them externally, I suggest buying e.g. an 8 channel relay. This way you can easily control them with the Arduino, and using external power for the devices to switch on/off.
If you want extra protection (especially with motors or expecting spikes on signals), use relays with opto-couplers.

Like that: https://arduino-info.wikispaces.com/ArduinoPower

Note that a typical 3.5" SATA hard drive has 3 power feeds - 12V, 5V and 3.3V, and all three need to be switched together. For 7 hard drives you'd need 21 single-pole relays, or 14 double-pole relays. Ideally you should also pre-charge the drive using the 5V and 12V pre-charge pins which you would provide power to before applying main power. That would raise it to 5 poles per drive, or 35 single-pole relays.


text:
Pause in the program for some time
I have a variable timeInSec which records the time as loop begins. It is defined as timeInSec = millis();. I have two conditions. If (timeInSec - lastRun)< 5 (that is 5 sec) , the first condition is executed(the if statement).Otherwise if (timeInSec - lastRun)>5 the second condition is executed(else statement). Here is the code:
void loop(){
  timeInSec = millis();  // Records time in seconds
  // if(lastRun > 0) {   // if i run this, only else statement is executed
  // delay(10000);
  // }
  if((timeInSec - lastRun) < 5000){  // Treshold time (if condition which runs when timeInSec is less than 5 seconds)
    // Some code
  }
  else{ // If treshold time exceeds (executes when timeInSec is > 5seconds)
   delay(10000);  // if i run this, only else statement is executed
   lastRun = timeInSec;
  }
}

Here the else statement executes once and control goes back if statement again. I want to pause the control at else statement for 10 seconds and then go back to if statement for further execution. Everytime  the control should pause at else statement for 10 seconds. I have used delay in the else statement and in this case only else statement is being executed. The same happens if I use delay at the start of loop (as in code). I have tried without using delay but didn't succeed.
Thanks for the help!

Do not try to change millis(). Instead, record the last time the
second code (else statement) ran, and check whether that was more than
five seconds ago:
void loop() {
    static uint32_t lastRun;
    uint32_t now = millis();
    if (now - lastRun < 5000) {
        // Some code
    }
    else {
        // Some code
        lastRun = now;  // record the time
    }
}

This is essentially the same technique used in the Blink without
delay Arduino
tutorial.

Thanks for the reply. The code works perfect. I have a small doubt here. If I keep a delay at the start of else code say delay(2000); , only the else statement runs continuously instead of going to if statement. If I remove the delay in else, the code works perfect. Please tell me the reason. I need the compiler to stop in else statement (after execution) for 2 seconds and then go to if statement. I have used the delay in else statement but it didn't work. To achieve the same I have typed if(lastRun>0){delay(2000);} ,but it didn't work.

@SriHarsha: Do not use the comments to ask new questions. You can either write a new question or, if you believe this really belongs to the same question, edit that question.

@edgar-Thanks for the suggestion. I have edited the question.

TLDR; try else{ delay(2000); lastRun = millis(); } instead. Using the now variable after a delay, will result in using the old time.

@Gerben-Thanks for the reply. It works perfect.


text:
Arduino nano to esp8266 level shifting needed?
I want to connect an Esp8266 Wifi module to an Arduino nano. I am wondering if I need to implement level-shifting for the Arduino TX line to Esp RX line?
I find different schema's on the net. Some with, some without level-shifting:
With:
http://community.blynk.cc/t/robot-with-esp8266-shield-and-arduino-nano/3316/8
Without:
Arduino Nano v3.0 with ESP8266
Some use a capacitor between GND and Esp CH_PD pin, others use a 10K resister between the 3.3V and the CH_PD pin (https://blogs.msdn.microsoft.com/abhinaba/2016/01/23/esp8266-wifi-with-arduino-uno-and-nano/)...
What is the most basic but required setup for a Arduino Nano and a Esp8266?
(I have Esp8266-12e modules)
Thanks!

You might also consider if one of the implementations of the ESP8266 with more I/Os could host your software under the available Arduino port, removing the need for the nano entirely.

@ChrisStratton do you have a link to such ESP8266 module?

There are many available, probably including whatever one your are running now, unless it is especially short on memory.  This is basically a software solution, not a hardware one.

The arduino nano v3's logic is 5v, and the ESP8266's logic is 3.3V, so you need to do level shifting between both.
Using a voltage divider drains more current (guess not an issue in this case) and it's ok only when going from 5V to 3.3V (when the signal must be shifted from 3.3V to 5V in the links you provide, it looks like it's based on that 3.3V is still considered "HIGH" on a TTL signal).
I personally prefer using a level shifter, it just complicates a bit the Bill Of Materials, but you won't have to debug the level shifting part.
And better than that, using an arduino mini pro @3.3v working directly at 3.3V gets rid of this hassle.

Shouldn't arduino nano 3.3v be arduino nano v3?

arduino nano v3 refers to the version of the architecture. afaik there's no arduino nano working at 3.3v. it must be an arduino mini

You could use a simple diode, between the Arduino TX and ESP RX. That's what the Adafruit Huzzah uses.
It takes advantage of the internal pull-up on the RX pin of the ESP. The diode will allow a LOW, to pull the signal low, through the diode. But it will block a HIGH 5 Volt signal from going into the ESP.

Yes, but for signals going in the other direction you have to also do something similarly, or hope that the pin the Arduino is receiving on never accidentally gets configured as an output instead and driven high.

Well, that goes for a lot of thing. The same could be said for the MISO pin on an SPI device connected to an Arduino. I've seen any protection on SPI lines, except maybe a resistor.

@ChrisStratton I dont get what you mean. One would assume that Arduino's RX pin is already configured as an input in firmware, when its used for serial comms. The risk here is no more than the usual when you connect the serial pins of 2 5V devices together.

It might boot up that way, but all it takes is mistakenly making that pin an output (perhaps while trying to make another pin one) to damage the ESP8266.  In the Arduino world, mistakes (especially purely software ones) should be considered normal, so it is unfortunate if one can cause damage.  And yes, it is even more a risk with SPI where the MISO pin is even more likely to be used for a different purpose in code that might be loaded with insufficient thought.  There's a difference between a cost-optimized solution, and an experimenter-friendly one.


text:
How can I get ultra clean dc wall power for my arduino project?
I'm doing an rfid project that requires a read range of at least 5 inches or about 13cm.  I'm using a nano with a usb port, a rfid reader from priority 1 design and a large antenna. The problem I'm running in to is that when I power the project from the usb port I get a pretty decent read range of 11-13cm. But when I power the project from a DC power supply the read range drops considerably.
After a lot of testing with various power supplies I believe that all my power adaptors are dirty enough to cause rf interference and reduce the range.  Powering the project with a 9v battery and a 5v power regulator gives me really good range: 18cm with the largest antenna.  But I need plug in power.
So how can I power this project in a way that gives me ultra clean power?

I tried that same 5v regulator with a 5v adaptor and still had short read range.
Someone suggested adding a smoothing capacitor between V+ and Gnd but I wouldn't know what size.  I'm not an EE - I'm just a coder with a soldering iron.
Is there a better power supply I can get?

[EDIT] Also just FYI, when I connect even only the ground wire the the computers USB port I get a much farther read range. So..

Could it be a case of needing to ground the circut better as the switching power supplies only have 2 prongs and probably no real "ground". (Or am I making stuff up?)

[EDIT 2] What about a rechargable situation where my wall adaptor keeps a litium charged and the litium supplies clean power to the circuit?
Also I now know that I can charge my whole circuit with anything from 5 to 12 volts. In fact it would be better to have more in the 7 to 12 range than strictly 5v.
[UPDATE 3] Since this project is in my wall I was able to ground essentially to "earth" and that cleared up the noise. See this question as well: https://electronics.stackexchange.com/questions/230024/grounding-dc-project-to-clean-rf-noise

You can't use a 5V regulator with a 5V adaptor.. You can experiment with 1) a USB wall adapter 2) a >7V wall adapter and a linear 5V regulator (e.g. 7805, with the two 100nF capacitors) 3) a >6V wall adapter and a switching step-down regulator, set to 5V 4) any wall adapter (maybe >3V) and a switching buck-boost regulator. I think that with the USB wall adapter you will already solve your problems, then I'd test a switching regulator (step downs are better, I think) and the last choice is a linear regulator. you can find switching regulator modules for a few dollars on ebay, if you need them

I did experiment with the USB wall adaptor and got the same short read ranges.
This is the regulator that I have today: http://www.robotshop.com/en/pololu-step-down-voltage-regulator-d15v35f5s3.html
I just tried that one with a 12v power supply and it won't read at all.
And the only thing I'm changing in these experiments is the power source.
I ordered this one which will be here tomorrow: http://www.amazon.com/SMAKN®-LM7805-3-Terminal-Voltage-Stabilizer/dp/B00RKY0NP6?ie=UTF8&psc=1&redirect=true&ref_=oh_aui_detailpage_o00_s00

Strange.. No reads at all? Did you check the ouitput voltage with a multimeter? Anyway your "new" board is a linear regulator, so use a 7V+ voltage source (12V should be fine) and be aware that you won't be able to draw much current from it..

Yeah it essentially dropped the read range to nothing. Too much rf interference I suspect. Of course it's hard to tell what's happening when I can't see a console output. I do have it blinking out some return values as a type of "morse code".  So I can tell that it's taking to the rfid reader and read that the measured antenna frequency is near 125khz.

@frarugi87 The new stabilizer didn't help. I also realized that I can power the whole thing (arduino and rfid reader) from 9-12v. With a 9v battery my range is optimal. With a 12v switched power adaptor direct I get very short range. If I then connect the ground of my circuit to the ground wire at the wall my range goes up again to closer to the 9v battery range (about 1-2cm shorter).  I want to try the 2 100nF caps but where do I put them?  In series between vcc and gnd?  Or in parallel? Can you write this up as an answer?

Actually I think in my circuit I'll just be connecting to real ground.

The two 100nF capacitors should be put one between 12V and ground and the other between 5V and ground. But.. Well, they should be already present in the circuit you bought. If adding them does not solve, try adding a big (e.g 1MOhm) resistor between ground and your earth plug at the wall instead of directly connecting them

This is what I use, although admittedly not in your application. I run it from a 12V wall adaptor and adjust the output voltage to suit my requirements. The input should ideally be at least a couple of volts above the output(depends on current and temperature at 25degC and 20mA it's > 1.6V and 1.5A at the same temp it's > 2.7V).

Another alternative if you want to really go to town would be to repurpose an old computer ATX or similar PSU. There are plenty of guides out there and it's a straightforward job.

Please specify that the input voltage should be at least X volts, where X is 5V + the dropout voltage of the LM317 (I don't remember how much it was)

My issue appears to be RF noise coming from the 12v power supply is messing up the RFID application. Something in the power supply is noisy enough that it makes the RFID not read at all.  Where as when I use a 9v power supply everything works golden.  What I'm looking for is a solution that will give me ultra clean power in the 5.5v -12v range without having to swap out 9v batteries every few months.  Even if it were a rechargable situation where the 12v wall supply charged a litium that then gave clean power to my circuit.

I think the problem is not the voltage but the magnetic field, so maybe better to use a faraday cage (a metal box) around the power supply and connect it to output DC ground.

Grounding it to actual ground cleaned up the power.


text:
Multiplying Arrays
I have an issuing multiplying two one dimension arrays together. Each array is an unsigned long that is storing values of factorials. The last row is completely off. My code is below also with a screenshot of the output.
void setup() {
//----------------------------- start serial monitor
Serial.begin(9600);

Serial.println("Factorial Table");
//----------------------------- declare variables
unsigned long fact = 1;
unsigned long r[5];
unsigned long c[5];
unsigned long product[6][6];
//----------------------------- load facotirals into array(s)
for (unsigned long d = 1; d <= 5; d++)
{
    fact = fact * d;
    r[d] = fact;
    c[d] = fact;
}
//----------------------------- multiply factorials
//                              and load into new array

for (int row = 1; row <= 5; row++)
{
    for (int col = 1; col <= 5; col++)
    {
        product[row][col] = r[row] * c[col];
    }
}

//----------------------------- print factorials

for (int prow = 1; prow <= 5; prow++)
{
    for (int pcol = 1; pcol <= 5; pcol++)
    {
        Serial.print(product[prow][pcol]);
        Serial.print(" ");
    }

    Serial.println(" ");
}

}

In C and its progeny, array indices start at 0. unsigned long r[5] declares an array of five longs; the array elements are r[0] through r[4]. Your loop, however, varies the array index from 1 though 5. r[5] is accessing whatever happens to lie in memory beyond r[4]
Here is a much better version of your code. Note, among other things, the coding style. Remember that you write programs for other humans to read!
const int kSize = 5;
void setup() {
  unsigned long r[kSize];
  unsigned long product[kSize][kSize];
  unsigned long fact = 1;
  for (int d = 0; d < 5; ++d) {
    fact *= d + 1;
    r[d] = fact;
  }
  for (int row = 0; row < 5; ++row) {
    for (int col = 0; col < 5; ++col) {
      product[row][col] = r[row] * r[col];
    }
  }

  Serial.begin(9600);
  Serial.println("Factorial Table");
  for (int row = 0; row < 5; ++row) {
    for (int col = 0; col < 5; ++col) {
      Serial.print(product[row][col]);
    }
    Serial.println();
  }
}

See the difference? Style points to note:

no unnecessary comments. In fact, the code is readable enough that no comments are necessary.
No unnecessary space.
The array size is used in several places; it's better to define it as a constant. There is also no reason to specify anything other than int; a good optimizer will detect that you are never using values of more than 5, and will optimize the code accordingly.
You don't really need two separate arrays, since they have the same values.
You obviously don't need to first store and then print, but I assume you are doing this to learn.
I didn't initialize the Serial port and didn't print the header until i was ready to print. Group logically-related statements together. (OTOH, you might have been thinking that at some point you might want to insert print statements before there, so putting Serial.begin first thing in your code might have been better.

While there are lots of styles around, https://google.github.io/styleguide/cppguide.html is good enough for Google, so it's good enough for me :)
Here is a better way to initialize the array of factorials:
  r[0] = 1;
  for (int d = 1; d < kSize; ++d) {
    r[d] = r[d - 1] * (d + 1);
  }

Thank you for the help on the code. You made good suggestions. I didnt know I could use the same array for multiplying. Also I used an unsigned long in one of the for loops because I was getting weird numbers when calculating the factorials. The code you presented was very neat. Thank you also for the style guide link.


text:
Arduino: put string through variable in array
I have a problem and I can't fix it.
I'm busy with an java to arduino project.
Java writes a string using writeString();
Arduino reads the serial monitor and put the incoming string into a function.
then I want to put the string into a variable and the variable into a char arr[];
The problem is: When I put the string directly in the arr[]; it works, but when I put first the incoming string in a variable and then the variable in the arr[]; it gives me the next error:

string-parser:44: error: array must be initialized with a brace-enclosed initializer
exit status 1
initializer fails to determine size of 'arr'

this is the code that doesnt work:
input = "2,5>2,6>2,7>4,8";

String splitStringIntoCoordinates(String input){
  char arr[] = input; // Place incoming route in char array
}

This is the code that does work:
String splitStringIntoCoordinates(String input){
  char arr[] = "2,5>2,6>2,7>4,8"; // Place incoming route in char array
}

I hope anyone can help me.
Thanks!

A String isn't a char array. You can't assign one to the other.
You shouldn't be using String, it's too heavyweight, and how you are passing your String object is wrong, it wastes huge amounts of memory making clones.
You should read this.
The only time you should ever consider using a String object is if you are using a third party library that requires a String object - and even then you should consider other methods.
Regardless of that, you need to copy the content of your string, not the string itself.  This code should work, but it doesn't address the underlying String issues:
String splitStringIntoCoordinates(String &input){
  char arr[input.length() + 1]; // Create a char array big enough including the terminating NULL
  strcpy(arr, input.c_str()); // Place incoming route in char array
  // ... etc ...
  // return a string
}

If you just want to reference the String as a C string you can just use the function input.c_str() to get the internal char * array pointer.

Thank you majenko! This worked for me. I never tought of that.


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

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

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

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

Unfortunately, the link appears to have died.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

See also Grove connector.

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

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

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

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

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

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

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


text:
bitClear doesn't work on most significant bit
I'm currently working on a project where I read a 32 bit sequence.
The digitalPin is always HIGH when no sequence is received and starts oscilating with about 1kHz when the sequence starts (RC5).
I am setting and clearing bits of an uint32_t depending on which signal is on the digitalPin.
It seems to work very well with every bit except of the MSB.
Here a short code snippet to show what I mean:
const short irPin = 8;
const short msgDelay = 250;

uint32_t data = 0xFFFFFFFF;
long msgArrived = 0;

void setup(){
  Serial.begin(115200);
  pinMode(irPin, INPUT);
}

void loop(){
  long now = millis();

  if( (!(PINB & 1)) && ((now - msgArrived)> msgDelay)){
    msgArrived = millis();
    bitClear(data, 31);

    Serial.println(data, BIN);
  }
}

This gives me an output of
11111111111111111111111111111111

I have already tried
bitClear(data, 32); -> 11111111111111111111111111111111
bitClear(data, 30); -> 10111111111111111111111111111111

So every output is right, but not the when I try to clear the msb.
Has anyone experienced a similar behaviour?

bitClear(data, 31);  should be the msb of the uint32_t. bitClear() goes from 0 - sizeof(uint32_t)-1. And with bitClear(data, 32); I only tried if the documentation lied to me.

sorry missed a part of code on first comment, does it work if you make it "manually" with data &= ~(0x1 << 31) ?

yes this works, but look at the answer by BrettAM. I missed out, that println() doesn't print leading zeros.

uint32_t data = 0xFFFFFFFF;
Serial.println(data, BIN);
data = 0xFFFFFFFF;
bitClear(data, 30);
Serial.println(data, BIN);
data = 0xFFFFFFFF;
bitClear(data, 31);
Serial.println(data, BIN);

On my mega outputs:
11111111111111111111111111111111
10111111111111111111111111111111
1111111111111111111111111111111

Are you sure you aren't mistaking the fact that println doesn't print leading 0's for the number being nothing but 1's? Try printing as hex, then all the numbers will be the same width:
FFFFFFFF
BFFFFFFF
7FFFFFFF

I fact i actually did miss out the fact, that println doesn't print leading zeros. Thanks. Would +1, but I am missing reputation for that.


text:
Operating two functions simultaneously
I have connected a bluetooth module(HC-06) and a voice recognition shield(EasyVR) on an arduino UNO.
By using an another HC-06 on the another arduino(so, 2 arduinos and 2 HC-06 totally), I am going to let two arduionos communicate with each other.
Also, simultaneously, one arduino with HC-06 will recogize the voice by using the voice recognition module.
I have successed each operations, but after combining two codes the bluetooth doesn't work...
(Voice recognition have successed.)

Is it unable to operate two operations simultaneously?

Can we use these two sentences in one code?
SoftwareSerial BT(2,3);     --> for bluetooth module
SoftwareSerial Port(12,13);   --> for voice recognition module

Is it unable to operate two operations simultaneously?

The only way you can do two operations simultaneously is to have two Arduinos. An Arduino can only do one thing at a time. In order to make it seem like it's doing things at once you have to create your sketch accordingly. The use of delay() is right out. As are long loops using things like while(). In short: anything that blocks is bad.

Can we use these two sentences in one code?

Not reliably, no.  They are both resource hungry and, to a large extent, blocking. A general rule is, if you need at least two more UARTs than the board provides then you need a different board. You can only reliably work with one software UART at a time.
I would suggest upgrading to a more capable board with more hardware UARTs. Either that or use a bluetooth system that doesn't use UART, such as an SPI based BLE module.

Physically It is impossible to run 2 things at the same time when you have one microcontroller. "The Arduino is a very simple processor with no operating system and can only run one program at a time". But I am pretty sure that the solution you are trying to find, hides in multitasking or interuption. There are some cones in delay() function: "The problem is that delay() is a "busy wait" that monopolizes the processor. " But in multitasking, you share clock of the processor between two different pieces. You can find more about running different things simultanously here.
I have used miles() in one of my projects where were coin validator which was outputing impulses and screen which was showing chash inside it.


text:
AT response clean-up
I am trying to get the response from server using AT commands. This is my program
#include <SoftwareSerial.h>

const byte rxPin = 2; // Wire this to Tx Pin of ESP8266
const byte txPin = 3; // Wire this to Rx Pin of ESP8266

// We'll use a software serial interface to connect to ESP8266
SoftwareSerial ESP8266 (rxPin, txPin);

void setup() {
  Serial.begin(115200);
  ESP8266.begin(115200); // Change this to the baudrate used by ESP8266
  delay(1000); // Let the module self-initialize
}

void loop() {
  Serial.println("Sending an AT command...");
  ESP8266.println("AT+CIPMUX=1");
  delay(3000);

  ESP8266.println("AT+CIPSTART=0,\"TCP\",\"192.168.50.1\",1234");
  delay(3000);

  while (ESP8266.available()){
     String res = ESP8266.readStringUntil('\t');
     Serial.println(res);
  }

}

My server is just sending just one string as the output.
My console is getting this kind of output? Is there a way to clean this?
Sending an AT command...
AZi%PSՊj
C⸮j⸮L⸮AT+CIPSTART<0,"TCP","193.168.50.1",1234
0,CONNECT

OK
+IPD,0,1:10,CLOSDD

Sending an AT command...

I read thread and changed SoftwareSerial.h file. But still no luck.
Thanks in advance.

why do you not use a library? WiFiEsp for example?

You can't use SoftwareSerial reliably at 115200 baud.

@Majenko Yes, I tested even for 9600

@Juraj can you given me an example? I had been looking for this days.

https://github.com/bportaluri/WiFiEsp


text:
Relay with mechanical fallback
In my circuit I have a relay that will turn on some light bulbs this is my circuit:

The switch over the 5V is in fact my Arduino. A HIGH will turn on the relay and a LOW will turn it off.
This is working fine, but because of security measures I need to add a mechanical switch to be able to turn on and off whenever needed. This is the circuit I'm using for this configuration:

This circuit also works fine, the lamp is turned on and off by changing either switches but the Arduino loses track of the status of the lamp. The only thing it knows is if the relay is on or off.
Is there a simple way to tell when the lamp is on?

Maybe you should replace your ON/OFF switch with a three way switch: ON/OFF/AUTO, where AUTO means Arduino-controlled.

@EdgarBonet I’m sorry, how? I’m mixing AC and DC and I’m not seeing how can I do that

Slap a current transformer over the AC line?

Is it enough to add an input to the arduino to override the programming? Or does it really need to be an electrical override?

@ratchetfreak what do you mean by "override the programming"? I just want a safe way to check if the lamp is on. I'm open to any suggestion that will keep the arduino and the switch working together

Connect the mechanical switch to an Arduino input pin. Then in you code, turn on the relay if the switch is turned on (or your other condition is met).

Searching "ac line monitor optocoupler" showed some interesting results, though I have no experience with these devices. Alternatively any way to monitor the second switch (maybe use double pole) may work as well.

If you add an optical sensor appropriate for the lamp (UV, IR, visible light?) and add a test line to your code, the Arduino would "know" if the light is on. Your second circuit could remain as presented, while the sensor would provide a status of the light.
If the light failed for an unknown reason, the code for your Arduino would not know the difference between that and a manually opened override switch.

This should work. But I’m not inclined to use this solution. I’m placing one Arduino (esp8266) per room. Meaning each board will have at least: 1 temperature sensor, 1 humidity sensor and 1 output for the relay. Adding another component to the board would be a little difficult. I would prefer a logic circuit over this solution.

I got the terminology wrong in my comment. My suggestion is not to use
what is commonly called a “three way switch”, but instead a single pole
triple throw
switch. This is
not available in the schematic editor, so I had to improvise. Imagine
that the switch labeled “SP3T” below has three contacts on its left
side:

simulate this circuit – Schematic created using CircuitLab

The top contact connects to nothing: this is the OFF position
the middle contact connects the controlled circuit with the relay:
this is the AUTO position where the Arduino is in charge
the bottom contact closes the controlled circuit: this is the ON
position

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


text:
3.3v pin on a 5v Pro Micro?
I have a arduino pro micro that runs on 5v.
I also have a Max4466 that needs 3.3v, however the pro micro doesn't seem to have a 3.3v VCC.
Is there any way to attach the max4466 to the Board?

You need to add an external 3.3V voltage regulator. You can get these quite cheap on eBay (etc) as a module - some even come in a breadboard friendly format.
Power it from the 5V from the Arduino, then power your MAX4466.
However, the MAX4466 can run at up to 5.5V, so I fail to see why you think you need 3.3V.

Thanks for giving a solution, so upvoted. The solution is missing from the link of my deleted answer. For completeness, I repeat your mentioned link here: https://majenko.co.uk/blog/why-you-cant-use-resistors-voltage-regulator


text:
Do I need the Ground and 5 V pin connect to Led?
I am building an ambilight. So I bought a 3 pin LED Strip which I power with the USB hub from my TV. Next step is to connect it to the Arduino Nano. Is it OK when I only use the dataport from the Aduino and the power only from the television?

I think it is not a good idea to power the LED strip via USB.
Normally USB delivers a maximum of mA  (see below). Assuming you have 30 LEDs (minimum for a normal LED strip), and each LED gives 40 mA (maximum), this is already more than what most USB ports can deliver. This can ruin your USB port.
For the Arduino Nano you can use the 5 V, and you should connect all GNDs together.
But you will need a decent adapter anyway for the LED strip, so than you can power your Arduino Nano from the adapter you use for the LED strip.
Update
According to Wikipedia USB power

Low-power devices (such as a typical USB keyboard) may draw at most 1
  unit load (1 unit load is 100 mA for USB devices up to USB 2.0, while
  USB 3.0 defines a unit load as 150 mA), and all devices must act as
  Low-power devices when starting out as unconfigured.
High-power devices (such as a typical 2.5-inch USB Hard Drive) draw at least 1 unit load and at most 5 unit loads (500 mA) for
  devices up to USB 2.0 or 6 unit loads (900 mA) for SuperSpeed devices.

I am totaly new to this but the lightstrip got a 5v connection it is a WS2812B strip with 300 leds. I use a 3.0 usb port but an old cable witch i got long before 3.0 was out does this made any differnce?

To be honest, I don't have much experience with current from USB, but 300 LEDs * 40 mA = 12 A, 12 A * 5 V = 60 W. Of course you can software wise make sure not all LEDs are on at maximum current at the same time, but this is not so safe (in case of a programming error).

Your TV certainly cannot power a strip this long. You will blow your USB port with this (at least). Keep in mind, that even most high power USB charger will only give you a few amps. You have to buy a 5V power source, that can actually handle this current. Also you should provide the power to both sides of the strip (Start and end of the strip) to avoid it getting too hot.

simulate this circuit – Schematic created using CircuitLab
Can you follow this? Connect all GNDs. TV 5V can power the Arduino, connect to the 5V/VCC pin and not the Vin pin.  5V power supply only powers the LED strip.  No reason it couldn't power the Arduino as well tho, in which case there would be no need to connect to connect anything to the TV.
PC USB ports typically can only supply 500mA, only enough for 8 RGB LEDs at full white. I doubt your TV can do much more.

Yes, you can take +5v from the TV's USB and supply data from the Arduino, as long as you connect both the TV's USB-Ground and the Arduino-Ground together.


text:
Difference between Ultrasonic sensor and Distance Sensor?
What is the difference between an Ultrasonic Sensor and a Distance Sensor?

An ultrasonic sensor is one type of distance sensor.

What's the difference between a Ford and a Car...?

An ultrasonic sensor can usually develop and receive high frequency sound waves.  They can be used to measure distance by measuring the time of flight of the sound wave.
distance(meters)  = [speed_of_sound(meters/second)][1] x time_of_flight(seconds)
distance(meters) = 343(meters/second) x time_of_flight(seconds)

For example, say the time of flight was 0.01 seconds.
distance(meters) = 343(meters/second) x 0.01(seconds)
distance = 3.43 meters

This is just one way distance can be measured by a processor.  Other ways use different types of radiation such as electromagnetic radio and light radiation.  Some of these use time of flight. Others use more exotic phase techniques.  These types of detectors can be very accurate over long distances.  But are usually very costly.  They are commonly used for automated car driving.
A completely different approach uses triangulation or parallax of a light beam and a focused linear array light sensor.

These types of detectors normally operate over short distances and are cheap to make.  They are commonly used in places like copier machine to detect objects and paper.  Or in automated vacuums cleaners to detect floor edges such as stair drop offs.

A proximity sensor is a sensor able to detect the presence of nearby objects without any physical contact, see article proximity sensor.
In that article a lot of types are mentioned and ultrasonic sensors are one of them, so an ultrasonic is one of the types of distance sensors.
Types (copied from the above article):

Capacitive
Capacitive displacement sensor
Doppler effect (sensor based on effect)
Eddy-current
Inductive
Magnetic, including magnetic proximity fuse
Optical

Photocell (reflective)
Laser rangefinder
Passive (such as charge-coupled devices)
Passive thermal infrared

Radar
Reflection of ionising radiation
Sonar (typically active or passive)
Ultrasonic sensor (sonar which runs in air)
Fiber optics sensor
Hall effect sensor

You wrote: “A distance (or proximity) sensor uses a beam of electromagnetic radiation”. Not all of them do, and specifically, an ultrasonic sensor doesn't.

I edit my answer, thanks for the improvement.


text:
writting to buffer from serial input
Can some one explain this behaviour please, i have the following code
  byte buffer[512];
  byte block;
  byte len;

  Serial.setTimeout(60000L) ;     // wait until 20 seconds for input from serial
  // Ask personal data: Family name
  Serial.println(F("Type text followed by #"));
  len = Serial.readBytesUntil('#', (char *) buffer, 500) ; // read from serial
  Serial.print(len);
  for (byte i = len; i < 250; i++) buffer[i] = '#';     // pad with #
  Serial.print(len);

This works but if i change the "for" line to any thing higer then 250 it stops working and there is a "buffer out of memory condition)
My question is why can't the for loop say the below as the buffer size is 512?
for (byte i = len; i < 512; i++) buffer[i] = '#';

Am i right in thinking it has something to do with  (Char *), i did copy this code from the example ardunio code and was jsut trying to incress the lenth of input it accpeted.

A byte can only contain values from 0 to 255 (including).
So my guess it works for values until 255.
You should use a different type, e.g. unsigned int or unsigned short.
for (unsigned short i = len; i < 250; i++) buffer[i] = '#';     // pad with #

Also, I advise to use a constant or define for the buffer size, now you have 3 values (512, 500 and 250 in the loop, I assume they should be based on the same value).
About the char*: Looking at StreamReadBytesUntil, it seems that the parameter wants a char* instead of a byte* (which is more or less the same), but it's better to cast to show the parameter is of type char* since that is high likely the exact type (but the official Arduino documentation does not show the parameter types sadly).

I agree use same constant, it was original but i was playing about when i tried to go over 250. the fact is broke at 254 should have told me this.

No problem, btw, I opt to close this questions since it's not related to Arduino, but you can continue coding, good luck.

you could  also explain why (char *) is used in this code, is that there to insure it write to the begining of the buffer. why cant you jsut use "buffer" or is there a particaul advantage of doing it this way?

I added a note about it.

for len is byte small too

That make sence, thank you for takeing the time out to help.

@See Juraj's remark ... btw, unless you know beforehand you might run into memory problems, always use int or unsigned int. Or if you want to do it better, create a specific type for it: typedef unsigned short buffer_length

Brillent all and it addresses some other problems in the code block i was writing the example used "byte" a lot. something for me to remember when hacking other peoples examples. check the sizes fit ::)

Personally I like to use types as int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t and bool ... some of them are predefined, some are not. But this way I always know exactly what ranges I can use. When a range could change in the future, I use a typedef and give if a specific name, like I said above (typedef uint16_t buffer_size). That saves a lot of type replacement when changed.

I seem to remember problems using unsigned as types for loop indexes. Someone please correct me if I’m wrong.

@RubberDuck Yes, for example, if you count down, you cannot check for >= 0, because an unsigned value always is >= 0, but for counting up (until value 254 max) an unsigned byte can be used.

Ahh. Yes. I made this mistake before. https://stackoverflow.com/a/9044067/3198973

@RubberDuck Yes ... sadly most compiler do not give a warning.


text:
Error in code (define a function)
I try to use this code, but it shows that I need to define again the last void turn_mer (int direction) function. How can I fix this?
#include <Servo.h> //create servo object to control a servo.
Servo myservo;

//pin configuration.
const byte servoPin = 2; const byte motorLeft = 5; const byte motorRight = 6;
const byte echoPin = 12; const byte trigPin = 13; const byte echoPin2 = 8; const byte trigPin2 = 9; // LET OP DE HOOFDLETTERS: echopin en echoPin
//delay determines how long the MER turns, increase to make the turning angle larger.
const int turnDelay = 500;
//standard angle for looking straight ahead, compensate for construction errors.
const int standardAngle = 90;
//angle in degrees that controls the direction in which the sensor looks.
const int viewAngle = 40;
//delay to let servo turn, not optimized; for smaller angles smaller delay could be used.
const int servoDelay = 250;
//object distance in cm at which the MER decides to look around and turn another way.
const int lineOfSight = 40;
//pwm duty cycle of the motor, use a value from 0 (no movement) to 255 (full speed).
const int motorSpeed = 90;

//const int lineDownSight = 35;
void setup() //setup pin configuration and initialize the sensor position.

{ delay(3000); //delay to give us some time to place the MER on the ground.
  myservo.attach(servoPin); //initialize the servo and look straight ahead.
  turn_servo(standardAngle);
  pinMode(motorLeft, OUTPUT); pinMode(motorRight, OUTPUT);
  pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); drive_mer();
} //start the mer.
void drive_mer() //this function lets the MER drive forward.
{
  analogWrite(motorLeft, motorSpeed);
  analogWrite(motorRight, motorSpeed);
}
void stop_mer() //this function stops the mer.
{
  digitalWrite(motorLeft, LOW);
  digitalWrite(motorRight, LOW);
}
void turn_servo(int angle)
//turn servo to given angle, do not return until angle is reached.
//if the servo is already at the correct angle, we don't have to do anything.
{ if (angle == myservo.read()) {
    return;
  }
  else {
    myservo.write(angle);
    delay(servoDelay);
  }
}

int look1() //looking function, returns distance in the observed direction as an integer.
{ int duration, distance;
  digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) / 29.1; return distance;
}
//turning function: makes MER turn in preferred direction. 0 for left and 1 for right.
void turn_mer(int direction)

{ if (direction == 0) {
    digitalWrite(motorLeft, LOW);
    digitalWrite(motorRight, HIGH);
  }
  else {
    digitalWrite(motorLeft, HIGH);
    digitalWrite(motorRight, LOW);
  }
  delay(turnDelay); stop_mer();
}//stop the engines when the MER has turned far enough.

//this function turns the MER depending on the observed distances.
void handle_measurements(int distanceLeft, int distanceStraight, int distanceRight)// int distanceDown

{ if (distanceLeft < lineOfSight and distanceStraight < lineOfSight and
      distanceRight < lineOfSight) {
    stop_mer();
  }

  else if (distanceLeft < lineOfSight) {
    turn_mer(1);
    drive_mer();
  }

  else if (distanceStraight < lineOfSight) {
    if (distanceRight > distanceLeft)
    {
      turn_mer(1);
    } else {
      turn_mer(0);
    } drive_mer();
  }

  else if (distanceRight < lineOfSight) {
    turn_mer(0);
    drive_mer();
  }
 //if (distanceDown > lineDownSight) {
  //  stop_mer();
  }

  void loop()
  { int distanceLeft, distanceStraight, distanceRight;

    turn_servo(standardAngle + viewAngle); distanceLeft = look1();
    turn_servo(standardAngle); distanceStraight = look1();
    turn_servo(standardAngle - viewAngle); distanceRight = look1();
       handle_measurements(distanceLeft, distanceStraight, distanceRight);}

/*  void handle_measurements(lineDownSight)
   {(distanceDown > lineDownSight) {
    stop_mer();
  }*/
  //                                                                                sensor 2
  //______________________________________________________________________________________________________________________________________________________________________________________________________

 const int lineDownSight = 35;

  void handle_measurements (int distanceDown)

{if (distanceDown > lineDownSight) {
    stop_mer();}}

  int look2() //looking function, returns distance in the observed direction as an integer.
  { int duration, distance;
    digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH);
    delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH);
    distance = (duration / 2) / 29.1; return distance;
  }
  //turning function: makes MER turn in preferred direction. 0 for left and 1 for right.
void turn_mer (int direction)

{handle_measurements(distanceDown)}

Next time write in English not Dutch (I translated it now for you), use ctrl-K for aligning code (I did now), and add the error, please add it yourself.

But the main problem is that in C, you can only define a function with the same name once.
Halfway you defined the function turn_mer already, and again at the end.
Also, you are missing an end colon in:
{handle_measurements(distanceDown)}

It's better to align your code like:
{
    handle_measurements(distanceDown);
}


text:
Arduino Mega and ADS1256 board
I found code for a Teensy board and now I added just digitalwriteFast library to code and changed port to SPI for Arduino Mega. And now I get just one number out:
#include <SPI.h>
#include <digitalWriteFast.h>

//(other stuff for getting the ADS1526 to work is in the next tab
#define ADS_RST_PIN    48 //ADS1256 reset pin
#define ADS_RDY_PIN    47 //ADS1256 data ready
#define ADS_CS_PIN    46 //ADS1256 chip select

/*
CLK  - pin 52
DIN  - pin 50 (MOSI)
DOUT - pin 51 (MISO)
*/

//put the ADC constants here

double resolution = 8388608.; //2^23-1

//this needs to match the setting in the ADC init function in the library tab
double Gain = 64.; //be sure to have a period

double vRef = 5.0; //reference voltage

//we'll calculate this in setup
double bitToVolt = 0.;

void setup() {
 delay(1000);
 Serial.begin(115200);
 Serial.println("booting");
 //initialize the ADS
 pinMode(ADS_CS_PIN, OUTPUT);

 pinMode(ADS_RDY_PIN, INPUT);
 pinMode(ADS_RST_PIN, OUTPUT);

 SPI.begin();

 initADS();
 Serial.println("done init");

 //determine the conversion factor
    //do some calculations for the constants
 bitToVolt = resolution*Gain/vRef;
}

int32_t val1;
int32_t val2;
int32_t val3;

void loop() {
  // put your main code here, to run repeatedly:

double value = 0;
for (int i = 0; i <1; i++){
 read_three_values();
 value += val1;
}

value /=1.;

 Serial.print(value,8);
 Serial.print("\t");
 Serial.print(val2);
 Serial.print("\t");
 Serial.println(val3);

//
//double value = 0;
//for (int i = 0; i <10; i++){
//  value += read_Value();
//}
//
//value /= 10.;
//value /= bitToVolt;
//
//Serial.println(value,11);
}

I don't know where to connect PDWN pin?
And I have this board:
https://www.ebay.com/itm/NEW-1PC-ADS1256-high-precision-ADC-module-conversion-24-bit-eight-channel/292541380872?hash=item441cd33908:g:uYUAAOSwLpda5BIZ:rk:1:pf:0
Greetings Matej

Please show us a working sketch. The sync/pdwn can be connected to 3.3v or also to 5v since it is 5v tolerant. It is in the datasheet. The spi bus is 5v tolerant but the data out (MISO on the arduino board) signal is only 3.3v. It will probably work, but a 3.3v arduino board is better. At ebay they say that also a dac8532 is on the board, but I can't see that in the photos. I can only see a ads1256 and a 2.5v voltage reference and a voltage regualator. It is a very nice and very cheap module, but without schematic you have to guess how to connect it.

no schematic came with it.

i use this code link is here https://github.com/mbilsky/TeensyADS1256

That code uses an interrupt for the ADS_RDY_PIN, but the arduino mega 2560 does not have an interrupt at pin 47. There is also no digitalPinToInterrupt() for the interrupt pin (the arduino mega 2560 needs that, the teensy does not). You can fix that, but I suggest to find a more basic simple library for the ads1256. You need to make it work in a basic way before trying a library that is optimized for speed.

Ok but will i reach 30000SPS with other library


text:
2 Direction Motor
Using an  Arduino-Nano, I'm trying to make a circuit that will change the direction of a motor based on two inputs. The input from the Arduino will be amplified by a transistor. Here's the code:
int rightIn = 2;
int rightOut = 3;
int leftIn = 4;
int leftOut = 5;
int rightVal = 0;
int leftVal = 0;

void setup() {
  pinMode(rightIn, INPUT);
  pinMode(leftIn, INPUT);
  pinMode(rightOut, OUTPUT);
  pinMode(leftOut, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  rightVal = digitalRead(rightIn);
  Serial.println(rightVal);
  leftVal = digitalRead(leftIn);
  if ((rightVal == HIGH) || (leftVal == HIGH)) {
    if (rightVal == HIGH) {
      digitalWrite(rightOut, HIGH);
      digitalWrite(leftOut, LOW);
    }
    if (leftVal == HIGH) {
      digitalWrite(rightOut, LOW);
      digitalWrite(leftOut, HIGH);
    }
  }
  else {
    digitalWrite(rightOut, LOW);
    digitalWrite(leftOut, LOW);
  }
}

And the arduino wiring:

Pins 3 and 5 are attached to the motors power and ground
Pins 2 ad 4 go to an seprate inputs

And your question is?   The Stack Exchange sites require stating a clear, answerable problem

Please read How do I ask a good question? - you have stated what you want. Now you need to describe what is happening, compared to what you want to have happen.

I think you are mixing up your rightVal and rightIn, and your leftVal and leftIn.
rightVal = digitalRead(rightIn);
....
if (rightIn == HIGH) {

I'm just testing it with an led. In theory, would the code work?

Thanks, now that that's fixed could it work?

Probably, yes - as long as your circuit is up to it

Your HIGH/LOW signals will have to switch a motor's pole between power and ground - so you need more than "a transistor". You will need at least two each side in a H-bridge arrangement.

my motor only needs 3.3  volts, is 2 transistors per side really necessary?

Well, yes. How else are you going to switch 4 possible connections?


text:
Using Rx and Tx pins(0 and 1) on Arduino Uno for GSM
I am using a GSM module sim800. My module responds to the output given by my PIR sensor and sends sms according to it. My module has got +5V, GND, Rx and Tx pins. What are the pin connections that I have to make?

my INFINIX x510 isn't reconginz the USB cable

My module has got +5V, GND, Rx and Tx pins. What are the pin connections that I have to make?

TX => RX, RX => TX, that is Arduino TX to module RX, and TX to module RX. If you want to use Serial the pins are 0 for Arduino RX, and 1 for Arduino TX.
If you want to use SoftwareSerial you decide which pins to use (check the documentation for valid pins on your board).
// Use software serial with pin 2 for rx and pin 3 for tx
SoftwareSerial gsm(2,3);

Cheers!

when I use software serial an error pops up during uploading: 'SoftwareSerial' does not name a type.

#include <SoftwareSerial.h>, https://www.arduino.cc/en/Tutorial/SoftwareSerialExample

the rx pin from module to 2 pin of microcontroller?

You have a choice.
Always:

GND => GND
+5V => +5V

Then, either:

TX => RX (0)
RX => TX (1)

and use the hardware UART "Serial", but that then means that uploading new code to your Arduino becomes an arduous task since the usage pins 0 and 1 will interfere with that.  So the other option:

TX => Any pin
RX => Any pin

And then use SoftwareSerial to set up a secondary "bit banged" serial port on the two pins you choose.


text:
Detecting Motion behind a robot
I am building a motion following robot. It has two PIR sensors on the left and right. It has an ultrasonic sensor in the front. When either of the PIR sensors detect motion then it turns to that side.
When both the PIR sensors sense motion then I calculate the distance first( with the ultrasonic sensor, if distance <= 50 cm and > 5 cm then the robot moves forward. But it could mean that the motion is either in the front or in the back. Thus, my robot moves forward even the motion is behind it.
 I need some help devising a method so that when motion is detected behind then the robot will turn back. I tried making the robot turn right when both the sensors detect motion, then it will turn towards the left(i.e. front) or right(i.e. back). But in reality this method is not so practical as it would to a lot of confusion when the intruder we are trying to detect is still in motion. Plz help. A sample sketch would help.

PIR sensors only detect moving heat sources. That is, moving relative to the PIR sensor. If the PIR sensor is moving then everything is moving relative to it, so who knows what it will be detecting. PIR is not, IMHO. a good choice for this kind of thing.

Dont worry about that. The if statement conditions state that when only one PIR detects motion, then the robot turns towards that side. Then it again checks the outputs.

Couldn't you point the PIRs slightly to the back. So you essentially split the 360degrees into three sections.

Was the answer helpful? If so, please accept it by clicking on the "tick" icon next to the answer, and also possibly upvote it. This indicates to other users that you found the answer useful, and it also stops Stack Exchange from periodically "bumping" your question in the hope of getting an accepted answer. Thanks for your understanding and cooperation!

This is a basic problem of only having two sensors.  There is no way that two sensors of this simple type (some motion yes/no) can be used to work out where the motion comes from except when there is a difference between the two sensors.  Anything else is, and always will be, ambiguous.
If you think of it as a circle divided in two, you have only three possible conditions:

That is, left, right or somewhere.  Not ideal.
So you need more data to be able to make a decision.  That means more sensors.  The ideal scenario is four sensors - left, right, front and rear.  That gives you many possible scenarios, including:

As you can see from that you have a full 360° idea of where the motion is. You can even know how far to the left it is by if the front or rear is also on.  For instance, using sailing terminology, those 8 circles would mean (in order):

Motion on the left beam
Motion on the port bow
Motion dead ahead
Motion on the starboard bow
Motion on the starboard beam
Motion on the starboard quarter
Motion dead astern
Motion on the port quarter

Also the dead-ahead and dead-astern could be indicated by just the forward or rear sensor on and the left/right sensors both off.  You could even use that fact to give some indication of the distance of the motion depending on the angular coverage of the different sensors.

OK that is a good answer, I had thought of a similar answer but using only 3 PIR and 1 ultrasonic. Do u think it is possible?

3 PIR could be possible, but harder to manage. You could either have the three as an equilateral triangle, but then you won't really know if it's left or left and behind, etc. You could have three of the four laid out as above - just the 4 with one missing - and assume that if the front is off the rear must be on when both left and right are also on - which is most likely the case. So you could save one PIR that way.


text:
Problem with my arduino board
I had attatched a GSM module to my arduino Uno board. The power had been switched on. The GSM 5V pin was connected to my board. I was still midway with my work so for some reason I gave an external power supply to my GSM module. Now smoke started coming out of my Uno board and a burning smell came from it. I immediately switched off the power supply. But now I am unable to burn sketches to my Arduino. It is showing error: Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
On opening the serial monitor it says: Board at COM3 not detected.
Link from wher I bought the GSM module: http://www.ebay.in/itm/GSM-Module-SIM800-Quadband-better-than-SIM-900-or-SIM900A-Modem-with-SMA-Antenna-/252053758680?hash=item3aaf9322d8

Oops.
You let the Magic Smoke™ escape from your Arduino.  Your Arduino is now somewhat dead.  Depending on what died it may be repairable by replacing components, or it may be beyond resurrection and it'll be easier to buy a new one.
Now - why did it happen?  Looking at the board in your link it should have been OK with the 12V power you provided, since it has its own regulator on board that can supposedly take up to 12V.  So one of two things may have happened:

What you thought was 12V was actually higher than 12V and the regulator didn't cope with it.
You connected the power backwards, so -12V was pumped straight through everything.

There seems to be no polarity protection on the board as far as I can see, and many regulators, if connected backwards, will just pass the power straight through with little or no change to it.  So my money is on having connected the power backwards.  Now, that might not be your fault, since on that site I can see no mention of which polarity the power connector uses - whether it is pin-positive or pin-negative.  The normal way (the way the Arduino board uses) is pin-positive, but that is not always the case.
Either way, the Arduino is now dead, and the GSM module may be dead as well. In fact the whole lot may be dead.

I provided 12V to the adapter. What about the GSM module?

Ouch. And what is the adapter?

SMPS Power adapter

What is the GSM module you are using?

The module I am using is sim800

And what is the module mounted on? And do I have to ask individually for every single little detail? Why can't you just tell us exactly what it is you have?!?!

GSM Module SIM800 Quadband with SMA Antenna. RS232 and TTL Output I2C, PWM, Inbuilt Bluetooth

That tells me absolutely nothing.  Please edit your question and include links to the exact products you are using.

I have put the link in the question

I have updated my answer.

I had connected the 5v pin of the GSM to the arduino board and also connected the GSM with 12v adapter.

WHAT DO YOU MEAN BY THE WHOLE LOT?

I mean just that. There is a chance that everything might be dead. It's impossible to tell though without testing every single part.

I had 3 PIRs1 ultrasonic and 1 ht12e and 1 rf transmitter. what about those?

BTW how do I check if the GSM is working?

it would be nice if u were able to help me regarding this matter as I need to then place my orders soon.

Well, you know your Arduino is dead since you can't upload to it. The only way you can know if the GSM is dead is to plug it in to something and try using it. I cannot help you with that, my arms do not reach all the way to India. Instead YOU are going to have to investigate it for yourself.

Okay but what do you think about my other components. I tried checking my PIRs and they seem fine.

I didn't know you had any other components. If they seem fine they probably are fine. I am not psychic. I cannot test your components, and I do not even know what components you have since you haven't ever mentioned any other components. Use your brain. Try the components out. Get another Arduino and try them on that. Do not, under any circumstances though, repeat your previous disaster with your power supply.


text:
Simple 2 Servo Synch
I have two servos connected to an Arduino, They work fine if i write to them one by one so the wiring is all correct. I have seen a lot of examples here but none are facing the same issue. I have a simple for loop with Servo.write() on two servos (Facing each other) one going clockwise and the other going counterclockwise. I just want them to rotate at the same time and i cannot connect them to the same signal line since their movement is opposite.
My Code Is:
 for(int pos = 0; pos < 90; pos += 2)
 {
     delay(200);
     int pos7 = 90-pos;
     pos7 = pos7*(-1);
     myservo6.write(pos);
     myservo7.write(pos7);
 }

What Is Happening
Both the servos go to the "same position" (if one is at 90 the other is at 0 etc.. ) Yet one goes there slow and the other goes super fast(not affected by delay). Even though my delay should affect both servos.
If i remove the delay they both go to the same position yet very fast. What i need is for them to move together slowly to the position.

Like most Arduino libraries, the documentation for Servo is horribly, inexcusably incomplete.   You might try splitting your delay to put say 3 or 4 milliseconds of it in between the servo writes - if there is an undocumented interaction in how the pulses are actually generated, that should accommodate it.

Servo's limited documentation does however say that it accepts values in the range of 0-180; your attempt to write negative numbers to it seems improper, and may be causing an odd outcome, either horribly mistimed pulses, or perhaps no valid pulse until you reach 0 at the end and finally generate a position the "reversed" servo can begin moving to.

That was it ... i hadnt realized until u said "negative numbers" that i had it reversed ... instead of int pos7 = 90-pos; its int pos7 = pos-90; ... thank you @ChrisStratton

The Arduino Servo class is intended to accept positive values only, in the range of 0-180.
In addition to reversing the values for one servo by subtracting from 90, your code is also negating the values by multiplying by negative one.
That results in an invalid argument to the Servo function.  It's unclear exactly what happens, but likely possibilities include an invalid pulse, or no pulse at all.
At the end of your for loop, you subtract 90 from 90 producing zero, and invert it to still zero.  Zero is a valid input to the Servo function, so a valid output is produced and the "reversed" servo finally has a position it can seek to.


text:
Button circuit draws all power away from LEDs
I'm very new to Arduino, so please forgive me if I don't know the proper terms for things.
Whenever I press the button on the board, the LEDs all shut off.

I can't host the image files on imgur, and I don't know how well Flikr will work with it.
Now:
The resistors being used are 220 ohm resistors for the LEDs. The one for the button is a 10k ohm resistor.
This also happens without a resistor in place. I tried simply replacing the button with a wire from the positive to a row, with a wire leading from there to another row, back to ground.
What do I do to fix this?
Edit: Sorry about the images being extremely low quality, they've been updated.
Here's the code, but it's mostly irrelevant:
//DEFINE STUFF BABYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
int ButtonState2 = 0;
int ButtonState1 = 0;
int ButtonState0 = 0;
const int ButtonPin2 = 2;
const int ButtonPin1 = 1;
const int ButtonPin0 = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  digitalWrite(13, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  digitalWrite(6, LOW);
  digitalWrite(5, LOW);
  digitalWrite(4, LOW);
  digitalWrite(3, LOW);
  pinMode(ButtonPin2, INPUT);
  pinMode(ButtonPin1, INPUT);
  pinMode(ButtonPin0, INPUT);
  Serial.print(78);
}

void loop() {
  // put your main code here, to run repeatedly:
  ButtonState2 = digitalRead(ButtonPin2);
  ButtonState1 = digitalRead(ButtonPin1);
  ButtonState0 = digitalRead(ButtonPin0);
  if (ButtonState2 == HIGH){
    digitalWrite(13, HIGH);
    }
    else{
      digitalWrite(13, LOW);
      }
}

As per your statement, wire from the positive to a row, with a wire leading from there to another row, back to ground.
That describes a short circuit between V+ and ground.
Remove either the ground wire or the positive wire.

This fixed the issue. I removed the ground wire, and the resistor.

You have your switch shorting both pin 1 and V+ to ground when you press the switch. Do not do that.
The resistor you have isn't doing anything at all. It isn't really a meaningful part of your circuit. It is in the middle of one of the rows of your breadboard. All the pins in the same side of one row of the breadboard are connected to each other.
In your breadboard, every row, from 1 to 30, is divided into columns a-e and columns f-j. All the pins a-e in a row are connected to each other, and all the columns f-j are connected to each other. You have one end of your resistor in row 7, column g, and the other end in row 7, column h. So the resistor is short-circuited by the breadboard, and doesn't serve any purpose.
It's as if both ends of your resistor are connected to different points on a wire. If you were to measure the resistance between the leads of that resistor as it's connected, you'd get zero ohms.
You need to rearrange your wiring so you have a wire coming from +5V to one row of your breadboard. Let's call that the +5V row. Have a 10K resistor with one lead into another pin in that row, and then put the other end of the resistor into another row. Let's call that the pull-up row. (It's weakly connected, through a 10K resistor, to +5V. Now plug your switch into that row, also. Finally, run a wire from the opposite side of the switch and into ground.
Make sure to configure the pin as an INPUT.
If you set it up as an OUTPUT, set it to HIGH, and close the switch, you'll short the pin output to ground, probably destroying that pin's output driver. DON'T DO THAT.
Now, when the switch is open, the pull-up resistor weakly connects the pin to +5V, so you get a HIGH signal. When you close the switch, it shorts the pin to ground, pulling the input LOW.
Note that you could skip the connections to +5V and set the pin to INPUT_PULLUP mode instead. INPUT_PULLUP mode connects the pin to +5V internally, through a high ohm resistor.


text:
Using two input methods to control one motor shield (bluetooth and pushbuttons)
since an Arduino cannot run two programs simultaneously, I have been struggling a lot to get my project working - basically it is a motorized desk which is supposed to take input either from a BLE controller app or a pushbutton in order to move the linear actuators. However these inputs should work SIMULTANEOUSLY, I have failed to make both of them work together, after countless hours of prototyping, code provided below, please help me out.
    #include <AFMotor.h>

    AF_DCMotor motor1(1, MOTOR12_64KHZ);

    AF_DCMotor motor2(2, MOTOR12_64KHZ);

    int command;

    int forwardButton = A3;

    int backwardButton = A4;

    void setup() {

      Serial.begin(9600);

      pinMode(forwardButton, INPUT_PULLUP);

      pinMode(backwardButton,INPUT_PULLUP);

      motor1.setSpeed(255);

      motor2.setSpeed(255);

    }

    void forward(){

       motor1.run(FORWARD);

       motor2.run(FORWARD);
    }

    void backward(){

       motor1.run(BACKWARD);

       motor2.run(BACKWARD);
    }

    void stopMotor(){

       motor1.run(RELEASE);

       motor2.run(RELEASE);
    }

    void loop() {

      if (Serial.available() > 0) {

        command = Serial.read();

        stopMotor();

        switch (command) {

          case 'a':
            forward();
            break;
          case 'c':
            backward();
            break;
          case 'e':
            forward();
            break;
          case 'g':
            backward();
            break;
          case 'b':
            forward();
            break;
          case 'd':
            backward();
            break;
          case 'f':
            forward();
            break;
          case 'h':
            backward();
            break;
        }

      }
        else {

          stopMotor();

      }

    while(digitalRead(forwardButton) == LOW)

    {

      forward();

    }

    while(digitalRead(backwardButton) == LOW)

    {

      backward();

    }

    if(digitalRead(backwardButton)== HIGH)

    {

      stopMotor();

    }

    if(digitalRead(forwardButton) == HIGH)

    {

      stopMotor();

    }

    }

you did not describe the problem ... all you said is that you failed, which does not really mean anyhing specific ... you also did not say how the system should work

read through your code in loop() one line at a time and make note of what it does ... keep in mind that loop() repeats several thousand times per second


text:
Multiple rgb control plus calculation help
Hi me and a friend is making a computer shelf with leds in the woodwork, were using a special glue for the plexiglass in the shelf which means we're using individual rgb leds, four leds for each window (3 windows) and what I need help with is, amount of voltage, ampere, code and how to connect all this up. I've used 123d.io to sketch something up but I'm struggling with getting proper strength in the leds.

(code https://puu.sh/lI6PC/e214028b07.txt)
Aswell as some of them change colors as the picture here shows:

I'm very new at these things so I really appreciate all help and advice (and from an earlier post, reason for not using strips is purely based on the method of build, the shelf will not sit correct if the strips were in use)

What do you mean by proper strength in the leds. The second image seems to indicate you are running the leds at only 1mA. 20mA is generally the current to run an led at, to get maximum brightness.

Also using 12v as a supply is way more that what's needed, resulting in more losses.

How do I calculate to get which voltage is needed, I thought it was just mostly multiplying 3V per led then sum it up and done deal, but as I've seen it's completely wrong so how big is the needed powersupply?

That what you need to do if you connect them in series, but you are connecting them in parallel. So you need a voltage higher that the forward voltage of the blue led, which is about 3.2V. You need about 720mA when you turn on every led (at 20mA).

It's not advised to connect leds in parallel, with only one common resistor. Slight difference in forward voltage of the leds will create big current differences. This will make some leds appear brighter that neighboring leds. It can also damage the brighter led since too much current can flow through them. So you need to add a resistor to each led, and common the other side of these resistors to the transistor.
Second bigger error is that there isn't any resistor between the arduino pin and the base of the transistor. Without it there is nothing limiting the current going into the base, which could fry the arduino pin.

Thank you, I'll add that :) is the ones I'm using decent (270ohm)

270 will work, but isn't ideal. I'd use something like 2k. Lower values will be less efficient, and make the transistor run hotter. You could put a few 270 resistors in series to create a higher value resistance.

There's a lot to unpack here, this is actually several questions.
First of all, the way your circuit is designed currently, your data pins are connected via the transistors to ground. This means if you set a pin high, or use analogWrite(), the Arduino will pump as much current as it can get, directly into the ground. This can damage the Arduino. Put a resistor between the pin, and the transistor.
The first point is that you are using several LEDs. If you want to control them separately, you will need 3 pins per colour. AnalogWrite() only works on PWM pins - if you look at your Uno, you can see that some of the pins are marked with a ~ (pin 3,45,6,9,10,11) - these are the only ones you can (easily) use. Since there are 6 of them, you could only run 2 LEDs this way. You could either run the project on multiple arduinos (1 Arduino per 2 "windows"), or you can get a chip to do the heavy lifting for you. I am working on a similar project, and am using a TLC5940 - there is a thorough tutorial at http://playground.arduino.cc/Learning/TLC5940 - they also save you from having all the resistors and transistors, and each TLC5940 will run up to 16 LED-pins (3 per LED, so you can run up to 5 "windows"). They are also designed to daisy chain, so if you need more, you can just add another chip; no extra Arduino pins to worry about. 3 of them can run all 12 of your LEDs independently.
The next item to be aware of is that there is a limit to how much power (in Amps, or milliAmps) you can draw from a given power source. Each part will use a certain number of millAmps. The spec sheet for your parts should tell you how many. LEDs are generally around 20mA (per colour), but this varies - check the datasheet. An Arduino uses about 50mA. This means that if all 12 of your LEDs are bright white, you will be drawing 50mA+(20mA * 12 * 3) = 770mA.
How does this affect you? Well, if your project draws less than the power source can provide, you're golden! You can't provide "too much current" to a component - it will draw what it needs. When you draw more than the supply can supply, you get one of two results. If it runs on the mains, it will overheat, and eventually either burn out, or catch fire (there are exceptions to this, but you'd better be sure of your facts before risking it!). How long this takes, depends on how much current you are drawing, and how much margin there is on the power supply. In the case of a battery, the battery will drop in voltage, and will also heat up (but is much less likely to catch fire). I suspect this is happening here. If you have a multimeter, you can hook up your circuit to batteries, and then measure the voltage between + and - on the batteries.
P.S - +1 to @Gerben - you need one resistor per LED leg (except common). If you use the TLC5940, you would need 3 TLC5940s; as I said before, you can daisy-chain them. This does, however, mean that you can control each LED individually.