Find fresh tutorials related to Arduino, Raspberry Pi, 555 Timer and many more microcontrollers. Learn something new everyday!



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

Saturday, 31 January 2015

Controlling micro servos using Arduino [ARDUINO]


So, by now you should have learnt how to control different things using HC-05 bluetooth module. Bluetooth becomes really convenient in home automation, because, it's simple. Especially controlling relays becomes very easy.

Now, let's shift our attention towards the mechanical side of electronics. Yeah, I'm talking about servos and motors. Servos, undoubtedly have many real life applications.
Servos come cheap. I ordered a few TowerPro Micro Servos for $4 each from Ebay. Maybe you'll find cheaper ones than these.

Yesterday I received these two cute little servos. The first thing that amazed me was the size. Check the image below:

The SG90 alongside a Rs.5 coin


Something about servos:
Simply put, a servo is a DC motor, but wait. Don't be mistaken.
It's a motor, which comes with several integrated gears that can be precisely controlled using sophisticated MCUs. This means, unlike a DC motor, whose only controllable parameter is the speed(by changing the voltage across it), a servo motor's shaft can be precisely controlled to a particular angular position. Read more about it on Wikipedia.

Given below is a simple 9g micro servo, with voltage requirements of 4.8V shown alongwith its horns and screws.

The micro servo with its attachments


What this project does?
Teaches you the simplest program to control a servo using arduino. This program will simply rotate the horn of your servo by 180 degrees CW and ACW.

Materials Required:
1. A 9g micro servo
2. Arduino
3. Jumpers
4. Breadboard
5. and of course, a PC with Arduino IDE installed!

Procedure:

Software part:
1. Upload the sketch given below.

Hardware part:
1. Connect the components as shown:

Schematics
2. Power on the Arduino.

WARNING: DON'T ATTACH MORE THAN TWO SERVOS DIRECTLY TO THE ARDUINO BOARD. USB CAN'T PROVIDE ENOUGH POWER FOR THEM. 

Sketch:
The sketch is the same one on official arduino site. Click here for the code

How this works (Algorithm):
The arduino is given the position feedback via its internal circuitry. The PWM pin 9 of the arduino varies the voltage and thus rotates the shaft accordingly.


Something for you!
Try these ideas to enhance your knowledge and test yourself:
1. Make a bluetooth operated servo controller.
2. Make a servo controller using two push button switches that rotate the servo either clockwise or anticlockwise.

The servos have a variety of applications including robotic arms to complete robots. Bipeds, Quadrupeds, etc implement the use of these servos. Several servo related projects will soon follow. Keep checking out electro.nitishdash.com everyday!


Saturday, 10 January 2015

Using HC-05 Bluetooth Module - Control an LED with an Android phone [ARDUINO]



So, you saw how we used a PIR motion sensor to create a simple motion detecting mechanism within a short span of time. We also saw how to use simple sensors like HC-SR04HC-SR501 and DHT11. We even controlled LCD and 7-segment display. But, the major inconvenience was - wiring. Just think of it. You make a motion detector, wire up all the components and then what, connect an LED in your room with around 5 to 6 meters to the setup on your staircase? Oh, hell no! In situations like these, the word: "wireless" comes to our mind, and why shouldn't it? Everything around us is more or less, wireless! Our phones, wifi, etc are major examples. You can even lock your car with a tiny wireless remote. We all know stuff like these.

But, to make your arduino project wireless, you have a lot of technologies at your disposal.
Major wireless techniques, that could be used with arduino projects and let you go wireless:
1. Bluetooth
2. FM transceiver
3. Infrared
4. WiFi

Now, let's briefly discuss these technologies:

1. Bluetooth: 

    Simple, elegant, cheap. Has a pretty good range. Less complicated. Easy to connect. A large spectrum of devices use Bluetooth.

2. FM transceiver:

    Excessively cheap. Pretty great range (90 meters). Requires two standalone arduinos(One for receiving, One for transferring data)
    But, huge chances for interference. Legal issues.

3. Infrared:

   Cheap, short range. Less effective, not secure. Can't send different signals.

4. WiFi:

   A bit expensive. Good range. A bit complex. But, convenient.

Don't worry, slowly but steadily, we'll use all of those, but first, lemme take a selfie! Just, kidding.
But first, let's use bluetooth in our projects.

Let's know the basics:

Pinouts of my HC-05 module

HC-05 module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for
transparent wireless serial connection setup.
Serial port Bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps
Modulation with complete 2.4GHz radio transceiver and baseband. It uses CSR Bluecore
04-External single chip Bluetooth system with CMOS technology and with AFH(Adaptive
Frequency Hopping Feature). It has the footprint as small as 12.7mmx27mm. Hope it will simplify
your overall design/development cycle.

The HC-06 module is similar in design to the HC-05, but, it can't act as a master device. The HC-05 can behave both as master and slave.

We'll also use this library: Software serial

What this project does?
Demonstates the simple use of HC-05 bluetooth module. With this, you can simply use your android phone to turn an LED ON or OFF, via an android app.

Materials Required:
Click for clarity

1. An HC-05 or HC-06 Bluetooth Module
2. Arduino
3. Jumpers
4. One LED
5. One 220OHM resistor for LED
6. Breadboard
7. and of course, a PC with Arduino IDE installed.
8. Oh yes, an Android phone too!


Procedure:

1. Upload the sketch given below.
2. Then remove the arduino and wire up the components as shown below.




NOTE: PLEASE REMEMBER TO CONNECT THE RX OF HC-05 TO SOFT TX[PIN 11] ON ARDUINO AND VICE VERSA.


3. Power on the Arduino.
4. Download and install the app on your phone: [DOWNLOAD THE APP]
5. Turn on the BLUETOOTH in your phone and tap on Scan.
6. You'll notice your HC-05 or HC-06 name on the list of found devices.
7. Tap on the module's name and pair with it. The default pairing code is 1234 or 0000
8. Now, open the HC05_ARDUINO_LED app.
9. Tap :"Connect to Module"
10. You'll get a screen, where the nearby bluetooth devices' names and addresses will be listed.
11. Tap on the device(HC-05 or HC-06)
12. You'll notice that the led on HC-05 will stop blinking randomly and will blink once in every 4 seconds
13. Now, tap on ON to turn on the LED or tap on OFF to turn it off.
14. Done. Simple. :)

Sketch:

/* 
 * ON PUBLIC DOMAIN
 * Author         : Nitish Dash
 * Name           : LED control with HC-05 and android
 * Created        : 1/10/2015
 * Webpage        : http://goo.gl/u2d0Cv
 * Author Email   : nitishdash95@gmail.com
 * Author Website : http://www.nitishdash.com/
 **** DONOT COPY AND PLAGIARATE WITHOUT THE AUTHOR'S PERMISSIONS ****
 */

#include 
SoftwareSerial electro(10, 11); // RX, TX
int l1=12; 
int flag=0;
String bdata="";
char c=' ';

void setup()
{
  electro.begin(9600);
  pinMode(l1, OUTPUT);
}
void loop()
{
  while (electro.available()){
    c=electro.read();
    bdata+=c;
if (bdata=="on")
    {
      flag=1;
    }
    if (bdata=="off")
    {
      flag=0;
    }  
}
  digitalWrite(l1, flag);
  delay(500);
  bdata="";
}
NOTE: Please remove the line 42 before uploading the sketch.

How this works (Algorithm):
We used Software Serial library, which converts any digital pins into serial pins RX and TX. That means, your 0 and 1 digital pins are free to be used. Now, I created the android app in such a way that, when you press the ON button, it will send a string value "on" to the HC-05 module. Same is the case of "off" button. Now, using if-else, I turn the LED on and off. At the end, the string is cleared for next iteration. 

Video:
Coming soon.....


Downloads:
1. sketch.ino
2. HC-05 datasheet
3. HC-06 datasheet
4. HC-05_ARDUINO_LED  app 

Something for you!
Try these ideas to enhance your knowledge and test yourself:
1. Replace the LED with a buzzer.
2. Try adding 3 different colored LEDs.

In the upcoming tutorials, we'll get more advanced and shift up our level! The HC-05 is a wonderfully good device, which will surprise you till the end. Just think of the possibilities! Controlling any device in your home, for example, you could easily automate your TV, A/C, XBOX, etc from the comfort of your couch!


Wednesday, 31 December 2014

Detecting motion using HC-SR501 PIR Sensor [ARDUINO]




Hope you tried yesterday's LCD tutorial. Now, let's shift our attention from displays to sensors! Yup, I am talking about the PIR motion sensor!

Here's the scenario: You have some really sensible and emotional stuff in digitized form on your laptop (:O, I hope you try to understand what I wanna say! :P) which could get you in trouble if someone sees you with them! Now if you close the door and watch your stuff,  someone's surely gonna know that something's fishy. What if you had some motion detector stuff, that could alarm you when someone's at the corridor? That would give you enough time to save yourself!!!

