text:
Can't retrieve IoT data with Arduino Ethernet shield
I have an IFM AL1332 IO-Link master.
https://media.ifm.com/CIP/mediadelivery/asset/3fe3e997b504a143aa0a54f558f218fd/80284134_EN.pdf?contentdisposition=inline
I can get data out of it via an ethernet connection to my computer and a browser. It looks like the following.

The "value" describes the status of port 1.
I want to do the same thing with an Arduino. I'm using an Arduino Mega and an Ethernet shield 2. Modified the web client code to the following.
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xA8, 0x61, 0x0A, 0xAF, 0x15, 0x1C };

// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(172, 16, 0, 110);  // numeric IP

// Set the static IP address
IPAddress ip(172, 16, 0, 101);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

// Variables to measure the speed
unsigned long beginMicros, endMicros;
unsigned long byteCount = 0;
bool printWebData = true;  // set to false for better speed measurement

void setup() {
  // You can use Ethernet.init(pin) to configure the CS pin
  //Ethernet.init(10);  // Most Arduino shields
  //Ethernet.init(5);   // MKR ETH Shield
  //Ethernet.init(0);   // Teensy 2.0
  //Ethernet.init(20);  // Teensy++ 2.0
  //Ethernet.init(15);  // ESP8266 with Adafruit FeatherWing Ethernet
  //Ethernet.init(33);  // ESP32 with Adafruit FeatherWing Ethernet

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ;  // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  Serial.println("Initialize Ethernet:");

  Ethernet.begin(mac, ip);

  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.print("connecting to ");
  Serial.print(server);
  Serial.println("...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.print("connected to ");
    Serial.println(client.remoteIP());
    // Make a HTTP request:
    client.println("GET /iolinkmaster/port[1]/iolinkdevice/pdin/getdata HTTP/1.1");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  beginMicros = micros();
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  int len = client.available();
  if (len > 0) {
    byte buffer[80];
    if (len > 80) len = 80;
    client.read(buffer, len);
    if (printWebData) {
      Serial.write(buffer, len);  // show in the serial monitor (slows some boards)
    }
    byteCount = byteCount + len;
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    endMicros = micros();
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    Serial.print("Received ");
    Serial.print(byteCount);
    Serial.print(" bytes in ");
    float seconds = (float)(endMicros - beginMicros) / 1000000.0;
    Serial.print(seconds, 4);
    float rate = (float)byteCount / seconds / 1000.0;
    Serial.print(", rate = ");
    Serial.print(rate);
    Serial.print(" kbytes/second");
    Serial.println();

    // do nothing forevermore:
    while (true) {
      delay(1);
    }
  }
}

Wehn I try it on the arduino I get the following.

Initialize Ethernet:
connecting to 172.16.0.110...
connected to 172.16.0.110
disconnecting.
Received 0 bytes in 32.1074, rate = 0.00 kbytes/second

No data arrives.
As far as I can tell I'm sending the correct GET request. I inspected the elements of the pictured webpage.

What am I missing?

send the Host header and finish the request with an empty line (as the WebClient example does)

@Juraj That's what I do, the host seemingly never replies.

it is not in the sketch in the question

@Juraj it is nearly at the end of void setup(). client.println("GET /iolinkmaster/port[1]/iolinkdevice/pdin/getdata HTTP/1.1"); client.println();

and the Host header?

@Juraj Is that not the host header?

client.println("Host: 172.16.0.110");

@Juraj it worked without that. Is that needed?

looks like the firmware of the device has not a strict implementation of the protocol, but if it is update-able then a future version may change it.

client.println("GET /iolinkmaster/port[1]/iolinkdevice/pdin/getdata HTTP/1.1");

The HTTP request was malformed. It was missing \r\n\r\n.
client.println("GET /iolinkmaster/port[1]/iolinkdevice/pdin/getdata HTTP/1.1\r\n\r\n");

This is the statement that returned data from the server.

how many new lines do you need? println adds one, then you have  two with \r\n\r\n and then you have one more client.println(). that is two empty lines more than HTTP requires.

@Juraj   That is what worked. I tried adding a single \r\n but that didn't do it. Adding two did the job. Can't tell you why

@Juraj After a bunch more digging and testing. It looks like the IFM device is extremely timing sensitive. Even a println() is not fast enough. The entire header information needs to be sent in a single line. client.print("GET /iolinkmaster/port[1]/iolinkdevice/pdin/getdata HTTP/1.1\r\nHost: 172.16.0.110\r\n\r\n");It will respond properly to this line.

Your Arduino requests may be missing some headers. You can try this instead:
#include <SPI.h>
#include <Ethernet.h>

// Ethernet setup
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(172, 16, 0, 110);  // Replace with your server IP
EthernetClient client;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ;  // Wait for serial port to connect
  }

  // Start the Ethernet connection
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    for (;;);
  }

  // Allow the Ethernet shield to initialize:
  delay(1000);

  if (client.connect(server, 80)) {
    Serial.println("connected");

    // Send HTTP GET request with additional headers
    client.println("GET /iolinkmaster/port[1]/iolinkdevice/pdin/getdata HTTP/1.1");
    client.println("Host: 172.16.0.110");
    client.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
    client.println("User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36");
    client.println("Accept-Encoding: gzip, deflate");
    client.println("Accept-Language: en-US,en;q=0.9");
    client.println("Connection: keep-alive");
    client.println("Upgrade-Insecure-Requests: 1");
    client.println();

  } else {
    Serial.println("connection failed");
  }
}

void loop() {
  // Read response from server
  while (client.connected()) {
    if (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
  }

  // Disconnect when done
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }
}


text:
NodeMCU does not connect to wifi
I'm trying to connect my nodeMCU to my WiFi network but it keeps printing ........ which means is not connecting to the network. Here is my code used to connect to WiFi. Any reason why it isn't connecting to WiFi network?.
#include <ESP8266WiFi.h>

        // Replace these with your WiFi network settings
        const char* ssid = "******"; //replace this with your WiFi network name
        const char* password = "******"; //replace this with your WiFi network password

        void setup()
        {
          delay(1000);
          Serial.begin(57600);

          WiFi.begin(ssid, password);

          Serial.println();
          Serial.print("Connecting");
          while (WiFi.status() != WL_CONNECTED)
          {
            delay(500);
            Serial.print(".");
          }

          Serial.println("success!");
          Serial.print("IP Address is: ");
          Serial.println(WiFi.localIP());
        }

        void loop() {
        }

could  be that your router is refusing the connection

@jsotola how to fix it?

that is only a guess ..... there could be other reasons ...... try connecting to another network ..... maybe one that does not require a password

try WiFiScan example

@Juraj I tried it and it shows all the WiFi connection available.

including the SSID you want to connect?

@Juraj Yes including the one im trying to connect

has the ssid or password unusual characters like space, hashtag, dolar?

@Juraj No only letters and numbers. Btw what if remove the password? can i pass an empty string to the password variable?

use only one parameter, the ssid

has the network, you want to connect, DHCP?

@Juraj No its not DHCP

then assign IP address

@Juraj How to do that?

try to print WiFi.status() instead of '.'. or better wifi_station_get_connect_status()

did you solve it?

I also have the same issue but i can connect it with mobile hotspot!! so just try in this method

5ghz networks will not connect to esp

If your WiFi network doesn't have DHCP, then you must set the IP addresses
example:
  IPAddress ip(192, 168, 1, 8);
  IPAddress gw(192, 168, 1, 1);
  IPAddress sn(255, 255, 255, 0);
  WiFi.config(ip, gw, sn, gw);

gw is gateway. the last parmeter is dns server's IP. sn is subnet mask.

Thanks for the answer but i checked my router configs and its is DHCP enabled

see DHCP logs in router if there is a record about DHCP request from the esp

If your powering the device via a computer USB port there is a good chance it’s not providing enough power for the wifi.
Try powering fron an external source.

where did you get this? 500 mA from USB is enough. he has no motor connected

source: Stack Exchange

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

sort: votes


text:
TinyGPS doesn't give longitude latitude and other data
I'm trying to get GPS coordinates using TinyGPS. But it keeps printing ********* for the data fields. Any idea on how to get this working?. Here is what the serial monitor looks like.
Here is my code
#include <SoftwareSerial.h>

#include <TinyGPS.h>

/* This sample code demonstrates the normal use of a TinyGPS object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/

TinyGPS gps;
SoftwareSerial ss(1, 0);

static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);

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

  Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
  Serial.println("Sats HDOP Latitude  Longitude  Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum");
  Serial.println("          (deg)     (deg)      Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail");
  Serial.println("-------------------------------------------------------------------------------------------------------------------------------------");

  ss.begin(4800);
}

void loop()
{
  float flat, flon;
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;
  static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

  print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
  print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
  gps.f_get_position(&flat, &flon, &age);
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6);
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  print_date(gps);
  print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 7, 2);
  print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
  print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
  print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0xFFFFFFFF : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
  print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? TinyGPS::GPS_INVALID_F_ANGLE : TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);

  gps.stats(&chars, &sentences, &failed);
  print_int(chars, 0xFFFFFFFF, 6);
  print_int(sentences, 0xFFFFFFFF, 10);
  print_int(failed, 0xFFFFFFFF, 9);
  Serial.println();

  smartdelay(1000);
}

static void smartdelay(unsigned long ms)
{
  unsigned long start = millis();
  do
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void print_float(float val, float invalid, int len, int prec)
{
  if (val == invalid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(' ');
  }
  smartdelay(0);
}

static void print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, "*******");
  else
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0)
    sz[len-1] = ' ';
  Serial.print(sz);
  smartdelay(0);
}

static void print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
  if (age == TinyGPS::GPS_INVALID_AGE)
    Serial.print("********** ******** ");
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ",
        month, day, year, hour, minute, second);
    Serial.print(sz);
  }
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  smartdelay(0);
}

static void print_str(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartdelay(0);
}

Looks like you have no signal or it hasn't locked on to the satellites yet. It can take a long time. How long have you waited? Is your antenna indoors?

why don't you simply print the raw serial data that is coming from the GPS module ...... use the above sketch only after the GPS module starts to send valid data

#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <SPI.h>

float lattitude,longitude; // create variable for latitude and longitude object
SoftwareSerial gpsSerial(8,9);//rx,tx
TinyGPSPlus gps;// create gps object

void setup(){
    Serial.begin(9600); // connect serial
    gpsSerial.begin(9600); // connect gps sensor
    delay(1000);
}

void loop(){

  while(1)
  {
   while (gpsSerial.available() > 0)
   { gps.encode(gpsSerial.read()); }

      if (gps.location.isUpdated())
      {
       lattitude=gps.location.lat();
       longitude=gps.location.lng();
       break;
      }

 }
   Serial.print("LATTITUDE="); Serial.println(lattitude,6);
   Serial.print("LONGITUDE="); Serial.println(longitude,6);
   delay(1000);
}

I managed to get it working using the following library TinyGPS++.h

From the description:
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
But you are using Pin0 and Pin 1, as shown in your code:
SoftwareSerial ss(1, 0);
given that pin0 and pin one are hard Tx and Rx may create problems.
to check if the GPS is receiving anything use the BareMinimum sketch:
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
//Remember that Tx connects to Tx and Rx to Rx
that will show the NMEA string in the serial monitor.
(you can see a video about it, search for:"GPS Module with Arduino- Ublox NEO-6M"
Note:
in TinyGPS the Rx connects to Tx and Tx connects to Rx...
In case you use Softwareserial.h with Arduino Mega  you may have issues as not all pins can Rx (receive)... please check:
https://www.arduino.cc/en/Reference/SoftwareSerial
for NEO-6M the seed should be 9600baud, not 4800 as shown in the sketch, please check page 11 on:
https://www.u-blox.com/sites/default/files/products/documents/NEO-6_DataSheet_%28GPS.G6-HW-09005%29.pdf
Also change Serial.begin(115200); to 9600  so they are in sync.

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


text:
How to connect NRF24 receiver and Micro SD Card Module to Arduino UNO
I would like to know how to connect a NRF24 receiver and Micro SD card module to Arduino board. I have already connected the NRF24 module to the arduino board but now i can't connect the Micro SD card module since the ports like 13,12,11 are used by the NRF24 module. Is there a way to connect those two modules?. I'm trying to save the receiving data on the Micro SD card.

SPI is a multi-drop bus protocol. That means that multiple devices can share the same physical communication medium (wires).
The only thing that needs to be "unique" for a device is its chip select pin which the master device (Arduino) uses to choose which of the devices on the SPI bus it's talking to.
So you can share pins 11, 12 and 13, but choose a different chip select pin for each device.
However, SD cards are notorious for not working well with other devices (especially with some cheap breakout boards) and your mileage may vary.


text:
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x17
Every time I try to upload code to my arduino I always get this error : avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x17. How do i fix it ?

@Juraj Mine is 0x17 the other one is 0x00

nothing special for 0x17

@Juraj Different responses = different error

it is not an error code. it is a random value received instead of expected value

Welcome to the community! I'm not able to comment yet so i'll answer here.
Try changing the connection to other USB port.
If that doesnt work check this question, the solutions can be similar (Juraj is right in the comments) :
avrdude: stk500_getsync(): not in sync: resp=0x00," aka Some Dude Named Avr Won't Let Me Upload My Program
Good Luck!

Comments are not for answering, so you did the right thing by posting an answer. :)


text:
SIM800 gsm Module returns 0 on AT+COPS?
I am using SIM800 Module with Arduino Micro. It reponds well to basic AT commands. But i am unable to send SMS from this module as:
AT+CMGF=1 ERROR
Now while further debugging i saw AT+COPS? Returns 0, means not connected to any operator. That may be causing the CMGF failure. But my AT+COPS=? returns multiple operator. I have an Airtel working sim. Intialyy it was showing AIRTEL too in AT+COPS=? but not now.. anything to do with signal??
AT+COPS?
+COPS: 0
OK AT+COPS=?
+COPS: (2,"405800","405800","405800"),(1," IDEA CELLULAR Ltd","IDEA","40404"),(1,"40505","40505","40505"),,(0-4),(0-2)
What is going wrong here. any inputs?

It can take a while for a modem to register on the network - sometimes several minutes.
Turning on CREG URCs can help you monitor what is happening:
AT+CREG=1

You should now start getting +CREG notifications as the network status changes.
Before using AT+COPS? you should really select a reporting mode so you know what you are looking at. I prefer numeric, since it's easier to parse:
AT+COPS=0,2

That will switch to automatic registration and reporting as numbers.
AT+COPS?
+COPS: 0
OK

That is not registered.
AT+COPS?
+COPS: 0,2,"40404"
OK

That is registered on a network with ID 40404.
The +CREG reports tell you what is going on:
+CREG: 1

That tells you that you have just connected to your home network.
If you are roaming, you would see:
+CREG: 5

Of course, if your home network is not available (say you have an AT&T SIM and only Verizon is visible at the moment), and your SIM doesn't have roaming enabled, then registration will never work.  You'd expect to see +CREG reports of:
+CREG: 2
+CREG: 3
+CREG: 0

That is "trying to register" (2), "registration denied" (3) and "doing nothing much now" (0).
The best document for learning about these commands is the 3GPP Command Set which is the standard that all modern GPRS modems should adhere to.

I am getting error on AT+GREG
OK
AT+COPS?
+COPS: 0
OK
AT+COPS=?
+COPS: (2,"405800","405800","405800"),(1," IDEA CELLULAR Ltd","IDEA","40404"),(1,"AirTel","AirTel","40410"),,(0-4),(0-2)
OK
AT+GREG?
ERROR
AT+GREG1
ERROR
AT+GREG=1
ERROR

If you are using linear voltage regulator such as LM7805 or LM317, then definitely you need to replace with buck converter.  Since the dropout at max current 1.5A is 1.8V.
Pls check the module voltage level using AT+CBC. If the voltage dropped less than 3.3V then module would keep restarts.  Hence recommended voltage level for sim800 series is 3.7 - 4.4v. In that case you need a proper power supply. Try buck converter which has 3A rating and less dropout voltage too.
You can refer my study on my blog..
http://vimtron.blogspot.in/2017/10/gsm-sim800l-and-arduino-mega-2560.html

1- Do you even a proprely working SIM card? Test it with your phone by calling or texting someone with it.
2- Try putting your SIM card into your phone and unlock the SIM card. This function is usualy in the setting area of your smartphone. It will make it easier later on.
3- As always, reboot your PC and try again.

Thanks, We ll as i said it is a working sim i use daily in my HTC android phone. Its not locked and i already restarted PC multiple time.

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


text:
How to Factory reset ESP8266?
I want to use ESP8266 to send emails. I tried twice flashing the Firmware to a particular firmware as suggested in a tutorial. Now both my ESP are unresponsive to AT commands. Let me know the way to RESET it. CH_PD + VCC + RST (Tried this combination), No success there any thing i am missing?

Flash the correct firmware.

You are missing that this is the Arduino SE.  You might get better answers on the EE SE which covers ESP8266

AT commands are executed by the AT interpreter firmware. If you've been attempting to flash other firmware to the ESP8266 module, there is no longer any code in it that interprets AT commands. If you want to it to respond to AT commands again, you'll need to re-flash it with that firmware.

You need to reflash the "AT Firmware" you probably overwrited.
Just follow the instructions in the Espressif board to get the latest one using their "Flash Download Tool".

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


text:
Generating analog signals
is there a way to make the Arduino act as a voltage source, by generating sinusoidal, triangular and other kinds of signals? If so, can it be done using LabVIEW? (I've already managed reading analog signals using VISA)
Thank you!

The Due (and similar SAM based boards) have a DAC built in which can be set to different voltages (I forget the range off hand, maybe 0-Vcc at 12-bit resolution). Change that voltage fast enough, and you have a waveform.
Other Arduinos have PWM outputs which, when filtered through a low-pass filter, give a voltage proportional to the duty cycle of the PWM. Again, change the duty cycle fast enough and you have a waveform (limited by the carrier frequency of the PWM).
Can you do it from LabVIEW? Who knows? I have never used it.


text:
OnKeyPress in a arduino
So, I have 3 buttons to a arduino.
I want to detect the button press on the 3 of them.
For that, i've created a function:
int OnKeyPress (int port) {

  int  LastState, BeginState, r;
  r = 0;

  BeginState = digitalRead(port);

  if (BeginState != LastState) {
      if (BeginState == 1) r = 1 ;
  }

  delay(5);
  LastState = BeginState;
  return r;
}

I want to instantiate 3 instances of this code, separately and they have to retain this variables int  LastState, BeginState, r; for each button, and the next time the function runs on the loop, the variables are the same of when they ran last time.
Just, how?

What you are looking for is called a class.  https://www.tutorialspoint.com/cplusplus/cpp_classes_objects.htm

Another relevant tutorial from the Arduino website: https://www.arduino.cc/en/Hacking/LibraryTutorial

This is an ordinary method (function) which can not be instantiated. It is necessary to write a class with 1 or more methods in it in order to instantiate multiple copies of that class and the method(s) with in that class.
The integers "LastState", "BeginState" and "r" only have scope within the method and will not survive after returning from the method.  There are several approaches to preserve these variables from one call to the next.  They can be declared as static integers.  Or they can be defined globally.
It appears you are recreating the existing Bounce library.  I encourage you to continue if you are learning.  However, you may want to look at the Bounce library's code for guidance.


text:
Connect BotBoarduino with servos and Ultrasonic sensor HC-SR04
I am new to Arduino and I am making a Walking Quadruped using BotBoarduino as microcontroller.
I want to install an Ultrasonic Sensor HC-SR04 so that it will stop when an obstacle is detected.
I have connected the sensor to Arduino UNO. RX-TX of both the boards are cross-connected. Now I have written this code for UNO:
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
}

void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(100);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance= duration*0.034/2;
  // Prints the distance on the Serial Monitor
  Serial.println(distance);

  delay(200);
}

And I am doing this on BotBoarduino:
int byteRead;

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

void loop() {
  while (Serial.available())
  {
    byteRead = Serial.read();
  }

  if(byteRead >= 10)
  {
    walk();
  }
  else
  {
    stand();
  }
}

Whenever distance = 10 or above, let it walk. Else stop.
But it's not working. It's not stopping on obstacles. Sensor is doing its work perfectly, but I think Botboarduino is not getting the values.
Any idea guyz?

you need to look at the output of your Serial.println and what you are receiving in,   if the distance is 40 it is printing a '4' and a '0'   then you are reading in a single byte, which would give you an ascii 4 which in decimal is 34    so you will never get a byte that is less then 10 (0-10 are all non printable characters)

You have a misconception, how the Serial interface works.
The Serial interface is basically a stream of bytes (and sometimes start/stop and parity bits, which you normally don't care about) without any structure. This has to be implemented by you.
Also you have to understand, that you don't and cannot know, when a specific byte actually is being send. The fact that you typed a complete string into the serial monitor (or send a string via one call for Serial.println()) does NOT mean, that they are transmitted as a complete packet. The bytes of the string are send one after another and there may be a short delay between two arbitrary bytes. So with your reading while() loop, you are reading bytes until there is a delay long enough for the microcontroller to notice or until the message is send complete. You cannot know, which is the case for this very specific transaction. Also it seems odd, that you are only using the last read byte in your code, since the variable byteRead is overwritten on every while() loop cycle.
Then there is the format, in which you can send data through Serial.

Binary data: Since it is a byte stream, you can directly use the binary values of the bytes to reflect the data. This is easy and good for cases, in which only one value of the size of one byte is transfered every time. So there is no need to distinguish between different parts of the message. In this case you have to use Serial.write() on your sending end. This will write binary data. (You will not be able to see the values in your serial monitor, since it is displaying only ASCII-encoded characters).
ASCII-encoded data string: You are using Serial.println(), which sends an ASCII-encoded string representing the data followed by a NEWLINE character ('\n'). In case of the value 10 you are currently sending 3 bytes: '1', '0', '\n'. In this method, you are using a delimiter character (in this case '\n') to mark the end of a message. On the receiving end you have to read all bytes into a buffer, until you are receiving the delimiter character. Then you can process the message as a whole. In your case you would convert the ASCII-encoded string into an integer variable (for example with the function atoi())

To exactly explain, what is happening with your code: As Chad wrote in his comment, you are trying to use the binary value of a byte, that is an ASCII-encoded character. When looking at an ASCII table, you can see, that there is no printable character with a binary value under 10. So, since you send only printable characters with Serial.println(), There will never be a value, that is under 10.
So now you have 2 options:

Send the variable as binary data in one (!!!) byte (since you are not using distances as big as 255cm the value can fit in there; just make sure, that the byte variable does not roll over) and use every read byte on the receiving end for your code.
Send the variable as ASCII-encoded data with Serial.println() and do the correct processing of the resulting message on the receiving end. Refer to the Serial examples in the Arduino IDE for this. You can directly integrate their code into yours.

Thanks! I just changed Serial.println(distance) to Serial.write(distance). Now it is sending the exact value.


text:
SPI Digital Potentiometer not working on ESP32
I have an MCP4151 digital potentiometer chip. I have managed to get it to work using and Arduino Uno using the code below:
#include <SPI.h>

byte address = 0x00;
int CS= 5;

void setup()
{
  pinMode (CS, OUTPUT);
  SPI.begin();
}

void loop()
{
  for (int i = 0; i <= 128; i++)
  {
    digitalPotWrite(i);
    delay(10);
  }
  delay(500);
  for (int i = 128; i >= 0; i--)
  {
    digitalPotWrite(i);
    delay(10);
  }
}

int digitalPotWrite(int value)
{
  digitalWrite(CS, LOW);
  SPI.transfer(address);
  SPI.transfer(value);
  digitalWrite(CS, HIGH);
}

But when I try to get it to work using an ESP32 programmed using Arduino language it doesn't. I have connected like that

SCK -> 18
MOSI -> 23
SS -> 5

I also used the potentiometer inside like a voltage divider for test purposes. GND on one leg, 3.3v on the other and an LED on the wiper. Are there other settings that I have to implement in order the ESP32 SPI to work like an Arduino SPI? Did I miss something?

If I am using the SPI defaults (Serial.begin()) and print the variables on the serial monitor Serial.println(MOSI); Serial.println(SCK); Serial.println(SS); I got these defaults MOSI 23, SCLK 18 and SS 5 (VSPI).

I managed to get it to work in a strange way. I opened the example included in the ESP32 SPI Library and copied some points from there.
I first initialise a pointer to the SPI class, then I call begin() at that pointer and inside the digitalPotWrite function I call beginTransaction(10000,MSBFIRST,SPI_MODE0) and end the transaction before digitalPotWrite finishes. Full code here:
#include <SPI.h>

static const int spiClk = 1000000;
byte address = 0x00;
SPIClass * hspi = NULL;

void setup()
{
  pinMode(15, OUTPUT);
  hspi = new SPIClass(HSPI);
  hspi->begin();
}

void loop()
{
  for (int i = 0; i <= 128; i++)
  {
    digitalPotWrite(i);
    delay(10);
  }
  delay(500);
  for (int i = 128; i >= 0; i--)
  {
    digitalPotWrite(i);
    delay(10);
  }
}

int digitalPotWrite(int value)
{
  hspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
  digitalWrite(15, LOW);
  hspi->transfer(address);
  hspi->transfer(value);
  digitalWrite(15, HIGH);
  hspi->endTransaction();
}

The ESP32 SPI library has defaults for the HSPI pins (14, 12, 13, 15). For VSPI pins, you must specify the pins in begin().
SPI.begin(18, 19, 23, 5);

I both tried to use the HSPI pins with SPI.begin(); and those pins using SPI.begin(18, 19, 23, 5); but nothing worked. Maybe ESP32 used an incompatible frequency for SPI?

Change the int for a void in the function...
That's it.
When you call that function is never going back, still waiting for a return.
int digitalPotWrite(int value)
{
  digitalWrite(CS, LOW);
  SPI.transfer(address);
  SPI.transfer(value);
  digitalWrite(CS, HIGH);
}


text:
Voltmeter using Arduino mega 2560 giving unexpected result after some time
I have been trying to construct a smart energy meter that can observe readings of 220v household. For now i am working on voltmeter. I have been following the circuit I attached. Transformer step down 220V to 6V. Zener diode is of 5V.
The output from the circuit( 5v max) is fed to arduino Mega 2560 A0 pin.
* I am powering arduino using a USB cable *
Arduino takes this voltage as input from pin A0 in form of analog values between 0 to 1023. 0 being 0 volt and 1023 being 5v.So any random analog value corresponds to X=(5/1023)*Y where Y is obtained analog value. X is then multiplied by a value obtained by hit and try method (165 in my case) to reach the exact reading of voltage in line observed via multimeter.
Now the problem is that, everything works fine when i calibrate it, but after some time when i switch circuit on the value is inaccurate by margin, and i have to calibrate it again and again every time I turn circuit on after some time.If i switch circuit on soon after switching it off, it gives almost accurate value. I guess this issue is due to the capacitor, but i don't know anything about it or how to solve it I have constructed the same circuit more than 5 times, soldering it 3 times and 2 times on bread board and i am sure there is no problem with my implementation, verified it many times.
this is my code:
float V; // Voltage samples
float V0;

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

void loop() {
  for(int i=0; i<=20000; i++){
    V = V + analogRead(A0);
  }
  V = V / 20000;
  V = round(V);

  float V0 = V * (5.0 / 1023.0);
  I0 = I0 * 165; // has to be callibrated again and again each time circuit is switched on after a while

  Serial.print("Voltage = ");
  Serial.print(V0);
  Serial.println(" -------------- ");
  delay(1500);
}

this is the link i am following
http://engineerexperiences.com/3-phase-smart-energy-meter-using-arduino.html
Any help would be appreciated, Thanks!

you monitor the household or only some appliance or device?

thank you for asking Mr. Edgar Bonet, my aim is to monitor electrical consumption of a household.

With that circuit you can expect a roughly 10% variance in the output voltage depending on the exact moment at which you sample the voltage.
The basic circuit you have, and the waveforms generated, are like this:

That green waveform is the one you are reading. As you can see, exactly where you sample defines what the result will be.
Since you're trying to average over an undefined period (20,000 samples of how long per sample exactly?) you're not going to get a particularly well defined output.
You should change your sampling strategy to perform multiple samples over a well defined period to find the maximum value. That is the value you should then use in your calculations.
Ideally, you want to repeatedly sample for at least one entire waveform cycle. At 50Hz that's a period of 20ms (17ms for 60Hz).
For example:
uint16_t maxval = 0;
uint32_t ts = millis();
while (millis() - ts < 20) {
    uint16_t val = analogRead(0);
    if (val > maxval) {
       maxval = val;
    }
}

// Use "maxval" in your calculations.

With this strategy, because you're looking for the peak value, you don't care about the impact that the capacitor has on the circuit (except that it will remain artificially high for a period if the voltage drops), so you could actually simplify the circuit and remove that capacitor completely.

he uses average of 20000 A0 readings

Yeah, now the post is formatted I see that. That's not really ideal though, since you're dependent on a) how fast the ADC reads, and b) how fast the capacitor discharges. By finding the max over at least 1 wave period you don't care about either of those.

Re-worded it to fit that existing method a little more.

Honorable Majenko, first of all thank you for sparing some time and communicating amazing knowledge to me.
Earlier i was using this approach
for (int i=0; i<=39; i++){
adc_int[i] = analogRead(A0);
}
int max = adc_int[0];
for(int i=0; i<=39; i++){
if(max < adc_int[i])
max = adc_int[i];
}
and i used this peak value in my calculations the results were unpredictable after time as i explained in my question, anyway I will follow what you have instructed and get back to you soon after implementing your teachings

I just wanted to add some points to what Majenko already said.
You are making a measurement device, so you need a precise reference. So why are you using the 5V reference?
Your 5V in your circuit is assumed to be stable. But is it? Maybe some time you are using the PC to power it, then you attach a lot of loads to the USB ports, then you use a wall USB power supply. Every time the 5V can change (see here for instance). A variation in the supply of +/-5% will be translated in a +/- 12V for a 240V input (I don't know if this is above or below your expected accuracy).
The solution is to use the internal reference, which is an internal peripheral used explicitely for measuring analog sources.
In your case (Arduino MEGA 2560) you have a 1.1V or a 2.56V internal references. Your transformer is a 240->6V transformer, which means the value you should read after it is around 8.5V (6Vrms has a peak of 6*1.415 = 8.5V). After the voltage divider, this becomes 1.53 V. Consequently you can use the 2.56V reference in this case. To do so write, in your setup function, analogReference(INTERNAL2V56);. Then your readings will be relative to 2.56V rather than 5.0V (so float V0 = V * 2.56 / 1023.0;).
(Note: the way to implement this was taken from the arduino reference manual; I never implemented it, so it may require tweaking)


text:
Angular velocity of a dc motor controlled by a potentiometer
I created a setup in which a potentiometer controls a dc motor, with current flow through the dc motor controlled by an H-bridge.
The principle is as follows:
With the potentiometer dial set to the mid-point, the motor is off. Rotating the potentiometer clockwise would cause the motor to rotate in one direction, with speed dictated by the displacement of the potentiometer from the mid-point: the greater the displacement from mid-point, the greater the speed of rotation of the motor. If the potentiometer is rotated anti-clockwise, away from mid-point, the motor would rotate in the opposite direction from before; again, with speed dictated by the extent of displacement of the potentiometer from mid-point.
The loop has three functions, where HB_12EN is to enable the drivers, HB_1A is the first driver input, and HB_2A is the second driver input (H-Bridge pins 1, 2 and 7, respectively) as per this datasheet:
http://www.ti.com/lit/ds/symlink/sn754410.pdf
To summarise their functions: HB_12EN allows voltage to be applied to the the device controlled by the H-Bridge (in this case a motor), and is pulse-wave-modulated. HB_1A and HB_2A control the flow of current through the motor, setting its angular velocity. HB_1A set HIGH and HB_2A set LOW directs current one way through the motor, and HB1A set LOW and HB_2A set HIGH directs current the other way through the motor.
The loop is:
//OUTPUTS
int const HB_12EN = 9; //pwm pin
int const HB_1A = 2;
int const HB_2A = 3;

//INPUTS
int const POT_MOT = 0; //A0, analog 0

//GLOBAL VARIABLES
unsigned int pot_val = 0; //ADC value from potentiometer
unsigned int grp_num = 1;

pot_val = analogRead(POT_MOT);
grp_num = setMotSwitch(HB_12EN, HB_1A, HB_2A, pot_val, grp_num);
setMotSpeed(HB_12EN, pot_val, grp_num);

The two (non-library) functions are:
unsigned int setMotSwitch(int const motor_reg, int const first_motor, int const sec_motor, unsigned int pot_value, unsigned int group_num) //grp 0: 0-383; grp 1: 384-639; grp 2: 640-1023
{
  if (pot_value >= 0 && pot_value < 384)
  {
    if (group_num != 0)
    {
       digitalWrite(motor_reg, LOW);
       digitalWrite(first_motor, HIGH);
       digitalWrite(sec_motor, LOW);
       group_num = 0;
    }
  }
  else if (pot_value > 383 && pot_value < 640)
  {
    if (group_num != 1)
    {
      digitalWrite(motor_reg, LOW);
      digitalWrite(first_motor, LOW);
      digitalWrite(sec_motor, LOW);
      group_num = 1;
    }
  }
  else if (pot_value > 639 && pot_value <= 1023)
  {
    if (group_num != 2)
    {
      digitalWrite(motor_reg, LOW);
      digitalWrite(first_motor, LOW);
      digitalWrite(sec_motor, HIGH);
      group_num = 2;
    }
  }
  else
  {
      digitalWrite(motor_reg, LOW);
      digitalWrite(first_motor, LOW);
      digitalWrite(sec_motor, LOW);
      group_num = 0;
  }
  return group_num;
}

void setMotSpeed(int const motor_reg, unsigned int pot_value, unsigned int group_num)
{
  unsigned int mot_speed = 0;
  if (group_num == 0)
  {
    mot_speed = map(pot_value, 0, 383, 255, 0);
    mot_speed = constrain(mot_speed, 0, 255);
    analogWrite(motor_reg, mot_speed);
  }
  else if (group_num == 1)
  {
    if (pot_value > 500 && pot_value < 523)
    {
      digitalWrite(motor_reg, HIGH); //braking
    }
    else
    {
      digitalWrite(motor_reg, LOW);
    }
  }
  else if (group_num == 2)
  {
    mot_speed = map(pot_value, 640, 1023, 0, 255);
    mot_speed = constrain(mot_speed, 0, 255);
    analogWrite(motor_reg, mot_speed);
  }
}

I tried to proceed as follows:
As the potentiometer would produce an ADC input with 1024 states, I divided those 1024 states in to 8 groups, the first three groups, covering the first 384 states (0-383) correspond to a dc motor direction (let's say anticlockwise), representing different speeds of rotation (ignoring issues of many-to-one mapping). The middle 2 groups, 256 states (384-639), correspond to a stationary motor. The last three groups, 384 states (640-1023), correspond to motor rotation in the other direction (in this example, clockwise). The ADC inputs have to be translated in to analog outputs with 256 possible states (0-255), so I map each range as appropriate; for 0-383, the mapping has to be reversed, so an input of 383 corresponds to an input of 0. The middle range (384-639) is stationary, but I tried to make a small "sub"-range in the middle a "braking range", I believed this is achieved by setting both H-bridge inputs to LOW. The 640-1023 range mapping is 640 to 0 and 1023 to 255.
Hopefully that makes sense. It seems to work, the issue I am having is that the motor seems to achieve a greater speed in one direction compared to the other: the maximum rotation speed produced in the motor is greater when the potentiometer is at its maximum in one direction compared to the other. I am pretty sure the code above gives an "even" mapping from the potentiometer to the motor for both directions. Is this, then, something to do with hardware?, and is it something to be anticipated in these kinds of setups?
Any help would be appreciated. If anyone has any advice on the best way to combine a potentiometer -or similar- input with a motor output let me know. The "braking" functionality is also a little confusing.

I appreciate all the feedback so far. I would like to add that the code itself is a product of a number of factors. It is partly constrained by a textbook: I am trying to limit the code to what has been covered in a textbook I am working through. The other factors include: I) I wanted to use a number of functions, and II) I wanted to write a programme that would bypass setting the H-Bridge pins through every iteration. My main motivation for posting is that I would like to know if the issue I am having with motor speed is a coding issue or possibly a hardware issue.

Personally I wouldn't bother with "groups". Just do simple maths:
int velocity = analogRead(POT_MOT) - 512;

velocity now gives you a value from -512 to +511.
bool dir = (velocity >= 0);

dir is now true for a positive value (0 is considered positive) or false for negative.
velocity = abs(velocity);

velocity is now made positive if it is negative.
So you now have two variables: dir which sets the direction, and velocity which sets the speed.
Now you can "offset" it:
velocity = map(velocity, 0, 512, -128, 255);

velocity is now changed to fit into the range -128 to 255. Anything above 0 is a valid speed, anything below is the "dead zone" and stops the motor.
if (velocity <= 0) {
    // If it's negative or zero stop
    digitalWrite(motor_reg, LOW);
    digitalWrite(first_motor, LOW);
    digitalWrite(sec_motor, LOW);
} else {
    if (dir) { // Pot was positive
        analogWrite(motor_reg, velocity);
        digitalWrite(first_motor, LOW);
        digitalWrite(sec_motor, HIGH);
    } else { // Pot was negative
        analogWrite(motor_reg, velocity);
        digitalWrite(first_motor, HIGH);
        digitalWrite(sec_motor, LOW);
    }
}

Adjust the negative value in the map to change the size of the "dead zone".

i would break out this into three or at least two parts:
1) a call to change the speed of the motor;
2) a call to read the potential meter setting;
3) a call to convert the potential meter setting into motor speed, optional.
the code would look like this:
  pot_setting = potsetting_read(); //read pot setting
  speed_setting = pot2spd(pot_setting); //convert pot setting to motor speed
  motor_setspeed(speed_setting); //set motor speed

it is not difficult to figure out each of the three functions.
the  more challenging of the three, to a newbie, is the one that sets the motor speed. there are many ways to do it, and I personally prefer to use timer interrupts.
the basic construct is to sequentially go through a set of pin states, where the duration of each state transition is controlled by a timer interrupt. by changing how fast that timer interrupt takes place, you change the speed in which the pins transition their states, thus motor speed.


text:
UNO: AnalogRead results not as expected
I'm new to Arduino, and trying to build a project that will measure the voltage and current from two, unconnected, 12v batteries. The present test environment comprises:-

a 13.8v power supply (run from the mains (240v)) which is powering two separate voltage dividers;
a take-off from one voltage divider going to A0, the take-off to the second going to A3;
a connection from Arduino GND to the -ve rail on the bread-board;

The voltage dividers are identical - both comprising 10kOhm and 200kOhm resistors - so I am expecting that an analogRead of A0 and A3 would return similar results, which they don't. A0 is up around the 344 mark, A3 is down around 133. So, the problem is that identical voltage dividers are not giving the same readings from the same input voltage.
Code and results follow, and I would be grateful for any hints, tips and further education!
Code follows
#define NUMBER_OF_SAMPLES 10
int looped = 0;

void setup()
{
  Serial.begin(57600);  Serial.println("Test sketch starting");
}

void loop()
{
  int temp1=0;
  int temp2=0;
  int temp3=0;

  looped++;

  for(int count=0; count<NUMBER_OF_SAMPLES; count++)
  {
    temp1 = analogRead(A0);
    temp3 += temp1;

    Serial.print("temp1 = ");
    Serial.print(temp1);    Serial.print(",");
    delay(200);
  }
  Serial.println(temp3);
  temp3 = 0;
  for(int count=0; count<NUMBER_OF_SAMPLES; count++)
  {

    temp2 = analogRead(A2);
    temp3 += temp2;
    Serial.print("temp2 = ");
    Serial.print(temp2);    Serial.print(",");
    delay(200);
  }
  Serial.println(temp3);
  Serial.println("");

  if(looped>NUMBER_OF_SAMPLES)
  {
    delay(500000);
  }
}

And this is the output.
Test sketch starting
temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,3450
temp2 = 129,temp2 = 125,temp2 = 137,temp2 = 137,temp2 = 126,temp2 = 136,temp2 = 134,temp2 = 136,temp2 = 132,temp2 = 132,1324

temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,3450
temp2 = 132,temp2 = 133,temp2 = 136,temp2 = 137,temp2 = 135,temp2 = 129,temp2 = 132,temp2 = 137,temp2 = 131,temp2 = 130,1332

temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 345,temp1 = 344,temp1 = 344,3448
temp2 = 133,temp2 = 134,temp2 = 132,temp2 = 128,temp2 = 133,temp2 = 134,temp2 = 131,temp2 = 125,temp2 = 130,temp2 = 129,1309

temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 345,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 345,3442
temp2 = 132,temp2 = 133,temp2 = 135,temp2 = 132,temp2 = 131,temp2 = 133,temp2 = 134,temp2 = 133,temp2 = 131,temp2 = 130,1324

temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,3440
temp2 = 133,temp2 = 133,temp2 = 131,temp2 = 133,temp2 = 132,temp2 = 133,temp2 = 133,temp2 = 130,temp2 = 133,temp2 = 138,1329

temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,3440
temp2 = 133,temp2 = 135,temp2 = 133,temp2 = 133,temp2 = 131,temp2 = 133,temp2 = 133,temp2 = 133,temp2 = 133,temp2 = 133,1330

temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,temp1 = 344,3440
temp2 = 131,temp2 = 134,temp2 = 128,temp2 = 134,temp2 = 134,temp2 = 132,temp2 = 132,temp2 = 132,temp2 = 132,temp2 = 133,1322

temp1 = 344,temp1 = 343,temp1 = 344,temp1 = 344,temp1 = 343,temp1 = 344,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 344,3435
temp2 = 142,temp2 = 141,temp2 = 135,temp2 = 135,temp2 = 135,temp2 = 133,temp2 = 134,temp2 = 133,temp2 = 133,temp2 = 132,1353

temp1 = 343,temp1 = 344,temp1 = 344,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,3432
temp2 = 135,temp2 = 130,temp2 = 136,temp2 = 135,temp2 = 141,temp2 = 130,temp2 = 135,temp2 = 133,temp2 = 134,temp2 = 131,1340

temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,3430
temp2 = 129,temp2 = 133,temp2 = 129,temp2 = 131,temp2 = 133,temp2 = 130,temp2 = 131,temp2 = 135,temp2 = 134,temp2 = 133,1318

temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,temp1 = 343,3430
temp2 = 131,temp2 = 135,temp2 = 130,temp2 = 128,temp2 = 137,temp2 = 136,temp2 = 136,temp2 = 131,temp2 = 134,temp2 = 134,1332

You are reading A2 instead of A3.

Well that's a schoolboy error! Thanks for that, and reformatting the original question. Now I've fixed the code I see that the result returned by A0 starts at 345 and drops to 341, while that for A3 starts at 324 and drops to 289 - both over 20 iterations. A0 returns 320 six times consecutively, while A3 just drops consistently and the gap between the two widens. Any ideas how I might correct this?

What resistors are you using?

The divider on A0 is 9840 and 200000, that on A3 is 9770 and 199800 - both measured on a UT203 digital multimeter, so nothing particularly special but, hopefully, not garbage either. The resistors were from Maplins, so probably 5%, but would that make the difference?

I'm new to electronics as well as Arduino, I have assumed that the tolerance would only apply to initial manufacture e.g. that a 5% 200kOhm resistor would actually be + or -  10kOhms, but that it would be stable in operation rather than having an allowable drift of + or - 5%?

Quote from: CtrlAltElite: you could try each time you do an analogRead, do two reads of each pin, but throw away the first one, and don't use it.

Try swapping the divider pin assignments and see if the difference goes with the pins or the resistors.

@CtrlAltElite - thanks for this. Could you explain why this might help resolve the problem that readings from both pins are falling, and why A3 is falling faster than A0 as that makes no sense to me.

@ChrisStratton - I've altered the code so that A2 is read before A0 e.g. swapped them around. That seems to have stopped both of them falling - are you able to explain why that might be. However, that has not resolved the problem that A2 is giving readings around 341 and A0 is giving readings around 135 - any ideas?

Again, try swapping the wires between A2 and A0 and see if the values follow the port pins or the external dividers.

Which Arduino? Please add the appropriate tag to the question. Also please edit the question to make absolutely clear what port you are using. As it stands the question says you are using A3 but the code says A2.

and why A3 is falling faster than A0 - what do you mean by that? And do you mean A2?

Can you please use your meter to actually measure the voltage at the mid-point of the voltage dividers? On the figures you give you should be getting around 0.657 volts there. On that basis the analog reading of 134 looks like the correct one. 134.5 / 1024 * 5 = 0.657

move this to just before the for loop ... Serial.print("temp1 = "); ... for narrower printout

Assuming you are using an Arduino Uno, I set up your test situation on my bench.
I modified the prints as jsotola suggested to move the "temp1 = " out of the loop.
I measured 0.670V on the A0 port and 0.666 on the A2 port.
We would expect 0.657V as per the Voltage Divider Calculator.
Vout = Vin * R2 / (R1 + R2)
13.8 * 10 / (200 + 10) = 0.657

As suggested on my page about the ADC the formula for converting a reading into a voltage is:
float voltage = ((float) rawADC  + 0.5 ) / 1024.0 * Vref;

Therefore a reading of 134 gives the correct results:
(134 + 0.5) / 1024 * 5 = 0.657

My results were:
Test sketch starting
temp1 = 133,134,133,134,134,134,134,134,134,134,1338
temp2 = 133,132,133,134,132,133,133,134,133,133,1330

temp1 = 134,134,134,134,133,134,134,134,134,134,1339
temp2 = 134,133,133,132,133,133,133,134,133,133,1331

temp1 = 134,134,134,133,134,134,134,133,134,134,1338
temp2 = 133,133,133,134,133,133,133,133,133,132,1330

temp1 = 134,134,133,135,134,134,134,134,134,134,1340
temp2 = 133,133,133,133,133,133,132,133,133,134,1330

temp1 = 134,134,134,134,134,134,134,134,134,134,1340
temp2 = 133,133,132,133,133,134,133,133,134,133,1331

temp1 = 134,133,133,134,134,133,134,134,134,134,1337
temp2 = 132,133,133,133,134,133,133,133,133,133,1330

temp1 = 134,134,134,135,134,133,134,134,134,134,1340
temp2 = 133,133,133,134,133,133,133,133,133,132,1330

This therefore shows that your sketch is working properly, and that there must be some electrical issue in your voltage divider or your connections.

The slight differences would be accounted for by noise in the voltage divider circuitry.

Excellent, thanks Nick, that gives me the confidence to try this again with soldered connections, rather than on a breadboard.


text:
How do I use an image sensor with an arduino uno?
I have recently taken apart an old digital camera for its parts and I have found an image sensor inside it.
For those of you who don't know, an image sensor measures light; the shutter opens, light hits the sensor and the sensor converts this light into data to be stored as an image.
My question is how can I implement it into a project? What equipment do I need? It has a tape wire so I'm not really sure how I can use it. I have attached a photo of it also. Thanks!!

You need to find markings on it and figure out what the component actually is.  Then you can maybe find a datasheet for it that explains how it works and commmnicates.  Once you know that you can decide if that's something you can do with an Arduino.  Be prepared to learn that Arduino might not be big enough or fast enough to do anything with that particular sensor.

ARM based Arduinos probably are fast enough.

how can I implement it into a project?

Find its datasheet, understand how it works and code to it.
Just as what you would with any other devices. The challenge here is that you will be hard pressed to find any info about those kind of devices.


text:
Cant get rid of Soft WDT reset using ESP8266
Im using ESP12E DevKit v2 (esp8266 wifi module) board for controlling relays and displaying DHT22 temp,humidity on web server. It runs smoothly but after while i always get a watchdog timer reset. (If i have serial monitor opened up it happens quicker)
I tried adding more delays, yield function, removing serial prints that i use for debugging but nothing helps.
I think it can be caused because my website is being refreshed every 1sec, because i want to display current time and most recent temp,humidity and this was the easiest way to do it. But this WDT reset problem appeared just recently after i added more code and functionality to my site.
Could anyone have a look at my code and give me some advice on what could help or cause the problem?
Arduino code:

// Including the needed libraries
#include <ESP8266WiFi.h>
#include <DHT.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#define DHTTYPE DHT22 // Defining DHT sensor type

// Network details
const char* ssid = "Connection1";
const char* password = "pass";

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);

// Set web server port number to 80
WiFiServer server(80);

// Variable to store the HTTP request
String header;

// Decode HTTP GET value
String valueString = "0";
int pos1 = 0;
int pos2 = 0;

// Variables to store the current output state
String relay0State = "on";
String relay1State = "off";
String relay2State = "off";
String brightness = "0";

// Variables to save date and time
String formattedDate;
String dayStamp;
String timeStamp;

// Variables assigned to pins
const int relay0 = 16;
const int relay1 = 5;
const int relay2 = 4;
const int DHT1Pin = 0;
const int DHT2Pin = 2;

// Initialize DHT sensors
DHT dht1(DHT1Pin, DHTTYPE);
DHT dht2(DHT2Pin, DHTTYPE);

void setup() {
  Serial.begin(115200);
  // Initialize the output variables as outputs
  pinMode(relay0, OUTPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  // Set outputs to LOW
  digitalWrite(relay0, LOW);
  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);

  dht1.begin();
  dht2.begin();

  // Connect to Wi-Fi network with SSID and password
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  delay(3000);
  while (WiFi.status() != WL_CONNECTED) {
    delay(300);
    Serial.print(".");
  }

  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi CONNECTED with IP: ");
  Serial.println(WiFi.localIP());
  server.begin();

  // Initialize a NTPClient to get time
  timeClient.begin();
  // Setting offset time in seconds to adjust for current timezone -> GMT +1 = 3600
  timeClient.setTimeOffset(3600);
}
void loop(){
  WiFiClient client = server.available();   // Listen for incoming clients

   while(!timeClient.update()) {
    timeClient.forceUpdate();
  }
  // The formattedDate comes with the following format 2018-05-28T16:00:13Z
  formattedDate = timeClient.getFormattedDate();
  // Extract date
  int splitT = formattedDate.indexOf("T");
  dayStamp = formattedDate.substring(0, splitT);
  // Extract time
  timeStamp = formattedDate.substring(splitT+1, formattedDate.length()-1);

  if (client) {
    Serial.println("NEW CLIENT");          // Printing a message out in the serial port, if a new client connects
    String currentLine = "";                // String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        //Serial.write(c);                    // print it out the serial monitor
        header += c;
        if (c == '\n') {                    // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();

            // Turns the PINs on and off
          if (header.indexOf("GET /0/on") >= 0) {
              relay0State = "on";
              digitalWrite(relay0, HIGH);
            } else if (header.indexOf("GET /0/off") >= 0) {
              relay0State = "off";
              digitalWrite(relay0, LOW);
            } else if (header.indexOf("GET /1/on") >= 0) {
              relay1State = "on";
              digitalWrite(relay1, HIGH);
            } else if (header.indexOf("GET /1/off") >= 0) {
              relay1State = "off";
              digitalWrite(relay1, LOW);
            } else if (header.indexOf("GET /2/on") >= 0) {
              relay2State = "on";
              brightness = "75";
              digitalWrite(relay2, 191);
            } else if (header.indexOf("GET /2/off") >= 0) {
              relay2State = "off";
              brightness = "0";
              digitalWrite(relay2, 0);
            }

            // Read humidity
            float h1 = dht1.readHumidity();
            float h2 = dht2.readHumidity();
            // Read temperature as Celsius (the default)
            float t1 = dht1.readTemperature();
            float t2 = dht2.readTemperature();
            // Read temperature as Fahrenheit (isFahrenheit = true)
            float f1 = dht1.readTemperature(true);
            float f2 = dht2.readTemperature(true);

            // Calculating average temp and humidity from DHT22 sensors
            float temperature = (t1 + t2)/2;
            float temperaturef = (f1 + f2)/2;
            float humidity = (h1 + h2)/2;

            // Display the HTML web page
            client.println("<!DOCTYPE html>");
            client.println("<meta http-equiv=\"refresh\" content=\"1\" name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("");
            client.println("<title>Smart TERA</title>  ");
            client.println("

Smart TERA

");
            client.println(timeStamp);
            client.println(" / " + dayStamp);
            client.println("

Temperature: ");
            client.println(temperature);
            client.println("℃ /  ");
            client.println(temperaturef);
            client.println("℉

Humidity: ");
            client.println(humidity);
            client.println("%

Light Brightness:  %
 <input class=\"slider\" type=\"range\" min=\"0\" max=\"100\" step=\"25\" value="+brightness+" id=\"myRange\">");
            client.println("
");

            if(header.indexOf("GET /?value=")>=0) {
                pos1 = header.indexOf('=');
                pos2 = header.indexOf('&');
                valueString = header.substring(pos1+1, pos2);
                if(valueString == "0" ){
                  relay2State = "off";
                  brightness = "0";
                  digitalWrite(relay2, 0);
                } else if (valueString == "25"){
                  relay2State = "on";
                  brightness = "25";
                  digitalWrite(relay2, 64);
                } else if (valueString == "50"){
                  relay2State = "on";
                  brightness = "50";
                  digitalWrite(relay2, 128);
                } else if (valueString == "75"){
                  relay2State = "on";
                  brightness = "75";
                  digitalWrite(relay2, 192);
                } else if (valueString == "100"){
                  relay2State = "on";
                  brightness = "100";
                 digitalWrite(relay2, 255);
                }
           }
            // Display current state, and ON/OFF buttons for controlling relays
            client.println("
Rock Heater - State " + relay0State + "
");
            // If the relay0State is off, it displays the ON button
            if (relay0State=="off") {
              client.println("
<button class=\"button\">ON</button>
");
            } else {
              client.println("
<button class=\"button button2\">OFF</button>
");
            }

            client.println("
Humidifier - State " + relay1State + "
");
            if (relay1State=="off") {
              client.println("
<button class=\"button\">ON</button>
");
            } else {
              client.println("
<button class=\"button button2\">OFF</button>
");
            }

            client.println("
Light - State " + relay2State + "
");
            if (relay2State=="off") {
              client.println("
<button class=\"button\">ON</button>
");
            } else {
              client.println("
<button class=\"button button2\">OFF</button>
");
            }
            client.println("
 ");

            // The HTTP response ends with another blank line
            client.println();
            yield();
            // Break out of the while loop
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      } yield();
    }
    // Clear the header variable and close the connection
    header = "";
    client.stop();
    Serial.println("CLIENT DISCONNECTED");
   }
}

Error message:
Soft WDT reset

>>>stack>>>

ctx: sys
sp: 3fffed40 end: 3fffffb0 offset: 01b0
3fffeef0:  3ffee990 0abd1a53 60000600 00000001
3fffef00:  00000000 3ffed9d8 00000000 00000000
3fffef10:  4022cf78 3ffed9d8 3ffee990 60000600
3fffef20:  4022f8c1 3ffed9d8 3ffee990 0abd1a53
3fffef30:  4022f906 3fffdab0 00000000 3fffdcb0
3fffef40:  3ffee9b8 3fffdab0 00000000 40205d0f
3fffef50:  40000f49 40000f49 3fffdab0 40000f49
3fffef60:  40000e19 40001878 00000002 00000000
3fffef70:  3fffff10 aa55aa55 000000b4 401048e4
3fffef80:  401048ea 00000002 00000000 3315d4f6
3fffef90:  4010000d 0c060f10 1427fd57 49e0d507
3fffefa0:  40100a84 3fffef3c 40100a31 3ffffe88
3fffefb0:  3fffffc0 00000000 00000000 feefeffe
3fffefc0:  feefeffe feefeffe feefeffe feefeffe
3fffefd0:  feefeffe feefeffe feefeffe feefeffe
3fffefe0:  feefeffe feefeffe feefeffe feefeffe
3fffeff0:  feefeffe feefeffe feefeffe feefeffe
3ffff000:  feefeffe feefeffe feefeffe feefeffe
3ffff010:  feefeffe feefeffe feefeffe feefeffe
3ffff020:  feefeffe feefeffe feefeffe feefeffe
3ffff030:  feefeffe feefeffe feefeffe feefeffe
3ffff040:  feefeffe feefeffe feefeffe feefeffe
3ffff050:  feefeffe feefeffe feefeffe feefeffe
3ffff060:  feefeffe feefeffe feefeffe feefeffe
3ffff070:  feefeffe feefeffe feefeffe feefeffe
3ffff080:  feefeffe feefeffe feefeffe feefeffe
3ffff090:  feefeffe feefeffe feefeffe feefeffe
3ffff0a0:  feefeffe feefeffe feefeffe feefeffe
3ffff0b0:  feefeffe feefeffe feefeffe feefeffe
3ffff0c0:  feefeffe feefeffe feefeffe feefeffe
3ffff0d0:  feefeffe feefeffe feefeffe feefeffe
3ffff0e0:  feefeffe feefeffe feefeffe feefeffe
3ffff0f0:  feefeffe feefeffe feefeffe feefeffe
3ffff100:  feefeffe feefeffe feefeffe feefeffe
3ffff110:  feefeffe feefeffe feefeffe feefeffe
3ffff120:  feefeffe feefeffe feefeffe feefeffe
3ffff130:  feefeffe feefeffe feefeffe feefeffe
3ffff140:  feefeffe feefeffe feefeffe feefeffe
3ffff150:  feefeffe feefeffe feefeffe feefeffe
3ffff160:  feefeffe feefeffe feefeffe feefeffe
3ffff170:  feefeffe feefeffe feefeffe feefeffe
3ffff180:  feefeffe feefeffe feefeffe feefeffe
3ffff190:  feefeffe feefeffe feefeffe feefeffe
3ffff1a0:  feefeffe feefeffe feefeffe feefeffe
3ffff1b0:  feefeffe feefeffe feefeffe feefeffe
3ffff1c0:  feefeffe feefeffe feefeffe feefeffe
3ffff1d0:  feefeffe feefeffe feefeffe feefeffe
3ffff1e0:  feefeffe feefeffe feefeffe feefeffe
3ffff1f0:  feefeffe feefeffe feefeffe feefeffe
3ffff200:  feefeffe feefeffe feefeffe feefeffe
3ffff210:  feefeffe feefeffe feefeffe feefeffe
3ffff220:  feefeffe feefeffe feefeffe feefeffe
3ffff230:  feefeffe feefeffe feefeffe feefeffe
3ffff240:  feefeffe feefeffe feefeffe feefeffe
3ffff250:  feefeffe feefeffe feefeffe feefeffe
3ffff260:  feefeffe feefeffe feefeffe feefeffe
3ffff270:  feefeffe feefeffe feefeffe feefeffe
3ffff280:  feefeffe feefeffe feefeffe feefeffe
3ffff290:  feefeffe feefeffe feefeffe feefeffe
3ffff2a0:  feefeffe feefeffe feefeffe feefeffe
3ffff2b0:  feefeffe feefeffe feefeffe feefeffe
3ffff2c0:  feefeffe feefeffe feefeffe feefeffe
3ffff2d0:  feefeffe feefeffe feefeffe feefeffe
3ffff2e0:  feefeffe feefeffe feefeffe feefeffe
3ffff2f0:  feefeffe feefeffe feefeffe feefeffe
3ffff300:  feefeffe feefeffe feefeffe feefeffe
3ffff310:  feefeffe feefeffe feefeffe feefeffe
3ffff320:  feefeffe feefeffe feefeffe feefeffe
3ffff330:  feefeffe feefeffe feefeffe feefeffe
3ffff340:  feefeffe feefeffe feefeffe feefeffe
3ffff350:  feefeffe feefeffe feefeffe feefeffe
3ffff360:  feefeffe feefeffe feefeffe feefeffe
3ffff370:  feefeffe feefeffe feefeffe feefeffe
3ffff380:  feefeffe feefeffe feefeffe feefeffe
3ffff390:  feefeffe feefeffe feefeffe feefeffe
3ffff3a0:  feefeffe feefeffe feefeffe feefeffe
3ffff3b0:  feefeffe feefeffe feefeffe feefeffe
3ffff3c0:  feefeffe feefeffe feefeffe feefeffe
3ffff3d0:  feefeffe feefeffe feefeffe feefeffe
3ffff3e0:  feefeffe feefeffe feefeffe feefeffe
3ffff3f0:  feefeffe feefeffe feefeffe feefeffe
3ffff400:  feefeffe feefeffe feefeffe feefeffe
3ffff410:  feefeffe feefeffe feefeffe feefeffe
3ffff420:  feefeffe feefeffe feefeffe feefeffe
3ffff430:  feefeffe feefeffe feefeffe feefeffe
3ffff440:  feefeffe feefeffe feefeffe feefeffe
3ffff450:  feefeffe feefeffe feefeffe feefeffe
3ffff460:  feefeffe feefeffe feefeffe feefeffe
3ffff470:  feefeffe feefeffe feefeffe feefeffe
3ffff480:  feefeffe feefeffe feefeffe feefeffe
3ffff490:  feefeffe feefeffe feefeffe feefeffe
3ffff4a0:  feefeffe feefeffe feefeffe feefeffe
3ffff4b0:  feefeffe feefeffe feefeffe feefeffe
3ffff4c0:  feefeffe feefeffe feefeffe feefeffe
3ffff4d0:  feefeffe feefeffe feefeffe feefeffe
3ffff4e0:  feefeffe feefeffe feefeffe feefeffe
3ffff4f0:  feefeffe feefeffe feefeffe feefeffe
3ffff500:  feefeffe feefeffe feefeffe feefeffe
3ffff510:  feefeffe feefeffe feefeffe feefeffe
3ffff520:  feefeffe feefeffe feefeffe feefeffe
3ffff530:  feefeffe feefeffe feefeffe feefeffe
3ffff540:  feefeffe feefeffe feefeffe feefeffe
3ffff550:  feefeffe feefeffe feefeffe feefeffe
3ffff560:  feefeffe feefeffe feefeffe feefeffe
3ffff570:  feefeffe feefeffe feefeffe feefeffe
3ffff580:  feefeffe feefeffe feefeffe feefeffe
3ffff590:  feefeffe feefeffe feefeffe feefeffe
3ffff5a0:  feefeffe feefeffe feefeffe feefeffe
3ffff5b0:  feefeffe feefeffe feefeffe feefeffe
3ffff5c0:  feefeffe feefeffe feefeffe feefeffe
3ffff5d0:  feefeffe feefeffe feefeffe feefeffe
3ffff5e0:  feefeffe feefeffe feefeffe feefeffe
3ffff5f0:  feefeffe feefeffe feefeffe feefeffe
3ffff600:  feefeffe feefeffe feefeffe feefeffe
3ffff610:  feefeffe feefeffe feefeffe feefeffe
3ffff620:  feefeffe feefeffe feefeffe feefeffe
3ffff630:  feefeffe feefeffe feefeffe feefeffe
3ffff640:  feefeffe feefeffe feefeffe feefeffe
3ffff650:  feefeffe feefeffe feefeffe feefeffe
3ffff660:  feefeffe feefeffe feefeffe feefeffe
3ffff670:  feefeffe feefeffe feefeffe feefeffe
3ffff680:  feefeffe feefeffe feefeffe feefeffe
3ffff690:  feefeffe feefeffe feefeffe feefeffe
3ffff6a0:  feefeffe feefeffe feefeffe feefeffe
3ffff6b0:  feefeffe feefeffe feefeffe feefeffe
3ffff6c0:  feefeffe feefeffe feefeffe feefeffe
3ffff6d0:  feefeffe feefeffe feefeffe feefeffe
3ffff6e0:  feefeffe feefeffe feefeffe feefeffe
3ffff6f0:  feefeffe feefeffe feefeffe feefeffe
3ffff700:  feefeffe feefeffe feefeffe feefeffe
3ffff710:  feefeffe feefeffe feefeffe feefeffe
3ffff720:  feefeffe feefeffe feefeffe feefeffe
3ffff730:  feefeffe feefeffe feefeffe feefeffe
3ffff740:  feefeffe feefeffe feefeffe feefeffe
3ffff750:  feefeffe feefeffe feefeffe feefeffe
3ffff760:  feefeffe feefeffe feefeffe feefeffe
3ffff770:  feefeffe feefeffe feefeffe feefeffe
3ffff780:  feefeffe feefeffe feefeffe feefeffe
3ffff790:  feefeffe feefeffe feefeffe feefeffe
3ffff7a0:  feefeffe feefeffe feefeffe feefeffe
3ffff7b0:  feefeffe feefeffe feefeffe feefeffe
3ffff7c0:  feefeffe feefeffe feefeffe feefeffe
3ffff7d0:  feefeffe feefeffe feefeffe feefeffe
3ffff7e0:  feefeffe feefeffe feefeffe feefeffe
3ffff7f0:  feefeffe feefeffe feefeffe feefeffe
3ffff800:  feefeffe feefeffe feefeffe feefeffe
3ffff810:  feefeffe feefeffe feefeffe feefeffe
3ffff820:  feefeffe feefeffe feefeffe feefeffe
3ffff830:  feefeffe feefeffe feefeffe feefeffe
3ffff840:  feefeffe feefeffe feefeffe feefeffe
3ffff850:  feefeffe feefeffe feefeffe feefeffe
3ffff860:  feefeffe feefeffe feefeffe feefeffe
3ffff870:  feefeffe feefeffe feefeffe feefeffe
3ffff880:  feefeffe feefeffe feefeffe feefeffe
3ffff890:  feefeffe feefeffe feefeffe feefeffe
3ffff8a0:  feefeffe feefeffe feefeffe feefeffe
3ffff8b0:  feefeffe feefeffe feefeffe feefeffe
3ffff8c0:  feefeffe feefeffe feefeffe feefeffe
3ffff8d0:  feefeffe feefeffe feefeffe feefeffe
3ffff8e0:  feefeffe feefeffe feefeffe feefeffe
3ffff8f0:  feefeffe feefeffe feefeffe feefeffe
3ffff900:  feefeffe feefeffe feefeffe feefeffe
3ffff910:  feefeffe feefeffe feefeffe feefeffe
3ffff920:  feefeffe feefeffe feefeffe feefeffe
3ffff930:  feefeffe feefeffe feefeffe feefeffe
3ffff940:  feefeffe feefeffe feefeffe feefeffe
3ffff950:  feefeffe feefeffe feefeffe feefeffe
3ffff960:  feefeffe feefeffe feefeffe feefeffe
3ffff970:  feefeffe feefeffe feefeffe feefeffe
3ffff980:  feefeffe feefeffe feefeffe feefeffe
3ffff990:  feefeffe feefeffe feefeffe feefeffe
3ffff9a0:  feefeffe feefeffe feefeffe feefeffe
3ffff9b0:  feefeffe feefeffe feefeffe feefeffe
3ffff9c0:  feefeffe feefeffe feefeffe feefeffe
3ffff9d0:  feefeffe feefeffe feefeffe feefeffe
3ffff9e0:  feefeffe feefeffe feefeffe feefeffe
3ffff9f0:  feefeffe feefeffe feefeffe feefeffe
3ffffa00:  feefeffe feefeffe feefeffe feefeffe
3ffffa10:  feefeffe feefeffe feefeffe feefeffe
3ffffa20:  feefeffe feefeffe feefeffe feefeffe
3ffffa30:  feefeffe feefeffe feefeffe feefeffe
3ffffa40:  feefeffe feefeffe feefeffe feefeffe
3ffffa50:  feefeffe feefeffe feefeffe feefeffe
3ffffa60:  feefeffe feefeffe feefeffe feefeffe
3ffffa70:  feefeffe feefeffe feefeffe feefeffe
3ffffa80:  feefeffe feefeffe feefeffe feefeffe
3ffffa90:  feefeffe feefeffe feefeffe feefeffe
3ffffaa0:  feefeffe feefeffe feefeffe feefeffe
3ffffab0:  feefeffe feefeffe feefeffe feefeffe
3ffffac0:  feefeffe feefeffe feefeffe feefeffe
3ffffad0:  feefeffe feefeffe feefeffe feefeffe
3ffffae0:  00000000 00000000 00000020 401013da
3ffffaf0:  3ffe9680 401047c0 3fff0154 000000fd
3ffffb00:  00000001 401039e3 3ffed800 3ffed848
3ffffb10:  40103e46 00000000 00000020 401013da
3ffffb20:  00000005 00000000 00000020 401013da
3ffffb30:  00000000 00000000 00000020 401013da
3ffffb40:  3ffe9680 401047c0 3fff0154 00000000
3ffffb50:  00000001 401039e3 3ffed800 401022c2
3ffffb60:  40103e46 00000000 00000000 401022c2
3ffffb70:  40103729 00040000 7fffffff 00000000
3ffffb80:  00000022 40103726 00040000 00000000
3ffffb90:  00000000 00000000 0000001f 401050bd
3ffffba0:  4000050c 00080000 00002000 4000050c
3ffffbb0:  40229838 00000030 0000001b ffffffff
3ffffbc0:  40229836 00000023 00000020 00000005
3ffffbd0:  3ffe95b4 00000020 3ffe951c 00000000
3ffffbe0:  00000005 3ffe9514 00000001 3ffecdc8
3ffffbf0:  3ffef854 00000001 3fff0a30 00000030
3ffffc00:  3ffe9685 401047db 3ffed110 3ffee2a8
3ffffc10:  00000000 00000000 00000020 000000fa
3ffffc20:  00000004 00000000 00000020 401013da
3ffffc30:  3ffe9684 401047a6 3ffecdc8 401013da
3ffffc40:  00000005 00000000 00000020 401013da
3ffffc50:  3ffe9685 401047db 3ffed110 3ffed800
3ffffc60:  401020f1 3ffed110 3ffed800 000000f4
3ffffc70:  00007fff 06460509 402296d3 00000001
3ffffc80:  ffffffff 00000000 3ffe97d1 00000008
3ffffc90:  40229722 3ffecdf0 3ffef854 00000001
3ffffca0:  4022982e 3ffecdf0 3ffef854 3ffecdf0
3ffffcb0:  00000005 00000005 00000008 3fff1250
3ffffcc0:  3ffe9682 402287df 3ffecdf0 3fff0a68
3ffffcd0:  00000000 4021ba8b 3ffee2a8 00000022
3ffffce0:  00000000 00000002 00000000 3ffecdf0
3ffffcf0:  3fff126a 40104e63 3fff0a68 3ffeffe4
3ffffd00:  3fff1234 0000002f 00013880 00000001
3ffffd10:  00000004 4020ddc9 3ffef218 3ffeffe4
3ffffd20:  3fff126a 0000023f 00000001 3ffeef98
3ffffd30:  00000000 3ffeef98 4216cccd 00000000
3ffffd40:  3ffef644 3ffef60c 3fff1234 4020e04b
3ffffd50:  4000dd1f 3ffef60c 3fff1234 4020e43c
3ffffd60:  3ffef490 4bc6a7f0 12b020c4 00000000
3ffffd70:  00000000 00000000 4bc6a7f0 3ffef494
3ffffd80:  3ffef644 00000000 3ffef60c 40215b14
3ffffd90:  00000000 3ffee968 019672ab 00000000
3ffffda0:  00000000 3fff1234 3ffef1b8 00000000
3ffffdb0:  3ffee990 3ffef1b8 3ffe8510 3fff1234
3ffffdc0:  3fff1234 3fff0868 3ffef60c 40215d18
3ffffdd0:  40100000 3ffeef98 00000000 401001cd
3ffffde0:  3fff1278 3fff0868 3ffef60c 40216730
3ffffdf0:  3fff0864 402171fc 00000010 401007f4
3ffffe00:  00000014 3fff0864 000000ff 00000000
3ffffe10:  00000006 3ffef580 00000284 401007f4
3ffffe20:  00000055 00000218 3fff0864 3fff0864
3ffffe30:  3fff07fc 3ffef60c 3fff0b2c 40216778
3ffffe40:  00000000 4bc6a7f0 676c8b43 00000000
3ffffe50:  00000000 00000000 4bc6a7f0 00000000
3ffffe60:  3ffef1dc 000003ef 4010014c 0002bef4
3ffffe70:  00000000 4bc6a7f0 79db22d0 00000000
3ffffe80:  032cca97 00000000 3ffe8510 00000000
3ffffe90:  00000003 3ffe9238 40205d54 3fffefa0
3ffffea0:  00000003 00000000 3fff05c4 40203a0b
3ffffeb0:  0328466c 00000000 3fff05c4 40203a5d
3ffffec0:  00000002 3ffe9235 40205d54 4216cccd
3ffffed0:  3fffff50 00000000 3fffff50 40205355
3ffffee0:  3ffe9238 00000000 3fff05c4 40203a5d
3ffffef0:  0000000d 00000000 7ff80000 402055ca
3fffff00:  00000002 00000000 3fffff50 40205355
3fffff10:  3ffe9235 429ab852 3fffff50 4216cccd
3fffff20:  7fc00000 429ab852 3fffff50 40205714
3fffff30:  7fc00000 429ab852 3fffff50 40205731
3fffff40:  7fc00000 429ab852 7fc00000 402029d7
3fffff50:  40206478 00000000 00001388 4020e7a7
3fffff60:  00000000 3fff05c4 00000000 00000000
3fffff70:  00000000 3fff0a8c 0000007f 00000000
3fffff80:  7fc00000 41c9999a 3ffef0f8 402025a4
3fffff90:  00000000 00000000 00000001 3ffef160
3fffffa0:  3fffdad0 00000000 3ffef130 40205e00
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(1,6)

 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

EspExceptionDecoder stack trace:

don't use the String class

u mean that i change string brightness to int?

http://hacking.majenko.co.uk/the-evils-of-arduino-strings

thanks that was new for me, but wouldnt that just make WDT reset come later? i want to eliminate it as much as possible

try the esp exception decoder, it will tell you what line of your code crashes.

But this WDT reset problem appeared just recently after i added more code and functionality to my site. ahhh, "more code", yes, it's always "more code" that does it ... any chance you can share what code you added that broke your ESP?

i have installed the decoder and posted the stack trace here, there are errors on more lines not just single one.. most of them are memory issues if i understand them correctly


text:
Using Arduino wireless SD Shield to save data to sd card and send to PC over wireless network
I'm using an Arduino Mega to monitor the current & voltage input to four different sensors. This works fine - the sensors work as expected and I can view the results via the Serial Monitor or Parallax DAQ for Excel.
SETUP
I also have an Arduino wireless SD shield (now retired) with an XBee module (shown in the below image):

Arduino Shield page
XBee module page

I would like to do the following:

Save the current/voltage sensors' output locally to the SD card
Send the data over a wifi connection for plotting using plotly API (see example  here)

I've seen a bunch of tutorials on how to get the shield to work but can't seem to figure it out:

Arduino WiFi shield example
Instructables
Can I connect to WiFi with an Arduino, "wireless SD shield" and XBee

Here's my code (removed the current/voltage sensor code for brevity):

#include <SPI.h>
#include <WiFi.h>
#include <SD.h>

void setup() {
  // initialize serial and wait for the port to open:
  Serial.begin(9600);
  while(!Serial) ;

  SPI.begin();

  Serial.println("Checking WiFi status:");
  Serial.print("\tWiFi Status: ");
  Serial.println(WiFi.status());

  if(WiFi.status() == WL_NO_SHIELD){
    Serial.println("\tNo Shield present.\n");
  }else{
    Serial.println("\tShield found.\n");
  }

  Serial.println("Initializing SD card:");
  if (!SD.begin(53)) {
    Serial.println("\tSD card initialization failed.\n");
    return;
  }else{
    Serial.println("\tSD card initialization successful.\n");
  }

  // attempt to connect using WEP encryption:
  Serial.println("Initializing Wifi:");
  printMacAddress();

  // scan for existing networks:
  Serial.println("Scanning available networks...");
  listNetworks();
}

void loop() {
  delay(5000);
  // scan for existing networks:
  Serial.println("Scanning available networks:");
  listNetworks();
}

void printMacAddress() {
  // the MAC address of your Wifi shield
  byte mac[6];

  // print your MAC address:
  WiFi.macAddress(mac);
  Serial.print("\tMAC: ");

  for(int i = 0; i < 5; i++){
    Serial.print(mac[5-i],HEX);
    if(i != 5){
      Serial.print(":");
    }
  }
  Serial.println(" ");
}

void listNetworks() {
  // scan for nearby networks:
  Serial.println("** Scan Networks **");
  byte numSsid = WiFi.scanNetworks();

  // print the list of networks seen:
  Serial.print("number of available networks:");
  Serial.println(numSsid);

  // print the network number and name for each network found:
  for (int thisNet = 0; thisNet<numSsid; thisNet++) {
    Serial.print(thisNet);
    Serial.print(") ");
    Serial.print(WiFi.SSID(thisNet));
    Serial.print("\tSignal: ");
    Serial.print(WiFi.RSSI(thisNet));
    Serial.print(" dBm");
    Serial.print("\tEncryption: ");
    Serial.println(WiFi.encryptionType(thisNet));
  }
}

OUTPUT
Checking WiFi status:
    WiFi Status: 255
    No Shield present.

Initializing SD card:
    SD card initialization successful.

Initializing Wifi:
    MAC: 0:0:0:0:0:
Scanning available networks...
** Scan Networks **
number of available networks:0

Not sure what is going on here.

"Arduino Wireless SD shield" is not "Arduino WiFi shield".
The code you have is for the Arduino WiFi shield. But you have Arduino Wireless SD shield for a XBee module. XBee is not WiFi. Zigbee protocol is different protocol than WiFi.
You can save data to SD card with the SD library. Install the library in Library Manager and try the examples.
Arduino WiFi shield:

Note: the Arduino WiFi library is only for this shield and clones

Thanks, I am able to write to the SD card without problem. I have the shield and the XBee module, how do I get them to work together and discover/send data over available WiFi networks?

XBee can't send data over WiFi

So, what is the shield/module for? the Arduino example seems to suggest that the shield by itself is capable to atleast finding the WiFi networks and joining them. Right now, I can't even get the Mac address to be printed.

which example? what you have in question is for WIFI shield, not for Wireless shield. Zigbee protocol is different protocol then WiFi

I don't think I understand the difference - if you do, can you point out how/where I'm wrong or what I should be looking for? I'm a mechanical engineer without much experience in electronics. I'm clearly lost and don't want to ask a million irrelevant questions to find out that my initial premise was flawed.

it is software which communicates over the radio-frequency. WiFi is other software then Zigbee. they can't talk to each other


text:
Breaking out of a while loop using IR remote for neopixel
I've been piecing together various lighting effects. I am wanting to have each lighting effect loop until another button is pressed to trigger another lighting effect.
I've come to a bit of standstill at the moment. I've created a loop that doesn't seem to end. I've had a look around but I can't work out how to fix my code. Sorry in advanced, I'm new to using arduinos but if anyone could help out, it would be much appreciated.
Thanks!

//www.elegoo.com
//2016.12.9

#include "IRremote.h"
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(20, PIN, NEO_GRB + NEO_KHZ800);

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'
int Remote = 0;

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received

// describing Remote IR codes

{

  switch(results.value)

  {
  case 0xFFA25D: Serial.println("POWER");
  ArrowRight(strip.Color(25, 0, 0), 100); //Red
  ArrowRight(strip.Color(0, 0, 25), 100); //Blue
//  Remote = 0xFFA25D;
  break;

  case 0xFFE21D: Serial.println("FUNC/STOP");
  ArrowLeft(strip.Color(25, 0, 0), 100); // Red
  ArrowLeft(strip.Color(0, 0, 25), 100); // Blue
//  Remote = 0xFFE21D;
  break;

  case 0xFF629D: Serial.println("VOL+"); break;
  case 0xFF22DD: Serial.println("FAST BACK");    break;
  case 0xFF02FD: Serial.println("PAUSE");    break;
  case 0xFFC23D: Serial.println("FAST FORWARD");   break;
  case 0xFFE01F: Serial.println("DOWN");    break;
  case 0xFFA857: Serial.println("VOL-");    break;
  case 0xFF906F: Serial.println("UP");    break;
  case 0xFF9867: Serial.println("EQ");    break;
  case 0xFFB04F: Serial.println("ST/REPT");    break;
  case 0xFF6897: Serial.println("0");    break;
  case 0xFF30CF: Serial.println("1");    break;
  case 0xFF18E7: Serial.println("2");    break;
  case 0xFF7A85: Serial.println("3");    break;
  case 0xFF10EF: Serial.println("4");    break;
  case 0xFF38C7: Serial.println("5");    break;
  case 0xFF5AA5: Serial.println("6");    break;
  case 0xFF42BD: Serial.println("7");    break;
  case 0xFF4AB5: Serial.println("8");    break;
  case 0xFF52AD: Serial.println("9");    break;
  case 0xFFFFFFFF: Serial.println(" REPEAT");break;

  default:
    Serial.println(" other button   ");

  }// End Case

  delay(0); // Do not get immediate repeat

} //END translateIR
void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode");
  irrecv.enableIRIn(); // Start the receiver
  strip.begin();
  strip.show();
  Remote = 0;

}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (irrecv.decode(&results)) // have we received an IR signal?

  {
    translateIR();
    irrecv.resume(); // receive the next value
  }
}/* --(end main loop )-- */

void ArrowRight(uint32_t c, uint8_t wait) {
  while (Remote = 0xFFA25D) {
    for (uint16_t i = strip.numPixels()/2; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
    }
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(wait);
  }
}

void ArrowLeft(uint32_t c, uint8_t wait) {
  while (Remote = 0xFFE21D) { // The j<# determines how many cycles
    for (uint16_t i = strip.numPixels()/2-1; i + 1 > 0 ; i--) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
    }
    for (uint16_t i = strip.numPixels(); i + 1 > 0 ; i--) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(wait);
  }
}

what loop runs constantly?

Both of them seem to do it at the moment. I think its because I've got Remote to equal the value that corresponds to the button press on my remote. I think the issue is that I've not been able to implement an "override" as you may say, to switch over to a different loop. Cheers.

both of which ones?   Are you referring to the the while loops in the Arrow functions? And they run forever when you press the corresponding button and release it?

I think you don't need the while loops -- you should take them out & turn them into one-shots and take the translateIR() out of the conditional in loop().  Inside the conditional, if you do get a new message, copy it to from a temp variable into &result instead of updating &result each loop()

while (Remote = 0xFFE21D) You have to use == here, or this will be an assignment

There are a few causes for eternal loops and other things that will go wrong in your code.
As ChrisL noted above you are assigning a value to Remote in the while condition which is almost certainly not what you wanted to do.  On the plus side, every C/C++ programmer ever has also made that same mistake at some time or another.
Now if you change it to while (Remote == 0xcFFE21D) it still won't work, because Remote is always 0.  You have commented out the lines that set Remote, but they are after the call to the function.  To be honest since you know the value before you call the function (because of the switch statement) you don't need to check the value within the function so you could remove the while loop all together.  If you intention is to call this function repeatedly until a different button is pressed on the remote, the way you are doing it won't work.  you need to store the last button pressed value and then pass that into the switch statement.  When a different button is pressed update the 'last button pressed' value.
You for loop conditions need looking at.  I don't think that the number of lights in the strip is going to change while the program is running.  If that's true then your are wasting processor instructions by doing strip.numPixels()/2-1 you might want to look at setting global values in setup.
Also the for loops might benefit from using i >= 0 because then you don't need to do i+1 every loop.

Hi Gorilla, thank you and everyone else for your help.
I'm fairly new to C/C++, as is quite evident. Like you have suggested, I am wanting to call a certain function, repeatedly, until another button is pressed, to switch to another function.
I'm going to have a go at it now but if anyone could help me amend the code that would be very helpful, thanks!

You'll learn more if you do it yourself.:)  You have said what you need to do in the above comment, "... call a certain function, repeatedly, until another button is pressed..." So ensure that the function you call does its think once and then returns.  The code that calls the function is the one that is checking to see if the "until ..." has occurred, because it was that code that decided to call the function in the first place.  You are 90% of the way there.

You might want to tinker with C/C++ programming concepts in an IDE that has a symbolic debugger, including tracing and breakpoints. Debugging Arduino programs is a pain in the butt since you don't have any of those tools. You have to add serial port print statements and do a fair amount of guesswork.

Once you work out your basic logic using normal non-Arduino C/C++, you can re-implement your code on Ardino.


text:
Arduino Switching Between Loops IR Remote
I've been working on an LED strip project. However, I've come to a stand still at the moment. Within the program I am wanting to assign different lighting effects to each button on my IR remote. I am wanting the program to work on the basis that each lighting effect will run, until another button is pressed, to start another effect.
Currently with my code I have made it so each effect will run, once, when the corresponding button on the IR remote is pressed.
I am fairly new to C++ / Arduino but from my understanding I need to have a variable which would hold the current value of the IR remote. I am unsure on how to actually implement this. I will post my code below and if anyone could give me tips or even amendments to my code it would be to a great help.
Thank you in advanced.

#include "IRremote.h"
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(20, PIN, NEO_GRB + NEO_KHZ800);

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'
int Remote = 0;

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received

// describing Remote IR codes

{
  switch(results.value)
  {
  case 0xFFA25D: Serial.println("POWER");
  ArrowRight(strip.Color(25, 0, 0), 100); //Red
  ArrowRight(strip.Color(0, 0, 25), 100); //Blue
  break;

  case 0xFFE21D: Serial.println("FUNC/STOP");
  ArrowLeft(strip.Color(25, 0, 0), 100); // Red
  ArrowLeft(strip.Color(0, 0, 25), 100); // Blue
  break;

  default:
  Serial.println(" other button   ");

  }// End Case

  delay(0); // Do not get immediate repeat

} //END translateIR
void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode");
  irrecv.enableIRIn(); // Start the receiver
  strip.begin();
  strip.show();
  Remote = 0;

}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (irrecv.decode(&results)) // have we received an IR signal?

  {
    translateIR();
    irrecv.resume(); // receive the next value
  }
}/* --(end main loop )-- */

void ArrowRight(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 1; j++) { // The j<# determines how many cycles
    for (uint16_t i = strip.numPixels()/2; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(50);
    }
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(50);
  }
}

void ArrowLeft(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 1; j++) { // The j<# determines how many cycles
    for (uint16_t i = strip.numPixels()/2-1; i + 1 > 0 ; i--) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(50);
    }
    for (uint16_t i = strip.numPixels(); i + 1 > 0 ; i--) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(50);
  }
}

delay(0) apparently[*] acts like delay(2^32) or about 10^10 milliseconds. That may not be what you had in mind ... :)
Try reducing the delay to 1 or use delayMicroseconds() to get something shorter. That should at least get you some repeatable results.
(10^10 mSec is ~ 16.5 weeks, for those without a calculator handy).
[*]  I didn't read the code, nor wait for the call to expire. I tried it and saw that the Uno froze. I'm guessing a zero-argument to delay() isn't rejected but just gets decremented as usual, until it hits zero.

Hi, thanks for the reply. I'm not sure you've understood what I'm wanting to achieve. I am wanting each effect to continuously loop until another button is pressed, activating another effect. I've loaded the code I pasted onto my uno, it works fine for me. I did changed the delay like you said, this seems to just change the speed of which my effect happens, changing it to 1 makes the effect turn into a flash. Thanks.

I need to have a variable which would hold the current value of the
  IR remote.

You already have one.  It's called results and is of type decode_results.
decode_results results;

You read the IR results into that variable.  Then you clear it to look for another one.  What you need is a way to store the last good code that you got.  Your best bet is to just use an int and store a certain number for each code, store a 1 when you get 0xFFA25D and a 2 when you get 0xFFE21D or something like that.  Then use that int instead of the results variable to decide what to do in the rest of the code.