I am curious. I like to know how things work. For the curious, this Instructable will try to explain some of the Arduino electronics.
I suspect many people have built Arduino projects but couldn’t get them to work. I hope to provide some knowledge and skills to help fix hardware problems such as wiring errors and bad components.
After some Internet searching, I found an electronics tutorial that I like and trust:
"This tutorial is by Limor Fried”
In fact, I recommend it to all Arduino readers. There is some overlap of information but lots of multimedia and more on programming.
So who am I? I am a Lazy Old Geek (L.O.G.). I am not a degreed engineer but I’ve been around the electronics field for over 40 years starting as an electronics tech in the USAF. I spent many years testing electronic systems.
As most of you know, Arduinos are based on a little black chip called a microcontroller. This is the heart and brains of the Arduino. You don’t have an Arduino without one. There are many flavors of the Arduino microcontroller but they all have the same functions. Currently the most popular for the DIYers is the ATmega328. See picture.
Microcontroller: A microcontroller is a CPU (central processing unit) with memory and interface circuitry built-in to the chip. Basically, the CPU takes all the commands in the program (sketch) (.PDE) and does what they tell it to do. Notice that I said what the commands tell it to do; I did not say what the programmer wants it to do. Writing a successful program is telling the CPU exactly what you want it do in the language it knows.
Frequently asked: Yes, the ATmega328 can always be used instead of the ATmega168 as the hardware is exactly the same. The ATmega168 may not replace the ATmega328 as it has less memory so bigger programs may not work.
Technobabble: The rest of this section is for Geeks only.
1 K Bytes
What does this mean? The K stands for kilo, a multiplier which in this case, means multiply the number by 1024. Bytes are just a place to store information (data). This is basically the only difference between the two microcontrollers.
Flash: is a type of memory that holds program information, even after the Arduino is disconnected from power. The same program will run anytime power is reapplied to the Arduino. This is the same way USB flash drives and digital camera cards retain their information.
EEPROM: is memory that also retains information after power is shutoff. It is different from Flash as it can be written by the program instead of the program itself. The Arduino instructions to use EEPROM memory are EEPROM.read() and EEPROM.write().
Tip: Be sure to have:
//in your sketch(program).
The limitation is, even in the ATmega328, there is only 1024 bytes so only so much data can be stored. Tip: By the way, I never got this to work.RAM: is also memory but it is volatile meaning it will go away when you turn off power. Sketches use it to store temporary information such as variables. What is a variable? Well, it is something that can change. Examples are the temperature or the time of day. Here is part of a sketch that converts a temperature sensor reading to degrees C (Centigrade) and degrees F (Farhenheit). float Vt=(float) sensorValue3Avg*5.0/1023.0;
All of these float variables are stored in RAM and will be overwritten the next time a measurement is taken and are lost when power is turned off.
Basically, variables are just labels for locations in RAM. Float variables are a specific type of variable. With this label, the sketch knows where to go to store the value it wants or retrieve the value stored at that location. The specific type determines how much room is needed and how to interpret the information.
Besides the CPU, flash and RAM, the ATmegas have interface circuitry built in:
Serial interface: this allows the CPU to talk to the PC through a serial port or through USB and I believe it’s used to communicate over I2C. This is also how it talks to serial LCDs.
Analog to digital converter (ADC): This allows the ATmega to convert analog voltages to digital data (will be discussed in another Instructable).
PWM (pulse width modulation): circuitry to output ‘analog’ voltages
Timers: for timing events, most often used to set delays between program steps, e.g., blinking LEDs.
If you have ever looked at the datasheets on these ATmegas and understand them, then maybe you should be writing this instead of me.
Prefixes: There are a lot of letters attached to electronic terminology that may be confusing. E.g. 16mV, 10Kohms, 20uF. These letters are called prefixes (and suffixes) that are just multipliers to the value. E.g., 10Kohms is (10 times 1,000) ohms or 10,000 ohms. See the table below.
Non-essential Info: Unfortunately, if you’re talking computer memory 1Kbyte is 1024 bytes. This is because computer people like to make everything complicated. So to them K is 210. Megabyte can mean 1,000,000, 1,048,576 or 1,024,000. Don’t ask, check it out on Wikipedia.