Monday, January 6, 2014

Introduction to Analog Design (Workshop 3) - Detailed Guide

Guide Contents

I. Temperature Sensors
II. Transistors
III. DC Motor
IV. Demo Part 1: Assembling the Circuit
V. Demo Part 2: The Code

I. Temperature Sensors

A temperature sensor is made of a small, special resistor that changes its voltage drop based on the temperature of the sensor. It has three pins - HIGH, GND, and signal. A voltage is applied to the sensor to make it operational, and based on the temperature an analog value will be displayed at the signal pin. The Arduino's temperature library will convert that value to a digital value in Celsius that can be converted to Fahrenheit. 


II. Transistors

Arduino can only supply enough current to run sensors and small servo motors from its digital and analog pins. This isn't enough current to drive DC motors and other larger loads, so a DC amplifier is needed. A transistor acts as this DC amplifier in our workshop (transistors can be used in many other applications. This is just one use.) 

For this workshop we will be using an NPN BJT. The BJT has three terminals - a collector (positive voltage), an emitter (negative voltage or ground), and a base. The base is like a switch - put a voltage into this terminal from the Arduino and current will flow from the collector to the emitter.

Every BJT transistor has a Beta value, usually between 5 and 100. It equals the current amplification of the transistor. 





III. DC Motor

For a more thorough introduction to DC and other types of motors, see Workshop 4. For the following demo, a DC motor will be used. The DC motor provided in the kits includes two leads, HIGH and GND. when a voltage is applied to the motor it will spin continuously until the voltage is removed.


IV. Demo Part 1: Assembling the Circuit

Follow the schematic below when setting up your circuit. You might want a breadboard for this design. Make sure to check and double check your pin connections before turning on the board so you don't fry anything. The sensor and BJT pins are set in the below image if looking at them from the pin side of the device.




V. Demo Part 2: The Code



double val;
void setup()
{
     Serial.begin(9600);     //  setup serial
     pinMode(13, OUTPUT);
     pinMode(12, OUTPUT);
}

void loop() 
{
     val = analogRead(A0)-123;    // read analog input pin 3
     float Temp=CtoF(val);
     Serial.println(Temp);    // print to screen
 
     if (Temp > 85)
     {
         digitalWrite(13,HIGH);
         digitalWrite(12,HIGH);
     }
     else
     {
         digitalWrite(13,LOW);
         digitalWrite(12,LOW);
     }
     delay(1000);
}

double FtoC(double F)
{
   return ((F-32)*5)/9;
}

double CtoF(double C)
{
  return ((C*9)/5) + 32;
}

Use this code for the workshop. Initially, you will want to open up the serial monitor and calibrate the input temperature by changing the number in the line at the beginning of the loop() loop ( val = analogRead(A0)-123; - adujst 123). Get the serial monitor to start displaying values near room temperature and then pinch the temperature sensor with your fingers. As you see the temperature rise, once it surpasses 85 degrees the motor will turn on. If the motor drove a fan, then this would automatically cool down the environment until the temperature was back under 85 degrees, acting as a simple air conditioning circuit.

No comments:

Post a Comment