Arduino an Explanation – AVR @ Heart

I have been asked again and again by my friends and students to use Arduino or not and some people who are using AVR asked me if Arduino is better and some who were using Arduino asked the same about AVR. Well, here it goes, [this is all that I know, haven’t researched or confirm any of this while writing it – this became a bit longer than I had initially thought].

To understand what is Arduino, lets see how AVR works. To use AVR, usually the following is done in order.

  • Install ATMEL Studio on your PC if you dont have it.
  • Make a new project, select the AVR you like.
  • Write the CODE in the source file, standard C/C++ code works. If you want to use something special like LCDs or UART or something, proper Libraries make work easier otherwise that too can be one by using C code and referring to the datasheet.
  • Build/Compile/Make whatever, get the HEX file (look in the DEBUG folder).
  • Upload/Burn/Flash that Hex File to the AVR using a Programmer (a separate Hardware device – USBasp is the BEST).
  • Once the AVR is programmed with the HEX file, it needs to be on a circuit with power supply, reset circuitry, oscillator and any other component etc required by your project. Usually it is a Development Board, or an AVR on a breadboard or maybe a project PCB which has everything on it including a programming port (ICSP/ISP Connector).
  • It should WORK!

Hoping that you did everything above correctly from writing proper code to having the right controller IC to a working programmer and a working/tested circuit with your AVR IC in it and you should see your code working.

Usually mistakes happen in making that AVR circuit or the programmer doesn’t work or the connections from the programmer to the AVR are loose/broken, resulting in frustration and waste of time, usually new comers at this point think of leaving the AVR world and moving on.

This is where ARDUINO comes, Arduino is basically a prefabricated PCB aka circuit board with

  • an AVR Micro-controller (ATMega8/328/2560 etc) on it +
  • Power Supply circuitry +
  • Programmer Support (allows programming) +
  • Pins provided in easy to use connectors and numbered from 0 to 13 and A0 to A5 (talking about Uno here)
  • an easy to use Software ARDUINO IDE
  • easy to use code/language – basically it is just C/C++ functions, more about Arduino language here
  • One button/click program UPLOAD/test

So an Arduino looks very easy for any beginner to use, but KNOW that it has the same AVR micro-controller and the IDE supports C/C++ completely and you can still use any and all AVR registers directly, but that might break some of the Arduino functions.

So anyone using AVRs, I would suggest STICK with it and learn it properly unless you are stuck in a situation where you dont have the time to learn AVR now, then move to Arduino, do your task and then come back to AVR and learn it. [here I mean the ATMega series in general]

Those using Arduinos, it is OKAY to use it at any and all levels including and beyond B.E. anyone who says this is kid stuff does not know that it is the same AVR as any other – it is upto the programmer to write powerful code for it.

As For myself, I use Arduinos to prototype faster, this includes using Arduino hardware and shields and the Arduino IDE/code – however after basic prototyping I move my projects to custom made AVR boards, sometimes with the same arduino code and sometimes I optimize the code properly and either rewrite it completely in Atmel Studio using the standard C/C++ and my own custom libraries or mix my code with the Arduino code.

Simulating Arduino [Steps for Windows/PC]

This is a STEP-by-STEP post, no-nonsense approach to simulating an Arduino on your PC, for those who don’t have the actual Arduino hardware, but have the following Required Software:

