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
main.cpp@0:ac502eed91bf, 2014-08-15 (annotated)
- Committer:
- sam_grove
- Date:
- Fri Aug 15 21:25:14 2014 +0000
- Revision:
- 0:ac502eed91bf
- Child:
- 1:2757e070a3c2
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:ac502eed91bf | 1 | |
sam_grove | 0:ac502eed91bf | 2 | #include "mbed.h" |
sam_grove | 0:ac502eed91bf | 3 | |
sam_grove | 0:ac502eed91bf | 4 | DigitalOut heater(A1); |
sam_grove | 0:ac502eed91bf | 5 | AnalogIn sensor(A0); |
sam_grove | 0:ac502eed91bf | 6 | |
sam_grove | 0:ac502eed91bf | 7 | int main(void) |
sam_grove | 0:ac502eed91bf | 8 | { |
sam_grove | 0:ac502eed91bf | 9 | float value = 0.0f; |
sam_grove | 0:ac502eed91bf | 10 | heater = 1; |
sam_grove | 0:ac502eed91bf | 11 | wait(0.1f); |
sam_grove | 0:ac502eed91bf | 12 | |
sam_grove | 0:ac502eed91bf | 13 | while(1) { |
sam_grove | 0:ac502eed91bf | 14 | heater = 0; |
sam_grove | 0:ac502eed91bf | 15 | value = sensor; |
sam_grove | 0:ac502eed91bf | 16 | printf("Sensor is: %2.2f\n", value); |
sam_grove | 0:ac502eed91bf | 17 | wait(1.0f); |
sam_grove | 0:ac502eed91bf | 18 | } |
sam_grove | 0:ac502eed91bf | 19 | } |