Arduino Mega 2560 as ISP for ATTINY2313 / ATMEGA328P

This worked for me dude :)

See this:

http://www.instructables.com/id/Bootloading-ATmega328-with-Arduino-Mega2560/?ALLSTEPS


It depends on the architecture.
Assuming AVR (8-bit Arduino) then it will queue the second interrupt until the first is finished.
It works by setting a flag in a register at the moment the interrupt occurs. Then between instructions it checks that flag and executes the associated interrupt routine. If an interrupt is in progress at the time the flag still gets set, but it is unable to check the state of that flag until after the current interrupt is over and normal execution occurs, at which point after the next instruction is completed it checks the interrupt flag statuses and runs the second interrupt routine.


For LED displays, I advise using a MAX7219.

This circuit:

can manage up to 8 digits (7-segments + 1 LED for DP or colon separator) or up to 64 LEDs
needs only 3 pins to manage display
can be daisy-chained if you need to interface with more than 64 LEDs
requires only 1 resistor to be fully functional
is easily supported on Arduino with this library

I have used it in several circuits and happy with it.

Note that there also other libraries that support this circuit but I haven't used them.

This circuit has only one downside: its price (about $10 each); but the price is counter-balanced by its simplicity and the fact you don't need any additional component (e.g. transistors) besides a simple resistor.


How compile an Arduino program for a desktop PC

If you want to run the Arduino sketch on your desktop, you just have to
implement the Arduino core library for your PC.

It may not be as bad as it sounds. If your program makes only minimal
use of the Arduino core, you may implement only the parts you really
need. For example, this partial implementation is enough to run your
program:

#include <cstdint>
#include <iostream>
#include <unistd.h>  // for usleep()

using std::cout;
using std::endl;

#define INPUT_PULLUP 2

void pinMode(uint8_t, uint8_t) {}

uint8_t digitalRead(uint8_t) { return 0; }

void delay(int t) { usleep(t * 1000UL); }

struct {
    void begin(int) {}
    template<typename T> void print(T x) { cout << x; }
    template<typename T> void println(T x) { cout << x << endl; }
} Serial;

int main()
{
    void setup();
    void loop();
    setup();
    for (;;) loop();
}

I tested this on Linux, by simply appending your program right below
this. If you are using Windows, you will have to replace the usleep()
function with the appropriate Windows call (and <unistd.h> with the
appropriate header). The serial stream goes to the standard output. You
may redirect it to the USB serial port if you wish (trivial to do in
Linux, I assume it should be doable on Windows). You may also want to
replace digitalRead() with something that simulates a more realistic
user interaction.

Keep in mind that the sizes of the basic data types can be different on
the Arduino and on the PC. On an AVR-based Arduinos, int and pointers
are 16 bits while long is 32 bits. This is an “IP16” data model. An
ARM-based Arduino would typically be ILP32, whereas a 64-bit PC is LP64,
unless it runs Windows, in which case it's LLP64. This can make a
difference, especially if some of your calculations are prone to
overflow with the smaller data models.

Edit: I recently stumbled upon NCORE, a native core for
Arduino. It may be a good fit for what you are trying to do.
From the page description:

  The native core allows you to compile and run Arduino sketches on the
  PC, generally with no modification. It provides native versions of
  standard Arduino functions, and a command-line interpreter to give
  inputs to your sketch that would normally come from the hardware
  itself.


Communication between 2 Bluetooth modules

println prints the int variable c as string "100" with /r/n at the end. And you read it as bytes with read and print the bytes as numbers with new line at the end. So you get ascii values of 1, 0, 0, \r and \n.

use write() to write a byte to Bluetooth and to Serial Monitor


System Is not Functioning Error. Windows XP, Arduino Uno R3, C# Listen SerialPort

I assume that by "USB" you mean "USB-to-serial adaptor".

Try running the same code without any serial communications, just have an LED do the equivalent of printing, and power it from a good power supply. If it runs for more than five hours, the problem is with the USB adaptor and/or your PC (Windows XP? Really?), and hence not relevant to this forum.

If the code crashes, then maybe you have a marginal board, or there is some other environmental factor that's giving you trouble. The code looks OK on first glance.


Nano onboard "test" LED blinks when powered via 5V pin

So, as per the comments on the question here's what I think happened:

That "test" LED lights briefly when the board is first powered on, indicating I suppose that it's booted and setup() is either complete or about to run.

It also lights briefly when the reset button is released.

In the sketch I'm using one of the digital pins is connected to RST -- the arduino is being controlled via UART.  I have swapped some of the pin numbers and wiring around, so I tried leaving the one driving RST low instead of high and indeed, this seems to be the issue: It's resetting at ~1s intervals.

(I honestly believe I checked this before by removing all connections, but since I did not note that in the question, perhaps I never did...)


How to burn arduino bootloader on SAMD21 chips using J-Link mini

The Atmel EDBG would work for Arduino Zero since that has the EDBG chip. With Jlink, you can use Atmel Studio. Once the Jlink is connected to the chip via the 10 pin SWD header, goto the programmer option in Atmel Studio, select the chip and programmer and burn your firmware with the selected programmer. You can follow a tutorial here which walks through it.


No valid serial ports for Arduino UNO on Mac

Have you hooked up your Arduino prior to pulling down the tools>Serial Port menu? I only see the port for my Arduino listed when it's actually connected and running. (And it's never one of the bluetooth ports.) I don't have my Arduino with me at the moment so I can't tell you exactly what it is.

Also note that on my MBP (running 10.9.4) I have to be sure to plug the USB cable into the CORRECT USB port. The other port maps to a different port in the list of serial ports.


Simplifying code, getting invalid conversion from 'const char*' to 'char*'

The function declaration

void publishTankValveStatus(bool demandStatus, char topicToPublishTo)

declares topicToPublishTo as a char, that is, as a single character instead of as an array of characters that is constant.

Change char to const char * to say that  topicToPublishTo is an array of characters that is constant.


Is it possible to extract the firmware of an Arduino BLE or IoT board wirelessly?

Technically, the firmware can read its own application section, but it won't send it to you wirelessly (or via any interface) if such a feature isn't implemented in that firmware. If you were to implement the firmware yourself, you can do (almost) anything. But if it is a third party firmware, this will not be possible.
The reason this works with arduinos and avrdude is, because firmware up- and download are implemented in hardware (ISP, works without a bootloader).


Object can't get the right value of its property

My guess: controller_right.Motor = motor_right; makes a copy of motor_right. So you don't have the same class instance.

Basically Controller controller_right; calls default constructor which includes also default constructor for the StepMotor. And later all variables are copied into it by using default assigment operator, but still, it's not the same instance.


How to wire Christmas lights with LEDs to use for Arduino Project?

Here is a string of Stripleds operated from a CPU 12V supply with built-in double-sided tape under the hand rail in one of my homes. Red downstairs and blue upstairs.

Now define your input and output attributes to modulate the current.


I have a page about I2C. The speed of I2C depends on a number of things, such as the I2C clock (which you can change) and also how many data bytes are in a "packet". There is a fixed overhead of the device address in each packet.

A broad rule-of-thumb would be around 4700 bytes per second for a single-byte payload at the default clock rate. You may also need to spend time asking for a reading. I haven't read the datasheet (which you didn't link).

The datasheet for the MPU6050 may give you more information about how fast it can respond.


I have done some Googling across the web and it turns out that this can be caused by a couple of things:

Incorrect wiring.
Wiring of LCD backwards (ie 1 to 16 and 16 to 1).
Faulty wiring (ie broken cables & dry joints).
Incorrect initialization of the LCD.
Buggy software.
Damaged screen.

The LCD screen that you have is a based on the Hitachi HD44780 chipset. It is the most common interface for text-based LCDs. It can be identified by the 16-pin interface. I2C is the next most common interface and is distinguishable as it has a 4-pin (sometimes 5-pin) interface.

Lets assume that your screen isn't damaged. From the details in your question, it sounds like your contrast is working just fine. The list above can be shrunk to just 2 things: bad wiring and/or bad code. Lets eliminate both of those by using known working software and known working circuit.

Arduino has an LCD library with example programs. Details for this library, including a wiring diagram, can be found over at the Arduino site in the Reference section. I use these example sketches to test my wiring connections before I write my own program. I recommend using the Autoscroll example.

Schematic:

These diagrams are from the Arduino Autoscroll page. I highly suggest that you read this page thoroughly.

The code can be easily uploaded into your Arduino, through the IDE, by going into File > Examples > LiquidCrystal > AutoScroll, then Sketch > Upload.
You should see the sketch print the characters 0 to 9 on the top line (with autoscroll off), then moves the cursor to the bottom right (turns autoscroll on,) and prints the characters 0 to 9 on the bottom line, but as it prints each character the display should move one to the left.

If you get this example program to work then you know that you have a working LCD and also that your wiring is OK as well.


Arduino serial communication input string checking

First, you declare an array of 4 items and provide an initializer for 3. Don't know how it can even compile, maybe it is tolerated but in doubt

String [] array = {"hey","jude","jane","foo"};

Also, your serialEvent function appends \n to the string. Even if you receive string jane, you will compare jane from array with jane\n from serial

char inChar = (char)Serial.read();
if( inChar == '\n')
   stringComplete = true;
else
   inputString += inChar


Is it possible for a HC-05 Bluetooth module to have multiple slaves

After some research, it looks like multiple slaves aren't possible with this particular module.

According to Wikipedia the Bluetooth technology allows a master to communicate with 7 slaves, but this option isn't implemented in the HC-05.


Driving numerous chips from 2 separate SPI connectors w/ Arduino Micro

The micro only has one SPI bus. It is SCK/MISO/MOSI. You may want a second one, but you don't have one.  You can't magic one up out of thin air.

You could emulate one in pure software (bit-banging) but it won't be anywhere near as efficient as using a real hardware one.

Why do you feel you need to have two independent buses anyway? What are you wanting to achieve that you can't achieve with a single shared bus? That same bus can quite happily appear on multiple connectors.

One thing to note with your strategy: Ribbon connectors and SPI don't mix well together.  There is a lot of crosstalk and capacitance in a ribbon cable that high speed serial communication really doesn't like.  If I had to use ribbon cable for SPI communication for anything longer than a couple of inches I would use twice as many connections and interleave ground between each signal.  That is what the ribbon cables for later IDE drives in PCs used to get higher speed, more reliable, communication down ribbon cables.


I2C master/slave maximum requestEvent message size

