Giter Site home page Giter Site logo

Richard C.J 's Projects

code-for-arduino- icon code-for-arduino-

byte a=0; #include<TimerOne.h> #define vcc_sensor 13 #define PIR1 11 #define PIR2 10 #include <SoftwareSerial.h> SoftwareSerial mySerial(3, 2); #define sensor A0 #define buzzer 5 #define pump 9 #define trig 8 #define echo 7 boolean count = 0; void setup() { Serial.begin(9600); pinMode(sensor,INPUT); pinMode(buzzer,OUTPUT); pinMode(vcc_sensor,OUTPUT); digitalWrite(vcc_sensor,HIGH); mySerial.begin(9600); Serial.println("Initializing..."); mySerial.println("AT"); updateSerial(); pinMode(trig,OUTPUT); pinMode(echo,INPUT); pinMode(12,OUTPUT); digitalWrite(12,HIGH); pinMode(13,OUTPUT); digitalWrite(13,HIGH); pinMode(PIR1,INPUT); pinMode(PIR2,INPUT); Timer1.initialize(60000000); Timer1.attachInterrupt(function_off); noInterrupts(); pinMode(4,OUTPUT); digitalWrite(4,HIGH); } void loop(void) { Auto_order_rice(); Auto_turn_off(); Fire_alarm(); } void function_off() { digitalWrite(12,LOW); Serial.println("Interrupt"); } void Fire_alarm() { int smoking_value = analogRead(sensor); if(smoking_value > 200){ tone(buzzer,400,200); digitalWrite(pump,HIGH); Serial.println("Fire, fire, fire!!!"); mySerial.println("AT+CMGF=1"); updateSerial(); mySerial.println("AT+CMGS=\"+84905248242\""); updateSerial(); mySerial.print("Your home is FIRE"); updateSerial(); mySerial.write(26); digitalWrite(vcc_sensor,LOW); digitalWrite(4,LOW); digitalWrite(12,LOW); } else{ noTone(buzzer); digitalWrite(pump,LOW); digitalWrite(4,HIGH); Serial.println("Not found Fire"); } } void updateSerial() { delay(500); while (Serial.available()) { mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port } while(mySerial.available()) { Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port } } void Auto_order_rice() { unsigned long duration; int distance; digitalWrite(trig,LOW); delayMicroseconds(2); digitalWrite(trig,HIGH); delayMicroseconds(5); digitalWrite(trig,LOW); duration= pulseIn(echo,HIGH); distance= int (duration/2/29.412); Serial.print(distance); Serial.println("cm"); if (distance == 5) { if(count == 0) { mySerial.println("AT+CMGF=1"); updateSerial(); mySerial.println("AT+CMGS=\"+84905248242\""); updateSerial(); mySerial.print("Order me 1 bag of rice. At 671 Ton Duc Thang"); updateSerial(); mySerial.write(26); count = 1; } else { count = 0; } } } void Auto_turn_off(void) { if(digitalRead(PIR2) == HIGH) { a = a + 1; } if(digitalRead(PIR1) == HIGH) { a = a + 1; } if (a == 0) { interrupts(); Serial.println("HIGH"); } if (a != 0 ) { noInterrupts(); Serial.println("LOW"); digitalWrite(12,HIGH); } a = 0; }

home-assitant-by-esp32 icon home-assitant-by-esp32

