Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Wednesday, May 26, 2021

Make Automatic Room light

Automatic Room Light Using Ultrasonic Sensor

Things Required:

·         Arduino

·         HC SR-04 Ultrasonic Sensor

·         5V Relay Module

·         Jumper Wires

Connections:

 


Code for Arduino:


#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.

#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.

#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). The maximum sensor distance is rated at 400-500cm. [this is an arbitrary number]

 

#define RELAY_LINE1_PIN 8

 

#include "NewPing.h"

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

 

 

unsigned int critical_distance_cms = 50;  // Cutoff distance at which the light will switch [this is an arbitrary number]

bool state = 0;

 

void setup() {

  Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.

  pinMode(RELAY_LINE1_PIN, OUTPUT);

  digitalWrite(RELAY_LINE1_PIN, HIGH);  // Turn the light off

}

 

void loop() {

  delay(5);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.

  unsigned int distance = readDistance(); // Current distance of any object facing the ultrasonic sensor

 

  Serial.print("Ultrasonic: ");

  Serial.print(distance); // Send ping, get distance in cm and print result (0 = outside set distance range)

  Serial.println("cm");

 

  // Someone is near the door

  if (distance < critical_distance_cms)

  {

    while (distance < critical_distance_cms)

    {

      // Check if they moved away

      distance = readDistance();

 

      delay(5); // Do nothing until the person moves away from the door

    }

 

    state = !state; // Change the state of the relay

 

    if (state)

    {

      Serial.println("Door Open!");

      digitalWrite(RELAY_LINE1_PIN, LOW); // Turn the light on

    }

    else

    {

      Serial.println("Door Closed!");

      digitalWrite(RELAY_LINE1_PIN, HIGH);  // Turn the light off

    }

  }

}

 

// Updates the value of the Ultrasonic reading

unsigned int readDistance()

{

  // Read 7 values from the ultrasonic and get the median value ( median filter )

  // Gets rid of noisy reading

  unsigned int distance = sonar.convert_cm(sonar.ping_median(7));

 

  // The value 0 indicates that the ultrasonic sensor is reading nothing in front of it

  // Set this distance to max distance so the light doesn't switch unnecessarily

  if (distance == 0)

  {

    distance = MAX_DISTANCE;

  }

 

  return distance;

}

 

Note:

            You can change the range of ultrasonic sensor by changing the value in the code which is mentioned in the third line of the code.

If you are facing a problem, contact me: rizwanmahad606@gmail.com


Stay tuned.

Bye.


Tuesday, May 25, 2021

Room Automation using IR Sensor

 

Automatic Light using IR Sensor

Things Required:

·         IR (Infrared) Sensor

·         5V Relay Module

·         Arduino (Uno or Nano)

·         Jumper Wires

Connections:

 


 

 

 

Code for Arduino:

int pbutton=8;

int led=3;

 

int val=0;

int ledon=0;

int pushed=0;

 

void setup()

{

  Serial.begin(9600);

  pinMode(pbutton, INPUT_PULLUP);

  pinMode(led, OUTPUT);

 

}

 

void loop()

{

  val=digitalRead(pbutton);

  if(val==HIGH && ledon==LOW)

  {

    pushed=1-pushed;

    delay(100);

  }

 

  ledon=val;

  if(pushed==HIGH)

  {

    Serial.println("led on");

    digitalWrite(led, LOW);

  }

 

  else

  {

    Serial.println("led off");

    digitalWrite(led, HIGH);

 

 

  } 

}

 

You can use this as an automatic room light.

If you are facing a problem making this, contact me at rizwanmahad606@gmail.com

Stay tuned.

Bye.

 

Wednesday, May 12, 2021

Types of Arduino: Explained.

Arduino:

If you haven't heard of Arduino, it's an entire ecosystem created for playing with and working with microcontrollers. There are many boards available that are considered to be Arduino compatible.

There's also software you can download which is the Arduino development environment that you can use to program the different boards. Almost everything in the Arduino world is considered to be open-source which means we can go online and find the schematics for these different boards and we can go and get the source code for the development environment. One of the other cool things about Arduino is its ability to stack these things called shields. For example, we have an mp3 player shield that we can stack on top of a few different Arduinos. This allows us to play music and other sound files.

 

 

Arduino Uno:

                First, we have Arduino’s flagship and most popular board the UNO. The Arduino UNO is built around the Atmel atmega 328p microcontroller. This runs at 16 megahertz. It offers 14 digital input/output pins or i/o pins and six of those can be used for pulse width modulation or PWM. On the other side, you'll notice another six pins that can be used for analog inputs. The 328p offers 32 kilobytes of flash memory which is used for holding programs and 2 kilobytes of RAM. Notice that the input/output pins run at 5 volts which means you want to be careful if you're trying to connect it to 3.3-volt logic. You could easily damage something. There are two versions

The UNO is a great board if you're just getting started in the world of Arduino or embedded electronics.

There's tons of documentation online you can find about it.

 

 SPARC fun red board:

                Next, we have the SPARC fun red board. This is the SPARC funds version of the Arduino with similar functionality to the UNO. It combines several of our favorite features from different Arduinos into one board. It is a bit cheaper and it allows us to control revisions and features.

 

Arduino Pro:

                Next, we have the Arduino Pro. This uses the same 328p microcontroller so it has less the same functionality as the UNO. The biggest difference you'll notice is that the pro comes without headers. This gives the user the option to solder on wires, male or female headers whatever they want. There are two different versions of the pro. The 3.3-volt version and the 5-volt version. You'll notice that some electronics can only handle 3.3 volts. You can easily damage sensitive electronics with something like 5 volts. Notice that the speed has been reduced to 8 megahertz for the 3.3-volt version but The 5-volt version still has a whopping 16 megahertz. The Arduino Pro does not have built-in USB support so you're going to need a serial cable or an FTDI breakout to program them. Make sure that the voltage of the cable or the breakout matches the voltage listed on your Arduino Pro. Otherwise, you could end up hurting some electronics.

 

Arduino Pro Mini:

                The pro mini it's exactly like the pro but in a tiny form-factor like the pro, the pro mini comes in 3.3 and 5-volt versions and you will need a serial cable or FTDI breakout to program them. It's small, it's cheap and it's easy to fit on a breadboard because there's a 3.3-volt version available. It's great to use with 3.3 volts sensors.

 

Arduino Pro Micro:

                Then we have the pro micro. This is similar to the pro mini but you don't need a special serial cable or FTDI breakout to program it. The first thing you'll notice about the pro micro is that there's a micro A USB port on the board. It also uses a different chip. It uses the atmega 32 u 4 which has built-in USB support. There are 12 digital i/o pins and 5 of those can be used for PWM. There are an additional 4 analog input pins on the board as well. Like the 328p, the chip contains 32 kilobytes of flash but there's a bit more RAM at 2.5 kilobytes. Like the pro mini, the pro micro comes in 3.3 volts and 5 volt versions where the 3.3-volt version runs at 8 megahertz and the 5-volt version runs at 16 megahertz. One cool feature about the pro micro is that it can be used as a USB device.

 

Arduino Micro View:

                Next, we have the micro view. This is a small Arduino compatible module with a built-in a

LED display. The O LED display is monochrome with a 64 by 48-pixel resolution. The micro view uses the same atmega328p microcontroller found in many of the other Arduino products. There's 12 digital i/o pins and 6 analog input pins. Notice that the pins run at 3.3 volt logic. There are a few ways to program. The micro view although the best is to use the micro view programmer. This is a really cool device to use if you just want to make some simple graphics.

 

Arduino Mega 2560:

                Then there's the Arduino mega 2560. The mega uses the at mega 2560 processor running at 16

Megahertz. There's a whopping 54 digital i/o pins and 15 of those can be used for PWM. There are an additional 16 analog inputs as well. It has 256 kilobytes of flash which is a lot of room for your programs and eight kilobytes of RAM. This is a great device for when you need a ton of pins. It also has 4 hardware serial ports where the UNO only has one. It is really useful when you're connecting to other serial peripherals and you need to send debugging information.

 

Arduino Yun:

                Finally, we have the Arduino Yun and this is closer to a single board computer. The Arduino Yun has two processors on board. Underneath the metal can is an Atheros our 93 31 which is typically found in Wi-Fi routers. It works at 400 megahertz and runs a custom version of Linux is known as open wrt you. Additionally, there's an atmega 32 u 4 onboard which can be programmed with Arduino. It has 32 kilobytes of flash and 2.5 kilobytes of RAM. Much like the pro micro, there are some features on the Yun which are not found on other Arduino boards. For example, it has Ethernet and Wi-Fi already on board and it can work as a USB host so you can do things like plug in a flash drive. There's a micro USB port for programming power and communications and a micro SD card slot. On the backside, there are 20 i/o pins of which seven of those can be used for PWM and 12 for analog input. 

Stay tuned. Bye

Monday, May 3, 2021

Home automation using Bluetooth

 

Bluetooth based Home Automation:

Components Required:

·        Arduino (UNO, or Nano)

·        Bluetooth Module (HC-06 or HC-05)

·        5V Relay (4 channel)

·        Jumper Wires

·        Breadboard (in case of Nano)

Working:

·        Arduino will be the mainboard. You can use any of Nano, UNO, and mega as well. Both have similar pins for connections and their method of uploading programs are the same. I am using Nano.

·        Bluetooth Module is responsible for receiving instructions from a smartphone. You can use any of HC-05 and HC-06 as they have the same pins.

·        The relay will act as a switch for appliances like a light bulb to on and off. You can use any relay module but you have to make some changes to the code as well. I recommend you to use 2 channel or 4 channel relay. But you can also use a single channel relay with this code as well.

·        Jumper wires will help to make connections.

·        I am using Arduino Nano. So, I also have to use a breadboard.

Connections:

 

Application:
        There are many apps available. If you are facing a problem in finding an application, contact me at: rizwanmahad606@gmail.com.
