Arduino - Reverse Car Parking Alarm

As promised in the previous post, we will be building a Reverse Parking alarm for cars. For doing so we will utilize the same wiring scheme as in my previous post. However, we will change the C sketch slightly. The change in the C code will be to start beeping the Piezo Buzzer at longer intervals when the Car is 30 centimeters (1 feet) away from an object, followed by intensifying the beeping at shorter intervals as the Car comes closer to the obstacle. Watch the Youtube video of the sample project below.



Setup the wiring for the reverse parking alarm as described in my previous post. Followed by using the C program written below.


Hope you enjoyed this article! Please share and comment on this post if you found it useful. I would love to hear from you.

Cheers,
KBRC

Arduino - How to detect obstacles/objects and react?

How to detect an obstacle with an Arduino and HC-SR04 Ultrasonic Module?

In this post we will detect an obstacle using the HC-SR04 Ultrasonic Ranging module with an Arduino. Basically, we will write an embedded C program for Arduino to read the Ultrasonic sensor data every second, followed by converting the sensor data into distance and in the end run a piece of logic that if the detected object (i.e. motion due to moving object) is within 10 centimeters then a Piezo Buzzer will be beeped. Check out the Youtube video below demonstrating my experiment with detecting motion.





The breadboard setup for detecting an obstacle has been provided below as a reference. You may use this wiring scheme for hooking up your HC-SR04 along with the Piezo Buzzer to your Arduino. Be careful not to connect the wrong wires, as it might result in a short circuit.


Figure 1 - Breadboard Wiring for obstacle detection 

The figure below shows the schematic wiring diagram for detecting an obstacle.


Figure 2 - Schematic wiring for obstacle detection

Join the wiring as follows:
  • HC-SR04: Connect Vcc (on HC-SR04) to 5V (on Arduino)
  • HC-SR04: Connect Gnd (on HC-SR04) to Gnd (on Arduino)
  • HC-SR04: Connect Trig (on HC-SR04) to Pin 4 (on Arduino)
  • HC-SR04: Connect Echo (on HC-SR04) to Pin 12 (on Arduino)
  • Piezo Buzzer: Connect the + Terminal (Longer leg) to Pin 8 (on Arduino)
  • Piezo Buzzer: Connect the - Terminal (Shorter leg) to Gnd (on Arduino)

That C sketch for detecting an obstacle with the Arduino is very simple and is provided for reference below.



Hope you enjoyed this post. Please share this post if you found it useful and write your comments below this post. I would love to read your your thoughts and experiences with the HC-SR04 Ultrasonic Ranging module.

In my next post, I will show you how you can use your Arduino and HC-SR04 to create a reverse parking alarm for a car!

Cheers!
KBRC

Arduino - How to measure distance?

How to measure distance using Arduino?

In this post we will look at measuring distances using an Ultrasonic sensor with the Arduino. For this purpose, I have chosen a commonly available sensor module called the HC-SR04 Ultrasonic Ranging Module. There are other Ultrasonic sensor as well, that give better field performance. However, we will start off with the HC-SR04. Given below is a picture of the HC-SR04 module. The HC-SR04 is an ultrasonic ranging module capable of measuring distances using Ultrasonic sound waves and it can be interfaced with not only the Arduino, but also various micro-controllers.


In one of my future posts, I will explain how we can hook  up the HC0SR04 with an ESP8266 Wifi Module and make it behave like a local web server, thereby reducing the costs of having a costly edge device for data acquisition.

Figure 1 - The HC-SR04 Ultasonic Module

There are various applications that may be developed using this Ultrasonic module with the Arduino. In these series of posts, we will analyze this module with the Arduino from various angles: Basic programming, Specifications Testing and then look at some Automation Solutions. For this post we will only look at basic distance measurement.

Basic Programming and Interfacing

The basic programming is straight forward and has two steps: setting up the circuit and writing the sketch/program. Build the circuit as shown below. This is a schematic provided to help you in wiring up.


Figure 1 - Wiring Schematic Diagram