The I2C protocol itself does not have a transmission size restriction. But the implementation in the Wire library only reserves a specific amount of RAM for the buffers. This site mentiones 32 bytes for normal Arduinos (couldn't find the source code currently) and I found 128 bytes for the ESP8266 in the source code.

You cannot have unlimited message length, since the buffer has to hold the whole message and the RAM on normal Arduinos is very limited.

But you can make the buffers of the libraries bigger by changing the corresponding defines in the header files to a bigger value. Keep in mind, that the actual used memory space is with a factor 2, since the buffer size gets used for both send and receive buffer.

If you need bigger messages, than is fitting in the available RAM, you should either change to a board with more RAM, or develop a way to process one part of a message, deleting it and then process the next part (multi part message). Though that raises the question, why the messages have to be that big in the first place.


If memory serves, the clock speed of an arduino Uno is 16Mhz. Some are faster, some much faster and a few are slower.

Most assembler instructions take around 1-3 clock cycles. A few take more. Assuming an average of 3 ticks per instruction, that translates to executing over 5 million instructions per second.

So, unless your motor is approaching supersonic speeds, the arduino should be able to "keep up" with polling your motor's sensor in your loop() function.

If you are doing a few other things in your loop, you might consider using an interrupt to trigger some code when the motor "activates" the sensor. In this case you will unlikely need to worry about the speed of the CPU at all. When using an interrupt, you do not need to worry about polling the state of your sensor inside the loop() function.

Always remember to keep the code in your interrupt service routine as short and fast as possible. In this case, probably you would just turn off the motor and return when the interrupt is triggered.

Having said all of that, you will still need to do some work to get the most appropriate implementation as only you know what other things you need to take into account at this time.

One other thing to note is that a single high level instruction will normally equate to more than one assembler instruction. Even a simple statement like int x = 1000; will be more than one assembler instruction and thus take more than 1 clock tick. However, if memory serves, the individual instructions generate to execute x = 1000 will all take just one clock tick.

Others will vary the amount of instructions that are generated to execute them. For example

float x = 1.0;
x = x + 2.0;

will likely take more instructions to execute than it's integer counterpart:

int x = 1;
x = x + 2

I hope this helps and enables you to try controlling your motor via Arduino. If not, you can always ask a more specific question later.


Arduino IDE loses programmer after installing Visual Micro

Uninstalled and installed 1.9.0 as I heard that fixes the launch time (it does). I'm aware it's beta but it fixed my issue. I assume reinstalling 1.8.5 would've also gotten me my programmer back.


Connecting Arduino to PC through Slimline SATA instead of USB?

No, there is no way of connecting an Arduino to a SATA port. You require USB or UART. SATA is a specific dedicated port, whereas USB is, as the name suggests, Universal. So USB can become SATA but SATA can never become USB.


In short:
Once you shutdown an Arduino, every variables on it, which have been calculated by the sketch, are lost. That is because they are stored in RAM, which is not able to store things without power. That is not the problem of EEPROM: values stored there will be available on reboot, and won't need to be calculated again.

This can prove useful is your device is allowing a user to store presets: so a configuration of the program. If this configuration, which can be for instance variables affecting the program behavior, is stored in RAM, it will be lost on next reboot. On the other hand, a value stored in EEPROM during the first execution (entered by user for instance) will still be available on next reboot, if you took the time to write it (on the first run) and to read it (on the second run). Just like saving and then recalling a preset.

Beware that EEPROM does not like to be written too many times and wear out, so you should keep that to a minimum (values that really need to be restored on reboot, and cannot be calculated at this time).


"Soft WDT reset" stack error: RFID-RC522 with NodeMCU

can you also try to increase the serial boud rate to fe. 115200 instead of 9600?
In some cases I had some issues with 9600, because some buffers were not cleared fast enough and forces some WDT resets.

Cheers,
Jorgen


Update button state in Blynk app through the code

BLYNK_READ() is documented as:

  BLYNK_READ(vPIN)

  BLYNK_READ defines a function that is called when device is requested to send it’s current value of Virtual Pin to the server.

That means it is called when the app or the Blynk server requests a state from the hardware/sketch, such as when the app first connects or reconnects to the Blynk server, or when the hardware reconnects to the Blynk server due to some network problem.

But if you just want to update the virtual pin V1 at an arbitrary time in your sketch, just call:

Blynk.virtualWrite(V1, pinValue);

at the point in your code where you want to "change" the button's current state. Not in the BLYNK_READ() function, but in your main code, such as:

[...]
else {
  // a lot of code here
  pinValue=0; //here i set pinValue to 0 again in order to return to mode1
  Blynk.virtualWrite(V1, pinMode);
}
[...]


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

You can control as many SPI devices as you can set the CS line for. You can even control all the CS lines from a SPI device. A SIPO register will help a lot there.

However you are probably better off using a proxy board to actually connect to the sensors and then connecting the mega to the proxy to communicate the measurements using a connection that is more robust over long distances.


How to interpret analog values sent to Arduino from line scanner?

First, a preliminary note: according to the datasheet, the only time you
need a delay in your program is after reading the whole array and before
sending the next sync pulse. All the other timing requirements are
shorter than a single CPU cycle of your Mega, so no need to add extra
delays.

  the camera didn't move so I assume that it should give back similar
  numbers.

Similar: yes. Identical: no. You expect noise to make every reading
slightly different, and you also will have variations due to uneven
timing of your program (e.g. the timer interrupt kicking in from time to
time).

  is there a way to determine what these numbers mean?

They are proportional to the amount of light collected by each pixel.
That's about all you know about their meaning.

  Is there some way of turning analog signals into color pixels?

No. This is a B&W camera.


How is AVR Assembly in Eclipse or at Linux command line done?

If you don't mind using make, I'd recommend copying the Makefiles from ChibiOS. For me it works quite well and it's much more aligned to my daily experience with Linux.


How to control Arduino robot wirelessly?

A 13 year old programming an embedded device? Good luck to you, if you conquer it you will be years ahead of your age group.

What you need to understand are the fundamentals; how can you transmit a 'pot' over an XBee? That is an electronics question, start there. You will find that another arduino or laptop is probably required. The XBee itself requires some sort of host adapter, and it might as well be another Arduino since something has to electronically read the 'pots'.

Then you need to develop your own protocol for signals sent between the 2 Arduino (over XBee or on a serial wire , it is the same).  There are many already out there, but they assume you know the basics before you use them (eg firmata). This is the basics.

The fact that your google results showed nothing similar is probably a good indication it can not be done as you had hoped.

update: I like @gerben comment, but even as an advanced person, I would find it challenging.


Perhaps something like this (for the Arduino Uno based MPU):


Blueduino Rev2 service UUID for web bluetooth

If the 0xFFF0 Bluetooth Service is not advertised by the Blueduino Rev2 board, you should not include it in the "services" key. It should be in "optionalServices. See https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web#request_bluetooth_devices

I think your code should look like:

navigator.bluetooth.requestDevice({
  filters: [{ name: 'ZeroBeacon' }],
  optionalServices: [0xFFF0]
});


Can I use a 3.3v GPIO to control an opto-isolated 5v relay board?

Yes, the Reddit post's approach is likely to work ok, as long as you correctly follow the cautions in it:  • connect the VCC pin of the relay board to a 5V source,
•  connect together the Arduino ground,  the relay ground, and the  5v-source ground.

Here is a typical relay-module circuit diagram (for one channel):

(Note, this diagram is from a home automation blog; for more discussion and similar diagrams, see eg
4-relay-shield-diagram at yourduino.com and stripboard-shield-relay-sm at startingelectronics.org.)

As you can see in the diagram, the Arduino pin that connects to JP2-2 will not be exposed to voltages.  (The base of an NPN transistor effectively is at the junction of two back-to-back diodes.)

When the Arduino or ESP pin at JP2-2 is at about 0 V (ie, when the Arduino pin is off) IBE=0; that is, no Q2 base-emitter current will flow; thus, Q2 will be off, so that both of LED1 and relay U1 will remain off.

When the Arduino or ESP pin at JP2-2 is at about 3.3 V (ie, when the Arduino pin is on) IBE is about 2.5 mA, which should be enough to reduce VCE to about 1 V, leaving 4 V across the relay coil, or enough to turn it on.

Note, the 2.5 mA figure for this circuit is calculated as follows:  IBE = (3.3-VBE)/1000 - VBE/10000 = (3.3-0.7)/1000 - 0.7/10000 = .00260 - .00007 = .00253 A = 2.53 mA.  Note that the alternate circuit diagrams linked above don't have a 10KΩ resistor like that in the diagram above, so instead of about 2.5 mA would have about 2.6 mA drive.

If for some reason you don't have quite enough base drive – in which case you might be able to hear a slight click from the relay, even if it doesn't switch – you could increase the "5 V" line into the LED and relay to say 5.5 V or 6 V.  As noted before, the  back-to-back diodes structure of the NPN transistor will isolate that voltage from your Arduino or ESP.


Receiving SMS by Arduino GSM Shield and control the LED with the content of this SMS?

First of all, you have a typo: You need the double-equals operator in

if (c == 'off') {

But more importantly, you can't use a char variable to hold or compare more than one character at a time. I don't know the details of the Arduino GSM library, but if sms.read() returns a string, then you'll need a string variable or an array of char to hold the result.


Your modified code doesn't disable the pullup on the pin.

PORTC &= ~_BV(ADCChannel);


What is the use of decoupling capacitor?

Quite simply put, it's a little reservoir of energy for a chip or other device to dip into when it needs to get a little extra power.

In Electronics nothing happens instantly.  When a chip needs more power it has to get it from the power source.  The power source then has to respond to that by providing more energy, and that then has to make its way down the wires or traces to where it needs to be.

By placing a small capacitor near where the power is consumed the capacitor can respond to that call for more power much faster than the power supply.


Your PHP server has a certain content type it can receive to process your requests from the ESP8266. The two most generic content-types used for php are either application/x-www-form-urlencoded or multipart/form-data. Try to play with those two and see if that solves it for you.


Doing that calculation from EEPROM is exactly the same as doing it from any other source.  You have a count so you know where the EEPROM data ends.  You know where the EEPROM data starts.  You know how to read a number out of EEPROM.  What is stopping you from creating a for loop to read the i'th address from EEPROM and add all those numbers together just like you would for an array?

for (int i = EEPROM_START; i < EEPROM_END; i++){
   sum = sum + EEPROM.read(i);
}
average = sum / count;

where EEPROM_START and EEPROM_END are supplied by you by knowing what address you started and ended writing at.


I bought USB > FT232RL, can I use it to program a bootloader onto an Arduino?

In fact, you can, but you are unlikely to enjoy it as it will be fairly slow.

While this module is intended for serial communications - which the ATmega won't support until it has a bootloader on it - the chip around which it is built can also be operated in "bitbang" mode:

http://www.ftdichip.com/Support/Documents/AppNotes/AN_232R-01_Bit_Bang_Mode_Available_For_FT232R_and_Ft245R.pdf

Using reconfigured pins of this wired to the ISP pins of your target, and an implementation of the ISP algorithm running on the PC, it will indeed be possible to load a bootloader on to a new ATmega chip.  However, USB is not designed for this type of usage - it is meant to move large blocks of data, rather than to efficiently do sequences of tiny operations.  The result is that the loading process will be drastically slower than with other methods.  You may also spend a fair amount of time tracking down software to do it, or writing your own.

If you have an already working Arduino-style board available, you can use that to program your new chip:

http://arduino.cc/en/Tutorial/ArduinoISP


Code test the duration press of the button

Why did the timers stop working?

The main issue seems to be that freeze_timer and btn_timer are of type unsigned int, while millis, as stated in its documentation, returns an unsigned long.

As you may know, unsigned int is normally be able to hold a much smaller range of values than unsigned long. In the case of whatever compiler Tinkercad uses for the Arduino Uno, I checked and unsigned int can hold values from 0 to 65535, while unsigned long can hold values from 0 to 4294967295. Whenever you save an unsigned long into an unsigned int, it will be reduced modulo 65536.

This means that once you pass 65.536 seconds checks such as the (millis() - freeze_timer) >= 2500 will always be true (at least until millis wraps back around after 4294967.296 seconds - around 50 days).

If you would like to learn a bit more about integer conversions, I think this Stack Overflow question covers it.

The simplest solution is, of course, to declare freeze_timer and btn_timer to be of the appropriate type, unsigned long.

Use simpler code

All of the above being said, like Gerben said, the code seems overly complex.

There also seem to be other issues. For instance, I would expect the debounce behavior should not ignore presses that last less than 1 second. Like Gerben said, 10 ms should be enough to discard any bounces.

Furthermore, I think it would be more appropriate to not even discard presses that last less than 10 ms. I would say the debouncer should trigger "press" regardless of whether the press lasted less than 10 ms. It's role should just be to ignore multiple presses within that 10 ms window (although to be fair, ignoring short presses is not a terribly big issue).

Although one could make some guesses, to really help you with this, we would need a description of your intended behavior. What is the purpose of freezing? Is it intended to allow multiple presses to be triggered when you never release the button (or maybe you should wait until release before triggering one again)?


The chip you are using (HD44780) only works with characters; you can't address single pixels. If you read the datasheet, the word "pixel" is absent.

Of course, you can add a wrapper that implement a drawPixel(row,col) function by defining custom characters and then sending it to the display.

The result will be unpleasent to the eye, because there is a gap between chars on screen, and another gap between rows.

A better alternative is an OLED display like this:

You can find the same display with I2C or SPI interfaces. Basic model is B&W, but you also have color and touch sensitive variants.


Latest news about alternative Arduino IDEs

I use the Arduino IDE to 'build' everything.

However, in case of a bigger project, I use a 'decent' code editor (Visual Studio in my case) to edit, and the Arduino IDE to build.

Also, because I prefer testing all non-Arduino related code on the PC (not on the Arduino), the Visual Studio (C++) project uses some stub classes I created (specifically for my project), and I can run the application on my PC.

When some part is finished, I can build the same code in Arduino IDE, but without the stubs (because these are acquired from Arduino.h and related Arduino files).

What IDE is best to 'edit' code is very subjective I think. But in the above way I can see many classes/files at a glance on the left side (and not in the top like Arduino IDE where only like 5 tabs fit on a screen), and to test lots of code on the PC already before sending it to an Arduino.

The GitHub repository can be found here: https://github.com/michelkeijzers/Mestra

Project inside is DmxLightShow.


Signal pin of buzzer is connected with which Arduino uno pin

As I have read in the page you have linked, I think you should program the Arduino to provide an impulse to the signal (s) pin.

Therefore, to answer your question you can use any digital pin of the Arduino. And I guess that as long as the impulse last as long as the buzzer will produce a sound.

Here an example of code:

int buzzPin =  2;    //Connect Buzzer on Digital Pin3
void setup()
{
 pinMode(buzzPin, OUTPUT);
}
 void loop()
{
 digitalWrite(buzzPin, HIGH);
 delayMicroseconds(50);
 digitalWrite(buzzPin, LOW);
 delayMicroseconds(50);
}


Why is Serial.print working when nobody receives the data?

The USB-UART bridge is, if it can. And if it can't, no one cares. A UART is asynchronous, hence it doesn't care if anyone consumes it; as long as it has sent the data, that's all it cares about. There can be additional checks to see if the other side is able to receive data, but that is not implemented on the Uno.


Avoid the 10 attempts of Avrdude when programmer is not responding

Unfortunately, MAX_SYNC_ATTEMPTS is a constant in the source code, and one which appears several times.

avrdude is an open source project, so customizing and building it should be relatively straightforward.  Since it is a numeric rather than string value, and is checked in several places, simply modifying the binary is likely to be tricky.

One can of course manually kill the process, though it is annoying to have to.

Another approach could be to write a wrapper which might potentially do some sanity checking first (does any other process have the port open?) and then would launch avrdude as its child, passing through all the arguments.  By monitoring the output before passing it on, it should be possible to detect this message and terminate the avrdude instance automatically.


it is okay to use for simple experiments directly. But while you choose to opt for a complex tasks read the details about all the components and their wiring techniques.
specifically try to check soldering is done correctly or not while connecting the wires to any component or to other wire. wrong soldering may damage your parts and arduino as well.
Be careful while using power supply, more when it comes to use multiple sources.
read carefully before you do anything. Dont be afraid just be careful.


Why does a Piezo Buzzer not require a PWM digital pin (Gallileo Gen2)?

Why does a Piezo Buzzer not require a PWM digital pin?

Tone() uses the microcontroller's hardware timers to control the related code function but do not use the hardware PWM features. The timer can be assigned to any pin that has a digital output capability.
Tone() sends a "rail to rail" square wave (50% duty cycle) to the selected pin

Slightly more lower level information here under Ugly details
They say:

The library uses the hardware timers on the microcontroller to generate square-wave tones in the audible range.

You can output the tones on any pin (arbitrary). The number of tones that can be played simultaneously depends on the number of hardware timers (with CTC capability) available on the microcontroller.

ATmega8: 2 (timers 2, and 1)
ATmega168/328: 3 (timers 2, 1, and 0)
ATmega1280: 6 (timers 2, 3, 4, 5, 1, 0)

The timer order given above is the order in which the timers are allocated. Timer 0 is a sensitive timer on the Arduino since it provides millis() and PWM functionality.

  ... what exactly is the difference between a PWM digital pin and an analog pin, in terms of output? They both use PWM, right? Why can't even a PWM digital pin read analog input?

There is a misconception there.
Analog pins are capable of Analog INPUT functionality .
"PWM" output is known as "analogWrite" but is actually a purely digital function and is not related to whether a pin has analog read functionality.
PWM out = analogWrite is available on pins which have associated PWM hardware.
The actual signal is a "rail to rail" square wave with a mark:space (on:off)that varies.   Filtering the PWM produces DC at the average DC level. PWM range is 0 to 255 (8 bits)


String is included by Arduino.h. Before #include <Arduino.h> String is not defined. Move #include <Arduino.h> to the top of the file or remove it. If you remove it, the Arduino builder adds it.


4 channel means having the ability to send 4 individual values (maybe speeds?) at once.

Since the nRF24L01+ is a packet based system it is as simple as sending the different "channels" as different bytes (or groups of bytes if more than 0-255 or -128 to +127 is needed).

For instance, if you want 4 channels that can represent 0-255 then you need 4 bytes, and so you can set both sender and receiver to have a packet size of 4 bytes (for efficiency) and send a packet made up of the 4 channel values.

If you want to represent numbers bigger than that then you need to split the variable into bytes (two bytes for an int, 4 for a long) or create a struct to represent your packet of data. Of course you then need the sender and receiver to be set to a packet size at least big enough to contain the data, and both ends must agree on the packet size.


Ensure board is always on the same port?

Normally, the COM port number wont change, but you cannot simply rely on this.

Depends on various effects, especially if you have multiple USB-Serial devices, update the driver, etc. Also, there's the possibility to clean the COM port numbers in the operating system to get rid of unused legacy entries, which will restart counting them from fresh.

Most applications search for all existing ones, eventually display their names, and leave it to the user to choose the desired port.

And, btw. it's not related to VB.net


Can you measure how much current goes through the wire when grounded (A: 2 mA from measurements in comments) ? And the open circuit voltage between the controller's ground and the control wire?  (A: 3.1V, from 2xAA)

If the current isn't more than the 40mA per pin/100mA per port, 200mA total, and the open circuit voltage of the controller pins is less than 5V, then you should be able to connect the Arduino's output pins and ground to your controller's wires and ground.

If the voltages and currents are higher, then you would need protection to prevent damaging your Arduino.

The controller and the Arduino should share a common ground, but without a circuit and without the controller's voltages and currents, it is hard to tell exactly what is wrong.

Edit: Since the controller's open circuit voltage and short-circuit currents (3.1 V, 2mA max) fit within the Arduino's capabilities, you can wire them directly to the pin outputs, and make sure the controller and the arduino share a common ground.

You need a fifth wire between the controller ground to the Arduino ground to make the logic levels actually communicate between the two devices.

You likely also need some 5V->3V level shifting to isolate the Arduino's output levels from the controller's inputs.   Top of the line would be MOSFETS, but you could possibly use a voltage dividing resistor pair.  See the hints in https://arduino.stackexchange.com/a/419/6628


Not directly, no.  When an Arduino or ESP8266 has lost power it's lost power. You need external circuitry to keep providing power after the power input has been removed, and alert your target chip that power has gone.

simulate this circuit – Schematic created using CircuitLab

C1 wants to be massive. The ESP8266, because of the WiFi interface in it, consumes a lot of power.  Also, writing to EEPROM or Flash (which the ESP8266 has instead of EEPROM) takes extra power.

Ideally, C1 wants to be a small Super-Cap to keep the physical size small.  For an ESP8266 you're probably talking thousands of uF.

An alternative is to use the 47L16 (or similar) EERAM chip which is designed to save its internal SRAM contents to internal EEPROM when power is lost using its own dedicated capacitor-based power reservoir.


Convert Long to binary - least signifant bit first

void sendCommand(unsigned long command){
  for (unsigned long  mask = 1UL; mask<256UL;  mask <<= 1) {

    if (command & mask) {

    Serial.print( "1" );
    } else {

    Serial.print( "0" );
    }
  }
}

PS a long is actually 4 bytes long. But your code only uses 1 byte of it.


Problem when using PROGMEM on array holding notes for speaker on Arduino

You can not directly dereference something ("access an array") that is in flash memory. You have to use pgm_read_xxx functions from <avr/pgmspace.h> .

In your case you should probably write something like this:

tone(8, pgm_read_word(&melody[thisNote]), noteDuration);

Pgm_read_word reads two bytes. You could also call that inside your tone() function, the function would take the pointer in flash as an argument.

I would also recommend you using integer types from <stdint.h>, because they have defined sizes. Pure int is most likely 32-bit on your PC, but 16-bit on the AVR (I have learned this the hard way when my algorithm ran fine on the PC but gave totally junk output on the AVR).


Many USB keyboards (certainly older ones, though almost certainly not wireless ones) are also PS/2 keyboards.  The wiring of the cable is all that differs, and the chip in the keyboard changes its behaviour depending on how it's wired.

A simple USB to PS/2 adaptor is merely a USB socket and PS/2 plug wired together in a certain way:

So that's:

5V to 5V
D- to Data
D+ to Clock
GND to GND

It may work with your keyboard, or it may not. All you can do is try it and see.


The MD_MAX72xx library has a transform function.

Depending on how you want to mirror the text (along which axis), you give that function the MD_MAX72XX::TFLR or MD_MAX72XX::TFUD argument.

Though I'm guessing that you might actually want to rotate the text 180deg. In that case use transform(MD_MAX72XX::TRC).


Addressing individual LEDS on a simple strip with LEDs in series and/or parallel connection is just not possible.
Connecting the strip directly to an output pin is completely nonsense. Forget it.

You need a strip with digital LED controllers populated, as described (for instance) in another link mentioned in your second link: http://www.adafruit.com/products/306

Have a look at this, then I'm sure you will come back with more detailed questions ;-)


Connecting MicroSd Reader with arduino uno

The best answer is: don't use pin 11 for your servo motor - move it to another pin.

The SD card needs SPI.  SPI is pins 10/11/12/13.  You can't change that.  You can much more easily move the servo to a different pin, since there are multiple PWM pins that can support the servo in hardware. If they are all taken then software PWM is easy and there are libraries available to do it for you, so you can use any IO pin you like for that.  Much simpler than re-writing the SD card software to use bit-banged SPI on other pins (which would also be incredibly slow).


Attiny85 Timer 1 comparator B doesn't work properly (while A does)

Here is the code:

that code can be greatly improved:

1) break down your task into logical blocks;

2) code each block as per the datasheet, with comments;