#define INCLUDE_TERMINAL_MODULE #define CUSTOM_SETTINGS #include <DabbleESP32.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #include <Adafruit_Sensor.h> #include <DHT.h> #include "esp32-hal-ledc.h" byte redPin = 19; byte bluePin = 5; byte greenPin = 18; #define redPin2 15 #define greenPin2 23 #define bluePin2 2 #define LED 16 const int freq = 5000; const byte resolution = 8; const byte redChannel = 0; const byte blueChannel = 1; const byte greenChannel = 2; const byte redChannel2 = 4; const byte blueChannel2 = 5; const byte greenChannel2 = 6; byte val = 0; #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); #define DHTPIN 14 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); #define TIMER_WIDTH 16 byte trig= 32; byte echo= 35; #define ServoPin 4 void setup() { pinMode(13,OUTPUT); digitalWrite(13,HIGH); pinMode(LED,OUTPUT); pinMode(LED,LOW); dht.begin(); if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); for(;;); } delay(2000); display.clearDisplay(); display.setTextColor(WHITE); Dabble.begin("Virtual_Assistant"); ledcSetup(redChannel, freq, resolution); ledcAttachPin(redPin, redChannel); ledcSetup(blueChannel, freq, resolution); ledcAttachPin(bluePin, blueChannel); ledcSetup(greenChannel, freq, resolution); ledcAttachPin(greenPin, greenChannel); ledcSetup(redChannel2, freq, resolution); ledcAttachPin(redPin2, redChannel2); ledcSetup(blueChannel2, freq, resolution); ledcAttachPin(bluePin2, blueChannel2); ledcSetup(greenChannel2, freq, resolution); ledcAttachPin(greenPin2, greenChannel2); setColor(0,0,0); setColor(0,0,0); ledcSetup(3, 50, TIMER_WIDTH); ledcAttachPin(ServoPin, 3); pinMode(trig,OUTPUT); pinMode(echo,INPUT); } void loop() { TemHum(); Virtual_Assistant(); Smart_rubbish(); } void Smart_rubbish() { unsigned long duration; int distance; digitalWrite(trig,LOW); delayMicroseconds(2); digitalWrite(trig,HIGH); delayMicroseconds(5); digitalWrite(trig,LOW); duration= pulseIn(echo,HIGH); distance= int (duration/2/29.412); if(distance <= 13){ ledcWrite(3,4751); } if (distance > 13){ ledcWrite(3,8000); } } void Virtual_Assistant() { Dabble.processInput(); if (Terminal.available() != 0) { String psg = Terminal.readString(); if(psg == "Hi") { Terminal.print("Hello :). What do you need?"); val = val + 1; } if(psg == "Hello") { Terminal.print("Hi :D. What do you need?"); val = val + 1; } if(psg == "Color Relax") { Terminal.print("What's thing make you tired? Let's relaxing with my LED color."); setColor(200, 50, 150); setColor2(200, 50, 150); val = val + 1; } if(psg == "Color Warm White") { Terminal.print("Is weather cold? Enjoy LED color."); setColor(255, 190, 70 ); setColor2(255, 190, 70 ); val = val + 1; } if(psg == "Color Cool White") { Terminal.print("OK, my own."); setColor(100, 110, 150); setColor2(100, 110, 150); val = val + 1; } if(psg == "Color Day Light") { Terminal.print("OK, my own."); setColor(255, 205, 80); setColor2(255, 205, 80); val = val + 1; } if(psg == "Color Cozy") { Terminal.print("Taking tea and enjoying this moment -_-"); setColor(255, 50, 0); setColor2(255, 50, 0); val = val + 1; } if(psg == "Color Focus") { Terminal.print("How about Twilight or IT?"); setColor(100, 110, 125); setColor2(100, 110, 125); val = val + 1; } if(psg == "Color TV Time") { Terminal.print("Which film are you watching? Did you watch Harry Potter?"); setColor(50, 80, 200); setColor2(50, 80, 200); val = val + 1; } if(psg == "Color Christmas") { Terminal.print("Happy Christmas! Did you get gift from Santa :>"); setColor(255,0,1); setColor(20,255,10); val = val + 1; } if(psg == "Color Halloween") { Terminal.print("Do you afraid of ghost. 0o0"); setColor(255, 50, 50); setColor(255, 156, 5); val = val + 1; } if(psg == "Color Forest") { Terminal.print("How about a picnic"); setColor(15,255,60); setColor2(10,255,10); digitalWrite(LED,HIGH); val = val + 1; } if(psg == "Temperature") { float t = dht.readTemperature(); Terminal.print("Temperature now is:"); Terminal.print(t); val = val + 1; } if(psg == "Humidity") { float h = dht.readHumidity(); Terminal.print("Humidity now is:"); Terminal.print(h); val = val + 1; } if(psg == "Off") { setColor(0,0,0); setColor2(0,0,0); digitalWrite(LED,LOW); Terminal.print("Will you go out?"); val = val + 1; } if (psg == "On") { digitalWrite(LED,HIGH); setColor(100, 110, 125); setColor2(80,40,255); Terminal.print("OK, my own :)"); val = val + 1; } if(val == 0) { Terminal.print("You just can send these massage:"); Terminal.print("Color Relax"); Terminal.print("Color Warm White"); Terminal.print("Color Cool White"); Terminal.print("Color Day Light"); Terminal.print("Color Cozy"); Terminal.print("Color Focus"); Terminal.print("Color TV Time"); Terminal.print("Color Christmas"); Terminal.print("Color Halloween"); Terminal.print("Color Forest"); Terminal.print("Humidity"); Terminal.print("Temperature"); Terminal.print("On"); Terminal.print("Off"); } val = 0; } } void setColor(byte red, byte green, byte blue) { red = 255 - red; green = 255- green; blue = 255 - blue; ledcWrite(redChannel, red); ledcWrite(blueChannel, blue); ledcWrite(greenChannel, green); } void setColor2(int red2, int green2, int blue2) { red2 = 255 - red2; green2 = 255- green2; blue2 = 255 - blue2; ledcWrite(redChannel2, red2); ledcWrite(blueChannel2, blue2); ledcWrite(greenChannel2, green2); } void TemHum() { float t = dht.readTemperature(); float h = dht.readHumidity(); display.clearDisplay(); display.setTextSize(1); display.setCursor(0,0); display.print("Temperature: "); display.setTextSize(2); display.setCursor(0,10); display.print(t); display.print(" "); display.setTextSize(1); display.cp437(true); display.write(167); display.setTextSize(2); display.print("C"); display.setTextSize(1); display.setCursor(0, 35); display.print("Humidity: "); display.setTextSize(2); display.setCursor(0, 45); display.print(h); display.print(" %"); display.display(); if(t > 40) { digitalWrite(LED,LOW); } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.