0
0
Embedded Cprogramming~20 mins

Sensor reading through ADC (temperature, light) in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ADC Sensor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this ADC temperature reading code?

Consider this embedded C code snippet that reads a temperature sensor value through ADC and converts it to Celsius. What will be printed?

Embedded C
#include <stdio.h>
#define ADC_MAX 1023
#define V_REF 5.0

int read_adc() {
    return 512; // Simulated ADC value
}

int main() {
    int adc_value = read_adc();
    float voltage = (adc_value * V_REF) / ADC_MAX;
    float temperature_c = (voltage - 0.5) * 100;
    printf("Temperature: %.1f C\n", temperature_c);
    return 0;
}
ATemperature: 200.2 C
BTemperature: 50.0 C
CTemperature: 0.0 C
DTemperature: 100.0 C
Attempts:
2 left
💡 Hint

Calculate voltage first, then apply the formula for temperature.

Predict Output
intermediate
2:00remaining
What is the light intensity output from this ADC reading?

This code reads a light sensor value from ADC and converts it to a percentage of light intensity. What will be printed?

Embedded C
#include <stdio.h>
#define ADC_MAX 1023

int read_adc() {
    return 256; // Simulated ADC value
}

int main() {
    int adc_value = read_adc();
    float light_percent = (adc_value * 100.0) / ADC_MAX;
    printf("Light Intensity: %.1f%%\n", light_percent);
    return 0;
}
ALight Intensity: 100.0%
BLight Intensity: 50.0%
CLight Intensity: 25.0%
DLight Intensity: 75.0%
Attempts:
2 left
💡 Hint

Calculate the percentage by dividing ADC value by max ADC value.

🔧 Debug
advanced
2:00remaining
What error does this ADC temperature conversion code produce?

Examine this code snippet that attempts to convert ADC reading to temperature. What error will it cause?

Embedded C
#include <stdio.h>
#define ADC_MAX 1023
#define V_REF 5.0

int main() {
    int adc_value = 600;
    float voltage = adc_value / ADC_MAX * V_REF;
    float temperature_c = (voltage - 0.5) * 100;
    printf("Temperature: %.1f C\n", temperature_c);
    return 0;
}
ATemperature: 2.4 C
BTemperature: -50.0 C
CTemperature: 0.0 C
DTemperature: 294.0 C
Attempts:
2 left
💡 Hint

Check the order of operations and data types in the voltage calculation.

📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in ADC reading code?

Identify which code snippet will cause a syntax error when compiling.

Afloat voltage = (adc_value * 5.0) / 1023;
Bfloat voltage = adc_value * 5.0 / 1023;
Cint adc_value = read_adc(); float voltage = (adc_value * 5.0) / 1023;
Dint adc_value = read_adc() float voltage = (adc_value * 5.0) / 1023;
Attempts:
2 left
💡 Hint

Look for missing semicolons or punctuation.

🚀 Application
expert
2:00remaining
How many distinct temperature values are possible from this 10-bit ADC?

A 10-bit ADC reads a temperature sensor. How many distinct temperature values can the system represent if the ADC output is directly converted to temperature using a linear scale?

A1024
B512
C2048
D1000
Attempts:
2 left
💡 Hint

Recall how many values a 10-bit number can represent.