The purpose of this project was to utilize a microcontroller to create a modulated light cycle of any period, and, with the added functionality that any point in the modulation cycle could be interrupted and reprogrammed from a smart phone. For instance, suppose you wanted to grow some sort of plant or vegetable under an LED lighting system, and perform various experiments. First you would need to create an on/off modulated light cycle in accordance to a particular period (24 hr cycle on earth, for example). Also, to simulate the earths natural day/night light intensity, the light source should follow an intensity profile, for example a Gaussian curve. For added control and functionality, If one wanted to adjust the light intensity similar to the natural light intensity on earth, you could simply use your smart phone to send the appropriate information to the microcontroller to interrupt its current light intensity. For example, by submitting 3:30 pm from the smart phone to the microcontroller, a corresponding light intensity would appear.
Step 1: Build and Connect Necessary Electronics
The attached electronic schematic encompasses a circuit that constitutes LED's, a microcontroller, and a Bluetooth module. This circuited is intended to control the illumination intensity of the LED's by implementing a pulsed width modulation (PWM) program in the microcontroller. A totem pole driver was used to fully open the gate of the field effect transistor (FET). The microcontroller was powered from a common source by using a voltage divider to set the voltage within the specification range for the MSP430. Pin 1.4 was used from the MSP430 as the PWM signal. The TX terminal from an RN 41 bluetooth module was connected to the RX UART terminal of the MSP430 G2553.
- NPN and PNP transistors
- high power field effect transistor (IRF540n)
- 32 kHz crystal (this comes with the MSP430 launchpad)
- TI MSP430 Launchpad
- MSP430 G2553 microcontroller
- RN 41 Bluetooth module
- 12 V LED's
- 12 V Power source
Step 2: Program the Microcontroller
There are two main parts to this program:
The program code is commented, please refer to it.
- A program that creates a modulated illumination cycle, which is linked to a master clock that keeps track of things. The master clock keeps time by a preset interruption period - by ANY period you desire! That is, it is interrupted and incremented by an amount based on the size of "modulation_step_period". Each time the master clock is interrupted, a variable called "intensity_index_counter" increments by 1. The index value of "intensity_index_counter" fetches a corresponding value from an array in the header file "Data.h" and passes it to "TACCR1". This array represent 1440 numbers on the basis of a 24 hour period (1440 = 24 hrs * 60 min/hr = x). Each value in the array represents the time the signal is active over the "PWM_Period" - this effectively is the duty cycle. Note that the numbers in the array are generated from a Gaussian formula: f(x) = ("frequency")*EXP(-0.5*((x-Xc/2)/100)^2).
- A program that receives a signal from the UART and reprograms the illumination intensity. Using the RX port on the microcontroller, bytes are fed in one-by-one from a Bluetooth module, and read by the microcontroller. If the size of the character is greater than 1 byte, then each byte is passed one-by-one into an array "Current_Time". Since the bytes are arriving as char type, they are then converted to int type and assigned to "true_time", which happens case-by-case. If the microcontroller receives any information from the UART a flag is raised "frame_received_flag" and the value of "intensity_index_counter" is overwritten by "true_time". *Note that the app written for sending bytes to the microcontroller sends 1, 2, 3, or 4 digit numbers encoded in ascii.
- The program code was compiled using Code Composer Studio.
Step 3: Build an App
I used MIT App inventor, which is very easy to learn, however it is clunky! See attachment for the app block code - unfortunately I could not find a way to export the code directly to a pdf file.
This program enables a user to (i) connect with a BT device, (ii) select any time of day, and (iii) submit this time of day to the BT module. In general, the program can send any 1, 2, 3, or 4 digit number. First the time of day (i.e., 11:30 am) is concatenated to a single number. Then this number (“Element”) is converted to an ASCII character (“new_Element”) selected from an array index, followed by transmission of a start byte “A”, sequentially ordered bytes representative of the selected time, and an end byte “X”. Each byte is read in from the UART of the MSP430 G2553 microcontroller and, depending on its length, each byte is converted from a char to an int type and then assigned to a global variable that is used to shift the intensity value of the PWM LED’s.
- Connect with BT module. Create “list picker” when-do blocks (before and after picking) as there may be multiple modules in range.
- Select time of day from “Time Picker”. Convert hour to minutes and consolidate with minute hand. This creates a number from 0 to 1440 in a 24 hour period, which is assigned to a variable.
- Create a large when-do if-then nested block structure that represents clicking the “submit current time of day” button. This block structure will look at the length of the value from the concatenated time the user selected and assign it to new variables. For example, if the time is 28 (meaning 12:28 am), the first digit would be assigned to the variable “Element1” and the second digit would be assigned to “Element2”, And so on. The remainder of the structure calls other programs, which contain the functionality for information to be sent over the BT module.
- As mentioned above, the nested block structure contains program calls. First in line is a call to a program that converts any digit from 0 to 9, which is originally assigned to the variable “Element”, to the appropriate ASCII character and assigns the new value to the variable “new_Element”. Next in line, in the case of a 2 digit number, would be another program call to convert the second digit. Third in line would be to send the start byte “A” character. Fourth in line is a call to a program that sends the first digit in a 1byteNumber. Fifth in line is as the preceding, however sending the second digit. Last in line is a call to send the end byte “X”.