Connect the PINS as described below:
  • Connect Vcc (on HC-SR04) to 5V (on Arduino)
  • Connect Gnd (on HC-SR04) to Gnd (on Arduino)
  • Connect Trig (on HC-SR04) to Pin 8 (on Arduino)
  • Connect Echo (on HC-SR04) to Pin 12 (on Arduino)


Next use the following sketch. Compile and load the following into your Arduino.



In order to test the system, keep your Arduino plugged in with your computer, and open your Arduino IDE's Serial Monitor window (Tools > Serial Monitor) - the serial monitor will show you the output from the print() and println() function calls in the running sketch. The running sketch will keep reading the sensor data, do some calculations and print the distance of the object in front of the sensor at regular intervals. Place/move some objects in front of the sensor and keep watching the serial monitor window.

See for yourself what gets printed on the Serial Monitor window, as you move the object(s) away from the sensor and bring them near the sensor. I will be eager to read and learn from your experiences, so please put your comments below.

In the next post we will see how to detect an obstacle and react using this Ultrasonic module.


Cheers,
KBRC







Basics of Embedded/IoT Circuit Electronic Components


<< Previous Visit my Traditional Programming Blog Next >>

Okay so before jumping into the embedded IoT world, one must know a few things regarding how to hook up basic circuits and also understand some commonly used basic electronic components and also why and how they are used.

When starting to tinker with embedded systems, unless from an electrical/electronics background, one has to research a bit in order to grasp the whys and hows of adding electronic components in the prototyping circuitry. In this post, I will try to provide a gist of the bare minimum things you need to understand before diving into working with electronic circuits.

The most commonly encountered electronic components while bread boarding (this itself is one of the topics) are:

  • Resistors
  • Transistors
  • Semiconductor Diodes

Use of Resistors

Resistors are used to reduce the amount of current. To draw an analogy you may think of them as a Firewall that reduces the amount of traffic. Or as an obstruction in the path of flowing water. Or just something that obstructs and reduces the flow of current - I tried to make it simple! So coming back to the topic, the thumb rule is if you are adding a delicate electronic component in the circuit that cannot withstand too much current, then we must add appropriate resistors before the component so that the resistor can resist (and dissipate) the input current and allow a reduced current to flow out to the delicate component. For example, in my earlier post I cautioned regarding placing resistors before LEDs, otherwise they will burn out.

Figure 1 - Resistors

The classical formula for calculating the value of a resistor required is provided below for reference. However, as a beginner, do not attempt the calculations; instead use the specified resistors from a circuit diagram.

                    Resistance = Voltage (from source) / Max. Tolerable Current

The two ends of a resistor do not have any polarity. You may place a resistor in any direction in your circuits.

Also you will have to get used to determining the value of a resistor by looking at the color bands. In the beginning, when you work out of a starter kit everything will be fine for a few weeks as all the resistors will come properly labelled. However, after a few months, as you start building more prototypes it is very likely to lose track of which one is which. In order to avoid any confusion, additional reading is suggested online, for decoding the resistor color bands and finding out its total value.

Use of Transistors

Transistors are commonly used for switching. By switching, I literally mean switching. It acts just like a physical ON/OFF switch. Trying to understand transistors can get academically demanding, hence I will try to stick to the basics...only to the extent needed to start with for building your circuits. You are encouraged to engage in advanced self study if you desire so.

A typical transistor has 3 legs, known as: Collector, Base and Emitter. The most common types of transistors are classified as PNP and NPN transistors. If you hold the flat face of a transistor towards your face then for a PNP type transitor the legs are arranged in the order: Collector, Base and Emitter (from left to right); whereas in case of a NPN transistor the legs are arranged as Emitter, Base and Collector (from left to right).

Figure 2 - Showing a PNP and NPN transistor


A transistor is built in such a unique way that internally there is a circuit between the Emitter, Base and Collector. Normally, a transistor's internal circuit is in a open (non conductive state) state. However, when a small voltage is applied on the Base, the internal circuit between the Emitter, Base and Collector gets closed (conductive state). Thus a transistor acts as a switch and gets activated (closed conductive state) when a voltage is applied on the base. In layman terms, applying a voltage on a transistor's base is like lifting/pressing a physical light bulb switch to ON position with your finger.

Use of Semiconductor Diodes

Diodes in general are of many types and is a separate topic and out of scope of this context, hence we will proceed with the basic understanding and build upon it as we proceed. We will ficus on Semiconductor Diodes for our purpose.

Primary function of a semiconductor diode is to act just like a check valve allowing current to flow in one direction and resisting (up to a limit) current from flowing in the opposite direction. Think of it as a "one way" lane in the direction of current permitted. Or think of it like a piece of cloth stuffed into a water pipeline that can only hold the water until it gets saturated, in the opposite direction.

Figure 3 - Shows some Semiconductor Diodes

Sometimes under certain situations a reverse current is generated - such as when a motor armature is stopped it continues to spin (due to inertia) inside the motor case until it comes to a halt. This reverse current has the potential to flow back into other electronic components (worse if it reaches your Arduino pins) - this might lead of damage. In order to stop this reverse current from flowing back, a diode is placed in a appropriate manner in the circuit. Rule of thumb is to face the banded end of the diode towards the source that has the potential to generate reverse current.

You must adhere to circuit specifications carefully while using diodes, as all diodes are not the same and may behave very differently, pay special attention to the model number specified for a particular setup.

I hope you found this post helpful to get you started. Please share your comments and reactions below.

Cheers!
KB

Arduino - How to setup and start programming?


<< Previous Post Visit my Traditional Programming Blog Next Post >>

Well, much has been written already online and in print media regarding setting up and writing  programs for the Arduino. However, I decided to write about the bare basics, primarily for the sake of completeness of my blog and also for sharing my experience on a particular platform. Hence I will not reinvent the wheel, instead point you to relevant technical literature on the Arduino Foundation's website for the purpose of the first time setup, and then add some personal observations that may help you getting started additionally.

Bare Basics of First Time Setup

Depending upon the operating system of your computer, you may visit one of these links for a detailed step-by-step guide for setting your Arduino UNO R3 board and starting to write the first program.

Windows https://www.arduino.cc/en/Guide/Windows
Mac https://www.arduino.cc/en/Guide/MacOSX
Linux https://www.arduino.cc/en/Guide/Linux

Provided below is my experience of setting up the Arduino on my Windows 7 laptop:

  • While the framework gets installed there is no need to connect the Arduino board to your computer.
  • After the installation is completed, and you connect the board for the first time, wait a bit for Windows to install the board drivers automatically.
  • After the drivers get auto-installed by Windows, launch the Arduino IDE (you may find the shortcut on your desktop).
  • Once the IDE is open, navigate to Tools menu and perform the Board and Port selections as instructed in the setup steps.
  • Just to verify I double checked the board connection by navigating to the menu Tools > Get Board Info. If everything has been completed successfully, you should receive a pop-up with the board details such as Serial Number, etc.
  • That is all, for the first time setup!
Moving ahead, I found that the board usually got auto detected after I plugged in my board to my laptop. However, sometimes you may notice that the board is not getting auto-detected, and this usually happens if you have opened your IDE first followed by plugging in the board. However, there is nothing to worry about, just re-launch the IDE and the board should get auto-detected.

Arduino Program Structure & Execution

All Arduino C programs need at least two functions: setup() and loop(), as shown below in the Arduino IDE. To understand what is going on, we must appreciate these three things:

Figure 1 - Basic structure of an Arduino C Program

  • The C program, after getting loaded into the Arduino board, keeps running in an infinite loop, until the board is powered off.
  • The setup() function is executed once, every time when the Arduino board is powered up. So all one time configuration/setup related code has to be written here. Think of it like a constructor.
  • The loop() function keeps getting invoked infinitely. Whatever you write here will keep getting executed infinitely, until the power supply to the Arduino board is turned off.

Some advice for your Hello World with LED Blinking

Right after the installation you will be tempted to try the LED blinking lesson that comes with the installation guide. If you are blinking the onboard LED on PIN 13 then is should be straight forward. However, if you try to blink an external off-board LED, and if the LED does not blink for the first time, then do not get dis-heartened. There could be several reasons for the LEDs not working such as:
  • Faulty LED (most common and in my case this is what had happened)
  • Defective jumper wire cable (this also happened in my case)
  • Defective Breadboard section rails (also common)
  • Defective resistor
  • Faulty circuit arrangement
Caution: Please remember to add a resistor to the LEDs always, otherwise they will burn out.

Cheers!
KB

Arduino - Easy Buyer's Guide & Getting Started


<< Previous Post Visit my Traditional Programming Blog Next Post >>

This post is primarily focused on getting started with the Arduino. There are many versions of the Arduino. You have 8-bit and 32-bit versions. Then there is the Nano, Mini, Uno, Mega. For most developmental purposes the Arduino UNO R3 can be used.

While ordering the Arduino

It would be best to order an
Arduino UNO R3 Starter Kit that contains everything you need to get started with the Arduino. Double check whether your kit includes at least the bare minimum such as:

Figure 1 - A typical Arduino Starter Kit


  • The Arduino UNO R3 mainboard
  • An USB A to B connector cable. USB Type A is the port on a computer while USB Type B is the port on the Arduino mainboard.
  • 1 Breadboard
  • Some Jumper Wires
  • Resistors, Transistors and Diodes
  • Optional - Most vendors usually also provide some LEDs and Buttons
  • Optional - Some vendors may or may not provide sensors (temperature) and actuators (motors)
  • If you get more from a vendor for the same price, then better!

Go the extra mile and order an outer Protective Jacket/Box for your Arduino. It is an invaluable asset and will save you away from the constant risk of damaging your Arduino from external shocks and injury.

Figure 2 - Some varieties of Arduino Cases/Boxes/Enclosures

Also order an Anti-Static Wrist Band for your Arduino. Believe me it will go miles in saving your precious electronics from static electric discharge from contact with your body (specially if you intend to work out of dry and cold weather conditions).

Figure 3 - Some varieties of Anti-Static Wrist Bands/Straps

Setting up and taking care of your Arduino

Once you have received your kit it becomes very important to handle the Arduino with care. Since there are a lot of delicate electronics involved, you will have to be very careful.

First, make sure you are free of static electricity. Touch some metal before handling the Arduino. Also wear your Anti Static wrist band for precaution.

The second important step is to encase your Arduino in the protective outer Jacket/Box. Believe me, I learnt it the hard way - don't leave your Arduino mainboard bare on your table. There are many ways it can get impacted from external influences.

And at last, the golden rules: be gentle when plugging in the jumper wires into the Arduino pins; and avoiding any liquids near or above the surface level of the Arduino mainboard. Also store the Arduino in a dry and moderate temperature. Avoid heat and humidity to keep your prized powerhouse chip going on and on for years of innovation to trickle out of your grey cells.

Cheers!
KB

How is Embedded Hardware & Software Development done?


<< Previous Post Visit my Traditional Programming Blog Next Post >>

Using the open source hardware software prototyping platforms is fairly straight forward. The big factor here is the degree of innovation implemented using these devices. In this post we will examine the development and prototyping methodology in general. First, I will explain how you can rapidly create new automated devices using the micro-controller boards, just from your PC/Laptop. Of course you would need some hardware to start with at the minimum. Let us dive into it!

We will start with a general overview of how the development is done, followed by a more platform specific "Hello World" example in the following post. However, this post will focus on a general overview of the process. The below diagram shows how embedded programming is done in general.

We can use an Arduino development board, some bare minimum electronic parts and a Laptop. You are also expected to know a little bit of C/Python/C# (depending on the platform) programming to implement the logic of the embedded programs that will reside in the micro-controller chip and co-ordinate the interactions among the various peripheral devices attached to the chip.

Typically the following hardware items would be used during development:
  • A development board of choice (Arduino, Netduino, Gadgeteer, Raspberry Pi, BeagleBone or Other Chips)
  • A Breadboard
  • Some Jumper Wires
  • Some basic electronic components (usually resistors to reduce current, transistors for switching and diodes for directional control of current flow, to start with) 
  • Some Sensors and/or Actuators
  • A Laptop (in case of Raspberry Pi and BeagleBone a Laptop may not be required).
The software used varies depending upon the chosen platform, as indicated below. However, note that in case of the Raspberry Pi and the BeagleBone a Laptop may not be required; as they are complete computer systems on their own.
  • An Operating System (Windows/Mac/Linux)
  • An IDE (Arduino IDE, Visual Studio, Notepad++, etc ...).
Knowledge Required:
  • Primarily C Programming (Arduino). However, Assembly Level programming can also be done.
  • Primarily it is Python (Raspberry Pi). However, with the Raspberry Pi there is an option to use Windows 10 IoT Core, Visual Studio 2015 and C#. Plus other Operating Systems can also be loaded using a separate SD Card.
So that is all you need to start developing your own devices! It might seem a lot to start with as there is the additional investment of the development boards and electronic components involved. Sometimes it is indeed a daunting task to find the right devices, because there is this element to experimentation and you never really know until you have really tried it out. However, with time as I find out more I will continue to share the right mix and combinations with you to successfully build your own connected devices around the world.

Cheers,
KB

Open Source Hardware & Embedded Software Prototyping Platforms


Visit my Traditional Programming Blog Next Post >>


     Finally, the secrets of software controlled hardware development for tech enthusiasts are catching up speed in the public domain. It has been quite many years since the first programmable development boards for writing embedded software had hit the market. Since then the tech market gods have been producing a few open source platforms for generating and inculcating the technology strains in the mortals. Arduino and Raspberry Pi being two of the commonly used platforms for rapid hardware-software based system prototyping. Given below are some of the popular platforms for IoT (Internet of Things), Automation, Robotics ... call what you will !

     This is my opener post for my tinkering with the various prototyping platforms. It just serves as a general compilation of the commonly used development boards in the market. Hence I have chosen not to bore you with loads of details (that you can anyway find in various wikis). So here you go...

The Embedded Revolution

Figure 1 - An "Arduino" Board
     The "Arduino" platform was introduced in the year 2005, it was an instant hit among both novices and professionals for creating devices that interacted with the environment using sensors and actuators. Some examples of such devices are simple automated machines/robotstemperature monitors, moisture sensors and motion detectors. This mini powerhouse has totally revolutionized the maker industry and can be used very creatively to build sophisticated automation projects. There are many revisions and versions of the Arduino platform: R3, Mega, Nano and Mini to name a few. The main programming language used is C and comes with an Arduino compatible IDE.

     Then there are also the "Netduino" and "Gadgeteer" platforms. They are also open source electronics prototyping platforms. Both these platforms are based on Microsoft .NET Micro Framework where in the language of choice is C#.
Figure 2 - A "Netduino" Board
     However, both are comparatively costly when compared to Arduino. However, all of these plarforms can be used for almost similar purposes. However, there definitely will be specific use case categories where they fit the best.
Figure 3 - A "Gadgeteer" Board
    Microsoft Gadgeteer comes with a lot of integration with Windows and Visual Studio in particular. The Gadgeteer platform is directly being backed by Microsoft.

The SoC (System on a Chip) Revolution

     The "Raspberry Pi" is a small single board computer system introduced in the year 2012 for teaching basic computer science in schools and developing nations. The Rpi (as it is also known as) is a powerful platform for computing and controlling various peripheral devices attached to it.
Figure 4 - A "Raspberry Pi" Board
     It is different from the "Arduino" platform in that it is a complete computer system in itself. You can hook up a monitor, a keyboard, a mouse and other devices as well. In this case the Python programming language was originally promoted, however, it has support for various embedded OS and languages.

Figure 5 - A "BeagleBone" Board
     Similarly, the "BeagleBone" is yet another open source electronics prototyping platform introduced as a relatively low-cost development platform for hobbyists and professionals to experience the powerful computer on a single chip phenomenon.

     As we proceed through this journey of exploring the various devices and platforms, I being a tech fan and instantly attracted to anything that even remotely smells automation, invite you and I hope you will enjoy your stay reading and participating here.

Cheers,
KB