3) tell your readers what you intended your code to do and what your code did.

4) read the datasheet.

edit: your code, following the steps above, set to flip PB4 at OCR1B = 70, on an attiny85 @ 8MIPS, produced the following.

you are close so keep working at it.

edit 2: once setup, the code is fairly simple.

ISR (TIMER1_COMPB_vect){
  //bitClear(TIMSK, OCIE1B);
    //update the next match point for timer1, ch b
    OCR1B +=(IO_GET(DEBUG_PORT, 1<<DEBUG_PIN))?(DEBUG_PR - DEBUG_DC):DEBUG_DC;
    IO_FLP(DEBUG_PORT, 1<<DEBUG_PIN);   //flip the output pin
}

void loop() {

}

the above code generates a pulse train with a duty cycle of DEBUG_DC / DEBUG_PR. Nothing in the loop() so it is fully transparent to the user.


What is the advantage of using a motor shield if I want to use a stepper motor?

The example you linked to isn't actually connecting the Arduino directly to a stepper motor. It's going via a ULN2003A driver. That's a very common Darlington transistor array, which basically just lets you use a small current to switch a larger load.

That's necessary because the Arduino pins can't safely source enough current to drive the stepper motor directly. It might work for a while, but it would damage your Arduino sooner or later.

Motor shields usually have a similar driver in them, but can also provide additional functionality which you might find useful. For example, the Adafruit shield you linked to is controlled by the I2C bus, and has its own on-board PWM. That means you can control several motors without needing any extra output pins on your Arduino.

