tag:blogger.com,1999:blog-90387182531680000722024-03-04T22:53:09.595-08:00Simple Labs' Quick Start Kit for ArduinoSimple Labshttp://www.blogger.com/profile/00881173225878503487noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-9038718253168000072.post-26668411774758737452012-05-17T00:30:00.000-07:002015-06-19T23:47:52.399-07:00Simple Labs Quick Start kit for Arduino - List of Contents<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<br />
<div style="margin-bottom: 0cm;">
Getting Started with the Arduino &
Simple Labs Quick Start Kit</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
So you have picked up Arduino [<a href="http://www.simplelabs.co.in/catalog/arduino-boards" target="_blank">Click Here to see Arduino Boards You Can Buy from Simple Labs</a>] and the
Simple Labs Quick Start kit[<a href="http://www.simplelabs.co.in/content/quick-start-kit-arduino" target="_blank">Click Here to Buy a Quick Start Kit</a>] for Arduino in hope of doing something.
We hope you have read your way through about Arduino as we are going
to directly jump into using the Quick Start Kit.
</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
So what can you do with an Arduino?</div>
<div style="margin-bottom: 0cm;">
<br /></div>
<div style="margin-bottom: 0cm;">
There are a lot of things that you can
do with an Arduino. The possibilities are quiet unlimited and
open-ended. We are putting together a list of topics to get you
started comfortably with Arduino. Here you go (if there is no link,
it means we are still putting it up!)<br />
<br />
<div style="text-align: justify;">
For this tutorial we will choose a simple activity for each element and
keep adding to the previous activity. Keep in mind we are saying
activity and not project as we are not building any project of great
significance, we are rather focusing on 'how to'. You are expected to go
step by step through the activities as some of the coding might build
on the previous activity. So , Lets get started!<br />
<br />
Download the following zip file with the source code / libraries for all these examples.<br />
<a href="http://downloads.simplelabs.co.in/Quick_Start_Kit.zip" target="_blank">Quick_Start_Kit.zip</a></div>
</div>
<div style="margin-bottom: 0cm;">
</div>
</div>
<div>
<ol style="text-align: left;">
<li><a href="http://quickstartkitforarduino.blogspot.in/2011/11/simple-labs-quick-start-kit-for-arduino.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - Kit Contents Overview</a> </li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_16.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - Basic Breadboard Setup How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_2763.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - LED Interfacing - How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_1372.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - RGB LED Interfacing - How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_7945.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - Push Button / Switch Interfacing - How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_2808.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - Trimpot / Potentiometer Interfacing - How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_9766.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - Sensor Interfacing - LM35 Temperature Sensor- How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_1623.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - Sensor Interfacing - LDR Simple Light Sensor- How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_382.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - Generating Sound - Buzzer + Transistor - How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_5679.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - Interfacing IC ULN2003 - Darlington Pair Transistor Array - How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_1543.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - IR Proximity Sensor Interfacing- How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_2186.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - LCD Interfacing - How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_17.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - DS1307 Real Time Clock IC Interfacing- How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_3359.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - TSOP - IR Receiver Interfacing- How To?</a></li>
<li><a href="http://quickstartkitforarduino.blogspot.com/2012/05/simple-labs-quick-start-kit-for-arduino_7820.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - 7-Segment Display Interfacing- How To?</a></li>
</ol>
<br /></div>
</div>
Simple Labshttp://www.blogger.com/profile/00881173225878503487noreply@blogger.com3tag:blogger.com,1999:blog-9038718253168000072.post-26003683759088316082012-05-17T00:04:00.002-07:002012-05-17T00:04:36.925-07:00Simple Labs' Quick Start Kit for Arduino - 7-Segment Display Interfacing- How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>The 7-Segment Display</b><br />
<br />
7-Segment displays are
another common component in the world of electronics. These displays
have 8 LEDs split into different segments designed to be able to display
numerals from 0-9 and a dot. All The LEDs have a common ground /
supply line. There are 5 pins at the top and 5 pins at the bottom. The
middle pins in the top and bottom are connected to each other internally
and have to be connected to Ground / Supply depending upon the type of
the 7-segment Display. You can control each segment like an individual
LED. However, this method of controlling the 7-segment LED to display
numbers would be hectic. So, we will use a technique called Port
Manipulation. Pins on the Arduino are grouped together as a PORT. You
can control a whole PORT at a time. Read the following write up on the
Arduino website before you proceed => <a href="http://www.arduino.cc/en/Reference/PortManipulation" target="_blank">Port Manipulation</a><br />
<br />
The 7-Segment Display included in the starter kit is a Common Cathode Type.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnf2x8r4P7_zb7N9OMiAYUUOM7wuGP7vL5F5ZxK01H9bktG0IppEBQoLa5_ohcX05i4rBJ92tlZKIi-vdWeZTMAQ53YrEAQoqpa5njRwMy27ObvN7dzq83dUOu81HJBAZwWBzvQM6O_inD/s1600/SEV1.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnf2x8r4P7_zb7N9OMiAYUUOM7wuGP7vL5F5ZxK01H9bktG0IppEBQoLa5_ohcX05i4rBJ92tlZKIi-vdWeZTMAQ53YrEAQoqpa5njRwMy27ObvN7dzq83dUOu81HJBAZwWBzvQM6O_inD/s400/SEV1.jpg" width="268" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">7 - Segment LED</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMez2IZ6NJtrSgitrl_ZJCb5zhdas3JHuuRmjUFtn2Nu39QF31GpJxowVH-3jtS76P12sNaC_TjYFjfZvOzfzDTDhEVV51m77mJf_y1VHN7dAQAHkd8IBOtHaX4Gr31fl_RdC6liOlvFJW/s1600/7seg_pinouts.png" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMez2IZ6NJtrSgitrl_ZJCb5zhdas3JHuuRmjUFtn2Nu39QF31GpJxowVH-3jtS76P12sNaC_TjYFjfZvOzfzDTDhEVV51m77mJf_y1VHN7dAQAHkd8IBOtHaX4Gr31fl_RdC6liOlvFJW/s400/7seg_pinouts.png" width="271" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Segment &
Pin Mapping of a 7-Segment LED / We will be connecting segments A-G
& P to digital pins 0-6 & 7 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxnpTraxHnzjcoRyMzskOsQm5Y2mBaSvOYQH7kAcThlsaPoTIQ0ASjoAsowIfc3-qizqFwlDMOhp49JXs_eB6cMEon2XoRa2vpCbPJH3RmhbdNsPrFaGkFdK33V81XH98vR9vGnUnhtBYu/s1600/SEV2.jpg" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxnpTraxHnzjcoRyMzskOsQm5Y2mBaSvOYQH7kAcThlsaPoTIQ0ASjoAsowIfc3-qizqFwlDMOhp49JXs_eB6cMEon2XoRa2vpCbPJH3RmhbdNsPrFaGkFdK33V81XH98vR9vGnUnhtBYu/s640/SEV2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the 7-segment Display on the Breadboard.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf9qELnYwwTlqBjkXQQKxGxCnUURQoYw1Y7PNzHe3DBRuo3qeRLjQSIaUB4rdVEDJrehnGUvV-MjlPtrCCJLx8dJF2YXhSgkoP_394h81gXMVfrQmiLAlRTwJE99-ssNquzUvpyBdB5J20/s1600/SEV3.jpg" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="416" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf9qELnYwwTlqBjkXQQKxGxCnUURQoYw1Y7PNzHe3DBRuo3qeRLjQSIaUB4rdVEDJrehnGUvV-MjlPtrCCJLx8dJF2YXhSgkoP_394h81gXMVfrQmiLAlRTwJE99-ssNquzUvpyBdB5J20/s640/SEV3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place a 1K resistor between the middle pin on the top and the '-'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB9UdwZ2ngLCtIBlqK1NK6kAwrBf5nLx-Q2F-A1P_phkx1Gzp9eqiVg6Yx_Dkr6UkpWRWsr-AjyJlL4IEFVluQq9twwJJ7JJhx0nQraB_ac2Jj0N9GvKz_G11_XScp4KFAn2d0NiX_ezM9/s1600/SEV4.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB9UdwZ2ngLCtIBlqK1NK6kAwrBf5nLx-Q2F-A1P_phkx1Gzp9eqiVg6Yx_Dkr6UkpWRWsr-AjyJlL4IEFVluQq9twwJJ7JJhx0nQraB_ac2Jj0N9GvKz_G11_XScp4KFAn2d0NiX_ezM9/s640/SEV4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment A to digital pin 0 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR0U4otO-S2JCSUPrfM28eQdzpvHI5e9u2-4sGrSyg400AjhOznakhoxhMbdLs9B5siAoH8aJ2R9fporvRgbtFrjMIdkUXgqPs71goG69Q7cNp9NB0OhT2cWRB1UG8z0WC014BGf_GmfGZ/s1600/SEV5.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="454" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR0U4otO-S2JCSUPrfM28eQdzpvHI5e9u2-4sGrSyg400AjhOznakhoxhMbdLs9B5siAoH8aJ2R9fporvRgbtFrjMIdkUXgqPs71goG69Q7cNp9NB0OhT2cWRB1UG8z0WC014BGf_GmfGZ/s640/SEV5.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment B to digital pin 1 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQKQkc07Nq97zLOIi_PgI3DjjXWPYD8sonY1ak0pLRbc0D_bI9oOPoi-WLP5pxwEUToZkDdu0SqkjLYAwkNKMWfQL0TTIMxfJfECU-9WQQch-6gaomNA6GsrNfyv2YzBE-2EPwBRmzwdkG/s1600/SEV6.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQKQkc07Nq97zLOIi_PgI3DjjXWPYD8sonY1ak0pLRbc0D_bI9oOPoi-WLP5pxwEUToZkDdu0SqkjLYAwkNKMWfQL0TTIMxfJfECU-9WQQch-6gaomNA6GsrNfyv2YzBE-2EPwBRmzwdkG/s640/SEV6.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment C to digital pin 2 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7HRuadYPXB4LGgm9FWHhiJ4XADL_aaScQFnNIynxFEo4obINa6OrQMjfjyDxvKzxi57ZoG85XphPOdpeIeKZB0HMaG2-kl97dT93UrHNh18ZO7gPq1KMREz2CjUcErftpY0lqjnE4KgJF/s1600/SEV7.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="498" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7HRuadYPXB4LGgm9FWHhiJ4XADL_aaScQFnNIynxFEo4obINa6OrQMjfjyDxvKzxi57ZoG85XphPOdpeIeKZB0HMaG2-kl97dT93UrHNh18ZO7gPq1KMREz2CjUcErftpY0lqjnE4KgJF/s640/SEV7.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment D to digital pin 3 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcozSIRjLIQohob-g4zbmfF7R1Y5meb6T5u4jhdbWN-xcuYJssJHQicDA8IHI7ShDD8DJztfsqUAkbx5w84p0Bdm3_6KCkO14GvA8vhIT_ogcZkC3_c_vuQvQcBW2nlchCZ3P9d3qQDp9U/s1600/SEV8.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="494" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcozSIRjLIQohob-g4zbmfF7R1Y5meb6T5u4jhdbWN-xcuYJssJHQicDA8IHI7ShDD8DJztfsqUAkbx5w84p0Bdm3_6KCkO14GvA8vhIT_ogcZkC3_c_vuQvQcBW2nlchCZ3P9d3qQDp9U/s640/SEV8.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment E to digital pin 4 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8f592uiy_wi-Ne90BQbsSjG7cMPQk4LcDIZpAKFuSkE_A8lyznyHMqhssYTAq-0Hklox8SqAhMK_1NmkndxC7pBCqKQAxu96rwOo7VjhVA4jML8gCqRR_EsUBhB4Ap0gsoNWCH_c1z3DA/s1600/SEV9.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="588" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8f592uiy_wi-Ne90BQbsSjG7cMPQk4LcDIZpAKFuSkE_A8lyznyHMqhssYTAq-0Hklox8SqAhMK_1NmkndxC7pBCqKQAxu96rwOo7VjhVA4jML8gCqRR_EsUBhB4Ap0gsoNWCH_c1z3DA/s640/SEV9.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment F to digital pin 5 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUJYxH3kazSGukrlJokVuJ_CPxp9BsgwqvFhiRg96SH0qkYVN61b_XAfnUOzjBlHwAdNM1NQp_ImpkJLa_rP0RnhvdR3Ct0x0bWE1Lkgn5r1kSTQKPTMWOdzO7OnDnQRZsnuuOkbumlk7q/s1600/SEV10.jpg" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUJYxH3kazSGukrlJokVuJ_CPxp9BsgwqvFhiRg96SH0qkYVN61b_XAfnUOzjBlHwAdNM1NQp_ImpkJLa_rP0RnhvdR3Ct0x0bWE1Lkgn5r1kSTQKPTMWOdzO7OnDnQRZsnuuOkbumlk7q/s640/SEV10.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment G to digital pin 6 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr8pyVqpVy-dhuI4JGjnoJgvs1yf4x9bz5LBt92BeGPd6g3o6tJuoE16WGjvo9q3WzG_1YUQsKAAChnbrtNYkYLb2c6gz2wLX0oJ-5hSAUdka_y0Sy2HIKgkQG5x8bwQYc0IBR0ab69CHc/s1600/SEV11.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="430" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr8pyVqpVy-dhuI4JGjnoJgvs1yf4x9bz5LBt92BeGPd6g3o6tJuoE16WGjvo9q3WzG_1YUQsKAAChnbrtNYkYLb2c6gz2wLX0oJ-5hSAUdka_y0Sy2HIKgkQG5x8bwQYc0IBR0ab69CHc/s640/SEV11.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment P to digital pin 7 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH2Kb8s9T2SUA6eZgWIHjsf6z1qG4H1pGWFd6NfvXviaLJ6xT4hyphenhyphenyuS8m3Iz6bnN5HqNOGM0jR5cpwNnIZ3boWvnBSmnW6WDoaMHME8wHocwkZIyOeocMc0fns-XSLZvKdcNBbqk0c5ZAc/s1600/SEV12.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="428" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH2Kb8s9T2SUA6eZgWIHjsf6z1qG4H1pGWFd6NfvXviaLJ6xT4hyphenhyphenyuS8m3Iz6bnN5HqNOGM0jR5cpwNnIZ3boWvnBSmnW6WDoaMHME8wHocwkZIyOeocMc0fns-XSLZvKdcNBbqk0c5ZAc/s640/SEV12.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Our Final Setup with a Program</td></tr>
</tbody></table>
First Try the following program that cycles from digits 0 - 9. [SEV_SEG.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">This is to Display numbers 0-9 on the seven segment LED</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">Wiring </span>
<span style="color: #7e7e7e;">Seg A - Pin 0</span>
<span style="color: #7e7e7e;">Seg B - Pin 1</span>
<span style="color: #7e7e7e;">Seg C - Pin 2</span>
<span style="color: #7e7e7e;">Seg D - Pin 3</span>
<span style="color: #7e7e7e;">Seg E - Pin 4</span>
<span style="color: #7e7e7e;">Seg F - Pin 5</span>
<span style="color: #7e7e7e;">Seg G - Pin 6</span>
<span style="color: #7e7e7e;">Seg H - Pin 7</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">To Display '0' we need to make high All Segments except G & H</span>
<span style="color: #7e7e7e;">based on this lets make a list of values to write to port D [pins 0-7 are grouped together as port D]</span>
<span style="color: #7e7e7e;">When we write a binary value to the port the MSB or the 8th bit will be written to pin 7 and the lsb will be written to pin 0</span>
<span style="color: #7e7e7e;">0 => B00111111</span>
<span style="color: #7e7e7e;">1 => B00000110</span>
<span style="color: #7e7e7e;">2 => B01011011</span>
<span style="color: #7e7e7e;">3 => B01001111</span>
<span style="color: #7e7e7e;">4 => B01100110</span>
<span style="color: #7e7e7e;">5 => B01101101</span>
<span style="color: #7e7e7e;">6 => B01111101</span>
<span style="color: #7e7e7e;">7 => B00000111</span>
<span style="color: #7e7e7e;">8 => B01111111</span>
<span style="color: #7e7e7e;">9 => B01101111</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #cc6600;">int</span> val[]={B00111111,B00000110,B01011011,B01001111,B01100110, B01101101,B01111101, B00000111, B01111111, B01101111};
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
DDRD = B11111111;
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
<span style="color: #cc6600;">for</span>(<span style="color: #cc6600;">int</span> i=0; i<10;i++)
{
PORTD = val[i];
<span style="color: #cc6600;">delay</span>(1000);
}
}
</pre>
<br />
Now Try the following program - An extension of our
Remote Control Program. Here the Value of the Button being pressed is
displayed on the 7-segment display. [SEV_SEG_TSOP.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">This is to Display numbers 0-9 on the seven segment LED based on Remote Control INPUT</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">Wiring </span>
<span style="color: #7e7e7e;">Seg A - Pin 0</span>
<span style="color: #7e7e7e;">Seg B - Pin 1</span>
<span style="color: #7e7e7e;">Seg C - Pin 2</span>
<span style="color: #7e7e7e;">Seg D - Pin 3</span>
<span style="color: #7e7e7e;">Seg E - Pin 4</span>
<span style="color: #7e7e7e;">Seg F - Pin 5</span>
<span style="color: #7e7e7e;">Seg G - Pin 6</span>
<span style="color: #7e7e7e;">Seg H - Pin 7</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">To Display '0' we need to make high All Segments except G & H</span>
<span style="color: #7e7e7e;">based on this lets make a list of values to write to port D [pins 0-7 are grouped together as port D]</span>
<span style="color: #7e7e7e;">When we write a binary value to the port the MSB or the 8th bit will be written to pin 7 and the lsb will be written to pin 0</span>
<span style="color: #7e7e7e;">0 => B00111111</span>
<span style="color: #7e7e7e;">1 => B00000110</span>
<span style="color: #7e7e7e;">2 => B01011011</span>
<span style="color: #7e7e7e;">3 => B01001111</span>
<span style="color: #7e7e7e;">4 => B01100110</span>
<span style="color: #7e7e7e;">5 => B01101101</span>
<span style="color: #7e7e7e;">6 => B01111101</span>
<span style="color: #7e7e7e;">7 => B00000111</span>
<span style="color: #7e7e7e;">8 => B01111111</span>
<span style="color: #7e7e7e;">9 => B01101111</span>
<span style="color: #7e7e7e;">*/</span>
#include <IRremote.h>
<span style="color: #cc6600;">int</span> RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
<span style="color: #cc6600;">int</span> remote = 0, display_value=0;
<span style="color: #cc6600;">int</span> val[]={B00111111,B00000110,B01011011,B01001111,B01100110, B01101101,B01111101, B00000111, B01111111, B01101111};
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
DDRD = B11111111; // Declares PORT D as Output, PORTD is digital pins 0-7
irrecv.enableIRIn(); <span style="color: #7e7e7e;">// Start the receiver</span>
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
<span style="color: #cc6600;">if</span> (irrecv.decode(&results)) {
remote = results.value;
<span style="color: #cc6600;">switch</span>(remote)
{
<span style="color: #cc6600;">case</span> 16 : display_value=1; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2064 : display_value=2; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 1040 : display_value=3; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 3088 : display_value=4; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 528 : display_value=5; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2576 : display_value=6; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2960 : display_value=7; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 3600 : display_value=8; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 272 : display_value=9; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2320 : display_value=0; <span style="color: #cc6600;">break</span>;
}
PORTD = val[display_value];
irrecv.resume(); <span style="color: #7e7e7e;">// Receive the next value</span>
}
}
</pre>
<br />
<br /></div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com6tag:blogger.com,1999:blog-9038718253168000072.post-75589305918286160352012-05-17T00:03:00.006-07:002021-03-28T02:31:53.696-07:00Simple Labs' Quick Start Kit for Arduino - TSOP - IR Receiver Interfacing- How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>TSOP - IR Receiver</b><br />
<b><br /></b><br />
<span class="Apple-style-span" style="background-color: white;"><span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif; font-size: 15px; line-height: 21px;">The
TSOP SM0038 is an IR receiver. The TSOP will help you to interface
your TV remote with the Arduino and in the Process learn the basics of
Wireless Communication.</span><span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif; font-size: 15px; line-height: 21px;"> </span></span><br />
<br />
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">The
TSOP outputs a constant HIGH signal when idle and as it receives data,
it tends to invert the data. i.e when an IR LED is transmitting data
onto the TSOP, everytime the IR led goes high, the TSOP will go LOW and
vice versa. Remote control signals are often bytes of data that is
encoded and transmitted by pulsing(switching ON & OFF the IR LED at a
specific frequency) Most TV remote controls work at 32-40 Khz frequency
and most receivers can receive this range. </span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"><br /></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">Heres
a link to a nice write up on different remote control protocols. lets
first take a look how the Sony Remote Control Protocol Works. We stick
to Sony as it is the easiest one to get started with. <a href="http://www.sbprojects.com/knowledge/ir/sirc.php" target="_blank">Read this before proceeding </a></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"><br /></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">Here's
a basic outline of how the data is sent. Every time you press a button
on a Sony remote control, it sends out a 13Bit data. The first bit is a
start bit indicating there are 12 bits of data following it. The next 7
bits are the command bit which will vary depending upon the keys being
pressed. The last 5 bits are the address bits which will the same for
all buttons but vary for remote controls of different devices.</span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"><br /></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">The
black bars in the following image correspond to high signals (called
marks) and the white spaces in between correspond to low signals (called
spaces). The duration of the 'marks' varies according to the bit being
transmitted. It is 2.4ms for the start bit, 1.2ms for HIGH bit and 0.6ms
for LOW bit. The duration of the 'spaces' is a constant 0.6ms. Every
mark is followed by a space. Any data can be converted to binary format
and transmitted in this manner. In fact this is the basic form of all
types of serial communication.</span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"><br /></span></span></div>
<div class="separator" style="clear: both;">
<div class="separator" style="clear: both; text-align: center;"><a href="https://www.sbprojects.net/knowledge/ir/sirctrain.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="110" data-original-width="430" height="156" src="https://www.sbprojects.net/knowledge/ir/sirctrain.png" width="608" /></a></div><br /><a href="https://www.sbprojects.net/knowledge/ir/sirctrain.png" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"></a></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"></span></span></div><span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">Technique
to decode this signal train, would be to constantly monitor the TSOP
pin[Digital 15] for its normal state and the moment it produces a low
signal, measure the duration of the low signal. If the measured duration
of the low signal is around 2ms then measure and store the duration for
the next 12 bits of the incoming data. After storing the data, evaluate
the duration and based on the duration convert the data to decimal /
hexadecimal and use it in your application.</span></span>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"><br /></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">The duration of a signal on an input pin of the arduino can be measured using the pulseIn function. <a href="http://arduino.cc/en/Reference/pulseIn" target="_blank">Read more about this function here</a></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;"><br /></span></div>
<b>Wire it up</b><br />
<br />
Before wiring the TSOP, remove the DS1307 part alone from the breadboard.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMMNuOpI50yhTBmuSiPCj7N4NhEdwggAGYo5j-S1b_pNYD-4i2nISTjh8KUVh0srZ8nadfhB9o1mwK6UcxKOT0uvb1EhI48AEkLV0XmNnmI_ivI9MogZrqdQEe6PFXoRk5DQLBi6V4-AlD/s1600/tsop173x.png" style="font-size: medium; margin-left: auto; margin-right: auto;"><img border="0" height="318" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMMNuOpI50yhTBmuSiPCj7N4NhEdwggAGYo5j-S1b_pNYD-4i2nISTjh8KUVh0srZ8nadfhB9o1mwK6UcxKOT0uvb1EhI48AEkLV0XmNnmI_ivI9MogZrqdQEe6PFXoRk5DQLBi6V4-AlD/s400/tsop173x.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">TSOP Pin Mappings</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh93ahu29Opu5wUMUtAOSeml3dOkgLRhj8c-r667qs43fMNBXAP2F7ZBw9Z965FnIELUp3YhZgzcRaBq9uKe9DpKkKZEOibrkAwlmjxK9ui8n-96q0pWOY1oWhiqyQp9IrXesxe9k8vhMYl/s1600/TSOP1.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="414" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh93ahu29Opu5wUMUtAOSeml3dOkgLRhj8c-r667qs43fMNBXAP2F7ZBw9Z965FnIELUp3YhZgzcRaBq9uKe9DpKkKZEOibrkAwlmjxK9ui8n-96q0pWOY1oWhiqyQp9IrXesxe9k8vhMYl/s640/TSOP1.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The TSOP 1738</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaW7aPaPe01sdOjBF7Py_FWPm0mdsIenMuANER9GXez5UtjIIi1qLemktHAYT8hXFb3NefbNXQ3AaCdMZEhorUZt6iGsh8kJk8OdD0MlLGIO-9WCS87qogcIaz0eFHjvr2fjEupUpDlPX8/s1600/TSOP2.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaW7aPaPe01sdOjBF7Py_FWPm0mdsIenMuANER9GXez5UtjIIi1qLemktHAYT8hXFb3NefbNXQ3AaCdMZEhorUZt6iGsh8kJk8OdD0MlLGIO-9WCS87qogcIaz0eFHjvr2fjEupUpDlPX8/s640/TSOP2.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the TSOP on the Breadboard as Shown<span class="Apple-style-span" style="font-size: small;"><br /></span></td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtvgyLvoEVroKBabjDfmmignqkW6_TYBV0FcJPyDuYhDTOJE689vIcM_5MF9UTmhME2pxnrP_QE7D5ciFp5BU8BNt_8cMA3vbYyUNOxXzCezFri1MSiO2jtZbSaa70H2cosJd8NvbZv_Qg/s1600/TSOP3.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtvgyLvoEVroKBabjDfmmignqkW6_TYBV0FcJPyDuYhDTOJE689vIcM_5MF9UTmhME2pxnrP_QE7D5ciFp5BU8BNt_8cMA3vbYyUNOxXzCezFri1MSiO2jtZbSaa70H2cosJd8NvbZv_Qg/s640/TSOP3.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between the 1st pin of the TSOP and the '-'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnifBx0skiBCH2ma-yaSGmDVvnOLK2J1HGr9mxF2ObyegR6rmMD784Nro972IoOIZUMWfK3s7KfizMbQnWwl8r4v64-qDGK16aJrLe0UcjGAxS1o0viv30tRaNnR9tMt7VenRa8LQcmzdP/s1600/TSOP4.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnifBx0skiBCH2ma-yaSGmDVvnOLK2J1HGr9mxF2ObyegR6rmMD784Nro972IoOIZUMWfK3s7KfizMbQnWwl8r4v64-qDGK16aJrLe0UcjGAxS1o0viv30tRaNnR9tMt7VenRa8LQcmzdP/s640/TSOP4.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between the 2nd pin of the TSOP and the '+'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXQnJX9BRaal2bauII64ODxNEVZADg762n12nBx6tNr39PGGTl9PtRdCtzJh1ef7gy2mXp3xE_yRXg2iZCIW6wL6Sv7fCYaKkvABNZjd022dHtzJOVx8ZzWdeOb9XSRk1j9qysvqzRkDFj/s1600/TSOP5.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXQnJX9BRaal2bauII64ODxNEVZADg762n12nBx6tNr39PGGTl9PtRdCtzJh1ef7gy2mXp3xE_yRXg2iZCIW6wL6Sv7fCYaKkvABNZjd022dHtzJOVx8ZzWdeOb9XSRk1j9qysvqzRkDFj/s640/TSOP5.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between the 3rd pin of the TSOP and digital pin 12 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO8AXRLm-dw_s_p_p-dDeaxej8CLKgztJOMGnwtsX1Mnvh47xWqlpX9yvVnycXqN7sS9UswVOSycR9pDyzo0xibACo7a0E6Rkxz4nzYWO-lDuJJMy_8yV9zR9N531cNesHxfeksx95kj1y/s1600/TSOP6.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO8AXRLm-dw_s_p_p-dDeaxej8CLKgztJOMGnwtsX1Mnvh47xWqlpX9yvVnycXqN7sS9UswVOSycR9pDyzo0xibACo7a0E6Rkxz4nzYWO-lDuJJMy_8yV9zR9N531cNesHxfeksx95kj1y/s640/TSOP6.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">A Closeup of the Previous step!</td></tr>
</tbody></table>
<br />
<span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif;">There
is an interesting IR remote library that can help you read different
remotes without any difficulty. [This is included in the zip file]</span><br />
<br />
<b>How to use Libraries in Arduino - An Overview</b><br />
To use any
library you download, unzip the downloaded file and copy its contents
to the libraries folder inside your arduino directory. You can check the
library by opening the arduino ide and going to Sketch -> Import
Library Option, if your library is in the proper location, it will show
up here. Next if there is an example provided with the library (it will
be inside a folder called example inside the base folder of the library)
it will show up under the libraries name in the File->Examples Menu.
You should reopen Arduino for the library to show up.<br />
<br />
Once you install the IRremote Library, You can try the example
program, IRrecvDemo. This program will give you a serial output of the
HEX code for each value corresponding to each button on a remote. We
will be using the decimal value in our next program. To get the decimal
value, just do the following modification<br />
change this line<br />
from<br />
<strike><i>int RECV_PIN = 11;</i></strike><br />
to<br />
int RECV_PIN = 12; // we have the lcd using the 11th pin ;)<br />
<br />
replace this line<br />
<strike><i>Serial.println(results.value, HEX);</i></strike><br />
with<br />
<i>Serial.println(results.value);</i><br />
<i><br /></i><br />
Here is the modified code [TSOP_IRrecvDemo.ino]<br />
<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv</span>
<span style="color: #7e7e7e;"> * An IR detector/demodulator must be connected to the input RECV_PIN.</span>
<span style="color: #7e7e7e;"> * Version 0.1 July, 2009</span>
<span style="color: #7e7e7e;"> * Copyright 2009 Ken Shirriff</span>
<span style="color: #7e7e7e;"> * http://arcfn.com</span>
<span style="color: #7e7e7e;"> */</span>
#include <IRremote.h>
<span style="color: #cc6600;">int</span> RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;</pre>
<pre>int remote = 0;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
irrecv.enableIRIn(); <span style="color: #7e7e7e;">// Start the receiver</span>
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span> (irrecv.decode(&results)) {</pre>
<pre> remote = results.value;
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(remote);
irrecv.resume(); <span style="color: #7e7e7e;">// Receive the next value</span>
}
}
</pre>
Now get your remote and make note of the values you get for pressing various buttons.<br />
<br />
Now lets try to display the remote button value on the LCD. [LCD_TSOP.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">The following program uses the IRremote library and displays the value of the button being pressed on the LCD</span>
<span style="color: #7e7e7e;">*/</span>
#include <IRremote.h>
#include <<span style="color: #cc6600;">LiquidCrystal</span>.h>
<span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">List of Values corresponding to numbers of the remote being pressed, remember to replace these values with the values you get.</span>
<span style="color: #7e7e7e;">1 16</span>
<span style="color: #7e7e7e;">2 2064</span>
<span style="color: #7e7e7e;">3 1040</span>
<span style="color: #7e7e7e;">4 3088</span>
<span style="color: #7e7e7e;">5 528</span>
<span style="color: #7e7e7e;">6 2576</span>
<span style="color: #7e7e7e;">7 2960</span>
<span style="color: #7e7e7e;">8 3600</span>
<span style="color: #7e7e7e;">9 272</span>
<span style="color: #7e7e7e;">0 2320</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">// initialize the library with the numbers of the interface pins</span>
<span style="color: #cc6600;">LiquidCrystal</span> lcd(2,4,8,9,10,11);
<span style="color: #cc6600;">int</span> RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
<span style="color: #cc6600;">int</span> remote = 0, display_value=0;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
lcd.<span style="color: #cc6600;">begin</span>(16,2);
irrecv.enableIRIn(); <span style="color: #7e7e7e;">// Start the receiver</span>
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span> (irrecv.decode(&results)) {
remote = results.value;
<span style="color: #cc6600;">switch</span>(remote)
{
<span style="color: #cc6600;">case</span> 16 : display_value=1; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2064 : display_value=2; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 1040 : display_value=3; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 3088 : display_value=4; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 528 : display_value=5; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2576 : display_value=6; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2960 : display_value=7; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 3600 : display_value=8; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 272 : display_value=9; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2320 : display_value=0; <span style="color: #cc6600;">break</span>;
}
lcd.<span style="color: #cc6600;">clear</span>();
lcd.<span style="color: #cc6600;">print</span>(display_value);
irrecv.resume(); <span style="color: #7e7e7e;">// Receive the next value</span>
}
}
</pre>
</div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com10tag:blogger.com,1999:blog-9038718253168000072.post-54521953108367374512012-05-17T00:02:00.002-07:002013-07-03T02:39:41.367-07:00Simple Labs' Quick Start Kit for Arduino - DS1307 Real Time Clock IC Interfacing- How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>DS1307 - Real Time Clock IC</b><br />
<br />
The DS1307 lets you explore I2C communication on the arduino.<br />
<br />
<div>
<b>I2C Communication</b></div>
<div>
I2C
is short form for 'Inter Integrated Circuit' I2C Communication is
Communication Bus standard developed by Phillips for standardising
Communication between Integrated Circuits. For Eg. In a circuit, there
could be a number of ICs each offering specific functionality[RTC,
Temperature Sensor, EEPROM, etc] and they can all communicate on a
single I2C Bus and provide combined functionalities. Each device on the
I2C Bus would have a unique address by which it can be addressed.</div>
<div>
<br /></div>
<div>
Here's an Interesting Introduction from NXP</div>
<div>
<iframe allowfullscreen="" frameborder="0" height="315" src="http://www.youtube.com/embed/BcWixZcZ6JY" width="560"></iframe>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<b>I2C on Arduino</b></div>
<div>
The
I2C Bus uses 2 lines for Communication - SDA(Serial Data) & SCL
(Serial Clock). On the InduinoX / Arduino, these are available on SDA
(Analog Input 4) & SCL (Analog Input 5). The I2C bus can be accessed
using the 'Wire' Library of Arduino. First, lets try out a Library</div>
<br />
<br />
<b>Wiring up the DS1307</b><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvIWAbgUU8gWVaXwtnJwkYyoyiHTdKRSYJTjfp9Jr5UP02wjJ7W5dUlY63yLM5P3mQ0_EasTqd58LQIKZGYjJscAKm6t7Edz4E5qvorbtTLv_WSeb954NVJ5Z0VaU65V_lV4hdkEQD2Xpt/s1600/DS1307.gif" style="margin-left: auto; margin-right: auto;"><img border="0" height="190" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvIWAbgUU8gWVaXwtnJwkYyoyiHTdKRSYJTjfp9Jr5UP02wjJ7W5dUlY63yLM5P3mQ0_EasTqd58LQIKZGYjJscAKm6t7Edz4E5qvorbtTLv_WSeb954NVJ5Z0VaU65V_lV4hdkEQD2Xpt/s400/DS1307.gif" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">DS1307 Pin
Mappings. SDA [Serial Data] / SCL [Serial Clock] correspond to lines for
I2C Communication. We can ignore Vbat & SQW / OUT Pins.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhat6Uj1pLY0PeQ4Uei4uVCKF2-dpjIYOO85tGGIR2cDt8g0RCjJAR83Io7CGGIJm40qjBMrI1rzou9L7BzsPcBAGkZkPgK8D7GDJcJnGXtJ7rcKltt4PFZNl_2FqxsYG3MfrlJzItbuCg/s1600/RTC1.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="560" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhat6Uj1pLY0PeQ4Uei4uVCKF2-dpjIYOO85tGGIR2cDt8g0RCjJAR83Io7CGGIJm40qjBMrI1rzou9L7BzsPcBAGkZkPgK8D7GDJcJnGXtJ7rcKltt4PFZNl_2FqxsYG3MfrlJzItbuCg/s640/RTC1.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Components - DS1307, Crystal for DS1307, 2 x 10K Resistors</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgneCgCIBXzpETOKTVP20tsu8hUj8QZnZ0hNVKoZO8tbTi1Z2mEtHgv4F-wm66Srhyphenhyphen7eemMAWVACAYPLNdZt6Uva9-pP1-3blyGcizhPpj8m0J11Cs90v8wDKsOztF8eTXH8Emcp9oM7_4k/s1600/RTC2.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="490" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgneCgCIBXzpETOKTVP20tsu8hUj8QZnZ0hNVKoZO8tbTi1Z2mEtHgv4F-wm66Srhyphenhyphen7eemMAWVACAYPLNdZt6Uva9-pP1-3blyGcizhPpj8m0J11Cs90v8wDKsOztF8eTXH8Emcp9oM7_4k/s640/RTC2.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the DS1307 IC as shown</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho63gpDnJ5KVOvi9X14s672eNjrhg-cmGSe_WFNP_PGVAhcCP9RYxWE24zTOgjlWq2amhofaqFHs_fPTtCIVsYdaDARU8EAsrP5U3YLgl3xgEb1sN2Ali7SFzosvaCJDiaBn3fUyn-v2qh/s1600/RTC3.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho63gpDnJ5KVOvi9X14s672eNjrhg-cmGSe_WFNP_PGVAhcCP9RYxWE24zTOgjlWq2amhofaqFHs_fPTtCIVsYdaDARU8EAsrP5U3YLgl3xgEb1sN2Ali7SFzosvaCJDiaBn3fUyn-v2qh/s640/RTC3.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from the 4th pin of DS1307 (GND) to the '-'ve terminal </td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE74qXt4epnjdlG0BrkvdvWKGgUUIjT9yEGMDqf18Slt7BYEO6tOjs4LHVf4atFA2VG11OVT47CDmAjfbN7MS_LXm302CmnbyqXgrHTNeRB-FgxNtCkw5VWoCfwBDme9A_zfzqOoKGDz56/s1600/RTC4.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="276" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE74qXt4epnjdlG0BrkvdvWKGgUUIjT9yEGMDqf18Slt7BYEO6tOjs4LHVf4atFA2VG11OVT47CDmAjfbN7MS_LXm302CmnbyqXgrHTNeRB-FgxNtCkw5VWoCfwBDme9A_zfzqOoKGDz56/s640/RTC4.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from the 8th pin of DS1307 (+5V) to the '+'ve terminal </td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqwE4uzdKll8tBr9mOcR8CVV8bAuGnl-VQU9PnLK440jKHk62UUPIE5fFkEIch7I5WscJuGm_QEpkT6uXUQeohUMeXnhCKxBeWRjUzCMSFhSrGVnVkROMpmb02UQQ1SUSQHQnxrP4FFLWb/s1600/RTC5.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqwE4uzdKll8tBr9mOcR8CVV8bAuGnl-VQU9PnLK440jKHk62UUPIE5fFkEIch7I5WscJuGm_QEpkT6uXUQeohUMeXnhCKxBeWRjUzCMSFhSrGVnVkROMpmb02UQQ1SUSQHQnxrP4FFLWb/s640/RTC5.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the
Cyrstal as shown between the 1st and 2nd pin of the DS1307 IC- There is
no polarity ('+' / '-' ve) for the crystal. So you can place it anyway</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS4jvlqBFY4XJyAkTKWU8flwnjP3ynnCguu0mLTe7TwwhmdhQi9h3ebYD9xeFsxBkcMANN8YUbyjDddrByzokJLqKrQQmx2kp5u2ub8GuMOeptzIkA4wDcS4PSK7mm0hYcwsk2uchyJxx3/s1600/RTC6.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="632" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS4jvlqBFY4XJyAkTKWU8flwnjP3ynnCguu0mLTe7TwwhmdhQi9h3ebYD9xeFsxBkcMANN8YUbyjDddrByzokJLqKrQQmx2kp5u2ub8GuMOeptzIkA4wDcS4PSK7mm0hYcwsk2uchyJxx3/s640/RTC6.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place one resistor between the SDA Pin and the '+'ve terminal and one resistor between the SCL Pin and the '+'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKIp-Knh9TFq1IV-b9PsW44ZJFUa44pcwS4j4PI18NRye9gKvTGI_qWQJSzJ9cd2Ah7nxAJGLhM0WyLpizWty9gEvTKjE-RYsI6i-KLbZIs1FEdvfzWmUrxGQvtdVQgFJTpIZ3E-WswwE3/s1600/RTC7.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="398" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKIp-Knh9TFq1IV-b9PsW44ZJFUa44pcwS4j4PI18NRye9gKvTGI_qWQJSzJ9cd2Ah7nxAJGLhM0WyLpizWty9gEvTKjE-RYsI6i-KLbZIs1FEdvfzWmUrxGQvtdVQgFJTpIZ3E-WswwE3/s640/RTC7.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between the SDA pin (pin5 of DS1307) and the SDA pin of the Arduino (Analog IN 4)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr13lN1Q9TP6JH0jfkCzOUKkVFSSustuvaCSnfVGxoDhrH59un4ZORHon_tiAx2g0rSJnz5QX2tIcRVKtxI1tauP5WdbFFxsKimtHAhcOM5ErSaMh3FAaBmFamya03feKMvfe7G7_bhpKX/s1600/RTC8.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr13lN1Q9TP6JH0jfkCzOUKkVFSSustuvaCSnfVGxoDhrH59un4ZORHon_tiAx2g0rSJnz5QX2tIcRVKtxI1tauP5WdbFFxsKimtHAhcOM5ErSaMh3FAaBmFamya03feKMvfe7G7_bhpKX/s640/RTC8.JPG" width="554" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between the SCL pin (pin6 of DS1307) and the SCL pin of the Arduino (Analog IN 5)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1SfVn7kbKtcPXN-R_MISnW3elaNJRLbBWJkAxkVPeWTsEReqo1hk_2xDKSof9gvkWIokzk7dSxs7m8fAEpwd-plD6QsWxdcE9P4VPpzAlKXQvz6OiLh_FDSx5zqwYB6J-GIXebyCtGmCh/s1600/RTC9.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="496" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1SfVn7kbKtcPXN-R_MISnW3elaNJRLbBWJkAxkVPeWTsEReqo1hk_2xDKSof9gvkWIokzk7dSxs7m8fAEpwd-plD6QsWxdcE9P4VPpzAlKXQvz6OiLh_FDSx5zqwYB6J-GIXebyCtGmCh/s640/RTC9.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Final Setup with output from the following program</td></tr>
</tbody></table>
<br />
Try following Sample Program [LCD_RTC.ino]<br />
<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">This program uses the Wire Library (for i2c communication)</span>
<span style="color: #7e7e7e;">This program sets the initial time for the RTC and keeps updating the time on an LCD everysecond.</span>
<span style="color: #7e7e7e;">*/</span>
#include <<span style="color: #cc6600;">Wire</span>.h>
#define rtc 0x68 <span style="color: #7e7e7e;">// The pre-defined address for DS1307</span>
<span style="color: #cc6600;">int</span> ss,mm,hh,d,DD,MM,YY,mode;
<span style="color: #cc6600;">boolean</span> time_format,meridiem;
<span style="color: #cc6600;">int</span> prev;
#include <<span style="color: #cc6600;">LiquidCrystal</span>.h>
<span style="color: #7e7e7e;">// initialize the library with the numbers of the interface pins</span>
<span style="color: #cc6600;">LiquidCrystal</span> lcd(2,4,8,9,10,11);
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">begin</span>();
lcd.<span style="color: #cc6600;">begin</span>(16, 2);
set_time();
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
get_time();
<span style="color: #cc6600;">if</span>(ss!=prev) <span style="color: #7e7e7e;">// lcd Print when the seconds change</span>
{
lcd.<span style="color: #cc6600;">setCursor</span>(0,0);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Date:"</span>);
lcd.<span style="color: #cc6600;">print</span>(DD);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"/"</span>);
lcd.<span style="color: #cc6600;">print</span>(MM);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"/"</span>);
lcd.<span style="color: #cc6600;">print</span>(YY);
lcd.<span style="color: #cc6600;">setCursor</span>(0,1);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Time:"</span>);
lcd.<span style="color: #cc6600;">print</span>(hh);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">":"</span>);
lcd.<span style="color: #cc6600;">print</span>(mm);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">":"</span>);
lcd.<span style="color: #cc6600;">print</span>(ss);
prev=ss;
}
}
<span style="color: #cc6600;">void</span> get_time()
{
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">beginTransmission</span>(rtc); // start communication over i2c with DS1307
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>((<span style="color: #cc6600;">byte</span>)0); // Write the value of the register to point to
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">endTransmission</span>(); // End communication over i2c with DS1307
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">requestFrom</span>(rtc,7); // This will request 7 bytes of data </pre>
<pre> //starting from the '0' the register
ss=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
mm=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
hh=<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>();
time_format=hh&(1<<6);
meridiem=hh&(1<<5); <span style="color: #7e7e7e;">// calculate am or pm</span>
hh=bcd_to_dec(hh&0x1F);
d=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
DD=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
MM=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
YY=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">endTransmission</span>();
}
<span style="color: #cc6600;">void</span> set_time()
{
time_format=0; <span style="color: #7e7e7e;">// 0=24 hour mode, 1=12 hour mode </span>
meridiem=1; <span style="color: #7e7e7e;">// 0=am, 1=pm will not be taken into consideration if time format is 24 hour mode</span>
mode=(time_format<<6)+((time_format&&meridiem)<<5); <span style="color: #7e7e7e;">//calculate the bits to be added for 12 hour mode </span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">beginTransmission</span>(rtc);
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>((<span style="color: #cc6600;">byte</span>)0);
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(50)); <span style="color: #7e7e7e;">// seconds</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(59)); <span style="color: #7e7e7e;">// minutes</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(mode+dec_to_bcd(11));<span style="color: #7e7e7e;">// hours</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(3)); <span style="color: #7e7e7e;">// day of the week, startin monday</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(21)); <span style="color: #7e7e7e;">// date</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(12)); <span style="color: #7e7e7e;">// month</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(11)); <span style="color: #7e7e7e;">// year</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">endTransmission</span>();
}
<span style="color: #cc6600;">int</span> dec_to_bcd(<span style="color: #cc6600;">int</span> dec)
{
<span style="color: #cc6600;">return</span> dec/10*16 + (dec%10);
}
<span style="color: #cc6600;">int</span> bcd_to_dec(<span style="color: #cc6600;">int</span> bcd)
{
<span style="color: #cc6600;">return</span> bcd/16*10 + (bcd%16);
}
</pre>
<br /></div>
R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com17tag:blogger.com,1999:blog-9038718253168000072.post-72311114933142928152012-05-16T23:59:00.002-07:002012-05-16T23:59:49.580-07:00Simple Labs' Quick Start Kit for Arduino - LCD Interfacing - How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>LCD - Liquid Crystal Display</b><br />
LCDs
are commonly used display devices that you would find in most
appliances / electronic devices. Your music players, Pay phones, Etc.<br />
<br />
<span class="Apple-style-span" style="background-color: white;"><span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif; font-size: 15px; line-height: 21px;">Here's an interesting Write up to get you understanding the working of the LCD</span><br style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif; font-size: 15px; line-height: 21px; text-align: left;" /><span class="Apple-style-span" style="color: #222222; font-family: Georgia,Utopia,'Palatino Linotype',Palatino,serif; font-size: 15px; line-height: 21px; text-align: left;"><a href="http://joshuagalloway.com/lcd.html">http://joshuagalloway.com/lcd.html</a></span></span><br />
<span class="Apple-style-span" style="background-color: white;"><br /></span><br />
<span class="Apple-style-span" style="background-color: white;">Wiring up the LCD</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3gwWhdcmh2Zxc2Vnx1e1KqBUZODfZ5_rif23HXA5UYv9fUFzRu-o0-3CGq-W_rGI0GK6vpW5hvfRPmmGOseBSTTYUexgBrMaBLL2YBObBEQO7YR-5VMcOH_7AAjhFFgyL4Al8VBuH9547/s1600/LCD3.JPG" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="314" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3gwWhdcmh2Zxc2Vnx1e1KqBUZODfZ5_rif23HXA5UYv9fUFzRu-o0-3CGq-W_rGI0GK6vpW5hvfRPmmGOseBSTTYUexgBrMaBLL2YBObBEQO7YR-5VMcOH_7AAjhFFgyL4Al8VBuH9547/s640/LCD3.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The 16x2 LCD Display</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB-ln_-vJQSODEoPU_UAXe13UZ_pkC6sZA3sSJ4TvKpE37PDeVia7nUEPE2TsEc1G7Q5UScGU8UZli969e74wAzCC8vCnuEtiM9ojVhWrU0lKZkL2ulzDvRHbIN43P6V_ipMKc-yRgKuql/s640/LCD_Pins.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="268" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB-ln_-vJQSODEoPU_UAXe13UZ_pkC6sZA3sSJ4TvKpE37PDeVia7nUEPE2TsEc1G7Q5UScGU8UZli969e74wAzCC8vCnuEtiM9ojVhWrU0lKZkL2ulzDvRHbIN43P6V_ipMKc-yRgKuql/s640/LCD_Pins.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">LCD Pin Mappings</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg5YNriB8g8GnF3bmcBy1KvHJvw2Zq7Onx92-rG45Nobmo8ytOrBqxDWPG6bp0ryuaiWh7E9Hk9SnOZpa03CzI225Xzu2S4qN-pqw2pIpO627KscdIaPdhzlA_FJII2D-ZrR7t282PWVhY/s1600/LCD2.JPG" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="488" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg5YNriB8g8GnF3bmcBy1KvHJvw2Zq7Onx92-rG45Nobmo8ytOrBqxDWPG6bp0ryuaiWh7E9Hk9SnOZpa03CzI225Xzu2S4qN-pqw2pIpO627KscdIaPdhzlA_FJII2D-ZrR7t282PWVhY/s640/LCD2.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">First Connect A
Wire between the GND pin of the Arduino and the '-'ve terminal. Then
Connect Another Wire from the 5V pin of the Arduino to the '+'ve
terminal.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4T5FMfyGqwUvg88oS2OLLtuh64dud9rrDqmdJrSKXRrWysCmHFNaBkY2p2DzGEBYWlA5mREkrErgPvwX3EZqXfAwCWWdYg-5fdtxIBREaFZaA2UX0uij6Ww0EQg5lFGMAvVjggVEKw9Vj/s1600/LCD4.JPG" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4T5FMfyGqwUvg88oS2OLLtuh64dud9rrDqmdJrSKXRrWysCmHFNaBkY2p2DzGEBYWlA5mREkrErgPvwX3EZqXfAwCWWdYg-5fdtxIBREaFZaA2UX0uij6Ww0EQg5lFGMAvVjggVEKw9Vj/s640/LCD4.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the LCD on the Breadboard as Shown (the 16th pin of the LCD is in the LEFT Corner of the Image)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmz2Xxee3fZAQV2elq-XTgAAJQREypTZH2eLYHt6FnO8pYdWXVVy9u-QnZPstdneZGhMpL49EL9TiaM-iPFtd5UJN45ZTyxRzUznMK-rfzSXTWJ-S_ypmBPU-FA5aht6xrwR02PQ0MlPwZ/s1600/LCD5.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmz2Xxee3fZAQV2elq-XTgAAJQREypTZH2eLYHt6FnO8pYdWXVVy9u-QnZPstdneZGhMpL49EL9TiaM-iPFtd5UJN45ZTyxRzUznMK-rfzSXTWJ-S_ypmBPU-FA5aht6xrwR02PQ0MlPwZ/s640/LCD5.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">This is what you should have now</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY21HAk0pxF8oazQE1ZhiU918q7inq2FoEjsU153lE3YhlQkILlx95J1HqJ8WX1WiBxUfPLu2wt7xxEvHgmhv6fZX8ryIUXpK8OMXECVziS20Q1rpEc3Tjh1vZVnbNyvYnPm46XBMDo_Js/s1600/LCD6.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY21HAk0pxF8oazQE1ZhiU918q7inq2FoEjsU153lE3YhlQkILlx95J1HqJ8WX1WiBxUfPLu2wt7xxEvHgmhv6fZX8ryIUXpK8OMXECVziS20Q1rpEc3Tjh1vZVnbNyvYnPm46XBMDo_Js/s640/LCD6.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the Trimpot Next to the LCD as shown (a bit away from the LCD pins)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgABoDNfxUvPlB9Wm8A-8TdAEB5UcKVGBxx4un6x5lV-6V9bB-_12YvTLsj2bLp_hKxdgucH3DBQgT-STNG_VWCRBQLsGH4piKIWeanp3vsNjG_AFxOQ9T9ImTQiDmcaF2yUCgnE-olo6Sd/s1600/LCD7.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgABoDNfxUvPlB9Wm8A-8TdAEB5UcKVGBxx4un6x5lV-6V9bB-_12YvTLsj2bLp_hKxdgucH3DBQgT-STNG_VWCRBQLsGH4piKIWeanp3vsNjG_AFxOQ9T9ImTQiDmcaF2yUCgnE-olo6Sd/s640/LCD7.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect the Supply & Ground Lines for the Trimpot</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Os3wN1DcX3vV1iIAiM70-HRD5GekwpKm93xuL0l03wIz0i52TlaTE6DeKekXBZjkg6yWceYrvnhFlH3a89mIPeLtTCgSjqwe5bwMpO5BB7WCyNn9ocB7rhZXm6q-eA3QLb7LZGna-HPR/s1600/LCD8.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Os3wN1DcX3vV1iIAiM70-HRD5GekwpKm93xuL0l03wIz0i52TlaTE6DeKekXBZjkg6yWceYrvnhFlH3a89mIPeLtTCgSjqwe5bwMpO5BB7WCyNn9ocB7rhZXm6q-eA3QLb7LZGna-HPR/s640/LCD8.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The First and Last pins of the LCD are GND pins. First Connect a Wire from the 1st pin of the LCD to the '-'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFzI9CLN683ERtFrcoZutU3CC-JdeCxaon7a9bYUdgqqV5TWxSnocLgYEKTr7wE_MGYEUSXfJOx1XLNjvCqdIAmjbXR7U4u8X5P5KYzK6lqQRau7lmCaz15z2gywSr_KzbAB-7dpDB7SX0/s1600/LCD9.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFzI9CLN683ERtFrcoZutU3CC-JdeCxaon7a9bYUdgqqV5TWxSnocLgYEKTr7wE_MGYEUSXfJOx1XLNjvCqdIAmjbXR7U4u8X5P5KYzK6lqQRau7lmCaz15z2gywSr_KzbAB-7dpDB7SX0/s640/LCD9.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire from the 16th pin of the LCD to the '-'ve terminal</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLE2l4XHtItKqOQc0RHqEtAeeMMP_RALvQ664nsPCkph5nWNH5apfJtbVnYNPWRJwx4ZZ-xcE8zC8W2alDIPq0oKLN5SaAagoeOj5qpnY8k2GZuQbz0lfqylr45VEoVFwcvbweMCNJok56/s1600/LCD10.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLE2l4XHtItKqOQc0RHqEtAeeMMP_RALvQ664nsPCkph5nWNH5apfJtbVnYNPWRJwx4ZZ-xcE8zC8W2alDIPq0oKLN5SaAagoeOj5qpnY8k2GZuQbz0lfqylr45VEoVFwcvbweMCNJok56/s640/LCD10.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The 2nd & 15th Pins of the LCD are Supply Pins, Connect Wires from these to the '+'ve Terminal as shown</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvvvsdjAr_HnVqpK7hMsGKM0WgYolQi5W59Cs1L-vy6oIgLngIYOd-Xh0NEiOT1iZPXURdtokGGum5PfgxfJaRPYZh62iFTuyzVGYV7zVPOhEETDSxgpsKAqgLc0K7mZYLgR8U6CAV3GeK/s1600/LCD11.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvvvsdjAr_HnVqpK7hMsGKM0WgYolQi5W59Cs1L-vy6oIgLngIYOd-Xh0NEiOT1iZPXURdtokGGum5PfgxfJaRPYZh62iFTuyzVGYV7zVPOhEETDSxgpsKAqgLc0K7mZYLgR8U6CAV3GeK/s640/LCD11.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The 5th of the
LCD is the RW pin. This pin is used to toggle between Read / Write Mode
of the LCD. Writing a HIGH signal to this pin corresponds to Read Mode
and Writing a LOW signal corresponds to Write Mode. Since we will be
using only the Write mode, we can wire this pin to GND / '-'ve terminal
[This is equivalent of writing a LOW signal to the pin]</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo6cfeFkX93GiCb3fOWRoRs7EIa1UmZmz-675jXHa80VTVUk1se1D98xnvZnWlMr9fJuYwioEfjJhryASy14oY2QgFcb6xCdC8BhAR7upLUqnXQN8OefL6uoyzZfLhCuDjTyfd8_sMtJFk/s1600/LCD12.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo6cfeFkX93GiCb3fOWRoRs7EIa1UmZmz-675jXHa80VTVUk1se1D98xnvZnWlMr9fJuYwioEfjJhryASy14oY2QgFcb6xCdC8BhAR7upLUqnXQN8OefL6uoyzZfLhCuDjTyfd8_sMtJFk/s640/LCD12.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire
from the middle pin of the trimpot to the 3rd pin of the LCD. The 3rd
pin of the LCD is the contrast pin and the contrast of the display can
be varied by varying the trimpot</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbAtQcZDlnR_OMer3gVtlpsVrCHWCDIFnLLJfFraV6eRpU-XeUJcPjb5_2cJ5iItuLHa27bKDurp7laxBe42TUzPQJheliFADFYhKjA6P9v-4ayxNiyomE7f58FfnyHqPDMB-ycuThsgNN/s1600/LCD13.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbAtQcZDlnR_OMer3gVtlpsVrCHWCDIFnLLJfFraV6eRpU-XeUJcPjb5_2cJ5iItuLHa27bKDurp7laxBe42TUzPQJheliFADFYhKjA6P9v-4ayxNiyomE7f58FfnyHqPDMB-ycuThsgNN/s640/LCD13.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire
between the RS pin of the LCD (4th pin) and digital pin 2 of the
Arudino. The RS pin helps select between the 2 registers of an LCD -
Data & Command - for communication</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSLMhW_tiIqejutUGhYZGjNpNqTfjWo7BCmsgxP1GiSA9imNHlfznIJK4uNHDEWfJJ8ximFGegBDn0ukqgFnAZtGza1xUXno4vJXHI_gdFzfO56pocd6sa491zV40rQXjL4RmNpXXePgHc/s1600/LCD14.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSLMhW_tiIqejutUGhYZGjNpNqTfjWo7BCmsgxP1GiSA9imNHlfznIJK4uNHDEWfJJ8ximFGegBDn0ukqgFnAZtGza1xUXno4vJXHI_gdFzfO56pocd6sa491zV40rQXjL4RmNpXXePgHc/s640/LCD14.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between the Enable pin (the 6th pin) of the LCD and digital pin 4 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvD_tCZWyJ5ARI_hZtqcSlG22BbOPBaTs3wpU10BOIobHhhsbMY0gqMt3YUqXoNHmAeQX7p31sm7MQ9BLEG2QDnPyud5bCylBTqnCSPt8P7vT5xhHpwFn60-mfiVONKl8G99kpi2OWYEA2/s1600/LCD15.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvD_tCZWyJ5ARI_hZtqcSlG22BbOPBaTs3wpU10BOIobHhhsbMY0gqMt3YUqXoNHmAeQX7p31sm7MQ9BLEG2QDnPyud5bCylBTqnCSPt8P7vT5xhHpwFn60-mfiVONKl8G99kpi2OWYEA2/s640/LCD15.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between D4 of the LCD (11th pin) and digital pin 8 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6QW1PcsIlBmpdmnWWZxAmbXcg6zXjucDkWnRTNKGtS4139mvN0IF_lQGT-7UAL6NhIflTf4boac7C98K4jNuc5EJm819AC-DBQeEpQyUm-czvxIIXQ2YsjfUhhhn0htt0aIvS7s57NUYo/s1600/LCD16.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6QW1PcsIlBmpdmnWWZxAmbXcg6zXjucDkWnRTNKGtS4139mvN0IF_lQGT-7UAL6NhIflTf4boac7C98K4jNuc5EJm819AC-DBQeEpQyUm-czvxIIXQ2YsjfUhhhn0htt0aIvS7s57NUYo/s640/LCD16.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between D5 of the LCD (12th pin) and digital pin 9 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlNLHHyDlzIvAtUvUSnwJE13qt3F9i_f9Yf5fQZ4nsey4PN3WXmXYDMn9E1-oaOqhyPXoW-lFqlJjYSJh9-fxm_zb1E6d9SWmSx_R5-AnG4g31AjPYCBj6uQ8HH3H9ktdsbJjK5JYeaFQz/s1600/LCD17.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlNLHHyDlzIvAtUvUSnwJE13qt3F9i_f9Yf5fQZ4nsey4PN3WXmXYDMn9E1-oaOqhyPXoW-lFqlJjYSJh9-fxm_zb1E6d9SWmSx_R5-AnG4g31AjPYCBj6uQ8HH3H9ktdsbJjK5JYeaFQz/s640/LCD17.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between D6 of the LCD (13th pin) and digital pin 10 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHQd8GOtv6JPoeXgxYlnlXwpIWIINAFfqHeJo_fxrYEmZ4jzz5lHMrUKw7RBqXWNuOV0iGhsEPRuUgs75XX0e6XkaJ1arNnwi7gYk3NBCw3cHzfs3ReWUqKt-O4NjENERikthYag1-VrCU/s1600/LCD18.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHQd8GOtv6JPoeXgxYlnlXwpIWIINAFfqHeJo_fxrYEmZ4jzz5lHMrUKw7RBqXWNuOV0iGhsEPRuUgs75XX0e6XkaJ1arNnwi7gYk3NBCw3cHzfs3ReWUqKt-O4NjENERikthYag1-VrCU/s640/LCD18.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between D7of the LCD (14th pin) and digital pin 11 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8HaJLG8m5tUsRdn5FsybdoXVUsvRD_b2hrFWBIUwuORnM6QKi20JEgD2L8weFds9ojbBfChLPHHV3rFvana_F-QW9QCXUKVN80MoHB0u-tjp8DT2MREs4JMAyMd1dlSlLrGPJ72ke0lTA/s1600/LCD19.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8HaJLG8m5tUsRdn5FsybdoXVUsvRD_b2hrFWBIUwuORnM6QKi20JEgD2L8weFds9ojbBfChLPHHV3rFvana_F-QW9QCXUKVN80MoHB0u-tjp8DT2MREs4JMAyMd1dlSlLrGPJ72ke0lTA/s640/LCD19.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Finished Setup</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnVzGYB0Rdi1mAqU0b5B3aQkGNIvEnT5pjeDy7Noe_oLTcImbWbv-0u9g1ACMvH0XxCqpScgaac2EJvztlni7FI4MvvCZP8YMUvCRqurAY92_rIlIfzIrZ7xj6-5fAO_eRT7wiOtfoS-ZK/s1600/LCD20.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="464" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnVzGYB0Rdi1mAqU0b5B3aQkGNIvEnT5pjeDy7Noe_oLTcImbWbv-0u9g1ACMvH0XxCqpScgaac2EJvztlni7FI4MvvCZP8YMUvCRqurAY92_rIlIfzIrZ7xj6-5fAO_eRT7wiOtfoS-ZK/s640/LCD20.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Sample Hello World Program</td></tr>
</tbody></table>
So Lets program the LCD. We can take the sample hello
world program found under File -> Examples -> LiquidCrystal menu
of Arduino IDE and change the pin numbers in the following statement<br />
From<br />
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);<br />
To<br />
LiquidCrystal lcd(2,4,8,9,10,11);<br />
<br />
####IMPORTANT - IN CASE NOTHING IS DISPLAYED ON THE LCD KEEP VARYING THE TRIMPOT TILL YOU CAN SEE THE CHARACTERS###<br />
<br />
Try the following Simple LCD program [Simple_LCD.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> LiquidCrystal Library - Hello World</span>
<span style="color: #7e7e7e;"> </span>
<span style="color: #7e7e7e;"> Demonstrates the use a 16x2 LCD display. The LiquidCrystal</span>
<span style="color: #7e7e7e;"> library works with all LCD displays that are compatible with the </span>
<span style="color: #7e7e7e;"> Hitachi HD44780 driver. There are many of them out there, and you</span>
<span style="color: #7e7e7e;"> can usually tell them by the 16-pin interface.</span>
<span style="color: #7e7e7e;"> </span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">// include the library code:</span>
#include <<span style="color: #cc6600;">LiquidCrystal</span>.h>
<span style="color: #7e7e7e;">// initialize the library with the numbers of the interface pins</span>
<span style="color: #cc6600;">LiquidCrystal</span> lcd(2,4,8,9,10,11);
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #7e7e7e;">// set up the LCD's number of columns and rows: </span>
lcd.<span style="color: #cc6600;">begin</span>(16, 2);
<span style="color: #7e7e7e;">// Print a message to the LCD.</span>
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"hello, world!"</span>);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #7e7e7e;">// set the cursor to column 0, line 1</span>
<span style="color: #7e7e7e;">// (note: line 1 is the second row, since counting begins with 0):</span>
lcd.<span style="color: #cc6600;">setCursor</span>(0, 1);
<span style="color: #7e7e7e;">// print the number of seconds since reset:</span>
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #cc6600;">millis</span>()/1000);
}
</pre>
<br /></div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com7tag:blogger.com,1999:blog-9038718253168000072.post-60274254346906401992012-05-16T23:58:00.002-07:002012-05-16T23:58:54.922-07:00Simple Labs' Quick Start Kit for Arduino - IR Proximity Sensor Interfacing- How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>The IR Proximity Sensor</b><br />
<br />
The IR Proximity
sensor is one of the most commonly used sensors. You will find these in
automatic taps, automatic door opening, etc. This sensor works on the
principle of IR reflectance. There is an IR LED (white / light blue in
color) that is constantly emitting IR light. The light when reflected
back falls on the IR Receiver LED / Photodiode (the black / dark blue
color led). This received signal is then processed by an Op-Amp and the
Op-Amp gives a HIGH signal. So the sensor module will give a HIGH signal
if there is an object in front of the LED's. The range of sensing can
be varied by adjusting the potentiometer on the sensor module. The
maximum range of this module is only a few cms, so don't expect to use
this as a distance sensor ;). The module will not work when pointed at
black objects as black color tends to absorb the IR light.<br />
<br />
Note:
The IR Sensor and its 3-pin cable will not come attached. You need to
fix the Cable on to the Sensor. There is only 1 way the cable will fit
on the sensor module, so, we presume you can't go wrong about it ;)<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifoapTZ8idLoHwTTPiypAjGEOWRnQ6Ojch-DPNKUpdbrv4BVNfYUzeTzINRrIuiTXVquT9VXQHMuHSjOkTGBz6-pDPJ7dZfhPYUbrDK_RZy4rr3nSLzaS6kFw80652jSCqgqY92VHzv6sM/s1600/IR1.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="256" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifoapTZ8idLoHwTTPiypAjGEOWRnQ6Ojch-DPNKUpdbrv4BVNfYUzeTzINRrIuiTXVquT9VXQHMuHSjOkTGBz6-pDPJ7dZfhPYUbrDK_RZy4rr3nSLzaS6kFw80652jSCqgqY92VHzv6sM/s640/IR1.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The IR Sensor. Look at the Wires and Their Mappings. We will connect these accordingly</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7AO3hxTayAt8Tzjot9nAI__T2Gf71Dxw50elhckArqX-7_Dfwa0J9Gjr1UsDZ4O0kwhKDW0tc5hx1Pjz0tcmyAEAPXB_IW5wo8uCQJXTW0X4_y1FsKThxNwMeBUouEkOX_xjKCzIcHi-m/s1600/IR2.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="458" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7AO3hxTayAt8Tzjot9nAI__T2Gf71Dxw50elhckArqX-7_Dfwa0J9Gjr1UsDZ4O0kwhKDW0tc5hx1Pjz0tcmyAEAPXB_IW5wo8uCQJXTW0X4_y1FsKThxNwMeBUouEkOX_xjKCzIcHi-m/s640/IR2.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect the Red Wire of the IR sensor to the '+'ve Terminal & the Black Wire of the IR sensor to the '-'ve Terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIiSd3MOFfxD0ZfV9KVtVc1vsp05Rw7ihk1aQ9gb0SNwLev1zrAof4JHe3FlRDwGYYT792q8oBM-i1VHa7kdHqMUprOjepEgLgiRf6sl-t8nxfZZLB-ipvjZnxyOIZrMtxKeUBCxH7XraJ/s1600/IR3.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIiSd3MOFfxD0ZfV9KVtVc1vsp05Rw7ihk1aQ9gb0SNwLev1zrAof4JHe3FlRDwGYYT792q8oBM-i1VHa7kdHqMUprOjepEgLgiRf6sl-t8nxfZZLB-ipvjZnxyOIZrMtxKeUBCxH7XraJ/s640/IR3.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect the Brown wire of the IR sensor to the 8th pin of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFmD56XwdoCdCnWJPlVR2ooq_BWWRMrP-jVzonCSjCjPPl9NHcMYLBEnY13CHJVwFfBku69tud1en-ZxVzZGeaVnanhShdWqRe8IrjnynIXNA2c5FXKV-MJrDB58VpkFERIHkl8T1hU4nf/s1600/IR4.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="528" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFmD56XwdoCdCnWJPlVR2ooq_BWWRMrP-jVzonCSjCjPPl9NHcMYLBEnY13CHJVwFfBku69tud1en-ZxVzZGeaVnanhShdWqRe8IrjnynIXNA2c5FXKV-MJrDB58VpkFERIHkl8T1hU4nf/s640/IR4.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">This is how your final setup should look like</td></tr>
</tbody></table>
<br />
<br />
Lets program to trigger the Buzzer everytime the sensor gives a HIGH signal. Try the following program. [ULN_Buzzer_IR.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">ULN2003- Buzzer</span>
<span style="color: #7e7e7e;">This program drives a Buzzer using ULN2003 </span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
<span style="color: #cc6600;">pinMode</span>(7,<span style="color: #006699;">OUTPUT</span>);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;">delay</span>(2000);
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">LOW</span>);
<span style="color: #cc6600;">delay</span>(3000);
}
</pre>
</div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com8tag:blogger.com,1999:blog-9038718253168000072.post-67875357101933329142012-05-16T23:51:00.003-07:002012-05-16T23:51:27.800-07:00Simple Labs' Quick Start Kit for Arduino - Interfacing IC ULN2003 - Darlington Pair Transistor Array - How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<b>IC ULN2003 - Darlington Pair Transistor Array</b><br />
<br />
In
our last example of the first part, we saw how to use a transistor to
trigger a buzzer. What if we had more than one buzzer? We can't be
setting up multiple transistors as that would get hectic. IC ULN2003 has
an array of transistors built inside it and these transistors can be
used very much like our regular transistor. The ULN2003 has 7 darlington
pairs of transistors inside it. A darlington transistor pair is a
cascading transistor setup that given an increased amplification. (<a href="http://en.wikipedia.org/wiki/Darlington_transistor" target="_blank">Click Here to Read more on Darlington Pairs</a>) Each of these pairs can drive a device and can be controlled individually.<br />
<br />
<br />
We hope you have kept the basic
breadboard setup intact and removed everything else from the previous
experiments. Here's how your breadboard should look now.</div>
<div style="text-align: justify;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhk5E3QY6LXWIS0sEmZxWotq1VqEaqMoD4tDXzijiCVfgj_gEW_3OhbVrG1KBonOMG2vQV1IpNY4NBNMYHUVyb2Q8-XbhzIBXF0rrwBAJVVTODlRmve6RQ9D-ikVAKO-SoR6H3djpufS6mm/s1600/breadboard1.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhk5E3QY6LXWIS0sEmZxWotq1VqEaqMoD4tDXzijiCVfgj_gEW_3OhbVrG1KBonOMG2vQV1IpNY4NBNMYHUVyb2Q8-XbhzIBXF0rrwBAJVVTODlRmve6RQ9D-ikVAKO-SoR6H3djpufS6mm/s640/breadboard1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Basic Breadboard Setup</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS3NrXoXR-QUEcjZ5ctO2ih8YL4FZ89mz2CGBSAT0xf4HW6j3YPFfzddBXoWWYBA__ed1ZqezhDEI6pLyDjERWdhF4Az9w6dp9BDnazM3bTq6ls0821-Neog1gFfLPwOrqCrIP-wXba8jL/s1600/ULN2003.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS3NrXoXR-QUEcjZ5ctO2ih8YL4FZ89mz2CGBSAT0xf4HW6j3YPFfzddBXoWWYBA__ed1ZqezhDEI6pLyDjERWdhF4Az9w6dp9BDnazM3bTq6ls0821-Neog1gFfLPwOrqCrIP-wXba8jL/s320/ULN2003.jpg" width="269" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Pin Diagram of ULN2003 / COM is +5V in our case</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3XDlRylHNTCym20oTTO1RU8CzWJsIuase6lCtRZQ75lL1UAWNXiZMEUx4kRNcdruRQxC01ttjalCeto9oHzeuksF0zLgeqNrV6_zRcnqpm2r2NK5Ala9e1N8LDvQ6zsfkk0qo74YyFdCN/s1600/ULN1A.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3XDlRylHNTCym20oTTO1RU8CzWJsIuase6lCtRZQ75lL1UAWNXiZMEUx4kRNcdruRQxC01ttjalCeto9oHzeuksF0zLgeqNrV6_zRcnqpm2r2NK5Ala9e1N8LDvQ6zsfkk0qo74YyFdCN/s640/ULN1A.jpg" width="596" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the
ULN2003 IC as shown. The Top of All ICs is marked by a notch. The Pin to
the LEFT of this Notch is the first pin of the IC. For Some IC's there
will be a small dot next to the first pin.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4IzrnYbPNBpW-8kQEtAIJo9qGmZEPCFg0E2HF6299e-R5hHRGQwddezSJOCA-pGyMOLfJOmgP9pbljFiKbkp1gCsqkTHeA6TcG0YYVXxlBUYqo_QlrBTSU9TyzSCfqkimZixeKV2jiKRE/s1600/ULN2.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="584" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4IzrnYbPNBpW-8kQEtAIJo9qGmZEPCFg0E2HF6299e-R5hHRGQwddezSJOCA-pGyMOLfJOmgP9pbljFiKbkp1gCsqkTHeA6TcG0YYVXxlBUYqo_QlrBTSU9TyzSCfqkimZixeKV2jiKRE/s640/ULN2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire from the '-'ve terminal to the 8th pin of the IC</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLRuNx0hzExFYRyTxRO9cWrB2tQdIEwr-jqyOEQLdckyA3umPhzKENe6Cl9N0J5bBVSbTqmvR51X3R0iXoCtBxinMu3wMA59FzftUBjEZoWHeymap-e-lp1h32SXgrpmVC7lh5fM-id0U_/s1600/ULN3.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="598" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLRuNx0hzExFYRyTxRO9cWrB2tQdIEwr-jqyOEQLdckyA3umPhzKENe6Cl9N0J5bBVSbTqmvR51X3R0iXoCtBxinMu3wMA59FzftUBjEZoWHeymap-e-lp1h32SXgrpmVC7lh5fM-id0U_/s640/ULN3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between the 9th pin of the IC to the '+'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmYrksxuU134uhD6NNSorQeiT2a8r0mWO6Qxiv5YBKJNE9nriaxYvhGqHlK1Yy8pTFCywHnpHE9bt2IC_5tx86MbhCUBarCkCxAobrpu8FvCT0BZxsx6A4UFcfCd9tR4RV2C18zR8kg9ML/s1600/ULN4.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="542" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmYrksxuU134uhD6NNSorQeiT2a8r0mWO6Qxiv5YBKJNE9nriaxYvhGqHlK1Yy8pTFCywHnpHE9bt2IC_5tx86MbhCUBarCkCxAobrpu8FvCT0BZxsx6A4UFcfCd9tR4RV2C18zR8kg9ML/s640/ULN4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Now Connect
the Positive of the Buzzer (the Red Wire) to the '+'ve terminal and the
Negative of the Buzzer to the 16th pin of the IC (OUTPUT 1)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7YlkRiuwubXRdrxKRzCJqK9vOzyqwu48w4zuKDEDLeOD2nyMgLZUhWxYJa3Jd0diH2_hv9CW3CL7yYCxY2v1mmx-2KaWQMjlRBvsPeFuWPRb8PRVrY7bfT2APpRiytHyDsA0HduS4uFkY/s1600/ULN5.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7YlkRiuwubXRdrxKRzCJqK9vOzyqwu48w4zuKDEDLeOD2nyMgLZUhWxYJa3Jd0diH2_hv9CW3CL7yYCxY2v1mmx-2KaWQMjlRBvsPeFuWPRb8PRVrY7bfT2APpRiytHyDsA0HduS4uFkY/s640/ULN5.jpg" width="594" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from GND on the Arduino to the '-'ve Terminal of the Breadboard</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLLB0gUsHDdxWVbsakL6aJqztVf2ioJOzG-fQY23Tt8rasfNXPKVq6LUNBbXUc1jd-zZvkWdztl0B9tC7t4KG99R2_vfSjHPIN2iR-k_2l72glBJZvBGijC5QMB5ZXIobdrVoYi98mIfu5/s1600/ULN6.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLLB0gUsHDdxWVbsakL6aJqztVf2ioJOzG-fQY23Tt8rasfNXPKVq6LUNBbXUc1jd-zZvkWdztl0B9tC7t4KG99R2_vfSjHPIN2iR-k_2l72glBJZvBGijC5QMB5ZXIobdrVoYi98mIfu5/s640/ULN6.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from the 5V pin on the Arduino to the '+'ve terminal on the Breadboard</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO3snjokijQY1Q77MIkFuepyqkUSAkQk92goODWB1y2OL9kDs8d3ZQahUTUXD637UZ63ruS0K02BM6qN4LjUkFpCbA_w8v96Rl1vfzh92UOR5xUUHH9aZ2KoGKLi5C-louukA0zojnSYhk/s1600/ULN7.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO3snjokijQY1Q77MIkFuepyqkUSAkQk92goODWB1y2OL9kDs8d3ZQahUTUXD637UZ63ruS0K02BM6qN4LjUkFpCbA_w8v96Rl1vfzh92UOR5xUUHH9aZ2KoGKLi5C-louukA0zojnSYhk/s640/ULN7.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from the 7th Pin of the Arduino to the 1st Pin of the ULN2003 [the Input1 Pin]</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp6NhpmEL9BgMqNw6p-1CznrxfJuOtBNtkdTewhk_guT7356qMqGtkF6ZhDdCY_vH4XvkNro4UvqNg1u1tlOs-HQzF0mgg7wqpb2ptd7NI2y0qUKOdWb13nLLGiyTMRppyGBlVr1ZO1OoX/s1600/ULN8.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="504" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp6NhpmEL9BgMqNw6p-1CznrxfJuOtBNtkdTewhk_guT7356qMqGtkF6ZhDdCY_vH4XvkNro4UvqNg1u1tlOs-HQzF0mgg7wqpb2ptd7NI2y0qUKOdWb13nLLGiyTMRppyGBlVr1ZO1OoX/s640/ULN8.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Here's how your final set up would look like!</td></tr>
</tbody></table>
Try the following code. A simple program - call it an audio_blink ;) [ULN_Buzzer.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">ULN2003- Buzzer</span>
<span style="color: #7e7e7e;">This program drives a Buzzer using ULN2003 </span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
<span style="color: #cc6600;">pinMode</span>(7,<span style="color: #006699;">OUTPUT</span>);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;">delay</span>(2000);
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">LOW</span>);
<span style="color: #cc6600;">delay</span>(3000);
}
</pre>
</div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com2tag:blogger.com,1999:blog-9038718253168000072.post-66379483924733939722012-05-16T23:46:00.000-07:002012-05-16T23:46:08.032-07:00Simple Labs' Quick Start Kit for Arduino - Generating Sound - Buzzer + Transistor - How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Generating Sound - Buzzer + Transistor</b><br />
<br />
Next
lets see how we can generate sound using a Buzzer. The Buzzer would
require more current than provided by the pins of the arduino. To
provide the buzzer with more current, we shall use a transistor to
trigger the buzzer. The transistor in turn will be triggered by a pin on
the arduino. If you do not know about transistors, its advisable you
check it out <a href="http://en.wikipedia.org/wiki/Transistor" target="_blank"> http://en.wikipedia.org/wiki/Transistor</a><br />
<br />
Here's what our Transistor 2N2222A looks like<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6QlUVtOop8hEkwxyXkMXrRzFczMzLWVWRbsMhgzHu61hSJHXrztQLqXYP9ZAOGVIbJqEoAIySdY0advcmYeKX16lA3W7sdGD2BAW5H9VGMJcLR16GW7-z3CNi2YEPqX3E10q9NgZ3sWQ2/s1600/Tran1.jpg" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="388" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6QlUVtOop8hEkwxyXkMXrRzFczMzLWVWRbsMhgzHu61hSJHXrztQLqXYP9ZAOGVIbJqEoAIySdY0advcmYeKX16lA3W7sdGD2BAW5H9VGMJcLR16GW7-z3CNi2YEPqX3E10q9NgZ3sWQ2/s640/Tran1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">2N2222A</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5_rKgDa69VSKtYUsJn-vhu9hotqwFCRPXvHR65InzsDP0C35SlJR5Skdo3b4GHz5snoY4LaDNtaOQ-LKAz_9dPEQ7hbv4kuwAG-FOHjTcn76xhyhVmSJjDtJdlr2YyJK9sBfgD98hAIOY/s1600/2n2222A.gif" style="margin-left: auto; margin-right: auto;"><img border="0" height="311" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5_rKgDa69VSKtYUsJn-vhu9hotqwFCRPXvHR65InzsDP0C35SlJR5Skdo3b4GHz5snoY4LaDNtaOQ-LKAz_9dPEQ7hbv4kuwAG-FOHjTcn76xhyhVmSJjDtJdlr2YyJK9sBfgD98hAIOY/s400/2n2222A.gif" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Pin Mappings for 2N2222A</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: justify;">
E = Emitter</div>
<div class="separator" style="clear: both; text-align: justify;">
B = Base</div>
<div class="separator" style="clear: both; text-align: justify;">
C = Collector </div>
<div class="separator" style="clear: both; text-align: justify;">
The
Emitter of a transistor is connected to ground, the device to be
triggered is connected between the Collector of the transistor and
SUPPLY. The transistor can be triggered by Supplying a Trigger voltage
to the Base (preferably through a resistor). Depending upon the trigger
voltage, Emitter and Collector of a transistor get in contact thereby
allowing current flow through the device connected.</div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie1rZ-wpftem843tfZmdjagtSO7LjiKjtgNzBz7iwmaLC0TZWKA1t-CFa-PHMcMhAuCTmvKOQAYfTHum6p2ccycwD_1M9ivUyrqDNY5BJZdEAV1pyTkLqAqAUBUzpJobB_PJpE4zOD1RoP/s1600/Buzzer1.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="570" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie1rZ-wpftem843tfZmdjagtSO7LjiKjtgNzBz7iwmaLC0TZWKA1t-CFa-PHMcMhAuCTmvKOQAYfTHum6p2ccycwD_1M9ivUyrqDNY5BJZdEAV1pyTkLqAqAUBUzpJobB_PJpE4zOD1RoP/s640/Buzzer1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Buzzer - The Red Wire is Positive & The Blue Wire is Negative.<span class="Apple-style-span" style="font-size: small;"> </span></td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiahqMjv-27whoWUcCe5ixwjZIsfRra6jCWzsF1O7RUWWv_nYa1Fikq9R-8ToXntfeJdBbkMx3ulMafb3wWowFHMZWVcA4EmfReftMYtumfhQu94zbfYCFnN2V82fAjAYhx-9g41s9gobP_/s1600/Buzzer2.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="466" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiahqMjv-27whoWUcCe5ixwjZIsfRra6jCWzsF1O7RUWWv_nYa1Fikq9R-8ToXntfeJdBbkMx3ulMafb3wWowFHMZWVcA4EmfReftMYtumfhQu94zbfYCFnN2V82fAjAYhx-9g41s9gobP_/s640/Buzzer2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">First Setup the Transistor Side like in the Image</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnvW5l6SLAFBgdldMFZds2t69Gmv5unb1k4mhAB-8gn_Y5kf7M1FRYky4BlRbdke4xh8OUL98IdRbknhkx5cUmsog2NNmg4XBmPspAH_Yo7YK8KSerZwy_v75eRRebK8nn7wY85dxxU49x/s1600/Buzzer3.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="428" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnvW5l6SLAFBgdldMFZds2t69Gmv5unb1k4mhAB-8gn_Y5kf7M1FRYky4BlRbdke4xh8OUL98IdRbknhkx5cUmsog2NNmg4XBmPspAH_Yo7YK8KSerZwy_v75eRRebK8nn7wY85dxxU49x/s640/Buzzer3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Blue wire
going to the Collector here is the Negative of the Buzzer and the Red
wire (the Positive of the Buzzer ) is connected to the '+'ve terminal of
the Breadboard</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSlDDEt2Y4Pfp0iriFQlUTuR8qe7-4vKUVpztxSlN6sUPfInmpza12GkwhKgmYGoAWuhLzu32sUx32waHN9nQKwyN2jx3uDhPSPfe1XM40M__TbzKQLFjKk7vMYJ4Qsxn3WIkOoVuenqpC/s1600/Buzzer4.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="464" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSlDDEt2Y4Pfp0iriFQlUTuR8qe7-4vKUVpztxSlN6sUPfInmpza12GkwhKgmYGoAWuhLzu32sUx32waHN9nQKwyN2jx3uDhPSPfe1XM40M__TbzKQLFjKk7vMYJ4Qsxn3WIkOoVuenqpC/s640/Buzzer4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Now Connect a Wire from the Other end of the Resistor to the 7th pin (digital) of the Arduino </td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTT0mbXli1en6-ZdGiTwx9t8is8YrOWMkCfWSw9thE8w9jtYibwbtpY-1LVRAngCc1k5XETUvHZSDVhT_aKRj42YpJjIaGFVml_EKCaWKLLdZOjdp0aq6nn0kZfONZZCwT40CfwereSVVV/s1600/Buzzer5.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="376" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTT0mbXli1en6-ZdGiTwx9t8is8YrOWMkCfWSw9thE8w9jtYibwbtpY-1LVRAngCc1k5XETUvHZSDVhT_aKRj42YpJjIaGFVml_EKCaWKLLdZOjdp0aq6nn0kZfONZZCwT40CfwereSVVV/s640/Buzzer5.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Here is how the Final Setup Looks Like</td></tr>
</tbody></table>
Try the following code where the Buzzer stays on as
you keep pressing the Button in our previous program
[RGB_button_ldr_buzzer.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> Pressing the Button changes the current active color of the RGB LED & prints the current temperature value to the Serial Monitor and Generates a Buzzer tone </span>
<span style="color: #7e7e7e;"> for the duration the button is being pressed.</span>
<span style="color: #7e7e7e;"> The light intensity detected by the LDR determines the intensity level of the active color</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0, pin = 9;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;">pinMode</span>(2,<span style="color: #006699;">INPUT</span>);
<span style="color: #cc6600;">pinMode</span>(7,<span style="color: #006699;">OUTPUT</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0) <span style="color: #7e7e7e;">// Switch being pressed</span>
{
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Temperature is : "</span>);
<span style="color: #cc6600;">int</span> temp = <span style="color: #cc6600;">analogRead</span>(2)/2;
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(temp);
<span style="color: #cc6600;">if</span>(pin<11)
pin++;
<span style="color: #cc6600;">else</span>
pin=9;
<span style="color: #cc6600;">analogWrite</span>(9,0);
<span style="color: #cc6600;">analogWrite</span>(10,0);
<span style="color: #cc6600;">analogWrite</span>(11,0);
<span style="color: #cc6600;">while</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0);
<span style="color: #cc6600;">delay</span>(100);
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">LOW</span>);
}
intensity = <span style="color: #cc6600;">analogRead</span>(4)/4;
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(pin);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(intensity);
}
</pre>
</div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com2tag:blogger.com,1999:blog-9038718253168000072.post-14961795594311097142012-05-16T23:45:00.002-07:002012-08-22T05:28:21.309-07:00Simple Labs' Quick Start Kit for Arduino - Sensor Interfacing - LDR Simple Light Sensor- How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>LDR - Light Dependent Resistor - A Simple Light Sensor</b><br />
The
LDR is a variable resistor, whose resistance varies based on the light
incident upon it. More the light, less the resistance. Now the LDR
cannot be used directly. We would need to convert the change in
resistance of the ldr to change in voltage. We can achieve this by
constructing a potential divider using the ldr and a fixed resistor.
Then we can take the output of the potential divider and connect it to
an Analog In pin on the arduino.<br />
<br />
Follow the images below and connect the LDR<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdMtp82S95XR9PggZAVPx5N3a5Tj5t4WIR_enLSU7P25OFunBcVOuqLVAIHsA0ZvYnfMI0ojs06FJiA0lknK7KsHNILOAr4tqLupcI25xQki40e0lqrUlm-oaHb05y0DnZhikz1nNDLR06/s1600/LDR1.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="496" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdMtp82S95XR9PggZAVPx5N3a5Tj5t4WIR_enLSU7P25OFunBcVOuqLVAIHsA0ZvYnfMI0ojs06FJiA0lknK7KsHNILOAr4tqLupcI25xQki40e0lqrUlm-oaHb05y0DnZhikz1nNDLR06/s640/LDR1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">This is the LDR</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLpxiVqdN5YGgCBFvBOkjaJUP_wezXw-Yi_KZoyWsz5eoE1uRVcIKLtFsf9j7svAHACTiW5a6Dd2rFN0uZjm7AUk4RBZezy1yVBGG88b103mHgnm3Taq9Y1aUXgMRz2WAVOc-8CC7-rcCZ/s1600/LDR2.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLpxiVqdN5YGgCBFvBOkjaJUP_wezXw-Yi_KZoyWsz5eoE1uRVcIKLtFsf9j7svAHACTiW5a6Dd2rFN0uZjm7AUk4RBZezy1yVBGG88b103mHgnm3Taq9Y1aUXgMRz2WAVOc-8CC7-rcCZ/s640/LDR2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the LDR as shown and connect a resistor as shown</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhknR5IVuKmJm8edQfSdPVJ-GXmwGx0oy1Otut91LOf56m-iLsL4RBkP-RpDttiGlejBypq0xFLcU-8Aril8ObPE10P01sdbXzwvBgil0bfQhBOQ8JCKjcb6ICu-VIh-NFrliGcAcyiHIVE/s1600/LDR3.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="470" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhknR5IVuKmJm8edQfSdPVJ-GXmwGx0oy1Otut91LOf56m-iLsL4RBkP-RpDttiGlejBypq0xFLcU-8Aril8ObPE10P01sdbXzwvBgil0bfQhBOQ8JCKjcb6ICu-VIh-NFrliGcAcyiHIVE/s640/LDR3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect Supply
& Ground. Take a Wire from the Junction of the Resistor & LDR
and connect it to Analog In 4 of the Arduino</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_8VMw5wUlUVdu1oURMXSTsnb_qpBvkh4dM1lYdvedy3bJbL4km0msAjWHW1iBS1YFlX9vtRQZAtCtnykrRDHyb6Ui6JvfdRT6OhgfUYB-T51lADocaJu7mnmxj4iZ4IzBpEmtfsQcKBVw/s1600/LDR4.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="272" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_8VMw5wUlUVdu1oURMXSTsnb_qpBvkh4dM1lYdvedy3bJbL4km0msAjWHW1iBS1YFlX9vtRQZAtCtnykrRDHyb6Ui6JvfdRT6OhgfUYB-T51lADocaJu7mnmxj4iZ4IzBpEmtfsQcKBVw/s640/LDR4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Here is how the Finished Setup will look like</td></tr>
</tbody></table>
Try the following Code [RGB_button_ldr.ino]<br />
<pre><span style="color: #7e7e7e;">/* </span>
<span style="color: #7e7e7e;"> </span>
<span style="color: #7e7e7e;"> Pressing the Button changes the current active color of the RGB LED & prints the current temperature value to the Serial Monitor </span>
<span style="color: #7e7e7e;"> </span>
<span style="color: #7e7e7e;"> and the light intensity detected by the LDR determines the intensity level of the active color </span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0, pin = 9;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;">pinMode</span>(2,<span style="color: #006699;">INPUT</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0) <span style="color: #7e7e7e;">// Switch being pressed </span>
{
<span style="color: #cc6600;">int</span> temp = <span style="color: #cc6600;">analogRead</span>(2)/2;
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Temperature is : "</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(temp);
<span style="color: #cc6600;">analogWrite</span>(10,0);
<span style="color: #cc6600;">analogWrite</span>(9,0);
<span style="color: #cc6600;">analogWrite</span>(11,0);
<span style="color: #cc6600;">if</span>(pin<11)
pin++;
<span style="color: #cc6600;">else</span>
pin = 9;
intensity = <span style="color: #cc6600;">analogRead</span>(4)/4;
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(pin);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(intensity);
<span style="color: #cc6600;">while</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0);
<span style="color: #cc6600;">delay</span>(100);
}
}
</pre>
</div>
R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com3tag:blogger.com,1999:blog-9038718253168000072.post-27865219389164907722012-05-16T23:44:00.002-07:002012-05-16T23:44:12.933-07:00Simple Labs' Quick Start Kit for Arduino - Sensor Interfacing - LM35 Temperature Sensor- How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Working with Sensors - LM35</b><br />
<br />
So lets get
started with some sensors, LM35 is a simple temperature sensor. LM35 has
3 pins. Refer to the following image for the pin mappings<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFOx0RIPwpRmxg9wm5hYQAFj0vENHDfTbCeI_9aFP6fOff6GuPEzjWy5M0R5r-Fkt8-BvviAaT3L6YTulomvsmFL4DT8xihUbC4PM2M26eSAmsfajmMnOBfh2CNYFQGxwGCyhqV-oab0Ik/s1600/LM35_1.jpg" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="521" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFOx0RIPwpRmxg9wm5hYQAFj0vENHDfTbCeI_9aFP6fOff6GuPEzjWy5M0R5r-Fkt8-BvviAaT3L6YTulomvsmFL4DT8xihUbC4PM2M26eSAmsfajmMnOBfh2CNYFQGxwGCyhqV-oab0Ik/s640/LM35_1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">This is the LM35 as it looks</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiF9puuLfNrASUxFL2vBavJ0-YcWlrfK14O-NsGVOiWehHfNGV6cfyb0_4sBj7OHZBIzwpzh_WmgM6ZJN6MDZBdpym_apLW6M8-sExE_cc1Gff19eIHz_GSL6C_YHINokpTbRrG2Wu-wDB0/s1600/LM35_0.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiF9puuLfNrASUxFL2vBavJ0-YcWlrfK14O-NsGVOiWehHfNGV6cfyb0_4sBj7OHZBIzwpzh_WmgM6ZJN6MDZBdpym_apLW6M8-sExE_cc1Gff19eIHz_GSL6C_YHINokpTbRrG2Wu-wDB0/s400/LM35_0.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The LM35 pin Mapping. Note: The image on the left is a BOTTON view. This is how you will find it in the Product Datasheet<span class="Apple-style-span" style="font-size: small;"> </span></td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNCP2rJLxkYaV4vpxaDUHZV25XMFuWTyF48TppEg9e8olDsSN2txmjdYz8pEYDifOSbMv6Fmh68C5YdM4S7TWZX_ZXJ4zHBR05AA7h6uba-6SNaCTBQH5XFdGPaylkEEv6-mKhbJ6BJVuq/s1600/LM35_2.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="444" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNCP2rJLxkYaV4vpxaDUHZV25XMFuWTyF48TppEg9e8olDsSN2txmjdYz8pEYDifOSbMv6Fmh68C5YdM4S7TWZX_ZXJ4zHBR05AA7h6uba-6SNaCTBQH5XFdGPaylkEEv6-mKhbJ6BJVuq/s640/LM35_2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the LM35 as shown</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvzrLc4f653QrioY3zSFEqqPb3ZHJAmEdWEWrpN2ky7IwTs5ailIA_ewCLgHByAz5RieblALj0J8jyY_Ap7DHN6C8UQKHJpJv_NQtWenyaPMK_vVJwZs6fh760DnqE8XfJwmCBr8R8Fvi2/s1600/LM35_3.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="414" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvzrLc4f653QrioY3zSFEqqPb3ZHJAmEdWEWrpN2ky7IwTs5ailIA_ewCLgHByAz5RieblALj0J8jyY_Ap7DHN6C8UQKHJpJv_NQtWenyaPMK_vVJwZs6fh760DnqE8XfJwmCBr8R8Fvi2/s640/LM35_3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect Wires to Supply & Ground. Take a wire from the middle pin and connect it to Analog In 2 of the Arduino</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><img border="0" height="332" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLN_nei4M5ZHgA08enTYR1VFsPP5F2SdwR86W0-6uW3XLB06-DY6YrkFGx5jxKeOBqvd0HtftaQ3VTGJGBSOAB8A8uFBrMTU6APq8h-zPbqwsRmvIBg9fFVlWwjKTfWKDKh8aGqVWbE9mp/s640/LM35_4.jpg" style="margin-left: auto; margin-right: auto;" width="640" /></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Heres the finished Setup</td></tr>
</tbody></table>
Now
time for the program. Try the following program. Pressing the Button
changes the current active color of the RGB LED & prints the current
temperature value to the Serial Monitor and varying the trimpot changes
the intensity of the color [RGB_button_lm35.ino]<br />
<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> Pressing the Button changes the current active color of the RGB LED & prints the current temperature value to the Serial Monitor</span>
<span style="color: #7e7e7e;"> and varying the trimpot changes the intensity of the color</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0, pin = 9;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;">pinMode</span>(2,<span style="color: #006699;">INPUT</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0) <span style="color: #7e7e7e;">// Switch being pressed</span>
{
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Temperature is : "</span>);
<span style="color: #cc6600;">int</span> temp = <span style="color: #cc6600;">analogRead</span>(2)/2;
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(temp);
<span style="color: #cc6600;">if</span>(pin<11)
pin++;
<span style="color: #cc6600;">else</span>
pin=9;
<span style="color: #cc6600;">analogWrite</span>(9,0);
<span style="color: #cc6600;">analogWrite</span>(10,0);
<span style="color: #cc6600;">analogWrite</span>(11,0);
<span style="color: #cc6600;">while</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0);
<span style="color: #cc6600;">delay</span>(100);
}
intensity = <span style="color: #cc6600;">analogRead</span>(0)/4;
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(pin);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(intensity);
}
</pre>
</div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com5tag:blogger.com,1999:blog-9038718253168000072.post-66213139697468096802012-05-16T23:43:00.000-07:002012-05-16T23:43:15.375-07:00Simple Labs' Quick Start Kit for Arduino - Trimpot / Potentiometer Interfacing - How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Trimpot</b><br />
Trimpots are used for getting variable /
adjustable user inputs. Common example of a trimpot is the volume knob
of your stereo player, Tuning knob of the radio, etc.<br />
<br />
A
Trimpot aka variable resistor has three pins and an adjustment screw. A
Trimpot acts as a potential divider and gives an output voltage on the
2nd pin. This output voltage is in-between the voltages supplied to the
1st and 3rd pins. The output voltage can be varied by adjusting the
screw. The 1st and 3rd pins are connected to SUPPLY / GROUND and the
middle pin is connected to Analog Input 0 on the arduino using a wire.<br />
<br />
Connect the trimpot as shown in the images below<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSL2dRvKkUmNshMQSq8TzaUKG5QM8MmlVkwLbibK7bCtL7JLRJcL4TYaOYNkltUolDJJSn2NZb2Knt6ZMM7K6vjl3WNTIkeFhYg90WLpwzwOsTg5yNGRM7Rlif3sci3yzDKNLOEJPyPGMu/s1600/trimpot1.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSL2dRvKkUmNshMQSq8TzaUKG5QM8MmlVkwLbibK7bCtL7JLRJcL4TYaOYNkltUolDJJSn2NZb2Knt6ZMM7K6vjl3WNTIkeFhYg90WLpwzwOsTg5yNGRM7Rlif3sci3yzDKNLOEJPyPGMu/s400/trimpot1.jpg" width="361" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Trimpot - See the markings for pins</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghBkLYkiGHjszf5oesmuMd3Xhq-TT8zgobCKcseFyTVvMscqvTBw6eT1aRXMK5Qgxz8AhNzjclttRoObtKVhKxuk1WwUMfkNhqgjGjSoUnePrFspLXo6DxClu6JYbA_smO-TBX-D0Py4zl/s1600/trimpot2.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="434" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghBkLYkiGHjszf5oesmuMd3Xhq-TT8zgobCKcseFyTVvMscqvTBw6eT1aRXMK5Qgxz8AhNzjclttRoObtKVhKxuk1WwUMfkNhqgjGjSoUnePrFspLXo6DxClu6JYbA_smO-TBX-D0Py4zl/s640/trimpot2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the trimpot as shown</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9HMw-F5-nb6U2Cp9mjTjZCVG_LZSjBscSzWGmRc2pjaZ9U3Db6LXacaW8JOTerywlvCT_qpWDU1HP3o-YS0lEKU-xfq08MfaaCD8lJX2vNm_RdCjFiSTih5DjGGf0eIPp7RFDLo32rMW2/s1600/trimpot3.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9HMw-F5-nb6U2Cp9mjTjZCVG_LZSjBscSzWGmRc2pjaZ9U3Db6LXacaW8JOTerywlvCT_qpWDU1HP3o-YS0lEKU-xfq08MfaaCD8lJX2vNm_RdCjFiSTih5DjGGf0eIPp7RFDLo32rMW2/s640/trimpot3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between pin 1 of the trimpot and the '+'ve terminal</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr0LaXRs2LCzWFG1pbsGVhm25D-AdDwQQWEZWai9wW64rnxKl9gxx1k7b20HPaWNalsKNFDY9uOBq0j952IluhbbNnWwIlVwv7aQDO5xui2bpyor2UgkWtBf-OTrNqhFtyisAC-KlJE3S2/s1600/trimpot4.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="336" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr0LaXRs2LCzWFG1pbsGVhm25D-AdDwQQWEZWai9wW64rnxKl9gxx1k7b20HPaWNalsKNFDY9uOBq0j952IluhbbNnWwIlVwv7aQDO5xui2bpyor2UgkWtBf-OTrNqhFtyisAC-KlJE3S2/s640/trimpot4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between pin 3 of the trimpot and the '-'ve terminal</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlNI0OS4gaXivIFQce4T-WjCcSKlXg5tXGbt9K54yzMQax7WN_35M0whwodtkgoQ2vjvXcJWkhKnDwcXb0k6In1UPpjegJdwg_LyayrMGE7Fd6Czd6xdJxWvAiHumbK30-OVnTc37VjrCl/s1600/trimpot5.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlNI0OS4gaXivIFQce4T-WjCcSKlXg5tXGbt9K54yzMQax7WN_35M0whwodtkgoQ2vjvXcJWkhKnDwcXb0k6In1UPpjegJdwg_LyayrMGE7Fd6Czd6xdJxWvAiHumbK30-OVnTc37VjrCl/s640/trimpot5.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between pin 2 of the trimpot and the Analog In 0 of the Arduino</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHsvqr5e0gDlOyp7A81VvVwvKfpest2Ccdrt5D6hyphenhyphen9tZ75_e6vgwE1fv_jh9LlBDakZ3Seo8Ei9b1gdsB6xGv2oTQI2I5WyRW4Eo98ndut4CZ7xEytc5afeID9XFV5ZbaUeligWZ7Ihaur/s1600/trimpot6.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="408" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHsvqr5e0gDlOyp7A81VvVwvKfpest2Ccdrt5D6hyphenhyphen9tZ75_e6vgwE1fv_jh9LlBDakZ3Seo8Ei9b1gdsB6xGv2oTQI2I5WyRW4Eo98ndut4CZ7xEytc5afeID9XFV5ZbaUeligWZ7Ihaur/s640/trimpot6.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Here is the connection going to the Analog In 0</td></tr>
</tbody></table>
The Analog Input pins on the Arduino let you connect
sensors and other analog devices like trimpots that product a voltage
output in the range of 0-5 volts. The Analog input on Arduino is of
10-bit resolution. 10-bit
resolution means that the Voltage range of 0-5 Volts is represented in
1024 steps from 0-1023. So you would be reading an input value in the
range of 0-1023 where 1023 would correspond to 5 Volts<br />
<br />
Arduino[the
IDE!] comes with a serial library
that can be used to transmit data serially to a computer. We shall make
use of this library to transmit our trimpot value to a Computer every 1
second. You can open the 'Serial Monitor' in the Arduino IDE to view
these values. You can open the 'Serial Monitor' by going to the 'Tools'
menu. When using the 'Serial Monitor' ensure that the baud rate selected
is the same as the one used in the program.<br />
<br />
Try the following program and see the values you get by varying the trimpot [ simple_trimpot.ino]<br />
<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> A Simple Program to display the value read from the trimpot onto the Serial Monitor</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
intensity = <span style="color: #cc6600;">analogRead</span>(0);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Current Value:"</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(intensity);
}
</pre>
If you notice, you will see values from 0-1023. Now
we are going to use the trimpot as part of our previous experiment. We
will use the button to select the active color of the RGB LED and then
use the trimpot to set the intensity of that color. Remember that this
would involve scaling 0-1023 to 0-255 (or divide by 4!)<br />
<br />
Try the following program [RGB_button_trimpot.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> Pressing the Button changes the current active color of the RGB LED and varying the trimpot changes the intensity of the color</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0, pin = 9;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;">pinMode</span>(2,<span style="color: #006699;">INPUT</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0) <span style="color: #7e7e7e;">// Switch being pressed</span>
{
<span style="color: #cc6600;">if</span>(pin<11)
pin++;
<span style="color: #cc6600;">else</span>
pin=9;
<span style="color: #cc6600;">analogWrite</span>(9,0);
<span style="color: #cc6600;">analogWrite</span>(10,0);
<span style="color: #cc6600;">analogWrite</span>(11,0);
<span style="color: #cc6600;">while</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0);
<span style="color: #cc6600;">delay</span>(100);
}
intensity = <span style="color: #cc6600;">analogRead</span>(0)/4; <span style="color: #7e7e7e;">// Scaling the input resolution to match with our output resolution.</span>
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(pin);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(intensity);
}
</pre>
Heres the final setup and the output!<br />
<br />
<div class="separator" style="clear: both; text-align: justify;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUFCi3jy2Cewd4JO5VEwmHnaqQ45BD84anNScQ1jKi9xpHaCWnKfzjmIXzi2bFPdCHCX29JaHV4hQBjogRXV8pj6d8wxG1KLZ4xJAM4SiQe9WsdDuyhTTCO8m0w47fCjaAvF5PojuirWDR/s1600/trimpot7.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="628" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUFCi3jy2Cewd4JO5VEwmHnaqQ45BD84anNScQ1jKi9xpHaCWnKfzjmIXzi2bFPdCHCX29JaHV4hQBjogRXV8pj6d8wxG1KLZ4xJAM4SiQe9WsdDuyhTTCO8m0w47fCjaAvF5PojuirWDR/s640/trimpot7.jpg" width="640" /></a></div>
<br /></div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com0tag:blogger.com,1999:blog-9038718253168000072.post-72083124828475745102012-05-16T23:41:00.003-07:002012-05-16T23:41:56.554-07:00Simple Labs' Quick Start Kit for Arduino - Push Button / Switch Interfacing - How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>The Push Button</b><br />
Push Buttons like LEDs form a common
part of most electronics devices. Push buttons can be used to get user
feedback. (image a common scenario of scrolling through a menu and
selecting an option - there are buttons all around the process!)<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikq-YBfMjFSXJX8LNSOSOTxDcstCmlJPOYVSTir0EFM_oTkXi5WU-3NJC43TsApnbc_ZakqR0MSRrD_NFQa-EFfb3yTkmR6K31IY7pqvTaWUOp3cbH1I-r0oAw125xrNoQ0Xa9zBoIsjzZ/s1600/Button1.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikq-YBfMjFSXJX8LNSOSOTxDcstCmlJPOYVSTir0EFM_oTkXi5WU-3NJC43TsApnbc_ZakqR0MSRrD_NFQa-EFfb3yTkmR6K31IY7pqvTaWUOp3cbH1I-r0oAw125xrNoQ0Xa9zBoIsjzZ/s640/Button1.jpg" width="540" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Working of a Push Button</td></tr>
</tbody></table>
<br />
So Far we have not used the SUPPLY voltage
from the Arduino however, for connecting the button, we would need
this. So, before connecting the Button, we need to connect our '+'ve
terminal to the 5Volts SUPPLY line on the Arduino. Connect as shown in
the image below.<br />
<br />
<div class="separator" style="clear: both; text-align: justify;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm7Wov3yiyThv7eCgGvguwPOM9Lvt5ePkfn_sH5PUd1_koC6In21ynU1rmcxMwqeBKtI7t0uFpjba9wGS9DLJWJj4Vyfey2DsBh0FgXtULEEEcPbJRnAjODaaLA33tNKKk_K4mBFBpgucP/s1600/power1.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="290" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm7Wov3yiyThv7eCgGvguwPOM9Lvt5ePkfn_sH5PUd1_koC6In21ynU1rmcxMwqeBKtI7t0uFpjba9wGS9DLJWJj4Vyfey2DsBh0FgXtULEEEcPbJRnAjODaaLA33tNKKk_K4mBFBpgucP/s640/power1.jpg" width="640" /></a></div>
<br />
There
are 2 ways to connect a Push Button to the arduino - the Pull-Down
Configuration & the Pull-Up Configuration. We will take a look at
both these.<br />
<br />
<b>The Pull-Down Cnfiguration</b><br />
In
this configuration the Push Button is set-up such that it keeps giving a
constant LOW signal(0) when not being pressed and gives a HIGH
signal(1) when being pressed. To ensure that it keeps giving a LOW
signal at all times, the Input line is also connect to the '-'ve
terminal through a resistor. So in when the button is not being pressed,
the input line stays connected to the GROUND. When the button is being
pressed (and as the path of low resistance is always preferred) the
input line gets connected to the SUPPLY line. Look at the following
image to see how to connect a button in this configuration. We will keep
this connection only as a reference as we will be using the Pull-Up
configuration for our circuits.<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQJOBr05M-zygjM0klJw6Ts2SCCeCG7p9I5GAqXXn8Bo1_qGfqSR9KmuFcLJdMr3rdMamyqn1fHRjEQlN-xk7jLakCwfyFDCyhpE9moBdxbg4TlOyVXp-o7e6VD4cSRz-LSNMHsDzin19a/s1600/Button2.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="618" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQJOBr05M-zygjM0klJw6Ts2SCCeCG7p9I5GAqXXn8Bo1_qGfqSR9KmuFcLJdMr3rdMamyqn1fHRjEQlN-xk7jLakCwfyFDCyhpE9moBdxbg4TlOyVXp-o7e6VD4cSRz-LSNMHsDzin19a/s640/Button2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>The Pull-Down Configuration</b></td></tr>
</tbody></table>
<b>The Pull-UP Cnfiguration</b><br />
In this
configuration the Push
Button is set-up such that it keeps giving a constant HIGH signal(1)
when
not being pressed and gives a LOW signal(0) when being pressed. To
ensure that it keeps giving a HIGH signal at all times, the Input line
is
also connect to the '+'ve terminal through a resistor. So in when the
button is not being pressed, the input line stays connected to the
SUPPLY . When the button is being pressed (and as the path of low
resistance is always preferred) the input line gets connected to the
GROUND line. Look at the following image to see how to connect a button
in this configuration. This is the most preferred method to connect a
button.<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjIDy40YNHkS0Em4vaM2KeB5-JwxcAaAXLCsXvA-o8M7i8boyKN13ap7o3jU5q5_EwfBU9y7XpyQ6JGncZxV8DqRwuqiUqZ_bZ3nGXKyvsZeRvgvwlPcTxGzkDXm0pwIjw9e_odJR44sMH/s1600/Button3.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="418" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjIDy40YNHkS0Em4vaM2KeB5-JwxcAaAXLCsXvA-o8M7i8boyKN13ap7o3jU5q5_EwfBU9y7XpyQ6JGncZxV8DqRwuqiUqZ_bZ3nGXKyvsZeRvgvwlPcTxGzkDXm0pwIjw9e_odJR44sMH/s640/Button3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>The Pull-Up Configuration</b></td><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
Now try the following code, Pressing the Button
increases the intensity of one colour at a time, once the maximum
intensity of the colour is reached that colour is set to 0 and the
intensity of the next colour starts increasing [ RGB_Button.ino]<br />
<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> RGB_Button</span>
<span style="color: #7e7e7e;"> Pressing the Button increases the intensity of one colour at a time, once the maximum intensity of the colour is reached</span>
<span style="color: #7e7e7e;"> that colour is set to 0 and the intensity of the next colour starts increasing</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0, pin = 9;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;">pinMode</span>(2,<span style="color: #006699;">INPUT</span>); <span style="color: #7e7e7e;">// This is the pin to which we have connected the button</span>
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0) <span style="color: #7e7e7e;">// check if the button is being pressed</span>
{
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(<span style="color: #006699;">"here"</span>);
<span style="color: #cc6600;">if</span>(intensity < 255)
{
intensity++;
}
<span style="color: #cc6600;">else</span>
{
intensity=0;
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
<span style="color: #cc6600;">if</span>(pin<11)
pin++;
<span style="color: #cc6600;">else</span>
pin=9;
}
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
}
}
</pre>
Here's the Output<br />
<br />
<div class="separator" style="clear: both; text-align: justify;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrFDwygqslEFksUtat-TS86GKjYT3Db8rT19i4XyVrZuqWyb5EG2dQGUdU0zVwFbw3VpX65ZVMed0MT4KwAhrR4PCGmdyQHy8S9YWrwzTtExEmheXmUdysl1s50iHtA6hd6oxkb3ho2gHc/s1600/Button4.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="448" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrFDwygqslEFksUtat-TS86GKjYT3Db8rT19i4XyVrZuqWyb5EG2dQGUdU0zVwFbw3VpX65ZVMed0MT4KwAhrR4PCGmdyQHy8S9YWrwzTtExEmheXmUdysl1s50iHtA6hd6oxkb3ho2gHc/s640/Button4.jpg" width="640" /></a></div>
<u><br /></u></div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com0tag:blogger.com,1999:blog-9038718253168000072.post-16747433569545695442012-05-16T23:40:00.000-07:002012-05-16T23:40:06.214-07:00Simple Labs' Quick Start Kit for Arduino - RGB LED Interfacing - How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b>The RGB LED</b><br />
<br />
The RGB led aka the tricolor led
is a led that can help generate a multitude of colors by mixing red,
blue & green colors. Its more like 3 leds (red, green & blue)
put together into a single led.<br />
<br />
It has 4 pins with 1 of
the pins being a common cathode and the other 3 pins acting as anodes
for the 3 different colours. by varying the intensity of each of the 3
colours individually, we can generate various colours. This led is the
same as 1 pixel of a LED TV!.<br />
<br />
Here is how to wire it up<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu0HFCv7mRN8ah1KPAyyQ1iBGtBzlL8mSvZgP_9XgD3XfotFo19V-Gjdo_Ag0xv57r0K92V_HneuSmmcZPEfAhW3SLcn3S2e7SEs3Xa7-8yM2QA0SE89NA84hfdg7PB6Sc9QlI73Qzgjee/s1600/RGB1.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu0HFCv7mRN8ah1KPAyyQ1iBGtBzlL8mSvZgP_9XgD3XfotFo19V-Gjdo_Ag0xv57r0K92V_HneuSmmcZPEfAhW3SLcn3S2e7SEs3Xa7-8yM2QA0SE89NA84hfdg7PB6Sc9QlI73Qzgjee/s400/RGB1.jpg" width="233" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Pin Mappings of the RGB LED</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsi7qb0Og8HuaRAhwiU_lH05zox2aM5iwOSWYcIWkL7lTqQdGEhpE5hddgfoD269NOhlO3SElH10MCiDZFEggsGYtrbDGCe0m2ZKAb5DSCRODNVAJHhdmUtbq45BCasThc-2o5oiXKsmi3/s1600/RGB2.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsi7qb0Og8HuaRAhwiU_lH05zox2aM5iwOSWYcIWkL7lTqQdGEhpE5hddgfoD269NOhlO3SElH10MCiDZFEggsGYtrbDGCe0m2ZKAb5DSCRODNVAJHhdmUtbq45BCasThc-2o5oiXKsmi3/s640/RGB2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place resistor between the common cathode and the '-'ve terminal</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZbrxdlqbCCwXMpM6ad2sXJZaPey1ahivnWJ3e_oW7Mz9V_7SHlRJrbRmNCRzbw-zIEzRh2rcLFrCEH-jXbX6i_jF9-Lk-7ym5vpLlBJ-R38HT42e7wwvFpmaSRoPzaTdy0s9rK7gWn6Oe/s1600/RGB3.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZbrxdlqbCCwXMpM6ad2sXJZaPey1ahivnWJ3e_oW7Mz9V_7SHlRJrbRmNCRzbw-zIEzRh2rcLFrCEH-jXbX6i_jF9-Lk-7ym5vpLlBJ-R38HT42e7wwvFpmaSRoPzaTdy0s9rK7gWn6Oe/s640/RGB3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect RED to Pin 11, Blue to Pin 10 & Green to Pin 9 on the Arduino (these are PWM pins)</td></tr>
</tbody></table>
Now try the following code first. This code is a normal digital control of all the three colors separately.[RGB_Blink.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> RGB_Blink</span>
<span style="color: #7e7e7e;"> Turns on each of the color spectrums for 4 seconds, repeatedly.</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #7e7e7e;">// initialize the digital pins as an output.</span>
<span style="color: #cc6600;">pinMode</span>(11, <span style="color: #006699;">OUTPUT</span>);
<span style="color: #cc6600;">pinMode</span>(10, <span style="color: #006699;">OUTPUT</span>);
<span style="color: #cc6600;">pinMode</span>(9, <span style="color: #006699;">OUTPUT</span>);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">digitalWrite</span>(9,<span style="color: #006699;">LOW</span>);
<span style="color: #cc6600;">digitalWrite</span>(11, <span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;">delay</span>(4000);
<span style="color: #cc6600;">digitalWrite</span>(11, <span style="color: #006699;">LOW</span>);
<span style="color: #cc6600;">digitalWrite</span>(10, <span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;">delay</span>(4000);
<span style="color: #cc6600;">digitalWrite</span>(10, <span style="color: #006699;">LOW</span>);
<span style="color: #cc6600;">digitalWrite</span>(9, <span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;">delay</span>(4000);
}
</pre>
<br />
Next Lets get generating Colors, try the following code. Play around with the values and get yourselves comfortable.[RGB.ino]<br />
<pre><span style="color: #7e7e7e;">/* RGB</span>
<span style="color: #7e7e7e;"> Sets some random intensity value to the various colours of the RGB LED</span>
<span style="color: #7e7e7e;"> </span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
<span style="color: #cc6600;">analogWrite</span>(11,153);<span style="color: #7e7e7e;">// Setting the voltage for Blue to around 3 Volts </span>
<span style="color: #cc6600;">analogWrite</span>(10,51);<span style="color: #7e7e7e;">// Setting the voltage for Red to around 1 Volt </span>
<span style="color: #cc6600;">analogWrite</span>(9,51);<span style="color: #7e7e7e;">// Setting the voltage for Green to around 1 Volt </span>
}
</pre>
</div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com5tag:blogger.com,1999:blog-9038718253168000072.post-15998393948360058352012-05-16T23:35:00.003-07:002012-05-16T23:35:51.812-07:00Simple Labs' Quick Start Kit for Arduino - LED Interfacing - How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<b style="text-align: justify;">The world of LEDS</b><br />
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
<br /></div>
</div>
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
LEDs (Light Emitting Diodes) are the
most commonly used of electronic components. They are everywhere –
torches, displays, indicators, etc. Every project will eventually end
up having atleast one led. The Official Arduino Boards and most of
the Clones do come with an on-board LED which you can try with the
default blink program found in the File->Examples->Basic menu
of Arduino IDE.</div>
</div>
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
<br /></div>
</div>
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
<b>So How to Connect a LED?</b></div>
</div>
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The Long of the LED is the Anode (Positive Terminal!) and the short led is the Cathode(Negative Terminal). </div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ9FQV_KsdLPDQOt9EI1NKG_aZzDdQhmgPl1UNENI0yHk_vUfvzx652juE8RlZHp92hjmav55rxVu0uv5WsvGT_PTKbwniHftg62eYcz0izJHxfhboDTkPpQDZcfTI33UP81WFa4EiHyk9/s1600/LED1.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="553" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ9FQV_KsdLPDQOt9EI1NKG_aZzDdQhmgPl1UNENI0yHk_vUfvzx652juE8RlZHp92hjmav55rxVu0uv5WsvGT_PTKbwniHftg62eYcz0izJHxfhboDTkPpQDZcfTI33UP81WFa4EiHyk9/s640/LED1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Terminals of the LED</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQebzZAo9QJHhiuQShgs5TlIbVF95SFiOXHEm3u1kwRk0FC2Ghu7vp8aGTO5RvDeP3LrPjuefR_yZBJq9cqm358irfeoy_ObuxsglMssLaeMTnpXOrSxgu3jG8yIbF-Heri-MsQ8pRkv9z/s1600/LED2.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="436" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQebzZAo9QJHhiuQShgs5TlIbVF95SFiOXHEm3u1kwRk0FC2Ghu7vp8aGTO5RvDeP3LrPjuefR_yZBJq9cqm358irfeoy_ObuxsglMssLaeMTnpXOrSxgu3jG8yIbF-Heri-MsQ8pRkv9z/s640/LED2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the LED as shown</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVNwFxlnsQJc7fa6OfextAdKN2GqeMlX-VM801LMWrlCpTwGO-MVke50hmzttCONiCHRxZJ4gLBqzwTgfAqFsJcPget0aZxForFqRNKQ-QgENXDruWPgM8q6A9M8MLQWFJYbvNnqolTc2-/s1600/LED3.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="542" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVNwFxlnsQJc7fa6OfextAdKN2GqeMlX-VM801LMWrlCpTwGO-MVke50hmzttCONiCHRxZJ4gLBqzwTgfAqFsJcPget0aZxForFqRNKQ-QgENXDruWPgM8q6A9M8MLQWFJYbvNnqolTc2-/s640/LED3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place a
Current Limiting Resistor (too much current passing through an LED can
burn it!) between the negative terminal of the LED and the '-'ve
terminal on the power rail (we will soon connect this to the '-'ve (aka
ground) of our Arduino Board!)</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ahCx-dSWiGQjJr2GvThbMjVZSVI_YveLuJ0Cy30lDcU71eWZFKbsnuieb4DxrSyW-AsKsRUSQuDDuadSrPtJm4SKQYZ3DuA7Ws2Xk6N_1VvGfF5SNz6glbkPUEInlA-FG0AtR_KVCkdl/s1600/LED4.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ahCx-dSWiGQjJr2GvThbMjVZSVI_YveLuJ0Cy30lDcU71eWZFKbsnuieb4DxrSyW-AsKsRUSQuDDuadSrPtJm4SKQYZ3DuA7Ws2Xk6N_1VvGfF5SNz6glbkPUEInlA-FG0AtR_KVCkdl/s640/LED4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Take a wire
from the pin marked 'GND' of your arduino and connect it to the '-'ve
power rail of the breadboard. Now all points of the '-' ve power rail
will be connected to the ground of the arduino!</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsJnHdP97QPBhRP03UNHeaXxC_B09BBU0UY1YLiKth3OBXZ92zpMWUltnXLU51ngLyc_GaJLIN5XhApV5t_j_FtjnvXgtXXix0GL6T_s3A8FVGejOS_GMN3Oqsx5kHYMv7-mgLKeM0w24H/s1600/LED5.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsJnHdP97QPBhRP03UNHeaXxC_B09BBU0UY1YLiKth3OBXZ92zpMWUltnXLU51ngLyc_GaJLIN5XhApV5t_j_FtjnvXgtXXix0GL6T_s3A8FVGejOS_GMN3Oqsx5kHYMv7-mgLKeM0w24H/s640/LED5.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Next, Connect a
wire between the 11th pin of the arduino(yes the 11th pin and not the
13th pin!) and the positive terminal of the LED. This is going to be
our control line for the LED</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: justify;">
<b>Programming to control the LED</b></div>
</div>
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
So
how can you control a LED? Well there are only 2 ways to control an
LED. you can either switch it ON / OFF or you can control the intensity
with which it glows (Very much like a fan!). So lets see how to do the
first control - ON/OFF (we can call this digital control! Very much 0s
& 1s)</div>
</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Try the following code. [Blink.ino]<br />
<pre> <span style="color: #7e7e7e;">/* </span>
<span style="color: #7e7e7e;"> Blink </span>
<span style="color: #7e7e7e;"> Turns on an LED on for one second, then off for one second, repeatedly. </span>
<span style="color: #7e7e7e;"> This example code is in the public domain. </span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #7e7e7e;">// initialize the digital pin as an output. </span>
<span style="color: #7e7e7e;">// We have our LED connected to Pin 11 </span>
<span style="color: #cc6600;">pinMode</span>(11, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7e7e7e;">// Sets the 11th pin as an Output pin</span>
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">digitalWrite</span>(11, <span style="color: #006699;">HIGH</span>); <span style="color: #7e7e7e;">// set the LED on </span>
<span style="color: #cc6600;">delay</span>(1000); <span style="color: #7e7e7e;">// wait for a second </span>
<span style="color: #cc6600;">digitalWrite</span>(11, <span style="color: #006699;">LOW</span>); <span style="color: #7e7e7e;">// set the LED off </span>
<span style="color: #cc6600;">delay</span>(1000); <span style="color: #7e7e7e;">// wait for a second </span>
}
</pre>
Next, Lets see how to control the intensity of the LED.</div>
<br />
The
Intensity can be varied by controlling the voltage applied to the
individual pins. If you take a look at the 11th PIN on the arduino, you
would see a marking 'PWM' next to it (Remember we connected our LED to
the 11th pin).
The PWM pins in addition to generating digital HIGH / LOW signals can
generate analog voltages between 0 & 5.<br />
<br />
The PWM Pins
[Pins 3,5,6,9,10,11] that can generate a PWM signal of 8-bit
resolution.[8-bits can represent a maximum value of 255, and a 8-bit
resolution here means that 5 volts is represented by 255 divisions. So
if you want to generate 1 volt, you would use the value 51]<br />
<br />
The analogWrite function will take a 8-bit numerical value as a
parameter [called duty cycle] and produce an output voltage
corresponding to this value. It will set the pin to generate a steady
square wave of the specified duty cycle at roughly 490Hz frequency.<br />
<br />
Finally, when using a pin in the PWM mode, we don't have to use the pinMode() function.<br />
<br />
Try the following code with the same setup and see how the intensity increases and decreases...[Intensity.ino]<br />
<pre> <span style="color: #7e7e7e;">/* </span>
<span style="color: #7e7e7e;"> Intensity </span>
<span style="color: #7e7e7e;"> Increases the Intensity of a LED from 0 to maximum and on reaching maximum</span>
<span style="color: #7e7e7e;"> starts decreasing back to 0</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">while</span>(intensity < 255) <span style="color: #7e7e7e;">// Check if intensity has reached maximum value, if yes then exit the loop</span>
{
<span style="color: #cc6600;">analogWrite</span>(11,intensity);
<span style="color: #cc6600;">delay</span>(25);
intensity++;
}
<span style="color: #cc6600;">while</span>(intensity > 0) <span style="color: #7e7e7e;">// Check if intensity has reached minimum value, if yes then exit the loop</span>
{
<span style="color: #cc6600;">analogWrite</span>(11,intensity);
<span style="color: #cc6600;">delay</span>(25);
intensity--;
}
}
</pre>
</div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com8tag:blogger.com,1999:blog-9038718253168000072.post-85710195111820547142012-05-16T23:34:00.000-07:002012-05-16T23:34:00.169-07:00Simple Labs' Quick Start Kit for Arduino - Basic Breadboard Setup How To?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<b>The Breadboard</b></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The
Breadboard is a simple construction base for building circuits without
soldering. you can plug in different components and plug in wires
between them. The top two rails and the bottom two rails are called the
power rails and these are marked with a '+' and '-' symbol. These are
connected as rows. Each row of connection consists of 5 groups of 5
points each per group. There is no connection between the 5th and the
6th group so the points is group 1 to 5 are connected and the points in
group 6-10 are connected. we can connect a wire between any 2 two points
of these groups and get them all connected. [This could be confusing if
you have never used a breadboard before, we will try and make it easier
soon!] </div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
We
would need to get all our '+' lines connected to each other and then do
the same for the '-' lines. This will make it easy for us to connect
various components. Its a good practice stick to color coding for wires.
Use red colored wires whenever you connect something to '+' ve, black<span class="Apple-style-span" style="text-align: left;"> colored wires whenever you connect something to '-' ve and blue colored wires whenever you are connecting between components.</span></div>
<div style="text-align: justify;">
<div style="text-align: justify;">
<span class="Apple-style-span" style="text-align: left;"><br /></span></div>
</div>
<div style="text-align: justify;">
<div style="text-align: justify;">
<span class="Apple-style-span" style="text-align: left;">So first set up the breadboard as in the following images</span></div>
</div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: justify;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXq2LesBfgH1n4joeZhd9ZuzLXhCfY-19cTOFhSPVnrSwR2blbKUpA8uA_af-FnSX93ElXJB9BT-WkRJvi-t6IGlabIafvoiB9raa8ZZ-7PxLeQTBWP6r8xQbuX-Fiq9oZx5feGNZF8b64/s1600/breadboard2.jpg" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXq2LesBfgH1n4joeZhd9ZuzLXhCfY-19cTOFhSPVnrSwR2blbKUpA8uA_af-FnSX93ElXJB9BT-WkRJvi-t6IGlabIafvoiB9raa8ZZ-7PxLeQTBWP6r8xQbuX-Fiq9oZx5feGNZF8b64/s320/breadboard2.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>First Like This</b></td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuKWD0zmotQTLkLaT7OAbfmkFldwCVNW_knjT-r5yd86OGWu12QrBRyHT7V0NfITHCoQC3Ms6omNbK6aiFZXD60_NpU9q1t91mn1_Yl0B4xr9y-pr6kEBVEy9pDPwPVFhCA8SAWhJh0jAY/s1600/breadboard3.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuKWD0zmotQTLkLaT7OAbfmkFldwCVNW_knjT-r5yd86OGWu12QrBRyHT7V0NfITHCoQC3Ms6omNbK6aiFZXD60_NpU9q1t91mn1_Yl0B4xr9y-pr6kEBVEy9pDPwPVFhCA8SAWhJh0jAY/s400/breadboard3.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>Then Like This</b></td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhk5E3QY6LXWIS0sEmZxWotq1VqEaqMoD4tDXzijiCVfgj_gEW_3OhbVrG1KBonOMG2vQV1IpNY4NBNMYHUVyb2Q8-XbhzIBXF0rrwBAJVVTODlRmve6RQ9D-ikVAKO-SoR6H3djpufS6mm/s1600/breadboard1.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="233" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhk5E3QY6LXWIS0sEmZxWotq1VqEaqMoD4tDXzijiCVfgj_gEW_3OhbVrG1KBonOMG2vQV1IpNY4NBNMYHUVyb2Q8-XbhzIBXF0rrwBAJVVTODlRmve6RQ9D-ikVAKO-SoR6H3djpufS6mm/s640/breadboard1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="font-size: 13px;"><b>Final Finished Setup</b></td></tr>
</tbody></table>
</div>R V Prakashhttp://www.blogger.com/profile/09408847003511126384noreply@blogger.com1tag:blogger.com,1999:blog-9038718253168000072.post-19197280378822620192012-05-11T04:38:00.001-07:002012-05-11T04:38:10.258-07:00Simple Labs' Quick Start Kit for Arduino - Getting Started - Part II<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<br />
This is the second part of a
multi-part tutorial that we are working on for you to get started with
the Simple Labs Quick Start kit for Arduino. In case you have not read the earlier part, you can check it out here = > <a href="http://quickstartkitforarduino.blogspot.in/2012/05/simple-labs-quick-start-kit-for-arduino.html" target="_blank">Simple Labs' Quick Start Kit for Arduino - Getting Started - Part I</a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
In this part, we will see
how to connect the following components of the Quick Start Kit and
Program for them using the Arduino. We will not delve into arduino
programming as this has been covered again and again. </div>
<div style="text-align: justify;">
<br /></div>
<ul style="text-align: justify;">
<li>IC ULN2003 - Replacing the Transistor </li>
<li>IR Proximity Sensor</li>
<li>LCD</li>
<li>DS1307 RTC</li>
<li>TSOP - Remote Control Receiver</li>
<li>7-Segment LED Display</li>
</ul>
<div style="text-align: justify;">
We will stick to our previous method, we will choose a simple activity for each element and
keep adding to the previous activity. Keep in mind we are saying
activity and not project as we are not building any project of great
significance, we are rather focusing on 'how to'. You are expected to go
step by step through the activities as some of the coding might build
on the previous activity. So , Lets get started!</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Download the following zip file with the source code for all these examples.<br />
<a href="http://downloads.simplelabs.co.in/Quick_Start_Kit.zip" target="_blank">Quick_Start_Kit.zip</a> </div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
We hope you have kept the basic breadboard setup intact and removed everything else from the previous experiments. Here's how your breadboard should look now.</div>
<div style="text-align: justify;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhk5E3QY6LXWIS0sEmZxWotq1VqEaqMoD4tDXzijiCVfgj_gEW_3OhbVrG1KBonOMG2vQV1IpNY4NBNMYHUVyb2Q8-XbhzIBXF0rrwBAJVVTODlRmve6RQ9D-ikVAKO-SoR6H3djpufS6mm/s1600/breadboard1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhk5E3QY6LXWIS0sEmZxWotq1VqEaqMoD4tDXzijiCVfgj_gEW_3OhbVrG1KBonOMG2vQV1IpNY4NBNMYHUVyb2Q8-XbhzIBXF0rrwBAJVVTODlRmve6RQ9D-ikVAKO-SoR6H3djpufS6mm/s640/breadboard1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Basic Breadboard Setup</td></tr>
</tbody></table>
<div style="text-align: justify;">
<br />
<b>IC ULN2003 - Darlington Pair Transistor Array</b><br />
<br />
In our last example of the first part, we saw how to use a transistor to trigger a buzzer. What if we had more than one buzzer? We can't be setting up multiple transistors as that would get hectic. IC ULN2003 has an array of transistors built inside it and these transistors can be used very much like our regular transistor. The ULN2003 has 7 darlington pairs of transistors inside it. A darlington transistor pair is a cascading transistor setup that given an increased amplification. (<a href="http://en.wikipedia.org/wiki/Darlington_transistor" target="_blank">Click Here to Read more on Darlington Pairs</a>) Each of these pairs can drive a device and can be controlled individually.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS3NrXoXR-QUEcjZ5ctO2ih8YL4FZ89mz2CGBSAT0xf4HW6j3YPFfzddBXoWWYBA__ed1ZqezhDEI6pLyDjERWdhF4Az9w6dp9BDnazM3bTq6ls0821-Neog1gFfLPwOrqCrIP-wXba8jL/s1600/ULN2003.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS3NrXoXR-QUEcjZ5ctO2ih8YL4FZ89mz2CGBSAT0xf4HW6j3YPFfzddBXoWWYBA__ed1ZqezhDEI6pLyDjERWdhF4Az9w6dp9BDnazM3bTq6ls0821-Neog1gFfLPwOrqCrIP-wXba8jL/s320/ULN2003.jpg" width="269" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Pin Diagram of ULN2003 / COM is +5V in our case</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3XDlRylHNTCym20oTTO1RU8CzWJsIuase6lCtRZQ75lL1UAWNXiZMEUx4kRNcdruRQxC01ttjalCeto9oHzeuksF0zLgeqNrV6_zRcnqpm2r2NK5Ala9e1N8LDvQ6zsfkk0qo74YyFdCN/s1600/ULN1A.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3XDlRylHNTCym20oTTO1RU8CzWJsIuase6lCtRZQ75lL1UAWNXiZMEUx4kRNcdruRQxC01ttjalCeto9oHzeuksF0zLgeqNrV6_zRcnqpm2r2NK5Ala9e1N8LDvQ6zsfkk0qo74YyFdCN/s640/ULN1A.jpg" width="596" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the ULN2003 IC as shown. The Top of All ICs is marked by a notch. The Pin to the LEFT of this Notch is the first pin of the IC. For Some IC's there will be a small dot next to the first pin.</td></tr>
</tbody></table>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4IzrnYbPNBpW-8kQEtAIJo9qGmZEPCFg0E2HF6299e-R5hHRGQwddezSJOCA-pGyMOLfJOmgP9pbljFiKbkp1gCsqkTHeA6TcG0YYVXxlBUYqo_QlrBTSU9TyzSCfqkimZixeKV2jiKRE/s1600/ULN2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="584" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4IzrnYbPNBpW-8kQEtAIJo9qGmZEPCFg0E2HF6299e-R5hHRGQwddezSJOCA-pGyMOLfJOmgP9pbljFiKbkp1gCsqkTHeA6TcG0YYVXxlBUYqo_QlrBTSU9TyzSCfqkimZixeKV2jiKRE/s640/ULN2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire from the '-'ve terminal to the 8th pin of the IC</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLRuNx0hzExFYRyTxRO9cWrB2tQdIEwr-jqyOEQLdckyA3umPhzKENe6Cl9N0J5bBVSbTqmvR51X3R0iXoCtBxinMu3wMA59FzftUBjEZoWHeymap-e-lp1h32SXgrpmVC7lh5fM-id0U_/s1600/ULN3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="598" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLRuNx0hzExFYRyTxRO9cWrB2tQdIEwr-jqyOEQLdckyA3umPhzKENe6Cl9N0J5bBVSbTqmvR51X3R0iXoCtBxinMu3wMA59FzftUBjEZoWHeymap-e-lp1h32SXgrpmVC7lh5fM-id0U_/s640/ULN3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between the 9th pin of the IC to the '+'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmYrksxuU134uhD6NNSorQeiT2a8r0mWO6Qxiv5YBKJNE9nriaxYvhGqHlK1Yy8pTFCywHnpHE9bt2IC_5tx86MbhCUBarCkCxAobrpu8FvCT0BZxsx6A4UFcfCd9tR4RV2C18zR8kg9ML/s1600/ULN4.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="542" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmYrksxuU134uhD6NNSorQeiT2a8r0mWO6Qxiv5YBKJNE9nriaxYvhGqHlK1Yy8pTFCywHnpHE9bt2IC_5tx86MbhCUBarCkCxAobrpu8FvCT0BZxsx6A4UFcfCd9tR4RV2C18zR8kg9ML/s640/ULN4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Now Connect the Positive of the Buzzer (the Red Wire) to the '+'ve terminal and the Negative of the Buzzer to the 16th pin of the IC (OUTPUT 1)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7YlkRiuwubXRdrxKRzCJqK9vOzyqwu48w4zuKDEDLeOD2nyMgLZUhWxYJa3Jd0diH2_hv9CW3CL7yYCxY2v1mmx-2KaWQMjlRBvsPeFuWPRb8PRVrY7bfT2APpRiytHyDsA0HduS4uFkY/s1600/ULN5.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7YlkRiuwubXRdrxKRzCJqK9vOzyqwu48w4zuKDEDLeOD2nyMgLZUhWxYJa3Jd0diH2_hv9CW3CL7yYCxY2v1mmx-2KaWQMjlRBvsPeFuWPRb8PRVrY7bfT2APpRiytHyDsA0HduS4uFkY/s640/ULN5.jpg" width="594" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from GND on the Arduino to the '-'ve Terminal of the Breadboard</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLLB0gUsHDdxWVbsakL6aJqztVf2ioJOzG-fQY23Tt8rasfNXPKVq6LUNBbXUc1jd-zZvkWdztl0B9tC7t4KG99R2_vfSjHPIN2iR-k_2l72glBJZvBGijC5QMB5ZXIobdrVoYi98mIfu5/s1600/ULN6.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLLB0gUsHDdxWVbsakL6aJqztVf2ioJOzG-fQY23Tt8rasfNXPKVq6LUNBbXUc1jd-zZvkWdztl0B9tC7t4KG99R2_vfSjHPIN2iR-k_2l72glBJZvBGijC5QMB5ZXIobdrVoYi98mIfu5/s640/ULN6.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from the 5V pin on the Arduino to the '+'ve terminal on the Breadboard</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO3snjokijQY1Q77MIkFuepyqkUSAkQk92goODWB1y2OL9kDs8d3ZQahUTUXD637UZ63ruS0K02BM6qN4LjUkFpCbA_w8v96Rl1vfzh92UOR5xUUHH9aZ2KoGKLi5C-louukA0zojnSYhk/s1600/ULN7.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO3snjokijQY1Q77MIkFuepyqkUSAkQk92goODWB1y2OL9kDs8d3ZQahUTUXD637UZ63ruS0K02BM6qN4LjUkFpCbA_w8v96Rl1vfzh92UOR5xUUHH9aZ2KoGKLi5C-louukA0zojnSYhk/s640/ULN7.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from the 7th Pin of the Arduino to the 1st Pin of the ULN2003 [the Input1 Pin]</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp6NhpmEL9BgMqNw6p-1CznrxfJuOtBNtkdTewhk_guT7356qMqGtkF6ZhDdCY_vH4XvkNro4UvqNg1u1tlOs-HQzF0mgg7wqpb2ptd7NI2y0qUKOdWb13nLLGiyTMRppyGBlVr1ZO1OoX/s1600/ULN8.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="504" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp6NhpmEL9BgMqNw6p-1CznrxfJuOtBNtkdTewhk_guT7356qMqGtkF6ZhDdCY_vH4XvkNro4UvqNg1u1tlOs-HQzF0mgg7wqpb2ptd7NI2y0qUKOdWb13nLLGiyTMRppyGBlVr1ZO1OoX/s640/ULN8.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Here's how your final set up would look like!</td></tr>
</tbody></table>
Try the following code. A simple program - call it an audio_blink ;) [ULN_Buzzer.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">ULN2003- Buzzer</span>
<span style="color: #7e7e7e;">This program drives a Buzzer using ULN2003 </span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
<span style="color: #cc6600;">pinMode</span>(7,<span style="color: #006699;">OUTPUT</span>);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;">delay</span>(2000);
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">LOW</span>);
<span style="color: #cc6600;">delay</span>(3000);
}
</pre>
<b>The IR Proximity Sensor</b><br />
<br />
The IR Proximity sensor is one of the most commonly used sensors. You will find these in automatic taps, automatic door opening, etc. This sensor works on the principle of IR reflectance. There is an IR LED (white / light blue in color) that is constantly emitting IR light. The light when reflected back falls on the IR Receiver LED / Photodiode (the black / dark blue color led). This received signal is then processed by an Op-Amp and the Op-Amp gives a HIGH signal. So the sensor module will give a HIGH signal if there is an object in front of the LED's. The range of sensing can be varied by adjusting the potentiometer on the sensor module. The maximum range of this module is only a few cms, so don't expect to use this as a distance sensor ;). The module will not work when pointed at black objects as black color tends to absorb the IR light.<br />
<br />
Note: The IR Sensor and its 3-pin cable will not come attached. You need to fix the Cable on to the Sensor. There is only 1 way the cable will fit on the sensor module, so, we presume you can't go wrong about it ;)<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifoapTZ8idLoHwTTPiypAjGEOWRnQ6Ojch-DPNKUpdbrv4BVNfYUzeTzINRrIuiTXVquT9VXQHMuHSjOkTGBz6-pDPJ7dZfhPYUbrDK_RZy4rr3nSLzaS6kFw80652jSCqgqY92VHzv6sM/s1600/IR1.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="256" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifoapTZ8idLoHwTTPiypAjGEOWRnQ6Ojch-DPNKUpdbrv4BVNfYUzeTzINRrIuiTXVquT9VXQHMuHSjOkTGBz6-pDPJ7dZfhPYUbrDK_RZy4rr3nSLzaS6kFw80652jSCqgqY92VHzv6sM/s640/IR1.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The IR Sensor. Look at the Wires and Their Mappings. We will connect these accordingly</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7AO3hxTayAt8Tzjot9nAI__T2Gf71Dxw50elhckArqX-7_Dfwa0J9Gjr1UsDZ4O0kwhKDW0tc5hx1Pjz0tcmyAEAPXB_IW5wo8uCQJXTW0X4_y1FsKThxNwMeBUouEkOX_xjKCzIcHi-m/s1600/IR2.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="458" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7AO3hxTayAt8Tzjot9nAI__T2Gf71Dxw50elhckArqX-7_Dfwa0J9Gjr1UsDZ4O0kwhKDW0tc5hx1Pjz0tcmyAEAPXB_IW5wo8uCQJXTW0X4_y1FsKThxNwMeBUouEkOX_xjKCzIcHi-m/s640/IR2.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect the Red Wire of the IR sensor to the '+'ve Terminal & the Black Wire of the IR sensor to the '-'ve Terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIiSd3MOFfxD0ZfV9KVtVc1vsp05Rw7ihk1aQ9gb0SNwLev1zrAof4JHe3FlRDwGYYT792q8oBM-i1VHa7kdHqMUprOjepEgLgiRf6sl-t8nxfZZLB-ipvjZnxyOIZrMtxKeUBCxH7XraJ/s1600/IR3.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIiSd3MOFfxD0ZfV9KVtVc1vsp05Rw7ihk1aQ9gb0SNwLev1zrAof4JHe3FlRDwGYYT792q8oBM-i1VHa7kdHqMUprOjepEgLgiRf6sl-t8nxfZZLB-ipvjZnxyOIZrMtxKeUBCxH7XraJ/s640/IR3.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect the Brown wire of the IR sensor to the 8th pin of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFmD56XwdoCdCnWJPlVR2ooq_BWWRMrP-jVzonCSjCjPPl9NHcMYLBEnY13CHJVwFfBku69tud1en-ZxVzZGeaVnanhShdWqRe8IrjnynIXNA2c5FXKV-MJrDB58VpkFERIHkl8T1hU4nf/s1600/IR4.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="528" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFmD56XwdoCdCnWJPlVR2ooq_BWWRMrP-jVzonCSjCjPPl9NHcMYLBEnY13CHJVwFfBku69tud1en-ZxVzZGeaVnanhShdWqRe8IrjnynIXNA2c5FXKV-MJrDB58VpkFERIHkl8T1hU4nf/s640/IR4.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">This is how your final setup should look like</td></tr>
</tbody></table>
<br />
<br />
Lets program to trigger the Buzzer everytime the sensor gives a HIGH signal. Try the following program. [ULN_Buzzer_IR.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">ULN2003- Buzzer</span>
<span style="color: #7e7e7e;">This program drives a Buzzer using ULN2003 </span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
<span style="color: #cc6600;">pinMode</span>(7,<span style="color: #006699;">OUTPUT</span>);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;">delay</span>(2000);
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">LOW</span>);
<span style="color: #cc6600;">delay</span>(3000);
}
</pre>
<b>LCD - Liquid Crystal Display</b></div>
<div style="text-align: justify;">
LCDs are commonly used display devices that you would find in most appliances / electronic devices. Your music players, Pay phones, Etc.<br />
<br />
<span class="Apple-style-span" style="background-color: white;"><span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif; font-size: 15px; line-height: 21px;">Here's an interesting Write up to get you understanding the working of the LCD</span><br style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif; font-size: 15px; line-height: 21px; text-align: left;" /><span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif; font-size: 15px; line-height: 21px; text-align: left;"><a href="http://joshuagalloway.com/lcd.html">http://joshuagalloway.com/lcd.html</a></span></span><br />
<span class="Apple-style-span" style="background-color: white;"><br /></span><br />
<span class="Apple-style-span" style="background-color: white;">Wiring up the LCD</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3gwWhdcmh2Zxc2Vnx1e1KqBUZODfZ5_rif23HXA5UYv9fUFzRu-o0-3CGq-W_rGI0GK6vpW5hvfRPmmGOseBSTTYUexgBrMaBLL2YBObBEQO7YR-5VMcOH_7AAjhFFgyL4Al8VBuH9547/s1600/LCD3.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="314" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3gwWhdcmh2Zxc2Vnx1e1KqBUZODfZ5_rif23HXA5UYv9fUFzRu-o0-3CGq-W_rGI0GK6vpW5hvfRPmmGOseBSTTYUexgBrMaBLL2YBObBEQO7YR-5VMcOH_7AAjhFFgyL4Al8VBuH9547/s640/LCD3.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The 16x2 LCD Display</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB-ln_-vJQSODEoPU_UAXe13UZ_pkC6sZA3sSJ4TvKpE37PDeVia7nUEPE2TsEc1G7Q5UScGU8UZli969e74wAzCC8vCnuEtiM9ojVhWrU0lKZkL2ulzDvRHbIN43P6V_ipMKc-yRgKuql/s640/LCD_Pins.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="268" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB-ln_-vJQSODEoPU_UAXe13UZ_pkC6sZA3sSJ4TvKpE37PDeVia7nUEPE2TsEc1G7Q5UScGU8UZli969e74wAzCC8vCnuEtiM9ojVhWrU0lKZkL2ulzDvRHbIN43P6V_ipMKc-yRgKuql/s640/LCD_Pins.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">LCD Pin Mappings</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg5YNriB8g8GnF3bmcBy1KvHJvw2Zq7Onx92-rG45Nobmo8ytOrBqxDWPG6bp0ryuaiWh7E9Hk9SnOZpa03CzI225Xzu2S4qN-pqw2pIpO627KscdIaPdhzlA_FJII2D-ZrR7t282PWVhY/s1600/LCD2.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="488" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg5YNriB8g8GnF3bmcBy1KvHJvw2Zq7Onx92-rG45Nobmo8ytOrBqxDWPG6bp0ryuaiWh7E9Hk9SnOZpa03CzI225Xzu2S4qN-pqw2pIpO627KscdIaPdhzlA_FJII2D-ZrR7t282PWVhY/s640/LCD2.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">First Connect A Wire between the GND pin of the Arduino and the '-'ve terminal. Then Connect Another Wire from the 5V pin of the Arduino to the '+'ve terminal.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4T5FMfyGqwUvg88oS2OLLtuh64dud9rrDqmdJrSKXRrWysCmHFNaBkY2p2DzGEBYWlA5mREkrErgPvwX3EZqXfAwCWWdYg-5fdtxIBREaFZaA2UX0uij6Ww0EQg5lFGMAvVjggVEKw9Vj/s1600/LCD4.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4T5FMfyGqwUvg88oS2OLLtuh64dud9rrDqmdJrSKXRrWysCmHFNaBkY2p2DzGEBYWlA5mREkrErgPvwX3EZqXfAwCWWdYg-5fdtxIBREaFZaA2UX0uij6Ww0EQg5lFGMAvVjggVEKw9Vj/s640/LCD4.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the LCD on the Breadboard as Shown (the 16th pin of the LCD is in the LEFT Corner of the Image)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmz2Xxee3fZAQV2elq-XTgAAJQREypTZH2eLYHt6FnO8pYdWXVVy9u-QnZPstdneZGhMpL49EL9TiaM-iPFtd5UJN45ZTyxRzUznMK-rfzSXTWJ-S_ypmBPU-FA5aht6xrwR02PQ0MlPwZ/s1600/LCD5.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmz2Xxee3fZAQV2elq-XTgAAJQREypTZH2eLYHt6FnO8pYdWXVVy9u-QnZPstdneZGhMpL49EL9TiaM-iPFtd5UJN45ZTyxRzUznMK-rfzSXTWJ-S_ypmBPU-FA5aht6xrwR02PQ0MlPwZ/s640/LCD5.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">This is what you should have now</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY21HAk0pxF8oazQE1ZhiU918q7inq2FoEjsU153lE3YhlQkILlx95J1HqJ8WX1WiBxUfPLu2wt7xxEvHgmhv6fZX8ryIUXpK8OMXECVziS20Q1rpEc3Tjh1vZVnbNyvYnPm46XBMDo_Js/s1600/LCD6.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiY21HAk0pxF8oazQE1ZhiU918q7inq2FoEjsU153lE3YhlQkILlx95J1HqJ8WX1WiBxUfPLu2wt7xxEvHgmhv6fZX8ryIUXpK8OMXECVziS20Q1rpEc3Tjh1vZVnbNyvYnPm46XBMDo_Js/s640/LCD6.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the Trimpot Next to the LCD as shown (a bit away from the LCD pins)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgABoDNfxUvPlB9Wm8A-8TdAEB5UcKVGBxx4un6x5lV-6V9bB-_12YvTLsj2bLp_hKxdgucH3DBQgT-STNG_VWCRBQLsGH4piKIWeanp3vsNjG_AFxOQ9T9ImTQiDmcaF2yUCgnE-olo6Sd/s1600/LCD7.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgABoDNfxUvPlB9Wm8A-8TdAEB5UcKVGBxx4un6x5lV-6V9bB-_12YvTLsj2bLp_hKxdgucH3DBQgT-STNG_VWCRBQLsGH4piKIWeanp3vsNjG_AFxOQ9T9ImTQiDmcaF2yUCgnE-olo6Sd/s640/LCD7.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect the Supply & Ground Lines for the Trimpot</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Os3wN1DcX3vV1iIAiM70-HRD5GekwpKm93xuL0l03wIz0i52TlaTE6DeKekXBZjkg6yWceYrvnhFlH3a89mIPeLtTCgSjqwe5bwMpO5BB7WCyNn9ocB7rhZXm6q-eA3QLb7LZGna-HPR/s1600/LCD8.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Os3wN1DcX3vV1iIAiM70-HRD5GekwpKm93xuL0l03wIz0i52TlaTE6DeKekXBZjkg6yWceYrvnhFlH3a89mIPeLtTCgSjqwe5bwMpO5BB7WCyNn9ocB7rhZXm6q-eA3QLb7LZGna-HPR/s640/LCD8.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The First and Last pins of the LCD are GND pins. First Connect a Wire from the 1st pin of the LCD to the '-'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFzI9CLN683ERtFrcoZutU3CC-JdeCxaon7a9bYUdgqqV5TWxSnocLgYEKTr7wE_MGYEUSXfJOx1XLNjvCqdIAmjbXR7U4u8X5P5KYzK6lqQRau7lmCaz15z2gywSr_KzbAB-7dpDB7SX0/s1600/LCD9.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFzI9CLN683ERtFrcoZutU3CC-JdeCxaon7a9bYUdgqqV5TWxSnocLgYEKTr7wE_MGYEUSXfJOx1XLNjvCqdIAmjbXR7U4u8X5P5KYzK6lqQRau7lmCaz15z2gywSr_KzbAB-7dpDB7SX0/s640/LCD9.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire from the 16th pin of the LCD to the '-'ve terminal</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLE2l4XHtItKqOQc0RHqEtAeeMMP_RALvQ664nsPCkph5nWNH5apfJtbVnYNPWRJwx4ZZ-xcE8zC8W2alDIPq0oKLN5SaAagoeOj5qpnY8k2GZuQbz0lfqylr45VEoVFwcvbweMCNJok56/s1600/LCD10.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLE2l4XHtItKqOQc0RHqEtAeeMMP_RALvQ664nsPCkph5nWNH5apfJtbVnYNPWRJwx4ZZ-xcE8zC8W2alDIPq0oKLN5SaAagoeOj5qpnY8k2GZuQbz0lfqylr45VEoVFwcvbweMCNJok56/s640/LCD10.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The 2nd & 15th Pins of the LCD are Supply Pins, Connect Wires from these to the '+'ve Terminal as shown</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvvvsdjAr_HnVqpK7hMsGKM0WgYolQi5W59Cs1L-vy6oIgLngIYOd-Xh0NEiOT1iZPXURdtokGGum5PfgxfJaRPYZh62iFTuyzVGYV7zVPOhEETDSxgpsKAqgLc0K7mZYLgR8U6CAV3GeK/s1600/LCD11.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvvvsdjAr_HnVqpK7hMsGKM0WgYolQi5W59Cs1L-vy6oIgLngIYOd-Xh0NEiOT1iZPXURdtokGGum5PfgxfJaRPYZh62iFTuyzVGYV7zVPOhEETDSxgpsKAqgLc0K7mZYLgR8U6CAV3GeK/s640/LCD11.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The 5th of the LCD is the RW pin. This pin is used to toggle between Read / Write Mode of the LCD. Writing a HIGH signal to this pin corresponds to Read Mode and Writing a LOW signal corresponds to Write Mode. Since we will be using only the Write mode, we can wire this pin to GND / '-'ve terminal [This is equivalent of writing a LOW signal to the pin]</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo6cfeFkX93GiCb3fOWRoRs7EIa1UmZmz-675jXHa80VTVUk1se1D98xnvZnWlMr9fJuYwioEfjJhryASy14oY2QgFcb6xCdC8BhAR7upLUqnXQN8OefL6uoyzZfLhCuDjTyfd8_sMtJFk/s1600/LCD12.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo6cfeFkX93GiCb3fOWRoRs7EIa1UmZmz-675jXHa80VTVUk1se1D98xnvZnWlMr9fJuYwioEfjJhryASy14oY2QgFcb6xCdC8BhAR7upLUqnXQN8OefL6uoyzZfLhCuDjTyfd8_sMtJFk/s640/LCD12.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from the middle pin of the trimpot to the 3rd pin of the LCD. The 3rd pin of the LCD is the contrast pin and the contrast of the display can be varied by varying the trimpot</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbAtQcZDlnR_OMer3gVtlpsVrCHWCDIFnLLJfFraV6eRpU-XeUJcPjb5_2cJ5iItuLHa27bKDurp7laxBe42TUzPQJheliFADFYhKjA6P9v-4ayxNiyomE7f58FfnyHqPDMB-ycuThsgNN/s1600/LCD13.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbAtQcZDlnR_OMer3gVtlpsVrCHWCDIFnLLJfFraV6eRpU-XeUJcPjb5_2cJ5iItuLHa27bKDurp7laxBe42TUzPQJheliFADFYhKjA6P9v-4ayxNiyomE7f58FfnyHqPDMB-ycuThsgNN/s640/LCD13.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between the RS pin of the LCD (4th pin) and digital pin 2 of the Arudino. The RS pin helps select between the 2 registers of an LCD - Data & Command - for communication</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSLMhW_tiIqejutUGhYZGjNpNqTfjWo7BCmsgxP1GiSA9imNHlfznIJK4uNHDEWfJJ8ximFGegBDn0ukqgFnAZtGza1xUXno4vJXHI_gdFzfO56pocd6sa491zV40rQXjL4RmNpXXePgHc/s1600/LCD14.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSLMhW_tiIqejutUGhYZGjNpNqTfjWo7BCmsgxP1GiSA9imNHlfznIJK4uNHDEWfJJ8ximFGegBDn0ukqgFnAZtGza1xUXno4vJXHI_gdFzfO56pocd6sa491zV40rQXjL4RmNpXXePgHc/s640/LCD14.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between the Enable pin (the 6th pin) of the LCD and digital pin 4 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvD_tCZWyJ5ARI_hZtqcSlG22BbOPBaTs3wpU10BOIobHhhsbMY0gqMt3YUqXoNHmAeQX7p31sm7MQ9BLEG2QDnPyud5bCylBTqnCSPt8P7vT5xhHpwFn60-mfiVONKl8G99kpi2OWYEA2/s1600/LCD15.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvD_tCZWyJ5ARI_hZtqcSlG22BbOPBaTs3wpU10BOIobHhhsbMY0gqMt3YUqXoNHmAeQX7p31sm7MQ9BLEG2QDnPyud5bCylBTqnCSPt8P7vT5xhHpwFn60-mfiVONKl8G99kpi2OWYEA2/s640/LCD15.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between D4 of the LCD (11th pin) and digital pin 8 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6QW1PcsIlBmpdmnWWZxAmbXcg6zXjucDkWnRTNKGtS4139mvN0IF_lQGT-7UAL6NhIflTf4boac7C98K4jNuc5EJm819AC-DBQeEpQyUm-czvxIIXQ2YsjfUhhhn0htt0aIvS7s57NUYo/s1600/LCD16.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6QW1PcsIlBmpdmnWWZxAmbXcg6zXjucDkWnRTNKGtS4139mvN0IF_lQGT-7UAL6NhIflTf4boac7C98K4jNuc5EJm819AC-DBQeEpQyUm-czvxIIXQ2YsjfUhhhn0htt0aIvS7s57NUYo/s640/LCD16.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between D5 of the LCD (12th pin) and digital pin 9 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlNLHHyDlzIvAtUvUSnwJE13qt3F9i_f9Yf5fQZ4nsey4PN3WXmXYDMn9E1-oaOqhyPXoW-lFqlJjYSJh9-fxm_zb1E6d9SWmSx_R5-AnG4g31AjPYCBj6uQ8HH3H9ktdsbJjK5JYeaFQz/s1600/LCD17.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlNLHHyDlzIvAtUvUSnwJE13qt3F9i_f9Yf5fQZ4nsey4PN3WXmXYDMn9E1-oaOqhyPXoW-lFqlJjYSJh9-fxm_zb1E6d9SWmSx_R5-AnG4g31AjPYCBj6uQ8HH3H9ktdsbJjK5JYeaFQz/s640/LCD17.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between D6 of the LCD (13th pin) and digital pin 10 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHQd8GOtv6JPoeXgxYlnlXwpIWIINAFfqHeJo_fxrYEmZ4jzz5lHMrUKw7RBqXWNuOV0iGhsEPRuUgs75XX0e6XkaJ1arNnwi7gYk3NBCw3cHzfs3ReWUqKt-O4NjENERikthYag1-VrCU/s1600/LCD18.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHQd8GOtv6JPoeXgxYlnlXwpIWIINAFfqHeJo_fxrYEmZ4jzz5lHMrUKw7RBqXWNuOV0iGhsEPRuUgs75XX0e6XkaJ1arNnwi7gYk3NBCw3cHzfs3ReWUqKt-O4NjENERikthYag1-VrCU/s640/LCD18.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between D7of the LCD (14th pin) and digital pin 11 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8HaJLG8m5tUsRdn5FsybdoXVUsvRD_b2hrFWBIUwuORnM6QKi20JEgD2L8weFds9ojbBfChLPHHV3rFvana_F-QW9QCXUKVN80MoHB0u-tjp8DT2MREs4JMAyMd1dlSlLrGPJ72ke0lTA/s1600/LCD19.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8HaJLG8m5tUsRdn5FsybdoXVUsvRD_b2hrFWBIUwuORnM6QKi20JEgD2L8weFds9ojbBfChLPHHV3rFvana_F-QW9QCXUKVN80MoHB0u-tjp8DT2MREs4JMAyMd1dlSlLrGPJ72ke0lTA/s640/LCD19.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Finished Setup</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnVzGYB0Rdi1mAqU0b5B3aQkGNIvEnT5pjeDy7Noe_oLTcImbWbv-0u9g1ACMvH0XxCqpScgaac2EJvztlni7FI4MvvCZP8YMUvCRqurAY92_rIlIfzIrZ7xj6-5fAO_eRT7wiOtfoS-ZK/s1600/LCD20.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="464" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnVzGYB0Rdi1mAqU0b5B3aQkGNIvEnT5pjeDy7Noe_oLTcImbWbv-0u9g1ACMvH0XxCqpScgaac2EJvztlni7FI4MvvCZP8YMUvCRqurAY92_rIlIfzIrZ7xj6-5fAO_eRT7wiOtfoS-ZK/s640/LCD20.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Sample Hello World Program</td></tr>
</tbody></table>
So Lets program the LCD. We can take the sample hello world program found under File -> Examples -> LiquidCrystal menu of Arduino IDE and change the pin numbers in the following statement<br />
From<br />
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);<br />
To<br />
LiquidCrystal lcd(2,4,8,9,10,11);<br />
<br />
####IMPORTANT - IN CASE NOTHING IS DISPLAYED ON THE LCD KEEP VARYING THE TRIMPOT TILL YOU CAN SEE THE CHARACTERS###<br />
<br />
Try the following Simple LCD program [Simple_LCD.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> LiquidCrystal Library - Hello World</span>
<span style="color: #7e7e7e;"> </span>
<span style="color: #7e7e7e;"> Demonstrates the use a 16x2 LCD display. The LiquidCrystal</span>
<span style="color: #7e7e7e;"> library works with all LCD displays that are compatible with the </span>
<span style="color: #7e7e7e;"> Hitachi HD44780 driver. There are many of them out there, and you</span>
<span style="color: #7e7e7e;"> can usually tell them by the 16-pin interface.</span>
<span style="color: #7e7e7e;"> </span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">// include the library code:</span>
#include <<span style="color: #cc6600;">LiquidCrystal</span>.h>
<span style="color: #7e7e7e;">// initialize the library with the numbers of the interface pins</span>
<span style="color: #cc6600;">LiquidCrystal</span> lcd(2,4,8,9,10,11);
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #7e7e7e;">// set up the LCD's number of columns and rows: </span>
lcd.<span style="color: #cc6600;">begin</span>(16, 2);
<span style="color: #7e7e7e;">// Print a message to the LCD.</span>
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"hello, world!"</span>);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #7e7e7e;">// set the cursor to column 0, line 1</span>
<span style="color: #7e7e7e;">// (note: line 1 is the second row, since counting begins with 0):</span>
lcd.<span style="color: #cc6600;">setCursor</span>(0, 1);
<span style="color: #7e7e7e;">// print the number of seconds since reset:</span>
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #cc6600;">millis</span>()/1000);
}
</pre>
<br />
<b>DS1307 - Real Time Clock IC</b><br />
<br />
The DS1307 lets you explore I2C communication on the arduino.<br />
<br />
<div>
<b>I2C Communication</b></div>
<div>
I2C is short form for 'Inter Integrated Circuit' I2C Communication is Communication Bus standard developed by Phillips for standardising Communication between Integrated Circuits. For Eg. In a circuit, there could be a number of ICs each offering specific functionality[RTC, Temperature Sensor, EEPROM, etc] and they can all communicate on a single I2C Bus and provide combined functionalities. Each device on the I2C Bus would have a unique address by which it can be addressed.</div>
<div>
<br /></div>
<div>
Here's an Interesting Introduction from NXP</div>
<div>
<br /></div>
<div>
<iframe allowfullscreen="" frameborder="0" height="315" src="http://www.youtube.com/embed/BcWixZcZ6JY" width="560"></iframe></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<b>I2C on Arduino</b></div>
<div>
The I2C Bus uses 2 lines for Communication - SDA(Serial Data) & SCL (Serial Clock). On the InduinoX / Arduino, these are available on SDA (Analog Input 4) & SCL (Analog Input 5). The I2C bus can be accessed using the 'Wire' Library of Arduino. First, lets try out a Library</div>
<br />
<br />
<b>Wiring up the DS1307</b><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvIWAbgUU8gWVaXwtnJwkYyoyiHTdKRSYJTjfp9Jr5UP02wjJ7W5dUlY63yLM5P3mQ0_EasTqd58LQIKZGYjJscAKm6t7Edz4E5qvorbtTLv_WSeb954NVJ5Z0VaU65V_lV4hdkEQD2Xpt/s1600/DS1307.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="190" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvIWAbgUU8gWVaXwtnJwkYyoyiHTdKRSYJTjfp9Jr5UP02wjJ7W5dUlY63yLM5P3mQ0_EasTqd58LQIKZGYjJscAKm6t7Edz4E5qvorbtTLv_WSeb954NVJ5Z0VaU65V_lV4hdkEQD2Xpt/s400/DS1307.gif" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">DS1307 Pin Mappings. SDA [Serial Data] / SCL [Serial Clock] correspond to lines for I2C Communication. We can ignore Vbat & SQW / OUT Pins.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhat6Uj1pLY0PeQ4Uei4uVCKF2-dpjIYOO85tGGIR2cDt8g0RCjJAR83Io7CGGIJm40qjBMrI1rzou9L7BzsPcBAGkZkPgK8D7GDJcJnGXtJ7rcKltt4PFZNl_2FqxsYG3MfrlJzItbuCg/s1600/RTC1.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="560" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhat6Uj1pLY0PeQ4Uei4uVCKF2-dpjIYOO85tGGIR2cDt8g0RCjJAR83Io7CGGIJm40qjBMrI1rzou9L7BzsPcBAGkZkPgK8D7GDJcJnGXtJ7rcKltt4PFZNl_2FqxsYG3MfrlJzItbuCg/s640/RTC1.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Components - DS1307, Crystal for DS1307, 2 x 10K Resistors</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgneCgCIBXzpETOKTVP20tsu8hUj8QZnZ0hNVKoZO8tbTi1Z2mEtHgv4F-wm66Srhyphenhyphen7eemMAWVACAYPLNdZt6Uva9-pP1-3blyGcizhPpj8m0J11Cs90v8wDKsOztF8eTXH8Emcp9oM7_4k/s1600/RTC2.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="490" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgneCgCIBXzpETOKTVP20tsu8hUj8QZnZ0hNVKoZO8tbTi1Z2mEtHgv4F-wm66Srhyphenhyphen7eemMAWVACAYPLNdZt6Uva9-pP1-3blyGcizhPpj8m0J11Cs90v8wDKsOztF8eTXH8Emcp9oM7_4k/s640/RTC2.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the DS1307 IC as shown</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho63gpDnJ5KVOvi9X14s672eNjrhg-cmGSe_WFNP_PGVAhcCP9RYxWE24zTOgjlWq2amhofaqFHs_fPTtCIVsYdaDARU8EAsrP5U3YLgl3xgEb1sN2Ali7SFzosvaCJDiaBn3fUyn-v2qh/s1600/RTC3.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho63gpDnJ5KVOvi9X14s672eNjrhg-cmGSe_WFNP_PGVAhcCP9RYxWE24zTOgjlWq2amhofaqFHs_fPTtCIVsYdaDARU8EAsrP5U3YLgl3xgEb1sN2Ali7SFzosvaCJDiaBn3fUyn-v2qh/s640/RTC3.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from the 4th pin of DS1307 (GND) to the '-'ve terminal </td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE74qXt4epnjdlG0BrkvdvWKGgUUIjT9yEGMDqf18Slt7BYEO6tOjs4LHVf4atFA2VG11OVT47CDmAjfbN7MS_LXm302CmnbyqXgrHTNeRB-FgxNtCkw5VWoCfwBDme9A_zfzqOoKGDz56/s1600/RTC4.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="276" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE74qXt4epnjdlG0BrkvdvWKGgUUIjT9yEGMDqf18Slt7BYEO6tOjs4LHVf4atFA2VG11OVT47CDmAjfbN7MS_LXm302CmnbyqXgrHTNeRB-FgxNtCkw5VWoCfwBDme9A_zfzqOoKGDz56/s640/RTC4.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from the 8th pin of DS1307 (+5V) to the '+'ve terminal </td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqwE4uzdKll8tBr9mOcR8CVV8bAuGnl-VQU9PnLK440jKHk62UUPIE5fFkEIch7I5WscJuGm_QEpkT6uXUQeohUMeXnhCKxBeWRjUzCMSFhSrGVnVkROMpmb02UQQ1SUSQHQnxrP4FFLWb/s1600/RTC5.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqwE4uzdKll8tBr9mOcR8CVV8bAuGnl-VQU9PnLK440jKHk62UUPIE5fFkEIch7I5WscJuGm_QEpkT6uXUQeohUMeXnhCKxBeWRjUzCMSFhSrGVnVkROMpmb02UQQ1SUSQHQnxrP4FFLWb/s640/RTC5.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the Cyrstal as shown between the 1st and 2nd pin of the DS1307 IC- There is no polarity ('+' / '-' ve) for the crystal. So you can place it anyway</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS4jvlqBFY4XJyAkTKWU8flwnjP3ynnCguu0mLTe7TwwhmdhQi9h3ebYD9xeFsxBkcMANN8YUbyjDddrByzokJLqKrQQmx2kp5u2ub8GuMOeptzIkA4wDcS4PSK7mm0hYcwsk2uchyJxx3/s1600/RTC6.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="632" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS4jvlqBFY4XJyAkTKWU8flwnjP3ynnCguu0mLTe7TwwhmdhQi9h3ebYD9xeFsxBkcMANN8YUbyjDddrByzokJLqKrQQmx2kp5u2ub8GuMOeptzIkA4wDcS4PSK7mm0hYcwsk2uchyJxx3/s640/RTC6.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place one resistor between the SDA Pin and the '+'ve terminal and one resistor between the SCL Pin and the '-'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKIp-Knh9TFq1IV-b9PsW44ZJFUa44pcwS4j4PI18NRye9gKvTGI_qWQJSzJ9cd2Ah7nxAJGLhM0WyLpizWty9gEvTKjE-RYsI6i-KLbZIs1FEdvfzWmUrxGQvtdVQgFJTpIZ3E-WswwE3/s1600/RTC7.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="398" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKIp-Knh9TFq1IV-b9PsW44ZJFUa44pcwS4j4PI18NRye9gKvTGI_qWQJSzJ9cd2Ah7nxAJGLhM0WyLpizWty9gEvTKjE-RYsI6i-KLbZIs1FEdvfzWmUrxGQvtdVQgFJTpIZ3E-WswwE3/s640/RTC7.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between the SDA pin (pin5 of DS1307) and the SDA pin of the Arduino (Analog IN 4)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr13lN1Q9TP6JH0jfkCzOUKkVFSSustuvaCSnfVGxoDhrH59un4ZORHon_tiAx2g0rSJnz5QX2tIcRVKtxI1tauP5WdbFFxsKimtHAhcOM5ErSaMh3FAaBmFamya03feKMvfe7G7_bhpKX/s1600/RTC8.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr13lN1Q9TP6JH0jfkCzOUKkVFSSustuvaCSnfVGxoDhrH59un4ZORHon_tiAx2g0rSJnz5QX2tIcRVKtxI1tauP5WdbFFxsKimtHAhcOM5ErSaMh3FAaBmFamya03feKMvfe7G7_bhpKX/s640/RTC8.JPG" width="554" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between the SCL pin (pin6 of DS1307) and the SCL pin of the Arduino (Analog IN 5)</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1SfVn7kbKtcPXN-R_MISnW3elaNJRLbBWJkAxkVPeWTsEReqo1hk_2xDKSof9gvkWIokzk7dSxs7m8fAEpwd-plD6QsWxdcE9P4VPpzAlKXQvz6OiLh_FDSx5zqwYB6J-GIXebyCtGmCh/s1600/RTC9.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1SfVn7kbKtcPXN-R_MISnW3elaNJRLbBWJkAxkVPeWTsEReqo1hk_2xDKSof9gvkWIokzk7dSxs7m8fAEpwd-plD6QsWxdcE9P4VPpzAlKXQvz6OiLh_FDSx5zqwYB6J-GIXebyCtGmCh/s1600/RTC9.JPG" style="margin-left: auto; margin-right: auto;"><img border="0" height="496" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1SfVn7kbKtcPXN-R_MISnW3elaNJRLbBWJkAxkVPeWTsEReqo1hk_2xDKSof9gvkWIokzk7dSxs7m8fAEpwd-plD6QsWxdcE9P4VPpzAlKXQvz6OiLh_FDSx5zqwYB6J-GIXebyCtGmCh/s640/RTC9.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Final Setup with output from the following program</td></tr>
</tbody></table>
<br />
Try following Sample Program [LCD_RTC.ino]<br />
<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">This program uses the Wire Library (for i2c communication)</span>
<span style="color: #7e7e7e;">This program sets the initial time for the RTC and keeps updating the time on an LCD everysecond.</span>
<span style="color: #7e7e7e;">*/</span>
#include <<span style="color: #cc6600;">Wire</span>.h>
#define rtc 0x68 <span style="color: #7e7e7e;">// The pre-defined address for DS1307</span>
<span style="color: #cc6600;">int</span> ss,mm,hh,d,DD,MM,YY,mode;
<span style="color: #cc6600;">boolean</span> time_format,meridiem;
<span style="color: #cc6600;">int</span> prev;
#include <<span style="color: #cc6600;">LiquidCrystal</span>.h>
<span style="color: #7e7e7e;">// initialize the library with the numbers of the interface pins</span>
<span style="color: #cc6600;">LiquidCrystal</span> lcd(2,4,8,9,10,11);
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">begin</span>();
lcd.<span style="color: #cc6600;">begin</span>(16, 2);
set_time();
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
get_time();
<span style="color: #cc6600;">if</span>(ss!=prev) <span style="color: #7e7e7e;">// lcd Print when the seconds change</span>
{
lcd.<span style="color: #cc6600;">setCursor</span>(0,0);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Date:"</span>);
lcd.<span style="color: #cc6600;">print</span>(DD);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"/"</span>);
lcd.<span style="color: #cc6600;">print</span>(MM);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"/"</span>);
lcd.<span style="color: #cc6600;">print</span>(YY);
lcd.<span style="color: #cc6600;">setCursor</span>(0,1);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Time:"</span>);
lcd.<span style="color: #cc6600;">print</span>(hh);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">":"</span>);
lcd.<span style="color: #cc6600;">print</span>(mm);
lcd.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">":"</span>);
lcd.<span style="color: #cc6600;">print</span>(ss);
prev=ss;
}
}
<span style="color: #cc6600;">void</span> get_time()
{
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">beginTransmission</span>(rtc); // start communication over i2c with DS1307
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>((<span style="color: #cc6600;">byte</span>)0); // Write the value of the register to point to
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">endTransmission</span>(); // End communication over i2c with DS1307
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">requestFrom</span>(rtc,7); // This will request 7 bytes of data </pre>
<pre> //starting from the '0' the register
ss=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
mm=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
hh=<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>();
time_format=hh&(1<<6);
meridiem=hh&(1<<5); <span style="color: #7e7e7e;">// calculate am or pm</span>
hh=bcd_to_dec(hh&0x1F);
d=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
DD=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
MM=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
YY=bcd_to_dec(<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">read</span>());
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">endTransmission</span>();
}
<span style="color: #cc6600;">void</span> set_time()
{
time_format=0; <span style="color: #7e7e7e;">// 0=24 hour mode, 1=12 hour mode </span>
meridiem=1; <span style="color: #7e7e7e;">// 0=am, 1=pm will not be taken into consideration if time format is 24 hour mode</span>
mode=(time_format<<6)+((time_format&&meridiem)<<5); <span style="color: #7e7e7e;">//calculate the bits to be added for 12 hour mode </span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">beginTransmission</span>(rtc);
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>((<span style="color: #cc6600;">byte</span>)0);
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(50)); <span style="color: #7e7e7e;">// seconds</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(59)); <span style="color: #7e7e7e;">// minutes</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(mode+dec_to_bcd(11));<span style="color: #7e7e7e;">// hours</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(3)); <span style="color: #7e7e7e;">// day of the week, startin monday</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(21)); <span style="color: #7e7e7e;">// date</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(12)); <span style="color: #7e7e7e;">// month</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">write</span>(dec_to_bcd(11)); <span style="color: #7e7e7e;">// year</span>
<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">endTransmission</span>();
}
<span style="color: #cc6600;">int</span> dec_to_bcd(<span style="color: #cc6600;">int</span> dec)
{
<span style="color: #cc6600;">return</span> dec/10*16 + (dec%10);
}
<span style="color: #cc6600;">int</span> bcd_to_dec(<span style="color: #cc6600;">int</span> bcd)
{
<span style="color: #cc6600;">return</span> bcd/16*10 + (bcd%16);
}
</pre>
<br />
<b>TSOP - IR Receiver</b><br />
<b><br /></b><br />
<span class="Apple-style-span" style="background-color: white;"><span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif; font-size: 15px; line-height: 21px;">The TSOP SM0038 is an IR receiver. The TSOP will help you to interface your TV remote with the Arduino and in the Process learn the basics of Wireless Communication.</span><span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif; font-size: 15px; line-height: 21px;"> </span></span><br />
<br />
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">The TSOP outputs a constant HIGH signal when idle and as it receives data, it tends to invert the data. i.e when an IR LED is transmitting data onto the TSOP, everytime the IR led goes high, the TSOP will go LOW and vice versa. Remote control signals are often bytes of data that is encoded and transmitted by pulsing(switching ON & OFF the IR LED at a specific frequency) Most TV remote controls work at 32-40 Khz frequency and most receivers can receive this range. </span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"><br /></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">Heres a link to a nice write up on different remote control protocols. lets first take a look how the Sony Remote Control Protocol Works. We stick to Sony as it is the easiest one to get started with. <a href="http://www.sbprojects.com/knowledge/ir/sirc.php" target="_blank">Read this before proceeding </a></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"><br /></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">Here's a basic outline of how the data is sent. Every time you press a button on a Sony remote control, it sends out a 13Bit data. The first bit is a start bit indicating there are 12 bits of data following it. The next 7 bits are the command bit which will vary depending upon the keys being pressed. The last 5 bits are the address bits which will the same for all buttons but vary for remote controls of different devices.</span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"><br /></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">The black bars in the following image correspond to high signals (called marks) and the white spaces in between correspond to low signals (called spaces). The duration of the 'marks' varies according to the bit being transmitted. It is 2.4ms for the start bit, 1.2ms for HIGH bit and 0.6ms for LOW bit. The duration of the 'spaces' is a constant 0.6ms. Every mark is followed by a space. Any data can be converted to binary format and transmitted in this manner. In fact this is the basic form of all types of serial communication.</span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"><br /></span></span></div>
<div class="separator" style="clear: both;">
<a href="http://www.sbprojects.com/knowledge/ir/sirctrain.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="163" src="http://www.sbprojects.com/knowledge/ir/sirctrain.gif" width="640" /></a></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"><br /></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">Technique to decode this signal train, would be to constantly monitor the TSOP pin[Digital 15] for its normal state and the moment it produces a low signal, measure the duration of the low signal. If the measured duration of the low signal is around 2ms then measure and store the duration for the next 12 bits of the incoming data. After storing the data, evaluate the duration and based on the duration convert the data to decimal / hexadecimal and use it in your application.</span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;"><br /></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><span class="Apple-style-span" style="font-size: 15px; line-height: 21px;">The duration of a signal on an input pin of the arduino can be measured using the pulseIn function. <a href="http://arduino.cc/en/Reference/pulseIn" target="_blank">Read more about this function here</a></span></span></div>
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><br /></span></div>
<div>
<b>Wire it up</b><br />
<br />
Before wiring the TSOP, remove the DS1307 part alone from the breadboard.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMMNuOpI50yhTBmuSiPCj7N4NhEdwggAGYo5j-S1b_pNYD-4i2nISTjh8KUVh0srZ8nadfhB9o1mwK6UcxKOT0uvb1EhI48AEkLV0XmNnmI_ivI9MogZrqdQEe6PFXoRk5DQLBi6V4-AlD/s1600/tsop173x.png" imageanchor="1" style="font-size: medium; margin-left: auto; margin-right: auto;"><img border="0" height="318" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMMNuOpI50yhTBmuSiPCj7N4NhEdwggAGYo5j-S1b_pNYD-4i2nISTjh8KUVh0srZ8nadfhB9o1mwK6UcxKOT0uvb1EhI48AEkLV0XmNnmI_ivI9MogZrqdQEe6PFXoRk5DQLBi6V4-AlD/s400/tsop173x.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">TSOP Pin Mappings</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh93ahu29Opu5wUMUtAOSeml3dOkgLRhj8c-r667qs43fMNBXAP2F7ZBw9Z965FnIELUp3YhZgzcRaBq9uKe9DpKkKZEOibrkAwlmjxK9ui8n-96q0pWOY1oWhiqyQp9IrXesxe9k8vhMYl/s1600/TSOP1.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="414" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh93ahu29Opu5wUMUtAOSeml3dOkgLRhj8c-r667qs43fMNBXAP2F7ZBw9Z965FnIELUp3YhZgzcRaBq9uKe9DpKkKZEOibrkAwlmjxK9ui8n-96q0pWOY1oWhiqyQp9IrXesxe9k8vhMYl/s640/TSOP1.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The TSOP 1738</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaW7aPaPe01sdOjBF7Py_FWPm0mdsIenMuANER9GXez5UtjIIi1qLemktHAYT8hXFb3NefbNXQ3AaCdMZEhorUZt6iGsh8kJk8OdD0MlLGIO-9WCS87qogcIaz0eFHjvr2fjEupUpDlPX8/s1600/TSOP2.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaW7aPaPe01sdOjBF7Py_FWPm0mdsIenMuANER9GXez5UtjIIi1qLemktHAYT8hXFb3NefbNXQ3AaCdMZEhorUZt6iGsh8kJk8OdD0MlLGIO-9WCS87qogcIaz0eFHjvr2fjEupUpDlPX8/s640/TSOP2.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the TSOP on the Breadboard as Shown<span class="Apple-style-span" style="font-size: small;"><br /></span></td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtvgyLvoEVroKBabjDfmmignqkW6_TYBV0FcJPyDuYhDTOJE689vIcM_5MF9UTmhME2pxnrP_QE7D5ciFp5BU8BNt_8cMA3vbYyUNOxXzCezFri1MSiO2jtZbSaa70H2cosJd8NvbZv_Qg/s1600/TSOP3.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtvgyLvoEVroKBabjDfmmignqkW6_TYBV0FcJPyDuYhDTOJE689vIcM_5MF9UTmhME2pxnrP_QE7D5ciFp5BU8BNt_8cMA3vbYyUNOxXzCezFri1MSiO2jtZbSaa70H2cosJd8NvbZv_Qg/s640/TSOP3.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between the 1st pin of the TSOP and the '-'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnifBx0skiBCH2ma-yaSGmDVvnOLK2J1HGr9mxF2ObyegR6rmMD784Nro972IoOIZUMWfK3s7KfizMbQnWwl8r4v64-qDGK16aJrLe0UcjGAxS1o0viv30tRaNnR9tMt7VenRa8LQcmzdP/s1600/TSOP4.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnifBx0skiBCH2ma-yaSGmDVvnOLK2J1HGr9mxF2ObyegR6rmMD784Nro972IoOIZUMWfK3s7KfizMbQnWwl8r4v64-qDGK16aJrLe0UcjGAxS1o0viv30tRaNnR9tMt7VenRa8LQcmzdP/s640/TSOP4.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between the 2nd pin of the TSOP and the '+'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXQnJX9BRaal2bauII64ODxNEVZADg762n12nBx6tNr39PGGTl9PtRdCtzJh1ef7gy2mXp3xE_yRXg2iZCIW6wL6Sv7fCYaKkvABNZjd022dHtzJOVx8ZzWdeOb9XSRk1j9qysvqzRkDFj/s1600/TSOP5.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXQnJX9BRaal2bauII64ODxNEVZADg762n12nBx6tNr39PGGTl9PtRdCtzJh1ef7gy2mXp3xE_yRXg2iZCIW6wL6Sv7fCYaKkvABNZjd022dHtzJOVx8ZzWdeOb9XSRk1j9qysvqzRkDFj/s640/TSOP5.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire between the 3rd pin of the TSOP and digital pin 12 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO8AXRLm-dw_s_p_p-dDeaxej8CLKgztJOMGnwtsX1Mnvh47xWqlpX9yvVnycXqN7sS9UswVOSycR9pDyzo0xibACo7a0E6Rkxz4nzYWO-lDuJJMy_8yV9zR9N531cNesHxfeksx95kj1y/s1600/TSOP6.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO8AXRLm-dw_s_p_p-dDeaxej8CLKgztJOMGnwtsX1Mnvh47xWqlpX9yvVnycXqN7sS9UswVOSycR9pDyzo0xibACo7a0E6Rkxz4nzYWO-lDuJJMy_8yV9zR9N531cNesHxfeksx95kj1y/s640/TSOP6.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">A Closeup of the Previous step!</td></tr>
</tbody></table>
<br />
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;">There is an interesting IR remote library that can help you read different remotes without any difficulty. [This is included in the zip file]</span><br />
<div>
<span class="Apple-style-span" style="color: #222222; font-family: Georgia, Utopia, 'Palatino Linotype', Palatino, serif;"><br /></span></div>
<b>How to use Libraries in Arduino - An Overview</b><br />
To use any library you download, unzip the downloaded file and copy its contents to the libraries folder inside your arduino directory. You can check the library by opening the arduino ide and going to Sketch -> Import Library Option, if your library is in the proper location, it will show up here. Next if there is an example provided with the library (it will be inside a folder called example inside the base folder of the library) it will show up under the libraries name in the File->Examples Menu. You should reopen Arduino for the library to show up.<br />
<div>
<br /></div>
<div>
Once you install the IRremote Library, You can try the example program, IRrecvDemo. This program will give you a serial output of the HEX code for each value corresponding to each button on a remote. We will be using the decimal value in our next program. To get the decimal value, just do the following modification<br />
change this line<br />
from<br />
<strike><i>int RECV_PIN = 11;</i></strike><br />
to<br />
int RECV_PIN = 12; // we have the lcd using the 11th pin ;)<br />
<br />
replace this line<br />
<strike><i>Serial.println(results.value, HEX);</i></strike><br />
with<br />
<i>Serial.println(results.value);</i><br />
<i><br /></i><br />
Here is the modified code [TSOP_IRrecvDemo.ino]<br />
<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv</span>
<span style="color: #7e7e7e;"> * An IR detector/demodulator must be connected to the input RECV_PIN.</span>
<span style="color: #7e7e7e;"> * Version 0.1 July, 2009</span>
<span style="color: #7e7e7e;"> * Copyright 2009 Ken Shirriff</span>
<span style="color: #7e7e7e;"> * http://arcfn.com</span>
<span style="color: #7e7e7e;"> */</span>
#include <IRremote.h>
<span style="color: #cc6600;">int</span> RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;</pre>
<pre>int remote = 0;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
irrecv.enableIRIn(); <span style="color: #7e7e7e;">// Start the receiver</span>
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span> (irrecv.decode(&results)) {</pre>
<pre> remote = results.value;
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(remote);
irrecv.resume(); <span style="color: #7e7e7e;">// Receive the next value</span>
}
}
</pre>
Now get your remote and make note of the values you get for pressing various buttons.<br />
<br />
Now lets try to display the remote button value on the LCD. [LCD_TSOP.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">The following program uses the IRremote library and displays the value of the button being pressed on the LCD</span>
<span style="color: #7e7e7e;">*/</span>
#include <IRremote.h>
#include <<span style="color: #cc6600;">LiquidCrystal</span>.h>
<span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">List of Values corresponding to numbers of the remote being pressed, remember to replace these values with the values you get.</span>
<span style="color: #7e7e7e;">1 16</span>
<span style="color: #7e7e7e;">2 2064</span>
<span style="color: #7e7e7e;">3 1040</span>
<span style="color: #7e7e7e;">4 3088</span>
<span style="color: #7e7e7e;">5 528</span>
<span style="color: #7e7e7e;">6 2576</span>
<span style="color: #7e7e7e;">7 2960</span>
<span style="color: #7e7e7e;">8 3600</span>
<span style="color: #7e7e7e;">9 272</span>
<span style="color: #7e7e7e;">0 2320</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">// initialize the library with the numbers of the interface pins</span>
<span style="color: #cc6600;">LiquidCrystal</span> lcd(2,4,8,9,10,11);
<span style="color: #cc6600;">int</span> RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
<span style="color: #cc6600;">int</span> remote = 0, display_value=0;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
lcd.<span style="color: #cc6600;">begin</span>(16,2);
irrecv.enableIRIn(); <span style="color: #7e7e7e;">// Start the receiver</span>
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span> (irrecv.decode(&results)) {
remote = results.value;
<span style="color: #cc6600;">switch</span>(remote)
{
<span style="color: #cc6600;">case</span> 16 : display_value=1; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2064 : display_value=2; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 1040 : display_value=3; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 3088 : display_value=4; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 528 : display_value=5; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2576 : display_value=6; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2960 : display_value=7; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 3600 : display_value=8; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 272 : display_value=9; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2320 : display_value=0; <span style="color: #cc6600;">break</span>;
}
lcd.<span style="color: #cc6600;">clear</span>();
lcd.<span style="color: #cc6600;">print</span>(display_value);
irrecv.resume(); <span style="color: #7e7e7e;">// Receive the next value</span>
}
}
</pre>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<b>The 7-Segment Display</b><br />
<br />
7-Segment displays are another common component in the world of electronics. These displays have 8 LEDs split into different segments designed to be able to display numerals from 0-9 and a dot. All The LEDs have a common ground / supply line. There are 5 pins at the top and 5 pins at the bottom. The middle pins in the top and bottom are connected to each other internally and have to be connected to Ground / Supply depending upon the type of the 7-segment Display. You can control each segment like an individual LED. However, this method of controlling the 7-segment LED to display numbers would be hectic. So, we will use a technique called Port Manipulation. Pins on the Arduino are grouped together as a PORT. You can control a whole PORT at a time. Read the following write up on the Arduino website before you proceed => <a href="http://www.arduino.cc/en/Reference/PortManipulation" target="_blank">Port Manipulation</a><br />
<br />
The 7-Segment Display included in the starter kit is a Common Cathode Type.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnf2x8r4P7_zb7N9OMiAYUUOM7wuGP7vL5F5ZxK01H9bktG0IppEBQoLa5_ohcX05i4rBJ92tlZKIi-vdWeZTMAQ53YrEAQoqpa5njRwMy27ObvN7dzq83dUOu81HJBAZwWBzvQM6O_inD/s1600/SEV1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnf2x8r4P7_zb7N9OMiAYUUOM7wuGP7vL5F5ZxK01H9bktG0IppEBQoLa5_ohcX05i4rBJ92tlZKIi-vdWeZTMAQ53YrEAQoqpa5njRwMy27ObvN7dzq83dUOu81HJBAZwWBzvQM6O_inD/s400/SEV1.jpg" width="268" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">7 - Segment LED</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMez2IZ6NJtrSgitrl_ZJCb5zhdas3JHuuRmjUFtn2Nu39QF31GpJxowVH-3jtS76P12sNaC_TjYFjfZvOzfzDTDhEVV51m77mJf_y1VHN7dAQAHkd8IBOtHaX4Gr31fl_RdC6liOlvFJW/s1600/7seg_pinouts.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMez2IZ6NJtrSgitrl_ZJCb5zhdas3JHuuRmjUFtn2Nu39QF31GpJxowVH-3jtS76P12sNaC_TjYFjfZvOzfzDTDhEVV51m77mJf_y1VHN7dAQAHkd8IBOtHaX4Gr31fl_RdC6liOlvFJW/s400/7seg_pinouts.png" width="271" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Segment & Pin Mapping of a 7-Segment LED / We will be connecting segments A-G & P to digital pins 0-6 & 7 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxnpTraxHnzjcoRyMzskOsQm5Y2mBaSvOYQH7kAcThlsaPoTIQ0ASjoAsowIfc3-qizqFwlDMOhp49JXs_eB6cMEon2XoRa2vpCbPJH3RmhbdNsPrFaGkFdK33V81XH98vR9vGnUnhtBYu/s1600/SEV2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxnpTraxHnzjcoRyMzskOsQm5Y2mBaSvOYQH7kAcThlsaPoTIQ0ASjoAsowIfc3-qizqFwlDMOhp49JXs_eB6cMEon2XoRa2vpCbPJH3RmhbdNsPrFaGkFdK33V81XH98vR9vGnUnhtBYu/s640/SEV2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the 7-segment Display on the Breadboard.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf9qELnYwwTlqBjkXQQKxGxCnUURQoYw1Y7PNzHe3DBRuo3qeRLjQSIaUB4rdVEDJrehnGUvV-MjlPtrCCJLx8dJF2YXhSgkoP_394h81gXMVfrQmiLAlRTwJE99-ssNquzUvpyBdB5J20/s1600/SEV3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="416" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjf9qELnYwwTlqBjkXQQKxGxCnUURQoYw1Y7PNzHe3DBRuo3qeRLjQSIaUB4rdVEDJrehnGUvV-MjlPtrCCJLx8dJF2YXhSgkoP_394h81gXMVfrQmiLAlRTwJE99-ssNquzUvpyBdB5J20/s640/SEV3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place a 1K resistor between the middle pin on the top and the '-'ve terminal</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB9UdwZ2ngLCtIBlqK1NK6kAwrBf5nLx-Q2F-A1P_phkx1Gzp9eqiVg6Yx_Dkr6UkpWRWsr-AjyJlL4IEFVluQq9twwJJ7JJhx0nQraB_ac2Jj0N9GvKz_G11_XScp4KFAn2d0NiX_ezM9/s1600/SEV4.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB9UdwZ2ngLCtIBlqK1NK6kAwrBf5nLx-Q2F-A1P_phkx1Gzp9eqiVg6Yx_Dkr6UkpWRWsr-AjyJlL4IEFVluQq9twwJJ7JJhx0nQraB_ac2Jj0N9GvKz_G11_XScp4KFAn2d0NiX_ezM9/s640/SEV4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment A to digital pin 0 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR0U4otO-S2JCSUPrfM28eQdzpvHI5e9u2-4sGrSyg400AjhOznakhoxhMbdLs9B5siAoH8aJ2R9fporvRgbtFrjMIdkUXgqPs71goG69Q7cNp9NB0OhT2cWRB1UG8z0WC014BGf_GmfGZ/s1600/SEV5.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="454" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR0U4otO-S2JCSUPrfM28eQdzpvHI5e9u2-4sGrSyg400AjhOznakhoxhMbdLs9B5siAoH8aJ2R9fporvRgbtFrjMIdkUXgqPs71goG69Q7cNp9NB0OhT2cWRB1UG8z0WC014BGf_GmfGZ/s640/SEV5.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment B to digital pin 1 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQKQkc07Nq97zLOIi_PgI3DjjXWPYD8sonY1ak0pLRbc0D_bI9oOPoi-WLP5pxwEUToZkDdu0SqkjLYAwkNKMWfQL0TTIMxfJfECU-9WQQch-6gaomNA6GsrNfyv2YzBE-2EPwBRmzwdkG/s1600/SEV6.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQKQkc07Nq97zLOIi_PgI3DjjXWPYD8sonY1ak0pLRbc0D_bI9oOPoi-WLP5pxwEUToZkDdu0SqkjLYAwkNKMWfQL0TTIMxfJfECU-9WQQch-6gaomNA6GsrNfyv2YzBE-2EPwBRmzwdkG/s640/SEV6.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment C to digital pin 2 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7HRuadYPXB4LGgm9FWHhiJ4XADL_aaScQFnNIynxFEo4obINa6OrQMjfjyDxvKzxi57ZoG85XphPOdpeIeKZB0HMaG2-kl97dT93UrHNh18ZO7gPq1KMREz2CjUcErftpY0lqjnE4KgJF/s1600/SEV7.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="498" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7HRuadYPXB4LGgm9FWHhiJ4XADL_aaScQFnNIynxFEo4obINa6OrQMjfjyDxvKzxi57ZoG85XphPOdpeIeKZB0HMaG2-kl97dT93UrHNh18ZO7gPq1KMREz2CjUcErftpY0lqjnE4KgJF/s640/SEV7.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment D to digital pin 3 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcozSIRjLIQohob-g4zbmfF7R1Y5meb6T5u4jhdbWN-xcuYJssJHQicDA8IHI7ShDD8DJztfsqUAkbx5w84p0Bdm3_6KCkO14GvA8vhIT_ogcZkC3_c_vuQvQcBW2nlchCZ3P9d3qQDp9U/s1600/SEV8.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="494" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcozSIRjLIQohob-g4zbmfF7R1Y5meb6T5u4jhdbWN-xcuYJssJHQicDA8IHI7ShDD8DJztfsqUAkbx5w84p0Bdm3_6KCkO14GvA8vhIT_ogcZkC3_c_vuQvQcBW2nlchCZ3P9d3qQDp9U/s640/SEV8.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment E to digital pin 4 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8f592uiy_wi-Ne90BQbsSjG7cMPQk4LcDIZpAKFuSkE_A8lyznyHMqhssYTAq-0Hklox8SqAhMK_1NmkndxC7pBCqKQAxu96rwOo7VjhVA4jML8gCqRR_EsUBhB4Ap0gsoNWCH_c1z3DA/s1600/SEV9.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="588" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8f592uiy_wi-Ne90BQbsSjG7cMPQk4LcDIZpAKFuSkE_A8lyznyHMqhssYTAq-0Hklox8SqAhMK_1NmkndxC7pBCqKQAxu96rwOo7VjhVA4jML8gCqRR_EsUBhB4Ap0gsoNWCH_c1z3DA/s640/SEV9.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment F to digital pin 5 of the Arduino</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUJYxH3kazSGukrlJokVuJ_CPxp9BsgwqvFhiRg96SH0qkYVN61b_XAfnUOzjBlHwAdNM1NQp_ImpkJLa_rP0RnhvdR3Ct0x0bWE1Lkgn5r1kSTQKPTMWOdzO7OnDnQRZsnuuOkbumlk7q/s1600/SEV10.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUJYxH3kazSGukrlJokVuJ_CPxp9BsgwqvFhiRg96SH0qkYVN61b_XAfnUOzjBlHwAdNM1NQp_ImpkJLa_rP0RnhvdR3Ct0x0bWE1Lkgn5r1kSTQKPTMWOdzO7OnDnQRZsnuuOkbumlk7q/s640/SEV10.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment G to digital pin 6 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr8pyVqpVy-dhuI4JGjnoJgvs1yf4x9bz5LBt92BeGPd6g3o6tJuoE16WGjvo9q3WzG_1YUQsKAAChnbrtNYkYLb2c6gz2wLX0oJ-5hSAUdka_y0Sy2HIKgkQG5x8bwQYc0IBR0ab69CHc/s1600/SEV11.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="430" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr8pyVqpVy-dhuI4JGjnoJgvs1yf4x9bz5LBt92BeGPd6g3o6tJuoE16WGjvo9q3WzG_1YUQsKAAChnbrtNYkYLb2c6gz2wLX0oJ-5hSAUdka_y0Sy2HIKgkQG5x8bwQYc0IBR0ab69CHc/s640/SEV11.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a Wire from Segment P to digital pin 7 of the Arduino</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH2Kb8s9T2SUA6eZgWIHjsf6z1qG4H1pGWFd6NfvXviaLJ6xT4hyphenhyphenyuS8m3Iz6bnN5HqNOGM0jR5cpwNnIZ3boWvnBSmnW6WDoaMHME8wHocwkZIyOeocMc0fns-XSLZvKdcNBbqk0c5ZAc/s1600/SEV12.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="428" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH2Kb8s9T2SUA6eZgWIHjsf6z1qG4H1pGWFd6NfvXviaLJ6xT4hyphenhyphenyuS8m3Iz6bnN5HqNOGM0jR5cpwNnIZ3boWvnBSmnW6WDoaMHME8wHocwkZIyOeocMc0fns-XSLZvKdcNBbqk0c5ZAc/s640/SEV12.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Our Final Setup with a Program</td></tr>
</tbody></table>
First Try the following program that cycles from digits 0 - 9. [SEV_SEG.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">This is to Display numbers 0-9 on the seven segment LED</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">Wiring </span>
<span style="color: #7e7e7e;">Seg A - Pin 0</span>
<span style="color: #7e7e7e;">Seg B - Pin 1</span>
<span style="color: #7e7e7e;">Seg C - Pin 2</span>
<span style="color: #7e7e7e;">Seg D - Pin 3</span>
<span style="color: #7e7e7e;">Seg E - Pin 4</span>
<span style="color: #7e7e7e;">Seg F - Pin 5</span>
<span style="color: #7e7e7e;">Seg G - Pin 6</span>
<span style="color: #7e7e7e;">Seg H - Pin 7</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">To Display '0' we need to make high All Segments except G & H</span>
<span style="color: #7e7e7e;">based on this lets make a list of values to write to port D [pins 0-7 are grouped together as port D]</span>
<span style="color: #7e7e7e;">When we write a binary value to the port the MSB or the 8th bit will be written to pin 7 and the lsb will be written to pin 0</span>
<span style="color: #7e7e7e;">0 => B00111111</span>
<span style="color: #7e7e7e;">1 => B00000110</span>
<span style="color: #7e7e7e;">2 => B01011011</span>
<span style="color: #7e7e7e;">3 => B01001111</span>
<span style="color: #7e7e7e;">4 => B01100110</span>
<span style="color: #7e7e7e;">5 => B01101101</span>
<span style="color: #7e7e7e;">6 => B01111101</span>
<span style="color: #7e7e7e;">7 => B00000111</span>
<span style="color: #7e7e7e;">8 => B01111111</span>
<span style="color: #7e7e7e;">9 => B01101111</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #cc6600;">int</span> val[]={B00111111,B00000110,B01011011,B01001111,B01100110, B01101101,B01111101, B00000111, B01111111, B01101111};
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
DDRD = B11111111;
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
<span style="color: #cc6600;">for</span>(<span style="color: #cc6600;">int</span> i=0; i<10;i++)
{
PORTD = val[i];
<span style="color: #cc6600;">delay</span>(1000);
}
}
</pre>
<br />
Now Try the following program - An extension of our Remote Control Program. Here the Value of the Button being pressed is displayed on the 7-segment display. [SEV_SEG_TSOP.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">This is to Display numbers 0-9 on the seven segment LED based on Remote Control INPUT</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">Wiring </span>
<span style="color: #7e7e7e;">Seg A - Pin 0</span>
<span style="color: #7e7e7e;">Seg B - Pin 1</span>
<span style="color: #7e7e7e;">Seg C - Pin 2</span>
<span style="color: #7e7e7e;">Seg D - Pin 3</span>
<span style="color: #7e7e7e;">Seg E - Pin 4</span>
<span style="color: #7e7e7e;">Seg F - Pin 5</span>
<span style="color: #7e7e7e;">Seg G - Pin 6</span>
<span style="color: #7e7e7e;">Seg H - Pin 7</span>
<span style="color: #7e7e7e;">*/</span>
<span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;">To Display '0' we need to make high All Segments except G & H</span>
<span style="color: #7e7e7e;">based on this lets make a list of values to write to port D [pins 0-7 are grouped together as port D]</span>
<span style="color: #7e7e7e;">When we write a binary value to the port the MSB or the 8th bit will be written to pin 7 and the lsb will be written to pin 0</span>
<span style="color: #7e7e7e;">0 => B00111111</span>
<span style="color: #7e7e7e;">1 => B00000110</span>
<span style="color: #7e7e7e;">2 => B01011011</span>
<span style="color: #7e7e7e;">3 => B01001111</span>
<span style="color: #7e7e7e;">4 => B01100110</span>
<span style="color: #7e7e7e;">5 => B01101101</span>
<span style="color: #7e7e7e;">6 => B01111101</span>
<span style="color: #7e7e7e;">7 => B00000111</span>
<span style="color: #7e7e7e;">8 => B01111111</span>
<span style="color: #7e7e7e;">9 => B01101111</span>
<span style="color: #7e7e7e;">*/</span>
#include <IRremote.h>
<span style="color: #cc6600;">int</span> RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;
<span style="color: #cc6600;">int</span> remote = 0, display_value=0;
<span style="color: #cc6600;">int</span> val[]={B00111111,B00000110,B01011011,B01001111,B01100110, B01101101,B01111101, B00000111, B01111111, B01101111};
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
DDRD = B11111111; // Declares PORT D as Output, PORTD is digital pins 0-7
irrecv.enableIRIn(); <span style="color: #7e7e7e;">// Start the receiver</span>
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
<span style="color: #cc6600;">if</span> (irrecv.decode(&results)) {
remote = results.value;
<span style="color: #cc6600;">switch</span>(remote)
{
<span style="color: #cc6600;">case</span> 16 : display_value=1; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2064 : display_value=2; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 1040 : display_value=3; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 3088 : display_value=4; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 528 : display_value=5; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2576 : display_value=6; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2960 : display_value=7; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 3600 : display_value=8; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 272 : display_value=9; <span style="color: #cc6600;">break</span>;
<span style="color: #cc6600;">case</span> 2320 : display_value=0; <span style="color: #cc6600;">break</span>;
}
PORTD = val[display_value];
irrecv.resume(); <span style="color: #7e7e7e;">// Receive the next value</span>
}
}
</pre>
<br />
<br />
<br /></div>
</div>
</div>
</div>Simple Labshttp://www.blogger.com/profile/00881173225878503487noreply@blogger.com0tag:blogger.com,1999:blog-9038718253168000072.post-74734854909078339902012-05-08T06:47:00.001-07:002012-05-08T20:26:17.555-07:00Simple Labs' Quick Start Kit for Arduino - Getting Started - Part I<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
This is the first part of a multi-part tutorial that we are working on for you to get started with the Simple Labs Quick Start kit for Arduino. In this part, we will see how to connect the following components of the Quick Start Kit and Program for them using the Arduino. We will not delve into arduino programming as this has been covered again and again. </div>
<ul style="text-align: left;">
<li style="text-align: justify;">LED</li>
<li style="text-align: justify;">RGB LED</li>
<li style="text-align: justify;">Push Button</li>
<li style="text-align: justify;">Trimpot</li>
<li style="text-align: justify;">LM 35 - Temperature Sensor</li>
<li style="text-align: justify;">LDR - Light sensor</li>
<li style="text-align: justify;">Transistor 2N2222A + Buzzer</li>
</ul>
<div style="text-align: justify;">
For this tutorial we will choose a simple activity for each element and keep adding to the previous activity. Keep in mind we are saying activity and not project as we are not building any project of great significance, we are rather focusing on 'how to'. You are expected to go step by step through the activities as some of the coding might build on the previous activity. So , Lets get started!<br />
<br />
Download the following zip file with the source code for all these examples.<br />
<a href="http://downloads.simplelabs.co.in/Quick_Start_Kit.zip" target="_blank">Quick_Start_Kit.zip</a></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<b>The Breadboard</b></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The Breadboard is a simple construction base for building circuits without soldering. you can plug in different components and plug in wires between them. The top two rails and the bottom two rails are called the power rails and these are marked with a '+' and '-' symbol. These are connected as rows. Each row of connection consists of 5 groups of 5 points each per group. There is no connection between the 5th and the 6th group so the points is group 1 to 5 are connected and the points in group 6-10 are connected. we can connect a wire between any 2 two points of these groups and get them all connected. [This could be confusing if you have never used a breadboard before, we will try and make it easier soon!] </div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
We would need to get all our '+' lines connected to each other and then do the same for the '-' lines. This will make it easy for us to connect various components. Its a good practice stick to color coding for wires. Use red colored wires whenever you connect something to '+' ve, black<span class="Apple-style-span" style="text-align: left;"> colored wires whenever you connect something to '-' ve and blue colored wires whenever you are connecting between components.</span></div>
<div style="text-align: justify;">
<div style="text-align: justify;">
<span class="Apple-style-span" style="text-align: left;"><br /></span></div>
</div>
<div style="text-align: justify;">
<div style="text-align: justify;">
<span class="Apple-style-span" style="text-align: left;">So first set up the breadboard as in the following images</span></div>
</div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: justify;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXq2LesBfgH1n4joeZhd9ZuzLXhCfY-19cTOFhSPVnrSwR2blbKUpA8uA_af-FnSX93ElXJB9BT-WkRJvi-t6IGlabIafvoiB9raa8ZZ-7PxLeQTBWP6r8xQbuX-Fiq9oZx5feGNZF8b64/s1600/breadboard2.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXq2LesBfgH1n4joeZhd9ZuzLXhCfY-19cTOFhSPVnrSwR2blbKUpA8uA_af-FnSX93ElXJB9BT-WkRJvi-t6IGlabIafvoiB9raa8ZZ-7PxLeQTBWP6r8xQbuX-Fiq9oZx5feGNZF8b64/s320/breadboard2.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>First Like This</b></td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuKWD0zmotQTLkLaT7OAbfmkFldwCVNW_knjT-r5yd86OGWu12QrBRyHT7V0NfITHCoQC3Ms6omNbK6aiFZXD60_NpU9q1t91mn1_Yl0B4xr9y-pr6kEBVEy9pDPwPVFhCA8SAWhJh0jAY/s1600/breadboard3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuKWD0zmotQTLkLaT7OAbfmkFldwCVNW_knjT-r5yd86OGWu12QrBRyHT7V0NfITHCoQC3Ms6omNbK6aiFZXD60_NpU9q1t91mn1_Yl0B4xr9y-pr6kEBVEy9pDPwPVFhCA8SAWhJh0jAY/s400/breadboard3.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>Then Like This</b></td></tr>
</tbody></table>
<div style="text-align: left;">
</div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhk5E3QY6LXWIS0sEmZxWotq1VqEaqMoD4tDXzijiCVfgj_gEW_3OhbVrG1KBonOMG2vQV1IpNY4NBNMYHUVyb2Q8-XbhzIBXF0rrwBAJVVTODlRmve6RQ9D-ikVAKO-SoR6H3djpufS6mm/s1600/breadboard1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="233" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhk5E3QY6LXWIS0sEmZxWotq1VqEaqMoD4tDXzijiCVfgj_gEW_3OhbVrG1KBonOMG2vQV1IpNY4NBNMYHUVyb2Q8-XbhzIBXF0rrwBAJVVTODlRmve6RQ9D-ikVAKO-SoR6H3djpufS6mm/s640/breadboard1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="font-size: 13px;"><b>Final Finished Setup</b></td></tr>
</tbody></table>
<b style="text-align: justify;">The world of LEDS</b><br />
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
<br /></div>
</div>
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
LEDs (Light Emitting Diodes) are the
most commonly used of electronic components. They are everywhere –
torches, displays, indicators, etc. Every project will eventually end
up having atleast one led. The Official Arduino Boards and most of
the Clones do come with an on-board LED which you can try with the
default blink program found in the File->Examples->Basic menu
of Arduino IDE.</div>
</div>
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
<br /></div>
</div>
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
<b>So How to Connect a LED?</b></div>
</div>
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The Long of the LED is the Anode (Positive Terminal!) and the short led is the Cathode(Negative Terminal). </div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ9FQV_KsdLPDQOt9EI1NKG_aZzDdQhmgPl1UNENI0yHk_vUfvzx652juE8RlZHp92hjmav55rxVu0uv5WsvGT_PTKbwniHftg62eYcz0izJHxfhboDTkPpQDZcfTI33UP81WFa4EiHyk9/s1600/LED1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="553" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ9FQV_KsdLPDQOt9EI1NKG_aZzDdQhmgPl1UNENI0yHk_vUfvzx652juE8RlZHp92hjmav55rxVu0uv5WsvGT_PTKbwniHftg62eYcz0izJHxfhboDTkPpQDZcfTI33UP81WFa4EiHyk9/s640/LED1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Terminals of the LED</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQebzZAo9QJHhiuQShgs5TlIbVF95SFiOXHEm3u1kwRk0FC2Ghu7vp8aGTO5RvDeP3LrPjuefR_yZBJq9cqm358irfeoy_ObuxsglMssLaeMTnpXOrSxgu3jG8yIbF-Heri-MsQ8pRkv9z/s1600/LED2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="436" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQebzZAo9QJHhiuQShgs5TlIbVF95SFiOXHEm3u1kwRk0FC2Ghu7vp8aGTO5RvDeP3LrPjuefR_yZBJq9cqm358irfeoy_ObuxsglMssLaeMTnpXOrSxgu3jG8yIbF-Heri-MsQ8pRkv9z/s640/LED2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the LED as shown</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVNwFxlnsQJc7fa6OfextAdKN2GqeMlX-VM801LMWrlCpTwGO-MVke50hmzttCONiCHRxZJ4gLBqzwTgfAqFsJcPget0aZxForFqRNKQ-QgENXDruWPgM8q6A9M8MLQWFJYbvNnqolTc2-/s1600/LED3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="542" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVNwFxlnsQJc7fa6OfextAdKN2GqeMlX-VM801LMWrlCpTwGO-MVke50hmzttCONiCHRxZJ4gLBqzwTgfAqFsJcPget0aZxForFqRNKQ-QgENXDruWPgM8q6A9M8MLQWFJYbvNnqolTc2-/s640/LED3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place a Current Limiting Resistor (too much current passing through an LED can burn it!) between the negative terminal of the LED and the '-'ve terminal on the power rail (we will soon connect this to the '-'ve (aka ground) of our Arduino Board!)</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ahCx-dSWiGQjJr2GvThbMjVZSVI_YveLuJ0Cy30lDcU71eWZFKbsnuieb4DxrSyW-AsKsRUSQuDDuadSrPtJm4SKQYZ3DuA7Ws2Xk6N_1VvGfF5SNz6glbkPUEInlA-FG0AtR_KVCkdl/s1600/LED4.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6ahCx-dSWiGQjJr2GvThbMjVZSVI_YveLuJ0Cy30lDcU71eWZFKbsnuieb4DxrSyW-AsKsRUSQuDDuadSrPtJm4SKQYZ3DuA7Ws2Xk6N_1VvGfF5SNz6glbkPUEInlA-FG0AtR_KVCkdl/s640/LED4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Take a wire from the pin marked 'GND' of your arduino and connect it to the '-'ve power rail of the breadboard. Now all points of the '-' ve power rail will be connected to the ground of the arduino!</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsJnHdP97QPBhRP03UNHeaXxC_B09BBU0UY1YLiKth3OBXZ92zpMWUltnXLU51ngLyc_GaJLIN5XhApV5t_j_FtjnvXgtXXix0GL6T_s3A8FVGejOS_GMN3Oqsx5kHYMv7-mgLKeM0w24H/s1600/LED5.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsJnHdP97QPBhRP03UNHeaXxC_B09BBU0UY1YLiKth3OBXZ92zpMWUltnXLU51ngLyc_GaJLIN5XhApV5t_j_FtjnvXgtXXix0GL6T_s3A8FVGejOS_GMN3Oqsx5kHYMv7-mgLKeM0w24H/s640/LED5.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Next, Connect a wire between the 11th pin of the arduino(yes the 11th pin and not the 13th pin!) and the positive terminal of the LED. This is going to be our control line for the LED</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: justify;">
<b>Programming to control the LED</b></div>
</div>
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
So how can you control a LED? Well there are only 2 ways to control an LED. you can either switch it ON / OFF or you can control the intensity with which it glows (Very much like a fan!). So lets see how to do the first control - ON/OFF (we can call this digital control! Very much 0s & 1s)</div>
</div>
<div style="margin-bottom: 0cm;">
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Try the following code. [Blink.ino]<br />
<pre> <span style="color: #7e7e7e;">/* </span>
<span style="color: #7e7e7e;"> Blink </span>
<span style="color: #7e7e7e;"> Turns on an LED on for one second, then off for one second, repeatedly. </span>
<span style="color: #7e7e7e;"> This example code is in the public domain. </span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #7e7e7e;">// initialize the digital pin as an output. </span>
<span style="color: #7e7e7e;">// We have our LED connected to Pin 11 </span>
<span style="color: #cc6600;">pinMode</span>(11, <span style="color: #006699;">OUTPUT</span>); <span style="color: #7e7e7e;">// Sets the 11th pin as an Output pin</span>
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">digitalWrite</span>(11, <span style="color: #006699;">HIGH</span>); <span style="color: #7e7e7e;">// set the LED on </span>
<span style="color: #cc6600;">delay</span>(1000); <span style="color: #7e7e7e;">// wait for a second </span>
<span style="color: #cc6600;">digitalWrite</span>(11, <span style="color: #006699;">LOW</span>); <span style="color: #7e7e7e;">// set the LED off </span>
<span style="color: #cc6600;">delay</span>(1000); <span style="color: #7e7e7e;">// wait for a second </span>
}
</pre>
Next, Lets see how to control the intensity of the LED.</div>
<div style="text-align: justify;">
<br />
The Intensity can be varied by controlling the voltage applied to the individual pins. If you take a look at the 11th PIN on the arduino, you would see a marking 'PWM' next to it (Remember we connected our LED to the 11th pin).
The PWM pins in addition to generating digital HIGH / LOW signals can
generate analog voltages between 0 & 5.<br />
<br />
<div style="text-align: justify;">
The PWM Pins
[Pins 3,5,6,9,10,11] that can generate a PWM signal of 8-bit
resolution.[8-bits can represent a maximum value of 255, and a 8-bit
resolution here means that 5 volts is represented by 255 divisions. So
if you want to generate 1 volt, you would use the value 51]<br />
<br />
The analogWrite function will take a 8-bit numerical value as a
parameter [called duty cycle] and produce an output voltage
corresponding to this value. It will set the pin to generate a steady
square wave of the specified duty cycle at roughly 490Hz frequency.<br />
<br />
Finally, when using a pin in the PWM mode, we don't have to use the pinMode() function.<br />
<br />
<div style="text-align: justify;">
Try the following code with the same setup and see how the intensity increases and decreases...[Intensity.ino]<br />
<pre> <span style="color: #7e7e7e;">/* </span>
<span style="color: #7e7e7e;"> Intensity </span>
<span style="color: #7e7e7e;"> Increases the Intensity of a LED from 0 to maximum and on reaching maximum</span>
<span style="color: #7e7e7e;"> starts decreasing back to 0</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">while</span>(intensity < 255) <span style="color: #7e7e7e;">// Check if intensity has reached maximum value, if yes then exit the loop</span>
{
<span style="color: #cc6600;">analogWrite</span>(11,intensity);
<span style="color: #cc6600;">delay</span>(25);
intensity++;
}
<span style="color: #cc6600;">while</span>(intensity > 0) <span style="color: #7e7e7e;">// Check if intensity has reached minimum value, if yes then exit the loop</span>
{
<span style="color: #cc6600;">analogWrite</span>(11,intensity);
<span style="color: #cc6600;">delay</span>(25);
intensity--;
}
}
</pre>
<b><br /></b><br />
<b>The RGB LED</b><br />
<br />
The RGB led aka the tricolor led is a led that can help generate a multitude of colors by mixing red, blue & green colors. Its more like 3 leds (red, green & blue) put together into a single led.<br />
<br />
It has 4 pins with 1 of the pins being a common cathode and the other 3 pins acting as anodes for the 3 different colours. by varying the intensity of each of the 3 colours individually, we can generate various colours. This led is the same as 1 pixel of a LED TV!.<br />
<br />
Heres how to wire it up<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu0HFCv7mRN8ah1KPAyyQ1iBGtBzlL8mSvZgP_9XgD3XfotFo19V-Gjdo_Ag0xv57r0K92V_HneuSmmcZPEfAhW3SLcn3S2e7SEs3Xa7-8yM2QA0SE89NA84hfdg7PB6Sc9QlI73Qzgjee/s1600/RGB1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu0HFCv7mRN8ah1KPAyyQ1iBGtBzlL8mSvZgP_9XgD3XfotFo19V-Gjdo_Ag0xv57r0K92V_HneuSmmcZPEfAhW3SLcn3S2e7SEs3Xa7-8yM2QA0SE89NA84hfdg7PB6Sc9QlI73Qzgjee/s400/RGB1.jpg" width="233" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Pin Mappings of the RGB LED</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsi7qb0Og8HuaRAhwiU_lH05zox2aM5iwOSWYcIWkL7lTqQdGEhpE5hddgfoD269NOhlO3SElH10MCiDZFEggsGYtrbDGCe0m2ZKAb5DSCRODNVAJHhdmUtbq45BCasThc-2o5oiXKsmi3/s1600/RGB2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsi7qb0Og8HuaRAhwiU_lH05zox2aM5iwOSWYcIWkL7lTqQdGEhpE5hddgfoD269NOhlO3SElH10MCiDZFEggsGYtrbDGCe0m2ZKAb5DSCRODNVAJHhdmUtbq45BCasThc-2o5oiXKsmi3/s640/RGB2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place resistor between the common cathode and the '-'ve terminal</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZbrxdlqbCCwXMpM6ad2sXJZaPey1ahivnWJ3e_oW7Mz9V_7SHlRJrbRmNCRzbw-zIEzRh2rcLFrCEH-jXbX6i_jF9-Lk-7ym5vpLlBJ-R38HT42e7wwvFpmaSRoPzaTdy0s9rK7gWn6Oe/s1600/RGB3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZbrxdlqbCCwXMpM6ad2sXJZaPey1ahivnWJ3e_oW7Mz9V_7SHlRJrbRmNCRzbw-zIEzRh2rcLFrCEH-jXbX6i_jF9-Lk-7ym5vpLlBJ-R38HT42e7wwvFpmaSRoPzaTdy0s9rK7gWn6Oe/s640/RGB3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect RED to Pin 11, Blue to Pin 10 & Green to Pin 9 on the Arduino (these are PWM pins)</td></tr>
</tbody></table>
Now try the following code first. This code is a normal digital control of all the three colors separately.[RGB_Blink.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> RGB_Blink</span>
<span style="color: #7e7e7e;"> Turns on each of the color spectrums for 4 seconds, repeatedly.</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #7e7e7e;">// initialize the digital pins as an output.</span>
<span style="color: #cc6600;">pinMode</span>(11, <span style="color: #006699;">OUTPUT</span>);
<span style="color: #cc6600;">pinMode</span>(10, <span style="color: #006699;">OUTPUT</span>);
<span style="color: #cc6600;">pinMode</span>(9, <span style="color: #006699;">OUTPUT</span>);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">digitalWrite</span>(9,<span style="color: #006699;">LOW</span>);
<span style="color: #cc6600;">digitalWrite</span>(11, <span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;">delay</span>(4000);
<span style="color: #cc6600;">digitalWrite</span>(11, <span style="color: #006699;">LOW</span>);
<span style="color: #cc6600;">digitalWrite</span>(10, <span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;">delay</span>(4000);
<span style="color: #cc6600;">digitalWrite</span>(10, <span style="color: #006699;">LOW</span>);
<span style="color: #cc6600;">digitalWrite</span>(9, <span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;">delay</span>(4000);
}
</pre>
<br />
Next Lets get generating Colors, try the following code. Play around with the values and get yourselves comfortable.[RGB.ino]<br />
<pre><span style="color: #7e7e7e;">/* RGB</span>
<span style="color: #7e7e7e;"> Sets some random intensity value to the various colours of the RGB LED</span>
<span style="color: #7e7e7e;"> </span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>()
{
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>()
{
<span style="color: #cc6600;">analogWrite</span>(11,153);<span style="color: #7e7e7e;">// Setting the voltage for Blue to around 3 Volts </span>
<span style="color: #cc6600;">analogWrite</span>(10,51);<span style="color: #7e7e7e;">// Setting the voltage for Red to around 1 Volt </span>
<span style="color: #cc6600;">analogWrite</span>(9,51);<span style="color: #7e7e7e;">// Setting the voltage for Green to around 1 Volt </span>
}
</pre>
<b>The Push Button</b><br />
Push Buttons like LEDs form a common part of most electronics devices. Push buttons can be used to get user feedback. (image a common scenario of scrolling through a menu and selecting an option - there are buttons all around the process!)<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikq-YBfMjFSXJX8LNSOSOTxDcstCmlJPOYVSTir0EFM_oTkXi5WU-3NJC43TsApnbc_ZakqR0MSRrD_NFQa-EFfb3yTkmR6K31IY7pqvTaWUOp3cbH1I-r0oAw125xrNoQ0Xa9zBoIsjzZ/s1600/Button1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikq-YBfMjFSXJX8LNSOSOTxDcstCmlJPOYVSTir0EFM_oTkXi5WU-3NJC43TsApnbc_ZakqR0MSRrD_NFQa-EFfb3yTkmR6K31IY7pqvTaWUOp3cbH1I-r0oAw125xrNoQ0Xa9zBoIsjzZ/s640/Button1.jpg" width="540" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Working of a Push Button</td></tr>
</tbody></table>
<br />
So Far we have not used the SUPPLY voltage from the Arduino however, for connecting the button, we would need this. So, before connecting the Button, we need to connect our '+'ve terminal to the 5Volts SUPPLY line on the Arduino. Connect as shown in the image below.<br />
<br />
<div class="separator" style="clear: both; text-align: justify;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm7Wov3yiyThv7eCgGvguwPOM9Lvt5ePkfn_sH5PUd1_koC6In21ynU1rmcxMwqeBKtI7t0uFpjba9wGS9DLJWJj4Vyfey2DsBh0FgXtULEEEcPbJRnAjODaaLA33tNKKk_K4mBFBpgucP/s1600/power1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="290" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm7Wov3yiyThv7eCgGvguwPOM9Lvt5ePkfn_sH5PUd1_koC6In21ynU1rmcxMwqeBKtI7t0uFpjba9wGS9DLJWJj4Vyfey2DsBh0FgXtULEEEcPbJRnAjODaaLA33tNKKk_K4mBFBpgucP/s640/power1.jpg" width="640" /></a></div>
<br />
There are 2 ways to connect a Push Button to the arduino - the Pull-Down Configuration & the Pull-Up Configuration. We will take a look at both these.<br />
<br />
<b>The Pull-Down Cnfiguration</b><br />
In this configuration the Push Button is set-up such that it keeps giving a constant LOW signal(0) when not being pressed and gives a HIGH signal(1) when being pressed. To ensure that it keeps giving a LOW signal at all times, the Input line is also connect to the '-'ve terminal through a resistor. So in when the button is not being pressed, the input line stays connected to the GROUND. When the button is being pressed (and as the path of low resistance is always preferred) the input line gets connected to the SUPPLY line. Look at the following image to see how to connect a button in this configuration. We will keep this connection only as a reference as we will be using the Pull-Up configuration for our circuits.<br />
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQJOBr05M-zygjM0klJw6Ts2SCCeCG7p9I5GAqXXn8Bo1_qGfqSR9KmuFcLJdMr3rdMamyqn1fHRjEQlN-xk7jLakCwfyFDCyhpE9moBdxbg4TlOyVXp-o7e6VD4cSRz-LSNMHsDzin19a/s1600/Button2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="618" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQJOBr05M-zygjM0klJw6Ts2SCCeCG7p9I5GAqXXn8Bo1_qGfqSR9KmuFcLJdMr3rdMamyqn1fHRjEQlN-xk7jLakCwfyFDCyhpE9moBdxbg4TlOyVXp-o7e6VD4cSRz-LSNMHsDzin19a/s640/Button2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>The Pull-Down Configuration</b></td></tr>
</tbody></table>
<b>The Pull-UP Cnfiguration</b><br />
In this configuration the Push
Button is set-up such that it keeps giving a constant HIGH signal(1) when
not being pressed and gives a LOW signal(0) when being pressed. To
ensure that it keeps giving a HIGH signal at all times, the Input line is
also connect to the '+'ve terminal through a resistor. So in when the
button is not being pressed, the input line stays connected to the SUPPLY . When the button is being pressed (and as the path of low
resistance is always preferred) the input line gets connected to the GROUND line. Look at the following image to see how to connect a button
in this configuration. This is the most preferred method to connect a button.<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjIDy40YNHkS0Em4vaM2KeB5-JwxcAaAXLCsXvA-o8M7i8boyKN13ap7o3jU5q5_EwfBU9y7XpyQ6JGncZxV8DqRwuqiUqZ_bZ3nGXKyvsZeRvgvwlPcTxGzkDXm0pwIjw9e_odJR44sMH/s1600/Button3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="418" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjIDy40YNHkS0Em4vaM2KeB5-JwxcAaAXLCsXvA-o8M7i8boyKN13ap7o3jU5q5_EwfBU9y7XpyQ6JGncZxV8DqRwuqiUqZ_bZ3nGXKyvsZeRvgvwlPcTxGzkDXm0pwIjw9e_odJR44sMH/s640/Button3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b>The Pull-Up Configuration</b></td><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
Now try the following code, Pressing the Button increases the intensity of one colour at a time, once the maximum intensity of the colour is reached that colour is set to 0 and the intensity of the next colour starts increasing [ RGB_Button.ino]<br />
<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> RGB_Button</span>
<span style="color: #7e7e7e;"> Pressing the Button increases the intensity of one colour at a time, once the maximum intensity of the colour is reached</span>
<span style="color: #7e7e7e;"> that colour is set to 0 and the intensity of the next colour starts increasing</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0, pin = 9;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;">pinMode</span>(2,<span style="color: #006699;">INPUT</span>); <span style="color: #7e7e7e;">// This is the pin to which we have connected the button</span>
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0) <span style="color: #7e7e7e;">// check if the button is being pressed</span>
{
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(<span style="color: #006699;">"here"</span>);
<span style="color: #cc6600;">if</span>(intensity < 255)
{
intensity++;
}
<span style="color: #cc6600;">else</span>
{
intensity=0;
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
<span style="color: #cc6600;">if</span>(pin<11)
pin++;
<span style="color: #cc6600;">else</span>
pin=9;
}
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
}
}
</pre>
Here's the Output<br />
<br />
<div class="separator" style="clear: both; text-align: justify;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrFDwygqslEFksUtat-TS86GKjYT3Db8rT19i4XyVrZuqWyb5EG2dQGUdU0zVwFbw3VpX65ZVMed0MT4KwAhrR4PCGmdyQHy8S9YWrwzTtExEmheXmUdysl1s50iHtA6hd6oxkb3ho2gHc/s1600/Button4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="448" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrFDwygqslEFksUtat-TS86GKjYT3Db8rT19i4XyVrZuqWyb5EG2dQGUdU0zVwFbw3VpX65ZVMed0MT4KwAhrR4PCGmdyQHy8S9YWrwzTtExEmheXmUdysl1s50iHtA6hd6oxkb3ho2gHc/s640/Button4.jpg" width="640" /></a></div>
<u><br /></u><br />
<b>Trimpot</b><br />
Trimpots are used for getting variable / adjustable user inputs. Common example of a trimpot is the volume knob of your stereo player, Tuning knob of the radio, etc.<br />
<br />
A Trimpot aka variable resistor has three pins and an adjustment screw. A Trimpot acts as a potential divider and gives an output voltage on the 2nd pin. This output voltage is in-between the voltages supplied to the 1st and 3rd pins. The output voltage can be varied by adjusting the screw. The 1st and 3rd pins are connected to SUPPLY / GROUND and the middle pin is connected to Analog Input 0 on the arduino using a wire.<br />
<br />
Connect the trimpot as shown in the images below<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSL2dRvKkUmNshMQSq8TzaUKG5QM8MmlVkwLbibK7bCtL7JLRJcL4TYaOYNkltUolDJJSn2NZb2Knt6ZMM7K6vjl3WNTIkeFhYg90WLpwzwOsTg5yNGRM7Rlif3sci3yzDKNLOEJPyPGMu/s1600/trimpot1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSL2dRvKkUmNshMQSq8TzaUKG5QM8MmlVkwLbibK7bCtL7JLRJcL4TYaOYNkltUolDJJSn2NZb2Knt6ZMM7K6vjl3WNTIkeFhYg90WLpwzwOsTg5yNGRM7Rlif3sci3yzDKNLOEJPyPGMu/s400/trimpot1.jpg" width="361" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Trimpot - See the markings for pins</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghBkLYkiGHjszf5oesmuMd3Xhq-TT8zgobCKcseFyTVvMscqvTBw6eT1aRXMK5Qgxz8AhNzjclttRoObtKVhKxuk1WwUMfkNhqgjGjSoUnePrFspLXo6DxClu6JYbA_smO-TBX-D0Py4zl/s1600/trimpot2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="434" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghBkLYkiGHjszf5oesmuMd3Xhq-TT8zgobCKcseFyTVvMscqvTBw6eT1aRXMK5Qgxz8AhNzjclttRoObtKVhKxuk1WwUMfkNhqgjGjSoUnePrFspLXo6DxClu6JYbA_smO-TBX-D0Py4zl/s640/trimpot2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the trimpot as shown</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9HMw-F5-nb6U2Cp9mjTjZCVG_LZSjBscSzWGmRc2pjaZ9U3Db6LXacaW8JOTerywlvCT_qpWDU1HP3o-YS0lEKU-xfq08MfaaCD8lJX2vNm_RdCjFiSTih5DjGGf0eIPp7RFDLo32rMW2/s1600/trimpot3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="358" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9HMw-F5-nb6U2Cp9mjTjZCVG_LZSjBscSzWGmRc2pjaZ9U3Db6LXacaW8JOTerywlvCT_qpWDU1HP3o-YS0lEKU-xfq08MfaaCD8lJX2vNm_RdCjFiSTih5DjGGf0eIPp7RFDLo32rMW2/s640/trimpot3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between pin 1 of the trimpot and the '+'ve terminal</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr0LaXRs2LCzWFG1pbsGVhm25D-AdDwQQWEZWai9wW64rnxKl9gxx1k7b20HPaWNalsKNFDY9uOBq0j952IluhbbNnWwIlVwv7aQDO5xui2bpyor2UgkWtBf-OTrNqhFtyisAC-KlJE3S2/s1600/trimpot4.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="336" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr0LaXRs2LCzWFG1pbsGVhm25D-AdDwQQWEZWai9wW64rnxKl9gxx1k7b20HPaWNalsKNFDY9uOBq0j952IluhbbNnWwIlVwv7aQDO5xui2bpyor2UgkWtBf-OTrNqhFtyisAC-KlJE3S2/s640/trimpot4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between pin 3 of the trimpot and the '-'ve terminal</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlNI0OS4gaXivIFQce4T-WjCcSKlXg5tXGbt9K54yzMQax7WN_35M0whwodtkgoQ2vjvXcJWkhKnDwcXb0k6In1UPpjegJdwg_LyayrMGE7Fd6Czd6xdJxWvAiHumbK30-OVnTc37VjrCl/s1600/trimpot5.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlNI0OS4gaXivIFQce4T-WjCcSKlXg5tXGbt9K54yzMQax7WN_35M0whwodtkgoQ2vjvXcJWkhKnDwcXb0k6In1UPpjegJdwg_LyayrMGE7Fd6Czd6xdJxWvAiHumbK30-OVnTc37VjrCl/s640/trimpot5.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect a wire between pin 2 of the trimpot and the Analog In 0 of the Arduino</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHsvqr5e0gDlOyp7A81VvVwvKfpest2Ccdrt5D6hyphenhyphen9tZ75_e6vgwE1fv_jh9LlBDakZ3Seo8Ei9b1gdsB6xGv2oTQI2I5WyRW4Eo98ndut4CZ7xEytc5afeID9XFV5ZbaUeligWZ7Ihaur/s1600/trimpot6.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="408" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHsvqr5e0gDlOyp7A81VvVwvKfpest2Ccdrt5D6hyphenhyphen9tZ75_e6vgwE1fv_jh9LlBDakZ3Seo8Ei9b1gdsB6xGv2oTQI2I5WyRW4Eo98ndut4CZ7xEytc5afeID9XFV5ZbaUeligWZ7Ihaur/s640/trimpot6.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Here is the connection going to the Analog In 0</td></tr>
</tbody></table>
The Analog Input pins on the Arduino let you connect sensors and other analog devices like trimpots that product a voltage output in the range of 0-5 volts. The Analog input on Arduino is of 10-bit resolution. 10-bit
resolution means that the Voltage range of 0-5 Volts is represented in
1024 steps from 0-1023. So you would be reading an input value in the
range of 0-1023 where 1023 would correspond to 5 Volts<br />
<br />
Arduino[the IDE!] comes with a serial library
that can be used to transmit data serially to a computer. We shall make
use of this library to transmit our trimpot value to a Computer every 1
second. You can open the 'Serial Monitor' in the Arduino IDE to view these values. You can open the 'Serial Monitor' by going to the 'Tools' menu. When using the 'Serial Monitor' ensure that the baud rate selected is the same as the one used in the program.<br />
<br />
Try the following program and see the values you get by varying the trimpot [ simple_trimpot.ino]<br />
<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> A Simple Program to display the value read from the trimpot onto the Serial Monitor</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
intensity = <span style="color: #cc6600;">analogRead</span>(0);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Current Value:"</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(intensity);
}
</pre>
<pre></pre>
If you notice, you will see values from 0-1023. Now we are going to use the trimpot as part of our previous experiment. We will use the button to select the active color of the RGB LED and then use the trimpot to set the intensity of that color. Remember that this would involve scaling 0-1023 to 0-255 (or divide by 4!)<br />
<br />
Try the following program [RGB_button_trimpot.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> Pressing the Button changes the current active color of the RGB LED and varying the trimpot changes the intensity of the color</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0, pin = 9;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;">pinMode</span>(2,<span style="color: #006699;">INPUT</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0) <span style="color: #7e7e7e;">// Switch being pressed</span>
{
<span style="color: #cc6600;">if</span>(pin<11)
pin++;
<span style="color: #cc6600;">else</span>
pin=9;
<span style="color: #cc6600;">analogWrite</span>(9,0);
<span style="color: #cc6600;">analogWrite</span>(10,0);
<span style="color: #cc6600;">analogWrite</span>(11,0);
<span style="color: #cc6600;">while</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0);
<span style="color: #cc6600;">delay</span>(100);
}
intensity = <span style="color: #cc6600;">analogRead</span>(0)/4; <span style="color: #7e7e7e;">// Scaling the input resolution to match with our output resolution.</span>
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(pin);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(intensity);
}
</pre>
Heres the final setup and the output!<br />
<br />
<div class="separator" style="clear: both; text-align: justify;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUFCi3jy2Cewd4JO5VEwmHnaqQ45BD84anNScQ1jKi9xpHaCWnKfzjmIXzi2bFPdCHCX29JaHV4hQBjogRXV8pj6d8wxG1KLZ4xJAM4SiQe9WsdDuyhTTCO8m0w47fCjaAvF5PojuirWDR/s1600/trimpot7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="628" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUFCi3jy2Cewd4JO5VEwmHnaqQ45BD84anNScQ1jKi9xpHaCWnKfzjmIXzi2bFPdCHCX29JaHV4hQBjogRXV8pj6d8wxG1KLZ4xJAM4SiQe9WsdDuyhTTCO8m0w47fCjaAvF5PojuirWDR/s640/trimpot7.jpg" width="640" /></a></div>
<br />
<b>Working with Sensors - LM35</b><br />
<br />
So lets get started with some sensors, LM35 is a simple temperature sensor. LM35 has 3 pins. Refer to the following image for the pin mappings<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFOx0RIPwpRmxg9wm5hYQAFj0vENHDfTbCeI_9aFP6fOff6GuPEzjWy5M0R5r-Fkt8-BvviAaT3L6YTulomvsmFL4DT8xihUbC4PM2M26eSAmsfajmMnOBfh2CNYFQGxwGCyhqV-oab0Ik/s1600/LM35_1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="521" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFOx0RIPwpRmxg9wm5hYQAFj0vENHDfTbCeI_9aFP6fOff6GuPEzjWy5M0R5r-Fkt8-BvviAaT3L6YTulomvsmFL4DT8xihUbC4PM2M26eSAmsfajmMnOBfh2CNYFQGxwGCyhqV-oab0Ik/s640/LM35_1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">This is the LM35 as it looks</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiF9puuLfNrASUxFL2vBavJ0-YcWlrfK14O-NsGVOiWehHfNGV6cfyb0_4sBj7OHZBIzwpzh_WmgM6ZJN6MDZBdpym_apLW6M8-sExE_cc1Gff19eIHz_GSL6C_YHINokpTbRrG2Wu-wDB0/s1600/LM35_0.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiF9puuLfNrASUxFL2vBavJ0-YcWlrfK14O-NsGVOiWehHfNGV6cfyb0_4sBj7OHZBIzwpzh_WmgM6ZJN6MDZBdpym_apLW6M8-sExE_cc1Gff19eIHz_GSL6C_YHINokpTbRrG2Wu-wDB0/s400/LM35_0.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The LM35 pin Mapping. Note: The image on the left is a BOTTON view. This is how you will find it in the Product Datasheet<span class="Apple-style-span" style="font-size: small;"> </span></td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNCP2rJLxkYaV4vpxaDUHZV25XMFuWTyF48TppEg9e8olDsSN2txmjdYz8pEYDifOSbMv6Fmh68C5YdM4S7TWZX_ZXJ4zHBR05AA7h6uba-6SNaCTBQH5XFdGPaylkEEv6-mKhbJ6BJVuq/s1600/LM35_2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="444" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNCP2rJLxkYaV4vpxaDUHZV25XMFuWTyF48TppEg9e8olDsSN2txmjdYz8pEYDifOSbMv6Fmh68C5YdM4S7TWZX_ZXJ4zHBR05AA7h6uba-6SNaCTBQH5XFdGPaylkEEv6-mKhbJ6BJVuq/s640/LM35_2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the LM35 as shown</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvzrLc4f653QrioY3zSFEqqPb3ZHJAmEdWEWrpN2ky7IwTs5ailIA_ewCLgHByAz5RieblALj0J8jyY_Ap7DHN6C8UQKHJpJv_NQtWenyaPMK_vVJwZs6fh760DnqE8XfJwmCBr8R8Fvi2/s1600/LM35_3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="414" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvzrLc4f653QrioY3zSFEqqPb3ZHJAmEdWEWrpN2ky7IwTs5ailIA_ewCLgHByAz5RieblALj0J8jyY_Ap7DHN6C8UQKHJpJv_NQtWenyaPMK_vVJwZs6fh760DnqE8XfJwmCBr8R8Fvi2/s640/LM35_3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect Wires to Supply & Ground. Take a wire from the middle pin and connect it to Analog In 2 of the Arduino</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><img border="0" height="332" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLN_nei4M5ZHgA08enTYR1VFsPP5F2SdwR86W0-6uW3XLB06-DY6YrkFGx5jxKeOBqvd0HtftaQ3VTGJGBSOAB8A8uFBrMTU6APq8h-zPbqwsRmvIBg9fFVlWwjKTfWKDKh8aGqVWbE9mp/s640/LM35_4.jpg" style="margin-left: auto; margin-right: auto;" width="640" /></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Heres the finished Setup</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLN_nei4M5ZHgA08enTYR1VFsPP5F2SdwR86W0-6uW3XLB06-DY6YrkFGx5jxKeOBqvd0HtftaQ3VTGJGBSOAB8A8uFBrMTU6APq8h-zPbqwsRmvIBg9fFVlWwjKTfWKDKh8aGqVWbE9mp/s1600/LM35_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLN_nei4M5ZHgA08enTYR1VFsPP5F2SdwR86W0-6uW3XLB06-DY6YrkFGx5jxKeOBqvd0HtftaQ3VTGJGBSOAB8A8uFBrMTU6APq8h-zPbqwsRmvIBg9fFVlWwjKTfWKDKh8aGqVWbE9mp/s1600/LM35_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a><br />
Now time for the program. Try the following program. Pressing the Button changes the current active color of the RGB LED & prints the current temperature value to the Serial Monitor and varying the trimpot changes the intensity of the color [RGB_button_lm35.ino]<br />
<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> Pressing the Button changes the current active color of the RGB LED & prints the current temperature value to the Serial Monitor</span>
<span style="color: #7e7e7e;"> and varying the trimpot changes the intensity of the color</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0, pin = 9;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;">pinMode</span>(2,<span style="color: #006699;">INPUT</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0) <span style="color: #7e7e7e;">// Switch being pressed</span>
{
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Temperature is : "</span>);
<span style="color: #cc6600;">int</span> temp = <span style="color: #cc6600;">analogRead</span>(2)/2;
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(temp);
<span style="color: #cc6600;">if</span>(pin<11)
pin++;
<span style="color: #cc6600;">else</span>
pin=9;
<span style="color: #cc6600;">analogWrite</span>(9,0);
<span style="color: #cc6600;">analogWrite</span>(10,0);
<span style="color: #cc6600;">analogWrite</span>(11,0);
<span style="color: #cc6600;">while</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0);
<span style="color: #cc6600;">delay</span>(100);
}
intensity = <span style="color: #cc6600;">analogRead</span>(0)/4;
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(pin);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(intensity);
}
</pre>
<br />
<b>LDR - Light Dependent Resistor - A Simple Light Sensor</b><br />
The LDR is a variable resistor, whose resistance varies based on the light incident upon it. More the light, less the resistance. Now the LDR cannot be used directly. We would need to convert the change in resistance of the ldr to change in voltage. We can achieve this by constructing a potential divider using the ldr and a fixed resistor. Then we can take the output of the potential divider and connect it to an Analog In pin on the arduino.<br />
<br />
Follow the images below and connect the LDR<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdMtp82S95XR9PggZAVPx5N3a5Tj5t4WIR_enLSU7P25OFunBcVOuqLVAIHsA0ZvYnfMI0ojs06FJiA0lknK7KsHNILOAr4tqLupcI25xQki40e0lqrUlm-oaHb05y0DnZhikz1nNDLR06/s1600/LDR1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="496" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdMtp82S95XR9PggZAVPx5N3a5Tj5t4WIR_enLSU7P25OFunBcVOuqLVAIHsA0ZvYnfMI0ojs06FJiA0lknK7KsHNILOAr4tqLupcI25xQki40e0lqrUlm-oaHb05y0DnZhikz1nNDLR06/s640/LDR1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">This is the LDR</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLpxiVqdN5YGgCBFvBOkjaJUP_wezXw-Yi_KZoyWsz5eoE1uRVcIKLtFsf9j7svAHACTiW5a6Dd2rFN0uZjm7AUk4RBZezy1yVBGG88b103mHgnm3Taq9Y1aUXgMRz2WAVOc-8CC7-rcCZ/s1600/LDR2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="474" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLpxiVqdN5YGgCBFvBOkjaJUP_wezXw-Yi_KZoyWsz5eoE1uRVcIKLtFsf9j7svAHACTiW5a6Dd2rFN0uZjm7AUk4RBZezy1yVBGG88b103mHgnm3Taq9Y1aUXgMRz2WAVOc-8CC7-rcCZ/s640/LDR2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Place the LDR as shown and connect a resistor as shown</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhknR5IVuKmJm8edQfSdPVJ-GXmwGx0oy1Otut91LOf56m-iLsL4RBkP-RpDttiGlejBypq0xFLcU-8Aril8ObPE10P01sdbXzwvBgil0bfQhBOQ8JCKjcb6ICu-VIh-NFrliGcAcyiHIVE/s1600/LDR3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="470" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhknR5IVuKmJm8edQfSdPVJ-GXmwGx0oy1Otut91LOf56m-iLsL4RBkP-RpDttiGlejBypq0xFLcU-8Aril8ObPE10P01sdbXzwvBgil0bfQhBOQ8JCKjcb6ICu-VIh-NFrliGcAcyiHIVE/s640/LDR3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Connect Supply & Ground. Take a Wire from the Junction of the Resistor & LDR and connect it to Analog In 4 of the Arduino</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_8VMw5wUlUVdu1oURMXSTsnb_qpBvkh4dM1lYdvedy3bJbL4km0msAjWHW1iBS1YFlX9vtRQZAtCtnykrRDHyb6Ui6JvfdRT6OhgfUYB-T51lADocaJu7mnmxj4iZ4IzBpEmtfsQcKBVw/s1600/LDR4.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="272" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_8VMw5wUlUVdu1oURMXSTsnb_qpBvkh4dM1lYdvedy3bJbL4km0msAjWHW1iBS1YFlX9vtRQZAtCtnykrRDHyb6Ui6JvfdRT6OhgfUYB-T51lADocaJu7mnmxj4iZ4IzBpEmtfsQcKBVw/s640/LDR4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Here is how the Finished Setup will look like</td></tr>
</tbody></table>
Try the following Code [RGB_button_ldr.ino]<br />
<pre><span style="color: #7e7e7e;">/* </span>
<span style="color: #7e7e7e;">Pressing the Button changes the current active color of the RGB LED & prints the current temperature value to the Serial Monitor </span>
<span style="color: #7e7e7e;">and the light intensity detected by the LDR determines the intensity level of the active color </span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span>(<span style="color: #cc6600;">digitalRead</span>(2
<span style="color: #cc6600;">int</span> intensity = 0, pin = 9;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;">pinMode</span>(2,<span style="color: #006699;">INPUT</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
}
voi
d)==0) <span style="color: #7e7e7e;">// Switch being pressed </span>
{
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Temperature is : "</span>);
<span style="color: #cc6600;">int</span> temp = <span style="color: #cc6600;">analogRead</span>(2)/2;
nalogWrite(10,0);
an
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(temp);
<span style="color: #cc6600;">if</span>(pin<11)
pin++;
<span style="color: #cc6600;">else</span>
pin=9;
<span style="color: #cc6600;">analogWrite</span>(9,0);
aalogWrite(11,0);
<span style="color: #cc6600;">while</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0);
<span style="color: #cc6600;">delay</span>(100);
}
intensity = <span style="color: #cc6600;">analogRead</span>(4)/4;
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(pin);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(intensity);
}
</pre>
<b>Generating Sound - Buzzer + Transistor</b><br />
<br />
Next lets see how we can generate sound using a Buzzer. The Buzzer would require more current than provided by the pins of the arduino. To provide the buzzer with more current, we shall use a transistor to trigger the buzzer. The transistor in turn will be triggered by a pin on the arduino. If you do not know about transistors, its advisable you check it out <a href="http://en.wikipedia.org/wiki/Transistor" target="_blank"> http://en.wikipedia.org/wiki/Transistor</a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
Here's what our Transistor 2N2222A looks like<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6QlUVtOop8hEkwxyXkMXrRzFczMzLWVWRbsMhgzHu61hSJHXrztQLqXYP9ZAOGVIbJqEoAIySdY0advcmYeKX16lA3W7sdGD2BAW5H9VGMJcLR16GW7-z3CNi2YEPqX3E10q9NgZ3sWQ2/s1600/Tran1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto; text-align: center;"><img border="0" height="388" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6QlUVtOop8hEkwxyXkMXrRzFczMzLWVWRbsMhgzHu61hSJHXrztQLqXYP9ZAOGVIbJqEoAIySdY0advcmYeKX16lA3W7sdGD2BAW5H9VGMJcLR16GW7-z3CNi2YEPqX3E10q9NgZ3sWQ2/s640/Tran1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">2N2222A</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5_rKgDa69VSKtYUsJn-vhu9hotqwFCRPXvHR65InzsDP0C35SlJR5Skdo3b4GHz5snoY4LaDNtaOQ-LKAz_9dPEQ7hbv4kuwAG-FOHjTcn76xhyhVmSJjDtJdlr2YyJK9sBfgD98hAIOY/s1600/2n2222A.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="311" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5_rKgDa69VSKtYUsJn-vhu9hotqwFCRPXvHR65InzsDP0C35SlJR5Skdo3b4GHz5snoY4LaDNtaOQ-LKAz_9dPEQ7hbv4kuwAG-FOHjTcn76xhyhVmSJjDtJdlr2YyJK9sBfgD98hAIOY/s400/2n2222A.gif" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Pin Mappings for 2N2222A</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: justify;">
E = Emitter</div>
<div class="separator" style="clear: both; text-align: justify;">
B = Base</div>
<div class="separator" style="clear: both; text-align: justify;">
C = Collector </div>
<div class="separator" style="clear: both; text-align: justify;">
The Emitter of a transistor is connected to ground, the device to be triggered is connected between the Collector of the transistor and SUPPLY. The transistor can be triggered by Supplying a Trigger voltage to the Base (preferably through a resistor). Depending upon the trigger voltage, Emitter and Collector of a transistor get in contact thereby allowing current flow through the device connected.</div>
<div class="separator" style="clear: both; text-align: justify;">
<br /></div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie1rZ-wpftem843tfZmdjagtSO7LjiKjtgNzBz7iwmaLC0TZWKA1t-CFa-PHMcMhAuCTmvKOQAYfTHum6p2ccycwD_1M9ivUyrqDNY5BJZdEAV1pyTkLqAqAUBUzpJobB_PJpE4zOD1RoP/s1600/Buzzer1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="570" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie1rZ-wpftem843tfZmdjagtSO7LjiKjtgNzBz7iwmaLC0TZWKA1t-CFa-PHMcMhAuCTmvKOQAYfTHum6p2ccycwD_1M9ivUyrqDNY5BJZdEAV1pyTkLqAqAUBUzpJobB_PJpE4zOD1RoP/s640/Buzzer1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Buzzer - The Red Wire is Positive & The Blue Wire is Negative.<span class="Apple-style-span" style="font-size: small;"> </span></td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiahqMjv-27whoWUcCe5ixwjZIsfRra6jCWzsF1O7RUWWv_nYa1Fikq9R-8ToXntfeJdBbkMx3ulMafb3wWowFHMZWVcA4EmfReftMYtumfhQu94zbfYCFnN2V82fAjAYhx-9g41s9gobP_/s1600/Buzzer2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="466" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiahqMjv-27whoWUcCe5ixwjZIsfRra6jCWzsF1O7RUWWv_nYa1Fikq9R-8ToXntfeJdBbkMx3ulMafb3wWowFHMZWVcA4EmfReftMYtumfhQu94zbfYCFnN2V82fAjAYhx-9g41s9gobP_/s640/Buzzer2.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">First Setup the Transistor Side like in the Image</td></tr>
</tbody></table>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnvW5l6SLAFBgdldMFZds2t69Gmv5unb1k4mhAB-8gn_Y5kf7M1FRYky4BlRbdke4xh8OUL98IdRbknhkx5cUmsog2NNmg4XBmPspAH_Yo7YK8KSerZwy_v75eRRebK8nn7wY85dxxU49x/s1600/Buzzer3.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="428" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnvW5l6SLAFBgdldMFZds2t69Gmv5unb1k4mhAB-8gn_Y5kf7M1FRYky4BlRbdke4xh8OUL98IdRbknhkx5cUmsog2NNmg4XBmPspAH_Yo7YK8KSerZwy_v75eRRebK8nn7wY85dxxU49x/s640/Buzzer3.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Blue wire going to the Collector here is the Negative of the Buzzer and the Red wire (the Positive of the Buzzer ) is connected to the '+'ve terminal of the Breadboard</td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSlDDEt2Y4Pfp0iriFQlUTuR8qe7-4vKUVpztxSlN6sUPfInmpza12GkwhKgmYGoAWuhLzu32sUx32waHN9nQKwyN2jx3uDhPSPfe1XM40M__TbzKQLFjKk7vMYJ4Qsxn3WIkOoVuenqpC/s1600/Buzzer4.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="464" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSlDDEt2Y4Pfp0iriFQlUTuR8qe7-4vKUVpztxSlN6sUPfInmpza12GkwhKgmYGoAWuhLzu32sUx32waHN9nQKwyN2jx3uDhPSPfe1XM40M__TbzKQLFjKk7vMYJ4Qsxn3WIkOoVuenqpC/s640/Buzzer4.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Now Connect a Wire from the Other end of the Resistor to the 7th pin (digital) of the Arduino </td></tr>
</tbody></table>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTT0mbXli1en6-ZdGiTwx9t8is8YrOWMkCfWSw9thE8w9jtYibwbtpY-1LVRAngCc1k5XETUvHZSDVhT_aKRj42YpJjIaGFVml_EKCaWKLLdZOjdp0aq6nn0kZfONZZCwT40CfwereSVVV/s1600/Buzzer5.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="376" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTT0mbXli1en6-ZdGiTwx9t8is8YrOWMkCfWSw9thE8w9jtYibwbtpY-1LVRAngCc1k5XETUvHZSDVhT_aKRj42YpJjIaGFVml_EKCaWKLLdZOjdp0aq6nn0kZfONZZCwT40CfwereSVVV/s640/Buzzer5.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Here is how the Final Setup Looks Like</td></tr>
</tbody></table>
Try the following code where the Buzzer stays on as you keep pressing the Button in our previous program [RGB_button_ldr_buzzer.ino]<br />
<pre><span style="color: #7e7e7e;">/*</span>
<span style="color: #7e7e7e;"> Pressing the Button changes the current active color of the RGB LED & prints the current temperature value to the Serial Monitor and Generates a Buzzer tone </span>
<span style="color: #7e7e7e;"> for the duration the button is being pressed.</span>
<span style="color: #7e7e7e;"> The light intensity detected by the LDR determines the intensity level of the active color</span>
<span style="color: #7e7e7e;"> */</span>
<span style="color: #cc6600;">int</span> intensity = 0, pin = 9;
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>setup</b></span>() {
<span style="color: #cc6600;">pinMode</span>(2,<span style="color: #006699;">INPUT</span>);
<span style="color: #cc6600;">pinMode</span>(7,<span style="color: #006699;">OUTPUT</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">begin</span>(9600);
}
<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><b>loop</b></span>() {
<span style="color: #cc6600;">if</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0) <span style="color: #7e7e7e;">// Switch being pressed</span>
{
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">HIGH</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"Temperature is : "</span>);
<span style="color: #cc6600;">int</span> temp = <span style="color: #cc6600;">analogRead</span>(2)/2;
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(temp);
<span style="color: #cc6600;">if</span>(pin<11)
pin++;
<span style="color: #cc6600;">else</span>
pin=9;
<span style="color: #cc6600;">analogWrite</span>(9,0);
<span style="color: #cc6600;">analogWrite</span>(10,0);
<span style="color: #cc6600;">analogWrite</span>(11,0);
<span style="color: #cc6600;">while</span>(<span style="color: #cc6600;">digitalRead</span>(2)==0);
<span style="color: #cc6600;">delay</span>(100);
<span style="color: #cc6600;">digitalWrite</span>(7,<span style="color: #006699;">LOW</span>);
}
intensity = <span style="color: #cc6600;">analogRead</span>(4)/4;
<span style="color: #cc6600;">analogWrite</span>(pin,intensity);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(pin);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
<span style="color: #cc6600;"><b>Serial</b></span>.<span style="color: #cc6600;">println</span>(intensity);
}
</pre>
With that we come to the end of the first part of this tutorial.<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
</div>
</div>
</div>
</div>Simple Labshttp://www.blogger.com/profile/00881173225878503487noreply@blogger.com2tag:blogger.com,1999:blog-9038718253168000072.post-79331271254715476012011-11-24T20:49:00.000-08:002012-04-26T02:31:21.847-07:00Simple Labs' Quick Start Kit for Arduino - Kit Contents Overview<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
The Simple Labs' Quick Start kit was designed to help users get started with Arduino. The kit provides a whole lot of components that increase the experimentation possibility for the beginner. The kit is under constant revision to add different components that promise an increased learning value for the beginner while keeping the cost as low as possible.<br />
<br /></div>
<div style="text-align: justify;">
<span style="font-size: large;"><b>Current Kit Contents</b></span><br />
<span style="font-size: large;"><b><br /></b></span></div>
<div style="text-align: justify;">
<b>Tools of the Trade - Basic set of Tools Required by a beginner </b></div>
<div style="text-align: justify;">
Breadboard X 1Nos<br />
Aligner X 1Nos<br />
Wire Stripper X 1Nos<br />
Hookup Wires – Set X 1Nos</div>
<div style="text-align: justify;">
3 Pin RMC Connector X 1Nos</div>
<div style="text-align: justify;">
IC Adaptor X 1Nos<br />
<br /></div>
<div style="text-align: justify;">
</div>
<div style="text-align: justify;">
<b>Basic Components </b></div>
<div style="text-align: justify;">
Red LED X 3Nos<br />
Green LED X 3Nos<br />
Orange LED X 3Nos<br />
Push Buttons – Large X 5Nos<br />
Trimpot – 10K X 1Nos<br />
Resistors – Mixed X 25Nos<br />
Capacitors – Mixed X 15Nos<br />
Diodes – Mixed X 15Nos<br />
Transistor – 2N2222A X 1Nos<br />
<br /></div>
<div style="text-align: justify;">
<b>Display Components</b><br />
7-Segment LED X 3Nos<br />
RGB LED X 1Nos<br />
16 x 2 LCD Display X 1Nos<br />
<br /></div>
<div style="text-align: justify;">
<b>Sensors</b></div>
<div style="text-align: justify;">
IR Proximity Sensor X 1Nos<br />
LM35 – Temperature Sensor X 1Nos<br />
LDR – Light Sensor X 1Nos<br />
<br /></div>
<div style="text-align: justify;">
<b>Misc Components</b></div>
<div style="text-align: justify;">
Buzzer X 1Nos<br />
ULN2003 X 1Nos</div>
<div style="text-align: justify;">
<b><br />
Components for Extended Learning</b><br />
DS1307 RTC with Crystal X 1Nos<br />
74595 – Shift Register X 1Nos<br />
TSOP - Remote Control Receiver X 1Nos</div>
</div>Simple Labshttp://www.blogger.com/profile/00881173225878503487noreply@blogger.com8