# Exercises

The goal is to write a program which executes following task:

## Warm-up exercise

• The value of the resistance of the potentiometer is displayed on the LCD in ohms when the resistance of potentiometer is below 1000 Ω and kilo-ohms when above 1000 Ω. The nominal value of the resistance is 10 kΩ. Results show in the correct units, ohm mark as (Ohm).

## For beginners

1. Measuring the distance to an object. The distance to an object is measured with an IR sensor by pressing the button S1. During the measuring yellow LED is blinked. If the object is beyond 50 cm a green LED is lit and when the object is closer than 50 cm a red LED is lit.
2. The distance to an object is measured using an UH sensor. The result is displayed on the 7 segment display. If the distance is growing, the displayed value must grow respectively. The scale should be in decimetres (dm).
3. The value of the NTC temperature sensor is displayed on the LCD in degrees. By pressing the S2 button the units may be selected: Kelvin (K), Fahrenheit (F) and Celsius (C). The temperature is displayed in correct units and symbols.
4. By using a LDR sensor, rapid changes of light intensity are registered (switching lamps on-off). If the change is rapid, red LED is blinked for 5 seconds. If the light changes smoothly the direction of the change is shown. Green LED means that the light intensity grows and yellow shows that it diminishes.(Suggestion: the value of the sensor does not need to convert the lux, the calculations may be done using the direct ADC value.)
5. By using a PIR sensor and combined temperature-humidity sensor, create a simple program that shows a room ambient parameters: humidity, temperature and light intensity on the LCD screen when a person entering the room. If a person is leaving, the LCD display is cleaned and the program will enter standby mode.

1. Data recorder. The values of all analogue sensors (potentiometer, thermistor, and the photoresistor) are measured constantly and minimum and maximum values are recorded. By pressing button S1 the user may change the information displayed on the LCD. Displayed must be: name of the sensor (shortly) and present minimum and maximum values.
2. UH Distance sensor. If the button number S2 is pressed, 10 sequential measurements are taken place in one second. After measuring the average distance to the object in decimetres it is displayed on 7-segment indicator. By pressing button S1, minimum measured value is displayed and by pressing button S3 maximum value is displayed.
3. Velocity. According to the changing rate of the distance to the object (as measured by infrared or ultrasonic sensor), it is shown with LEDs as follows: slow change – green LED, moderate change – yellow LED and rapid change red LED. The speed may be displayed on the LCD.
4. By combining IR and ultrasonic distance sensors the distance to the object, velocity of the object and direction of the object are determined. Results are displayed on LCD.
5. Using the acceleration sensor detect the movement of an object and the direction of movement, which is displayed on a stripe with direction of the center of the LCD. The stripe length corresponds to the absolute value of the acceleration.

## Questions

1. How accurate is the digital-analogue converter (ADC) of ATxmega128A1U microcontroller? How small is the minimal change of input voltage which can be measured?
2. How long takes one ADC process? How is the operating frequency changed?
3. Which is the the range of input voltage of the ADC? Is it possible to be changed? How?
4. What is the difference between positive temperature coefficient (PTC) thermistor and negative temperature coefficient(NTC)? What are the advantages of each?
5. What is the purpose of a voltage divider in a measuring circuit?
6. Combine a voltage divider, which allows to use an analogue sensor with ATxmega128A1U microcontroller. The maximum output voltage of the sensor is 10 V.
7. Extra resistors were added to the potentiometer pins and voltage of 5 V were applied on them. How big must be the resistances of extra resistors and the potentiometer so the regulated voltage on the slider of the potentiometer can be regulated between 1 V and 2 V (from one end to the other end)? The current should not exceed 10 mA.
8. Which parameters of the surroundings have an effect on the functioning of ultrasonic distance sensor and why?
9. Which light sensitive sensors could be used in a robotics project. Count at least three principal components and explain their differences.
10. Besides trigonometrical method, how is distance determined by using light? Name at least 3 methods. 