Saturday 18 November 2017

MSP430G2553 with a Light Dependent Resistor

In this tutorial, we will connect a Light Dependent Resistor to an MSP430 and turn ON the LED connected to Port 1, pin 0 if the light is below a threshold value else we will turn it OFF.

The LDR is connected to Port 1, pin 7 (configured to act as input channel for the ADC). The SAR ADC on MSP430 converts the analog values supplied by the LDR to digital values.

As displayed in the video (link given below), the LDR is connected in a voltage divider circuit with a 10K Ohms resistor. The detailed theory about the operation of the voltage divider circuit and the formula for calculating the voltage due to variation in resistance of the LDR can be found on: http://robotics.hobbizine.com/ldrlaunch.html

Youtube video link: Demo Video

#include <msp430.h>

unsigned int value = 0;

void ConfigureADC(void)

{
ADC10CTL1 = INCH_7 + ADC10DIV_0;
ADC10CTL0 = SREF_0 + ADC10SHT_2 + ADC10ON + ADC10IE;
ADC10AE0 |= BIT7;
}

void ConfigurePins(void)
{
P1OUT = 0;
P1DIR |= BIT0;
}

void main(void) {

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

BCSCTL1 = CALBC1_1MHZ;

DCOCTL = CALDCO_1MHZ;

ConfigurePins();

ConfigureADC();

while(1)

{

ADC10CTL0 |= ENC + ADC10SC;

__bis_SR_register(CPUOFF + GIE);

value = ADC10MEM;

if(value <= 511)

{

P1OUT |= BIT0; //turn ON the Light

}

else

{

P1OUT &= ~BIT0; //turn if OFF

}

}

}

#pragma vector = ADC10_VECTOR

__interrupt void ADC10_ISR(void)

{

__bic_SR_register_on_exit(CPUOFF);

}

You may use this circuit with a bulb and power the circuit with a solar panel during day time and use the saved power to turn ON the bulb after evening. Another interesting project along similar lines is: Solar Powered Project using MSP430
Kindly comment if you want to know anything specific about the H/W or S/W part!
Next post will be on an MSP430 + Bluetooth low energy module!

No comments:

Post a Comment