Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- //#include <stdio.h>
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- int relay = 8;
- int relay2 = 9;
- int buzzer = 10;
- String str;
- int blueToothVal;
- int timer_started_flag = 0;
- long int total_Seconds = 0;
- // Tracks the time since last event fired
- unsigned long int previoussecs = 0;
- unsigned long int currentsecs = 0;
- unsigned long currentMillis = 0;
- int interval = 1 ; // updated every 1 second
- void setup()
- {
- Serial.begin(9600);
- pinMode(relay, OUTPUT);
- pinMode(relay2, OUTPUT);
- pinMode(buzzer, OUTPUT);
- digitalWrite(relay, HIGH);// relay is OFF
- digitalWrite(relay2, HIGH);// relay is OFF
- digitalWrite(buzzer, LOW);
- lcd.init();
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("Hello, world!");
- lcd.setCursor(0, 1);
- lcd.print("Ywrobot Arduino!");
- }
- void loop()
- {
- bluetooth();
- countdown();
- }
- void bluetooth()
- {
- while (Serial.available() && timer_started_flag == 0)
- {
- {
- str = Serial.readStringUntil('\n');
- }
- blueToothVal = (str.toInt());
- if (blueToothVal > 12) {
- blueToothVal = 12;
- }
- total_Seconds = blueToothVal * 60;// convert to sec
- timer_started_flag = 1;
- lcd.clear();
- lcd.print("T Seconds:");
- lcd.setCursor(11, 0);
- lcd.print( total_Seconds );
- delay(1000);
- }
- }
- void countdown() {
- while (timer_started_flag == 1) {
- lcd.setCursor(0, 0);
- lcd.print("T Seconds:");
- lcd.setCursor(11, 0);
- lcd.print( total_Seconds );
- lcd.setCursor(0, 1);
- if ( total_Seconds > 0)
- {
- digitalWrite(relay, LOW);// turn ON relay 1
- digitalWrite(relay2, LOW);// turn ON relay 2
- lcd.print("load ON ");
- }
- if ( total_Seconds <= 0)
- {
- total_Seconds = 0;
- timer_started_flag = 0;
- digitalWrite(relay, HIGH);// turn OFF Relay 1
- digitalWrite(relay2, HIGH);// turn OFF Relay 2
- lcd.print("load OFF");
- //------------------------------Buzzer Tone
- digitalWrite(buzzer, HIGH);
- delay(500);
- digitalWrite(buzzer, LOW);
- delay(500);
- digitalWrite(buzzer, HIGH);
- delay(1500);
- digitalWrite(buzzer, LOW);
- delay(500);
- /////////////////////////////////////////////
- }
- currentMillis = millis();
- currentsecs = currentMillis / 1000;
- if ((unsigned long)(currentsecs - previoussecs) >= interval) {
- total_Seconds = total_Seconds - 1;
- lcd.clear();
- previoussecs = currentsecs;
- }
- }//end of while loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement