Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- String str;
- float ratio;
- float RS_gas;
- float sensor_volt;
- int blueToothVal;
- int sensorValue;
- void setup() {
- Serial.begin(9600);
- pinMode(A0, INPUT);
- pinMode(6, OUTPUT);
- pinMode(7, OUTPUT);
- digitalWrite(6, 1);// OFF
- digitalWrite(7, 1);// OFF
- }
- void loop() {
- bluetooth();
- sendGas();
- }
- void bluetooth()
- {
- while (Serial.available())
- {
- {
- str = Serial.readStringUntil('\n');
- //Serial.print(str);
- }
- blueToothVal = (str.toInt());
- switch (blueToothVal)
- {
- case 1:
- //ON
- digitalWrite(6, 0); // ON 220V Light
- delay(10);
- break;
- case 2:
- //OFF
- digitalWrite(6, 1); // OFF 220V Light
- delay(10);
- break;
- case 3:
- //ON
- digitalWrite(7, 0); // ON 220V Socket
- delay(10);
- break;
- case 4:
- //OFF
- digitalWrite(7, 1); // OFF 220V Socket
- delay(10);
- break;
- }//end of SWITCH
- }//end of Serial
- }//end of function
- void sendGas() {
- sensorValue = analogRead(A0);
- sensor_volt = (float)sensorValue / 1024 * 5.0;
- RS_gas = (5.0 - sensor_volt) / sensor_volt;
- ratio = RS_gas / (0.6);
- Serial.println(ratio);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement