Share My Creation eBreathalyzer : wifi enabled cheap eBAC sensor

Hi all,

Again a small IoT device showing clearly all the power of ESP8266 chip and B4A.

It's just a MQ-3 gaz sensor UDP connected to my Android.
A little calibration, a nice gauge and that's it

See it in action !


and remember... BoM is less than 20$ :)

[updated 05/12/2015] I have just received Pcbs from seeedstudio

The result is really good for a very cheap price.
pcb_double_sided2.jpg
 

Attachments

  • eBreathalyzer.jpg
    eBreathalyzer.jpg
    74.5 KB · Views: 10,003
Last edited:

freedom2000

Well-Known Member
Licensed User
Longtime User
How does it work ?

Have a look to this great explaination. You will see that MQ-3 sensor is composed of a heater and two electrods
MQ-3_opened.jpg


The heater is evaporating the alcool which reacts on the electrods
"Then, when the alcohol molecules in the air meet the electrode that is between alumina and tin dioxide, ethanol burns into acetic acid then more current is produced. So the more alcohol molecules there are, the more current we will get. Because of this current change, we get the different values from the sensor."

If you feed this current into a resistor divider (R8, R9) then you can estimate the BAC level in your blood.

MQ3.png


Heater drives quite a lot of current... the sensor gets 60°C.
I have added a mosfet to switch On/Off the heater when the App is pausing or closed.

The voltage divider is setup in order to have a max 1V voltage sent to the ADC (limitation of ESP8266...)

This setting is not very precise... sensor is sensitive to other gas than Alcohol

MQ3_curves.jpg


So do not expect to have a professional breathalyzer...
However with a little calibration the results are really useful. That's the reason why I have added "zero calibration" and "drunked calibration" parameters.

The software side is quite simple :
  • ESP8266 exposes a Wifi "Access Point".
  • You can connect your Android on this AP and launch the app
  • The App will first broadcast a UDP message and ESP8266 should answer
  • inside the app you can send to ESP8266 your router SSID and password
  • Next time ESP8266 will try to access your router. If it fails then it will jump to Access Point again.
 
Last edited:

imbault

Well-Known Member
Licensed User
Longtime User
Hi JP,

Very interesting, did you built the hardware part yourself or can it be found somewhere?

Patrick
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Hi Patrick,

Yes I fully designed the hardware and the pcb.
The cheap MQ-3 boards sold on ebay are 5V devices with an output between 0 and 3.5V roughly.

ESP8266 ADC only accepts 1V max.

So I have been obliged to hack the ebay board !
And now I have a fully compact board powered via USB power banks and totally wireless !

I believe that this "Wifi MQ-3 sensor" is quite unique (for the moment)

Same design could be used to detect methane leakage.
ESP8266 being fully "internet connected" it becomes easy with the same board to have a gas detector alarm triggering a mail or a pusbullet on your phone.
 

imbault

Well-Known Member
Licensed User
Longtime User
@freedom2000 , did you make that prototype like a hobby or do your have other plans.
BTW, you'r french like me, I live in Paris, and you?

Patrick
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Just a hobby :)

et j'habite à Toulouse.
Si intéressé par une carte --> PM !
 

Danbicky

Member
Licensed User
Longtime User
Hi Freedom,

My posts before seem to have disappeared? I am danbicks from ESP8266 please let me know when you can see this post. I am not sure if moderation has removed my prior posts.

Regards

Dans
 

Danbicky

Member
Licensed User
Longtime User
Brilliant, woo my post's are getting through.

Can you mail me the android App and I would love to look at the Ino code as well if possible. This is an excellent project, my needs will be using UDP to control my garden lighting system. I have the hardware all fired up, using IRF540 mosfet's for PWM on 5 chans all controlled by an ESP, incorporated also is MQTT control and web configuration. I am more than happy to share this with you in return.

Last night I fired up my b4a version 2.50 to get my head back in to it. It is not to bad basic is pretty easy, I will ping Erel a mail and see if I can pay a fee to upgrade to the latest version of b4a.

So looking forward to getting my project of the ground. A massive thanks.

Dans
 

Danbicky

Member
Licensed User
Longtime User
Hi JP,

Any chance of a link for the android code, I am now all back up and operational on this forum. Can you mail this to me or is there another method you prefer for file transfer?.

A massive thanks again.

Dans
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Brilliant, woo my post's are getting through.

This is an excellent project, my needs will be using UDP to control my garden lighting system. I have the hardware all fired up, using IRF540 mosfet's for PWM on 5 chans all controlled by an ESP, incorporated also is MQTT control and web configuration. I am more than happy to share this with you in return.

A massive thanks.

Dans

Hi Dans,

Here is the code used to connect UDP with a broadcast message, to get IP address of the ESP8266 and then to send/receive packets with this address :


B4X:
Sub Process_Globals
    Dim UDPSocket1 As UDPSocket
    Dim Server As ServerSocket
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim ButtonSend As Button
    Dim EditData As EditText
    Dim EditDest As EditText
    Dim LbReceived As Label
    Dim Timer1 As Timer
    Dim DestAddress As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        UDPSocket1.Initialize("UDP", 6000, 8000)
    End If
    Activity.LoadLayout("udp")
End Sub

Sub Activity_Resume
    Timer1.Initialize("Timer1", 400)
    UDPConnect
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Timer1.Enabled = False
End Sub

Sub UDP_PacketArrived (Packet As UDPPacket)
    Dim msg As String
   
    msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
    'Msgbox("Message received: " & msg , "")
    LbReceived.Text = msg
    Try
        'Msgbox(" from host " & Packet.HostAddress, "")
    Catch
        Msgbox(" error from host ", "")
    End Try
    If msg = "eBreathalyzer" Then
        Timer1.Enabled = True
        DestAddress = Packet.HostAddress
    End If
   
End Sub

Sub ButtonSend_Click
    UDPConnect
    ToastMessageShow("Message send = " &EditData.Text, False)
End Sub

Sub Timer1_Tick
    Dim Packet As UDPPacket
    Dim Dest As String
    Dim data() As Byte
    data = EditData.text.GetBytes("UTF8")
    Dest = DestAddress
    Packet.Initialize(data, Dest, 6000)
    UDPSocket1.Send(Packet)
    'ToastMessageShow("Message send = " &EditData.Text, False)
End Sub

Sub UDPConnect
    Dim Packet As UDPPacket
    Dim Dest As String
    Dim data() As Byte
    data = "ID".GetBytes("UTF8")
    Dest = "255.255.255.255"
    Packet.Initialize(data, Dest, 6000)
    UDPSocket1.Send(Packet)
End Sub
 

Danbicky

Member
Licensed User
Longtime User
JP, this is awesome buddy a massive thanks, I will try some of this code on my old version but still intend to upgrade this as I think there is a lot more options on the later version and a nicer user interface.

How do you save the settings such as Server IP, port etc, I can't see this option in your code?

Big thanks buddy look forward to tinkering with this, so much to learn about this platform.

Dans
 

freedom2000

Well-Known Member
Licensed User
Longtime User
How does the network work? Does it require both devices to be connected to the same router?
Well yes and no :)

The ESP8266 app is first trying to connect to a router, if it fails then it jumps to "access point mode". It exposes a wifi access point and listen to UDP messages.
The android can connect to this hotspot (standard wifi settings) and the app automatically tries to connect to the ESP (UDP message)
When the connection is achieved, a menu into the App allows to setup the router SSID and Password, to send it to the ESP8266 board which will reset and perform the connection to the router.

Well to summarize, both AccessPoint and Router modes are working together in an easy user friendly way.
 

Vrayn

New Member
This is brilliant! I just stumbled upon your project and instantly wanted to to this.
Sadly I just started programming with the ESP8266. Could you give me some starting directions? First of all I have no idea at all how to design the hardware parts. But I live in Europe too, could you possibly send me one of your PCBs?
 
Top