Arduino libraries rely on the Arduino API to operate (usually). Things like the Serial object are expected to be defined.

Linux doesn't have any of that stuff, so you would have to implement it all yourself.

There is the "Wiring Pi" project for (obviously) the Raspberry Pi that implements the majority of the Arudino API, but whether that could be made to run on Linux on a PC is anyone's guess.

It may be simpler to just examine the existing library (and datasheet) and implement it yourself in your chosen language.


Infinite Loop on Pin Input (Teensy 3.1)?

Try using the internal Pullup/Pulldown resistor to control the input when the pin is not connected to anything.  If you do not have a pullup/pulldown, then the input capacitance on the input pin circuitry can sample and hold the 5V unreliably.

...
void setup() {
  // Outputting for error checking
  Serial.begin(38400);

  // Readying the pin for input
  pinMode(signal_receiving_pin, INPUT_PULLDOWN);
}
...

You may want to uncomment the delay() or add some state logic trigger only one activation per each cycle of signal_receiving_pin


Any way a GSM sim 900 can still work (USA)?

Somehow I got a connection! I live in PA but when I went to Boston for school I got 2G service. Maybe carriers haven’t fully shut it down.


Water pump controlled by soil moisture sensor

I don't see a second power-supply in your photo. If you're trying to run the pump directly from an Arduino pin, it is highly likely that the pump needs way more current than the pin can supply.

It may be possible to power the motor from the USB but 1) the Uno board doesn't make that readily available, 2) it puts your PC at some risk (of back-EMF or of over-drawing the port's capability. But the ideal would be a separate power supply (don't forget to connect that supply's ground to the Uno's ground).

Also, if you tested the pump while dry it may have been able to run, yet with water in it, have been unable pull enough starting current to get going.


Powering ESP8266 module from arduino nano

Why shouldn't i power ESP8266 WiFi module directly from arduino nano 3.3V rail?

The 3.3V rail of the Arduino is not meant to provide much current. The onboard regulator is a simple linear voltage regulator, which will dissipate the extra power as heat. As you draw more current through it, it will get hotter and finally get fried, as it cannot dissipate the created heat. The ESP chip needs multiple hundreds of mA, especially, when it is connecting to a wifi network. The onboard voltage regulator of the Arduino cannot handle this much. So you cannot power it over the Arduino.

I don't really know, what you mean with "using resistors".

  Could i use something like a Mean Well Switching Power Supply, 5V 10A to power the Arduino Nano [...] connect ESP8266 directly to arduino without fear of breaking something?

Yes, you can power the Arduino with this power supply, but you should power the ESP through the Arduino. Not through the 3.3V, nor through the 5V rail (which will fry the protection diode, I think). Instead you should power the ESP directly from the power supply, in parallel to the Arduino. Often ESP modules have their own voltage regulator, that regulates the voltage from 5V to 3.3V. If that is the case for you, you should use this input of the ESP module with the power supply. If you don't have a 5V capable regulated input on your ESP module, you will have to use a dedicated voltage regulator for that. In that case be sure, that the voltage regulator can provide enough power for the ESP (with some headroom on top).

  Could Arduino nano be powered through USB? And if yes, would it be then safe to connect ESP module to arduinos' 3.3V rail?

Yes, the Arduino Nano can be powered over USB. But again you must be sure to not draw too much current from the Arduino. Between USB and the 5V rail is a diode, that will be destroyed, if you draw too much current through it. And the standard USB port can only provide up to 500mA. And regarding the 3.3V rail: All the explanations above about the 3.3V rail apply here again, since the USB voltage (5V) is regulated down to 3.3V by the linear voltage regulator. So: No, you still cannot power the ESP through the Arduino. It's not about the power supply here, but about the electronic parts inbetween.


You can indeed use a serial monitor on your PC on the Mega's first serial port, in fact you will have to if you are connecting to one on the PC via USB port.. And just as with the Uno, you can connect a TTL serial device (like RS-232 serial, but using logic levels of 0 and +5v instead of [-3v - -25v] and [+3v - +25v] (which most PCs implemented as -12v and +12v).

If you need to connect to a true RS-232 device, you'll need to convert the TTL logic levels to something within the RS-232 spec; -5v and +5v would probably be the easiest.


#define INTERRUPTS 975

volatile uint8_t count;

if (count >= INTERRUPTS){

count is an 8 bit integer, so the maximum value of it is 255. Therefor count will never be bigger of equal to 975.

Use volatile uint16_t count; instead.

PS instead of messing with the TCNT0 register, I'd use 2 different values of INTERRUPTS to change between 15 and 5 second intervals.

Something like if( count>=975 || ( (col=='g'||col=='r') && count>=325 ) ){


Running Stepper motors (at least 2) at the same time

Try the AccelStepper library. It can control both steppers at the same time. Also provides some useful examples

AccelStepper with more than one stepper also requires the Adafruit Motor library to be installed.


Two other possible problems, apart from what Jake C has adressed in his answer are:

1. Hardware bounce

If your signal from the sensor isn't a clean transition from high to low but rather "bouncy" (see image below). The microcontroller will register multiple transitions in the meantime.

Solution to this would be to add a small capacitor (wil slow it down though) or add debouncing code... Best would be to get a "clean" sensor.

2. Floating contact

  When I even move my finger close to the wire running to PIN2 the interrupt fires.

That kinda seems like it's a floating contact, where it's not really connected to anything.

This is usually solved by using a pullup/pulldown resistor. Or maybe there is something wrong with the connection.

Also:

  Maybe due to the type of sensor?

You should note the part number of the sensor or link a datasheet, so we can see if it's typical behaviour for this type of sensor.


Rotate a brush less motor using arduino only

By brushless motor, do you mean a BLDC (brushless DC) motor? If so, no this is unfortunately not possible. You need to synchronize your phases to actually rotate the motor. Hence the ESC or an h-bridge with your own code. On top of that your Arduino doesn't have the power, nor the safety circuits in place to prevent the energy in the motor from not killing the board when you turn it off.

The servo library is used for, lack of a better term, the hobby servo motors.

http://www.instructables.com/id/BLDC-Motor-Control-with-Arduino-salvaged-HD-motor/

Here's an example. You're looking to do the same. Good luck!


ESP8266 Arduino 2.2inch ILI9341 TFT library

You did not include any output from the esp8266, but I'm pretty sure what is happening is that the watchdog timer is expiring and resetting your board. This is because the SPI transactions to transfer data to the display are taking too long.

Put the following line in both setup() and loop() before any display operations happen:

wdt_disable();

Needless to say, if you actually do need the WDT in your application, you can reenable it after the display operations complete (of course, if you are doing something that depends on the wdt, you already know this!)

Look at the source for the Adafruit library, make sure there are #ifdef ESP8266 statements there; older versions did not support the 8266.
You may also want to increase the default speed at which the library drives the SPI bus from 8000000. I've gotten it to work at up to 40MHz, with the board flashed at 160MHz of course, and it's a lot faster (unsurprisingly), but if you have long wires or a marginal-quality display, that may fail.

Post pictures :)


Powering arduino and 12V Fan from same supply

The board will take 12V, but the regulator will have to dissipate (as in heat) the excess power.

However, how much do you trust your power supply to not exceed the 12V?

The same applies to the other loads.

About max current, you should do the math for both typical case and peak case. Ex: the fan will draw much more current if for any reason it is stopped.

If you use only 1 transistor, you will get both fans to behave in the same way, because you will be using only 1 control line. Is this what you want?


There are two associated issues here that underly your problem.

Firstly, with a log pot, you get a period of very small changes in resistance followed by a period of massive changes:

(* a "commercial" log pot is how log pots are usually manufactured - two linear traces of different resistances back to back).

So when turning you get "not much ... not much ... not much ... lots ... even more ... full".

Now couple that with how a motor works. A motor has a "stall current", which is higher than the "run current" (especially the "unloaded" run current).  This is the minimum amount of current required to overcome the inertia of the motor and start it spinning. This is, in effect, a lower threshold on the PWM value that you need to exceed before the motor will begin moving (once it's started moving you can go a little below that threshold and it will still move).

With a linear pot it's easy to get to that threshold and stay around it, increasing slowly above it, etc.  However, as you can imagine looking at the curve of the log pot above, if the "flatter" area of the pot is below the stall current threshold of the motor, the motor will do nothing until you are well into the sharper up-turn of the curve.  The effect of this is you will go from "stopped" to "quite fast" in one jump. It's very very hard to get even close to the stall current threshold.

For instance, if your motor needs a minimum of 30% duty cycle to start it running, that's about a 160 degree turn on the log pot above, compared to just 70 degrees of a linear pot, and the rest of the log pot's PWM range is compressed into a tight space.


Use an ethernet shield and RFID rc522 together on a mega?

Yes, I do think so. according to my Question with RFID and display it turned out that those pins are for serial communiacation. So I think it should work.
I can verify
 that it will work if you do use the ICSP headers MOSI/MISO/SCLK pins. Connecting those three with the RC552 as well as GND and 3V3. Also connect two other pins to SS and RST. This pins can be adjusted in the sketch on the Arduino.


What I should be aware before I touch my Arduino?

Turning the power off and taking proper static precautions also applies to Arduinos.  Anorton's tip about not resting it on a conductive surface is also useful.  Some other things to keep in mind:

Double check the polarities of any connections you make.
Keep a consistent wiring color code.  Use red for power and black for ground.
Calculate the expected current through all components before you apply power.  Check the datasheet to make sure it's within safe limits.
Calculate the heat dissipation for higher power components like power supplies and motor drivers.
Connect and test one small part at a time, instead of in one big bang.
Make sure the parts you buy expect the same voltage, or perform the appropriate conversion.

For keeping people safe:

Know where the fire extinguisher is.
Don't put cords where people can trip on them.
Use a proper stand to hold your soldering iron, and keep pets and small children away.
If your project has a propeller or something physically dangerous, build failsafes and kill switches into the system.
Be careful to charge any batteries properly, and not let them overheat.
Be careful what you touch while troubleshooting.  Arduinos usually don't deal with very high voltages, but inductors and capacitors can build up higher charges than you expect, and hold it after power is removed.


A TFT screen is just a screen. You can't modify SSIDs and passwords with it, any more than you can by poking your PC monitor (unless perhaps you have a touch-screen*). To modify things you would need:

An input device (eg. a keypad)
A method of displaying what you are entering (this is where the screen would be handy)
A method of storing the new information. You could store things like passwords in EEPROM.
Code to make all that work.

* Some distributors sell touch-screen interfaces designed to go on top of screens - this might conceivably be what you are thinking of. However you still need the touch-screen, and code to make the touch-screen, and the TFT screen, work.


It seems, that you are talking about 2 different things:

The programming/burning of the PIC can be done via an Arduino (so you don't need to build a complex PIC programmer circuit). It is irrelevant, what microcontroller type is on the programmer, as long as the programmer speaks ISP (the programming protocol). So even, when your specific PIC is not mentioned at your found sites, it should work nonetheless. The connections are every time the same, though of your specific PIC the used pin functions might be on other pins (consult the datasheet for this).
An Arduino project - meaning the sketch/program, that was written for a normal Arduino, is normally not easily reusable. PICs are different microcontrollers with different hardware, so you need to port those projects to your specific microcontroller, which might involve extensive changes. When you have an Arduino Project, that was directly written for your PIC, then you can reuse it. (Be sure to install the correct core for your PIC in the Arduino IDE)


The ESP8266 has a relatively high peak current requirement compared to general microcontrollers. This is rarely fully understood. There is a lot of information on the Internet that says the current requirements is about 70mA. But that is a long term operational average. The peak current requirements can be as high as 1/2 an Amp.

When the ESP8266 starts one of the first things it does is an analog calibration. This is where it draws more current. If the power supply can not maintain the minimum required voltage at that current the voltage dip will cause a failure. The duration of this dip can be very short. A digital scope needed to see the fault.

I tend to recommend the use of ESP8266 modules that have an onboard regulator. Modules like the Wemos and Nodemcu type boards.

Using modules like the ESP-01 or the ESP-12 type modules (no regulators) are a lot more touchy. What you need to do is keep the 3.3v regulator as close as possible to those modules, and short solid connections. It also helps to have some additional capacitance across the 3.3v connections at the module.

Breadboards are convenient to use but they also can be the source of poor connections.

Consider what I have wrote here, how it applies to your setup. You may also want to solder an additional capacitor on the module. Vcc to ground. Something like 200-470uF, right onto the top of the module.


You cannot (easily) have all nodes on the network with the same address.

There are ways of doing it but they aren't easy.  They basically involve creating a "broadcast" facility in your network, and that has certain caveats involved with it.

The nRF24L01 modules have an "auto-ACK" mode to give reliable communications.  This only works with 1:1 addressing and cannot work with broadcast.  If you want to (as most people do) use the auto-ACK facility then you have to have each node with its own unique address.  After all, if you're sending the ACK to a station, and there are multiple stations with that address, which one will ACK?

So you have to think about if what you are trying to achieve is really the right way of going about it.  It sounds like you want to just program another node with the same code as an existing node without making any changes to that code and "just have it work".  That's a very advanced topic and one that even I would spend quite some time implementing it.  Yes, you can do unreliable communications (i.e., no auto-ACK) then you could have all the remote stations with the same address, but I would certainly keep the master as a unique address.  Better would be for each node to start up with a pre-defined address which it then uses to ask the master for a unique address (a-la DHCP) and the master then keeps a list of what is connected on what address.  From then on it can use reliable communications to send and receive data to each node as it needs to.

A system I wrote for the chipKIT boards gives each node two addresses - its own unique address which you have to provide manually, and a more global "broadcast" address.  They are each on different pipes within the nRF24L01.  To communicate with an individual node you send to its unique address.  To broadcast to all nodes you send to the broadcast address.  If you're sending to the unique address you can then turn on auto-ACK. If you're sending to the broadcast address you don't turn on auto-ACK.

Note that using auto-ACK is a whole topic in itself and requires careful design planning to get it to work properly.

Also you have to think about what happens when you send a broadcast packet out and it's received by other nodes - how do they handle that data? Sending temperature data out globally, it will be received by the RGB receiver, which may try and interpret it, causing problems.  You need to come up with a way of identifying just what it is you're sending out and only having the right nodes responding to the right data.  That means coming up with a strict packet format.  Luckily the nRF24L01 chips communicate in fixed packet sizes (incidentally, all nodes on the network will have to be set to use the same packet size or it just won't work) up to 32 bytes, so implementing a packet structure over that is easy enough.  Just sending strings of data is both hard to interpret and incredibly inefficient.  You should be sending the data as actual data values in variables as part of the packet structure.


Arduino MKR GSM 1400 SSL client example fails to connect

I finally found a solution to this problem. Disabling certificate validation in MKRGSM library makes the SSL connection succeed also to this site. In MKRGSM/src/GSMClient.cpp I changed

//     MODEM.sendf("AT+USECPRF=0,0,1,4,\"%s\"", _host);
       MODEM.sendf("AT+USECPRF=0");

to use modem factory settings. I still don't know what was the problem with the certificates.
Thanks to everyone who tried to help with this.


Console monitor on different wifi network

The Yun is just an ordinary network device.  However, the tools you are provided with use a system called mDNS to find the Yun.  That only works across the same local subnet that you are on.

If the Yun is on a different subnet then you will have to (assuming the routing between subnets is working fine) do it manually by knowing the IP address of your Yun.  Use that IP address in place of "arduino.local" or whatever your Yun is called.


Arduino Uno not including two header files at the same time

First of all, that page has a link to an old version of the RadioHead library.
This is a link to RadioHead: www.airspayce.com/mikem/arduino/RadioHead. You will find the newest library on that page.

The Servo library uses TIMER1.
The RadioHead in RH_ASK mode uses TIMER1.
Both use the same interrupt of TIMER1. That is what the compiler is trying to tell you with: "multiple definition of _vector_11".

You could move one of them to TIMER2.
There are alternative Servo libraries that use TIMER2.
The RadioHead can set a define for TIMER2. The explanation is in the library files in RH_ASK.h, you have to set "#define RH_ASK_ARDUINO_USE_TIMER2" in RH_ASK.cpp.

Why are you using the Servo library for a stepper motor ?


'serialWrite' was not declared in this scope

It should be Serial.write to notice the period.

Which would make your code:

int buttonPin
void setup ()
{
    Serial.begin(9600);  # There was an error on this line as well
    pinMode (buttonPin, INPUT);
}
void loop ()
{
    if (digitalRead(buttonPin) == HIGH)
    Serial.write('H');
    else
    Serial.write('L');
    delay(1000);
}

Have a look at https://www.arduino.cc/en/Serial/Write for a complete example


How can I give power to Arduino Uno using a 12V 7.5 Ah Lead-Acid battery?

The input voltage on the DC pin is specified as 7 to 12V. Your battery may well be supplying more than that, causing the voltage regulator to overheat and shut down.

  The voltage was 12.62 volts.

That is out of spec for the Arduino Uno. When you operate out of specified voltages anything can happen, and that anything may not be very good.

You could get a buck converter to lower the voltage.

Certainly a Uno should be able to run for a long time on a 7 Ah battery (provided you are supplying voltages in range for it, preferably using a buck converter or similar to make sure that a fully-charged battery does not supply too high a voltage).


How to use strtok() and strstr() with arduino?

You have to define a format for the header you will be parsing and stick to that format. Say this is a sample header terminated by null:

s=123 d=789 e=463

A common property of each assignment in the string is the '=' symbol. You can use that to locate each variable and the value assigned to it. strchr is the function to use to locate a single character. Once you locate the = character, you move back and then forward along the array to obtain the variable and its value.

I will make some assumptions here: that your variable names will be single character, that numbers assigned will be no bigger than ints, and a space character is used to separate assignments.

char header[] = "s=123 d=789 e=463";

int d, s, e;   //your variables to be assigned to
char * ptr = header;
char * eq = NULL; //locate assmts
int * num = NULL; //just for starters
while (1){
  eq = strchr(ptr, '=');
  ptr = eq; // update the pointer
  if (ptr == NULL) // found no = chars
    break;
  switch (*(ptr - 1)){
    case 'd':    //all the possible variables
      num = &d; break;
    case 's':
      num = &s; break;
    case 'e':
      num = &e; break;
    default:   //unknown variable
      num = NULL;
  }
  ptr++;
  if (num == NULL) //unrecognized var
    continue;   // locate next = char
  *num = 0;
  while (*ptr && (*ptr != ' ')){  // while space or end of string not yet reached
    *num *= 10;  // extract each int
    *num += *ptr - '0';
    ptr++;
  }
}

Serial.println(d);  //now contains the numbers in the header
Serial.println(s);
Serial.println(e);

Untested but it should work for the header sample I gave.


Processing Power is a bit of a misnomer. Clock Frequency is a better description.

In general one assembly instruction gets executed each clock cycle. That means approximately 16 million instructions per second (there are a couple that take more than 1).

Your C program gets compiled into those instructions and executed at 16 million instructions per second.

If your routine is 16 million instructions long (when loops are unrolled) then it will take 1 second to execute.

Unlike a PC, which is constantly switching between tasks, an Arduino does only one thing, and that is the one thing you programmed it to do. Because of that execution time is predictable. If it took 1 second to execute today it will take 1 second tomorrow,  and 1 second next week.


Can a 9V battery be used as a backup power supply (to Arduino Uno) while plugged directly into Vin and ground?

My problem with that is that the other side of the diode on the Arduino is normally powered up. So for example if you have a 12V supply in the power jack you'll have 11.3V at Vin (because of the diode drop). Thus you are pumping 11.3V into your 9V battery which won't be designed to handle it. It will probably get hot and explode.

You would need another diode specifically between the battery and Vin. And make sure that Vin is at least 10V so that the normal mains power does not charge the battery.

Bear in mind a 9V battery doesn't have much capacity. With the power LED on,  taking sensor readings, and sending data via Ethernet (if that is what you are doing) you may have only bought yourself 15 minutes.

I have a post about a temperature and humidity sensor which runs all the time from 3 x AA batteries. I think the batteries need replacing about every two years. The data is written to an SD card which you remove and plug into your computer when you want to.

  when you have 9V hooked up to Vin and 5V coming in from the USB, it will use power from the 9V battery

Looks like I misread the question. @mwwalk is quite right. If you supply more than 6.6V through Vin then the circuitry switches the USB off. See here:

Vin is provided by the power jack (after a diode which drops it by 0.7V) - see blue ellipse. In any case (power jack or not) Vin goes through a voltage divider (two 10k resistors to the left of the red circle). This is compared to the output of the 3.3V voltage regulator. Therefore GATE_CMD is HIGH if Vin exceeds 6.6V. This turns off the MOSFET (green circle) and disconnects the USB power.


Yes but you want something much faster then the Arduino, normally it is in the 96k~48k bps range.  Try this link, they make a lot of great parts and the bulk of what you have to do is control software.  You can let the chip do the grunt work (analog) and transfer thee data to where ever you want.  Some of the chips will record for 300 seconds plus.

http://www.aplusinc.com.tw/exec/product.php?lg=E&mod=show&cid=43&pid=aPR33A3

I have used there parts they work great.

Have fun,
Gil


Are pins 0 and 1 (Rx and Tx) parallel with the USB jack? Can I connect another USB jack th 0 and 1 and use it to upload sketches?

No. For many reasons. No. USB is not TTL. You need an adapter to connect rx/tx pins of arduino to USB. And the on-board adapter has the DTR line connected to reset the Atmega before writing a program into it. Without it, you would need to push the reset button in the right moment.


Bypass the regulator, and connect the battery directly to the VCC pin. However, running at 16Mhz requires at least 3.8 Volts, according to the datasheet. Lower voltages may work, but aren't guarantied.


Yes, if you have a 0 to 30 mV signal that you need to measure to an accuracy of 2 microvolts, you'll need an ADC with an effective number of bits (ENOB) of at least 13.9 bits and an amplifier to make the signal to match the range accepted by the ADC.
Most ADCs pretty much require some sort of op-amp or differential amplifier between such low-level input signals and the ADC input pins.
A few ADCs have a differential amplifier already built in -- that makes things a lot easier to get working, but I don't know if any of such ADC available would meet the other requirements of your project.

I don't know any way to make such high-resolution measurements other than using a dedicated external ADC chip.

You'll want to read the ADC datasheet -- some of them, and so far all the microcontrollers I've seen that claim to have a built-in "16 bit ADC", have an effective number of bits (ENOB) worse than the 13.9 ENOB you need at the sampling rates I typically use.

Adafruit has a very nice tutorial describing how to connect the 12-bit ADC ADS1015 or the 16-bit ADC ADS1115 to an Arduino.

The Arduino playground has a brief tutorial describing connecting a 12-bit ADC MCP3208 or a 13-bit ADC MCP3304 to an Arduino.

I see from the Arduino blog and other sites that people have connected some even higher resolution ADCs to an to an Arduino board, including
the 24-bit Linear LTC2440 ADC;
the 18-bit LTC2400 ADC (24 bit at 5 samples per second); and
the 24-bit ADC TI ADS1220.

Arduino blog. "Archive for the ‘ADC’ Category"
Peter Oakes. "Arduino UNO, Using precision ADCs and DACs". (video tutorial: connecting the 24-bit ADC TI ADS1220 to an Arduino).
Martin Nawrath. "Connect a LTC2400 High Precision 24 Bit Analog to Digital Converter ... to the Arduino"
John Boxall. "Tutorial – Arduino and the TI ADS1110 16-bit ADC".

Sounds like a fun project.
Good luck.

EDIT:

Steve Luce. The LTC2440 24 BIT ADC and the Arduino Uno.

Everyone that uses an ADC needs some antialiasing filter between the signal and the ADC.

People that measure very faint signals usually need some sort of amplifier between the signal and the ADC.
You may find the list of suggested op amps on p. 7 of the AMP03 datasheet useful.

Because historically ADCs were expensive (and high-resolution ADCs were unavailable), people have developed many clever tricks for processing signals before feeding the processed signal into a relatively low-resolution ADC.
(Lock-in amplifiers, chopper amplifiers, manual precision gain adjustment, manual precision offset adjustment, heterodyning, etc.)

Have you tried asking "What sort of amplifier do I need to measure ((something)) with a 16-bit ADC" at https://electronics.stackexchange.com/ to learn some of those tricks that specifically apply to ((something))?


If your chips have a bootloader already installed in them, you can use any USB -> Serial cable (FTDI cable) to program them in-circuit on their Rx/Tx pins. If not, you can use the Uno to program a boot loader into them (one time) and program them with the cable from then on.

To use standard C, you can use the bare chips or the UNO. You'll want a different environment than the Arduino IDE, though. That can be anything from an editor, the the gnu compiler tools run from a command line, to almost any other IDE. A number of people, myself included, use the Eclipse IDE with an AVR plug-in and do almost everything from writing the code to programming the AVR from within it. (I say 'almost' only because I personally prefer a full-blown programming editor, run outside of the IDE, for initial creation of sizeable projects or major edits and rewrites. That isn't necessary, though).


Sending sensor readings from Arduino to Raspberry Pi over 433 MHz

You could look into the RadioHead library - there might be a port for RPi, though I couldn't find one with a (very) quick google. This library works well, I use it actually with RFM69H 433 MHz radios (from Moteinos), a little more expensive than the simple 433 kits, but also supports encryption which might be important down the line. If you can't find a good library for RPi one solution could be to have a second Arduino acting as a receiver and sending data serially to RPi. This is what I use with a regular desktop PC which is my home server.

I also found a discussion about connecting a RFM69 to the RPi here which might give you more information about the process in general, even if you won't use the same radio.


Can't read from DHT sensor when motor is running

The problem may be electrical noise from the motor, or
you may have a wiring problem (an incorrect or intermittent connection).

Kira San’s comment “try to add a 100nF ceramic capacitor between the motor terminals” is directed toward suppressing electrical motor noise.  As brushes make or break connections on a motor's commutator, arcs and sparks can occur.  The capacitor will limit voltage rate of change thus suppressing some of that electrical noise.
CharlieHanson's comment (add a flyback diode across the motor terminals) is partly related to noise suppression but mostly to suppressing high voltage excursion that occurs when you shut off motor power.  While the motor is running, the magnetic field in it stores ½ L i² joules of power.  When current stops suddenly, those joules of power convert to a high voltage spike.  A flyback diode acts as a near-short to absorb that spike.  The cathode (cross-bar) of the flyback diode attaches to the high side of the motor voltage, as shown in the circuit diagram of the project you linked to on electroschematics.com.
Re “you are using a resistor with that LED, yes? I'll overlook the fact that it's the wrong way round in the schematic!”, if the LED is wired backwards as shown in your drawing, it won't turn on – which is a good thing, because without a resistor (say 300-3000 Ω) in series with the LED, enough current may flow to damage the Uno or the LED.  Turn the LED around on the schematic (and on your wiring setup if you didn't already), and add a series resistor.

Edit: A comment says, “Don't have a diode either :S Will an LED work instead?”.  LEDs typically have rather low reverse-voltage ratings – 4 to 5 volts.  You could put two or three in series and if they don't burn up you're ok for this experiment.  But in production, don't depend on LEDs as flyback diodes except where it doesn't matter what happens.

Gerben's comment, “What is that capacitor doing there? Slow start?” refers to the 100 μF capacitor shown between transistor base and emitter.  In conjunction with the 1KΩ resistor from D4, that gives RC=0.1 second, so the transistor will take an appreciable amount of time to turn on.  This has a couple of consequences:  PWM control may be less effective (at low duty cycles, PWM depends on short, high-current pulses, to overcome stiction etc) and the transistor will run hotter.  If it's a big power transistor, ok.  If it's a small switching transistor intended for full-on or full-off, no.

Edit: A comment refers to a fan speed controlled temperature page at electroschematics.com.  That page shows a BD139 power transistor, and says the 100 μF capacitor between transistor base and emitter eliminates some motor noise.  Thus it falls into the “big power transistor, ok” category.  Well, more or less ok.  A heat sink may be needed on the transistor and the capacitor probably doesn't need to be that big; eg try 10 μF instead of 100.

An ordinary 9V battery easily supplies a dozen milliamps, but current draw larger than that quickly depletes it.  See eg 9V Alkaline tests at powerstream.com and my answer to a previous question, Using Arduino Micro With 12V Buzzer that's somewhat related.  The motor shown (TD599839) is rated at 35 mA at 5.9 V no-load, so will draw say 50 mA no-load from a 9V battery and will try to draw several times that if loaded; ie it will overstress an ordinary 9V battery.  In brief: Use a wall-wart or equivalent, or a big battery, rather than a small 9V battery when running motors.


Arduino Pro Micro clone clock cycle issue

The fix for this issue was to reload the bootloader.  I used the SparkFun Caterina bootloader.


Breaking out of a while loop using IR remote for neopixel

There are a few causes for eternal loops and other things that will go wrong in your code.

As ChrisL noted above you are assigning a value to Remote in the while condition which is almost certainly not what you wanted to do.  On the plus side, every C/C++ programmer ever has also made that same mistake at some time or another.

Now if you change it to while (Remote == 0xcFFE21D) it still won't work, because Remote is always 0.  You have commented out the lines that set Remote, but they are after the call to the function.  To be honest since you know the value before you call the function (because of the switch statement) you don't need to check the value within the function so you could remove the while loop all together.  If you intention is to call this function repeatedly until a different button is pressed on the remote, the way you are doing it won't work.  you need to store the last button pressed value and then pass that into the switch statement.  When a different button is pressed update the 'last button pressed' value.

You for loop conditions need looking at.  I don't think that the number of lights in the strip is going to change while the program is running.  If that's true then your are wasting processor instructions by doing strip.numPixels()/2-1 you might want to look at setting global values in setup.

Also the for loops might benefit from using i >= 0 because then you don't need to do i+1 every loop.


Assemble or typecast byte array to float

I tried the code below and it worked for me, don't miss the delay() part:

Sender Code:

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

void loop() {
    float yaw = 10.5;
    float pitch = 20.15;
    float roll = 100.10;
    float ypr[3];
    ypr[0] = yaw;
    ypr[1] = pitch;
    ypr[2] = roll;
    Serial.write((byte*) ypr, 12);  // No new-line
    delay(1000);

}

Receiver Code:

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

void loop() {

}

void serialEvent() {
    if (Serial.available() == 12){
      byte yawData[4];
      yawData[0] = Serial.read();
      yawData[1] = Serial.read();
      yawData[2] = Serial.read();
      yawData[3] = Serial.read();
      float yawAngle = *((float*)(yawData));
      Serial.println(yawAngle);

      yawData[0] = Serial.read();
      yawData[1] = Serial.read();
      yawData[2] = Serial.read();
      yawData[3] = Serial.read();
      float yawPitch = *((float*)(yawData));
      Serial.println(yawPitch);

      yawData[0] = Serial.read();
      yawData[1] = Serial.read();
      yawData[2] = Serial.read();
      yawData[3] = Serial.read();
      float yawRoll = *((float*)(yawData));
      Serial.println(yawRoll);
    }
}

Results:


How to catch the Enter key received by Bluetooth?

It depends on what the enter key sends. It may be just CR (carriage return), LF (line feed), or both. You can check the ASCII table for the hex values for those characters.

LF is 0x0A and CR is 0x0D. Those are the characters you're looking for, you can add a if for these cases in order to guard the call to lcd.print(dato):

char dato= Serial1.read(); //Comprobamos el dato
if (dato != 0x0A && dato != 0x0F)
    lcd.print(dato);


`LOW` being defined as `0` and `HIGH` being defined as `1` - is this a part of external specification?

The underlying reason for this question is to figure out whether code like

digitalWrite(some_pin, true);
digitalWrite(some_other_pin, !digitalRead(some_other_pin));

  is a good programming practice. (If LOW and HIGH are there to abstract the user's code form their actual values then code like that is definitely a bad programming practice.)

Strictly speaking, no, that is not good programming practice.

digitalRead() returns an int. digitalWrite() expects an int.  Using ! converts the int into a bool and then it's promoted back to an int again.

In fact, the "next gen" Arduino core API changes HIGH and LOW from a simple int to an enum - and that struggles with casting through bool like that:

typedef enum {
  LOW     = 0,
  HIGH    = 1,
  CHANGE  = 2,
  FALLING = 3,
  RISING  = 4,
} PinStatus;

You can see the problems that causes here.


How do I stop the Arduino TX/RX LEDs from flashing? How do I turn off the "ON" LED?

I'm wondering how much control the programmer has over the various LEDs on the board. First there's the "ON" LED which is very bright. Can this be turned off or dimmed, or do I need to resort to electrical tape?

Remove it, remove the resistor inline with it, or cut the track powering it. Either that or resort to electrical tape (or blu-tack). You have absolutely no control over it.

  More annoying is the "TX" and "RX" LEDs. These blink rapidly when data is being communicated over the USB-serial connection. I'm guessing these are not configurable, but I couldn't find the answer anywhere online.

If your board uses an ATMega16U2

As above, or compile a custom version of the ATMega16U2 firmware and flash it on to the ATMega16U2 chip.

If your board uses an FT232 chip

Download the FT232 EEPROM editing program from FTDI and use that to reconfigure the IO pins the LEDs are attached to so they do nothing. If you are on Linux you can use libftdi's ftdi_eeprom program.


I've been using usb power packs.

Easy to source (can be found in all electronics stores and many general stores).
Come in many sizes (500mAh to 20,000 mAh are common).
Rechargable, usually by using a generic phone changer with a usb micro connector.
Not costly.
Quite roubust.
Most Arduino boards and many motor driver boards are designed to be powered from usb.

Make sure you get one that is rated for enough current for your project.


The core of the problem is that the code is being compiled as C and not C++.

The error says 'new[]' is undefined at the link stage.  This is because the linker is not pulling in the C++ standard libraries.  The built-in function new[] it doesn't exist in C.

The filename FPS_GT511C3.c.cpp is the elephant in the room.  You could consider renaming it (and others) to FPS_GT511C3.cpp.  Although the plain Arduino IDE does not really have a problem with building them.

Another option might be to modify the new[] (and delete[]) for C's malloc() and free().  However this is only appropriate for the allocation of simple types (byte, int, etc).  If the code also allocates objects, it's not possible to simply swap these functions out since C++ (default) initialisation is be going on.


Any resources you know with regards to remotely reading data from arduino?

You can use the Bluetooth on the board, a Bluetooth dongle for your laptop if the laptop does not have bluetooth or you can buy a wifi shield.

The 101 has Bluetooth LE on the board.

You will find there is a Bluetooth -> Serial USB software, so the application on the laptop can still work the same way as when using the usb.

Here are the Bluetooth examples for the 101 on arduino.cc

https://www.arduino.cc/en/Reference/CurieBLE

and the user guide for the 101

https://www.arduino.cc/en/Guide/Arduino101


Why the 4.7 K Ω resistor in this pitch follower sketch?

The resistor couples with the LDR to form a voltage divider. The voltage at the point where the resistor and LDR join will vary depending on the ratio of the two resistances - the resistance of the LDR and the 4700 ohm resistor.

The value of 4700 is chosen to allow a reasonable range of voltages when in a ratio with the LDR, and the best value depends on the resistance range of the LDR.


Your solution does not work, mainly because GPIOs are not intended to source current higher than a few mA. If you want the laser diode to emit a reasonable amount of power, you need to drive it with a transistor. A MOSFET-based low-side-switch would probably be the easiest solution. But note that you still need to limit the current, e.g. by using a series resistor.
Even better would be to use a constant current driver (you can use any led driver with appropriate rating).
If the power supply that came with the laser diode is a constant current source, it might be possible to switch its output directly (without resistor), but that depends on how it behaves when it is open-circuited.


How to read Negative number with serial.read

You could do something like this:

static int setpoint;      // the partially read setpoint
static bool isNegative;   // whether it should be negative
void applySetpoint(int);  // apply the setpoint when fully read

char tmpChar = Serial.read();
if (isDigit(tmpChar)) {
    setpoint =  (setpoint  * 10 ) + tmpChar - '0';
} else if (tmpChar == '-') {  // minus sign
    isNegative = true;
} else if (tmpChar == '\r') {  // line terminator
    if (isNegative) {
        setpoint = -setpoint;
        isNegative = false;  // reset for next read
    }
    applySetpoint(setpoint);
}

Note that this is not very robust: it will happily interpret "3-2" as
meaning "-32". Note also that I assumed your terminator to be '\r', you
may be using another one.


how to implement PWM LED fading into a random case switch?

In order to fade in and fade out LEDs you need to use PWM feature. And, specifically you need to use the analogWrite() function call. Also, you need to make sure all your LEDs are connected to PWM port pins.  Port pins which support the PWM feature for various Arduinos are listed in the above link.

In your code you might try replacing your 500ms delay with a count up followed by a count down loop.  Each loop should contain the appropriate delay and count up or down to the appropriate value.

For instance, you might try a 1ms delay and a count from 0 to 255 followed by a count from 255 to 0.  In both loops just before or just after calling the delay() function, place the call to the analogWrite() function and pass the counter value as the PWM duty cycle (LED brightness setting).

added later...

For example, you might try to see if this code works for the 1st case statement:

int brightness_level;

case 1: //if ledcolor equals 1 then the led on pin 11 will turn on etc.
  for(brightness_level = 0 ; brightness_level < 255 ; brightness_level++)
  {
    analogWrite(11, brightness_level);
    delay(1);
  }
  for(brightness_level = 255 ; brightness_level >= 0 ; brightness_level--)
  {
    analogWrite(11, brightness_level);
    delay(1);
  }
break;


The 'new' board with green soldermask and the lighter headers is made by arduino.org.  The old one was probably made by the same company, but prior to the split in the founders.

Right now there is arduino.cc (the original website) and arduino.org (the website set up by the company that split from Arduino).  There is a lot of different perspectives about who really owns Arduino and I won't attempt to weigh in here.

The changes in firmware are still unknown.  It's likely that they are simple strings or response changes so the boards can be differentiated in software.  The new IDE is in alpha, and is yet another attempt to differentiate between the two Arduino groups.  I haven't attempted to program either with either group's IDE, but if I do I'll update this answer with the results.

At least there's a way to visually identify the difference once received - wish they had given them different part numbers so Digikey wouldn't have sent me a mixture...


The simplest method of connection is just to plug the Arduino into the BBB's USB socket.  That way there's no level conversion or anything needed - you can just open the serial port and communicate through that - what could be simpler?

You can even install avrdude on the BBB itself and upload code (HEX files) direct from the BBB, and the BBB supplies all the power.


Why Arduino Mega 2560 throw error when i try to upload example

I install driver for this site and everything is working well.
driver download:  wch.cn/download/CH341SER_EXE.html

I'm recommend to unplug arduino first and install driver, after that plug and enjoy.

Here is a video:
https://www.youtube.com/watch?v=FhmG5J-AHrg


To analyze your problem:

Switch two wires between two motors (and repeat this to get all combinations), to find out if the code/wiring until the motors is wrong, or there is a problem with the motors.
Print out the values of pins 9, 10, 11 and 12 and the value of t/input to see if the pins are controlled as you expect.
Remove all but one motors, for all motors one at a time, to see if there is no influence between them.

Below is not an answer to your question, but I can only align the code as answer.

It is better coding style to use the following form:

void loop() {
  if(Serial.available()){
    t = Serial.read();
    Serial.println(t);
  }

  if ((t >= '1') && (t <= '5'))
  {
    int input = (int) t - (int)'0';

    digitalWrite( 9, (input == 1) || (input == 4) ? HIGH : LOW);
    digitalWrite(10, (input == 2)                 ? HIGH : LOW);
    digitalWrite(11, (input == 1) || (input == 3) ? HIGH : LOW);
    digitalWrite(12, (input == 2)                 ? HIGH : LOW);
  }

  delay(100);
}

Note: ? : is a ternary operator which means : a ? b : c => if a then b else c.

Instead of using 9, 10, 11, 12 define pin numbers (e.g. PIN_MOTOR_X), and for 1, 2, 3, 4, 5 input numbers define LEFT, RIGHT, UP/FORWARD, DOWN/BACKWARD, STOP.


Output specific value using port manipulation

The analogWrite function is just an interface to setting up the hardware timers to do PWM (pulse-width modulation). I have a page about timers which you may find helpful.

Depending on which pin you want to output the PWM to, the registers will be slightly different. Here is one example from my page:

const byte OUTPUT_PIN = 3;  // Timer 2 "B" output: OC2B

const byte n = 224;  // for example, 1.111 kHz

void setup()
 {
  pinMode (OUTPUT_PIN, OUTPUT);

  TCCR2A = bit (WGM20) | bit (WGM21) | bit (COM2B1); // fast PWM, clear OC2A on compare
  TCCR2B = bit (WGM22) | bit (CS22);         // fast PWM, prescaler of 64
  OCR2A =  n;                                // from table
  OCR2B = ((n + 1) / 2) - 1;                 // 50% duty cycle
  }  // end of setup

void loop() { }

  How can I output a specific value on a pin ?

I should point out that the only values you can output are +5V or 0V. There is no provision for outputting (say) 3.7V. The only way you can sort-of do this is by using PWM and then running the result through an RC filter. There is an example on my page about op amps.

An example circuit could be:

This uses a resistor and capacitor to filter out the "ripple" in the PWM, giving you a reasonably smooth output voltage, proportional to the PWM duty cycle.

For a larger range of output values a rail-to-rail op-amp would be preferable.


Accuracy of liquid level measurement using sonar sensor

I've implemented this on my 2 x 23,000 litre water tanks using 2x hc-sr04 sensors mounted on the tank lids and a nano in the pump house. Yes water is a good hard reflective surface to bounce the ultrasonic sound waves off. My tanks have an overflow outlet but not sure how well the eletronic will last? However they are cheap to replace. It is only early days but the overall the results are looking good.
Couple of points:

1.polling occurs hourly.

2.I only power the ultrasonic sensor just before taking a reading.

3.Has a sound detection sensor to alert on water pump overrun, ie a leak.

good luck


My ESP8266-01 doesn't want to respond to AT command after a successful flash!

The tutorial is to flash SDK 2.0 AT firmware. The AT 2.0.0 firmware is build with RTOS SDK. The 2.0 AT firmware available on Espressif site was build with settings not compatible with esp-01. It is built for 2 MB flash and  communicates over pins 13 and 15.

The latest NonOS SDK AT firmware is 1.7.1 (SDK 3), but it requires 2 MB flash too. It is possible to flash it to 1 MB module with the 2MB-c1 parameter with esptool.py. (The OTA update command will not work.)

GitHub user loboris (Boris Lovosevic) builds customized versions of AT firmware with SDK 3 for all flash sizes. You can download the files from his ESP8266_AT_LoBo GitHub repository. If you can't run his flash.sh utility, then for 1 MB flash you can Flash Download Tool with bin/upgrade/esp8266_AT_1_2.bin file and the right addresses for 1 MB flash: boot_v1.7.bin on 0x0; esp8266_AT_1_2.bin on 0x01000; esp_init_data_default.bin on 0xfc000 and blank.bin on 0x7e000 and 0xfe000.


How can I connect multiple MCP23017's to an arduino?

If you know how to connect one chip you know how to connect many chips.  One or eight it's the same.

All the SCL pins connect to the SCL pin of the Arduino. All the SDA pins connect to SDA on the Arduino.

Just make sure that each chip is given a unique address using the A0-A2 pins as detailed in the datasheet.


What are the traditional ways to optimize program memory usage?

What are the generally practiced methods for the optimization program
memory usage?

First, note you are searching for ways to lower SRAM memory. This contains global (variable) memory and heap space (dynamic memory + stack memory).

Avoid memory gaps, by not using dynamic memory (with free/malloc/new).
Avoid using the String class.
Avoid global memory in SRAM by using PROGMEM, F(..) if possible.
Use the smallest variable size (e.g. uint8_t instead of int).
Store arrays of booleans into bits (8 booleans per byte).
Use bit flags if applicable.
Use some compressed type of memory internally (affects performance), e.g. if you have many 6 bit values to store, store them not in separate bytes but use 6 bytes for 8 times 6 bit values).
Avoid passing arrays by value.
Avoid a deep call stack with many (big) variables. Note this affects your design, so use it as a last resort.
If you need a calculatable table, calculate each value instead of storing it as a table.
Do not use longer arrays than needed, and think about reasonable maximum array sizes otherwise (see hcheung's comment below).
(this is not a complete list).

Is there any difference in memory usage if the variable is declared
globally or locally.

Yes, local variables are added to the stack, but are removed after the function ends, global variables stay (but are only created once).
Note that variables on the stack (and also dynamic memory) are NOT taken into account in the memory calculated in the warning message during compiling.

Will it matter what the control statement/selection statements are
(like if, switch )

No, this will only affect the program memory.

Usage of Serial monitor. Serial.print()

Probably yes, the serial monitor probably reserves (quite?) some memory as a buffer.

Low memory available, stability problems may occur.
How bad are these warnings?

How bad it is, depends on how much memory is used which is not calculated, which is dynamic memory, and stack memory.
You can calculate it manually (which can be quite cumbersome for a big program), you can also use the GitHub library for this:
Arduino MemoryFree
If you know how much heap memory you use worst case, than add it to the calculated global variables memory. If this is less than your maximum available SRAM memory, you are safe.


Any problems taking arduino(esque) devices through airport security?

It will depend on your particular country of course. Check the rules on cabin baggage.

In Australia, Arduino boards should pose no problem. It is best to not take any batteries or tools with edges (screwdrivers) or heavy tools (wrenches). In case they do want to have a look, place the boards at the top of your bag for easy access.

I have traveled to Europe from Australia with half a suitcase full of large PCBs with no problem. The only time my bag was opened was when I was carrying a tea pot stand, which was in the shape of a tea pot. Apparently it looked like a gun.


Need help modelling and coding a feedback scenario

Well, (very) simply you could slowly increase/decrease the PWM value driving M2 until the voltage at A1 equals that of A2. If you make the time between adjustments long enough you should not get any (significant) oscillations.

However, more likely you want to get to the correct M2 PWM value quickly and for that you need a Proportional, integral, Differential (PID) control algorithm. Explaining this in detail is outside the scope of a S.E. answer, but in summary:

You have a value that signifies the current state of the system - which will be the A2 reading.
You also have a value that states where you want to get to - which will be the A1 reading.
You also have a control value - which will be the PWM value of M2

The Proportial part looks at how far away the A2 reading is from the A1 reading.
The  Integral part looks at how quickly we (the A2 reading) are moving towards (or away from) the desired value (the A1 reading). The Differential part looks at how long we have been away from the desired value.

Each of these (PID) parts (with tuning values that you set) contributes towards determining a new value for PWM at M2 and this iterates around with new values getting the current state closer and closer to the desired value.

There are lots of Arduino PID examples around. I'd suggest you read up on the algorithm itself and have a look at the Arduino.cc samples here.


How to control Keyboard inputs using arduino(serial monitor) and python keyboard libraries?

Your examples of sending input to the Arduino IDE monitor and to Python involve the Arduino sending data via "Serial over USB" convention. However this is not seen by the operating system (Windows, MacOS) as legitimate keyboard/mouse/joystick input.

There are separate USB conventions (device types) for keyboard/mouse/joystick. Only Arduinos where the USB interface is programmable are able to present those conventions, and some more easily than others, and require understanding some USB client libraries.  The link provided by Chris Stratton has some useful background.

A particularly easy way to get into this is with the PJRC Teensy, https://www.pjrc.com/teensy/, which comes with libraries and examples that let you do this out-of-the-box. See the "Teensyduino" section of their website for USB Keyboard, Mouse, Joystick and so on. These pages are useful background even if not using Teensy. It has attracted a small following of users interested in this area. Plus the various Teensies are conveniently small boards that fits nicely in some user-interface device you might want to build.


Do we have to calibrate LDR before using it in a project?

An LDR is a pretty inaccurate device. It just gives you a number which relates to darkness or brightness. How do those numbers relate to darkness and brightness? Well, only in a very vague way. All you can really say with any confidence is that bigger numbers mean brighter light, and smaller numbers mean darker darkness.

Even after "calibration" the numbers are pretty meaningless in any real-world sense.

All the "calibration" does is give a rough guide to the range of the numbers produced in any given lighting situation. It's then up to you to program your sketch in such a way that it works within the ranges of those numbers.

And yes, those numbers will change depending on the current lighting situation.

You could incorporate some form of "calibration" routine in your sketch to adjust any relevant values and calculations, or you could just provide some interface for tweaking values. Or your system may just really not care. It's impossible to know until you actually start creating your system.


Accessing 2 dimensional array in PROGMEM inside loop

After going through link given by Juraj above again, I could make it work as follows:

const byte a1[] PROGMEM = {'a', 'b', 'c', 'd'};
const byte a2[] PROGMEM = {'e', 'f', 'g', 'h', 'i'};
const byte a3[] PROGMEM = {'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'};
const byte a4[] PROGMEM = {'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

const byte * const arr[] PROGMEM = {a1, a2, a3, a4};

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

  Serial.println(pgm_read_byte(&(arr[0][0])));
  Serial.println(pgm_read_byte(&(arr[1][0])));
  Serial.println(pgm_read_byte(&(arr[2][0])));
  Serial.println(pgm_read_byte(&(arr[3][0])));
  for (int i = 0; i < 4; i++) {
    Serial.print(i);
    Serial.print(":");
    Serial.println(pgm_read_byte_near(pgm_read_word(&(arr[i])) + 0));
  }
  int j = 0;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 1;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 2;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 3;
  Serial.println(pgm_read_byte(&(arr[j][0])));
}

void loop() {

}

Now it shows the expected output and access from inside loop using variable index is possible. Thanks.


Difference between char array and unsigned char array

tl;dr : Since unsigned char is represented as a byte value, the output to the serial is the byte representation, not the char
I re-wrote the code you had for reference:
#define CHARS 255
#define BAUD 115200

unsigned char unsChar[CHARS];
char sinChar[CHARS];

void setup() {
  Serial.begin(BAUD);
  Serial.println("~~Setup~~");
  for(int i = 0; i < CHARS; i++) {
    unsChar[i] = (unsigned char)i;
    sinChar[i] = (char)i;
  }
}

void loop() {
  Serial.println("~~Loop~~");
  for(int i = 0; i < CHARS; i++) {
    Serial.print("INDEX        : ");
    Serial.println(i);
    Serial.print("unsigned char: ");
    Serial.println(unsChar[i]);
    Serial.print("         char: ");
    Serial.println(sinChar[i]);
    Serial.println("---------------------");
  }
  delay(10000);
}

When you run this you'll see the unsigned char is simply printed to the serial like any other byte value but the char value is printed as a character according to the ASCII chart.
If you compare the documentation for unsigned char

An unsigned data type that occupies 1 byte of memory. Same as the byte datatype.

The unsigned char datatype encodes numbers from 0 to 255.

For consistency of Arduino programming style, the byte data type is to be preferred.

versus a normal (signed) char:

A data type used to store a character value. Character literals are written in single quotes, like this: 'A' (for multiple characters - strings - use double quotes: "ABC").Characters are stored as numbers however. You can see the specific encoding in the ASCII chart. This means that it is possible to do arithmetic on characters, in which the ASCII value of the character is used (e.g. 'A' + 1 has the value 66, since the ASCII value of the capital letter A is 65). See Serial.println reference for more on how characters are translated to numbers.The size of the char datatype is at least 8 bits. It’s recommended to only use char for storing characters. For an unsigned, one-byte (8 bit) data type, use the byte data type.

So size wise an array of chars and unsigned chars are going to be the same. It's more about the representation of the underlying number (byte) and what works best for your use case.


At the moment, you've got two main problems. Firstly, both your if statements are being triggered one after the other. This is because the first if statement sets x to 0, which is part of the condition the second if statement looks for.

The second problem is that you're not monitoring the previous state of the button. buttonState will appear HIGH every time round loop, even if the button has been held down for several seconds. The result is that the output pin will be quickly getting turned on and off all the time.

What you need to do is store the last known state of the button. On every iteration of the main loop, only respond to the button if it's currently HIGH, and if it was LOW last time round the loop. You also need to make sure your two if statements are mutually exclusive; i.e. if you trigger one then don't trigger the other by mistake too, or it will cancel it out.

Something like this should work better:

// This will store the last known state of the button
int oldButtonState = LOW;

void loop()
{
  // Get the current state of the button
  int newButtonState = digitalRead(buttonPin);

  // Has the button gone high since we last read it?
  if (newButtonState == HIGH && oldButtonState == LOW) {

    if (x == 0) {
      // Toggle on
      digitalWrite(ledPin, HIGH);
      x = 1;

    } else {
      // Toggle off
      digitalWrite(ledPin, LOW);
      x = 0;
    }
  }

  // Store the button's state so we can tell if it's changed next time round
  oldButtonState = newButtonState;
}

As noted elsewhere, you still need to debounce the button, otherwise you're likely to get some false-positives. That can be done in hardware or software. A really simple way to get around it temporarily is to put in a delay of several milliseconds every time you detect the button changing state. It's not perfect, but it might be enough to get you started.


The datasheets for the AVR microcontrollers are reasonably good to read. Just Google for the exact controller on your Arduino (eg. ATmege328) and find the "Complete" datasheet on the atmel.com website. Don't download the "Summary", it doesn't include a lot of information. Download the datasheet from atmel.com, that is the only location with the most recent documentation.

There are three registers used in basic IO (check the chapter called "I/O-Ports"):

Where n is a port identifier, a letter ranging from A, B, C, ... depending on the number of IO pins your controller has. Each bit in each register represents a single GPIO pin (yes, you need some basic knowledge on binary to fully understand this).

DDRn, Data Direction Register: This basically configures a pin for either input (0) or output (1).
PORTn, Port n Data Register: When a pin is set as output, the related bit toggles the output pin high (1) or low (0). When configured as input, this enables a weak pull up resistor on the output pin.
PINn,  Port n Input Register: Use this register to read the current level on a pin that is configured as input.


1st : you have to put an appropriate resistor between the output of your arduino and transistor Base pin

2nd : you have to connect you motor and biased transistor to >>>> a suitable power supply (which has enough current (Amps) on it's output)

you can use this circuit instead of yours :

3rd : don't forget to use the diode in the schematic; it protects transistors from you motor coil's spikes you can use 1n4147 ( it depends on the size of your motor but i think, it works for you ( i wasn't successful to take a look at your motor and it's specifications )

4th : ignore the number of transistor, you can use your transistor (2N3904) instead of it

5th :NOTICE : this circuit has a problem, you have to connect appropriate power supply and replace "arduino 5 volts" by the + of your power supply in this circuit schematic

good luck


You can't.

The LDR has a spectral sensitivity which is very different from the
human eye's. The definition of the lux, or any photometric unit for
that matter, pretty much requires that your sensor is filtered in such
a way as to have the human eye's spectral sensitivity.


In your while loop, you never check the time again, so when the while loops hits, you will never leave it. You need to request the time again. Something like:

while ( now.minute()>0 && now.minute() < 30)
{
   digitalWrite(ledPin, HIGH);
   delay(100);
   digitalWrite(ledPin, LOW);
   delay(1000);
   now = rtc.now(); // check time again
}


You call servoX.write() repeatedly, even when no button has changed. Each call turns off interrupts briefly while the servo value is being updated. This happens, maybe 40 times/sec and may be messing up the servo timing in some non-constant way. Try only calling the servoX.write() functions once, only when its button-state has settled into a new state.
Update:

could you provide an example please

  bool prevButton5 = LOW;            // one of these for each button
    :                                // outside of the loop() func.
    :

  if(digitalRead(5) != prevButton5){  // button changed?
    prevButton5 = !prevButton5;       // save new button state
    if(preButton5 == LOW){            // (your same code from here down)
      servo1.write(120);
      delay(20);
    }
    else{
      servo1.write(50);
      delay(20);
    }
  }

Make a boolean for each button.
Wrap each of your button segments as I did for button5. Notice that your code is now executed only if the associated button has changed, so you will have many fewer servoX.write() calls.

That isn't the totally best way to do it. I made it as straightforward as I could, even though the additional code gets replicated for every button. I'd probably write a single function that manages one button and one motor, and call that function for each button / motor pair.
I also ignored the concept of switch-bounce to keep the number of changes low, but you should look it up and consider it. Switch-bounce is apparent bouncing of the switch contacts for a few milli-seconds during the change from open to closed or vice-versa, which leads to several make-break-make.....-make cycles (or the reverse) when you push or release the button. I'd probably make (or search for) a button debounce function and call it for the particular button I'm testing if I see that button has changed.
First try the "rude and crude" fix I suggested and get that working. Then if you're interested, try making one or more of the refinements.
Update:
the servos still jitter and twitch esspecailly when
I move the whole arduino and wires around.

That suggests either or both of

cross-talk;
the plug wires' connections being less than solid, especially when the wires move.

Try:

laying out the servo cables to keep them away from each other as much as possible;
wiring only a few of the servos, and in different combinations;
also try commenting out the code - or not - for those servos you disconnected in the previous step.

If it turns out to be the plug-in wires and if this project is intended to actually be used for something, I'd suggest using a screw-terminal shield on your Uno to attach the servo wires more securely.


You're using #define when it should be #include.


What are the main differences between Arduino and mbed?

As both an Mbed user and an Arduino user, this is my perspective on the differences between the platforms.

The IDEs are completely different. The Mbed IDE is an in-browser compiler that allows you to easily import other people's source code. It is a full c/c++ IDE that saves your code to your online Mbed account. You must be signed in to do any development work (requires internet access). Code completion exists, but is clunky. Project format more closely mirrors c/c++ programming than does Arduino's environment.
Programming the board is different. The Mbed uses a custom boot loader. The Mbed shows up as a flash drive when you plug it into your computer via USB. You compile your code using the online IDE, download the .hex file, and copy it to the Mbed. It's actually pretty neat, but more time consuming than clicking the 'Upload' button in the Arduino IDE.
The Hardware is different. This means different pinouts, as well as different capabilities. Take a look at the Mbed platforms and compare them to the Arduinos. Mbeds are generally more powerful than Arduinos (cpu speed, mem size, build in capabilities).

I use my Mbed when my Arduino isn't powerful enough or fast enough. It would replace Arduinos for me if it wasn't for the online IDE. The IDE is a little awkward to use, and it takes too long to program the board (downloading/copying and pasting is much more inconvenient).
I'm able to use all my same sensors and peripherals that I purchased for the Arduino with my Mbed (Except for shields due to the physical layout differences). I sometimes have to rewrite code to get it to work on the Mbed, but that's a good learning exercise.


Grounding issues Arduino Ethernet Shield makes WS2811 LEDs flicker

I suspect that the signal driving the LED strip does not have enough voltage swing. And that ground noise/resistance is what makes the system sometimes appear to work correctly.

With 12 volt LED strips, the data signal into the WS2811 should swing at least 0.3x to 0.7x 12 volts, or below 3.6 volts (low) to above 8.4 volts (high).

The Arduino Due has output signals from 0 volts to 3.3 volts.

Which would explain the observation that if ground is connected directly between Due and LED then the Due output is never high enough to signal the LEDs.

I would try using a logic level converter between the Arduino Due output and the LED strip data input.


Arduino Nano and 0.96 i2c oled screen not working

From what I am reading it is not properly connected.  You are getting what I would expect. ACL of the device goes directly to A5 and a pull up resistor to +5. Same thing with SCL, connected directly, both need pull ups. You did not state what it is connected to. If there is nothing connected you will get nothing. Also the old wire library did not support timeout so you could hang indefinitely.


Is there a known issue with deepsleep and MQTT ?

No. There may be a specific problem with the specific library you are using, but the concept of there being an issue with MQTT in general is nonsense.

Most deepsleep example I see online, all code is outside loop()section - is it mandatory to be like that ?

No, that's just being structured and tidy with your code. Whether code is in loop or in functions that are called by loop makes no difference. It can be a lot easier to manage your code if you structure it in functions rather than dumping it all in loop.


Does Arduino Tian/LininoOS support Python 3?

Yes, run the following

opkg update
opkg install python3-base_3.4.3-2_ar71xx.ipk


Reading from a KY-040 rotary encoder with Digispark

Shown below is a KY-040 test program that in my tests doesn't lose any counts and is more accurate than some other software; it picks up the counts between detents as well as those at detents.  You may be able to adapt it to your DigiKeyboard ATtiny system.

/*  roto_jw4.ino -- JW, 29 September 2015 --
 *  A 4-state state-machine implementation of rotary
 *  encoding for KY-040 rotary knobs.  The state-machine picture at
 *  https://e2e.ti.com/support/microcontrollers/hercules/f/312/t/318762
 *  in a Feb 4, 2014 7:40 PM post by Anthony Seely shows counts
 *  increasing on transitions 10 -> 11 -> 01 -> 00 -> 10 and
 *  decreasing on transitions the other way.  Transitions between 00
 *  and 11 or 10 and 01 are invalid.  This code detects valid
 *  transitions by (abOld xor abNew) equaling 1 or 2.  It detects
 *  up-count events by the tri-bit value ABA' (where A' is the new
 *  reading on pin A) being equal to 1, 2, 5, or 6 (a bit mask of
 *  0x66), and down-count events by ABA' being equal to 0, 3, 4, or 7
 *  (a bit mask of 0x99).
 *
 *  On a KY-040 unit I tested, there are 30 detent positions per turn.
 *  With this unit the code generates 60 counts per turn, which can be
 *  seen individually as one turns the rotor slowly.  Odd counts
 *  appear between detents, even counts at detents.
 *
 *  Set quadrature-signal pin numbers, via PinA and PinB constants.
 *  Set IPINMODE to INPUT_PULLUP if there are no external pull-ups
 *  on encoder AB pins, else set IPINMODE to INPUT
 */
enum { PinA=2, PinB=3, IPINMODE=INPUT };

static  byte abOld;     // Initialize state
volatile int count;     // current rotary count
         int old_count;     // old rotary count

void setup() {
  pinMode(PinA, IPINMODE);
  pinMode(PinB, IPINMODE);
  attachInterrupt(0, pinChangeISR, CHANGE); // Set up pin-change interrupts
  attachInterrupt(1, pinChangeISR, CHANGE);
  abOld = count = old_count = 0;
  Serial.begin(115200);
  Serial.println("Starting Rotary Encoder Test");
}

// On interrupt, read input pins, compute new state, and adjust count
void pinChangeISR() {
  enum { upMask = 0x66, downMask = 0x99 };
  byte abNew = (digitalRead(PinA) << 1) | digitalRead(PinB);
  byte criterion = abNew^abOld;
  if (criterion==1 || criterion==2) {
    if (upMask & (1 << (2*abOld + abNew/2)))
      count++;
    else count--;       // upMask = ~downMask
  }
  abOld = abNew;        // Save new state
}

void loop() {
  if (old_count != count) {
    Serial.print(millis());
    Serial.print("  ");
    Serial.println(count);
    old_count = count;
  }
}

Since some ATtiny's only have one external-interrupt pin, it may be necessary to use two pin-change interrupts instead of two external-interrupt pins.
(Six of the pins on an ATtiny45, for example, support pin-change interrupts, and only one is an external-interrupt pin.) Change PinA and PinB to appropriate pin numbers, and replace

  attachInterrupt(0, pinChangeISR, CHANGE); // Set up pin-change interrupts
  attachInterrupt(1, pinChangeISR, CHANGE);

with

  enableInterrupt(PinA, pinChangeISR, CHANGE); // Set up pin-change interrupts
  enableInterrupt(PinB, pinChangeISR, CHANGE);

and add the following #include near the beginning:

#include <EnableInterrupt.h>

To install the .h file for use via the Arduino IDE, unpack an EnableInterrupt zip file (for example, enableinterrupt-0.8.2.zip from bintray.com/greygnome) in the directory ~/sketchbook/libraries.  I think the package works with ATtiny's as well as more-standard Arduinos.


Using both TMRpcm and VirtualWire libs with ATmega328, despite the conflict on TIMER1

You could edit the VirtualWire.cpp source to use Timer2 instead of Timer1. For VirtualWire 1.18 the relevant section starts on line 512 with #else // ARDUINO.

On line 515 change (uint16_t)-1 to (uint8_t)-1 since Timer2 is only 8 bit. Then change all the TCCR1A, TCCR1B, OCR1A, TIMSK1 and OCIE1A to their Timer2 equivalent (hint: swap the 1's for 2's). Line 533 should be the last. On line 778 you also need to make a change to use TIMER2_COMPA_vect for VW_TIMER_VECTOR.

I hope that it helps.


I briefly read up on this subject and I found out this:

It seems like there's a protocol called J1850. There's no native support on the Arduino for that, but you might be able to do something bit-banging if you can find the specifications for this protocol. If you do this, I'd advise accessing the registers directly and skipping the digitalRead() command.

There are a few protocols in use, so it is hard to know without knowing the car you drive to even tell what the car will send.

More on this topic...

Anyway, it seems like you need a chip to use with this. Sparkfun also sells a breakout board for the STN1110 OBD-II to UART chip (tutorial). I couldn't really find anything else besides this.

Anyway, you probably need another chip to do this work. The Arduino isn't meant to do all of these protocols, and the OBD isn't UART-compatible.


Try this code:

void setup() {
    pinMode(8, OUTPUT);//MODE
    pinMode(5, OUTPUT);//AENBL
    pinMode(7, OUTPUT);//APHASE
}

void loop() {
  pinMode(7, HIGH);//APHASE
  pinMode(8, HIGH);//MODE
  pinMode(5, HIGH);//AENBL
  delay(200);
  pinMode(5, LOW);//AENBL
}

Here is a description of the breakout board, this shows a requirement of PWM on AENBL for speed control. Try different  delays.


Chrisl already gave the clue.

However, to add a comment with a code example I use the answer box.

In C you have more or less two kind of loops:

for
do / while

The first one is when you know beforehand how many iterations you have, the second when it depends on external input (e.g. when you expect a value acquired from within the loop).

In your case, you can better use the for loop, so you get:

for (x = 0; x < 6; x++)
{
   ...
}

What this does i:

Initializes x to 0 (first part of the for statement)
It checks the condition x < 5' (second part of theforstatement). If false, it continues with the first statement after thefor` body (after the } bracket).
It runs the body of the loop (inside the brackets)
It increases x (third part of the for statement)
It continues with 2

Also it is quite common for the condition to include the start element of the ragne (x = 0), but exclude the end element of the range (x < 6), thus it runs the last time with x == 5.


The key point is that if you do that, you're doing it wrong.

Typically a multi digit display is time multiplexed, such that you use a common set of segment lines to activate the pattern on each digit in turn, therefore at any one time only at most 7 (or 8 counting the decimal point) segments should actually be on.

Then in terms of the common connection which selects a given digit, this will indeed typically have to source or sink more current than an MCU I/O pin is typically rated to handle, so it's best if the common connection is driven by an external transistor or FET.

Other options of course include mutli-digit LED display drivers, or lower power display technologies like LCDs.

That said, if a software bug briefly means everything is on, chances are the chip will survive.  But hopefully this only happens to "engineering units" - you do want to make sure that production units don't suffer this at some point in the programming process or something like that (though that's not all that likely, as typically all I/Os become inputs with at most a weak pullup).


Ultrasonic sensor returns random values on external power supply

So i tried to used a stable 5V input on the 5V input pin and got the same more or less random values (jumping all around... especially on targets more than 1m away)

So I changed form newPing lib (http://forum.arduino.cc/index.php?topic=37712.0) to Ultrasonic lib (http://forum.arduino.cc/index.php?topic=37712.0).

Now the values are correct on each power supply and even more accurate on high distance than with newPing on USB power supply.

Don't know whats broken with the newPing v1.7 lib -.- but this works!


Consulting and inserting a string into an array if it doesn't exist (Arduino IDE) 1

In C there is no such thing as an "empty array".  All arrays have a finite pre-defined size.

String sensors[10]; // Room for up to 10 sensors

The usual way of storing an unknown number of entries that will be added to "as and when" is to use a linked list or doubly-linked list.

A linked list is a list of items where each item also contains a pointer to say where the next item in the list is located.

Also you shouldn't use the String class as it is not good when working with linked lists (or in general - stick to C strings).

Warning: linked lists aren't for the faint of heart.

First you would define a struct to store the data you want in the linked list:

struct sensor {
    char *name;
    int currentValue;
    struct sensor *next;
};

That would store the name of the sensor ("name"), the current value from the sensor ("currentValue") and also contains a pointer ("*next") to the next entry in the list.  That last bit is the most important.

Now you create a "head" pointer variable to start your list off:

struct sensor *mySensors = NULL;

That starts out as NULL to say "This variable has nothing in it at the moment".

Now that was the easy part.  The hard part is adding entries to the list...

A couple of helper functions can be of use here.  Let's start by defining a function that will look for a specific entry by name in the list:

struct sensor *findSensor(const char *name) {
    for (struct sensor *scan = mySensors; *scan; scan = scan->next) {
        if (strcmp(scan->name , name) == 0) {
            return scan;
        }
    }
    return NULL;
}

That will start off with a pointer variable scan pointing to the first entry in the linked list (mySensors).  While it's pointing to a valid entry (not NULL) compare the name to the given string and if they match then return the entry we are pointing to.  Next point to whatever the "next" pointer is pointing to, so you move down the list.

Now to add a sensor:

struct sensor *addSensor(const char *name, int value) {
    // First look to see if it exists:
    struct sensor existing = findSensor(name);
    if (existing != NULL) { // We found it
        existing->currentValue = value; // Update the value
        return existing;
    }
    // We haven't got it in our list, so create a new entry:
    struct sensor newsensor = (struct sensor *)malloc(sizeof(struct sensor));
    // And fill in the data:
    newsensor->name = strdup(name); // Create a COPY of the string
    newsensor->currentValue = value; // Store the value
    newsensor->next = NULL;
    // IMPORTANT: The new entry must point to NULL to mark the end of the list:
    newsensor->next = NULL;

    // Now where to add it in the list? Is there even a list?
    if (mySensors == NULL) {
        // No? Then we just make our new entry the head of the list:
        mySensors = newsensor;
        return newsensor;
    }
    // Otherwise we need to scan through the whole list to find
    // where the tail of the list is:

    struct sensor *scan = mySensors;
    // While the current entry points to a valid next entry
    while (scan->next) {
        // move on to that next entry
        scan = scan->next;
    }
    // There must be no valid next entry now (scan->next == NULL), so
    //  add our new sensor as the next valid entry:
    scan->next = newsensor;
    return newsensor;
}

Removing a sensor from the list is a much more involved process (even more than adding a sensor).  You need to "splice" the list around the deleted entry.  I'll add detail on that if you need it, but by the sound of things you won't be removing entries, only adding them.

The routines shown there (I haven't actually tested them, but it is standard code I write all the time) aren't as efficient as they could be.  If you are adding and removing entries all the time and you end up with quite a large list it can take longer and longer to scan right through the list to find the last entry to add to.  If that is the case you can maintain a "tail" pointer that you always update to point to the last added entry whenever you add one.  That can then be used to rapidly add to the end of the list without having to scan through the whole list every time.

Another optimisation if you do a lot of scanning around within a list is to make a doubly linked list.  This is just like the linked list above except it works in both directions.  Not only do you store a next pointer, you also store a previous pointer.  You can now scan in either direction - from head to tail or from tail to head, or hopping around at will inside the list.  That is especially useful if you want to do things like ordering the list alphabetically.


What is the tool to send file to SPIFSS on ESP8266/32?

The mkspiffs tool creates bin from file system data (or extracts data from bin).

SPIFFS bin is uploaded with esptool over USB or with espota over WiFi. It can be uploaded with the sketch binary in one command.

Example:

esptool.py -p /dev/ttyUSB0 write_flash 0x0 sketch.bin 0x300000 spiffs.bin

The IDE plugin adds SPIFFS upload to Arduino IDE Tools menu.


How to rotate servo every 12 hours using RTC module?

You have to spend some time and practice coding, it does not come over night. As far as your timing look up for an alarm clock sketch that will do what you want.  Once you understand that you should only have to add a few lines of code. As far as open source the tools you are using are open source. Remember there are people out there that are expertes and there people just starting so expect what you find to fall some in that range of quality.


If temperature regulation is what you seek, why bother with the Tachometer signal at all?

Thermistors don't require interrupts. Why do you need fully closed loop fan control? A simple proportional control of each fan and each hot item would likely suffice in keeping your system cool. Noise concerns, perhaps?

A brief article on proportional temperature control

A data sheet on a TI chip that may have some inspiration for you


Arduino USB Power vs External Power Supply

The design assumes USB provides a regulated 5v so no further regulation is necessary. The power connecter is meant to accept a wider range of voltage and regulate it to 5v, and the kind of regulators used on the Arduino board need that much higher voltage to provide regulation. If you already have a regulated +5v source you can supply it to the 5v pin. You'll bypass the on-board regulator this way, so just know that it will then be up to you to provide clean power.


How to set string in the structure part of NRF24?

Did you actually 'instantiate' the struct in the TX and construct sensor1 as payload.sensor1 = ...? Anyways, there's still a problem.

You are using String in your payload. The third argument to read is the maximum message length that can be stored in payload. In your read call, you passed the size of payload as MAX_LEN. You will receive incomplete payloads since the String object in the RX payload struct has no content in it yet and thus payload's size, which you passed as MAX_LEN, will be less than that of the actual payload that was transmitted. Just ditch the Strings and try:

TX:

int vals = {x, y, z};   // guessing they are ints

network.write(header, &vals, sizeof(vals));

RX:

int vals[3];
network.read(header, &vals, sizeof(vals));

Serial.print(vals[0]); Serial.print(',');
Serial.print(vals[1]); Serial.print(',');
Serial.println(vals[2]);


How to dim background LEDs on TFT display with ILI9341

I got in contact with the manufacturer of the shield, they informed that the background LEDs are hardwired and not controllable via the ILI9341. So, it is not possible to dim the background light in this shield

:-(

I will look for another TFT shield and make sure it's dimmable before buying.


how to do Arduino to esp8266 communication

using SoftSerial on the hardware serial isn't working on Arduino properly as sometime data receive and sometime not with garbage added so Using digital pins  other  2, & 3  other than hardware serial resolved the issue.


ACS712 to build doorbell sensor - Arduino Hangs up

There are two probable solutions to your problem:

The ACS712 is a hall effect based sensor and also door bells have a solenoid attracting a hammer to hit the bell. Try and place the sensor away from the bell, this could avoid any possible magnetic interference. (This is less likely to happen but there is a fair amount of chance)
May be, there is a problem with the code OR the laptops USB. Connect the Arduino to the sensor and the OUT pin to an analog input. Run the following code:

  void setup()
  {
     Serial.begin(9600);
  }
  void loop()
  {
     Serial.println(analogRead(A2));
  }

If this doesn't work, probably there's a problem with the sensor or the connections.

Give me more details about your connections, code and post a picture of your project for more help.


Im having another problem with my code the error is "redefinition of 'AF_DCMotor motor'?

Adafruit has a V1 and a V2 motor shield. They have different libraries too. AFMotor.h is for the V1 shield. From the error, I can tell you installed V2 lib. For that you need to include:

#include <Adafruit_MotorShield.h>


Several SIM with Arduino GSM/GPRS shield

You should reset the shield, and keep reset, while switch sims. The reset is on pin 7.

If you look at the schematic, you can see there are only 3 lines, plus a GND and VDD. The GND and VDD you can probably share between the different sims. The SIM_RST, SIM_SCK and SIM_DATA need to be switched.

I think you should use a MUX for that, but that is not my area of expertise. Note that at least the DATA line is bi-directional.


Delay() is not working outside of interrupt

Do I need interrupts() noInterrupts() in the loop section?

Yes, you do. Always.

The optimal workflow is

In the ISR itself, just raise a flag or directly change some global
variable.
In the loop you first copy that flag/variable to a local variable, using interrupts/noInterrupts to prevent the ISR changing the value while you are using/copying it.

Assignment are not atomic in Arduino World. That means that the value you are copying can change while you are doing it, and you end with garbage in your variables. Or, worse, it can change between one statement and the next. Try to debug that.

This is how you do it. In this example, I'm using an interrupt to manage a button (with debouncing). I need to detect state (pressed/not pressed) and timing (how long you pressed it). I can't directly use lastFallingEdge in loop; I copy it first so it won't change while I'm using it.

volatile unsigned long lastFallingEdge = 0; // For debouncing.
volatile boolean bPressed = false;

void buttonInterrupt(void)
{
    lastFallingEdge = millis();
    bPressed = true;
}

void loop()
{

    if(bPressed) {
        noInterrupts();
        bPressed = false;
        unsigned long falling = lastFallingEdge;
        interrupts();
        unsigned long len = millis() - falling;

        // Do something.
    }
}


Initialize a "Matrix" object in my own library?

This is a C++ question actually.

In C++, you initialize class members in the class constructor definition by using a "member intialization list" as follows for your example:

ZackBiColorMatrix::ZackBiColorMatrix (byte dataR, byte loadR, byte clockR, byte dataG, byte loadG, byte clockG)
:   r(dataR, clockR, loadR),
    g(dataG, clockG, loadG) {
    ... Additional initialization here
}

This is a special C++ construct (note the colon : after the constructor declaration but before its implementation).

Also note that, in your example, I think you don't need to declare redData, redLoad, redClock, greenData, greenLoad, greenClock, sicne they are not being used once your 2 Matrix fields have been initialized.

Hence you could simplify your class further, I think.


How to filter the power supply for an Arduino in a vehicle (car, motorcycle)?

The solution depend on what causes the reset.

It might be EMI interference on the RESET, in this case a stronger pull-up might help. The standard pull-up for nano is 1kohm which should be enough but if you use a clone the value might be higher.

If the reset comes from power drops then only a higher capacitor on the regulator input would not be enough since you also have other consumers on the 12V line that will suck the energy stored in the input capacitor.

Feed the capacitor and the regulator input through a diode, anode to 12v, cathode to capacitor/regulator. This will stop the energy stored in the capacitor to go back to the 12V line.


Wiring power new power button to UPS power module for raspberry pi

This looks like a momentary push-button; use a latching button (push-on/push-off) instead.


Why does Arduino IDE take so long to open?

The simple answer is "libraries".

Every time you start the application, all files inside your library folder are parsed.

And this is not done over your OS, but over the Java-Virtual Machine.

So it is not just slow, it is ultra-slow! Since your antivirus will probably also check each file.

Once, all files was read (maybe 1/2 of the time spent by your Arduino start), all your sketch folders are parsed.

At the end Windows devices and Arduino specific libraries are loaded.

On my Arduino IDE (is installed locally), on each starts, the Arduino IDE checks about 300.000 files. I need up to 20 seconds to load everything, before I can use the IDE.

What can you do?

Base

do not waste the library folder with unused libraries
NEVER put some documentation or non-Arduino files in your sketch folder, as they are all parsed by the IDE
disable the Antivirus for the folders:

Arduino
libraries
sketch

Advanced

If you open always the same project, you can for example edit the "preferences.txt" file.

If you remove some parameters from the preferences.txt, you will be able to lauch your IDE much faster. I created an application that statrs your Arduino IDE with personalized settings:
https://github.com/Adrianotiger/ArduinoIDE_Launcher

This application can remove some preferences like:

boardsmanager
last.* settings
recent sketches

when the Arduino starts, so it will be launched faster. But if you set the preference sketchbook.path, you can start your Arduino IDE 3-4 times faster. Just place the folder with your project libraries and you can start the IDE much faster.


You cannot get 50kYz from a DAC running on I2C on an Arduino.

The maximum rate for I2C (if you select fast mode) is 400kbps. Setting the DAC takes three bytes plus start/stop/ack bits (total 29 bits).

At 400kbps that equates to (400000/29) 13793 settings per second.

Add to that the time taken to actually create and process the data, running the instructions to do everything, you can expect about half that - which is the 7kHz you're getting.

To get 50kHz from a DAC you really need a CODEC and run something like I2S, which you are never going to do on an Arduino.


AVR (Arduino Uno) Serial.print and Serial.println only printing 1 or 2 chars

You have two issues here:

The first is that you are using the Arduino core library and failed to
initialize it. This is done automatically if you rely on the core's
supplied main(), i.e. you stick with the setup()/loop() style of
coding. If you write your own main(), you should start by calling
init() to initialize the core.

Edit: In this particular instance, you could get away by just enabling
interrupts with sei(). But I consider it good practice to initialize the
core if you are ever going to use it.

The second issue is the abrupt termination of main:
Serial.print() and println() do not really print to the serial port.
Instead, they put the characters to be printed in the output buffer, and
let an interrupt take care of actually sending them through the UART.

Your program ends with

return 0;

This will stop it. It will stop the whole program, including
interrupt-driven tasks. So you will see whatever characters did make it
to the UART, and nothing more.

If you instead end the program with and endless loop

for (;;) ;

it should work as expected.


HID communication between Arduino Uno and computer

You could use a second USB on the PC and use Hardware Serial to transmit commands. (Either via a second Arduino or a FTDI adapter) But be aware that at least the firmware I use and the controller programs are very sensitive to being disturbed in the loop. So you should have a good understanding of timers, interupts and non blocking code.


Can I include a header file into a new header file?

Yes, a header can include another header.  But if you are using the Arduino IDE and the headers aren't in the same folder, then you'll also need an #include line for it in the .ino file.


Chips & High voltage: Connected in Series?

If  you put three resistors of the same value in series, then you would get equal voltage division between them.
But chips are not like resistors. Their current usage is not constant and typically vary by orders of magnitude even within each clock cycle. See why this would be a problem?
If you have good 3V batteries that supply 3V up to the maximum current that the chips can draw, and the chips are rated to run reliably at 3V then there is another problem. Maybe you need decoupling capacitors across the chips?


Water pressure an salinity sensor connected to arduino

I suggest that you look for a sensor from Honeywell. The problem is that the pressure is very high for a board mounted sensor and the atmospheric pressure is varying. The board mounted sensors measure a maximum of 10 bar.  It is not clear what accuracy you require. Is there a connection to the surface? If so you should measure differential pressure between the seabed and the surface.  Can you be content with a maximum depth of 100 m?

I don't think salinity varies much offshore so it might not be worth measuring.


How to choose alternate I2C pins on ESP32?

I was able to resolve my issue thanks to Juraj comment.
I did :

Wire.begin(16, 17);
htu21d.begin(Wire);