In short, motor shields aren't necessary. They can be helpful though, especially if you aren't familiar with the underlying electronics, or you don't want to build it yourself.


Sending data over two independently powered arduinos

It's ok if the distance between the two devices are not too big. (couple meters)

Since the valid logic level (voltage) ranges are pretty wide a small difference won't affect the operation of the devices. Arduino uses TTL (5V) logic so let's see the level diagrams:

If you see the output level ranges (on the right) are more strict than on the input side (on left) so the logic value remains valid even if a small voltage drop or noise occurs on the wire.

Make sure you won't connect two outputs directly since it can damage the microcontrollers. Connecting two inputs are totally safe.

EDIT: If you want to cover longer distances you need to use a balanced line  e.g. differential I/O-s, RS-485 or CAN. These are not default Arduino features so you'll need additional electronic to use them.


Why does exit status 1 stray '\302' in program pop up around Serial.println ( "-> Second Service load");?

As Gerben notes, the stackoverflow question error: stray '\302' in program is about this issue.  Basically, your file contains one or more characters not valid in the current character set.  The character is either non-printing or a multi-byte unicode character.

How did the character get there? Some of the ways mentioned in the stackoverflow question are pressing ctrl-space or shift-space.

How to find the character and get rid of it?  You can look at output from hex-dumping the file, which will identify all characters definitively.  Or by trial and error you can delete and retype spaces in the region of the error.


Arduino Mega - Multithreaded (run two loops simultaneously)

You can combine the 2 programs into 1 program.  But when you start wanting to do multiple things at once then you can't have any code that "blocks" and waits to finish before letting the next thing happen.  The Arduino has a single core, it can't do multithreading.  But if you write non-blocking code you can make things appear to happen at the same time.  I imagine the problem with your code now is that you have probably used the delay function.  That function blocks, so nothing else can happen while the delay is running.  Instead you have to use millis to record the time and periodically check against that time to see if it is time to take the next step instead of calling a delay to wait for the next step.  See the "Blink Without Delay" example that comes with the IDE and any of the multitude of tutorials about it on the web to see how it works.


The RS485 has no internal registers, all of that is in your target unit. Hopefully the instructions for that will tell you how to do it.  Start by getting simple communications working then slowly progress from there.


Can I hook up an Analog multiplexer to Arduino Nano?

yes. those using IO expanders offers more flexibility.


Why is the T2 transistor used in Arduino Micro?

T1 and T2 implement a power supply ORing of the VUSB and VIN voltages. Read this for extended information.

The body diode of each MOSFET performs the basic ORing function. When the MOSFET is turned OFF it just behaves as a diode. But when the MOSFET is turned ON, the diode is shorted by the conduction channel, thus avoiding its voltage drop (and achieving a behaviour closer to an ideal diode).

So:

When VUSB is present and VIN is not connected (but pulled down to ground by R9), T1 turns ON and the +5V rail is connected to VUSB. Also, T2 turns OFF and the regulator input is isolated from VIN and the regulator simply doesn't operate (thus, avoiding a potential conflict because its output +5V is being forced to VUSB).
When VUSB is not connected and VIN is present, T1 turns OFF and VUSB is isolated from the +5V rail. Also T2 turns ON and VIN is connected to the regulator input, which then regulates the voltage down into the +5V rail.
When both VUSB and VIN are connected, the behaviour is the same as in case 2 above. Because VIN is supposed to be >7V and VUSB approx 5V, T1 will isolate VUSB and avoid a conflict with the regulator output. Also, a VIN >7V will allow T2 to turn on hard enough to bypass the body diode and avoid its voltage drop.


How can I use an arduino as an intermediary step between my PC and a LED strip?

