Temperature controlled fan with hysteresis cooling

Dependencies:   Motor mbed

Files at this revision

API Documentation at this revision

Comitter:
bryanbates
Date:
Thu Dec 08 19:58:11 2016 +0000
Commit message:
Final Project for 4180

Changed in this revision

Motor.lib Show annotated file Show diff for this revision Revisions of this file
TMP36.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Thu Dec 08 19:58:11 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Motor/#f265e441bcd9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TMP36.h	Thu Dec 08 19:58:11 2016 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+
+//Setup a new class for TMP36 sensor
+class TMP36
+{
+public:
+    TMP36(PinName pin);
+    TMP36();
+    operator float ();
+    float read();
+private:
+//class sets up the AnalogIn pin
+    AnalogIn _pin;
+};
+
+TMP36::TMP36(PinName pin) : _pin(pin)
+{
+// _pin(pin) means pass pin to the AnalogIn constructor
+}
+
+float TMP36::read()
+{
+//convert sensor reading to temperature in degrees C
+    return ((_pin.read()*3.3)-0.500)*100.0;
+}
+//overload of float conversion (avoids needing to type .read() in equations)
+TMP36::operator float ()
+{
+//convert sensor reading to temperature in degrees C
+    return ((_pin.read()*3.3)-0.500)*100.0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 08 19:58:11 2016 +0000
@@ -0,0 +1,48 @@
+#include "mbed.h"
+#include "TMP36.h"
+#include "Motor.h"
+#include <math.h>
+
+TMP36 tempSensor(p15);  // Uses TMP36.h to display temperature in Celcius
+Serial xbee1(p28, p27); // TX, RX
+Motor m(p21, p19, p20); // pwm, fwd, rev
+DigitalOut rst(p11); // RST (RESET)
+DigitalOut redLED(p5);
+
+
+
+
+char *float2str(float float_num);
+
+int main(){
+    rst = 0;
+    wait_ms(1);
+    rst = 1;
+    wait_ms(1);
+    
+    float temp = 0.0;
+    float fanspeed;
+    float fanratio;
+    
+    xbee1.baud(9600);
+    
+    while (1){
+        temp = tempSensor;
+        if (temp > 26.0){
+            fanratio = temp/26;
+            fanspeed = exp(fanratio) - 2.2;
+            redLED = 1;
+        }
+        else{
+            fanspeed = 0.0;
+            redLED = 0;
+        }
+        m.speed(fanspeed);
+        
+        xbee1.printf("%.1f\n\r",temp);
+        wait(1);
+    }
+    
+}
+
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 08 19:58:11 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file