text:
2 way RF with Virtual Wire / 315 / 433 MHz
I am trying to figure out how to get 2 Arduinos to talk back and forth from one another using cheap simple RF modules. I have a total of 4 RF modules (2 receiver and 2 transmitter) and 2 Arduinos. I need Arduino A to send about 3 variables to Arduino B, and I need Arduino B to send 1 variable back to Arduino A.
When I attempted 2 way communication, I programmed Arduino A to broadcast constantly, while having Arduino B trade off between receiving once, then sending once on every other loop. This resulted in Arduino B also only broadcasting, and was not receiving any signal from Arduino A.
My other attempt was to have Arduino B send for about 250 ms, then receive for 250 ms, and repeat. This worked as long as Arduino A was only broadcasting, but as soon as I had Arduino A doing the same thing, the clock on each seemed to be slightly off and there would be periods where both Arduinos were sending, or where both were trying to receive, so it was also very unreliable.
Is there a reliable way to do two way communication with this kind of hardware, or would I need transceivers to do this kind of project?

What bit rate are you using? And what is the message size? I would start by increasing the receive period and add a listen-before-send logic.

You should synchronize communication, instead of relying on just time. E.g. send 250ms after a message was received.

@MikaelPatel 2000 bps and a 4 byte message size. I tried increasing the receive period when I had it trading off with my first attempt. I wound up having it send once for every ~2000-4000 times it would read. That was the minimum it took for me to actually get it to receive anything, but that doesn't work well because when I have the other arduino do that same thing, they don't send frequently enough to reliably receive messages.

If the RF Modules you are mentioning are the ones I am thinking of they do seem to be very special bits of kit.  I have tried Bluetooth you can get cheap HM05 modules (Might be the wrong number you want the one that can be the master or slave).  These were a bit better but don't have the range.
My personal fav at the moment would be a ESP8266, no I have never hooked one up to an Arduino, but it can be done fairly easily.  You should get 100m range (in ideal circumstances) and you can get aerials to boost that.  You can also set one up as a repeater between two wifi segments.
Whatever you decide you might want to change your code slightly so that one Arduino sends a time signal and the other doesn't send its data until its turn.  Or give them GPS receivers and pull the time from there.

With VirtualWire, an Arduino can only send, or only receive. It can't do both at once. It is basically like software serial, but with Manchester encoding of the message.
Write your code for the sender to send once, and then listen for a response.
If no response after some interval, try sending again, and then go back to listening.
Perhaps try one more time.
Write your code for the receiver to always be listening, and not reply until a message is received.
Add some code to indicate when a good message is received as an aid to debugging.
You should be able to connect Tx to Rx and Rx to Tx (and Gnds) between the two Arduinos and get the sequence to work back and forth, and then connect the RF modules and have them work as well.
I think the encoding done by Virtual wire adds 37 bytes to the message, which the library takes care of, so the end result is only the data that was sent.
You might also try the RadioHead library, of which VirtualWire is one part now.


text:
Supply arduino through Vin pin with a battery

is it dangerous for arduino the below circuit because GND pin is common with -12V battery pole?
is it dangerous for lots of 5v circuit to be grounded on -12v battery pole?
in case i don't connect GND arduino pin with -12v , does arduino works?
in case that 1,2 question is dangerous for arduino,does it safe if a connect a diode at P1 mark?

You seem to be confusing ground and negative voltages an awful lot...

if a want to supply arduino with a battery which should be the connections?

there is no -12v in a battery, it is GND. So all -5v and -12v you have there are GND. Unless it is an ACTUAL negative voltage derived from the same power source, then it is irrelevant

Change your diagram's three '-5v' and one '-12v' to GND and the "+voltage" to be  "+5V".

Voltages, being a potential difference are always measured relative to another voltage.  Normally that reference voltage is referred to as ground, though may not always be.
The + and - on the battery refers to the polarity of the battery not the polarity of the voltage.
For instance, relative to the - terminal the positive terminal is 12 volts higher, or +12V.  Relative to the + terminal the negative terminal is 12V lower, so -12V.
When one of your battery terminals is connected to a point in your circuit nominated as ground (the - terminal of your battery in this case) then your battery voltage at the + terminal is measured relative to ground, which we say is 0V.  So the + terminal is 12V higher than the - terminal, and the - terminal is 0V, so therefore the + terminal must be 12V with respect to ground.  The - terminal, since it is connected to ground is at the same voltage as ground, so it is 0V with respect to ground.
If you were to connect the + terminal of a battery to ground instead, then the - terminal would be 12V lower than ground, so would be -12V with respect to ground.  The + terminal would be 0V with respect to ground.

source: Stack Exchange

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

sort: votes


text:
I'd like to make RC car and remote controller via bluetooth (HC06)
At first, I tried to make whole code for an RC car and remote controller, but I realized that it's difficult for me since I have few ideas about C++. So, I changed a few things like turning on the LEDs with switches and servomotors with potentiometer. Here are my code.
Remote controller
#include <SoftwareSerial.h>

SoftwareSerial BTSerial(2,3);
int sw1=13;
int sw2=12;

void setup() {
  BTSerial.begin(9600);
  Serial.begin(9600);
  pinMode(sw1, INPUT_PULLUP);
  pinMode(sw2, INPUT_PULLUP);
}

void loop() {
  int a = analogRead(A0);
  int map_a=map(a,0,1023,0,255);
  int state1=digitalRead(sw1);
  int state2=digitalRead(sw2);

  BTSerial.print('S');
  BTSerial.print(map_a);
  BTSerial.print(',');
  BTSerial.print(state1);
  BTSerial.print(',');
  BTSerial.print(state2);
  BTSerial.print('E');
  delay(100);
}

< RC CAR >
#include <SoftwareSerial.h>

SoftwareSerial BTSerial(2,3);

byte buffer[255];
int bufferPosition;

void setup() {
 BTSerial.begin(9600);
 Serial.begin(9600);
 bufferPosition=0;

}

void loop() {
  {
    if(BTSerial.available()>0){
    unsigned char data = (unsigned char)BTSerial.read();
    buffer[bufferPosition++]=data;
    Serial.println(data);
    delay(100);
    }
}
}

When I checked the result from Serial.println(data) from RC car code,
it was trash...
Can you instruct me what's wrong with this code?

Why the delay(100) in the RC CAR part? And what happens when the buffer is full? Seems incomplete. BW: Please use a code tag.

i was expecting this result
S map_a, state1, state2, E
S map_a, state1, state2, E
S map_a, state1, state2, E
....
after i receive this result, i would like to proceed more...and sorry, i didn't know how to use a code tag,,it is first time to ask a question here...

Please post what you actually get in the serial monitor - one man's "trash" is another man's really-easy-answer.

Wait, why are you casting to unsigned char ? Serial.print() very expects a 'regular' char.

There are some fundamental problems in the code - bufferPosition never stops increasing (until it reaches 32768) and so buffer will overflow. However, neither of these two problems are causing the 'trash', as you are outputting the result of reading the serial, not anything from the buffer.
The problem lies in the casting of the result from BTSerial.read() to unsigned char.
Serial.print() does not like this. Actually it doesn't care, but it won't give you what you expect. It just prints out the value stored - so 'a', which is 97, will come out as '97' on the serial monitor. Serial.print() only outputs ASCII characters when you give it a char or char[].

thank you so much. I just started to study C language. So i've got confused with char or int or unsigned char. I'm trying to learn those things from some examples..thanks again. I will try to fix some codes you mentioned and post again later :)

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


text:
What does the 'arduino' avrdude programmer do?
The command line that my toolchain (CLion + PlatformIO) uses to program my Arduino (Uno) includes includes
avrdude ... -c arduino ...

but the documentation for this programmer simply reads

-c programmer-id
           ...
          arduino           Arduino
           ...

What does the arduino programmer do. Does it just correspond to using the bootloader?

Yes, the -c option specifies the methods of interacting with the device's loader.
The source code of the arduino programmer is http://svn.savannah.nongnu.org/viewvc/trunk/avrdude/arduino.c?root=avrdude&view=markup
Specifically, '-c arduino' chooses the client side code tailored to the bootloader in the Arduino Uno.  Looking at the code in the above link, it tweaks the DTR and RTS lines to get the Ardunino into an stk500 compatible mode, and then invokes the stk500 protocol.

Yes, I know the -c option generally specifies "methods of interacting". The question is:  What does choosing -c arduino do? Specifically, is it using the bootloader, when I'm connected to the Uno using the serial port?

'-c arduino' chooses the client side code tailored to the bootloader in the Arduino Uno.  Looking at the code, it tweaks the DTR and RTS lines to get the Ardunino into an stk500 compatibple mode, and then invokes that.

Can you elaborate a bit (in noob terms)?

I don't know much, but I'd look in the code and "Trust the source, Luke".  The avrdude has '-c ??????' options for a large number of embedded systems, and from a cursory browse, it seems like each one may have  different initialization and protocol schemes.  The '-c arduino' has its own that apparently works with whatever is normally loaded into the arduino's bootloader.  You can look at the avrdude code to see how one side interacts with the other.  I don't know what's in the chip's bootloader, but maybe https://www.arduino.cc/en/Hacking/Bootloader/ would help you.


text:
I would like to retrieve data from a MySQL database using PHP using HTTP requests, on my Arduino
Please help me find a way to do it.
I have looked at the following for sending data Arduino to MySql
But can't seem to find visa-versa.

What actions have you taken yet? What does/doesn't work?
Is the connection between arduino/php website working or is the problem at php<-mysql

Sure, why not. If interested let us know a time frame, any of us here would deliver you the way, and quote you accordingly.

Point is that i forgot to check the date of the question, :D replied to a 2yr old question.

There are two things you have to set up for this:
1. Retrieving/parsing websites from your Arduino.
2. Making a dynamic website using PHP (and MySql).

Try to set up your Arduino as a WebClient, check if you can retrieve a website like google.com or a minimalistic website.
Try to get your arduino to interpret a string or retrieve values from that website. (I.E: retrieve the day/time from the HTTP message)

IF your arduino can retrieve webpages, you're halfway there (somewhat). And your project is running out of the scope of this arduino.stackexchange.
Now you're going to have to create a dynamic website. You can let PHP reach for values from your MySql database (you should just use a text file first) and display them on your site (in HTML).
Your Arduino can now poll your website, to get the HTML content and parse it to the values.

You could develop a REST based service, to make Arduino consume web service using the aRest library.
Following is a tutorial of how to use the aRest API with Arduino: A REST API for Arduino & the CC3000 WiFi Chip.


text:
IR sensor readings at different voltages
I am currently working on a photo-transistor like this:
http://www.ebay.com/itm/10pcs-ITR8307-S18-TR8-Optical-Switches-Reflective-Phototransistor-Output-/381374566327?hash=item58cbb20fb7:g:lgoAAOSwr81UQ7KG
It very nicely allows me to identify colors white, green and black. The problem I am having is that the Arduino is powered with batteries so the readings for those colors change as voltage in the batteries reduces.
I tried to make the reading proportional to the voltage in the system, but this still gives different values, I guess the readings change non-linearly as voltage changes.
I wonder what will be the solution to this problem: Specifically, how to make the reading of an IR sensor the same for the same color at different voltages?
This is the code I am using so far:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

void loop() {
// read the input from the IR sensor on pin A0:
float sensorValue = analogRead(A0);
// read the voltage in the system by connecting pin A1 to Vcc, with the same resistor value used in the IR sensor:
float Vref = analogRead(A1);

// adjust reading value to voltage in system:
float AdjustedReading = sensorValue/Vref;

Serial.println(AdjustedReading);
delay(100);
}

How it it connected? How are you powering you arduino?

What is Vref connected to...?

the device is powered with 2 aa batteries. The Attemega328 works well at voltages as low as 1.8v. but in the ranges from 3.5v (the maximum with 2 AA batteries) to 1.8 v, for the same color I get different IR readings, which prevents me of setting thresholds to define each color.

The circuit is very similar to this: http://blog.huntgang.com/2014/06/17/arduino-tcrt5000-build-ir-sensor/  the only difference is the polarity of the IR emitter which has to be inverted for the phototransistor I am using.

That doesn't show what Vref is. Is it by chance connected direct to the Vcc pin of the ATMega? I.e., connected to V+ of the battery? If so it will always read the same value and is of absolutely no use in this situation. Instead you need to back-calculate the Vcc vaue from reading the internal 1.1V band-gap reference voltage.

It sounds to me like your system works, but you have trouble if your voltage drops.
First of all here's 2 tips that might solve your problem.

instead of just making 1 reading do 10 and take an average - this reduces noise.
the voltage reference is allready based on the voltage that powers the system so with your adjusted reading you try to accomplish something which has already happened an therefore has the opposite effect and actually increase the error.

see http://tronixstuff.com/2013/12/12/arduino-tutorials-chapter-22-aref-pin/ for a very good explanation.

Add a RC filter to removes random fluctuations in the signal from you photoresistor

see https://electronics.stackexchange.com/questions/17754/where-to-place-a-capacitor-to-smoothen-ir-sensor-reading for a short description and the calculated example.
If however it is correct, and your readings of colors don't follow a linear scale, you would have to deduce that actual curve and apply it in the code - but that might not be easy.
So it would be much more easy to remove that variable by ensuring that the voltage is constant. Most Arduino boards have an 5V onboard voltage regulator that will keep the voltage exactly at 5 Volt when connected to battery via the power Jack!
(USB bypasses this regulator and have a little voltage drop so it is sligthly lower than 5V, and more very prone to fluctations if coming from a AC source affecting your analog read considerably)
The battery connected onboard voltage regulator however requires a higher input to do the regulation so the battery needs to supply atleast 6.2V or higher, in your case you would have to use a voltage source of less than 6.2V if this is the source of your problems.
(the voltage regulator on original arduino boards needs voltage of 1.2V higher than the needed output - clones might differ and require upto 2v more than the needed output)
hope this can help solve the issue
Mikael


text:
Using a Hot Wheels Radar Gun with FreqPeriod library
I want to make a clone of those radar enforcement signs that look like this:

I bought a Hot Wheels Radar gun that can send an analog signal to determine speed.  See this thread:  http://forum.arduino.cc/index.php?topic=145063.msg1889312#msg1889312
From FreqPeriod's documentation, it has the following comment in the code:
connect pin 5,6,7 to input circuit
Question is -- how do I wire up the radar gun analog signal wire to the arduino to successfully use FreqPeriod?

What makes you think that the FreqPeriod library has anything whatsoever to do with this...?!  5 seconds reading that thread and the link to the project within it and I already know that FreqPeriod is NOT what you want to be using. Go do some more reading.

The post below the one I linked to included a working sketch, rigged up the the guts of the hot wheels radar gun. There are a few in the forums that have used that sketch to get speed using FreqPeriod.  I just need help figuring out how to wire it up.

Ignore the forum, most of that is talking gibberish. Instead read the project page. The code linked to by the forum thread is for something entirely different. For the hotwheels it gives an analog signal that you just read with analogRead(). FreqPeriod is used if you are building your own doppler circuit and doing the work in the Atmel. The hotwheels one does the work in external hardware and just gives you an analog voltage. Or that's what the project page says.


text:
connecting RTC DS1307 to ethernet shield
What is the easiest way to mount DS1307 to ethernet shield?
I tried to do this:
https://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/wiring-it-up
but my program just freezes when I try to read data from RTC. Is there any other ways to do it?
Code looks like this:
const int RTCpin2 = 2;
const int RTCpin3 = 3;

void setup() {
    pinMode(RTCpin2, OUTPUT);
    pinMode(RTCpin3, OUTPUT);

    analogWrite(RTCpin2, LOW);
    analogWrite(RTCpin3, HIGH);
}

void loop() {
     // process RTC time
}

What do you hope to achieve with that code?

this is not the whole code, is bunch of other things too, so I need ethernet shield and then RTC mounter to it.

Yes, but what do you hope to achieve with that code that you have shown? What do you think it will do?

5V to pin3, reading with pin2?

Nope, you couldn't be more wrong. I assume those pins are supposed to power the RTC? Well, first you are using the wrong pins, and secondly you are using the wrong functions.

I assume that snippet of code is supposed to provide the +5Vand GND for powering the RTC module.  Well, there's two fundamental flaws with it:

Pins 2 and 3 are the DIGITAL pins, not the analog pins. Instead you want to be using pins A2 and A3.
analogWrite controls the PWM output on pins that support PWM. HIGH is 1, so analogWrite will be providing a 1/255 duty cycle PWM signal on that pin.

So to fix it:

Use pins A2 and A3 instead of 2 and 3
Use digitalWrite() instead of analogWrite().


text:
Multithreading with Arduino
Well I've just started learning the concept of multithreading with C++ and immediately a bunch of questions came to mind about the possibility of using multithreading with microcontrollers in general and Arduino specifically.
So, is it possible to use multithreading on any type of Arduino boards?

By multithreaded, do you also mean concurrent? If you don't, Interrupt routines triggered by a timer at even intervals can cover a lot of similar functionality on AVR processors.

You could try this library https://github.com/mikaelpatel/Arduino-Scheduler

In Cosa you can find the following support for concurrent programming:

Events, interface interrupt service routines
Jobs, delayed, periodic or alarm functions with us, ms and seconds level timers (Watchdog, RTT or RTC).
FSM, object-state function
ProtoThreads, object-state pointer
Threads, Semaphores, etc, multiple stacks
UML Capsules and Connectors, dependency driven programming

There are plenty examples on how to use these. A good starting point is the Blink sketches. There is even a multi-threading Blink example with a thread that does the LED on/off and a controller thread that periodically changes the blink period. The thread stack size is only 64 bytes and it runs even on an ATtiny.
With all the AVR internal hardware modules (such as SPI, TWI, UART, etc) there is plenty of opportunities for concurrency.
A Scheduler library for the Arduino core is also available. This is a port of the Cosa Threads. Please see github for further details.
Cheers!

Of what order is the memory overhead of Cosa? 100 KB flash and 20 KB RAM?

Depends on what you use/include. In general the "overhead" is less than the Arduino core for similar functionality. Best way to find out is to run some of the example sketches.

The really quick answer is "maybe" – it depends on what you mean by "Arduino" and what you mean by "thread." The answer is likely to be different for the AVR based Arduinos (Uno et al.) vs. the ARM based Arduinos (Due et al.) – I would expect there to be much better hardware support for "real" threads on the ARM processors. Another question you'd want to answer is "why threads?" Do you want the abstraction to help you organize your code? Or do you actually need "real" threads?
Before there was hardware thread support (e.g., the mid-80s) there are user thread implementations, it seems possible that they might be adaptable to run even on an AVR. I would expect it to be something of a project.
There is a threads package called Protothreads which may be interesting. The description says "Protothreads are extremely lightweight stalkless threads designed for severely memory constrained systems." I found another question asking about simple usage of Protothreads, so it seems that you may find some other users of the package.
You may also find some useful information in this Stack Exchange question on threads, a quick search for "C user threads" found this implementation on the first page – and I'm sure there are many more.
A search on "Arduino threads" found several more interesting looking links:

How can I create multiple running threads?
Arduino Thread package on GitHub
http://www.kwartzlab.ca/2010/09/arduino-multi-threading-librar/
http://forums.trossenrobotics.com/showthread.php?5923-Multithreading-(Parallel-loops)-on-an-Arduino

If you just want threads, a small and inexpensive board, and I/O pins it might be worth considering a Raspberry Pi – Linux has thread support.

Good answer. It also might be worth noting that even with hardware thread support, an OS or at least some software will layer will probably need to manage and schedule the threads.

@Mlagma: As far as I can tell, each link in this answer shows an implementation of threads that are statically compiled into the user's program. The Arduino runs only that one program. Can you give even one example of an OS or other software layer, other than the user program?

@Mlagma, it could be as simple as something like coroutines and interrupts. I'm not expecting to find much beyond maybe a library that implements a basic scheduler – but I haven't found even that.

There's one Arduino-like product that certainly could enable multi-threading, as it is multi-core: the Shield Buddy TC275.

So basically you have three setup() functions, and three loop() functions. True multi-threading.

+1 for finding this. Excellent board, but not cheap. However, it would give AeroQuad a new lease of life..!

Yeah it's been on my radar for a while but the cost... I hope Chinese clone-makers find it soon :-)

It's not as compatible as I initially thought though, for reasons that are, now, obvious. A simple recompilation may not be sufficient. It will depend on the complexity of the code, i.e. if assembler has been used. See Has anyone used a Shield Buddy (en lieu of a Arduino Mega2560) as the RAMPS 1.4 host board?

Yeah, ASM could be a problem. Plus, adjusting the code to a 3-core environment, even without ASM, would require some work. But I think for a new project, it could be indeed interesting.

I use Atomthreads on Atmega128, it is very lightweight with minimum overhead. Have task scheduler, mutex, semaphores and queue. Code is portable but might require some configuration to use with Arduino IDE (I use Atmel Studio). I primarily use task scheduler, never had problems. Just checked, the development is still active.

Re: "very lightweight". Can you quantify that? Is it 8 KB of flash and 600 bytes of memory?


text:
What is the minimum wattage of resistors for breadboarding with Arduino Uno?
I'd like to buy new resistors for breadboarding with my Arduino Uno. There are 0.25W, 0.4W, 0.6W, 1W, 2W, 3W, 5W, 10W resistors in the shop. What is the most suitable for this operation?

I know this has been answered, but would you care to elaborate? What is it you're trying to do? Which resistors are you wanting to replace, and why?

I'm building a morse transmitter/reciever, you can find a discussion about it here and here. I don't want to replace my current resistors just buying some I don't have in my repertoire 100R, 500R, 1K. I'm buying 0,25W ones, because it's enough according to the equation P=UU/R=55/100=0,25, 100R is the smallest I'll buy. It is not all for the current project, but for the future. I gladly hear your opinion too.

lol, no worries. I thought the question was a bit odd :)

The answer is: It depends what you want to use them for.
You need a wattage that is higher than the power it will dissipate. What that power is depends on what you are doing with them.  There are standard formulae that tell you the power in any given situation.
For instance, if you know the current and the resistance you can use:  P=I²×R. If you know the voltage across the resistor it's P=V²÷R.
Take as an example the common resistor for an LED.  Assume a 2V LED and a 220 ohm resistor. With a 5V total voltage the voltage across the resistor would be 5-2=3V. So the power would be (3²)/220 = 9/220 = 0.041W so you could quite happily use a 0.125w (⅛w) resistor for that job.
To be honest though most common Arduino jobs can be accommodated by ⅛W or ¼W resistors.  ¼W is better for breadboarding since the leads are fatter than ⅛W, but ⅛W can take two leads at once direct into an Arduino's headers. Also if you fold the leads in half and squash them with pliers they fit better.

Thanks. That equation is really useful. I calculated and it seems 0,25W is good for what I'm going to do. Also there are no 1/8 resistors in the shop.

Go with 1/4 Watt resistors but be prepared to use 1/2 Watts if the leads don't press down cleanly into the breadboard which is what I think you are asking about. If you need anything in the higher wattage range and you are working with an Arduino, then you are doing it wrong. An Arduino could not smoke a 1/4 watt if it tried.
I have fought for years with our purchasing agent over this at the college I work for. He buys 1/8th watt resistor in bulk, but fails to heed the advice that you cannot use these on standard classroom breadboard without bending the leads at best and failing to even make a good connection at worst. You need reliable connections and 1/8th and smaller are useless on breadboards. Just my two cents from years and years of experience.

The smaller the better for the most part. On 1/4 or 1/8 W resistors the leads size is small enough to work well in bread boards. Rarely do you need to dissipate large amounts of power so 1/8 is a good size for logic, maybe 1/4-1/2 for power supply areas.  See Majenko's answer for the heavy math, mostly applicable in power supply areas as he points out.

1/8 watt resistor leads are typically too small for easy breadboarding.  Even some modern 1/4 watt resistors have thin soft leads, though that was the traditional size mechanically speaking.

Hmm, I'll have to check that the one's I'm calling 1/8 really are. They are very easy to work with and the leads are much more "breadboard friendly."


text:
Taking off the chip from Arduino
I just uploaded a sketch of a song to my Arduino and it works well.  Could I just take the chip out and hook up speakers to it and a power source to play the song? and just get another chip and put it in the Arduino.

There are lots of resources on this subject on the internet.
It is possible, but requires some engineering.
Try searching: "Breadboard arduino" or "barebones arduino".
https://www.arduino.cc/en/Main/Standalone
You'll need:
5V power supply, or circuitry to provide so.
20Mhz clock or use the internal 8Mhz clock.
Something to program it with, an USB<->uart converter or ICSP programmer. (Or just put a programmed chip in)
And optionally a reset button,

@FuaZe arduinos use 16MHz, not 20mHz.

@Gerben ah, ofcourse, no idea why I thought of 20Mhz. Thanks for pointing that out!

Yes and no.
To elaborate, the sketch you downloaded to the chip has been flashed to internal non-volatile memory. So if you were to move it to another Arduino board or other device with the appropriate support hardware, then it should work just fine.
However, if you're intending to directly hook-up speakers to it and a power source, then I highly doubt it's going to work. You really need some support hardware for the chip (such as an external clock - though I think the Atmega328 has an internal clock, decoupling capacitors, amplifiers for the spearkers, etc.).

More specifically, the ATmega328p in a typical full-size Arduino is typically fused to rely on an external clock.  While being provided with such a clock it can be re-programmed for internal clock operation, as those used on some of the various smaller boards typically are.

Easy part first: You CAN put another chip on arduino PROVIDED that chip already has a bootloader on it. If it's a raw chip, burn the bootloader on it first. This guide will help.
You CAN connect the programmed chip to speaker PROVIDED you add the minimal circuit components required for an arduino to run. These include - a 16 MHz crystal, two 22 pf capacitors and a 10K resistor. Use the schematic in the bootloader guide. That will work.
Besides this, you will require a 5V power source. You can alternatively use 3xAA cells (4.5V will work perfectly). Alternatively use a wall adapter of 7V or higher and use a linear regulator (7805) to generate a perfect 5V supply for your arduino. You will need this pin mapping diagram to connect the speaker to arduino once you take it out from the board:


text:
Why won't processing not communicate with Arduino uno?
I downloaded the Processing language and ran the "Hello World" program to test it. The message appears in the Serial console but not on the Processing console. It prints "null" only. I am using the code supplied by Sparkfun. Other people have had this problem. I am looking for clear explanation and solution.

What code? What sketch? What what?!

I apologize for presenting a vague question. I was unable to successfully run the simple code to learn "serial communication" presented by Sparkfun on: https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing.
Step 1. Run Arduino to produce "Hello, World" on the Serial Port.
Step 2. Run Progressing 3.0.1 to produce "Hello, World" on its console.
The code from the website are copied and pasted onto my iMac running El Capitan. I received an error message for Step 2 stating the "port is busy."
Once I closed the Arduino (Step 1) and compiled and ran Step 2, it worked!
Several other people found different solutions. My solution is simple. Run one program at a time.

You had both the serial monitor and the processing application running at once? No wonder it didn't work - the serial monitor was using the serial port so the processing application couldn't get at it. Only one thing can read from the serial at a time - you choose which: the serial monitor or the processing application.


text:
Is a HC-SR04 fast enough to make decisions on moving robot (4 Johnson motors 300 rpm)?
I am working on a project in which I have made a robot powered by 4 Johnson DC motors (300 rpm) and controlled by Arduino UNO R3. Now in my project I'd used ultrasonic sensor (HC-SR04) for detecting obstacles.
What I want is that as soon as my an obstacle is detected robot should turn by 180° but what actually happening is that sometimes robot takes turn very late (though I'd kept range of sensor approximately 50cm) and sometimes it just collides with obstacles.
As I'm new to Arduino I just want to know if an ultrasonic sensor is fast enough to sense obstacles and signal the Arduino about it, before it gets close enough?
Here's my code
int sense()
{
     analogWrite(trigPin, 0);
 // instead of digitalWrite(trigPin,LOW);
     delayMicroseconds(2);

/* as I'd used my digital pins for  motors and all i have to use pwm pin for  trigger pin of sensors i guess it doesn't make any difference*/

     analogWrite(trigPin, 255);
  // instead of digitalWrite(trigPin, HIGH);
     delayMicroseconds(10);

     analogWrite(trigPin, 0);
     duration = pulseIn(echoPin, HIGH);

     distance = duration/58.2;

      if (distance > maximumRange)
          return 0;
      else
          return 1;
}

Why are you using analogWrite()?

Use digital mode for the pins - analog pins are those with analog input capability but still digital outputs.  If it is fast enough depends on things like how far you move in the time spent waiting for out of range echoes to die.  Your more serious problem may be if objects are hard to detect due to size or angle.  You may also have algorithm problems.

i am using wall or my bag as obstacle i dont think it has any problem detectiñg such object and if you think problem is with pins then it is not, as i had tried blinking LED using those pwm pins and regarding algorithm i dont know anything about it because i copied this code from internet and it worked so i used it in my project but now i am façing problems in response time of sensor

@NISHANTDESAI Try attaching a USB cable and print out the value all the time and see, maybe the object is indeed not detected.

On it's max speed, how far is it's braking distance?
Then you should start braking atleast from before that distance of the object.
Let's say your braking distance is 25cm, you should start braking >25cm.
But this is only when you would instantly brake at the moment you're within 25cm reach.
So we have to know how many distance we will travel during the calculation, before we start braking.
You could just try it out, set the distance a little higher everytime you crash into it (Assuming it doesn't fail and is always at the same time).
We have to know the top speed of your motor, RPM doesn't say a lot in this story, we'll need to know how big your wheels are to be able to determine how many cm's you'll travel per revolution, and doing that times the RPM, you know your top speed. (Or you can also measure this, but it can change depending on how full your battery is)
Also, your code should be real-time you'll likely want to use timers to trigger the trigPin and use an interrupt on the echoPin to be sure none of your code will delay your sensor. This will improve execution speed aswell as reliability/deterministic timing. Also, it will make it possible to run it aside from your regular code.
So if you know, your top speed = 10cm/second.
And you know that 1 calculation+reaction-time is 200ms.
You can safely assume that you need >2cm extra.
To be honest, you should add a little for when it's slippery/another surface or just so you won't touch the object.
So. The ping sensor is almost always fast enough, only if the calculated range is outside your max range, it will not work.
You could however, use an IR proximity sensor which will trigger at a set distance. This way you don't have to do any calculations and just brake whenever you receive the interrupt. But it won't tell you the distance to the object.
The cool thing on the distance sensor is that you can also scale the brake distance on your driving speed, so that it will brake later when you're driving on half your speed. That way you can come very close to an object, but still be 100% sure that you won't crash into it.

Try using NewPing library. Ping sensors consistently and reliably at up to 30 times per second.

You can't achieve 30 times per second if you use the ping_median which basically does error correction. Best you can do is 1000/(29*5), or 6 readings (assuming using default 5 pings per median reading)


text:
Where is the Aref pin for Attitny88
I would like to use the external analog refence voltage in an Attiny88 project I am working on that will be powered with batteries.
However, the datasheet for this processor does not show an Aref pin like other versions of the attiny, like attiny85 and attiny84, where it is usually the pin PA0 or PB0. Does anyone know where is the pin for the external voltage reference in attiny88 (e.i. Aref pin)? Does this chip has the functionality for an external analog reference voltage?

As shown in the detailed information for the ADMUX register in the ADC section of the datasheet, the ATtiny88 has no external voltage reference. Consider using a ATmega8 or ATmega88PB instead.


text:
What is the correct way to wire a piezzo buzzer with a potentiometer and a button?
I'm working on a morse transmitter (kind-a), this how it looks like now:

It's working, but is it correct? My piezo buzzer is 3-24V. I use the potentiometer as a volume control. The button is for transmitting morse code.
I've seen a way of wiring like this, not using any resistors, it feels wrong, is it correct?
https://cdn.sparkfun.com/assets/learn_tutorials/3/1/0/Arduino_circuit_11_01.png

You are using the Arduino basically as a power supply (in your wiring). The linked wiring is for PWM (analogWrite). This allows pulse output to generate tone (and volume). Here is a good reference.


text:
Sending IR (NEC)-Signals with Arduino
I have an Arduino Micro where I want to control a display with IR commands. So the Arduino should send the IR commands to the display.
I have found a library "Arduino-IRremote", which I am using to transmit Commands to the display. The display works perfectly with its remote control, however I can't get it accept signals from my Arduino.
Now the special part about my setup is, that I do not use a "classic" IR transmitter. Instead i uset an IR cable, which is connected to "IR-In" of the display. So no LED - only a wired connection. The IR-cable consists of 3 wires. 2 for power supply (VIN and GND) and one is for the data connection. The wire with the data connection is connected with the Arduino PWM pin 3 (like it is said on the example in the linked library), but I tried all other pins anyway.
#include <IRremote.h>
IRsend irsend;

void loop() {

  for (int i = 0; i < 2; i++) {
    digitalWrite(RXLED, HIGH);
    irsend.sendNEC(0x004eff71, 32);
    Serial.println( "sendNEC 00 4E FF 71" );
    digitalWrite(RXLED, LOW);
    delay(40);

  }
  delay(1000);
}

004eff71 is a NEC-Command from the original remote control
Now can somebody tell me, what I'm doing wrong? The program compiles and the LED lights up, everytime it should send the NEC-command. But still the display receives nothing.
What is wrong?

It isn't working probably because the output of the Arduino isn't simply an on/off signal.
That library uses a pulse width modulated output on the Arduino to drive an LED.  When the LED is "on" the signal driving it is actually pulsing at a very high rate.
I don't know what all you'd have to change to make that work with a direct wired connection.
Another thing that might becausing problems is that without checking, you can't be sure that the signal level you are sending matches the levels that the IR receiver would normally produce.

It would help to know the specifications of the IR input on the device you're trying to control but after a bit of googling it looks like most of them are just expecting a connection to an IR receiver. I found a link to what appears to be a common one, TSOP22.., TSOP24.., TSOP48.., TSOP44.. and here's a link to the data sheet (http://www.vishay.com/docs/82459/tsop48.pdf). If you check the Vo on page 2 it shows 0-5V. You didn't mention if you're using a 5V or 3V Arduino so that could be an issue.
The PWM outputs do in fact generate square wave signals so at first glance this does not look like a hardware issue (assuming it is wired correctly for the IR input on your equipment).
I'd start taking a look at the data you're trying to send. I haven't looked into the library you mentioned and hopefully it contains a sample to show how to properly initialize the library and send data. Maybe instead of first byte first it needs to be sent first byte last or requires a fixed number of bytes to send...
Providing more details about your project you might get a better answer.


text:
How to read all avaiable data from a Serial stream and then stop
I am trying to read data from the Serial port in my Arduino, store it in a buffer and when all the data has been read stop reading and then start using the data (the talkMIDI() function). The Arduino succesfully some bytes from Serial but not all of them and then hangs without stopping before the end.
void loop() {
  if (!stop)
  {
    char in = Serial.read();
    if (in != -1)
    {
      buffer[pos] = in;
      pos++;
      Serial.write("read");
      Serial.print(pos);
      Serial.print("\r\n");
    }
    if (in == 126)
    {
      stop = 1;
      Serial.write("STOP");
    }
  }
  else
  {
    if (cursor < pos)
    {
      talkMIDI (buffer[cursor], buffer[cursor+1], buffer[cursor+2]);
      cursor = cursor+3;
      delay(500);
    }
  }
}

After manually sending a 126 value (~) character, I get a "STOP" response on the Serial line but Arduino doesn't start executing the code from the else branch (the talkMIDI() part -- the function doesn't even get called once).

Where do you declare stop? Maybe it's not the same stop at the top of the loop.

stop is declared globally at the beginning.

Then it must be the cursor < pos test.

How do you mean?

You should read this: http://hacking.majenko.co.uk/reading-serial-on-the-arduino

Looking at it quickly, if stop is set, then the reason for not executing the code in the else branch would be the expression (cursor < pos). Maybe put a Serial.println in the branch (before the if) to confirm that the else is getting executed.

Trying to send multiple characters for each received character is not likely to work well unless the characters are sent to the Arduino with substantial delays in between them.


text:
FastLED fade WS2812B
Learning how to program with Arduino, but the learning curve is out of my league.
I have this
    #include <FastLED.h>
    #define NUM_LEDS 4
    #define DATA_PIN 3

        CRGB leds[NUM_LEDS];

           void setup() {
       FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
   }

       void loop() {
      // Turn the first led red for 1 second
      leds[0] = CRGB::Green;
      leds[1] = CRGB::Red;
      leds[2] = CRGB::Green;
      leds[3] = CRGB::Red;
      FastLED.show( 99 );
      delay(1000);

      // Set the first led back to black for 1 second
      leds[0] = CRGB::Red;
      leds[1] = CRGB::Green;
      leds[2] = CRGB::Red;
      leds[3] = CRGB::Green;
      FastLED.show( 99 );
      delay(1000);
    }

So, I want them to fade from green to red.
led 1 is green, and led 2 is red
I should probably program this in a different way, but I don't know how.
Any ideas are welcome!

You understand that you'll be fading through yellow, right?

At the moment you have become used to working with pre-defined named colours, like CRGB::Red and CRGB::Green.  Those are just symbolic names for combinations of numeric values for red, green and blue.
So by using numeric values and varying them slightly over time you can create fade effects.  I am not personally familiar with that library or class, so I cannot tell you how to do it, but reading the documentation should show you how you can use variables to specify each of the colour components as a single colour.
As for how to fade from red to green - since they are two completely separate colours (they use separate colour channels in the LEDs) there are two main ways of doing it:

Start with red on full and green off. Slowly increase green to get yellow. Then slowly decrease red to get green.
Start with red on full and green off. Slowly increase green while slowly decrease red. At 50% they will cross over.

//start with full red
leds[0].red = 255;

//slowly add green
for( int i=0; i<256; i++ )
{
  leds[0].green = i;
  delay(10);
}

// slowly subtract red
for( int i=255; i>=0; i-- )
{
  leds[0].red = i;
  delay(10);
}


text:
Send AT commands to ESP8266 from Arduino Uno via a SoftwareSerial port
GOAL
From Arduino UNO, send AT commands to ESP8266 via a SoftwareSerial port and receive results.
CURRENT STATUS
I either send AT commands and get nothing back (wiring scheme 1) or I send AT commands and get garbage back (wiring scheme 2).
Using the Arduino as a pass through (as explained in the tutorial listed in the resources section), I can send AT commands. I have found that I can communicate with the ESP8266 at 115200 baud.
This is the results of running AT+GMR:
AT version:0.40.0.0(Aug  8 2015 14:45:58)
SDK version:1.3.0
Ai-Thinker Technology Co.,Ltd.
Build:1.3.0.2 Sep 11 2015 11:48:04

WIRING SCHEME 1
!! I have the green wire attached to pin 3 on the Arduino Uno and the yellow wire attached to pin 2; not 1 and 0 as the picture suggests !!

WIRING SCHEME 2
Same wiring as above, but I have RX and TX reversed. The green wire is attached to pin 2 and the yellow wire is attached to pin 3.
CODE
This is running on Arduino Uno
#include <SoftwareSerial.h>

SoftwareSerial esp8266(2, 3);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Started");

  // set the data rate for the SoftwareSerial port
  esp8266.begin(115200);
  esp8266.write("AT\r\n");
}

void loop() {
  if (esp8266.available()) {
    Serial.write(esp8266.read());
  }
  if (Serial.available()) {
    esp8266.write(Serial.read());
  }
}

RESULTS FROM RUNNING SKETCH
Wiring Scheme 1
Started

Wiring Scheme 2
Started
�����

I have tested the ESP8266 via the instructions listed in the tutorial in the Resources I've Used section below. The ESP8266 works just fine when sending it instructions via the Serial Prompt.
RESOURCES I'VE USED
http://rancidbacon.com/files/kiwicon8/ESP8266_WiFi_Module_Quick_Start_Guide_v_1.0.4.pdf
QUESTION
Does anyone know if what I am trying to do is possible? And if it is, what am I doing wrong?

Try as sugested in the PDF to use arduino as a bypass to the serial (use the connections as in image). After try set baud at 115200 and test it using serial monitor. You need to send \r\n as line ends also. If esp doesn't respond try 9600 baudrate. If you get good output then move to software serial with the working baudrate. You can also try to update the firmware of esp to the latest version if you haven't already.

Can you post the software serial code?

@Personagem, Thanks. I have done that troubleshooting (ie. checking that I can send AT commands by using Arduino as a bypass). I have found that I can communicate with the esp at 115200. I'll try updating the firmware as you suggested.

@Magic-Mouse SoftwareSerial is a library provided by, I believe, Arduino. Thanks for you help on the question but I don't think posting the library here would be helpful.

I know what the software serial library is, i want to se the code where you use the software serial.

Ok i read it again the variable naming made me think that was the ESP8266 library, not the software serial, disregard my comments.

The link you shared is amazing!!!!!!!!!!!!!!!!!!!!!!!!!!

Why did you map ports 2 and 3 via software serial instead of using the built in Rx and Tx pins?

Does anyone know if what I am trying to do is possible?

Absolutely possible :)

And if it is, what am I doing wrong?

