Firmware for a line-following robot based on the ATmega64 microcontroller.
The robot uses an array of 24 infrared (IR) sensors to detect the track, processes sensor data to calculate error, and controls the left and right motors using PWM for stable navigation.
This project was auto-generated with CodeWizardAVR V3.12 and then extended with custom control algorithms.
- 24-channel IR sensor array for line detection
- Digitalization of sensor values with configurable threshold
- Motor control via Timer1 PWM outputs
- PID-like control using proportional error (
kp) for smooth turns - LCD support (
alcd.h) for debugging and sensor monitoring - Utility functions for:
- Move forward, backward, left, right, stop
- Sensor calibration (optional, disabled in code)
- LCD output of sensor states
- Microcontroller: ATmega64 running at 8 MHz
- IR sensors: 24 arranged in left/right groups
- Motor driver: Controlled via
IN1,IN2, PWM outputs (OCR1A,OCR1B) - LCD (16x2 alphanumeric) for debugging
- Power stage: H-bridge or motor driver IC (e.g., L298/L293D)
- Main Loop
- Continuously reads sensor data
- Calls
controller()to compute error and adjust motor speeds
- Functions
ReadMp()→ Reads 24 sensors through a multiplexer and ADCcontroller()→ Calculates error from sensor weights, applies proportional controlMove()→ Drives motors with appropriate PWM valuesGo(),Left(),Right(),Back(),Stop()→ Motor primitiveslcd_show_sensor()→ Prints raw sensor values for debugging
- Each sensor has a weight (
E_L_i,E_R_i) indicating its position relative to the line. - The controller computes: