USB Communication between Arduino Nano and UHF Reader module

I've been under the assumption that USB operates using UART.

No. You have it backwards.  Devices can emulate a UART (known as CDC/ACM) over a USB connection as one of the many possible device profiles, but it is about as far from being a UART as an F1 car is from a Penny Farthing.

USB operates on a strict Master / Slave principle. That is, it has a single master device, called the Host, which coordinates all the devices on the bus and makes requests to them.  Everything you plug into a USB system is a Device and requires a Host to tell it what to do.

Neither the Nano, nor this adaptor you bought, are Hosts. They are just Devices. And Devices cannot talk to Devices. Only Hosts can talk to Devices.

Which means you need a Host in there somewhere. If you want it controlled by Arduino then you need a USB Host Shield (or something similar) which normally communicates over SPI.

If the device you are trying to talk to uses the CDC/ACM profile then you can use the USB Host Shield with it. If it uses a proprietary profile, like the CH340G or FT232, then getting it to work with the USB Host Shield will be much harder (maybe even impossible) unless you are intimate with the underlying protocol used.


When the LCD pulled enough current to overheat, the Arduino's power supply (which I gather was the Uno's USB interface, at the time) was probably stressed to the point of failure. One fortunate result is that the Arduino took the hit instead of the computer's USB port that was supplying it. It's not clear which part was involved but here's a discussion on another forum concerning a similar failure and replacing the ATMegaxU2 which does USB-interface duty on the Uno (x = 8, if it's a rev 2 Uno, x = 16, if rev 3). It may be possible to replace the failed chip - regulator or USB interface (though with LEDs working, it's probably not the regulator). Otherwise, you can probably still program it with an ISP (In System Programmer). But the easiest way to do that is probably involves another Uno.


I'd take a look at Mark Kriegsmans FastLED example "DemoReel100". This example shows how to delegate to multiple functions.

First, I'll explain that example a bit: You set up an array of function pointers plus a variable for the current index.

typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
uint8_t gCurrentPatternNumber = 0;

All the functions (rainbow, juggle, etc) just need to work on your leds[] array that you gave to FastLED.addLeds() in your setup() -- I assume that your functions already fulfill that requirement. But: All functions must have the same argument list (in this case: they must be defined like void rainbow() { leds[x] = CHSV(a,b,c); }), so you might need to wrap them in another function.

Then, in your loop, you call your effect functions like this while calling nextPattern() every 10 seconds:

void loop()
{
  // Call the current pattern function once, updating the 'leds' array
  gPatterns[gCurrentPatternNumber]();

  // send the 'leds' array out to the actual LED strip
  FastLED.show();
  // insert a delay to keep the framerate modest
  FastLED.delay(1000/FRAMES_PER_SECOND);

  // do some periodic updates
  EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
}

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
void nextPattern()
{
  gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}

EVERY_N_SECONDS is a macro defined in the FastLED library; it basically does what you did with currentMillis, previousMillis and interval (There's also EVERY_N_MILLISECONDS and some other related macros).

That's the example so far, now we need to work with differing "effect switch times".

The easiest method in code would be to find the greatest common factor of all switch times -- let's say you want the rainbow() effect to last for 10 seconds, the juggle() effect for 15 and the bpm() effect for 5 seconds. All those switch times are a multiple of 5, so we put that as the switch delay: EVERY_N_SECONDS(5). Now, to get higher runtimes, we just put those functions multiple times into the array:

SimplePatternList gPatterns = { rainbow, rainbow, juggle, juggle, juggle, bpm };

There's another way, which gives you the option of setting the effect durations directly. First, we need an array of durations of the same length than our effect function array and a variable to remember where we are in the durations:

SimplePatternList gPatterns = { rainbow, juggle, bpm };
int[] gPatternDurations = { 10, 13, 73 };
int effectDurationLeft = gPatternDurations[0];

Then, we reduce the "effect switch resolution" down to 1 second and put a bit of logic around the nextPattern() call:

  EVERY_N_SECONDS( 1 ) {
    if( effectDurationLeft == 0 ) {
      nextPattern();
      effectDurationLeft = gPatternDurations[gCurrentPatternNumber];
    } else {
      effectDurationLeft -= 1;
    }
  }

Now you could set your pattern durations by editing the gPatternDurations array.

Please be aware that I did not test the code above. Syntax Errors may occur :)


Ways of communication between two Arduinos?

Let the ultrasound-module broadcast measurements and not care about whether anyone are listening or not. If you are using wifi, you can send to the broadcast address of the network you are using. Then the ultrasound-module does not need to know anything about the receiver, like ip address or number of receivers. The only thing you need to make sure is that they are on the same subnet. If you want to, you can later put another module on the same subnet and it will also receive the data.
If you establish a handshake protocol it complicates things, because there are so many cases you need to consider. What should happen if communication link dies after handshake, but before data are transmittet? Should the receiver acknowledge the data? What should the sender do, if it does not receive the acknowledge? etc...
If the only thing the sender is using the handshake for is to know whether to send data or not, then just send it and forget about it. If it was to do something special, in case there are no receiver, like logging data and send the log when the receiver comes back online, then there is a use case for the handshaking.


Detecting the presence of a specific smartphone

Can I easily detect that a specific smartphone is in proximity ?

It can be done, yes. How "easily" depends on how much money and expertise you have to throw at it.

  Can I use the smartphone's NFC (RFID) to do so ?

It is possible to use that, yes - if you add the right hardware and software to the Arduino.

  How long can an Arduino run on battery using a 9V battery from the market ?

A couple of hours if you're lucky. They are useless batteries.

  What kind of output could I possibly get from an Arduino ? I would like to make statistics, so it must be stored somewhere, and I know Arduino has not a lot of memory.

Whatever you want. Again, it's SMOP / SMOH.

  Is it possible to write on an USB key ?

Sure, if you get the right hardware for that.

  Which Arduino is best suited for my needs ? Should I consider buying an Arduino with Ethernet in order so send email ?

The Arduino that provides the facilities your project requires - and that depends on how you are going to decide on how to do it. Remember: the Arduino is just the "brain" of the operation. You need to decide what "organs" the brain needs to control and in what way.

There's a million and one ways of achieving what you want. You could even do it 100% in the phone in software (there's probably an app for that...) without need of an Arduino...


How to control a large number of devices with an Arduino

This is just a suggestion, certainly not the only possible approach.

Step 1: Get a handful of small linear actuators with a builtin
controller. Some actuators have no controller, and will require one
H-bridge and one analog input each. You do not want these. I have seen
some actuators with built-in controllers that can be driven just like
servos, I would suggest you get some of those. At this point you should
carefully look at costs when choosing the actuators.

Step 2: Learn how to drive those actuators from an AVR-based
Arduino, like an Arduino Uno, using the Servo library. I believe you can
drive up to 12 actuators with a single Arduino.

Step 3: Drive them using two Arduinos in a master-slave
configuration. The master would be a beefy Arduino, like a Mega or a
Due. It would send commands to the slave using, say, an I2C bus. After
sending the set points for the actuators, it would send a "go" order to
the I2C broadcast address. The slave would be the Uno. It would
interpret the commands and actually drive the actuators.

Step 3b: Change the master's program to pretend it is controlling
many slaves, and a total of 1000 actuators. In reality, all the
slaves would have the same I2C address: that of the unique slave
actually available. This will tell you whether your master is powerful
enough for the job, and you will see how the performance scales.

Step 3c: Optimize the slave's code. Try to have it work with an
8 MHz clock, and use as little flash and RAM as possible.

Step 4: Replace the slave Arduino with a bare AVR chip. You will
have to learn how to program it via ISP, but the information is widely
available. An Uno is an ATmega328P at heart, but depending on the
program size, you may get away with an ATmega48A, which is the same
thing only with less memory, and dirty cheap. Or even with a still
cheaper ATtiny. If you can make your program work with an 8 MHz
clock, then use the internal oscillator, which will save you having to
buy an external resonator. All this is to keep the costs reasonable.

Step 4b: Test, test, test. Last chance to change your mind before
committing big bucks.

Step 5: If everything works at this stage, it's time to scale up.
The same master Arduino, and one bare AVR for each dozen actuators, each
with it's own I2C address.


clkI/O 256 & 1024 (From prescaler) not working with driving PWM on Nano board

The main problem is the prescaler on Timer0 is already configured to divide clock source by 64 CS01 and CS00 are set (0b00000011).

And you are using bitwise OR to "change" prescaler: TCCR0B |= 0x05; or TCCR0B |= 0x04;. But this'll result into the clock source 7 (0b00000111) - clock source is expected on T0 input counting on rising edge.


Re-use smartphone/tablets parts like a camera

The connector on the flex circuit from that camera was made by Hirose (it has an HRS logo on it), and might be in the BM10, BM14, or BM20 series.  You can measure the pin spacing, stacking height, etc. to check which series it's in.  For example, the Hirose BM14 series of FPC to board connectors has pins at 0.4 mm Pitch and 0.8 stacking height.

Mouser.com carries a 24-pin BM14 connector that might mate or match with the pictured connector.  For other photos of Hirose FPC connectors, see google images for hirose fpc.

While you probably can find a matching connector (via careful measurement and perhaps some trial and error) and build an interface, it may be difficult to use the camera once it's hooked up.  Most Arduino models have too little RAM to support image processing.  A Yun might do it, a Tre, or some other micro entirely, eg Beagle or Raspberry.


You need to research 'Scope'.

Your variable has to be at the same level as all functions that will use it.  So at a simple level the answer has to be no.

int variableOne = 0;
void setup ()
{
  variableOne = 1;
}
void loop ()
{
  variableOne = 2;
}

The above code will work, but if you move int variableOne = 0; inside either function then it won't work, because the variable will not be in scope in the other function.

You can use parameters to functions.

void AFunction (const int& variable);

Will let you pass a single integer value to the function from the parent.  You can't change that value, because of the const qualifier.  If you remove the const then the & means pass the parameter by reference, which means you are passing in a reference (pointer) to the variable in the parent function and you can change it.  A better way to change the parent's value is to return a value from the call.

int AFunction (const int& variable);

So you could use this like this:

int AFunction (const int& variable)
{
  return (++variable);
}
void loop (void)
{
  int value = 0;
  value = AFunction(value);
  // value now == 1.
}

You could use a Singleton class, but this is hardcore and I'm not sure you would see any real benefit on an Arduino.  A class is a grouping of related function and variables that you see in libraries and a Singleton class means there will only ever be one during the lifetime of the program.  In this way you can declare an instance of the class (i.e. CSingleInstanceClass onlyOne;) and then retrieve/set data from the setup and loop function, i.e.

void setup ()
{
  CSingleInstanceClass onlyOne;  // Single instance class
  onlyOne.SetVariableOne (1);
}
void loop ()
{
  CSingleInstanceClass onlyOne;  // Single instance class
  Serial.println(onlyOne.GetVariableOne());// Prints 1
}

Hope that helps.


What are the basic steps to make a printed circuit board?

Software packages are, amongst others

Fritzing (more target at beginners)
Eagle (free for board of size 100 x 80 mm (4 x 3.2 inches)).
KiCad (open source)

Companies that make you pcb in small quantities are e.g.

OSHPark
seeedstudio
Dirt Cheap Dirty Boards

I personally create my own double layer PCBs at home. I first started with the toner-transfer method, but now use photo lithography. I etch in Hydrochloric acid and hydrogen-peroxide. I can have a finished board in 1-2 hours, instead of having to wait a week or so. Great learning experience.


Arduino recieve sensor data from other arduino SPI

Well had a bit of luck after spending all day on this.
Arduino UNO (sender): Like mentioned by chrisl, use Serial.write and not Serial.print
mySerial.write(sonar.ping_cm());

UNO Wifi (receiver):
Serial.println(mySerial.readString());

So, instead of mySerial.read I used mySerial.readString.
This is most likely a obvious mistake to almost everybody here; took me two days. Sigh.


Developing Standalone Arduino GUI Controller

The Uno is connected to the PC with a Serial interface (emulated over USB). The program on the PC only sees the Serial interface. It is not important, if there is really an Arduino at the other end. Nearly every programmung language can be used for interfacing a Serial interface, each gives advantages and disadvantages. But you will not have a single portable program file, that you can start on different OS without installing anything. Either you need to compile the program for each OS individually, or you can use a portable programming language, where you first need to install it's framework on the OS (for example python).

I would propose a different solution (that I'm currently also working on): Depending on your lab situation you could extend your project with a network interface, either Wifi or LAN. Then you can present a webinterface to the user. When writing HTML/javascript websites, it is easy to have them display correctly on most mayor browsers.

That way the GUI is really independent from the OS. For adding the network connection, you could use a LAN shield, Wifi shield, or directly change the microcontroller from an Arduino Uno to an ESP board, which has Wifi build in and is also has more computation power and memory.

The webinterface can be interactive by the use of javascript (since you cannot run php or similar on the Arduino or ESP).

Wether you want to use a companion application, that you write for the PC, or a webinterface is up to you and depends on your exact lab situation.


This is C++, so the single quotes are used for character literals. If you want string literal, you have to use double quotes. However, string literals can't be used in switch.

And you can't definitely use it like that if you are reading only one character.

However you can use single characters for this:

#define CH1 2
#define CH2 3
#define CH3 4
#define CH4 5

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

  pinMode(CH1, OUTPUT);
  pinMode(CH2, OUTPUT);
  pinMode(CH3, OUTPUT);
  pinMode(CH4, OUTPUT);
  digitalWrite(CH1,HIGH);
  digitalWrite(CH2,HIGH);
  digitalWrite(CH3,HIGH);
  digitalWrite(CH4,HIGH);
}

void loop (){
  if (Serial.available()) {
    char ser = Serial.read();
    switch(ser){
      case '1':  onPin(CH1); break;
      case '2':  onPin(CH2); break;
      case '3':  onPin(CH3); break;
      case '4':  onPin(CH4); break;
      case '5': offPin(CH1); break;
      case '6': offPin(CH2); break;
      case '7': offPin(CH3); break;
      case '8': offPin(CH4); break;
    }
  }
}

void onPin(int8_t pin) {
  digitalWrite(pin, LOW);
}

void offPin(int8_t pin) {
  digitalWrite(pin, HIGH);
}

Or you can toggle the relay states.

Test strings as commands are little bit harder to use as you have to read whole command (or use state machine). Following example is little bit unnecessary hard but it's working...

constexpr uint8_t     channels = 4;
constexpr uint8_t ch[channels] = { 2, 3, 4, 5};

template <uint8_t pin, uint8_t val> void setChan() {
  digitalWrite(pin,val);

  Serial.print("setChan: "); Serial.print(pin);  Serial.print(' ');  Serial.println(val);
}

using action_t = void(*)(void);

action_t  on_actions[channels] = {
  &setChan<ch[0],LOW>,
  &setChan<ch[1],LOW>,
  &setChan<ch[2],LOW>,
  &setChan<ch[3],LOW>
};

action_t off_actions[channels] = {
  &setChan<ch[0],HIGH>,
  &setChan<ch[1],HIGH>,
  &setChan<ch[2],HIGH>,
  &setChan<ch[3],HIGH>
};

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

  for (auto pin : ch) {
    pinMode(pin, OUTPUT);
  }
}

String command = "";
action_t action = nullptr;

void loop() {
  if (action != nullptr) {
    action();
    action = nullptr;
  }
}

void serialEvent() {
  if (Serial.available() > 0) {
    char inChar = (char)Serial.read();
    if ((inChar == '\r' || inChar == '\n')) {
      if (command.length() > 0) {
        Serial.print(command);
        if (command.startsWith("on")) {
          uint8_t channel = command.substring(2).toInt()-1;
          if (channel < channels) {
            action = on_actions[channel];
          }
          Serial.print(" On="); Serial.print(channel+1);
        } else if (command.startsWith("off")) {
          uint8_t channel = command.substring(3).toInt()-1;
          if (channel < channels) {
            action = off_actions[channel];
          }
          Serial.print(" Off="); Serial.print(channel+1);
        }
        Serial.println();
        command = "";
      }
    } else {
      command += inChar;
    }
  }
}


Could I use metal buttons as a capacitive button for my arduino project?

Yes, that would work.

The only thing to watch out for is that the buttons might be plastic with a thin layer of metal on top (Chemical vapor deposition).


Calling external function from a class function

Yes, you can do it.

You pass function pointer as function parameter.

See this stackoverflow question:

https://stackoverflow.com/questions/2582161/c-function-pointer-as-parameter


To compare with F() macro encased strings you have to use special forms of the string functions that are suffixed with _P.  You also need to cast the string literals to the right type (PGM_P).

To do a case-insensitive comparison you should use strcasecmp instead of strcmp.

To put those together you end up with:

if (strcasecmp_P(cmdParam, (PGM_P)F("help")) == 0) {
    ...
}

There is a problem here:

found = strtok(next[type], &separator)

strtok takes a C string as a list of separators (must be NULL terminated). You're passing it the address of a single character. There may or may not (probably not) be a NULL in the next byte in memory, but everything else up to the first NULL found in memory will be taken as delimiter characters.


Connect Multiple L293D Motor Controllers to Arduino

The suggestion of using an Adafruit Motor Shield V2 for Arduino seems fairly good, although that particular shield controls only four DC motors at once.  That shield has a dedicated PWM driver chip on it, which removes the overhead of motor and speed control from the MCU.  That might allow you to drive four motors via the shield, and two via wires from the Arduino; or, stack two motor shields on the Uno.

If you definitely want to drive six motors from the Arduino, you may need to add a couple of control chips.  You could add a 74HCT04 hex inverter and a 74LS595, to create inverted drive signals and enable signals.  For example, the first PWM drive would go to L293 pin 1A and to '04 pin 1A; the first '04 output, 1Y, would drive L293 pin 2A.  One of the '595 outputs would go to L293 pin 1,2EN.

Alternately, you could use two '595s, with outputs to control L293 pins 2A; 4A; 1,2EN; and 3,4EN on each of three L293's.  The six PWM outputs from the Uno would go to 1A and 3A on the several L293's.  Using motor shields probably is a better idea, however.


How to handle multiple input pins at once?

How fast do we need to read the magnetic switch to not miss any pulses? I'll make some working assumptions:

Using 700c wheel and 28mm tire [assumed; adjust as necessary]
Rolling radius 2.1m [from here; there are other ways to arrive at this]
Max speed 22 m/sec (50mph), [working assumption; adjust as you see fit]
Magnet and switch interact for at most 3% of a rotation, [WAGuess]

The wheel will have to turn at ~10RPS at max speed giving a pulse period of 100ms. The pulse width will be at most 3% of that, or 3ms.

Your service loop would have to execute in somewhat less than 3ms, every time, in order to not miss any wheel pulses and that's if I haven't been too optimistic about the pulse width. I'd personally assume a 1ms maximum loop time, then test it on the road by sampling & logging wheel-pulse level with an Arduino at at least 10x that rate or 10+KHz.

Or I'd go with an interrupt-driven wheel pulse period timer not width) to ease the constraints on the main loop.

The main loop need only poll your turn, brake, and horn switches and a timer for blinking the turn signals. Even if the timing is a little erratic for some reason, no harm is done, and nothing is likely to be apparent to the rider or other road users.


Formula for decision making when in contact with an obstacle using Arduino

The algorithm mentioned in the blog uses a Fuzzy Logic Controller to perform obstacle avoidance. You can read up more on fuzzy logic here: https://www.calvin.edu/~pribeiro/othrlnks/Fuzzy/home.htm

  newMotorSPD_L = basicVelocity + urgMotor_L + (urgTurn_R/4) - (urgTurn_L/2) + 60;
  newMotorSPD_R = basicVelocity + urgMotor_R + (urgTurn_L/4) - (urgTurn_R/2) + 60;

Based on the code, the formula is basically made up of variables with different weight/ratio.

basicVelocity is the default moving velocity of the robot when there is no obstacle or wall detected.

urgMotor_L/urgMotor_R is the ouput of the controller for frontal object detection/avoidance by getting the difference between the left and right ultrasonic sensor.

(urgTurn_R/4) - (urgTurn_L/2) is probably the left/right bias?

+60 at the end is probably to offset the error of the motor. (Assuming all other variable are 0, the robot should be still at 60 for their case?)

To simplify what the formula does, it can be shown using this graph:


Error - invalid conversion from 'char' to 'const char*', Not able to connect on pubnub server using node mcu

problem was in the declaration of API keys and channel on the above code

Here is the right code:-

const char * pubkey = "publisher key from your account";
const char * subkey = "subscriber key from your account";

const char * pubchannel = "demo_keyset";
const char * subchannel = "demo_keyset";


Cannot use radio transmitter after switching to LowPower library

I've never tried this, but if you are putting the Arduino to sleep I would expect it to cut power to the devices (does it?) if it does then after a 30 minute sleep I would expect the devices to come back up in the initial state.  Guessing by your code the initial state of the radio is Tx Disabled, so try moving the

tempSwitch.enableTransmit(RADIO_PIN);

to before the

float temp = dht.readTemperature();

line.

I'd also be concerned that the DHT22 is not in the correct state after you wake up.

Can you try doing a 1 second LowPower sleep in debug mode, I suspect it would work more often.


You would be better off formatting it nicely instead of relying on String...

char macValue[17]; // Don't forget one byte for the terminating NULL...
uint64_t mac = ESP.getEFuseMac();
sprintf(macValue, "%016x", mac);
client.publish("esp32/ChipID", macValue);

However, I'm not certain that sprintf can cope with a 64 bit value like that directly. If not, you can split it:

char macValue[17]; // Don't forget one byte for the terminating NULL...
uint64_t mac = ESP.getEFuseMac();
uint32_t hi = mac >> 32;
uint32_t lo = mac;
sprintf(macValue, "%08x%08x", hi, lo);
client.publish("esp32/ChipID", macValue);


Did I accidentally short something? My Arduino UNO board does not communicate with the computer anymore

Unfortunately, the arduino's input pins are not tolerant of 12 volts, You have likely caused permanent damage to the chip =(. There is a regulator that makes it capable of being powered by 12 volts, but the input pins are different.

If you look at table 30-1 on the datasheet for the Uno's controller here you can see the input characteristics. The arduino is powered at 5v, so the max digital input voltage is 5.5v


Do Arduino Nano Every devices short out?

this might because of powering issue...try using different source having a good number of current capability. likely up


Extracting data from Arduino MultiWii Flight Controller

Since you're new to Arduino, I'd suggest beginning with a basic interfacing arduino activity. Once you understand reading and writing digital and analog signals it's pretty much plain sailing from there. You may want to invest some time and a bit of cash in a beginners course on Udemy (try PEter Dalmaris' course https://www.udemy.com/arduino-sbs/) it's a good start. From there, talking to the MultiWii should be a piece of cake. Also, check out http://www.multiwii.com/connecting-elements


The problem is that you can't use serial's find function to look for one thing or another.  It is a greedy function and it will consume everything coming in to the serial port until it finds what it's looking for or until it times out.  That includes the :1 if you are using find to look for the :0 at the time.

Instead you either need to receive the whole string into memory and examine the string to see what it contains, or you need to manually process the data as it comes in character by character to decide what there is.


How to debug an Arduino sketch on a Mac?

So... I want to debug the WaterMote sketch, but I do not see an option in my Arduino IDE on Mac OS X. Is there a way to debug sketches using Macs? Searching online shows various and preferred options, but mostly on Windows (of which I don't have any at home).

It's definitely possible to debug a sketch with OS X. But it's definitely an advanced AVR topic, and if you're not experienced enough with embedded programming you should first try to avoid it, except if it is really necessary.

Debugging a sketch for an ATmega328 implies:

Running a flasher such as the AVR Dragon, the JTAG ICE 3, the STK500 or the AVR ONE; no cheap flasher implements the DebugWire protocol;
Setting up the debug fuse, which is an operation that can brick your MCU.

If you're using an ATmega32U4 (or alike), you won't be able to do it out of the box, as the 32U4 needs a JTAG connection for on-chip debugging.

Finally, once you got through that, you can bind a gdb to the AVR using AVaRICE. I'm not getting you through all that, because I really, really, strongly advise you not to do it until you're experienced enough to know what you're doing.

  Moteino with WaterMote sketch loaded
         connected via USB to the MacBook Pro
         Arduino IDE running, but I see strange "[][][]" square output in the Serial connection.
         I do not know what to make of this since that text is not in the WaterMote sketch.
  Is there a way to debug sketches loaded on Arduino clones using Arduino IDE on Macs?

It is very likely you did not setup the correct baudrate for the serial outputs. Arduino IDE defaults to 9600 bits/s connections, whereas the WaterMote source code defines a 115,200 bits/s connection. When you open the Serial Monitor change the setting at the right of the status bar.

And finally, be sure to uncomment the #define SERIAL_EN line to enable the serial communication and debug outputs.


Vin and Ground pins shorting only under specific conditions

But it only shorts when: The Arduino has power

You must not use a continuity checker or ohm meter on a powered circuit.

Not only will it not work, you risk damaging the meter.

It's also not necessarily safe to use such a meter on an unpowered active electronic circuit like an IC or eval board, as the meter must apply a small amount of power to the circuit to make a measurement - how much power varies between meters and settings, and how much a circuit can tolerate in an unintended way depends on things like polarity and the state of other parts of the circuit.  However, it is common practice to do so - especially for example when there's a fear that the device might already be damaged.


What you are trying to do is perfectly safe. In fact, you reading PINC
will have no effect whatsoever on the input circuitry. You are just
reading an I/O register and, whether you read it or not, this register
is updated on every clock cycle from a set of comparators that monitor
the pin voltages.

Just for completeness, I should mention that it is possible to disable
the comparators that update the register. The Atmel datasheet recommends
to disable them if you want the lowest possible ADC noise. If you follow
that recommendation, then reading PINC will just return zero. The
Arduino core library does not disable them: the input comparators are
thus always active, and you can get a meaningful value by reading that
digital input register.

Edit: You can selectivly disable the input comparator on the pin
A2 by issuing DIDR0 |= _BV(ADC2D);. But that is only useful if you
really need to maximize the accuracy.


MPU6050 Measure distance traveled or position

You won't - not with any degree of accuracy anyway.

You could attempt "dead reckoning" whereby you estimate the current speed by the acceleration and deceleration over time, and from that get a rough idea about the distance travelled in any one direction, but the accuracy will be so poor and the drift so huge that it would be next to pointless.

Instead you really want to monitor the wheels. Count how many revolutions (or half revolutions, quarter revolutions, whatever accuracy you need) and combine that with the circumference of the wheels to calculate how far you have travelled.


Arduino: load variables with values read from SD card

File implements Stream just like Serial. so you can use parseInt and parseFloat

int n = File.parseInt();
float x = File.parseFloat();
Serial.println(n);
Serial.println(x, 6);


The specification1 says (emphasis is mine):

using IO trigger distance, the high signal to at least 10us.

So, longer than 10 μS is not a problem.
With respect to less than 10 μS, well 5 μS may also work, but it is out-of-spec and therefore not guaranteed to work and so may not always work correctly, or as expected.
From Source 1:

From Source 2:

As to why must it be 10 μS, well that is probably (at a guess) down to the design of the logic upon the silicon and the resultant propagation delay through the logic gates. Most, if not all, logic ICs specify a minimum amount of time required for a signal level, in order to allow the signal to propagate through the transistors that make up the logic, so that they switch correctly. PN junctions require a finite time for the electrons and holes to move, and when there are a number of them in sequential stages, that time is multiplied by the number of stages that the signal needs to propagate through. That is a very simplified way of looking at it.
To confirm this, you would need to speak to either the designers, or take a look at the mask used to fabricate the IC. Test simulations were probably run during the design phase, and they suggested a minimum trigger pulse of 10 μS. The figure could also be arrived at by simply looking at the design and counting the number of stages and multiplying that by the propagation delay per stage.
However, as Valbhav points out, the HC-SR04 is controlled by a STM8 (actually it is a STC11F), and after having looked at the STM8 programming manual, it is more related to instruction cycles. The Trig pin is, I assume, an interrupt, and from section 3.2 CPU registers

When an interrupt occurs, the CPU registers (CC, X, Y, A, PC) are pushed onto the stack.
This operation takes 9 CPU cycles and uses 9 bytes in RAM

So, 9 CPU cycles just begin to to service the interrupt, and then however many needed to actually do the rest. I can't find any timing diagrams in the Programming Manual which would show the minimum interrupt signal length.  This information, is however in the Reference Manual
The length of a CPU cycle will obviously depend upon the clock frequency., which according to this schematic, from An Ultrasonic Shortcut – Getting the HC-SR04 Transducer Up and Running Fast!, is 4 MHz:

So, 10 μS is 40 CPU cycles.

1 Sources for downloading HC-SR04 pdf datasheet:

Source 1
Source 2

HC-SR04 Specifications

Working Voltage: DC 5V
Working Current: 15mA
Working Frequency: 40Hz
Max Range: 4m
Min Range: 2cm
Measuring Angle: 15 degree
Trigger Input Signal: 10µS TTL pulse
Echo Output Signal Input TTL lever signal and the range in proportion
Dimension 45 * 20 * 15mm


Why when I pull an EEPROM index the value returned is garbage?

Your array is in PROGMEM, but you are accessing it as if it were in RAM.

You must use pgm_read_word() to access the data in your array.

pgm_read_word(&(colorTheme[EEPROM.read(x)]))

BTW - what Arduino board has more than 2kB of EEPROM?


There's an obvious code problem in your blink() function:

state != state;

The above statement will never modify your state variable. The != operator in C/C++ does not perform an assignment (unlike operators such as += and -=). It's a comparison operator which just tests for inequality. You presumably meant to do this:

state = !state;

That may not fix your problem entirely though. You might find that the interrupt doesn't get reliably triggered anyway because it's not designed to handle AC. I'd recommend using an external comparator circuit to generate a clean digital signal, such as a Schmitt trigger.


I found what's happening. Module was shutdown due to over voltage.


Use ESP-01 with Arduino Uno/Nano, with the ESP8266WiFi library

You cannot use that "library". Simply because that isn't a library, that is a core. It's the entirety of the Arduino API designed to run on an ESP8266.

You can use it to program the ESP8266 directly and nothing else. No part of that has anything at all to do with Arduino boards like the Uno.


Can an AT89S52 be programmed using an Arduino as ISP?

You should be able to use the Arduino as an ISP since an ISP is basically just a serial to SPI interface. If you are trying to use the arduino software to upload your program, you will need to edit your boards.txt file to be able to talk to the chip. If you are just using avrdude you will need to update your avrdude.conf.  AVR Freaks has a post on someone trying something similar and may be of some help. Without knowing your environment it's difficult to give more specific advice


I resolved this issue by installing older arduino ide version.


Autolock transistor for powering Arduino

Here is a mock-up of what I usually do.

simulate this circuit – Schematic created using CircuitLab

Keep in mind that the resistors are just an example value: you'll have to make some calculations.

Now, M1 is a PMOS, while M2 is an NMOS. Both MOSFETs should be able to turn on and off with the voltages you can supply them (so look at their Vgs curves). Moreover the M1 mos will be the one where all the supply current will run, so you'll have to choose it wisely. The M2 mos will only have to supply a small current, so the smallest one is fine. Beware that if the Vin voltage is greater than the maximum Vgs voltage of M1 you'll have to add a resistor between M1 gate and M2 drain to form a voltage divider with R1.

The R4 and D1 are used if you want to detect a SW1 push (for instance to turn off the device). If you don't need this feature, remove them both.

The circuit works this way: when you push the button, a voltage (for instance 5V - 0.6V of D1) will come to the arduino Vcc. The arduino then should immediately bring up the pin. This will turn on M2, which in turn switches on the M1 transistor, thus bypassing the switch. When you remove it, the arduino stays powered.

When the arduino decides that it should turn off (either because you pressed the button again, or because it timed out, or who knows) it executes two instructions: one to pull down the pin and the other is while(1). This prevents it to continue executing the program. The M2 transistor shuts down, the M1 gate floats to Vin and so it shuts down too.

You can find the transistor as discrete componetns (sometimes also in the same SOIC-8 package. Usually I use big pMOS (e.g. IRF9310 in SOIC8) and smaller nMOS (usually in SOT-23 case). I do this because I can easily solder them also on perfboards (SOIC8 single transistors have a lot of redundancy for pins, while SOT-23 ones can be mounted easily on 3 pads).


how to fix mirrored text on 3.2 inch IPS TFT LCD Display ILI9481 480X320 36 Pins for Arduino Mega2560

The orientation of the display is controlled by the "Set Address Mode" command (0x36) at line 42 of the ILI9481 driver.
The current value is 0x0A which is 00001010 in binary.  According to the datasheet (8.2.25) bit 6 is "Column Address Order", and that is set to "Left to Right" currently.
Turning that bit on should reverse the column order for the display.
So changing those two lines of code to:
LCD_Write_COM(0x36);
LCD_Write_DATA(0x4A);

should have the desired effect.


Various suggestions:

Create 2 different arrays of pin numbers: 1 for the first group of relay pins, and the 2nd for the second group of relay pins:

byte firstRelayPins[] = [7, 8, 9, 10, 11, 12];
byte secondRelayPins[] = [13, 14]; //Replace values with your relay pins

Write a function that returns a random index from one or the other of the arrays based on a bool:

byte randomPin(bool useSecondArray) {
    int max;
    int index;
    if useSecondArray {
       return secondRelayPins[random(sizeof(secondRelayPins))]; //Fetch random pin from array
    } else {
       return firstRelayPins[random(sizeof(firstRelayPins))]; //Fetch random pin from array
    }
}

Based on the state of your switch, set useSecondArray when you call that function to determine which relay's pin you turn on.

Use the returned value to set the desired relay pin.

In your "turn everything off" code, use the arrays of index pins rather than hard-coded indexes.

You should also refactor your code to use millis() rather than using delay(). (Search on "Arduino blink without delay" for guidance on how to do that.)

Note that this is a rough outline of what to do. The code above will likely need to be adjusted to fit your needs. Don't expect to be able to copy/paste it into your project.


You need a driver board to run it. SSD1963 based ones are popular and are often included on the screen, especially the 7" ones on eBay.

Arduinos cannot drive a display directly. Small TFT screens often include the driver chip on them in the form of a Chip On Glass (CoG). That can't be done with the larger screens due to the sheer amount of memory needed to store the frame buffer. So an external chip has to be used, or a microcontroller with built in TFT interface.

Note that even with an SSD1963 (or equivalent - see the ones BuyDisplay sell are based on the RA8875) interfacing the Arduino to the TFT screen results will most likely be somewhat disappointing. Especially if you are interfacing using SPI or I2C which will create a bottleneck. Best is to interface with a 16-bit "8080" interface (16 data bits, read, write, chip select, reset and D/C), however that takes a lot of IO pins, and ideally a proper parallel interface to drive it quickly. And you want a lot of RAM for manipulating the data you want to display...


Extract binary data from text string. Like Perl pack, not just regexp

Something that does both simple matches, and converts data to binary
  return values on the fly.

You are describing sscanf(). It is way less powerful than
regexps when it comes to pattern matching, but it seems to closely match
your requirements.

Dummy example:

const int FORMAT_COUNT = 2;
const char * formats[FORMAT_COUNT] = {
    "c,%*x,%lx,%lx,%lx",  // first data logger
    "%lu %lu %lu"         // second data logger
};

// Here goes the data.
unsigned long channels[3];

// Try to parse using all the known formats.
void parse(const char *message)
{
    for (int i = 0; i < FORMAT_COUNT; i++) {
        int ret = sscanf(message, formats[i],
                &channels[0], &channels[1], &channels[2]);
        if (ret == 3) {
            Serial.print("Message \"");
            Serial.print(message);
            Serial.print("\" matched with format \"");
            Serial.print(formats[i]);
            Serial.println("\"");
            return;
        }
    }
    Serial.println("Could not parse message.");
}

Sample output:

Message "c,03,1234,5678,9ABC" matched with format "c,%*x,%lx,%lx,%lx"
Message "2342 1313 234236" matched with format "%lu %lu %lu"


Why is my arduino now working with my LCD 16x2 displays?

Well first when looking at your code what you are essentially doing using the Clear() function is that you are writing something to the memory of your lcd screen again.If you really want to clear the display you could use lcd.clear().Try changing that.
And make sure that your wiring is correct.


Although I have not used either SparkFun's RedBoard Turbo or the MOVI voice shield, reading the specifications, which you can find on their respective web sites, it would appear that they have incompatible power requirements.
The SparkFun's RedBoard Turbo board web page says

The barrel jack connection on the RedBoard Turbo has a lower input voltage than most Arduino development boards. Make sure that you are using a power supply below 6V. Please be aware that the RedBoard Turbo is also a 3.3V device and not a 5V one like the original RedBoard.

Whilst the MOVI voice shield PDF manual (page 7) says

What you don’t see in Figure 1 is a power supply jack. MOVI is powered through the
Arduino board that needs to be powered using an external power supply. The external
power supply should provide between 7V and 16V and at least 500mA current. During tests
we usually used either 9V or 12V. Battery packs with this specification work as well.

So the one needs less than 6V whilst the other more than 7V. I don't know if you can break the power connection between the two boards and feed the MOVI from a separate supply (9V is very common in the Arduino world) or you may have to swap your SparkFun for an Arduino that runs on 5V and uses a 9V supply.

The gotcha is that Arduino boards, their clones and code compatible boards such as the ESP32 etc fall into 2 different groups, those that run on 3.3V and those that use 5V, and you must be very careful you don't over voltage the latter.

I haven't delved into the specifications further, but you will almost certainly find that the logic levels used by the two boards are also incompatible. One will be using 0 & 5V whilst the other 0 & 3.3V. Connecting a 5V logic output to a 3.3V logic input is not conducive to long life and happiness for the latter.


How do you make a switch case run until another serial input is detected?

Use something like this (it is pseudo code so convert it to your sketch):

enum EState { NORMAL, SPECIAL } _state; // States
enum ENormalState { RED, YELLOW1, GREEN, YELLOW2 } _normalState; // State only valid when _state == NORMAL
unsigned long _time; // _time only valid when _state == NORMAL

void loop()
{
   if ('serial input available')
   {
      if ('input == ...')
      {
         _state = NORMAL;
      }
      else if ('input == ...')
      {
         _state = SPECIAL;
      }
      ...
   }

   switch (_state)
   {
   case NORMAL:
       if (_time + ... > time())
       {
          // Change to next state
          switch (_normalState)
          {
          case RED:
              _normalState = YELLOW1;
              _time = time();
              break;

          case YELLOW1:
              _normalState = GREEN;
              _time = time();
              break;
          ...
          }

       setLight(_normalState); // Change the light according to the _normalState
       break;

   case SPECIAL:
       ...
       break;

   ...
   }
}

Ideas to improve/explain:

Try to make some specific functions for setting the light according to the current state
You do not need a delay
Split functions (like above, make a separate function for normal state, and specific state


Decimals missing when using radio.write(); with Arduino

Since I can't comment yet I will place this as answer.

But have you tried to use radio.print(data[1], DEC); ?

DEC stands for Decimal for if you want to force something to print it in Decimals. When you want something to be printed in Hexadecimals you can use HEX for example. Hope this will help you.


What are the tools that I need to program the Arduino in C?

Well, if you want to do more advanced stuff with your AVRs, you should definitely leave the Arduino environment, and integrate your AVR development in your "usual" favorite development environment, whatever it is.

Then you've got two choices, either do 100% pure C with AVR libraries, for which you only need a simple makefile that calls avr-gcc with avr-libc libraries as include path. You can also use Atmel Studio that helps you a lot on that stuff. But if you do so, you're loosing the advantages of the libraries built for/by the arduino community – which, sadly, is not a huge loss for a strong majority of those.

Or you can work your code out as a 100% C external library, used from within the sketch, and included at linking time. Then you'll have all the advantages of working with any C++ library you'd like to have, but still doing the important code in pure C. Having only the .ino used to generate the main .cpp and any .cpp library you'd need. Though, for many basic features like writing on the serial port, you'll have to do it [the good old way][2] or by doing some weird encapsulation of Serial.println() call sent as a functor to the pure C parts.

In the makefile I've written (debian offers another one with the non-gui install of arduino), every .c file from declared libraries are detected and compiled with avr-gcc, every .cpp file is compiled with avr-g++ and both gets linked when doing the .elf/.hex file.


First of all: it is not a good idea to do dynamic memory maagement in embedded systems (in casu arduino)
Secondly freeing memory means: marking the memory as available. It does not mean "setting the memory to 0"
because ar still points to the same locaton in memory it is "normal" that it also still reads the old values. Only -according to the C CP0P0 pàrogramming rules- you should not do so. Reading will not cause problems but writing will very likely.


Unexpected behaviour of blinking LED code

As Abhishek mentioned in his answer is correct, but the better way is to use for loops while dealing with many led's.

Let's say you have led's connected from pin 2 to 8.

int pin = 2;
void setup()
{
   for (Pin = 2; Pin < 8; Pin++)
   {
     pinMode(Pin, OUTPUT);
   }
}
void loop()
{
   for (int Pin = 2; Pin < 8; Pin++)
   {
     digitalWrite(Pin, HIGH);
     delay(1000);
     digitalWrite(Pin, LOW);
     delay(1000);
    }
}


The 5V pin is either supplied by the USB port, which has a limit of 500mA (imposed by a resettable fuse) if directly connected to the computer or a powered hub (or 100mA in an unpowered hub), or the on-board regulator (NCP1117ST50T3G), which is 1A, when powered externally.

The 3.3V pin is regulated using an LP2985-33DBVR which has a current limit of 150mA (the specifications on the website say 50mA. This is wrong. I think it is a left-over from the old Uno boards with FTDI chips where the 3.3V was fed directly by the internal 3.3V regulator of the FTDI chip and thus limited to 50mA).

Yes, the 5V pin has more than enough current to run an LM741 op-amp.


I am very new to Arduino and the kit tutorial just told me to wire this, I do not know how to wire it. Can Someone plz help!

If you don't have a breadboard, get one. It's a board with lots of holes in it that you can use for experimenting.
Something like this:

https://www.adafruit.com/product/64?gclid=EAIaIQobChMIz9XDj9bF6wIVcuW1Ch2_kgD3EAQYAiABEgL4DvD_BwE
As Delta_G said in their comment, you could wire a circuit as simple as yours by just putting the wires from the components directly into the terminals on the Arduino, but that quickly becomes impractical. Get a breadboard and learn how to use it.


Windows upload from command line gives Access Denied

This is because you are running the Windows App Store version of the IDE.
Windows doesn't like you messing with the insides of App Store programs (I think it scares it...).
Install the real version of the IDE from the Arduino.cc website and it will work.


Alter baud rate after being certain events

To answer your specific question, yes you can alter the baud rate after an event.  Just use a Serial.end() then a Serial.begin() with the new baud rate.


How can arduino read a frequency higher than 16Mhz?

How can arduino read frequencies higher than 100Hz? How does it achieve that?

Interrupts (if you want to do it in software) or a magical piece of hardware called the Input Compare peripheral that is built into most MCUs.

  I Googled arduino's frequency and it shows to be 16MHz. That means arudino can read frequencies up to 16Mhz?

No, that is the speed the CPU operates at. The maximum frequency signal it can read is usually below that (for SPI it's half that, 8MHz, for example).

  Ethernet cables specifically CAT5 has a frequency of 100MHz. That means that it sends signals 100,000,000 in one second! How could Arduino send that many signals in one second if I where to buy a Ethernet shield such as this one?

It doesn't. The shield does. The Arduino just tells the shield what to do, and the chip on the shield does it.


Access method from main sketch inside class

Unlike Java, which insists on everything being inside a class, C++
allows “plain” functions which do not belong to any class. In fact,
main() in standard C++, as well setup() and loop() in Arduino
code, are all plain functions. Then, the main program (or “sketch” if
you wish) is not an object, you cannot give it to the constructor of
your class. Instead, you would give it a pointer to the particular
function it needs. This is called a callback, because the library is
calling back something from your main program.

Here is how I would write it in C++:

/*
 * Class definition.
 */

class DoClass {

    // Define a callback type: a pointer to a function taking no
    // arguments and returning void.
    typedef void (*callback_t)();

public:
    // Constructor.
    DoClass(callback_t _callback)
        // Initialize internal callback with the one given as parameter.
        : callback(_callback)
        // empty function body
        {}

    // This class method invokes the callback.
    void doIt() { callback(); }

private:
    // The callback is kept as private internal data.
    callback_t callback;
};

/*
 * Main program.
 */

// This is the function we are going to provide as a callback.
void doSomething()
{
    Serial.println(F("Doing some work..."));
}

// Instantiate the class statically.
DoClass doObject(doSomething);

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

void loop()
{
    doObject.doIt();  // <- this will invoke our callback.
    delay(1000);
}

The class could be instantiated dynamically
(DoClass *doObject = new DoClass(doSomething);).
I prefer to do it statically when possible, because dynamic memory
allocation can easily led to memory fragmentation problems in such small
platforms.


I had a similar issue once before. It actually matters a lot to properly ramp up your stepper motor. Especially under load if you ramp up too steep you can loose steps.

Since you are already using the arduino environment I suggest you could use the AccelStepper library.

I lets you set the acceleration and max. speed parameters nicely and uses a properly calculated ramp.


Arduino Nano no output on any controllable pins except for RX and TX pins

I've tested pins 26 (serial), 5 (digital) and 15 (digital) and none output anything.
No, the LED doesn't need a resistor ...
because I tested it with the 5v and 3.3v therefore higher voltages doesn't blow it up

Sounds to me like you have damaged your output pins. Read The care and feeding of LEDs by Mike Cook.
The LED may briefly light up, but without a resistor you are damaging both the LED and the output pin. It is no surprise then, that afterwards the pins "none output anything".
Without a limiting resistor the output driver on the Arduino is overloaded and may burn out. Whether you have damaged the LED, the pin, or both, is hard to say.

(Edited to add)

still doesn't work on pins that I haven't used ...

Can you slow down a bit?

I've tested pins 26 (serial) ...

There is no pin 26 from the IDE point of view. On the board pin 26 is A7 (analog input 7) which cannot be used for digital input/output.
Please specify exactly what pin you tried (just choose one) and stick to the Arduino number (printed on the board, eg. D05) and then show the code you used to access that pin.

According to this ... the analogue pins can be used just the same as digital pins

That page shows a Uno. You have a Nano.
See Arduino Nano - Arduino.cc. On that page:

Analog pins 6 and 7 cannot be used as digital pins.


I2C Master-Slave Arduino system to control array of steppers

I don't quite understand the problem. A
 arduino mega would have no problem controlling 9 of these steppers alone. If you are asking about i2c protocol please be more specific about what you need help with.


Mega 2560 pin output power and control question

Neopixels only need a control signal and Gnd when powered externally - connect the external power supply Gnd to the Mega Gnd as well.

The 2560 chip can definitely work with 800mA (200mA per VCC & Gnd pin, and there are 4 of each). The onboard supply can't cope with that - you get a max of 500mA from USB (due the 500mA PTC fuse, the big gold or green part next to the USB connector), or something under an 1000mA depending on how 5V is created. 12V into the barrel jack and high current will over heat the 5V regulator. 7.5V into the barrel will give you a better shot at high current. Then there is 1V rated reverse polarity protection diode between the barrel jack and the regulator.  You can't put 5V into the barrel and get 5V out, you need to overcome the diode and the regulator. 7.5V wallwarts work well for that. www.dipmicro.com used to carry 7.5V/1A wallwarts, I don't know if they still do.  If you decide to use an external 5V source via the power header, then the power headers are only rated for 1A current as well.
I use this one for 5V projects, 4A to power the Arduino, make yourself a power cord splitter and have 5V for other stuff as well direct from the wallwart, and not off the Mega board.

Are the lasers controlled by current into the R,G,B pins, or are they externally powered and R,G,B are just control signals? If their power comes from RGB, then you'll also want to power the TLC5947 seperately and just connect control signals and Gnd to the Mega.


Here is the step-by-step on upgrade the ESP-01 AT Command firmware (for running on macOS).
Wiring
For flashing the ESP-01 firmware, you need to have a USB-TTL adaptor as a programmer.
+---------------------+---------+
|                     | RxD Vcc |
|       Top View      | IO2 RST |
|                     | IO0 CPD |
|                     | GND TxD |
+---------------------+---------+

ESP-01          USB-TTL Adaptor
 VCC   ---------- 3V3
 GND   ---------- GND
 TxD   ---------- RxD
 RxD   ---------- TxD
 CH_PD ---------- see note* below
 GPIO0 ---------- Connect to a push switch (Flash button) to GND
 RST   ---------- a push switch (Reset button) to GND

Note: depend on whether you have ESP-01 or ESP-01S, for ESP-01, you will need to connect CH_PD either directly to 3v3 or via a 3k-10k resistor to 3v3. However, you don't need the an extra pull-up resistor for ESP-01S as CH_PD already has on-board pull-up resistor. This picture shows the different between ESP-01 and ESP-01S, visually ESP-01 has 2 LEDs on board near the antenna, while ESP-01S have two extra resistor between header pins and ESP8266EX chip, and with only one LED.

Download and install esptool
Download and install esptool from https://github.com/espressif/esptool. esptool is a python application. You need to have python installed as well.
Download firmware 2.1
Download ESP8266 nonOS SDK - Release 2.1.x, noticed that this is not the latest version as the latest version doesn't works for ESP-01 based on my experience.
Upgrade the firmware
You will actually only need 4 files for the upgrade, I would suggest that you copy and paste those files into your esptool directory from the downloaded bin/ directory. cd into your esptool directory and run the following commands to upgrade the firmware.
To put ESP-01 into programming mode:

Press and hold BOTH buttons;
Release the Reset button while keep holding the Flash button until the upload is completed;
Press Reset to start the newly uploaded program when all upgrades are done.

./esptool.py --port /dev/cu.SLAB_USBtoUART write_flash 0x00000 boot_v1.7.bin
./esptool.py --port /dev/cu.SLAB_USBtoUART write_flash 0x01000 user1.1024.new.2.bin
./esptool.py --port /dev/cu.SLAB_USBtoUART write_flash 0x7c000 esp_init_data_default.bin
./esptool.py --port /dev/cu.SLAB_USBtoUART write_flash 0x3e000 blank.bin
./esptool.py --port /dev/cu.SLAB_USBtoUART write_flash 0x7e000 blank.bin

Please noted that /dev/cu.SLAB_USBtoUART is the USB port for my USB-TTL interface, yours might be different, run ls /dev/tty.* to find out your USB port


Difference between these two NodeMCU boards?

The top one is a real NodeMCU version 1 board (ESP-12E module).

The bottom one is a knock-off copy - looks like the same module on it.

The biggest difference is the USB interface. The real one uses a CP2102 USB to UART bridge. The copy uses a CH340G chip.  The CH340G is notoriously unstable and liable to die at a moments notice.  The CP2102 is far more reliable.  I recently accidentally nuked a Wemos D1 Mini pro which has the same CP2102 on it with 12V.  It took out the voltage regulator. It took out the ESP8266 chip.  I replaced both those, and the CP2102 was proved to still be working fine. More than could be said for a CH340G - glance at one of those wrong and they die.


Question about infrared receiver with metal shell to detect heart pulse rate?

"Proper" oxygen meters use a bimodal LED - red + IR - so there will be limitations to this. They also have a piece of copper foil wrapped around the sensor & heavily earthed, so your shielded sensor has, already, an advantage!

You should be able to use your receiver exactly the same way. If you can ground the shield, do so.


Yes, absolutely, it should work. But your code will be easier to read if
you use some constants, like:

const unsigned long SECOND = 1000;
const unsigned long HOUR = 3600*SECOND;

delay(7*HOUR);


Regarding “The data pins will be wired to pins 6, 8, 9, 12 and 13 and each will have a 470 ohm 1/2W resistor on each pin”, note that WS2812s typically are connected together in strings, with the DO (data out) pin of each upstream unit connected to the DI (data in) pin of the next unit downstream. Thus, there is no need to allocate five Arduino IO pins; one is enough.

For further background on WS2812 mechanisms, see for example Is it possible to infer the length of a neopixel string using 1-wire protocol?, and see discussions and diagrams at adafruit.com and sparkfun.com.

Regarding use of an efficient step-down switching-supply voltage regulator set for 12 V out, if you use an adjustable regulator you might as well set it lower than that, for example at 8 or 9 volts. Typically, the regulators on Arduino boards that convert Vin to +5 or +3.3 V are linear regulators rather than switching regulators, so every unnecessary extra volt (above the dropout limit) proportionally increases the amount of wasted energy.

In typical use, a WS2812 draws 20 to 60 mA current, supposing up-to-five-volt power. Thus, a string of 30 to 40 of them will draw at least 0.6 A, in most cases, and up to 2.4 A, if all are on at top brightness. In either case, an external power supply would be de rigueur. You would connect the external supply's ground to the Nano's ground; the +5Vs need not be connected together.

Edit: Addressing questions from comments

Re “if one data in will control the entire array of LEDs, it should be connected to D13”, I'm not aware of any reason for that idea, and indeed would recommend against it. On many Arduino models, D13 drives an LED. While the Uno uses a buffer amplifier to drive the LED, the Nano just has a 680 Ω resistor in series with an LED. I'd not load it further.

Wiring each of several strips in its own chain seems quite reasonable. Yes, you could wire all the DIs of 30 or 40 WS2812 units in parallel. However, parallel inputs would require 30 or 40 wire runs, vs. the simple wiring chain the WS2812 is intended for. Note, per its spec sheet the WS2812 DI load is ±1 µA max, so one '328 IO pin could drive hundreds of them. But input capacitance, up to 15 pF each, probably precludes driving thousands in parallel.

If performance is an issue, possibly use short chains (up to several dozen units long) in parallel, rather than one long chain of hundreds of units. The spec sheet says, “When the refresh rate is 30fps, low speed model cascade number are not less than 512 points, high speed mode not less than 1024 points.” (Low speed refers to 400Kbps signalling; high speed, 800Kbps).

Note, paralleled chains improve refresh rates only when multiple chains are used to show the same pattern. Otherwise, each chain being refreshed separately is no faster than refreshing the same number of units in series. The library that drives a chain of WS2812s hogs the whole processor each time it sends a chain of data. Also note that scan rates of 400 Hz are mentioned in the spec sheet. It is likely to be futile to try to exceed that by paralleling units.

Summary: If you have a dozen or so units on a rotor arm, I'd wire them in series. If it's more convenient to keep each arm's wiring separate from that of other arms, then do so. If each arm will show the same pattern as other arms, you could wire the chain inputs (the first units in each chain) in parallel, else would use separate driver pins.


Powering 30+ LEDs and flickering one at random

Yes, it is possible, but it's harder than making one LED light up, and then doing the other 29 the same.

An LED typically draws 20mA, which is within the limit for an Arduino pin (40mA); however, there is also a 200mA limit for all pins together, so you cannot power more than 10 LEDs off the same arduino. Also, the Arduino only has 13 digital pins, and 5 analog pins, a total of 18 pins. This includes 2 pins used for programming your Arduino.

If you want to run lots of LEDs, the easiest way is running it through an external chip. You can buy a pre-made board e.g. https://www.adafruit.com/products/1429 (24 channel, these can be daisy-chained together for more than 24 LEDs).

Alternatively, you can save yourself some money if you can just buy the chip - a DIP chip, or through-hole, will slot directly into a solderless breadboard, and can be soldered onto veroboard later to make your project more permanent.

There are a number of chips that will do the job, you want an "LED PWM driver" chip - for example, the TLC5940. There is a tutorial for this at http://tronixstuff.com/2013/10/21/tutorial-arduino-tlc5940-led-driver-ic/ - PWM just means you can control the brightness of each LED (individually).

If you want to make your project more permanent, you can solder a board of your own - find someone who can solder (your local makerspace/hackspace will be glad to help, I'm sure!) to teach you the basics, don't burn yourself. The easiest way is to use stripboard (aka Veroboard), this also means you can solder the resistors on to the same board (the LEDs too, if you like!). It sounds very intimidating, but it's not hard to learn. You can then buy PWM chips (make sure you get through-hole, aka "DIP" chips - https://en.wikipedia.org/wiki/Dual_in-line_package ) rather than "surface mount" chips. The chips are sensitive to heat, so to start you might want to solder on sockets (see same wiki page), then you can slot the chips in later.

You should consider very carefully your power supply - find out how many milliamps (or amps) it can provide - every (lit) LED will draw 20 milliAmps, and the Arduino is rated for 200mA, so if you want more than 9 LEDs, you will want an external power source, with an appropriate rating - 500mA = 0.5 amp will drive 24 LEDs. In this case, do NOT use the 2.1mm jack on the Arduino to power it; the transformer will overheat.

P.S. - you will be able to control the exact brightness of each LED independently. Also, if you use RGB leds, and use 3 pins on the IC to drive each LED, then you will be able to control the exact colour of each LED too!

Good luck!


How to send a pitch bend MIDI message using arcore?

arcore creator Ralf Kistner provided the answer:

// The pitch bend value is a 14-bit number (0-16383). 0x2000 (8192) is the default / middle value.

// First byte is the event type (0x0E = pitch bend change).
// Second byte is the event type, combined with the channel.
// Third byte is the 7 least significant bits of the value.
// Fourth byte is the 7 most significant bits of the value.
void pitchBendChange(byte channel, int value) {
  byte lowValue = value & 0x7F;
  byte highValue = value >> 7;
  MIDIEvent event = {0x0E, 0xE0 | channel, lowValue, highValue};
  MIDIUSB.write(event);
}


switch pump on with transistor, mosfet, or relay

Transistor - Big voltage drop between C-E @ 5A (depends on type but it will be about 2V). Power dissipitation is voltage drop times current so about 24Watts. You must be careful with inductive load - induced high voltage must be supressed. Usual way is using anti-parallel fast diode over load.
Mosfet - Voltage drop can be really small, so it might be possible to use it without heatsink. Big Gate capacity needs strong driver to charge and discharge. If not, slow switching causes huge losses (again voltage drop times current). For inductive load it's same as for transistor.
Relay - It must be selected carefully as switch-off causes electric arc (= burning contacts) and because of DC current it's burning for much longer time than AC.


Setting serial number on CH340 USB-Serial device

There is no storage on the CH340 and family of UARTs where you could put a unique ID. This is also a problem for the PL2303 type. I have been trying to find solutions for this problem. First and easiest is the position of the device on the USB bus. It will be unique for each device. If you're using linux you can find each device under /dev/serial/by-path . There is also a /dev/serial/by-id but there will only be one entry there for this device because it shows the last one connected. FTDI chips will each have unique entries here. Cheap chips won't, but they each have an entry under /dev/serial/by-path.
This position, and the device names, should persist across reboots. If you have a lot of changes to your USB devices, plug all the CH340 devices into the same hub, then plug that in. The devices will enumerate in the order that they are plugged in to the hub. This one-hub trick should work for MacOS and windows too, they should come up in the same order.

Harder method- udev rules.
For devices with a unique ID such as FTDI you can set a udev rule that sees it's serial number and then creates a symlink to that device, it's straightforward.

For devices with the same or no Serial number, it's a lot more complex. I created a udev rule that looks like this:

SUBSYSTEM=="tty", ATTRS{product}=="USB2.0-Serial", RUN+="/usr/local/bin/cheapduino.py %k", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ENV{ID_MM_DEVICE_IGNORE}="1"

when the device matches the product and vendor of the cheap arduino, it runs the script 'cheapduino.py' with the device as argument, for instance

cheapduino.py ttyUSB0

Then the cheapduino script connects by serial to the device and sends the string 'ID' and the software on the device responds DEVID=THX1138 or whatever. The script then creates a symlink /dev/THX1138 that points to /dev/ttyUSB0

There are a lot of drawbacks to this method. The script must time out if the software on the cheapduino doesn't answer. Also this is not using the SYMLINK function of udev so it won't clean up dead links on disconnect, but it will overwrite them on reconnect. All of your cheapduinos must have this functionality in their software, with different device IDs set. They all must use the same baud rate as the script unless you want to write a very complex script that takes a long time. Finally, this method works much better at low baud rate than at high baud rate, which for timing reasons may not succeed every time. (cheapduinos are cheap!) 9600 works much better than 115200 which works after several tries. But since all your CH340 arduinos must be the same speed with this method, you can only go as slow as your fastest device.

This method DOES work though, and it's what I'm using because I bought way too many of these cheap things.

In the end, buy genuine Arduinos or at least ones with FTDI chips or something else that sends a unique device ID.

=Rich


What you're doing wrong is living your life at a normal speed.

The LED will be blinking, but so fast you can't see it change.

Without adding some delays in there you will just see the LED light up.


Setting serial speed on your computer side doesn't change speed on the HC-06 side. So you have to set the same speed for HC-06 interface (and in your sketches) as a bootloader is using.


Serial communication between an Uno and an Esplora by connecting their usb ports together

It will not work. USB communication is master/slave. There must be a 'host' and a 'device'. Uno and Esplora are two 'devices'.

Connect the boards over TTL Serial. Wire Rx and TX pins together, TX to RX and RX to TX. And ground of course.

Serial on Esplora is the USB interface. In 'core' I see the Esplora has a second serial interface called Serial1. According to schematics, the RX and TX pin of Serial1 on Esplora are on LCD header as DC_LCD (RX) and RESET_LCD (TX). Use this Serial1 to communicate with Uno.

On Uno side you should disconnect the Uno from computer to not disturb the Serial interface with USB connection. Or use SoftwareSerial to communicate with Esplora and have debug prints to Serial Monitor.


Using Blynk to control stepper motor is jerky

Blynk runs over a network and therefore cannot respond in real-time nor consistently. You could have the Blynk slider control set a local variable which the motor controller would use for motor speed, but the basic motor-drive timing needs to be locally controlled and independent of network operations. The SimpleTimer library is one way; a timer interrupt would be another.


How to rotate a servo motor on a specific angle?

The kind people who have written the Arduino libraries include software drivers for servo control.  These drivers abstract the hardware from the programmer of the sketch software (the sketch is application software you write in C or C++).  It is unnecessary to understand the driver in detail.  However the servo driver software (likely written in C++) can been examined here.

To move a normal servo to a particular position, make a call to the Arduino Servo Driver using the function write(angle) passing an angle value from 0 to 180.  The value is an approximation of degrees and the value type is of type integer.

In the above links you will find this example of sweeping the servo motor across its range:

/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Proceed to that page for more details including a schmatic (diagram) of how the servo is connected to an Arduino Uno board.


The Arduino "language" is actually C/C++. GNU GCC and tool chain are used. The Arduino IDE uses a preprocessor to make it easier for beginners by removing some of the C/C++ requirements such as forward declaration of functions.

The GNU AVR GCC data types and representation, and the answer to your question can be found on the project Wiki page; https://gcc.gnu.org/wiki/avr-gcc

For C/C++ there are build-in data types but also a set of standards. One of the standard header files with data types is stdint.h. http://www.nongnu.org/avr-libc/user-manual/group__avr__stdint.html

Arduino.h and additional header files within the Arduino core libary contains the extensions or redefinitions made. The complete reference list; https://www.arduino.cc/en/Reference/HomePage

Cheers!


Install the latest Arduino IDE with windows administrator rights.


I was working with it more and I found that my mistake was that I was using pin 0 and 1 to test (serial) and switching to pin 2 and above works.


Arduino fingerprint verification from server

According to the adafruit driver's code, it is capable of loading and storing fingerprint templates (256byte each) from and to its flash

  uint8_t emptyDatabase(void);
  uint8_t storeModel(uint16_t id);
  uint8_t loadModel(uint16_t id);
  uint8_t getModel(void);

These functions would allow you to sync the local database of each device with a server for example or even download and test for each template individually, which would obviously be pretty slow and only viable, if you had to store more templates than the flash itself can.

You can encrypt this data before transmitting in whatever way you wish but that is a topic on its own.

Other than that your components seem to be compatible.

An idea for syncing:

Every unit should check on a fixed interval of 1 second for instance, whether the online database has changed. This may be represented by a simple counter i.e. version that increments with each change and is copied to local storage after downloading the latest changes.

So whenever an Arduino uploads a new fingerprint model or your mobile app removes a fingerprint, the counter on the server is incremented and every other device knows to update its database in case the local version is lower.

Another tip if changes happen very frequently:

Every flash memory just has so many write cycles before it dies.
If you happen to update the database a lot, you should try to minimize the stress on each fingerprint sensor's memory by assigning an arbitrary, unique id to each fingerprint and storing a local 'map' where you have stored which id on this specific device.
This way you can update only the fingerprint(s) that have actually changed.

Good luck.


My best guess (not knowing what the pins are driving) is that your trying to draw too much current from the Arduino gpio.

Ref: https://playground.arduino.cc/Main/ArduinoPinCurrentLimitations


How to analogRead() 2 separate pins simultanously?

This is not a full code but more of an explanation of the logic of your program.

  when the flex sensor is triggered, a sound is played on the piezzo buzzer. The tone it makes is dependent the values received from the proximity sensor.

Follow this logic and try to code it:

1- read the flex sensor values

int val = analogRead(flexPin);

2- if it is triggered, THEN read the proximity sensor.

if(val > minimum) {
  int distance = analogRead(proximityPin); //this line depends on which proximity sensor you are using

3- play the sound accordingly to the proximity sensor (still in the if loop).

analogWrite(distance);

This logic should work fine. If you could include more info like board, flex sensor and proximity sensor, that could help.


ESP8266 crashes when trying to copy a string into a big char

Function local variable are created on the stack, and in the case of an ESP8266, the total size is limited to 4096 Bytes - so, 3900 for one variable is cutting it close.

I would recommend you either use malloc/free

int str_len = payload.length() + 1;

// Prepare the character array
char *xml = (char *) malloc(str_len);

// Copy it over
payload.toCharArray(xml, str_len);

// there I'll parse xml with tinyxml2 but the MCU crashes before getting here
//
// when done, free the memory malloc'd

free(xml);

or, if you know an absolute maximum size for the string, e.g. 5000, make char xml[5001]; in the global scope


bit_is_clear(ACSR, ACO) Instead of digital_read(1)==LOW

Does [bit_is_clear(ACSR, ACO)] have something to do with something
  called in Internal Analog Comparator?

Exactly. ACSR is the “Analog Comparator Control and Status Register”.
ACO, the “Analog Comparator Output” is one bit of this register. The
ATmega328P has the same comparator, with the same register and bit names
as the ATmega8. C.f. the datasheet. You should be able to use this
part of the code as is.

  Frigon has wired his Atmega8 in a peculiar way. [...]

It seems to me that is termination is intended to ensure that, in the
“floating level”, the line AVC− is at a potential higher than AVC+. In
the “driving level”, the opposite should be true, with a difference of
at least 120 mV.

  I attempted to create something similar using while(digitalRead(2)) ;

It's not surprising that it doesn't work. This is a differential bus.
The information is carried by the potential difference between AVC+ and
AVC−, not by the potential of a single wire. A difference higher than
120 mV should be interpreted and a high state. Your digital input
instead reads a single wire and compares its potential to ground. The
thresholds to switch between LOW and HIGH are typically around 2.1
and 2.6 V, with some hysteresis. This is far from being compatible
with the signaling of the bus.

I recommend you follow Frigon's steps and use the analog comparator just
as he does. The comparator will tell you which of AVC+ or AVC− has a
higher potential, and it will not be bothered by the low level of the
differential signaling.


How can I make Arduino IDE use Atmel's provided toolchain? (Linux/Ubuntu)

In the directory for the new core create a new platform.txt and give the entry for compiler.path the location of the bin/ directory containing the Atmel toolchain.

compiler.path=/path/to/bin/


Using Arduino to control a high voltage DC device

Batteries are going to be annoying because they're run out and have to be recharged/replaced. A mains power supply would be easier to "set and forget.
I did a google search on "36V DC power supply" and found a 4A power supply from "Alitove" on Amazon for $22.99 US. That should be fine. (Assuming you are somewhere with 120VAC mains power. If you live somewhere with 240VAC mains power you would need a different unit, but since I found one, I would expect a google search in your region would find one for your area.)
I would suggest using a logic-level MOSFET transistor + flyback diode to switch your DC power. That's easier to do than a relay (That would require another power supply.)


While EEPROM.read and EEPROM.write are valid methods, it's like mopping the floor with a toothbrush. Use EEPROM.put and EEPROM.get instead.

For example:

#include <EEPROM.h>

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

  uint addr = 0;

  // fake data
  struct {
    uint val = 0;
    char str[20] = "";
  } data;

  // commit 512 bytes of ESP8266 flash (for "EEPROM" emulation)
  // this step actually loads the content (512 bytes) of flash into
  // a 512-byte-array cache in RAM
  EEPROM.begin(512);

  // read bytes (i.e. sizeof(data) from "EEPROM"),
  // in reality, reads from byte-array cache
  // cast bytes into structure called data
  EEPROM.get(addr,data);
  Serial.println("Old values are: "+String(data.val)+","+String(data.str));

  // fiddle with the data "read" from EEPROM
  data.val += 5;
  if ( strcmp(data.str,"hello") == 0 )
      strncpy(data.str, "jerry",20);
  else
      strncpy(data.str, "hello",20);

  // replace values in byte-array cache with modified data
  // no changes made to flash, all in local byte-array cache
  EEPROM.put(addr,data);

  // actually write the content of byte-array cache to
  // hardware flash.  flash write occurs if and only if one or more byte
  // in byte-array cache has been changed, but if so, ALL 512 bytes are
  // written to flash
  EEPROM.commit();

  // clear 'data' structure
  data.val = 0;
  strncpy(data.str,"",20);

  // reload data for EEPROM, see the change
  //   OOPS, not actually reading flash, but reading byte-array cache (in RAM),
  //   power cycle ESP8266 to really see the flash/"EEPROM" updated
  EEPROM.get(addr,data);
  Serial.println("New values are: "+String(data.val)+","+String(data.str));
}

void loop()
{
  delay(1000);
}

UPDATE:  If you want to understand how the "EEPROM" is emulated in the ESP8266, you might want to reference https://github.com/esp8266/Arduino/tree/master/libraries/EEPROM, specifically, EEPROM.h.

Also, EEPROM.end is not needed, it simply clears the local byte-array cache of the flash/EEPROM from RAM.  It serves on other function.


Arduino MEGA2560 wake up using DS3231 RTC

after further web research, it looks like this is a bug which hasnt been fixed yet.
it was discussed previously here and here.

My solution was to go into the "LowPower.cpp" scroll down to the lines, where the functions are not declared and I just out-commented them. Compiling works now.


Good detective work so far!
In the admin page you found one can see the name of the module: HLK-RM04. Googling on that I found the manufacturer/seller page.

A PDF with some information can be found here.

Also one link with somebody's experience with the module.

For other projects you might want to try as well the ESP8266 - very cheap and seems a lot of people have experience with it, so you might find more information on the net.


Mega + SIM808 GPRS GSM GPS IPX-SMA module power on from code

Looking at the pictures it looks like it should be possible to take the two exposed connections of the switch and add flying leads to them and run them back to the microprocessor to allow it to turn them on and off.  The possible problem is the current that has to run through the switch.

You will need to investigate, but it looks like it could be done like that if you can't find a better solution.


'readPulsioximeter' was not declared in this scope

The problem is that you have no function called "readPulsioximeter" in your code. Either define it, pick a different function, or remove that line of code.


Standalone chipset, power regulation & pinout

Voltage regulation is needed if the voltage you are providing to the chip is outside (or can drift outside) the allowed range for the chip to operate.

At the upper limit that is 5.5V. The lower limit is 1.8V. Note that at lower voltages you can only reliably run at lower clock speeds.

If your power source is between those two voltages (say a 3.4V LiPo battery) then you don't need a regulator.

If your power source is above 5.5V (say a 9V PP3 battery [urgh]) then you definitely need a regulator.

A proper regulator is quite a complex device, and it is highly unlikely that you have the components to make one.  A simple, very inefficient one, though, can be made using a resistor and a 5V Zener diode if you have one.

Until you have your own regulator of whatever form, yes, you can power the chip from the 5V pin of the Arduino.

The pin mapping for the chip -> Arduino IO numbers is in the file pins_arduino.h for the Uno variant in the IDE.  In the top of that file is this handy drawing:

// ATMEL ATMEGA8 & 168 / ARDUINO
//
//                  +-\/-+
//            PC6  1|    |28  PC5 (AI 5)
//      (D 0) PD0  2|    |27  PC4 (AI 4)
//      (D 1) PD1  3|    |26  PC3 (AI 3)
//      (D 2) PD2  4|    |25  PC2 (AI 2)
// PWM+ (D 3) PD3  5|    |24  PC1 (AI 1)
//      (D 4) PD4  6|    |23  PC0 (AI 0)
//            VCC  7|    |22  GND
//            GND  8|    |21  AREF
//            PB6  9|    |20  AVCC
//            PB7 10|    |19  PB5 (D 13)
// PWM+ (D 5) PD5 11|    |18  PB4 (D 12)
// PWM+ (D 6) PD6 12|    |17  PB3 (D 11) PWM
//      (D 7) PD7 13|    |16  PB2 (D 10) PWM
//      (D 8) PB0 14|    |15  PB1 (D 9) PWM
//                  +----+
//
// (PWM+ indicates the additional PWM pins on the ATmega168.)


Yes.

If you're using an Ethernet Shield, you should be able to run a webserver on the Arduino and simple do an HTTP request from your C# webservice to the Arduino.

Check this tutorial on how to write a webserver for arduino using the ethernet shield: http://arduino.cc/en/Tutorial/WebServer

Doing an HTTP request of any kind from C# should be easy enough and is not in the scope of this site.


You will need to open up the VarSpeedServo library source code and read through it to understand how the library actually works with your sketch.

Consider that you have not setup an initial position before issuing your first "slow moving" command.  It may be by setting an initial position before assigning a pin to the servo, you may prevent any unexpected movement.

Try something (for your code) like "myServo.wirte(0,0)" where the first argument is the position and second is the speed.


Powering a Nano with a 5v mini USB adaptor

Thanks all. I found a different power source with a mini-usb connector and it works fine. I think when plugging it in to the PC the Nano makes some faint clicking noises but when direct to  5v plug it does not? I'm not sure so I'll re-test. It was the lack of clicking that lead me to believe it wasn't working as I can't see the on board LEDs using my enclosure.

I don't know about the accuracy but it seems to work for my situation - it is to be placed in a fridge that recently turned itself in to a freezer but has since fixed itself. This project is an early warning system in case it decides to do it again.

Thanks again.
Jack


Will Setting Interrupt Pin High Damage Bluetooth Module?

I'm not sure, if you can rule out the hardware damage (you wrote, that you removed the linear voltage regulator, but didn't explain more there). But with that code you won't get what you want.
I see multiple issues, all boiling down to the same problem: You cannot do that inside of an ISR:

delay() relies on interrupts to happen during its execution. As of my knowledge this leads to delay() never ending, blocking your code. Also it is very bad design to have a long running ISR. So much is depending on interrupts to work and when you have something long running, you can just easily do that inside the main code, triggered by an interrupt flag variable.
millis() will not increment during the run of the ISR.
delayMicroseconds() will work, but you still should keep the ISR very short. Reading an ultrasonic sensor is a no-go.
Serial.write() will fill the libraries internal TX buffer, but the actual transmission of the data also relies on interrupts. You won't get your data that way.

Instead of doing all that inside the ISR, you should just let the Arduino wake up, then set a (single byte) flag variable. In your main code you need to check for that flag with an if statement. In that if statement, you are doing all what you need to do and at the end you are resetting the flag and going to sleep again.


Use an DS3231 RTC instead. It include a temperature sensor with digital output. No need to read an analog value and it means less component in your PCB.


Configuring Accelerometer on BNO055 sensor

This was partly discussed as an issue on the library's github

https://github.com/adafruit/Adafruit_BNO055/issues/48

Here's how I understand it:

The library doesn't configure the registers you want. I don't see a reference to writing to the ACC_CONFIG register (address 8). Not even defined in the header.

The sensor has two register-pages (0 and 1) [refer page 50]. I.e. if you select page 0 then the register at address X means something, at page 1 it means something else.

We want to write to ACC_Config at address 0x08 on Page 1.

Page 77 tells us that, regarding writing to the register: "Write: can only be changed in sensor mode, see section 3.5.2"

In code, you could hack something in there:

https://github.com/adafruit/Adafruit_BNO055/blob/master/Adafruit_BNO055.cpp#L115

After changing to the sensore mode, you could then write to the register as

//values taken from section 3.5.2 page 27
#define BNO055_ACC_CONFIG_2G (0) //0B00
#define BNO055_ACC_CONFIG_4G (1) //0B01
#define BNO055_ACC_CONFIG_8G (2)  //0B10
#define BNO055_ACC_CONFIG_16G (3)  //0B11

//bandwidth definitions
#define BNO055_ACC_BW_7_81_Hz (0)
#define BNO055_ACC_BW_15_63_Hz (1)
#define BNO055_ACC_BW_31_25_Hz (2)
#define BNO055_ACC_BW_62_5_Hz (3)
#define BNO055_ACC_BW_125_Hz (4)
#define BNO055_ACC_BW_250_Hz (5)
#define BNO055_ACC_BW_500_Hz (6)
#define BNO055_ACC_BW_1000_Hz (7)

//powermode definitions
#define BNO055_ACC_PWRMODE_NORMAL (0)
#define BNO055_ACC_PWRMODE_SUSPEND (1)
#define BNO055_ACC_PWRMODE_LP1 (2)
#define BNO055_ACC_PWRMODE_STANDBY (3)
#define BNO055_ACC_PWRMODE_LP2 (4)
#define BNO055_ACC_PWRMODE_DEEP_SUSPEND (5)

#define BNO055_ACC_CONFIG_ADDR 0x08

//Select page ID 1 to write to the right register
write8(BNO055_PAGE_ID_ADDR, 1);
//build the config value with bitshifts
//see page 77
//use all standard values except 16G parameter
uint8_t acc_config = (uint8_t)((BNO055_ACC_PWRMODE_NORMAL << 5)
                   | (BNO055_ACC_BW_62_5_Hz << 2)
                   | BNO055_ACC_CONFIG_16G);
//write new accelerometer config
write8(BNO055_ACC_CONFIG_ADDR, acc_config);

//change back to page ID 0 (or whatever was before there)
//Otherwise we read sensor data from the wrong page with entirely different meaning
write8(BNO055_PAGE_ID_ADDR, 0);

Since I don't have that sensor here I have no way to test it. So this is just the basic idea. You can also read registers with read8, with which you can verify that before you write anything to the register, it has some standard (or expected) value. E.g., ACC_CONFIG should read as 0B00001101 = 0x0d. And after you write a value there you should be able to read the same value back, otherwise the chip didn't let you execute the write and you have to investigate why.

Yes, you mostly have to do the hard work by yourself. Changing from 4G to 16G might also have the implication that some other calculations on the raw data has to be done different, however I am not sure of that.


Arduino-compatible wireless technology which can be suitable for transmitting data

You can use radio transmitter/receivers, they are typically called RF (Radio Frequency) modules.

Typical examples are nRF24L01+ (2.4 GHz), or RF 315/433 modules (on 315/433 MHz).

There are more possibilities, but these are the most used on Arduino and libraries are available.


What is the difference between a motor driver and a motor shield?

A motor driver is a chip that drives motors.  A motor shield is a circuit board with connections on it that contains a motor driver chip that drives motors.

A shield is convenient since you can just plug it in to your Arduino and wire the motors direct to it, but it lacks the flexibility of a raw driver chip which you can wire up precisely as your project demands.


threshold voltage level and blinking problem

What is the sensetive ac voltage stabilization method coming from
  voltage divider and it contains noise filter capacitor and take
  avarage?

Calculating an average by using 3/4 of the current average and 1/4 of the new measurement (exponential average) works well for me in a lot of situations. You can adjust the constants as you see fit, as long as they add to 1.0. I use powers of 2 and shifting for maximum performance:

// Exp. average: 3/4 old avg + 1/4 new data, with rounding
int16_t xpavg(int16_t newdat, int16_t avg){

   // (3 * avg + 1 * newdat) / 4
   return( (((avg<<2) - avg + newdat) + 2) >> 2 );
}


No Matching Function for call to Ultrasonic:Ultrasonic(int,int)

You are very likely to have confused the libraries.

When using your code with the library at https://github.com/JRodrigoTech/Ultrasonic-HC-SR04, the code compiles perfectly fine. The constructors match up with your code.

//Constructor 1
Ultrasonic(int TP, int EP);
//Constructor 2
Ultrasonic(int TP, int EP, long TO);
//methods.. (used in your source)
long Timing();
long Ranging(int sys);

I think you have installed this Ultrasonic library: https://github.com/ErickSimoes/Ultrasonic. It has the same header file and class name but the class is constructed differently

//Constructor 1
Ultrasonic(uint8_t sigPin) : Ultrasonic(sigPin, sigPin) {};
//Constructor 2
Ultrasonic(uint8_t trigPin, uint8_t echoPin, unsigned long timeOut = 20000UL);
//Note that a constructor with only 2 arguments is not directly visible

You should go into the Arduino IDE and uninstall your current "Ultrasonic" library from the library manager. Then download the zip file from the first given github repository and add that ZIP file to your libraries.

Alternatively of course, you can use the second library and its correct example code.

Also note that your Arduino IDE 1.0.6 is extremely outdated, current one is 1.8.5


If your motor doesn't work when connected to the 9V battery, either the battery is flat (which is likely since you were able to connect the LED without destroying it!! - they are a 2.5-3v part, not a 9v part) or the wiring to the motor is damaged. When you connect the motor directly to a 9v battery, it should turn pretty fast - may also work if you connect it to between 2 & 4 AA batteries.

9v batteries don't have that much energy in them... you would be better off with a battery pack with 6 AA batteries in it.


Is there any way that the values here be converted to another variable and not string?

sprintf() is a nicer way to do that (imo), however, there's nothing wrong with what you've done-- if you don't have a ton more code, I'd continue to use it.

It's simple and that's a lot more important that speed most of the time. Also, the likely memory usage isn't enough to worry about.

In my experience, once I got past 1500 bytes SRAM (dynamic) memory usage, I ran into trouble. But my projects have a ton of code. I've read through the String class code and it's totally reasonable-- you're not likely to experience lag there.

My bet is that the lag is due to the timeout period, try making it smaller.


Arduino-Bluetooth HC-05 Android app blueterm connection for chatting

Its totally Normal. You must be doing something wrong. It has happen to my Arduino Code a lot of times. try following:

Try interchanging you Tx and Rx Pin Positions. (This happens all the time).
Try connecting using default Serial and using Pin 1 and Pin 0 as Tx/Rx. (In this case remember to unplug the Tx/Rx Pins while running code.)
Try using just basic Serial.Write() function in beginning.


void receiveEvent(int received_bytes)
{
  while(Wire.available())
  {
    unsigned char i = Wire.read();
    if(1)
    {
      int j = 5;
      while(j>0)
      {
        digitalWrite(LED, HIGH);
        delay(300);
        digitalWrite(LED, LOW);
        delay(300);
        j-=1;
      }
    }
    delay(1);
  }
}

receiveEvent is an ISR (interrupt service routine). Don't do delay in an ISR. That will hang indefinitely. Thus the LED only blinks once. You could do delayMicroseconds for testing. In general an ISR should be short.

Interrupts
I2C


How to use the analog comparator to determine when an analog pin has reached a certain voltage?

I have a page about the analog comparator that has code:

volatile boolean triggered;

ISR (ANALOG_COMP_vect)
  {
  triggered = true;
  }

void setup ()
  {
  Serial.begin (115200);
  Serial.println ("Started.");
  ADCSRB = 0;           // (Disable) ACME: Analog Comparator Multiplexer Enable
  ACSR =  bit (ACI)     // (Clear) Analog Comparator Interrupt Flag
        | bit (ACIE)    // Analog Comparator Interrupt Enable
        | bit (ACIS1);  // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on falling edge)
   }  // end of setup

void loop ()
  {
  if (triggered)
    {
    Serial.println ("Triggered!");
    triggered = false;
    }

  }  // end of loop

This is for a fixed reference voltage, for example:


Controlling VFD with ModBus RTU via RS485 and Arduino

User on other site (https://forum.arduino.cc/index.php?topic=663365.0) Might have default run conditons on VFD set differently or by hardware.

Check the VFD is listening to the ModBus Comms.  OK.

Check VFD is 'Ready to Run'. Hardwire e-stop or 'Active' inputs.
F00.22 Check Binding source
F00.05 Check Set min Hz
F01.01 Check Set min Hz

Give drive MIN Hz So when received RUN signal has default speed to goto.

Are you doing a Hard Reset on the UNO every time you want to send the Modbus string? Code runs once, does not actively transmit.


Looking for a waterproof SPI temperature sensor

There is a delay in the DallasTemperature requestTemperatures() function - it blocks until the temperature conversion is complete unless you have previously called setWaitForConversion(FALSE). If you did that, you would still have to wait for the conversion but you can do it an a non-blocking manner, and I don't see that happening in your code.