From here on, I will be simply providing the steps of the process, no talk about what and how, just the steps, follow them and you will hopefully be able to see simulation of arduino code within your PC.

  1. Open Arduino Software
    — Select Arduino Uno from Tools(menu)>>Boards
    — Select Preferences from File Menu
    — Check the compilation box after the Show verbose output during:
  2. Write your program in Arduino, anything, or simply open some example program.
  3. Once done with the code, CLICK ON VERIFY,
    the RIGHT/check button on top-left – do not click on Upload, cause you don’t have the Arduino connected.

  4. As the arduino IDE verifies and compiles your code, you will see the output of the compilation process as it happens,
    once done, it will show something like this at the bottom LOG window (black area).
    Binary sketch size: 1,084 bytes (of a 32,256 byte maximum)

  5. I have only shown the last few lines,
    Copy the PATH of the hex file, complete path from the drive root to .hex
    C:\Users\ZAIDPI~1\AppData\Local\Temp\build3564184540682511069.tmp\Blink.cpp.hexThe arduino Part is DONE, now we move to Proteus.
  6. Open Proteus (ISIS) and add an ATMega328P into the Editing Window of Proteus.
    [press P for Part, search for ATMega328P and then add it, first to library then to the editing area, place part]
  7. Add Power to the AVCC and AREF by attaching them to 5V/VCC/Power Rail
  8. Now double click on ATMega328P to open the properties page, do the followign changes:
    — Set the CLKDIV8 option to (1) Unprogrammed
    — Set the CKSEL Fuses option to (1111) Ext. Crystal 8.0-MHz
    — in Advanced Properties section, write in 16000000 as the value of Clock Frequency Property
    — PASTE the address of HEX file, previously copied from Arduino software in the Program File option.
    Press OK, to close the properties window

  9. ADD any circuit, components etc in Proteus as you would with the actual ARDUINO

  11. Now, whenever you change code in arduino, just click on VERIFY to re-compile it, the hex file will remain the same and you can simply test the new code by stopping and re-starting the proteus simulation.

Raspberry Pi – Setting up for Electronics and Development Work

RaspberryPiThe following is a step-by-step procedure of what I did to get my Raspberry Pi in some sort of working condition, having SSH, VNC access, development tools installed, GPIO and Wiring-Pi Library and having a static IP so that Raspberry Pin can be connected directly to Laptop/PC via an ethernet cable without any router etc.

The hardware setup is as follows:

  • 1x Raspberry Pi having latest Raspbian Image on an 8GB SD card
  • 1x Ethernet Cable, Cross connection
  • 5V Adapter with USB Cable to power Raspberry Pi [powering via laptop USB port is NOT recommended]

Now coming to the steps which I followed to set up my Raspberry Pi for use:

    1. Power up raspberry pi with fresh Raspbian image and connect it to a router using some ethernet cable. Use Win32DiskImager to put install the Raspbian image on an SD Card
    2. Find IP of Raspberry Pi by using any network scanner , I used SoftPerfect Network Scanner. Just make sure to put in proper IP range for the search, there is an IP button at the top to select the right range automatically.
    3. Open PuTTY, and enter Raspi’s IP and connect via SSH
      — user name: pi
      — password: raspberry
    4. To configure any settings etc which you want, enter
      sudo raspi-config
      I expanded the Root File System by expand_rootfs, enabled SSH (though it seems to be already enabled else we wouldn’t be able to use PuTTY) and then upgraded raspi-config [requires Internet and may take some time depending on Internet speed]
    5. Reboot Raspberry Pi by
      sudo reboot
    6. Restart the PuTTY session and login again.

6.5. Before following the the next step, see Step 9 first..!

  1. Enter
    cd /etc/network
    to change to /etc/network directoy, by now entering ls you can see the list of files/directories in the folder, we are interested in the interfaces file.
  2. The interfaces file has the configuration and settings regarding the Ethernet and Wifi interface, we want to make the IP static so we can access Raspberry Pi directly via PC as well without router.
    To access and edit the interfaces file, enter
    sudo nano interfaces
    Now, edit the line: iface eth0 inet dhcp by changind dhcp to static and then add the following lines right below it;
    auto lo
    iface lo inet loopback
    iface eth0 inet static

    Select the IP addresses as you want, I have set it up according to the setting of my home wifi router, your’s may differ a bit.
    to save and exit, press Ctrl+X, then Y for Yes and then ENTER to keep the same file name, now reboot again by entering
    sudo reboot
  3. Now start a new PuTTY session with the new IP you assigned. I had selected the IP so that the Raspberry Pi works with my Wifi router as well and since I have still kept it there and it is connected to Internet, I can isntall a few more things, if you cannot access Internet after changing IP, do these steps and any other online installation BEFORE changing the IP.
  4. Update the package list by entering
    sudo apt-get update
  5. To install TightVNC, enter
    sudo apt-get install tightvncserver
    it will ask for disk spacce usage press Y.
  6. Run VNCServer for the first time to set up passwords, by entering
    vncserver :1
    the 1 is the VNC Server port number.
    set password, 8 characters. I did not set any view-only password so left it blank.
  7. To install some essentials for C/C++ programming, enter
    sudo apt-get install build-essential
    [I found out later that it is already installed]
  8. Installing the RPi.GPIO Python module
    sudo apt-get install python-rpi.gpio
    sudo apt-get install python-rpi.gpio

This much should be enough for most, however, I installed/downloaded a couple more things

  • Python Development toolkit
    sudo apt-get install python-dev
    sudo apt-get install python-smbus
  • I2C Tools Utility
    sudo apt-get install i2c-tools
  • installed GIT
    sudo apt-get install git
  • Cloned of Adafruit’s Raspberry pi code library
    git clone
  • Cloned Wiring-Pi Library
    git clone git://
  • Installed Arduino
    sudo apt-get install arduino
  • Load and Enable I2C modules at boot time by editing the file modules in /etc/
    sudo nano /etc/modules
    add the following 2 lines at the end of the file:

    save and exit, Ctrl+X, then Y, then Enter
    open another file:
    sudo nano /etc/modprobe.d/raspi-blacklist.conf
    comment the following 2 lines by adding a # at the start.
    #blacklist spi-bcm2708
    #blacklist i2c-bcm2708

    save and exit, Ctrl+X, then Y, then Enter
  • UPDATE: Installing Mono for C# Development
    sudo apt-get install mono-complete
    the installation may take some time, but after it is done, you can use CSharp by typing in csharp
    More information at:


Accessing Raspberry Pi via VNC

After boot and login via PuTTY, type in
vncserver :1
to start the VNC Server at port 1, you should have UltraVNC or some other VNC viewer application installed on your PC, start the viewer and put in the IP of Raspberry Pi along with port number. Connect, enter password and you are now logged in.
To start the VNC Server with specific options, you can use
vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565:
or see the vncserver help yourself to find out more options.


Accessing Raspberry Pi directly from PC

If you are like me, you want to access the Raspberry Pi directly from your PC/Laptop without router etc in between.
to do this, you will need the following, besides a Raspberry Pi and your Laptop.
— An Ethernet cable, cross connection is preferred.
— Raspberry Pi set at some STATIC IP, mine is set as follows:

Set the IP settings of your PC Ethernet adapter as follows:

Laptop/PC - IP Settings
Laptop/PC – IP Settings


Now start a new PuTTY session and do as follows, (start VNCServer)

PuTTY from Login to VNCServer
PuTTY from Login to VNCServer


Login to VNCServer by using the VNC Viewer application, see how the port number is added with the IP address.



FINALLY, Raspberry Pi desktop, accessed from a PC, directly via a LAN Cable, without any Switch or Router.

VNC Window, showing Raspebrry Pi Desktop ‘X’

Note: Most of the stuff mentioned and steps taken and commands used were taken from different websites, some of the ones worth mentioning are:


Project Files: Tachtastic – AVR Tachometer

Tachtastic – an Image from the old days

On demand of a site-visitor (Mohsen) I have uploaded all the relevant files that I had for the project Tachtastic: AVR Tachometer, you can download and view them. The files are more than a year old and show how I coded back then and were not meant for uploading – but now that I have seen it myself, seems to be well-documented not well coded though.

Download the below provided rar file, it contains all of the files that I have, including 2 versions of AVR Code, schematic files made in Circuit Wizard, PCB files [pdf] and images of the circuit.

There have already been 2 posts about this Tachtastic project and this being the third one will probably be the last one unless I make another AVR Tachometer, Tachtastic v2.0.

  1. Tachtastic Project Details
  2. Tachtastic Image Gallery

Without any further delay, here is the download link:

[Download not found]

Now that you have downloaded the rar file, this is what you will find inside, 4 folders:


  • Circuit-files
    • This folder contains Circuit Wizard files of the circuit, which has both the schematic and the PCB layout, plus schematic and PCB layout in PDF files if you don’t have circuit wizard, multiple views of the circuit as circuit wizard had a number of views to choose from.
  • MISC
    • The MISC folder, contains things like datasheets, mechanical drawing of LCD that I used and a couple other things used and downloaded during the course of making the project.
  • Tachtastic
    • This is the main folder which contains the AVR Studio v4 solution, all source files and related files etc included. I tested it that it was compiling before uploading, so it should compile without any problem. I myself have gone through the code, it seems I had commented it when I was making the first time, so looks good enough and I am leaving the understanding of the code to you.
  • tachometer-01
    • Another AVR Studio v4 project, haven’t even seen the code, but seems relevant as it was in the same folder, maybe it is some older version of the code I was writing.

Phase and Integral Cycle AC Power Control with Arduino

Phase and Integral Cycle AC Power Control with Arduino
Phase and Integral Cycle AC Power Control with Arduino

What you see above is a project made for my Power Electronics Course, last term, finally completed and submitted. It is an AVR based board having 2 optically-isolated TRIACs for AC Power Control and implements both Phase Control and Burst Fire Control on each of the TRIACs. Controllable by an NEC IR Remote, shows status on Text LCD and the complete code was written in Arduino IDE [though there is some non-arduino/AVR code too].

The circuit above can be distributed into 3 parts, Power Supply, Controller and TRIACs.

Power Supply

The Power Supply for this board comes in the form of 220V AC from the wall outlet into the green terminal at the top-centre, which gets stepped-down by the transformer to 20V AC. The 20V AC is half-rectified by the 1N4007 diode [above the blue terminal] and is fed into the 15v regulator 7815 which feeds the next regulator 7805 to get a stable 5V DC supply for the controller circuitry.

The small white IC that you see is H11AA1 which detects the zero-crossings in the AC Line, I fed it stepped down AC supply [after the transformer]. It gives a pulse at every zero crossing and the whole AC Control relies on the signals coming from this IC. the Zero detect pulse goes to the INT0 pin of AVR, D2 pin on Arduino.

And what project would be complete without a Red LED to indicate Power.

Power Supply Portion - AC Supply to 5V DC with Zero Crossing Detection
Power Supply Portion: AC Supply to 5V DC with Zero Crossing Detection


Controller – AtMega8 / Arduino

I used an AtMega8 as the controller in this project running at 16MHz (hidden beneath the LCD) and programmed it via the Arduino IDE, using a USBasp programmer, the connector to the right is the ISP connector.

I used the Arduino environment as I wanted to use the IR Remote Library from AdaFruit and the LCD Library along with wanting to keep it simple and clean. The pinout of the LCD and the IR sensor (Black Component at the bottom) etc is provided in the arduino code, so I will not dwell in the schematic details here. It is to note that the IR remote I had was not working properly with the library so I had to do a few hacks in the original library. [code details in a later post]

Controller Portion - AtMega8 + LCD + IR = Arduino at 16MHz
Controller Portion: AtMega8 + LCD + IR = Arduino at 16MHz
[Download not found]


AC Power Control – TRIACs

This is the portion of the circuit which controls AC Power, the TRIACs used are BTA41 which are coupled to the controller by optical isolators MOC3011 (the white ICs). I am a bit paranoid when working with high voltage so I put up a plastic sheet over the 2 TRIACs and the bottom side is hidden with a card-sheet so no joints are exposed from below as well. Both TRIACs share teh same heat sink, an aluminum piece I found lying around, drilled it to use with the TRIACs. As labelled, one TRIAC controls the power by INtegral Cycle control method and the other uses Phase Control.

AC power Control Portion: TRIAC circuit + optical isolator + with plastic sheet and heatsink
AC power Control Portion: TRIAC circuit + optical isolator + with plastic sheet and heatsink

Code and other details on how the circuit is working will come in another post.

%d bloggers like this: