Memory Saving

a. Size of data that can not be fit into ram, we can save them into program memory.
Normally global variable or table is store in ram memory, so sometimes there is not enough ram to save data on ram.
in that, we can save them into program memory.

b. if we have an array/table of data that holds font/bitmap or any fixed information which can be not be changed through the program. That table can be saved into program memory instead of ram memory.
In such a case, we can tell the compiler to save data into program memory by making that table / variable global const and using PROGMEM statement.

	//make global declaration of variable or array/table like this.
const uint8_t font5x7[128] PROGMEM ={0};

c.  Putting String Into Program Memory.

	Serial.println(F("Hello World")); //Store String Data Into Program Memory.
Serial.println("Hello World"); //Store String Data Into RAM Memory.

Good Naming Conversion

Write Program in a manner so that it can be  Easily Readable and Understandable formatMake use of Constant or define statement for naming conversion at the beginning of the program to make code easily readable format. it is also useful when there are any changes in hardware, we can simply change the constant instead of looking searching into the whole source code.

	const int LEDPin = 5;  //LED is interfaced at pin 5 of arduino.
//#define LEDPin 5 //Or
setup(){
pinMode(LEDPin,OUTPUT); //it is easily readable and understandable
//pinMode(5,OUTPUT); //it is Not easily readable and understandable by other
}
loop(){
digitalWrite(LEDPin,HIGH);
//digitalWrite(5,OUTPUT); //it is Not easily readable and understandable by other
}

Reset Your MCU Automatically

As my hardware is working correctly till the day, in some cases I found that it is getting stuck/hang at some time and I had to reset it manually and it becomes a headache to manage. 

How To overcome this manually reset issue? So, I am working around and find about watchdog resetWatchdog is a timer that can counter continuously and if counter overflow then it reset the MCU.

so I had to clear the watchdog counter continuously, in the case where the program not getting work or stuck counter overflow and reset my MCU.

Documentation

Always comment out the code segment or block, it is good practice for programming. it makes a clear understanding and purpose of what this code does in an application and how to use it. Try to manage separate readme files to keep track of firmware versioning control and change notes accordingly. 

Standard Data Type

Always try to make use of standard data type in programming to overcome the size of a variable when same code or block of code is used in different 8,16 bits of micro-controller and compiler.

#include
uint8_t unsigned8bitData; //fixed size of variable independent of compiler and mcu
int8_t signed8bitData;
uint16_t unsigned16bitData;

Responses