All Tutorials / Steve G / Using ADC (Analog to Digital) Ports, Commands and Controls.

Using ADC (Analog to Digital) Ports, Commands and Controls.

Step 6. ADC Example with Smoke Sensor.

This is an example using a smoke detection sensor module and an ADC Graph control, and a script that responds to specific ADC readings.

1.) Connect the smoke sensor module to an analog port on the EZ-B (This example will use "A0"). Then power up the EZ-B.

2.) Open EZ-Builder, then from the menu ribbon, click "Project", "Add controls", "ADC", then "ADC Graph" to add this to your project. Do the same, and add an "ADC Value" control as well.

User-inserted image


3.) On the "ADC Graph" and "Value" controls, click on the gear icon to open the configuration menu, and select the port the sensor is connected to, then click "Save".

User-inserted image

4.) Now use a source to make smoke, and wave the smoke fumes in front of the sensor. You should now see the values change in the control windows. (Please take care with whatever source you are using to make the smoke with. Remember the old saying, "There's no smoke without fire").

5.) The more smoke that is detected, the higher the ADC values will reach. Make a note of the readings from the "ADC Value" control with a small amount of smoke, and a larger amount of smoke.

Now to make the smoke detector useful.

6.) From the menu ribbon, press "Project", "Add controls", "Scripting", then "EZ-Script" to add this to your project.

User-inserted image

7.) Open the script configuration menu, and write or copy/paste the following script...

Code:

:loop
#Read's the value on EZ-B port A0
$smoke=getADC(adc0)

#Will detect LOW level smoke over 40
#Change the values if necessary.
if($smoke>40)
saywait("I am now sensing smoke, or gas fumes in the area.")
Sleep(10000)

#Will detect HIGH level smoke over 60
elseif($smoke>60)
saywait("Warning. I am now sensing an increased level of smoke, or gas fumes in the area.")
endif
goto(loop)



You can adjust the script above, and add a "greater than" 40 and "less then" 59 in the first half of the script, so only low levels of smoke will be detected. Anything over 60, and the second half will run. (Unable to post this example as using the greater than and less than symbols in this document. See screenshot below)...

User-inserted image

Below, is a video demonstration showing the smoke sensor using both the "ADC Read" and "Script" controls in action...



And below is another video demonstration of the smoke sensor being used on a robot...



The next step will guide you through using sound sensors on an analog port. sound sensor