GND Servo and Arduino - arduino

I was working in a little project with Arduino and two Servomotors
Why is it necessary to putting the GND from external source (necessary to power the servomotor) and Arduino GND together?
Why is not able to work properly with separated GND?

Whenever you interface your Arduino to a separate device -- or several -- you must establish a common ground. Perhaps your servos run off their own power of a small breadboard, or you have a sensor or a bunch of LEDs... in all cases you'll need to make a common ground for all components of the circuit.
If I'm hooking up more than a single LED or single sensor to my Arduino, I prototype on a breadboard and the first thing I do is connect the power GND pin of the Arduino to the blue/black ground rail of the breadboard. That ensures a common ground, which is vitally important as a reference 0V in any circuit you build.
In many well-designed multi-layer circuit boards for example, often one layer of copper is devoted entirely to GND so that every component will be able to have a solid connection to GND. Then it's referred to as a "ground plane" and is a common goal in good circuit board design.

Current flows from + to - in a circuit, from the highest to the lowest reference point. See details here and here.
The GND is a reference point usually 0v.
With different GND (I'm guessing different positive input as well), you might end up with:
some short circuits
independent circuits
reflection phase change if you are working with alternating currents
Anyway in a circuit the GND should always the same (even though it can be in multiple places).

Related

Built-in led glowing on code of led on arduino mega

I had written a code on atmel studio for blinking a led on pin 13. After uploading the code with xloader mega's builtin led was blinking.
I uploaded fade code on my mega and the builtin led was blinking instead of led. What should i do?
I am using arduino mega 2560.
int main(void)
{
DDRB=0b00000000;
while (1)
{
PORTB=0b10000000;
_delay_ms(1000);
PORTB=0b00000000;
}
}
What you should do? Read the manual.
Please refer to https://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf
Chapter 13.2.
The DDxn bit in the DDRx Register selects the direction of this pin.
If DDxn is written logic one, Pxn is configured as an output pin. If
DDxn is written logic zero, Pxn is configured as an input pin.
Working with registers doesn't make sense if you don't know what they do.
DDRB=0b00000000;
Gives you inputs only.
why would you use Arduino and try to program it without its conventional macros and functions?
If you are trying to blink an led or make it breath then use the Arduino IDE and its built-in functions analogWrite() to generate a pwm pulse for your led or any led on suitable pins which support analogwrite(). You shouldn't try to do any direct modifications on registers if you have no suitable knowledge, because your risk destroying your development kit and maybe burning some other stuff around. Please use your kit's schematics to spot the pins which support analogwrite() and then use the code in examples.
That way you will achieve your goal faster and without any issues.
TL/DR: you have to set 7th bit in DDRB to one.
In AVR ports are configured by bits in two registers: DDRx and PORTx.
When the corresponding bit in the DDRx register is set to one, the port is configured as output. And the corresponding bit in the PORTx register chooses which electrical level is output on the pin. If it is 0 then internal MOSFET shorts the pin to "ground" lane, and sinks current from external source. When the bit of the PORTx is one, then the pin is connected to "VCC", sourcing big amount of current enough to lit up a LED.
But if the pin is connected to something, what consumes too much of current, or the pin is shorted to GND or VCC (let's say you have a button connected and pressed), then output MOSFETS might be overloaded and damaged.
If the bit in DDRx is set to zero, then the pin is configured as input. If the corresponding bit in the PORTx is zero, then the pin has no internal connection to power lines, it is called "Hi-impedance" state, or Tri-state. It does not source or sink any current. So, if no external source of current is connected, then pin level is floating, influenced by electrical interference. Logical level is not detectable and can change occasionally. If you want to connect, for example, a button (between the pin and GND), then logical level will be defined only when button is pressed. When it is released, the logical level will be undefined.
But! If the bit in the PORTx is set to one, then internal MOSFET connects the pin thru a resistor (about 35 kOhm) to VCC line. This make the pin to source a little amount of current, setting its logical level to high. Therefore, if a button is connected, when it is released, then pin will have defined high level. This is called "pull-up resistor". When button is pressed, it will not short and damage the MCU, because current flowing thru the button is limited by the resistor, but the logical level will be defined low.
What if instead of button you have a LED connected to the pin? Very small amount of current will flow thru the LED, makes it barely glow.
Read more in the datasheet (chapter 13. I/O-Ports)

Is it possible to connect many (20+) SPI sensors to an Arduino Mega?

I am making a system for measuring whether or not there is vacuum present in big steel containers. They are located up to 100 meters from the control cabinet.
The question is, how many SPI sensors can I successfully use at the same time with an Arduino Mega?
I have two main concerns, and there are probably more things I didn't think about.
Signal strength
The shared lines for CLK, MOSI and MISO will need to be split up at several junction boxes and led to the different sensors. Since the voltage out from the Arduino is fixed, I'm fearing instability because the signal is weaker for some sensors, has someone done something similar? What is the greatest acceptable voltage loss for these lines to an ordinary sensor?
Processing
Will the SPI library be fine coping with this many sensors?
The refresh rate can be set to extremely low, thinking 0.3Hz.
The alternative to all this is to go for 4-20mA sensors and have a 0-5V converter circuit for each sensor, near the controller.
Any inputs would be greatly appreciated!

How many amp can arduino take

Im currently trying to get an electric signal from arduino, its 5v and 1amp that i get from a powersupply.
I want to input that signal into an arduino pin, lets say pin 4.
The main powersource from my arduino is via usb, but the 5v signal is from an external device.
I just want to know the number of time that signal became active, like a switch.
As far as i know arduino can take only .04amp from 5v.
Is there anyway i can reduce the current?
Anyway to obtain the value of a resistor to make it less dangerous for my arduino?
Your question is a very common application for Arduino!
You can give your Arduino some additional protection by placing a 10kOhm resistor between the Arduino analog pin you wish to use and the positive voltage output of the power supply.
If you're worried that the voltage could increase above 5V, you can protect your arduino with a simple voltage divider using two resistors. There's a detailed tutorial for this approach here: https://startingelectronics.org/articles/arduino/measuring-voltage-with-arduino/ Here's a simplified circuit diagram with a voltage divider that reduces voltage 11 fold - making voltages up to 55V safe to measure (where the battery could be replaced by your power supply):
For your code, you can use analogread() to read the voltage of the pin. If you wired it correctly, it should return near 0 when the powersupply is at 0, and 1026 or thereabouts if it is at 5v (or whatever the maximum value your voltage divider is designed for). Here is an example to get you started :
https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
If you need any support with your code to count the number of times the voltage goes high, post that as a separate question along with the code you have so far.

Does Ardunino serial need a common ground

I have a device running off a different power supply, that I'm trying to talk to serially, it has TX and RX lines, GND and 2.7+ line, its quite grunty so It has its own PS.
I'm getting some odd results at the moment, so wondering if I need to use a common GND between the Arduino GND and the PS GND and the device GND.
Does serial require a common voltage reference point?
Its a mega 2560 R3
All signals require a reference voltage. Ground is what provides this reference for single-ended signals such as those used by a UART.
UART signals are composed of low-level and high-level signals.
The receptor, at the other end, to be able to understand your UART signal, must be aware of what is that low-level and high-level signals.
So you must put your UART GND to the GND of the receptor, and the high-level voltage must correspond to the TTL input level of your receptor.
For example, if the high-level of your UART is 2.7v, and your receptor input-level is 5v, you could encounter bad level detections sometime, because 2.7v could be detected as a low-level input.
For the low-level inputs, this is no problem because 0v is always 0v.
Sorry but... didn't you break your 2.7V device? Besides using a common ground, like Ignacio pointed out, when you have to interface something to something else you should ALWAYS check what are the correct voltage levels expected.
So did you check that the high voltage levels and low voltage levels are fulfilled? I think not. Because:
Arduino Uno (i just have the 328P datasheet on hand, so i'll use this) has an Atmega328P powered at 5V. The datasheet says that the Vih parameter (the minimum voltage sensed as a "high" value) is 0.6Vcc, which means 3V. So if you send him a 2.7V signal.... You are doing something wrong.
The 2.7V device has probably an absolute maximum voltage allowed on any pin of Vcc+0.3V. This means that the maximum voltage for each pin is 3V; if you go above this current starts flowing through the protection diode and... you blow your device. Now you are giving it 5V, so.... Puff...
If the above criteria are not fulfilled you have to put between the two circuits something. Which is
a resistor divider if you have to make the voltage lower (just two resistors) and a couple of transistors to make it higher
Opto-isolators (and you can keep the grounds separated)
Voltage translators (such as TXS0102)
other...

Arduino board : difference between two gnd port

On Arduino board, I see two port gnd : one in power line (a list of port has power label beside), that I call gnd(1). And the one is on the other (the line that has port from 0 --> 13 and gnd), that I call gnd(2).
I don't know the difference between two port, but when I test a LED on breadboard, if one line I connect to gnd(1), the LED will be lighter than gnd(2) (gnd(2) just has a small red light)
Please explain for me the difference.
Thanks :)
From reading this page: http://arduino.cc/en/Main/ArduinoBoardUno/ (if this is your board) I can't see that it should be any difference in your gnd ports. Maybe you provide different amount of power? Or do you have too much resistance at one time?
I have used Arduino pretty much and I've never had your issue even if I am using all gnd ports available.
The ground connections are usually directly connected on the board. In my opinion there are at least two good reasons for this design:
1) Ground connections are needed very often. Thus it is convenient to have as many ground connections as possible. Especially if you are experimenting with jumper wires.
2) Ground connections are very important and should be reliable. Thus redundant connections will improve reliability in case of vibrations and or bumps.
In my experience adding an extra GND to my breadboard greatly increases reliability and stability. I have had the same experience of LED turning brighter, but also of digital results becoming unreliable if i'am only using one GND.
I tried fixing my stability issues by adding capacitors to the breadboard, but adding an extra GND was much more effective.

Resources