Controlling LED Brightness using Potentiometer CloudX

  • img
Project Details

Analog to Digital Conversion (ADC) is the ability to measure the input voltage on the microcontroller analog pin and convert this reading into a digital number between 0 and 1024 if 10-bit which translates in a precision of about 4.88mV when supplied with 5V from a power source. 

For example if the digital reading shows 600 that means the analog input is 2.93V. The analog input gives more insight than digital input because it gives you the precise value other than just detecting a high or low. The input voltage on the 5V pin on the cloudx board needs to be considered during the conversion in your code.

ADC values between microcontroller varies, the cloudx ADC pins are 10-bit which means it has the ability to read maximum of 1024 analog level. When the cloudx pin reads analog voltage 5v, it means the digital value is 1023 mathematically. Pin A0 – A5 on the cloudx board is assigned only for analog readings but the maximum input voltage on the pin must not be greater than 5V else it will damage the microcontroller.

For every ADC readings greater than 5V, a voltage divider is required especially when measuring a voltage greater than 5V.

Using a potentiometer (which is also known as variable resistor) for our project, let’s program the microcontroller so that an LED will come on when the analog input is greater than 3.5v and goes off when it’s lesser.

The voltage on the A0 pin changes when the potentiometer is adjusted.

The Analog_setting(); functionis used to initialize the ADC, the 

Analog_read(A0); is used to read from any analog pins on the cloudx, in our example we are reading from the A0. If the voltage on the A0 is greater than 3.5v which is 716 digital value then the LED on pin1 comes on and the voltage is less than 3.5v the LED goes off.


#include <CloudX\M633.h>
#include <CloudX\Adc.h>

int digitalValue;
           //setup here

           //Program here
           digitalValue = Analog_read(A0); 
           if(digitalValue > 716)  //from ADC calculation 1023/5 = x/3.5
              pin1 = HIGH;
                pin1 = LOW; 

Share this with friends