Last active
April 12, 2022 18:31
-
-
Save hussienzy/2f1724f4bd7703a0af8c2fc3b7d96880 to your computer and use it in GitHub Desktop.
MakerUno Oxygen Sensor With Blynk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include "rgb_lcd.h" | |
#include <ESP8266_Lib.h> | |
#include <BlynkSimpleShieldEsp8266.h> | |
#include <SoftwareSerial.h> | |
SoftwareSerial EspSerial(6, 7); // RX, TX | |
char auth[] = "djigt1lMWzPmqbppsEDxk6uUFNeLzf-C"; | |
// Set password to "" for open networks. | |
char ssid[] = "hotspot"; | |
char pass[] = "hotspot123"; | |
// Your ESP8266 baud rate: | |
#define ESP8266_BAUD 115200 | |
ESP8266 wifi(&EspSerial); | |
// Grove - Gas Sensor(O2) test code | |
// Note: | |
// 1. It need about about 5-10 minutes to preheat the sensor | |
// 2. modify VRefer if needed | |
const float VRefer = 3.3; // voltage of adc reference | |
const int pinAdc = A0; | |
rgb_lcd lcd; | |
const int colorR = 255; | |
const int colorG = 0; | |
const int colorB = 0; | |
void setup() | |
{ | |
// set up the LCD's number of columns and rows: | |
lcd.begin(16, 2); | |
// lcd.setRGB(colorR, colorG, colorB); | |
// Print a message to the LCD. | |
lcd.print("Oxygen Level"); | |
lcd.setCursor(0, 1); | |
lcd.print("Monitoring"); | |
delay(1000); | |
// Open the connection at 115200 | |
EspSerial.begin(115200); | |
EspSerial.println("AT"); | |
Blynk.begin(auth, wifi, ssid, pass); | |
} | |
void loop() | |
{ | |
Blynk.run(); | |
lcd.clear(); | |
lcd.setCursor(0, 0); | |
float Vout =0; | |
Vout = readO2Vout(); | |
lcd.print("Vout : "); | |
lcd.print(Vout); | |
lcd.setCursor(0, 1); | |
lcd.print("O2% : "); | |
lcd.print(readConcentration()); | |
Blynk.virtualWrite(V1, readConcentration()); | |
//delay(1000); | |
delay(100); | |
} | |
float readO2Vout() | |
{ | |
long sum = 0; | |
for(int i=0; i<32; i++) | |
{ | |
sum += analogRead(pinAdc); | |
} | |
sum >>= 5; | |
float MeasuredVout = sum * (VRefer / 1023.0); | |
return MeasuredVout; | |
} | |
float readConcentration() | |
{ | |
// Vout samples are with reference to 3.3V | |
float MeasuredVout = readO2Vout(); | |
//float Concentration = FmultiMap(MeasuredVout, VoutArray,O2ConArray, 6); | |
//when its output voltage is 2.0V, | |
float Concentration = MeasuredVout * 0.21 / 2.0; | |
float Concentration_Percentage=Concentration*100; | |
return Concentration_Percentage; | |
} | |
/********************************************************************************************************* | |
END FILE | |
*********************************************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment