text:
SPI Temperature sensor interface with Arduino Uno
I want to interface with an AD7314 Temperature Sensor. I want to only read the temperature value from the sensor and output the value on to 8 LEDs connected to the Arduino. But so far I have not been able to read from the sensor. The datasheet says that the temperature readings are in 10 bit 2's complement, so I plan to convert to 8 bit before putting it out on the LEDs. Here is my code so far.
I am new to SPI and clearly don't understand the temperature sensor's datasheet. Please can anyone elaborate or explain where I am going wrong?
Note: I have chosen pin A0 (PIN 23 of ATMEGA328P) as slave select and not pin 10
#include <SPI.h>

byte val;

void setup (void) {
  pinMode(0, OUTPUT); //LED 1
  pinMode(1, OUTPUT); //LED 2
  pinMode(5, OUTPUT); //LED 3
  pinMode(6, OUTPUT); //LED 4
  pinMode(7, OUTPUT); //LED 5
  pinMode(8, OUTPUT); //LED 6
  pinMode(9, OUTPUT); //LED 7
  pinMode(10, OUTPUT);//LED 8
  pinMode(11, OUTPUT); // MOSI
  pinMode(12, INPUT); //MISO
  pinMode(13, OUTPUT); //CLOCK PIN
  digitalWrite(A0, HIGH);  // ensure Slave select stays high
  SPI.begin ();
  Serial.begin(9600);
} // end of setup

void loop (void) {
  // enable Slave Select
  digitalWrite(A0, LOW); // enable communication with slave
  delay (0.425);// wait for conversion
  val = SPI.transfer(0x00);// read from sensor
  Serial.println(val); // display reading on serial monitor
  // disable Slave
  digitalWrite(A0, HIGH);
}

delay (0.425);// wait for conversion

You can't delay a fraction of a millisecond. You can use delayMicroseconds though:
delayMicroseconds(425);

However, you don't need to sleep at all.

The conversion clock for the part is internally generated so no
  external clock is required except when reading from and writing
  to the serial port. In normal mode, an internal clock oscillator
  runs the automatic conversion sequence. A conversion is initiated
  every 400 ms. At this time, the part wakes up and performs
  a temperature conversion. This temperature conversion typically
  takes 25 ms, at which time the part automatically shuts down.
  The result of the most recent temperature conversion is available
  in the serial output register at any time.

You have your chip select pin backwards:

To ensure that the serial port is reset properly
  after power-up, the CE must be at a logic low before the
  first serial port access. The serial clock is active only when CE is
  high. For correct data synchronization, it is important that the
  CE be low when the serial port is not being accessed

So it should start LOW, and be set HIGH before you read, and back to LOW afterwards.
You need to read 2 bytes, not one, then combine them in the right way to make a proper 8-bit value:
digitalWrite(A0, HIGH);
uint8_t b1 = SPI.transfer(0x00);
uint8_t b2 = SPI.transfer(0x00);
digitalWrite(A0, LOW);

int8_t = (b1 << 1) | (b2 >> 7);

The reason for that is that the first bit of the first byte is a "leading zero" so you need to discard it, then add the first bit of the second byte as the last bit of your value, discarding the remainder of the second byte, since you specified only an 8-bit resolution in your question.

Just for my clarification, i have 2 questions: 1) uint8_t SPI.transfer(0x00), does this statement mean that the value being read is an unsigned integer and not a byte why so ?  2) SPI.transfer(0x00), does the 0x00 mean that value being read or transferred is 0 (decimal) regardless ?

@user7187418 uint8_t is an 8 bit unsigned value. Better known as a byte. The 0x00 is the value being sent by SPI which happens (and is ignored) at the same time as receiving. It's how SPI works.

could i replace the 0x00 with an unsigned integer variable, lets say x1 or would that actually discard the value being read ?

You can replace it with whatever you like. It will make no difference. The ADC chip ignores it. With SPI you can only transmit and receive at the same time, so to receive you must send something, even if it's ignored.

If the output was to be changed from 8 bit to 6 bit out, would the bit shift change to (b1<<0) | (b2<<5) ?  (i am new to bit shifting and digital logic, if that helps)

No it would be just b1 >> 1


text:
Using 5V microphone module with Wemos D1 Mini Pro 3.3V analog pin
I want to read values from this microphone module using Wemos D1 Mini Pro analog pin. Unfortunately, this module operates on 5V, but the analog pin on Wemos has range 0-3.3V. I have tried to use a voltage divider on microphone module output, but I am getting very low values which don't reflect sound power (to get values greater than zero I have to knock on the microphone). In the voltage divider R1 = 500 Ohm and R2 = 1000 Ohm. Is there some way to make this work correctly?

What are the output impedance of the module and the input impedance of the Wemos pin?

