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



Showing posts with label LED. Show all posts
Showing posts with label LED. Show all posts

Saturday, 13 August 2016

Flasing LED using 555 Timer IC [555 IC]



What this project does?
Flashes an LED using the 555 timer IC.

Materials Required:
1. 1 KΩ resistors - 2 nos
2. 470 KΩ resistor - 1 nos
3. Jumpers
4. 1 µF capacitor (electrolytic/ceramic) - 1 nos
5. Bipolar 555 timer IC
6. Breadboard
7. LED - 1 nos
8. 9V battery



Procedure:
Hardware part:
1. Make the connections as shown:





How this works:
This circuit works in an astable mode. Thus, it generates a continuous output at the 3rd pin in the form of a square wave. Thus, the LED turns on and off.

To change the flashing rate, you can tamper with the values of R1(1kΩ) and R2(470kΩ).


Video:




Downloads:
1. Schematics


Monday, 21 March 2016

Firmata Protocol for Arduino in under 4 mins!

Don't know Objective C? Finding it difficult to code in Arduino? Wouldn't it be awesome if you could directly code in python for your arduino? Yup, it's possible and now you'll learn how.

What this project does?
Use python language to program arduino.


Procedure:
This can be best understood by the following video:






Code:

Firmata Software:
http://www.firmata.org/wiki/Main_Page


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!


Saturday, 20 December 2014

Blinking an LED (An intro to Raspberry Pi) [RPI]



OK. So, let's discuss something about the Rpi. Many of you might know what it is. Many might not.

According to Wikipedia,

The Raspberry Pi is a credit card-sized single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer science in schools.

According to me,

It's the bigger brother of Arduino, in terms of memory and performance but in a certain context
Although the RPi functions a lot as a computer(which it is!), it has also got the 40 GPIO pins, much similar to the digital pins of the Arduino. To be frank, there are lots of differences between them too. But, since we are more interested in the application of both the MCU's in sensing the environment and manipulating them, we'll confine ourselves to the input/output capabilities.

That's enough talk about RPi. For more info, you may simply search for "Raspberry Pi" on Google and you'll be saturated with information! :P


So, let's begin.

What this project does?
Blink an LED 20 times using the RPi.


Let's know the basics!
Well, you should be knowing what an LED is and what minimum current should pass through it. For me, it was around 20 mA. Do refer to your LED Datasheet for more info. Also, keep in mind that messing up even a little bit can damage your RPi, which is a little more heavier on the pocket as compared to the Arduino!

NOTE:
This is the arangement of the pins. Please keep this in mind. 1 is the PIN No.1.


NOTE:
The GPIO Pins on the RPi, can be fully controlled via Python. So, it's recommended that you play around with some Python code and get acquainted with the Python environment.
Here are some sites to get you started if you have no or zero knowledge of the Python environment.




Materials Required:
1. An LED
2. Raspberry Pi and accessories. (Including monitor, keyboard and mouse)
3. Jumpers
4. One 330 OHM resistor
5. Breadboard


Procedure:
1. Start up RPi and open LeafPad.

2. Type in the code(scroll down to find the code) and save the file with the name: "blink,py".
    Save this file in the root folder, i.e, [/home/pi]

3. Connect all the components as shown below:



Connect:
  • GPIO PIN17 [PIN No.11] to the LED's +ve pin 
  • GPIO GND[PIN No. 6] to the LED's -ve pin via resistor.
NOTE: To see the pin layout on Raspberry Pi model B+, check out the attachment in the downloads section.


4. Open LXTerminal and type the command:

sudo python blink.py

and press enter.

5. You should see the LED flash. After blinking 20 times, the GPIO pins return to normal state.


Python Code:

#Code by electro.nitishdash.com
import RPi.GPIO as GPIO
import time
def blink(pin):
        GPIO.output(pin,GPIO.HIGH)
        time.sleep(1)
        GPIO.output(pin,GPIO.LOW)
        time.sleep(1)
        return
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output pin
GPIO.setup(11, GPIO.OUT)
#to blink GPIO17 20 times
for i in range(0,20):
        blink(11)
GPIO.cleanup() 



Video:
Coming soon.....


Downloads:
1. blink.py
2. Breadboard schematics
3. Pin layout (Model B+)


Homework for you!
1. Try adding 3 leds of different colours and light them up one by one after a small interval.


Wednesday, 17 December 2014

Measuring Distance with HC-SR04 Ultrasonic Ping Sensor and Arduino PART-1 [ARDUINO]



Hope you guys enjoyed making the last project. So, today my HC-SR04 Ping sensor arrived via courier which I had ordered 2 days back. Opened it up and there was this shiny flashing (not really!) 2 eyed thing.
See for yourself.


What this project does?
Measure the distance of a distant object using the ultrasonic ping sensor. Then, light up the red led if the distance between sensor and the object is 12cms or less. And green led remains on if the distance is more than 12cms. Also, it will print the reading on the serial monitor every 0.4 seconds.
But, in this first part, we'll use LEDs to notify us the proximity. In part 2, we'll use an LCD to directly display the values.

Let's know the basics!
So, let's discuss a little bit about this sensor. So, as the title itself suggests, this is a ping sensor or in simple form, a tiny little SONAR. With an arduino, you can harness the power of this tiny sonar, which is surprising me everyday. Some quick facts:


The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats or dolphins do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package. From 2cm to 400 cm or 1” to 13 feet. It operation is not affected by sunlight or black material like Sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). It comes complete with ultrasonic transmitter and receiver module.

Features:
  • Power Supply :+5V DC
  • Quiescent Current : <2mA
  • Working Currnt: 15mA
  • Effectual Angle: <15°
  • Ranging Distance : 2cm – 400 cm/1" - 13ft
  • Resolution : 0.3 cm
  • Measuring Angle: 30 degree
  • Trigger Input Pulse width: 10uS
  • Dimension: 45mm x 20mm x 15mm



Parameter
Min
Typ.
Max
Unit
Operating Voltage
4.50
5.0
5.5
V
Quiescent Current
1.5
2
2.5
mA
Working Current
10
15
20
mA
Ultrasonic Frequency
-
40
-
kHz

So, hope you have got a quick idea of this device and the power it is packed with.

Now, our common algorithm follows!:

Materials Required:
1. An HC-SR04 Ultrasonic Ping Sensor
2. Arduino
3. Jumpers
4. Two 560 OHM resistors
5. One green led and one red led
6. Breadboard

Procedure:
1. Make the connections as shown:



2. Upload sketch

3. Start the serial monitor and check the runtime distance measurements

4. Bring an object close and test the project. If the red led glows, you're done with the project!


Sketch:

/*
 HC-SR04 Ultrasonic Distance Sensor
 CODED BY: Nitish Dash [nitishdash95@gmail.com]
 More info at: http://eweekend.blogspot.com
 */

#define trig 13
#define echo 12
#define red 11
#define green 10

void setup() {
  Serial.begin (9600);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
}

void loop() {
  long time, dist;
  digitalWrite(trig, LOW); 
  delayMicroseconds(2); 
  digitalWrite(trig, HIGH);
  delayMicroseconds(10); 
  digitalWrite(trig, LOW);
  time = pulseIn(echo, HIGH);
  dist = ((time/2) / 29.1); //measure in cms
  if (dist < 12) //change this to set proximity distance 
  
{  
    digitalWrite(red,HIGH); 
  digitalWrite(green,LOW);
}
  else {
    digitalWrite(red,LOW);
    digitalWrite(green,HIGH);
  }
  if (dist >= 200 || dist <= 0){
    Serial.println("Out of range");
  }
  else {
    Serial.print(dist);
    Serial.println(" cm");
  }
  delay(400);
}

How this works (Algorithm):
The timing diagram of HC-SR04 is shown. To start measurement, Trig of SR04 must receive a pulse of high (5V) for at least 10us, this will initiate the sensor will transmit out 8 cycle of ultrasonic burst at 40kHz and wait for the reflected ultrasonic burst. When the sensor detected ultrasonic from receiver, it will set the Echo pin to high (5V) and delay for a period (width) which proportion to distance. To obtain the distance, measure the width (Ton) of Echo pin.

>>Time = Width of Echo pulse, in uS (micro second)
>>Distance in centimeters = Time / 58
>>Distance in inches = Time / 148
>>Or you can utilize the speed of sound, which is 340m/s



Video:
Coming soon.....

Downloads:
1. Sketch.ino
2. Breadboard schematics


Homework for you!

Try these ideas to enhance your knowledge and application:
1. Add another yellow led and modify the code for testing three conditions and glow the three leds as per the distance
2. Add a speaker and change it's tone as and when the distance changes.
3. Add this near your door and turn on an alarm if someone opens the door.

Stay tuned for the next part, where we will print the readings directly to a 16X2 LCD! So much fun!

UPDATE: Guys, part-2 is online now. Check it out here: http://electro.nitishdash.com/2014/12/7-measuring-distance-with-hc-sr04.html

Any doubts? Feel free to leave a comment.



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!