SoftwareSerial isn't capable of 115200 baud rate (despite "allowing" this as a setting).  Some reports suggest as high as 57600 is workable, though in my experience 9600 is best for reliability.  How to change the baud rate on the ESP8266 will depend on the firmware version.  I've had success with AT+IPR=9600.  You only need to run this command once (it's a persistent setting).  I'd suggest, based on your description, that this is the most likely culprit that's causing the "garbage" output you describe.
A couple of other notes:

The ESP8266 runs on 3v3, not 5v, so you shouldn't have it directly connected to the digital pins—you need to run through a logic level converter.  Running 5v can fry your ESP8266.
The Arduino's 3v3 output has insufficient current to support the ESP8266 reliably (50mA Arduino vs up to 300mA for the ESP8266 by some accounts)—try running the ESP8266 off a separate supply.  It probably won't affect simple commands like AT but when you try to connect to a network etc. it may cause unexpected device resets.
As noted by others, you need to send \r\n — so make sure your Serial window is set to send both (this is a drop-down in the serial window)

Please note that AT+IPR can sometimes brick ESP8266. More details are at: http://arduino.stackexchange.com/questions/24156/how-to-change-baudrate-of-esp8266-12e-permanently/

Well you may try this:
Start by uploading blink sketch to your Arduino then connect it to your ESP8266 like this: TX-TX and RX-RX.
Now open Serial Monitor and send AT command and see if it responds. If so then you can control it using your Arduino by wiring it back to TX-RX and RX-TX.
PS: Don't forget to set the line ending in the Serial Monitor to Newline or Carriage Return.
Use this code to connect to ESP8266:
#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");
  delay(30);
  while (ESP8266.available()){
     String inData = ESP8266.readStringUntil('\n');
     Serial.println("Got reponse from ESP8266: " + inData);
  }
}

Since the Hardware Serial interface will be busy when connected to Computer, then you have to use another Serial interface to communicate with your ESP8266. In this case, Software Serial comes handy.

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference.  Link-only answers can become invalid if the linked page changes. - From Review

Yes, I guess you're right. I edited my answer.

@KiraSan why delay(30) is required?

@RahulRastogi just for this example, you can use delay to allow the ESP to respond, 30ms is only a random value but in a real life program, you should avoid that and use another mechanism to check for the response.

Does anyone know if what I am trying to do is possible?
It is possible, i've done it with 2 arduinos where one was simulating ESP8266 (waiting for ebay order).
And if it is, what am I doing wrong?
What you are doing is wrong on most levels, but i think you got most sorted out.
An idea is to implement this little fella: Logic level shifter it will save you many troubles later.
On your "WIRING SCHEME 1" you are using the arduino's Hardware serial port to talk directly to the device as if it was connected through a TTL cable or FTDI cable.
This means that the arduino device would in theory read from the hardware when talking too the ESP8266, if you have another arduino or a TTL cable, try and connect it to gate 2 and 3 on the "main" arduino and you should get a similar result as for your example result 2. Since you would that way proxy through the arduino. If not that would be a place to start debugging.
Beside that i could only recommend you in investing in either a TTL 3,3v or a logic level converter. When i got my cable everything worked out of the box.

I had lot of problems as well. In my case problems are almost solved by switching from SoftwareSerial to AltSoftSerial. It seemed that on the Uno the standard software serial library was not working for me. After switching I started to get results back for the first time. (I also used level shifting and external power supply for 3.3V)

And by almost solved I mean - I still get, from time to time, gibberish on the terminal. So even AltSoftSerial isn't a perfect solution.
I was using the ESP-07 with a 115200 bps data rate.

Can you add to your description? It would be helpful to know how you wired the connection between the Uno and the ESP. Thanks!

We found that many of the problems with the ESP - Arduino Uno serial software integration had to do with incompatible baudrate. We created this short tutorial (including a Github library) which you are welcome to test and see if it solves these issues. http://www.instructables.com/id/Simple-ESP8266-Arduino-Uno-Software-Serial-Integra/

Here are a few tips when using ESP8266 Module.

Don't use software serial as it's unreliable especially at higher baud rates.
Always connect ESP module to computer and test all AT commands before interacing with Arduino to ensure that you are working in right direction
Make a power adaptor board to make ESP module compatible with Arduino 5v supply

Also check out this link for more details


text:
Wire over 1ft does not work with sensors SRF02
Im using an SRf02 ultrasonic sensor, and I need to make the wires long to elevate the sensor. They turn on and blink and are able to transmit a signal, yet they are not able to receive a signal. What is the error?

Which interface are you using - UART or I2C?

im using i2c as the interface

I thought you might be. Are you using the internal pullups of the Arduino IO pins or have you added external pullup resistors?

internal, i havent added any resistors

Again, I suspected as much.

Using the internal pullup resistors for I2C is not recommended.  Arduino are very wrong in providing those as the default option and basically "hiding" the fact that I2C needs decent pullup resistors from you.
The internal pullup resistors, because they are so weak (i.e., a high resistance, typically > 50KΩ), do not pull the clock and data lines up adequately, and as such are only suitable for very short connections (in the order of a few inches).  Anything longer and the induced noise and inductance and capacitance of the wires will corrupt the I2C waveform.
I2C requires pullup resistors in the range of 2.2KΩ to 4.7KΩ.  As you can see that is more than 10x the pullup strength of the internal resistors.
For off-board connections (i.e., wires) you want the lower end of that range.  So add a 2.2KΩ resistor between SCL and +5V and another between SDA and +5V and you should find it works much better.

so what do you mean, add the resistor between SDL and V+, i cant just place it in between SDL on arduino and the TX pin of the sensor?

I mean exactly what I say. Connect a 2.2k resistor with one end connected to the SCL pin on the Arduino and the other end connected to +5V on the arduino. The same with the SDA pin.

i uploaded a picture in the original post, is this what you mean?

I don't know, it's too small to make out.

i put a better picture

It's confusing to work out what goes where in that picture, but I think you have it right, yes. It's not exactly a hard concept, there's only two ends to a resistor and I have told you the two places they connect to.

yeah i get what the circuit is supposed to look like, it didnt work btw


text:
MPPT using preassembled 'adjustable' buck/boost IC
This is more of a thought experiment, as I don't know if I'll have the time to work on it.
Items:

Arduino
Homebrew MPPT controller from Instructables
LM2596 Adjustable Buck Regulator

Idea:
Looking at the Instructable, that seems like a fairly interesting and robust circuit, originally developed by one Tim Nolan whose website no longer seems to exist.
I'm somewhat lazy/fearful of messing things up when building from scratch, so I like to get preassembled modules and tinker instead. So, my thought is simple (ish). Looking at the LM2596 module, the output voltage is determined by the setting of the multiturn pot. I'd like to replace that pot with, say, a PWM controlled voltage from an Arduino, which I can then adjust using Tim Nolan's code to achieve MPPT.
So to be very specific, the question is: can I safely remove that pot and use a PWM'd voltage in its place, in order to control the output for MPPT?

No.
The switching frequency of the LM2596 is 150kHz, but the sampling frequency of the Arduino is only 10kHz (on a good day).  You won't be able to adjust the PWM quickly enough to fine-tune the LM2596 output voltage.  The LM2596 uses the 1.23V feedback voltage to change what it's doing.  But the feedback voltage will only change as fast as the Arduino can change the PWM feeding it (and that the RC smoother will allow).
It will be like pushing a shopping cart backwards, blindfolded.  By the time you feel the directional change in the cart, it will have steered off course by quite a bit.  Then you have to compensate wildly to bring it back on course.
The same would probably happen here: the LM2596 would begin adjusting the output voltage to make the feedback voltage come back towards 1.23V.  But the Arduino doesn't respond in time.  The Arduino has to do an ADC conversion, do some calculations, change the PWM, which eventually changes the RC output voltage, which is the feedback voltage.  So the LM2596 changes some more... and even more.  Eventually the feedback voltage does change, but by this time the output voltage has changed significantly.
Another way to look at is that the LM2596 is like another "processor", trying to optimize its own function, output voltage instead of MPPT.  It's running much faster than the Arduino, so there's no way the Arduino can trick the LM2596 into doing what it really wants, MPPT.

This makes sense, I wasn't thinking about the switching vs. sampling frequency. Knew I was missing something. The second answer here seems plausible - using a digital pot instead to replace the trimpot, or feeding it a fixed PWM voltage separately from the output. I might try that and see, but based on your answer direct PWM control is clearly out of the question.

Yes, as Gerben suggested, a digital pot would be ok, because it has the same (nearly) instantaneous response as a passive resistor.  This decouples the Arduino from the response cycle, which is good.  It will be free to measure current and voltage at its leisure (you still have to measure both).  Of course, the software will be different, as you would be changing the digital pot value instead of the PWM frequency/duty cycle.

@Boloar, here is a relevant discussion at EEVBlog.  Reply #6 mentions using PWM+filter to offset the feedback resistor voltage.  This also allows an instantaneous response to be seen by the regulator.  Just make sure the PWM freq is high enough and the filter RC is slow enough that the regulator doesn't see a ripple it needs to correct.  Oscillation, anyone?  :)

The pot is actually part of the feedback mechanism, so you can just feed it a fixed voltage (based on PWM duty cycle). See the second diagram on page 9 of the datasheet
You could however replace it with a digital pot (not necessarily 10k).

Thanks, I don't know why I didn't think of a digital pot. I'll look into both options, :-)


text:
How to send unmodulated IR-Signal via cable?
I need to generate en (extended) NEC signal. I have connected an Arduino with a display-device via an IR cable.
Arduino --> IR-cable --> IR-input of display device
IR-cable:

One plug is cutted and the 3 wires are connected with the arduino.
The arduino should generate NEC Signals, and the display shall react to it. Basically the arduino acts like a wired remote control.
The problem is: There are many tutorials around, that show how to do this with a sensor (e.g by using this library). But none of the tutorials says how to do it with a cable.
I found out, my previous attempts all failed, because I tried to generate a modulated NEC-signal to the display. The display however does not understand it, because there is no device that demodulates the signal. The IR sensor normally does this, which is missing in this case.
e.g.
This is, what an modulated NEC signal looks like:
00 4e ff 61
The library generates the moduled signal (pulse bursts) and this is how it works for IR sensors.
But how do I have to send my IR-command, that the display understands it? How do I send a not-modulated IR signal?
The following graphic demonstrates the issue:

I do not have IR-LED Transmitter, Amplifier, Limiter, Band Pass Filter, Demodulator, Integrator, Comparator....
I just want to create the green Output-signal directly from my Arduino

Does this cable thing have a datasheet?

I have updated my post

There are two major components to an infra-red signal.  One is the high frequency carrier wave signal that pulses the LED on and off.  This frequency has to match that of the receiver and is used with either a high-pass or band-pass filter to filter out ambient IR light and allow it to only react to a real signal.
The second component, and it sounds like this is the one you are interested in, is the on-off pulsing of that carrier wave in different combinations and with different timings to denote binary 0 and 1.
Without knowing what your cable actually is, and we'd need to see a datasheet to get all the proper information, all this is just surmising.
I would imagine that you provide power and ground to the emitter cable, and the third pin is a logical "on/off" signal that enables and disables the carrier frequency to the LED.  That would allow you to send any codes you like as long as you know the timing of the signal.
In the library you link to is all the timing you need in the ir_NEC.cpp file.  The times are defined as:
#define NEC_BITS          32
#define NEC_HDR_MARK    9000
#define NEC_HDR_SPACE   4500
#define NEC_BIT_MARK     560
#define NEC_ONE_SPACE   1690
#define NEC_ZERO_SPACE   560
#define NEC_RPT_SPACE   2250

The actual data format is defined in the sendNEC function:
void  IRsend::sendNEC (unsigned long data,  int nbits)
{
    // Set IR carrier frequency
    enableIROut(38);

    // Header
    mark(NEC_HDR_MARK);
    space(NEC_HDR_SPACE);

    // Data
    for (unsigned long  mask = 1UL << (nbits - 1);  mask;  mask >>= 1) {
        if (data & mask) {
            mark(NEC_BIT_MARK);
            space(NEC_ONE_SPACE);
        } else {
            mark(NEC_BIT_MARK);
            space(NEC_ZERO_SPACE);
        }
    }

    // Footer
    mark(NEC_BIT_MARK);
    space(0);  // Always end with the LED off
}

The mark and space functions take a number of microseconds to perform either an ON or OFF of the PWM signal.  That is somewhat simpler for you, since it is just an ON or OFF of a digital IO pin to control the output of the emitter cable.  So where you have a MARK you turn on the output, then delay for the specified time. For a space you turn off the output and again delay for the specified time.
So you can just replicate the operation of that sendNEC function but with your own output control and timing in it instead of using the functions in that library.

Edit: It seems the cable doesn't need power - just provide the ground connection and the signal connection.  Of course, this is assuming that it isn't just an LED on a wire.  If it is just an LED on a wire then you would need to just use the library you link to as it is.

You probably want to make sure the voltage level of the power wire is the same as the arduino. Otherwise you should buffer the signal.

@Gerben Everything should be made clear by the datasheet that doesn't seem to be forthcoming.

"So you can just replicate the operation of that sendNEC function but with your own output control and timing in it instead of using the functions in that library." This is exactly the point. I do not know how my own output should look like. I don't really understand the difference between "modulated" and "unmodulated"-signals. So how for example does my code 004eff61has to be sent?

Voltage Level of cable and arduino are both 5V

The difference between modulated and unmodulated is that the modulated is a series of pulses of a pwm signal, and unmodulated is a series of pulses of just steady 5v.

I needed the same thing, so I created a library for it: https://github.com/dennisfrett/Arduino-Direct-NEC-Transmitter.
It basically just pulls the pin high and low with the correct timings for the NEC protocol.

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


text:
Olimexino 32u4: Wire.endTransmission() hangs
I'm trying to get a TAE5767 (FM radio) to work. According to this instructable I'm trying it on a 5V-Olimexino 32u4 (Leonardo-compatible) with following code (Arduino 1.6.3):
#include <Wire.h>

void setFrequency(float frequency) {
  unsigned int frequencyB = 4 * (frequency * 1000000 + 225000) / 32768;
  byte frequencyH = frequencyB >> 8;
  byte frequencyL = frequencyB & 0xFF;
  Wire.beginTransmission(0x60);

  Wire.write(frequencyH);
  Wire.write(frequencyL);
  Wire.write(0xB0);
  Wire.write(0x10);
  Wire.write(0x00);
  Serial.println("sending");
  Wire.endTransmission();
  Serial.println("sent");
}

void setup() {
  Serial.begin(9600);
  while (!Serial) {
  }

  Wire.begin();
  setFrequency(89);
}

void loop() {
}

Unfortunately, it only prints
sending

First, I thought I'd damaged my chip, but I'm now using the second with the same result. I've also tried the I2C-Scanner from Nick Gammon, but it prints nothing. I've tried adding 2.2k resistors from SCL and SDA to 5V without success. Does someone has a clue what I can try?

I've did not got it working with Wire. Hence I've implemented a I2C protocol myself using bit-banging and then it works.
Update from 2017-September-16
The problem was not Wire.h but a specialty of the Olimexino 32u4 board. I've only found out by using a Real Time Clock connected to the UEXT port's I2C bus, that I have to switch on the power for the UEXT port by setting D8 to LOW. Otherwise SDA or SCL seem to be pulled down preventing any I2C communication.


text:
Read serial data from XV11 sensor
I am trying to read data from an XV-11 sensor using the description of the format found here https://xv11hacking.wikispaces.com/LIDAR+Sensor.  This is the code I am currently using to communicate with the computer by USB and the sensor with software serial on an arduino uno.
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  mySerial.begin(115200);
}

int count = 0;

void loop()
{
    if(mySerial.available())
    {
      byte in = mySerial.read();
      Serial.println(in, HEX);
    }
}

However, the data I am receiving on the computer is inconsistent with what I expect.  For example, I am expecting a 0xFA byte every 22 bytes, however this only sometimes happens.  Many times extra or fewer bytes appear in the middle of the data.  I am using the 5 volt arduino serial communication, however I have heard that it is still compatible with 3.3 V sensor communication, so I doubt it is the problem.  I don't thinkthe sensor is broken, as it is new from a working unit.

3.3v is "on the edge" of communication with 5v. Also the Ardunoo's TX must go through a level shifter of some form (resistor divider would do) to drop it to the 3.3v of the sensor or you could damage the sensor. Also, you do have the grounds connected together don't you...?

I am only receiving data from the sensor so the arduino tx isn't even connected to the sensor.  The sensor is connected to the arduino 5V and ground pins

Soft Serial is totally unreliable. You may have a better error rate at other baud rates, but you will never achieve the same as a hardware based serial connection.  I'd switch my debugging connection to the software serial, nd use the hardware serial for the XV-11.

The 'Serial' baud rate is too low compared to the baud rate of 'mySerial'. It could be causing you to lose bytes as the Serial buffer overflows, especially if the sensor transmits a lot of values in a relatively short interval. Increase the Serial baud rate to 115200 and see how it goes.


text:
Printing Serial Readings for 2+ Parallax Ping Sensors
trying print values for two sensors, one works the other is 0, any tips on how i can use more than one?
const int pingPin = 10;
const int pingPinz = 11;
unsigned int duration1, duration2, inches1, inches2;

void setup() {
  Serial.begin(9600);
}

void loop() {
  pinMode(pingPin, OUTPUT);          // Set pin to OUTPUT
  pinMode(pingPinz, OUTPUT);          // Set pin to OUTPUT
  digitalWrite(pingPin, LOW);        // Ensure pin is low
  digitalWrite(pingPinz, LOW);        // Ensure pin is low
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);       // Start ranging
  digitalWrite(pingPinz, HIGH);       // Start ranging
  delayMicroseconds(5);              //   with 5 microsecond burst
  digitalWrite(pingPin, LOW);        // End ranging
  digitalWrite(pingPinz, LOW);        // End ranging
  pinMode(pingPin, INPUT);           // Set pin to INPUT
  pinMode(pingPinz, INPUT);           // Set pin to INPUT
  duration1 = pulseIn(pingPin, HIGH); // Read echo pulse
  duration2 = pulseIn(pingPinz, HIGH); // Read echo pulse
  inches1 = duration1 / 74 ;        // Convert to inches
  inches2 = duration2 / 74 ;        // Convert to inches
  Serial.println(inches1);            // Display result
  Serial.println(inches2);            // Display result
  delay(200);                 // Short delay
}

Your problem is in how you are working with the two sensors. At the moment you are triggering both sensors together then waiting for the first one to echo back. Only when that has responded do you then wait for the second one to echo back, and that echo has been and gone already.
Imagine you have two tennis balls. You throw them both at different walls at the same time, then attempt to catch them both. While you are catching the first ball the second one bounces off the back of your head and rolls under the table. That's what's happening with your echos.
So instead you need to treat both sensors completely separately. Trigger the first, then get the response. Then trigger the second and get the response.


text:
Reading Analog values of bluetooth module HC 05
I am working on a project which requires signal strength of a bluetooth TX and RX. what i assume is that in bluetooth module like hc05, there is an antenna receiver which reads the analog signal and then passes it to its ADC to get data in terms of 0's and 1's. But is there any way i can read the analog signal strength of the reveiver antenna directly? Please help

Start by getting the data sheet for the HC05 and reading up on how it works. If anybody has written drivers for the HC05 you may also find useful information there.

Try looking up the datasheet to see if there is a command for signal strength. It's impossible to directly read the the analog value since the signal strength is way too low in amplitude.


text:
Sublime Text Compilation Issue
I've tried searching for this issue but came up empty. Due to the desire to use a better IDE, I installed Sublime Text 3 and Stino. I have installed the Stino package and now have the Arduino menu inside the Sublime Text editor. I have selected the Arduino application folder appropriately. However, when I compile the simple Blink example, I'm presented with the following error. This error comes up when I attempt to compile any Arduino project. Have I forgotten to configure a setting? All videos and tutorials I've seen just follow the same steps as I have and don't seem to include any additional configuration (besides selecting the Arduino application folder).
[Stino - Start building "Blink"...]
[  3%] Creating C:\Users\cketc_000\Documents\Arduino\Blink\Blink.ino.cpp.o...
"C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-g++" -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD  -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=161 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\examples\01.Basics\Blink" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\cketc_000\Documents\Arduino\Blink\Blink.ino.cpp" -o "C:\Users\cketc_000\Documents\Arduino\Blink\Blink.ino.cpp.o"
The filename, directory name, or volume label syntax is incorrect.

[Stino - Exit with error code 1.]

You might need an older version of the IDE. Which version are you using?

@Majenko I am using Arduino 1.6.1. I noticed in the Arduino forums that some were having trouble with 1.6.2 and suggested reverting back to 1.6.1. I can try with a pre-1.6 version this evening. I receive the same error at compilation with both Sublime Text 2 and 3.

As a quick update for anyone who runs into a similar issue (granted, a week later)...
I upgraded to 1.6.5 of the Arduino IDE, making sure to set my Arduino application folder appropriately, and the compilation issue has disappeared. I am able to compile and upload projects successfully.


text:
Send stepper to position and back AccelStepper
At the moment I am working on a code that should send a plateau to a certain position and back. The plateau is being moved by the stepper, in my case a Nema 17 with a Polulu DRV8825 driver. Everything is hooked up correctly.
My goal is to press '4' on the keyboard and that then the stepper moves to a certain position. However, I am not succeeding in this. I am using AccelStepper and at the moment I have the following code:
#include <AccelStepper.h>

AccelStepper stepper(1, 5, 4);

int spd = 1000;    // The current speed in steps/second
int sign = 1;      // Either 1, 0 or -1
int buttonState = 0;

void setup()
{
  Serial.begin(9600);
  stepper.setMaxSpeed(1000);
  stepper.setSpeed(1000);
}

void loop()
{
  char c;
  if (Serial.available()) {
    c = Serial.read();
    if (c == 'f') {  // forward
      sign = 1;
    }
    if (c == 'r') {  // reverse
      sign = -1;
    }
    if (c == 's') {  // stop
      sign = 0;
    }
    if (c == '1') {  // super slow
      spd = 100;
    }
    if (c == '2') {  // medium
      spd = 900;
    }
    if (c == '3') {  // fast
      spd = 1000;
    }
    if (c == '4') {
      //not working, does anyone know how to do this?
      stepper.moveTo(500);
    }
    stepper.setSpeed(sign * spd);
  }
  stepper.runSpeed();
}

Does anyone have tips or know how to achieve this?
Thanks is advance!

You need to call stepper.run() instead of runSpeed, for moveTo to work.

Gerben's comment:

You need to call stepper.run() instead of runSpeed, for moveTo to work.

provides the answer. The updated code is:
#include <AccelStepper.h>

AccelStepper stepper(1, 5, 4);

int spd = 1000;    // The current speed in steps/second
int sign = 1;      // Either 1, 0 or -1

int buttonState = 0;

void setup()
{
  Serial.begin(9600);
  stepper.setMaxSpeed(1000);
  stepper.setSpeed(1000);
}

void loop()
{
  char c;
  if (Serial.available()) {
    c = Serial.read();
    if (c == 'f') {  // forward
      sign = 1;
    }
    if (c == 'r') {  // reverse
      sign = -1;
    }
    if (c == 's') {  // stop
      sign = 0;
    }
    if (c == '1') {  // super slow
      spd = 100;
    }
    if (c == '2') {  // medium
      spd = 900;
    }
    if (c == '3') {  // fast
      spd = 1000;
    }
    if (c == '4') {
      //not working, does anyone know how to do this?
      stepper.moveTo(500);
    }
    stepper.setSpeed(sign * spd);
  }
  stepper.run(); //You need to call stepper.run() instead of runSpeed, for moveTo to work. – Gerben
}


text:
The 3.3 volts of the USB To TTL
I'm using ESP with USB to serial converter (D-SUN) is it possible to use the 3.3 volts of the USB instead of the Arduino Uno?

I don't know what that adapter is (a link would be nice, or at least the chip number it uses) but in general the 3.3v on a USB TTL adapter can only provide a small current. For instance the FT232RL can only provide up to 50mA at 3.3v. That may not be enough current to drive the RF circuitry of the ESP. The early Arduinos used the FT232RL chip for the USB interface and it was the 3.3v from that which was used for the 3.3v header on the Arduino. This was somewhat of a failing with those Arduinos since the 50mA limit was a real problem when people started using more 3.3v devices. That was one of the driving forces (as well as cost) in the decision to switch to an MCU for the USB interface.
So to be on the safe side I wouldn't use the 3.3v from the USB adapter to power the ESP. You are better using a 5v to 3.3v regulator circuit driven from the 5v of the USB. And yes, that could be a whole Arduino, or build your own on some stripboard.

From my experience using the USB to TTL adapter will not work very well. I got some code on my ESP somehow, but could not get it working reliable. So I ended up powering it from an additional source.


text:
How to convert frequency into db
I have made an Arduino circuit which outputs in terms of frequency(hz) and I need output in terms of db as well
So is there any formula which can I apply to convert frequency hertz to db or is there any reference link to understand the conversion process.
Any help will be highly appreciated

Sad to see both answers reversed the required capitalization of "dB"

My answer was written on my tablet that capitalises the first letter of a sentence for you automatically. Too much haastle to change it for just one symbol...  however the question doesn't have any capitalization, correct or otherwise ;)

dB is volume (sound pressure), frequency is pitch. The two are entirely different concepts and can't be converted. A bit like you can't convert the roundness of a doughnut into blue. Roundness and blueness (it has blueberries in it by the way) are two different properties of the doughnut.

dB it self just express in a logarithmic scale a ratio between two values and it self is unit independent (because is a ratio). Just because the most common uses of dB scales are linked to intensity or power doesn't necessarily mean that can't be used to represent other ratios of different types of quantities. Or at least I couldn't find any definition that restricts the use of dB in such cases. The formulas to express such ratio are present here you just have to figured it out what is really your ratio.
So, for example, if you have some kind of sensor that somehow the output is a frequency, let's say something like
f(x) = ax + f0  [Hz]

There is no reason why you can't express this function in a logarithmic ratio scale using dB something like, related to f0 or f(x=0)
L(x) = 10*Log10*(f(x)/f0) [dB]

which would give you the represented dB output of your equation with respect to x.
But since we are in arduino stackexchange and talking about sensor, the common use of dB in electronics is the representation of power ratio or (the more common) a frequency response of a circuit(or system) that is represented by a Bode Plot, so I advise you to really take a good look at both links and try to figure what you really are asked to represent.

Great answer! Not many would have thought about the real definition of dB.

Decibels (Db) are calculated using amplitudes and by definition decibels are the measurement of sound intensity or power level of electrical signal by comparing it with a given level on a logarithmic scale, which is independent of frequency.
You can measure the decibels though if you know the amplitude of your source which i'm guessing is ~5v .


text:
Connecting via serial with Arduino comand line
Since inotool is dead, I'm trying to transition over to Arduino's built-in command line tool.
It seems largely equivalent, but the one feature it seems to be missing is a serial interface. e.g. Running ino serial would open a simple serial interface to the Arduino, providing invaluable debugging info from any Serial.print() statements.
How is this accomplished with the current Arduino command line tool?

You may want to just use some other command line serial solution.

@ChrisStratton, Such as...?

Well, I use an ever-evolving custom solution, so won't be of much help with that...

What OS are you using? Putty, screen, minicom ...

I ended up simply switching to ano.

If you are using linux, as I guess, you can look at this archwiki page. Even if is a wiki relative to archlinux OS some informations explained are LinuxOS independendent.
For your needs, you can use screen command. Here is an example: remember to substitute the serial port with the one wich arduino is connected (usually /dev/ttyACM* or /dev/ttyUSB*) and to specify the right baud rate.
screen /dev/ttyACM0 9600


text:
Using arduino shield seems to break serial.print and uploading new code?
Hello Stack Exchange Community!
For an arduino project I am working on, I modify the SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 to support DSSCircuit's I2C Master Library (https://github.com/DSSCircuits/I2C-Master-Library). This is to combat the known issue of arduino's Wire library to often get hung up while trying to run the EndTransmission function, and it works some of the time. Code was from Stack Exchange community (Modifying Arduino IMU library to rely on DSSCircuit's I2C Master Library).
#include <I2C.h>
#include "FIMU_ADXL345.h"

ADXL345 acc = ADXL345();
int x=0,  y=0, z=0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  I2c.begin();
  delay(100);
  acc.init(ADXL345_ADDR_ALT_LOW);
  delay(100);
  Serial.print("Is ACC OK?: ");
  Serial.println(acc.status);
  Serial.print("Any Error code?: ");
  Serial.println(acc.error_code);
  Serial.println("********Print all register current values********");
  acc.printAllRegister();
  Serial.println("********END register print******");
  Serial.println(acc.getRate());
}

void loop() {
  // put your main code here, to run repeatedly:
  acc.readAccel(&x,&y,&z);
  Serial.print(x);
  Serial.print('\t');
  Serial.print(y);
  Serial.print('\t');
  Serial.println(z);
  delay(500);
}

Also, the SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 libraries must be modified from using Wire.h to I2C.h .
// Writes val to address register on device
void ADXL345::writeTo(byte address, byte val) {
  I2c.write((uint8_t) _dev_address, (uint8_t) address, (uint8_t) val);
}

// Reads num bytes starting from address register on device in to _buff array
void ADXL345::readFrom(byte address, int num, byte _buff[]) {
  I2c.read((uint8_t) _dev_address, (uint8_t) address, (uint8_t) num);  // request 6 bytes from device
  if(I2c.available() != num){  // device may send less than requested (abnormal)
    status = ADXL345_ERROR;
    error_code = ADXL345_READ_ERROR;
  }

  int i = 0;
  while(I2c.available())
  {
    _buff[i] = I2c.receive();    // receive a byte
    i++;
  }
}

I'm using an arduino shield, and it prevents me from uploading the code at the same time as the shield is on. My best guess is that the shield is continually triggering the device to restart in a way that does not harm performance but harms upload of code.
Sketch uses 8,244 bytes (25%) of program storage space. Maximum is 32,256 bytes.
Global variables use 600 bytes (29%) of dynamic memory, leaving 1,448 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

When I open the serial port and let it run for a few seconds, it shows no current register values, and returns 0 for x y -- as expected.
Is ACC OK?: 1
Any Error code?: 0
********Print all register current values********
0x00: B00000000
0x1D: B00000000
0x1E: B00000000
0x1F: B00000000
0x20: B00000000
0x21: B00000000
0x22: B00000000
0x23: B00000000
0x24: B00000000
0x25: B00000000
0x26: B00000000
0x27: B00000000
0x28: B00000000
0x29: B00000000
0x2A: B00000000
0x2B: B00000000
0x2C: B00000000
0x2D: B00000000
0x2E: B00000000
0x2F: B00000000
0x30: B00000000
0x31: B00000000
0x32: B00000000
0x33: B00000000
0x34: B00000000
0x35: B00000000
0x36: B00000000
0x37: B00000000
0x38: B00000000
0x39: B00000000
********END register print******
0.10
0   0   0
0   0   0
0   0   0
0   0   0
0   0   0
0   0   0
0   0   0

Problem is, when the arduino shield is put on during serial transmission the loop will stop, and the device will stop outputting any information to serial even if the shield is taken off. This also usually disallows the uploading of new code even if the shield is off, and the only solution I've found to sometimes work is waiting a few minutes, disconnecting the arduino from computer to kill its power source, and restart the arduino IDE.
Can someone help me understand why this happens?
Thanks Community!
John Doe

