text:
Send button press over RF
I'm trying to send a button press over RF (performing a closed circuit operation on the receiving end).
I have a controller with an UP and DOWN button. Unfortunately I am limited to the cable length, and would like to extend it with radio frequency. The controller has one cable for GND and one each for the corresponding UP and DOWN buttons.
The RF units is the typical 433mhz bought online (ebay).
Can I in someway send the signal over RF (directly on the data pin of the transmitter) without hooking it up to a microcontroller (Arduino)?

You could buy specialized an encoder/decoder IC pair like the HT12D and HT12E. They will serve as a bridge between your controller and the RF module; no need for an MCU. I've used them to control an RC car, so they should work just fine for sending 2 button presses.

No. You need a micro-controller at both the sending, and receiving sides.
eBay does set RF remotes with a few buttons. This might be easier and cheaper than making your own.

Here what might suit you http://www.ebay.com.au/itm/DC-5V-433mHz-2-Channel-Wireless-Delay-Relay-Remote-Controller-/281937100910

The reason you need a micro-controller at each end is the radio doesn't send data in a digital way.  It modulates the signal it sends to encode the data.  I'm afraid that's about as far a I got before I got lost and decided to give up.


text:
Adding Date and Time to existing sketch
I am currently trying to add a clock functionality to my current sketch for a peristaltic pump [run by NEMA 23].
The current sketch waits for a button on my breadboard to be pressed, it then runs the motor for a specified amount of steps and then stops and waits for the next press of the button. It also displays the amount of steps to the Serial Monitor. I have a working sketch for a clock using an RTC DS3231 module and have unsuccessfuly attempted to fit it into my motor sketch. The problem is, the clock seems to be taking precedent over the rest of my sketch, so pressing the button no longer works and the time is simply consistently output onto the Serial Monitor.
The ideal functionality would be the time and date displayed on LCD constantly (or at least blinking so rapidly that one could not tell the difference) with the number of button presses displayed under it, changing in value only when a button is pressed.
Attatched find my code, it is really quite simple, and thank you so much for the time and help.
#include <Bounce2.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
#include <Wire.h>       //I2C Library
#include <OneWire.h>
#define DS3231_I2C_ADDRESS 0x68

AccelStepper stepper(1, 9, 8); // initiate stepper motor

LiquidCrystal lcd(6, 7, 5, 4, 3, 2);

int pos = 0; // variable to store position
int buttonPresses = 0;

const byte ButtonPin = 10;
const byte LedPin = 13; // for debugging and visualization

unsigned long ledOnTimer = 0;

const unsigned int ledPeriod = 3000;

Bounce button;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  lcd.begin(16, 2);
  button.attach(ButtonPin);
  pinMode(LedPin, OUTPUT);
  stepper.setMaxSpeed(4000);
  stepper.setSpeed(2000);
  stepper.setCurrentPosition(0);
}

byte bcdToDec(byte val)  {
  // Convert binary coded decimal to normal decimal numbers
  return ( (val / 16 * 10) + (val % 16) );
}

void loop() {
  motor();
  printDate();
}

void motor() { // functioning motor sketch by itself

  //if led is on
  if (digitalRead(LedPin)) {
    stepper.runToNewPosition(21000); //about 420 steps per 10 mL
    digitalWrite(LedPin, LOW);
    // }
  }

  //if led is off
  else {
    button.update();
    if (button.fell()) { // if the button "fell" from a value from HIGH to LOW (so now it is off)
      stepper.setCurrentPosition(0);
      digitalWrite(LedPin, HIGH);
      buttonPresses++; // count presses of button and print to monitor
      lcd.clear();
      Serial.print("Number of Button ");
      lcd.setCursor(0, 1);
      Serial.print("Presses = ");
      Serial.println(buttonPresses);
    }
  }
}

void printDate() { //functioning time sketch by itself

  // Reset the register pointer
  Wire.beginTransmission(DS3231_I2C_ADDRESS);

  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);

  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());

  //  print the date EG   3/1/11 23:59:59
  Serial.print(month);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);
}

Last note: Everything compiles, and I will change "Serial" to "lcd" after I finish debugging the sketch, so that is why everything is currently beign sent to the Serial Monitor.

Even if you want to display time with the seconds showing, you don't need to check the time on the RTC continiously. Once a second should be enough. You can use a timer interrupt that triggers an ISR(Interrupt Service Routine) every second to do that check for you. This will free a lot of time which your arduino can use to do other stuff.
Same goes for your button(s): you can use an External Interrupt (INT) or a Pin Change Interrupt (PCINT) for them. This way the arduino will only look at them when they are pushed (and/or released).
If you combine those two interrupts (for the clock and the button), your arduino will have a lot of spare time. This is especially handy if you later want to expand your project with more buttons and motors.

Thank you, I am not entirely sure how to do any of this but I will work on it for a few hours and let you know if I am able to figure it out.

Here is some info about timer interrupts: http://www.instructables.com/id/Arduino-Timer-Interrupts/ and about INT and PCINT http://www.geertlangereis.nl/Electronics/Pin_Change_Interrupts/PinChange_en.html

Appreciate it I will read these both!

I think you need to look at using interrupts.
The printDate function is quite processor intensive with all the Wire and Serial.print calls, it will be taking the majority of the time in each loop().
Whilst in printDate it won't be looking at the state of the button, so you have to press at just the right time.
If you place an interrupt on the button's pin I think you will get a more responsive system.  Another thing that you could look at it only reading the clock once a second, this could be done with a timer interrupt.

Attaching interrupt (PIN change or LEVEL change) to the push button would work fine. You can trigger a flag and the flag should access the controller to run motor() function.

source: Stack Exchange

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

sort: votes


text:
Can I use a PIR sensor to turn on an arduino?
I'd like to use a PIR sensor (HC-SR501) to control the power to an Arduino Uno. Note that I'm not talking about using a PIR sensor as input to the Arduino and sensing the output pin from the PIR, I'm talking about using the output pin from the PIR to turn the Arduino itself on and off.
Hooking it up directly doesn't seem to work as I'm guessing the PIR doesn't handle that much current output. Would I use a transistor of some kind to do this?
My reason for wanting to do this is simple, power preservation. The PIR uses so little current when it doesn't sense anything that I thought it would be nice for something like a mailbox sensor that doesn't need to run that often. Thanks.

Most serious designs would do this by suspending the processor rather than depowering it, though the whole board needs to designed with that in mind, something an off-the-shelf Arduino is not.  If you actually want to depower it, and the Arduino needs to communicate with anything having a common ground with the control circuit, you may find high-side "USB power switch" like the RT9701B simplest for controlling the supply, even if it is not USB.

Did anyone find a solution to this? I have a servo to power with the Arduino. Maybe the PIR sensor can turn on a second power supply before turning on the Arduino and running the servo? Long shot but who knows.

Yes you can.
It all depends on how you are turning the power on.  You sensor needs to flip a 'switch' rather than actually power the Arduino directly.  (I'm sure you know that but just in case).
So you need a normally open relay in between you power source and you Arduino.  Normally open because you don't want it powered unless you 'turn it on'.  Your relay might be able to be switched by your PIR sensor's data output, but if you need more current then you are going to have to use a transistor and draw more power from the power source.
You have the PIR sensor, so now find the relay capable of carrying the maximum current you need for the Arduino.

Ok that's kinda what I figured and I did try a relay before, but not with a transistor between it and the PIR. I guess the PIR can't drive the relay directly.  Thanks.

I'd suggest using a transistor, instead of a relay. Relays are more expensive, and  waste power energizing the coil inside them.

Thanks. Do you happen to know what transistor type I should use for this? I tried using a PNP 2N3906 as recomended at http://www.rason.org/Projects/transwit/transwit.htm, but it didn't provide enough current, only a trickle. I could see the LED lights on the Uno slightly light up, but not quite full power.

Well, I got a 2N2222 NPN transistor to do the job, but I'm not sure if this is the correct solution. When I use this to turn on an Arduino Uno that plays a melody, the power leds on the arduino flicker with each note played. However a multimeter across the circuit only shows it drawing 54mA at most.

A bipolar NPN transistor like a 2N2222 is a relatively poor choice for this, and as a low-side switch creates some substantial complications if the Arduino is connected to anything.

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


text:
OTA Update Esp8266 without IDE
I was wondering if its possible to program the esp8266 to receive firmware updates without the use of an IDE to program.
Use Case:
This device should be setup to the WiFi network scan an IP for a firmware update and update itself if needed.
Any help is greatly appreciated. Thank you

This: https://github.com/arendst/Sonoff-MQTT-OTA-Arduino is a Arduino based firmware with support for OTA. It's written for Sonoff, but that is just a ESP8266 with a relay attached, you can easily adapt it to any ESP8266.
It uses a 'hard coded' address of a web server where it downloads the firmware, and updates are triggered by MQTT messages, but all of that should not be too hard to change to something else.

The firmware host will need a loader application that can talk to the bootloader in the ESP. You'll probably need to build a bit of hardware on the client to sequence grounding of the appropriate GPIO & Reset pins.
The application on the ESP would probably need to do something like:

Discover the availability of an update;
Tell the host to start its loader application;
Begin the local I/O-pin sequencer to start the local bootloader.

The final step should cause the chip to reset and the bootloader to take control. Both the loader on the host and the bootloader will nned to be somewhat tolerant of the potential network delays.


text:
SIM808 module: GSM location command (AT+CIPGSMLOC=1,1) giving wrong value after execution of sending message command (AT+CMGS=+91xxxxxxxx)
I wrote the code that if an interrupt is generated, get GSM location and send a  message.
The first time the interrupt is generated, I got the correct GSM location using AT+CIPGSMLOC=1,1 and successfully sent a message using the AT+CMGS=+91xxxxxxxxcommand.
But the next time an interrupt was generated, AT+CIPGSMLOC=1,1 gave a wrong location. When I commented out the code to send a message, on every interrupt generated I am getting the correct GSM location. So it seems like the problem is occurring after sending a message. But I have no clue what exactly is going wrong. Following is my code.
Note: on restarting the module, I'm again getting the correct location the first time, before sending a message.
void setup() {
  mySerial.begin(9600);
  Serial.begin(9600);
  while (!Serial) {
  }
  // initialize the pushbutton pin as an input:
  pinMode(sensorPin, INPUT);
  // Attach an interrupt to the ISR vector
  attachInterrupt(0, pin_ISR, FALLING);
}

/////////***GSM RESPONSE***///////////
String DisplayGSMResponse() {
  if(mySerial.available()) {
    String gsm_input="";
    while(mySerial.available()) {
      gsm_input+= (char)mySerial.read();
    }
    gsm_input.trim();
    delay(1000);
    Serial.println(gsm_input);
    return gsm_input;
  }
}

void SendMessage(String mobNum,String Location) {
  Serial.println("Sending message..");
  mySerial.println("AT+CMGF=1");
  //Sets the GSM Module in Text Mode
  delay(2000);
  // Delay of 1000 milli seconds or 1 second
  DisplayGSMResponse();
  mySerial.println("AT+CMGS=\""+mobNum+"\"\r");
  // mobile Number
  delay(4000);
  DisplayGSMResponse();
  cleanBuffer();
  mySerial.print("test");
  // The SMS text you want to send
  delay(100);
  mySerial.println((char)26);
  // ASCII code of CTRL+Z
  delay(8000);
  DisplayGSMResponse();
}

void gprsInit() {
  if (isGPRSInit) {
    return;
  }
  Serial.println("GPRS INITIALIZING");
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(2000);
  DisplayGSMResponse();
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"INTERNET\"");
  delay(2000);
  DisplayGSMResponse();
  mySerial.println("AT+SAPBR=1,1");
  delay(8000);
  DisplayGSMResponse();
  mySerial.println("AT+SAPBR=2,1");
  delay(2000);
  DisplayGSMResponse();
  isGPRSInit = true;
}

void gprsterm() {
  mySerial.println("AT+SAPBR=0,1");
  delay(1000);
  DisplayGSMResponse();
  isGPRSInit = false;
}

String getGPS() {
  Serial.println("GETTING GPS LOCATION");
  String loc = "";
  String location = "";
  mySerial.println("AT+CIPGSMLOC=1,1");
  delay(3000);
  loc = DisplayGSMResponse();
  return location;
}

void loop() {
  if (buttonState == 1) {
    detachInterrupt(0);
    gprsInit();
    location = getGPS();
    SendMessage(mobileNumber, location);
    gprsterm();
    Serial.println("location = " + location);
    buttonState = 0;
    location = "";
    attachInterrupt(0, pin_ISR, FALLING );
  }
}

void pin_ISR() {
  buttonState = 1;
  Serial.println("interrupt");
}

EDIT: added gprsterm function.
Note: I removed the interrupt and called the code inside the loop function twice. The first time I got a correct result. The second time a wrong result. So it seems like the interrupt is not be causing the problem.
EDIT2:
One interesting thing I found is that at my home it is showing correct results every time, but in the office it is showing a wrong location on second location call i.e after the SMS was sent and we get the GSM location using AT+CIPGSMLOC=1,1.

What does your gprsterm() function do? But more importantly, review how you are using interrupts, please consult how to use attachInterrupt() on arduino.cc

added gprsterm func. I removed the interrupt and called the code inside loop function twice. first time got correct result. second time wrong result. so it interrupt seems not be causing problem.

Check the function getGPS(). Especially the usage of the local String variables. You might find something there :)

I checked local string variable all are well means intialized with empty string then with data. on interesting thing I found is that at my home it is giving correct results every time, but in office it is showing wrong location on second location call,

It might be due to the command giving the nearest cell tower location. And for sending SMS it might be shifting to a different cell tower depending on your network. This could maybe be easily checked using a different cell provider or as you said its working at your home so I believe I am correct in assuming this is the answer

Serial.println("location = " + location);

I think in upper line you should remove + sign from the code.

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


text:
Reading digital port with pullup via Firmata
I've got a weird issue, probably something I'm missing but have no clue what.
Got some simple float sensors connected to D2 - D5 on a Nano. Need internal pull-up to eliminate a floating value. Wrote this little sketch to test things:
pinMode(2, INPUT_PULLUP);
int sensorVal = digitalRead(2);
Serial.println(sensorVal);

pinMode(3, INPUT_PULLUP);
int sensorVal = digitalRead(3);
Serial.println(sensorVal);

There's one sensor connected reading HIGH and one reading LOW. This works as expected (displays 1010101010...).
Now I've got this connected to my Raspberry Pi via Bluetooth (BT shield connected to RX/TX) and using Firmata to communicate with the Nano. Code (C#):
_arduino.pinMode(2, PinMode.PULLUP);
PinState result2 = _arduino.digitalRead(2);

_arduino.pinMode(3, PinMode.PULLUP);
PinState result3 = _arduino.digitalRead(3);

Debug.WriteLine($"Result pin 2: {result2} and pin 3: {result3}");

This always gives me two pinstates of LOW, even though I'm absolutely sure it should be reading HIGH as my test sketch is outputting the correct value. This driving me nuts. The Firmata sketch I've got loaded on the Arduino is this one: https://github.com/jsiegmund/submerged/blob/master/src/Arduino%20Sketches/SubmergedCabinetModule/SubmergedCabinetModule.ino. Also tried the latest available version from the firmata repo, doesn't solve the issue. As I've got the BlueTooth shield connected to RX/TX (and wasn't able to change that) I cannot use the serial monitor to provide more debug info. Should anyone know how to change that, would also be appreciated.
Btw for other things, Firmata is working just fine. So the communication itself shouldn't be the issue I think.

Are you sure pinNumber is 2 when you are calling _arduino.digitalRead(pinNumber) ?  and you do have a semicolon at the end of that line right ?

Absolutely sure and yes it's there :) I'll see whether I can create a very simple test app which does the same to rule out interference of other code.

