temperature and pressure sensor
Dependencies: BMP180 beep N5110 PowerControl mbed
Revision 0:0d59691c1dd5, committed 2015-05-12
- Comitter:
- T_AlKurdi
- Date:
- Tue May 12 23:00:47 2015 +0000
- Commit message:
- final code
Changed in this revision
diff -r 000000000000 -r 0d59691c1dd5 BMP180.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BMP180.lib Tue May 12 23:00:47 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/eencae/code/BMP180/#0e92710a46f9
diff -r 000000000000 -r 0d59691c1dd5 Beep.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Beep.lib Tue May 12 23:00:47 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/dreschpe/code/beep/#d8e14429a95f
diff -r 000000000000 -r 0d59691c1dd5 N5110.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/N5110.lib Tue May 12 23:00:47 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/eencae/code/N5110/#ba8addc061ea
diff -r 000000000000 -r 0d59691c1dd5 PowerControl.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PowerControl.lib Tue May 12 23:00:47 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/JST2011/code/PowerControl/#d0fa2aeb02a4
diff -r 000000000000 -r 0d59691c1dd5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue May 12 23:00:47 2015 +0000 @@ -0,0 +1,113 @@ +/** +@file main.cpp +@brief Program implementation + +*/ + +#include "main.h" + + + +void buttonPressed() { + buttonFlag=!buttonFlag; + } + +int main() +{ + + /// initiliase the barometer + + bmp180.init(); + lcd.init(); // initialise display + + lcd.printString("Welcome to",15,1); // display text on screen + lcd.printString("Weather Station",20,2); + lcd.printString("Project",6,3); + lcd.printString("Tarek I. AlKurdi",0,5); + wait(5.0); // wait for 5 seconds before refreshing the LCD to display the temperature + + lcd.clear(); + lcd.refresh(); + + + button.rise(&buttonPressed); + + while(1) { + + lcd.setBrightness(1.0); // put LED backlight on full + + P = mypotentiometer; + lcd.setBrightness(P); + + if(buttonFlag) { + + + lcd.clear(); + lcd.refresh(); + + char buffer[14]; + + Measurement value; // measurement structure declared in BMP180 class + value = bmp180.readValues(); + wait(0.1); + + int length = sprintf(buffer, "T = %.2f K", value.temperature+273); // configuration of celsis to kelvin conversion + if (length <= 14) + lcd.printString(buffer,0,1);// display value on LCD screen + wait(0.1); + + length = sprintf(buffer, "P =%.2f P", value.pressure/1000); // coverting mili Pascal to pascal + if (length <=14) + lcd.printString(buffer,0,2); // display the value on the LCD screen + wait(0.1); + + } + else{ + + lcd.clear(); + lcd.refresh(); // refresh the screen + + char buffer[14]; + + Measurement value; // measurement structure declared in BMP180 class + value = bmp180.readValues(); // set the value to the sensors reading + wait(0.1); + + int length = sprintf(buffer, "T = %.2f C", value.temperature); + if (length <= 14) + lcd.printString(buffer,0,1); // Display the temperature on the first line + wait(0.1); + + length = sprintf(buffer, "P =%.2f mP", value.pressure); // Display the pressure on the 2nd line under the temp. + if (length <=14) + lcd.printString(buffer,0,2); + wait(0.1); + //lcd.refresh(); + } + + Measurement value; // measurement structure declared in BMP180 class + value = bmp180.readValues(); // set values of sensor reading on the screen + wait(0.1); + + + if (value.temperature>22 && value.temperature<=28) { // if the temp is between 22 and 28 celsius + greenled= 0; // LED OFF + redled=1; // LED ON + } + + else if (value.temperature>28 && value.temperature<=31) { // if temp. between 28 and 31 celsius + greenled=1; //LED ON + redled=0; // LED OFF + } + + else { + greenled=0; // LED OFF + redled=0; // LED OFF + buzzer.beep(1000,0.5); // Buzzer will be activated when the temp increases above 31 celsius + } + + wait(0.01); + + } + + } \ No newline at end of file
diff -r 000000000000 -r 0d59691c1dd5 main.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Tue May 12 23:00:47 2015 +0000 @@ -0,0 +1,58 @@ +/** +@file main.h +@brief Header file containing functions prototype, defines and global variables +@brief Revision 1.0. +@author Tarek I. AlKurdi +@date May 2015 + +*/ + +#include "mbed.h" +#include "BMP180.h" +#include "N5110.h" +#include "beep.h" +#include "PowerControl/PowerControl.h" +#include "PowerControl/EthernetPowerControl.h" + + +Serial serial(USBTX,USBRX); +N5110 lcd(p7,p8,p9,p10,p11,p13,p26); // VCC, GND, SCE, RST, DC, MOSI, CLK, LED + +InterruptIn button(p16); +/** +@namespace button +@output for status button +*/ +AnalogIn mypotentiometer(p20); +/** +@namespace mypotentimeter +@output for status potentiometer +*/ +Beep buzzer(p21); +/** +@namespace buzzer +@output for status buzzer +*/ +BMP180 bmp180(p28,p27); // SDA, SCL + +PwmOut greenled(p23); // Green LED +/** +@namespace greenled +@output for status Green +*/ + +PwmOut redled(p24); // RED LED +/** +@namespace redled +@output for status red +*/ +Measurement value; + + + + +float P; + +int buttonFlag=0; + +#endif
diff -r 000000000000 -r 0d59691c1dd5 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue May 12 23:00:47 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8ab26030e058 \ No newline at end of file