Which shield are you trying to use? Could you add a photograph?

@JohnDoe can you confirm to us the connection diagrams you have? Also the sample output you get is with the shield connected to arduino or without? I see a strange thing because register 0x00 is fixed according to datasheet and should be B11100101. Have you tried the old libraries to see if sensor is not broken?


text:
How to install a library for a single project
How do you install an Arduino library so it's only available for a specific project?
Say I have a codebase located at /myproject, and I want to install libraries at /myproject/lib/somelib. I can't find how to make arduino myproject.ino find the libraries under ./lib.
Googling "installing Arduino libraries" only finds me examples of installing libraries globally (and through the GUI no less), which is horrible practice and guarantees version conflicts.
When I used ino, it supported a local ./lib directory, but I can't find any equivalent feature in arduino.

I don't think you can "install a library for a single project". A workaround is to simply copy all the header and source files of the library into the sketch folder, as if they were other source files.

Doesn't #include lib/somelib/libheader.h work?

@Gerben, Not for me. Arduino only seems to be able to find includes in the current directory or in one of the expected system library paths.

I ended up switching to ano, which supports a local lib directory.

You want to switch to my UECIDE for that functionality. You can then place libraries inside a folder called libraries in your sketch folder.
You also get the benefits of a much improved IDE :)


text:
ATtiny85 + HC-05 + Oled = smart watch
I am using an ATtiny85 for making a smart watch. Bluetooth module HC-05 with ATtiny85 pins PB3->TX, PB4->RX and it works. Secondly I have connected a 0.96" OLED on PB0 (SDA) and PB2 (SCL) and this is also working perfectly. But once I combine both things, it doesn't work.

Why did you decide to use an AVR without a hardware UART?

@IgnacioVazquez-Abrams: suggest me an alternate 8 pin micro-controller with I2C and UART hardware.

@Vipin Why 8 pin?

@IgnacioVazquez-Abrams Probably because he's not aware of the excellent offerings by Microchip in 8-pin MCUs with hardware I2C and UART, such as the PIC12F1840 - though why you'd cripple yourself with just 8 pins is beyond me when you can get a PIC32 in a 28-pin QFN package that is smaller than those old fashioned chunky DIP things and about 100x more powerful...

@Majenko: to keep the size of overall device as small as possible. I just need to hook 1 oled (two pins over I2C) and 1 bluetooth module (two pins) thats it. One more thing, should be able to hold glyph( font), flash > 8kB


text:
How to program ESP8266 with Arduino Uno pins 0 and 1?
I know that I can connect an ESP8266 with an Arduino Uno at pins 0 and 1, which is Rx and Tx, and enter commands manually in the serial monitor the commands to test it.
I had tried to use software serial and altserial to connect an ESP8266 to other pins, but it was error prone at sometimes.
My question is that how to use an automated program to control an ESP8266 when I connect the ESP8266 with an Arduino Uno at pins 0 and 1.
Sample code would be helpful.
Edit: I have added a simple program to blink led when it get response but it is not working. could you look at it too?
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(3000);
  pinMode(12,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(12,LOW);
  delay(2000);
  Serial.println("AT");
  if(Serial.available())
  {
    digitalWrite(12,HIGH);

    while(Serial.available())
    {
      char c=Serial.read();
    }

    delay(2000);
  }

}

What are you trying to achieve here using esp8266 and arduino? You said connecting using software serial was error prone. What do you mean? Were you getting junk values in the serial monitor? or something else.. please be specific. There could be a lot of issues related to power supplied or the buad rate or even loose connections...

Remember that the TX pin on the arduino puts out 5v logic levels, while the ESP8266 require 3.3v logic level. You can create a buffer using a simple diode (cathode on the Arduino TX pin, anode on the ESP RX pin)

The problem with using pins 0 and 1 is that they are also used to communicate with the PC for both serial monitoring and programming.
If you attach an ESP8266 to pins 0 and 1 chances are you will fail when uploading a new sketch - you will have to disconnect the ESP8266 every time you need to upload a new sketch - that is why most people use SoftwareSerial.
Also if you are using pins 0 and 1 for the ESP8266 you cannot then also use the serial monitor to see what is going on with your program and thus be able to debug it when it's not working.
If you're OK with both those caveats then by all means go ahead and use pins 0 and 1.  You use it in exactly the same way as using SoftwareSerial but you don't need to define an object first - you just use the pre-defined Serial object.
One important thing to remember with the ESP8266 is that the default firmware's AT command interface is ropey as hell.  It's most likely that which is tripping you up not your SoftwareSerial.  You have to get the timing right with it from what I remember - always impose a 1 second delay after sending each command - it's the delay that terminates the command, not a carriage return (although I think a CR is also needed). Maybe later versions have been improved since, but that's one really good reason to directly program the ESP8266 and implement your own protocol for communicating.  My ICSC library is a good candidate for communicating between the two - it runs on both the ESP8266 and the Arduino.

I tried a simple program to send AT commands via serial which is connected to esp8266. I added an led to blink when i got the response so that i could know it is working. But the led is not blinking.

i have added it in the question.

@abdulrahuman You're program is expecting a response from the ESP module before the serial command has had a change to get there and be processed. Your whole serial reading methodology is flawed.

could you please be specific about where in the program should I change. I am beginner. A sample code could help better.

@abdulrahuman http://hacking.majenko.co.uk/reading-serial-on-the-arduino

Nice article majenko. Now I think i got what I am missing. I will try it and give you results. Thank you so much.

I tried your program. But it didn't work. It gave the same results as before

You need to use Arduino IDE serial Monitor Window for ESP8266 setup instead of using TTL or Serial Converters. I successfully Setup My ESP8266 Module by using just Arduino Nano and Arduino IDE Serial Monitor.
    #include <SoftwareSerial.h>
SoftwareSerial softSerial(3, 2); // RX, TX

void setup()
{
  uint32_t baud = 9600;
  Serial.begin(baud);
  softSerial.begin(baud);
  Serial.print("SETUP!! @");
  Serial.println(baud);
}

void loop()
{
    while(softSerial.available() > 0)
    {
      char a = softSerial.read();
      if(a == '\0')
        continue;
      if(a != '\r' && a != '\n' && (a < 32))
        continue;
      Serial.print(a);
    }

    while(Serial.available() > 0)
    {
      char a = Serial.read();
      Serial.write(a);
      softSerial.write(a);
    }
}

Necessary AT Commands


text:
Arduino in-built LED is not turning off
I have an Arduino Uno whose LED, which is connected to  pin 13, is not turning off and it always stays on, and it annoys me.

Touching any exposed pins turns off the LED after removing my hands from the pins it turns back on slowly.
However it works perfectly with the programs. This program does turn the LED off and it stays that way while the program is running.
void loop() {
  digitalWrite(13, LOW);
}

When I upload other programs that don't use pin 13 then it stays on again. How can I fix this?

did you set the mode of the pin 13 to output (pinMode(13, OUTPUT);) in your setup function?

When i want to use pin 13 only then i set it as output else its not even defined any where in the code

See: Uno pin 13 LED mysteriously always ON at 0.14V unless pinMode OUTPUT

If you don't tell it to turn off, it behaves "as it wants". If you don't write a 0 on its pin, how can you force it to stay shut down?
If you want it to be in an off state, force it: in your setup function write
pinMode(13, OUTPUT);
digitalWrite(13, LOW);

No need to refresh it every loop, just in the setup.

Yeah i know. that was the example i am giving to tell it behaves that way when the pin is not defined/set. Means i have not set pinMode(13,OUTUPT/INPUT); and still it stays on.. but when i do define it with pinmode than it works the way it supposed to work

Yes, that's because if you want the board to do (or not to do) something you have to explicitely say it. Otherwise you will have a behavior that can change between runs

i have another arduio uno who doesn't behave like this one.. its led stays off.

Again, " you have to explicitely say it. Otherwise you will have a behavior that can change between runs". If you don't tell it to pull it down, it will be in a floating state. Floating means that no one knows what state it will have. So pull it down. Or solder a resistor (any value above 10k are fine) between the 13 pad and ground. Or place a resistor of the same value in the header between pin 13 and ground. But you have to set a value

You could try to actually remove the LED with a soldering pen... I haven't tried it however, so you could end up disabling pin 13 (or worst).

That's my last option..

As I referred to in my comment on the question ( http://arduino.stackexchange.com/questions/17675/uno-pin-13-led-mysteriously-always-on-at-0-14v-unless-pinmode-output ) this behaviour is normal because of the op-amp they use to drive the LED. The output state is undefined if the pin is configured as an input, and the op-amp may or may not turn on the LED. To be sure, configure the pin as an output. Soldering a resistor or removing the LED seems an overkill. Define the pin as an output if it is not used for anything else, and write LOW to it.

@AkashKumar you could just put a small square of electrical tape over it, which is also temporary. Don't overthink it!


text:
arduino uno external power supply
I have an arduino uno which is powered by batteries. I have 6 AA-Batteries (1,5V each) connected to Vin and GND.
Thats cool because I don't have any cables and works pretty good.
The reason I need 6 AA batteries is, that I have a SIM900-module connected to my arduino uno. My USB Port (5V and 500mA) and my standard external power supply (9V and 1A) doesn't deliver enough current for the SIM900. But with the batteries the SIM900 gets enough power (current).
But there is the problem, that the batteries get sucked empty pretty fast and i don't want to exchange them every day. :-)
I searched for an power supply which can deliver 3A with 9V and found one. But i'm not sure if the arduino uno can handle that input via the on-board power-jack? The reason I want a 3A power supply is, that some users on the internet say that the sim900 sometimes uses more than the maximum current written in the documentation (which is 2A).
I'm an electronic noob.
So is there a risk if I try to use the 9V-3A power supply?
Does the arduino only pull the power it needs? So when it needs only 900mA, it only takes 900mA even if the power supply can deliver 3A?
As far as I know, it should work, because the batteries deliver as much current as the arduino (ad sim900) needs. So the batteries don't have an ampere limit, right?

I believe the Arduino uno is rated for up to 12V on VIn, sparkfuns website should have the spec. If it is 12V then you are OK.

The Arduino itself has a limit of about 800mA. That is imposed by the voltage regulator that converts the incoming voltage to 5V.
If you need more than 800mA then you need to provide your own regulated 5V power source and feed it in to the 5V pin (not VIN).
Suitable power sources are mobile phone chargers (modern USB ones).  They generally come in multiples of amps.
And to answer your theory question - the current is the maximum that the supply can provide. It's the voltage that is fixed and the current varies depending on the load.