Never mind, I found out what the problem is. The Firmata SDK (Remote Wiring) for Windows just completely ignores the PULLUP pin mode. There are PR (https://github.com/ms-iot/remote-wiring/pull/102) which fixes this, now it's working just fine.


text:
ir sender detecting receiver and display
I am in a pickle and want to know if you can help me. I have an IR sensor and receiver and want a program that makes a light bulb flash or detect whenever the IR receiver is in range.
So whenever the IR sender detects the receiver, it should print "detect". This will be done using the Arduino program. And it is an Arduino Nano I am using.
These are the things I use:
http://www.dx.com/p/keyestudio-digital-ir-receiver-module-for-arduino-black-429206#.V5gcpzYko-U
http://www.dx.com/p/38khz-ir-infrared-transmitter-module-for-arduino-135040#.V5gcpjYko-U
How should this program look like? Anyone have the code for this?
Never mind the LED blinking, I just want the program to know whenever the receiver is detected and probably display it somehow. My plan is to send the number of times the transmitter detects the receiver to an Android app in the end.

You can't.
IR is a one-way protocol. The transmitter has no way of knowing whether a receiver is in range; it's literally just an LED that emits infrared instead of visible light.

Assuming you got receiver and transmitter mixed up, then its simple. Otherwise, its not as simple. As @duskwuff points out, simple IR is one-way. The Transmitter here is just an IR Led. That's it. The Receiver is a Remote Control type IR Receiver, looks for a 38khz modulated IR signal, and removes the 38khz carrier wave, passing on the data to be read by the other end.
For a IR beacon type setup, in either simple or two way mode, you'd need two micro controllers.
Simple:

Microcontroller A is the Transmitter. All it does is repeatedly send out an IR modulated code. The Arduino IRLib library can do this.
Microcontroller B is the Receiver. It looks for that specific code, and if found, does X, which could be print to serial, or send over bluetooth to a phone.

Complex, both receive and send:

Microcontroller A is the main part. It sends a code then switches to receive mode for X seconds. If it receives a confirmation or its own code back, it tells the phone/pc it has been found or flashes a different LED.
Microcontroller B is a beacon/repeater. It waits to receive the code above, then switches to transmit mode, and sends the same code or a different code back. That's all it does. A Basic IR Remote Control Repeater.

This tutorial at Adafruit explains it all, with code examples.

Yes, How would I do this? I have 2 arduino nanos. How would I program the 1 to be a receiver and the other 1 to be a transmitter? Is there code anywhere of someone that did this? I have an IR emitter and receiver. Should I use 1 emitter on the 1 arduino and 1 receiver on the other?

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


text:
Please explain this adafruit image for connecting a DS1307 RTC
https://learn.adafruit.com/assets/3813
I understand that analog 4 and 5 are SDA/SLC, isn't the picture also showing 5v and GND being plugged into two analog pins? Does that work?
I have it wired up to the actual 5v and GND, but it would be convieniet to be able to stack the RTC like they show in the picture

You can use ADC pins as general DIO too. In this case 2 PORTA pins set as output, one with HIGH and other LOW outputs to be used as source and sink. Sure pin currents must be within the allowed specs. DS1307 shall consume very low current (designed to be operating years by battery).

@Flanker You just gave an answer. You shouldn't put that in a comment.

It's written in the tutorial

If you set analog pin 3 (digital 17) to an OUTPUT and HIGH and analog pin 2 (digital 16) to an OUTPUT and LOW you can power the RTC directly from the pins!

Wow I don't know how I missed that. Thanks!


text:
Arduino and A4988
I am new in the Arduino area.
What is necessary to control motors through Arduinos.

What is the difference between A4988 and the Arduino motor shield?
Is one A4988 needed for each stepper motor?
Or is one A4988 enough for all motors?

An A4988 can control a single motor and supply up to 35V at 1.5A.
An Arduino motor shield can drive 2 DC Motors or 1 stepper motor at up to 12V and 4A/2A.
An A4988 needs mounting.
A motor shield drops straight in.
There are other options, including getting the ICs and doing it your self.  I have a motor shield which drives 4 DC motors or 2 Stepper motors that I got off eBay.

The A4988 is a bipolar stepper driver. It is designed specifically to drive a single bipolar (4-wire) stepper motor. It consists of a pair of H-bridges and some extra drive logic to provide a simple GPIO interface.
The motor shield, in contrast, uses the L298D motor driver chip. This provides, as well, two H-bridges like the A4988. However it just gives you direct control of those H-bridges without a simple stepper-oriented interface.  So it is up to you to provide the correct control signals to effectively emulate the A4988's outputs.
Both chips can interface with exactly one bipolar stepper motor. The A4988 can only interface with a stepper motor. The L298D can also be used with other types of motor (though of course not at the same time as a bipolar stepper).

The L298 may seem more versatile, but it's also an antiquated high-loss bipolar device, vs a relatively modern and efficient FET one.

@ChrisStratton Agreed. But then people around here still use the LM741 and the TIP120, so the L298 isn't that bad by comparison ;)

@Majenko Are you absolutely certain the A4988 can't be used as an H-bridge for any type of motor?

@user2497 There's nothing to say you couldn't any other load up to it - however the interface to it is geared towards stepping. You don't have control over the H-bridge directly, you can only send it instructions on how to step a stepper motor and the internal logic controls the H-bridge for you. You have pins to set how far to step (1/1, 1/2, 1/4, 1/8 or 1/16 step), one for the direction, and one to initiate a step.  So yes, you could connect some other motor up to it, but you wouldn't be able to do anything useful with it.


text:
Arduino sketch unexpected behaviour
I am currently in a arduino project to read some parameters from another microcontroller serially and the arduino is supposed to transmit these serially to dweet.io cloud. I use SIM900 modem for this. But my problem is that if i put some data to the variables, then the post to the cloud becomes unsuccessfull. Without any data in all parameters, the code runs fine.
Please find the code
char code[4] = {'\0'}, voltage[4] = {'\0'}, current[4] = {'\0'}, mcurrent[4] = {'\0'}, acurrent[4] = {'\0'}, power[4] = {'\0'}, pf[4] = {'\0'}, freq[4] = {'\0'}, temp[4] = {'\0'};
const char APN[18] = "bsnlnet";
byte dtype = 0;

#include <avr/pgmspace.h>

void read_comp() {
    byte flag = 0, index = 0, l = 0;
    char c;
    char readings[8] = {'\0'};
    dtype = 0;

    do {
        while (Serial.available() && l == 0) {
            c = Serial.read();
            delay(20);

            if (c == '\n') {
                l = 1;
                break;
            } else {
                readings[index] = c;
                index++;
            }
        }

        readings[index] = '\0';
        index = 0;
        l = 0;

        if (readings[0] == 'v' || readings[0] == 'V') {             //check if received reading is voltage
            dtype = 1;
            flag = 1;

            if (readings[1] == 'o') {
                flag = 100;
            }
        } else if (readings[0] == 'c' || readings[0] == 'C') {  //check if received reading is current
            dtype = 2;
            flag = 1;

            if (readings[1] == 'u') {
                flag = 100;
            }
        } else if (flag == 1 && readings[1] == 'o') {
            dtype = 9;
            flag = 100;
        } else if (readings[0] == 'm' || readings[0] == 'M') {
            dtype = 3;
            flag = 1;

            if (readings[1] == 'c' && flag == 1) {
                flag = 100;
            }
        } else if (readings[0] == 'a' || readings[0] == 'A') {
            dtype = 4;
            flag = 1;

            if (readings[1] == 'c') {
                flag = 100;
            }
        } else if (readings[0] == 'p' || readings[0] == 'P') {
            flag = 1;

            if (readings[1] == 'o') {
                flag = 100;
                dtype = 5;
            } else if (readings[1] == 'f' || readings[1] == 'F') {
                flag = 100;
                dtype = 6;
            }
        } else if (readings[0] == 'f' || readings[0] == 'F') {
            dtype = 7;
            flag = 1;

            if (readings[1] == 'r') {
                flag = 100;
            }
        } else if (readings[0] == 't' || readings[0] == 'T') {
            dtype = 8;
            flag = 1;

            if (readings[1] == 'e') {
                flag = 100;
            }
        }

        if (flag == 100) {
            switch (dtype) {
                case 1:
                    voltage[0] = readings[3];
                    voltage[1] = readings[4];
                    voltage[2] = readings[5];
                    voltage[3] = readings[6];
                    voltage[4] = '\0';
                    flag = 0;
                    break;

                case 2:
                    current[0] = readings[3];
                    current[1] = readings[4];
                    current[2] = readings[5];
                    current[3] = readings[6];
                    current[4] = '\0';
                    flag = 0;
                    break;

                case 3:
                    mcurrent[0] = readings[3];
                    mcurrent[1] = readings[4];
                    mcurrent[2] = readings[5];
                    mcurrent[3] = readings[3];
                    mcurrent[4] = '\0';
                    flag = 0;
                    break;

                case 4:
                    acurrent[0] = readings[3];
                    acurrent[1] = readings[4];
                    acurrent[2] = readings[5];
                    acurrent[3] = readings[6];
                    acurrent[4] = '\0';
                    flag = 0;
                    break;

                case 5:
                    power[0] = readings[3];
                    power[1] = readings[4];
                    power[2] = readings[5];
                    power[3] = readings[6];
                    power[4] = '\0';
                    flag = 0;
                    break;

                case 6:
                    pf[0] = readings[3];
                    pf[1] = readings[4];
                    pf[2] = readings[5];
                    pf[3] = readings[6];
                    pf[4] = '\0';
                    flag = 0;
                    break;

                case 7:
                    freq[0] = readings[3];
                    freq[1] = readings[4];
                    freq[2] = readings[5];
                    freq[3] = readings[6];
                    freq[4] = '\0';
                    flag = 0;
                    break;

                case 8:
                    temp[0] = readings[3];
                    temp[1] = readings[4];
                    temp[2] = readings[5];
                    temp[3] = readings[6];
                    temp[4] = '\0';
                    flag = 0;
                    break;

                case 9:
                    code[0] = readings[3];
                    code[1] = readings[4];
                    code[2] = readings[5];
                    code[3] = readings[6];
                    code[4] = '\0';
                    dtype = 10;
                    flag = 0;
                    break;
            }
        }
    } while (dtype != 10);
}

void modem_initialization(void) {
    char rec_data, r;
    byte network_status = 0 ;//network_status initialized as zero
    byte status_check = 0 ;//status_check initialized as zero
    byte Serial3_cnt = 0;//Serial3_cnt initialized as zero
    byte ok_flag = 0; //ok_flag initialized as zero
    byte count = 0; //count initialized as zero
    clear_rx_buffer();

    while (Serial3_cnt < 4) { // repeat entire loop until Serial3_cnt less than 5
        switch (Serial3_cnt) {
            case 0:
                clear_rx_buffer();//clearing receiving buffer
                Serial3.println(F("AT"));// Attention command to wake up Serial3 modem
                delay(1000);
                break;

            case 1:
                clear_rx_buffer();//clearing receiving buffer
                Serial3.println(F("ATE0"));//Command for disable echo
                delay(1000);
                break;

            /*case 2: clear_rx_buffer();//clearing receiving buffer
                   // Serial3.println("ATV0");// Command for numeric response after this '0'(zero) will be recieved instead of "OK"
                    delay(1000);
                    break;*/
            case 2:
                clear_rx_buffer();//clearing receiving buffer
                Serial3.println(F("AT&W"));// Command TO SAVE SETTINGS
                delay(1000);
                break;

            case 3:
                Serial3_cnt = 4;// exit from the loop
                break;

            default :
                break;
        }

        while (Serial3.available() > 0) {
            rec_data = Serial3.read();

            if (rec_data == 'O') { // 'o' is recieved
                ok_flag = 1;
            } else if (ok_flag == 1 && rec_data == 'K') { // 'K' is recieved
                Serial3_cnt ++;
                ok_flag = 0;
            } else if (rec_data == '0') { // '0'(zero) is recieved (numeric response)
                Serial3_cnt ++;
                ok_flag = 0;
            } else if (rec_data == '+') { // '+' is recieved message
                clear_rx_buffer();

                if (Serial3_cnt > 0) {
                    Serial3_cnt --;
                }
            }
        }
    }

    Serial3_cnt = 0;
    ok_flag = 0;

    while (network_status == 0) { //wait for PIN READY
        if (status_check == 0) {
            delay(1000);
            status_check = 1 ;
            clear_rx_buffer();
            Serial3.println(F("AT+CPIN?")); //checkin PIN return ready(+CPIN: READY) with a valid simcard otherwise error
        }

        while (Serial3.available() > 0) {
            rec_data = Serial3.read();

            if (rec_data == '+' && status_check == 1) { // '+' is recieved
                status_check = 2 ;
            } else if (rec_data == 'C' && status_check == 2) { // 'C' is recieved
                status_check = 3 ;
            } else if (rec_data == 'P' && status_check == 3) { // 'P' is recieved
                status_check = 4 ;
            } else if (rec_data == 'I' && status_check == 4) { // 'I' is recieved
                status_check = 5 ;
            } else if (rec_data == 'N' && status_check == 5) { // 'N' is recieved
                status_check = 6 ;
            } else if (rec_data == ':' && status_check == 6) { // ':' is recieved
                status_check = 7 ;
            } else if (rec_data == ' ' && status_check == 7) { // ' ' is recieved
                status_check = 8 ;
            } else if (rec_data == 'R' && status_check == 8) { // 'R' is recieved
                status_check = 9 ;
            } else if (rec_data == 'E' && status_check == 9) { // 'E' is recieved
                status_check = 10 ;
            } else if (rec_data == 'A' && status_check == 10) { // 'A' is recieved
                status_check = 11 ;
            } else if (rec_data == 'D' && status_check == 11) { // 'D' is recieved
                status_check = 12 ;
            } else if (rec_data == 'Y' && status_check == 12) { // 'Y' is recieved
                status_check = 13 ;
            } else if (rec_data == 0X0D && status_check == 13) { //Carriage return
                status_check = 14 ;
            } else if (rec_data == 0X0A && status_check == 14) { //Line Feed
                status_check = 15 ;
            } else if (rec_data == 'O' && status_check == 15) { // '0' is recieved
                status_check = 16;
            } else if (rec_data == 'K' && status_check == 16) {
                clear_rx_buffer();
                status_check = 0 ;
                network_status = 1; //goto next step
            } else if (rec_data != 'R' && status_check == 8) { //+CPIN: NOT READY
                clear_rx_buffer();
                status_check = 0 ;
                network_status = 0; //repeat current step
            } else if (rec_data == 'M' && status_check == 3) { // in case of any message
                clear_rx_buffer();
                status_check = 0 ;
                network_status = 0; //repeat current step
            }
        }
    }

    while (network_status == 1) { //wait for SIM network registration
        if (status_check == 0) {
            delay(1000);
            status_check = 1 ;
            clear_rx_buffer();
            Serial3.println(F("AT+CREG?")); //checking for SIM card registration ,if registerd "+CREG: 0,1" will receive
        }

        while (Serial3.available() > 0) {
            rec_data = Serial3.read();

            if (rec_data == '+' && status_check == 1) { // '+' is recieved
                status_check = 2 ;
            } else if (rec_data == 'C' && status_check == 2) { // 'C' is recieved
                status_check = 3 ;
            } else if (rec_data == 'R' && status_check == 3) { // 'R' is recieved
                status_check = 4 ;
            } else if (rec_data == 'E' && status_check == 4) { // 'E' is recieved
                status_check = 5 ;
            } else if (rec_data == 'G' && status_check == 5) { // 'G' is recieved
                status_check = 6 ;
            } else if (rec_data == ':' && status_check == 6) { // ':' is recieved
                status_check = 7 ;
            } else if (rec_data == ' ' && status_check == 7) { // ' ' is recieved
                status_check = 8 ;
            } else if (rec_data == '0' && status_check == 8) { // '0' is recieved
                status_check = 9 ;
            } else if (rec_data == ',' && status_check == 9) { // ',' is recieved
                status_check = 10 ;
            } else if (rec_data == '1' && status_check == 10) { // '1' is recieved
                status_check = 11 ;
            } else if (rec_data == 0X0D && status_check == 11) { //Carriage return
                status_check = 12 ;
            } else if (rec_data == 0X0A && status_check == 12) { //Line Feed
                status_check = 12 ;
            } else if (rec_data == 'O' && status_check == 12) { // '0' is recieved
                status_check = 13;
            } else if (rec_data == 'K' && status_check == 13) {
                clear_rx_buffer();
                status_check = 0 ;
                network_status = 2; //goto next step
            } else if (rec_data != '1' && status_check == 10) { // +CREG: 0,2 not registered
                clear_rx_buffer();
                status_check = 0 ;
                network_status = 1; //repeat current step
            } else if (rec_data == 'M' && status_check == 3) { // in case of any message
                clear_rx_buffer();
                status_check = 0 ;
                network_status = 1; //repeat current step
            }
        }
    }

    Serial3_cnt = 0;

    while (Serial3_cnt < 4) { // repeat entire loop until Serial3_cnt less than 4
        switch (Serial3_cnt) {
            case 0:
                clear_rx_buffer();//clearing receiving buffer
                Serial3.println(F("AT+CMGF=1"));// Attention command to wake up Serial3 modem
                delay(1000);
                break;

            case 1:
                clear_rx_buffer();//clearing receiving buffer
                Serial3.println(F("AT+CNMI=2,1,0,0,0"));//Command to configure new message indication
                delay(1000);
                break;

            case 2:
                clear_rx_buffer();//clearing receiving buffer
                Serial3.println(F("AT+CMGD=1,4"));// Command to delete all received messages
                delay(1000);
                break;

            case 3:
                Serial3_cnt = 4;// exit from the loop
                break;

            default :
                break;
        }

        while (Serial3.available() > 0) {
            rec_data = Serial3.read();

            if (rec_data == 'O') { // '0'(zero) is recieved (numeric response)
                rec_data = Serial3.read();

                if (rec_data == 'K') {
                    Serial3_cnt ++;
                }
            } else if (rec_data == '+') { // '+' recieved ,before "AT+CIICR" command,may be any message
                clear_rx_buffer();

                if (Serial3_cnt > 0) {
                    Serial3_cnt --;
                }
            } else if (rec_data == 'E' && Serial3_cnt > 2) { // '4' recieved (error),in gprs initialisation commands
                clear_rx_buffer();
                Serial3_cnt = 4;
            }
        }
    }

    Serial3_cnt = 0;
}

void clear_rx_buffer(void) {
    Serial3.flush();
}

void gprs_init() {
    byte st = 1, i = 0, response = 0;
    char r[10];

    while (st <= 9) {
        delay(1000);
        clear_rx_buffer();

        switch (st) {
            case 1:
                Serial3.println(F("AT+CGATT?"));
                break;

            case 2:
                Serial3.println(F("AT+CIPSHUT"));
                break;

            case 3:
                Serial3.println(F("AT+CIPMUX=0"));
                break;

            case 4:
                response = cmd1_check(1);
                break;

            case 5:
                Serial3.println(F("AT+CIICR"));
                delay(1000);
                break;

            case 6:
                Serial3.println(F("AT+CIFSR"));
                break;

            case 7:
                response = cmd1_check(2);
                delay(2200);
                clear_rx_buffer();
                break;

            case 8:
                Serial3.println(F("AT+CIPSEND"));
                break;

            case 9:
                Serial3_send();
                ++st;
                break;
        }

        if (st == 10) {
            clear_rx_buffer();
        }

        delay(1000);

        while (Serial3.available() && st < 9 && st != 7 && st != 4) {
            r[i] = Serial3.read();
            i++;
        }

        i = 0;

        if (strstr(r, "ALREADY") != NULL) {
            Serial3.println("AT+CIPSHUT");
            delay(50);
            clear_rx_buffer();
            st = 2;
            r[0] = '\0';
        }

        if (strstr(r, "OK") != NULL || strstr(r, "+CGATT") != NULL || (strstr(r, ".") != NULL && st == 6) || strstr(r, ">") != NULL) {
            st++;
        } else if (strstr(r, "ERR") != NULL) {
            break;
        } else if (response == 1 && (st == 7 || st == 4)) {
            st++;
            response = 0;
        }
    }
}

char cmd1_check(short int o) {
    byte timout1 = 10500, m1, p1 = 0, resp1 = 0;
    char response1[25] = {'\0'};
    m1 = millis();
    clear_rx_buffer();

    if (o == 1) {
        Serial3.print(F("AT+CSTT="));
        Serial3.print('"');
        Serial3.print(APN);
        Serial3.print('"');
        Serial3.print(',');
        Serial3.print('"');
        Serial3.print('"');
        Serial3.print(',');
        Serial3.print('"');
        Serial3.println('"');
        delay(3000);
    } else if (o == 2) {
        Serial3.print(F("AT+CIPSTART="));
        Serial3.print('"');
        Serial3.print(F("TCP"));
        Serial3.print('"');
        Serial3.print(',');
        Serial3.print('"');
        Serial3.print(F("dweet.io"));
        Serial3.print('"');
        Serial3.print(',');
        Serial3.println(80);
        delay(2000);
    }

    do {
        p1 = 0;

        while (Serial3.available()) {
            response1[p1] = Serial3.read();
            p1++;
            delay(20);
        }

        if (strstr(response1, "OK") != NULL && o == 1) {
            resp1 = 1;
        } else if (strstr(response1, "ERR") != NULL) {
            resp1 = 2;
        } else if (strstr(response1, "CONNECT OK") != NULL && o == 2) {
            resp1 = 1;
        }
    } while ((millis() - m1) <= timout1 && resp1 == 0);

    return (resp1);
}

void Serial3_send() {
    Serial3.print("POST /dweet/for/");
    Serial3.print("mythingname");
    Serial3.print("?vo=");
    Serial3.print(voltage);
    Serial3.print("&cu=");
    Serial3.print(current);
    Serial3.print("&Mc=");
    Serial3.print(mcurrent);
    Serial3.print("&Ac=");
    Serial3.print(acurrent);
    Serial3.print("&Po=");
    Serial3.print(power);
    Serial3.print("&PF=");
    Serial3.print(pf);
    Serial3.print("&fr=");
    Serial3.print(freq);
    Serial3.print("&Te=");
    Serial3.print(temp);
    Serial3.println(" HTTP/1.1");
    Serial3.println("connection: keep-alive");
    Serial3.println();
    Serial3.println();
    Serial3.write(26);
    Serial3.println();
    delay(10000);
    Serial3.println("AT+CIPSHUT");
    delay(50);
}

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

void loop() {
    dtype = 0;
    read_comp();
    gprs_init();
}

This looks like you are constructing the data to be sent as GET parameters (i.e as part of the querystring), whereas I believe dweet.io expects them as part of the POST body - as seen here.
There seem to be many people struggling to successfully send HTTP POSTs with a SIM900, but I think this answer outlines the correct sequence to make it work.


text:
Solar Power Inside a Car
I plan on making an Arduino project for reminding a parent to take a child from a car. In order to power the project I though on using a solar panel. Since I can't rely on having solar power all the time I'll need to use rechargeable batteries and charge them with the solar panel.
The problem is that from reading about the subject it is clear that it can be dangerous as far as battery go up in flame in some cases, especially due to high heat.
My car can get into very high temperature when parked outside so this scenario is very likely to happen.
Can someone please direct me to reading materials about using solar power in a very safe way?

Is there a reason why you don't want to use the power source the car already has?

Well, the power source of the car mease run cables inside the car which is not ideal. Of course having battery explide is even less ideal :) Also the car give 24V if I'm not mistaking and I'll need to adjust for Ardino.