Wemos: < 100 Kohm (http://www.esp8266.com/viewtopic.php?p=61759#p61759). About the module I am not sure, but I have found page with more info: http://sensorkit.en.joy-it.net/index.php?title=KY-038_Microphone_sound_sensor_module . I can tell you the resistance of that potentiometer: 66.4 Kohm

source: Stack Exchange

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

sort: votes


text:
Arduino LED flashes with one button press
I want the LED to flash when I press the switch once, but it keeps flashing. I tried the idea of just lighting the LED and keeping it lit with just one button press, so I wrote:
int led=13,button=12;
void setup() {
pinMode(led,OUTPUT);
pinMode(button,INPUT);
}
void loop() {
if (digitalRead(button)==HIGH)
  digitalWrite(led,HIGH);
}

and this worked; it stayed on after I pressed the button once, so for the flashing LED I wrote:
int led=13,button=12;
void setup() {
pinMode(led,OUTPUT);
pinMode(button,INPUT);
}
void loop() {
if (digitalRead(button)==HIGH)
{
  digitalWrite(led,HIGH);
delay(1000);
 digitalWrite(led,LOW);
 delay(1000);

} }

but this didn't work. It stops flashing after I remove my hand from the switch. Why is this happening?

Welcome to EE.SE. Please edit the question and use the {} tags to format your code properly. Make sure it's indented properly too. You also need to fix capitalisation in your title and in your post for legibility and credibility. Your compiler wouldn't let you away with it. Why should we? Note that your question has no electrical design element to it so it will probably be moved to the Arduino StackExchange site.

How can it remember the switch has been operated?

exactly i dont know whats the difference between the two cases above, the first one just one press of the bush button and the led keeps on, the second case it flashes only when i keep pressing on the bush button, and stops when i remove my hand..i want it also in the second case to keep flashing after i remove my hand

That's what I am trying to do, i understand it should execute the same way what is inside if {}..but that is not happening

If you want the LED to stay on indefinitely, remove the line that sets the LED to LOW.

I re-read your question, and it makes no sense.  ... I want the LED to flash when I press the switch once, but it keeps flashing.  .. This means that you press the switch once and you expect the LED to flash (I assume that you want it to flash one time).  The LED keeps flashing without stopping, and you do not want that.  .... At the end of your question, you say that the LED stops flashing.

Why this question is so difficult, i repeated it many times, i am comparing between the two codes although they are the same structure they behave differently, i want basically know why

Because the digital writes only apply on if (digitalRead(button)==HIGH). If you don't press the button, then the code goes:
void loop() {
}

Essentially doing nothing. Your code needs a bit more to keep track of the button press. Pseudo Code:
if button == pressed {
    int tracker=1;
}
if tracker == 1 {
    led on;
    wait;
    led off;
    wait;
}
loop

Thnx, can you please explain more, i understand that it should execute what is in if {} in the same way, so why one time it kept executing after i pressed zhe button and in the another example it stopped executing what is in if {} after i pressed the button , i can send videos if someone gives me email

Try posting your new code if you have modified yours based on this answer. Don't change your original code or the question won't make any sense. Add a new part to your question (edit the question) saying you tried XYZ and showing what that was.

This is what you need. When you pressed the button then your LED turn ON. And it still ON until you pressed the button again.I hope it will help you.
const int kPinBtn = 2;
const int kPinLed = 13;

boolean kPress = false;

void setup()
{
  pinMode(kPinBtn, INPUT_PULLUP);
  pinMode(kPinLed, OUTPUT);
}

void loop()
{
  if(digitalRead(kPinBtn) == LOW && kPress == false)
  {
    digitalWrite(kPinLed, HIGH);
    kPress = true;
  }
  if(digitalRead(kPinBtn) == LOW && kPress == true)
  {
    digitalWrite(kPinLed, LOW);
    kPress = false;
  }
}

ok,thnx, i will study this code, but still  the question, why in the first code it kept executing what is inside if {} even after i removed my hand from the push button, and in the second codeit stopped executing what is in if {} after i removed my hand from frm the switch button,although the both codes have the same structure but the difference only in what inside  if {} ,i can send vids if you didnt get what i mean

@sumerfattoum Becuase you can see that here I use one flag means boolean named kPress. By default it's value is false. When you pressed the button for the first time then code check the value of kPress. If it is false then and then your LED turns ON and that time we changed the value of kPress means now it's true. Now, your LED remains ON until not pressing the second time. This happens because of the value of kPress. Now when you pressed the second time then code check again the value of kPress. If it's true then and then it turns OFF the LED.

My friend, they are two different codes, and two different cases for my codes above , i upload the code differently to Arduino ,  there is no consideration if the button is pressed for the first and second time

The case is when I upload the first code then press the push button ,it keeps applying what is in if {} ,it means it stays on although i removed my hand from the button, now when i upload the second code and press the button it applies what is in if {} (means it flashes ) only when my hand stills on the button, but it stops flashing when i remove my hand unlike the first case although they have the structure and the difference only what is inside if {}

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


text:
ATTiny85 Digispark clones failing USB handshake - how to program them?
I've recently bought a batch of ATTiny85 modules (Digispark clones) from China, and tried to write a first test program into them now. I noticed that they do seem to have some bootloader already installed since the P1 LED is flashing, but they do not seem to make any reasonable USB handshake.
(I have ordered other seemingly identical modules from a different seller on Ali before and was able to use them just fine.. so I generally know how to work with these.)
Linux dmesg shows me that a device was plugged in, but does not get any vendor or model ID. Windows tells me that 'the device last plugged in has failed enumeration'. This looks to me like the bootloader is incomplete or somehow broken.
So, as a next step, I tried to rewrite the AVR with an USBASP adapter over ISP, only to find out that the /reset pin apparently has been disabled via fuse bit.
I'm in some kind of a loop now... If the bootloader doesn't speak USB correctly, I can't use the Arduino IDE or avrdude or anything to write to it, and if the /reset is remapped I can't replace the bootloader via ISP to get USB working.
Can anyone provide a hint on how I can get these modules to work? Or should I just assume I bought a bad batch, throw them away and order fresh ones?

maybe you shouldn't order fresh ones, but not from sketchy Chinese clone manufacturers? Just a hunch, though...

maybe there is no usb firmware loaded into the devices  ... can you post the seller's device homepage?

@jsotola Their page said "arduino compatible" and the same standard feature list copied from all other vendors on AliExpress. A non-usb firmware makes little sense, since ISP needs a working /reset pin which is definitely deactivated...

"arduino compatible" may be referring to the hardware

Maybe needs install the bootloader and than try to upload the sketch.

I had problems too - SHORT: all about USB-hub or PC's root-hub and extension cables +Luck.
My ebay items were going under the name "Digispark Kickstarter ATTINY85 Arduino Micro USB Development Board" and naturally it came with no Digispark-(c)-right infringing markings from China. I kept my fingers crossed that my items would at least be AVRisp-programable..
So in high hopes I plugged in my China import into my trusty USB HUB2.0(which I always use at least as a current limiter) – after testing it first on a powerbank (>5secs blinky-blink)  .. checked for enumeration (which it did-but no driver yet) .. installed the DPinst[64].exe drivers.. and then kept getting messages like >>device failed to enumerate<<, etc. - the list of my failures:

determined directly plugged into a PC's USB root-hub rigged/minimalistic usb devices do not enumerate at all (all 0s)
with a certain USBAmale-to-USBAfemale extension cable with plastic-encasing(female side) the USBA device’s was not allowed to go "in" probably just for some millimeters to short.. the Data-lamella do not connect correct – just power's okay (blinky-blink) .. but no Windows device-recognition .. No-No!
AND reminding the FTDI black-listing dilemma I used PCs without out the drivers still – using the good old “USBview.exe” program to check on the enumeration (on all my available device the same .. previously plugged into my driver-enable PC or just into an “out of the fab”-one
idVendor:           0x16D0
idProduct:          0x0753
bcdDevice:          0x010B

so no mis-configuration of the bootloader through a >possibly mallign< Digispark clone dis-configurator (as I was thinking the FTDI schemes .. of course FTDI only did it to protect their name X-) – to stop getting accused for faulty devices coming from cheap chinese fake or clone-producers)
* EVEN tried to deinstall the Drivers with DPinst[64].exe /D .. which gave me .. Yes .. yet again “Drivers all installed properly!”..
.. and IN THE END .. I just went back to my old, initial “USB HUB-behind root-hub” configuration .. and Abra-ca-Zang .. the device just enumerated and registered as “Digispark Bootloader” (windows device manager under libusb-win32 Usb Devices)
and all went okay - reprogramming with the Arduino IDE - NO FUZZ!
.. The !very same! config I was using on my “first testings” (minus some fair time and headaches of debugging)
So my advice .. always do a Basic-Test on a USB Powerbank, USE an USB-Hub, check your cables - use ones you trusted before! – try as many options as you (may) have .. and use the tools at your hand .. down to PC-progs or an logic-analyzer or an Beagle USB / protocol analyer to check where the problem may be.. trace back your tracks and even retry..
There may be a suprise for you at the end of the rainbow!

Using Arduino IDE 1.8, I had a Windows did not recognize USB Device message.
I successfully installed the DigiSpark drivers but still the PC was not recognizing the Tiny85 development board. In the Arduino IDE I had  initially selected the DigiSpark (16.5 MHz default) as instructed in a YouTube video. I did some more research,  someone suggested trying a different board. I selected the DigiSpark (No USB 16 MHz) uploaded the Blink example.
The LED started to flash and windows stopped complaining about the unrecognized device. I removed the flashed board and plugged in another, Windows started complaining, I uploaded the sketch successfully windows stopped complaining. I removed the second board and installed the first one and there were no further issues with Windows.

What YouTube video, do you have a link?

Bootloader is poorly programmers it hand overs the overall hardware to user code,many people encounter error when uploading sketch second time.
Well i have solution though it may sound wears but it works for sure
"1.Disconnect board from USB ,
2.Hit upload button.,
3.Timout timer starts for 60 seconds.
4. Go ahead plug board to USB
5. CONGRATULATIONS"
thank me it will work...

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


text:
GUI interface with microcontroller to control a device through SPI
I am trying to develop a GUI to control a device hooked up on the Arduino. The Arduino communicates with the device through SPI. I have developed a GUI on MATLAB to visualize read by the Arduino. For this, I made Arduino write data from the MISO line to the serial port and MATLAB would read from the same port and do its magic. However, I am trying to come up with a method to write to the MOSI line using the GUI.
Right now I am thinking of making Arduino listen for a particular code (like a character) on the serial port and once it sees it, it will look for an x number of succeeding bytes. The bytes will be formatted in a particular way so that Arduino can then parse it and write to the appropriate registers.
Is there a better way to do this? As a generic question, what's a good way to write to a device hooked onto a microcontroller using I2C or SPI through a GUI?

the GUI should be separate from the communication. develop the communication part first. once that works, add the GUI code.

You can bypass the Arduino entirely, if you want to make this more efficient. https://www.adafruit.com/product/2264 EDIT: I just realized how old this is. What are the chances OP needs this anymore?

@Tri Thanks for the recent reply. I decided to make the GUI write a configuration file to the serial port and have the Arduino code parse through the same before communicating with the device on SPI. Thank you for the FT232 link though. That will be helpful in the future

Perhaps we need clarification / definition of "GUI" by the original poster, hence stop mixing "graphical user interface" with "device interface".

I grappled with the same question for a while. Here is how I solved the issue.
1- Find a suitable exchange format and protocol
Here you need to decide what is the most important thing on the communication. Is it speed? Is it error detection? Is it memory footprint? For my project, for instance, I decided that I need my communication to be as error free as possible, with minimal memory footprint (up to 64 bytes) and I don't really care about speed, so I gone for a JSON messaging protocol where the desktop application send a short (up to 64 characters) JSON message and receives a short answer. This solved MY problem, your requirements might be different. If you need speed and don't care for memory, for instance, you can use a binary protocol with a header specifing size, the message and a CRC footer to check vailidity. Or you can use BSON and take this library to avoid the hassle.
2- Define the Serial Polling Cycle
How will the arduino firmware knows it is time to send or receive messages? It is always talking? Always ready to receive? It looks at the serial port buffer once each few microsseconds to know if there is an incomming message? How that is handled by your device? If you just need to output data without bothering whether there is someone listening or not, like an GPS device, just throw a Serial.print now and then, but if you need to wait for data, you will have to compartimentalize the process inside an FSM or using some kind of scheduler. If you are not using a scheduler, I recommend this one.
3- Define the Communication Cycle
Here you will take the data from serial port and storing it on a buffer for later usage.
The trick here is
1- Check the serial FIFO for incomming data. Serial.available() does it already.
2- If there is incomming data, copy the data to next available space in the buffer.
3- Check if there is more incomming data after a few millisseconds.
4- If there is no incomming data, mark the buffer as ready to use, and parse it.
The following code is unscheduled for simplicity,and I recommend you to replace the sleep() calls to proper scheduling least you want the arduino go unresponsive. It is also waiting text data, so you will need to make changes if you are waiting binary data.
  char buffer[64];
  memset(buffer, 0, 64);

  while (!Serial.available())
    delay(50);

  while (Serial.available()){
    Serial.readBytes(buffer + strlen(buffer), Serial.available());
    delay(50);
  }
  parseBuffer(buffer);

SPI is a synchronized interface, it has master and slave. Either you need to switch between slave and master, or you need to provide a way to let Arduino start "reading" from the other end, since the one who initiates the communication in SPI or I2C is a master, in your case, Arduino, I suppose. The simplest way to do this is to provide another line via gpio. As for generic question, to do two-way communication properly, you probably want to choose asynchronous protocol like UART.

Does that mean that devices on I2C or SPI cannot be using a GUI; a GUI not running on the microcontroller?

@MathewsJohn: you don't directly control the SPI or I2C busses from a PC/Matlab, you have an abstraction layer between the two.

I had a similar requirement and came up with Wirekite. It is a complete solution based on a Teensy board, some code for it plus libraries for Mac or PC.
With Wirekite, you can hook up digital and analog inputs and outputs, I2C devices and SPI devices (very soon) to the Teensy board and connect the Teensy board via USB to your Mac or PC. You can then control the I/Os, I2C and SPI buses from you Mac or PC. You don't need to adapt the code on the Teensy.
Wirekite uses a custom protocol for the communication. But you don't need to care about that because you can simply use the far more convenient API provided by the Wirekite libraries (.NET for Windows, Objective-C/Swift for MacOS).

Ya I guess that's one way of doing it. MATLAB can already do this. There's a hardware package that I can use for the same. I think this is a good alternative. Will look into it.

If you want to communicate from the computer to the arduino, use USART. Arduino already has this pre-programmed, as well it's own GUI.


text:
Using a keypad to play an audio file on Arduino Mega and Adafruit VS1053?
I am trying to use a keypad to trigger an audio file using an Arduino Mega and Adafruit VS1053 Music Maker. I have gotten the music files to play independently, and when the correct number is entered into the keypad a red LED flashes to green, but I have no idea how to make the music file play as a result of my combination.
What works is that the music file plays, but the problem is that it plays automatically and not upon a combination input.
I have tried putting musicPlayer.playfullfile("track002.mp3") in the loop with an if statement, and when I press the keypad the serial reader tells me it is playing the music file, but nothing is actually playing :
char key = keypad.getKey();
if (key) {
    Serial.println(key);
    if (key =='9') {
        playMusic("track001.mp3");
    }
}

I've done experiments with playmusic outside of the loop and it works fine and finds the file no problem. So the problem occurs when I try and put it into the loop as part of a keypad combination, it returns immediately without playing.
This is from the Serial reader

Playing music file 9
  Playing music file 9
  Playing music file 9
  Playing music file

Any help would be tremendously appreciated.
My full code is below:
#include <Keypad.h>
#include <SD.h>
#define SD_ChipSelectPin 53
#include <SPI.h>
#include <Adafruit_VS1053.h>

String password = "123";
String answer = "";
int position = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = { 51, 49, 47, 53 };
byte colPins[COLS] = { 45, 43, 41, 39 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS,
COLS );
int R = 27; // 3rd yellow wire in GROUND
int G = 29;

// define the pins used
//#define CLK 13       // SPI Clock, shared with SD card
//#define MISO 12      // Input data, from VS1053/SD card
//#define MOSI 11      // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins.
// See http://arduino.cc/en/Reference/SPI "Connections"

// These are the pins used for the breakout example
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin
(output)
// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin
(output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see
http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer =
  // create breakout-example object!
  //Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS,
BREAKOUT_DCS,
DREQ, CARDCS);
// create shield-example object!
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

void setup() {
  if (! musicPlayer.begin()) {
    // initialise the music player
    Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
    while (1);
  }
  Serial.println(F("VS1053 found"));
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
    // Set volume for left, right channels. lower numbers == louder volume!
    musicPlayer.setVolume(20,20);
    pinMode(R, OUTPUT);
    pinMode(G, OUTPUT);
  }
  musicPlayer.playFullFile("track003.mp3");
}