You should take a look at FadeCandy if you are dealing with NeoPixel LED Strip. Ived used that in conjunction with Processing (which is JavaBased) to send stuff into a 16x16 NeoPixel display. (4 8x8 matrix's linked together)
Fadecandy uses Open Pixel Control
http://openpixelcontrol.org/

I've got an example of it on youtube... https://www.youtube.com/watch?v=rz_U4dzjp1s&feature=autoshare


What is the best way to get more RAM for a sound buffer?

A simple SPI SRAM chip. Available up to 128KB, such as the 23LC1024: http://www.microchip.com/wwwproducts/en/23LC1024


To do this you would usually use MOSFETs to control the power.

Take the following circuit, for example:

simulate this circuit – Schematic created using CircuitLab

M1 is normally off, having its gate pulled up by R1.

Pressing SW1 pulls the gate of M1 low, allowing current to flow through it to power the D1.

The D1 boots up, and immediately drives the GPIO high.

This then turns on M2 (which is normally off, having the gate pulled down by R2), which in turn pulls the gate of M1 low.

SW1 can now be released since M2 is doing the same job.

To turn off, simply drive the GPIO low, or allow it to float as an input, in which case R2 will turn off M2, which then turns off M1, which stops the current flowing.


Is it better to use #define or const int for constants?

It's important to note that const int does not behave identically in C and in C++, so in fact several of the objections against it that have been alluded to in the original question and in Peter Bloomfields's extensive answer are not valid:

In C++, const int constants are compile time values and can be used to set array limits, as case labels, etc.
const int constants do not necessarily occupy any storage. Unless you take their address or declare them extern, they will generally just have a compile time existence.

However, for integer constants, it might often be preferable to use a (named or anonymous) enum. I often like this because:

It's backward compatible with C.
It's nearly as type safe as const int (every bit as type safe in C++11).
It provides a natural way of grouping related constants.
You can even use them for some amount of namespace control.

So in an idiomatic C++ program, there is no reason whatsoever to use #define to define an integer constant. Even if you want to remain C compatible (because of technical requirements, because you're kickin' it old school, or because people you work with prefer it that way), you can still use enum and should do so, rather than use #define.


AT+UART_DEF=9600,8,1,0,3

Are you aware that this configuration (3) as a rule would require both RTS and CTS extra physical signals to work ? That means, if you do not connect anything there, the level present at some pin configured anywhere would prevent ESP8266 from receiving further data from serial.

In general people use "no flow control" (0)

AT+UART_DEF=9600,8,1,0,0


Faster way to parse a HTTP response in Arduino

there are nice functions inherited from Stream class

int parseResponse(char uuid[], int size) {
  if (!client.find("HTTP/1.1")) // skip HTTP/1.1
    return -1;
  int st = client.parseInt(); // parse status code
  int l = -1;
  if (st == 200 && client.find("\"uuid\" : \"")) {
    int l = client.readBytesUntil('"', uuid, size);
    uuid[l] = 0; // terminate the C string
  }
  return l;
}


No. There is no such facility in Bluetooth to provide such a feature.  That's not to say that technically it can't be done, there just isn't any software (a web browser) that would support it.

Instead you would need to use a Bluetooth-enabled app on the smartphone to communicate with the ESP32 over Bluetooth and display the data / provide control natively.  Such an app would probably have to be written by you since it would be specific to the way you are working, unless you can find a generic app that lets you design an interface for your project and then communicate using a documented protocol that you would then have to implement on the ESP32.

An alternative is to just reverse everything. Instead of having your phone connect to the ESP32 then connect to a webserver on it just have the ESp32 connect to your phone when your phone is set to WiFi Hotspot mode. You can still then get your phone to connect to the webserver on the ESP32, and your phone also has mobile internet. If course, if you are wanting internet through a WiFi connection for your phone then you can't do that. However, your ESP32 can then just also connect to your WiFi router so there is nothing to change on your phone. You just browse to the webserver on the ESP32 through your local WiFi network.


Easy. Here is one way to do it.

Read the clock off the rtc.
Wait a known period of time, based on the mcu frequency,
Read the clock off the rtc again.
Compare the two time reading and it should have advanced. If not, fall back to compiled time.

There are other ways to do it as well, like bor, or square wave output, interrupt on vbat line, ......


What is the best way to measure PWM signals ( pulseIn ) with the Arduino via a Raspberry Pi?

Nanpy seems to have a CounterClass that does frequency measurements.

Or do you want to measure the PWM duty-cycle?


What I did wrong was using |= instead of = . Apparently Arduino set some of these Bits on start, which didn't change.
Now it works like a charm and I added a frequency choice, which works for at least 50,200,400,488 Hz. Everything in between should work aswell!

Working testcode for timer1 with serial input of HIGH-time:

#define PRESCALAR 8
#define PWM_FREQUENCY 50
#define TOP_VALUE F_CPU/(2*PRESCALAR*PWM_FREQUENCY)

uint16_t dutytime = 1000; // this gives idle throttle signal

void setup(void) {
  Serial.begin(115200);

  // TIMER 1
  DDRB |= (1<<DDB5); // D9 Output

  // set 1000ms to start motors in idle mode
  OCR1A = 1000L;

  // bits 7,5,3 PWM Output on pins A,B,C respectively (COMnx1)
  // bits 1,0 WGM1(1,0): phase correction mode
  TCCR1A = B10000010; // in hex: 0xAA for all 3 = B 1010 1010
  // bit 4,3 WGM_3,2: phase correction mode
  // bits 2,1,0 Prescalar: 8
  TCCR1B = B00010010; // in hex: 0x12; B 0001 0010
  ICR1 = TOP_VALUE;
}//setup

void loop(void) {
  // Serial.println(TOP_VALUE);
  dutytime = serial_input();
  if (dutytime) {
    OCR1A = dutytime;
  }
  delay(500);
}//loop

float serial_input() {
  double num = 0;
  while(Serial.available()) {
    delay(2);
    char ser = Serial.read();
    if(isDigit(ser)) {
      num = (num*10)+(ser-48);
    }else{ break; }
  }
  if (num) {Serial.println(num);}
  return num;
}


Can I specify custom port names in the Arduino IDE on Linux?

Consider using a device name of form ttyUSBnn, where nn is fairly large.  For example, in /dev you could say

sudo ln -s ttyUSB1 ttyUSB77

Then, ttyUSB77 shows up in the IDE's ports list and can be selected.

(I don't know how to set up that link using the udev system, but imagine it can be done.)


Input voltage from circuit drops despite Arduino turned off

To protect the internals of integrated circuits many contain diodes at most input and output pins to VCC.  In normal operation where the voltage at these pins are not expected to become greater than VCC, these diodes are not in forward bias.  However, should the unexpected happen and the voltage at these pins does become higher than VCC the diodes are in forward bias.
 That is to say, the diodes try to keep the voltage at the pin no higher than VCC.

When you removed the power from the Arduino you essentially lowered VCC to zero.  This will likely forward biased the diodes inside the Arduino and drive the voltage at the pin toward zero.

There is a good discussion of this in this Electrical Engineering StackExchange question & answer.


These lines of code will wreak havoc with reading the GPS data:

tone(buzzer, 2200);
delay(5000);
digitalWrite(ledsinal, LOW);  // turn LED OFF
noTone(buzzer);

The Arduino is "blocked" at these lines for seconds.  During that time, the GPS keeps babbling and eventually overflows the input buffer.  The next call to smartDelay only waits for 1 second, and it may not get a complete sentence.

Here is a NeoGPS version of your sketch that does not block:

#include <EEPROM.h>
#include <NMEAGPS.h>
#include <NeoSWSerial.h>
#include <Wire.h>

NMEAGPS gps;

static const int RXPin = 10, TXPin = 9;
static const uint32_t GPSBaud = 9600;
NeoSWSerial gpsPort(RXPin, TXPin);

//***************************************************************
int aux = 0;
int vel_prog = 20; //programed SPEED
float vel_atual;//  actual SPEED
int val_inc = 0;
int val_dec = 0;
int led0 = 2;//led pin
int led20 = 3;//led pin
int led60 = 4;//led pin
int led80 = 5;//led pin
int ledsinal = 6;//led pin
int buzzer = 7;//buzzer pin
bool buzzing = false;
uint32_t buzzTime;
int incrementa = 8;//button pin
//****************************************************************
void setup()
{
  Serial.begin(115200);
  gpsPort.begin(GPSBaud);
  pinMode(incrementa, INPUT);
  pinMode(led0, OUTPUT);  // declare LED as output
  pinMode(led20, OUTPUT);  // declare LED as output
  pinMode(led60, OUTPUT);  // declare LED as output
  pinMode(led80, OUTPUT);  // declare LED as output
  pinMode(ledsinal, OUTPUT);  // declare LED as output
  pinMode(buzzer, OUTPUT);  // dbuzeer
  delay(10);
}

void loop()
{
  // Check the buttons
  val_inc = digitalRead(incrementa);  // read increment button
  if (val_inc == 1) {
   if (vel_prog > 80) {
      vel_prog = -20;
   }
      vel_prog = vel_prog + 20;
  }

  if (vel_prog == 0) {
    digitalWrite(led0,HIGH);
    digitalWrite(led20,LOW);
    digitalWrite(led60,LOW);
    digitalWrite(led80,LOW);
  } else if (vel_prog == 20) {
    digitalWrite(led0,LOW);
    digitalWrite(led20,HIGH);
    digitalWrite(led60,LOW);
    digitalWrite(led80,LOW);
  } else if (vel_prog == 60) {
    digitalWrite(led0,LOW);
    digitalWrite(led20,LOW);
    digitalWrite(led60,HIGH);
    digitalWrite(led80,LOW);
  } else if (vel_prog == 80) {
    digitalWrite(led0,LOW);
    digitalWrite(led20,LOW);
    digitalWrite(led60,LOW);
    digitalWrite(led80,HIGH);
  }

  // Check the GPS
  while (gps.available( gpsPort )) {
    gps_fix fix = gps.read();

    if (fix.valid.speed) {

      if ((fix.speed_kph() >= vel_prog) && (aux == 0)) { //comparacao da velocidades
        digitalWrite(ledsinal, HIGH);  // turn LED OFF
        tone(buzzer, 2200);
        aux = 1;
        buzzing = true;
        buzzTime = millis();
      }

      Serial.print( fix.speed_kph() );
    } else {
      Serial.print( '*' );
    }
  }

  // Check the buzzer
  if (buzzing && (millis() - buzzTime > 5000)) {
    digitalWrite(ledsinal, LOW);  // turn LED OFF
    noTone(buzzer);
    aux = 0; // Need this?
    buzzing = false;
  }
}

Notice how it checks millis() every time through loop to see if the buzzer has been on for 5 seconds.  It doesn't block for 5 seconds.

It only checks the speed when a new GPS fix arrives.  This happens once per second, not every time through loop.

Your original version uses 11472 bytes of program space and 786 bytes of RAM.
The NeoGPS version uses 10722 bytes of program space and 590 bytes of RAM, a significant savings.

NeoGPS is smaller, faster and more accurate than all other libraries.  If you want to try it, NeoGPS is available from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries.

The above sketch also uses my NeoSWSerial.  It is much more efficient than SoftwareSerial.  SoftwareSerial blocks interrupts for long periods of time, which can interfere with other parts of your sketch.

It would be even better to use AltSoftSerial on pins 8 & 9 (on an UNO).


First things first; please INDENT YOUR CODE. The code you posted is a mess and I took at least double the time to fix that.

First, you have an extra closing curly bracket at line 17 and the if (Fire == High); should be changed to if (Fire == High){

Fixed code:

int Led = 4;
int Buzz = 7;
int Sensor = 11;
int Fire = HIGH;
void setup()
{
  Serial.begin(9600);
  pinMode(Buzz,OUTPUT);
  pinMode(Sensor,INPUT);
  pinMode(Led,OUTPUT);
}
void loop()
{
  Fire = digitalRead(Sensor);
  if(Fire == HIGH){
//Serial.print("analog Read = ");
//Serial.print(analogRead);
    Serial.println("HELP! A FIRE!");
    digitalWrite(Buzz,HIGH);
    digitalWrite(Led,HIGH);
    delay(200);
    digitalWrite(Led,LOW);
    delay(200);
    Serial.println(analogRead(A0));
 }
 else
 {
    Serial.println("No fire detected");
    digitalWrite(Buzz,LOW);
    digitalWrite(Led,LOW);
  }
  delay(500);
}


I think the easiest way to solve your problem is using a separator and transmit the array values one after the other. That means having a for loop and in every iteration sending one value of the array with

Serial.println(array[i]).

The function will

convert numbers into Strings so you will get "125", "1250", ...
append a carriage return character (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n')

On the receiver side you can simply wait for Serial.read() to equal the number 13 and (immediately afterwards) 10 and split the messages there. That works unless your transmitted strings contain new lines.

The disadvantage is, that numbers are of course transmitted in an unefficient way. If you want to transmit them as real numbers instead of strings you have to write your own protocol. This video "Wireless Module Multiple Receivers" goes into that direction, it's using a fixed packet length but it gives an idea of how such a thing works.


How do I get the request params from a ESPAsyncWebServer?

For POST request the hasParam needs to know if you want to test the url parameters or x-www-form-urlencoded parameters in body of the POST request. The second parameter of the hasParam is boolean post and it has default value false. Use hasParam("device", true).


Ok, sorry for the delay, I had my exams. But I have finally solved the issue.
There were several issues:

MOSI should be connected to pin 23 not 19.
tft.begin() function should be in the setup to initialize the TFT. (for ILI9341)
The SPI library used should be the one that comes with ESP-32 support. The general SPI library for Arduino does not work with ESP-32.

Note: the ST7735 library currently does not work with ESP-32. It can be made to work by adding the following definitions given bellow to the Adafruit_ST7735.h header file.

    #elif defined(ESP32)
    volatile uint32_t *dataport, *clkport, *csport, *rsport;
    uint32_t  _cs, _rs, _rst, _sid, _sclk,
    datapinmask, clkpinmask, cspinmask, rspinmask,
    colstart, rowstart;

(add this just after the ESP8266 definitions).


How do I make a motor spin every 10 minutes?

The simplest option is to use delay() to implement the waits:
void loop() {
    turn_motor_on();
    delay(10000);  // 10 seconds
    turn_motor_off();
    delay(600000);  // 10 minutes
}

Since these long numbers may be difficult to read, you can make them
more readable by defining some units:
const unsigned long second = 1000;
const unsigned long minute = 60000;

Then you can for example delay(10 * minute);
Beware there is a trap if you try to do arithmetics with integer
literals. The following:
delay(10 * 60 * 1000);  // BUG!

will not work on most Arduinos, as the multiplications will be
performed on the int data type, which can only hold numbers up to
32,767. It is safer to use either explicitly typed constants (unsigned long is the appropriate type for delays) or integer literals typed with
the suffix UL (which stands for “unsigned long”).
Note that the Arduino will do no useful work while delaying. If you want
to do any kind of work during the delay, see the “Blink Without Delay”
Arduino example.


There are two methods of dimming a LED : by PWM or by a limiting current resistor.

PWM code
 `//Initializing LED Pin
 int led_pin = 10;
 void setup() {
 //Declaring LED pin as output
         pinMode(led_pin, OUTPUT);
 }
 void loop() {
         analogWrite(led_pin, 127); // half intensity
         delay(5);
 }`

Hardware. Use following schematic


In the Arduino IDE you need to select which port COM port the Uno is connected to.


IO with port manipulation while not interfering with i2c

I don't think you need to worry. A simple piece of code:

void setup()
{
 PORTA |= bit (0);
}

void loop() { }

Generates:

00000044 <setup>:
  44:   d8 9a           sbi 0x1b, 0 ; 27
  46:   08 95           ret

In other words, the compiler generates code to set that bit, ignoring all the other bits.


Is it possible to run two for loops separated?

No, but there is a solution to put the action in one loop (main loop).

If I understand you well, you have the following scheme:

Time[s]
0..1     Loop 1
1..2     Nothing
2..3     Loop 2
3..4     Nothing
4..5     Loop 3

Define a variable that keeps track of the time.
Check against the current time (millis) and when within the correct 'range' perform an action.
After 5 seconds start over again.

uint32_t lastTime = -1;

void loop()
{
    if (lastTime == -1)
    {
        lastTime = currentTime; // Initialization, can be done in setup too
    }

    uint32_t diffTime = millis() - lastTime;

    if (diffTime < 1000) // 0..1 sec
    {
        DoLoop1();
    }
    else if (diffTime < 2000)
    {
         // Do nothing();
    }
    else if (diffTime < 3000)
    {
       DoLoop2();
    }
    else if (diffTime < 4000)
    {
        // Do nothing
    }
    else if (diffTime < 5000)
    {
       DoLoop3();
    }
    else // diffTime >= 5000
    {
         lastTime == currentTime; // Reset after 6 s
    }
}

Update

Since you need all three loops together (and mixed), it's easier to define some variables.

bool loop1state, loop2state, loop3state; // True if running, false if off
int  loop1index, loop2index, loop3index; // Iterator values
int  periodIndex = 0; // starting with 0, increasing every 10 ms

Too bad I don't know the conditions when a loop starts, but let's say each iteration is 10 ms, and loop 1 starts immediately, loop 2 after 1000 ms, loop 3 after 1500 ms. After 3000 ms it starts all over.

void loop()
{
  // Update loop enablers.
  switch(periodIndex)
  {
  case 0:
     loop1state = true;
     loop1index = 0;
     break;

  case 1000:
     loop2state = true;
     loop2index = 0;
     break;

  case 1500:
     loop3state = true;
     loop3index = 0;
     break;

  case 4000:
     periodIndex = 0;
     break;
  }

  if (loop1state)
  {
     DoLoop1(loop1index++);
     loop1state = loop1index < 256;
  }

  if (loop2state)
  {
     DoLoop2(loop2index++);
     loop2state = loop2index < 256;
  }

  if (loop3state)
  {
     DoLoop3(loop3index++);
     loop3state = loop3index < 256;
  }

  delay(10); // 10 ms
}

Note, not tested, but the idea shold be clear

New update

You should not do a full loop during each switch, but only one iteration of the loop.

I did not run the sketch, just out of my head.

Some tips: print out the variables during each loop, so you get a clear idea what is happening (so all loop states and indices, and the periodIndex).

int LED = 3;
int LED2 =10;
int LED3 = 9;

bool loop1state, loop2state, loop3state; // True if running, false if off
int  loop1index, loop2index, loop3index; // Iterator values
int  periodIndex = 0; // starting with 0, increasing every 10 ms

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

void loop()
{
  // Update loop enablers.
  switch(periodIndex)
  {
  case 0:
    loop1state = true;
    loop1index = 0;
    break;

  case 1000:
    loop2state = true;
    loop2index = 0;
    break;

  case 1500:
    loop3state = true;
    loop3index = 0;
    break;

  case 4000:
     periodIndex = 0;
     break;
  }

  if (loop1state)
  {
    analogWrite(LED,loop1index++);
    loop1state = loop1index < 256;
  }

  if (loop2state)
  {
    analogWrite(LED2,loop2index++);
    loop2state = loop2index < 256;
  }

  if (loop3state)
  {
    analogWrite(LED3,loop3index++);
    loop3state = loop3index < 256;
  }

  periodIndex++;
  delay(10);
}


you have the HTTP chunked transfer encoding numbers in the content. 38 is the length of the body and it is on the first line of the HTTP body and 0 marks the end.
maybe try using ArduinoHttpClient library for HTTP


ATmega 8 wrong timing with Arduino NG bootloader

Ok, I finally solved it, so I will write it here so somebody may learn from it in the future :) The problem was really in the fuses, thanks Chris Stratton. Most of my chips were bought already modified for working with Arduino. But this ATmega 8 had the factory fuses, which were setting it for working with internal 1MHz oscillator. You can read and your write your fuse settings with avrdude, so I set them to arduino default (lfuse 0xDF, hfuse 0xCA, from boards.txt). Now it works perfectly even without uploading bootloader.


You need to use Serial.readStringUntil('\n') instead of Serial.readString if you use the Arduino IDE's serial monitor (where a \n is added as termination character when you press enter).
Also remove that while(Serial.available()==0). It will wait as long as there are any bytes in the serial buffer and as you don't Serial.read() within the loop, the buffer will not be emptied. So, if anything is received while Serial.println(state) is called or if you send two termination characters, the program will be stuck in that loop.


Statistical Mode calculation in Arduino programme

First, two caveats: (a) The question is fairly general and might be better asked on stackoverflow, except that asking here will tend to focus answers on algorithms with low memory requirements or online methods (methods that continually compute an answer as data streams through).  (b) In many cases – eg, with noisy sensors, noisy inputs, changing inputs – the statistical mode is less likely to be relevant than the statistical mean or median.

What computation method is best depends on which model of Arduino you use (because available RAM depends on model), what range of data your distance sensor returns, how many readings are taken, what you want to do with the data, whether an approximate (or nearly-correct) answer is acceptable vs an exact answer, and so forth.

Assuming you take 30 readings and store the data in an array d (that is, in d[0] ... d[29]), you could act as follows:

  Set high-value and high-count variables, say hiv and hic, both to 0.  For i from 0 to 29, count the number of occurrences ni of the value d[i] in the d array.  Whenever ni exceeds hic, set hic to ni and hiv to d[i].

You could make this more elaborate by detecting whether hiv is already equal to d[i] and testing ni ≥ hic rather than ni > hic.  This would allow detecting cases where two values are modal.

The method suggested in a comment – counting number of readings in various intervals – may compute an incorrect answer because the interval with the highest total count need not be the interval the mode is in.


Make Sure Digital pin is high before Serial.write()

The MAX485 requires 2V on the DE pin to register a HIGH. It takes no more than an absolute maximum of 50ns for the DE pin to switch the buffers. The Arduino takes 10.4ns for an IO pin to rise to 2V.

That's an absolute maximum of 60.4ns.

One clock cycle of a 16MHz Arduino is 63ns.

That is longer than it takes for the IO pin to tell the MAX485 to switch the buffers.

You can increase that rise time by taking in to account the input capacitance of the MAX485 and the resistance of the connection between the Arduino and the DE pin, but it will still be microscopically small compared to the time between the pin going HIGH and the serial transmission starting.

So there must be something fundamentally wrong with your setup.  Two possibilities spring to mind:

You aren't controlling RE, only DE, so RE is floating and is being capacitively linked to DE through the parasitic capacitances of the board and circuitry, making it rise and fall very slowly.
You haven't set the IO pin on the Arduino to OUTPUT, so it switches between floating and HIGH through a very high resistance, causing slow rise to HIGH and maybe never getting to LOW at all.

Or a combination of the two.


Program jumps alone from void loop() to another void

loop() calls Rip1Status(), which calls loop(), which calls Rip1Status(), which calls loop(), which calls ....

That process will continue until the stack overflows (runs out of memory) or over-writes some necessary variable. If you just meant for Rip1Status() to return to the main loop, delete the loop() call at the end of the function. When Rip1Status()exits, control will automatically return toloop()at the statement following theRip1Status()` call.


Problem uploading to ATMega using ArduinoIDE ("unbricking" "bricked" microcontroller?)

We use these a lot, and it's very easy to accidentally program the boards with the incorrect settings - particularly as the Sparkfun Pro Micro library defaults to the 3.3V/8 MHz variant instead of the more common 5V/16MHz.

I have recovered the boards with the bootloader reset method, but it is hard - you have to get the timing just right. What we do now is to simply reinstall the bootloader using an ISP programmer (instructions: https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader). It works first time, and ends up being much quicker than repeated tries to get the reset timing right. Just make sure that you have the right board selected when you burn the bootloader. We use a USBASP, and it only takes a couple of minutes to set up.


Arduino SIM5320e HTTP GET request to 000webhost.com

Try just using IP address for the Host line instead. I did the same thing for POST and it works fine for me.

Example:

Host: 13.xxx.xx.xx


attiny85 and arduino - analogRead + pwmOut

Analog read is 10-bits (2^10 = 0-1023 range), analog write is 8-bits (2^8 = 0-255 range). Ditch the lower two bits of the result either by doing:

analogIn = analogIn >> 2;

which can be shortened to:

analogIn >>= 2;

Or you can use the rather complex map function:

analogIn = map( analogIn(0, 1023, 0, 255) )


I've used a somewhat more complex method with some success, which uses 2 timers to play 8kHz sampled audio. The idea is that one of the timers runs at 8kHz to determine the PWM duty cycle of the other, which runs at as fast a frequency as possible.

While the original code uses a short stored sample (On an Arduino, you could store maybe 3 seconds of audio that way), my usages involved computing the audio on the fly by overlapping several sine waves or using table lookups with varying strides. As long as computation is kept simple, this just barely works.


How to accept user input (array, variables,...)

Your hardware side for the user to use can be based on an ADC type keypad pictured below, this only uses one pin and is pretty reliable. Note that not all code is given or design as it would be useless for learning and I also put effort into the code this came from, logic helps with the rest of each part...

The code is pretty simple:

You would write a function like so~

char keypad(int in){

if(in < 949){
    if(in > 935){
        return 's'; //select
    }
}

//......

else return = 0;
}

Next would be the code for the menu, you could hold the default values in an array and then modify them in the code, with set positions for defaults, considering

  My default values for solenoids used, droplet size, droplet timing, solenoid timing, camera delay and flash(es) delay(s) are put in an array.

Example from one of my projects

//Menu levels
#define level0 0
#define level1 1
#define level2 2
//master level of current point
#define mlevel 6
#define msub_level 7
//\\\\\\\\\\\\\\\\\\\\
#define sub_level1 0
#define sub_level2 1
#define sub_level3 2
#define sub_level4 3
#define sub_level5 4
// default level on boot
uint8_t current_level = mlevel;

Next would be to push the data to

int navigate(char key){
if(key == 'u'){
        if(current_level == mlevel){
        if(count == 3){ //roll-over

            count = 0;
            //update LCD....
        }
        else count++;
        //update LCD....
    }

    if(current_level == msub_level){

        if(count == 5){//roll-over

            count = 0;
            //update LCD....
        }
        else count++;
        //update LCD....
    }
}

//..... other ones here

    return count;
}

You would use the returned count to find the relative place in your array. e.g:

int default[n] ={x,y,z,...};

  get the key > put into navigate() > put into dafault[count];

You would also change the default after

It has been changed or,
The key has been debounced, i.e. use logic to determine if the key has changed state or,
The user has chosen 'accept'

Update of the LCD can be done at the points you want it done


Faster and lighter approximate timing code without using timer

Personally I wouldn't be putting too much effort into optimizing away your timers. millis() is pretty fast - the work needed to calculate the result is done in the background anyway (by interrupts). I tried some test code:

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  unsigned long start, finish;

  start = micros ();
  for (byte i = 0; i < 100; i++)
    digitalWrite (13, HIGH);
  finish = micros ();

  Serial.print ("Time taken to do digitalWrites: ");
  Serial.println (finish - start);
  Serial.flush ();

  start = micros ();
  volatile unsigned long now;
  for (byte i = 0; i < 100; i++)
    now = millis ();
  finish = micros ();

  Serial.print ("Time taken to do millis: ");
  Serial.println (finish - start);
  Serial.flush ();

  }  // end of setup

void loop ()
  {

  }  // end of loop

Results:

Time taken to do digitalWrites: 520
Time taken to do millis: 188

You can see that the digitalWrite() (which you weren't worried about) takes 5.2 µs, whereas calling millis() (which you were worried about) takes 1.88 µs.

  Are millis() and micros() timing patterns using more operations (setting value to variable, computing the difference between 2 values and than comparing it to a period you have set) instead of decrementing and comparing to zero with my pattern?

Yes, just adding one to a variable and then comparing will be faster. Whether it is worth the effort is debatable.


Send button only works when pressed immediately after

tavis’ answer nailed down your problem: your program is completely
unresponsive when it is blocked in the first while loop of the
loop() function. Here I will try to give you some hints on how to
avoid this situation, but first some general comments:

if (pres_len < (unit_delay*3) && pres_len > 50)

The threshold should be unit_delay*2, maybe with a longer
unit_delay. In Morse, a dot is one unit, and a dash is three units. If
you have to set a threshold, it should be somewhere in the middle.
Otherwise, a perfectly valid dash of 2.99 units would be mistaken
for a dot.
Also, a function returning anything but void should always return a
value. What is this function supposed to return if press_len is
smaller or equal than 50? And if it is exactly equal to
unit_delay*3? The best way to make sure you did not forget any case is
to have an else at the end that returns a default value in case no
condition matches:
else
    return '?';  // we could not understand

In this particular case, it seems to me like you already did the
debounce prior to calling the function, so it could be simplified to
char getSymbol()
{
    if (pres_len < 2 * unit_delay)
        return '.';
    else
        return '-';
}

Note that giving functions meaningful names is an important step in
making the code easy to understand and reason about.

if(i2>=2)
{
  i1++;
  i2=0;
}
else
{i2++;
}

All this serves no useful purpose, as you do not use i1 or i2 after
setup(). Removing useless stuff is also important for the clarity of
the code.

Serial.println("This code is not exist!");

It should say “I cannot understand this code!”, but it may well exist.
Now, to the core of the issue. If you want the program to be responsive,
you should embrace non-blocking programming. This means getting rid of
delay() (see Blink Without Delay) and getting rid of blocking
loops, like the two while loops at the top of loop(). A very useful
approach is to program your system as a finite state machine.
Please, take the time to read and digest these two resources.
Next, as an example, I can point you to a Morse decoder of mine that is
based on the finite state machine concept. You do not have have to look
at my code, which may be too low level for your taste, but look at the
documentation of the program internals. It explains how the state
machines are built and interact with one another. Below is a state
diagram taken from that documentation. It shows the state machine that
takes the debounced “rise” and “fall” events as inputs, and generates
“dot”, “dash”, “end-of-char” and “end-of-word” symbols as outputs:


What is the most Inputs on An analog Pin with a specified Accuracy on the Resistors Used?

My question using only 4k ohm resistors (connected in series in the
  voltage divider)

The circuit you are describing (a collection of identical resistors
connected in series) is quite different from the one discussed in the
link you provide. I assume you have in mind something analogous to a
digital pot, i.e. a chain of N resistors between GND and Vcc, with N
switches connecting the Arduino analog input to N taps along the chain:
N−1 taps in between consecutive resistors and one extra tap at GND¹.

simulate this circuit – Schematic created using CircuitLab

The push buttons could actually be the multiple contacts of a rotary
switch. If using real push buttons, it would be tricky to know whether a
button is being pushed or if you are just reading noise, though it can
be known by toggling the pin between output and input and using its
stray capacitance.

In this case, the worst case error happens when all the resistors on one
side of the tap are 5% too high, while all those at the other side are
5% too low. It can be easily shown that the minimum possible voltage at
tap k is

V−(k) = k(1−e)/(k(1−e) + (N−k)(1+e))×Vcc

where e = 0.05 is the 5% tolerance of the resistors. The
maximum possible voltage, V+(k), is given by the same formula
after replacing e by −e.

The graph below shows the expected voltage at each tap for a chain of
20 resistors, with the error bars showing the possible voltage
ranges. The blue curves are the analytical expressions of
V−(k) and V+(k).

As can be seen on the graph, the largest error bars are the ones closer
to the central tap. Thus, the buttons can be discriminated accurately if
the two taps closest to the center have non overlapping error bars. This
criterion could be translated into an exact formula, but the formula
would be quite complex and depend on the parity of N. I propose to do
instead some approximations, starting with a first order Taylor
expansion on the error. This expansion gives the length of the error
bars as

V+(k) − V−(k) ≈ 4/N2 k (N−k) e × Vcc

This error is maximal when k = N/2 (we will forget the parity issue):

V+(N/2) − V−(N/2k) ≈ e × Vcc

Then we say that the taps can be discriminated if this error is smaller
than the expected voltage difference between consecutive taps, namely
Vcc/N. Then the criterion is now simply

N ≤ 1/e

which is exactly what your intuition told you.

¹ The extra tap could be at Vcc rather than GND. It would be unwise,
however, to tap both GND and Vcc, as a user pressing both buttons
simultaneously would then short the power supply.

Edit to answer the questions in comments.

Yes, you could use the expressions of V+ and V− to
set the thresholds for discriminating the buttons. For example, you
could set the threshold between k and k+1 halfway between
V+(k) and V−(k+1), i.e.

threshold(k, k+1) = (V+(k) + V−(k+1)) / 2

However, if you try to compute that, you will see that it is extremely
close the average between the expected voltages. Then, you could use
that average as your threshold, which is given by a very simple formula:

threshold(k, k+1) = (k+½)/N×Vcc

Then, the pin number is just the integer closest to Vin/Vcc×N.
Assuming N = 20, this can be written as:

const float VCC = 5.0
float voltage = analogRead(PIN) * VCC / 1024;
int button_number = round(voltage / VCC * 20);

This can be optimized to use only integer arithmetics:

int button_number = (analogRead(PIN) * 5 + 128) >> 8;

Note that 20 buttons is kind of borderline. Your system could fail
if the errors due to resistor inaccuracies and those intrinsic to the
ADC (offset, gain error...) add up the wrong way. If you are building
only one device, then the safest fix would be to take note of the value
analogRead() returns for each button, and set the thresholds halfway
between consecutive values.

You could also measure the resistances of all your resistors, and
arrange them in a way that minimizes the errors. For example, if you
number the resistors from 0 to 19 in order of increasing resistance, I
would build the chain by arranging them in the following order:

0 19 2 17 4 15 6 13 8 11 9 10 7 12 5 14 3 16 1 18

Then you could most likely use the simple formula above to get the
button number at a minimal computing cost.


Can a DHT11+ESP8266 be powered by a Adafruit USB LiPo charger directly?

No, you can't.

The charger circuit will only operate properly with a battery attached.

It is not designed to provide power to a system. It is designed for charging the battery and nothing else.  You are supposed to remove the battery from the charger and then attach it to your circuit.  Even with a battery attached you can't use it to power your circuit - the voltage will be too high, and your target circuit will confuse the charger and it will fail to charge the battery properly (or it may end up over-charging the battery).

To do what it sounds like you want to do you need:

A LiPo charge circuit
A 3.3V regulator (ideally a Buck/Boost combined regulator)
Bypass circuitry to power the 3.3V regulator directly from the incoming power when present or from the battery when no external power is present.


What's the maximum number of keys in Yun Bridge?

The data is just stored in an array within the Python daemon. The ATMega32U4 just sends commands to set / get the values, so there is no limit imposed by the ATMega side of things.

The only limit is the size of the array in Python, and that is restricted by:

The amount of available memory in Linux, and
Whether or not you have swap space set up on the Yun

Since both those are very much variable (it depends what processes you have running, what your configuration is, etc) the answer can only really be:

Quite a few.

Putting memory aside for a moment, an answer to this question on SO states:

  According to the source code, the maximum size of a list is PY_SSIZE_T_MAX/sizeof(PyObject*) . On a regular 32bit system, this is (4294967295 / 2) / 4 or 536870912. Therefore the maximum size of a python list on a 32 bit system is 536,870,912 elements.

So you have the smaller of:

The maximum you can fit in Linux's memory, and
536,870,912


Does AWG size affect signal from sensors?

A signal is just a varying voltage.  A wire is just a (very long) small resistor.  The device reading the signal is just a current sink.

That's three terms there: voltage, resistance, and current. Three terms you should know are related by Ohm's Law.

Also, some simple rules:

The thinner the wire the bigger the resistance
The longer the wire the bigger the resistance
The more load on the wire the greater the current

And of course, that all means:

The greater the resistance or the greater the current, the greater the voltage drop across the wire.

If the voltage drop gets too great then the device receiving the signal won't be able to work out what it is.

But then of course a wire is also an antenna picking up all sorts of noise. The longer the wire the more noise it will pick up. And the thinner the wire the greater the resistance and the greater the resultant voltage drop, meaning the lower the noise margin and immunity.

So no, a thinner wire isn't better than a thicker wire. The exact opposite is true.


Atmega328P-PU: Programmer is not responding

I've read the tutorial at the crash-bang website and found two issues with it. The first issue is minor and probably won't fix your upload issue.

Step 3 says to connect +ve rail –> AVCC (pin 20) and +ve rail –> AREF (pin 21). You can leave those pins not connected. A really awesome guy named Julian ILETT has a video on youtube showing a homemade Arduino using the bare minimum connections needed. https://www.youtube.com/watch?v=sNIMCdVOHOM.

The second issue with the tutorial is in Step 5, "Connect the DTR pin of the FTDI, via a 0.1uF capacitor to pin1 on the ATmega.". A lot of people claim this works, but it doesn't work for everyone. It doesn't work for me and I have 2 of the identical FTDI programmers used in the tutorial. If you watch Julian's video starting at 12:48, you will see that he had trouble uploading a sketch using the DTR / 0.1uf capacitor method. He is using a different USB to TTL device but I have one of the identical devices he was using and the 0.1uf cap method doesn't work for me.

The solution to the upload issue is to use a switch to reset the Atmega328P-PU. Like the tutorial says, use a 10k ohm resistor connected to +5V and pin 1 of the Atmega328P. Now connect a one terminal of a N.O. momentary switch to ground and the other to pin 1 of the Atmega328P. To upload your sketch, click the upload button on the Arduino IDE window. As soon as the Debug window says "Binary Sketch Size…", press the reset button and hold it down for 1/2 a second then release.

I've just joined arduino.stackexchange.com a week ago so my answer may be a bit late. Hopefully this helps people in the future.


Arduno Uno voltage in via VIN pin or DC power?

DC Jack has a Reverse Protection Diode, that drops 0.7V at usable currents. The VIN does not. Both go through the on board LM7805 or similar linear regulator. The USB does not, but it does go through a P-Channel Mosfet used to switch between USB and DC/VIN power before connecting to the 5V rail. The 5V pin bypasses the regulator, Diode, and P-Channel Mosfet completely.

The advantage of the DC jack is that the Reverse Protection Diode is used, preventing reverse voltage problems if you wire it wrong.


Most relays have their ratings written on them. You can also find all the information you need in the datasheet for that relay. Search for the part-nr in your favorite search engine.

You need to find a relay that can handle at least 24Volt DC. Not AC as relays can handle a much higher voltage at AC than they can at DC.

You also need to check how maximum current your appliance draws. Make sure the relay is rated for at least that amount of Amps.

For example; the picture below shows a relay that's rated for 10A and 30VDC


Eventually I got it working. The connections that i made are as follows:

SDA pin on beetle -> SDA pin on SD card module
SCL pin on beetle -> SCL pin on SD card module
GND pin on beetle -> GND pin on SD card module
VCC pin on beetle -> VIN pin on SD card module

Then upload the sample code present on arduino IDE, or you can find it here as well: https://www.arduino.cc/en/Tutorial/ReadWrite

There we go!

EDIT: The soldering is tricky for bluno beetle. Detailed instructions can be found here :


Try to play with this one:

int forwardSpeed = constrain(400 - (size/256), -100, 400);

By changing the value of 256 and 400, not at the same time though, you better use 2 potentiometer to change those values. That's a trial and error though, I hope this will give you an idea.


Stopping / starting DC motor with Limit Switches and on/off button

Check your switches have pull-up resistors

It would be helpful if your question included a schematic. Do you have pullup resistors in line with your activation and limit switches? If not, you might find the input is "floating" - that is, it will randomly return either HIGH or LOW. This would possibly cause the motor to go forwards and backwards, but because the loop is possibly occurring hundreds of times per second, you might not see anything moving. You need pull-up or pull-down resistors in the circuit so the Arduino can see a definite LOW or HIGH. See https://www.arduino.cc/en/Tutorial/Button for a tutorial with a resistor, or even better, use https://www.arduino.cc/en/Tutorial/InputPullupSerial and use the existing onboard pullup resistors on the Arduino, as suggested by Juraj below.

Potential Logic Error

There might be a logic error in this part of the code:

  if (onOffButtonState == HIGH) {
    if ( frontButtonState == LOW ) {
      drawMovesForward();
    }
    else if (backButtonState == LOW ) {
      drawMovesBackward();
    }
  }
  else {
    if ( frontButtonState == HIGH ) {
      stopDrawFromMoving();
    }
    else if (backButtonState == HIGH ) {
      stopDrawFromMoving();
    }
  }

Loop #1: Let's say the onOffButtonState is HIGH (someone has pressed the switch to ON). The drawer is closed, so the front limit switch is depressed, so frontButtonState is HIGH. So the program will execute stopDrawFromMoving, and do nothing. Currently you are saying nothing is happening, so this might be your issue.

What you will probably need to do is use flags and while loops. For example:

At the start of the loop() declare this

drawerMovingOutFlag = 1;

Then change the loop to contain:

if (onOffButtonState == HIGH) {
    if ( frontButtonState == HIGH ) {
        while(drawerMovingOutFlag == 1)
            drawMovesForward();
            if ( backButtonState == HIGH ) {
                drawerMovingOutFlag = 0;
                stopDrawFromMoving()
            }
        }
    }
    else ...

I'll let you do the rest!


Bit shifting fails with warning: left shift count >= width of type

It's basically an inability of the compiler to auto-promote the source variables to a size big enough to fit the shifted version.

The default type for all operations, unless otherwise specified, is 16-bit. By shifting more than 16 bits you are overflowing that default type.

To get around it you have to manually tell the compiler that you want to work with 32-bits:

#define SET_CMD_ID(ID)      ( ((uint32_t)ID) << 27)
#define SET_CMD_CMD(CMD)    ( ((uint32_t)CMD)  << 25)
#define SET_CMD_TYPE(TYPE)  ( ((uint32_t)TYPE) << 19)
#define SET_CMD_PKT(PKT)    ( ((uint32_t)PKT)    )


strcmp() returns 0 when chars are different

strcmp is not for comparing a single character like your c parameter. It is for comparing a null-terminated string. I'm a little surprised you didn't get a compiler error, but there it is.

If you want to compare individual characters, just compare them with ==.


The HC-SR04 is not calibrated, nor does it take any measurements.

All it does is allow software on a connected microcontroller or system like an Arduino to measure the sum of the round trip time delay and some small internal offset delay, and from this calculate distance.

As the timing and calculation are entirely in your program, calibration is entirely up to you.

Under known conditions you could measure both a short and a long distance.  This would give you a slope and intercept - the slope from the speed of sound (which should not depend on the device at all, only on the conditions and your timing reference), and the intercept or offset, having to do with latencies in the system.

You could then cross-check at other distances, but under fixed conditions behavior should be linear.

As there is some initial ringing of the sender which can couple to the receiver and be mistaken for an echo, there will be a minimum distance below which you cannot reliably take a reading - as a guess, this is more than 5 cm, but you'll have to see, and it may even vary a little from unit to unit.

To a degree, it's a little bit amazing that these even work.  They use an RS232 level shifter to generate transmit pulses, and it's been alleged that the receive circuit is horribly mistuned, not really matching the emitted frequency at all... but despite that they do seem to work fairly well.


Is it possible for ThingSpeak to show a simple table of all data collected?

Since ThingSpeak has an extensive API, you can build a tool to read in data and display it as a table. I have created a GitHub repo called, "IoT Debugger" that allows you to see data as a table as the it comes into a ThingSpeak Channel.

To use the demo, enter your channel number and the read API key.

If you want to modify the project, fork the project on GitHub.


You can use both IDEs no matter of the origin of the UNO even fake ones runs with the IDEs.
The arduino.org IDE is just a fork of the arduino.cc.
But arduino.org has many Board which are only run with the .org IDE.


Bluetooth sending values from two joysticks

Arduino A

You can read the values from two joysticks as normal and send it like this. This method ensures of no data loss. Ensure that you read the values and store them in appropriate variables and then send it over serial.

// Setting Sensor pins
const int potPin = A0;
const int pot1Pin = A1;

// Creating variables
uint8_t pot;
uint8_t pot1;

void setup() {
// Declearing the pinModes' for sensors
  pinMode(potPin, INPUT);
  pinMode(pot1Pin, INPUT);
// Begining Serial Communication
  Serial.begin(9600);

}

void loop() {
// reading from the sensors
  pot = map(analogRead(potPin),0 ,1023, 0, 255);
  pot1 = map(analogRead(pot1Pin),0 ,1023, 0, 255);

//Packing the Serial message
  Serial.print("U*"); //A header
  Serial.print("A");  //a token to indicate the message payload
  Serial.print(pot);
  Serial.println("");

  Serial.print("U*"); //A header
  Serial.print("B");  //a token to indicate the message payload
  Serial.print(pot1);
  Serial.println("");

}

Arduino B

After the data are packed and sent over the serial. You need to unpack it with the other Arduino/device

The code will look like this:

String data; //Store each line of Serial communication
String pot1String = "0", pot2String = "0";
float pot1, pot2;
void setup()
{
  //initialize Serial communication
  Serial.begin(9600);
  //read first package
  if (Serial.available() > 0)
  {
    data = Serial.readStringUntil('\n');
  }
  //Disregard the first reading
  data = "0";
}

void loop() {
  //start reading from serial
  if (Serial.available() > 0)
  {
    data = Serial.readStringUntil('\n');
  }
  String payload = "";
  if (data != "0")
  {
    int offset = data.indexOf("U*"); //This is the header (0x552A)
    if (offset >= 0)
    {
      payload = data.substring(offset + 3, data.indexOf('\n'));
      char value = data.charAt (offset + 2);
      switch (value)
      {
        case 'A':
          pot1String = payload;
          break;
        case 'B':
          pot2String = payload;
          break;
      //Add more case as the project grow
      }
    }
  }
  //convert strings to float
  pot1 = pot1String.toFloat();
  pot2 = pot2String.toFloat();

// Continue with the rest of your project

}

Make sure to use the same baud rate in both sketches

Hope this helped. Ask me if you have farther questions


avrdude: verification error, first mismatch at byte 0x0000 : 0x00 != 0x16 using USBasp

The cause is most likely the fact that you "... do not use any resistors, capacitors etc."

Connect a 100nF capacitor between Vcc and GND.  Connect a 10KΩ resistor between RESET and Vcc.