Most cars give 12V and Car to USB adapters are quite common, so that's now down to 5v.

Thanks, I'll consider that but it still leave running cables inside the car.

Just to clarify, its the batteries that are the problem, not the solar cell.  Could you put the batteries in a place that doesn't get hot, i.e. under the seats?  I have to be honest, I'm a bit confused as to the purpose of this system you are developing, do people really forget to remove their children from a car?

You right, the battaries are the problem but charge them seem to increase the chances of problems. Regarding the purpose, it turns out that people do forget their children, there has been few death cases in the past year. If I can reduce the chance of this happens to me it worth it.

If you would like to Charge batteries from solar you would Need more wiring, a charging System (over current shutdown, over Charge protection) and btw where do you install the solar? how does it get the sunlight? 12 Volts are running thougout the car, 12 also goes to reverse lights so you can Access probably from the floor. I don't know much about car wiring schemes.

Now that you say it I actually have car charger in the trunk so maybe running cables from there is not such a big-deal. Thanks

BTW how do you sense the child on the seat? which sensor do you have?

I plan to use one piezo sensor inside the child seat to detect when the child is in the seat and another piezo on the car body to detect when the car is on. If the car piezo is not detect anything and the child piezo detect something I'll sound some sound using another piezo buzzer.

Car Body? If the parent is calling, probably the engine will be off, it should be. Can engine can also be switched off at the time when stopping on Signal etc. There are no sensors already in seats? New cars have it.

Just an idea you might like to consider - I wonder if an inductive pad on (or in) the car seat would be a useful way to transfer power to the device without wires (and without solar panels.) It would require a bit of research on inductive chargers etc...

I'd just add some sensors to  both the drivers door, and the back door. If the parent opens it's door, but doesn't open the rear-door, it must have forgotten the child. I'd skip the solar panel, and make the system as battery efficient as possible. Depending on the sensors used, it's possible to get the system running on a couple of AA batteries for a year or more.

That's sound great. My question is if it's safe to leave batteries inside really hot car. I think my car can easily go ask high as 60 degrees C

Firstly, solar panels inside a car is pretty pointless. Solar panels need to be in direct sunlight to be effective. Having them inside a car means they're not going to be in direct sunlight, so they're not going to be able to generate anywhere near enough power - unless they are massive, in which case where is the child going to sit? Yes, you could put them on the roof, but that would be silly.
The whole concept of solar panels for this project is completely wrong.
The car has a big battery and an in-built generator. Use them. There is absolutely no reason for you to have your own batteries as well. Yes, you could charge your own batteries from the car's battery, but that just introduces extra losses and wastefulness.
The only possible benefit of having your own batteries is it will safeguard the car's battery when the engine isn't running. It would then be impossible for your project to flatten the car's battery. But if you design your project properly that wouldn't be a problem anyway.
Some things you seem to be missing with your project:

The car has power you can use. It's throughout the car. No need to provide your own external power source.
The car has an "accessory" signal that is only turned on when the ignition is on. It's used by things like the radio etc so that when you turn the car's ignition off the radio turns off. No need for vibration sensors or anything to know if the car is running, it can tell you directly.
Cars generally have "seat occupied" sensors in them that couple with the seatbelts to know if a passenger hasn't got their seatbelt on and warn the driver (in most jurisdictions it's the responsibility of the driver to ensure all passengers have their seatbelts on).

If you really must charge batteries there are certain safety aspects you really must take into account. Your charge circuit must be able to manage the battery charging 100% safely. You have mentioned heat, and that is a very very important thing to manage. A decent battery manager chip will include an input for a thermistor. That is used as one of the multiple methods of charge termination (there's dv/dt (change in voltage over time), dT/dt (change in temperature over time), etc). It also serves as an over-heat safety cutout. Ensure that the charge circuit you use not only provides a thermistor input but also has the ability to cut off charging in the case of an overheat situation.
You also need to consider over-voltage. A car's 12V supply isn't 12V. It can get as high as 16V sometimes, and noise from the ignition can cause regular spikes as high as 70V or more. Automotive electronics have to be able to withstand those spikes, and that means your charge circuit has to be able to withstand those spikes.  Buffering the 12V through a proper 5V (cigarette lighter USB charger) regulator will remove that noise and make your circuit easier to work with.
So you need to think more carefully about just what it is you want to achieve and how that is going to fit into an automotive situation.

Thank you for the detailed answer. One reason not to use the car power is that I need this device to work exactly when the card is off so I can't use the car power. Make sure this device doesn't drain the car battery is also very important. I'll read more about car electricity.

The car still has power when it is off. That is why you can turn the lights on without the engine running.

You right. I'm not familiar with car electricity so if I can solve this safely and reliably without messing with the car it will be better but I don't rule this out completely

Add a large (super) capacitor to it. So it will continue working for a while, after the engine is off. On the plus side, you now know when the engine is off, and that you should check to see if the driver is forgetting the precious cargo.


text:
On UNO, when serial.print to UART pin 11, nothing comes out of pin 11
The problem: Message prints only to the Arduino IDE's Tools > Serial Monitor, not coming out of TX pin 11.
Question, please how to get Arduino Uno or Mega to send data out of pin 11?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 13); // RX, TX pins on Arduino
void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.print("This is a test\n\n");
  delay(1000);
}

Where in that code are you doing anything at all with pin 11?!

Of course it's only coming out on the serial monitor - you are printing it to the hardware UART which comes out on the serial monitor.
You have created a SoftwareSerial object which you are then completely ignoring and then using the HardwareSerial UART object instead, which is on pins 0/1.
If you want to use a SoftwareSerial object you should actually use the SoftwareSerial object.
Replace all the references to Serial with mySerial instead.

Thank you for the speedy answer.  I will try that immediately.

I change  to my Serial and had to add mySerial.begin(9600).   Now it works. Thank you Majenko.


text:
Blocking Serial Data
I am driving two stepper motor using serial data from Raspberry Pi to Arduino. Motors work fine when i am passing serial data but once i stop sending serial data, it doesn't accept serial data again unless I burn the program again in arduino. Here is code for that:
 #include <Driver.h>

//////////////////////////////////////////////////////////////////////////////////////////
/*
   Hardware pins defined in this section as connected from arduino to Pan DRV8834
   controller and tilt DRV8834 controller.M0 and M1 pins are common for both controllers
   ,hence declared only once(This is done to save number of pins, connecting it to
   additional pins , provide no special advantage since both both motors should be set
   to same level of microstepping).SLP pin is not currently used.

*/
//////////////////////////////////////////////////////////////////////////////////////////

#define PAN_DIRECTION_PIN 8
#define TILT_DIRECTION_PIN 7

#define PAN_STEP_PIN 10
#define TILT_STEP_PIN 9

#define M0 6
#define M1 5

#define MOTOR_SPEED 200

#define SLP 0
///////////////////////////////////////////////////////////////////////////////////////////

#define BAUD_RATE 230400      //Baud Rate for serial communication

///////////////////////////////////////////////////////////////////////////////////////////

/*
   field data for receiving buffer on arduino side , important for serial communication
*/
#define NUMBER_OF_FIELDS 2 // how many comma separated fields we expect
int fieldIndex = 0;           // the current field being received
int values[NUMBER_OF_FIELDS];  // array holding angles for both motors

const char startChar = '<'; //beginning character of a valid command
const char endchar   = '>'; //this will be ending character to ensure a valid command has ended
boolean storeString = false; //This will be our flag to put the data in our buffer

#define zeroCharacter 'z'

bool zeroCommand = false;

#define DATABUFFERSIZE 50
char dataBuffer[DATABUFFERSIZE + 1]; //Add 1 for NULL terminator
int dataBufferIndex = 0;

int procBufCounter;         //iterate through whole string to obtain the commands

float panAngle, tiltAngle;

int sign = 1;

    Driver stepper_pan(M0, M1, PAN_STEP_PIN, SLP, PAN_DIRECTION_PIN);
    Driver stepper_tilt(M0, M1, TILT_STEP_PIN, SLP, TILT_DIRECTION_PIN);

    void processCommand(char *buffer) {

        procBufCounter = 0;
        bool startprocessing = false;
        bool endprocessing = false;

        values[0] = 0;
        values[1] = 0;

        while ((procBufCounter < DATABUFFERSIZE) && (!endprocessing)) {

            char ch = buffer[procBufCounter];           //read the character while simulatneously increasing the buffer cursor

            if (ch == '<') {
                startprocessing = true;
            }
            else if (ch == '>') {
                values[fieldIndex] = values[fieldIndex] * sign ;
                fieldIndex = 0;
                endprocessing = true;
            }

            if (startprocessing)
            {
                if (ch == ',') {
                    values[fieldIndex] = values[fieldIndex] * sign ; // set value to the accumulated value
                    sign = 1;
                    fieldIndex++;
                }
                else if ('0' <= ch && ch <= '9' ) {
                    values[fieldIndex] = (values[fieldIndex] * 10) + (ch - '0');
                }
                else if (ch == '-') {
                    sign = -1;
                }
                else if(ch == 'z'){
                  zeroCommand = true;
                }
            }
            procBufCounter++;
        }
        panAngle = ((float)(values[0]))/100;
        tiltAngle = ((float)(values[1]))/100;

       bool panMoved = true, tiltMoved = true;
        stepper_pan.moveTo(panAngle);
        stepper_tilt.moveTo(tiltAngle);
      while (panMoved || tiltMoved) {
        panMoved = stepper_pan.run();
        tiltMoved = stepper_tilt.run();
      }

      if(zeroCommand){
        stepper_pan.reset_positions();
        stepper_tilt.reset_positions();
        zeroCommand = false;
      }

    }

    //////////////////////////////////////////////////////////////////////////////////////

    void setup() {
      stepper_pan.setStepMode(STEP_THIRTYTWO);
      stepper_pan.setSpeed(MOTOR_SPEED);
      stepper_tilt.setStepMode(STEP_THIRTYTWO);
      stepper_tilt.setSpeed(MOTOR_SPEED);
      Serial.begin (BAUD_RATE);
      Serial.flush();
    }

    void loop() {
      if (processString) {
        processCommand(dataBuffer);
        processString = false;
    //     dataBuffer = "";

      }
    }

    void serialEvent() {
      static int dataBufferIndex = 0;
      while (Serial.available() > 0) {
        char incomingbyte = Serial.read();
        if (incomingbyte == startChar) {
          dataBufferIndex = 0;  //Initialize our dataBufferIndex variable
          storeString = true;
        }
        if (storeString) {
          //Let's check our index here, and abort if we're outside our buffer size
          //We use our define here so our buffer size can be easily modified
          if (dataBufferIndex == DATABUFFERSIZE) {
            //Oops, our index is pointing to an array element outside our buffer.
            dataBufferIndex = 0;
            break;
          }
          if (incomingbyte == endchar) {
            dataBuffer[dataBufferIndex] = endchar; //null terminate the C string
            dataBuffer[dataBufferIndex + 1] = '\0';
            //Our data string is complete.  return true
            storeString = false;
            processString = true;
            dataBufferIndex = 0;
          }
          else {
            dataBuffer[dataBufferIndex++] = incomingbyte;
            dataBuffer[dataBufferIndex] = 0; //null terminate the C string
          }
        }

      }

    }

It's difficult to debug your code because it's not complete, I think there is quite a bit of code in parameters.h.  Also the commented out LCD code is a distraction.  Is it possible to edit your post to have al of the relevant code? (Then people can copy it and debug it)

@Matt I have edited the code , can you please have a look now, thanks!

I finally figured it out. It is due to reset whenever I open a port for serial communication. Attaching a 10uF capacitor between ground and reset fixed everything.

Note that you can control the reset behavior from the Raspberry Pi without having to add components: http://arduino.stackexchange.com/questions/16776/how-to-connect-arduino-device-to-linux


text:
How to run servo 180 degrees and stop?
I'm creating a PIR motion sensor doggy door.
The problem I'm having with it is, it runs 3 times, I've figured out how to pause when reaches 180° but not how to stop.
I was thinking I could use detach my servo and attach after a delay of 30,000 and then re-attach return to 0 degrees, then wait for next PIR high.
But I don't know how to code it into what I have or even if it would work.
My code:

/* This code sweeps a servo from 0 degrees to 180 when the PIR sensor detects motion.
   Special thanks goes to the author of the PIR sensor code, whose code helped tremendously
   in the making of this code and Instructable.
   author of PIR sensor code: Kristian Gohlke / krigoo (_) gmail (_) com / http://krx.at
**/

#include <Servo.h>

Servo myservo; //creates a servo object
//a maximum of eight servo objects can be created
int pos = 0; //variable to store servo position
//amount of time we give the sensor to calibrate(10-60 secs according to the datasheet)
int calibrationTime = 30;
//the time when the sensor outputs a low impulse
long unsigned int lowIn;
//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int pirPin = 12; //digital pin connected to the PIR's output
int pirPos = 13; //connects to the PIR's 5V pin

void setup() {
  myservo.attach(4); //attaches servo to pin 4
  Serial.begin(9600); //begins serial communication
  pinMode(pirPin, INPUT);
  pinMode(pirPos, OUTPUT);
  digitalWrite(pirPos, HIGH);
  //give the sensor time to calibrate
  Serial.println("calibrating sensor ");
  for (int i = 0; i < calibrationTime; i++) {
    Serial.print(calibrationTime - i);
    Serial.print("-");
    delay(1000);
  }
  Serial.println();
  Serial.println("done");
  //while making this Instructable, I had some issues with the PIR's output
  //going HIGH immediately after calibrating
  //this waits until the PIR's output is low before ending setup
  while (digitalRead(pirPin) == HIGH) {
    delay(500);
    Serial.print(".");
  }
  Serial.print("SENSOR ACTIVE");
}

void loop() {
  if (digitalRead(pirPin) == HIGH) {
    //if the PIR output is HIGH, turn servo
    /*turns servo from 0 to 180 degrees and back
      it does this by increasing the variable "pos" by 1 every 5 milliseconds until it hits 180
      and setting the servo's position in degrees to "pos" every 5 milliseconds
      it then does it in reverse to have it go back
      to learn more about this, google "for loops"
      to change the amount of degrees the servo turns, change the number 180 to the number of degrees you want it to turn
    **/
    for (pos = 0; pos < 180; pos += 1) {
      //goes from 0 to 180 degrees
      myservo.write(180);
      delay(8000); ////stops motor for 8 seconds
      for (pos = 180; pos >= 90; pos -= 1) {
        // goes from 180 degrees to 0 degrees
        myservo.write(pos); // tell servo to go to position in variable 'pos'
        delay(15); // waits 15ms for the servo to reach the position
      }
      myservo.write(90);
      delay(4000); //stops motor for 4 seconds
      for (pos = 90; pos <= 180; pos += 1) {
        // goes from 0 degrees to 180 degrees
        // in steps of 1 degree
        myservo.write(pos); // tell servo to go to position in variable 'pos'
        delay(15); // waits 15ms for the servo to reach the position
      }
      //to make it go slower, increase the number.
      if (lockLow) {
        //makes sure we wait for a transition to LOW before further output is made
        lockLow = false;
        Serial.println("---");
        Serial.print("motion detected at ");
        Serial.print(millis() / 1000);
        Serial.println(" sec");
        delay(50);
      }
      takeLowTime = true;
    }

    if (digitalRead(pirPin) == LOW) {
      if (takeLowTime) {
        lowIn = millis(); //save the time of the transition from HIGH to LOW
        takeLowTime = false; //make sure this is only done at the start of a LOW phase
      }
      //if the sensor is low for more than the given pause,
      //we can assume the motion has stopped
      if (!lockLow && millis() - lowIn > pause) {
        //makes sure this block of code is only executed again after
        //a new motion sequence has been detected
        lockLow = true;
        Serial.print("motion ended at "); //output
        Serial.print((millis() - pause) / 1000);
        Serial.println(" sec");
        delay(50);
      }
    }
  }
}

Could I also just change the jumper pin on the PIR hardware for a retriggering set high to keep the door open when the dog is there so it won't just close on them?
I'm using this PIR:

Can you add you code rather than link to it.

Sorry that's a blocked site for me.  Hope someone else can help.

Please can you confirm you want you servo to turn to 180 degrees when you PIR sensor sends a high.  You want your servo to wait for 30 seconds and then return to zero?

I've just realised the servo is opening the door, not moving the PIR sensor :)

Please edit your post, post your code, and format the code using the code formatting markdown (four leading spaces). For help see Markdown help. You should be able to do this by selecting the code and pressing Ctrl+K to have your browser do this for you.

Try to restructure the logic in your question also. What do you want to happen when the PIR is triggered. Put it in small (numbered) steps, not in one big sentence.

I haven't been able to compile or test this but I think it should do what you are asking for, or at the very least steer you in the right direction.
// This code waits for a signal from the PIR sensor.
// When the signal is recieved it rotates the servo 180 degrees and waits 30 seconds
// it then rotates the servo back to 0 (to close the door)

#include <Servo.h>

const int ServoIntraStepDelay   =  15;      // Delay between servo steps (ms)
const int ServoAngleStep        =   1;      // The angle by which the servo position is changed every step (degree)
const int ServoAngleMinimum     =   0;      // The min angle of the servo (degrees)
const int ServoAngleMaximum     = 180;      // The max angle of the servo (degree)
const int DoorOpenPeriod        = 30 * 1000;// The time the door will remain open for (ms)
const int DoorClearPoll         = 100;      // The interval betwen polls to the sensor when checking to see if the door is clear(ms)
const int DoorClearPeriod       = 5000;     // The interval that the PIR sensor must report low before closing the door (ms)

const int PIRCalibrationTime    = 30;       //amount of time we give the sensor to calibrate(10-60 secs according to the datasheet) (s)

const int PinPIRData            = 12;       //digital pin connected to the PIR's output
const int PinPIRPower           = 13;       //connects to the PIR's 5V pin
const int PinServoPower         = 4;        // The pin that controls the servo.

Servo myservo;                              //creates a servo object

void setupCalibratePIR()
{
        //give the sensor time to calibrate
    Serial.println("Calibrating sensor ");
    for(int i = 0; i < PIRCalibrationTime; i++)
    {
        Serial.print(PIRCalibrationTime - i);
        Serial.print("-");
        delay(1000);
    }
    Serial.println();
    Serial.println("done");
    //while making this Instructable, I had some issues with the PIR's output
    //going HIGH immediately after calibrating
    //this waits until the PIR's output is low before ending setup
    Serial.print("Waiting for PIR sensor to report low");
    while (digitalRead(PinPIRData) == HIGH)
    {
        delay(500);
        Serial.print(".");
    }
    Serial.print("SENSOR ACTIVE");
}

void turnServo (const int& from, const int& to, const int& step)
{
    for(int pos = from; pos <= to; pos += step)
    {
        myservo.write(pos);
        delay(ServoIntraStepDelay);
    } //to make it go slower, increase the number.
}

// Test the PIR sensor and ensure that it reports low for a specific time
void waitForDoorClear ()
{
    bool doorIsNotClear = true;
    while (doorIsNotClear)
    {
        doorIsNotClear = false;
        for (int doorClear = 0; !doorIsNotClear && (doorClear * DoorClearPoll) < DoorClearPeriod; ++doorClear)
        {   // Poll every few ms and check that the sensor in LOW
            // As soon as it is high this loop will exit which restarts the time that the low signal must been seen for.
            delay (DoorClearPoll);
            doorIsNotClear = (digitalRead(PinPIRData) == HIGH);
        }
    }   // This is potentially an infinite loop.
}

void setup()
{
    Serial.begin(9600);                     // Begins serial communication
    myservo.attach(PinServoPower);          // Connect to the servo object
    pinMode(PinPIRData, INPUT);             // Connect the PIR data
    pinMode(PinPIRPower, OUTPUT);           // Connect the PIR power
    digitalWrite(PinPIRPower, HIGH);        // Turn on the PIR power

    setupCalibratePIR();                    // Calibrate the PIR sensor
}
// attach
void loop()
{

    if(digitalRead(PinPIRData) == HIGH)
    { //if the PIR output is HIGH, turn servo

        turnServo (ServoAngleMinimum, ServoAngleMaximum, ServoAngleStep);
        delay (DoorOpenPeriod - DoorClearPeriod);
        waitForDoorClear ();
        turnServo (ServoAngleMaximum, ServoAngleMinimum, -ServoAngleStep);
    }
}

You weren't that far off.

