Software

Goals and Design Decisions

After discussing options such as controlling the mechanism with buttons or with USB to a laptop computer, the group decided to build a system that was as autonomous as possible.  Avoiding USB simplified the firmware, because the microcontroller need only communicate with a few sensors and a servo motor.

Programming a PIC

The PIC Source Code

The entire circuit is controlled with a PIC18F2455 microcontroller, which can be programmed in C.  We used the MPLAB IDE to compile code and build hex files that could be written onto the PIC, and we transferred these files to the PIC using a PICkit 2 programmer. The goal of the code is to cause the blinds to react as descibed in the figure below.

code

The circuit depends on the PIC’s plethora of pins that can read analog voltage values and convert these to digital values.  We were introduced to the A/D converters earlier in the Principles of Engineering course, and within this project we used A/D conversion for readings from photoresistors, temperature sensors, and other circuitry components.  However, the final design includes just two pins as analog inputs: one photoresistor and one temperature sensor.

The PIC reads these pins about twice a second to determine the conditions in the room, and the values are written to variables that the PIC can use to make decisions.  From the conditions, the PIC decides whether the blinds should be open or closed.  Then, we use digital output pins in the PIC to control the servo that turns the blinds.  If the blinds need to turn, the PIC tells a transistor to allow power to the servo and sends the servo a pulsed signal to tell which direction to turn. Sending a pulse of the appropriate width at the appropriate frequency requires some fiddling with a quartz oscillator and the PIC’s timer0 module, but this was a skill we were comfortable and familiar with from the first part of the course.

 

Improvement

The way the PIC tells whether the blinds are opened or closed in this system is through a variable that increments itself up or down as the blinds are open or closed.  Such a system is subject to compounding error and vulnerable to power outages, and replacing it with a tilt sensor input for the blinds would make the product far more reliable.