Yup, were not talking about high tech "James Bond" stuff here! I am talking about a simple $2 motion detector, which is accurate enough to save your a**.

Whatever be the reason, the PIR sensor can be used in a variety of projects starting from home automation to presence detector. It's your call.

What this project does?
Detects motion and turns on an LED as long as the motion is detected. Also, prints "Motion Detected" on the serial monitor.

Let's Learn The Basics! 
According to Wikipedia,
  1. A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors.
Read more here: PIR Sensor

Now, the HC-SR501 PIR SENSOR, is a very famous sensor, available across all major E-Shopping sites.

My PIR Sensor looks like this:

My Favorite Sensor!



Shown below, is an under view of the sensor:
Copyrights: Adafruit
 PINOUT:

GND   >>  GROUND(0V)
OUT   >>  HIGH/LOW DATA OUT PIN
VCC   >>  5V

Materials Required:
1. A HC-SR501 PIR Motion Sensor
2. Arduino
3. Jumpers
4. One LED
5. A 220OHM (or equivalent) resistor
6. Breadboard
7. and of course, a PC with Arduino IDE installed!

Procedure:
Software part:
1. FIRST UPLOAD THE SKETCH WITHOUT CONNECTING ANY COMPONENTS ACROSS THE ARDUINO PINS

2. Don't power on the Arduino, yet.

Hardware part:
1. Make the connections as shown:


The Setup



Sketch:

/* 
 * ON PUBLIC DOMAIN
 * Author         : Nitish Dash
 * Name           : Detect motion with HC-SR501 and Arduino
 * Created        : 12/31/2014
 * Webpage        : http://goo.gl/qNoi9f
 * Author Email   : nitishdash95@gmail.com
 * Author Website : http://www.nitishdash.com/
 **** DONOT COPY AND PLAGIARATE WITHOUT THE AUTHOR'S PERMISSIONS ****
 */

int ct = 10;    //calibration time
int pirPin = 9;    //PIR sensor's output
int ledPin = 10;

void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);
  
  Serial.println("Please wait, now calibrating the sensor....");
    for(int i = 0; i <= ct; i++){
      Serial.print(((i*100)/ct));
      Serial.print("% ");
      Serial.println("DONE.....");
      delay(1000);
      }
    Serial.println("Calibration Succesfully Done.");
    Serial.println("** SENSOR ACTIVE **");
    delay(50);
  }

void loop(){
     if(digitalRead(pirPin) == HIGH)
     {
       digitalWrite(ledPin, HIGH);
       Serial.println("------------------------");
       Serial.println("** MOTION DETECTED **");
       Serial.println("------------------------");
       Serial.println("");
       delay(1000);   
   }
   
     else
     {
       digitalWrite(ledPin, LOW);   
     }
   
}


How this works (Algorithm):
You might be knowing that every body emits radiations. Hot bodies emit infrared too. Now, our PIR sensor basically works on the principle of thermal imaging. Every body leaves a heat signature. The PIR sensor, continuously scans the environment for any thermal change and then compares the values on its processor. If there is a change in the thermal state of its environment, it sets the OUT pin to HIGH. And if there is no change in the thermal state, it gives a LOW value to its OUT Pin.

Now, we have simply used this theory in out code. We have used an if-else condition to set the LED on or off according to the OUT PIN's voltage. Simple. :)

Video:


Downloads:
1. HC-SR501 Datasheet
2. sketch.ino

Something for you!
Try these ideas to enhance your knowledge and test yourself:

1. Try replacing the LED with a buzzer / piezo.
2. Try making a code that would send an SMS to your phone, whenever someone's at your home
3. Try making two circuits, one with the PIR and another with a buzzer and let them communicate via Bluetooth or FM(433Mhz module)


So, guys, there you go. I tried to explain the basics of a PIR sensor. In future projects, we'll go wireless and let the PIR transmit presence data even when you are travelling the world. We'll let arduino message us, whenever the sensor detects motion. We'll also make an android app, that would communicate with the Arduino via HC-05 Bluetooth module and send us data.

Bye! Thanks for reading the tutorial. Leave comments for sure!


Tuesday, 30 December 2014

Interfacing a 16X2 LCD with Arduino - Displaying "Hello, World!" [ARDUINO]



You might have seen me using the 16X2 JHD16A LCD many times in my tutorials. Many of you might be new to this component. So what is the 16X2 LCD all about? Let's see.

What this tutorial does?
Teaches you the basics of an JCD16A 16X2 LCD, including the pin mapping, hardware and controlling it. and lets you display "Hello, World!" on the LCD with an Arduino. In the many upcoming articles and tutorials, we'll keep learning new ways of displaying messages and learn how to scroll the letters. We'll also create small animations too. But, in this one, we'll simply display "Hello, World!" in the first row and "Arduino is Fun." in the second.


Let's Learn The Basics! 
The JHD16A is a pretty popular module among the tinkerers mainly because it's cheap, and a perfect output device for many projects. It's also small. There might be many other alternatives and manufacturers. But the one I bought is made by JHD. When you buy the module, you might not get the headers soldered. There are 16 ports on it, which can be soldered to headers or directly to wires(if your project is permanent). But still I would suggest you to solder headers on it, because even if your project is permanent, you might occasionally need to check the health of your components in the project and that  in turn, would require maintenance. But again, that's entirely upto you.

If you are poor at soldering, I recommend you to read these articles:


The JHD16A is based on the Hitachi HD44780 . (Read more here: Hitachi HD44780 LCD controller) And the good thing is that, the Arduino 1.0.6 IDE, has inbuilt support for this controller. So, there's no need of downloading any library! We can get started easily.

Now, some geeky stats about the JHD16A module:

The pin config:

Copyrights: Instructables


 Pin No.
 Function of the pin
 Name
1
Ground (0V)
    VSS
2
Supply voltage; 5V (4.7V – 5.3V)
    VCC
3
Contrast adjustment; through a variable resistor
    VEE
4
Selects command register when low; and data register when high
    RS
5
Low to write to the register; High to read from the register
    R/W
6
Sends data to data pins when a high to low pulse is given
    E
7
8-bit data pins
    DB0
8
    DB1
9
    DB2
10
    DB3
11
    DB4
12
    DB5
13
    DB6
14
    DB7
15
Backlight VCC (5V)
    LED+
16
Backlight Ground (0V)
    LED-

PLEASE, NOTE THAT THE TOP LEFT PIN IS PIN NO.1. THIS IS BECAUSE, IN MY LCD, THE "JHD 16A" WAS PRINTED UPSIDE DOWN, WHICH MADE ME PRETTY CONFUSED! REFER THIS PICTURE:




Also, we shall never use the 4 pins DB0, DB1, DB2 AND DB3, because, we'll be using only the 4-bit mode everytime we print something on the LCD. So, it's completely safe to ignore it!


Materials Required:
1. PC with Arduino IDE installed!
2. Arduino UNO or NANO or PRO MINI
3. Jumpers
4. One 16X2 LCD
5. Three 1K and one 10K resistor.
6. Breadboard


Procedure:
Software part:
1. FIRST UPLOAD THE SKETCH WITHOUT CONNECTING ANY COMPONENTS ACROSS THE ARDUINO PINS

2. Don't power on the Arduino, yet.

Hardware part:
1. Make the connections as shown: Please remember this config because we'll never ever change this configuration in any of the tutorials.



THE SETUP


Now, power on the arduino.


Sketch:

/* 
 * ON PUBLIC DOMAIN
 * Author         : Nitish Dash
 * Name           : HELLO WORLD Display on 16X2 LCD
 * Created        : 12/30/2014
 * Webpage        : http://goo.gl/NjOEsH
 * Author Email   : nitishdash95@gmail.com
 * Author Website : http://www.nitishdash.com/
 **** DONOT COPY AND PLAGIARATE WITHOUT THE AUTHOR'S PERMISSIONS ****
 */
#include 

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2); //column and rows 
  lcd.print("Hello, World!");
  lcd.setCursor(0, 1);
  lcd.print("Arduino Is Fun.");
}

void loop() {
}

Please take care to remove the line 24 from the code before uploading
How this works (Algorithm):
It's simple. The command:
lcd.begin(16, 2);

initialises the LCD.

By using the command:
lcd.print("TEXT HERE");

we can easily print any text to the LCD (upto 16 characters).
To shift the cursor to 2nd row, use the command:
lcd.setCursor(0, 1);
and then again you can use:
lcd.print("TEXT HERE, AGAIN");

to print.

Video:
Coming soon.....


Downloads:
1. 16X2 LCD JHD16A DATASHEET
2. sketch.ino

Something for you!
Try these ideas to enhance your knowledge and test yourself:




Upcoming projects!

1. Programming ESP8266 using NodeMCU and LUA Scripts

2. IoT Applications

3. NRF42L01 2.4 GhZ module interfacing with arduino

4. ESP8266 - Everything cool about it!

Language ain't any barrier!

Get Updates!

Enter your email address:


Get the latest projects delivered into your inbox, hot!