Max current of Vin and 5V pin on Arduino Nano

It's hard to say. The maximum the on-board regulator can provide is 800mA. However the actual amount it can provide at any time depends on other external factors - most notably:

The voltage of your supply
The ambient temperature around the board
The thermal mass of the copper the tab is soldered to

The higher your input voltage the more excess voltage has to be converted to heat. When it gets too hot it overheats and (theoretically) shuts down.

Also the board itself will take some of the maximum 800mA quota, say 50mA (guestimate), so that leaves 750mA theoretical maximum for the 5V pin - but only when powered from not much more than 6.2V (5V + 1.2V regulator dropout voltage).

However, if you are powering from the USB port then it is limited to whatever the USB port can provide (100mA for a passive hub, 500mA for a normal USB port, 2A for a CDP).

The VIN current will be the same as the 5V pin current + the board current.


How to connect two Arduino without shields?

For long distance wired communication, look at RS-485.

  Since it uses a differential balanced line over twisted pair (like
  RS-422), it can span relatively large distances (up to 4,000 feet
  (1,200 m)). A rule of thumb is that the speed in bit/s multiplied by
  the length in meters should not exceed 108. Thus a 50 meter cable
  should not signal faster than 2 Mbit/s

You can use the MAX485 chip. It's pretty easy to work with but there's a good library as well:

https://github.com/Protoneer/RS485-Arduino-Library


Try powering the PIR motion sensor with a higher voltage.  I get the same problem you're seeing when powering it with the 3.3v output of an Adafruit Huzzah ESP-12, but it works just fine when I power it with the 5v USB power.


Ultimate GPS Logger Shield : Soft Serial Sketch Error

jfpoilpret > My apologies for not including enough information and details. But your comments did lead to me resolving my issue. I did not change my baud rate to match the baud rate of the source code and the script is working now. Appreciated.


You're reading (and doing your sums) backwards.

You have 1024 bytes of data space.

That data space is split into 16 sectors, so 1024 / 16 = 64 bytes per sector.

Each sector has 16 bytes reserved for keys etc, so each sector has 64 - 16 = 48 bytes of user data space.

48 bytes of user data space per sector multiplied by 16 sectors is 768 bytes.

Incidentally 1024 - 768 = 256, which is what you were calculating before.  What you calculated was the amount of the 1024 bytes that is reserved in total for the keys and access controls.


Can I hook up a compass directly to my GPS module?

Unfortunately this will not work. If you take a look at the documentation for the module (here and here) you'll see that the RX pin is just there to receive commands for doing things like changing the baud rate and the protocol. The GPS wouldn't be able to comprehend the compass data.


Nested for loop used to evaluate a two dimensional array of integers

if(i != 0 || i != 2){ //non time arrays

Let's see.

If i is 0 then that is true (it isn't 2)
If i is 1 then that is true (it isn't 0 or 2)
If i is 2 then that is true (it isn't 0)
If i is 3 then that is true (it isn't 0 or 2)

In fact that expression is always true. You probably want:

            if(i != 0 && i != 2){ //non time arrays

   void MinHrLimit(){
      int i = 0;

      for(int i; i < 3; i++){

You don't need the declaration of i there, because it is redefined in the for loop. In the for loop the variable i has an undefined value. You really want:

   void MinHrLimit(){

      for(int i = 0; i < 3; i++){


I got a missignatured ATmega328-PU. How can I fix that?

While browsing sparkfun, i have found several news posts that show their struggle with mislabeled chips. Here are a few:

https://www.sparkfun.com/news/350
https://www.sparkfun.com/news/384
https://www.sparkfun.com/news/364

Sparkfun had received a questionable shipment if ICs from a new seller in china. They decided to test them before sending them into production, and none of their test boards worked. Using nitric acid, they were able to remove the case of the ICs and fould a hunk of metal that looked like copper.

In another article, they dissected some suspicious ICs from Atmel, and found an ON semiconductor silicon wafer inside. The chips were not functional ATmegas, but they did have silicon, unlike the other ones.


By visually assessing the pictures, the issue seems to be due to poor soldering job.

You should try re-heating the soldering joints and make sure they are clean. There could be dry joints that may not be conducting signals.

Also you should upload pictures to your question post, not as an answer.


The % is the modulo operator in C/C++, which basically means:

Divide the value to the left of the % by the value to the right of it
Discard the quotient and keep only the remainder.

For instance, 10 % 5 = 0, because 10/5 = 2 with no remainder. Whereas 11 % 5 = 1, because the remainder of the division is 1.

In your case, the modulo operator is likely being used to keep the value of put_index less than 100 at all times. If it became 100 because of the operation put_index = put_index + 1, then the modulo operation would make the 100 into 0, so put_index will keep incrementing 0–99 repeatedly.


You probably want to take a look at Robert Faludi's book Building Wireless Sensor Networks, published by O'Reilly. He describes, step by step, a very similar project, but without the Arduino.

Or Alasdair Allan's Distributed Network Data, also published by O'Reilly, which has a similar project using an Arduino.

Also, take a look at Robert Faludi's blog TMP36 Instructions: Simple Sensor Network.


How to stop program while Servo is rotating

How can I implement this? Is it possible to read Servo's statement?

No, it is not possible. When you do a servo.write() it just changes the PWM duty cycle. It's then up to the servo to use that to set its position. The Arduino has no concept at all of the current position of the servo.

  Btw, I don't want to put delay after write(), so other than that strategy.

The only other way, besides delaying or otherwise using millis() to wait for a predefined period after your write would be to implement some form of feedback between the shaft of the servo and the Arduino. Maybe a potentiometer, or rotary encoder would do the job.


To me it seems, as if you have no knowledge about C/C++. ( I might be wrong. ;-) )

If you plan to do more programming projects, I advice you to learn the basics of this programming language before proceed with the projects. It would be hard thinking about an algorithm, if you don't know the tools to implement it.

In case you just need this once for a (let's say arts project [or homework ;-)] ), I add some example code. At the moment I have no chance to test the code. So it's blind written, and there might be typos. In about 8 hours I will have access to a test setup then I'll correct it if necessary.

#include <LiquidCrystal.h>

// Here you setup your LCD display
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// you initialize the position where the next character
// will be displayed (0,1) (x,y)
int x = 0;
int y = 1;
// setup is only done once
void setup()
{
    // initialize the lcd lib to be used with a 16x2 LCD
    lcd.begin(16, 2);
    // erase all character from the display
    lcd.clear();
}

// the loop is executed again and again and ...
void loop()
{
    // move forward
    // as long as the position is less than 15
    // you allow x = 0, 1, 2, ... ,15 because
    // you increase two times in each loop step
    while (x < 15)
    {
        lcd.clear( );

        lcd.setCursor( x, y );
        lcd.print( "A" );
        delay( 250 );

        // step to the next position
        x = x + 1;
        // toggle y
        y = toggle( y );

        lcd.clear();
        lcd.setCursor( x, y );
        lcd.print( "A" );
        delay( 250 );

        // step to the next position
        x = x + 1;
        // toggle y
        y = toggle( y );
    }

    // now move backward
    // x is still 15 and you want to go backwards until x == 0
    while ( x > 0 )
    {
        lcd.clear( );

        lcd.setCursor( x, y );
        lcd.print( "B" );
        delay( 250 );

        // step to the next position
        x = x - 1;
        // toggle y
        y = toggle( y );

        lcd.clear( );
        lcd.setCursor( x, y );
        lcd.print( "B" );
        delay( 250 );

        // step to the next position
        x = x - 1;
        // toggle y
        y = toggle( y);
    }
}

// this is a subroutine that toggles y = 0 <-> 1
int toggle( int yval )
{
   // I use a ternary operator
   // in case y == 1, I return 0 and a 1 otherwise
   return ( yval == 1) ? 0 : 1;
}


Just to give an anwser for users struggling with the same problem I will sum up what helped me.

To connect the UART to the ESP the Beginner's Guide to the ESP8266 from @tttapa was very helpful. Another helpful link was this one:
https://www.allaboutcircuits.com/projects/flashing-the-ESP-01-firmware-to-SDK-v2.0.0-is-easier-now/

So in my case I just needed the GND, 3V3, RXI and TX0 pins from my UART.

I needed no external powersupply for the flashing process and some simple examples.


How do I configure the Arduino IDE to look for source code in a subdirectory within the directory that holds my sketch?

The behavior of the Arduino IDE with this sort of thing has changed over time so it depends on which version of the Arduino IDE you're using. With recent versions you can put the files in a src subfolder of your sketch folder and then do:

#include "src/mylib1.h"

or:

#include "src/mylib1/mylib1.h"

depending on how you want to organize the folder structure.

When doing this you may find that Arduino libraries often use incorrect include syntax in their source code. For example in mylib1.cpp:

#include <mylib1.h>

although wrong, would still work if the library was located in one of the Arduino libraries folders but with the library located in the sketch folder this no longer works and you need to change it to:

#include "mylib1.h"


Make an Xbox 360 controller with an Arduino Uno

Arduino Uno's do not have a native USB Connection. However, if you use an Arduino Leonardo or Pro Micro, you can use MHeironimus's Joystick library, However I am not sure if they are specifically compatible with the XBox.

https://github.com/MHeironimus/ArduinoJoystickLibrary


Digital Pins reads 1 when configured with internal_pullup

There is no difference between a switch and a "pin" for input. All are either HIGH or LOW. You tie it HIGH with the pullup, and then try giving it a HIGH with +5V (Caution: The Due is a 3.3V device, not 5V!).

At no point do you ever give it a LOW signal (connect the input to GND), so how can it ever read LOW?


In my experience (15 years in industry, 30 total), this does not matter. What matters is having good developers who understand code written in ANY valid style. I currently work at a large bank, and there's 2 different bracket styles being used in our code, and nobody cares. Good developers don't care about this. We care a lot more about the code being valid, error-free, and efficient. If you do that, I don't care where your brackets are.

Yes, there are style guides for C++ but you don't need to use them. This is a good one though...

http://google-styleguide.googlecode.com/svn/trunk/cppguide.html

I am not aware of any style tools that integrate into Arduino IDE. There are some style tools that integrate into Eclipse though - and if this is important to you and your team, I strongly suggest using Eclipse for development. The Arduino IDE isn't really for large projects.

http://astyleclipse.sourceforge.net/ - but Eclipse doesn't really need this, it has a pretty good built-in formatter.


IR sensor readings at different voltages

It sounds to me like your system works, but you have trouble if your voltage drops.

First of all here's 2 tips that might solve your problem.

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

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

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

see https://electronics.stackexchange.com/questions/17754/where-to-place-a-capacitor-to-smoothen-ir-sensor-reading for a short description and the calculated example.

If however it is correct, and your readings of colors don't follow a linear scale, you would have to deduce that actual curve and apply it in the code - but that might not be easy.

So it would be much more easy to remove that variable by ensuring that the voltage is constant. Most Arduino boards have an 5V onboard voltage regulator that will keep the voltage exactly at 5 Volt when connected to battery via the power Jack!

(USB bypasses this regulator and have a little voltage drop so it is sligthly lower than 5V, and more very prone to fluctations if coming from a AC source affecting your analog read considerably)

The battery connected onboard voltage regulator however requires a higher input to do the regulation so the battery needs to supply atleast 6.2V or higher, in your case you would have to use a voltage source of less than 6.2V if this is the source of your problems.

(the voltage regulator on original arduino boards needs voltage of 1.2V higher than the needed output - clones might differ and require upto 2v more than the needed output)

hope this can help solve the issue

Mikael


ESP-8266 stopped working due to possibly faulty perfboard layout

It turns out the real culprit was the AT+IPR=9600 command bricking the board. The board was "fixed" by obtaining the firmware and flashing it to the board using esptool.py. Download the repo's source code, navigate to the directory bin/at/, and see the file README.md to see which addresses to flash the different parts to.


It doesn't require const char *, it says "passed string won't be changed inside of call". Externally it can be char * or char [] or Arduino String class with using c_str() method to get const char *.

And as the MAC address won't change a lot, it should be done once in the setup().


Code for activating a led after 2 minutes and will blink after 30 seconds interval

Use a commonly available USB power pack re-charging from mains and powering the Arduino.  Use a light source directly powered by main and optically couple that to an Arduino.  There are plenty of examples on the web where an Arduino is used to detect light.  Once triggered, write some additional code to blink the led.  Since you are not doing anything other than timing, you can use the delay Arduino library to time events.


SR505 PIR sensor Time Delay Using Ticker Library NodeMCU

You really don't need the Ticker library. Just maintain a timestamp of the last time the PIR was seen to be HIGH:

void loop() {
    static uint32_t lastSeenHigh = millis();
    static bool pirState = false;

    // If it's active then record that fact along with the time
    if (digitalRead(SIGNAL_PIN) == HIGH) {
        lastSeenHigh = millis();
        pirState = true;
    } else {
        // otherwise, if it's been 12 seconds since last seen
        // active, record that it's inactive.
        // 20 seconds, minus the 8 second active time, times 1000 is
        // 12000 milliseconds to extend the time by
        if ((millis() - lastSeenHigh) > 12000) {
            pirState = false;
        }
    }

    if (pirState == true) {
        // Do whatever you want in here when the PIR is active
    }
}

With that (untested) code:

Any time the PIR is active the current time is recorded and the state is set true
When the PIR is LOW and at least 12 seconds have passed since the last activation, set the state to false.


Programming Micro controllers using Arduino ISP

Page does nog exist (404).

Also, to run actual Arduino code on it, you'll most likely have to port the Arduino library, if this hasn't been done before.

You may opt for something as easy as a teensy 3.2, they probably meet your requirements and work well in combination with Arduino.
Or fetch one of the newer Arduino models that have comparable microcontrollers

If you still want an M3 (without development board?) you'll be entering a somewhat advanced usecase, in which you probably don't even want to rely on or use Arduino. There are far better IDE's.


Can't change pins in AM2320 code, types mismatch

Two problems:

When you create an object instance with no parameters you must not have parentheses. You should construct thus:

TwoWire mywire;

The constructor expects a pointer to an object, not an object. Just take the address of the object with & and pass that:

Adafruit_AM2320 am2320 = Adafruit_AM2320(&mywire, -1, -1); // as the default values

However
Most Arduino boards have the I2C pins hard-wired internal to the chip and can't be changed. You would need to use some form of software implementation that is also a polymorphic child of the TwoWire class. If such a thing exists.


All floats feedback a rounded down integer

You already got a couple of perfectly good answer. I will nevertheless
suggest a slightly different idiom:

float voltage = sensorVal * (5.0 / 1024);

or, maybe better:

const float V_REF = 5.0;  // at the top of the sketch

float voltage = sensorVal * (V_REF / 1024);

The reason this is slightly better than the other options is because
division – even integer division – is a very expensive
operation on the smaller Arduinos. By writing the conversion as in the
lines above, the ratio V_REF / 1024 becomes a compile-time constant,
which is evaluated by the compiler at build time. Then, only the much
cheaper multiplication needs to be done by the Arduino itself, at run
time. Not a big deal if you are not time constrained, but it's a
low-hanging fruit in terms of optimization.

You may write 1024.0 instead of 1024 if it feels safer. I tend to
keep the .0 for the voltage only, because 1024 is an integer, whereas
the “5” in “5 volts” is conceptually a real number (it's an
analog voltage, and not even exactly 5 V if you bother to measure
it). But this is just a personal preference at the end.


Increasing payload size above 32 bytes using nRF24L01+

If you look at the specification or datasheet for the nRF24l01+, you will see that the 32 byte payload is the maximum that the device can handle.
For example:

If you need to transmit anything larger than 32 bytes, you will need to develop a protocol that splits up your data into chunks of 32 bytes or less and sends the data in several packets.
The actual protocol you design is up to you, but a simple technique might be using the first packet to send a count of the number of data packets to expect and then simply send those packets, each with a part of your data and reassemble it at the receiving end.
You may need to design something more robust so you don't get confused by lost packets or bad data. The larger your payload, the more chance of transmission errors, so it might be an idea to experiemnt with the payload size to get the best throughput for your particular application.


All you need is a single resistor.

simulate this circuit – Schematic created using CircuitLab

When DATA is an input the data from MOSI passes through the resistor to both DATA and MISO.  When DATA is an output the data from DATA goes to MISO and voltage is dropped safely across R1 to the sink or source of MOSI depending on what state it is in.

In other words, when DATA is input it receives from MOSI. When DATA is output MOSI is ignored.

Code wise, it's no different to any other transfer. You just never have any valid data to transfer while receiving. So just transfer anything (0xFF is a common choice).

For example, if you need to send 0x38 first then receive two bytes, you would:

SPI.transfer(0x38);
uint8_t byte1 = SPI.transfer(0xFF);
uint8_t byte2 = SPI.transfer(0xFF);


FSR wiring using internal pullup resistors?

There is probably no practical difference concerning high side vs low side (except the Arduino Uno only has a pullup, and no pulldown).

The issue would be the accuracy of the pullup (graphs in the datasheet show variations of 10% with temperature) vs the accuracy of the resistor (1% is now commonplace).

The pullup is usually a current source, not a specific resistor value. Even if the supply voltage is not known, the maths involved with solving a known resistor is series with an unknown resistor is quite straightforward.

Short answer, using the pullups would probably work, but you would have to confirm accuracy, calibration and even repeatability, while this is already well known for a resistor.

Datasheet, see graphs on p412:

http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf


Receiving junk values in Arduino serial monitor console

You have created a SoftwareSerial instance called XBee which is taking pins 17 and 18. You then use Serial1 which is pins 17 and 18.

You do not want, nor need, the XBee SoftwareSerial instance, since you are using hardware serial pins.  Delete it and all references to it.

Also, you are turning off Serial1 after using it, which means it will never work again:

Serial1.end();

You would only use that instruction in very very specific circumstances.  Delete it.

After checking to see if there is data available to read on Serial1 you then proceed to try and read it from Serial:

char recbyte=Serial.read();

That should be:

char recbyte=Serial1.read();

You are writing to EEPROM on every single iteration of loop:

EEPROM.write(addr, id);

It is likely that you have already killed your EEPROM.  C'est la vie...


I managed to fix the problem. I have a PC with Ubuntu 16.04 and I tried to re-flash it using Ubuntu's ESPTool, which was why it was failing. I noticed it failed constantly at a certain point. To fix it, I re-flahed the firmware with this python script, and it was successful.


Outputting 400 mV using Arduino Nano PWM pin

PWM pins don't output analog voltages. They output pulses of 5V. You then need to average the output in order to get an actual analog voltage out of it. You should be able to use a capacitor and resistor to average out the voltage of the PWM pin, making a low-pass filter. You won't get exactly to 400mV. If I remember correctly the PWM pin has a value of 0 - 255, and 1/255 is 0.0196 V after a good low-pass filter, or 19.6 mV, so analogWrite(pin,20) should get close to the 400mV you want.

Another option would be to use a voltage divider to the output to get the output you want. That way you can use the full range of analogWrite() in producing the 400 mV and smaller voltages, thus gaining precision. Then again, if all you want is a fixed 0 or 400mV you could accomplish that with a digital output pin and a fixed voltage divider - no need for PWM.


What is the size of the buffer in serial communication with arduino uno?

That would be 64 bytes, providing the buffer is fully empty. See https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/HardwareSerial.h#L42-L43


On the NodeMCU “v3” (and only on the v3) there’s a pin called VU (Vusb) that is connected to the +5V on the USB bus of the NodeMCU socket. This pin can be used to feed external components when it’s connected to USB, within the limits of the USB power supply it’s connected to.

The Vin pin (which is available on all NodeMCUs (and not just the v3) is a +5V power input which can be used to power the NodeMCU if it is not connected to USB. It can not be used as an output and it needs a stabilized supply.


Simple compiler design help: Variable length arrays in Arduino?

The Arduino IDE features nearly full C++ language support (at least for C++03 features).
library support is limited, but any standard component you need, you should be able to get an open source implementation that compiles.
That said, you have 2K of RAM to work with on an Arduino, so the kind of C++ code you would write for a general purpose computer just won’t get you very far.
I could be wrong, but I very much doubt there are full Python implementations for Arduino.

Edit: Thanks to Mr. Penguin for pointing out that we’re dealing with an Arduino Due, not an Uno (I had overlooked the OP’s tag). 96K of memory is actually a decent amount to play with, so grab a library implementation like this one and use the C++ techniques you wish to use.


Playing audio files with sine wave from arduino

I used some time ago the TMRPCM library that the tutorial you linked used and I was very satisfied.
It doesn't take too much space and it has some really unique and neat features like the possibility to use two speakers instead of one to reproduce stereo audio (Unfortunately you need a more powerful AVR IC, surely not an UNO board/328 IC for this feature if you don't want to occur in bad reproduction)
From GitHub's wiki:

All 328 based boards: Arduino Uno, Nano, Duemilanove, etc
Mega Types: 1280, 2560, etc
No Due support currently.

You can only have WAV files on the SD but they can be very large (other libraries limit you to a specific maximum size/duration) and you need to connect the SD to the arduino via SPI (as far as I know it is the only way to communicate directly with an SD card).
Also, you will need to convert the files to 8 bit WAV (so it's faster and easier for the arduino to reproduce the sound) with sample rate from 8 to 32khz, mono audio.
Be careful just because you'll need to power the SD with 3.3 volts otherwise you'll fry the entire card.

Most of the extra features require more memory, more program space, and in some cases, more processing power for playback Some of them are still being fine tuned. Please keep this in mind when enabling these features.

If you want to take a look, go to this page for more informations on the advanced features
A last thing that I have to say is that the functions are really straightforward:
TMRpcm audio;
audio.play("filename");    plays a file
audio.play("filename",30); plays a file starting at 30 seconds into the track
audio.speakerPin = 11;     set to 5,6,11 or 46 for Mega, 9 for Uno, Nano, etc.
audio.disable();           disables the timer on output pin and stops the music
audio.stopPlayback();      stops the music, but leaves the timer running
audio.isPlaying();         returns 1 if music playing, 0 if not
audio.pause();             pauses/unpauses playback
audio.quality(1);          Set 1 for 2x oversampling
audio.volume(0);           1(up) or 0(down) to control volume
audio.setVolume(0);        0 to 7. Set volume level
audio.loop(1);             0 or 1. Can be changed during playback for full control of looping.


Differences between Arduino Uno SMD and Uno DIP

As far as I know there is no real difference, at least not directly related to the SMD.

There are many clones which sometimes have slightly different behavior or protection.

But for the SMD the only disadvantage is it cannot (easily) be replaced.

I have one original one (with DIP) and several clones and so far I did not found any difference, except for having mini USB instead of normal USB.


What you have to understand is the concept of scope.

Everything (well, almost everything) in C and C++ is enclosed in { and }. Those define a scope, and everything defined within that scope is available to any other scopes defined within that scope.

You can also assume that the whole sketch is surrounded by { and }. This scope is called the global scope.  Anything defined within it is available anywhere in your sketch.

So by defining the object in the global scope it is available everywhere:

# include "Leddisplay.h"

Leddisplay *pRightDigit;

void setup() {
    byte Digit[9] = { 22, 23 , 24 ,25, 26, 27, 28, 29, 2 };
    pRightDigit = new Leddisplay(Digit);
}

void loop() {
    pRightDigit->setDigit(5);
    pRightDigit->displayDigit();
}

However the use of new etc is discouraged in low-memory systems. Better is to statically define the object:

# include "Leddisplay.h"

const byte Digit[9] = { 22, 23 , 24 ,25, 26, 27, 28, 29, 2 };
Leddisplay pRightDigit(Digit);

void setup() {
}

void loop() {
    pRightDigit.setDigit(5);
    pRightDigit.displayDigit();
}

Note that, when statically defined like this, things in the constructor aren't guaranteed to be run at the right time. They should be moved into a .begin() function that you then call from setup():

# include "Leddisplay.h"

const byte Digit[9] = { 22, 23 , 24 ,25, 26, 27, 28, 29, 2 };
Leddisplay rightDigit(Digit);

void setup() {
    rightDigit.begin();
}

void loop() {
    rightDigit.setDigit(5);
    rightDigit.displayDigit();
}


Running a HC-SR501 PIR Sensor constantly using battery

This are multiple questions in one. But I will do my best to tackle them one by one.

  Can the ESP8266 module count impulses during one of the sleep modes?

The ESP8266 has different power modes. Short answer: As long as the CPU is running, yes.

Long answer: The ESP8266 has quite a few power modes. They are easily put:

No-sleep (as high as 170 mA while communicating)
Modem-sleep (15 mA Wifi is off, everything else is running)
Light-sleep (0.9 mA CPU is put to sleep and system clock stopped, can be waken up by a external interrupted)
Deep-sleep (20 uA Everything is off, basically it's powered down, but can wake itself on set intervals or reset it to wake it. everything in RAM is lost, except RTC RAM)

So if your sensor gives a pulse, you can use that as a interrupt and go to light-sleep. If you need to pull it, all you can do is modem-sleep.

ESP8266 power modes

  Do you have a less current consumpting module in mind allowing wifi transmittance? (LoRa or the NRF Module are not an option atm, since the router has to be used)

Modem-sleep is your friend. Only connect to the router if there is data to send.

You can set up an AVR and use it in ultra low power mode and only turn on the esp if there is data to send. But explaining how to set that up goes way too far out of this scope.

  What kind of battery/akku would you suggest? Having sufficient voltage and capacity (mAh) and still being easy to handle?

I can't choose a battery for you, there are just too many of them. But what I can do is tell you about how batteries work.

Take for example a 9 volt battery (not my first choice, you will see in a bit).

We take an energizer 522. It's a Alkaline battery and has 600 mAh. That means it can deliver 600 mA in one hour. But there is a catch. the more you draw from a Alkaline battery, the less capacity it will have.

It is 9 volts right? yes and no. you see. the voltage potential will drop (quite dramatically) over its lifetime.

A liniar voltage regulator (AMS1117) will take the needed mA of the output on the input and drop off the extra power as heat. So the battery will always have the same load (Yes, the esp8266 is a dynamic load, but lets keep it simple)

so lets say it's in modem-sleep (15mA). Lets divide 600 by 15, that is 40 hours of runtime. For simplicity I don't count the sensor itself.

9 volt block datasheet

The AMS1117 needs 1.5 volts more then its output voltage for ensuring a stable output. So that is 4.8 volts or higher. But no higher than 12 volts.

AMS1117 datasheet

Choose a battery that has enough mAh and isn't more then 12 volts and not lower than 5 when depleted. If using outside, check if its operating temp range is wide enough.

So basically try to lower your energy footprint as far as it can possibly go and then based on the new average power usage, find a battery that is big enough for the task.

Better yet, get a solar cell and a rechargeable battery. It has a full list of other problems, but this answer is a bit too long already and that topic is out of the current scope.


NRF24L01 +pa +lna modules do not communicate

That sketch never worked for me also so try this:

Check whether your power supply can give a constant 3.3V and a minimum of 0.5A(500mA)?
Then try these connections:

Then try your code again.
If it fails to work try a simpler library like the NRFLite library and

I actually never got that library and that sketch to work, but when I kept everything the same and used the NRFLite library, everything worked!


Code doesn't seem to work when trying to program 2 sensors

As JFPoilpret says you if logic is wrong.
It might make it easier if you took that whole if block out and made it into a function that accepted the value from the sensor as a parameter.

void CheckReading(int reading)
{
    if (reading < 10) {
        Serial.println(" - Nothing");
    } else if (reading < 200) {
        Serial.println(" - Light");
    } else if (reading < 500) {
        Serial.println(" - Lightness");
    } else if (reading < 800) {
        Serial.println(" - Medium");
    } else {
        Serial.println(" - Big-squeeze");
    }
}

Notice that the values only go up to 800, going larger than 1023 won't work anyway.


nRF24L01 using sender as receiver and vice versa with RF24 library

Update: It was working yesterday, but today... same thing as with "delay()". What's wrong with these radio-modules??

I have discovered that the delay() function was causing this abnormal behavior.

So I have implemented periods instead of delay() and now I'm able to switch operating mode between "receiver" and "transmitter". Moreover, I have discovered few additional conditions that must be met (read the comments for the code).

Below is working sample code where transmitter sends some large message. Receiver gets it, waits 2 secs, then responds with another large message and gets the acknowledge for this message:

Sender

#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#include "printf.h"
const uint64_t pipe01_ = 0xE8E8F0F0A1LL; //Writing pipe must be full address if acknowledges will be used
const uint64_t pipe02_ = 0xE8E8F0F0A2LL; //At least one of reading pipes must be full adress
const uint64_t pipe03_ = 0xA3LL;
const uint64_t pipe04_ = 0xA4LL;
const uint64_t pipe05_ = 0xA5LL;
const uint64_t pipe06_ = 0xA6LL;
RF24 radio(9, 53);

void setup()
{
    Serial.begin(115200);
    delay(250);
    radio.begin();
    radio.setChannel(0x57); //not necessary. But must be equal at both sides
    radio.setPALevel(RF24_PA_LOW); //not necessary. But must be equal at both sides
    radio.enableAckPayload(); //For ability to change the Ack Payload with writeAckPayload()
    radio.openReadingPipe(2, pipe02_); //At least one of reading pipes must be full adress
    radio.openWritingPipe(pipe01_); //Writing pipe must be full address if acknowledges will be used
    radio.enableDynamicPayloads(); //If not set, size will be of fixed length. Default fixed length is 32 bytes

    /*Must run this if "startListening()" will be used anywhere in the code below.
    nRF24L01 remembers it's state even if Arduino was restarted*/
    radio.stopListening();
    Serial.println("Sending the message...");
    char message[32] = "qwertyuiopasdfghjklzxc1234567890"; //some test message
    radio.write(message, 32); //Send message over the predefined "writing pipe"

    Serial.println("Waiting for response...");
    radio.startListening(); //Resets TX buffer and switches radio module's mode to "receiver"

    uint16_t ack = 123;
    radio.writeAckPayload(2, &ack, sizeof(ack)); //Custom ACK payload must be set after "startListening()". Because "startListening()" resets TX buffer
}

void loop()
{
    if (radio.available())
    {
        char respMessage[33];
        memset(respMessage, 0, sizeof(byte) * 33);
        while (radio.available())
        {radio.read(respMessage, 32);}

        Serial.println("respMessage: " + String((const char*)respMessage));
    }
}

Receiver

#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#include "printf.h"

#define period_  2000

// Set pipes
const uint64_t pipe01_ = 0xE8E8F0F0A1LL; //At least one of reading pipes must be full adress
const uint64_t pipe02_ = 0xE8E8F0F0A2LL; //Writing pipe must be full address if acknowledges will be used
const uint64_t pipe03_ = 0xA3LL;
const uint64_t pipe04_ = 0xA4LL;
const uint64_t pipe05_ = 0xA5LL;
const uint64_t pipe06_ = 0xA6LL;

unsigned long checkPoint = 0;
bool messageReceived = false;
RF24 radio(9, 53);

void setup()
{
    Serial.begin(115200);
    delay(250);
    radio.begin();
    radio.setChannel(0x57); //not necessary. But must be equal at both sides
    radio.setPALevel(RF24_PA_LOW); //not necessary. But must be equal at both sides
    radio.enableAckPayload(); //For ability to change the Ack Payload with writeAckPayload()
    radio.openReadingPipe(1, pipe01_); //At least one of reading pipes must be full adress
    radio.openWritingPipe(pipe02_); //Writing pipe must be full address if acknowledges will be used
    radio.enableDynamicPayloads(); //Writing pipe must be full address if acknowledges will be used
    radio.startListening(); //If not set, size will be of fixed length. Default fixed length is 32 bytes
}

void loop()
{
    if (radio.available())
    {
        char newMessage[33];
        memset(newMessage, 0, sizeof(byte) * 33);
        while (radio.available())
        {radio.read(newMessage, 32);}

        Serial.println("newMessage: " + String((const char*)newMessage));
        checkPoint = millis();
        messageReceived = true;
    }

    unsigned long timePassed = millis() - checkPoint;

    //When it receives, controller waits for 2 seconds then sends the response just one time
    if (messageReceived && timePassed > period_)
    {
        messageReceived = false;
        checkPoint = millis();
        Serial.println("sending response...");

        //This must be called before sending anything (except acknowledges)
        radio.stopListening(); //Resets TX buffer and switches radio module's mode to transmitter

        char response[32] = "1234567890qwertyuiopasdfghjklzxc";
        radio.write(response, 32);

        unsigned long ack = 0;
        if (radio.isAckPayloadAvailable())
        {
            radio.read(&ack, sizeof(ack));
            Serial.println("ack received: " + String(ack));
        }

        radio.startListening(); //Resets TX buffer and switches radio module's mode to "receiver"
    }
}


Why should I put a 10K resistor with an LDR?

LDRs themselves come in a considerable range of resistances. Search LDR specs and you will see what I mean. For example, from eBay I found one:

  Bright Resistance(10Lux)(KΩ):20-230

  Dark Resistance: 2 MΩ

This particular one, for example, seems to range from around 20k to 2M ohms. A reasonable series resistor would then seem to be somewhere in the middle of that range, otherwise all your readings would be skewed at one end of the scale.

For example, in this case if you used 10k and the LDR had 20 k resistance in very bright light, then the voltage would be 3.33 V

20000 / (20000 + 10000) * 5 = 3.33 V

Then if it got slightly darker and the LDR was 230 k, you would get:

230000 / (230000 + 10000) * 5 = 4.79 V

And if it was really dark you would get:

2000000 / (2000000 + 10000) * 5 = 4.98 V

You can see from those figures that you will never get a reading less than 3.33 V with this particular LDR and a 10k resistor. Thus a higher value resistor would give you a better range of readings.

However this totally depends on what resistance your particular LDR has.


Atlas Scientific pH project - serialEvent3 problems

On a typical Arduino, the delay between loop() ending and loop() running again is a few microseconds.  Serial.println() in getPh() is interrupt-driven so that call too takes only a few microseconds.  Writing two bytes with Serial3.print() at 38400 bps will take about half a millisecond.  In short, there is plenty of time for loop() to run several times before  serialEvent3() sets sensor_string_complete.

To call  getPh() once and readph() once per loop(), instead of

if (sensor_string_complete == true) readph();

say

while (!sensor_string_complete) {}
readph();

This will stall the loop while the pH sensor takes and reports a reading.

Note, in getPh() instead of using two separate Serial3.print() statements, you can just say Serial3.print("r\r").


Arduino Blink two LEDs without Delay(amount of repetitions)

For such a simple task, the code is very complex.

First, write a piece of code that blinks the LEDs if sufficient passage of time has been met.

You can implement a blink counter, either in the main loop or the blink routine mentioned earlier.

Should be fairly simple.

edit: here is how I would have implemented it.

//blink the led for a given number of times
//cnt: number of times of the blinks needed
uint8_t led_blinky(uint8_t cnt) {
    static uint8_t led_cnt=0;       //blinky count
    static uint32_t millis_prev=0;  //previous millies

    if (led_cnt>=cnt) return led_cnt;   //return blink count
    if (millis() > millis_prev + LED_ms) {    //enough time has passed
        millis_prev += LED_ms;                      //update the time
        digitalWrite(LED, (digitalRead(LED)==HIGH)?LOW:HIGH);       //flip led
        led_cnt+=1;                 //increment the led count
    }
    return led_cnt;                 //return blinky count
}

the code itself is fairly self-explanatory -> the only (marginally) tricky part is how it maintains timing accuracy over a long period of time. in this particular implementation, the test is done inside the led_blinky() routine so it is self-contained -> it does return the number of blinks that have been executed.

Here is the execution of performing 100ms blinks 4 times:


You don't "remove" the bootloader, you just ignore it.  When you program your new code with the hardware programmer of your choice it will just overwrite the bootloader code with your software's startup code.


You are comparing a byte which was read through uart with a number. If you send number '5' through uart, you won't get number 5, but character '5'. To convert single character to number, you can do following:

Luku4 = Serial.read(); // '0' .. '9'
Luku4 = Luku4 - '0'; // 0..9

But this will work only for single digit numbers, for more robust solution please refer to readString function to see how you can read strings from UART and to function atoi which converts string to number.


It looks to me like your arduino is working just fine.

In the first two images you use the arduino only to provide 5v power to the circuit on the breadboard. In the first image you haven't connected your button to properly function as a button. I don't know the exact pin layout of the button (which should be explained in a datasheet of that button), but it is also good to know exactly how to holes in a breadboard are connected. This picture shows why your button works on your second image but not your first:

This picture also shows how the breadboard holes are connected:

In your third image you have practically connected input pin 13 to GND, so it makes sense that digitalRead(13) in your code always returns LOW. Thus, the variable var is always LOW (or 0). Thus, the comparison (var == HIGH) is FALSE, which won't send "OKAY" to the serial monitor. And, the comparison (var == LOW) is TRUE, which will* send "OKAY" to the serial monitor.

I hope you can follow the logical steps and it is clear to you what is happening.


5V pin out, 8 pins and micropython/circuitpython support: does such a board exist?

Both your "requirements" for the board are non-requirements.

You do not need PWM pins to drive Neopixel strips. The Neopixel uses its own custom protocol that has nothing at all to do with PWM.
Your board only communicates with the first Neopixel. That one then communicates with the second, which then communicates with the third, etc. The length of the strip is completely irrelevant to what voltage you might want to drive it with.

You only care about having enough general IO pins and if the IO voltage is suitable to communicate with one Neopixel.
According to the WS2812B datasheet VIH is 0.7Vdd, which if you are powering the strips from 5V means 0.7 * 5 = 3.5V. However I think that is an overestimation and they are erring on the side of caution there, since I regularly drive WS2812B strips from a 3.3V microcontroller with no problems whatsoever (after all it's only 0.2V difference).
So just use your favourite 3.3V microcontroller that can run micropython and, if you really want to, drop the power supply voltage to the strips a fraction with a diode.


Circumventing overflow error by pushing data into computer?

One of the "features" of most microcontrollers/microprocessors is that they don't have a whole heap of RAM - this keeps costs down, and lets the manufacturers keep everything on one chip (unlike your PC).

However to "push" data to somewhere that can process it, you need to have a fast communications channel. SPI is quite fast, but you don't generally talk to PCs using SPI. Serial communication is slower, but if it gets converted into a USB interface (such as on a Uno) you can get respectable speeds talking to a PC. Something like 115200 baud is usually reliable, which lets you transmit 11520 bytes per second.

However it depends on what you want to send (ie. how many bytes), how you are going to indicate where one piece of data ends and the next one starts, maybe allow for error detection or correction, and so on.

Say, for example, it takes 5 bytes to send one piece of data (eg. 4 digits plus a delimiter). Now you are down to 11520/5 = 2304 pieces of data per second.

This may or may not be adequate for whatever-it-is you are trying to do.


Reading from EEPROM and writing to addressable LED with limited connections

My working details, per-request
Setup
So, the setup is the same as you what you have in its essentials:

The code is your code with the near-1 kHz tweak.  That said, I believe I also tested it at the default rate and that worked as well.  In any case, the images that show the LED changing were taken while that 1 kHz adjustment was made.

The UNO and Nano are functionally identical for this.  They use different serial transceivers which has nothing to do with anything.   The Nano will typically have a lower "5V" than the UNO when USB powered owing to the Nano using a diode where the UNO has a FET.  Which is unlikely to matter either.  They're otherwise the same device so far as the setup goes.

The 24LC02B uses the same pinout and I2C address and command-sequences as your AT24C16.  It is a smaller memory, not that it makes a difference; we're reading from address 0.  I did not find I necessary to add external pull-up resistors and it worked, so it seemed unnecessary to add them to demonstrate that it can work since adding them should only improve it's chances for working correctly.

The LEDs are the Adafruit ADA1643 12 Neopixel Ring. We're both using the first LED of a string, doesn't really matter how long the are.   We're only lighting one "pixel" so I just powered it from USB.  Have no idea what you're doing there.  But for one LED lit, I doubt a difference there would matter much.

You'll see a resistor connecting SDA at the EEPROM to IN on the addressable LED(s).  I put that there in case by some chance the EEPROM could drive SDA low while the addressable LED code was driving the LED data line high. while.  I doubt that can happen, but it was a small thing to do.  For what it's worth, I did run it briefly without it in series, and it also worked fine that way as well.  I'm only telling you this so you have all the information and not because I think it matters; I don't.

Running
It prints out 72.  This is the first value in my EEPROM. The 'H' of "Hello world" basically.  And then it goes on to cycle the first addressable LED of the set through all of the colors.
Configuration Pictures


Does an Arduino get worn out by too much command execution?

No, the code doesn't "wear out" the MCU. In general no matter what you are doing roughly the same level of activity is being performed. Even delay() does lots of work while it's "idling".

There are commands to make the CPU do less - place it in an IDLE or SLEEP mode - but these are used to save power rather than to reduce "wear" on the MCU.

Of course there are specific things that do have a limited lifetime and you can only use them a limited amount of times - things like writing to EEPROM and writing to the Flash memory - so you don't want to be doing those all the time. Other than that, no, no matter what you are doing it doesn't wear the MCU out.


The playTrack function used in MP3ButtonPlayer2 example plays file with name created with printf format "track%03d.mp3". %03d creates a number prefixed with zeros to lenght 3. For example track005.mp3 or track042.mp3 or track999.mp3.

implementation of the playTrack function:

uint8_t SFEMP3Shield::playTrack(uint8_t trackNo){

  //a storage place for track names
  char trackName[] = "track001.mp3";
  uint8_t trackNumber = 1;

  //tack the number onto the rest of the filename
  sprintf(trackName, "track%03d.mp3", trackNo);

  //play the file
  return playMP3(trackName);
}

change it to:

uint8_t SFEMP3Shield::playTrack(uint8_t trackNo){

  //a storage place for track names
  char trackName[13];
  int trackNumber = trackNo;

  //tack the number onto the rest of the filename
  sprintf(trackName, "track%03d.mp3", trackNumber);

  //play the file
  return playMP3(trackName);
}


I think the wire itself is perfectly normal. It looks like he's simply soldered right-angled header pins onto the ends. That way, the wires can lie flat on the breadboard instead of being bent over for connections, meaning the whole thing is lower-profile and a little easier to route neatly.

It also has the advantage that they will probably survive far more insertions/removals. With that said, it brings the disadvantage that it exposes the contacts more above the surface of the board, which could increase the risk of accidental connections (short circuits and such like).


Based on my experience with Xbee, I would say the limit is 50ms as Xbee can do the lowest sampling rate of 50ms.


Unable to access SD Card when using GPS and MS5611 sensors

I suspect that your problem lies with how your SD card is connecting via the SPI bus.

The problem is that a lot of Serial Peripheral Interface (SPI) devices, particularly the cheaper ones, don't properly put the MISO pin into high-impedance when SS is pulled high.

I had almost exactly this situation with one of my projects. I eventually resolved it by placing a tri-state buffer in the MISO line for each of the SPI devices.

I used a 74HC125 (4-channel tri-state buffer).

This is the page on Better SPI Bus Design in 3 steps that finally got me on the right track. I think the explanations are reasonably clear (at least compared with many other sites I found!).


Is there a way to test whether the UART Tx buffer is empty without waiting?

It doesn't look like that function is implemented. The source for HardwareSerial.{cpp,h} are in /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino under OS-X. (Someone better versed in Window than I may have to chime in here to point you to that source location.)

Taking HardwareSerial::available() as a model, create a new function, say, HardwareSerial::txremaining(), that does the same thing, but for the transmit buffer.

Left as an exercise for the student:Make a common function that returns the contents of an arbitrary ring-buffer and use it in both ::available() and ::txremaining().


Can I design Arduino Mega 2560 circuit without adding ATMega 16?

Yes, you can omit the ATmega16U2 and its accompanying parts. That is, the whole right block of schematic in this sheet.

The resulting board will work perfectly fine, it will simply no longer have a built-in programming interface, nor a built-in USB-serial interface. You will likely want to buy an FTDI cable and an AVR programmer, if you do not already have these.


How do I make my Arduino do a specific action when the computer is locked/unlocked?

Read a value through serial (what exactly is entirely up to you) to do the same job the button does now.
Use Serial.read() to get that data, and Serial.available() to know if there is any data to read.
How you generate that value on the PC to send through serial we cannot help you with, as that is outside the scope of this site.


You do some strange things that I, at least, don't understand (e.g. I don't see what you need posretry for), but you might have a reason for doing so.
But you don't reset posretry and pos, which means they will very soon be out of a reasonable range. At some point the int will actually overflow to negative values, which is definitely not going to work!

To make it less complicate, you should write a function that prints the char array shifted by a desired value as a beginning.

The below code is completely untested as I don't have your hardware and I'm aware that it does not include all your desired features. But it should give you an idea of how scrolling can be implemented in principle and it's up to you to improve/fix it.

#define LCD_SIZE 16
#define STR_LEN 12
char str_to_print[STR_LEN]={'T', 'r', 'u', 'e', 't', 'z', 's', 'c', 'h', 'l', 'e', 'r'};

void print_scrolled (uint8_t scrolled_by) {
  for (uint8_t i=0;i<LCD_SIZE;i++) {
    lcd.set_cursor(i,0);
    if (scrolled_by>=LCD_SIZE) scrolled_by=0;

    if (scrolled_by<STR_SIZE) lcd.print(str_to_print[scrolled_by]);
    else lcd.print(' ');
    scrolled_by++;
  }
}

You could call it like this:

for (uint8_t i=0;i<STR_LEN;i++) {
  print_scrolled(i);
  delay(500);
}

Once you are familiar with my approach you should be able to enhance it with additional features (end of text coming in from the other side, spaces between end and beginning, etc).


Is the SIM800L 3G? Or is it able to connect to 3G?

Is the sim800L 3g? Or is the sim800L able to connect to 3g?

No, GSM and GPRS only. A SIM card is not specifically 3G. That depends on the network providers usage of SIM cards. Most providers will allow handover between 3G and GSM cells thus allowing GSM usage. The network provider may also allow roaming and handover to another networks for better coverage.

Check if your network provider has restrictions on the GSM/GPRS internet connection for the SIM.

Cheers!


It's better with resistor so output driver isn't stressed to its maximum limits. Gate has its capacitance so it's better to limit charge/discharge current for such weak source
As the gate is basically capacitor, it has really big input impedance. Without pull down resistor it'll be catching all kinds of EMI (electro-magnetic interferences). So 10k is fine. The 100k might be less unreliable if the mcu output is not active (boot/reset)


Would a 100KΩ resistor connected to ground pull an open analog line down to 0

With a 100 kΩ resistor to GND, it is not guaranteed that the value will be zero. If a (servo)motor is connected, it might get some noise.

The pull down resistor can be any value, because it is possible to calculate the value of the photoresistor.

There is an alternative solution. I think that all the analog pins of the Arduino Mega 2560 are digital pins as well. You can do a pinMode(A0,INPUT_PULLUP); to pull the input high. When a photoresistor is connected, you can turn the internal pullup resistor off with pinMode(A0,INPUT);.


help adapting a sketch to use a 16x2 lcd

OK, I have it working OK, by adding code from a battery monitor. I kinda just stabbed at it till it stuck, changing "oled" to "LCD" and a few other things.  Sorry i can't be more descriptive..... I'm not sure why it worked but eventually it stopped chucking errors at me .
This is the working code:
#include <LiquidCrystal_I2C.h>

int TankValue0;
int TankValue1;

LiquidCrystal_I2C lcd(0x27, 16, 2);   // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup() {
  lcd.init();                          // initialize the lcd
  lcd.init();
  lcd.backlight();
  lcd.setCursor(1, 0);
  lcd.clear();
  lcd.print("WORD");
  lcd.setCursor(0, 1);
  lcd.print("TO");
  delay(1500);
  lcd.clear();
  lcd.print("YO ");
  lcd.setCursor(0, 1);
  lcd.print("MOMMA");
  delay(2000);
  lcd.clear();
  pinMode(A0, INPUT);
  Serial.begin(9600);               // starting the Serial Monitor
}

void loop() {
  int sensorTankValue0 = analogRead(A0);
  int sensorTankValue1 = analogRead(A1);
  TankValue0 = map(sensorTankValue0, 210, 695, 0, 100);// i just changed the first 2 set of values till it was right for full and empty
  TankValue1 = map(sensorTankValue1, 210, 695, 0, 100);
  if (TankValue0 < 0) {
    TankValue0 = 0;
  }
  if (TankValue1 < 0) {
    TankValue1 = 0;
  }
  if (TankValue0 > 100) {
    TankValue0 = 100;
  }
  if (TankValue1 > 100) {
    TankValue1 = 100;
  }
  lcd.print("Water Level is :");
  lcd.setCursor(0, 1);
  delay(100);
  lcd.print("WATER TANK = ");
  lcd.print(TankValue0);
  lcd.print("%");
  lcd.setCursor(0, 0);

  delay(10000);
  lcd.clear();
}


There's two ways you could algorithmically do what you want, both with different results.

The first is with a sinewave:

for (int i = 0; i < 360; i++) {
    analogWrite(5, (sin(i * 0.0174533) + 1) * 127));
    delay(3);
}

Basically you work your way 360 degrees around a circle and take one axis (e.g., the vertical one), offset it so that the values are all positive (sin gives a value between -1 and +1), then multiply it to fit the full brightness.

This is the smoothest way of fading an LED, but it doesn't respect the different sensitivities your eye has to the different brightnesses (you see more brightness variation when it's dim compared to when it's bright).

The other method is much cruder but does respect those differences in sensitivities. This specific method only gives you 8 brightnesses as opposed to 256, but they are on a log2 curve:

for (int i = 0; i < 9; i++) {
    int v = (1 << i) - 1;
    analogWrite(5, v);
    delay(100);
}
for (int i = 7; i > 0; i--) {
    int v = (1 << i) - 1;
    analogWrite(5, v);
    delay(100);
}

The theory of this one is it uses bit-shifting to gradually fill a byte with 1 from the least significant bit upwards.

When i is 0, this formula:

int v = (i << i) - 1;

gives:

1 << 0 == 0b00000001
0b00000001 - 1 = 0b00000000

If i is 4, you get:

1 << 4 == 0b00010000
0b00010000 - 1 = 0b00001111

So you effectively end up with a set of values:

0: 0
1: 1
2: 3
3: 7
4: 15
5: 31
6: 63
7: 127
8: 255


Contrarily to other answers, I'd rather stay away from String for the following reasons:

dynamic memory usage (that may quickly lead to heap fragmentation and memory exhaustion)
quite slow due to construction/destruction/assignment operators

In an embedded environment like Arduino (even for a Mega that has more SRAM), I'd rather use standard C functions:

strchr(): search for a character in a C string (i.e. char *)
strtok(): splits a C string into substrings, based on a separator character
atoi(): converts a C string to an int

That would lead to the following code sample:

// Calculate based on max input size expected for one command
#define INPUT_SIZE 30
...

// Get next command from Serial (add 1 for final 0)
char input[INPUT_SIZE + 1];
byte size = Serial.readBytes(input, INPUT_SIZE);
// Add the final 0 to end the C string
input[size] = 0;

// Read each command pair
char* command = strtok(input, "&");
while (command != 0)
{
    // Split the command in two values
    char* separator = strchr(command, ':');
    if (separator != 0)
    {
        // Actually split the string in 2: replace ':' with 0
        *separator = 0;
        int servoId = atoi(command);
        ++separator;
        int position = atoi(separator);

        // Do something with servoId and position
    }
    // Find the next command in input string
    command = strtok(0, "&");
}

The advantage here is that no dynamic memory allocation takes place; you can even declare input as a local variable inside a function that would read the commands and execute them; once the function is returned the size occupied by input (in the stack) is recovered.


Unable to make a really basic sketch work

#define button_pin 2  //defining button pin as pin 2
bool button_state = 0; //button state is either 0/1 so using bool
void Button();
void setup()
{
    Serial.begin(9600);
    pinMode(button_pin, INPUT_PULLUP); //Setting input as input pullup
}

void loop()
{
    Button();
}

void Button()
{

    button_state = digitalRead(button_pin); //Read button state
    if (button_state == LOW)
    {
        Serial.println(button_state); //print button state when it is low
    }
}

In your code, you have used = operator in place of == in the if loop. Just if you change it, it will start working also you can use my above code it is same as yours just I have made some minor changes such as using bool in place of int and use of #define in place of pin declaration where you used int


Arduino Due - wireless programming via Xbee

Theoretically, it is possible I have not tried to do it on an Arduino but I did work something similar with a pic controller. Usually, when we program the board with the firmware file we break the firmware file and send it as multiple packets over the serial com port to be written to on a certain flash memory location on the controller.
In your case, you can try an experiment by using 2 XBee modules that are connected together with the appropriate channel and network ID settings wirelessly. connect one XBee to your computer using a serial to USB cable. On the Arduino side, you have to connect to power it and use the second XBee to connect to it on the UART port. This way the XBee acts as a simple wireless data transfer channel to send and receive data wirelessly (if I am right this should be achievable in the transparent mode on XBee).
One thing to note is to check the Arduino schematic to see how exactly the data over USB is sent to the controller. If it is on UART then this should work straightforward if not then you may have to figure out something else for it.


You are lacking a space:

client.println((String)"GET /msg.php?action=send&ID=2&message=" += currentMessage += "HTTP/1.1");
                                                                                ^

Your HTTP is running in to the content of your message ending up with a corrupt request. Also you are doing appending within your strings (+=) when you don't need to (+ is all that is needed). In fact, you don't even need that - just do multiple prints and reduce the hammering your heap is getting. Oh, and don't forget to use F():

client.print(F("GET /msg.php?action=send&ID=2&message="));
client.print(currentMessage);
client.println(F(" HTTP/1.1"));


How to detect the pulse width from microphone as Input?

You will need some sort of interface circuit between your mic and your
Arduino. Best would probably be to have some kind of external peak
detection. This way the Arduino reads instantaneous wave amplitude. The
other option is to only shift and scale the signal so that it fits the
Arduino ADC, acquire the signal at a high enough sampling rate, and
compute the instantaneous amplitude in software.

I suggest you take a look at this sound-meter program. You could use
it as a basis for your own processing.

Then you just have to define a threshold and time how long the amplitude
remains above that threshold.


Unless there are exceptional circumstances you can just connect the two ground connections together. Then the 5V of your other circuit will be the same voltage as the 5V of the Arduino and you can just connect your signal direct to an input.

However, if there are exceptional circumstances (ground isn't really ground, for example) then you can use an opto-coupler to act like an optically-controlled button:

simulate this circuit – Schematic created using CircuitLab

R1 can be replaced by the internal pullup resistor of the Arduino by setting the pinMode to INPUT_PULLUP.

Note that this inverts the logic of the input: a HIGH input signal is detected on the Arduino as a LOW logic level, and vice versa.


Using XBee and OLED screens with Timer Interrupts

I suspect send() is blocking.

XBee::send() calls _serial->flush() (see code). Serial.write() buffers data to be written, sets transmitting = true, clears TXC0 and enables the USART data register empty (DRE) interrupt. Bytes will be sent out when the DRE interrupt triggers. However, since you are currently in interrupt context, this will not happen until your ISR returns. flush() spins until TXC0 is set, but since the DRE interrupt never triggers, it spins infinitely. I am basing this on this code.


Just slapping a random capacitor across your supply is not going to work. It's far more complex than that.

Yes, a capacitor is used to store a charge, but you have to manage that charge properly or you won't get much of a chance to do anything with it.

You need to:

Ensure that the discharge voltage remains high enough to run the chip for long enough to save your data (Note: writing to EEPROM causes an increase in current)
Isolate the capacitor from the rest of the circuit so it only powers the main chip
Monitor the incoming power to know when to do the saving.

A block-diagram of your setup may look something like this:

simulate this circuit – Schematic created using CircuitLab

In that diagram R1 and R2 form a voltage divider so you can monitor the battery voltage. C1 is a big capacitor. We're talking super-cap teritory here. Rated at 9V minimum. The regulator on the Arduino is ignored. You don't want to use it.  Two external regulators are now used to power your project - one direct from the battery to run the breadboard and other external components (which will lose power immediately the battery power is removed) and the other to run the main MCU and nothing else.  The second regulator is isolated from the rest of the circuit by D1, and the capacitor's charge then can only go through that regulator to power the main MCU.

That regulator for the MCU should be a switching regulator (DC-DC, "buck" regulator).  If you use a linear ("LDO") regulator you will waste power and your capacitor will have to be two or three times bigger than otherwise.  Even better would be to have a "buck-boost" regulator that will boost the voltage up to 5V when the input voltage drops below 5V, thus giving you even more life from the capacitor.

An alternative to all this is to use the 47C16 chip (5V) or 47L16 chip (3.3V) to store your data. This is an "EERAM" chip - an EEPROM with RAM buffer and automatic saving to EEPROM at power failure. It works through I2C and needs a capacitor connected to it directly to provide the backup power while it stores the data to EEPROM.


If your target is a USB audio device - like a USB headset or USB speakers (NOT an MP3 player with USB interface) then you could connect it to something which can act as a USB host with USB audio device drivers.  That means not an Arduino, but something much more powerful like a Raspberry Pi or BeagleBone Black for instance.

If your target is basically an MP3 player that allows you to connect a USB stick with songs on it then you're completely out of luck.  There's this small thing called time that gets in your way.  You can't stream data to something that expects the data to already be there. You can't seek in a file that doesn't exist until the moment you try to read from it. Also you have to act as if you were a USB memory stick, and that's not easy, and certainly not something an Arduino can do. Even things like the Pi would have a lot of difficulty in managing that since they are hosts, not devices, as far as USB is concerned.

The key word here is stream.  Your target as to be able to receive a stream of data rather than request blocks of data from a file.  USB audio devices can do that, but USB audio hosts cannot.


Usually strips have not individual LEDs, but are composed of a lot of "pieces" in parallel, and each piece is composed by three leds in series along with a resistor.

Usually the strips are composed by 60 leds/m (i.e. pieces of 5cm), but sometimes also 120 leds/m or 30 leds/m. Let's assume it is the 60 leds/m version (you can check the length of the piece you can cut - which should be 5 cm - and that it contains 3 leds).

This means that in 5m there are 100 pieces. Now, usually the 3528 leds absorb 20mA of current for each segment (the 5050 version should be rated at 60). This means that the whole led strip should absorb 2A @ 12V.

Now the power supply. 2A is the nominal current the whole strips should absorb. Add about 200mA for the nano, and increase a bit the current requirement not to stress the power supply: you get a 12V 3A power supply at least (note that, while 12V should remain the same, you can take any current greater than this value - if for instance you have a 12V 5A power supply it is perfectly fine).

Now, the nano. It surely can't handle the 2A current. This means that you can power the arduino nano from the 12V. BUT beware: you should connect the 12V power to the VIN input (so the onboard regulator lowers it to 5V). Then you can't power the LEDs directly from the nano, but you need a transistor to decouple them. You can take any nMOS with a drain current greater than 3A or an NPN with collector current >3A and build the appropriate curcuit to drive them, then connect the + terminal of the strip to the +12V wire, the transistor source (or emitter) to the ground wire and the gate (base) should be driven by the nano.


5v to 4.3v Regulator - For SIM800 module

I planned to use 3.7v LIPO battery

That's what your SIM800 module is intended to be directly powered by, without any intervening boost or buck converter.

Behind all the misdirection of a title that doesn't describe what you are actually trying to do, your question is an exercise in going around in a circle right back to where you started.  Don't try to convert energy from the lithium cell to some other voltage and then from there to the allowed input range of the SIM800 (which is very intentionally that of a single lithium cell), rather use the parts as they were intended to be used.

  i guess it has current 800mA..

No, it has a capacity of 800 milliamp hours, not 800 milliamps.

A phone or RC model type lithium cell you would find today would have a "C" rating of 10 or better, but even if we assumed one of only 5, that would predict that your cell should be expected to be able to support pulse loads of 5 times the one-hour draw rate, which would be .8 * 5 = 4 amps.


Attiny13 project with leds and electret microphone

want to use 1 electret microphone instead of the buttons.

In what way do you want to use the microphone? You do realise, don't you, that an Arduino can't understand speech (or much of anything really) without powerful extra hardware? A microphone by itself is pretty much useless, especially without any form of preamp and signal conditioning.

  i only want to know if it is possible to make the project with the attiny13a chip without the requirement of any additional parts.

No, it's not possible. You will require lots more parts. You can't just take an arbitrary chip and connect it to a battery and expect it to work properly. You need to consider correct supply voltages (voltage regulation or boosting depending on your power source), decoupling capacitors, drive circuitry, amplification, signal processing, etc...

  i wanted to use these leds instead of the lilypad led's, so i want to know if i can do the model in exactly the same way without using any mofsets etc

Again, no.  Those are 12V LED strips. You need both a 12V supply (and the associated regulation down to 5V to power the ATTiny etc) and MOSFETs (or something similar) to allow the ATTiny to switch that 12V to the LED strips as needed.


Arduino due - SAM-BA bootloader is it there even if you replace the original chip

Yes, for the Due, but No, for a Zero or Adafruit Feather M0.

The Due uses the Atmel SAM3X8E featuring:

  16 Kbytes ROM with embedded bootloader routines

As a ROM the contents are fixed during manufacture, so would be there in a new chip.

However it is worth noting that many SAM devices including this one have the NVM bits that are much like the fuse bits on an ATmega.  Here GPNVM bit 1 defaults to 0, enabling the bootloader, but if set to 1 the bootloader will be skipped.   Hence it may well be possible to get one into a state where the bootloader is not available.  They also have an "erase" pin which if driven high during startup will restore the default state (bootloader invoked) of this NVM bit (and erase whatever you put in flash).

In contrast, the Arduino Zero and the Adafruit Feather M0 also use Atmel "SAM" chips with "SAM-BA", however, they use the SAMD21, where the situation is a bit different:

  Unlike
  existing SAM products, ROM monitor is not available in SAM D21 and SAM-BA will
  be loaded in Flash memory.

  SAM-BA bootloader is not factory programmed on SAM D21 devices and has to be programmed using an
  external programmer.

Incidentally, congratulations on being willing to step beyond the ATmega DIP packages - more people need to learn that surface mounts part (or at least the TSSOP and LQFP varieties) are something that can be worked with by hand.  If you do not have hot air tools, make sure to only solder one corner, check alignment, solder the opposite and recheck, etc.  But hot air will save you so many headaches and a solder station with it is now in the $60-70 range.

Finally, while you do have the bootloader available in the SAM, to really take advantage of all of its capabilities you will want to get an SWD interface - in addition to programming without reliance on the bootloader, this exposes things like breakpoint debugging, which while almost never "necessary" can still be quite convenient and useful.   Atmel used to offer a great deal on the PCB of the SAM-ICE pod less cables kit and housing, unfortunately there was a massive price increase after the Microchip acquisition.

SWD programming is effectively vendor-unique software operations performed on top of a standard signalling scheme, so you do have options for programmers from other sources - you can make a functional if quite slow CMSIS-DAP from an MBED board (or apparently an Arduino Pro Micro) that will work for debugging but be slow at flashing, you can probably use a Raspberry pi, or the more advanced FTDI devices with the MPSSE engine such as FT232H/FT2232H/FT4232H (but not the everyday FT232RL).  With alternate programmers you will probably need to use something like openocd for the host software - Atmel Studio likely only supports their own and perhaps a few pricey alternatives.


arduino PWM temperature inexpected results

As Gerben said in a comment, you should add the value of Input to the serial print, to facilitate problem diagnosis.  As your question stands, one can only speculate about what the problem might be.  My speculation is that the system is unable to cope with parameters (Kp, Ki, Kd) = (0, 20, 20), ie, that it's unstable and unresponsive without proportional control.


SeeedDuino/Grove and the story of not being able to upload programs

OK mystery solved!

I ended up getting Visual Micro Debugger plug-in for my Visual Studio 2013 since I am native .NET programmer. I could see that the code was indeed loaded onto the board and when I pressed the button it was indeed getting to the line of code for setting the digital LED to HIGH.

It was a very unfortunate case of trying different components and learning I actually had 3 dead LEDs and one bad cable. After getting functioning ones it's all good. :) unlucky me just had 4 bad parts in my kit.

Output from Visual Studio Debugging:

Legend:
line 12 = button state check
line 16 = button pressed turn on LED
line 20 = button not pressed turn off LED

=================OUTPUT====================
14:01:04.372 SeeedDuinoPlayground.ino, line 12  loop()
14:01:04.372 SeeedDuinoPlayground.ino, line 16  loop()
14:01:04.481 SeeedDuinoPlayground.ino, line 10
14:01:04.481 SeeedDuinoPlayground.ino, line 12  loop()
14:01:04.592 SeeedDuinoPlayground.ino, line 16  loop()
14:01:04.592 SeeedDuinoPlayground.ino, line 10
14:01:04.696 SeeedDuinoPlayground.ino, line 12  loop()
14:01:04.697 SeeedDuinoPlayground.ino, line 20  loop()
14:01:04.804 SeeedDuinoPlayground.ino, line 10
14:01:04.804 SeeedDuinoPlayground.ino, line 12  loop()
14:01:04.912 SeeedDuinoPlayground.ino, line 20  loop()


In Genuino 5V pin is a DC regulated pin. That means when you supply Power (9 to 12 V) to Vin or through the DC Jack, a 5V voltage regulator regulates to give constant output at 5 V. The purpose of that pin is to provide 5V output for other use- as a power supply to some sensor you are interfacing or anything.

However, you can power up the Genuino 101 via the 5V pin. But that is not advisable because in that case it will bypass the regulator present in the board and can damage the circuit if improperly regulated.


Arduino/ESP8266 to put PC to sleep and wake it up

The hardware interface would be the easiest like others were saying.
Here is a project someone else shared that does that.

https://www.hackster.io/zvonko-bockaj/wemos-esp8266-remote-pc-switch-062c7a

The wake-on-lan part is easy and here is some code for that.

https://github.com/koen-github/WakeOnLan-ESP8266

I'm also interested in sending some kind of RPC call to a system (linux/windows/mac) via wifi to initiate a shutdown.  If I find a solution I will post it here.

UPDATE: I found a Sleep-On-Lan project that should work.  You can use the same code above for the ESP8266 but just reverse the MAC Address of the system you want to shutdown.

https://github.com/SR-G/sleep-on-lan

You will need to run this as a service on the system you intend to put to sleep.  There is a windows and linux version.  They didn't mention mac but I bet it will compile and run on a mac too.  :)

I hope this helps.  I will probably use this myself in the future.


There are two things you need to measure the battery of the system that is doing the measuring of the battery:

An analog-to-digital converter
Some form of fixed voltage reference to compare the battery voltage against.

Some ESP8266 modules have a single analog input available, and some don't. You need to check which module you have and which pins are available on it.

Then you need to use the ADC to measure the fixed known voltage. That could be from a small LDO voltage regulator that is below the voltage of the minimum voltage you will care about from your battery, or something like the forward voltage drop of a silicon diode (~0.7V) - something where you know what the voltage is.

From that reading you can then back-track what the supply voltage must be in order to give you the reading it has given you.  As the battery voltage drops the voltage range the ADC will be measuring will be reduced, and so the fixed voltage will rise within that range giving you higher readings from the ADC.

Here is a snippet of code I use with the 1.1V internal voltage reference of the ATMega328P to calculate the supply voltage:

long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1125300L / result; // Back-calculate AVcc in mV
  return result;
}

Of course, you need to change that to use the analog input of the ESP8266 instead (probably just using analogRead()). And of course change the ADC-scaled voltage.  The formula is basically:

Vref * ADCmax / ADCreading

So if you have the 1.1V reference as above, and the ADC can read 0-1023, then it's:

1.1 * 1023 / reading

Or, pre-calculate the first half of the sum:

1125.3 / reading

To keep it as integer mathematics work in millivolts instead of volts by multiplying the reference voltage by 1000:

1125300 / reading

And that, as you can see, is what is in the function above.


I2C seems to stop working when I attach an AF motor shield

Motors draw large amounts of current, and will either cause your power supply voltage to sag if you draw more current than your power supply can support, or cause blips in the power supply that will cause you all sorts of problems.

You need to take steps to isolate the power from the motor shield from the power for the Arduino.

How are you powering the motor shield? How are you powering the Arduino?

If your power supply has enough current to support both your Arduino and your motors then you can probably solve the problem by adding an isolation capacitor between the Vin port on your Arduino and ground.

What that does is to filter out temporary variations in the input voltage that's being fed to the Arduino. Without it, the Vin voltage to the Arduino is probably dropping as your motor draws large pulses of current, and that causes the output from the voltage regulator to droop as well.

I don't know how to pick the rating of the cap. A trip to the Electrical Engineering stack exchange is probably in order.


How to read ASCII values from AT24C32 IC using Arduino? And what is serial.begin(?) in that EEPROM?

You have to know what the I2C address of your EEPROM is. Right now you have

#define EEPROM_ADDRESS 0x000

The example from the library you cite has this:

/**************************************************************************//**
 * \def EEPROM_ADDRESS
 * \brief Address of EEPROM memory on TWI bus.
 ******************************************************************************/
#define EEPROM_ADDRESS 0x50

Then, you have to create an instance of the Eeprom24C32_64 object:

static Eeprom24C32_64 eeprom(EEPROM_ADDRESS);

That sets up the object for the EEPROM on the right I2C address, so you can later use the eeprom object to read and write.


Arduino Uno R2 and Ethernet Shield R3 compatibility

The only issue that may create an incompatibility seems to be the IOREF pin next the 5V output pin which is extra on Revision 3 but not in Revision 2.

However, I just had a look at the board schematics and the shield does not use IOREF.

Pin 2 is extending IOREF

So, the shield should work correctly with the Uno Revision 2. As far as the extra pins are concerned, I would recommend not damaging them in any way. If you absolutely need to, then just try to bend them outwards very carefully.


Whatever compiler you are using (Arduino IDE?) should have a 'verbose' setting that you can activate.  This will give you a HUGE amount of output, but will also show you exactly what file is being accessed for the library in question.
When I do this, I copy/paste the entire output into Notepad++ and use its search capabilities to sort through all the chaff.
Frank


Flash a .hex to an ATtiny45 with Arduino

Googling the error gives this tutorial. Towards the bottom of the page they say

  You’ll probably get the following message, but don’t worry, the upload should have worked anyway:

  avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85

So it seems this can be ignored and the part has been programmed!


MIDI controlled analog RGB LED strip (code problem)

I suggest that you write separate test programs for MIDI input and LED control, before trying to combine them together.  That is, write a sketch to report back on Serial what MIDI data was read, and a sketch to cycle the LEDs through obvious patterns.

For example, if you read 10,20,30 as the three MIDI bytes, output "Got 10,20,30" (or similar).  If that appears to be working, then add your arithmetic and output the results of colorGroup, pColor, and sColor calculations.

Note, the comment after do{ ...} while (Serial.available() > 2); says //when at least three bytes available, which does not correctly represent what that do loop does.  When one or more bytes are available, that loop immediately reads three bytes (getting a value of -1 for any not-available byte).  To do the read only if three bytes are available, get rid of the do{ ...} while construct, and instead say if (Serial.available() > 2) { <read 3 bytes> }.

Note, use parentheses in expressions like pColor*velocityByte/127.  IIRC the C spec allows evaluation of that as either (pColor*velocityByte)/127 or as pColor*(velocityByte/127).  Since velocityByte/127 can only evaluate to 0 or 1, the result of the latter form is either pColor or 0.

Note, your code shows if (colorGroup == 1){ twice.  Change 1 to some other number in the second instance.

To cycle the LEDs through obvious patterns, you could have three different sketches, one that gradually raises and lowers the PWM level on Red, one that does the same for Green, and another for Blue.


Same output on displays with different I2C-addresses (AdaFruit library, ESP32)

Try the new constructors (old ones are deprecated):

Wire.begin(21, 23); // SDA, SCL

Adafruit_SSD1306 display1(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT);
Adafruit_SSD1306 display2(SSD1306_LCDWIDTH, SSD1306_LCDHEIGHT);

display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display2.begin(SSD1306_SWITCHCAPVCC, 0x3D);


Is volatile needed when variable is accessed from > 1 ISRs, but not shared outside ISRs?

volatile only informs the compiler's code generator that the variable may be modified by something other than the code being generated, so not to assume any copy of it remains accurate.

ISR code must be written/generated under the assumption that it has no context at entry, and preserve the CPU's context around its (ISR's) own operation. So, as with the indivisbility of non-atomic operations, volatility depends, in this case*, on whether or not interrupts are allowed to nest. If non-nesting is guaranteed, the shared variable can not change by other than this ISR during its own execution. If your ISR might someday be used in an environment where interrupts are allowed to nest, then that constraint will no longer hold.

* in this case:
I'm assuming a software-maintained variable here. If we're talking about a variable that can be updated by a hardware event, a timer register for example, all bets are off: the variable is volatile no matter what.


How to transmit string data using the rc-switch library?

The communication protocol used by this library is unreliable. Thus,
each code word is sent multiple times, 10 times by
default. One solution around this problem is to send
a “byte number” along with each byte you transmit. You would then
transmit 16-bit words, where the MSB (most significant byte) is the byte
number, and the LSB is the actual byte you want to transmit. Something
like this:

int i = 0;
for (char *p = str; *p; p++) {
    mySwitch.send((i<<8) + *p, 16);
    i++;
}

Oh, wait! That's exactly what you are already doing! So it appears that
you are already aware of this issue and you have even implemented a
solution. How come you are asking this question then?

OK, I'll assume in the following that you just forgot to tells us that
the code snippet above is not from you, and that you didn't even
understand what it is doing. And you also forgot to provide a link to
the source of that code. Please, next time read How do I ask a good
question? before asking, and provide all the relevant
information right in the question.

So now the problem is in the reading side. You have to use those byte
numbers to remove the duplicates. One (untested) solution could look
like this:

// Return a received byte, or -1 if none is available.
int receivedValue()
{
    if (!mySwitch.available())  // no byte available
        return -1;
    static uint8_t last_byte_number = 0xff;
    uint16_t code = mySwitch.getReceivedValue();
    uint8_t this_byte_number = code >> 8;
    if (last_byte_number == this_byte_number)  // this is a duplicate
        return -1;
    last_byte_number = this_byte_number;
    return code & 0xff;  // LSB is the byte to return
}

And you could use it to print the data on the serial monitor like this:

int c = receivedValue();
if (c != -1)  // if we really got a new byte
    Serial.write(c);


How does this code move the bird sprite in this sketch?

This part of your code is what changes the sprite's y-value.

y += deltaIde * moveSpeed;

When you click the "jump" button or when the bird falls the y-value is changed to reflect either an upward movement or a downward movement. When your render() method is called the bird will either be drawn higher up on the y-axis (it's flying) or lower on the y-axis (it's falling).

As for the bars, if you watch closely in the video you can see that they aren't actually randomized.

Compound Assignment Operators

+= is the "plus assign" operator. It adds whatever is on the right side to the variable on the left side. Here is a table of other compound assignment operators: https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Compound_assignment_operators

int x = 5;
x += 2; // equals 7; equivalent to x = x + 2;
x = 5;
x = x + 2; // also equals 7; equivalent to x += 2;


If you broadcast data using Wire.send(data), the slaves would receive this in there onReceive handler but as far as I can remember, the I2C slave will not respond on a Wire.requestFrom(...) broadcast from the master.

Imagine x slaves responding all at the same time to the request...


There is no need for a SPDT switch. A SPST works just as well.
If you have a SPDT switch with 3 positions (pole 1 closed, open, pole 2 closed) you can use it to activate one pin or the other, or neither.
Let's pretend your switch is an SPST. Ignore one of the poles (pole 2, say.)
Connect a digital pin to pole 1. connect the common (center) pin to ground.
Set your digital pin to INPUT_PULLUP. Now, when the pin is LOW, the switch is closed (mode A). When the pin is HIGH, the switch is open (mode B).


First of all - You can drain max 20mA via pin, when one of the pins is HIGH and the other LOW, there is 5V between them, so there should be at least 250 Ohm resistor placed there, if you do not want damage your Arduino. I sugest add, to each of the red wires, at least a 200 Ohm resistor (to be safe).

For playing melody you have to save it somewhere, probabely easiest way is in arrays, and then play it note by note at regular intervals.

something like this (but insert your notes and set the length correctly):

int num_tones=6;
int tones1[] = {100,200,400,200,100,50};
int tones2[] = {262,131,131,262,131,524};

void loop() {
  for (int i=0;i<num_tones;i++){
    analogWrite(buzzer1, tones1[i]);
    tone(buzzer2,tones2[i]);
    delay(250);
  }
}


On the DHT11 it's connected to pin 6 of the SOIC14 inside. So it's at least connected to something. But who knows what it's for.

It has a (internal) pull-up resistor to VCC of around 100kOhm on this pin.

I connected my logic analyzer to it, there is no signal, even while reading the sensor. Also connecting the arduino's signal wire to this (incorrect) pin does nothing.

Factory calibration or testing would be my guess too, but who knows.


Using Arduino to control a 12v car light system?

Yes, you can use a relay. However, you'll almost certainly need to drive the relay with a transistor because the current requirements of the relay will be too high for an Arduino pin.

Better to use a logic MOSFET N-channel transistor as an electronic switch. You connect the Arduino's output pin to the gate of the transistor. You connect the + terminal of your 12 volt source to one end of the light, and connect the other wire from the light to the drain on the MOSFET. You then connect the source pin on the MOSFET to ground, and tie the ground of your Arduino to the 12 volt negative terminal.

In this setup, the MOSFET acts as a switch. When you switch the output pin of your Arduino to HIGH, the MOSFET turns on, providing a very low resistance path to ground. Current flows from the +12 volt supply, through the light, through the MOSFET, and to ground.

When the Arduino's output pin is low, the MOSFET acts as an open switch. There's no path to ground so the light is not lit.

You can't use PWM to lower 12 volts to 6 volts without some additional circuitry. PWM rapidly pulses the output from all the way on to all the way off. If you feed a PWM pin into a transistor, it can be used to create a higher voltage and/or current pulsed signal. However, pulsed DC is not the same thing as a lower DC voltage. You'd need to feed the pulsed 12 volts through a reservoir capacitor, perhaps 2 capacitors (and possibly a choke)  in order to average out the pulses into a lower DC voltage. That simple approach would work ok for powering a 6 volt incandescent light, but would not be good enough to power a solid state component because the output would not be even enough. It would have a fair amount of ripple and high frequency noise in it.


SIM900 Shield read only sms headers without text

This is most likely a case of overrun SoftwareSerial buffer. You are reading too slowly from the modem, especially with the Serial.print()s in your code. You should look for SoftwareSerial.h in C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial if you're using Win 8 and above. Or just search your PC for it. Look for this line:

    #define _SS_MAX_RX_BUFF 64

Change 64 to 256 and save. If it solves your problem, try reducing 256 to 128 to see if it still works. The greater the size of the buffer, the lesser the amount of memory available to the rest of your program.

You could also try this, to interact with the module:

#include <SoftwareSerial.h>

SoftwareSerial SIM900(7,8);

void setup() {
  Serial.begin(19200);
  SIM900.begin(19200);
}

void loop() {
  // put your main code here, to run repeatedly:
  while (Serial.available() > 0){
    SIM900.write(Serial.read());
  }
  while (SIM900.available() > 0){
    Serial.write(SIM900.read());
  }
}

It does the same thing as your code and doesn't require adjusting buffer size, though I still recommend you make the change if you will use other sketches.


Looking for an accurate and fast updating range sensor

Inside an inkjet printer, I've found a clear plastic strip with photo-engraved (loose approximation) lines perpendicular to the length of the strip. This strip passes through an optical pair, one side illuminates, the other reads. The strip stretches the entire width of the printer and if I recall correctly, the reading module is on the print head carriage. Consider that many printers are described as 600 dots per inch, which would create a resolution on the strip of 1/600" / 0.04 mm.
Additionally, I've discovered circular plastic encoders on which the rings of black/clear alternated the segment counts with each expanding ring. That is to say, the first ring was half black, half clear. The next ring out was 1/4 black/white alternating, the one following was 8 segments, then 16, etc.
This required a reader for each ring, but provided an absolute reference rather than a relative reference as is the case with the linear strip. One could create a linear strip which would work in a similar manner. One level would be half black, half clear, the next layer would be 1/4 black/clear, etc.

The requirement for 500 mm fits into a binary 512 value, which would require 9 stripes and provide for the accuracy noted in the post.
The aspect I can't answer is the speed of the encoding, although I suspect that any design based on an optical reader could be optimized to work.
I found an article at rp-photonics.com

When light is diffracted at the traveling refractive index grating in
an acousto-optic modulator, the diffracted light experiences a shift
of optical frequency which is plus or minus the acoustic (or drive)
frequency. That effect (which can be interpreted as a Doppler shift)
is exploited in acousto-optic frequency shifters.
Drive frequencies are typically between some tens and hundreds of
megahertz, rarely more than 1 GHz. The resulting change of optical
wavelength is quite small. For larger frequency shifts, or for
realizing very small frequency shifts (e.g. only a few MHz), one may
cascade two or more devices. It is also possible to use a double pass
through a single device in order to obtain twice the frequency shift.

I think from reading that excerpt that the long strip in the inkjet printer is the traveling refractive index grating. I had not considered that a low-power laser could be substituted for a simple optical pair. Doing so would provided even better resolution.
If your project allows for a strip of sufficient length to be attached to the piston, with assurance that it won't buckle under acceleration and jam in the sensor, you'd probably make it work.
But wait, there's more. I can picture the rod on the piston alternately obscuring and uncovering a digital design, which is constantly scanned by a laser. This reduces the number of parts in close contact and possibly the moving mass.


Unable to get output on Arduino serial communication with ESP8266 and M6E RFID reader

You have not the same baud rate on both ends.
SoftwareSerial is not reliable at 115200. use 9600 baud
SoftwareSerial on esp8266 is not reliable.

remove Uno from the project and connect the reader to NodeMcu


Option 1 is by far the simplest. Just have one 5V power supply for everything.  Make sure you have enough capacitance on there to absorb the noise of the motors - maybe separate the digital side from the drive side with an inductor.

You can add a diode connected backwards between the 5V and VIN pins to bypass the regulator when reverse powered.  That is, anode to 5V and cathode to VIN.


Almost.

Fork the library to your account
Check out your fork
Edit as needed
Commit locally
Push back to your fork

Your fork is yours to do with as you wish. Github makes it easy, should you wish, to then pass those changes back up to the original repository (make a "pull request"). But you don't have to do that (and probably don't want to).

You can make a new branch if you like, but that's pointless - your fork is, in effect, a branch itself (well, it's an entire new tree really).


How to analyse audio and to affect source?

I have actually just finished a project doing exactly that. I used a frequency analyser chip called an MSGEQ7 (Available from Sparksfun), here's the datasheet.

https://www.sparkfun.com/datasheets/Components/General/MSGEQ7.pdf

These little things are really easy to use. Give me a shout if you would like any help with it such as coding or wiring.


I don't think you'll have any problems. The LED's have a data rate of 800kbps, so you can theoretically push out 110 frames per second if your Arduino does nothing but transmit data. If you keep the routine that updates the colors fairly efficient then you'll have nothing to worry about.

Note that the array storing the colors would take up 900 bytes of memory, leaving you with only 1100 bytes for everything else your program would need to store (which should be fine).