Code:

char data = 0;

void setup() {

  Serial.begin(9600);

  pinMode(8,OUTPUT);

  pinMode(9,OUTPUT);

  pinMode(10,OUTPUT);

  pinMode(11,OUTPUT);

 

}

 

void loop() {

  if(Serial.available()>0)

{

data=Serial.read();

Serial.print(data);

Serial.print("\n");

if(data=='a')

digitalWrite(8,HIGH);

else if(data=='b')

digitalWrite(8,LOW);

if(data=='c')

digitalWrite(9,HIGH);

else if(data=='d')

digitalWrite(9,LOW);

if(data=='e')

digitalWrite(10,HIGH);

else if(data=='f')

digitalWrite(10,LOW);

if(data=='g')

digitalWrite(11,HIGH);

else if(data=='h')

digitalWrite(11,LOW);

}

}

 

Note:

Disconnect the Bluetooth module while uploading the code.

If you are facing a problem with this project, contact me in the comments. Hope you will enjoy this project.

Sunday, May 2, 2021

Arduino Nano: Explained.

 

Arduino Nano

 




 Let's get started with Arduino Nano.

Microcontroller:

Arduino Nano is a Microcontroller Board designed by Arduino. cc

The microcontroller used in Arduino Nano is ATmega328p.

Pins:

Let’s discuss its pins.

So, coming towards its pinout, Arduino Nano has 12 digital pins starting from D2 to D13. It also has 8 analog pins starting from A0 to A7.

These digital & analog pins are assigned with multiple functions but their main function is to act as either input or output.

1

D0 - D13

Digital Input / Output Pins.

2

A0 - A7

Analog Input / Output Pins.

3

Pin # 3, 5, 6, 9, 11

Pulse Width Modulation ( PWM ) Pins.

4

Pin # 0 (RX) , Pin # 1 (TX)

Serial Communication Pins.

5

Pin # 10, 11, 12, 13

SPI Communication Pins.

6

Pin # A4, A5

I2C Communication Pins.

7

Pin # 13

Built-In LED for Testing.

8

D2 & D3

External Interrupt Pins.

 

For example, if you are working on some project and you want to interface some sensors with any of these pins, then, in that case, you have to make those pins INPUT.

But if you are interfacing a LED then that pin will act as OUTPUT because it’s sending a command from Arduino Nano.

Arduino Nano can perform 3 types of communication protocols, which are: Serial, SPI & I2C Protocol.

Pin # 0 and 1 are used for Serial communication, where Pin # 0 is RX, used to receive data and Pin # 1 is TX and we transmit serial data via this pin

It also has an SPI protocol and pins used for SPI communication are Pin # 10, 11, 12, and 13 Where Pin # 10 is SS short for Slave Select.

Pin # 11 is MOSI short for Master Out Slave In.

Pin # 12 is MISO short for Master In Slave Out.

And the last one Pin # 13 is SCK short for Serial Clock.

We also have I2C Protocol in Arduino Nano and the pins used for I2C Communication are A4 and A5 where A4 is SDA short for Data Line and A5 is SCL short for Clock Line.

So, we can use these pins as input/output and can also perform these different types of communications.

It depends on our projects' requirements.

For example, if we have GSM module which works on serial protocol then we have to interface that module with Pin # 0 and Pin # 1.

Similarly, if we are working on some RTC module then RTC works on I2C Protocol and we have to interface that module with A4 and A5 Pin.

We can also use Software Serial in Arduino Nano.

Arduino Nano has only one Hardware Serial Port but let's say you are working on some project where you have to interface two Serial modules with Arduino Nano

In that case, you have to create a software serial in Arduino Nano.

Arduino Nano also has 6 PWM Pins: Pin # 3, 5, 6 , 9, 10, and 11.

These Pins can be used for Pulse Width Modulation.

It also has two Reset Pins that are used to reset this Arduino NANO programmatically.

It also has a RESET Button on it.

It uses a crystal oscillator of 16 MHz frequency.

It has 4 LEDs embedded in it.

The first LED is for TX, the second one is for RX where the third LED is for Power and the fourth one is connected to Pin # 13 and is normally used for Testing.

Memory:

Arduino Nano has 3 types of built-in memories associated with it.

The first one is Flash Memory.

Arduino Nano has a Flash memory of 32 KB.

This Flash memory is responsible for storing our code in Arduino Nano

Flash memory of Arduino Nano is 32 KB but 2KB of its memory is used for Bootloader which is pre-installed on Arduino Nano.

The SRAM memory of Arduino Nano is 2KB, while the EEPROM memory is 1KB.

The input range of Arduino Nano varies from 7V to 12V, while the operating voltage is 5V.

It doesn't have a DC Power Jack as in Arduino UNO, but we have this mini USB Port, which is used for powering up as well as uploading code in Arduino Nano

.

 

 

Scanners: Explained.

 Introduction:           If you need a copy of a document that is sitting on your table. For this, with your PC, you use your flatbed scan...