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



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!


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!