PadhaikoAll subjects

Past exam question: Assignment 3, Q10

Instrumentation · 5 marks

Open in the Padhaiko app

Topic: Microcontrollers (Atmega328, STM32): Architecture, pin configuration…

Question

Explain Atmega328 application with interfacing example.

Solution

Key Applications of ATmega328 in Instrumentation: Because it integrates a 10-bit ADC, hardware timers/PWM, USART/I²C/SPI buses, and 23 GPIO pins in a single low-cost 28-pin IC, the ATmega328 is widely used in:

  1. Sensor Data Acquisition & Telemetry: Reading analog transducers (temperature, humidity, light, pressure) and transmitting readings over UART/I²C/SPI.
  2. Closed-Loop Motor & Heater Control: Generating PWM waveforms to regulate DC motor speed, servo position, or heating power.
  3. Industrial & Smart Home Automation: Relay switching, keypad/LCD user interfaces, and smart energy monitoring.
  4. Portable Battery-Operated Loggers: Leveraging low-power sleep modes for periodic environmental sampling.

Interfacing Example: Automated Temperature-Controlled Fan (LM35 + DC Fan via Transistor):

ATmega328 Interfacing Circuit: LM35 Sensor & PWM FanText
               +5V
                |
        +-------+-------+
        | 1:Vcc         |               +12V
      [LM35]            |                |
        | 2:Vout -----> PC0 (ADC0)    [DC Fan]===+ (1N4007 Flyback Diode)
        | 3:GND         |                |       |
       GND        ATmega328P             +-------+
                        |                | Collector
                   PD3 (OC2B) --[1k]--|(B) NPN Transistor (TIP120/2N2222)
                        |                | Emitter
                   PB5 (D13) --[330]--|>|--GND

Interfacing Program (C / Arduino Sketch): The 10-bit ADC maps to :

ATmega328 Temperature-Controlled Fan ExampleC
const int TEMP_PIN = A0;   // PC0 (ADC0)
const int FAN_PWM  = 3;    // PD3 (OC2B)
const int LED_PIN  = 13;   // PB5

void setup() {
  pinMode(FAN_PWM, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int raw = analogRead(TEMP_PIN);
  float tempC = (raw * 5.0 / 1024.0) * 100.0;

  if (tempC < 25.0) {
    analogWrite(FAN_PWM, 0);     // Fan OFF
    digitalWrite(LED_PIN, LOW);
  } else if (tempC < 35.0) {
    analogWrite(FAN_PWM, 140);   // Medium speed (~55% duty)
    digitalWrite(LED_PIN, LOW);
  } else {
    analogWrite(FAN_PWM, 255);   // Full speed (100% duty)
    digitalWrite(LED_PIN, HIGH); // High-temperature alert
  }
  Serial.println(tempC);
  delay(500);
}
Answer:

The ATmega328 is widely applied in sensor telemetry, closed-loop control, and automation. In a typical temperature-controlled fan interface, an LM35 analog sensor connects to ADC0 (PC0), the 10-bit ADC computes temperature , and PWM pin PD3 (OC2B) modulates a transistor driver (with flyback diode) to regulate fan speed while PB5 signals over-temperature.

All past exam questions for Instrumentation