top of page

Search Results

143 items found for ""

  • Real Time Temperature Data Logger with Bluetooth

    Learn here to create Arduino Based temperature data logger. We’ll use the DHT11 to measure temperature and Humidity, the real time clock (RTC) module to take time stamps and the SD card module to save the temperature, Humidity and Heat index data on the SD card, and Bluetooth send temperature data to HTML Java script Gauge display using android application. Components required Arduino Nano - 1 no Micro SD card Module - 1no Memory Card 16GB (16GB used in this Project)- 1no DHT 11 - 1 no DS1307 RTC I²Cmodule - 1 no Bluetooth HC-05 - 1 no Jumper wires Circuit diagram Micro SD Card Adapter Module SD cards or Micro SD cards are widely used in various applications, such as data logging, data visualization, and many more. Micro SD Card Adapter modules make it easier for us to access these SD cards with ease. The Micro SD Card Adapter module is an easy-to-use module with an SPI interface and an on-board 3.3V voltage regulator to provide proper supply to the SD card. The diagram shows the detail connections of SD module with Arduino. MOSI (Master Out Slave In) - pin 11 MISO (Master In Slave Out) - pin 12 SCK (Clock)- pin 13 CS (Chip Select) - pin 10 GND-GND VCC-5v or 3.3v. A Micro SD Card adapter module can be easily connected to an arduino. Since the module communicates via the SPI protocol, we need to connect the MISO, MOSI, SCK, and CS of the module to the MCU’s. Along with the SD card holder, the module has a 3.3V voltage regulator, along with a 74LVC125A Level shifter IC. Data Sheet Bluetooth HC-05 Module HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth. HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module. HC-05 Default Settings Default Bluetooth Name: “HC-05” Default Password: 1234 or 0000 Default Communication: Slave Default Mode: Data Mode Data Mode Baud Rate: 9600 DHT 11 DHT11 digital temperature and humidity sensor is a calibrated digital signal output of the temperature and humidity combined sensor. It uses a dedicated digital modules capture technology and the temperature and humidity sensor technology to ensure that products with high reliability and excellent long-term stability. Sensor includes a resistive element and a sense of wet NTC temperature measurement devices, and with a high-performance 8-bit micro controller connected. Data Sheet DHT11 Specifications: Operating Voltage: 3.5V to 5.5V Operating current: 0.3mA (measuring) 60uA (standby) Output: Serial data Temperature Range: 0°C to 50°C Humidity Range: 20% to 90% Resolution: Temperature and Humidity both are 16-bit Accuracy: ±1°C and ±1% DHT11 Equivalent Temperature Sensors: DHT22, AM2302, SHT71 DS1307 RTC Module DS1307 Module is a real-time clock module with 32kHz and has an onboard battery backup. This module provides seconds, minutes, hours, date, week and year with leap-year compensation up to 2100. It is a small size module that’s why it is easy to plug in even on a breadboard. It has the functionality to set in 24 hours and 12 hours. It is a real time clock module so after removing the power also it sore the real-time and whenever power is given, it starts with real time. Module is compatible with microprocessors and Arduino. Data Sheet Pin Connection to Arduino. SCL – analog pin5 SDA – analog pin4 Vcc - +5V Gnd - Gnd Code To Update the RTC time adjusment using the following the code in Void setup. Unslash the "set DS3231time (x,x,x,x,x,x,x) // set the initial time here: // DS3231 seconds, minutes, hours, day, date, month, year // setDS3231time(30,42,21,4,15,12,21); Example: setDS3231time(30,42,21,4,15,12,21); 30 - Seconds 42- Minute 21- Hours 4-Wednesday 15-date 12-Month 21-Year. Arduino Nano The Arduino Nano is another popular Arduino development board very much similar to the Arduino UNO. They use the same Processor (Atmega328p) and hence they both can share the same program. Data Sheet Powering you Arduino Nano: There are total three ways by which you can power your Nano. USB Jack: Connect the mini USB jack to a phone charger or computer through a cable and it will draw power required for the board to function Vin Pin: The Vin pin can be supplied with an unregulated 6-12V to power the board. The on-board voltage regulator regulates it to +5V. +5V Pin: If you have a regulated +5V supply then you can directly provide this o the +5V pin of the Arduino. Input/output: There are total 14 digital Pins and 8 Analog pins on your Nano board. The digital pins can be used to interface sensors by using them as input pins or drive loads by using them as output pins. A simple function like pinMode() and digitalWrite() can be used to control their operation. The operating voltage is 0V and 5V for digital pins. The analog pins can measure analog voltage from 0V to 5V using any of the 8 Analog pins using a simple function like analogRead(). These pins apart from serving their purpose, can also be used for special purposes, which are discussed below: Serial Pins 0 (Rx) and 1 (Tx): Rx and Tx pins are used to receive and transmit TTL serial data. They are connected with the corresponding ATmega328P USB to TTL serial chip. External Interrupt Pins 2 and 3: These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. PWM Pins 3, 5, 6, 9 and 11: These pins provide an 8-bit PWM output by using analogWrite() function. SPI Pins 10 (SS), 11 (MOSI), 12 (MISO) and 13 (SCK): These pins are used for SPI communication. In-built LED Pin 13: This pin is connected with a built-in LED. When pin 13 is HIGH – LED is on and when pin 13 is LOW, it is off. I2C A4 (SDA) and A5 (SCA): Used for IIC communication using Wire library. AREF: Used to provide reference voltage for analog inputs with analogReference() function. Reset Pin: Making this pin LOW, resets the micro controller. Installing adafruit Library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. DHT11: you need to Download and install the DHT11 library. DS1307: you need to Download and install the RTC library. Adafruit Unified Sensor Download and install the sensor library. Adafruit BusIO Download and install the signal library. After installing the required libraries, copy the following code to your Arduino IDE. Arduino Code Subscribe and Download code. /* SD card test This example shows how use the utility libraries on which the' SD library is based in order to get info about your SD card. Very useful for testing a card when you're not sure whether its working or not. The circuit: SD card attached to SPI bus as follows: ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila ** CS - depends on your SD card shield or module. Pin 10 used here for consistency with other Arduino examples */ // include the SD library: #include // Include SPI library (needed for the SD card) #include // Include SD library #include // for the RTC File dataFile; // REQUIRES the following Arduino libraries: // - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library // - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor #include "DHT.h" #define DHTPIN 2 // Digital pin connected to the DHT sensor // Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 -- // Pin 15 can work but DHT must be disconnected during program upload. // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Connect pin 1 (on the left) of the sensor to +5V // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 // to 3.3V instead of 5V! // Connect pin 2 of the sensor to whatever your DHTPIN is // Connect pin 3 (on the right) of the sensor to GROUND (if your sensor has 3 pins) // Connect pin 4 (on the right) of the sensor to GROUND and leave the pin 3 EMPTY (if your sensor has 4 pins) // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor // Initialize DHT sensor. // Note that older versions of this library took an optional third parameter to // tweak the timings for faster processors. This parameter is no longer needed // as the current DHT reading algorithm adjusts itself to work on faster procs. DHT dht(DHTPIN, DHTTYPE); // Real Time Clock RTC_DS1307 rtc; void setup() { Serial.begin(9600); // set the initial time here: // DS3231 seconds, minutes, hours, day, date, month, year // setDS3231time(30,42,21,4,15,12,21); Serial.println(F("DHTxx test!")); dht.begin(); // setup for the RTC while(!Serial); // for Leonardo/Micro/Zero if(! rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); } else { // following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); } if(! rtc.isrunning()) { Serial.println("RTC is NOT running!"); } while (!Serial); // wait for serial port to connect. Needed for native USB port only Serial.print("Initializing SD card..."); if (!SD.begin()) { Serial.println("initialization failed!"); while (1); } Serial.println("initialization done."); delay(2000); } void loop() { // Wait a few seconds between measurements. delay(2000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); // Read temperature as Fahrenheit (isFahrenheit = true) float f = dht.readTemperature(true); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) || isnan(f)) { Serial.println(F("Failed to read from DHT sensor!")); return; } // Compute heat index in Fahrenheit (the default) float hif = dht.computeHeatIndex(f, h); // Compute heat index in Celsius (isFahreheit = false) float hic = dht.computeHeatIndex(t, h, false); dataFile = SD.open("DHT11Log.txt", FILE_WRITE); DateTime now = rtc.now(); if (dataFile) { // Serial.print(F("Humidity: ")); Serial.print(h); Serial.print("|"); // Serial.print(F("% Temperature: ")); Serial.print(t); Serial.print("|"); // Serial.print(F("°C ")); // Serial.print(f); // Serial.print(F("°F Heat index: ")); Serial.print(hic); Serial.print("|"); // Serial.print(F("°C ")); Serial.print(hif); Serial.print("\n"); delay(15000); // Serial.println(F("°F")); // Write data to SD card file (DHT11Log.txt) dataFile.print(now.year(), DEC); dataFile.print('/'); dataFile.print(now.month(), DEC); dataFile.print('/'); dataFile.print(now.day(), DEC); dataFile.print(','); dataFile.print(now.hour(), DEC); dataFile.print(':'); dataFile.print(now.minute(), DEC); dataFile.print(':'); dataFile.print(now.second(), DEC); dataFile.print(","); dataFile.print(F("Humidity: ")); dataFile.print(h); dataFile.print(F("% Temperature: ")); dataFile.print(t); dataFile.print(F("°C ")); dataFile.print(f); dataFile.print(F("°F Heat index: ")); dataFile.print(hic); dataFile.print(F("°C ")); dataFile.print(hif); dataFile.println(F("°F")); dataFile.close(); } // if the file didn't open, print an error: else Serial.println("error opening DHT11Log.txt"); } Subscribe and Download code. Serial Monitor After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the Arduino Uno board and see the Temerature, Humidity and Heat index vaule in Serial monitor at every 15 second. SD Card First Power off the arduino nano and remove SD card from module and connect to the PC using SD card reader. The SD card contains DHT11log.txt file, the txt file have Temperature data with Time stamp. Android application First open Mobile application and select Bluetooth image button, after that select Bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234). Subscribe and Download code. Android App offline App Download (Gauge work without internet) MIT BLOCK MIT app inventor Block image for android application development. Amcharts Here to used amChart Gauge for Temperature and Humididty data visualization. Refer below demo HTML code for Gauges. https://www.amcharts.com/demos/#gauges Html code for angular gauge

  • Interfacing SD card module with Arduino - Card Info, Read/Write and DATA LOGGER Functions

    The micro SD Card Module is a simple solution for transferring data to and from a standard SD card. This module has SPI interface which is compatible with any SD card and it uses 5V or 3.3V power supply which is compatible with Arduino UNO/Mega. Some times we have the need for a way to store data in our projects, and most of the time, the EEPROM which comes readily to mind has a limited storage capacity, and issues with the format and nature of data it can hold. All this and more makes it probably not the best for storing data like text, CSV, audio, video or image files. To get around this we could use an SD card to store the data, and remove the card when we need to view on some other platform etc. That is why today’s project is focusing on how to interface an SD card module with an Arduino. Secure Digital (SD) is a non-volatile memory card format developed by the SD Card Association (SDA) for use in portable devices like mobile phones, cameras etc. Secure Digital includes four card families as follows- 1. SDSC: Standard Capacity SD. It has storage capacity of 2GB uses FAT- 12 and FAT-16 file systems. 2. SDHC: High Capacity SD. It has storage capacity ranging from 2GB to 32GB uses FAT-32 file system. 3. SDXC: extended Capacity SD. It has storage capacity ranging from 32GB to 2TB uses exFAT file system. 4. SDIO: It combines INPUT/OUTPUT functions with data storage. File System SD card is a block-addressable storage device, in which the host device can read or write fixed-size blocks by specifying their block number. Most SD cards are formatted with one or more MBR (Master Boot Record) partitions in which the first partition contains the file system which enables it to work like hard disks. 1. For SDSC card Capacity smaller than 16 MB- FAT 12 Capacity between 16 MB and 32 MB- FAT 16 Capacity larger than 32 MB- FAT 16B 2. For SDHC cards Capacity smaller than 7.8 GB- FAT 32 Capacity greater than 7.8 GB- FAT 32 3. For SDXC cards exFAT Subscribe The Arduino Micro SD card Module is an SPI Communication based device. It is compatible with the TF SD cards used in mobile phones and can be used to provide some sort of external storage for micro controller and microprocessor based projects, to store different kind of data types from images to videos. SD cards generally are 3.3v logic level based devices, but with the aid of the Micro SD card module, the signals are converted to 5v via a logic level converter implemented on the SD card Module. Components required Arduino Nano - 1 no Micro SD card Module - 1no Memory Card 16GB (16GB used in this Project)- 1no Jumper wires Circuit diagram The diagram shows the detail connections of SD module with Arduino. MOSI (Master Out Slave In) - pin 11 MISO (Master In Slave Out) - pin 12 SCK (Clock)- pin 13 CS (Chip Select) - pin 4 GND-GND VCC-5v or 3.3v. The operating voltage of any standard micro SD Cards is 3.3 V. So we cannot directly connect it to circuits that use 5V logic. In fact, any voltages exceeding 3.6V will permanently damage the micro SD card. That’s why; the module has an onboard ultra-low dropout regulator that will convert voltages from 3.3V – 6V down to ~3.3V. There’s also a 74LVC125A chip on the module which converts the interface logic from 3.3V-5V to 3.3V. This is called logic level shifting. That means you can use this board to interact with both 3.3V and 5V microcontrollers like Arduino. Arduino Library Library will be using the inbuilt code provided by Arduino IDE. The code in the Arduino IDE uses the two library files – SPI.h SD.h These library files direct contain function definitions which are used for SD card read-write operations. For accessing code in Arduino IDE you can follow the following mention steps- Copy the code above and paste it into the Arduino IDE, Upload it to your board and you should see something like what is displayed below on your serial monitor. SD Card Information Download Code // include the SD library: #include #include // set up variables using the SD utility library functions: Sd2Card card; SdVolume volume; SdFile root; // change this to match your SD shield or module; // Arduino Ethernet shield: pin 4 // Adafruit SD shields and modules: pin 10 // Sparkfun SD shield: pin 8 // MKRZero SD: SDCARD_SS_PIN const int chipSelect = 4; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial.print("\nInitializing SD card..."); // we'll use the initialization code from the utility libraries // since we're just testing if the card is working! if (!card.init(SPI_HALF_SPEED, chipSelect)) { Serial.println("initialization failed. Things to check:"); Serial.println("* is a card inserted?"); Serial.println("* is your wiring correct?"); Serial.println("* did you change the chipSelect pin to match your shield or module?"); while (1); } else { Serial.println("Wiring is correct and a card is present."); } // print the type of card Serial.println(); Serial.print("Card type: "); switch (card.type()) { case SD_CARD_TYPE_SD1: Serial.println("SD1"); break; case SD_CARD_TYPE_SD2: Serial.println("SD2"); break; case SD_CARD_TYPE_SDHC: Serial.println("SDHC"); break; default: Serial.println("Unknown"); } // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 if (!volume.init(card)) { Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); while (1); } Serial.print("Clusters: "); Serial.println(volume.clusterCount()); Serial.print("Blocks x Cluster: "); Serial.println(volume.blocksPerCluster()); Serial.print("Total Blocks: "); Serial.println(volume.blocksPerCluster() * volume.clusterCount()); Serial.println(); // print the type and size of the first FAT-type volume uint32_t volumesize; Serial.print("Volume type is: FAT"); Serial.println(volume.fatType(), DEC); volumesize = volume.blocksPerCluster(); // clusters are collections of blocks volumesize *= volume.clusterCount(); // we'll have a lot of clusters volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB) Serial.print("Volume size (Kb): "); Serial.println(volumesize); Serial.print("Volume size (Mb): "); volumesize /= 1024; Serial.println(volumesize); Serial.print("Volume size (Gb): "); Serial.println((float)volumesize / 1024.0); Serial.println("\nFiles found on the card (name, date and size in bytes): "); root.openRoot(volume); // list all files in the card with date and size root.ls(LS_R | LS_DATE | LS_SIZE); } void loop(void) { } Serial monitor After a successful upload, open the Serial Monitor at a baud rate of 9600. see the result on Serial monitor. SD Card Read/Write Subscribe Download Code Code Explanation: The sketch starts with including the built in SD library and the SPI library which allows us to easily communicate with the SD card over SPI interface. #include #include After the libraries have been included, the next thing we do is declare the Arduino pin to which the chipSelect (CS) pin of the SD card module is connected. The CS pin is the only one that is not really fixed as any of the Arduino digital pin. We don’t need to declare other SPI pins since we are using hardware SPI interface and these pins are already declared in the SPI library. After declaring the pin, we then create an object myFile, which will be used later on to store data on the SD card. const int chipSelect = 10; File myFile; Next, in the setup() section: We start the serial communication for showing the results on the serial monitor. Now, using the SD.begin() function we will initialize the SD card and if initialization is successful the “if” statement becomes true and the String “initialization done.” gets printed on the serial monitor, else the string “initialization failed!” gets printed and the program terminates. Serial.begin(9600); Serial.print("Initializing SD card..."); if (!SD.begin()) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); Next, the SD.open() function will open the file named “test.txt”. In our case, as such file is not present, it’ll be created. The other parameter FILE_WRITE opens the file in read-write mode. myFile = SD.open("test.txt", FILE_WRITE); Once the file is opened, we will print the “Writing to test.txt…” message on the serial monitor and then using the myFile.println() function we will write the text “testing 1, 2, 3.” into the file. After that we need to use close() function to ensure that the data written to the file is saved. if (myFile) { Serial.print("Writing to test.txt..."); myFile.println("testing 1, 2, 3."); myFile.close(); Serial.println("done."); } else { Serial.println("error opening test.txt"); } Now let’s read the same file to check if the write operation was successful.To do that, we will use the same function, SD.open() , but this time as the file “test.txt” has already been created, the function will just open the file. Then using the myFile.read() function we will read from the file and print it on the serial monitor. The read() function actually reads just one character at a time, so therefore we need to use the “while” loop and the function myFile.available() to read all characters in file. At the end we need to close the file. myFile = SD.open("test.txt"); if (myFile) { Serial.println("test.txt:"); while (myFile.available()) { Serial.write(myFile.read()); } myFile.close(); } else { Serial.println("error opening test.txt"); } Since this is just a demo sketch to demonstrate how to read and write files, there is no point to run the code multiple times so all the code was placed in the setup() function which runs just once, instead of putting it in a loop() function which runs over and over again. void loop() { } Serial monitor After a successful upload, open the Serial Monitor at a baud rate of 9600. see the result on Serial monitor. SD Card DATA LOGGER Subscribe Download Code #include #include const int chipSelect = 4; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial.print("Initializing SD card..."); // see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); // don't do anything more: while (1); } Serial.println("card initialized."); } void loop() { // make a string for assembling the data to log: String dataString = ""; // read three sensors and append to the string: for (int analogPin = 0; analogPin < 3; analogPin++) { int sensor = analogRead(analogPin); dataString += String(sensor); if (analogPin < 2) { dataString += ","; } } // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. File dataFile = SD.open("datalog.txt", FILE_WRITE); // if the file is available, write to it: if (dataFile) { dataFile.println(dataString); dataFile.close(); // print to the serial port too: Serial.println(dataString); } // if the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); } } Serial monitor After a successful upload, open the Serial Monitor at a baud rate of 9600. see the result on Serial monitor. Note You can use print() and println() functions just like Serial objects, to write strings, variables, etc Read() only returns a character at a time. It does not read a full line or a number! The SD card library does not support ‘long filenames’. Instead, it uses the 3 format for file names, so keep file names short! For example datalog.txt is fine. Also keep in mind that file names do not have ‘case’ sensitivity, so datalog.txt is the same file as DataLog.Txt is the same file as DATALOG.TXT Subscribe

  • Bluetooth Visitor Counter and automatic light control

    Here to learn, we will make a Arduino and Bluetooth based Visitor Counter and an Automatic Light Control System using Infrared sensor. In this project, a pair of IR sensors can detect the visitor IN/OUT directions, and arduino send these data to android application using Bluetooth. Android screen displayed in Visitor Walk In count, Visitor Walk Out count and Visitor inside count using android application. This device also have a Bar chart and pie chart for comparison of Visitor In, Out and Inside count for visual and data analysis. In addition to that Visitor counter control an automatic light control system for ON/OFF for the light. If people presence inside the building the light automatically ON and If no people are inside the building the light automatically OFF. Components required Arduino Nano - 1 no Bluetooth module HC-05 - 1no IR sensor module -2nos 1-Channel 5V Relay Module - 1no Circuit diagram What is an IR Sensor? IR sensor is an electronic device, that emits the light in order to sense some object of the surroundings. An IR sensor can measure the heat of an object as well as detects the motion. Usually, in the infrared spectrum, all the objects radiate some form of thermal radiation. These types of radiations are invisible to our eyes, but infrared sensor can detect these radiations. The emitter is simply an IR LED (Light Emitting Diode) and the detector is simply an IR photodiode . Photodiode is sensitive to IR light of the same wavelength which is emitted by the IR LED. When IR light falls on the photodiode, the resistances and the output voltages will change in proportion to the magnitude of the IR light received. IR Sensor Working Principle There are different types of infrared transmitters depending on their wavelengths, output power and response time. An IR sensor consists of an IR LED and an IR Photodiode, together they are called as PhotoCoupler or OptoCoupler. IR Transmitter or IR LED Infrared Transmitter is a light emitting diode (LED) which emits infrared radiations called as IR LED’s. Even though an IR LED looks like a normal LED, the radiation emitted by it is invisible to the human eye. IR Receiver or Photodiode Infrared receivers or infrared sensors detect the radiation from an IR transmitter. IR receivers come in the form of photodiodes and phototransistors. Infrared Photodiodes are different from normal photo diodes as they detect only infrared radiation. Different types of IR receivers exist based on the wavelength, voltage, package, etc. When used in an infrared transmitter – receiver combination, the wavelength of the receiver should match with that of the transmitter. The emitter is an IR LED and the detector is an IR photodiode. The IR photodiode is sensitive to the IR light emitted by an IR LED. The photo-diode’s resistance and output voltage change in proportion to the IR light received. This is the underlying working principle of the IR sensor. When the IR transmitter emits radiation, it reaches the object and some of the radiation reflects back to the IR receiver. Based on the intensity of the reception by the IR receiver, the output of the sensor defines. Bluetooth HC-05 Module HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth. It has 6 pins, Key/EN- NC VCC to Connect 5 V power GND to power Ground TXD to Arduino Nano Rx (D0) RXD to Arduino Nano Tx (D1) State- NC HC-05 module Information HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module. HC-05 Default Settings Default Bluetooth Name: “HC-05” Default Password: 1234 or 0000 Download Datasheet Subscribe and Download code. Arduino Code #define DELAY_TIMEOUT 1500 int IR_Right_Pin = 8; // <<<---->>> ** IN DIRECTION ** SENSOR int IR_Left_Pin = 9; // **<<<---->>> OUT DIRECTION ** SENSOR #define Relay 2 //Remove Bluetooth RX, Tx wiring when program upload int IR_Right_state = 0; int IR_Left_state = 0; int IR_Right_state_last = -1; int IR_Left_state_last = -1; int IN_counter = 0; int OUT_counter = 0; int Inside_counter = 0; bool Walk_IN = false; bool Walk_Out = false; unsigned long tm; void setup(void) { Serial.begin(9600); pinMode(IR_Right_Pin, INPUT); pinMode( IR_Left_Pin , INPUT); pinMode(Relay, OUTPUT); } void loop(void) { IR_Right_state = digitalRead(IR_Right_Pin ); IR_Left_state = digitalRead( IR_Left_Pin ); checkWalkIn(); checkWalkOUT(); checkInside(); } void checkWalkIn(){ if( IR_Right_state != IR_Right_state_last ){ IR_Right_state_last = IR_Right_state; if( (Walk_IN == false) && ( IR_Right_state == LOW ) ){ Walk_IN = true; tm = millis(); } } if( (millis() - tm) > DELAY_TIMEOUT ){ Walk_IN = false; } if( Walk_IN && (IR_Left_state == LOW) && (IR_Right_state == HIGH) ){ Walk_IN = false; IN_counter++; // Serial.print("in:"); // Serial.print(IN_counter); } } void checkWalkOUT(){ if( IR_Left_state != IR_Left_state_last ){ IR_Left_state_last = IR_Left_state; if( (Walk_Out == false) && ( IR_Left_state == LOW ) ){ Walk_Out = true; tm = millis(); } } if( (millis() - tm) > DELAY_TIMEOUT ){ Walk_Out = false; } if( Walk_Out && (IR_Right_state == LOW) && (IR_Left_state == HIGH) ){ Walk_Out = false; OUT_counter++; // Serial.print("out:"); // Serial.print(OUT_counter); } } void checkInside(){ Inside_counter = (IN_counter-OUT_counter); if(Inside_counter<=0) { digitalWrite(Relay, LOW); delay(200); } else digitalWrite(Relay, HIGH); Serial.print(IN_counter); Serial.print("|"); Serial.print(OUT_counter); Serial.print("|"); Serial.print(Inside_counter); Serial.print("|"); Serial.print(digitalRead(Relay)); Serial.print("\n"); delay(700); } Serial monitor After a successful upload, open the Serial Monitor at a baud rate of 9600. see the result on Serial monitor. Android application First open Mobile application and select Bluetooth image button, after that select Bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234). In this Mobile output Visitors In, Out,Inside head counts and Light control ON/OFF status displayed in screen. And also update chart button for Bar chart and Pie chart view and you can click to In,out,inside count data to add/remove in pie chart for desired output result. Subscribe and Download code. Android App Download

  • Angle Measure using MPU 6050 3-Axis Accelerometer and Gyroscope Sensor

    In this tutorial, Measuring the angle (Object Position) using MPU6050 sensor, Bluetooth HC-05 device for wireless monitor using android application.The MPU6050 sensor module has a built-in gyroscope and an accelerometer sensor. The gyroscope is used to determine the orientation and the accelerometer provides information about the angle, such as X, Y, and Z-axis data. These information send through serial port connected with bluetooth device and send to android mobile application. The android application provide corresponding X,Y,Z values in circular bar format on screen. Circuit diagram Components Required MPU6050 Accelerometer - 1 no Arduino Nano - 1 no Bluetooth module HC-05 - 1no Bluetooth HC-05 Module HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth. It has 6 pins, Key/EN- NC VCC to Connect 5 V power GND to power Ground TXD to Arduino Nano Rx (D0) RXD to Arduino Nano Tx (D1) State- NC HC-05 module Information HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module. HC-05 Default Settings Default Bluetooth Name: “HC-05” Default Password: 1234 or 0000 Download Datasheet MPU6050 Sensor The MPU6050 devices combine a 3-axis gyroscope and a 3-axis accelerometer on the same silicon together with an onboard Digital Motion Processor (DMP) capable of processing complex 9-axis MotionFusion algorithms. Also, it has additional feature of on-chip Temperature sensor. It has I2C bus interface to communicate with the microcontrollers. A micro-electro-mechanical system (MEMS) is used to measure velocity, acceleration, orientation, displacement, and many other motion-related parameters. Refer blog for more detail :https://www.dofbot.com/post/iot-based-object-angle-measure-using-mpu-6050-and-blynk Calculations Note that gyroscope and accelerometer sensor data of MPU6050 module consists of 16-bit raw data in 2’s complement form. Temperature sensor data of MPU6050 module consists of 16-bit data (not in 2’s complement form). Now suppose we have selected, - Accelerometer full scale range of +/- 2g with Sensitivity Scale Factor of 16,384 LSB(Count)/g. - Gyroscope full scale range of +/- 250 °/s with Sensitivity Scale Factor of 131 LSB (Count)/°/s. then, To get sensor raw data, we need to first perform 2’s complement on sensor data of Accelerometer and gyroscope. After getting sensor raw data we can calculate acceleration and angular velocity by dividing sensor raw data with their sensitivity scale factor as follows, Accelerometer values in g (g force) Acceleration along the X axis = (Accelerometer X axis raw data/16384) g. Acceleration along the Y axis = (Accelerometer Y axis raw data/16384) g. Acceleration along the Z axis = (Accelerometer Z axis raw data/16384) g. Gyroscope values in °/s (degree per second) Angular velocity along the X axis = (Gyroscope X axis raw data/131) °/s. Angular velocity along the Y axis = (Gyroscope Y axis raw data/131) °/s. Angular velocity along the Z axis = (Gyroscope Z axis raw data/131) °/s. For example, Suppose, after 2’ complement we get accelerometer X axes raw value = +15454 Then Ax = +15454/16384 = 0.94 g. Installing the Arduino Library No need any special libraries. Subscribe and Download code. Arduino Code #include const int MPU_addr=0x68; int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; // remove wiring from bluetooth while uploading program int minVal=265; int maxVal=402; double x; double y; double z; void setup(){ Wire.begin(); Wire.beginTransmission(MPU_addr); Wire.write(0x6B); Wire.write(0); Wire.endTransmission(true); Serial.begin(9600); } void loop(){ Wire.beginTransmission(MPU_addr); Wire.write(0x3B); Wire.endTransmission(false); Wire.requestFrom(MPU_addr,14,true); AcX=Wire.read()<<8|Wire.read(); AcY=Wire.read()<<8|Wire.read(); AcZ=Wire.read()<<8|Wire.read(); int xAng = map(AcX,minVal,maxVal,-90,90); int yAng = map(AcY,minVal,maxVal,-90,90); int zAng = map(AcZ,minVal,maxVal,-90,90); x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI); y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI); z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI); Serial.print(x); Serial.print("|"); Serial.print(y); Serial.print("|"); Serial.print(z); Serial.print("\n"); delay(500); } Serial monitor After a successful upload, open the Serial Monitor at a baud rate of 9600. see the result on Serial monitor. Android application First open Mobile application and select Bluetooth image button, after that select Bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234). Subscribe and Download code. Android App MIT BLOCK MIT app inventor Block image for android application development.

  • Bluetooth Controlled Water Level Controller

    Water is one of the essential need for the survival of all human beings, animals and plants. The water overflow from the overhead tanks in the houses, commercial properties, educational institutions the percentage of water overflow wastage. To avoid such Spillage implementation of an automatic water level controller becomes a key factor which further reduces human intervention. In this Project work, an automatic water level controller using bluetooth wireless technology and Ultrasonic water level sensor is proposed. This project can be further enhanced to control and animated the water level as follows. Soft Slider - Automatic ON/OFF Pump The water Pump automatic turning it ON, when the water level is reached LOW level set point, and water Pump automatic turning it OFF when the water level reached is HIGH level set point. The Low & High set point to be adjusted from 0 % to 100 % using slider from android app and value send to arduino and stored in Arduino EEPROM by pressing SET button in the android application. Pushbutton- Tank height Set A push button switch is provided for tank height set and value stored in Arduino EEPROM. If tank is empty then press to push button switch for tank height set in cm and value send to arduino and stored in EEPROM. Gauge Display (Android) The Cylindrical gauge display for water level percentage indication from 0 % to 100%. Bar Graph Display (Android) The Bar Graph LED display for water level percentage indication from 10 % to 100% by step 10. Progress Monitor (Android) The Progress Monitor display for water level percentage indication from 0 % to 100%. Motor Indication (Android) Pump Motor ON/OFF indicator for further animated display. 7 segment LED display (Android) The final Arduino result is send to android application and displayed. Thus, the Arduino water level indicator helps in preventing wastage of water in overhead tank. This project is wireless so, it is easy to install and it can work up to 400cm for HC-SR04 ultrasonic sensor. Circuit diagram Components required Arduino Nano - 1 no Bluetooth module HC-05 - 1no HC-SR04 ultrasonic sensor-1no 1-Channel 5V Relay Module - 1no HC-SR04 ultrasonic sensor The Ultrasonic sensor has four terminals - +5V, Trigger, Echo, and GND connected as follows − Connect the +5V pin to Vin Pin of Arduino Nano board. Connect Trigger to digital pin D12 of Arduino Nano board. Connect Echo to digital pin D13 of Arduino Nano board. Connect GND with GND on Arduino Nano. Datasheet Download Bluetooth HC-05 Module HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth. It has 6 pins, Key/EN- NC VCC to Connect 5 V power GND to power Ground TXD to Arduino Nano Rx (D0) RXD to Arduino Nano Tx (D1) State- NC HC-05 module Information HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module. HC-05 Default Settings Default Bluetooth Name: “HC-05” Default Password: 1234 or 0000 Download Datasheet Installing the Arduino Library Download Ultrasonic library , we need to use this library. Follow the next steps to install those libraries. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code. Download Android application. Android application First open Mobile application and select Bluetooth image button, after that select Bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234). Subscribe and Download code. Arduino Code #include Ultrasonic ultrasonic(12, 13); #include #define relay 7 #define buttonPin 10 int buttonState = 0; char Character; String Text; String TankHigh; String TankLow; String water; int CutOff; int heightset; int TankHeight; //long distance; int distance; float percentage,math; int LowCutoff; int HighCutoff; int Lowlevel; int Highlevel; void setup () { Serial.begin(9600); // We initialize serial connection so that we could print values from sensor. pinMode(buttonPin,INPUT); pinMode(relay,OUTPUT); Serial.setTimeout(200); } void loop () { distance = ultrasonic.read(); ////////////////// if(Serial.available()) { Character = Serial.read(); Text = Text + Character; if (Character == '*') { Text = Text.substring(0, Text.length() - 1); // Delete last char * CutOff = Text.indexOf(','); TankLow = Text.substring(0, CutOff); TankHigh = Text.substring(CutOff+1, -1); Text = ""; LowCutoff = (TankLow.toInt()); EEPROM.update(2,LowCutoff); {LowCutoff= EEPROM.read(2); } HighCutoff = (TankHigh.toInt()); EEPROM.update(4,HighCutoff); {HighCutoff= EEPROM.read(4); } delay(200); } } ///////////////////////////////////// buttonState = digitalRead(buttonPin); if (buttonState == LOW) // +RESISTOR, GND-BUTTON { TankHeight =distance; EEPROM.update(0,TankHeight); } {TankHeight= EEPROM.read(0); } delay(200); heightset= EEPROM.read(0); Lowlevel= EEPROM.read(2); Highlevel= EEPROM.read(4); math = heightset-distance; percentage = (math/heightset)*100; if ((percentage >= 0) && (percentage <= 100)) if (percentage <= Lowlevel) { digitalWrite(relay, HIGH); } if (percentage >= Highlevel) { digitalWrite(relay, LOW); } Serial.print(distance); Serial.print("|"); Serial.print(percentage); Serial.print("|"); Serial.print(Lowlevel); Serial.print("|"); Serial.print(Highlevel); Serial.print("|"); Serial.print(TankHeight); Serial.print("|"); Serial.print(digitalRead(relay)); Serial.print("\n"); delay(1000); }

  • Garbage Monitoring System with Bluetooth Interface

    This project Arduino based Garbage Monitoring system is a very innovative system which will help to keep the home, restaurant, hospitals, Office clean. This system monitors the garbage bins about the level of garbage collected in the garbage bins via mobile. For this the system uses ultrasonic sensors placed over the bins to detect the garbage level and compare it with the garbage bins depth. The system makes use of Arduino family microcontroller, Bluetooth HC-05 for sending data to android application. The Mobile screen is used to display the status of the level of garbage collected in the bins, remaining of free space and Bin height. The android application can set the Garbage bin height when empty bin for level calculations. The Garbage bin depth is 0 % to 100%, if the value less than 33% the bin color should be Green, if the value less than 66% and grater than 34% the bin color should be light rose, if the value less than 100% and grater than 67%the bin color should be Red is assigned in this project using android application. Circuit diagram Components required Arduino Nano - 1 no Bluetooth module HC-05 - 1no HC-SR04 ultrasonic sensor-1no HC-SR04 This is the HC-SR04 ultrasonic distance sensor. This economical sensor provides 2cm to 400cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3mm. Each HC-SR04 module includes an ultrasonic transmitter, a receiver and a control circuit. There are only four pins that you need to worry about on the HC-SR04: VCC (Power) to Arduino Nano Vin Pin Trig (Trigger) to Arduino Nano D2 Pin Echo (Receive) to Arduino Nano D3 Pin GND (Ground) to Arduino Nano GND Pin. Bluetooth HC-05 Module HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth. It has 6 pins, 1.Key/EN: It is used to bring Bluetooth module in AT commands mode. If Key/EN pin is set to high, then this module will work in command mode. Otherwise by default it is in data mode. The default baud rate of HC-05 in command mode is 38400bps and 9600 in data mode. HC-05 module has two modes, Data mode: Exchange of data between devices. Command mode: It uses AT commands which are used to change setting of HC-05. To send these commands to module serial (USART) port is used. 2. VCC: Connect 5 V or 3.3 V to this Pin. 3. GND: Ground Pin of module. 4. TXD: Transmit Serial data (wirelessly received data by Bluetooth module transmitted out serially on TXD pin) 5. RXD: Receive data serially (received data will be transmitted wirelessly by Bluetooth module). 6. State: It tells whether module is connected or not. HC-05 module Information HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module. HC-05 Default Settings Default Bluetooth Name: “HC-05” Default Password: 1234 or 0000 Default Communication: Slave Default Mode: Data Mode Data Mode Baud Rate: 9600, 8, N, 1 Command Mode Baud Rate: 38400, 8, N, 1 Default firmware: LINVOR Installing the Arduino Library Download Ultrasonic library , we need to use this library. Follow the next steps to install those libraries. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code. Download Android application. Mobile Output The Arduino will send this data via Bluetooth then the mobile application will receive this data and will proceed to show the status of the garbage bin level , free space to the user and giving a additional Gauge view with color changes in depends on percentage of waste filled in the garbage bin. First open Mobile application Garbage BT and select Bluetooth connect button, after that select Bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234). Subscribe and Download code. Arduino Code #include Ultrasonic ultrasonic(2, 3); #include int addr = 0; int height = 0; int heightset; int BinHeight; long distance; float percentage,math; String waste; // remove wiring from Bluetooth when program upload void setup () { Serial.begin(9600); // We initialize serial connection so that we could print values from sensor. } void loop () { // Every 500 miliseconds, do a measurement using the sensor and print the distance in centimeters. distance = ultrasonic.read(); if(Serial.available()> 0) { height = Serial.read(); if(height == 'h') { BinHeight =distance; EEPROM.write(addr,BinHeight); } {BinHeight= EEPROM.read(addr); } } delay(500); heightset= EEPROM.read(addr); math = heightset-distance; percentage = (math/heightset)*100; waste = (String)distance + "," + (String)percentage + "," + (String)heightset; Serial.println(waste); } After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the Arduino Uno board and see the result in monitor. Download .aia file https://drive.google.com/file/d/1KbmXBIM9xpV4IUayfnqQMmNkh1fonpMz/view?usp=sharing

  • DS18B20 Digital Thermometer with Bluetooth Interface

    Here to learn Arduino based bluetooth temperature sensor measures the temperature via the DS18B20 integrated digital temperature sensor and makes it available via bluetooth. This creating a kind of remote temperature monitor and temperature reading is transmitted via the Arduino’s serial port to the Arduino bluetooth module. Then the android application receive celsius & fahrenheit temperature reading and displays digital reading and therometer gauge display in mobile screen. Circuit Diagram: Components Required: Arduino Nano Board - 1 no DS18B20 with Probe - 1 no Resistor 4k7- 1 no HC-05 Bluetooth Module- 1no DS18B20 The DS18B20 is a 1-wire programmable Temperature sensor from maxim integrated. It is widely used to measure temperature in hard environments like in chemical solutions, mines or soil etc. The constriction of the sensor is rugged and also can be purchased with a waterproof option making the mounting process easy. It can measure a wide range of temperature from -55°C to +125° with a decent accuracy of ±5°C. Each sensor has a unique address and requires only one pin of the MCU to transfer data so it a very good choice for measuring temperature at multiple points without compromising much of your digital pins on the microcontroller. How to use the DS18B20 Sensor The sensor works with the method of 1-Wire communication. It requires only the data pin connected to the microcontroller with a pull up resistor and the other two pins are used for power as shown below. The pull-up resistor is used to keep the line in high state when the bus is not in use. The temperature value measured by the sensor will be stored in a 2-byte register inside the sensor. This data can be read by the using the 1- wire method by sending in a sequence of data. There are two types of commands that are to be sent to read the values, one is a ROM command and the other is function command. The address value of each ROM memory along with the sequence is given in the datasheet below. You have to read through it to understand how to communicate with the sensor. Applications Measuring temperature at hard environments Liquid temperature measurement Applications where temperature has to be measured at multiple points DS18B20 Sensor Specifications Programmable Digital Temperature Sensor Communicates using 1-Wire method Operating voltage: 3V to 5V Temperature Range: -55°C to +125°C Accuracy: ±0.5°C Output Resolution: 9-bit to 12-bit (programmable) Unique 64-bit address enables multiplexing Conversion time: 750ms at 12-bit Programmable alarm options Available as To-92, SOP and even as a waterproof sensor Bluetooth HC-05 Module HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth. It has 6 pins, 1.Key/EN: It is used to bring Bluetooth module in AT commands mode. If Key/EN pin is set to high, then this module will work in command mode. Otherwise by default it is in data mode. The default baud rate of HC-05 in command mode is 38400bps and 9600 in data mode. HC-05 module has two modes, Data mode: Exchange of data between devices. Command mode: It uses AT commands which are used to change setting of HC-05. To send these commands to module serial (USART) port is used. 2. VCC: Connect 5 V or 3.3 V to this Pin. 3. GND: Ground Pin of module. 4. TXD: Transmit Serial data (wirelessly received data by Bluetooth module transmitted out serially on TXD pin) 5. RXD: Receive data serially (received data will be transmitted wirelessly by Bluetooth module). 6. State: It tells whether module is connected or not. HC-05 module Information HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module. HC-05 Default Settings Default Bluetooth Name: “HC-05” Default Password: 1234 or 0000 Default Communication: Slave Default Mode: Data Mode Data Mode Baud Rate: 9600, 8, N, 1 Command Mode Baud Rate: 38400, 8, N, 1 Default firmware: LINVOR Installing the Arduino Library Installing Libraries for DS18B20 To interface with the DS18B20 temperature sensor, you need to install the One Wire library . Follow the next steps to install those libraries. 1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open. 2. Type “onewire” in the search box and install the OneWire library by Paul Stoffregen. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code. After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the Arduino Uno board and see the result in monitor. Mobile Output First open Mobile application Thermometer_BT and select Bluetooth Connect button, after that select bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234). Demo Video: Subscribe and Download code. Android Download Arduino code #include // OneWire DS18S20, DS18B20, DS1822 Temperature Example // http://www.pjrc.com/teensy/td_libs_OneWire.html OneWire ds(5); // on pin 10 (a 4.7K resistor is necessary) String temperature; void setup(void) { Serial.begin(9600); } void loop(void) { byte i; byte present = 0; byte type_s; byte data[12]; byte addr[8]; float celsius, fahrenheit; if ( !ds.search(addr)) { ds.reset_search(); delay(250); return; } for( i = 0; i < 8; i++) { //// Serial.write(' '); } if (OneWire::crc8(addr, 7) != addr[7]) { return; } // the first ROM byte indicates which chip switch (addr[0]) { case 0x10: type_s = 1; break; case 0x28: type_s = 0; break; case 0x22: type_s = 0; break; default: return; } ds.reset(); ds.select(addr); ds.write(0x44, 1); // start conversion, with parasite power on at the end delay(1000); // maybe 750ms is enough, maybe not // we might do a ds.depower() here, but the reset will take care of it. present = ds.reset(); ds.select(addr); ds.write(0xBE); // Read Scratchpad for ( i = 0; i < 9; i++) { // we need 9 bytes data[i] = ds.read(); } // Convert the data to actual temperature // because the result is a 16 bit signed integer, it should // be stored to an "int16_t" type, which is always 16 bits // even when compiled on a 32 bit processor. int16_t raw = (data[1] << 8) | data[0]; if (type_s) { raw = raw << 3; // 9 bit resolution default if (data[7] == 0x10) { // "count remain" gives full 12 bit resolution raw = (raw & 0xFFF0) + 12 - data[6]; } } else { byte cfg = (data[4] & 0x60); // at lower res, the low bits are undefined, so let's zero them if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms //// default is 12 bit resolution, 750 ms conversion time } celsius = (float)raw / 16.0; fahrenheit = celsius * 1.8 + 32.0; temperature = (String) celsius + "," + (String) fahrenheit ; Serial.println(temperature); }

  • Bluetooth Controlled Automatic Door using PIR Sensor

    Here to learn How to Make an Bluetooth controlled Automatic Door Opening and closing System Using Arduino, PIR Sensor HC-SR501 and android application, which automatically opens and closes the door by detecting a person and controlled by android app. You might have seen Automatic Door Opener Systems at office, shopping malls, cinemas, hospitals etc. where, as soon as a person approaches the door (at about 2 or 3 feet), the door automatically slides open. And after some time (about 5 to 10 seconds), the door closes by sliding in the reverse direction. Such Automatic Door Opener Systems are very useful as you do not need a person to standby the door and open it whenever a guest comes. Also, since the doors are opened and closed only when a person approaches the door. This automatic control and Stop control using bluetooth HC-05 through android application. So, In order to understand the potential of this concept, we have implemented a simple Automatic Door Opener System using Arduino and PIR HC-SR501 Sensor, Servo and Bluetooth. Circuit Diagram Components Required Arduino Nano - 1 no Bluetooth module HC-05 - 1no PIR HC-SR501sensor - 1 no Servo mini - 1 no HC-SR501 PIR sensor The PIR sensor stands for Passive Infrared sensor. It is a low cost sensor which can detect the presence of Human beings or animals. This sensor has three output pins Vcc, Output and Ground The module can be powered from voltage 4.5V to 20V but, typically 5V is used. Once the module is powered allow the module to calibrate itself for few minutes, 2 minutes is a well settled time. Then observe the output on the output pin. Before we analyze the output we need to know that there are two operating modes in this sensor such as Repeatable(H) and Non- Repeatable(L) and mode. The Repeatable mode is the default mode. The output of the sensor can be set by shorting any two pins on the left of the module. Repeatable(H) mode (used in this Project) In Repeatable(H) mode the output pin Dout will go high (3.3V) when a person is detected within range and goes low after a particular time (time is set by “Off time control” potentiometer). In this mode the output pin will go high irrespective of whether the person is still present inside the range or has left the area. The sensitivity can be set using the “sensitivity control” potentiometer Non- Repeatable(L) mode In “I” mode the output pin Dout will go high (3.3V) when a person is detected within range and will stay high as long as he/she stays within the limit of the Sensors range. Once the person has left the area the pin will go low after the particular time which can be set using the potentiometer. The sensitivity can be set using the “sensitivity control” potentiometer There are two important materials present in the sensor one is the pyroelectric crystal which can detect the heat signatures from a living organism (humans/animals) and the other is a Fresnel lenses which can widen the range of the sensor. Yes the white colour things is just a lense that is used to widen the range of the sensor, if you remove the lense you can find the Pyroelectric sensor inside it covered inside a protective metal casing as shown above. PIR Sensor Applications Automatic Street/Garage/Warehouse or Garden Lights Burglar Alarms Security cams as motion detectors Industrial Automation Control Download Datasheet Bluetooth HC-05 Module HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth. It has 6 pins, 1.Key/EN: It is used to bring Bluetooth module in AT commands mode. If Key/EN pin is set to high, then this module will work in command mode. Otherwise by default it is in data mode. The default baud rate of HC-05 in command mode is 38400bps and 9600 in data mode. HC-05 module has two modes, Data mode: Exchange of data between devices. Command mode: It uses AT commands which are used to change setting of HC-05. To send these commands to module serial (USART) port is used. 2. VCC: Connect 5 V or 3.3 V to this Pin. 3. GND: Ground Pin of module. 4. TXD: Transmit Serial data (wirelessly received data by Bluetooth module transmitted out serially on TXD pin) 5. RXD: Receive data serially (received data will be transmitted wirelessly by Bluetooth module). 6. State: It tells whether module is connected or not. HC-05 module Information HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module. HC-05 Default Settings Default Bluetooth Name: “HC-05” Default Password: 1234 or 0000 Default Communication: Slave Default Mode: Data Mode Data Mode Baud Rate: 9600, 8, N, 1 Command Mode Baud Rate: 38400, 8, N, 1 Default firmware: LINVOR Installing the Arduino Library No special library for this project. Subscribe and Download code. Download Android application. Download aia file for android development Mobile Output First open Mobile application BT PIR and select Bluetooth image, after that select bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234). Arduino Code: #include const int PIR_PIN = 8; // Arduino pin connected to motion sensor's pin const int SERVO_PIN = 9; // Arduino pin connected to servo motor's pin Servo servo; // create servo object to control a servo // variables will change: int angle = 0; // the current angle of servo motor int lastMotionState; // the previous state of motion sensor int currentMotionState; // the current state of motion sensor char switchstate; void setup() { Serial.begin(9600); // initialize serial pinMode(PIR_PIN, INPUT); // set arduino pin to input mode servo.attach(SERVO_PIN); // attaches the servo on pin 9 to the servo object servo.write(angle); currentMotionState = digitalRead(PIR_PIN); } void loop() { while(Serial.available()>0){ //code to be executed only when Serial.available()>0 /*Serial.available>0 is to check if there is any reading from the HC-05 Bluetooth module.*/ switchstate = Serial.read(); /*The character we had declared earlier is now being assigned a value- the value of whatever Serial.read() is.*/ //Serial.read() is to read the value coming from app. Serial.print(switchstate); //This will print the value onto the Serial monitor. Serial.print("\n"); //This moves to the next line after every new line printed. delay(15); } lastMotionState = currentMotionState; // save the last state currentMotionState = digitalRead(PIR_PIN); // read new state if (currentMotionState == LOW && lastMotionState == HIGH && (switchstate == 'A')) { // pin state change: LOW -> HIGH // Serial.println("DOOR CLOSE"); Serial.println(currentMotionState); servo.write(0); } //else if (currentMotionState == HIGH && lastMotionState == LOW && (switchstate == 'A')) { // pin state change: HIGH -> LOW // Serial.println("DOOR OPEN"); Serial.println(currentMotionState); servo.write(90); } }

  • Arduino Nano Based Weather Monitor with Bluetooth HC-05

    In this tutorial shows how to connect BMP280 barometric pressure, temperature and altitude sensor interface to Arduino Nano board with Bluetooth HC-05 and android application for output monitor. Circuit Diagram Components Required Arduino Nano - 1 no Bluetooth module HC-05 - 1no BMP 280 - 1no BMP280 Pressure Sensor Module: The GY-BMP280 Barometer Sensor is a breakout board for Bosch BMP280 high-precision and low-power digital barometer. It can be used to measure temperature and atmospheric pressure accurately. It can be connected to a microcontroller with I2C. Applications of GY-BMP280 Module Enhancement of GPS navigation (e.g. time-to-first-fix improvement, dead-reckoning, slope detection) Indoor navigation (floor detection, elevator detection) Outdoor navigation, leisure and sports applications Weather forecast, Home weather stations Health care application (e.g. sirometry) Vertical velocity indication (e.g. risk/sink speed) Handsets such as mobile phones, tablet PCs, GPS devices Flying toys Watches Bluetooth HC-05 Module HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth. It has 6 pins, 1.Key/EN: It is used to bring Bluetooth module in AT commands mode. If Key/EN pin is set to high, then this module will work in command mode. Otherwise by default it is in data mode. The default baud rate of HC-05 in command mode is 38400bps and 9600 in data mode. HC-05 module has two modes, Data mode: Exchange of data between devices. Command mode: It uses AT commands which are used to change setting of HC-05. To send these commands to module serial (USART) port is used. 2. VCC: Connect 5 V or 3.3 V to this Pin. 3. GND: Ground Pin of module. 4. TXD: Transmit Serial data (wirelessly received data by Bluetooth module transmitted out serially on TXD pin) 5. RXD: Receive data serially (received data will be transmitted wirelessly by Bluetooth module). 6. State: It tells whether module is connected or not. HC-05 module Information HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module. HC-05 Default Settings Default Bluetooth Name: “HC-05” Default Password: 1234 or 0000 Default Communication: Slave Default Mode: Data Mode Data Mode Baud Rate: 9600, 8, N, 1 Command Mode Baud Rate: 38400, 8, N, 1 Default firmware: LINVOR Installing the Arduino Library Download Adafruit_BMP280_Library , we need to use this library. Follow the next steps to install those libraries. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code. Download Android application. Mobile Output First open Mobile application BMP280 and select Bluetooth image, after that select bluetooth HC-05 device to connect and enter Password as mentioned above (0000 or 1234). Arduino Code #include #include #include Adafruit_BMP280 bmp; // I2C Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor(); Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor(); //Adafruit_BMP280 bmp(BMP_CS); // hardware SPI //Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); void setup() { Serial.begin(9600); Serial.println(F("BMP280 test")); //if (!bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID)) { if (!bmp.begin()) { Serial.println(F("Could not find a valid BMP280 sensor, check wiring or " "try a different address!")); while (1) delay(10); } /* Default settings from datasheet. */ bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ Adafruit_BMP280::FILTER_X16, /* Filtering. */ Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ bmp_temp->printSensorDetails(); } void loop() { sensors_event_t temp_event, pressure_event; bmp_temp->getEvent(&temp_event); bmp_pressure->getEvent(&pressure_event); // Serial.print(F("Temperature = ")); Serial.print(bmp.readTemperature()); // Serial.println("°C"); Serial.print("|"); // Serial.print(F("Pressure = ")); Serial.print(pressure_event.pressure); // Serial.println(" hPa"); Serial.print("|"); // Serial.print(F("Approx altitude = ")); Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */ // Serial.println(" m"); Serial.print("\n"); delay(1000); }

  • Water Level Depth Detection and LED control with Bluetooth HC-05

    In this article, we’re going to do an Arduino based water level depth sensor and (PWM) LED brightness control and interface with HC-05 Bluetooth module for Graphical representation using android mobile application and LCD display for Sensor dipped in water level data print. Circuit Diagram Components Required Arduino Uno - 1 no LCD16x2 I²C - 1no Bluetooth module HC-05 - 1no water level sensor K-0135- 1no LED - 1no Water Level Sensor Water sensor brick is designed for water detection, which can be widely used in sensing the rainfall, water level, even the liquate leakage. The brick is mainly comprised of three parts: An Electronic brick connector, a 1 MΩ resistor, and several lines of bare conducting wires. This sensor works by having a series of exposed traces connected to ground and interlaced between the grounded traces are the sense traces. The sensor traces have a weak pull-up resistor of 1 MΩ. The resistor will pull the sensor trace value high until a drop of water shorts the sensor trace to the grounded trace. Believe it or not this circuit will work with the digital I/O pins of your Arduino or you can use it with the analog pins to detect the amount of water induced contact between the grounded and sensor traces. This item can judge the water level through with a series of exposed parallel wires stitch to measure the water droplet/water size. This High Sensitivity Water Sensor can easily change the water size to analog signal, and output analog value can directly be used in the program function, then to achieve the function of water level alarm. This item have low power consumption, and high sensitivity, which are the biggest characteristics of this module. The High Sensitivity Water Sensor can be compatible with Arduino UNO, Arduino mega2560,Arduino ADK etc. However, one commonly known issue with these sensors is their short lifespan when exposed to a moist environment. Having power applied to the probe constantly speeds the rate of corrosion significantly. To overcome this, we recommend that you do not power the sensor constantly, but power it only when you take the readings The working of the water level sensor is pretty straightforward. The series of exposed parallel conductors, together acts as a variable resistor (just like a potentiometer) whose resistance varies according to the water level. The change in resistance corresponds to the distance from the top of the sensor to the surface of the water. The resistance is inversely proportional to the height of the water: The more water the sensor is immersed in, results in better conductivity and will result in a lower resistance. The less water the sensor is immersed in, results in poor conductivity and will result in a higher resistance. The sensor produces an output voltage according to the resistance, which by measuring we can determine the water level. Features : Working voltage: DC5V Working Current: <20ma Interface: Analog Width of detection: 40mm×16mm Working Temperature: 10°C~30°C Humidity: 10% -90% non-condensing Arduino compatible interface Low power consumption High sensitivity Output voltage signal: 0~4.2V Pin definition : "S" stand for signal input "+" stand for power supply "-" stand for GND Applications : Rainfall detecting Liquid leakage Tank overflow detector Bluetooth HC-05: HC-05 is a Bluetooth module which is designed for wireless comunication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth. It has 6 pins, 1.Key/EN: It is used to bring Bluetooth module in AT commands mode. If Key/EN pin is set to high, then this module will work in command mode. Otherwise by default it is in data mode. The default baud rate of HC-05 in command mode is 38400bps and 9600 in data mode. HC-05 module has two modes, Data mode: Exchange of data between devices. Command mode: It uses AT commands which are used to change setting of HC-05. To send these commands to module serial (USART) port is used. 2. VCC: Connect 5 V or 3.3 V to this Pin. 3. GND: Ground Pin of module. 4. TXD: Transmit Serial data (wirelessly received data by Bluetooth module transmitted out serially on TXD pin) 5. RXD: Receive data serially (received data will be transmitted wirelessly by Bluetooth module). 6. State: It tells whether module is connected or not. HC-05 module Information HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module. HC-05 Default Settings Default Bluetooth Name: “HC-05” Default Password: 1234 or 0000 Default Communication: Slave Default Mode: Data Mode Data Mode Baud Rate: 9600, 8, N, 1 Command Mode Baud Rate: 38400, 8, N, 1 Default firmware: LINVOR Installing the Arduino Library LiquidCrystal_I2C.h : you need to Download and install the LiquidCrystal_I2C library. Follow the next steps to install those libraries. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. Mobile output Subscribe and Download code. Download Android application. Final result: Arduino Code: #include LiquidCrystal_I2C lcd(0x27,16,2); // These constants won't change. They're used to give names to the pins used: const int analogInPin = A0; // Analog input pin that the potentiometer is attached to const int analogOutPin = 9; // Analog output pin that the LED is attached to int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out) int Level = 0; void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); pinMode(analogOutPin, OUTPUT); lcd.init(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); lcd.begin(16, 2); // set up the LCD's number of columns and rows: } void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 750, 0, 255); Level = map(outputValue, 0, 255, 0, 100); // calibrated value // change the analog out value: analogWrite(analogOutPin, outputValue); // print the results to the Serial Monitor: // Serial.print("sensor = "); // Serial.print(sensorValue); // Serial.print("\t output = "); // Serial.println(outputValue); Serial.println(Level); lcd.setCursor(0,0); lcd.print("LEVEL DETECTION "); lcd.setCursor(0,1); lcd.print("Dipped: "); lcd.print(Level); lcd.print(" %"); lcd.print(" "); // lcd.setCursor(0,1); // lcd.print("PWM: "); // lcd.print(outputValue); // lcd.print(" "); // wait 2 milliseconds before the next loop for the analog-to-digital // converter to settle after the last reading: delay(500); } MIT Block for mobile application.

  • LUX Meter Using BH1750 and OLED Display

    In this project, we will make a Arduino based LUX Meter Using BH1750 and OLED Gauge Display. Sometime we need to measure the exposure of light but a lux meter costs is high. Here to learn low cost and accurate ambient lighting sensor BH1750 interface with arduino with OLED Gauge display and enjoyed it. In this Project Push Button added for HOLD the Lux meter display value if pressed and Reading value displayed again push button pressed. Circuit Diagram Components Required Arduino Uno - 1 no OLED 0.96 SSD1306 - 4 PIN - 1no BH1750 GY-302- 1no Push button switch- 1 no BH1750 Refer previous project for more detail : https://www.dofbot.com/post/iot-cloud-bh1750-lux-monitor A digital Lux Meter is a device to measure the intensity of a source of light. A lux meter will be used in photography to estimate how bright the flash is and also the encircling ambient lighting. BH1750 is a digital ambient light sensor that is used commonly used in mobile phones to manipulate the screen brightness based on the environment lighting. This sensor can accurately measure the LUX value of light up to 65535lx. A digital Lux Meter is a device to measure the intensity of a source of light. A lux meter will be used in photography to estimate how bright the flash is and also the encircling ambient lighting. working principle of lux meter Most of the lux meter consists of a body, photocell or light sensor, and display. The light that falls on to the photocell or sensor contains energy that is transformed into electric current. Indeed, the measure of current depends on the light that strokes the photocell or light sensor. Lux meters read the electrical current calculate the appropriate value, and show this value on its display. BH1750 Features Power Supply: 2.4V-3.6V (typically 3.0V) Less current consumption: 0.12mA Measuring Rang: 1-65535lx Communication: I2C bus Accuracy: +/-20% Built in A/D converter for converting analog illuminance in the digital data. Very small effect of IR radiation Highly responsive near to human eye. This is a BH1750 light intensity sensor breakout board with a 16 bit AD converter built-in which can immediately output a digital signal, there is no need for complex calculations. This is more accurate and simpler to use the version of the simple LDR which only outputs a voltage that needs to be calculated to obtain meaningful data. First, connect the VCC and GND of the BH1750 Light Sensor to 3V3 and GND of Arduino Then connect the SCL and SDA pins of the sensor to corresponding pins of Arduino A5 &A4 Pin using jumper wires. Then, connect the SCL, SDA, GND, and VCC pin of the OLED display to the corresponding BH1750 sensor pins. Let's talk about lux and Illuminance: The lux (symbol: lx) is the SI derived unit of illuminance, measuring luminous flux per unit area. It is equal to one lumen per square meter. In photometry, this is used as a measure of the intensity, as perceived by the human eye, of light that hits or passes through a surface. It is analogous to the radiometric unit watt per square meter, but with the power at each wavelength weighted according to the luminosity function, a standardized model of human visual brightness perception. In English, "lux" is used as both the singular and plural form. Illuminance: Illuminance is a measure of how much luminous flux is spread over a given area. One can think of luminous flux (measured in lumens) as a measure of the total "amount" of visible light present, and the illuminance as a measure of the intensity of illumination on a surface. A given amount of light will illuminate a surface more dimly if it is spread over a larger area, so illuminance is inversely proportional to the area when the luminous flux is held constant. One lux is equal to one lumen per square meter: 1 lx = 1 lm/m2 = 1 cd·sr/m2. A flux of 1000 lumens, concentrated into an area of 1 square meter, lights up that square meter with an illuminance of 1000 lux. However, the same 1000 lumens, spread out over 10 square meters produces a dimmer illuminance of only 100 lux. OLED SSD1306-I2C 128X64 Display Module 0.96 inch This is a 0.96 inch Blue OLED display module. The display module can be interfaced with any microcontroller using SPI/IIC protocols. It is having a resolution of 128x64. The package includes display board,display, 4 pin male header presoldered to board. OLED (Organic Light-Emitting Diode) is a self light-emitting technology composed of a thin, multi-layered organic film placed between an anode and cathode. In contrast to LCD technology, OLED does not require a backlight. OLED possesses high application potential for virtually all types of displays and is regarded as the ultimate technology for the next generation of flat-panel displays. Download Data sheet Installing the Arduino Library Installing SSD1306 OLED Library – Arduino Download u8glib Library , we need to use this library for OLED Download BH1750_Library , we need to use this library for Lux Sensor Follow the next steps to install those libraries. In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code. Arduino Code: //----------------------------------------Include Library #include #include "U8glib.h" #include //---------------------------------------- //----------------------------------------Initialize u8g U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI //---------------------------------------- ///----------------------------------------BH1750 I2C address // ADDR line LOW/open: I2C address 0x23 (0x46 including R/W bit) [default] // ADDR line HIGH: I2C address 0x5C (0xB8 including R/W bit) BH1750 sensor(LOW); //---------------------------------------- //----------------------------------------Variable and button pin declarations #define Button_Pin 4 bool Button; //---------------------------------------- //----------------------------------------Variable for LUX Value uint16_t read_lux; uint16_t result_lux; byte lux_HR; //---------------------------------------- int x_LUX_val; //--> X position to display LUX value //----------------------------------------Variables for Gauge Chart int xmax=128; int ymax=62; int xcenter=xmax/2; int ycenter=ymax/2+10; int arc=ymax/2; int angle=0; int p, w, m; u8g_uint_t xx=0; //----------------------------------------Variables for Gauge Chart //----------------------------------------Variable for Mode // Mode = 1 for realtime reading of sensor values (LUX). // Mode = 2 to capture sensor value (LUX). int Mode = 1; //---------------------------------------- bool Blink_Cap; //--> Variables to make the sensor value flashes on the capture mode. unsigned long previousMillis = 0; //--> will store last time was updated const long interval = 250; //--> interval (milliseconds) //========================================================================VOID ShowLux_With_GaugeChart(uint8_t angle) void ShowLux_With_GaugeChart(uint8_t angle) { //----------------------------------------draw border of the gauge u8g.drawCircle(xcenter,ycenter,arc+6, U8G_DRAW_UPPER_RIGHT); u8g.drawCircle(xcenter,ycenter,arc+4, U8G_DRAW_UPPER_RIGHT); u8g.drawCircle(xcenter,ycenter,arc+6, U8G_DRAW_UPPER_LEFT); u8g.drawCircle(xcenter,ycenter,arc+4, U8G_DRAW_UPPER_LEFT); //---------------------------------------- //----------------------------------------draw the needle float x1=sin(2*angle*2*3.14/360); float y1=cos(2*angle*2*3.14/360); u8g.drawLine(xcenter, ycenter, xcenter+arc*x1, ycenter-arc*y1); u8g.drawDisc(xcenter, ycenter, 5, U8G_DRAW_UPPER_LEFT); u8g.drawDisc(xcenter, ycenter, 5, U8G_DRAW_UPPER_RIGHT); u8g.setFont(u8g_font_chikita); //---------------------------------------- //----------------------------------------show MIN and MAX labels u8g.drawStr(0, 5, "MIN"); u8g.drawStr(0, 13, "1"); u8g.drawStr(110, 5, "MAX"); u8g.drawStr(98, 13, "65535"); u8g.drawStr(9, 42, "MIN"); u8g.drawStr(105, 42, "MAX"); //---------------------------------------- //----------------------------------------show gauge label u8g.setPrintPos(56,24); u8g.print("LUX"); u8g.setPrintPos(50,32); u8g.print("METER"); //---------------------------------------- u8g.setFont(u8g_font_unifont); //----------------------------------------Conditions for displaying LUX value center align on OLED if (result_lux < 10) { x_LUX_val = 36; } else if (result_lux < 100 && result_lux > 9) { x_LUX_val = 32; } else if (result_lux < 1000 && result_lux > 99) { x_LUX_val = 28; } else if (result_lux < 10000 && result_lux > 999) { x_LUX_val = 24; } else if (result_lux > 9999) { x_LUX_val = 20; } //---------------------------------------- //----------------------------------------Mode = 1 for realtime reading of sensor values (LUX). if (Mode == 1) { u8g.setPrintPos(x_LUX_val, 60); u8g.print(result_lux); u8g.print("."); u8g.print(lux_HR); u8g.print(" lx"); } //---------------------------------------- //----------------------------------------Mode = 2 to capture sensor value (LUX). if (Mode == 2) { if (Blink_Cap == false) { u8g.setPrintPos(x_LUX_val, 60); u8g.print(result_lux); u8g.print("."); u8g.print(lux_HR); u8g.print(" lx"); } else { u8g.setPrintPos(0, 60); u8g.print(" "); } //---------------------------------------- } } //======================================================================== //========================================================================VOID SETUP void setup(void) { u8g.setFont(u8g_font_chikita); pinMode(Button_Pin, INPUT_PULLUP); Wire.begin(); //--> Initialize I2C bus sensor.begin(ModeContinuous, ResolutionHigh); //--> Initialize sensor in continues mode, high 0.5 lx resolution sensor.startConversion(); //--> Start conversion } //======================================================================== //========================================================================VOID LOOP void loop(void) { //----------------------------------------Read button Button = digitalRead(Button_Pin); if (Button == LOW) { Mode++; if (Mode > 2) Mode = 1; //----------------------------------------Looping to check the button condition until the button is finished pressing to perform the next instruction. while(Button == LOW) { Button = digitalRead(Button_Pin); delay(100); } //---------------------------------------- } //---------------------------------------- //.................................................................................Millis for loop delay unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; //--> save the last time currentMillis //----------------------------------------Mode = 1 for realtime reading of sensor values (LUX). if (Mode == 1) { //----------------------------------------Wait for completion (blocking busy-wait delay) if (sensor.isConversionCompleted()) { read_lux = sensor.read(); //--> Read light result_lux = read_lux / 2; lux_HR = read_lux % 10; } //---------------------------------------- } //---------------------------------------- if (Mode == 2) Blink_Cap = !Blink_Cap; //--> Toggle Blink_Cap //----------------------------------------Converts sensor / LUX value to angle value m = map(result_lux,0,65535,0,90); //---------------------------------------- //----------------------------------------show needle and dial xx = m; if (xx<45){ xx=xx+135; } else { xx=xx-45; } //---------------------------------------- //----------------------------------------picture loop (Loop for display on OLED) u8g.firstPage(); do { ShowLux_With_GaugeChart(xx); } while( u8g.nextPage() ); //---------------------------------------- } //................................................................................. }

  • Radar Monitor using Ultrasonic sensor

    In this tutorial we are learn to finding Object distance and angle (radar monitor) using Ultrasonic sensor and Servo Motor. Radars have long been used for detecting objects far away and mapping them on a display. With a number of military and arial applications radars are widely used these days. This advanced Arduino sonar system can be used to monitor local patch area and can also scan suspicious object. We propose to demonstrate this concept using arduino based radar project. This Arduino sonar project system continuously scans the area at 180 degree angle using Servo motor and the radar provides the angle as well as distance of the object from the source and value sent to OLED display. It makes use of an ultrasonic wave to simulate sonar or radar sweep 180 degree. It is mounted on a Servo motor to create sweep angles and rotate the ultrasonic sensor. Circuit Diagram Components Required Arduino Uno - 1 no Ultrasonic Sensor HC-SR04 - 1no Ultrasonic Sensor Mounting Bracket - 1 Servo Motor MG90S - 1no OLED 0.96 SSD1306 - 4 PIN - 1no HC-SR04 HC-SR04 Ultrasonic (US) sensor is a 4 pin module, whose pin names are Vcc, Trigger, Echo and Ground respectively. This sensor is a very popular sensor used in many applications where measuring distance or sensing objects are required. The module has two eyes like projects in the front which forms the Ultrasonic transmitter and Receiver. The sensor works with the simple high school formula that Distance = Speed × Time Refer more Data sheet Download OLED SSD1306-I2C 128X64 Display Module 0.96 inch This is a 0.96 inch Blue-Yellow OLED display module. The display module can be interfaced with any microcontroller using SPI/IIC protocols. It is having a resolution of 128x64. The package includes display board,display, 4 pin male header presoldered to board. OLED (Organic Light-Emitting Diode) is a self light-emitting technology composed of a thin, multi-layered organic film placed between an anode and cathode. In contrast to LCD technology, OLED does not require a backlight. OLED possesses high application potential for virtually all types of displays and is regarded as the ultimate technology for the next generation of flat-panel displays. ssd1306 Specifications : Viewing angle : greater than 160 degrees Supported platforms : for arduino, 51 series, MSP430 series, STIM32 / 2, SCR chips Low power consumption : 0.04W during normal operation Support wide voltage : 3.3V-5V DC Driver IC : SSD1306 Communication : IIC, only two I / O ports No font : The software takes word modulo Backlight : OLED self light, no backlight Interface: VCC: 3.3-5V GND: Ground SCL: Serial Clock SDA: Serial Installing the Arduino Library Installing SSD1306 OLED Library – Arduino Download Adafruit_SSD1306_Library , we need to use this library for OLED Download Adafruit_GFX_Library , we need to use this library for OLED Follow the next steps to install those libraries. 1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open. 2. Type “SSD1306” in the search box and install the Adafruit SSD1306 library version 1.2.9 library from Adafruit. 3. After installing the SSD1306 library from Adafruit GFX version 1.4.13 in the search box and install the library. 4. After installing the libraries, restart your Arduino IDE. After installing the required libraries, copy the following code to your Arduino IDE. Subscribe and Download code. Arduino Code: #include #include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)//unstroke for yellow+blue OLED // double stroke for Blue OLED Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); #include Servo servo; const int trig = 2, echo = 3 ; int pos = 0, distcm = 0; void setup() { Serial.begin(9600); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); pinMode(trig, OUTPUT); pinMode(echo, INPUT); servo.attach(9); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(7,0); display.clearDisplay(); display.println("DOFBOT PROJECTS"); display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(0,10); display.println("WELCOME"); display.display(); delay(3000); } void loop() { for (pos = 0; pos <= 180; pos += 1) { servo.write(pos); delay(50); Serial.println(radar()); display.clearDisplay(); // text display tests display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,0); display.println("RADAR SCANNING.."); display.setTextColor(BLACK, WHITE); // 'inverted' text //display.println(3.141592); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,16); display.print("DISTANCE SERVO"); display.setCursor(0,30); display.print(" IN CM DEGREE"); display.display(); display.setTextColor(WHITE); display.setCursor(0,45); display.setTextSize(2); display.print(radar()); display.setCursor(90,45); display.setTextSize(2); display.print(pos); // display.println(0xDEADBEEF, HEX); display.display(); } for (pos = 180; pos >= 0; pos -= 1) { servo.write(pos); delay(50); Serial.println(radar()); display.clearDisplay(); // text display tests display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,0); display.println("RADAR SCANNING...."); display.setTextColor(BLACK, WHITE); // 'inverted' text //display.println(3.141592); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,16); display.print("DISTANCE SERVO"); display.setCursor(0,30); display.print(" IN CM DEGREE"); display.display(); display.setTextColor(WHITE); display.setCursor(0,45); display.setTextSize(2); display.setTextSize(2); display.print(radar()); display.setCursor(90,45); display.setTextSize(2); display.print(pos); // display.println(0xDEADBEEF, HEX); display.display(); } delay(50); } long radar(void) { digitalWrite(trig, HIGH); delayMicroseconds(15); digitalWrite(trig, LOW); long dur = pulseIn(echo, HIGH); distcm = dur / 58; return distcm; delay(300); } After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the Arduino Uno board and Open Serial monitor and see the result in Serial monitor.

bottom of page