$29
Objective:
To learn how to program the ATmega Analog to Digital Converters by initializing and using the appropriate special function registers. You will develop two functions, adc_init, and adc_read, and a program which uses the two functions to read analog data from a photoresistor and sends the data over serial to a PC.
Procedure:
1. Read chapter 8 of the textbook and browse section 26 of the Atmel 2560’s datasheet, paying extra attention to sections 26.2, 26.3, 26.4, and 26.8.
2. Write two ANSI C functions:
1. void adc_init( ) – Initializes the Analog to Digital Converter to be ready to read analog data.
2. unsigned int adc_read(unsigned char adc_channel) – Returns the analog data read from the analog channel given as a parameter.
3. Connect a photoresistor and an axial resistor in series as a voltage divider and write a program which reads the analog voltage of the divider and sends the voltage values over serial to your PC. Use the Arduino IDE’s Serial Plotter to plot the voltage values.
4. Modify the program to turn on the on-board LED when the light level is above some threshold.
Notes:
1. ALL programs written for this course need to be documented in a complete manner which will make sense to you if you need to go back and review the program a year or two from now. You need to include your NAME and a revision number on ALL programs as well.