void loop() {
  char key = keypad.getKey(); // init. variable key keypad is non blocking
  while(key == NO_KEY) {
    // we got no key press? -> do again
    key = keypad.getKey();
    delay(100);
  }
  answer.concat(key); //add key to answer
  if(answer.equals(password)) {
    //password OK
    musicPlayer.playFullFile("track002.mp3");
    Serial.println(F("Playing track 001"));
    LockedPosition(false);
    answer="";
  } else {
    LockedPosition(true);
  }
  if (answer.length() > password.length()) {
    // answer is different and bigger than password
    // can't become the right answer
    answer = "";
  }
  if (key == '*' || key == '#') {
    LockedPosition(true);
    answer="";
  }
}

void LockedPosition(int locked) {
  if (locked) {
    digitalWrite(R, HIGH);
    digitalWrite(G, LOW);
  } else {
    digitalWrite(R, LOW);
    digitalWrite(G, HIGH);
    delay(10000);
    digitalWrite(G,LOW);
  }
}

Hey @josecanuc, that part is from a previous code attempt to show what I've tried so far. What I was trying to do with that attempt was get the audio to play when I press '9' using the code below. The serial reader read Playing Music File, but did not actually play anything:  char key = keypad.getKey();
if (key) {
Serial.println(key);
if (key =='9') {
playMusic("track001.mp3");
}
}

I've narrowed down the circumstances where this happens. I put "SD.exists("file")" at the top of the loop and it consistently returns true until the first time the keypad is used. From that point on it returns false, which explains why the musicPlayer doesn't play it. It just can't find it. Any thoughts how how the keypad could be interfering with SD?

The sketch has a pins conflict.
SD card is on SPI bus. SPI pins on Arduino Mega are pins 50, 51, 52 and 53. These pins are available on the ICSP/SPI header too. Mega compatible shields use the SPI pins on the ICSP header. Pin 53 must be set as output if the Mega is SPI master and is usual to use it as CS pin for a slave.
According to sketch the SD CS pin is 53.
According to sketch the keypad uses pins 51 and 53. 51 is SPI pin used by the shield and pin 53 is CS pin for SD card.


text:
Measuring frequency of 3-wire 12V fan on Arduino Uno
I am using a PC 12V fan (40x40mm), which I control speed with voltage (with adjustable power supply). I would like to measure the frequency of the fan with Arduino and read it on serial monitor.
I've googled over some results and I came across pulseIn(), which I don't quite understand. I've also used this code, which I found here, but it doesn't work for me. I've added serial.print and delay line.
My output of this program is: "0000000" etc. and nothing else.
My goal is to set the frequency of the fan to around 50-500 Hz somewhere.
int pin = 7;
unsigned long duration;

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

void loop()
{
  duration = pulseIn(pin, HIGH);
  Serial.print(duration);
  delay(1);
}

My schematics:

Edited. I hope it helps. I power supply arduino through USB cable from PC and instead of battery I just use variable bench power supply.

Thanks. Try changing pinMode(pin, INPUT); to pinMode(pin, INPUT_PULLUP); and tell us what happens. If it works, I'll write an answer explaining why.

@MarkSmith: Yes and no. But this is a step further for sure.
Yes: I do get values from arduino, but not some kind of useful.
No: As I raise the voltage (and raise the turning speed) the lower values I get by reading the input. At about 4.85V I got the value of 2800, but at voltage 2.48V I get value of 5740 (about). How can I get RPMs from this?

You should not connect the ground wire to the other side of the potentiometer! That will just waste energy.

The pulseIn measures the duration of a high pulse on the pin.  The reference page explains it as well as I ever could.  If there is a specific thing you don't understand from it, please ask.  However, I don't think it will achieve what you want.
The circuitry in the fan connects the third (yellow?) wire to ground twice per revolution of the fan.  To make this into a "pulse" you need to pull the pin high.  Twice per revolution, the fan will pull it low.
What you now have is a signal which, for every revolution of the fan, goes HIGH, LOW, HIGH, LOW.  We want to measure the time from one rising edge to the next.  This is the time for half a rotation of the fan.
Here's some untested code:
// Wait for signal to go low
while (HIGH==digitalRead(pin)) { /* Do nothing */ }

// Start timing
unsigned long start_time = micros();

// Wait for signal to go high and low again
while (LOW==digitalRead(pin)) { /* Do nothing */ }
while (HIGH==digitalRead(pin)) { /* Do nothing */ }

// Stop timing
unsigned long end_time = micros();

// How long did that take?
unsigned long duration  = end_time - start_time;

That code can be improved in various ways but I hope it will let you understand what's going on.
That tells us how LONG half a cycle takes.  You can easily find how long a whole cycle would take -- double it.  If you want the frequency in revolutions-per-minute, you need to work out how many whole cycles you can get in a minute, which is the same as the number of half-cycles in half a minute:
unsigned long rpm = 30000000L / duration;


text:
Reading input from digital pins 36, 37, 38 in Arduino Mega 2560 is giving a problem
I wrote a program to read digital input from pins 36, 37, 38 and print on LCD when they go HIGH.
I've connected those pins to a switch to test.
The program looks like this:
#include "LiquidCrystal.h"

// initialize the library by providing the nuber of pins to it
LiquidCrystal lcd(8,9,4,5,6,7);
int vswr,th,od,a;

void setup() {
  pinMode(36,INPUT);//SENSING VSWR
  pinMode(37,INPUT);//SENSING THERMAL
  pinMode(38,INPUT);//SENSING OVER DRIVE
  pinMode(35,OUTPUT);//BYTE_CTRL SIGNAL TO SHUTDOWN
  digitalWrite(35,LOW);
}

void loop() {
  vswr = digitalRead(36);
  th= digitalRead(37);
  od = digitalRead(38);
  lcd.begin(16,2);
  // set cursor position to start of first line on the LCD
  lcd.setCursor(0,0);
  if (vswr==1) {
    lcd.write("vswr");
    digitalWrite(35,HIGH);
    delay(2000);
  }
  if (th==1) {
    lcd.write("thermal");
    digitalWrite(35,HIGH);
    delay(2000);
  }
  if (od==1) {
    lcd.write("over drive");
    digitalWrite(35,HIGH);
    delay(2000);
  }
}

When I run this, the LCD continuously  displays:**

vswrthermaloverdrive

Even though none of the pins are high.
When I use Pins 11, 12, 13 instead of 36, 37, 38 it works fine. I already used pins 11,12,13 for some other purpose. Why is this happening? And how do I solve this problem?

Please edit your question to specify what you have connected to the input pins.

The pin needs to be pulled high or pulled low. Either with a pullup or pulldown resistor or a switch. When a input pin is not connected to something, the digitalRead can return HIGH or LOW, it can be anything. The digital pins 11, 12, 13, 36, 37, 38 are all the same: http://www.pighixxx.com/test/portfolio-items/mega/

I expect the problem is in the circuit. To be sure, put a serial print statement directly after reading the inputs, to be sure the input values are read correctly.
See the remark of using INPUT or INPUT_PULLUP from Jot below.
The following is just a more compact way of writing your loop (and does not fix your problem):
void process(int pin, char* text)
{
    if (digitalRead(pin) == HIGH) // Use HIGH instead of 1
    {
       lcd.write(text);
       digitalWrite(35, HIGH);
       delay(2000);
    }
}

void loop()
{
    lcd.begin(16,2);
    // set cursor position to start of first line on the LCD
    lcd.setCursor(0,0);

    process(36, "vswr");
    process(37, "thermal");
    process(38, "overdrive");
}

Also, I would add the delay at the end (after the three calls of process).
And instead of hard coded values 36, 37 and 38 use 3 constants/defines.

He never write LOW on pin 35 ...

I will add it in the answer .. THAT will be the fix high likely

@Michel Keijzers: thanks for simplifying the program. I'm new to programming. Anyways I want to know why those input are not sensed properly.

@MichelKeijzers, don't write an input LOW. That was used many years ago for the internal pullup resistor, but now the INPUT is specifically a INPUT without a pullup resistor, and INPUT_PULLUP is with internal pullup resistor. Do you have a reference to that wrong use of writing LOW an input? You also can't reduce a pin as OUTPUT in a loop and make it INPUT.

@Jjot ... you are completely right ... I will change it according to your remark.

@Jot  So, using internal PULLUP can solve my problem?

I just found out that by pulling down my inputs i'm not getting the output like i have show in the question. is it possible to pull down internally?

Not that I know off, there is more info at https://www.arduino.cc/en/Tutorial/DigitalPins

@MichelKeijzers : pull down resistor solved my problem.

Another thing, only pin == HIGH writes something to the LCD, the message does not magically go away when pin == LOW
Also, about the logic for pin 35, what should happen when alarm goes away?
Maybe pin 35 should be low again?
Code suggestion:
void process(int pin, char* text)
{
    if (digitalRead(pin) == HIGH) // Use HIGH instead of 1
    {
       lcd.write(text);
       digitalWrite(35, HIGH);
    }
    else
    {
       lcd.write("      ");
    }
}

pin 35 should be low when alarm goes away and I tried your code. I still need to use pull down


text:
Multiple I2C devices on Arduino
I'm design a custom PCB based around the Arduino Zero/Adafruit Feather M0. The plan is to use a few I2C devices. I just had a few questions about whether I've designed the board correctly.
You'll see that I've used 10k resistors on each devices's SDA and SCL lines, but is this necessary? I've seen it mentioned on a few online documents for certain breakout boards etc...
Also, are the devices just connected in parallel? Are there any considerations I need to make when using 3 I2C devices like this?

You'll see that I've used 10k resistors on each devices's SDA and SCL lines, but is this necessary? I've seen it mentioned on a few online documents for certain breakout boards etc...

You should have just two 3.3K resistors - one on the SDA and one on the SCL lines.  However all your 10K resistors in parallel will equate to about the same thing - just taking up 3x the space.

Also, are the devices just connected in parallel?

Yes, it's a simple multi-drop bus.

Are there any considerations I need to make when using 3 I2C devices like this?

Not really, no.  The frequencies in use are generally too low to require any specific layout considerations. Just try to keep vias to a minimum and don't snake the traces around the board too far.

Where does the value of 3.3K come from? I've seen 10k total suggested and also 4.7k. Will the bus capacitance make a difference?

2.2-4.7k is the recommended range for I2C. It is above the minimum for the voltage the Arduino works at, and low enough as to keep the rise times well below the thresholds for "normal" (<200pF) bus capacitances.  Chapter 7 of this document by NXP gives you all the technical blurb and formulae. There's even some nice graphs. You can see from those that 10k is kind of on the knee of the graph - too high really to be properly in spec - and the 30k+ of the internal pullups on the Arduino that everyone seems to use are way way out.


text:
How can I write an integer to a Mifare RFID card using the RFID library?
I'm a beginner to C++ and I'm clearly missing some fundamental knowledge of data types. As such, I'm struggling to adapt the examples in the miguelbalboa/rfid library to my use case. I'm simply trying to write an integer to a 13.56Mhz RFID tag. Ideally I'd like to optimize the data so as to be quick to read (it seems fully reading these cards can take a while and I'd like to read the integer, an ID, as quickly as possible).
So on to my actual questions... what is the data type shown in this block of example code (shown below) and how can I turn an integer into the same data type? Finally, how should I read this saved value back into the familiar integer data type?
byte dataBlock[]    = {
    0x01, 0x02, 0x03, 0x04, //  1,  2,   3,  4,
    0x05, 0x06, 0x07, 0x08, //  5,  6,   7,  8,
    0x09, 0x0a, 0xff, 0x0b, //  9, 10, 255, 11,
    0x0c, 0x0d, 0x0e, 0x0f  // 12, 13, 14, 15
};

really important info that you failed to mention ... what is the model of the device that you are using?

The dataBlock[] variable is an array of bytes. One byte can represent an integer ranging from -128 to 127, or a positive integer ranging from 0 to 255. If your integer value will always be in one of those ranges, then you can just put your integer in the first element of the array and zero out the remaining.
byte dataBlock[]    = {
    0x01, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00
};

(That saves a value of 1 to the first element, and zeros to the rest. If you want to change the first element:
dataBlock[0] = yourValue;

If your integer is a 2-byte integer, as is typically found in Arduino with type int, you need to split your value into the high byte and low byte:
dataBlock[0] = (byte)(yourValue & 0xFF); // Low byte
dataBlock[1] = (byte)(yourValue >> 8);   // High byte

Then you write the data block as per the example. To get your 2-byte integer value back:
yourValue = ((int)dataBlock[1])<<8 | dataBlock[0];  // Shift high byte, OR with low byte.

Well, the example is using the MIFARE_Write and MIFARE_Read functions. These functions, as explained in the library, accept at least 16 bytes, so the 16-bytes buffer is the smallest you can read/write. Consequently I suggest you, if you don't have any additional data, to use 16-bytes IDs (you get a much wider code space).
If you strictly want to use 2 or 4-bytes integers, the first solution which comes to my mind is jose's one, so manually split the int in two (or the long in four) bytes and store them in the array. For instance
// Big endian format
dataBlock[idx]   = (byte)(intValue >> 8); // Byte 1
dataBlock[idx+1] = (byte)(intValue);      // Byte 0
// or
dataBlock[idx]   = (byte)(longValue >> 24); // Byte 3
dataBlock[idx+1] = (byte)(longValue >> 16); // Byte 2
dataBlock[idx+2] = (byte)(longValue >> 8);  // Byte 1
dataBlock[idx+3] = (byte)(longValue);       // Byte 0

// Little endian format
dataBlock[idx]   = (byte)(intValue);      // Byte 0
dataBlock[idx+1] = (byte)(intValue >> 8); // Byte 1
// or
dataBlock[idx]   = (byte)(longValue);       // Byte 0
dataBlock[idx+1] = (byte)(longValue >> 8);  // Byte 1
dataBlock[idx+2] = (byte)(longValue >> 16); // Byte 2
dataBlock[idx+3] = (byte)(longValue >> 24); // Byte 3

NOTE: idx can be any value; the easiest approach is to put the int at the beginning (so substitute idx with 0)
This is the safest way to handle this, since the endianness is explicit. You can, however, trust the compiler and use its implicit handling of multi-byte variables in this way:
*((int*)(&datablock[idx])) = intValue;
// or
*((long*)(&datablock[idx])) = longValue;

You take the cell where you want to put the beginning of the data, get its pointer, cast it to the pointer type you need, then write inside that pointer the value you want. Please note, however, that cells idx and idx+1 in the case of an int, or idx to idx+3 for long, will be written. If your array ends, you will pollute the memory in unpredictible ways (just like if you write dataBlock[18] = something when dataBlock has 16 cells).
Note you cannot control the endianness of the byte array, but if you always use the same device to read and write you should not worry. FYI, at present the compiler used by Arduino IDE is little endian.
Note also that, for idx = 0, (&datablock[idx]) can be simplified in (datablock).
To read back the data, you have the following ways
// Big endian format
intValue = (((int)dataBlock[idx]) << 8) | dataBlock[idx+1];
// or
longValue = (((long)dataBlock[idx]) << 24) | (((long)dataBlock[idx+1]) << 16) | (((long)dataBlock[idx+2]) << 8) | dataBlock[idx+3];

// Little endian format
intValue = (((int)dataBlock[idx+1]) << 8) | dataBlock[idx];
// or
longValue = (((long)dataBlock[idx+3]) << 24) | (((long)dataBlock[idx+2]) << 16) | (((long)dataBlock[idx+1]) << 8) | dataBlock[idx];

Or, in the last case,
intValue = *((int*)(&datablock[idx]));
// or
longValue = *((long*)(&datablock[idx]));


text:
Can I code in Arduino depending up on LED status?
I have to count the blinkings of an LED. For that
IF (LED = ON)
{
    COUNT=COUNT++
}
Else
{
}

Can I code like this algorithm? In Arduino is it possible?

Instead of controling led through arduino ,can we code in  arduino to read the led status as input???? Like the above theme???

In C (the language used to program Arduinos) tests require two equal signs.  Using one equal sign will assign the variable on the left side of the equal sign the value on the right side of the equal sign.  Also, when incrementing a variable you only need the two plus signs following the variable.  So "COUNT=COUNT++" should likely be "COUNT++".

if( digitalRead(ledPin)==HIGH )...?

it is a duplicate ... posted by the same person ... evidently the OP asks questions, but does not read the answers

Yes, you can make an arduino detect and count LED blinking. You will need some kind of light sensor, such as a photodiode or photoresistor.
Also, you would need to code in C++, and the example pseudo-code you presented is not C or C++.
As you proceed with your project, you may ask more questions here, of a more specific nature. As it stands, your question is very broad.

Oh really thanks sir... Can I simply connect the led to digital pins of arduino ??

You have already asked that before.

@rajiravi You will have to work out what the circuit is you are connecting to before you can know if it is possible to connect to it. Suffice it to say, probably no, you cannot connect directly to it. Someone with more knowledge probably can, but if you are asking, the answer is going to be no. Especially if it involves dismantling power company owned and installed and certified equipment.


text:
Arduino Code hang
I am working on a project to dim/brighten the LED lights between each hour. To make the program readable i have only kept the code for few hours.
For example if T1 is at 255 PWM and T2 is 20 PWM, the code calculates the moves required to dim the LED by One PWM every few second such that by T2 the PWM is at 20.
I have Included DS1307 RTC for keeping track of time, further i have used a HC-05 Bluetooth module to communicate with the Arduino, using Android phone, so that i can change the PWM values between T1 and T2.
When i run the code it works perfectly for some time post which it freezes, and the LED starts flickering.
#include <Wire.h>
#include "RTClib.h"
String fromAndroid;
////////RTC
int h = 0;
int m = 0;

int hours;
unsigned long interval = 1000;

////////////Millis
unsigned long currentMillis;
unsigned long White_previousMillis;
unsigned long previousMillis;//for clock
unsigned long Hr_interval = 3600000;
unsigned long white_each_interval;

int pwm02 = 2;
int pwm03 = 3;
int pwm04 = 4;
int pwm05 = 5;
int pwm06 = 6;
int pwm07 = 7;

/////////////////Peak Keeper
int white_t24 = 10;
int white_t1 = 233;
int white_t2 = 18;
int white_t3 = 189;
int white_t4 = 12;
int white_t5 = 255;
int white_t6 = 19;
int white_t7 = 199;
int white_t8 = 2;
int white_t9 = 177;
int white_t10 = 2;
int white_t11 = 245;
int white_t12 = 12;
int white_t13 = 252;
int white_t14 = 0;
int white_t15 = 255;
int white_t16 = 50;
int white_t17 = 239;
int white_t18 = 20;
int white_t19 = 253;
int white_t20 = 1;
int white_t21 = 252;
int white_t22 = 2;
int white_t23 = 255;

/////Secondary time
int white_Secondary;

int white_steps; //new

int white_move; //New

RTC_DS1307 rtc;
void setup() {
  Serial.begin(9600);
  rtc.begin();
  if (! rtc.begin())
  {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (! rtc.isrunning())
  {
    Serial.println("RTC is NOT running!");
  }
  Serial.println("Start");
  //  rtc.adjust(DateTime(2017,12,17,11,52,00));
  pinMode(pwm02, OUTPUT);
}

void loop() {
  while (Serial.available() == 0)
  {
    DateTime now = rtc.now();
    currentMillis = millis();
    hours = now.hour();
    if (currentMillis - previousMillis >= interval)
    {
      Serial.print(now.year(), DEC);
      Serial.print('/');
      Serial.print(now.month(), DEC);
      Serial.print('/');
      Serial.print(now.day(), DEC);
      Serial.print(" (");
      Serial.print(now.hour(), DEC);
      Serial.print(':');
      Serial.print(now.minute(), DEC);
      Serial.print(':');
      Serial.print(now.second(), DEC);
      Serial.println(')');
      previousMillis = currentMillis;
    }

    if (hours == 12)
    {
      if(now.minute()==00 && now.second()<=1)
      {
        white_Secondary = white_t24;
        analogWrite(pwm02, white_Secondary);
      }
      white_steps = white_t1 - white_t24;
      if (white_steps == 0)
      {
        white_move = 0;
        white_each_interval = 1800000;
      }
      if (white_steps < 0)
      {
        white_move = -1;
      }
      else
      {
        white_move = 1;
      }
      if (white_steps != 0)
      {
        white_each_interval = Hr_interval / abs(white_steps);
      }
    }

    if (currentMillis - White_previousMillis >= white_each_interval)
    {
      white_Secondary = white_Secondary + white_move;
      analogWrite(pwm02, white_Secondary);
      Serial.print("PWM02: "); Serial.println(white_Secondary);

      White_previousMillis = currentMillis;
    }
  }

  while (Serial.available() > 0)
  {
    Serial.println("In Input Loop");
    fromAndroid = Serial.readString();
    if (fromAndroid.startsWith("White"))
    {
      fromAndroid.replace("White", "");

      if (fromAndroid.startsWith("time18"))
      {
        fromAndroid.replace("time18", "");
        white_t18 = fromAndroid.toInt();
        Serial.print("white_t18 VALUE: ");
        Serial.println(fromAndroid);
      }
      if (fromAndroid.startsWith("time19"))
      {
        fromAndroid.replace("time19", "");
        white_t19 = fromAndroid.toInt();
        Serial.print("white_t19 VALUE: ");
        Serial.println(fromAndroid);
      }
      if (fromAndroid.startsWith("time20"))
      {
        fromAndroid.replace("time20", "");
        white_t20 = fromAndroid.toInt();
        Serial.print("white_t20 VALUE: ");
        Serial.println(fromAndroid);
      }
    }
  }
}

Your code has several println() statements for debugging. What's the last line printed, and does it always fail after that particular line?

what does this mean? To make the program readable i have only kept the code for few hours.

@ jose, ihad kep lot of print statements to find when the code sops, but unfortunately the code doesn't stop at fixed point, it stops at random.

@jsotola, I had made the program for 24 hours, which had 24 sub If statements, which would be hard to read in a post hence limited the code for couple of hours.

i think that you only posted code to one hour. please post code for three hours. there may be a way to simplify the code.


text:
Can 2 or more LED strobe Lights Flash in Sync?
I'm trying to build a strobe light that has at least 1 mode that can sync with another unit.
The strobe light has 2 colors, white and red which are driven by 2 qlite drivers which are controlled by an ATtiny13a processor.
The strobe light will be used on an ultralight aircraft. I want the ability to have the lights sync, so if there are a few aircraft flying, each strobe would be in sync and creating a better chance of being seen as a collective.
The easiest way to see this is from obstruction lights on windfarms. https://www.youtube.com/watch?v=bb7MWrBEZjU  They are mandated by FAA to be in sync. I believe they achieve this by matching internal processor clock speeds with the GPS clock data.
Or could I use a Real Time Clock to time the processors together?
If I'm already using Qlite flashlight drivers which use ATtiny13 chips, is there any way I can get the different lights to sync?
The body is a standard flashlight body.

Thanks in advance,

Using the 1PPS output of a GPS receiver seems to be the easiest way, just make sure to use an integral flash frequency.

Thank you! So would the GPS module interface my existing ATtiny13 processor via the 1PPS or would I need something else? Forgive my ignorance. Does the strobe pattern need to be simple flashes or would it be possible to sync any flashing pattern? Thanks again for your comment

Depends on whether the GPS modules need live interaction or if they can be preprogrammed to find satellites and output the signal. Any pattern, integral frequency.

Ah gotcha, so I'll need one that can connect automatically and send the pulse.

Something like this https://www.sparkfun.com/products/14239

"The S1315F performs all the necessary system initialization, satellite signal acquisition & tracking, data demodulation, and calculation of navigation solution autonomously." Sounds like it should do.


text:
16*2 1602A LCD not displaying any character or contrast, although correct wiring
I've used my LCD display with a lot of small projects. Now it doesn't work anymore. Most of the diagrams you find online use resistors and potentiometers. However I never done that, but still got it to work nonetheless.
I tried different schematics, but none of them seem to work. So I'm thinking I broke my LCD somehow.
I'm pretty sure the schematic I'm currently using works. The backlight works but nothing is being printed.
Pictures of the project (Warning!! wire hell)
The LCD component is a blue 16x2 1602A v2.0 display.
All the components come from the official Arduino starter kit, except for the wires. Though I tested every single wire for continuity, to make absolutely sure the problem was not within the wires themselves.
Also, turning the potentiometer doesn't show any blocks, or change anything on the LCD as expected.
Code:
#include <LiquidCrystal.h>
//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  pinMode(6,OUTPUT);
  analogWrite(6,90); //sweetspot for backlight without using a potentiometer.

  lcd.begin(16, 2);
  //lcd.setCursor(0,0);
  lcd.print("hello, world!");
}

void loop() {
}

I'm not sure what's wrong, I tested everything I can think off.
I can upload more (cleaner) pictures if requested, I just didn't want to tear down my other project.

Contrast? Adjust the contrast pot until something (even a black box) is displayed.

What do you mean? I said that turning the potentiometer doesn't change anything to the display.

Two things: bright and contrast. You are controlling bright. For contrast, the old LCD that comes with the Start Kit (mine, at least), use pin 3 (V0) to control contrast. You can add a pot there. Newer I2C versions comes a pot to the same effect.

Look at the schematic I posted, this is exactly what I'm doing, the potentiometer is connected to the 3rd pin on the display (V0). The brightness is being controlled by PWM on pin 6, value 90 gives it  just enough backlight for things to be readable. I've always used it like this.

You posted not a schematic but a drawing of you circuit. A schematic show clearly how things are connected (pin number/name). A schematic doesn't include a graphic representation of the parts involved; all of them are represented by symbols. Goal is to communicate information in a precise, complete and concise way.

Ok so the problem were the wires.
Although I tested every single wire for continuity I went to the store and bought a brand new (expensive/not-from-aliexpress) pack of jumper wires. I rewired the entire project with the schematic and code that was posted in my question-post and it worked like a charm..
So I'm not sure what exactly caused the problem, but it was in the wire. I thought having continuity in a wire is like a 100% proof that the wire works properly. Maybe someone has an idea what could cause this?
So again, I only replaced the wires, not the schematic nor the code, with brand new ones and it worked perfectly.

I have an suggestion.  Try removing the comment from this line:  //lcd.setCursor(0,0);
You need to be sure your text is displaying on the first line, first position(0,0).

The LCD is working perfectly fine (hardware side).
Only 2 changes require in your code.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  pinMode(6,OUTPUT);
  analogWrite(6,90); //sweetspot for backlight without using a potentiometer.

  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("hello, world!");
  delay(3000);
}

void loop() {
}

Added delay (it must!) and set the cursor position.
Try above code and let inform.

Adding delay or change the cursor position did not change anything. I don't even think it is necessary. Cursor position is by default on (0,0).

(This is a duplicate).
I solved it following this:

The contrast can be adjusted by the potential-meter displayed in the following picture.

credit


text:
Using a Micro SD card for data logging, bad idea? Reliable?
I'm planning a project that will read data from an I/O board.
The micro SD card would hold data for input bit identity, labeling ?, then logging after events end.
Nothing would be written to or read from the micro sd, unless an event takes place, usually 2-10 events/hour. System will run 24/7 for years, hopefully.
Is a micro sd card the best way?  Is it reliable enough?

We've been maintaining a network of loggers (60+ currently deployed) using SD card connected directly to the SPI pins (see: http://www.mdpi.com/1424-8220/18/2/530 for details) and our experience is that the SD cards are really reliable provided you don't have a brown-out when they are writing, even when we abuse them with hot surface deployments in the tropical sun. And we buy them used, (since the older, smaller Nokia & Sandisk cards have lower sleep currents) but test them well with H2testw.
 However there is one problem that develops over time: the actual SD adapters are not made that well, and tend to have solder flux residue left on the little pads used to hold the contact springs, and these will corrode over time if moisture gets in. I give everything a sonic bath in 90% isopropyl until the parts are squeaky clean, and then always put 2x10gram desiccant packs into the logger housings (with color indicator beads). If you are careful about the cleaning, the contacts last for years, but if you forget, and moisture gets into the housing, then the SD card contact spring solder points are often the first things to corrode.

As far as durability concern, SD cards are quite durable.
8-10 years data storage and operations would be OKAY. In a practical scenario, average time is about to 5-6 years.
Just you have to keep some important and necessary instructions/cautions keep in mind while dealing with SD card and for its long life.
Importantly, use standard standard manufacture SD card (suggestion - Swissbit)

Don't store them below -40 °C or above +70 °C
Don't pressurized

Here are a few links, which may help you.
https://superuser.com/questions/17350/whats-the-life-expectancy-of-an-sd-card
SD cards generally have wear leveling (https://en.wikipedia.org/wiki/Wear_leveling)
Hope, this will helpful.

My concern wasn't so much the age, but read/write frequency and quantity.
And the mean time between failure.  I've read a bit in years past that lots of long-term read/writes are not the best use of SD/Micro SD cards.  I'm hoping the technology has improved.


text:
Lost AT+ commands on ESP8266 after flashing with "blink" sketch
I set my ESP8266 ESP-01 to flash mode and uploaded the example blink sketch on the arduino IDE esp example options. I know can no longer communicate with the ESP8266 using AT+ commands. I also cannot flash the device and can only receive the following message under baud 74880
"
 ets Jan  8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x0f
csum 0x0f
~ld
"
Anyone know how to fix this? Thanks.

Thank you Juraj!
I had attempted to update the firmware multiple times and after 6hrs of trying was giving up. I really thought I had trashed my ESP-01. My post here was my last attempt to resolve the issue. I tend to have a problem of not asking for help until I'm frustrated. I saw your comment, and even though I had already attempted to reflash with new firmware I realized that you knew something I did not, and hopefully I could still salvage the ESP-01. So I downloaded documents about the esp8266 and decided to give it another try. What I found is my ignorance had let me believe that the esp-01 was broken when it was functioning as it should. Anytime you upload new firmware it will replace the old (including the at commands, but that's what it suppose to do). I then found this page that brought to my attention the mistake I was making. I was flashing the files to the wrong address, and there are multiple locations where the "blank" file needs to be flashed to.     So all is back to normal. At commands have returned. Now I have to remove them again to upload my program :).
https://www.allaboutcircuits.com/projects/flashing-the-ESP-01-firmware-to-SDK-v2.0.0-is-easier-now
I almost forgot to mention, I also had to hard wire my GPIO0 pin to ground before flashing. I was originally pulling GPIO0 to ground with a button. However, even though the serial console showed that I had booted in flash mode the flash tool failed. Only after hardwiring the GPIO0 to ground would the flash tool work.

This has been flagged as not-an-answer, however the OP is allowed to answer his/her own question, and this answer seems to me to be helpful for future people with similar issues, so I'm going to decline this flag.

on Windows use Espressif Flash Download Tool to flash the AT firmware. Everything is on Espressif's site


text:
Receive data using ESP8266
I have connected ESP8266 to my Raspberry Pi's WiFi network and assigned a static IP.
My Arduino code
#include "SoftwareSerial.h"

String ssid = "Rpi";
String password = "raspberry";

SoftwareSerial esp(3, 2);// RX, TX

String server = "192.168.50.1"; //my Host

void setup() {
  esp.begin(115200);
  Serial.begin(115200);
  connectWifi();
  httpget();
  delay(1000);
}

void connectWifi() {
  String cmd = "AT+CWJAP=\"" + ssid + "\",\"" + password + "\"";
  esp.println(cmd);
  delay(4000);
  if (esp.find("OK")) {
    Serial.println("Connected!");
  }
  else {
    Serial.println("Cannot connect to wifi ! Connecting again...");
  }
  connectWifi();
}

/////////////////////////////GET METHOD///////////////////////////////
void httpget() {
  esp.println("AT+CIPSTART=\"TCP\",\"" + server + "\",1234");//start a TCP connection.
  if ( esp.find("OK")) {
    Serial.println("TCP connection ready");
  }
  delay(1000);
  /*
    String getRequest =
    "GET " + uri + " HTTP/1.0\r\n" +
    "Host: " + server + "\r\n" +
    "Accept: *" + "/" + "*\r\n" +
    "Content-Type: application/json\r\n" +
    "\r\n";
  */
  String sendCmd = "AT+CIPSEND=";
  esp.print(sendCmd);
  //esp.println(getRequest.length() );
  delay(500);
  if (esp.find(">")) {
    Serial.println("Sending..");
    //  esp.print(getRequest);
    if ( esp.find("SEND OK")) {
      Serial.println("Packet sent");
      while (esp.available()) {
        String response = esp.readString();
      }
      esp.println("AT+CIPCLOSE");
    }
  }
}

void loop() {
  httpget();
}

I get this message

Cannot connect to wifi ! Connecting again...

In my Raspberry Pi I am constantly sending a signal to this IP address.
import socket

TCP_IP = '192.168.50.1' #Local Host
TCP_PORT = 1234            #Listening Port
BUFFER_SIZE = 12

SERVER_IP = '192.168.50.18'  #Arduino IP
SERVER_PORT = 3007            #Server Port

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((TCP_IP,TCP_PORT))
#s.listen(1)

#(conn,addr) = s.accept()
#print 'Connection address: ',addr
while True:
    print 'Sending message'
    s.sendto('1',(SERVER_IP,SERVER_PORT))
    print 'Waiting for response'
    data,addr = s.recvfrom(BUFFER_SIZE)
    if not data: break
    print 'received data: ',data
    print 'data recieved from: ',addr
    conn.close()
s.close()

But I can not see it in my Serial Monitor. Do I need to create a separate program for getting from WiFi?

you didn't start a server on esp8266 so nothing listens on esp for signals from raspberry

did you change the wifi mode in esp? it is in AP mode at default

softwareserial at 115200 has errors

You are recursively calling connectWifi() and therefore your setup function results in an infinite loop.
You must not implement loops and for processes, which take some time, you should set and ask a flag.
Btw. why don't you use the official ESP WiFi library?

What is official ESP WiFi library?


text:
ESP8266 returning 400 bad request
I am trying to get JSON data from my website using an HTTP GET request, but I'm getting a 400 bad request error. Can someone let me know why am I getting this error and how to fix that? I am tired of looking at online resources.
I am trying to fetch data from www.himalayavats.com/to_fetch/system_info.json
I am using this code:
#include <SoftwareSerial.h>

const byte rxPin = 2;
const byte txPin = 3;

SoftwareSerial ESP8266 (rxPin, txPin);

unsigned long lastTimeMillis = 0;

void setup() {
  sendData("AT+RST\r\n",1000, true);
  Serial.begin(9600);
  ESP8266.begin(9600);
  delay(2000);
  connectToWifi();
}

void connectToWifi() {
  String ssid = "moto g";
  String pass = "hvats555";
  sendData("AT+CWMODE=1\r\n", 3000, true); // Configure as client
  sendData("AT+CWJAP=\"moto g\",\"hvats555\"\r\n", 5000, true);  // Connects to wifi
}

String sendData(String command, const int timeout, boolean debug) {
  String response = "";
  ESP8266.print(command); // send the read character to ESP8266
  long int time = millis();
  while( (time+timeout) > millis() ) {
    while(ESP8266.available()) {
      // The ESP has data so display its output to serial window
      char c = ESP8266.read(); // read the next character
      response+=c;
    }
  }
  if(debug) {
    Serial.print(response);
  }
  return response;
}

void printResponse() {
  while (ESP8266.available()) {
    Serial.println(ESP8266.readStringUntil('\n'));
  }
}

void loop() {
  if (millis() - lastTimeMillis > 30000) {
    lastTimeMillis = millis();
    ESP8266.println("AT+CIPMUX=1");
    delay(1000);
    printResponse();
    ESP8266.println("AT+CIPSTART=4,\"TCP\",\"himalayavats.com\", 80");
    delay(1000);
    printResponse();
    String cmd = "GET /to_fetch/system_info.json HTTP/1.1";
    ESP8266.println("AT+CIPSEND=4," + String(cmd.length() + 4));
    delay(1000);
    ESP8266.println(cmd);
    delay(1000);
    ESP8266.println("");
  }

  if (ESP8266.available()) {
    Serial.write(ESP8266.read());
  }
}

I get this response every time:
AT+CWMODE=1

OK
AT+CWJAP="moto g","hvats555"

WIFI DISCONNECT
WIFI CONNECTED
WIFI GOT IP

OK
AT+CIPMUX=1

OK

AT+CIPSTART=4,"TCP","himalayavats.com",80

4,CONNECT

OK

AT+CIPSEND=4,43

OK
>
Recv 43 bytes

SEND OK

+IPD,4,1370:HTTP/1.1 400 Bad Request
Date: Tue, 19 Dec 2017 08:30:21 GMT
Server: Apache
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Connection: close
Content-Type: text/html

My JSON file on the website looks like this:
{"power" : "high"}

Why are you putting delay(1000); between ESP8266.println(cmd); and ESP8266.println("");? That's bound to break things...

@dda getting error on removing delay

What kind of error?

And anyway you should build your request so that the two CRLF are in the string, and send that.

@dda I have no idea about that

the delays are a substitute for waiting on confirmation from the esp. better use a library that makes the AT communication for you. for example the WiFiEsp library https://github.com/bportaluri/WiFiEsp

Take a look at the HTTP specification:
Request       = Request-Line              ; Section 5.1
                *(( general-header        ; Section 4.5
                 | request-header         ; Section 5.3
                 | entity-header ) CRLF)  ; Section 7.1
                CRLF
                [ message-body ]          ; Section 4.3

Request-Line  = Method SP Request-URI SP HTTP-Version CRLF

You don't send the CRLF (carriage return, line feed) at the end of your request line and at the end of the header at the same time of the request. Why the delay?
You also miss the obligatory host header.
Host = "Host" ":" host [ ":" port ] ; Section 3.2.2

getting the error without delay
AT+CWMODE=1
OK
AT+CWJAP="moto g","hvats555"
4,CLOSED
WIFI DISCONNECT
WIFI CONNECTED
WIFI GOT IP
OK
AT+CIPMUX=1
AT+CIPSTART=4,"TCP","himalayavats.com",80
busy GET /to_fetch/system_info.json HTTP/1.1
ERROR


text:
Arduino parsing JSON
I have created an API in Ruby on Rails and it send the following JSON response:
{"sun_position":{"altitude":"32.46","azimuth":"223.93"}}

I'm able to successfully hit the API and store the response. But when I try to parse it and store data it gives me an error. I have used the Arduino JSON library.
The code for parsing the JSON is as follows:
bool parseSunPosData(char* content, SunPosData* sunPos) {
  StaticJsonBuffer<JSONBUFFER_SIZE> jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(content);
  Serial.println("In parse fuc");
  Serial.println(content);
  Serial.println("==============");
  if (!root.success()) {
    Serial.println("JSON parsing failed!");
    return false;
  }

And the output on the serial monitor is as follows:

In parse fuc 38
{"sun_position":{"altitude":"32.46","azimuth":"223.93"}} 0
==============
JSON parsing failed! Disconnect

My guess is it can't parse the data due to the numbers 38 and zero printing... I don't know what that is and what it is.
PS: New to Arduino coding.

you have the HTTP chunked transfer encoding numbers in the content. 38 is the length of the body and it is on the first line of the HTTP body and 0 marks the end.
maybe try using ArduinoHttpClient library for HTTP

Thanks Juraj, That helped.. I changed the HTTP version to 1.0 from 1.1 and it worked like a charm


text:
avrdude flash issues
I want to burn a hex file to a custom ATmega2560 board. I use this USBasp programmer for flashing (firmware version 1.01) on my Mac OS X 10.12.6 system. All hex files are compiled with avr-gcc (GCC) 4.9.2.
I use this command to burn fuses (without bootloader):
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude -C/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf -v -patmega2560 -cusbasp -Pusb -U lfuse:w:0xff:m -U hfuse:w:0xd9:m -U efuse:w:0xfd:m -s -F

What is working fine: I can flash smaller (43,266 bytes) programs and they work straight away without bootloader. If I flash bigger programs (99,986 bytes) they do not run. I can verify if the program runs because they spit out data via TTL. The smaller program does work but the bigger one does not produce anything.
I turned on "Code verify" and I can see for smaller programs:
avrdude: 43264 bytes of flash verified

big programs:
avrdude: verification error, first mismatch at byte 0x0001
         0x90 != 0x94
avrdude: verification error; content mismatch

Any hints on this side?
Secondly: after deleting the whole flash, when I flash a custom bootloader (from Atmel Studio - fuses are Ext. 0xFD, High: 0xD2, Low: 0xFF), command:
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude -C/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf -v -patmega2560 -cusbasp -Pusb -U flash:w:ATmega_Example.hex:i

and afterwards read the flash, the bootloader ended up in several blocks within the flash.
From the readout hexfile (data blocks):
Line 1
>:20000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00

All the flash is 0xFF until Line 1921

:20F0000077C000009BC0000099C0000097C0000095C0000093C0000091C000008FC0000066

Some more data until Line 1995.

:20F940000895F894FFCF65300000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF31

All the flash is 0xFF until Line 3970.

:20F0000077C000009BC0000099C0000097C0000095C0000093C0000091C000008FC0000066

Some more data until Line 4044.

:20F940000895F894FFCF65300000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF31

And so on... I can find similar data 4 times in the file.
Is this a problem with the flashing or with reading the data from the chip?
Let me know if you need more information to help me here.

any change if using -D flag?

no change when I flash with the "-D" option

Define "smaller" and "bigger" wrt the code size.

small: 43.266 bytes
big: 99.986 bytes

I added verification information. On bigger problems it fails:
avrdude: verification error, first mismatch at byte 0x0001
0x90 != 0x94
avrdude: verification error; content mismatch

Could the size limit be 65,536 bytes? IIRC, there was an issue with addresses longer that 16 bits requiring a special extension of the normal upload protocol. But I don't remember whether the size limit was 2^16 bytes or 2^16 16-bit words.

Personally I use AVRDUDESS for uploading sketch on atmega328p and attiny85. Try to use it and run detect.
I answer this because AVRDUDESS is very easy to use and it can help you to show more info of your error.
I think you maybe have a bad wiring or a defect cable.

I'm not certain that it's going to fix your problem, but few years ago I had similar issue. I was trying to upload program to ATTiny13A using cheap e-bay USPasp and got verification errors. One step of my solution was changing programmer id from "-c usbasp" to "-c usbasp-clone"
More here: https://www.nongnu.org/avrdude/user-manual/avrdude_4.html

I am familiar with that issue. I don't have an USBasp but an USBtinyISP but I think the problem is the same.
The USBtinyISP cannot read or write past 64kiB. Since AVR are 8-bit machines with 16-bit addressing they cannot address past 64kiB on their own. A special addressing schema is used on runtime and also during flash. (I think it was larger page sizes during flash.)
I could manage to get around the issue by using an original Atmel AVRISP mkII.


text:
Moving a character around an LCD screen - is there a better way?
I have some basic programming experience but I am a novice at both C and Arduino.
I messed around with the example LCD code to try to move a character around with the onboard keypad. I also wanted the actual move to occur only once the button is released, like you would expect from a keypad.
The code works, but I have a feeling all the empty WHILE loops inside the main loop() function I used are not the best practice.. :)
How did I do? Is there a more convenient/elegant solution I missed and can learn from?
Thanks, and sorry for the messy code!
void loop()
{
  lcd.clear();
  lcd.setCursor(posCol,posRow);      //initialized beforehand
  lcd.print("O");                    //random char to move
  lcdOld = btnNONE;

  while (read_LCD_buttons() == btnNONE)     //do nothing while nothing is pressed
  {
  }

  lcdOld = read_LCD_buttons();

  while (read_LCD_buttons() == lcdOld)     //do nothing while button is down
  {
  }

  switch (lcdOld)               // depending on which button was pushed, we perform an action
   {
   case btnRIGHT:
     {
     posCol++;
     break;
     }
   case btnLEFT:
     {
     posCol--;
     break;
     }
   case btnUP:
     {
     if (posRow == 1)
     {
        posRow = 0;
        break;
     }
     else
     {
     break;
     }
     }
   case btnDOWN:
     {
     if (posRow == 0)
     {
        posRow = 1;
        break;
     }
     else
     {
     break;
     }
     }
   case btnSELECT:
     {
     break;
     }
     case btnNONE:
     {
     break;
     }
 }
}

This is fine, as long as you don't want you program to do anything else at the same time (like blinking an led for example). If you want that, you could just make the code remember the last button states, and only run the switch part of the code when any button goes from not being pressed, to being pressed. (PS remember to take button bounce into account, as that can mess things up. Not sure if read_LCD_buttons() already takes care of that)

I know it is been a while since you post this post but is there any way you can repost the whole source code?

You could encapsulate the logic of detecting a button release into its
own function:
// Return the button that was just released, or btnNONE.
int releasedButton()
{
    static int last_button = btnNONE;
    int previous_button = last_button;
    last_button = read_LCD_buttons();
    if (last_button == btnNONE)
        return previous_button;
    else
        return btnNONE;
}

Then the logic in the loo gets simplified:
void loop()
{
    switch (releasedButton()) {
        ...
    }
}


text:
Connecting multiple component's VCC wires to one Arduino UNO R3 5V Pin
Apologies for the title gore and whether this seems to be a fairly basic question, I'm an Arduino noob.
I'm working on a wearable sensor system project at my university using an Arduino UNO R3 to handle all the sensors and power them. I'm currently powering the board with a USB connection and will be powering my components from the board's 5V pin as they can all safely operate with that voltage. The individual components do not exceed their I/O pins max current and their combined current usage doesn't exceed the boards maximum current.
My question comes in here: in the past if I've needed to connect multiple components to the ground and 5V pins of an Arduino board, I was always taught to use a matrix board to solder my component's 5V and GND wires to, where they could then be powered from two soldered wires from the microcontrollers 5V and GND pins.
Given that this is a wearable system, I would like to minimise any unnecessary hardware and so proposed to my supervisor that we cut out the matrix board and simply solder the VCC wires of the components together to one header pin which we can then plug into the 5V pin on the board to draw power. He strongly cautioned against this but wasn't able to provide a concrete reason as to why it would be a problem; as far as I can see the fundamental theory is the same and we are simply cutting out an unnecessary middle man.
Is there something I'm missing here or does this solution seem like it would work fine? Additionally, if this solution works for VCC, would the same principle work for sharing a grounded connection?

I would suggest you look for a supervisor who understands circuit theory. He/she may simply be sceptical about your soldering ability, but should be able to rationalise any valid concerns.

I don't see a problem with splicing together all the power pins. The problem here is that single pins don't connect very solidly to the Arduino's pin headers, and can easily come out. Especially with a wearable project. I'd suggest getting a cheap proto-shield, and soldering all the wires of the components to that (maybe add some hot-melt glue for strain-relief). Then you can just press the shield onto the Arduino, and get a very solid (and reliable) connection.

Assuming you have suitable soldering skill, there are some considerations when you solder lots of wires to one header:

Lots of wires means lots of weight. The strain of several wires may degrade your connection or header over time, especially for a wearable system, where I assume the parts would be subject to some movement.
The width of the connection when all the wires are soldered to it. It might touch adjacent pins, or lean on them, creating mechanical stress. Heatshrink or sleeving can help with the electrical contact issue, but won't remove the mechanical risk.
Lots of wires soldered to one point may make the system more difficult to service. Instead of desoldering the wire to one component, you have to either desolder them all, or cut the wire to the one suspect component and then solder together wire stubs later to replace it.

When referring specifically to power supply pins, you'll need to consider the peak current requirements of anything you power from it. Based on https://playground.arduino.cc/Main/ArduinoPinCurrentLimitations it seems like you shouldn't be pulling more than 200mA from the Vcc PIN. Check the maximum current draw of all of your components that you want to power, add them together, and make sure it's under the limit of the Arduino board.


text:
How to connect RFID Module to Arduino UNO
I brought 860mhz-960mhz UHF rfid reader module for chip card skimmer from follow link:
https://www.alibaba.com/product-detail/860mhz-960mhz-UHF-rfid-reader-module_60312310172.html
I want to do communication with arduino uno so is it possible to connect

VCC to VCC
GND to GND
RX to TX
TX to RX
and what is meaning of EN and GPIO if any one know please help me to do serial communication.

Its just a simple RFID module based on UART working on 5V.  EN stands for enable, to enable the chip. It has to be connected to VCC too. Because its active high signal. GPIOs are general purpose io pins. No need of them if you are just reading from RFID.

thank you so much I will try to connect these and let you know


text:
Arduino Uno Keeps Resetting (Power issue)
Arduinites!
Hoping you can help a newbie. I'm putting together a board for a Christmas present this year. It's replacing the factory board that comes on a beer fridge/vending machine, with minimal interactions.
Basically, when the beer can falls into an outlet chute, it trips a switch that triggers some LEDs and audio. Pretty simple stuff. The fridge supplied +5v to the previous board, so I thought I could remove it and simply swap in the Arduino.
The code runs fine when the Arduino is powered by USB/laptop. I spliced a USB header onto the +5v wire supplied by the fridge and plugged it all in. Now, it will boot up, play some weird fuzz out of the speaker, and reset after about 10 seconds.
How can I use the +5v to power my nutty creation? The previous board had a capacitor on it which I removed (I know next to nothing about some of this stuff but it seems like maybe that would help?)
Here's a photo of what I'm working with. If I need to provide any additional information or photos I can do that.

If you have any advice, please ELI5 with regards to what I might be able to place in my circuit to get this working (links or definitions are incredibly helpful!)
Any help is appreciated!

Without knowing the specs of the power supply it's impossible to tell. It may only have a very low current capacity, or it may be unsmoothed, or similar.

@Majenko thanks for the reply. what's the best way to determine more information about the specs? Multimeter?

First step is to examine the power supply and see if there are any clues. Second step is probably to monitor the power with an oscilloscope looking for brownouts.

Holy jumper wires, Batman!  It might help if you used ribbon jumpers, so you can make sure you don't have an accidental short somewhere.

@computercarguy haha, thanks for the recommendation! You're right, that would definitely clean up the board. Everything works fine when plugged in to my computer, so although it definitely looks a little unwieldly I'm sure it's wired alright for now.

@Majenko I've added some photos from the back of the fridge (informational) and a pic of the power supply board and transformer. In your mind, does this shed any additional information as to why this is happening?

I think @Majenko is on the right track. It's probably a noisy and/or low current power supply.
You also mentioned the old board had a capacitor on it, which makes me suspicious. What happens if you add a capacitor (say 470uF, 16V) across the 5v supply? That capacitor may have been smoothing out the supply, especially with an electrically-noisy compressor nearby.

@toxicantidote thanks for the reply. Where exactly would I add the capacitor? Seems like it would need to somehow be added somewhere before the 5v hits the Arduino, yes?

The main problem here is the current IMHO. The IC on the power supply is a 78L05, which provides at most 100mA. The arduino itself can drain around 30mA; each LED can be around 20mA (you did not specify how many and how much current they absorb), and the audio board is usually hungry. So I think that 100mA are not enough. You can confirm this by measuring the current when it works. Are you forced to use that power supply? Otherwise take a small cheap USB charger (1-2$) and you will have something like 1A+ of available current

@frarugi87 thanks for the reply. I don't have to use it as a power source but it is certainly the cleaner option if I can figure out how to make it work! I have 8 LEDs on the board along with the audio chip, so I could see it being underpowered, but I guess I don't understand why it would work when plugged into a laptop USB and not this source.

@DaveKiss well, a (recent) laptop USB usually can provide at least 500mA (or even more, if it has some USB3 ports). If it is a current issue, I don't think you can solve it with just a capacitor (BTW, use a large electrolytic capacitor rated at 10V or more; connect the pin labelled "-" to the ground and the other to +5V - but don't invert the pins!!! Explosion risk). But maybe it is worth trying. In any case, another supply rated at 1A or more in my opinion will solve your problem

How much current takes your board with all components? Maybe the 5V power supply can not give you the wanted current.

You can use a oscilloscope to see what is happening with the 5V when you use your board (maybe not enough current) for example interruptions on your connection or the voltage is not stable.
Maybe you can find a datasheed for the power supply for more information
try your board with another power supply to see if this is a problem of the board or the power supply

I just recognized in the third picture that the transformers output have 5V and 200mA. Your speaker will maybe have 8 Ohm (please write us the resistance). This means it will take 5V/8 Ohm this equals a current of 0,625 or 625mA. This current is 3 times higher than the output current of the transformer.
My theory 1 is:
Your circuit worked on your computers USB because you have got usb 3.0 and the max current for it is 900mA wich is much greater than 625mA and enough for leds, speaker and arduino. Your speaker is not connected directly to a pin and gnd. Some seperate electronics manages the pulses and takes directly the 5V of the USB.
My theory 2 is:
You used USB 2.0 (500mA) or USB 3.0 (900mA) and the speaker is connected directly to a pin (the resistance is ok or you added some resistance). The sound was probably not loud because the power was low. The current for both USBs were enough for leds, speaker and arduino.
Now to your problem with the resetting.
The solution:
Switch off the speaker and test your circuit without it. (I think it will work fine).
If it works: You took too much current and this current heated the pin and  influenced the charecteristics of the pin and finally the voltage at your pin (weird fuzz). Add a variable resistor in series to your speaker an try it.
If it not works: Measure the output voltage of the transformer and wirte us the value.


text:
understanding timer overflow detection code
I am trying to understand in details the (great tutorial and) code of Nick Gammon ''Improved sketch using Timer 1'', available here: http://www.gammon.com.au/forum/?id=12075 . I post the whole code at the end of this in the case the web page would go down.
I find the code quite clear: Nick wants to estimate the value of a capacitor by measuring its characteristic discharge time. For this he uses one of the Arduino timers, together with an interrupt raised by the analog comparator. As the Arduino timer he uses is only 16 bits and he uses a pre-factor of 1 at 16MHz, he expects overflow of the timer to occur so he keeps track of the number of overflows that happened:
ISR (TIMER1_OVF_vect)
{
  ++overflowCount;               // count number of Counter1 overflows
}  // end of TIMER1_OVF_vect

However, what I do not understand is why he tries to find a 'missed overflow' in the ISR raised by the analog comparator (this is in the ISR (ANALOG_COMP_vect) function body):
// if just missed an overflow
    if ((TIFR1 & bit (TOV1)) && timer1CounterValue < 256)
      overflowCopy++;

So my questions are:

How could a missed overflow happen? 'Naively' I would guess that, as soon as the analog comparator ISR is called, the timer stops incrementing so that it should not overflow after the comparator ISR fires, am I wrong?
If there is a timer overflow happening, I understand why one wants to check TIFR1 at TOV1 (this is the overflow flag, set automatically at timer overflow, which should be cleared as a side-effect of execution of ISR(TIMER1_0VF_vect) according to datasheet), why add also the && timer1CounterValue < 256 in the if condition? I understand that 256 is a 'small' value, any reason for this exact numerical value?

Copy of the whole code:
/*
Capacitance meter

Author: Nick Gammon
Date:   27 June 2013

Pulse pin (D2): Connect to capacitor via 10K resistor.

Reference voltage of 0.632 of output pin (pulsePin) connected to D7.
In my case I used 3.06V because I measured 4.84 on the 5V pin.

Measure pin (D6) connected to first leg of capacitor, other leg connected to Gnd.

Like this:

Capacitor to test:

D2  ----> 10K ----> D6 ----> capacitor_under_test ----> Gnd

Reference voltage:

+5V ----> 1.8K ---> D7 ---> 3.1K ----> Gnd

*/

const byte pulsePin = 2;
const float resistance = 10000.0;

volatile boolean triggered;
volatile boolean active;

volatile unsigned long timerCounts;
volatile unsigned long overflowCount;

ISR (TIMER1_OVF_vect)
{
  ++overflowCount;               // count number of Counter1 overflows
}  // end of TIMER1_OVF_vect

ISR (ANALOG_COMP_vect)
  {
  // grab counter value before it changes any more
  unsigned int timer1CounterValue;
  timer1CounterValue = TCNT1;  // see datasheet, page 117 (accessing 16-bit registers)
  unsigned long overflowCopy = overflowCount;

  if (active)
    {
    // if just missed an overflow
    if ((TIFR1 & bit (TOV1)) && timer1CounterValue < 256)
      overflowCopy++;
    // calculate total count
    timerCounts = (overflowCopy << 16) + timer1CounterValue;  // each overflow is 65536 more
    triggered = true;
    digitalWrite (pulsePin, LOW);  // start discharging capacitor
    }
  }  // end of ANALOG_COMP_vect

void setup ()
  {
  pinMode (pulsePin, OUTPUT);
  digitalWrite (pulsePin, LOW);

  Serial.begin (115200);
  Serial.println ("Started.");
  ADCSRB = 0;           // (Disable) ACME: Analog Comparator Multiplexer Enable
  ACSR =  bit (ACI)     // (Clear) Analog Comparator Interrupt Flag
        | bit (ACIE)    // Analog Comparator Interrupt Enable
        | bit (ACIS0) | bit (ACIS1);  // ACIS1, ACIS0: Analog Comparator Interrupt Mode Select (trigger on rising edge)
   }  // end of setup

void startTiming ()
  {
  active = true;
  triggered = false;

  // prepare timer
  overflowCount = 0;            // no overflows yet
  // reset Timer 1
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;      // Counter to zero
  TIFR1 = bit (TOV1);  // clear overflow bit
  // Timer 1 - counts clock pulses
  TIMSK1 = bit (TOIE1);   // interrupt on Timer 1 overflow

  // get on with it
  digitalWrite (pulsePin, HIGH);  // start charging capacitor
  // start Timer 1, no prescaler
  TCCR1B =  bit (CS10);

  } // end of startTiming

void finishTiming ()
  {
  active = false;
  Serial.print ("Capacitance = ");
  float capacitance = (float) timerCounts * 1000.0 / 16.0 / resistance;
  Serial.print (capacitance);
  Serial.println (" nF");
  triggered = false;
  delay (3000);
  }  // end of finishTiming

void loop ()
  {
  // start another test?
  if (!active)
    startTiming ();

  // if the ISR noted the time interval is up, display results
  if (active && triggered)
    finishTiming ();

  }  // end of loop

'Naively' I would guess that, as soon as the analog comparator ISR is
   called, the timer stops incrementing

It doesn't. The timer stops only when you ask it to stop.
Now, consider this scenario:

overflowCount = 0, TCNT1 = 0xfffc
the ANALOG_COMP interrupt fires, which automatically disables
servicing nested interrupts
while ISR(ANALOG_COMP_vect) is executing its prologue (saving the
execution context), Timer 1 overflows, which sets the TOV1 flag, but
the corresponding interrupt is for now pending
when timer1CounterValue = TCNT1; gets executed, TCNT1 is now
0x0008.

At this point, we have overflowCount = 0 and timer1CounterValue =
0x0008. If we have no provision for detecting the overflow, we will
grossly underestimate the time. This can be fixed by accounting for the
missed overflow as
// if just missed an overflow
if (TIFR1 & bit(TOV1))
    overflowCopy++;

The is still an issue however. Think of what would happen if the timer
overflows after executing timer1CounterValue = TCNT1; but before
reading the TOV1 flag. Then we would unduly increment overflowCopy.
This is why the code tests for
(TIFR1 & bit(TOV1)) && timer1CounterValue < 256. There is no reason
for choosing this particular small value, other than the test being
easier to perform in assembly. The compiler is probably smart enough to
notice it doesn't need to do a subtraction for this particular value.

Great, thank you! I had always thought that timers were not working in interrupts and that this is why you cannot use delay() there, am I wrong?

Sorry, now I may understand: actually, the problem is not that timers were stopped in interrupts, but that delay() relies on an interrupt itself; is this right?

Mmh, no, this is not it: delay does not seem to have rely on any interrupt: ```void delay(unsigned long ms)
{
uint32_t start = micros();
    while (ms > 0) {
            yield();
            while ( ms > 0 && (micros() - start) >= 1000) {
                    ms--;
                    start += 1000;
            }
    }

}```

@Zorglub29: delay() relies on micros() which relies on timer0_overflow_count which is updated by the TIMER0_OVF interrupt.


text:
5v input on ATmega328p running on 3.3v
The ATmega328p can run on 5v but will it cause problems if it runs on 3.3 v and one input signal is 5v?

Logic levels can be different across differently made integrated circuits and processors.  You should not directly connect differently powered devices together.  Logic level differences (as described here) should be dealt with using logic level converting devices such as this one.

The voltage at any input must be less than VCC+0.3V unless it is restricted to only a few milliamperes (so it doesn't burn out the clamping diode). Use a proper voltage translator if it is available, otherwise use a 1kohm or greater resistor (at the cost of life expectancy for the MCU).


text:
Connect a sensor to Arduino without knowing much info about the sensor
I am planning to buy a formaldehyde sensor and I would like to connect it to an Arduino Uno board (and later to a Raspberry). As far as I know, the sensor comes in a small box/bag without any other external components (e.g. amplifiers etc.). So I will end up having in my hand a sensor with two copper terminals for connection (see image below):

Is it possible to connect this to an Arduino board without having a connection scheme? If yes, where do I connect the two terminals of this sensor to the 5V, GND and the A## ports? Also, how to translate the voltage coming from the sensor to ppm (parts per million) only by having general specifications from the manufacturer and not some kind of table of conversion? Also, would I need an external component for this? If yes, which component?
I know that this question sounds very stupid, but so far I've used sensors that come with a code on Seeed Grove with a clear description and I assumed that the code is there because there is a link between the producer of a certain sensor and Groove. Thank you!
FYI: The producer writes some things about the sensor but that doesn't help me a lot:

This sensor is of the two-electrode electrochemical type, operating by the
  diffusion principle and as such requires no external sampling hardware. In
  the presence of formaldehyde gas a small direct current is produced; the
  sensor requires no power supply of its own but this current requires
  amplification to make it readable using external data collection
  equipment.

Step one: read the datasheet. Step two: implement the circuit described therein.

buy the sensor kit

I would gladly buy the kit, but I'm afraid I would end up with the same problem. How would I connect the kit to an Arduino board? As for implementing the circuit, well, I don't have the right knowledge. You are referring to the one with resistors and capacitors, right? (I can only read some of the symbols in the circuit schemes)

You have linked to the datasheet of the sensor.
In the datasheet, look at the "Application Circuit" section. You must build this circuit. The sensor produces a very small electric current, and the application circuit is high-gain amplifier to translate that very small electric current to a varying voltage you can sample with the Arduino ADC.
Note on the circuit, the wire labled "To ADC" -- that is the part which you connect to your arduino.
As for calibration, the datasheet itself notes that the process is non-trivial, or that they can perform a calibration, for an additional fee, at the time you order a batch of sensors. Presumably their calibration will include the precise resistor values used to set the gain of the amplifier, and also an equation to associate PPM values to the analog voltage provided at the "To ADC" wire.
As for reading the circuit diagram (schematic), you may already know resistors and capacitors. For the other items, search online for the part numbers given, to find out what they are.
The datasheet also notes that the application circuit is available pre-built from the sensor manufacturer. You may want to contact them to determine how to purchase one for yourself.
Most electronics products have a datasheet that explains all you typically need to know about the device, such as it's operating parameter minima and maxima, typical values, typical outputs, etc. This sensor is no different, except that the calibration procedure is not described in great detail due to the complexity.

Thank you for the nice answer. Do you know if the Kit they offer on the website is composed of that extra circuit from the datasheet or it is a different circuit? Otherwise, I will ask them to send the sensor together with that particular circuit. Thank you for clarifying this.

Read their website. In the Accessories section is the interface circuit board. I do find it hard to believe that a Q&A website is need to read information that is freely available and linked to already!?

It's not only about reading it. It's also about understanding. I'm a noob in electronics and that's why I am dealing with this. The interface circuit board doesn't have a scheme that would make me understand that it is the one in the specs. That's why I need help. Thanks to you it is now clear how to connect that circuit to an Arduino. If that accessory is the circuit that I would have to build, then I will just get it.