text:
Wearable GPS LED help
I'm very new to Arduino and C++ and have been playing with the Flora Wearable GPS. However, nowhere I've looked has given me any help in setting and changing the color of the LEDs. The tutorial on their site is barebones and doesn't explain how to modify code and make the colors change. I've tried mixing what I know, but none of it results in what I want: one color to show when I'm in range of a a point, and another to show when I'm not.
// Flora GPS + LED Pixel Code
//
// This code shows how to listen to the GPS module in an interrupt
// which allows the program to have more 'freedom' - just parse
// when a new NMEA sentence is available! Then access data when
// desired.
//
// Tested and works great with the Adafruit Flora GPS module
//    ------> http://adafruit.com/products/1059
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include "Adafruit_NeoPixel.h"
Adafruit_GPS GPS(&Serial1);

// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO false

#define PIN 6

// this keeps track of whether we're using the interrupt
// off by default!
boolean usingInterrupt = false;

//--------------------------------------------------|
//                    WAYPOINTS                     |
//--------------------------------------------------|
//Please enter the latitude and longitude of your   |
//desired destination:                              |
  #define GEO_LAT                44.995012
  #define GEO_LON               -93.228967
//--------------------------------------------------|

//--------------------------------------------------|
//                    DISTANCE                      |
//--------------------------------------------------|
//Please enter the distance (in meters) from your   |
//destination that you want your LEDs to light up:  |
  #define DESTINATION_DISTANCE   20
//--------------------------------------------------|

// Navigation location
float targetLat = GEO_LAT;
float targetLon = GEO_LON;

// Trip distance
float tripDistance;

boolean isStarted = false;

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

uint8_t LED_Breathe_Table[]  = {   80,  87,  95, 103, 112, 121, 131, 141, 151, 161, 172, 182, 192, 202, 211, 220,
              228, 236, 242, 247, 251, 254, 255, 255, 254, 251, 247, 242, 236, 228, 220, 211,
              202, 192, 182, 172, 161, 151, 141, 131, 121, 112, 103,  95,  87,  80,  73,  66,
               60,  55,  50,  45,  41,  38,  34,  31,  28,  26,  24,  22,  20,  20,  20,  20,
               20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,
               20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  22,  24,  26,  28,
               31,  34,  38,  41,  45,  50,  55,  60,  66,  73 };

#define BREATHE_TABLE_SIZE (sizeof(LED_Breathe_Table))
#define BREATHE_CYCLE    5000      /*breathe cycle in milliseconds*/
#define BREATHE_UPDATE    (BREATHE_CYCLE / BREATHE_TABLE_SIZE)
uint32_t lastBreatheUpdate = 0;
uint8_t breatheIndex = 0;

void setup()
{
  // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
  // also spit it out
  Serial.begin(115200);

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);

  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  // the parser doesn't care about other sentences at this time

  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  // For the parsing code to work nicely and have time to sort thru the data, and
  // print it out we don't suggest using anything higher than 1 Hz

  delay(1000);
  // Ask for firmware version
  Serial1.println(PMTK_Q_RELEASE);

    // Start up the LED strip
  strip.begin();

  // Update the strip, to start they are all 'off'
  strip.show();
}

uint32_t timer = millis();

void loop()                     // run over and over again
{
  // read data from the GPS in the 'main loop'
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if (GPSECHO)
      if (c) Serial.print(c);

  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences!
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false

    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }

    if (GPS.fix) {
      //Serial.print("Location: ");
      //Serial.print(GPS.latitude, 2); Serial.print(GPS.lat);
      //Serial.print(", ");
      //Serial.print(GPS.longitude, 2); Serial.println(GPS.lon);

      float fLat = decimalDegrees(GPS.latitude, GPS.lat);
      float fLon = decimalDegrees(GPS.longitude, GPS.lon);

      if (!isStarted) {
        isStarted = true;
        tripDistance = (double)calc_dist(fLat, fLon, targetLat, targetLon);
      }

      //Uncomment below if you want your Flora to navigate to a certain destination.  Then modify the headingDirection function.
      /*if ((calc_bearing(fLat, fLon, targetLat, targetLon) - GPS.angle) > 0) {
        headingDirection(calc_bearing(fLat, fLon, targetLat, targetLon)-GPS.angle);
       }
      else {
        headingDirection(calc_bearing(fLat, fLon, targetLat, targetLon)-GPS.angle+360);
      }*/

      headingDistance((double)calc_dist(fLat, fLon, targetLat, targetLon));
      //Serial.print("Distance Remaining:"); Serial.println((double)calc_dist(fLat, fLon, targetLat, targetLon));

    }
  //}

}

int calc_bearing(float flat1, float flon1, float flat2, float flon2)
{
  float calc;
  float bear_calc;

  float x = 69.1 * (flat2 - flat1);
  float y = 69.1 * (flon2 - flon1) * cos(flat1/57.3);

  calc=atan2(y,x);

  bear_calc= degrees(calc);

  if(bear_calc<=1){
    bear_calc=360+bear_calc;
  }
  return bear_calc;
}

void headingDirection(float heading)
{
  //Use this part of the code to determine which way you need to go.
  //Remember: this is not the direction you are heading, it is the direction to the destination (north = forward).
  if ((heading > 348.75)||(heading < 11.25)) {
    Serial.println("  N");
    //Serial.println("Forward");
  }

  if ((heading >= 11.25)&&(heading < 33.75)) {
    Serial.println("NNE");
    //Serial.println("Go Right");
  }

  if ((heading >= 33.75)&&(heading < 56.25)) {
    Serial.println(" NE");
    //Serial.println("Go Right");
  }

  if ((heading >= 56.25)&&(heading < 78.75)) {
    Serial.println("ENE");
    //Serial.println("Go Right");
  }

  if ((heading >= 78.75)&&(heading < 101.25)) {
    Serial.println("  E");
    //Serial.println("Go Right");
  }

  if ((heading >= 101.25)&&(heading < 123.75)) {
    Serial.println("ESE");
    //Serial.println("Go Right");
  }

  if ((heading >= 123.75)&&(heading < 146.25)) {
    Serial.println(" SE");
    //Serial.println("Go Right");
  }

  if ((heading >= 146.25)&&(heading < 168.75)) {
    Serial.println("SSE");
    //Serial.println("Go Right");
  }

  if ((heading >= 168.75)&&(heading < 191.25)) {
    Serial.println("  S");
    //Serial.println("Turn Around");
  }

  if ((heading >= 191.25)&&(heading < 213.75)) {
    Serial.println("SSW");
    //Serial.println("Go Left");
  }

  if ((heading >= 213.75)&&(heading < 236.25)) {
    Serial.println(" SW");
    //Serial.println("Go Left");
  }

  if ((heading >= 236.25)&&(heading < 258.75)) {
    Serial.println("WSW");
    //Serial.println("Go Left");
  }

  if ((heading >= 258.75)&&(heading < 281.25)) {
    Serial.println("  W");
    //Serial.println("Go Left");
  }

  if ((heading >= 281.25)&&(heading < 303.75)) {
    Serial.println("WNW");
    //Serial.println("Go Left");
  }

  if ((heading >= 303.75)&&(heading < 326.25)) {
    Serial.println(" NW");
    //Serial.println("Go Left");
  }

  if ((heading >= 326.25)&&(heading < 348.75)) {
    Serial.println("NWN");
    //Serial.println("Go Left");
  }
}

void headingDistance(float fDist)
{
  //Use this part of the code to determine how far you are away from the destination.
  //The total trip distance (from where you started) is divided into five trip segments.
 Serial.println(fDist);
 if ((fDist >= DESTINATION_DISTANCE)) { // You are now within 5 meters of your destination.
    //Serial.println("Trip Distance: 1");
    //Serial.println("Arrived at destination!");
    int i;
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, 0, 0, 0);
    }
    strip.show();   // write all the pixels out
  }

  if ((fDist < DESTINATION_DISTANCE)) { // You are now within 5 meters of your destination.
    //Serial.println("Trip Distance: 0");
    //Serial.println("Arrived at destination!");
    breath();
  }

}

unsigned long calc_dist(float flat1, float flon1, float flat2, float flon2)
{
  float dist_calc=0;
  float dist_calc2=0;
  float diflat=0;
  float diflon=0;

  diflat=radians(flat2-flat1);
  flat1=radians(flat1);
  flat2=radians(flat2);
  diflon=radians((flon2)-(flon1));

  dist_calc = (sin(diflat/2.0)*sin(diflat/2.0));
  dist_calc2= cos(flat1);
  dist_calc2*=cos(flat2);
  dist_calc2*=sin(diflon/2.0);
  dist_calc2*=sin(diflon/2.0);
  dist_calc +=dist_calc2;

  dist_calc=(2*atan2(sqrt(dist_calc),sqrt(1.0-dist_calc)));

  dist_calc*=6371000.0; //Converting to meters
  return dist_calc;
}

// Convert NMEA coordinate to decimal degrees
float decimalDegrees(float nmeaCoord, char dir) {
  uint16_t wholeDegrees = 0.01*nmeaCoord;
  int modifier = 1;

  if (dir == 'W' || dir == 'S') {
    modifier = -1;
  }

  return (wholeDegrees + (nmeaCoord - 100.0*wholeDegrees)/60.0) * modifier;
}

void breath()
{
  uniformBreathe(LED_Breathe_Table, BREATHE_TABLE_SIZE, BREATHE_UPDATE, 127, 127, 127);
}

void uniformBreathe(uint8_t* breatheTable, uint8_t breatheTableSize, uint16_t updatePeriod, uint16_t r, uint16_t g, uint16_t b)
{
  int i;

  uint8_t breatheBlu;

  if ((millis() - lastBreatheUpdate) > updatePeriod) {
    lastBreatheUpdate = millis();

    for (i=0; i < strip.numPixels(); i++) {
      breatheBlu = (b * breatheTable[breatheIndex]) / 256;
      strip.setPixelColor(i, 0, 0, breatheBlu);
    }
    strip.show();

    breatheIndex++;
    if (breatheIndex > breatheTableSize) {
      breatheIndex = 0;
    }
  }
}

What gets me the most is this part
void headingDistance(float fDist)
{
  //Use this part of the code to determine how far you are away from the destination.
  //The total trip distance (from where you started) is divided into five trip segments.
 Serial.println(fDist);
 if ((fDist >= DESTINATION_DISTANCE)) { // You are now within 5 meters of your destination.
    //Serial.println("Trip Distance: 1");
    //Serial.println("Arrived at destination!");
    int i;
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, 0, 0, 0);
    }
    strip.show();   // write all the pixels out
  }

  if ((fDist < DESTINATION_DISTANCE)) { // You are now within 5 meters of your destination.
    //Serial.println("Trip Distance: 0");
    //Serial.println("Arrived at destination!");
    breath();
  }

}

Since the comments say both are for within 5 meters but have opposite conditions and "fDist" isn't defined anywhere that I can see, I don't know which is for near or far or how to set a color to either one. I tried setting colors for the first if statement and they seemed to work, but I couldn't get it to work consistently for some reason.

I think others have addressed the need for you to modify the strip colors based on distance or bearing or... whatever you want to show.
Here's a NeoGPS version of that sketch.  I think it may be easier to understand what's going on, and where you need to focus:
// Flora GPS + LED Pixel Code
//   Modified to use NeoGPS library.
//
// Adafruit Flora GPS module
//    ------> http://adafruit.com/products/1059
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada

#include "Adafruit_NeoPixel.h"
#include <NMEAGPS.h>

NMEAGPS gps;
gps_fix fix;
#define gpsPort Serial1

const int NEOPIXEL_PIN = 6;

//----------------------------------------------------|
//                     WAYPOINTS                      |
//----------------------------------------------------|
// Please enter the latitude and longitude of your    |
// desired destination:                               |
NeoGPS::Location_t destination( 449950120L, -932289670L );
//  To be more accurate, these are degrees * 10000000 |
//----------------------------------------------------|

//--------------------------------------------------|
//                    DISTANCE                      |
//--------------------------------------------------|
//Please enter the distance (in meters) from your   |
//destination that you want your LEDs to light up:  |
const float DESTINATION_DISTANCE = 20.0;

//--------------------------------------------------|
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel( 8, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800 );

uint8_t LED_Breathe_Table[]  =
  {
     80,  87,  95, 103, 112, 121, 131, 141, 151, 161, 172, 182, 192, 202, 211, 220,
    228, 236, 242, 247, 251, 254, 255, 255, 254, 251, 247, 242, 236, 228, 220, 211,
    202, 192, 182, 172, 161, 151, 141, 131, 121, 112, 103,  95,  87,  80,  73,  66,
     60,  55,  50,  45,  41,  38,  34,  31,  28,  26,  24,  22,  20,  20,  20,  20,
     20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,
     20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  22,  24,  26,  28,
     31,  34,  38,  41,  45,  50,  55,  60,  66,  73
  };

#define BREATHE_TABLE_SIZE (sizeof(LED_Breathe_Table))
#define BREATHE_CYCLE      5000      /*breathe cycle in milliseconds*/
#define BREATHE_UPDATE     (BREATHE_CYCLE / BREATHE_TABLE_SIZE)
uint32_t lastBreatheUpdate = 0;
size_t   breatheIndex      = 0;

void setup()
{
  Serial.begin(115200);
  gpsPort.begin(9600);  // default baud rate for Adafruit MTK GPS's - some use 4800

  gps.send_P( &gpsPort, F("PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0") ); // RMC+GGA
  delay(100);
  gps.send_P( &gpsPort, F("PMTK220,1000") ); // 1Hz
  delay(100);
  gps.send_P( &gpsPort, F("PGCMD,33,0") ); // No antenna status

  strip.begin();
  strip.show();  // Update the strip, to start they are all 'off'
}

void loop()
{
  if (gps.available( gpsPort ) ) {
    fix = gps.read();

    const bool spoof = false; // change to true for spoofing
    if (spoof) {
      float t           = fix.dateTime.seconds / 4.0;  // 15 second cycle (60 / 4)
      float offsetAngle = (TWO_PI / 20.0) * t;         // 20 steps around circle
      float offsetDist  = 0.005 * t / NeoGPS::Location_t::EARTH_RADIUS_KM;
                           // 5m per second, 75m away or less. In RADIANS!
      fix.location = destination; // start here and step away
      fix.location.OffsetBy( offsetDist, offsetAngle );
    }

    //Serial.print( F("Location: ") );
    //Serial.print( fix.latitude(), 5 );
    //Serial.print( F(", ") );
    //Serial.print( fix.longitude(), 5 );

    if (fix.valid.location) {
      float distance = fix.location.DistanceKm( destination ) * 1000.0; // meters

      // Set below to true if you want your Flora to navigate to a
      //  certain destination.  Then modify the showDirection function.
      const bool showNavigationHints = true;

      if (showNavigationHints) {

        float bearing = fix.location.BearingToDegrees( destination );

        //  If we're moving fast enough, show the user which way to go, left or right.
        if (fix.valid.heading and (fix.valid.speed and fix.speed_kph() > 3.0)) {

          float courseCorrection = bearing - fix.heading();
          if (courseCorrection < 0.0)
            courseCorrection += 360.0;

          showDirection( courseCorrection );

        } else {
          // We're not moving very fast, show a compass direction.
          showDirection( bearing );
        }
      }

      showDistance( distance );
    }
  }
}

void showDirection( float bearing )
{
  //  Use this to show which way you need to go.
  //    Some times, it's an absolute compass direction.
  //    Other times, it's a course correction (left or right from current heading)

  const __FlashStringHelper *dir = compassDir( bearing );
  size_t dirLen = strlen_P( (const char *) dir );
  for (uint8_t i = 0; i < (3 - dirLen); i++)
    Serial.print( ' ' );
  Serial.println( dir );
}

void showDistance(float distance)
{
  Serial.println( distance );

  // Are we close enough?
  if (distance >= DESTINATION_DISTANCE) {
    // No.

    const uint8_t level = 0; // you might set this based on distance

    for (int i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor( i, level, level, level );
    }
    strip.show();   // write all the pixels out

  } else {
    // Yes!
    // Serial.println("Arrived at destination!");
    breath();
  }

}

//------------------------------------------------------------
// This is copied from the NeoGPS NMEAaverage.ino example program

const char nCD  [] PROGMEM = "N";
const char nneCD[] PROGMEM = "NNE";
const char neCD [] PROGMEM = "NE";
const char eneCD[] PROGMEM = "ENE";
const char eCD  [] PROGMEM = "E";
const char eseCD[] PROGMEM = "ESE";
const char seCD [] PROGMEM = "SE";
const char sseCD[] PROGMEM = "SSE";
const char sCD  [] PROGMEM = "S";
const char sswCD[] PROGMEM = "SSW";
const char swCD [] PROGMEM = "SW";
const char wswCD[] PROGMEM = "WSW";
const char wCD  [] PROGMEM = "W";
const char wnwCD[] PROGMEM = "WNW";
const char nwCD [] PROGMEM = "NW";
const char nnwCD[] PROGMEM = "NNW";

const char * const dirStrings[] PROGMEM =
  { nCD, nneCD, neCD, eneCD, eCD, eseCD, seCD, sseCD,
    sCD, sswCD, swCD, wswCD, wCD, wnwCD, nwCD, nnwCD };

const __FlashStringHelper *compassDir( uint16_t bearing ) // degrees CW from N
{
  const int16_t directions    = sizeof(dirStrings)/sizeof(dirStrings[0]);
  const int16_t degreesPerDir = 360 / directions;
        int8_t  dir           = (bearing + degreesPerDir/2) / degreesPerDir;

  while (dir < 0)
    dir += directions;
  while (dir >= directions)
    dir -= directions;

  return (const __FlashStringHelper *) pgm_read_ptr( &dirStrings[ dir ] );

} // compassDir

//--------------------------

void uniformBreathe
  ( uint8_t *breatheTable, size_t breatheTableSize,
    uint16_t updatePeriod,
    uint16_t r, uint16_t g, uint16_t b )
{

  if ((millis() - lastBreatheUpdate) > updatePeriod) {
    lastBreatheUpdate = millis();

    for (int i=0; i < strip.numPixels(); i++) {
      uint8_t breatheBlu = (b * breatheTable[breatheIndex]) / 256;
      strip.setPixelColor( i, 0, 0, breatheBlu );
    }
    strip.show();

    breatheIndex++;
    if (breatheIndex > breatheTableSize) {
      breatheIndex = 0;
    }
  }
}

void breath()
{
  uniformBreathe(LED_Breathe_Table, BREATHE_TABLE_SIZE, BREATHE_UPDATE, 127, 127, 127);
}

I am always amazed by how much a little whitespace can improve the readability.
 Good variable and function names are also important.  You are also being misled by bad comments.  :P
I have added some location "spoofing" code that lets you test it without having to walk around.  That spoofing section can be removed when you're done testing.
If you want to try it, NeoGPS is available from the Arduino Library Manager, under the menu Sketch-> Include Library-> Manage Libraries.  BTW, this saves about 500 bytes of RAM.
To answer your original question, the showDistance and showDirection functions should be modified to do whatever you want.

Three comments:

For someone who is new to Arduino and programming (or perhaps just new
to C / C++), you have taken on a large challenge.
It should be widely said (but it is not) that not all Arduino
libraries are compatible with one another.  And that it is up to the
user (or community) to identify conflicts.  As there are far too
many combinations for any one person to test them all.
You should ask only 1 question per post.  I think you are most
interested about programming different colors for a WS2812 LED.  So
we should not talk about GPS for now.

Most if not all Adafruit.com software source code are available free to the community at github.com.  The Adafruit_NeoPixel github repository  at github should contain all the source code for this project as well as several files of example code. In the example code is this segment of code that changes the LED color:
  switch(i){
    case 0: colorWipe(strip.Color(0, 0, 0), 50);    // Black/off
            break;
    case 1: colorWipe(strip.Color(255, 0, 0), 50);  // Red
            break;
    case 2: colorWipe(strip.Color(0, 255, 0), 50);  // Green
            break;
    case 3: colorWipe(strip.Color(0, 0, 255), 50);  // Blue
            break;
...removed some code for clarity...
    }

It is not really clear what your actual problem is. I will go with the following:

How to set the colors of the RGB LEDs: You are already using the Adafruit_NeoPixel library. The definition of Adafruit_Neopixel strip shows, that you have a strip with 8 LEDs. In setup the sketch calls strip.begin() to initiate it. After that, everytime you want to change the color/state of any number of LEDs on the strip, you can set them one by one with strip.setPixelColor(), which takes the number of the LED and the color in RGB format as parameters. To make the LEDs show your changes you have to call strip.show(), which sends the data to the LEDs.
What your sketch does: In the function headingDistance(float fDist) the colors of the LEDs are set according to the previously calculated distance. fDist comes as parameter to this function, so it is declared in the function header. The value comes from the function calc_dist(). Now you have 2 if-statements:

The first one (if you are farer away from your target) will set the color of all LEDs to black (turning them off) by calling strip.setPixelColor(i, 0, 0, 0) for every LED and then calling strip.show(). So this is easy.
The second one (if you are within the 5m radius) calls the function breath(). It will set the intensity of the blue color component for all LEDs dependent on it's parameter b and the time that passed since it set the LEDs color the last time (this is done with the millis()-if-statement). The function headingDistance() is called in loop(), whenever the fix variable of the GPS is set. Calling the breath() function (which is called from headingDistance()) very often results in a timed update of the LEDs every updatePeriod milliseconds. Refer to the BlinkWithoutDelay example in the Arduino IDE for this working principle. It leaves you time to do other things during the wait periods, because it is non-blocking. The breath() function is a more complex thing, than simply turning on and of the LEDs with the right color. If you just want to do that, replace it's call in headingDistance() with your own code, setting the LEDs like I explained above.

So:

one color to show when I'm in range of a a point, and another to show when I'm not.

Set the color values in RGB format in the first if-statement, to set for the case that your are not in the range of your GPS point. And replace the breath() function by a similar code with the color values in RGB format for the case, that you are within the range of your point.
If it still doesn't work, try if the original sketch works correctly. This would verify, that the measurement and calculation of the distance works as intended.


text:
Ribbon sensor resistance slowly drops when released
I recently bought a ribbon sensor (the one displayed here), with the intention to use it as a touch-enabled music instrument.
I used it correctly (so it seems), but I have two issues :

When not pressed, the sensor seems to give random data, as if nothing was plugged to the pin.
When unpressed, the resistance slowly decreases (and so is my sound pitch). Is that a normal behaviour ?

I don't know how to solve both issues. Has anyone an idea ?
A tinker of my test (Currently corrected thanks to @VE7JRO) can be seen here with my code here (The ribbon is replaced by a potentiometer but the principle remains the same). The code is also Available on GitHub.

The instructions on Adafruit say "When no pressure is applied, the middle pin floats, so be sure to use some sort of weak pull-up, such as 100K ohm.". Have you connected it to your Arduino using all of the "To use" directions?

I didn't quite understood this instruction (English is not my first language), so it should work with a 100kohm resistor between the middle pin and the reading pin ?

The Adafruit website says this:
There is a nominal 10K resistance across the two outer leads. The middle pin resistance with respect to either of the outer pins changes depending on where on the strip one presses. When no pressure is applied, the middle pin floats, so be sure to use some sort of weak pullup, such as 100K ohm.
To use Connect one side pin to ground via a 10K resistor in series. Connect the other side pin to your Vcc power line (3V, 5V etc) via a different 10K resistor in series. Then read the analog voltage on the center pin. It will range from 1/3 Vcc to 2/3 Vcc . Do not connect to Ground and Power directly!
Here is a diagram of how I would connect it to a 5V Arduino Uno.

Yes, it works, thanks ! I didn't understood where to put this resistor first.

source: Stack Exchange

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

sort: votes


text:
Arduino Uno as Xbox One Controller?
I’m very new to Arduino and have been doing a lot of research on how to connect my Arduino Uno to my Xbox One as a wired controller, unfortunately I haven’t been able to find much help.  I found UnoJoy but it seems to only work with PlayStation.  I know that it is possible because the Uno has HID.  I’m sorry if this has been answered before, but how do I code the Uno so the Xbox will recognize it so I can assign (push buttons, toggle switches, rotary encoders) to certain functions in game?

The Uno does not normally have HID.  It is true that USB its interface chip can be reprogrammed to do that, but it's complicated and complicates normal operation.  You'd be better of with a direct USB board like a Leonardo or something else based on a 32u4, or something based on a suitable ARM part like most of the Teensy series.

I expect if you do some research you will find there is a body of knowledge on fully custom game controllers.  Actually had some unrelated boards assembled once by someone who had invested in short-run assembly equipment in order to serve that market.

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


text:
ESP8266 in AP Mode -determining if a station is connected
I have an ESP8266 running in AP mode using softAP and i want to conserve battery life.
I am wanting to turn on wifi and advertise SSID for 20 seconds. If no station connects to the ssid within the 20 seconds, I want to go to sleep for 1 minute, otherwise I do not sleep.
My problem is that I cannot get "WiFi.softAPgetStationNum()" working. when I build i get a message that this is not part of ESP8266WiFi class. I have attached simplified code.
Can someone help me to achieve this please?
#include <ESP8266WiFi.h>

//WIFI Access point setup
const char* Ssid = "SSID";
const char* Password = "Password";
IPAddress ip(10,0,0,10);
IPAddress gateway(10,0,0,1);
IPAddress subnet(255,255,255,0);
WiFiServer server(80);                    // Set web server port number to
80

// GPIO pins
const int output_set = 5;
int delay_loop=0;

void setup()
{
  // Data Direction
  pinMode(output_set, OUTPUT);

  // Output initial Values
  digitalWrite(output_set, LOW);

  WiFi.softAPConfig(ip,gateway,subnet);
  WiFi.softAP(Ssid,Password);
  server.begin();

// check to see if a station is connected to this AP. If no station
connected within 20 sec timeframe, go to sleep.

while (WiFi.softAPgetStationNum()==0)              //loop here while no AP is connected to this station
{
    delay(1);
    delay_loop++;
    if (delay_loop>=20000)
    {

        ESP.deepSleep(60e6);                          //go to sleep for 60 sec -wake pin externally connected to reset pin
    }
}
}

void loop()
{
   digitalWrite(output_set, HIGH);      //Flash led once station is connected
   delay(200);
   digitalWrite(output_set, LOW);
   delay(400);
}

Cannot reproduce. Above code builds fine for me in PlatformIO and in Arduino IDE 1.8.3 using Arduino-ESP8266 version 2.4.1 and ESP8266WiFi library version 1.0.0. What version are you using?

Hi, thanks for your response, Arduino IDE Ver:1.8.5, ESP8266WiFi library Ver: 1.0.0.  I am unsure what Arduino-ESP8266 v2.4.1 is? are you able to clarify this?

I have: http://arduino.esp8266.com/stable/package_esp8266com_index.json added to my additional boards manager URL in preferences

That URL is correct. What version does boardmanager say you have for esp8266? (Tools->Board->Board manager)

it said 2.0.0, and I have now changed it to 2.4.1. My problem has now been solved. Thank you for your help with this. I continue to learn. Kudos.

Followup answer from comments:
The issue was an outdated version of the ESP8266-Arduino framework. The function WiFi.softAPgetStationNum() is available in 2.4.1
For the sake of completeness: The function itself is simply a wrapper for the Espressif non-os SDK function:
/**
 * Get the count of the Station / client that are connected to the softAP interface
 * @return Stations count
 */
uint8_t ESP8266WiFiAPClass::softAPgetStationNum() {
    return wifi_softap_get_station_num();
}

See Espressif Non-OS SDK API reference chapter 3.5.36.
That function should also be available on older framework versions. However, upgrading is the recommended way to use that function.


text:
Is there a way to send data from Tensorflow to Arduino via Bluetooth?
I am not sure if such a question is accepted here. If not please direct me to a more suitable Exchange.
I am planning a small project involving Machine Learning using TensorFlow and Python, which involves GAIT learning of a quadrupedal robotic system. The robotic system will be controlled by a simple Arduino. This will send data to the 8 servo motors located in the 4 legs of the robot. (2 on each leg) The robot is similar to this.
My question is if there a way to transfer data to and from Tensorflow via Bluetooth to the Arduino.
The Arduino will not be connected serially to my PC, so serial communication is not an option. Bluetooth and Wireless remain, of which, Bluetooth is generally easier.
I have done several projects involving HC-05 modules to transfer data from different systems to an Arduino so that part is not an issue. What I am interested in is if Tensorflow offers this kind of support, or if there is an easier way to do this. Searching online did not yield any results related to what I am after.
Any tips or suggestions would be appreciated.

"What I am interested in is if Tensorflow offers this kind of support, or if there is an easier way to do this." That's not an Arduino question.

Any advice on a better exchange to ask this? I thought that there was quite a possibility that someone from this community would have done something similar.

Robotics Stack Exchange might be a better fit. I can migrate your question there if you want.

The question is more "Is there a way to send data from Python ?" than "Is there a way to send them from Tensorflow to an Arduino ?" and the Answer is yes.
In Tensorflow your can recover your result in a tensor (which you can easily transform in a Python array) and then send it with Python through whatever support you want to the Arduino.


text:
How to loop the result
int receive_pin = 2;

#define MAX 120
int value[MAX];
unsigned long time[MAX];
int changes;
int printed;

void setup() {
    Serial.begin(9600);
    pinMode(receive_pin, INPUT);

    changes = 0;
    printed = 0;
    attachInterrupt(2, change_handler, CHANGE);
    Serial.println("Receiver 433MHz setup");
}

void change_handler()
{
    if (changes >= MAX) return;
    value[changes] = digitalRead(receive_pin);
    time[changes] = micros();
    changes++;
}

void loop() {
  if (printed + 1 < changes) {
      Serial.println(time[printed+1] - time[printed]);
      printed++;
  }
}

Hi all
when i run this sketch after the result its stop and i close the serial monitor to run it again
my question how to make it run with out restart it

test the code with a button on pin 2

Without knowing what your goals are and what you expect this sketch to do, it is really hard to figure out how to help you. Please add more details, so what should this sketch do and what you want it to do. I think that Juraj's comment is right, but since the whole target of this setch seems to be to count the pulses, well, it seems strange that you don't know that you have to make a pulse on pin 2 to detect it...

atleast declare int changes to be volatile.

@frarugi87, based on the "Receiver 433MHz setup", I suspect that the source of the pulses is some other device


text:
connecting 5 mq sensor at a time
I want to take a reading from 5 different mq sensor at a time. do I need an external power source to power these sensors or it will be ok to power sensors from 5v available from the board? I am using arduino uno board .

How much current does each sensor draw?

@VE7JRO     maximum current drawn by each sensor is 240 ma . I have measured using multimeter altough its power rating is given as 800 mw .

I only had experience with the MQ2 sensor (more info here), so I'm going to use it as an example. If you have different sensors double check their datasheets.
Now, the main current consumption for these comes from the heater. Can you turn the heater off to save some power? Apparently not, since they say that

Please note that the best preheat time for the sensor is above 24
  hours.

So, for the moment, let's consider all five sensors turned on at the same time.
The heater specs say that its resistance is around 33 ohm +/- 5% in the worst case this means 31.35 ohms. At 5V, this means 160mA for each sensor. Five of them are 800mA, and then let's add something like 50mA for the rest of the circuit (just a random number, and highly depends on the rest of the circuit).
Now, how is the UNO powered? If it is powered from the USB, the maximum current you can draw is 500mA (so 850mA is not allowed). So.. No powering from USB. If, on the other hand, the board is powered by the barrel jack, the onboard regulator can dissipate roughly 1-1.5W (taken from this thread). The power dissipation comes from the input voltage. With a 9V input, about 3V (slightly more) will need to be handled by the regulator. At 850mA, this means 2.5W (Not ok). In both cases you will need an external 5V power supply. With a 7V input (the very minimum you can apply) you will have to dissipate roughly 1.2V, at 850mA this means 1.02W. Please beware that this means something like 80-90°C of temperature increase in that area, so the part will become very hot. And moreover its lifespan will be reduced. So use this path only if really necessary.
If you reduce the performances and start powering just one sensor at a time (this means longer time before having it fully operational, and adding some transistor to switch them on and off) this data can change. I mean, if put a transistor to stop powering it, and then turn on one sensor at a time, you will be able to reduce the maximum current consumption to 210mA.
This means that you will be able to get power from the USB port; moreover you will be able to use the external power connector for voltages up to 10.5V (0.8V on the diode, so 4.7V on the regulator - around 1W). This comes at a price, of course: the heater will work for 1/5 of the time, so it will be harder to reach the temperature required for the measurement

160 ma is the maximum requirement. For safer side, if I take 120 ma per sensor that is total 720 ma. Now can I use an external power source whose output is 5v and power rating is 3500 mw or around this? . One more doubt is that although I will provide the external power source to sensors for input but, will there be any problem for Arduino due to input from all six sensors at the same time which may exceed its input capacity?

@r0000 You can also assume 100mA per sensor. Even 10mA. But it will be wrong. Usually a designer makes designs in the worst case, which in this case is 160mA. If you use the nominal value, it is 152mA. But this will be an underestimation, and may result in bad working. As I told you, if you want to dimension it, assume 850mA. At 5V, this means 4.25W. Your 3.5W will be undersized. As for the inputs, the UNO has six inputs so six sensors are feasible


text:
Which EEPROM has a long lifecycle?
I would like to build a box counter for machine, so I'm going to use EEPROM in Arduino to save count. But the lifecycle is limited to 100,000 writes. Please suggest an external EEPROM with a long lifecycle or any other solution.

Lifetime is not limited to 100,000. Lifetime is minimum 100,000. It's guaranteed to be at least 100,000.

See also this question: https://arduino.stackexchange.com/questions/48872/extending-eeprom-life

I would use an ESP8266: it's 1-4MB of SPIFFS storage wear-levels, so storing one counter takes ~1/1,000,000 writes, and you can do 100k+ writes, so that's a lot of counting: 100bln for $2. you can also use the RTC ram of the ESP if you have some power managment.

You can cycle through all the addresses in the EEPROM like a ring buffer.
You'll need to reserve a bit so you can binary search for the head of the buffer during startup.
You can also reduce how often you write in general especially when the count will increment in bursts, try and wait out those bursts instead of writing on every increment.

Wear leveling is the way to go. +1.

Great answer, but if you know of external EEPROM modules, please add that info as well.

The EEPROMs from Microchip have a guaranteed erase count of 1 million. The ones from ST offer 4 million. So it's not hard to find EEPROMs with a higher endurance.
But for a device which writes a lot, a better solution would be a NVRAM, FRAM or EERAM. Those usually come with virtually no limitations to the write cycles but usually are more expensive than EEPROMs but that might very well be worth it compared to the hassle you can get in otherwise.
Adafruit offers SPI and I²C variants for FRAM boards.

If you use something like an SD card, they have internal logic that will move the data around when a call is used up.  This should give you virtually unlimited storage for something as simple as a count.


text:
Cons of using timer0 with external input?
I'm working on a project of differential drive control in which I use speed encoders for the odometry.
I count the number of rising edges using counter0 and counter5 (on Arduino Mega 2560), which works fine by itself, but when I combine that code with other parts of my code, many things stop working and I can't figure out why. My current guess is that it is related to timer0.
So my question is: what can go wrong when we modify the registers for timer0? I know that delay(), millis(), micros(), and PWM on pins 4 and 13 won't be available anymore, but are there other things that I should be aware of? Are there some libraries that stop working?
If that is the case, I'm thinking of using hardware interrupts for the odometry.
Thanks in advance.
Edit: Here's more information about the project:
In the project, I use a behavior based controller to build a differential drive robot that goes to some goal coordinates while avoiding obstacles.
The speed measurement is done using speed encoders and optocouplers. those values are also used for updating the position and heading of the robot. It runs every 210 milliseconds.
The obstacle distance is measured using 7 ultrasonic sensors that are controlled using pin change interrupts.
The only external libraries that I use are TimerOne.h and TimerThree.h (which do not use timer0) and I made sure not to use timer0 (at least directly) in the parts that I wrote myself.
My code is interrupt-driven, so I wonder if that could also be a cause for the wrong behavior.
Here's the main code
#include "definitions.h"    // contains constants that should be accessible by many files
#include "diff_cntrl.h"     // controls the wheels (left and right speed) uses timer0 and timer5 for speed measurement
#include <TimerThree.h>     // used for generating timer interrupts for the differential control
#include "A7.h"             // used for commmunication using an A7 module through Serial1
#include "M_Ultrasonics.h"  // measures distance from 7 ultrasonic sensors using pin change interrupts on A8 - A14 (PORTK) and TimerOne.h
#include "FuzzyBBC.h"       // a fuzzy logic behavior-based controller (does only floating point computations

volatile double dists[NUM_US]; // array where the obstacle distances will be stored
volatile uint8_t   done = 0;   // flag set by M_Ultrasonics.h when all 7 seven distances are measured
FuzzyBBC fbbc;                 // reference to the behavior based controller

volatile double xG = 0, yG = 0; // coordinates of the goal

volatile double v = 0, w = 0;   // desired velocity and angular velocity. set by fbbc and used by the differential controller

// variables holding the current state of the
volatile double x = 0, y = 0, phi = 0; // coordinates and heading

volatile double dx, dy, dphi;   // changes in coordinates and heading (used for debugging

// variables used for the speed control of the motors: reference speed, actual speed, counter value, output voltage for left and right motors
volatile double l_ref = 0, l_spd = 0, r_ref = 0, r_spd = 0;
volatile uint8_t l_ctr = 0, r_ctr = 0;
volatile uint8_t l_volt = 0, r_volt = 0;

volatile boolean newvolt = true;  // flag set when a new voltage value is computed

volatile boolean updated = false; // flag set to allow transmission of data to the remote machine
volatile uint8_t update_count = 0;

//------------debug variables-----------------
volatile double dvl, dvr;
//--------------------------------------------
void setup()
{
  delay(5000);
  A7begin();    // starts up the A7 module and connects to a predefined remote machine
  initMotors(); // initialize the pins for the motor control (I use an LM293D motor driver)
  setup_cntr(); // set the registers for timer0 and timer5
//  vw2lr();

  fbbc.begin(&xG, &yG, NUM_US, dists, &x, &y, &phi, &v, &w);  // starting the fuzzy logic controller, it has direct access to the provided variables
  HCRS04.begin(T_US, dists, &done);   // starting the ultrasonic sensors controller (it runs every 30 millisecond

  Timer3.initialize(T_MOTOR*1000L);   // timer interrupts for the speed control (T_MOTOR = 210 milliseconds)
  Timer3.attachInterrupt(cntrISR);
}

void loop() {
  if(done)    // wait for obstacle distances to be updated
  {
    arbiter();  // update v and w
    if(updated && !waiting){    // send data to the remote machine
      String info = "v: " + String(v) + "\tw: " + String(w) +
                    "\t\tvl: " + String(l_spd) + "\tlref: " + String(l_ref) + "\tlvolt: " + String(l_volt) +
                    "\t\tvr: " + String(r_spd) + "\trref: " + String(r_ref) + "\trvolt: " + String(r_volt) +
                    "\t\tx: " + String(x) + "\ty: " + String(y) + "\txG: " + String(xG) + "\tyG: " + String(yG);
      LogInfo(info);
      updated = false;

    }
    done = false;
  }
  if (A7_STREAM.available() > 0) {    // receive input from the A7 module (Serial1)
    String msg = "";
    if(waiting){
      get_A7_resp();  // read the message (function in A7.h)
      msg = resp;     // save the message (variable in A7.h)
      resp = "";
    }
    else{
      msg = readStr();
    }
    if (msg.length() > 2)   // process the received message
    {
      if (msg.substring(0, 2).equals("xy")) {
        readXYG(msg);
        resp = "";
      }
      else if(msg.equals("stop")){
        xG = x;
        yG = y;

        resp = "";
      }
      else if(msg.equals("+TCPCLOSE:0")){
        disconnected();
      }
    }
  }

}
inline void arbiter(){
  fbbc.arbiter();
  newvolt = true;
  vw2lr();  // convert v and w to left speed and right speed
}
inline void cntrISR() // ISR that runs every 210 milliseconds (for speed control)
{
  // compute the speed of the car
  read_rm();
  read_lm();
  ctr2lr();   // convert counter values to centimeter/second
  if (newvolt){
    spd2volt_init();
    newvolt = false;
  }
  else
    spd2volt();
  // update motor values
  analogWrite(L_PWM_PIN, l_volt);
  analogWrite(R_PWM_PIN, r_volt);

  updatePos();
}

inline void updatePos()   // compute new position (using differential drive kinematic equations)
{
  lr2xyphi();
}

inline void readXYG(String cmd) // get the new goal coordinates
{
  int sp1 = cmd.indexOf(' ');
  int sp2 = cmd.indexOf(' ', sp1 + 1);
  xG = (double)cmd.substring(sp1 + 1, sp2).toInt();
  yG = (double)cmd.substring(sp2 + 1, cmd.indexOf('~',sp2+1)).toInt();
}

the motor initialization code:
inline void setup_cntr()
{
  pinMode(CTR0_PIN, INPUT_PULLUP);
  pinMode(CTR5_PIN, INPUT_PULLUP);
  TCNT5H = 0;
  TCNT5L = 0;
  TCCR5B = 0X07;
  TCNT0 = 0;
  TCCR0B = 0X07;
}

inline void initMotors(){
  pinMode(L_FWD_PIN, OUTPUT);
  pinMode(L_BACK_PIN, OUTPUT);
  pinMode(L_PWM_PIN, OUTPUT);
  pinMode(L_EN_PIN, OUTPUT);
  digitalWrite(L_EN_PIN, HIGH);
  digitalWrite(L_FWD_PIN, HIGH);
  digitalWrite(L_BACK_PIN, LOW);

  pinMode(R_FWD_PIN, OUTPUT);
  pinMode(R_BACK_PIN, OUTPUT);
  pinMode(R_PWM_PIN, OUTPUT);
  pinMode(R_EN_PIN, OUTPUT);
  digitalWrite(R_EN_PIN, HIGH);
  digitalWrite(R_FWD_PIN, HIGH);
  digitalWrite(R_BACK_PIN, LOW);
}

ultrasonic sensors code:
#include "M_Ultrasonics.h"

M_Ultrasonics HCRS04;
void measISR();
void trigISR();
M_Ultrasonics::M_Ultrasonics()
{
  pinIndex = -1;
  for(int i=0; i < NUM_US; i++)
  {
    pinMode(trigs[i],OUTPUT); // trigs: array containing the trigger pins of the ultrasonic sensors
    digitalWrite(trigs[i],LOW);
  }
}
void M_Ultrasonics::begin(uint32_t period, volatile double *dists_, volatile uint8_t *done_)
{
  Timer1.initialize(period*1000);
  Timer1.attachInterrupt(trigISR);
  dists = dists_;
  done = done_;
  pinIndex = -1;
  for(int i=0; i < NUM_US; i++)
  {
    pinMode(trigs[i],OUTPUT);
    digitalWrite(trigs[i],LOW);
    dists[i] = MAX_DIST;
  }
  enable_pci();
}
void M_Ultrasonics::end()
{
  Timer1.stop();
  Timer1.detachInterrupt();
  PCICR = 0;
}
inline void M_Ultrasonics::trig() // send the trigger signal to the sensor
{
  pinIndex ++;
  if(pinIndex == NUM_US)
  {
    pinIndex = 0;
    *done = 1;
  }
  set_pci();
  digitalWrite(trigs[pinIndex], HIGH);
  delayMicroseconds(ping);
  digitalWrite(trigs[pinIndex], LOW);
}
inline void M_Ultrasonics::enable_pci() // enable pin change interrupts on PORTK
{
  PCICR = 0x04;
}
inline void M_Ultrasonics::set_pci()  // activate interrupts for the current pin
{
  PCMSK2 = (1<<pinIndex);
}
inline unsigned long M_Ultrasonics::read_time() // convert the timer value to microseconds
{
  return (/*(TCNT1H<<8) | */TCNT1L) * F_CLOCK;
}
inline void M_Ultrasonics::meas()
{
  if(PINK & (1<<pinIndex)) {  // check if the pin is high
    s_echo = /*micros();/*/read_time();
    dists[pinIndex] = MAX_DIST*DOBST_COEFF;
  }
  else
  {
    f_echo =/* micros();/*/read_time();
//    d = (f_echo-s_echo)*soundSpeed/2E4;
    if(d < MAX_DIST) {
      dists[pinIndex] = d/**DOBST_COEFF*/;
    }
//    dists[pinIndex] = d; // (double)(f_echo - s_echo);
  }
}
ISR (PCINT2_vect) // handle pin change interrupt for A8 to A14 here
{
  measISR();
}
void measISR() // ISR called on rising or falling edge on the current pin
{
  HCRS04.meas();
}
void trigISR()  // function called every 30 millisecond to trigger the next ultrasonic sensor
{
  HCRS04.trig();
}

Tell or better yet, show us what 'other parts' of your code do. There are endless possibilities of breaking interrupts.

Many libraries expect delay(), millis() or micros() to work.

@EdgarBonet In that case I think I better leave it unused. thanks.


text:
How to post HTTP POST requests on my website?
I am working on a NodeMCU board to post sensor data on my website service. Basically my project is about POST and GET requests both in single code.
I am succeeding in sending GET requests from my website. However, I just can't post data to my website.
To post I have 2 different links (asp services): one will post data and another will be used to get data same as transmitted by first link.
Here is my code, and also how to post 2 variables in http post request?
#include (ESP8266WiFi.h)
#include (ESP8266HTTPClient.h)

const char* ssid = "oppo";
const char* password = "11111111";
int giSwitchNum = 1, buttonPin = 2;

void setup () {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  pinMode(D1, OUTPUT);
  pinMode(D2, INPUT);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print("Connecting..");
  }
  giSwitchNum = 1;
  Serial.print("Connect");
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
    HTTPClient Post;
    Post.begin("http://lemontechnologies.net/Services/Service.svc/SetData");
    Post.addHeader("operator", "text/plain");
    Post.POST("Key=hi&val=jagrut1");
    String payload = Post.getString();
    Post.end();
  }
  delay(500);
}

remove the 'operator' header and add a "Content-Type" header with value "application/x-www-form-urlencoded"

void wifi_connect(){
  WiFi.mode(WIFI_OFF);        //Prevents reconnection issue (taking too long to connect)
  delay(1000);
  WiFi.mode(WIFI_STA);        //This line hides the viewing of ESP as wifi hotspot
  //WIFI_STA It's very important !!!!

  WiFi.begin(ssid, password);     //Connect to your WiFi router
  while(WiFi.status() != WL_CONNECTED){
    delay(1000);
    Serial.print(".");
  }

  Serial.println("Wifi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  return;
}

I think you may try "WiFi.mode(WIFI.STA)"

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


text:
Arduino Mega Sensor shield
I'm using an Arduino Mega Sensor Shield on a Mega 2560 board and so far I have 12 servos attached to it from PWM pins 2 to 13.
I want to add 5 more servos but there are no more PWM pins.
So which pins do I do I use for these.

Since the HW peripherals are finished, I think you have to implement a software timer to control them. This should (never tested, though) be doable with the Arduino Servo library (formerly MegaServo). From the notes, "On the Mega, up to 12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12. ". So it appears that you can use any digital pin using the default library. Did you try?

There seems to be a library called
According to this  Answer you have some possibilities:

Using ShiftPWM library
Using a timer with a generic GPIO

I'm using the MegaServo.h library. I can control the existing 12 servos but which pins do I use to add further servos. It says that the Mega Sensor Shield can support up to 48 servos. I've tried from pin 22 but it does not work.

I think the library name is missing. @MalcolmPalmer the MegaServo library was renamed to Servo; so my suggestion is to avoid using an older version


text:
Building an EEZYBOTARM MK1
My bot arm building is complete, I'm using it with Arduino and 2 joysticks with 4 servos ( mg90s), running with the 9v battery, but still, the servos could not lift the bot arm once it is going down and the servo keeps fluctuating. It is a 3d printed bot so it is not so heavy. please help?

A little wimpy PP3 battery?

Even if your device is not so heavy, a 9V battery has a maximum practical current draw in the 10s of milliamps. It's not a good choice for operating motors.
A better choice would be AA, C, D, or Lithium-Ion/Lithium-Polymer batteries, wired in series to produce the desired voltage.

how much volts AA batteries?

Nominally 1.5V per cell (each AA is one cell)

will 5, AA 1.5v each work fine?

I can't answer that for you. It depends on the specs of your servos, how long you want the device to operate on one set of batteries, etc. If you needed to get to 9V, then 5 AAs will not do it. The 1.5V per cell is the max, and as they discharge, the voltage will drop lower and lower.

The proper number of batteries depends on how your servos are powered.  You must not use the Arduino's regulator for this.  Run bare they want 4 or 5 AA's depending on their maximum voltage rating and the cell chemistry.  However 5 AA's is not reliably enough to feed an Arduino's regulator.


text:
Trouble using proximity sensor as input and LED output
I was wondering if anyone had any pointers or advice to make this project work. Essentially I would like to have the LED fade (meaning like fade on and off at a calm rate) at one rate when there is nothing close to the proximity sensor, and then to speed up the fade amount when there is something close to the sensor.
#include <NewPing.h>   //include the library

int led = 9;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount;    // how many points to fade the LED by

int triggerPin = 12;   //pin conneccted to the Trig pin on the sensor
int echoPin = 11;       //pin connected to the Echo pin on the sensor
int maxDistance = 200;  //set the max distance for the sensor to read (helps with errors)
int distanceVal;        //variable to hold the distance val

int sampleRate = 200;   //how fast to sample the value
long lastReading;       //used for the timer

NewPing proximity1(triggerPin, echoPin, maxDistance);   //sets up the sensor object

void setup()
{
  Serial.begin(9600);  //start the serial port
  pinMode(led, OUTPUT);
}

void loop() {

    if(millis()-lastReading>=sampleRate) //this very simple statement is the timer,
  {
  distanceVal = proximity1.ping_cm();  //get the distance value in centimeters

  lastReading = millis();

  Serial.print("Distance Reading CM : ");  //print the value to the Serial monitor
  Serial.println(distanceVal);

if(distanceVal<20){

fadeAmount = 5;
}
else{
  fadeAmount = 2;
}

  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
  }
}

https://github.com/sanaalla/Fade-LED-with-Proximity-sensor
Above is my code, which is not working. I am fairly new to Arduino and so would greatly appreciate some more seasoned wisdom!

I'm on my mobile, so I can't test anything. For me the link is not working in the app (you can copy the code in the question, formatting it as code, this is recommended as in the future the link may be broken). And "it's not working" is not the most accurate way of describing your problem. Does the code not compile? Does your actual physical setup not work? Post a schematic!

You want 2 independant loops, one for the measurement and one for the dimming effect. The latter one must also be able to run when not measuring.
if(millis()-lastReading>=sampleRate) //this very simple statement is the timer,
{
  distanceVal = proximity1.ping_cm();  //get the distance value in centimeters

  lastReading = millis();

  Serial.print("Distance Reading CM : ");  //print the value to the Serial monitor
  Serial.println(distanceVal);
}

if(millis() - lastFade >= fadeRate) //other timer
{
  lastFade = millis();
  if(distanceVal<20){
    fadeAmount = 5;
  }else{
    fadeAmount = 2;
  }

  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
}

*update! I fixed the code and got it to do what I want.
#include <NewPing.h>   //include the library

int led = 9;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount1 = 10;    // how many points to fade the LED by
int fadeAmount2 = 2;    // how many points to fade the LED by

int triggerPin = 12;   //pin conneccted to the Trig pin on the sensor
int echoPin = 11;       //pin connected to the Echo pin on the sensor
int maxDistance = 200;  //set the max distance for the sensor to read (helps with errors)
int distanceVal; //variable to hold the distance val
int lastFade;
int fadeRate = 200;

int sampleRate = 200;   //how fast to sample the value
long lastReading;       //used for the timer

NewPing proximity1(triggerPin, echoPin, maxDistance);   //sets up the sensor object

void setup()
{
  Serial.begin(9600);  //start the serial port
  pinMode(led, OUTPUT);
}

void loop() {

  if(millis()-lastReading>=sampleRate) //this very simple statement is the timer,
{
  distanceVal = proximity1.ping_cm();  //get the distance value in centimeters

  lastReading = millis();

  Serial.print("Distance Reading CM : ");  //print the value to the Serial monitor
  Serial.println(distanceVal);
}

if(distanceVal<20){

    // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount1;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount1 = -fadeAmount1;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

else{

    // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount2;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount2 = -fadeAmount2;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

}


text:
LED strip problem... getting red when expecting white with lots of pixels. Fine with 1 pixel
I have an Arduino Uno.  I bought this LED strip:  https://www.amazon.com/gp/product/B019DYZNO6/ref=oh_aui_detailpage_o08_s02?ie=UTF8&psc=1
Starting initially using FastLED library. When I tried to set the entire strip to white (255,255,255), it was coming out red. Any color close to white was coming out red.
I thought maybe there was an issue with the library, so I tried the neopixel library. Same thing until... If I just set one pixel to 255,255,255 and don't set any other, it comes out white!  If I set about 10 pixels, they still look white. As I set more pixels, they start to loose their whiteness and become red.
I want to say that maybe this was a power issue... but I tested this both when it was running off my PC and running standalone with a power supply (supplying 5V).
Any suggestions??  I also thought that maybe it's a bum strip, but I also bought https://www.amazon.com/gp/product/B01AG923GI/ref=ask_ql_qh_dp_hza and did the same experiment, and am getting the same results...

How much current does your external power can supply? These LEDs can be very power hungry. For my strip each LED uses 30mA when completely white. This would result in 4.2A for a 140 LED strip like yours

do you have the recommended capacitor and resistor between the strip and MCU?

For future searchers, this same problem can also give a Green colour when trying to set the neopixel grid to white.

According to https://learn.adafruit.com/adafruit-neopixel-uberguide/powering-neopixels a Neopixel can consume 60 mA at full brightness white.

Each individual NeoPixel draws up to 60 milliamps at maximum brightness white (red + green + blue). In actual use though, it’s rare for all pixels to be turned on that way. When mixing colors and displaying animations, the current draw will be much less. It’s impossible to estimate a single number for all circumstances, but we’ve been using 1/3 this (20 mA per pixel) as a gross rule of thumb with no ill effects. But if you know for a fact that you need every pixel on at maximum brightness, use the full 60 mA figure.

So your 144 Neopixels would require 8.4 amps. You would need a pretty solid power supply to supply that much.
One way of confirming that would be to measure the voltage in to the Neopixel strip (at the strip end) when it is displaying all white. I'd be surprised if it measures 5V.
The Amazon page you linked says:

Voltage: DC 5V
Power: 0.3W ± 0.01% per LED

That agrees with the figure of 60 mA (0.060A * 5V = 0.3W)

To put it another way, your power supply would need to supply 43.2W (144 * 0.3W). None of the bench power supplies I have here can put out 43W (or 8A), nor any of the wall-warts. You may have a really massive one, but you haven't specified what sort of power supply you are using.

I run them with a power supply (one that is working as expected, but still have it connected to the PC/USB?

Yes, there is a technique for doing that (similar to powering motors etc.).

You have one low-current supply to the Arduino (this could be your USB port even).
You have a high-current supply to the pixels/motor/whatever. This would require thicker cables.
You connect the grounds of both supplies so that they have a common ground reference.
The data line (the pixel information) is sent from the Arduino to the Neopixels

The one power supply can do both roles, just connect the wires together at the power supply end (this automatically connects the grounds, of course).
This way, the heavy-duty current does not go through the Arduino board.

If you are using the USB port for logic power you still connect the grounds like this:

I'm using the power supply recommended by the LED folks on the Amazon page which is a 5V, 10A.  https://www.amazon.com/gp/product/B01M0KLECZ/ref=oh_aui_detailpage_o08_s00?ie=UTF8&psc=1   Now... I haven't taken out my multimeter and doublechecked that that's what I'm getting out of it... but problems with current make sense.

Sounds reasonable, but at that current you might be losing voltage over the wires. Measuring the input to the strips, at the LED end would confirm that.

You might need to apply power to both ends of the strip (if that is practical) because there might be a voltage drop over the length of the strip itself. Especially if the white colour deteriorates progressively (ie. white at the start, not so white at the end).

I just measured the output voltage of the supply... getting less than 3V. :(
My multimeter doesn't seem to be working for Amps. So my next question... can I run this strip of light off the Uno when it's connected to my PC? I'm guessing not since there's only a 5V and 3.3V output. I did try with the 5V and am also getting the same issue... white for a few pix, no white for lots of pix.

The strip needs 5V to operate correctly. With 3V it won't work as intended. Also you cannot drive your strip from your PCs USB, since they only provide up to 500mA, so far not enough current for the strip when turned on. In doing so you can also damage your Arduino or USB port of the PC. When the LEDs are of it is possible. Try measuring the voltage output of your power supply without anything connected, to ensure that it really outputs 5V. If not the seller send you a wrong product.

like I said, I measured and am not getting the expected 5V. So I guess that's my problem. Thanks for the tips on not running it off PC/USB. Next question is... can I run them with a power supply (one that is working as expected, but still have it connected to the PC/USB?  I want to take input from the PC...

See amended answer for how to do this.

My multimeter doesn't seem to be working for Amps - measuring amps requires a different technique. Don't just bang the leads onto the two wires, you don't measure amps that way. Try Googling "how to measure current with a multimeter".


text:
Powering servos with external source
I understand why servos and motors require an external power source when run from the Uno, but I've seen a lot of tutorials (for example, this one), where the servo is connected directly to the Arduino's 5V port. I did this, and I think it fried my servo. This is also the method shown on the official Arduino tutorials for Knob and Sweep. In fact, the knob tutorial was the first and last tutorial I tried with my servo -- after trying it, the servo didn't work.
It went like this:
1) Try sweep code without using external supply. Works fine.
2) Try knob code without using external supply. Servo hums without moving and heats up (a lot).
Why do tutorials say to do this if it's not advisable?

"I think it fried my servo". servo? not Arduino?

The servo no longer works, but I’ve used the same Arduino to power other things, including other servos on a separate power supply (now that I know).

Did it die immediately or work for a bit and then die?  Is it possible that you got a bad servo?  I've occasionally gotten one dead servo in the few batches I've ordered.

It went like this:

Try sweep code without using external supply. Works fine.
Try knob code without using external supply. Servo hums without moving and heats up (a lot).

Hmm...I'll add that to the original question.

Mhh, are you sure, that you connected everything correctly? I thought long about this and I see only 2 reasons, that it would heat up like this: 1. You have corrupt hardware or 2. You connected something wrong (like for example wrong polarity). Are you sure that everything is connected in the right way?

Most likely you fried the voltage regulator or the diode on your Arduino board (depending in which power source you used), because the servo has drawn too much current.
Many Arduino Kits or Starter Packs come with really small servos. These do not need much power (especially when no mechanical load is attached to them), so you can power them directly from the 5V pin. Greater/stronger Servos draw much more current and cannot be safely run in the 5V pin.
Many tutorials show this, because it is an easy start for a beginner. And with the right servo it works. More sophisticated cases are not covered there.
EDIT:
Since your Arduino works fine, the voltage regulator and/or the diode should be fine. I tested the Knob example on my Arduino Nano, while powering the servo on the Arduinos 5V pin (and the Arduino is powered over USB). When the Servo is moving, you can see that there is a significant power draw (The power LED gets a bit dimmer), but not so much, that it would be a problem for the Arduino or USB port. Also the example code works as it should, without the servo heating up. I also used a SG90 Micro Servo (9g, by Tower Pro; same as in the tutorial you linked). I also tried the same with an external power source (5V from a powerful USB charger). It still works as intended, but with more power, since the servo now can draw much more current to produce a higher thrust.
So the only thing, I can think of for your problem is, that you either have corrupt hardware, or you have connected it wrong (for example wrong polarity). My Servo has the same color coding for the wires as in the tutorial you linked. Brown is ground, Red is 5V Vcc and Yellow is for the pulse signal.

it’s a small SG90 hobby servo, came with the starter kit I bought. How can I test the voltage regulator and diode on the Arduino?

@Jim421616 did you use an external power supply when powering the UNO and the servo? If the answer is no, then you haven't fried the regulator. If you did, attach it again and then measure if on the +5V pin you actually have 5V. if you haven't (the USB needs to be disconnected, only the power supply needs to be connected), then the onboard regulator is fried. If you have, try connecting the "fried" servo to the external power supply you have (it should be a 5V power supply). If it moves or becomes stiffer, it works, otherwse it doesn't


text:
5V Pressure sensor module with 3.3V ADC
I'm using ESP32 to read analogue pressure readings from this pressure transducer. My Problem is this sensor outputs 0.5V – 4.5V linear voltage output based on the pressure but ESP32 can only handle 0 - 3.3V in the ADC inputs. Can anyone advice me to how to accomplish this in 0 - 3.3V range?

voltage divider is what you need ... approx values for R1 and R2 are R2 = 2 * R1 ... that will produce 3v on 4.5v input

@JaromandaX That could work if the output is low impedance. It may not be though, in which case it would need to be buffered first, since the voltage divider would mess things up royally.

LOL... Gotta love Chinese specifications... Insulation Resistance: >100mΩ 500VDC... milli ohms?!?!

@Majenko you can't challenge that statement.. In fact it should be greater than 100 milliohms... Hopefully ;)

@frarugi87 You right that it's not "wrong" ;) It's just like saying that "The temperature today is greater than 3 Kelvin"...

@JaromandaX, Thanks for the comment and thats what exactly i wanted. I can accept it as the correct answer if you could just put it as an answer.


text:
How to continuously monitor range finder and immediately interrupt code to run a different code in pedestrian traffic lights setup?
I am currently doing part 2: Pedestrian Mode of my project below:

Regular Mode: This is the regular mode of operation. In this mode the
three lights (Red, Yellow and Green LEDs) should operate in the following
order. The Red LED lights for 2 seconds, followed by the Yellow LED for 1
second, the Green LED for 2 seconds and then the Yellow LED again for 1
second. The cycle should repeat until the mode changes.
Pedestrian Mode: This mode uses the SRF05 Ultrasonic Range Finder to
detect the proximity of any object. The lights should operate as defined in
the regular mode UNTIL an object is detected less than 10 cm from the
TLC. The buzzer should then beep and the Yellow LED must blink ON/OFF
(flashing intervals of 0.1 sec) repeatedly 10 times. The buzzer should then
stop beeping and the operation of the lights (not the system) must behave
as it would in the regular mode. The operation stays the same until the
mode changes

My code works, however it waits for the entire regular cycle to finish before sensing a pulse with the ultrasonic range sensor to determine if an object is near or not. Therefore, when I put my hand near the sensor, it has to finish running the regular mode before it detects my hand and switches to pedestrian mode. What I would like is for the range finder to continuously fire the pulse and immediately switch to pedestrian mode when it detects an object less than 10 cm away.
Code below:
int red_light = 12;
int yellow_light = 10;
int green_light = 8;
int ECHOPIN = 3;
int TRIGPIN = 5;
int buzzer = 7;
float distance;

void setup() {
  Serial.begin(9600);
  pinMode(red_light, OUTPUT);
  pinMode(yellow_light, OUTPUT);
  pinMode(green_light, OUTPUT);
  pinMode(ECHOPIN, INPUT);
  pinMode(TRIGPIN, OUTPUT);
  pinMode(buzzer, OUTPUT);
}

void loop() {
  range_finder();
  if (distance < 10) {
    pedestrian_mode();
  } else {
    regular_mode();
  }
}

void regular_mode() {
  digitalWrite(red_light, HIGH);
  delay(2000);
  digitalWrite(red_light, LOW);
  digitalWrite(yellow_light, HIGH);
  delay(1000);
  digitalWrite(yellow_light, LOW);
  digitalWrite(green_light, HIGH);
  delay(2000);
  digitalWrite(green_light, LOW);
  digitalWrite(yellow_light, HIGH);
  delay(1000);
  digitalWrite(yellow_light, LOW);
}

void range_finder() {
  digitalWrite(TRIGPIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGPIN,HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGPIN,LOW);
  distance = pulseIn(ECHOPIN, HIGH);
  // return 0 if no high pulse in 1 sec
  distance = distance/58;
  Serial.print(distance);
  Serial.println("cm");
  delay(200);
}

void pedestrian_mode() {
  digitalWrite(buzzer, HIGH);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
  digitalWrite(yellow_light, HIGH);
  delay(100);
  digitalWrite(yellow_light, LOW);
  delay(100);
}

Also I have a feeling some parts of my code may be unnecessarily long and could be shortened. If so, I would appreciate any advice and how to do that. Thank you.

   digitalWrite(yellow_light, HIGH);
   delay(100);
   digitalWrite(yellow_light, LOW);
   delay(100);

   digitalWrite(yellow_light, HIGH);
   delay(100);
   digitalWrite(yellow_light, LOW);
   delay(100);

...

You really need to read up on "for" loops. Make a loop that does it 10 times, don't copy and paste 10 times.
As for your other issue, at the very least you could test the proximity sensor after each delay. Read up on millis. Just imagine how you might do it in real life. Would you really delay for two seconds? Or would you check the clock to see if two seconds had elapsed and also check if a pedestrian had arrived?
And better still, replace delay with a loop which tests elapsed time, and also tests the distance sensor.

I'm not writing more specific code because clearly the exercise is for you to learn how to do this. I already know how to do it, and if I just posted the exact answer you wouldn't have learned how to do it.

As a short addition: The BlinkWithoutDelay example in the Arduino IDE is a good starting point for learning this principle

You should use an interrupt pin.
Interrupt pins can operate outside the normal void loop().
So you can have a normal loop going on. If an interrupt pin is triggered - it performs a function immediately.
https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/
Or you could consider using a switch case.

However that function should be brief. What the OP seems to want is to switch modes (regular mode to pedestrian mode). It might be better to check for the conditions for a mode change to occur, while a particular mode is in operation.


text:
Infrared frequency recorded with saleae
i'm trying to decode infrared signal recorded with the saleae. It makes me wonder why saleae shows so low values for the frequencies from 0.1kHz to 0.8kHz. I found that standard for the IR is around 38kHZ. Is there something wrong with my record? Or did i misread the sample?

If you are using an IR receiver with 3 pins that is designed for a carrier frequency of 38kHz, then your will receive the logic signal only. If you use a photo transistor with 2 pins, then you should be able to see the carrier frequency along with a lot of noise.

What you are looking now is NOT the IR frequency, but the de-modulated signal.
Here is what I'm talking about:

(image taken from http://www.electronicwings.com/sensors-modules/ir-communication)
As you can see, the various pulses are made of smaller pulses.
In your case you are seeing what is here called "Serial data", which is different from the carrier frequency. What the saleae board is telling you is that the width of the high part is 1.625ms, while the width of the low part is 0.631 ms; as you can see, the waveform is NOT periodic, so the "frequency" is meaningless (it's the reverse of the time marked on the view, which is the sum of one large high value and one low value).
Your plot resembles the NEC protocol (see for instance here). A logic '0' is a 562.5µs pulse followed by a 562.5µs space, while the logic '1' is a 562.5µs pulse burst followed by a 1.6875ms space (this is similar to by 0.631 ms and 1.625 ms measurement)


text:
Readings changing in hall effect sensor
I am using a A1324 hall effect sensor for a distance measuring.
The voltage output keeps changing even if the distance between the magnet and sensor does not change. The output changes +-0.200V and I am trying to measure the distances at steps of 0.01V.

What values do you see? What is the range of the changes?

The output changes +-0.200V and I am trying to measure the distances at steps of 0.01V.

What variation in Gauss do you expect? What mathematic/design do you have?

I am not interested in measuring the magnetic flux in my project. The main aim is to measure the distance from a magnet. I am using a voltage divider method to  get the voltage output from the hall effect sensor.

From https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/

analogRead()
Reads the value from the specified analog pin. The Arduino board
  contains a 6 channel (8 channels on the Mini and Nano, 16 on the
  Mega), 10-bit analog to digital converter. This means that it will map
  input voltages between 0 and 5 volts into integer values between 0 and
  1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.

It is likely what you are seeing is noise and is to be expected. The source of the noise is likely multiple and could be environmental physical metallic or magnetic objects some distance away that are moving, electrical wiring (mains) nearby, and noise introduced by the power supply to the Arduino.
If you want to get a stable precise reading that close to the minimum step size, you will want to take several readings and average them. The more you read and average, the more you can eliminate the random effect of the noise, but the tradeoff is that it is slower because you are taking tens or hundreds of readings just for one result.

I was reading online that I can use filters to reduce the noise. But I have never worked with filters before could you suggest a way to start with that ?


text:
adafruit LSM9DS0 Library - ok with Uno but compile error with LinkitOne?
I'm calling an adafruit Flora LSM9DS0 magnetometer using the Adafruit library with the following sketch:
        #include <Wire.h>
        #include <SPI.h>
        #include <Adafruit_LSM9DS0.h>
        #include <Adafruit_Sensor.h>  // not used in this demo but required!

        unsigned long timeNow = 0;
        unsigned long mSecInHour = 3600000;
        unsigned long TimeNow =0;
        int millisecs =0;
        int seconds = 0;
        byte minutes = 0;
        byte hours = 0;

        int mag_raw_x;
        int mag_raw_y;
        int mag_raw_z;

        // i2c
        Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();

        // You can also use software SPI
        //Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(13, 12, 11, 10, 9);
        // Or hardware SPI! In this case, only CS pins are passed in
        //Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(10, 9);

        void setupSensor()
        {
          // 2.) Set the magnetometer sensitivity
          lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);
        }

        void setup()
        {
        #ifndef ESP8266
          while (!Serial);     // will pause Zero, Leonardo, etc
        #endif
          Serial.begin(9600);

          // Try to initialise and warn if we couldn't detect the chip
          if (!lsm.begin())
          {

            while (1);
          }
          Serial.println(F("Found LSM9DS0 9DOF, measurements in Gauss"));
         }
         void loop()
        {
          lsm.read();
          TimeNow = millis();
          mag_raw_x = lsm.magData.x;
          mag_raw_y = lsm.magData.y;
          mag_raw_z = lsm.magData.z;

Which compiles and runs fine on the Arduino Uno, but I don't understand why the same sketch causes this compile error in the LSM9DS0 library when I compile for the LinkitOne?
    C:\Users\elbg\Arduino\libraries\arduino_373648\Adafruit_LSM9DS0.cpp: In member function 'bool Adafruit_LSM9DS0::begin()':

    C:\Users\elbg\Arduino\libraries\arduino_373648\Adafruit_LSM9DS0.cpp:77:16: error: 'SPCR' was not declared in this scope

         SPCRback = SPCR;

                    ^

    C:\Users\elbg\Arduino\libraries\arduino_373648\Adafruit_LSM9DS0.cpp: In member function 'void Adafruit_LSM9DS0::write8(boolean, byte, byte)':

    C:\Users\elbg\Arduino\libraries\arduino_373648\Adafruit_LSM9DS0.cpp:365:18: error: 'SPCR' was not declared in this scope

           SPCRback = SPCR;

                      ^

    C:\Users\elbg\Arduino\libraries\arduino_373648\Adafruit_LSM9DS0.cpp:374:7: error: 'SPCR' was not declared in this scope

           SPCR = SPCRback;

           ^

    C:\Users\elbg\Arduino\libraries\arduino_373648\Adafruit_LSM9DS0.cpp: In member function 'byte Adafruit_LSM9DS0::readBuffer(boolean, byte, byte, uint8_t*)':

    C:\Users\elbg\Arduino\libraries\arduino_373648\Adafruit_LSM9DS0.cpp:415:18: error: 'SPCR' was not declared in this scope

           SPCRback = SPCR;

                      ^

    C:\Users\elbg\Arduino\libraries\arduino_373648\Adafruit_LSM9DS0.cpp:426:7: error: 'SPCR' was not declared in this scope

           SPCR = SPCRback;

           ^

Any suggestions welcome !

The SPCR register is low level programming for SPI on a Arduino Uno.

The Adafruit library for the LSM9DS0 is written to run on an 8-bit Arduino. The LinkitOne isn't - it's an ARM board.
Either get a different library that is written to work on ARM, write your own library to work on ARM, or don't use that combination of components.


text:
How to solve problem AT+INQ ERROR (1F), AT+INIT ERROR(17) on Bluetooth Module HC-05?
i have problem with accessing at-command in module Bluetooh HC-05.
i just follow all tutorial to activate at-command like this,
http://www.martyncurrey.com/arduino-with-hc-05-bluetooth-module-in-slave-mode/
or in this video
https://www.youtube.com/watch?v=Vr4cdpsoVEo&t=31s
and just read some explanation and implemented to my problem
HC-05 Bluetooth AT+INQ command not working
but i just still get same error.
i cant use AT+INQ command, always get ERROR(1F).
AT+INIT get ERROR(17).
i have module HC-05 with version 3.0-20170601
This is my code i use it.
#include <SoftwareSerial.h>
SoftwareSerial BTserial(8, 9); // RX | TX`

const long baudRate = 38400;
char c=' ';
boolean NL = true;

void setup()

{
   Serial.begin(9600);
   Serial.print("Sketch:   ");   Serial.println(__FILE__);
   Serial.print("Uploaded: ");   Serial.println(__DATE__);
   Serial.println(" ");

BTserial.begin(baudRate);
Serial.print("BTserial started at "); Serial.println(baudRate);
Serial.println(" ");
}

void loop()

{

// Read from the Bluetooth module and send to the Arduino Serial Monitor
if (BTserial.available())
   {
       c = BTserial.read();
       Serial.write(c);
   }

   // Read from the Serial Monitor and send to the Bluetooth module
if (Serial.available())
   {
       c = Serial.read();
       BTserial.write(c);

    // Echo the user input to the main window. The ">" character indicates
    the user entered text.
    if (NL) { Serial.print(">");  NL = false; }
    Serial.write(c);
    if (c==10) { NL = true; }
   }

}

check this out ... https://stackoverflow.com/questions/23221336/hc-05-bluetooth-rssi-not-working-with-arduino

Ty for comment sir. I just read and implemented your guide But my problem still not solve. I wondering my firmware. Because I have Bluetooth version is 3.0. and other tutorial have version is 2.0

Do other AT commands work? what arduino are you using?

Yap i just use all AT-COMMAND. Just AT+INQ get error. I use Arduino uno.

thank you for this wonderful post Presidenten ,but i am having issue, "AT+STATE" shows inquiring ..if i power up my bluetooth device (not hc05) it doesnt show any address...what am i missing..please help...

I have a HC-05 with 3.0-20170601 that I managed to bind to a slave last night. It turns out that the v3 has two AT-modes.
The first is when you hold the button while you connect power. The led will blink slowly and you can connect at 38400 baud. But this is like a configuration mode, where AT+INQ is not available.
In this mode I did these commands:
AT
AT+UART
AT+RMAAD
AT+ROLE=1

(Press and hold the button)
AT+RESET

(Release the button after device restarts and led is slowly blinking)
AT+CMODE=1
AT+INQM=0,5,5
AT+PSWD="9999"

AT should give OK as answer to know connection is working
AT+UART will show configured baudrate. Default is 9600.
AT+RMAAD clears all saved connections
AT+ROLE=1 sets it as master
AT+RESET restarts the device to change to master
AT+CMODE=1 accepts all kinds of devices
AT+INQM=0,5,5 inquires in standard mode, with 5 max connections or 5 secs
AT+PSWD="9999" sets the pin code 9999, change to the pin you need
After this it is time to update the arudino code. In your case you should update line 4 from
const long baudRate = 38400;

to
const long baudRate = 9600;

...or what ever value you might have set the baud rate to. Then reflash your arduino.
Now enter the very irritating second AT command mode.
Power up without holding the button. You will get the fast blink speed. When its powered up, press and hold the button. The led will continue blinking fast, but while the button is pressed you can now connect to the device on the configured baud rate. So open the serial monitor and type AT to verify.
Remember that the mode is only active while the button is pressed. So keep it pressed. I had a small clamp I put on there.
Then I entered these commands:
AT+STATE

AT+STATE will show current state, should be inquiring
Then power up the slave device and the adress should start popping up. It will be something like xyz:xy:xyzw,931F00,7FFF
The first part is the address you want (xyz:xy:xyzw)
Change : to , and get xyz,xy,xyzw
Check that you connecting to the correct device
AT+RNAME?xyz,xy,xyzw

Then bind
AT+PAIR=xyz,xy,xyzw,5
AT+BIND=xyz,xy,xyzw
AT+LINK=xyz,xy,xyzw

The AT+LINK command gave me FAIL as output. But it did not matter.
I restarted and did not press any button before or after. Just normal start.
After 5-10s serial data showed up in my serial monitor.
Modules are bound. And will automatically connect at power up. If not you might have the wrong pincode. Make sure to change 9999 above to 0000 or 1234 or what ever it may be. When I hade the wrong pin I still got OK from the AT+PAIR and AT+BIND commands... It didnt work for me until I entered the correct pin.
Sorry for long post, but I wanted to be thorough since info about HC-05 v3 is very scarce on the internet right now.
A reference to all commands can be found here:
http://www.electronicaestudio.com/docs/istd016A.pdf
(Link valid 2018-08-13)

I have two modules:
(A) HC-05 with firmware version 3.0-20170601
(B) HC-05 with firmware version 2.0-20100601 (ok)
I have the same problem: when the AT command "AT+INQ" is sent on (A) module, the response is always "ERROR:(1F)". This error code seems not be reported in any document or specification available on internet. This BT module have firmware version (AT+VERSION) 3.0-20170601. Also I have noticed that command AT+INIT on (A) module returns always ERROR:(17), this error normally can be ignored if the command has been sent already (Initiate SPP lib), but the first time should be return "OK" as on (B) module.
The (B) module with firmware version 2.0-20100601 works ok with the following commands (set PIN34 high at power-up, or press button on module and keep pressed during commands):
AT+RMAAD -> delete all paired devices list
AT+ROLE=1 -> Set master mode
AT+RESET -> reset module to enter into master mode
AT+CMODE=1 -> Permit connection with any device
AT+INQM=0,5,9 -> Set Search parameters(Query mode standard, 5 devices, 9secs)
AT+INIT  --> Init SPP profile mode (first time response: "OK")
AT+INQ  --> Start search devices (return device list after some seconds)
The differences between two modules are:
On AT+INIT the (A) module return always ERROR:(17), the (B) module return "OK" first time and ERROR:(17) if the command is sent twice.
On (A) module the command AT+INQ return always ERROR:(1F), the (B) module return the list of the BT devices.
Also the (A) and (B) modules are physically different. The (B) module have some components (resistors/capacitors) between the two big black chips, the (A) module no.
Also I noticed that on (A) module the AT+CLASS? return "1f00" value (default?). The correct value should be "0" as (B) module ? Anyway setting AT+CLASS=0 on (A) module the result is always the same.
In slave mode (AT+ROLE=0) both modules works fine.
With (A) module I'm unable to use it as "MASTER" and connect it to any other slave BT modules because did not perform devices search. (INQ fails).
I think that in 3.0 firmware is needed to set other(s) parameter(s) in order to start SPP profile correctly (INIT) and then avoid ERROR:(1F) in INQ command (search).
Someone already solved the problem ?

So the conclusion about my problem is the firmware on HC-05. Firmware with 3.0 make AT+INQ will be not work. Ty very much for your answer. This is problem make me Stack on a month. Your answer very useful to me.

So your HC-05 with firmware 2.0 have push button or not?

Yes, it have the push button. The HC-05 is soldered on ZS-040 board that have the push button connected to PIN34. If you press the button at power-up, the module will enter in AT-COMMAND mode (38400bps, CR+LF) and it is possible to setup and view configuration of the module as MASTER o SLAVE by using AT commands. Some similar modules (HC-06) doesn't have the button because they are SLAVE only.

Okay. Ty very much brother.

Sir, can I buy your HC 05 with Firmware 2.0?

Extending the Presidenten's answer, the easiest way to program HC-05 is to sonnect a wire to EN on the chip and set the UART console to 9600.
Then pull the EN high, send commands, wait for OK (after each one), and drive EN down.
You now have a chip in data state.

I have the same version module HC-05.
This mode (INQ) is enabled for default and it's impossible switch it off. Seems that manufacturer removed this command in that version.
Another point, that it works only on default 9600 bod/s regardless of settings AT+UART=... and only in standart AT mode (key pin pull high after power on device).
Once connected to other module only one way to return to "inquiring" that I found is full reset it by command ORGL, and reconfigure it class and role.
Don't touch IAC settings - that also causes improperty working.


text:
I'm trying to make a program which you choose an angle
I'm trying to make a program which you choose an angle, and it tells you it's respective Sin, Cos and Tan. But, I can't figure out why all of the angles I use have the same answer (Sin 0, Cos 1 and Tan 0. Can someone help me out?
#include <math.h>
double angulo;
double seno;
double cosseno;
double tangente;
double rad;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {

 Serial.println("Programa para calcular sen, cos e tg");
 delay(1000);
 Serial.println("Digite o angulo");
 angulo = Serial.parseInt();
 rad = angulo*0,0174533;
 seno = sin(rad);
 Serial.println("Seno");
 Serial.println(seno);
 cosseno = cos(rad);
 Serial.println("Cosseno");
 Serial.println(cosseno);
 tangente = tan(rad);
 Serial.println("Tangente");
 Serial.println(tangente);

}

You have written
rad = angulo*0,0174533;

But, C++ uses the american decimal notation:
rad = angulo*0.0174533;

Thus, you have been multiplying angulo by zero every time.

I guess this is a language thing, where some cultures use a comma as a decimal indicator, and a full-stop as a thousands separator... I.e., they are backwards.

Saying it is backwards implies there is a correct (forward) and wrong (backwards) way, but of course they are merely different ways of denoting the same concept.

My way is right and every one else's is wrong ;) "Right" is whatever the majority of people use....

Doesn't the C++ comma operator calculate and discard the first expression and then use the following expression for the assignment?

https://stackoverflow.com/questions/54142/how-does-the-comma-operator-work


text:
What is wrong with my code? Did you forget '()'?
#include <SimbleeBLE.h>

// constants won't change. They're used here to set pin numbers:

const int ButtonPlayPause = 15;
const int ButtonNext = 12;
const int ButtonPrevious = 11;
const int OBled = 29;
       int Playp = 1;

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup()
{

  pinMode(ButtonPlayPause, INPUT);
  pinMode(ButtonNext, INPUT);
  pinMode(ButtonPrevious, INPUT);

  pinMode(OBled, INPUT);

  SimbleeBLE.deviceName = "GBAND";

  Serial.begin(115200);

  SimbleeBLE.begin();

  SimbleeBLE.txPowerLevel = +4;
}

void loop()
{
  buttonState = digitalRead(ButtonPlayPause);
  if (buttonState == HIGH)
  {
    SimbleeBLE.begin();
    SimbleeBLE.deviceName = "GBAND";
    //More code here to establish connection with android
     SimbleeBLE.sendInt = (Playp);
    digitalWrite(OBled, HIGH);
    SimbleeBLE.end();
    digitalWrite(OBled, LOW);
  } else  {
            buttonState = digitalRead(ButtonNext);
            if (buttonState == HIGH)
            {
              SimbleeBLE.begin();

              //More code here to establish connection with android

              digitalWrite(OBled, HIGH);
              SimbleeBLE.end();
              digitalWrite(OBled, LOW);
            } else  {
                      buttonState = digitalRead(ButtonPrevious);
                      if (buttonState == HIGH)
                      {
                        SimbleeBLE.begin();
                        //More code here to establish connection with android

                        digitalWrite(OBled, HIGH);
                        SimbleeBLE.end();
                        digitalWrite(OBled, LOW);
                      }
                    }
          }
    }

This is the error I keep getting:
Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: "Simblee"

C:\Users\Lestat\Desktop\SD PROJECR PAPERWORK\Sketch programs\sketch_mar20a\sketch_mar20a.ino: In function 'void loop()':

sketch_mar20a:42: error: invalid use of member function (did you forget the '()' ?)

     SimbleeBLE.sendInt = (Playp);
                        ^
exit status 1
invalid use of member function (did you forget the '()' ?)

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Tagging a question [tag:compilation-errors] and then not posting them is the fast track to getting ignored.

Also asked at: http://forum.arduino.cc/index.php?topic=536567 If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information.

You're trying to assign a value to a function. That is almost certainly wrong.
SimbleeBLE.sendInt(Playp);