text:
How can I use a transistor to "press" a button?
I have a heater remote that I want to press the buttons of with my Arduino. I am powering both the remote and Arduino from an external 5V source so both grounds are connected.
Currently I have tried using an NPN transistor(TIP122) and it does work but is not very reliable. It probably works 80% of the time but isn't good enough for my purpose. Sometimes nothing happens and sometimes the button is pressed twice for no reason.
These are my connections.
I have the emitter connected to ground, collector connected to the button and the base connected to the Arduino with a 1k resistor. Are my connections OK?
I've also tried using a PNP transistor but pulling LOW instead of HIGH and LOW instead of HIGH.
The code is very simple, in the setup I have:
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
delay(20);
digitalWrite(4, LOW);

Therefore when I restart the Arduino it should press the button, right?
I also have IRLZ44N and IRF540N, would either of these work better?

you have to press the button longer than 1/50th of a second

I have tried altering this. I've tried everything from 20-1000ms and they have all given similar results.

Are you sure, that the button simply pulls a pin to low? That might not be the case. I have solved a similar problem once by using a NPN transistor to bridge the button, instead of pulling it low. That seem to work pretty well, though I haven't tested it thoroughly.

When I tap the ground of the remote on a pin of the button, it "presses it". While I was testing and just doing this with a jumper wire, it seemed to work almost every time.

why do you use a transistor to pull other 5 V logic pin LOW?

When given an unknown circuit to control the buttons of I find it's usually better to go for full isolation and use an optocoupler.

However certainly an N-channel FET is far better than an NPN transistor - you don't get the voltage drop from a FET that you get with a BJT.

How would I wire a MOSFET to the button. Do I connect the gate to the Arduino with a resistor, source to ground and drain to the button?

Sounds right to me, yes.

A PNP transistor has fairly high "on" resistance. It might be too much. You should try using a variable resistor and see what level of resistance triggers the switch reliably, and then try a timing circuit to see how long you have to hold that resistance before it registers. (Start at 1 second and work backwards.) A MOSFET has much lower on resistance, and you can get them that can be fully switched on from a 5V logic signal.

You've already opened the remote, so you need to check whether the button connects the remote controller chip's input pin to GND or to its own VCC or maybe something else. Should not take long with a multimeter in "beep" mode. If there are lots of buttons they could be multiplexed, so check that. A picture of the remote pcb would help. Also you need to check what the VCC is on that chip, it probably isn't running on 5V so might want to be careful to not output some 5V from the arduino in there.

A glance at the TIP22 datasheet shows that this is a Darlington pair transistor, which means that it has very high DC gain (good), but at the cost of a very high Vbe_ON (bad).  The datasheet shows that the Vbe_ON is 2.5V, which means that the voltage across the 1K is only 2.5V max, which limits the base current to around 2mA.  This is probably not enough for good saturation.  In addition, the Vce_SAT for this device is about 2.0V, which may or may not be enough to look like a good GND to the button circuit.
I think a MOSFET like the IRF540N, connected as shown here (substitute button circuit for motor) might be a better choice
YMMV

You really only need one wire and no resistors or mosfet.
I see many answers including expensive mosfets and relays to answer this question. There is a much simpler solution requiring no glue logic or interfacing circuitry. I recently had to install an off-the-shelf ultrasonic humidifier in an incubator/brooder. It is the cheap little home-use aromatherapy type diffuser. It had to be controlled by a relay to turn on and off. The catch is that the control circuit and firmware used in nearly all of these is the same, it can be turned on by a relay in the PID incubator controller but requires a single button press once power is supplied to start the ultrasonic humidifier and fan. three button presses turns the humidifier off and returns it to standby and turns off automatically when it runs out of water. using the arduino to control only the button to bring it out of standby would not lead to reliable operation. I searched for an answer but found none that I could make given I had few parts and was working on a remote farm. This is my solution.
The science behind this and how it works is that the microcontroller does not sense the press of a button, it detects a state change. You may familiarize yourself with this in the arduino tutorials for reading a button press.
Tie the arduino ground to ground in the circuit you want to control. find a 5v rail and power the arduino. no extra power required. There is usually a test pad that will be ground and 5v close to the button you want to control. if not, find the regulator for the microcontroller that you are trying to trigger by tracing the circuit and attach the power rails. I used Digital Pin 2 for the trigger signal. connect d2 to a point near the switch. Ensure there is a resistor of about 600-1000ohm in the circuit between the point and the microcontroller. This should be present on the circuit you are triggering already simply because this is how microcontrollers detect state changes without sinking or sourcing infinite current.
This code will trigger once and then go to sleep. The long delays are to allow for expected debounce code in the microcontroller and allow for boot time. put simply, it switches PD2 between high and low states in high impedance and low impedance states and basically all a switch does is switch between high impedance and low impedance states. This code should trigger pretty much any microcontroller regardless of the specific state required once and then go to sleep.
#include <avr/sleep.h>
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  pinMode(PD2, INPUT_PULLUP);
  digitalWrite(PD2, HIGH);
  delay(2000);
  pinMode(PD2, OUTPUT);
  digitalWrite(PD2, HIGH);
  digitalWrite(13, HIGH);
  delay(300);
  digitalWrite(13, LOW);
  pinMode(PD2, INPUT_PULLUP);
  digitalWrite(PD2, HIGH);
  delay(300);
  pinMode(PD2, OUTPUT);
  digitalWrite(PD2, LOW);
  digitalWrite(13, HIGH);
  delay(300);
  digitalWrite(13, LOW);
  pinMode(PD2, INPUT_PULLUP);
  digitalWrite(PD2, LOW);
  delay(500);
  sleep_enable();
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_cpu();
}

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
`.readFileCounts()` not working on DFPlayer mini module
I just played around using a MP3-TF-16P module, aka DFPlayer mini. The library and the examples I used as a basis can be found here.
My current setup contains a button (NC, normally closed), which is connected to Pin D2 and has an interrupted attached to it. The button input is debounced by using a time difference inside the ISR. The code (based on getStarted example) can be found below.
Using the button to play the next song works as expected. However, when trying to get the total number of tracks located on the SD card by calling Serial.println(player.readFileCounts()) as shown in the FullFunction example the board does neither print anything nor respond to any further commands. Even using the FullFunction example does not print anything.
Could someone please double-check this behaviour? Is this a module-related ore a library-related problem, since I am using a MP3-FT-16P module which might be a cheap clone of the original DFPlayer mini module? Does this work with other MP3-FT-16P modules out there meaning that mine is faulty?
#include "stdint.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

#define interruptPin 2
#define softSerialRx 10
#define softSerialTx 11
#define debounceDelayMillis 1000

volatile uint32_t lastInterruptTime = 0;
volatile bool interruptOccured = false;

SoftwareSerial softSerial(softSerialRx, softSerialTx);
DFRobotDFPlayerMini player;

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

  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), interruptHandler, FALLING);

  Serial.println(F("Initing player ..."));
  // `player.begin(stream)` returns true when module is initialized
  if (!player.begin(softSerial)) {
    Serial.println(F("... failed"));
    while(true) {
      // never leave this loop since initialization went wrong
    }
  }
  Serial.println(F("... ready."));

  // volume: 0 ... 30
  player.volume(30);

  // when using `player.readFileCounts()` player module does not respond to further commands
  // Serial.println(player.readFileCounts());
}

void loop() {
  // read status messages from DFPlayerMini on its software serial port when available
  if (player.available()) {
    printPlayerStatus(player.readType(), player.read());
  }

  if (interruptOccured) {
    Serial.println("Button pressed");
    player.next();
    interruptOccured = false;
  }
}

void interruptHandler() {
 uint32_t interruptTime = millis();
 if (interruptTime - lastInterruptTime > debounceDelayMillis) {
   interruptOccured = true;
 }
 lastInterruptTime = interruptTime;
}

void printPlayerStatus(uint8_t type, uint16_t value){
  switch (type) {
    case TimeOut:
      Serial.println(F("Time Out!"));
      break;
    case WrongStack:
      Serial.println(F("Stack Wrong!"));
      break;
    case DFPlayerCardInserted:
      Serial.println(F("Card Inserted!"));
      break;
    case DFPlayerCardRemoved:
      Serial.println(F("Card Removed!"));
      break;
    case DFPlayerCardOnline:
      Serial.println(F("Card Online!"));
      break;
    case DFPlayerPlayFinished:
      Serial.print(F("Number: "));
      Serial.print(value);
      Serial.println(F(" Play Finished!"));
      break;
    case DFPlayerError:
      Serial.print(F("DFPlayerError: "));
      switch (value) {
        case Busy:
          Serial.println(F("Card not found"));
          break;
        case Sleeping:
          Serial.println(F("Sleeping"));
          break;
        case SerialWrongStack:
          Serial.println(F("Get Wrong Stack"));
          break;
        case CheckSumNotMatch:
          Serial.println(F("Check Sum Not Match"));
          break;
        case FileIndexOut:
          Serial.println(F("File Index Out of Bound"));
          break;
        case FileMismatch:
          Serial.println(F("Cannot Find File"));
          break;
        case Advertise:
          Serial.println(F("In Advertise"));
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
}

These DFPlayer modules are more difficult to drive than the examples suggest. Whenever you send a command to the DFPlayer (such as player.setVolume(30)) the module will return some sort of acknowledgement or a status command.  You need to be calling the player.available() method and then player.readType() and player.read() continually in loop() to keep the SoftwareSerial buffer free before you try sending commands. So calling player.setVolume(30) and then player.readFileCounts() in setup() may be overfilling the buffer before you start clearing it and the buffer will contain unread messages that are not the expected file count reply thus confusing the library. The other thing to consider is that it takes the module a second or two to initialise the SD card after .begin() and you really need to wait for the DFPlayerCardOnline status message to come in before you can ask for file counts.
I've written a more comprehensive library to drive these but it's not mature enough to share yet.

Tried to implement your suggestions, but without any success. Do you have some similar hardware available in order to try my code with your suggestions added to it?

These worked for me:
int fileCounts = 0;

myDFPlayer.readFileCounts();
fileCounts = myDFPlayer.readFileCountsInFolder(0);

Serial.println(fileCounts);

Thank you Andre. I tried everything but this finally solved it.

OK... For those who are looking for the answer, I found it in a complicated way, reading the library file. When the begin() task is executed, within the parameters, the COM port is required, but two more parameters are also allowed: ACK and doReset. Then begin(com_player, false, true); the ACK parameter blocks the responses of the serial parse.

source: Stack Exchange

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
ArduinoJSON: Using a reference to a reference when parsing array of arrays
I started to play around with the ArduinoJson library to parse data I got from one of my APIs (the format of the JSON data I get from my API can be improved for sure, but the software I had to implement the API with is rather limited in formatting JSON strings). The data is formatted as an array of arrays like this:
[["P101","1.2345","bar(a)"],["P102","1234.567","mbar"],["P103","2345.678","mbar"],["P104","2.3456","bar(a)"]]

In order to get a first impression about how much memory is needed I used ArduinoJSON's Assistant to analyse my dataset, calculate memory requirements and get a very basic code snippet for parsing the data. Code snippet generated by the assistant is as follows:
const size_t bufferSize = 4*JSON_ARRAY_SIZE(3) + JSON_ARRAY_SIZE(4) + 90;
DynamicJsonBuffer jsonBuffer(bufferSize);

const char* json = "[[\"P101\",\"1.2345\",\"bar(a)\"],[\"P102\",\"1234.567\",\"mbar\"],[\"P103\",\"2345.678\",\"mbar\"],[\"P104\",\"2.3456\",\"bar(a)\"]]";

JsonArray& root = jsonBuffer.parseArray(json);

JsonArray& root_ = root;

JsonArray& root_0 = root_[0];
const char* root_00 = root_0[0]; // "P101"
const char* root_01 = root_0[1]; // "1.2345"
const char* root_02 = root_0[2]; // "bar(a)"

JsonArray& root_1 = root_[1];
const char* root_10 = root_1[0]; // "P102"
const char* root_11 = root_1[1]; // "1234.567"
const char* root_12 = root_1[2]; // "mbar"

JsonArray& root_2 = root_[2];
const char* root_20 = root_2[0]; // "P103"
const char* root_21 = root_2[1]; // "2345.678"
const char* root_22 = root_2[2]; // "mbar"

JsonArray& root_3 = root_[3];
const char* root_30 = root_3[0]; // "P104"
const char* root_31 = root_3[1]; // "2.3456"
const char* root_32 = root_3[2]; // "bar(a)"

I did not test this, yet but had a look at the produced snippet and stumbled upon these lines:
JsonArray& root = jsonBuffer.parseArray(json);

JsonArray& root_ = root;

What is the exact advantage of using address-references root, root_ and e.g. root_1 here? Those should, as far as I understood the code, reference to the same data at the end. Is it for better readability only?

The advantage of reference above pointers:

References cannot be NULL, so it's much safer to use them
Address of a reference cannot be acquired, this means a calling function cannot mess up anything outside the type (value) being passed.

For passing a reference to an address the same advantages applies (cannot be NULL, address cannot be changed).
Also, address arithmetic (address + xxx or address - xxx) cannot be used, which prevents tricky programming errors where values outside a variable's memory space can be changed.

It is not a reference to reference. It is a copy of the reference.
The generator must handle more difficult JSON inputs then yours and to make output readable it has a strategy, which in simple case can look as unnecessary. Yes, it could use root[n][m].


text:
Unable to receive data when using multiple SoftSerial on Arduino Nano
I am trying to use several (four) software-based serial ports to talk to different peripheral hardware. However, I am unable to receive data through the SoftSerial when using more than one software serial port.
I tested each pair of pins be defining it to the first port. All pairs are working as desired. In addition, I am only interested in bridging/piping from a software serial port to the hardware serial (for debugging reasons).
My code is as follows:
#include <stdint.h>
#include <SoftwareSerial.h>

#define SOFT_SERIAL_A_RX        5
#define SOFT_SERIAL_A_TX        6
#define SOFT_SERIAL_B_RX        7
#define SOFT_SERIAL_B_TX        8
#define SOFT_SERIAL_C_RX        9
#define SOFT_SERIAL_C_TX        10
#define SOFT_SERIAL_D_RX        11
#define SOFT_SERIAL_D_TX        12

#define SERIAL_BAUD_RATE        9600

SoftwareSerial softwareSerials[] = {
    SoftwareSerial(SOFT_SERIAL_A_RX, SOFT_SERIAL_A_TX),
    // Unable to receive data on first software serial when un-commenting following lines.
    // All pins are working when declaring each pair for first software serial (tested pins by doing this)
    // SoftwareSerial(SOFT_SERIAL_B_RX, SOFT_SERIAL_B_TX),
    // SoftwareSerial(SOFT_SERIAL_C_RX, SOFT_SERIAL_C_TX),
    // SoftwareSerial(SOFT_SERIAL_D_RX, SOFT_SERIAL_D_TX)
};
const uint8_t numberSoftwareSerials = sizeof(softwareSerials)/sizeof(*softwareSerials);

void initHardwareSerial()
{
  Serial.begin(SERIAL_BAUD_RATE);
}

void initSoftwareSerials()
{
    for(uint8_t i=0; i<numberSoftwareSerials; i++) {
        softwareSerials[i].begin(SERIAL_BAUD_RATE);
    }
}

void setup()
{
    initHardwareSerial();
    initSoftwareSerials();
}

void loop()
{
  // Only one software serial can be used (receive/transmit) at once.
  // So just using a single software serial port (first element from array)
  if (softwareSerials[0].available()) {
    Serial.write(softwareSerials[0].read());
  }
  if (Serial.available()) {
    softwareSerials[0].write(Serial.read());
  }

}

How can I narrow down the issue of being unable to receive when defining several serial ports? If there is no suitable solution I might switch to an Arduino Mega with its four hardware ports (would need only one additional software serial in that case), but an Arduino Nano is strongly preferred due to smaller footprint.

You cannot receive on more than one SoftwareSerial port. It's sad, but that's the way it is.
You can manually select which port you are listening to at any time with the softwareSerials[x].listen() function, but only one can ever listen at a time.
SoftwareSerial is a fudge at best and should only be used for one port and even then only if you really have to.

Thanks for this hint. After some more searching around the Internet in the meantime, I finally found a link to the docs where '.listen()' is used: https://www.arduino.cc/en/Tutorial/TwoPortReceive


text:
Unable to use analog pins as digital inputs
I want to use the analog pin A7 as a digital input pin. As stated in the Arduino docs the analog pins can be configured in the same way like any other digital pin.
However, when trying to configure an analog pin as a digital input pin, I get unexpected behaviour:

Using a digital pin (e.g. D2) works as expected.
When using an analog pin (e.g. A7) the LED is lit after start-up without pressing the button and does not change/react to any button press.
Since the docs state, that analog pins can be configured as digital pins and used in the same way, this behavior seems to be kind of confusing.

See my attached snippet to reproduce/examine the issue:
// using pin 2 (D2) works as expected (LED is lit on button press only)
// const int buttonPin = 2;

// using analog pin 7 (A7 / pin 21) as a digital input is not working,
// LED is lit directly after start-up & does not react to button press,
// analog pins are generally usabable as digital inputs
// see https://www.arduino.cc/en/Tutorial/Foundations/AnalogInputPins
const int buttonPin = A7;

const int ledPin = 13;

int buttonState = 0;

void setup() {
  // button is connected to GND, so enable internal pull-up resistors
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
};

void loop() {
  // as we use internal pull-up resistors, logic HIGH & LOW are inverted
  buttonState = !digitalRead(buttonPin);
  if (buttonState) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
};

A6 and A7 are special on the nano. They are the only pins that can't be used for digital.  They are only analog inputs.

Is that due to Arduino's hardware abstraction / pin mapping or related to the capabilities of the Atmega328?

It's the hardware capabilities of the ATMega328P-AU. Those pins only connect internally to the ADC MUX and don't have any digital drivers.

@albert, in fairness to the authors of the website, it is likely true at the time they wrote that statement, that analog pins could always be used as digital.  The DIP package ATMega328P, ATMega168P, and ATMega8 were used on the earlier Arduino boards.  The -AU in the part Majenko mentions refers to a surface mount version of the chip that has pins not present on the DIP version of the 328P.  You can see the lack and presence of A6 and A7 between the DIP and SMT versions of the Arduino UNO board.

const int buttonPin = A7; //is an invalid statement because A7 is not an integer.
Use a number instead:
const int buttonPin = 21; // 21 is the decimal pin number for A7.
Don't use A6 or A7 for pinMode(21, INPUT); on Nano, they don't work. You can use analogRead() (returns  0..1023) and then convert it to wanted boolean value (eg. >511 or <511 for crossing half Vref level)

A7 is a constant with value 21. https://github.com/arduino/ArduinoCore-avr/blob/24e6edd475c287cdafee0a4db2eb98927ce3cf58/variants/standard/pins_arduino.h#L63


text:
Own type definition using a struct does not name a type
I need to initialize several buttons and LEDs connected to my Arduino. To store data related to an individual button or LED, I decided to define my own data type using two different structs. One for a button and another one for a LED.
As I need to configure some GPIOs and other peripherals after instantiating each button/LED, I implemented a small factory function to get a clean interface and combine the required steps for instantiating and initialization.
Defining my own button_t type works as expected. The compiler does not throw any errors. However, I tried to implement the same approach for led_t type upon the compiler states the following error:

example:25:1: error: 'led_t' does not name a type
led_t ledFactory(uint8_t pinNumber)
^~~~~
exit status 1 'led_t' does not name a type

My example code looks like this:
#include <Arduino.h>
#include <stdint.h>

struct button_t
{
    const uint8_t pin;
    uint8_t currentState;
    uint8_t lastState;
    uint32_t lastDebounceTime;
};

button_t buttonFactory(uint8_t pinNumber)
{
    button_t btn = {pinNumber, 0, 0, 0};
    // setting some MCU registers here
    return btn;
};

struct led_t
{
    const uint8_t pin;
    const uint8_t state;
};

led_t ledFactory(uint8_t pinNumber)
{
    led_t led = {pinNumber, 0};
    // setting some MCU registers here
    return led;
};

void setup()
{
}

void loop()
{
}

This is a bug in the Arduino IDE: when converting your .ino file to a
.cpp file, it added a declaration for the function ledFactory()
before the declaration of the type led_t.
As it appears to be adding those declarations right before the first
function of your sketch, a simple workaround is to put all your type
definitions before your functions.

@albert, if your curious to see this mangling for yourself, check "compilation" for "Show verbose ... " in File/Preferences.  You should see the full compiler command-line immediately before the error message.  It will reference some /sketch/your_sketch_name.ino.cpp file.  There you see the result of the build process's manipulation of your .ino file into the .cpp file it ultimately tries to compile.  And for your code, under IDE version 1.8.13 at least, exactly what Edgar described.

First create structure and after create function and after function declaration line c++ is bottom approach.

Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.


text:
If (serial.available()) conditional statement
I am very new to Arduino and I have a question I would like to clarify on Serial.Available()
According to Arduino documentation, Available() returns the number of bytes that are stored in the buffer, ready to be read. Why then, both If function below works, when there are data in the buffer? For Scenario A, it appears to me that there is no conditional statement, how then, would the IF function evaluates to TRUE?
Scenario A: IF(Serial.Available())
compare with
Scenario B: IF(Serial.Available()>0)
Thanks in advance!

Mind the case: neither IF nor serial or Available exist.

the do the same thing; the 2nd is a pedantic long-hand way of writing it more explicitly

In C, 0 is false and anything else is true. So if Serial.available() returns 0 it is considered false. If it returns 7, 23, 44, etc it is considered true.

But it is bad programming. It should be "if(Serial.available()>0)". The Serial.available does not return a boolean, but an integer. Therefor it should be tested against an integer. Off-topic: was there something with 'bool' and 'boolean' ?

@jot Boolean doesn't actually exist. There's a typedef in C++ (and in "stdbool.h" for C) that links it to an unsigned char. 0 is false, anything not 0 is true. There is absolutely nothing "bad" about it.

In my opinion an integer should be treated as an integer. Trying to be smart and rely on the compiler to fix bad programming is not okay. I think the 'boolean' and 'bool' problem have been fixed: "bool x = (bool) 23;" sets x to 1 and the same for boolean.

Personal opinions don't count. C and C++ are what they are. If you don't like it then program in visual basic.

Ha ha, visual basic. The 'c' and 'c++' is all about writing good code, because they allow to make a big mess of the code. Call it personal if you want to, I prefer code that shows what is going on. @user35336, Majenko has explained how it works, but we disagree if it is nice programming.

if( x ){ in C/C++ reads "if x is not equal to zero". If x is numeric, that expression could be considered an idiomatic shorthand. If x represents a boolean, it reads quite naturally. Consider, f/ex, the character-class test isdigit(). Most people (in my experience) write if( isdigit(x) ){, not if( isdigit(x) != 0 ){; even though the latter states in explicit detail, what test is to be made. It comes to stylistic preference, and like discussions of which programming editor is "best", & what placement of braces or indentation is "best", rapidly devolves into a religious argument.

@JRobert Hence "personal opinions don't count". A personal opinion doesn't make something "bad", only "not the same as I think". My personal opinion is that all footballers are overpaid pansies. Does that make it true? I think so, but millions of football supporters disagree with me. Neither is right, neither is wrong, they are just opinions. And we don't like opinions on this site - hence we can close a question as "primarily opinion based". It'd be nice if we could do the same with comments ;) - but that's just an opinion :P

Thanks for taking my point and running with it! I couldn't have constructed a better example. :)

@Majenko, I take back the "bad programming" and turn it into "some use the fact that 'true' is everything but zero, as specified by the 'c' language. Others prefer to test the Serial.available against an integer to show that the function returns an integer". I think everyone is happy now.

For certain functions I agree, for others I don't. if(!strcmp(...)) reads wrong. It looks like "if the strings don't match" when in fact they do. if (strcmp(...) == 0) is better in that instance. if (Serial.available()) says"if there is some serial data available" which is fine. It's more to do with how it reads to the human eye than what type it returns.

Scenario A, it appears to me that there is no conditional statement, h

The first is a test on if available() returns a non zero value.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Why would digital outputs on Arduino Due be less than 3.3V?
We are working on a project that requires a temperature sensor to tell the Arduino Due to turn a digital pin to HIGH (3.3V) to active a relay so a heating pad can be powered on.
We have diagnosed all possibilities and the only explanation as to why the switch will not active is the digital pins are only reading 1.8 V on the relay.
We are using a JQC-3F(T73) relay. We are using two digital pins to give it plenty of voltage and amps to switch on and off when needed.
so any explanation as to why it isnt working? thanks.

It sounds like you are directly wiring the relay to the due. Bye bye due...

Also posted at http://forum.arduino.cc/index.php?topic=488837. And indeed they had the relay directly connected to the Due's pin.

volts go down as you run out of omph

The output impedance for the MCU used in the Due is about 46ohm. Along with the relay's impedance this forms a voltage divider that results in a final voltage that is lower than the unloaded voltage from the output.
In any case, do not connect an inductive load directly to a MCU; use a driver such as a ULN2803 instead, being certain to connect the flyback connection of the driver chip properly.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Arduino Mega - I2C pins (20/21) unreliable
Has anybody else noticed that the Arduino Mega pins 20/21 are exceedingly unreliable over long periods of time? It has been the case four times now where I have hooked up no more than 3 I2C devices to these pins and had them fail after approx. 10 days of light use on average.
For example, my team and I had 3 sensors hooked up and were successfully running tests for about two weeks, then right before our launch, I2C stopped working entirely, returning completely incorrect (all zero) data every time.
Again, I have had this issue four separate times in the past, some where pull-up resistors are present, others not.
I seem to be unable to find related information on the web.
Has anyone else noticed this?

If you mean a lasting failure, this may be indicative of electrical abuse.  Are you running these to off-board sensors?  I2C in its everyday form really isn't intended for that.  What sort of environment and power situation are you operating in?  And what do you mean by without pull-up resistors - those are absolutely required...

then right before our launch, I2C stopped working entirely, - have you changed absolutely nothing in that time (including code)? I find it exceedingly hard to believe that the I2C circuit "wears out".

Your question would be better by including the sensors part numbers, and your code and schematic. As it is, your question is really "some unidentified sensors, connected in a way we haven't disclosed, using code we haven't posted, fails after two weeks".

That's because it has a built-in "crisis detector" and you made the mistake of talking about your presentation where it could hear you.  ;-)

Welcome to Arduino Stack Exchange.  Please take the tour to see how to get the most out of this site:  https://arduino.stackexchange.com/Tour - you will notice that it is best to show us what you have tried (photos, code, etc.) then post a specific question about where you have a problem.  Then put your question in the title.

The I2C pins on the Arduino Mega 2560 board are 100% reliable, but you have to use them correctly.
The Wire library could halt when something is wrong with the hardware I2C bus. In that case the sketch stops. The Wire library should have timeouts programmed in case something is wrong with the hardware, but sadly it doesn't have timeouts.
Hardware
The hardware I2C bus on the Arduino Mega 2560 board is a 5V I2C bus, because the Arduino Mega 2560 has 10k pullup resistors to 5V for SDA and SCL.
The wires for I2C can only be short. Long wires will not work.
The worst thing is when SDA and SCL are in a flat ribbon cable next to each other. The crosstalk between SDA and SCL will make the I2C very unreliable.
Because it is a 5V I2C bus, you may not connect 3.3V sensors to that 5V I2C bus. In that case you need a level converter.
The total value of all pullup resistors in parallel should not be too high (more sensitive for electrical noise, longer wires are not possible) and not be too low. The I2C specificiation is maximum 3 mA pulling of down current to get the signal low.
Everything that is connected to the I2C bus must have proper power supply. If one sensor has a power supply that fails, then that sensor will probably pull down the SCL and SDA signals.
A test with a breadboard might fail, due to bad contacts of the breadboard.
Software
The Arduino Wire library is often used in a wrong way.
If one of the sensors is an Arduino board as a I2C slave, then the code for the slave must be done right, because there are many ways to do it wrong.
You could check the return value of every Wire.endTransmissions for an error, and check every return value of Wire.requestFrom for the amount of data that is received.
If you tell us everything about the sensors, the wires (with photos), the logic level converters, the sketch, and so on, then we can tell you what the problem is.


text:
15x15x15 LED cube with thermal sensors
I'm trying to wrap my head around a public art project that I've recently received funding for, and I'm hoping that someone here can help me with a bit of guidance.
The concept I'm working on is a kind of 'digital campfire' that builds and falls in intensity as people approach and depart.
The way I imagine it working is with a 15x15x15 RGB LED cube that plays fire-like animations of varying intensities in response to the presence of nearby people - detected by a 360 degree array of thermal sensors (probably something like Omron D6T sensors, rather than IR movement sensors).
Full disclosure: I'm an Arduino noob. I've tinkered with LEDs and soldering, but even the thought of building a non-responsive 4x4x4 LED cube hurts my brain. That said, I have a couple of months up my sleeve, a bit of cash, and a willingness to forge new neural pathways to get this done.
My main questions at this point are:

Can an Arduino even handle the processing power required to run a thermal activated 15x15x15 LED cube, even with multiplexing?
I'm considering 15-cubed because I want the object to have a fairly large physical presence, and have a relatively high definition. Is there any game-changing reason I should seriously consider something smaller? I anticipate being able to connect to a 240v power outlet (I'm in Australia), but running off battery would be ideal.
How difficult would it be to build a 360 degree thermal sensor array consisting of, say, 8 separate thermal sensors? The programming is clearly beyond me, and I expect to out-source this...

Any help or suggestions would be hugely appreciated. And don't be gentle – if my expectations need to be 're-aligned' to something closer to reality, I'd rather that happen sooner than later.
Cheers,
Adam

That sounds like a fun project. However... you're talking about 3375 LEDs there. That's a helluva lot of LEDs. Even with charlieplexing you'd need 59 IO pins just for the LEDs, and the wiring would be a nightmare. I'd be inclined to think about making it modular. Having it 16x16x16 would be more logical than 15x15x15 since it's a power of 2. Maybe make small modules of 2x2x16 (PCB at the bottom with 4 strings upwards) with a separate controller for each block. Get them to communicate - spread the load.

The answer to "Can an Arduino even handle the processing power" is probably No, but no one can really answer because you have not specified the problem.
Just for starters you have >3k LEDS, if you want to control RGB that means ~10k devices.
To operate at moderate brightness (10mA per LED) you will need at least a 35A power supply. This will require external high power circuitry to switch/control.
Do you need to individually control each LED? To control 10k devices you will need serious external circuitry.
Do you need to control brightness or just switch individual devices on/off?
You could probably achieve a solution, but 15 modules each controlling 15*15 LEDS may be achievable, 32 or 64 is probably more realistic.
Either way soldering by hand would be impractical, you need to design a board for each module.
You could use an Arduino on each module, but a ATMega chip would achieve the same end, without the unnecessary peripheral circuitry.

firstly we need a bit more detail, I'm assuming by saying a 15x15x15 cube you actually mean a cube with a 15x15 array of LEDs on each face, so you would have a total of 1350 LEDs. we also need to know if you intend to have just single colour LEDs of whether you want multi colour or even RGB with full control (like a monitor)
assuming you only want single colour with on/off control then look into the MAX7219 or MAX7221 IC's, these can be bought with LED matrix's already fitted, and each IC can drive an 8x8 matrix of LEDs, so you would need 4 ICs to do each side (these can be daisy chained) and so a total of 24 ICs for the whole cube.
but note that that would allow for 16x16 on each side.
the arduino can easily drive this many, what you need to consider is how often you want the LEDs to "update" i.e. the frame rate. the more you try and drive the slower you can drive it, however from experience i believe the arduino could easily drive that many LEDs in this arrangement.
on the subject of current the MAX72xx ICs work by multiplexing the output for you, so at most only 8 out of each 64 LEDs are on at any one time, so if you drive each at 10mA your maximum current would be 1.7A, probably a bit much for batteries (unless you use something big, AA's or a 9V won't cut it.) but still reasonable.
if you wanted individual brightness control things get more complicated, and the rate at which you could update the outputs would sharply drop off. I still think it would be feasibly for this many LEDs but you may find your update rate is only 10-20 times a second so any motion may not appear very smooth.
but this way will require a lot more wiring, and will be a lot more complex to program.
if you want full RGB control then the amount of connections and components required would grow to ridiculous proportions, you would need 3 connections plus power to each LED so about 4000 connections between your control circuitry and your LEDs, and your current requirements would go through the roof due to so many LEDs being on at the same time.
and if I read wrong and you actually want 3375 LEDs on each face, for a total of 20250 LEDs then this becomes extremely impractical, even with output multiplexing (mentioned above in the MAX72xx bit) the current requirements would be insane. not to mention the time taken to update all those LEDs would drastically slow down how quickly you could update them. even at a max data rate of 30MHz (SPI) you will probably only be able to update your LEDs at around 1-2 times a second, and there would not be enough RAM in the arduino to remember the previous output states when you are calculating your next ones.
a raspberry pi may be more suitable from that point of view, but the current and the update rate would still be a problem.


text:
Writing on a SdCard
I'm writing on a SD card the value of a measured voltage. I've a good sampling/writing frequency but regularly the acquisition take a lot of time (like 4000us instead of 400us). I noticed that this "pause" appears every 85 values (my values are 6 bytes long, so it appears every 510 bytes).
So I have hypothesized that there is a buffer of 512 bytes somewhere which is full and need some times to empty.
But I don't know where is this buffer. In SDcard? in Arduino? And how can I avoid this issue?
Here, my results on 1Hz sinus with a zoom on the "break":
And here my loop to read the value and write it on sd card:

Hope you can help me guys !

Possibilities:

What you can do it measure what you need inside an interrupt routine (I hope the measurement itself does not take too long). Write it to a buffer in the interrupt routine. Your 'normal' loop can do the writing to the SD card.
A possible very extensive solution would be to send the sampled data to another Arduino which can store it on an SD without affecting the sampling (since it's done on another Arduino).
Using DMA (Direct Memory Access), however afaik this option is not available for an Arduino.

That a good idea thank you, but my measure is did with an external ADC wich communicate in I2C. And I2C use interrupt so i can't communicate in another interrupt. And Sdcard communicate in SPI, so i will probably miss values too while interrupt is disable during SPI communication

True, to be honest, I don't have experience with interrupts myself, but it seemed appropriate here, but it already uses interrupts.

Other interrupts are disable during an interrupt vector, maybe i can do a software SPI and software I2C, but i'm thinking it will take a lot of devellopment to finally lost a lot of speed.

I never tried software SPI or I2C, but tried software UART/Serial for MIDI (which is slow, 31250 baud) and it didn't work at all, so I assume you will not have much luck with software solutions.
You might need to use DMA , but afaik the Arduino does not have that.

A possible very extensive solution would be to send the sampled data to another Arduino which can store it on an SD without affecting the sampling (since it's done on another Arduino).

This idea interests me a lot, i think i will try this ! Thanks !

@bouaah I added it in the answers (easier for others too)

The buffer is in the SD card library. It is the size of one block on the SD card. When it is full it needs flushing out to the SD card, which takes time. Once that is done the buffer is then empty again and can be filled back up by your code.
It has to be done this way because SD cards work in blocks of 512 bytes.

Thanks a lot, I was confused to don't know where was this buffer. I have to find a solution now to keep the best regular sampling rate.


text:
Start I2C communication at an external event
I'm working on a Arduino Uno and a ADC ADS1115. Devices communicate by I2C where Arduino is the master.
I would like to use the ADC to the maximum of his possibility.
So i configure the ADC to set a pin when a conversion finish and use this pin as an external interrupt.
But i can't read the data because I2C interrupt can't work in a external interrupt handler.
I think to use a timer to have a fixed sampling rate too, but it's the same issue.
There is my code below, and if you have any idea of how i can doing my goal let's share it ;)
#include <QueueArray.h>
#include <ADS1115_Vibratec.h>

  Adafruit_ADS1115 ads;

  QueueArray <uint16_t> fifo;

  int i=0;

void setup() {

 Wire.begin();

 Serial.begin(115200);

 ads.Config( ADS1115_REG_CONFIG_OS_NOEFFECT,
          ADS1115_REG_CONFIG_MUX_DIFF_0_1,
          ADS1115_REG_CONFIG_PGA_6_144V,
          ADS1115_REG_CONFIG_MODE_CONTIN,
          ADS1115_REG_CONFIG_DR_860SPS,
          ADS1115_REG_CONFIG_CMODE_TRAD,
          ADS1115_REG_CONFIG_CPOL_ACTVLOW,
          ADS1115_REG_CONFIG_CLAT_NONLAT,
          ADS1115_REG_CONFIG_CQUE_1CONV);

 ads.Set_ConvReady_function();

 attachInterrupt(0,interrupt,RISING); //INT0 -> pin 2, fonction interrupt,    front montant

  }

  void loop() {

   while (!fifo.isEmpty ())
   {
      Serial.write(fifo.dequeue());
      Serial.println();

   }

  }
  void interrupt()
  {
    fifo.enqueue(ads.ReadConvert());
  }

You could set a 'volatile' flag in the interrupt routine. In the loop() you can check if the flag is set. That is how the i2dev uses the interrupt for the MPU-6050. See the MPU6050_DMP6.ino example.
First thing to do is set the I2C clock to 400 kHz. Keep the wires short and pullup resistors low.
Wire.begin();
Wire.setClock(400000L);   // 400 kHz I2C clock speed

You can let the MultiSpeed I2C Scanner run for a while to see if it is stable.
The ADS1115 has also I2C High-Speed Mode up to 3.4MHz. The Arduino can not do that. The Arduino has a fast SPI mode, but the ADS1115 has no SPI bus.
Using an interrupt adds extra overhead. A fixed software timer with millis might be just as fast.
Do you want the maximum of 860 Samples per second? The Arduino Uno or Mega or Leonardo are too slow for that. Do you want to continuously read data or just a burst and store it in ram ?

Thanks for your help. I would like to continuously read data. Are you sure that Arduino is too slow for 860 sps?

The Arduino Uno is too slow. It probably can not handle all that data with the normal Arduino functions. The Arduino Leonardo or Micro is a little better, because they can transmit data via the USB at higher rates. I think you need a Due or Zero or M0. Use the Arduino Uno to run tests and develop code, you will found out soon enough what datarate it can do.


text:
FreeRTOS : Create Tasks but don't start Scheduler
I'm using FreeRTOs on Arduino for the first time. In my setup(), i would like to create my tasks but i have few more configuration to do after so i would like to create my tasks but don't start the scheduler immediately.
This is my code currently with xTaskCreate and vTaskScheduler, but my code start the task immediately when they are created :
   //Create Tasks
   s1 = xTaskCreate(TaskAcquisition, NULL, configMINIMAL_STACK_SIZE, NULL, 2, &Acquisition);
   s2 = xTaskCreate(TaskStockage,NULL,configMINIMAL_STACK_SIZE + 200, NULL, 1, &Stockage);

.... Some more config

   Serial.println(F("Config finished"));

  //Check errors
  if(fifoData==NULL || fifoSpace == NULL || s1 != pdPASS || s2 != pdPASS){
  Serial.println(F("Creation error"));
  while(1);
  }
  Serial.println(F("Fifo and Tasks created"));

  //starting
  vTaskStartScheduler();

  //if the scheduler start the code don't came here
  Serial.println(F("Ram issue"));
  while(1);

Thanks for your help !

I'm voting to close this question as off-topic because it is entirely about FreeRTOS, and not at all about the Arduino on which that is running.  You really need to seek help in a FreeRTOS forum.

You need to vTaskSuspend the tasks immediately after creating them.
Then when you need a task to run you vTaskResume it.


text:
Writing serial data on a pin on Arduino
I want to write some data (GPS) to a digital port on Arduino.  As far as I understand sending data via a pin as if it were USB is possible. But I don't know what function to use. digital.Write doesn't expect any data or strings. How do I write serial data on to a digital pin

USB is a complex protocol which is not supported by most of the simpler processors used in most of the simpler Arduino boards.  So you need to specify your exact hardware or answers to your questions will have to be generic and vague.  The USB port on an Arduino Uno is actually a separate chip from that which you run your Arduino sketches on.  What your Arduino Uno program can do is send out serial data to this separate chip.  Not USB protocol.  Also, as far as I know, the only USB protocol supported on an Arduino Uno is Serial Data over USB.  Hopefully that is what the GPS uses.

It would help if you edited your title so that people know that you are asking about connecting a Arduno to a USB Device.

You need to edit this to be clear what exact "serial" signalling scheme you need to use, and if you are able to choose the pin on which the chip can do that best, or if it has to be a particular pre-chosen and specified in the question pin even if that requirement makes the task far more difficult or impossible.

Using the arduino library "software Serial" (https://www.arduino.cc/en/Reference/SoftwareSerial) you can use any pin to write/read serial data.

The Aruduino Uno uses an ATmega328P which only has 1 hardware UART to help the software communicate serially with the outside world.  If you are already using this hardware resource (for example through the normal Arduino serial library), it is unavailable to talk to a 2nd external device.  In such a case you can emulate a UART in software using this Software Serial Library in exchange for some processor time (that is, using a software emulated serial port will slow down your program's execution).

This is likely not what the asker is trying to do - by appearances the data is GPS-like (probably NMEA or something) but they probably don't want to output it to a GPS.  Unless they mean some kind of moving map display for a GPS, but that probably won't want USB input, rather some suitable marine grade serial interface.

Again, it pays to tell which Arduino / processor you are using.  If the processor only has 1 UART you will need to use a software implemented library to talk to a 2nd device over a serial port.  If the processor has 2 UARTs, then the serial communications will be more robust.  But you will have to figure out if the Arduino serial port library you are using will support the 2nd UART of the processor you are using.

Please re-word (edit) your Title & Question.  Make it clear you are already using the serial port built into the Arduino Uno.  And you wish to create a 2nd serial port.  I will in turn make my answer fit the re-worded (edited) question.


text:
Arduino-compatible Bluetooth classic module to use in a product
I've been designing a product for some time using arduino language, but on our own hardware. Recently a need arose to add some Bluetooth capability to our product. We decided to use BT classic instead of BLE, because not every phone has BLE capability yet. Of course immediately I went to check HC-05 modules and their cousins. The issue is I believe they are a chinese product and have no FCC certification and I can't buy them from any reputable source (digikey,mouser,farnell etc.).
Seeing that this is an issue for a product I went and checked the mentioned suppliers to see what they offer. The thing is though, I'd like to stay in the arduino environment so I'm looking for a module that has some support from the arduino side.
I found this module from Cypress, that has this "arduino-compatible" code. However when a tried to find any library that I could use to program this board using arduino environment on Cypress's site I only found mentions of their own SDK.
Thus comes the question: are there any FCC compliant bluetooth modules that have an easy to use arduino library available?

You've got the same compatibility issue whether you choose BLE or BT-2. Not every phone has BT-2 either: iPhones have had BLE (only) for some time.

Hmm didn't know that. Thanks for the heads-up.

You should choose chip that support at least bluetooth 4.0 or above (i.e. BLE capable) as this is most of the phones or other products supporting now. BT2.0 probably only supported by products that are more than 10 years old.

There are plenty of FCC pre-certified modules to choose from, look at their FCC certified ID which is usually available on the RF shield cover of the module.


text:
How can I get Serial.print to print a variable thats a char?
I'm trying to write a function as part of my code, and the function basically has to write the name of a parameter, but I can't get it to print properly to the screen. Here is what I've got:
void dataprint(char parameterName, float dataNum, char unitName);
{
 Serial.print(",");
 Serial.print(parameterName);
 Serial.print(",");
 Serial.print(dataNum);
 Serial.print(",");
 Serial.print(unitName);
}

In the actual program part I have something like this:
char temp = "temperature";
float t = tempsensor.readTempC(); // just some number that comes from sensor
char unit = "C";
dataprint(temp,t,unit);

Right now in the serial monitor I get a question mark or something like that instead of the name I have saved in parameterName or unitName. I want this function to print the same way something like this would show up:
Serial.print(",");
Serial.print("temperature");
Serial.print(",");
Serial.print(c);
Serial.print(",");
Serial.print("C");

Thanks in advance for any help.

char unit = "C"; won't compile, and that's quite important to your question. Could you edit the question with the code you really have please?

@MarkSmith Funny thing with that is: it'll compile. (@ Arduino IDE 1.8.1)

@KIIV Just tested it, and so it does. That's mad. Confirmed not compile on the (older) version I was using!

To make your code work, you must use character array pointers. A "char" holds only one character, while "char*" can point to a string.
char foo = 'a';
char *bar = "string with lots of stuff.";

So the full code to implement your example is:
void setup()
{
  Serial.begin(9600);
}

void dataprint(char *parameterName, float dataNum, char *unitName)
{
  Serial.print(parameterName);
  Serial.print(",");
  Serial.print(dataNum);
  Serial.print(",");
  Serial.println(unitName);
}

void loop() {
  char *temp = "temperature";
  float t = 123.4;
  char *unit = "C";
  dataprint(temp,t,unit);

  while(1)
  {
    //do nothing
  }
}

Which prints the following to the serial port:
temperature,123.40,C

It works, but it's bad C++: warning: deprecated conversion from string constant to ‘char*’. This means you should replace every char * with const char *.


text:
Compatibility between shields
Despite that I am new to Arduino, I am tasked to invent a serious alarm system and I chose Arduino.
I study electronics, but virtually I am a software programmer and C is my area of expertise.
I ordered the parts I think I will need and the time is immensely pushing me.
The delivery goes slow and it needs to happen before our planned vacation, because
we've been robbed several times so far.
I need to know if I will need another gadgets to deal with a problem I've discovered suddenly.

>

I plan to stack up these 3 shields

Arducam-F Shield V2 Camera module shield /w OV2640
3.5" TFT LCD Display Touch Screen Module
SIM900 Quad-band GSM/GPRS Shield

From what I've learned the shields 1 and 3 are compatible, as the arducam uses
CS/SD, ICSP, VCC, GND, SDA and SCL
or according to standard pin out table:
I2C_SCL, I2C_SDA, SPI_SCLK, SPI_MISO,
SPI_MOSI, 9, 10, Reset, 5V, GND
and the GPRS shield uses D7 and D0/D1(or D2/D3), 3 I/O ports. For D7.
The arducam however seems to be not stackable and as far as I can not see it is impossible
to make it stackable (Maybe even if I drill holes and solder stackable shield headers)
So it must be the topmost shield.
What about the LCD shield? I also learned that such shields use a lot of pins, so it is possible that there will be no free pins. I also ordered lots of jumper wires of any kind, if that can help.
Maybe I don't need to wire each of the pins in order to make it work or do some extra coding to get it work? I also don't necessarily need the other shields to work while I operate with the screen, so maybe there is a way I can connect/disconnect shields separately with a program or something else I can buy. I have a feeling that this LCD shield will leave no pins for the other shields and I should connect the arducam on another way since it is not stackable.

I don't want to disappoint you, but it seems a lot is at stake (robberies). Are you sure if you are new to Arduino / electronics, to create something critical in a short time, instead of buying a (probably more expensive) solution?

I agree with @MichelKeijzers that IF this project is for protection of a building then its a stupid idea.  You should be able to purchase a commercial system with at least the same capabilities for not much more than you have already spent.  I see the attraction in doing it for fun, but not for real.  Would you operate on someone to remove their appendix?  No, you don't have the skills and its unreasonable for someone to think you can jump into another field and just start achieving stuff.

That said, I think the kit you have selected isn't really good enough, any image processing requires much more grunt than an Arduino can provide, but you don't want the lack of real time of the Pi.

@CodeGorilla What if I buy second arduino, optimized for the screen only and connect it to the main arduino creating I2C bus.
I also bought motion sensor as a condition to activate the camera, I bought 4 li-ion lg batteries for independent power supply.

@MichelKeijzers We have very limited resources unfortunately.
And we only need to protect a room.. it's a small apartment.

@Ediana ... I hope you can finish it in time, I also have a 'hobby' project in mind, but it will take much longer than expected, but of course it's fun. I wish you all good luck (and see you already have tips/answers from others).

@Edenia - I understand what you mean, but I don't think it is the right way to go.  Why have a screen on this system?  Who are you showing pictures to?  What about using a old smart phone, could you write an app for that and leave it connected to a PCs USB port?

@Edenia - Remote IP HD Camera ~ £17 (ebay), Arduino Uno ~£25.

@CodeGorilla there is no computer near the place I intend to mount the alarm (I called the project "AllArm" it's catchy), also I plan to make it electricity-independent (Well more like house electrification-independent). The screen I need for varying diverse configuration of the behavior and yes, you are right - eventually for showing pictures as well. I will be auto-calling police after all, they must know who are they looking for.

Comments are not for extended discussion; most of this conversation has been moved to chat. (cc: @MichelKeijzers)

Its not just a question of the stackability of the shields and the clash of pins you also need to consider what the shields do.
Stacking the GSM shield under the LCD is going to restrict is tx/rx power unless you have an external aerial.
The LCD will require a large amount of memory and processing power, a 3.5" inch display is really going to push an Uno to the edge, you aren't going to get much time for servicing the GSM and camera.
The camera is also going to require a large amount of RAM and processing time to handle still images.  If you are processing video then I really doubt you will be able use the other shields.
You don't say if you are experienced in Embedded development.  Its different to Linux or Windows dev where resources are almost limitless.  If you don't have experience then you might find the transition quite hard.
Your question was are they compatible, I don't have the evidence but I would say no because of the resources they consume.  Sorry I can't see this project going anywhere fast. :(

Code Gorilla, thank you for your help.
I don't particularly have experience in embedded programming, but I have experience in something very similar - optimizational programming - using as little resources as possible (in terms of memory and performance)

I think it should do, because I don't need all shields working in the same time. On the contrary, It occurs that I will use one in event.


text:
How can I control the speed and direction of dc motor at the same time (through Bluetooth
I am working on a project of an arduino car it's simple really i know how to control the speed and direction using simple button but I was looking for an upgrade so I add a virtual joystick in my app now It can send 2 values first is the angle where the pointer of the joystick is which will be used to control the direction. And the distance between the center of the joystick and the pointer will be used to control the speed, problem is they are both int values how can I make the arduino differentiate between both values ? also they would be sent simultaneously over Bluetooth which might be a problem as well

look into "H bridge" modules or circuits.

Use delimiters to separate the two values you are sending over bluetooth.
Something like
"30,5\n"

instead of
"30\n"
"5\n"

On the Arduino side, read the the incoming string into a char array and add a \0 after the last read character to make it a C string. The use strtok() to parse the C string and atoi() or atof() to convert the parsed C strings to an int or float.
See this answer for more information about parsing a string.

I would say it would be the best way to use a H-bridge motor driver such as L293N. With it you can simply drive a DC motor both ways and even control it's speed.
Make the connection as shown on picture below, but connect wires of both motors to the same motor and PWM_SPEED_CTRL are channels connected to the Arduino. Don't forget to add relays between pins: 3-1, 6-2 and 11-1, 14-2, which would determine the turning direction.
If you don't understand certain thing, just ask and I'll try to reply ASAP.

thank you for your answer but that wasn't the point i was asking about . Still it's really helpful


text:
DFRobot GPS init error [Arduino Uno, SIM808]
i have problem with initialization DFRobot SIM808 actually when i try to recieve gps data by SoftwareSerial only it does works (i mean examples based on sending and reading command to and from serial's), and recieve data but very long string of data and i need only Latitude and Longitude and i think using DFRobot will be the easiest way to extract the data i need. So the simple test program like this one is not working:
    /*
### Get GPS data
1. This example is used to test SIM808 GPS/GPRS/GSM Shield's reading GPS data.
2. Open the SIM808_GetGPS example or copy these code to your project
3. Download and dial the function switch to Arduino
4. open serial helper
4. Place it outside, waiting for a few minutes and then it will send GPS data to serial

create on 2016/09/23, version: 1.0
by jason

*/
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>

#define PIN_TX    7
#define PIN_RX    8
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,

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

  //******** Initialize sim808 module *************
  while(!sim808.init()) {
      delay(1000);
      Serial.print("Sim808 init error\r\n");
  }

  //************* Turn on the GPS power************
  if( sim808.attachGPS())
      Serial.println("Open the GPS power success");
  else
      Serial.println("Open the GPS power failure");

}

void loop() {
   //************** Get GPS data *******************
   if (sim808.getGPS()) {
    Serial.print(sim808.GPSdata.year);
    Serial.print("/");
    Serial.print(sim808.GPSdata.month);
    Serial.print("/");
    Serial.print(sim808.GPSdata.day);
    Serial.print(" ");
    Serial.print(sim808.GPSdata.hour);
    Serial.print(":");
    Serial.print(sim808.GPSdata.minute);
    Serial.print(":");
    Serial.print(sim808.GPSdata.second);
    Serial.print(":");
    Serial.println(sim808.GPSdata.centisecond);
    Serial.print("latitude :");
    Serial.println(sim808.GPSdata.lat);
    Serial.print("longitude :");
    Serial.println(sim808.GPSdata.lon);
    Serial.print("speed_kph :");
    Serial.println(sim808.GPSdata.speed_kph);
    Serial.print("heading :");
    Serial.println(sim808.GPSdata.heading);
    Serial.println();

    //************* Turn off the GPS power ************
    sim808.detachGPS();
  }

}

SoftwareSerial accepts the pins in RX, TX order. You have them backwards. This may not  be the issue depending on your wiring, but it's the first thing I noticed.

yea some mistake in template but it is (7,8) anyways, same as in working example

I have the same issue were you able to resolve?

Nope, i just wrote my code instead using library :( . Resolving it would be still useful

I have tried to run the sim808 shield with the source code from above and also with the Dave's code. Without success. I have the external power supply, I switch between the different modes when uploading the code. I receive on the serial monitor either Sim808 init error
or GPS initializing. Do you have any suggestions where to start troubleshooting?

I had similar problems, couldn't even get a basic connection from Arduino - Shield. I guess the DF Robot GPRS library is broken.

@stevieb, well spotted about the TX&RX being the wrong way round in the DFR demo, but sadly that doesn't fix the problem.

@OnuralpArslan I have unprotected this question so you can answer it. Your original answer is here as a Community WiKi answer that you can copy and paste into your new answer.

{Original answer by Onuralp Arslan}
gps function of sim808 does not require sim card you only need 9v source with enough current and 1575.42 mHz gps antenna
use this code it will help
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
#define PIN_RX 11
#define PIN_TX 10
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,

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

//************* Turn on the GPS power************
if( sim808.attachGPS())
Serial.println("Open the GPS power success");
else
Serial.println("Open the GPS power failure");

}

void loop() {
//************** Get GPS data *******************
if (sim808.getGPS()) {
Serial.print(sim808.GPSdata.year);
Serial.print("/");
Serial.print(sim808.GPSdata.month);
Serial.print("/");
Serial.print(sim808.GPSdata.day);
Serial.print(" ");
Serial.print(sim808.GPSdata.hour);
Serial.print(":");
Serial.print(sim808.GPSdata.minute);
Serial.print(":");
Serial.print(sim808.GPSdata.second);
Serial.print(":");
Serial.println(sim808.GPSdata.centisecond);

Serial.print("latitude :");
Serial.println(sim808.GPSdata.lat,6);

sim808.latitudeConverToDMS();
Serial.print("latitude :");
Serial.print(sim808.latDMS.degrees);
Serial.print("\^");
Serial.print(sim808.latDMS.minutes);
Serial.print("\'");
Serial.print(sim808.latDMS.seconeds,6);
Serial.println("\"");
Serial.print("longitude :");
Serial.println(sim808.GPSdata.lon,6);
sim808.LongitudeConverToDMS();
Serial.print("longitude :");
Serial.print(sim808.longDMS.degrees);
Serial.print("\^");
Serial.print(sim808.longDMS.minutes);
Serial.print("\'");
Serial.print(sim808.longDMS.seconeds,6);
Serial.println("\"");

Serial.print("speed_kph :");
Serial.println(sim808.GPSdata.speed_kph);
Serial.print("heading :");
Serial.println(sim808.GPSdata.heading);

//************* Turn off the GPS power ************
sim808.detachGPS();
}

}

try this, worked for me without sim card
connect rx of sim808 to arduino 11
tx to 10
and connect grounds of arduino and sim808

We had the same error in the code. But we managed to solve it! You have to insert the SIM CARD to work. We do not know why, but it works!


text:
Arduino Pro Mini maximal and recommended current per pin
In Arduino Pro Mini (3.3V) specs indicated the maximal and recommended current per pin, 40mA and 20mA respectively. Does these values means input current (i.e. safe input current Arduino can handle) or output current?

It is the amount of current the pin can source or sink when in OUTPUT mode.
That is, the amount of current that can flow from the pin to ground, or can flow from VCC into the pin.
You can understand it better if you learn how a GPIO pin works.

So, basically, there's no needs in current limiting resistors to protect the external processor connected to Arduino?

It can be good to include a small series resistance when connecting microcontrollers together in case both have their pins set to output and one is high and the other low.

Will the 100 Ohm 1/4 Watt resistors directly soldered on the wires quite adequate for this? While this resistors protects the buffer from being damaged, it also limits the drive strength of the buffer, that may
result in degraded operation.

100 ohm is pretty much perfect. The drive strength reduction is minimal. You are only driving one gate pair at a few (tens of) pF. It would take many times that to affect the kind of frequency signals an Arduino can produce.

Incidentally that is exactly what the Arduino uses between the 328p and the 16u2.

In datasheet, paragraph 32.1 is stated:
DC Current per I/O Pin 40.0mA

See comments below about the implication. (I will not delete this questions because of the useful comments below from Majenko and Milliways, unless downvoted).
See:

No, it implies both source and sink which are different to input (high impedance) and output (sources and sinks current).

@Majenko ... where can that be found in the data sheet?

Input current is not specified (except for pull-up current). DC Input current would be negligible (of the order of nA). Of more significance in a practical circuit would be the input capacitance ~10pF.

Well. I mainly worry about max current, mA that will be applied from Arduino output to digital input pins of external chip to which Arduino connected to.

In that case the following table will be sufficient (and more useful in general with the remarks of Majenko and Milliways

Does these values means input current (i.e. safe input current Arduino can handle) or output current?

Depending on your definition of input.
The numbers are the max current that an output pin can provide , either flowing in or out of the pin.
The max current you can force into or out of an input pin is mostly determined by the clamp diodes. Typical a few ma.

The clamp diodes start working at 0.5V above VCC and 0.5V below GND. There is a Application Note AVR182 that mentions that a maximum of 1mA is allowed to push into or pull from an input put of an AVR microcontroller. I use this 1 mA to calculate the maximum input voltage for a voltage divider with two resistors.


text:
How do I disable drag-and-drop text editing in Arduino IDE
How do I disable drag-and-drop text editing in Arduino IDE?  This is very annoying.  If not careful, this causes code to move around when trying to copy and paste...

I cannot find any settings in 'Preferences' that control drag-and-drop functionality.

If you cannot a corresponding setting in the preferences file, the IDE doesn't have this feature. The Arduino IDE is really not a good IDE, so you might want to move to a more professional IDE

ctrl-z is your friend

When I did a bigger (proof of concept) project, I use Visual Studio, Eclipse (or any decent IDE), and you still can use the Arduino IDE to compile.

@MichelKeijzers - what do you mean "still can use the Arduino IDE to compile"? do you mean - copy from the other IDE back into Arduino IDE for the compile and load?  Or do you mean, you can use the other IDE and somehow get the Arduino IDE to recognize changes in an external IDE to compile against?

I mean the last ... edit in the external IDE, and press the compile button (or shortcut) of the Arduino IDE. I remember there was an issue one way around (I think the Arduino does not recognize automatically changes), so you have to make the .ino file stable (just let it load a C++ (startup) class that executes everything.

Thanks @MichelKeijzers - I will give it a try!

In the preferences dialog, there is a checkbox labeled “Use external editor”.


text:
LED Webserver control not working
I've got an Arduino Uno and Ethernet shield, trying to test it out with a simple on off switch for the on-board LED.
My Code is this
// FILENAME = LED2.ino
// SOURCE= http://www.instructables.com/id/Control-an-LED-over-the-internet-using-the-Arduino/
// Control an LED over the internet using the Arduino Ethernet Shield and Transistor
// http://www.instructables.com/id/Control-an-LED-over-the-internet-using-the-Arduino/
// code SOURCE= http://pastebin.com/CZ6J62qJ

#include <SPI.h>
#include <Ethernet.h>

#include <Servo.h>
Servo myservo; // create servo object to control a servo

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 177 }; // fixed IP addr in LAN
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

String readString;
//////////////////////
void setup()
{
    pinMode(6, OUTPUT); //pin selected to control LED
    pinMode(13, OUTPUT);
    //start Ethernet
    Ethernet.begin(mac, ip, gateway, subnet);
    server.begin();
    //the pin for the servo co
    //enable serial data print
    Serial.begin(9600);
    Serial.println("server LED test 1.0 ---- FILENAME = LED2.ino "); // so I can keep track
}

void loop()
{
    // Create a client connection
    EthernetClient client = server.available();
    if (client) {
        while (client.connected()) {
            if (client.available()) {
                char c = client.read();

                //read char by char HTTP request
                if (readString.length() < 100) {

                    //store characters to string
                    readString += c;
                    //Serial.print(c);
                }

                //if HTTP request has ended
                if (c == '\n') {

                    ///////////////
                    Serial.println(readString); //print to serial monitor for debuging
                    client.println("HTTP/1.1 200 OK"); //send new page
                    client.println("Content-Type: text/html");
                    client.println();
                    client.println("");
                    client.println("");
                    client.println("<TITLE>Home Automation</TITLE>");
                    client.println("");
                    client.println("");
                    client.println("
Home Automation
");
                    client.println("
");
                    client.println("
");

                    client.println("Turn On Light");
                    client.println("Turn Off Light
");

                    client.println("");
                    client.println("");

                    delay(1);
                    //stopping client
                    client.stop();

                    ///////////////////// control arduino pin
                    if (readString.indexOf("?lighton") > 0) //checks for on
                    {
                        digitalWrite(13, HIGH); // set pin 6 high
                        Serial.println("LED On");
                    }
                    else {
                        if (readString.indexOf("?lightoff") > 0) //checks for off
                        {
                            digitalWrite(13, LOW); // set pin 6 low
                            Serial.println("LED Off");
                        }
                    }
                    readString = ""; //clearing string for next read
                }
            }
        }
    }
}

The problem is that when I click a button (either on or off)  the LED will blink twice, and then remain off.
My serial monitor also shows 2 HTTP requests, I'm not sure if this is usual or not?
server LED test 1.0 ---- FILENAME = LED2.ino
GET /?lighton HTTP/1.1

LED On
GET /favicon.ico HTTP/1.1

GET /?lighton HTTP/1.1

LED On
GET /?lighton HTTP/1.1

LED On
GET /favicon.ico HTTP/1.1

GET /?lighton HTTP/1.1

LED On
GET /favicon.ico HTTP/1.1

GET /?lightoff HTTP/1.1

LED Off
GET /favicon.ico HTTP/1.1

Would appreciate any help!

Might need to reconsider using pin 6 for the LED as pin 13 is used by the Ethernet shield for SPI clock (SCK).

@lookalterno It's the button on the webserver control  (html button) if you view my code

@LookAlterno OK.. So how could I rectify this issue?


text:
Can anyone identify these headers?
I'm very new to the Arduino platform and micro-controller projects in general, which is why I'm still learning about all the parts needed for circuit creation. There is one particular part that I would need for my current project but I'm having troubles figuring out what exactly this "thing" is ...
Please take a look at this picture: https://i2.wp.com/makezine.com/wp-content/uploads/2015/08/rolljam-hardware.jpg?fit=929%2C724
I need to know, please, what exactly these dual row female headers are called that are placed right to the Teensy board and are holding the two CC1101 units (so I can find them on Amazon or in other shops).
Obviously, they are spanning the gap on the breadboard but is there something you can buy like this? Or are these common dual row headers that have had their pins bent and put into single row headers?
I can't quite tell. The whole thing looks custom made though (to me it even looks like some hot glue was used, but I might be entirely wrong about that).
^^ And if my assumption is right, what might be the purpose of doing this? From my understanding this would create a full row for the power (instead of having two shorter rows), which the gap on the breadboard is meant to prevent?!
Thank you for suggestions.

https://www.creatroninc.com/category/idc-ribbon-breakout-board/prototyping/breadboard-adapter

Thank you very much! Now I know that you can buy these things (but I still can't shake the feeling that the ones on the picture are custom made). I would still like to know, please, what might be the purpose of bridging the gap with one of these? Why not just use common dual row headers on one half of the breadboard?

All the rows on one side of the breadboard are tied together. Without such an adapter you can't access each pin individually.

Yes, my mistake. You are right. Please see my previous comment to the answer below. Thank you.

Btw: There is another slightly different version of this device that makes it more clear what you mean --> http://www.popsci.com/sites/popsci.com/files/styles/large_1x_/public/_rolljam2-web.jpg?itok=9pmUGcrd If there's just one row of pins like on the two RF433 modules, you can put either one on one half of the breadboard.

From the pic, it looks like a 2x16 female header, PCB mount, with the pins bent outward and soldered to some male header pins.
I think they do this to provide mating sockets for the 2x5 male pins on the CC11001s that can be hooked up to a breadboard.
You could avoid this by prototyping on something like "stripboard' or 'Veroboard' like https://www.amazon.com/Soldering-Prototype-Printed-Circuit-Stripboard/dp/B019Q14GRQ/ and cutting/soldering a few traces where appropriate.
Or you could use a small chunk of stripboard tor protoboard to do the adapting from the 2x5 at 0.1" centers, to 2x5 on 0.1"x0.4" centers.

Yes, these headers are there so all the pins of the CC1101 units can be connected to the breadboard. The one thing I'm curious about is: why do it exactly this way? Why bridge the gap? Why not just use common dual row headers on one half of the breadboard? Since the creator of the device on the picture obviously put in some effort to create these custom made "bridge", I can only assume that there must be some purpose behind it. That's what I need to find out next. But you guys already answered my initial question. Thank you for that!

Edit: Just saw Ignacio's comment above. That seems to be the right answer. I understand now why this "bridge" was necessary for the CC1101s.

Ah, it seems that you are missing the fact that each set of 5 holes on one half of the breadboard are shorted together with a metal clip.  If you do as you say, you will short the C1101's pin 1 to pin 2, pin 3 to pin 4, etc....  You need to bridge the gap to break those connections.


text:
Arduino 3.3V Conversion
I am fairly new to Arduino. As far I know all official Arduinos run on 5 volts. Or there is Arduino versions that run from 3.3V? I need use Arduino with devices which chipsets all use 3.3V logic level. Do I need modify Arduino to make it  3.3V powered, like described in this Tips, or there is another way? I plan get Arduino UNO R3 ATmega328P board (comes with bootloader for Arduino UNO ZT).

The best solutions to this are to move away from an antiquated ATmega to a modern MCU which achieves full performance on 3.3v.

Nucleo boards (ARM). And on Olimexino 32u4 it's even possible to switch between 3.3V and 5V. So many possibilities

You can use different possibilities:

Use Arduinos which are already 3.3V by default (like Pro Mini, Due if I recall right)
(removed after valid comment of minto below)
Use 5->3.3V adapters, most general devices have adapters which can be bought separately (for under 1$) to convert 5 to 3.3V (including logic level converters)

I think the point 2) "Use the 3.3V pin on e.g. the Arduino Uno" is simply wrong: the Arduino Uno has a 3.3V power source, but the digital I/O pins are based on 5V, not 3.3V. We can't to make the I/O pins 3.3V, unless we are powering the Atmega at 3.3V also.

True, I will remove it from the answer (was mixed up with powering in general)

What about just getting the bare chip so you can run it at whatever rail you want? Seems like the simplest and easiest solution.


text:
I2C communication between Arduino Due and Nano
I'm trying to communicate between two Arduino Due and Nano. Nano as Master and Due as a slave. As given in the library description Wire Lib
When the master request for data from the slave, first it goes to Request ISR. Wire.onRequest(requestEvent)    But when compile the program for Arduino Due I get following errors.
In file included from C:\Users\\Slave_Test3.ino:14:0:

C:\Users\..\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\libraries\Wire\src/Wire.h:59:7: error:   initializing argument 1 of 'void TwoWire::onRequest(void (*)())' [-fpermissive]

 void onRequest(void(*)(void));

       ^

But If I change from Arduino Due to any other board this error does not come.
Thank you

It looks like a problem with the Wire lib that the Due BSP includes.

Dead easy !!
(Well only because I had a -fpermissive yesterday :) )
You are trying to implicitly cast, and you can't do that with modern GCC versions (quite rightly).
So you need to explicitly cast the first parameter to void*.
Because this is in a "core" library for the Due I would get the latest version of the board package and see if it goes away.  You can turn the check off, but you will need to google on how to do that.

Thank you for the solution. Yes, I have the latest version of the board package. Still, I'm getting those errors. Can please elaborate your last suggestion I am new to this.

Not really because I can't see the code that has the problem.

I have written the same come as given here .

That link won't help.  This "error" is not in your code, its in Wire.h as per your original post


text:
How can I configure the RFM95 LoRa module to emit packets at only 'one' particular frequency?
I have created a LoRa gateway using a Pi3; I have used a RFM95 module for it. So, it is a single channel gateway, and I'm operating it at 868.1Mhz. But my LoRa node(also a RFM95, on an Arduino Uno), whenever transmits data, does so on various frequencies at random, and there seems to be no pattern to it. Hence a lot of data gets lost. How can i transmit data on a particular frequency only?


text:
AT command to put the A6 GSM/GPRS into sleep / power down
The general AT command for sleep mode (for the SIMCOM GSM modules) is AT+CSCLK=1 (or AT+CSCLK=2). I have given both a shot but they don't work with the A6 module. Does anyone know of any other command that does the same? The manufacturers claim that it can function at very low current levels when in sleep. But sadly they don't mention the sleep AT command.

A6 module uses a hardware pin (INT/GPIO_1) or (EN) enable on some modules.
There is no AT command as in the SIM900.


text:
Detect if a 3 phase AC submersible pump is on
I need to know when a 3 phase AC submersible pump is turned on, for the sake of logging it to a online database. Thing is, I do not know how tell if it is ON, or OFF. I've given a thought to using a current transformer, specifically the "STC-013-30" one, but it requires to be wrapped around one of the AC wires (live/neutral) but the motor i have has both the wires insulated together forming a single, huge wire. Plus, its 3 phase, and I do now know if the STC can detect 3 phase currents. Can it be done some way? Can I utilise some other tool to tell if the motor is ON?

Well, you're just going to have to separate out those wires then aren't you?

The surprising sensor that tells me my furnace is running? a microphone. unless you have a silent pump (dream on), a mic taped to the housing should work a treat. if you needed measurements, it's complicated, but telling it's merely "on"? An adjustable cheap mic module w/opamp and pot is fine.

It's likely that the power to the motor is originating at a panel with breakers. You should be able to confirm that only one breaker set is being used to power the pump motor. At that location, all the wires are separated.
If you do not have the necessary skill to identify the correct wires, consider to consult an electrician. It is advisable to remove power to the panel before you begin to insert your fingers to wrap the sensor wire around the correct lead.

I'm afraid I'm not allowed to split the wires. I'm to alter nothing. It's a shame the current transformer is useless when the live and neutral wires are wrapped around each other.

It seems likely, based on the other comments, that the electrical method is not suited for your purpose. I suggest that water flowing through a pipe is not silent. Using a sensitive microphone on the pipe nearest the pump would provide an on/off level trigger. Credit to dandavis for his suggestion.

The long and short of it is that you need to measure the current. And there's two basic methods of doing that, and both require access to just one of the wires in the cable.
So you will either have to take a knife to your cable and carefully remove a section of the outer insulation to access the wires within it, or create some kind of adaptor cable that the existing cable plugs into (however that is done on your system) to allow access to the individual wires.
Then it's a case of either:

Use the magnetic field of one wire to monitor the current (current transformer) or
Introduce a shunt resistance into the current path and measure the voltage drop across it.

The first option is by far the safest.
Alternatively there may well be some form of commercial three-phase power monitor with an output that you can monitor to achieve what you want with less danger of electrocuting yourself and others in the process.

thanks, but I cannot split the wires.

Then you will either have to build an adaptor for it to plug into (if there is even a plug - but who knows round here except you...?) or do something else further up the electrical chain.

Ok, thank you. Any way you think I could accomplish it by checking if the water's flowing through the pump's pipe?

If you can break into (cut) the pipe and add a suitable flow meter, sure.

Oops like I said, I cannot alter the existing. I mean, not so much as CUTTING open anything. Anyway, thank you.

So you need a 100% non-intrusive method to see if the pump is running. That only really leaves sound or vibration then - is the pump making a noise, or is it vibrating. Since it's submerged that's tricky to do...

the pump hardly makes noise, and yes its submerged. so, cannot attach and vibration sensors to it.

Well you're a bit stuffed then...


text:
How to calculate voltage from A0 pin
I would like to calculate the amount of voltage from my A0 pin. I am using a 9v battery to power my load in my circuit. The formula to calculate voltage from the A0 pin is:
    sens = analogRead(A0);
    vol = sens * ( 5.0 / 1023.0);

If my power source is 9v, should i replace the 5.0 to 9.0?

The formula is sens * ( 5.0 / 1024.0), not 1023. C.f. the datasheet of the microcontroller.

The analog input pins are 0V-5V strictly. If you need to measure a 9V input, you need to scale the voltage to test so that it is within a 0V-5V range. Often this is done with a voltage divider circuit.
In the example below, the 9V test voltage is divided in half, so the scale is 0V-4.5V, which is within range of the input pin.
Then your algorithm is
vol = sens * (2.0) * ( 5.0 / 1024.0);

simulate this circuit – Schematic created using CircuitLab

Per the datasheet of the microcontroller: 1) The scaling factor is 1024, not 1023. 2) The resistors should be no more than 20 kΩ.

Updated the answer. Was trying to keep leakage current low, but you're right, 100k+100k is too high to get enough current for a reliable reading.


text:
No change in acs 712 readings after connection to load
I would like to measure the amount of power used by a 3w bulb. I am using a 9v battery to power the bulb and an acs712 current sensor to get current usage. However, i get no change in values after i connect the load and it light up.
Is my current sensor faulty or? I'm confused.

Which sensitivity of ACS712 do you have? If your bulb is really running at 3W off your 9V battery you will only be pulling about 300mA. A 30A ACS712 won't even notice it. A 5A one might see a little change.

Can a 20A ACS712 sensor detect the current going through a 12V and 3W light bulb?

Based on the previous comment it is unlikely that it is sensitive enough.

The 30Amp version will read 66mV/A, the 20A will read 100mV/A and the 5A version will output 185 mV/A.  So even if the sensor does detect the change in the reading you will see on Analog In will be in the region of 5 to 20, which is less probably less than the noise you see anyway.

Sensitivity is very low for low wattage load.

For such light and low-voltage loads you wouldn't normally use a mains rated high current amplifier like this.
Instead you would just use a simple shunt resistor in the low-side of the circuit:

simulate this circuit – Schematic created using CircuitLab
The voltage dropped across the resistor (and hence the voltage you will read on A0) is proportional to the resistance of the resistor and the current flowing round the circuit.
You want the resistor to be small enough that it doesn't overly affect the operation of the circuit, yet large enough that it drops a voltage you are able to sense at enough resolution.
For example the 1Ω resistor above, with 333mA round the circuit (3W at 9V) would drop (V=IR) 0.3 * 1 = 0.3V.
While that's not a very high voltage it's small enough to not really affect the circuit, and you can increase the sensitivity of the Arduino by using the 1.1V internal reference instead of relying on the default 5V external Vcc voltage:
analogReference(INTERNAL);

Or on the Mega2560:
analogReference(INTERNAL1V1);

Hi, so what do i use to measure the voltage drop? So that i can feed my Arduino with this data?

The Arduino. As shown in the circuit.

What if i use a 220 ohms resistor? 0.333 * 220 = 73.2v (V= I * R) Does that make any sense?

You will get a lower current with a higher shunt resistor. Shunt resistors need to be small enough to not really affect the circuit

Ok. So i will then take the voltage from my analog output and then multiply it to the 0.333mA so as to get the power? Forgive me, i am relatively new to electronics stuff

No, you take the voltage you read using the analog input, divide it by the value of the shunt resistor, and it tells you what the current is. The 0.333 is an example of what it might give you as an answer.

Ok. So once i have the current, how do i calculate power? I know its I * V but which voltage should i use for power calculation?

It depends what power you want to calculate. The overall power is the overall voltage (the battery voltage) multiplied by the overall current. The power of just the bulb is the voltage across the bulb (which happens to be the battery voltage minus the voltage you measured across your resistor) multiplied by the current.

Ok. I have now grasped the concepts well enough. Thank you very much for sharing your knowledge and patience. You are a very good teacher :)

HI, in your circuit, i have seen you've grounded the circuit twice, once to the power source and the second to the arduino board. Is this necessary? Cause i am short on ground pins in my arduino

https://hackingmajenkoblog.wordpress.com/2016/12/06/the-importance-of-sharing-grounds/


text:
Arduino Newbie: Solderless Breadboard Alternate
I am completely new to arduino. I have created a circuit using solderless breadboard. But obviously the connections are lose or not as good as a soldered solution. So I was wondering since I am new to circuits too, what is the easiest

i found that with thick custom-cut wiring (~20AWG solid) and a brand new breadboard the connections are actually pretty robust ("drop proof"). deadbug-style is easy as well, at least for small circuits

The next step up from breadboard is either matrix board or strip board.
Matrix board is a PCB with a grid (matrix) of holes in a 0.1" grid with copper annulars around them for soldering.

Strip board (also known as the brand name Veroboard) is like matrix board but the holes are linked together in long strips, a little like a breadboard. These strips run the length of the board and you have to break the strips (there is a special tool you can use, but most people just use a small drill bit) into the pattern you require for your circuit.

Yes, both of these require soldering - so now is the time to get to grips with how to solder. There's plenty of tutorials and videos online to help you get to grips with it (though don't grip the hot end...). Don't be afraid of making a mess of your first attempts, soldering takes practice to get it right - and having the right tools helps.
Get a semi-decent soldering iron - not a plumber's iron, but a proper electronic one. You can get basic ones quite cheap. I started out with one of these cheap Antex ones:

If you can afford it, though, go for a temperature controlled one instead. It makes soldering easier since you are less likely to lift pads from over-temperature.
And last you will want some decent solder. I use 0.7mm solder with a rosin flux core. Don't use solder that doesn't have a flux core, that is for plumbing.
Having a flux pen (electronic flux, not plumbing flux) will help get you out of some sticky situations with your soldering as well. The addition of flux makes the solder behave itself. Without extra flux it can me somewhat unruly. Also some desoldering braid and maybe a desoldering pump can be useful (I tend to use braid more than my pump these days).

One alternative that I like is the "breadboard-like" copper boards from Busboard Prototype Systems.  Several of their models have layouts just like solderless breadboards, but are soldered, and so more durable and stable, while leveraging your breadboard design pin-for-pin:

I love these because like many folks, I prototype earliest versions on one or more breadboards and these have the same hole layout, even down to the parallel power and ground rails down the sides.  Very convenient and available in several sizes and other configurations.

To make it easy, you can buy so-called proto shields for Arduino like below.
The advantage is that you can stick it directly on your Arduino (Uno/Mega) and you can soldier the extra components on the proto space.

and the connection will be same as that on the breakboard? or will I have to make some changes? like i said I am new to all this. Sorry if my question sounds stupid

It's not a stupid questions ... when I started half year ago I had the same problems. Btw, I never used a proto board like this. But yes, they have the same connections. (I used normal shields, meaning shields which you can stick on top of an Arduino Uno or Mega with premade components, e.g. for SD cards). But with a proto shield you can add your own components.

I basically want to connect four sensors. And I am unable to figure out how to do it without the breakboard. I want to connect humidity sensor, relay board 5v, pir sensor, and solenoid valve. Do you think there is a shield available for something like this?

I know there are boards with preassembled sensors, but I doubt it's exactly the ones you need. Btw, you can normally stack multiple boards on top of each other, but I doubt you will find exactly the configuration you want. In that case, I would use a proto shield (if they can fit on one proto shield).

Use wire wrap for quick and easy prototyping.

Welcome to Arduino Stack Exchange.  Please take the tour at https://arduino.stackexchange.com/Tour to get the most out of this site.  This is an intriguing idea.  Good presentation of the answer.

I have not had much luck with breadboards either. I see, on internet, that others seem to make even quite complex circuits. I can only assume it means I need to take more care to insert the components better and perhaps spend a bit more on a better quality product? I see the replies all give alternatives but no suggestions as to why Saad has problems and how to improve I would be interested to know too! At the moment, I also solder components to breadboards but it is a pain if I have to de-solder. I also use one of those childrens kits for experimenting with electronics together with a solderless bread board. It has transistors and capacitors etc and so I can connect it to IC or other particular components fitted to the [![enter image description here][1]][1]solderless breadboard. The photo is just to give an idea. I have also tried soldering small female sockets to breadboards and plug the various components into those for testing.
I have been experimenting more and reading some articles on internet. In fact, I found it better to make small jumper wires, rather than use tje ready made ones. The ready made ones tend to move and the contact is not so secure. It is nit so easy to make the small jumpers though and needs patience! I also made a small switch power supply board.. I found on "instructables" https://www.instructables.com/id/Ultimate-DIY-Breadboard-Power-Supply/#CB1TV2QJ70QKF7I
It plugs into the bread board and I can select a required voltage
[1]: https://i.sstatic.net/sXOmY.jpg

what is the easiest

for most people, breadboard is the easiest.
I sometimes do point to point (deadbug, mostly RF or small things), or onto pcb adapters (ghetto-style).

Make a PCB with a plotter

You can create a PCB using copper foil and a cutting plotter. The complexity of the circuits will be limited to the resolution and precision that you cutter can plot at but it's a great for prototypes or full projects.
If you already have a machine, the materials are cheap and circuits can be designed using any vector based editing software. Fritzing supports the export of vector files.

[LudwigLabs] is creating PCBs using copper foil and a cutting plotter
(vinyl cutter). In this approach, it’s an additive process where
instead of removing copper from a copper-clad board, the traces are
cut out of copper foil and transferred to a solid backing surface
(cardboard, fiberglass, etc.).

Hackaday: Making PCBs with a cutting plotter
Cricut copper PCB