Multifunction Cube


Multifunction Cube

· Air Quality Monitor

· Natural Gas Alarm

· Fire Detection Alarm

· Temperature Monitor

· Humidity Monitor

· Microwave Radar Alarm

· WiFi Repeater

· Real Time Clock


Air Quality Monitor

Code


#include <Arduino.h>


#include <SPI.h>

#include <Wire.h>


int led2 = 2;

int led3 = 3;

int led4 = 4;

int led5 = 5;

int led6 = 6;

int led7 = 7;

int led8 = 8;

int led9 = 9;

int led10 = 10;

int led11 = 11;

int led13 = 13;


int analogPin = 4;

int val = 0;


void setup() {

Serial.begin(9600); // sets the serial port to 9600


digitalWrite(led11, HIGH);

delay(25000);

digitalWrite(led11, LOW);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT);

pinMode(led5, OUTPUT);

pinMode(led6, OUTPUT);

pinMode(led7, OUTPUT);

pinMode(led8, OUTPUT);

pinMode(led9, OUTPUT);

pinMode(led10, OUTPUT);

pinMode(led11, OUTPUT);

pinMode(led13, OUTPUT);


delay(25);

}


void loop() {

int sensorValue = analogRead(A4);

Serial.println(sensorValue);

digitalWrite(led2, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led4, HIGH);

digitalWrite(led5, HIGH);

digitalWrite(led6, HIGH);

digitalWrite(led7, HIGH);

digitalWrite(led8, HIGH);

digitalWrite(led9, HIGH);

digitalWrite(led10, HIGH);

digitalWrite(led11, HIGH);

digitalWrite(led13, HIGH);



if (sensorValue > 70)digitalWrite(led11, LOW);

if (sensorValue > 80)digitalWrite(led10, LOW);

if (sensorValue > 90)digitalWrite(led9, LOW);

if (sensorValue > 110)digitalWrite(led8, LOW);

if (sensorValue > 130)digitalWrite(led7, LOW);

if (sensorValue > 150)digitalWrite(led6, LOW);

if (sensorValue > 170)digitalWrite(led5, LOW);

if (sensorValue > 200)digitalWrite(led4, LOW);

if (sensorValue > 220)digitalWrite(led3, LOW);

if (sensorValue > 240)digitalWrite(led2, HIGH);

if (sensorValue > 300)digitalWrite(led13, LOW);

if (sensorValue < 300)digitalWrite(led13, HIGH);


delay(500);

}

Natural Gas Alarm - Fire Detection Alarm - Temperature Monitor - Humidity Monitor

Code


/***********************************************************************

*

* Interfacing Arduino with ST7789 TFT display (240x240 pixel)

* and DHT11 digital humidity & temperature sensor.

*

*

*

***********************************************************************/

#include <Adafruit_GFX.h> // Adafruit core graphics library

#include <Adafruit_ST7789.h> // Adafruit hardware-specific library for ST7789

#include <DHT.h> // Adafruit DHT library code

int LED = 4;

int buttonA = 2;

int buttonB = 3;

int buttonC = 5;

int BUTTONstate2 = 0;

int BUTTONstate3 = 0;

int BUTTONstate5 = 0;

// ST7789 TFT module connections

#define TFT_CS 10 // define chip select pin

#define TFT_DC 8 // define data/command pin

#define TFT_RST 9 // define reset pin, or set to -1 and connect to Arduino RESET pin

// initialize Adafruit ST7789 TFT library with hardware SPI module

// MOSI(SDA) ---> Arduino digital pin 11

// SCK (SCL) ---> Arduino digital pin 13

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

#define DHTPIN 6 // DHT11 data pin is connected to Arduino analog pin 2

#define DHTTYPE DHT11 // DHT11 sensor is used

DHT dht11(DHTPIN, DHTTYPE); // initialize DHT library

void setup(void) {

pinMode(LED, OUTPUT);

pinMode(buttonA, INPUT);

pinMode(buttonB, INPUT);

pinMode(buttonC, INPUT);

// initialize the ST7789 display (240x240 pixel)

// if the display has CS pin try with SPI_MODE0

tft.init(240, 240, SPI_MODE2);

// if the screen is flipped, remove this command

tft.setRotation(2);

// fill the screen with black color

tft.fillScreen(ST77XX_BLACK);


tft.setTextColor(ST77XX_YELLOW);

tft.setCursor(45, 90);

tft.setTextSize(7);

tft.println("Wait");

digitalWrite(LED,HIGH);

delay(25000);


tft.fillScreen(ST77XX_BLACK);


tft.setTextWrap(false); // turn off text wrap option

tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK); // set text color to green and black background

tft.setTextSize(4); // text size = 3

tft.setCursor(2, 20); // move cursor to position (15, 27) pixel

tft.print("TEMPERATURE");

tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK); // set text color to yellow and black background

tft.setCursor(20, 130); // move cursor to position (15, 27) pixel

tft.print("HUMIDITY");

tft.setTextSize(6); // text size = 4

// initialize DHT11 sensor

dht11.begin();

}

char _buffer[7];

// main loop


void loop() {

delay(500); // wait a second


digitalWrite(LED,HIGH);

digitalWrite(buttonA,HIGH);

digitalWrite(buttonB,HIGH);

digitalWrite(buttonC,HIGH);

// read humidity in rH%

int Humi = dht11.readHumidity() * 10;

// read temperature in degrees Celsius

int Temp = dht11.readTemperature() * 10;

tft.setTextColor(ST77XX_RED, ST77XX_BLACK);

sprintf(_buffer, "%02u.%1u", (Temp / 10) % 100, Temp % 10);

tft.setCursor(20, 65);

tft.setTextSize(6); // text size

tft.print(_buffer);

tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);

tft.drawCircle(175, 65, 4, ST77XX_YELLOW); // print degree symbol ( ° )

tft.setCursor(180, 65);

tft.print("C");

tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);

sprintf(_buffer, "%02u.%1u", (Humi / 10) % 100, Humi % 10);

tft.setCursor(20, 180);

tft.setTextSize(6); // text size

tft.print(_buffer);

tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);

tft.setCursor(175, 180);

tft.print("%");


BUTTONstate2 = digitalRead(buttonA);

if (BUTTONstate2 == LOW){

tft.fillScreen(ST77XX_RED);

tft.setTextColor(ST77XX_WHITE, ST77XX_RED); // set text color to green and black background

tft.setTextSize(7); // text size

tft.setCursor(20, 61); // move cursor to position pixel

tft.print(" GAS ");

tft.setCursor(20, 140); // move cursor to position pixel

tft.print("ALARM");

digitalWrite(LED,LOW);

delay(500);

tft.invertDisplay(false);

digitalWrite(LED,HIGH);

delay(500);

tft.invertDisplay(true);

digitalWrite(LED,LOW);

delay(500);

tft.invertDisplay(false);

digitalWrite(LED,HIGH);

delay(500);

tft.invertDisplay(true);

digitalWrite(LED,LOW);

delay(500);

tft.invertDisplay(false);

digitalWrite(LED,HIGH);

delay(500);

tft.invertDisplay(true);

digitalWrite(LED,LOW);

delay(500);


asm volatile (" jmp 10");


}

else

{



BUTTONstate5 = digitalRead(buttonC);

if (BUTTONstate5 == LOW){

tft.fillScreen(ST77XX_RED);

tft.setTextColor(ST77XX_WHITE, ST77XX_RED); // set text color to green and black background

tft.setTextSize(7); // text size

tft.setCursor(20, 61); // move cursor to position pixel

tft.print("FAIER");

tft.setCursor(20, 140); // move cursor to position pixel

tft.print("ALARM");

digitalWrite(LED,LOW);

delay(500);

tft.invertDisplay(false);

digitalWrite(LED,HIGH);

delay(500);

tft.invertDisplay(true);

digitalWrite(LED,LOW);

delay(500);

tft.invertDisplay(false);

digitalWrite(LED,HIGH);

delay(500);

tft.invertDisplay(true);

digitalWrite(LED,LOW);

delay(500);

tft.invertDisplay(false);

digitalWrite(LED,HIGH);

delay(500);

tft.invertDisplay(true);

digitalWrite(LED,LOW);

delay(500);

asm volatile (" jmp 10");

}

}

}

// end of code.

Real Time Clock

Code

Code//MORY ARDUINO AND TECH

//How to Display a Real Time Clock on the OLED Screen | Arduino


// How to connect the DS1302 and OLED.

// DS1302: CE pin -> Arduino Digital A0 :also called rst

// I/O pin -> Arduino Digital A1 :also called dat

// SCLK pin -> Arduino Digital A2 :also called clk

// GND pin -> Arduino GND

// OLED: SCL pin -> Arduino SCL

// SDA pin -> Arduino SDA

// VCC pin -> Arduino 5V

// GND pin -> Arduino GND


#include <DS1302.h>

#include "U8glib.h"


U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI


// Init the DS1302

DS1302 rtc(A0, A1, A2);


void setup()

{

Serial.begin(9600);

// Set the clock to run-mode, and disable the write protection

rtc.halt(false);

rtc.writeProtect(false);


// assign default color value

if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {

u8g.setColorIndex(255); // white

}

else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {

u8g.setColorIndex(3); // max intensity

}

else if ( u8g.getMode() == U8G_MODE_BW ) {

u8g.setColorIndex(1); // pixel on

}

else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {

u8g.setHiColorByRGB(255,255,255);

}


// The following lines are initially needed to set the time but should be commented out

// and reuploaded to use the values already stored in the DS1302

//rtc.setDOW(MONDEY); // Set Day-of-Week to FRIDAY

//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)

//rtc.setDate(31, 12, 2019); // Set the date to August 6th, 2019

}


void loop()

{

u8g.firstPage();

do {

draw();

} while( u8g.nextPage() );


// rebuild the picture after some delay

delay(50);

}


void draw(void) {

u8g.setFontPosTop(); //reference position for a text

u8g.setFont(u8g_font_courB14r);

u8g.drawStr( 5, 12,rtc.getDateStr());

u8g.setFont(u8g_font_courB14r);

u8g.drawStr( 5, 30, rtc.getDOWStr());

u8g.setFont(u8g_font_courB18r);

u8g.drawStr( 0, 60, rtc.getTimeStr());//changing the two numbers adjusts the position of the words


}

Microwave Radar Alarm

WiFi Repeater and Power Supply