text:
SD print in script works in setup but not loop
I am a bit of a novice with the Arduino, and have had to learn a lot for my High Altitude balloon launch. I am getting ready to launch this, but for some reason, my datalogger, printing to an SD card, will work in the setup function but not the loop.
If someone could explain what is wrong with my code, and any improvements that could be made to it, it would be very helpful. I am using SPI, SD, I2C, Wire, Sparkfun BMP, and MPU6050 library.
    #include <SPI.h>
    #include <SD.h>
    #include <math.h>
    #define thermoPin 0

    #include <SFE_BMP180.h>
    SFE_BMP180 pressure;

    #define ALTITUDE 87.8
    #include "I2Cdev.h"

    #include "MPU6050_6Axis_MotionApps20.h"
    #include <Wire.h>

    MPU6050 mpu;
    #define OUTPUT_READABLE_YAWPITCHROLL

    #define OUTPUT_READABLE_REALACCEL

    #define analogInPin 3  // Analog input pin that the potentiometer is attached to

    int sensorValue = 0;        // value read from the sensor

    // MPU control/status vars
    bool dmpReady = false;  // set true if DMP init was successful
    uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
    uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
    uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
    uint16_t fifoCount;     // count of all bytes currently in FIFO
    uint8_t fifoBuffer[64]; // FIFO storage buffer

    // orientation/motion vars
    Quaternion q;           // [w, x, y, z]         quaternion container
    VectorInt16 aa;         // [x, y, z]            accel sensor measurements
    VectorInt16 aaReal;     // [x, y, z]            gravity-free accel sensor measurements
    VectorFloat gravity;    // [x, y, z]            gravity vector
    float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector

    volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high
    void dmpDataReady() {
        mpuInterrupt = true;
    }

    #define photocellPin 2
    // the cell and 10K pulldown are connected to a9
    int photocellReading;     // the analog reading from the analog resistor divider

    #define chipSelect 4

    void setup() {
      pinMode(A5, OUTPUT);
      pinMode(A4, OUTPUT);
      // Open dataFile communications and wait for port to open:
      if (!SD.begin(chipSelect)) {
        // don't do anything more:
        return;
      }
        File dataFile = SD.open("datalog.txt", FILE_WRITE);
      if(dataFile) {

      // Initialize the sensor (it is important to get calibration values stored on the device).

      if (pressure.begin())
        dataFile.println("BMP180 init success");
      else
      {
        dataFile.println("BMP180 init fail\n\n");
        while(1); // Pause forever.
      }
      // join I2C bus (I2Cdev library doesn't do this automatically)
        #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
            Wire.begin();
            TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
        #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
            Fastwire::setup(400, true);
        #endif
        dataFile.println(F("Initializing I2C devices..."));
        mpu.initialize();

        dataFile.println(F("Testing device connections..."));
        dataFile.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
        // load and configure the DMP
        dataFile.println(F("Initializing DMP..."));
        devStatus = mpu.dmpInitialize();

        mpu.setXGyroOffset(220);
        mpu.setYGyroOffset(76);
        mpu.setZGyroOffset(-85);
        mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
    mpu.setDMPEnabled(true);
    mpuIntStatus = mpu.getIntStatus();
    dmpReady = true;
    packetSize = mpu.dmpGetFIFOPacketSize();
    dataFile.close();
      }

    }

    void loop() {
      // make a string for assembling the data to log:
      int valF, valC;
      valF = analogRead(thermoPin);
      valC = analogRead(thermoPin);
      File dataFile = SD.open("datalog.txt", FILE_WRITE);

      // if the file is available, write to it:
      if (dataFile) {

        dataFile.print(F("Millis since Launch"));
        dataFile.println(millis());
        dataFile.print(F(", Analog Val."));
        dataFile.print(valF);

        photocellReading = analogRead(photocellPin);

        dataFile.print(F("  Analog reading = "));
        dataFile.println(photocellReading);     // the raw analog reading
                                          // We'll have a few threshholds, qualitatively determined
      dataFile.println();
      char status;
      double T,P,p0,a;

        dataFile.print(F("provided altitude: "));
      dataFile.print(ALTITUDE,0);
      dataFile.println(F(" meters, "));

      status = pressure.startTemperature();
      if (status != 0)
      {
        // Wait for the measurement to complete:
        delay(status);

        status = pressure.getTemperature(T);
        if (status != 0)
        {
          // Print out the measurement:
          dataFile.print(F("temperature: "));
          dataFile.print(T,2);
          dataFile.println(" deg F");

          status = pressure.startPressure(3);
          if (status != 0)
          {
            // Wait for the measurement to complete:
            delay(status);

            status = pressure.getPressure(P,T);
            if (status != 0)
            {
              // Print out the measurement:
              dataFile.print(F("absolute pressure: "));
              dataFile.print(P,2);
              dataFile.print(F(" mb, "));

              p0 = pressure.sealevel(P,ALTITUDE); // we're at 87.08 meters (Home)
              dataFile.print(F("relative (sea-level) pressure: "));
              dataFile.print(p0,2);
              dataFile.print(F(" mb, "));
              dataFile.print(p0*0.0295333727,2);
              dataFile.println(" inHg");

              a = pressure.altitude(P,p0);
              dataFile.print(F("computed altitude: "));
              dataFile.print(a,0);
              dataFile.print(F(" meters, "));
            }
            else dataFile.println("error retrieving pressure measurement\n");
          }
          else dataFile.println("error starting pressure measurement\n");
        }
        else dataFile.println("error retrieving temperature measurement\n");
      }
      else dataFile.println("error starting temperature measurement\n");
      // if programming failed, don't try to do anything
        if (!dmpReady) return;

        // wait for MPU interrupt or extra packet(s) available
        while (!mpuInterrupt && fifoCount < packetSize) {
        }

        // reset interrupt flag and get INT_STATUS byte
        mpuInterrupt = false;
        mpuIntStatus = mpu.getIntStatus();

        // get current FIFO count
        fifoCount = mpu.getFIFOCount();

        // check for overflow (this should never happen unless our code is too inefficient)
        if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
            // reset so we can continue cleanly
            mpu.resetFIFO();
            dataFile.println(F("FIFO overflow!"));

        // otherwise, check for DMP data ready interrupt (this should happen frequently)
        } else if (mpuIntStatus & 0x02) {
            // wait for correct available data length, should be a VERY short wait
            while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

            // read a packet from FIFO
            mpu.getFIFOBytes(fifoBuffer, packetSize);

            // track FIFO count here in case there is > 1 packet available
            // (this lets us immediately read more without waiting for an interrupt)
            fifoCount -= packetSize;

            #ifdef OUTPUT_READABLE_YAWPITCHROLL
                // display Euler angles in degrees
                mpu.dmpGetQuaternion(&q, fifoBuffer);
                mpu.dmpGetGravity(&gravity, &q);
                mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
                dataFile.print(F("ypr\t"));
                dataFile.print(ypr[0] * 180/M_PI);
                dataFile.print(F("\t"));
                dataFile.print(ypr[1] * 180/M_PI);
                dataFile.print(F("\t"));
                dataFile.println(ypr[2] * 180/M_PI);
            #endif

            #ifdef OUTPUT_READABLE_REALACCEL
                // display real acceleration, adjusted to remove gravity
                mpu.dmpGetQuaternion(&q, fifoBuffer);
                mpu.dmpGetAccel(&aa, fifoBuffer);
                mpu.dmpGetGravity(&gravity, &q);
                mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
                dataFile.print(F("areal\t"));
                dataFile.print(aaReal.x);
                dataFile.print(F("\t"));
                dataFile.print(aaReal.y);
                dataFile.print(F("\t"));
                dataFile.println(aaReal.z);
            #endif
        }
        // read the analog in value:
      sensorValue = analogRead(analogInPin);
      // print the results to the dataFile monitor:
      dataFile.print(F("  analog Val of OZONE= " ));
      dataFile.println(sensorValue);
      dataFile.close();
      }
      analogWrite(A4, 168);
      delay(3000);
      analogWrite(A4, 0);
      delay(750);
      analogWrite(A5, 0);
      delay(250);
      analogWrite(A5, 168);
      delay(3000);
        analogWrite(A4, 168);
      delay(2000);
      analogWrite(A4, 0);
      delay(1000);
    }

Possible problems (correct me if I'm wrong):

I noticed that the MPU6050 stops transmitting if delays are put into it

EDIT:
I have now tried the script but commented out the accelerometer (MPU6050) portion,  and it successfully writes to the SD card. could someone explain why the accelerometer portion messes up the rest of the code?

I haven't followed all the details of your code, nor looked into all of the libraries being used, so you may need to ignore some of the following comments.

You write “my datalogger, printing to an sd card, will work in the setup function but not the loop”.  However, you don't say what you mean by “work”, nor how you tell if it works.
It looks like your code in loop() uses the same filename as in setup().  If so, there's no reason to write a file insetup() because it will just be overwritten later.  (If you have a reason, use a different file name.)
Sequences like status = pressure.startTemperature(); if (status != 0) {... delay(status); ... } look suspect.  The parameter to Arduino's delay() function is a number of milliseconds, in an unsigned long; is your startTemperature() supposed to return a status that's usable as the number of milliseconds to delay?
Your status is declared via char status; and  char is a signed type.  If status is negative, the call delay(status); will first convert status to a signed long by sign-extension.  Then it will convert the signed long to an unsigned long with the same bit pattern.  This will ensure a delay of at least 7 weeks, which presumably is longer than you mean to wait.
[Ref: See the “Conversions from Signed Integral Types” table in microsoft.com/en-us/library's Conversions from Signed Integral Types webpage.]
To avoid those long and tedious sequences of dataFile.print(...); statements, you can #include Streaming.h, which is a contributed library that adds some “syntactic sugar” to Arduino C.  At compile time it converts C++-like << stream operators to .print() calls, without increasing code size.  If you don't have Streaming.h installed, install it via Streaming5.zip from arduiniana.org.  Then, for example, in place of
dataFile.print(F("areal\t"));
  dataFile.print(aaReal.x);
  dataFile.print(F("\t"));
  dataFile.print(aaReal.y);
  dataFile.print(F("\t"));
  dataFile.println(aaReal.z);

write
  dataFile << F("areal\t") << aaReal.x << '\t' << aaReal.y << '\t' << aaReal.z << endl;

Whether using Streaming.h or not, writing F("\t") instead of '\t' uses half a dozen bytes of program memory where one will do, and uses the same amount or more of RAM.  That is, while F() saves on RAM usage for long strings, it's of negative value for single characters and short strings.


text:
how to use the decoded raw value to send IR signal in arduino
I am IR library from Ken Shirrif at https://github.com/z3t0/Arduino-IRremote/releases/download/MAJOR/IRremote.zip
It is good and I have used the examples to receive and send and to playback IR signals from the library. And they are working good.
To send Unknown signals we should use sendRaw() method with a list of integers got from the receiver.
My question is when I use the receive program, I get the decoded hexadecimal value for even the Unknown signals. And can I use this small decoded signal to send signals apart from the long list of integers.
I am trying to send these codes from android. It would be quite easy to send and store the small hexadecimal decoded value.
Is there a way to use the decoded value to send for raw signals with some encodings at arduino?

You'd have to find out the proper protocol used. Most often used is NEC. Apart from that, you question has to little information. As it sound like you are controlling both the sending and receiving side, which makes it pointless to use an unknown protocol.

The library recognises NEC, Sony and some other protocols if you could look at the IRrecorder file in the library. And it gives Decoded signals for recognised protocols and for unknown protocols(protocols it don't know) it just gives a list of integers. It can duplicate the signal I give from my remote and to the IR transmitter I have connected to my arduino. I want to know how to converted the integers into decoded format like the Protocols recognised by the library. @Gerben

You'll have to figure out the protocol, and extend the IRremote library to include this protocol, like Jefferson said. You could try adding some of the raw codes to your question and see if anyone is willing to decode if for you. I'd also be helpful to know what the remote you used is for.

If the signal is reported as "unknown" the library couldn't identify the protocol (RC5, RC6, NEC, SONY, etc).  If the library doesn't know the protocol,  the decoded number is meaningless. Simply put, an IR remote transmission has a frequency; a header; some data (the actual remote command); and a footer.  Without knowing the protocol the library doesn't know the length and shape of each section, so the purpose of the decoded number is only to show quickly if the decoding is receiving the same code at each keypress. You can verify this yourself.  Every time something makes an already known remote code be reported as "unknown", the code received is different from a real code, so simply guessing (or knowing beforehand) the protocol is not going to help anyway.

The library recognises NEC, Sony and some other protocols if you could look at the IRrecorder file in the library. And it gives Decoded signals for recognised protocols and for unknown protocols(protocols it don't know) it just gives a list of integers. It can duplicate the signal I give from my remote and to the IR transmitter I have connected to my arduino. I want to know how to converted the integers into decoded format like the Protocols recognised by the library. @Jefferson Ryan

@abdul rahuman, that is the role of recognizing the protocol. In order to achieve what you want, you need to analyze the list of integers to learn how the protocol works, write your own protocol functions for the library and output your commands using these functions.

The list of integers the library shows to you is just a representation of the ON-OFF duration of the remote pulses so with patience or a suitable software you can draw graphics of the received streams and by comparing the graphics of a good number of commands you can usually understand how the protocol works. This is not easy, but if it would, the library could automatically "learn" unknown protocols for you. Sorry for any mistake, but English is not my first language.

Thank you for your comment Jefferson. I would try to do it.

As a side note, I learnt the bad way that sometimes the library is unable to understand the protocol because you are using an unsuitable receiver. For example, the library is unable to recognize 40bit commands (XBOX and some sattelite TV remotes) with some old receivers.

If you are going to reverse engineer your remote protocol, some tips: it is very important to understand the most common protocols first. For example, the Samsung protocol is just a little header pulse duration different from the NEC protocol. And air condittioning remote protocols can be very hard to decipher.

I am not an expect in the field. I am just trying to make and Ir signal duplicater to duplicate the given signals. Could you suggest an easy way for that?

The only easy way I know is to use the Send Raw function

Yeah. You see the send raw function. It's first parameter is a list of integers. I want it in a hex code format like the known protocols. Is it possible?

source: Stack Exchange

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

sort: votes


text:
problem on implementation of the ultrasonic circuitry
I used an Arduino Uno on my project to produce a frequency greater than 35000Hz and the output of digital pin was connected to the ultrasonic transmitter circuitry:

However, it's not working on the transmitting side. Here's the Arduino code:
void setup()
{
    Serial.begin(9600);
}

void loop()
{
    pinMode(13,OUTPUT);
    pinMode(12,OUTPUT);
    int pirSenses = analogRead(A1);
    int pirOuts=11;
    pinMode(pirOuts,INPUT); /*PIR sensor 1*/
    int pirSense = analogRead(A0);
    int pirOut = 10;
    pinMode(pirOut,INPUT); /*PIR sensor 2*/
    Serial.println(pirSense);Serial.println(pirSenses);

    if (pirOut || pirOuts == HIGH)
    { /*tone produces ultrasonic frequency*/
        delay(8000);
        tone(13, 50132); delay(100); noTone(13); delay(10);
        tone(13,54621);  delay(50);  noTone(13); delay(50);
        tone(13,35689);  delay(60);  noTone(13);
    }
    else if (pirOut||pirOuts==LOW)
    {
        tone(13, 50132); delay(100); noTone(13); delay(10);
        tone(13,54621);  delay(50);  noTone(13); delay(50);
        tone(13,35689);  delay(60);  noTone(13);
    }
    else
    {}
}

And the transmitter (model "MCPCT-G5100-4139") specification:

Please help me with this problem. Thanks!

How do you know it's not working. First try it with an audible frequency.

You have at most a tiny burst of attempt after more than 8 seconds of other operations and delay.  First make it transmit continuously, and either use a scope or check at audio frequency as Gerben suggested.

The circuit diagram shows pin 3 but your code uses pin 13 - have you wired it correctly? The code in general makes little to no sense - check it's working with the following: void setup() { pinMode(13, OUTPUT); tone(13, 10000); } void loop() {}.

Your ultrasonic Transducer driver circuit isn't doing a very good job. At most you are getting only a few milliwatts output to the transducer. Your circuit is applying 12 volts through a 2.2K resistor to the transducer, and your Q1 transistor is merely shorting out the Transducer.
From viewing the data sheet on your transducer, it looks like a tiny loud speaker and not a Piezo device. But that is OK.
Try the following push pull driver circuit.  I have tried to keep it simple, but you would need to come up with a PNP transistor (in addition to your existing NPN transistor).
The V2 square wave is your 5 volt output from Arduino.
Also, notice that I have shown the driver circuit using 5 volts, not 12 volts. Using this circuit, if you use 12 volts supply, the output doesn't get any more powerful, and just causes more heating in the transistors.
EDIT 1  :  IMPORTANT :  Don't leave your output pin in the HIGH state.  This turns on transistor Q1 and causes sustained current in the Transducer.  To alleviate this, insert a 47uf capacitor in series with the transducer.
EDIT 2 :  Changed schematic to include output capacitor.

What kind of capacitor should I use for this? Electrolytic or polarize capacitor?

You can use electrolytic. Connect the positive to the transistors emitter.

what is the function of the 47uF capacitor? do this capacitor function as a high pass filter? thanks

To block DC from your transducer.

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


text:
Arduino Christmas light project with dimmer
I have an existing project using an Arduino Yun that controls Christmas lights with relays to turn them on/off. There are currently 13 separate rows of lights on the (60 foot) tree, each plugged into a wall wart that's controlled by its own relay.
I'm considering adding the ability to dim the lights, so I wanted to figure out the best way to do it. The lights can all be dimmed "in unison" - there's no need for 13 seperately controlled dimmers. But I have to be mindful not to cause any "buzzing" in the audio equipment on stage where the tree is.
I've read about PWN, zero cross, and other terms and saw the zero cross tail from powerswitchtail.com that seem useful in the typical project. I'd like to be able to pull this off with no more than 2 "dimmers" for the whole project, if possible.
Where do I start, and how do I do it?

What voltage lights? What kind of lights? Where are the relays - mains or low voltage side?

Traditional 120v white Christmas lights. The relays are currently powertail switch relays, but as I add more modules in the future (for additional colors) I plan to use sainsmart 8  channel SSR relays (so, low voltage side in both setups).

Do you have the budget to get some DMX dimmers? You could use the Arduino as your DMX controller. For example, something like this 4 channel dimmer.

@dlu I'm powering all my lights from 2 power strips. so if I do as you suggest, with an arduino fix shield, could I plug my 2 power strips (for my 60 foot Christmas tree) into 2 (or 4, at most) outlets on a DMX dimmer? Or does each row need to be on its own outlet on the DMX dimmer?

Basically the DMX dimmer gives you an outlet with a remote control that you can talk to programmatically. I suppose the big question is how much power you need to control. I think the DMX dimmer that I linked to is capable of handling about 5 A (~600 W) per channel (or maybe per outlet, there are two outlets per channel on that one. So depending on how much power you need you could divide up the load amongst the channels. Another approach would be to get one or more X10 dimmers. Looks like they run about $20 US for a 500 W dimmer.

"Traditional 120v white Christmas lights."  does not fully describe the problem.  Presumably you mean a series (and possibly secondarily parallel) string of incandescent bulbs which are presumably dimmable, but your mention of "wallwart" instead implies something else like low-voltage LED which is not AC dimmable but rather requires a PWM source.

@ChrisStratton my apologies for probably not being expert enough to give more specific detail. I don't have on-demand access to the actual lights or tree once it's put away. I assume the lights to be regular Walmart Christmas  lights. My use of the word "wallwart" can be ignored for now given the current use of powertail switch relays. What would be the deciding factor that differentiates DMX dimmers from a PWM implementation, and could that implementation run the risk of interfering with audio equipment in close proximity?

The primary concern shouldn't be audio interference, but utter failure and/or fire.  This is a task which you simply cannot undertake without determining the exact nature of the lights to be controlled.  If they won't unpack samples for you, run away from the project as quickly as you can.

@ChrisStratton again, what determines which implementation I should pursue? How can I tell what I'm dealing with, and what characteristics would determine whether I should go with DMX or PWM?

You need to determine if they are incandescent running directly off the mains supply or if they are LED with some sort of power supply or control module.  With the latter, you must assume that they cannot be dimmed unless you entirely understand and/or replace that power supply.

I can think of a couple of ways to approach this:

Use a DMX dimmer, something like this 4-channel dimmer, or
Use an household X10 dimmer.

DMX is used for stage lighting and there is some information on controlling DMX devices with an Arduino in the Playground where there is also some information on the hardware interface and shields, it looks pretty simple. DMX is a differential RS485 interface.
X10 is used for home automation, the signaling is done over the AC line. There is some information on using X10 and an Arduino library in the Tutorials.
Both seem like viable approaches, if you're working in a theater it is likely that they might already have DMX equipment and it would be as simple as hooking up to the gear in the house. Then you'd only need to add a shield or build the interface hardware.

For the DMX dimmer, since it's meant for stage/DJ use, does that also mean there won't be a hum in the sound system from nearby microphones, speakers, etc? And is there more compact DMX dimmers out there that might fit more nicely into a project box (smaller than, maybe, 6 inches on its biggest side)?

I think that will depend on the dimmer, but yes, I'd expect them to be designed to take interference with other equipment into account. As to size, I don't know off hand. Since they are often close to the load they typically include the outlets and that makes them pretty big – the one I linked to has 8 outlets. But, there are probably DMX chips out there and the triacs they control aren't all that big you might be able to build something pretty small. But in a theatre the equipment might already be there, it might be as simple as hooking up to it with the tree & the Arduino.


text:
How to send a group message to multiple receivers using GSM900 and Arduino Mega2560?
I'm working on a project and it can send to one receiver only. What I need is to send a message to multiple receivers. I need a code sample that would satisfy my needs. Please help! I need to finish this ASAP.

Simply change the number in the AT command and send the message again.


text:
How to connect an L293D and an MPU6050 to run together?
I'm wondering how to connect the L293D (H-bridge) and an MPU 6050.
I'm using 1 Arduino Uno, 2 DC motors, 1 MPU6050 and an L293D.
When I tried this, I got some sparks/smoke from the breadboard and none of the motors where running. I only used a 9v battery, not 12v.

Here's the L293D:

MPU 6050 wiring: int-digital 2, SDA-A4, SCL-A5, GND-GND, VDD-Vss
L293D wiring: Vss-VDD, Input4-Digital 5, Output4-Motor, Output3-Motor, Input3-Digital 6, Enable2-5V, Enable1-5V, Input1-Digital 9, Output1-motor, Output2-motor, Input2-Digital 10, Vs-12V battery.

I can't see the connections on that Fritzing diagram clearly enough to answer.  A properly-drawn schematic might help.  Also, if you only used a 9V battery, draw the diagram and schematic that way, instead of drawing 9V in series with 3V and then saying differently.  Also indicate how you are powering the Arduino -- is it via USB?  The diagram doesn't show anything connected to Vin.  Also indicate pin 1 on the L293D

You should not be using a 9v "transistor" battery in a motor control project.  This 9v + 2xAA horrible idea keeps showing up in posts, so clearly some grossly misguided person is promoting that somewhere on the Internet, but it is a flawed idea best avoided.  If you really need such a voltage, use 8-10 AA's to have decent current capability.  The L293D and L298 are also general bad ideas, requiring relatively high voltages to overcome their loss, while many of the readily available motors/gearboxes want low voltages and high current more suited to FET driver chips.

I agree with @ChrisStratton. That is not a 12V battery.

It actually is a 12v (nominal) battery, it is just not suitable for the task.

I don't really se anything wrong with the wiring, atleast your diagram seems to be in order. only thing I would ad is give the pin 8 a ceramic capacitor to ground
but There is a few possible issues you can check.
1 -the sparks make me think that you had a Loose connection at the spark site on the breadboard, maybe the IC was not properly pushed Down in the breadboard, this happens alot, try Again and make sure the IC is complete inserted.
2 - if this does not work You might have destroyed the first L293 or the breadboard tracks but if you have more than one try to see if a replacement or movement of the old ic does the trick
3 -  the motors are to large, and so the current drawn is to high for the L293 to handle and caused thermal shutdown of the L293, a very high current drain will also occur if the motor is stalled. Anyway add some current limiting resistors and see what happends.
4 - if the motor hums without moving then it is because Both the forward and reverse input eg. 1 and 2 is enabled simultaneously.
5 - the code is not appended, so that cannot be verfified, but the MPU 6050 is correctly installed

Ive switched out the H-bridge and added a capacitor. But still nothing

There a some mistakes with the wiring of the supply voltage (Vss) according to the datasheet (http://www.ti.com/lit/ds/symlink/l293.pdf) of the L293D a those on pin 8 (Vss2) and 16 (Vss1). I think those are not connected because each Vss is for one motor of the driver. So you have to connect 9V (or 12V) to both pins.
There is also something wrong with the capacitor (polarity). And your connection of the battery to the breadboard is a bit weird because + of the battery is usally the red not the black wire / marked row on the breadboard.

I will add the changes when i get time. For any people in the future

Hey do you mean that i should connect pin 16 to the battery and not the arduino 5V?

VCC1 16 — 5-V supply for internal logic translation
VCC2 8 — Power VCC for drivers 4.5 V to 36 V

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


text:
Strange problem with serial communication
I'm developing a little project with Arduino, using a small web page to show data. Well, I have been develop the web page and the small code to communicate with Arduino board in my local computer and all work fine.
But, after, I uploaded the code to a Raspberry Pi and then the problems appear.
This is very strange, because when I execute the code inside a WSGI like  django (in my case is other, webapp2) the code works well. I call a specific URL and this WSGI call a method inside a class that communicated with the Arduino board through serial port, so far, so good.
The problem appears when I decided build a method to execute the lines that do the communication, in this moment Arduino does not response and only lights the led number 13 and the 'L' led twice (the led inside the board).
I don't understand why this happens. The code is exactly the same. Any idea?
For the other hand, because I don't have GUI in the raspberry I don't can view the serial port communication easy.
Do you  know any way to view or debug the serial communications between a pc and Arduino without GUI, over the command line?
This is the code:

# -*- coding: utf-8 -*-
import serial
import time

arduino=serial.Serial('/dev/ttyACM0', baudrate=9600, timeout=3.0)
arduino.close()
arduino.open()

sensorTemp=''
arduino.write('a')
while arduino.inWaiting() > 0:
        sensorTemp+=arduino.read(1)
print sensorTemp

Thanks you so much. Any idea is welcome.

Opening the port typically resets the arduino and incurs the bootloader delay (causing it to miss your 'a') unless you change the hupctl setting.  It has been covered in existing questions here.

You can SSH to the PI, then use ```screen /dev/ttyACM0´´´ to open the serial port to the Arduino (when nothing else is using it) just to make sure the Arduino is behaving.

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


text:
Reading temp data
I have hacked this kettle so that I can turn it on and off remotely via wifi and that is working perfectly.

Added this to get a better signal.

This is my micro controlling the 5v buttons on the kettle.

I keep running into a wall when it comes to reading the temperature of the water. The kettle does this automatically, but I want to transfer this information to my micro.
If I hook my multimeter to the ground and and yellow wire that connects to the lower voltage board (5v) that had the buttons and display I can use the voltage reading to predict the temp. The reading ranges from 0-5v, but my micro is a 3.3v micro so a direct connection isn't a great idea. I've tried using breakout boards designed to read voltage, but if I connect anything it throws the reading off.
The multi-meter is fine.
How can I get my micro to read the voltage as if it were a multi-meter? I even tried one of those little seven segment voltmeters but that threw off the reading just like the optocoupler and leds and other methods that I tried.
Here is how I have it set up:

Have you tried a voltage buffer followed by an attenuator yet?

no, but I'll research that next.

@IgnacioVazquez-Abrams - I couldn't quite work out if it was a duplicate or a follow-up question. I believed it to be the latter. However, on re-reading it, it does appear to be a duplicate. It would be better if the original question was edited or appended to...

I am voting to close this... but I think that it would be a shame to lose the extra information... That information should be added to your original question. :-)

Voltage divider
You can possibly use a simple voltage divider. Try connecting two 100K ohm resistors in series between the voltage you want to measure and ground.
Yellow->100K ohm resistor->100K ohm resistor->ground
Now connect your multi-meter to the middle connection between the two resistors.
Depending on the circuit that happens to be driving the yellow wire, you should hopefully see a voltage that varies between ~ 0-2.5 volts. If so, you can connect this voltage to your 3.3v micro analog input.
Note that the value of the resistors is not critical - you just want them to be about the same and pretty large.
Op Amp
If the yellow wire output is so weak that even a voltage divider with very large resistors is pulling the voltage down significantly, then you can use a high impedance op-amp with 1x gain to buffer the signal.
So, you'd connect the yellow wire to the + input of the op amp, and connect ground to the - input of the op amp. The output voltage of the op amp would not track the input voltage (the yellow wire) and you can use a voltage divider on the output as above.
Use digital temp sensor
This option does not directly answer you question, but might be the best solution.
You can get something like a DS18B20 digital temperature sensor for a buck or two and connect it digitally to your MCU and avoid the problem altogether. This chip is happy at 3.3 volts, so you'd just need to put it physically someplace where it is sensing the same temperature as the yellow wire.  This will likely be more accurate too!

When I do this (I tried this weeks ago) it changes the signal going to the micro in the kettle and the temp displayed by the kettle is no longer correct.

What size resistors did you use?

I tried a few combinations. 10k, 100k, 1M then I tried 200ohm just to see what would happen. It changes the voltage, but it also messes up the temp readings on the teapot.

So with 2x 100k ohm resistors in series connecting yellow wire to ground (nothing else) does the temp readings on the pot get messed up? Or only after you connect your ADC pin?

It's messed up before I connect it to the micro.

Even with 1M ohm resistors? Does checking the yellow wire with your volt meter mess up the temp display also? If so, then something else is probably going on and I'd just used an independent digital temp sensor.


text:
Atmel studio 7 with Arduino Uno: Just upgraded to Atmel studio 7 and my target platform is the Arduino Uno
Atmel studio 7 with Arduino Uno:
Just upgraded to Atmel studio 7 and my target platform is the Arduino Uno.
I can't get past the start procedure: Firstly on starting up I get Sequence contains no elements (first image below). Then after pressing enter and entering the the Sketch File and Arduino IDE Path fields, the Board and Device fields remain empty (second image below).
I'm unable to select or update any of these two fields (Board and Device) - any assistance is appreciated.

I also had random problems trying to import Arduino sketches using the new Atmel Studio feature. I eventually gave up. It might just not be ready for prime time yet.

Do you run the Configuration Manager, upon the first launch? It should run automatically, in fact. I installed AS7 yesterday, using the web installer, and it automatically selected Arduino IDE 1.6.5, and the boards were also selected automatically. Do you actually have the Arduino IDE installed? I assume so, from looking at your screen shot. Try upgrading the IDE and running the Configuration Manager again.

Do you have Visual Micro installed?


text:
Why is setup() executed twice at runtime?
Code:
void setup() {
  Serial.begin(9600);
  Serial.println("hello");
}

void loop() {
}

Output:
hello
hello

Why does hello print twice?

Just tried it on my Arduino Uno - only executes once for me. Could it be a residual value in your Serial Monitor

I considered that so I created a new file, restarted the device and Sketch. Still there...

Your Arduino must be resetting as it starts
1 how are you turning it on ?
2 how are you connecting the serial monitor ?
3 what else is connected ?

I think it depends on how quickly you start the serial monitor after downloading a program or resetting the Arduino and on operating system buffering.  Ie, your OS (which is what?) buffers a "hello", then you start the serial monitor, which resets the Arduino and produces the second  "hello"

@jwpat7 That seems the most plausible as sometimes connected lights blink on boot when they are no suppose to.

jwpat7's suggestion sounds the most plausible. Try opening the IDE's built-in serial monitor before you upload your program. The later IDE's will disconnect their own monitor for the duration of the upload and reconnect it again when the upload is done. That way there will be only one reset and you should see the program output only once.

If I open my serial monitor, my arduino sometimes resets twice. I wouldn't worry about this.

Add a 'Serial.println("world"); while(1){};' to your loop, and see if you get just one cycle of loop() per setup().

@DaveX, I get Hello world Hello world, so it looks like the device is resetting every time, like @Gerben's.

Please edit the question to indicate what type of Arduino you are running this on.  They are not all the same with respect to serial port.

Since you get hello world twice, it is also entering into the endless loop twice.  Folks are right in that you are seeing two boot-up cycles -- it isn't that the setup is running twice in one poweron/reset cycle.

It isn't, it's displaying the previous message from when you didn't have the Serial Monitor open yet, plus the new message caused by the Arduino resetting from the Serial Monitor being opened.
If you put a longer message in there you'll probably see the first line get cut off and then the full line.


text:
Using fluctuating voltage as an input
I had an idea to hack a wireless doorbell so it could send notifications to my phone when someone rings the doorbell.
I pulled out the PCB from the doorbell and powered it using the +5v from the Arduino - so far so good
I used the (once was a wire to the speaker) as an analog input
The issue I have is that the voltage for the chime continues for a long time. eg its at 0 before push then it fluctuates for a second, then returns to 519 for a while, before eventually returning to 0.
Is there a smarter way to do this - I have included my code below.
void loop()
{
  //detect a changing voltage
  val = analogRead(sensorPin); //pin A0
  delay(500);
  oldVal = analogRead(sensorPin);//pin A0

//if the voltage changed then +1 to the ring counter
  if (val != oldVal) {
      ringCounter = ringCounter+1;
  }

  if (ringCounter > 3 && pinDevid1State == false) // someone pressed the doorbell
  {
    if(DEBUG){Serial.println("pinDevid1 is HIGH");}
    pinDevid1State = true;
    Serial.println("DingDong");
    digitalWrite(ledPin, HIGH);
    delay(5000);
    Serial.println("Notification Sent.");

    //reset vars
    val = 0;
    oldVal = 0;
    ringCounter =0;
  }

  if (ringCounter < 3 && pinDevid1State == true) // the doorbell stopped ringing
  {
    if(DEBUG){Serial.println("pinDevid1 is LOW");}
    pinDevid1State = false;
    digitalWrite(ledPin, LOW);
    Serial.println("DingDongEnd");
    //Sending request to PushingBox when the pin is LOW
    //sendToPushingBox(DEVID1);    //Here you can run an other scenario by creating a DEVID2 variable

    //reset vars
    val = 0;
    oldVal = 0;
    ringCounter =0;

  }

What are you trying to solve/improve/create? Does this work the way you want it to?

Expecting two analogRead()s half a second apart not to differ at all isn't realistic, I think.  Low order bits fluctuate a lot if there's any electrical noise at all in your system.

@jwpat7your right but the way the logic works is most of the time they are the same... Its only when the door bell is pressed that it then is consistently different for 30 seconds - hence the ring counter

@JRobert It does do what I want it to do - I just wondered if there was a more intelligent way to trigger a notification from a change in voltage. I guess my issue is there will be positive voltage while the speaker wire tries to power the speaker. I wonder if there is another pin on the board I could read - I want the bell to responsive to people impatiently pressing = multiple notifications and fast so there is as little delay as possible

I will try with an hysteresis,

I wonder if there is another pin on the board I could read

I guess that would depend on the particular doorbell. The transmitter must send some representation of a button press to the receiver - a pulse train for the duration of the press, or perhaps just CW: carrier on, carrier off - which the receiver somehow passes on to trigger the audio. Look at the receiver's output side to identify that trigger signal and pass it, or a processed version of it, to the Arduino.

I wonder if there is another pin on the board I could read

You could try to hook up a multimeter to the pins/leads from the doorbell button. Positive to doorbell button pin, negative to power supply ground/doorbell battery.
Once you figure out which pin has voltage when the doorbell button is pressed, you can have that go into a digital or analog input in the Arduino. Make sure that the ground from the doorbell PCB and the Arduino are connected so that they'll have common ground and it should be detectable.


text:
Upload a .hex file, using a standalone ISP, without overwriting bootloader
Is it possible to flash a .hex file on an AVR MCU, which already contains the Arduino bootloader, using an AVRISP mkII, without overwriting the bootloader?
In my concrete situation, I have an Arduino Uno that I would like to program sometimes over an AVRISP mkII, and sometimes using the built-in programmer (i.e. by just connecting the Uno via USB to a computer).
For reference, given a compiled .hex file, this is what I use to upload it using the built-in programmer:
avrdude -c arduino -p atmega328p -P/dev/ttyACM0 -b115200 -D -Uflash:w:_build/image.hex:i

By default, this works as expected. I  can also use avrdude to upload it using the AVRISP:
avrdude -c avrisp2 -p atmega328p -U flash:w:_build/image.hex:i

This gets my image on the board as well; however, it also seems to overwrite the bootloader, i.e. after this, I can only use the AVRISP, and not the built-in one, to upload images. The only way back, at this point, is to re-flash the bootloader (via the AVRISP) on the Uno.
If I try to instruct avrdude to upload via the AVRISP without overwriting the bootloader:
avrdude -c avrisp2 -p atmega328p -D -U flash:w:_build/image.hex:i

then it fails in the verification phase:
avrdude: verification error; content mismatch

Based on @ChrisStratton's answer, I understand this means my problem actually starts before I even try to upload it, by the compiler emitting code which has addresses that should belong to the bootloader.
Here is the command I use to compile and link (I am not using the Arduino IDE at all)
avr-g++ -c -g -O3 -w -std=c++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -I.. -mmcu=atmega328p -DF_CPU=16000000L blinkPB5.cpp -o _build/blinkPB5.cpp.o -MMD -MF _build/blinkPB5.cpp.m
avr-g++ -Os -Wl,--gc-sections -mmcu=atmega328p -o _build/image.elf _build/blinkPB5.cpp.o
avr-objdump -S _build/image.elf
avr-objcopy -Oihex -R.eeprom _build/image.elf _build/image.hex

As explained above, I can use the same resulting .hex file both via the bootloader (by just uploading it via serial) and the AVRISP (by overwriting the bootloader).

To preserve the bootloader, you should use the -D option in the ISP command line just as it was used in the bootloader upload command line. This will disable usage of full-chip erase.
I expect you would end up with something like
avrdude -c avrisp2 -p atmega328p -D -U flash:w:_build/image.hex

However, it is important to add something which I overlooked when first posting this answer, which is that the ATmega series cannot do a partial flash erase via the ISP interface in the way that it can when the bootloader causes the chip to program itself.  This effectively means that you only get one shot at loading a program to an already blank area of the chip this way - after that, to load a different one to the same area you will have to do a mass erase of the entire chip and reload both the bootloader and the sketch, or else command the bootloader to erase the blocks where the sketch would reside.
Of course you will also need a hex file for your sketch with no contents that conflict with the bootloader, as while the bootloader would refuse to overwrite any of its own blocks when programming a sketch, the ISP is perfectly happy to try to write over the top of the bootloader, which would likely result in a logical AND of the bits of two different pieces of code, and cause the chip to boot to nonsense.  A typical Arduino board configuration reserves space for the expected bootloader, so if the one you are using matches the size reserved in the chosen configuration, you should not have a conflict.
Another option could be to combine the bootloader and sketch hex files, literally concatenating their contents one after the other into the same file.

Newer Arduino IDE version already create a hex file without and with bootloader

OK, I've tried that and that fails with
verification error; content mismatch, so I guess that confirms that the compiled .hex file starts at the wrong address. I'll edit my question to include details of how I am compiling.

@Cactus - the verification issue might be a limitation I overlooked when first posting this, which is that an ATmega cannot be partially erased over ISP.  So while this method would work the first time you load something to the sketch area, the second time you will get the garbled result of programing a new sketch over an old one without erasing it, which would indeed be likely to cause a verification error.


text:
Can I run a loop in setup()
Are loops not allowed in setup()? The following doesn't print anything inside the for loop to the serial terminal
Code:
void setup() {
  Serial.begin(9600);
  Serial.println("Ping");
  for (int i = 0; i >= 10; i++) {
    Serial.println(i);
    Serial.println("Pong");
  }
}

void loop() {

}

Output:
Ping

In principle yes, you can use a loop in setup() however this specific code
for (int i = 0; i >= 10; i++) {
  Serial.println(i);
  Serial.println("Pong");
}

will result in the body of the loop never executing, as the loop test i >= 10 is initially false.
You probably meant i <= 10
Generally speaking, it would be poor program structure to use a loop in setup() in place of one in loop(), however if you need a loop to apply similar operations to a range of things, or to briefly busy wait on a condition as part of setting up operation, that kind of thing could be appropriate.

You could (and I occasionally do) write your entire program in the setup() function. Setup() and loop() are constructs provided for your convenience, but they aren't necessary. In C/C++ compiled programs, it conventional for the C run-time code to call main(), and for main() to be written by the programmer.
It is conventional within the Arduino IDE world to bury the complicated stuff to let new user get productive quickly with a gentle learning curve.
That includes a pre-written main() that provides the calls to setup() and loop() for you.
The following main() function is typical of a number of pre-written Arduino main() functions, but you don't have to use the pre-written one; you can supply your own. It will need to call init(), and Arduino library function that prepares the hardware and software environment into a known state; after that you're good to go.
/*
 * main.cpp
 *
 *  Created on: Dec 13, 2011
 *      Author: jrobert
 */

#include "WProgram.h"

int main(void){
    init();
    setup();
    for(;;)
        loop();
}

extern "C" void __cxa_pure_virtual() {
    while (1)
        ;

}

While that was true years ago, this is not sound advice today (2015).  The current main() includes (if (serialEventRun) serialEventRun();)  after loop().  The user's loop() is expected to return; in order to yield time back for other services to run.

Correct, modern versions do include such a call. But that is exactly the point: The C main() function is where the run-time setup hands over control to the user; what the user writes from there down is up to him/her. Every program doesn't need every facility, and it is assumed that you know what you are doing when you circumvent the provided ones. Do also note, that unlike setup() and loop(), which you must provide (or the linker will fail), 'if (serialEventRun)` specifically honors the lack of such a requirement by testing for the existence of serialEventRun() before trying to call it.

... An equally reasonable addition to main() would be calls to similarly optional functions for timer events, Ethernet or WiFi events, and even some less critical interrupts. These support facilities aren't at all necessary; in fact I can't remember when I've seen an Arduino program that actually used serialEventRun() instead of managing serial on its own.


text:
Different behavior than in simulator: 5V pin works instead of GND. Why is that?
I use this simulator to check if what I want to do works. This is how it looks like:

I've recently realised that I've connected my RGB LED to 5V pin instead of GND like on schema. It worked perfectly that way (led worked and chanaged colors). When I connected it back to GND pin, it didn't worked.
When I went back to simulator and changed things to those that worked physically (using 5V pin) it didn't worked, but GND did.
Why do you think there are some differences? Can I use 5V pin instead of GND if it works?
My Arduino: Arduino Leonardo.

Maybe you hooked the leds up backwards?

The RGB LED's are available with common cathode and common anode.  That determines whether you connect the common pin to ground or to +5.
In your schematic you likely mismatched the selected part to what you actually have.  If you have the opposite type of LED as planned, just reverse the connection as you did.  You are not alone in this type of mistake.  see similar whot? here
A digital multimeter with a diode test mode would be very useful here.  The DMM would quickly measure the polarity of the diode tell you which lead connects to positive and which to ground.
But did it really work correctly?  Don't you also see that you have to write LOW to the digital output to make the LED light up?

Big thanks for answer. Can you recommend me some sources to learn more about those pins in arduino? Especially what are differences between 5V and GND? And why do I have to write LOW to digital output? Doesn't it mean: "stop the current"?

LOW takes the pin to GROUND level; in particular, it does not disconnect the pin. A HIGH pin can source current; a LOW pin can sink current. A LOW pin only appears to stop current flow if the circuit it is connected to is also at ground level. If the were at HIGH, or +5v level, the LOW pin would enable current flow by sinking it, which is probably what you saw with your LED.


text:
Input clock limit
If you use an external oscillator, and divide-by-8 internally, can you apply up to 160MHz on PB6? For example, can I use my 50MHz oscillator to clock my 328p @ 6250KHz? Note: when I say oscillator I don't mean resonator or crystal

No! 20 MHz max (Please see 8.8 External Clock, pp. 34). The 50MHz clock could be divided by 8 with a counter or the 150MHz clock by 16 with a faster counter.
Cheers!

So divide-by-8 doesn't apply to external oscillators?

Exactly. The external clock is max 20 MHz and then it may be divided internally.


text:
#define macro not in scope when i try to use IR library
My code keeps saying that that Button_8 and the rest of the #define macros are out of scope.
#include <IRLib.h>
#include <Servo.h>

#define MY_PROTOCOL SONY
#define RIGHT_ARROW   0xfd50af //Move several clockwise
#define LEFT_ARROW    0xfd10ef //Move servo counterclockwise
#define SELECT_BUTTON 0xfd906f //Center the servo
#define UP_ARROW      0xfda05f //Increased number of degrees servo
#define DOWN_ARROW    0xfdb04f //Decrease number of degrees servo moves
#define BUTTON_0 0xfd30cf  //Pushing buttons 0-9 moves to fixed  positions
#define BUTTON_1 0xfd08f7  // each 20 degrees greater
#define BUTTON_2 0xfd8877
#define BUTTON_3 0xfd48b7
#define BUTTON_4 0xfd28d7
#define BUTTON_5 0xfda857
#define BUTTON_6 0xfd6897
#define BUTTON_7 0xfd18e7
#define BUTTON_8 0xfd9867
#define BUTTON_9 0xfd58a7

IRrecv My_Receiver(11);//Receive on pin 11
IRdecode My_Decoder;
long Previous;
Servo myservo2;
Servo myservo;

void setup()
{
myservo.attach(8);
myservo2.attach(3);
My_Receiver.enableIRIn();
}

void loop()
{

  if (My_Receiver.GetResults(&My_Decoder))
{
   My_Decoder.decode();
   if(My_Decoder.decode_type==MY_PROTOCOL)
   {
       if(My_Decoder.value==0xFFFFFFFF)
       My_Decoder.value= Previous;
       if(My_Decoder.value == Button_9)
       {
       myservo.write(0);
       myservo2.write(180);
       }
     else if(My_Decoder.value == Button_8)
      {
         myservo.write(180);
          myservo2.write(180);
       }

    }
}
}

when i use a switch statement instead of the 4 and 5 if statement like so:
switch(My_Decoder.value) {
        case Button_8:   //do something; break;

it works, but i dont know why.

C++ is case-sensitive. Button_8 is different from BUTTON_8.


text:
Arduino C, Led > binary alternative all lights
I'm trying to alternatively have a random int generate a binary number with 4 lights.
This is my current code, However, it seems that all the lights(leds) go on, I don't think the minus option works. As in, it won't take a value from the currently randomized digit. (randombinary = randombinary - x)
I also tried just "randombinary - x"

const int button = 2;
const int redone = 13;
const int redtwo = 8;
const int greenone = 12;
const int greentwo = 7;
int randomnumber = 0;
int randombinary = 0;

void setup() {

  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(2, INPUT);

}
  void loop() {

delay(1000);

  int randomnumber = (1, 15);
  randombinary = randomnumber;

  if (randombinary >=8){
    digitalWrite(redone, HIGH);
   randombinary = randombinary - 8;
  }
 else {
   digitalWrite(redone, LOW);
 }

  if (randombinary >=4){
    digitalWrite(greenone, HIGH);
   randombinary = randombinary - 4;
  }
  else {
    digitalWrite(greenone, LOW);
  }

  if (randombinary >=2){
    digitalWrite(redtwo, HIGH);
  randombinary =  randombinary - 2;
  }
  else  {
    digitalWrite(greentwo, LOW);
  }

  if (randombinary >=1){
    digitalWrite(greentwo, HIGH);
  randombinary =  randombinary - 1;
  }
  else  {
    digitalWrite(greentwo, LOW);
  }

  }

Would appreciate any help!

Please edit your question and state what you want to happen.  Eg, "Generate a random number.  Turn on light x if ..., turn off light x if ..., turn on light y if ..., turn off light y if ..." and so forth.

Code review (one possible solution can be found below)

Absolute numbers in the code, like 15 as the limit for the random numbers are generally considered harmful. It would be better to give all absolute numbers a constantsname and use these throughout. The OP code did not use the constants for the pins, for instance.
Writing similar pieces of code in a row makes maintenance hard. Therefore, group similar items in any kind of list, like an array, and iterate over them.
Functions should have expressive names clearly stating what is going on inside.
Functions should be short and concise, ideally having only a few lines.

Try something along these lines:
// setting the number of bits to analyze, corresponding pins and corresponding powers of two.
// the latter is here for instructional purposes although it is redundant.
const int numberOfBits = 4;
const int randLimit = 15;   // 2^(1+numberOfBits)-1 actually;
int ledPins[numberOfBits] = {13, 8, 12, 7};
int bitValue[numberOfBits] = {8, 4, 2, 1}; // the powers of two

void turnOffAllLeds ()
{
  Serial.println ("turning all off");
  for (int i = 0; i < numberOfBits; i++)
  {
    digitalWrite (ledPins[i], LOW);
  }
}

void selectivelyTurnOnLeds(int value)
{
  turnOffAllLeds ();

  // now for each bit, check if it is set in the value, if yes: turn on corresponding led
  for (int i = 0; i < numberOfBits; i++)
  {
    if ((value & bitValue[i]) > 0)
    {
      digitalWrite (ledPins[i], HIGH);
    }
  }
}

void setup()
{
  for (int i = 0; i < numberOfBits; i++)
  {
    pinMode (ledPins[i], OUTPUT);
  }
}

void loop()
{
  selectivelyTurnOnLeds (random (randLimit));
  delay (1000);
}

P.S. When posting a question, please also post what your code is supposed to do. If it were not for a lazy prechristmas workday, I would not have taken the time to reverse engineer your code.

Thank you !! My apologies for the late reply, I'm working on it now, Yours is very tough, I cannot seem to get it working, yet I myself am not sure how exactly you've done it, this is a bit over my level. I for example, don't know how where the "i" is linked to, nor do I know why you put (int value) after the selectivelyturn... void. I thank you kindly, and I'm sorry for not being clear in my question, it was the first time I've entered a forum for help.. It's always giving the value of 15, but the leds change nevertheless

int randomnumber = (1, 15);

Guess you have missed to call random. That statement actually always returns 15. C is a strange language.
int randomnumber = random(1, 15);

Cheers!

Thanks a bunch! You're a savior, Now only I have to make it so that I have the button input match the random binary which results into a victory LED if it's completed. :S It's going to be tough

I actually just moved it into a new void, as due to the loop, it kept recreating a new binary. Now it only shows the value of 8, each time.. do you happen to know what could possibly be wrong? Nothing in the code changed

Something must have changed if you moved it into a new void! Post the new code under the old to keep the history of the question.

Thank you for your time, I've replied to this inquiry myself with the new code and issue.

So here's the new version, very strange, when I set the number on random, it doesn't work. However, if I enter a number myself, it does.
const int button = 2;
const int redone = 13;
const int redtwo = 8;
const int greenone = 12;
const int greentwo = 7;
int randomnumber = 0;
int randombinary = 0;

void setup() {

  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(2, INPUT);

      maarten();

    }
      void loop() {

      }

      void maarten(){

      int randomnumber = random(1, 15);
      randombinary = randomnumber;

    if (randombinary >=8){

      digitalWrite(redone, HIGH);
      randombinary = randombinary - 8;
    }
    else {
      digitalWrite(redone, LOW);
 }

    if (randombinary >=4){

      digitalWrite(greenone, HIGH);
      randombinary = randombinary - 4;
    }
    else {
      digitalWrite(greenone, LOW);
    }

    if (randombinary >=2){

      digitalWrite(redtwo, HIGH);
      randombinary =  randombinary - 2;
    }
    else  {
      digitalWrite(greentwo, LOW);
    }

   if (randombinary >=1){

     digitalWrite(greentwo, HIGH);
     randombinary =  randombinary - 1;
   }
   else  {
     digitalWrite(greentwo, LOW);
  }

  }

But now the setting (maarten) is only done once?

Please do the edits in the main question so folks know which code to work with.  I'd replace the conditional subtraction math with bitwise operations on an unsigned value  "unsigned int randombinary; ... digitalWrite(redone,randombinary && 0b1000 ); ..."


text:
Arduino DC motor causes disturbance. What can cause it?
I tried to fix this problem the whole weekend but, after no success I decided to post it here. I would really appreciate any help.
The problem
The Wi-Fi module activates the DC motor and lets it run for 3 seconds, but when the DC motor stops after that 3 seconds, the Wi-Fi module and display don't respond anymore.  It only works once.  (After I push the reset button the same thing happens.)
Question
What causes this disturbance? Any advice on my circuit? (I included a Fritzing Diagram because I am bad at drawing schematics)

#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
SoftwareSerial ESP8266(9, 8); // RX = 8 en TX = 9

#define DEBUG true

boolean FAIL_8266 = false;
int LED = 13; // led op 13

int secondeAan = 3000;

String my_AP_SSID = "myID";
String my_AP_Pass = "myPass";

void setup()
{
  // -- stel led in --
  pinMode(LED, OUTPUT);

  // -- lcd scherm --
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 1);

  do {
    ESP8266.begin(115200); // start communicatie met esp8266

    //Wait Serial Monitor to start
    while (!Serial);

    lcd.clear();
    lcd.print("--- Start ---");

    ESP8266.print("AT\r\n");
    delay(500);

    if (ESP8266.find("OK"))
    {
      FAIL_8266 = false;
      sendData("AT+RST\r\n", 4000, DEBUG);
      sendData("AT+CWMODE=3\r\n", 2000, DEBUG);
      sendData("AT+CWJAP=\"" + my_AP_SSID + "\",\"" + my_AP_Pass + "\",9,4\r\n", 2000, DEBUG);
      sendData("AT+CIFSR\r\n", 2000, DEBUG);
      sendData("AT+CIPMUX=1\r\n", 2000, DEBUG);
      sendData("AT+CIPSERVER=1,80\r\n", 2000, DEBUG);

    } else {
      lcd.clear();
      lcd.setCursor(0, 1);
      lcd.print("Module have no response.");
      delay(500);
      FAIL_8266 = true;
    }
  } while (FAIL_8266);
}

void loop()
{
  // Get the number of bytes (characters) available for reading from the serial port
  if (ESP8266.find("+IPD,"))
  {
    lcd.clear();
    lcd.print("Nieuwe connectie");
    // -- sluit connectie --
    motorToggle();
    sendData("AT+CIPCLOSE=0\r\n", 100, DEBUG);
    sendData("AT+CIPCLOSE=1\r\n", 100, DEBUG);
    sendData("AT+CIPCLOSE=2\r\n", 100, DEBUG);
  }
}

void motorToggle () {
  digitalWrite(LED, HIGH);
  lcd.clear();
  lcd.print("eten gegeven");
  delay(secondeAan);
  digitalWrite(LED, LOW);
  delay(200);
}

String sendData(String command, const int timeout, boolean debug)
{
  String response = "";

  ESP8266.print(command); // send the read character to the esp8266

  long int time = millis();

  while ( (time + timeout) > millis())
  {
    while (ESP8266.available())
    {
      char c = ESP8266.read();
      response += c;
    }
  }

  if (debug)
  { lcd.clear();
    lcd.print(response);
  }

  return response;
}

Can the Uno provide 3.3V power for the esp8266? Should have a 3.3V regulator from 5V instead. And a few very large capacitors. This reference might help: http://iot-playground.com/2-uncategorised/17-esp8266-wifi-module-and-5v-arduino-connection. Cheers!

@MikaelPatel  Thanks for the comment! Do you think this causes the disturbance? The esp8266 works fine without the dc motor running

Exceeding the 3.3v regulator capability is possibly an issue, yes.  You might also put a small ceramic disc capacitor across the motor terminals or one between each terminal and the can.  That used to be considered necessary to suppress interference to lower frequency analog RC gear, it may be less so at 2.4 GHz but still isn't a bad idea.

Are you sure this is a hardware issue and not a software issue? Can you post some example code? Based on the information provided, it is impossible to know if it is infact the motor that causes the issue.

Since the motor runs open loop, simply disconnexting the motor while running software that assumes it is still there should clarify if it is a hardware or software issue.

@ChrisStratton MattClark   My guess it is a hardware issue because, when I disconnect the battery that supplies the dc motor everything works fine. I shall add the arduino code to my post

The battery wiring looks odd in the diagram, is it correct? Replace the motor with an open circuit or dummy resistor to eliminate it as a cause.  Is your FET and resistor working as expected? Can you check it out with a DMM?  A 2k2 resistor should limit the draw on the UNO to ~2mA.

Thanks for the help everyone. I fixed it by using Capacitors. They suppress the noise that the dc motor produces. I found my information  here

There are a couple of things that could be causing your problems:

The current draw of the motor, especially at start up. The motor may be drawing enough power to pull down the voltage at the processor causing it to crash, or
You may be seeing transients as the motor starts and/or stops that are causing the processor to crash.

One way you could detect problems like this is to use the on-board LED as a heart beat or run indicator. You could either blink it in loop() or do something like turn it off just before starting or stopping the motor and then back on afterwards. If the blink stops or if the LED goes out then you know that the processor has stopped running.
As a general rule, except with the tiniest of motors, I'd suggest using the Arduino to control a transistor that controls the motor from its own power supply line (it could be the same supply as the one the feeds the Arduino, just don't run the motor power through the Arduino). That and the suggestions in the comments will go a long way towards isolating the Arduino from the motor and power disturbances it will cause.

Note that the poster is already "using a transistor that controls the motor from its own power supply"

Ack, missed that…


text:
What is the Mark and Space of Ir remote of Airtel?
Can you please tell me to find out Airtel IR Remote Mark and Space coding. I am making a project in which i have to Airtel IR Remote But I do not have decoding style of it. So please help me out. Any help will be appreciated.
Thank you

What have you tried? Isn't it a standard ir-protocol? The IRremote library supports raw ir-data.

I have tried IRremote library of arduino, But it is not decoding the Airtel ir remote code. I found that there is no protocol set for airtel in its library. So if you have any idea please suggest me.

Just write a simple sketch, that logs the lengths of marks and spaces to the serial console. I did just that to decode the Samsung TV remote protocol. I loaded the values into excel to easily get the min and max lengths etc.

I have tried that too,  #Gerben, but getting the garbage output ( mark and space ). Th is is not able to distinguish between the header, bit- mark & space. All are coming same. And the main part, it is not giving the code length that I am sending through Airtel ir remote.

If it's garbage, then there is something wrong. Are you using the correct frequency receiver? Could you post a sample output. There aren't a lot of people from India here.


text:
Issue with Serial PINs (RX/TX) on Arduino
I have an issue with an Arduino Nano.
I want to communicate with it through the Serial-Port. Meaning I want to send and receive Serial commands. With USB and the "Serial Monitor" this works nice.
Now I have connected the COM-Port of the PC with Adruinos Digital Pins 0 and 1 (RX and TX) and a GND PIN. (3 Cables total).
Here is a minimal example of my Code:
void setup() {
  Serial.begin(9600,SERIAL_8N1);
  Serial.println("Start");
}

void loop() {
  Serial.println("Hello World");

  delay( 1000 );
}

The Serial Monitor says:
Start
Hello World
Hello World
Hello World
Hello World
...

Putty however says:
▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒::
                                                     ▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒    ▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*

Putty is connected with
- BaudRate: 9600
- Data Bits:
- Stop Bits: 1
- Parity: None
- Flow Control: None
What is wrong here?
Update:
The PC has a 9-pin D socket (Image)
This is connected to a RS232 to RJ45 connector (image)
From the RJ45-Cable I used the Brown, Blue, and White/Green Cable to connect with the Arduino

Is this a 9-pin D socket built in to the PC?

I have updated my question

RS232 is not TTL. You need a level converter. For more details see https://www.sparkfun.com/tutorials/215.

Thanks. That's it! I just found it in the documentation: "Don't connect these pins directly to an RS232 serial port; they operate at +/- 12V and can damage your Arduino board." https://www.arduino.cc/en/Reference/Serial


text:
Flashing dotStar LED
I have a DotStar LED strip that I want to make it blink (e.g., 1 second on, 5 second off in an endless loop).
I tried doing so via the script below but it does not work. Can someone please explain me how to do so?
Script:
#include <Adafruit_DotStar.h>
#include <SPI.h>

#define NUMPIXELS 10

#define DATAPIN    4
#define CLOCKPIN   5
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);

void setup()
{
  strip.begin();
  strip.show();
}

void loop()
{
  strip.show();
  strip.setBrightness(155);
  for (int i=0; i <= 10; i=i+1) {
    strip.setPixelColor(i, 255, 255, 255);
  }
  delay(1000);

  strip.setBrightness(0);
  delay(5000);
}

There's absolutely nothing in that sketch that shows an attempt at achieving what you want. Are you sure you posted the right code?

This is the starting code and I hoped that the delay will cause at least a blink but it did not work.

You will only get a blink if you turn the LEDs on, then delay, then turn them off, then delay again. At the moment you are just turning them on and never off.

The authors of the library are not fans of the setBrightness() method and advise handling it yourself.
The following code should do what you want.
#include <Adafruit_DotStar.h>
#include <SPI.h>

#define NUMPIXELS 60 // This should be the total number of LEDs in your strip

#define DATAPIN    4
#define CLOCKPIN   5
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);

void setup()
{
  strip.begin();
  strip.show();
}

void loop()
{

  // loop through each pixel in the control array setting it to the colour mix you want.
  for (int i=0; i <= NUMPIXELS; i=i+1) {
    strip.setPixelColor(i, 25, 25, 25); // Even 25 on my strip gives reasonably bright flash
  }

  strip.show(); // Then push the control array to the strip
  delay(1000); // and leave it set for a while

// Then do it again for the 2nd brightness in your scheme

  // loop through each pixel in the control array setting it to off.
  for (int i=0; i <= NUMPIXELS; i=i+1) {
    strip.setPixelColor(i, 0, 0, 0);
  }

  strip.show(); // Then push the control array to the strip
  delay(1000); // and leave it set for a while

}

Both here and in the OP: If you have 10 pixels, and you go from 0 to 10, you have tried to address 11 pixels. The middle condition check on the for loop ought to be a plain “<“.

The basic idea of the program you're trying to write is:
loop() {
  strip.show(); // Turn LED strip on.
  delay(1000);  // One second, argument is milliseconds.
  strip.setBrightness(0); //Turn LED strip off.
  delay(5000);
  strip.setBrightness(155); //Turn LED strip on.
}

I haven't used the Adafruit DotStar library, so there may be details that I'm missing (like do you need to do a strip.show() after setting the brightness). But maybe this is enough to get you thinking about how to construct the program.
The real joy in hacking with something like this is the experimenting and the learning. Take the time to try to understand how you project works and to predict what will change as you modify the code and how you can tell if it is working the way you expect – that will get you a long way towards being a strong programmer.
When you're troubleshooting something new and/or unfamiliar, one thing that really helps is to break down the problem into simple steps. For example with this project a good first step would be to get the DotStart strip to turn on. Then see if you can get it to turn off. Build it up piece by piece.

Thanks, I updated the script in the question based on your suggestions but it still does not work, any idea why?

Can you describe what it does do, and what you're expecting it to do? "Does not work" is very hard to troubleshoot – especially remotely when you can't see the behavior.

OK, Only LED number 10 in the strip is on and no flashing.


text:
RFID tag "location identification"
Can an RFID tag be used to identify a room? For example, I walk into a room, and the RFID receiver tells me that I am in say, the living room. Would it be possible for a tag to ping back the signal from a distance of 10ft? Or is there a similar technology like RFID that can extend to a much greater range?

You could attach them to the doors. 10ft is way to much. RFID only works within a few inches. Something like iBeacon/Eddystone (Bluetooth) would perhaps be an alternative.

There are newer long range RFID solutions. You can do a google search on "Ultra Long-Range UHF Wireless RFID Sensors" for more information, but almost all of these systems are still proprietary (i.e. I'm not aware of any hobbyist breakout-boards based around UHF tags yet).
The Disney MagicBands are an exact use-case of your question: Their magic bands use a combination of 13MHz RFID tags, and a new UHF active tag (it requires a small battery). They use them to collect data on how people flow through their Walt Disney World facility.  What bathrooms see the most activity, and when, for example.  There is actually a pretty decent amount of information available about the technology used in the Disney Magicbands if you're curious about the technology.


text:
Arduino Uno Wire Transmission Issues
I am developing code to run a word clock and have noticed a slight problem. I am using a DS3231 to keep time, and using the Wire library to communicate with it. I ping the DS3231 every second to get the time and check a few other things. This is all working fine except when the clock loses power. It seems that occasionally upon loss of power to the Arduino, the time that that the DS3231 reports when it regains power, is incorrect.
My thought is that the power is getting cut in the middle of various Wire.read() commands and this is causing the chip to mess up and reset its own time, but I am not sure. The DS3231 has a battery backup attached to it, and that battery has only been plugged in for a month or two, so I don't imagine that is the problem.
I am wondering if anyone has an idea how I can deal with this potential problem, or if there is some way I can clear the Wire library before it starts up again.
I have put some sample code below to give an idea of what I am doing. There is of course much more code, but this is the only relevant part.
#include "Wire.h"
#define kClockAddress 0x68

void readDS3231time(byte * second, byte * minute, byte * hour, byte * dayOfWeek, byte * dayOfMonth, byte * month, byte * year) {
  Wire.beginTransmission(kClockAddress);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(kClockAddress, 7); // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}

void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year) { // sets time and date data to DS3231
  Wire.beginTransmission(kClockAddress);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}

void setup() {
  // put your setup code here, to run once:
  Wire.begin()
   // DS3231 seconds, minutes, hours, day, date, month, year
   //setDS3231time(0, 36, 10, 2, 21, 12, 15);
}

void loop() {
  // put your main code here, to run repeatedly:
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year; // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  delay(1000);
}

By incorrect, do you mean 01/01/00 01 00:00:00?

@Gerben no, I mean off as in like a few hours or a few days.

That's weird. I'd check the battery voltage. The DS3231 should transition to battery power just fine.

  Wire.requestFrom(kClockAddress, 7); // request seven bytes of data

Just because you request 7 bytes doesn't necessarily mean you get them. I suggest before reading the date and time you set all those variables to something invalid (like 0xFF). Then after reading, if you get 0xFF in any of them, ignore the entire lot.

we are sending a start bit again, when we never sent a stop bit previosuly. ... Does this sound reasonable

Not really, because I2C doesn't have start and stop bits, it has start condition and stop condition which are specific changes to SDA and SCL which don't happen at any other times. See I2C for a description. I would be checking the data for validity, as I said. There is no other way of knowing for sure that a transmission wasn't interrupted. If you request 7 bytes of data, the library tells you that you got 7, even if you did not. However if it cannot even find the target device, it returns 0 as the number of bytes (you aren't testing for that anyway).
The very least you should do is test for a valid connection, eg.
if (Wire.requestFrom(kClockAddress, 7) == 7)
  {
  // read the data
  }

That at least confirms that the clock chip responded in some way. Not checking error returns from function calls, where documented, is not wise.
Similarly when you send your command.
  Wire.endTransmission();

That should be:
if (Wire.endTransmission() != 0)
  {
  // handle error here
  return;
  }

You have no tests in your code for either the sending or receiving to be working. And then you are unconditionally using the resulting time values. That's like opening a file, and reading it, without checking if the file exists.

I think the actual problem came about with the I2C interface with the DS3231. If the power is lost to the device in the middle of an I2C read, it never gets the stop signal or some other signal. Because of this, some bogus data either ends up getting written, or the next time we attempt to start a transmission (upon return of power) we are sending a start bit again, when we never sent a stop bit previosuly. At least this is my running assumption as of right now. Does this sound reasonable, or is there a way to fix that?

See amended answer.


text:
Use Arduino to transmit signal to a vibrating pager
I am an engineer at a machine shop. When a machine stops running, I want to be notified via a vibrating pager (like at restaurants). My plan is to attach the arduino board in the machine and when the machine stops (quits vibrating) I want it to trigger the vibrating pager that I have in my pocket. By what means can the arduino communicate with the vibrating pager to cause it to go off? SMS? Wifi? Bluetooth would likely be out of range. Other options?

I'd go with an internet solution (wifi), and use an online service to send a pager message. That way, in the future you could change/add other types of notification, like: SMS, e-mail, push-notification, webpage (with e.g. history information)

If the machines are CNC, add a program step at the end of the G-code to turn on a digital output to the Arduino, rather than trying to detect  “when the machine quits vibrating”

I don't write the g-code, so I'm not sure how that would work. But that sounds like a good idea. I will talk to them about that.
Let's say the digital output is turned on..then how would I make the Arduino begin communication with the receiver? Is it just a matter of coding something along the lines of "if there is digital input, do this ..."?

To do SMS through a GSM shield like https://www.arduino.cc/en/Main/ArduinoGSMShield with a dataplan, and the device should be accessible anywhere you can get reception.  With a wifi shield like https://www.arduino.cc/en/Main/ArduinoWiFiShield101 you could make it work within your wifi network.
Sparkfun's sales guide at https://www.sparkfun.com/pages/wireless_guide indicates there are a few bluetooth modules that reach 100m, so if your range is less than 100m, bluetooth is a possibility.


text:
Marlin Firmware troubles: <time.h> error
I am trying to upload the Marlin Firmware to my 3D printer's Arduino Mega 2560 and I am experiencing a problem. It keeps saying:
qr_solve.cpp:7:18: fatal error: time.h: No such file or directory
 #include <time.h>
                  ^
compilation terminated.
Error compiling.

Please help as I'm lost as how to fix it, because I try to scroll up to see what is highlighted in red and I can't find anything.

This might be helpful; https://groups.google.com/forum/#!topic/deltabot/IknX0wamH2M

Gerben's comment fixed my issue.

Hi @Rdawg33 - If one of the answers below solved your issue, can you mark it as the accepted answer, using the tick icon next to the answer, in order to remove your question from the Unanswered Questions list? Thanks.

From Gerben's link to the googlegroups's thread, Delta robot 3D printers › compiling jcrocholl's Marlin (Ubuntu), as Francis Mallet points out, at the bottom of the thread, it is necessary to change <time.h> to "Time.h":

I copied the content of the Time library right in the Marlin folder, then changed line 7 of qr_solve.cpp from #include  to #include "Time.h"
The code compiled and everything seems to be working ok.

So, to iterate, the line in qr_solve.cpp:
#include <time.h>

becomes
#include "Time.h"

Now, Marlin.ino should compile as expected.
Note that the latest version of Marlin, from github.com/MarlinFirmware/Marlin no longer suffers from this issue, but older versions of the software, such as github.com/gpfwestie/kossel_2020_sintron will do, due to line 7, in qr_solve.cpp.

interestingly changing to Time.h didn't work for me (arduino sdk 1.6.9) however commenting out the include line did...


text:
How Master and Slave concept works with Bluetooth?
From what I understand the master has primary control over the slaves and communicates with them. A master must always be present as well, and can be connected to (up to) 7 slaves.
Question

If I have 2 arduinos with Bluetooth communicating with each other
from within a radius of 80 meters or less, which arduino do I set as
the master and which do I set as the slave? (what dictates which one should be set as master, etc.)

I want both arduinos to be able to transmit data to one-another (where neither has privilege over the other), so in my mind this is more like two slaves communicating. Both devices have the same controls on them and will effect the other devices the exact same way.

How does the communication process work exactly, and how should more
arduinos be addressed if they are to be added with similar
privileges?

Well, master/slave concept for Bluetooth resides on the protocol, not in the communications. On few words, this means Bluetooth Master is who has the ability to initiate connection with a peripheral (or slave), but onces connected both master and slave basically can interchange information without restriction (limited by application). If your bluetooth module or implementation has a SPP (serial port profile https://developer.bluetooth.org/TechnologyOverview/Pages/SPP.aspx) once the master finds and connect to the slave, information can flow in both ways like a chat (actually, chat application is the most common usage example of bluetooth modules)


text:
What does "Arduino compatible" mean?
I wanted to buy an Arduino (ATmega) 2560 (8 Bit MCU) via Amazon. But there was no Arduino visible. There was only a

SainSmart 2560 and

SunFounder 2560

On both websides (SainSmart and SunFounder) there is the information that they are Arduino compatible. But all three boards (Atmel-orginal, SainSmart, SunFounder) do not look similar... There are differences. Is it possible to buy one of those boards without:

checking the datasheet differences
having problems with the Arduino Ethernet Shield !?

So, what is compatible ?

It means whatever the manufacturer says it means.

The most frequently annoying difference tends to be how the USB-serial function is implemented, for example with a CH340 instead of an FTDI or an ATmega16u2.  FWIW, an Ethernet shield on an Arduino is generally speaking a bad idea - people have made them work, but it's an absurdly expensive way to get very limited network functionality.

Arduino Compatible can mean many things, but most of the time it means that some company has made something they sell to a customer that supports development with the Arduino IDE.
The thing is that most Arduino Compatible units use the Atmel processors, but some use others too. Third party developers then make "board"-projects that you can add into the Arduino IDE.
Be aware though that you in some cases can run into issues if you dont do your homework, here are some of the issues you can run into:

Some "compatible" boards use different architectures, so even if you can do many things with the Arduino IDE, maybe some sensor libraries are not supported. (Might have to be hacked or updated)
Some "compatible" boards have different USB-circuits (if they have them at all)
Most of the boards you buy off aliexpress, banggood etc. do not come with instructions at all and some times they differ from the "original" design (might be better, might be "the same" or might be worse.).

I'm not trying to scare you off, but just my experiences. You can find a lot of fun things on those sites like clones of lilitiny with the AtTiny 85. One example is in my blog heer: http://mjelde.blogspot.no/2015/12/lilytiny-lilypad-attiny85-wearable-iot.html
The main issue with the clones I've had is that some times they differ in some ways that the first times will make you scratch your head. Like: ESP8266 is Arduino Compatible with the boards manager added ( https://github.com/esp8266/Arduino ), BUT: The input pins are not "correct" marked. So you should then add constants to "remap" them in your code.
Also the ESP8266 does only support 1V analog read, while many Arduinos support 5V. But you can "fix" this with an 16bit ADC (analog to digital converter). The ESP8266 only has 3.3V also, so you cant run sensors that "must" have 5V, without then giving them a different power circuit :)
The AtTiny 85 LilyTiny clone i bought in a pair of 2 from AliExpress works fine and works different than the rest of the Arduinos. Uploading to those for instance means you leave them disconnected and then you hit upload in the IDE. Then it says in the status window to connect it, which you then do.
Then it uploads. It has very few inputs, but it's very cute id say. Primarily it's made for wearable and of course it has a lot of short comings compared to a large arduino board. But you can of course use it to control RGB leds, etc.
Remember to always check specifications (3V vs 5V, how much analog read resolution can it handle, etc). There is the sensor vs board (some sensors work on both 3.3V and 5V, some work only on 5V, some only on 3.3V).
For going to 5V to 3.3V you usually use a voltage divider. Either you can buy pre made ones or you can make it based off three resistors and some math :-)

So you can use the same Arduino software and code to connect to and update the board?

Arduino is an open-source electronics platform. Lots of other manufacturers make Arduino-compatible boards, not just Arduino/Genuino. I have used both Arduino-branded and 3rd party manufactured boards without encountering any issues. I have not used boards by SainSmart or SunFounder, but they look compatible from a specifications perspective.
If you are worried about compatibility with the Ethernet Shield, you could always buy them as a pair (e.g. SainSmart Arduino Mega 2560 + Ethernet Shield for Arduino UNO Mega Duemilanove R3 AVR PIC ATMEL Robot) just to be on the safe side.

The other answer seem to focus on "compatible" meaning "works with the IDE" but that's not what they mean here. "Compatible" in this context means "clone of the original".
You can count on these boards being functionally identical. The microprocessor and pinout are the same, which is what a shield cares about. The peripheral circuitry might vary slightly, but that's not a big deal. They might (as mentioned) have a different USB-Serial chip but that won't cause any issues once you install the appropriate drivers on your PC.


text:
Connecting ESP8266 with Arduino Uno - WiFi shield not present
I have an Arduino Uno and ESP8266. I want to connect and control an LED from a web server. I made a connection referring to this:

I uploaded the WifiWebServer code to the Arduino, and applied my router's credentials.
char ssid[] = "Router SSID";      // your network SSID (name)
char pass[] = "Router's WPA Password"; `

I'm getting a "Wifi Shield not present" message from the Serial Monitor. I even tried giving external 3.3v power supply to my ESP8266 module, but no change. What am I missing here? Can someone help me fix this issue?

The WifWebServer isn't compatible with the ESP8266, look up example code for the ESP8266 in stead.

Yes, I looked up ESP8266 samples, sounds like we need to have FTDI to load WifiWebServer into ESP... Is there any other way to load Wifiserver into esp directly without FTDI?

Actually  I made a mistake assuming esp8266 itself can act as a Wifi-Shield when it is connected with Arduino Uno, But it won't. So we can't use any Wifi shield examples for Arduino with esp8266

From your diagram, you appear to be using an ESP8266-01?
Another ESP8266 AT command library that may be of interest/use.
Note that the AT command libraries are very dependent on the version of the firmware that you have on the device.  Depending on when/where you bought the device, this firmware will vary significantly.  I've not had any of the libraries work correctly with current versions of the firmware.
Run the AT+GMR at command (using your serial terminal) to determine the firmware version.  If you're on Windows/PC updating the firmware to a previous version (the 0.9.x.x range seems to be the most stable according to my research) is relatively straightforward.  If you're on Mac, it's not as straightforward...
Official/current release of the firmware is available from Espressif's Github repo.
There are plenty of directions on the net for getting firmware onto the ESP8266 for both Mac and Windows/PC.  YMMV as to their accuracy/ease of use.
Note that different versions of the firmware default to different baud rates.  Some default to 115200, others to 9600.  If you decide to use SoftwareSerial (rather than Serial, which your diagram suggests is what you're currently using) you'll need it to run on 9600.  I've not personally tested what Serial supports up to (but my understanding is that you can run up to 115200). Note that there are different commands for setting the ESP8266 AT command firmware baud rate depending on the firmware version/supplier.  The official SDK uses the AT+IPR=9600 command.  This stores the baud rate to the device (i.e. you don't need to send it every time, just once and it's then persistent).
If you haven't already, I'd recommend you get the system working with a simple serial terminal program (CoolTerm, for example) before getting into Arduino-land.
Note that the ESP8266 does not reliably run from the 3v3 power rail on the Arduino. The ESP8266 requires up to 300mA, the Arduino is capability of around 50mA to my understanding.  Symptoms of insufficient power include random resetting of the device.  Best to run a separate 3v3 source to the ESP, or if you have a strong enough 5v supply, use a step-down converter.  Your diagram indicates you're using a standard Arduino, which runs 5v out of the serial pins (or digital outs), but your comments indicate you're running 3v3 (which means you're probably running a 3v3 Pro Mini or similar)?  If you're not running a 3v3 device, you'll definitely need to run a 5v-3v3 logic level converter (I can't link to examples due to not having enough reputation points—but these are relatively easy to get from SparkFun or similar.  I picked up a combined step-down converter with logic level converter which does both tasks.
Lastly, If you don't need the ADC from the Arduino device for your application (which it sounds like you don't given your project description) I'd strongly recommend you reconsider the advice from gmag11 and yeti re: running Arduino on the ESP8266.  It is much more stable, and the extra SRAM will make a big difference with processing/building HTTP request strings etc.  I wasted a lot of time (unsuccessfully) trying to get AT commands working before switching to Arduino on the ESP8266, which has been a breeze by comparison.

You can program and upload code to ESP8266 using Arduino programming environment, reusing code and libraries with small changes. Check https://github.com/esp8266/Arduino for more information.
For most tasks ESP8266 may substitute Arduino board completely. It has more flash, more RAM and integrated WiFi, and is faster (80MHz).

The WiFiWebServer tutorial describes how to use the ArduinoWiFiShield. This shield is based on different WiFi hardware than the ESP8266 modules.
You need a WiFi library driving the ESP8266 modules instead, e.g WeeESP8266.
Your favourite internet finding machine sure will find lots of similar libraries.
A different approach would be ArduinESP (https://github.com/esp8266/Arduino), which means to develop code to run on the ESP8266 module directly.

...aaaand please rethink your wiring. The ESP8266 modules are a pure 3.3V pets and your wiring connects a 5V logic signal directly to the ESP8266 and this may send your ESP8266 into the digital heaven with or without waving goodbye using blue smoke...

Have ESP8266 library in my arduino & connected with 3.3V only, I don't want to directly upload firmware into ESP8266, but via Arduino Uno. and Wifi Shield is different from ESP8266 module. I use esp8266 only

ArangaNathan has posted another Fritzing diagram with the same errors as the opening diagram:

You can't drive the ESP8266 from the Arduino 3.3V pin as it can only supply 50mA but the ESP requires > 200mA to transmit properly.
All I/O wires between Arduino and ESP must be level shifted from 5V to 3.3V otherwise you will damage the ESP. It may not happen straight away, but it will happen.
If you wire Arduino Tx <-> ESP Tx and Arduino RX <-> ESP Rx you must remove the Arduino MCU chip completely before powering on, and use the Arduino IDE monitor to send commands to the ESP.
If you don't remove the MCU then you have to wire Arduino TX->RX and Arduino Rx<-TX.
If also you want to use the Arduino IDE in this mode (MCU installed) then you can't wire ESP TX/RX to D0/D1 and must use other pins instead (e.g. D2/D3) and SoftSerial to create another serial UART port.

Fritzing's wiring diagram has errors. 1) the serial connections wrong way around. You need to swap them so that
Arduino TX -> ESP Rx and
Arduino RX <- ESP Tx. Also 2) the ESP-01 require more than 200mA so supplying voltage reg cannot be provided from the Arduino 5V pin. It must be supplied by VIN with a supply able to provide 1A.

For the esp you must use an external 3.3v power source (300 mA or more), and a logic level converter for the esp Rx (arduino Tx is in 5v logic).

Here is how to send commands to an ESP8266, without using an FTDI Programmer (NOTE: the IC used is LM117 (5V to 3.3v) IC for level shifting.)

Wait, it does not shift anything else than 5V to 3.3V. You have to shift other pins too.