Alcohol sensor example with WIZwiki-W7500
Dependencies: mbed
Fork of Seeed_Grove_Alcohol_Sensor_Example by
Prerequisite
This Program is an example of how to get analog data with WIZwiki-W7500 board A0 Pin.
To implement this function, you need a Platform board only.
- WIZwiki-W7500 from WIZnet (Platform board) http://wizwiki.net/wiki/doku.php?id=products:wizwiki_w7500:start
- Grove - Alcohol Sensor
Hardware Configuration
WIZwiki-W7500 Pin map
Initialize an analog pin
Initialize an A0 pin of WIZwiki-W7500 platform as an analog pin.
Read analog data from analog pin
Connect an analog device, such as an Alcohol sensor, to A0 pin. And read analog data.
Software
main.cpp
#include "mbed.h" DigitalOut heater(A1); AnalogIn sensor(A0); DigitalOut led_r(LEDR); DigitalOut led_g(LEDG); DigitalOut led_b(LEDB); int main(void) { float value = 0.0f; led_g = 0; led_r = 0; led_b = 0; heater = 0; wait(0.1f); // Waiting for the sensor to warm-up while(value > 0.001f) { wait(1.0f); value = 1.0f - sensor; printf("Sensor is warming up : %2.2f\r\n", value); } led_g = 1; led_r = 1; led_b = 1; while(1) { value = 1- sensor; printf("%2.1f\r\n", value); if(value < 0.3) { led_g = 0; led_r = 1; led_b = 1; } else if(value < 0.7) { led_g = 1; led_r = 1; led_b = 0; } else { led_g = 1; led_r = 0; led_b = 1; } wait(1); } }
Images
Before alcohol test
During alcohol test
Revision 1:2757e070a3c2, committed 2015-10-30
- Comitter:
- hjjeon
- Date:
- Fri Oct 30 01:00:33 2015 +0000
- Parent:
- 0:ac502eed91bf
- Commit message:
- Alcohol sensor example with WIZwiki-W7500
Changed in this revision
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 |
diff -r ac502eed91bf -r 2757e070a3c2 main.cpp --- a/main.cpp Fri Aug 15 21:25:14 2014 +0000 +++ b/main.cpp Fri Oct 30 01:00:33 2015 +0000 @@ -3,17 +3,57 @@ DigitalOut heater(A1); AnalogIn sensor(A0); +DigitalOut led_r(LEDR); +DigitalOut led_g(LEDG); +DigitalOut led_b(LEDB); + int main(void) { float value = 0.0f; - heater = 1; + + led_g = 0; + led_r = 0; + led_b = 0; + + heater = 0; + wait(0.1f); - while(1) { - heater = 0; - value = sensor; - printf("Sensor is: %2.2f\n", value); + + // Waiting for the sensor to warm-up + while(value > 0.001f) { wait(1.0f); + value = 1.0f - sensor; + printf("Sensor is warming up : %2.2f\r\n", value); + } + led_g = 1; + led_r = 1; + led_b = 1; + + while(1) + { + value = 1- sensor; + printf("%2.1f\r\n", value); + if(value < 0.3) + { + led_g = 0; + led_r = 1; + led_b = 1; + } + else if(value < 0.7) + { + led_g = 1; + led_r = 1; + led_b = 0; + } + else + { + led_g = 1; + led_r = 0; + led_b = 1; + } + wait(1); + } }
diff -r ac502eed91bf -r 2757e070a3c2 mbed.bld --- a/mbed.bld Fri Aug 15 21:25:14 2014 +0000 +++ b/mbed.bld Fri Oct 30 01:00:33 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68 \ No newline at end of file