State Machine Controlled Transistor Project
Page 1 of 6
Abstract This report will describe the process to build a temperature
controlled cooling system using the SJSU ONE board. A
diagram of the circuit as well as the design methodology
will also be included to walk the reader through the design
process.
I. INTRODUCTION
This project will make use of the SJSU ONE
boards microcontroller in order to control a fan based on the
temperature in the room. The SJSU ONE board has several
general purpose input output (GPIO) pins that can be used
to send signals to various appliances. The GPIO pins
essentially control a current across the wires and therefore
through the appliance. When there is no current provided by
the microcontroller the appliance is off. Conversely, when
current is provided the appliance turns on.
II. DESIGN METHODOLOGY
In order to put this project together we used a single
GPIO pin on the SJSU board. With jumper wires this pin
was connected to a breadboard. The fan was then connected
to the same node through a transistor on the breadboard.
The ground pin was also connected to the ground wire of
the fan. This connection allows for the board to change the
voltage by creating potential differences along the path of
the circuit. The current through the fan is what powers it on.
Conversely, an absence of current provided by the board
would turn the fan off.
Since a 12-volt fan has been used the power from the
USB cable through the microcontroller would not be
enough to power the fan. In this case we had to use a
transistor and a 9-volt battery. A transistor would allow a
complete circuit between the fan and the batter while also
controlled the output through signals of the microprocessor.
If the microprocessor issued a stop signal through a change
in voltage of the connected pin the resistance of the
transistor would go so high as to stop current from running
through it. On the other hand, if the change in voltage
signaled a start then the resistance would drop again and the
circuit would continue to operate as normal.
Buttons on the SJSU ONE Board allow the user to
interact with an interface and select either an automatic
mode based on a pre-defined temperature threshold or
manual mode where the threshold can be changed
dynamically or the fan can be controlled on and off by the
user. Once the board turns on it goes into the start phase. By
pressing the first button the board then goes into Automatic
phase where the temperature threshold is predefined. By
pressing the second button the board goes into manual
mode. In this case the board can be turned on and off by
pressing the first and third switches respectively. The fourth
switch is then used to go back to automatic mode. From
here, the third button is used to go into configuration mode.
Here you can use the first and fourth buttons to increase or
decrease the threshold temperature. Finally, the second
button on the board can be pressed to go back to automatic
board. The code and state diagram which embody this
design can be found in appendix B and C respectively.
A. Parts List
SJSU ONE Board
Jumper Wires
12V Fan
Breadboard
USB Cable
9V Power Supply
MOSFET Transistor
B. Schematics
A schematic for this circuit design can be found in appendix
A.
III. TESTING PROCEDURES
Several tests were performed before and after construction
to ensure the operation integrity and durability of the
working model.
1. Test all the components individually to ensure that they all work. This testing can be done by testing each
component with just a batter attached and assuring that
current is going through the peripheral.
2. Test software procedures and ensure that programs could be uploaded to the SJSU One board. Other
Amir Jabbari and Altemush Bhatti,
CmpE 30 Fall 2015, Lab Section 01
Computer Engineering Department, College of Engineering
San Jose State University, San Jose, CA 94303
Temperature Controlled Cooler
Fo r R
ef er
en ce
O nly
. M ay
co nt
ain e
rro rs
.
Page 2 of 6
simpler programs were previously uploaded and tested
on the SJSU One board used in this experiment.
3. Test the completed circuit after assembly. This can be done by looking for the desired response. However, an
even more thorough testing process is to use a multi-
meter and test that each node has voltage in
comparison with the ground node, this ensures a
complete circuit.
4. Run circuit through various scenarios even extraneous boundary cases such as power immediately
disconnected or wrong button pressed.
5. Run tests multiple times over several days to ensure durability and sustainability of circuit design and
equipment.
IV. TESTING RESULTS
The initial tests supported the hypothesis that all the
components were working separately. The fan turned on
and off by application of currents and the 9V battery was
tested to have 7.8V still left by a multi-meter. Once the
circuit was put together it passed all the tests and didn’t act
out of the ordinary in any situation. Over the course of
several days the circuit was still functional and did not
show any signs of wear or detriment in functional quality.
V. CONCLUSION
The purpose of this lab was to create a temperature
controlled cooling system with the SJSU ONE board. Not
only has this purpose been fulfilled much has been learned
in the process. This lab has taught us basic circuit design,
how to work with transistors and how to program and work
with the SJSU one microcontroller. We did encounter some
problems when using the transistor at first because we
hadn’t looked at the data sheet. Even once we had the data
sheet we looked at it backwards and we were wondering
why the circuit wasn’t working. Perhaps the biggest lesson
taken away from this lab is to carefully read and analyze the
data sheets. I imagine that with even more complicated
circuits this concept becomes crucial to the design process.
Overall, this lab was a success and much was learned from
it. Both of us look forward to learning and working on
bigger things in the future.
Fo r R
ef er
en ce
O nly
. M ay
co nt
ain e
rro rs
.
Page 3 of 6
VI. APPENDICES AND REFERENCES
Appendix A: Circuit Diagram
Fo r R
ef er
en ce
O nly
. M ay
co nt
ain e
rro rs
.
Page 4 of 6
Appendix B: State Machine Diagram
START
AUTO
MANUAL CALIBRATION
FAN ON FAN OFF THRESHOLD TEMP +1
THRESHOLD
TEMP -1
BUTTON 1
BUTTON 2
BUTTON 3
BUTTON 4
BUTTON 1
BUTTON 1
BUTTON 3
BUTTON 2
BUTTON 4
Fo r R
ef er
en ce
O nly
. M ay
co nt
ain e
rro rs
.
Page 5 of 6
Appendix C: Source Code
#include <stdio.h>
#include "tasks.hpp"
#include "utilities.h"
#include "io.hpp"
int main(void)
{
typedef enum {start,autom,manual,calibration} myStateType;
myStateType currentState = start;
int temperature = TS.getFarenheit();
LD.setNumber(temperature);
while(1) {
delay_ms(100);
bool sw1_pressed = SW.getSwitch(1);
bool sw2_pressed = SW.getSwitch(2);
bool sw3_pressed = SW.getSwitch(3);
bool sw4_pressed = SW.getSwitch(4);
switch(currentState)
{
case start:
if( sw1_pressed )
{
currentState = autom;
printf("Current state: AUTO.\n");
}
break;
case autom:
if( temperature > 70 )
{
currentState = autom;
pin20.setAsOutput();
pin20.setLow();
motor1.set(0);
LE.on(1);
}
else { LE.off(1); }
if( sw2_pressed )
{
currentState = manual;
printf("Current state: MANUAL.\n");
}
if( sw3_pressed )
{
currentState = calibration;
printf("Current state: CALIBRATION.\n");
}
Fo r R
ef er
en ce
O nly
. M ay
co nt
ain e
rro rs
.
Page 6 of 6
break;
case manual:
if( sw1_pressed )
{
pin20.setAsOutput();
pin20.setLow();
motor1.set(0);
LE.on(1);
printf("Current state: FAN ON.\n");
}
if( sw3_pressed )
{
pin20.setAsOutput();
pin20.setHigh();
motor1.set(100);
LE.off(1);
printf("Current state: FAN OFF.\n");
}
if( sw4_pressed )
{
currentState = autom;
printf("Current state: AUTO.\n");
}
break;
case calibration:
if ( sw1_pressed )
{
temperature = temperature + 1;
LD.setNumber(temperature);
}
if ( sw4_pressed )
{
temperature = temperature - 1;
LD.setNumber(temperature);
}
if ( sw2_pressed )
{
currentState = autom;
printf("Current state: AUTO.\n");
}
break;
default:
printf("State machine ERROR!\n");
}
}
return 0;
}
Fo r R
ef er
en ce
O nly
. M ay
co nt
ain e
rro rs
.