a bunch of errors
Arduino: 1.6.9 (Windows 7), Board: "Arduino/Genuino Uno"
: In function 'void setupCalibratePIR()':
matt:39: error: 'pirPin' was not declared in this scope
while (digitalRead(pirPin) == HIGH)
^
: In function 'void turnServo(const int&, const int&, const int&)':
matt:49: error: 'os' was not declared in this scope
for(int pos = from; pos <= to; [os += step)
^
matt:49: error: expected ',' before '+=' token
for(int pos = from; pos <= to; [os += step)
^
matt:49: error: expected identifier before '+=' token

Yep, sorry like I said I can't compile it at work. pirPin should be PinPIRData.  os should be pos that will clear those three.

ive figured them out     for(int pos = from; pos <= to; [pos += Step) im guessing step is ServoAngleStep but it says expected ',' before '+=' token  ???

That's the [ I must have hit that key instead of P.  I have updated the code, This time I know it compiles, well in visual studio.

the code runs but it is always open now until power is off only then will it return to 0 degrees ive tried changing the code but it doesnt seem to work for me

Comment out the line in loop() that call waitForDoorClear(). Hopefully the door will now open and close, and it will prove the fault is in waitForDoorClear().  Then we need to work out a better way of detecting it's clear.

I have tried all this matt im using the answer u gave that @Nick Gammon deleted for not being an answer and ive tried adding in new lines that run 180 to 0 even new starts that run starting at 180 and runs to 0 but its not working for me
sorry to the site i cant open chat cause i dont have enough rep


text:
Why am I always getting 48 with serial communication?
So I want to send some data from Matlab to Arduino. To verify that I am getting the correct data I am sending the data back to Matlab (since I get errors if I open the serial monitor, if there's an easier way to print debug messages let me know).
The problem is that I always get 48 back.
My matlab code:
arduino = serial('COM3','BaudRate',115200);
fopen(arduino);
fprintf(arduino,'%f',1);
fclose(arduino);

fopen(arduino);
disp(fscanf(arduino, '%f'))
fclose(arduino);

and my arduino code:
In the setup:
Serial.begin(115200);

In the loop:
delay(100);
myFunction();

In myFunction:
while(!Serial.available()>0)){}
int data = Serial.read();
Serial.println(data,DEC);

It seems like the 48 is an ascii code for something but it doesn't ever change when I change the 1 is the 3rd line of the matlab code to anything else.

Why am I always getting 48 with serial communication?

Your Arduino sketch (snippet) is reading a byte and writing the value, not the character. The value 48 in ASCII is the character '0'.
The below loop() function will echo all the characters received.
void loop()
{
  while (Serial.available()) {
     char c = Serial.read();
     Serial.println(c);
  }
}

This could be a good starting point when debugging what is actually written from MATLAB.

I don't know much about maylab, but you are sending a float to the Arduino where you read bytes and send characters back to matlab and read it as a float.
Try sending a single character from matlab and reading a single character back, %c.

If instead of sending data back from arduino I send back a set number it works (although I get 0 first and then the number 3 times). Trying the character as  you suggsted, I get a 0 and then nothing.

You need to understand "data types".  The Matlab code is sending 1 as a floating point number.  The Arduino Serial.read() function reads a character and you then save this as an integer.  A float is going to be at least 4 bytes and the number is encoded in a special way so it can store the whole number and the decimal.  You cannot convert a float into a char or int without special handling.  A char is 1 byte and an Arduino int is 2 bytes, the chances are the upper byte of the int will be blank when you write the char into it, but its not a great idea.

So if you want to send a float, you need to receive a float, which means calling Serial.Read() 4 times and then assembling that as a float using bit shifting.  BUT you are sending a string a series of characters terminated by a NULL character.  You are doing this because you are using fprintf(), if you want to send a float as binary you have to use fwrite().

Thanks for your explanation @Matt I tried calling Serial.Read a second time but then it would just freeze at that line (presumably). I tried replacing the fprintf with fwrite but then I couldn't get any response back at all.

Also as some additional information: I put a loop in the matlab code to display and fscanf from the arduino object, and I noticed that it will end up printing the data sent from the arduino three times. So if I send a 5 from arduino to matlab it will print out 5 three times, if in the arduino I send back the data I receive from matlab, then 48 will be printed in matlab three times.

May I recommend that you take a look at the data stream that MatLab produces? That will show you what it is producing, and therefore what code you should write in the Arduino to process it.

If you had a second COM port on the PC, and a cable to connect your PC's MatLab port (COM3) to that port, you could use Arduino's Serial Monitor to show the data - make the Arduino Serial Monitor "pretend" to be the Arduino listening to MatLab.

But on the assumption that you don't have a second port or a NULL Modem serial cable, another alternative is to use a PC program such as "Serial Port Monitor" (I've heard good things about this program, although I've never used it). Apparently you can use it for 14 days to trial it.
Basically it presents a window (you'll want the Window called "Terminal", not any of the others) that shows what is being sent and received on the COM port - even data generated by another program. Shut down MatLab, start this program, tell it to listen to COM3, set the baudrate etc, press Go - then start MatLab again.
When MatLab sends data, you'll see whether it's sending "0.125" or "0y@/" - and assuming that you don't want to decode the latter, how to change your MatLab code so that it looks like the former! Then you can change the Arduino code to understand values like "0.125".


text:
Server checkbox not working properly
I am trying to make an arduino alarm clock to which you can send alarm clock times over the web.
This is the HTML code
 <input type="checkbox" name="alarm1" id="alarm1">1</button>

It's sending the HTTP correctly but the rest of the code insists that the alarms are always on.
      if (_server.arg("alarm1") = "on") {
      alarm1 = true;
      Serial.println("Alarm 1 is set");
  }
  else {
      alarm1 = false;
      Serial.println("Alarm 1 is inactive");
  }

The alarm is always on because you are setting it to be always on.  You code should say:
 if (_server.arg("alarm1") == "on") {

To clarify, one equal sign is used to assign a value to a variable, two equal signs is used to determine if one value equals another.


text:
Printing the messages having problem in SIM 900A to Arduino
I have added my Arduino code for reading messages from GSM SIM900A using Arduino. But the output is showing something different. Please help me.
#define SERIAL_BUFFER_SIZE 256

char msg;
void setup() {
  Serial.begin(9600);   // Setting the baud rate of GSM Module
  delay(60000);
  Serial.println("AT");
  delay(1000);
  Serial.println("AT+CREG=1");
  delay(1000);
  Serial.println("AT+CMGF=1"); // set SMS mode to text
  delay(1000);
  Serial.println("AT+CMGR=\"ALL\"");
  delay(1000);
  Serial.println("AT+CMGR=\"ALL\"");
  delay(1000);
  while ( Serial.available() > 0) Serial.read();  // removing serial buffer values
  Serial.println("AT+CMGR=1");
  delay(2000);
}

void loop() {
  while (Serial.available() > 0) {
    msg = serial.read()
    Serial.print(msg);
  }
}

This is the output:
+CMGR: "REC READ","+91xxxxxxxxxx","","16/07

Hello Guys i found the issue. Serial.read() function reads only 62bytes. After i have update the serial buffer size in library file C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.H ... It shows the messages which is stored in serial buffer.

Please note that you may want to check/handle the responses on these commands.

Please, accept your own answer to close this question.


text:
Size of String array
I am trying to find out the size of an array like this:
    String days[3] = { "Mon", "Tue", "Wed" };
Serial.printf("Size of array: %2d\n", sizeof(days));
for (int i = 0; i < sizeof(days); i++) {
    Serial.print(days[i]);
}

The result of the code above is 36 which is incorrect.
Do I have any other options considering that I don't know the size of the array to begin with?

sizeof() is the number of bytes and not the number of elements. sizeof(array) / sizeof(element) gives the number of elements.

No, the result is correct, you're just interpreting it incorrectly. If you want the number of elements in a statically-allocated array use:
sizeof(somearray) / sizeof(somearray[0])

Sorry if I post in wrong topic
follow answer of Ignacio Vazquez-Abrams, in case of size of each String in array is different? like String days[] = { "Monday", "Tuesday", "Wednesday" }; Thanks


text:
Is possible to concatenate integers?
It's a basic one: I have two values from two different analogRead pins:
int val1;
int val2;

For example, val1 = 10 and val2 = 10. How could I put these two values into a variable val3 = val1 + val2 that will give the answer 1010, instead 20 ?

val = (val1*100) + (val2%100)

val = (val1 << 8) + (val2 & 0xff)

float val = val1 + (val2 / 100.0)

It is far from clear what you think you are attempting to achieve. I suspect you may be suffering from an XY problem where you think you have come up with a solution to a problem, and are asking for help with the solution, when you don't actually really understand what the problem is, and so your solution won't actually do what you expect it to do.

For instance, have you considered what will happen if val1 is 3, or val2 is 400? Concatenating integers makes little to no sense, and I suspect you actually want to do something else entirely.

Actually I am trying to reduce the times I need to transmit data over radio frequency. My question could be poste in other form: How could I concatenate any kind of variable? What I need to do to have
char  val1 = "abc";
char val 2 = "def";
char val3 = val1 + val2
and could I have val3 = "abcdef"  ?

I really like the explanation of a XY problem!!! Maybe this question could be suitable for.
But in matter of fact, the answer to the question "is possible to concatenate integers?" could be simply "no, it´s not".

Integers aren't things you meaningfully concatenate. You could turn them into strings, and then use strcat to concatenate them.

If you are reading from the analog pins then the values are 10 bits (not 8 as suggested above).  Are you looking at concatenating 2 10 bit numbers or 2 16 bit numbers or are you using a zero or duo in which case they could be 12 bit numbers.
In any case:
const int BITMASK = 0x3FF;  // 10 bits = 0x3FF, 12 = 0xFFF, 16 = 0xFFFF
const int BITWIDTH = 10;
long result = ((value1 & BITMASK) << BITWIDTH) | (value2 & BITMASK);

I suspect it won't give you the answer you want, but...

Sound promising... I will take a look

It sounds to me, from your comments, that what you want to do is turn this:
myRadio.transmit(val1);
myRadio.transmit(val2);

into something more like this:
myVal = join(val1, val2);
myRadio.transmit(myVal);

That's all pseudocode of course, and those functions are in themselves nonsense, but it serves to illustrate.
So you want to turn two values into one single block of data for sending thus reducing the overall transmission overhead of the packet (one large packet instead of two smaller packets).
What you are actually looking for is called a struct and looks something like this:
struct MyData {
    int val1;
    int val2;
};

That creates a new variable type which contains two sub-variables in it. You then use it like any other variable:
struct MyData data;

You can then get at the values inside it with:
data.val1 = analogRead(A1);
data.val2 = analogRead(A2);

And the whole thing can be transmitted in one block with whatever functions your RF library provides:
myRadio.transmit(&data, sizeof(struct MyData));

Receiving at the other end is just the same - as long as the receiving end has the same structure. Receive into a MyData structure variable and you can get at the individual sub-variables:
struct MyData data;
myRadio.receive(&data, sizeof(struct MyData));
Serial.print(data.val1);
Serial.print(",");
Serial.println(data.val2);

Of course, you need to read up on whatever library it is you're using to do your transmitting and receiving to find the actual correct functions to call to transmit and receive a block of data like that...

This is not even remotely related to Arduino but mathematics.
As Mikael Patel pointed out this can be done fairly easy.
You might tell us your intent.
If you are seeking for a way to pack values tightly you may consider Integer Sequence Enconding.
But without more detailed information this will be just a guess.

The intent is stated in the question as handling numbers read from two analog pins.

Well that is what he tells us, he wants to achieve. But I'm not sure he really knows what he wants to do with that. Why does it make sense to "concatenate" two integer values in decimal? Why not hex? What is the goal with that? What are the sources of the analog reads?

Actually, it can be done arithmetically with no problem, but I used 10 + 10 = 1010 just for example.
I am open to suggestions if I need to convert to HEX or BIN. I thought it was a question easy to be solved and it was just me that was missing something.

I am using a MEGA2560 to read several sensors (termistors, encoders, RTC, etc) and transmits this data over a RF433 module to an UNO. The module only send pointers pointed to strings. What I am doing is converting the data from sensors into string and sending one by one through RF.
I have a Python script reading the data on the other side, if I could concatenate all the data from the sensors to send all at once will be much easy for me handle this data in Python.

@DiegoDyan - based on what you have just said I think you need to look in a different direction.  Please see my 2nd answer.

You want to send a string of data that represents the data from a number of sensors. For example let's say you have 2 10 bit analog readings and 4 Boolean readings, high or low from the digital pins.  You can compress this into 24 bits of data, or 3 bytes.
If your transmission library supports binary writing and reading then you can send it as 3 unsigned chars.
If your transmission library doesn't support binary then you can either base64 encode it as 4 bytes. (The numbers are converted into printable characters that represent their value).  Or a more light weight solution would be to write each byte as two hexadecimal digits.
You pack the data into three bytes by using bit masking and shifting (as per my other answer).
int sensor1data = 512;
int sensor2data = 64;
bool digital1 = true;
bool digital2 = false;
bool digital3 = false;
bool digital4 = true;

unsigned char data[3]{ 0, 0, 0 };

// Take the top 8 bits of the 10 bit data on sensor1data
// 0x300 takes the 2 lowest bits of the upper byte
// 0x0FC takes the 6 highest bits of the lower byte.
// Shift the result 2 places right so the what was bit 2
// of the upper byte becomes the most significant bit (MSb)
// in the result byte.
data[0] = (sensor1data & 0x3FC) >> 2;

// Take the 2 lowest bits of the lower byte (0x03)
// Shift the 6  places left to make them the MSb of the
// result byte.
data[1] = ((sensor1data & 0x3) << 6);
// Take the 6 MSbs of the sensor2data and left shift them
// so that they become the LSbs of the result byte.
// The result is ORed onto what is already in the result
// to retain the previous instruction.
data[1] |= ((sensor2data & 0x3F0) >> 4);

// Take the 4 LSbs of sensor2data and shift them right
// for places to ocupy the 4 MSbs of the result.
data[2] = ((sensor2data & 0xF) << 4);
// OR each of the flags into the result, shifting by
// a different amount each time.
data[2] |= (digital1 ? 1 : 0) << 3; // I explicitly convert the bool to an int
data[2] |= (digital2 ? 1 : 0) << 2; // because some older compilers don't always
data[2] |= (digital3 ? 1 : 0) << 1; // use 1 for true.
data[2] |= (digital4 ? 1 : 0);

This is a very elegant solution!

If you know in advance how many variables' values you want to transmit:
char output[100+1];
....
snprintf(output, sizeof(buffer), "%d,%d,$d\n", val, val2, val3);

If not and you need to build the string "as you go":
char output[100+1] = "";
char oneVal[12+1];
...
snprintf(oneVal, sizeof(buf), "%d,", value);
strcat(output, oneVal);

// more of the above, possibly in a loop.
...
strcat(output, "\n");      // if you need a newline at the end


text:
Arduino UNO HTTPS
Is it possible to call a HTTPS web service on arduino UNO? I am trying to connect it through client.connect(ip,port). It said connected but never respond, ended up in TIMEOUT.

You have some sort of Ethernet or WIFI interface don't you, which one?

ethernet shield

No, it is not possible. The Arduino UNO is not powerful enough to encrypt the data for an SSL connection. On top of that the W5100 chip used on the Ethernet shield has its own IP stack built into it, and that stack doesn't support SSL either.
If you require SSL then it is recommended that you use one of the "dual" boards, like the Yun, and have the Linux portion of the board make the SSL connection for you using cURL.


text:
Trying to figure out how to use an extension board with Pi
I am trying to make the following board work with Raspberry Pi.
Board Name: L293D Motor Drive Shield Expansion Board for Arduino Mega Raspberry Pi

All I need to know is which pins do the following:

Enable the motor
Disable the motor
Rotate forward
Rotate backward

More information about the board:

https://learn.adafruit.com/adafruit-motor-shield/using-dc-motors
https://www.raspberrypi.org/forums/viewtopic.php?f=45&t=16118

Can someone please help me find this information?

Does the schematic not show this?

This is not an Arduino question and should be closed - it never belonged here in the first place, and it's sat abandoned by the asker for half a year now.  If it remains open, the anti-community daemon will continue to useless churn it back up.

The following pins are in use only if the DC/Stepper noted is in use:

Digital pin 11: DC Motor #1 / Stepper #1 (activation/speed control)
Digital pin 3: DC Motor #2 / Stepper #1 (activation/speed control)
Digital pin 5: DC Motor #3 / Stepper #2 (activation/speed control)
Digital pin 6: DC Motor #4 / Stepper #2 (activation/speed control)

The following pins are in use if any DC/steppers are used

Digital pin 4, 7, 8 and 12 are used to drive the DC/Stepper motors via the 74HC595 serial-to-parallel latch

The following pins are used only if that particular servo is in use:

Digitals pin 9: Servo #1 control
Digital pin 10: Servo #2 control

(source)


text:
Sending a text/notification with Arduino + ESP8266 Wifi shield
Is it possible to send a text message using an Arduino and the Sparkfun ESP8266 Wifi Shield using Temboo? I noticed that the ESP8266 might not be supported by Temboo and I was wondering if there is a workaround.
Thanks.

I work at Temboo.
While we don't officially support the ESP8266, we've found a couple of forum posts in which people have been able to get Temboo to work with the ESP8266. Here you go:
http://www.esp8266.com/viewtopic.php?p=24019
https://forum.arduino.cc/index.php?topic=337186.0
If that doesn't help, feel free to contact Temboo Support and we'll do our best to help figure out what's going wrong for you.
The key piece of info you need to be aware of is that you need to modify following Temboo library files:
\Arduino\libraries\Temboo\src\Temboo.cpp

\Arduino\libraries\Temboo\src\utility\
--ChoreoInputFormatter
--ChoreoOutputFormatter
--ChoreoPresetFormatter
--TembooSession
--tmbhmac
--tmbmd5

You need to modify all occurrences of "avr/pgmspace.h" in these files, changing it to "pgmspace.h".

Could you add a folder called avr and a file called pgmspace.h with #include "..\pgmspace.h" in?  If you could that would save re making the change if you updated the Tembo library.

Thanks for the suggestion, @Matt. I'll certainly pass it on to our dev team.

I meant for the original poster, but if it works :)

Yes, apparently you can.
I did a quick search on Google and found a GitHub library for the ESP8266 https://github.com/sabas1080/TembooForESP8266 and a post on the Arduino Forum https://forum.arduino.cc/index.php?topic=337186.0 that says you can download a skeleton program and hack that.


text:
Is it possible for ThingSpeak to show a simple table of all data collected?
I just recently found the ThingSpeak platform for the IoT. I have been playing around with its features a bit, but I have not found a way for it to show a simple table of all the data collected. For example, the table might have humidity, temperature, and timestamp columns, and then every time data is written to ThingSpeak, a new row would be added with the latest readings. I would be surprised if this is not possible with all of its complex graphing tools. Has anybody found a feature like this?

What does this have to do with the Arduino?

Since ThingSpeak has an extensive API, you can build a tool to read in data and display it as a table. I have created a GitHub repo called, "IoT Debugger" that allows you to see data as a table as the it comes into a ThingSpeak Channel.
To use the demo, enter your channel number and the read API key.
If you want to modify the project, fork the project on GitHub.


text:
Interfacing to scale over RS-232
Objective: interface and Arduino MEGA to a Mettler Toledo SB32001 using the RS-232 communication protocol described in the manual.
Equipment Used:

SB32001 Mettler Toledo 32 kg scale
Arduino MEGA
Sparkfun RS232 Shifter - SMD

Background:
I am using the SoftwareSerial library to try to communicate with the scale through MEGA pins 52 and 53. I have the level shifter connected to the scale using a through cable.
So far, I have tried to send the most basic command to the scale, and the command is both not executing, and not causing a status code to be send back (i.e. failure OR success). My Tx light on the level shifter flashes, but the Rx light never does.
Write string to screen:
D "String"
Because I have a through cable, I have tried switching the Tx and Rx pins in code. Neither has worked.
The from the scale has the following options I can set:

Baud Rate: 150, 300, 600, 1200, 2400, 4800, 9600
Parity: 7b-E, 7b-no, 8b-no, 7b-odd

Here is a minimal (non)working example of my code:
#include <SoftwareSerial.h>

const int pinTX = 53;
const int pinRX = 52;

scale = SoftwareSerial(53, 52);

void setup(){
    Serial.begin(9600);
    scale.begin(9600);
    delay(100);
}

void loop(){
    scale.println("D \"Hello!?\"");
    delay(100);

    while (scale.available()){
        Serial.print(scale.read());
    }
    Serial.println()
    delay(100);
}

What I need:
I need help figuring out where I should look next to solve this issue. I have tried switching the transmit and receive pins in software. I have tried using jumpers to switch the Tx and Rx pins in hardware. I have tried 7 and 8-bit settings with no parity. Nothing give me a signal back. Totally perplexed?
Is it my converter chip? Does anyone know of problems with this shifter? I know that it does not contain the industry standard MAX232

"I have tried switching the Tx and Rx pins in code" The drivers are unidirectional.

Did you remember to send the CRLF?

According to my understanding of the documentation, println() automatically applies a CRLF.

I switched the Tx and Rx pins by changing the line scale = SoftwareSerial(52, 53); to scale = SoftwareSerial(53, 52);

Your quote escaping is wrong: "D "\Hello!?\"" should be "D \"Hello!?\""

Why do people insist on trying to use SoftwareSerial on a Mega when the Mega has multiple hardware UART ports?!?! Unless you are wiring lots and lots of UART based things to your Mega there is absolutely no reason to ever use SoftwareSerial!

Because we are naive

Fixed the escape character typo. Unfortunately that was just a transcription error, but even if it wasn't, I would expect to get an error code back from the scale.

Have you tried to connect your computer directly to the Scale serial port and use a terminal (putty for example) to send and received data to the scale?

Indeed, trying to make this work from an embedded system when you haven't first verified your understanding of its requirement by far simpler experiments from a PC is just wasting time.

The solution turned out to be a couple of things, some of which mentioned by others in the comments.
Problems that needed to be fixed:

My level-shifter was a huge part of the problem. I switched to a MAX232-based chip and then I was a least able to get responses shorted lines 2 and 3 (Tx and Rx).
I needed a cross-over cable. I had tried this while troubleshooting, but because that alone didn't fix the problem, I had not idea whether or not that was the problem, or just one of the problems.
I needed to use the onboard UART (Serial1) rather than SoftwareSerial. The problem was that I needed to be able to set the protocol to 8 bits with no parity. This configuration parameter cannot be changed on SoftwareSerial, but is as simple as Serial1.begin(9600, SERIAL_8N2).

Thank you for the help, and hopefully my mistakes make the process easier for others.

Thats 8 bits, no parity and 2 stop bits. The last property is what distinguishes your mode from the usual one, 8N1.

Did my comment get deleted (strange)? I had said that the SERIAL_8N2 configuration is straight from a code example I was using, and that I just went with it because I knew I needed 8-bits and it worked. The manual doesn't specify (or mention) stop bits, but it seemed to work. I get a lot of invalid command codes back from the scale (~70%), so I may try the SERIAL_8N1 configuration to see if that improves the response. Then again, my 'cross-over' cable is a bunch of breadboard jumpers jammed onto the pins to swtich Tx and Rx, so that faulty, unreliable connection could be the problem too.


text:
Can multiple xbees send data to one xbee
I am new to xbees. I want to have multiple xbees (up to 400 xbees) send data constantly to one xbee (receiver).This is just simple data like lets say 0 or 1 . Is this possible? Are there any limitations?

Yes, you can send data from 400 XBees to a single xbee. I would like to clarify one thing. XBees are connecting to a network, not to a particular xbee. And the devices connected in a network can communicate each other.

Thank you. My goal afterwards is for the receiver xbee connected to wifi module to send the data from all 400 xbees to the server.I am assuming that is also possible?


text:
Connecting multiple TFT panels to Arduino Uno via SPI?
Is it possible to connect more than one TFT screen (like this one or similar: https://www.adafruit.com/products/1651) to an Arduino Uno?
I'm wanting to connect and control two color screens at once; note the touch functionality of the one linked above isn't really necessary, I just like the size and overall build. They have a version that works like a shield and sits on top of the Arduino, which would work I suppose if I bought another unit for the other screen. The breakout board version is more flexible but I don't know of a way to control two screens that require that many pins.
Any suggestions?
Thanks

Yes, you can. All the SPI pins (MISO, MOSI and SCK) are all shared between the panels. You can even share the D/C and RST signals. The only signal that needs to be separate is the CS pin since this is the pin that identifies which panel is actively receiving commands and data at any one time. Also you don't need to connect up the MISO pin at all, since that is only connected to the SD card slot, not the TFT screen.
So each screen that you add just requires one more pin to be used. One screen uses 5 pins. Two screens use 6 pins. Three screens use 7 pins, etc.
And yes, for this the breakout version would be easier to work with than the shield version.

Similarly, would communicating in 8-bit mode be possible? If draw speed was a concern that is

Sure. The data lines are shared and wr and Rd are unique.

Actually for 8 bit parallel you can share RD and WR as well. It's the CS pin on there that is unique. I couldn't remember if there was a CS or not, and certainly on the 8-bit parallel TFT I just grabbed from my box there is a CS pin.