ATMega328 Led Blink + Fan control (PWM) Project (In progress)

Thread Starter


Joined Sep 24, 2019
Hello everyone,

After lurking on this forum for years now (I'm currently on my senior year) I decided to create an account since I need help / 2nd opinions or suggestions for my big final project. I'm making a basic project with an ATMega328:

---Brief Explanation---

I need to use an ATMega (in this case, I chose to go with the 328p version + an external 16Mhz crystal) and create a program (and build it) where I have a 1Hz square wave output (I connected a LED in order to simplify this step - 500ms the led is on / 500ms the led is off) + a basic PWM control (I'm thinking about using a fan / motor in order to change it's speed via PWM - i.e. pressing switch 1 will increment pwm in 10, pressing switch 2 will decrement pwm in 10, pressing switch 3 will force pwm to 50, pressing switch 4 will force pwm to 100, pressing switch 5 will force pwm to 0).

At the moment I (think) I've made the first step and completed the led / square wave output code (image below). I also built my circuit on a breadboard (image below) aswel as in a schematic (didn't simulate, didn't had the time yet; image below). If this is alright, I'm missing the PWM part and that's it.

My issue here is:

Since I can only test it next week, is the code fine (schematics aswell)? I can't seem to understand how the debug function on Atmel Studio works (my last time messing around with microcontrollrers was 1 year ago. Since then I had 1 or 2 projects in arduino so I kinda forgot some basic ATMega things).
Also, it would be helpful to replace the voltage source (10V in the beggining of the circuit) with some sort of battery, etc. so I could experiment the circuit at home. Any idea if that's something hard to find / implement?



Joined Mar 10, 2018
Not a C writer for Atmega so cannot offer any advice on your
code. But for future reference, for simple projects, here is a
fast way of creating a PWM controlled load, in this case a FAN.

Basically POT V on wiper controls PWM. The V is read by internal
A/D and that result written to PWM control f() in Arduino.

Note ATTINY85 shown, but ATMEGA would work just fine, using
a UNO or Nano or Mega board.

Used mBlock (below) to do the coding, a drag and drop GUI IDE that translates block coding
to Arduino code. Blocks are dragged out of catalog (2'ond window from left) into coding area
(second window from right) and then when upload button code is generated (right hand window)
and programmed into part/board.

Regards, Dana.


Last edited: