Start Bootstrap

Interface and application programming

Week 16

AP Programming




For this week of Interface and application programming I decided to create a mobile phone application that would allow me to read the CO2 values through the MQ135 sensor I made in the week 13 of the input device.




My initial idea was to make a wifi communication between my microcontroller board and a ESP8266 wifi module that I made.


However, I realized that working with a wifi module, in this case the ESP2866, is not possible with Attiny 44 because it does not have enough processing memory to run the wifi.

And, also the wifi module works at 3.3V which also generated some problems when I tried to get it to work.




So I went to see some work on the fabacademy of past issues and realized that in many projects the bluetooth module with an Attiny microprocessor is used.


Some examples I've seen:


  • Air Quality and Ultrasound sensors and connecting its to the Bluetooth with microcontroller atmega328

  • Make a led on or off with an application, using a microcontroller attiny44

  • Make RGB led working with an application, using a microcontroller attiny85

  • Receive data by an ultrasonic sensor, using a microcontroller attiny44



  • The bluetooth module works by TX-RX communication, and both can work with 3.3V or 5V power.


    For all of this reasons I thought it would be a good and simple option to use bluetooth in my project.

    USING MIT APP INVENTOR




    I decided to use the appinventor mit which is the visual, blocks language for building Android

    Apps.

    You can find out more here:

  • MITappInventor


  • To work with this application is very simple, there are two parts, the graphic part where you draw your application by blocks and the part of code that is also made by blocks.



    There are many tutorials on how to do almost everything and use this application.


    There are many tutorials on how to do almost everything and use this application.


    For my project I wanted to make the application receive data from my MQ135 sensor, so the bluetooth had to function as receiver.


    So I followed this tutorial:

  • MITappInventor



  • And I created a series of blocks of code that do receive the data of the bluetooth, as can be seen in the image to the side.

    APP COding

    After I created the code in the APP inventor, I did a test code in Arduino to by my attiny to send sequential numbers to APP just to test the operation.



    First I connected the:


  •  TX (from 44 attiny) to RX (from bluetooth)
  • RX (from attiny 44) to TX (from bluetooth)
  •  GND (from 44 attiny) to GND (from bluetooth)
  •  VCC (from attiny 44) to VCC (from bluetooth)



  • And it did not work :( I did not quite understand why, but there must have been some conflict between the pins 0 and 1 corresponding to the TX and RX of my attiny.



    So I decided to change the TX and RX pins and configure them as if they were the SDA and SCL pins, as you can see from the diagram below.





    I conect:

  •  pin4- RX - SCL/SCK (from 44 attiny) to RX (from bluetooth)
  • pin8 - TX - SDA/MOSI (from attiny 44) to TX (from bluetooth)
  •  GND (from 44 attiny) to GND (from bluetooth)
  •  VCC (from attiny 44) to VCC (from bluetooth)

  • The code I sent was:


  • week16_bluetooth_test


  • This time the code worked and the data was sent.


    Watch the video below


    APP WITH CO2 SENSOR





    The next step is to add to the test code, the code to read the MQ135 that already had the week 13 input device.




    In addition to reading the CO2 sensor I want the leds that I have implemented in my microcontroller to light showing that the air inside our homes is healthy or harmful to our health, so if you turn on the LEDs means:


  • Blue LED - means CO2 is less than 800ppm and it is good for health

  • Yellow LED - means CO2 is less than 800ppm and greater than 1200ppm and you have to be careful about health

  • Red LED - means CO2 is greater than 1200ppm and is harmful to health
  • The final code I sent was:


  • week16_bluetooth_co2



  • The code is correct. But I came across a problem! Again the processing memory of attiny44 was not enough to run a code that included the bluetooth, 3 leds, and the analog sensor reading.



    For this reason I was forced to reduce the code, and I decided to make the calculations to calculate the ppm sent by the co2 sensor directly in the APP INVENTOR, thus reducing the required code processing to attiny44.


    And it worked!





    I wanted to make a graph in APP to present the data of the CO2 gas sensor.


    I followed one more tutorial that I found that explains how to make a graphic:


  • MITappInventor- Make a Graph





  • App inventor on the phone


    To connect the app with your phone you need to install an application on the mobile phone.

    See how it is done here:


  • MITappInventor - Connect your Phone or Tablet over WiFi

  • Or download here!



  • It is necessary to have bluetooth in your mobile phone and to pair it with the bluetooth to which the microcontroller is connected, through the menu to connect the bluetooth that we created in the APP. See next figure.




    The final aspect of my application looks like this: see figure on the side.




    The video below shows the connection of my microcontroller, with the sensor and the bluettoh, and the LEDs to be connected according to the value shown in the application chart.


    Our halite contains a large percentage of co2 so when blowing into the sensor, the values increase.

    APP VIDEO