tag:blogger.com,1999:blog-65408700805175465682024-03-05T15:34:28.421+01:00Rogier's Tinker ProjectsThings with Arduino'sAnonymoushttp://www.blogger.com/profile/07872324688604427960noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-6540870080517546568.post-26668303624295551932015-05-10T14:44:00.000+02:002015-05-10T14:51:24.279+02:00Arduino sending mobile Push notifications about front door<i>I wanted to be notified about people entering my house. This could be my neighbor to pick up the mail while being on a holiday, our cleaning lady when being at work or my spouse so I would know it was time to go home ;)</i><br />
<h2>
</h2>
<h3>
Why monitor entrance to your house?</h3>
My two main reasons for this project were:<br />
<ol>
<li>Security and control, when somebody would enter unexpectedly, I could ask somebody to go and take a look.</li>
<li>Because I can. >:)</li>
</ol>
<h2>
</h2>
<h3>
Two Arduino’s</h3>
I really like all the posibilties with <a href="http://www.arduino.cc/">Arduino</a>’s. For this project I used two Arduino’s.<br />
<h3>
</h3>
<h3>
Monitoring the door</h3>
One to be monitoring my door with a <a href="http://en.wikipedia.org/wiki/Reed_switch">reed contact sensor</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfeFwCPNEzAPZMkPF5JQgled3fUJIkIzgSTd5bHgPThLoBXeG5FT45Cup_ptkzS9ZS15UtYXJ6yp6r4pNtIIKvAVZUWbaKnzcAGH0DsuLUy4r895twafDKPu65iHLWmTtaUMwy458rkXeN/s1600/proximity-switch-60774-3861855.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfeFwCPNEzAPZMkPF5JQgled3fUJIkIzgSTd5bHgPThLoBXeG5FT45Cup_ptkzS9ZS15UtYXJ6yp6r4pNtIIKvAVZUWbaKnzcAGH0DsuLUy4r895twafDKPu65iHLWmTtaUMwy458rkXeN/s320/proximity-switch-60774-3861855.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<i>Reed contact sensor</i></div>
<br />
<br />
<br />
When the door is opened, the input pin goes <em>HIGH</em>, so my Arduino 'knows' the door is open. When closing the input goes <em>LOW</em> again. Let’s call this one the “Front-door Arduino”.<br />
<h3>
</h3>
<h3>
Connection to the internet</h3>
Because I don’t have a wired internet connection at my door, I used a second (Ethernet-)Arduino that was connected to my router. Let’s call this one the “Internet Arduino”.<br />
The Internet Arduino sends API calls to <a href="https://pushover.net/">Pushover</a>. Pushover makes it easy to send push notifications to your Android phone or iPhone.<br />
<h3>
</h3>
<h3>
RF-Link for wireless data communication</h3>
The front-door Arduino communicates with the Internet Arduino about the door status.<br />
For this connection I used two <a href="http://www.dfrobot.com/index.php?route=product/product&path=156_45_81&product_id=57">DFRobot APC220 Radio Communication Modules</a>. They make a perfectly stable serial connection between both ends.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmlVeAxOmiZIgmSMJAKFuIjAipb2_jMVo791CPMqBunQ7zJFB0CssO3zqyo4DuZyeYawAcBZj-tmeIyNezcVBUQ77BKF779-LmDWHOVfeQhVaQeSEx6oT-SQbQSWgzftucXjUc8GLLKNOW/s1600/dfrobot-rf-modules-pair-3-large.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="205" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmlVeAxOmiZIgmSMJAKFuIjAipb2_jMVo791CPMqBunQ7zJFB0CssO3zqyo4DuZyeYawAcBZj-tmeIyNezcVBUQ77BKF779-LmDWHOVfeQhVaQeSEx6oT-SQbQSWgzftucXjUc8GLLKNOW/s320/dfrobot-rf-modules-pair-3-large.jpg" width="320" /></a></div>
<br />
<br />
<figure><figcaption style="text-align: center;"><i>APC220 Radio Communication Modules</i></figcaption></figure>
<br />
Because of this separated setup, it also <strong>enhances security</strong>. When the <em>’intruder’</em> would tamper with the Front-door Arduino, the (hidden) Internet Arduino would notice and send me a push notification to tell me that there is something wrong with the setup.<br />
<h2>
</h2>
<h3>
Schematic</h3>
My Setup looks like this:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://docs.google.com/drawings/d/14CW2HyTsnna7obtu4YK4xMwC3MjxzvZ48uvaT5RvMMQ/pub?w=960&h=720" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://docs.google.com/drawings/d/14CW2HyTsnna7obtu4YK4xMwC3MjxzvZ48uvaT5RvMMQ/pub?w=960&h=720" width="640" /></a></div>
<br />
<h2>
</h2>
<h3>
Pushover</h3>
As you can see, the Internet Arduino sends a message to Pushover. You can make a free account there that allows you to send and receive push notifications on your mobile phone.<br />
<br />
In your Pushover account, you’ll find a userkey. Also register an ‘Application’, this will be your Arduino sending stuff. Pushover will give you an Application API token/key as well. You need those two values (userkey and API token).<br />
<h2>
</h2>
<h3>
Video</h3>
This works like a charm:<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/hsiiRwTY7gg/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/hsiiRwTY7gg?feature=player_embedded" width="320"></iframe></div>
<br />
<h2>
</h2>
<h3>
Source code</h3>
Do you want to build your own setup? Please let me help you with my source code:<br />
<br />
<ul>
<li>Front door Arduino: <a href="https://gist.github.com/rogiervandenberg/48b9b08df8c29d3fe5c4">https://gist.github.com/rogiervandenberg/48b9b08df8c29d3fe5c4</a></li>
<li>Internet Arduino: <a href="https://gist.github.com/rogiervandenberg/7219c67f3e74e9b79cd5">https://gist.github.com/rogiervandenberg/7219c67f3e74e9b79cd5</a></li>
</ul>
<br />
<h2>
</h2>
<h3>
Disadvantages</h3>
Right now, my Front door Arduino is consuming some power and I need a wire to an outlet to power my Arduino. There must be a smarter way to handle the ‘detecting’-part of this solution. I am working on this now. :)Anonymoushttp://www.blogger.com/profile/07872324688604427960noreply@blogger.com1tag:blogger.com,1999:blog-6540870080517546568.post-35670276038681616192013-08-09T16:45:00.000+02:002013-08-09T16:48:13.567+02:00Arduino Pomodoro TimerDo you want to work on something, fully focused? Maybe <a href="http://www.pomodorotechnique.com/">The Pomodoro Technique</a> can help you. It dictates that you work in blocks of 25-minutes.<br />
<br />
<h3>
Timer</h3>
<div>
Inspired by this concept, I made my own Pomodoro Timer, with an Arduino of course ;) I made a prototype, with a breadboarded Arduino and only a Lego casing around the display, but it could also be built into a proper case of course.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtvpe63LP2w4X_01n6kSfP7ElQDchGFvs0-yKZUq7KzRhImXzuX82y9Vi0kbaqH8SrqMvEzlTyIecs47mQpZ22DcpxrThOfR0siuEYqvx6UskmB00t0fZcbkUYmWaBmr_bUy9rwhpP7BcW/s1600/Screen+Shot+2013-08-09+at+16.23.26.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtvpe63LP2w4X_01n6kSfP7ElQDchGFvs0-yKZUq7KzRhImXzuX82y9Vi0kbaqH8SrqMvEzlTyIecs47mQpZ22DcpxrThOfR0siuEYqvx6UskmB00t0fZcbkUYmWaBmr_bUy9rwhpP7BcW/s400/Screen+Shot+2013-08-09+at+16.23.26.png" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
When connecting to power, it will automatically start counting down 25 minutes (default). When your time is up, you will hear a beep and the timer shuts its display down. With one press on the button and you can start a new session. When pressing the button multiple times, you can switch the count-down period.</div>
<div>
<br /></div>
<h3>
One button</h3>
<div>
The timer had to be super-easy to operate, so it only has <b>one</b> button. This button will make the timer:</div>
<div>
<ul>
<li>Reset the current session when already counting down;</li>
<li>Switch to a different count-down period (25 (default), 45, 5 or 15 minutes);</li>
<li>Start a new session when stopped.</li>
</ul>
<div>
<br /></div>
<h3>
Display</h3>
<div>
The display I used is a <a href="http://www.dfrobot.com/wiki/index.php/3-Wire_LED_Module_(SKU:DFR0090)">3-Wire LED Module from DFRobot</a>.<br />
<br /></div>
<h3>
Demonstration</h3>
<div>
<iframe allowfullscreen="" frameborder="0" height="297" src="//www.youtube.com/embed/yk0zJRWw_6c" width="528"></iframe>
</div>
<h3>
</h3>
<h3>
Source code</h3>
</div>
<div>
<a href="https://github.com/rogiervandenberg/pomodorotimer">Download the source code for the Arduino Pomodoro Timer</a></div>
Anonymoushttp://www.blogger.com/profile/07872324688604427960noreply@blogger.com0tag:blogger.com,1999:blog-6540870080517546568.post-35704152961290915842013-05-22T18:00:00.001+02:002013-05-22T18:23:57.414+02:00How to fix boot problems with Hynix Raspberry Pi<i>I fixed a way to make the new 512MB Model B Raspberry Pi with Hynix RAM work with images based on an older boot loader.</i><br />
<i><br /></i>
<br />
<h3>
Just a Red LED</h3>
Many users just have a "Red LED" and no further activity when using some images on their 512MB Raspberry Pi. When the Red LED lits and the green flashes briefly, there could be a problem with the version of the boot loader you are using.<br />
<br />
<h3>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiu9pTN7_guuSXLDPwXfzuUroJjqVYx1_nqOryd63v8njsErocOwHG4axExVi6M7Ktw-nMZagOfaCXreh-Xzk9uLk-nomnHTBGeDN_ix_aGaEVQUiJwaUnucXRFtr8Id90kYXkVmyECC7iF/s1600/R7568308-01.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiu9pTN7_guuSXLDPwXfzuUroJjqVYx1_nqOryd63v8njsErocOwHG4axExVi6M7Ktw-nMZagOfaCXreh-Xzk9uLk-nomnHTBGeDN_ix_aGaEVQUiJwaUnucXRFtr8Id90kYXkVmyECC7iF/s1600/R7568308-01.jpg" /></a>512MB model with Hynix RAM needs latest boot loader</h3>
Supposedly there are multiple versions of the 512MB Model B Raspberry Pi. I am having the lastest edition, with the new Hynix RAM. This might have advantages (newer is better?) but older boot loaders won't work on this one. Please also look at: <a href="http://www.raspberrypi.org/archives/3534">http://www.raspberrypi.org/archives/3534</a><br />
<br />
Because many 3rd party images are not based on the latest version of Raspbian (with the new boot loader), they won't work on these newer Raspberry Pi boards.<br />
<br />
<h3>
</h3>
<h3>
Is your Raspberry Pi working?</h3>
To determine whether your Pi is working in general, just make a "regular" latest version (<a href="http://downloads.raspberrypi.org/images/raspbian/2013-02-09-wheezy-raspbian/2013-02-09-wheezy-raspbian.zip">2013-02-09-wheezy-raspbian</a> in my case) SD card. See if your Pi starts as supposed to.<br />
<br />
<h3>
Yes? Let's migrate the boot loader</h3>
If your Raspberry Pi is working with the latest Raspbian, try the following steps:<br />
<h4>
Backup the Boot loader</h4>
If your Raspberry Pi is working OK with the above image, mount the SD card on your computer and backup the "bootcode.bin" and "start.elf" files.<br />
<h4>
Create your image</h4>
Make the image you want (I was working on a Ninjablocks SD card, with the image from <a href="http://wiki.ninjablocks.com/images#raspberry-pi">http://wiki.ninjablocks.com/images#raspberry-pi</a>).<br />
<h4>
Replace the boot loader</h4>
After creating the new image (that doesn't work, because of the wrong boot loader) replace the "bootcode.bin" and "start.elf" files with the ones from the Raspbian Wheezy backup.<br />
<br />
<h3>
That's it!</h3>
Now insert your SD Card in your Raspberry Pi, and it should work! At least, it did in my case :)Anonymoushttp://www.blogger.com/profile/07872324688604427960noreply@blogger.com0tag:blogger.com,1999:blog-6540870080517546568.post-58391352962612171262013-04-14T10:11:00.000+02:002013-05-22T19:30:54.891+02:00Setup a Raspberry Pi LAMP web server from scratch (without monitor, keyboard or mouse attached)<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVsu2nu4AAsRT9KwDq2g2wVkK86LC_So0yo-BTbV4-OIKjDAAycHee1kLR5a4VgFXgY6OJ4lH1XZBelbzCzL-ds9_OpksChxXj6WmD7T60em45nphJiyLr6AETg5DnVdN_fIh3yXsvyAUt/s1600/Raspi_Colour_R.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVsu2nu4AAsRT9KwDq2g2wVkK86LC_So0yo-BTbV4-OIKjDAAycHee1kLR5a4VgFXgY6OJ4lH1XZBelbzCzL-ds9_OpksChxXj6WmD7T60em45nphJiyLr6AETg5DnVdN_fIh3yXsvyAUt/s200/Raspi_Colour_R.png" width="165" /></a></div>
<br />
Friday I received my <a href="http://raspberrypi.org/">Raspberry Pi</a>. My intention is to use it as a webserver. When you receive a Raspberry Pi it doesn't do anything straight out of the box. In this blogpost I will give you an overview of how I set up my Raspberry Pi with just:<br />
<br />
<ul>
<li>The Raspberry Pi itself</li>
<li>A 4GB SD card</li>
</ul>
<div>
<br /></div>
<div>
So I never connected a screen, keyboard and mouse to it, to install it.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<h3>
</h3>
<h3>
Prepare the SD card</h3>
<div>
<a href="http://www.raspberrypi.org/downloads">Download the image</a> (I used the Raspbian “wheezy”) and put it to an SD card. To make this process easy I used the <a href="http://ivanx.com/raspberrypi/">Pi filler</a> (for Mac OS X 10.5 through 10.8). Read more on how to set up your SD card <a href="http://elinux.org/RPi_Easy_SD_Card_Setup">here</a>.</div>
<h3>
</h3>
<h3>
SSH to your Pi</h3>
<div>
Insert your prepared SD-card in your Raspberry Pi, connect your ethernet and hook it up to power. Your Raspberry Pi will boot.</div>
<div>
<br /></div>
<div>
Since the latest images SSH is enabled by default. This makes it possible to directly connect to your Raspberry Pi, without attaching a monitor, keyboard and mouse the first time.</div>
<div>
<br /></div>
<div>
You can find the IP-address of your Raspberry Pi in your router, or use a tool like <a href="http://ivanx.com/raspberrypi/">Pi Finder</a>.</div>
<div>
<br /></div>
<div>
If you open a terminal (e.g. Terminal on Mac) you can connect to your Raspberry Pi:</div>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">ssh pi@192.168.xxx.xxx</span></blockquote>
The default password is "raspberry".<br />
But to make life easier, you can copy your SSH certificate to the Raspberry Pi to make logging in very easy:<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">cat ~/.ssh/id_rsa.pub | ssh pi@192.168.xxx.xxx 'cat >> ~/.ssh/authorized_keys'</span></blockquote>
Just type the password one last time and you're done!<br />
After logging in, you can change the default password:<br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">sudo passwd pi <<<PASSWORD>>></span></blockquote>
<h3>
</h3>
<h3>
Basic Raspberry Pi config</h3>
<div>
Run the following, to configure your Raspberry Pi:</div>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">sudo raspi-config</span></blockquote>
<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/AVvXsEizwbRv0gE-6kTQ4dbS-CpeKeJhy22Hb4HigZQFVswsPXd2lesDOQwAGzOwVf-s-ZToiQ-z7QDuOTu_6TKqszSSCUXp6RF-V7GE8FBDi81qzmZakir9WzdY4WJ17LK3aKppY56aECEVOvGt/s1600/Screen+Shot+2013-04-14+at+09.56.31.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="245" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizwbRv0gE-6kTQ4dbS-CpeKeJhy22Hb4HigZQFVswsPXd2lesDOQwAGzOwVf-s-ZToiQ-z7QDuOTu_6TKqszSSCUXp6RF-V7GE8FBDi81qzmZakir9WzdY4WJ17LK3aKppY56aECEVOvGt/s400/Screen+Shot+2013-04-14+at+09.56.31.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">raspi-config</td></tr>
</tbody></table>
<div>
<br /></div>
<div>
I made the following settings:</div>
<div>
<ul>
<li>Expand_rootfs, to have more storage space (makes it possible to use the full SD card)</li>
<li>memory_split, changed it to 16, because I don't need graphical memory for my webserver. </li>
<li>boot_behaviour, "no", don't start the desktop</li>
<li>update, to update raspi-config</li>
</ul>
<h3>
</h3>
<h3>
Update Debian</h3>
</div>
<div>
To update Debian:</div>
<div>
<ul>
<li><span style="font-family: 'Courier New', Courier, monospace;">sudo dpkg-reconfigure tzdata</span></li>
<li><span style="font-family: 'Courier New', Courier, monospace;">sudo apt-get update</span></li>
<li><span style="font-family: 'Courier New', Courier, monospace;">sudo apt-get upgrade</span></li>
</ul>
</div>
<div>
<h3>
</h3>
<h3>
Install Git</h3>
</div>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">sudo apt-get install git-core</span></blockquote>
<h3>
</h3>
<h3>
Install automatic firmware updater and update</h3>
<div>
<ul>
<li><span style="font-family: Courier New, Courier, monospace;">sudo wget https://raw.github.com/Hexxeh/rpi-update/master/rpi-update -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update</span></li>
<li><span style="font-family: Courier New, Courier, monospace;">sudo rpi-update</span></li>
</ul>
<div>
Now the firmware and software are up to date, reboot the Pi:</div>
</div>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">sudo shutdown -r now</span></blockquote>
<div>
<h3>
</h3>
<h3>
Install Apache and PHP5</h3>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">sudo apt-get install apache2 php5 libapache2-mod-php5</span></blockquote>
<div>
If you want to enable all error reporting you could do stuff like this:</div>
<div>
<ul>
<li><span style="font-family: Courier New, Courier, monospace;">echo 'error_reporting = E_ALL' > /etc/php5/conf.d/error_reporting.ini</span></li>
<li><span style="font-family: Courier New, Courier, monospace;">echo 'display_errors = On' >> /etc/php5/cond./error_reporting.ini</span></li>
</ul>
</div>
<h3>
</h3>
<h3>
Install MySQL</h3>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">sudo apt-get install mysql-server mysql-client php5-mysql</span></blockquote>
<h3>
</h3>
<h3>
Restart Apache</h3>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">sudo service apache2 restart</span></blockquote>
<h3>
</h3>
<h3>
That's it!</h3>
<div>
Now you have a running webserver with PHP5 and MySQL. You can put your PHP files in /var/www/.</div>
</div>
Anonymoushttp://www.blogger.com/profile/07872324688604427960noreply@blogger.com0tag:blogger.com,1999:blog-6540870080517546568.post-64638090751036431742013-04-09T14:25:00.000+02:002013-08-09T17:00:51.163+02:00Arduino Facebook like-counter with 7 segment displayLast year I wanted to be able to follow the amount of likes on a website, but not by looking at a Facebook or the website itself. I made an IRL display with the amount of likes with an Arduino.<br />
<br />
<b>The case</b><br />
I created an PHP-script, using the Facebook API, checking the amount of likes and just outputting it. My Arduino would regularly check for the value outputted by my PHP script and display this on its display.<br />
<br />
<b>Requirements</b><br />
The stuff I used is:<br />
<br />
<ul>
<li><a href="http://arduino.cc/en/Main/ArduinoBoardEthernet">An Arduino Ethernet</a></li>
<li><a href="http://www.dfrobot.com/wiki/index.php?title=SPI_LED_Module_(SKU:DFR0090)">A 3-wire LED bar module from DF Robot</a> (bought it <a href="https://iprototype.nl/products/components/led-lcd/led-bar-8xsegment">at iPrototype</a>)</li>
</ul>
<br />
<b>Result</b><br />
Check this video for the results:<br />
<iframe allowfullscreen="" frameborder="0" height="297" src="//www.youtube.com/embed/5ugYnJFP5H0" width="528"></iframe>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
My Arduino code looks like this:<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#include <SPI.h></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#include <Ethernet.h></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// Enter a MAC address for your controller below.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// Newer Ethernet shields have a MAC address printed on a sticker on the shield</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">char serverName[] = "xxxxxxxx.nl"; //location of PHP script telling me the amount of likes</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">const int latchPin = 8;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">const int clockPin = 3;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">const int dataPin = 9;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">byte chars[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf,0xf7,0xfb,0xab,0x86}; //0-9," ", -, _,i,n,e</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// Initialize the Ethernet client library</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// with the IP address and port of the server </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// that you want to connect to (port 80 is default for HTTP):</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">EthernetClient client;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void setup() {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> pinMode(latchPin, OUTPUT);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> pinMode(dataPin, OUTPUT); </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> pinMode(clockPin, OUTPUT);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> //Put "ini" on the dis</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> digitalWrite(latchPin, LOW);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[13]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[14]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[13]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> digitalWrite(latchPin, HIGH);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // Open serial communications and wait for port to open:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> Serial.begin(9600);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> while (!Serial) {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ; // wait for serial port to connect. Needed for Leonardo only</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // start the Ethernet connection:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> if (Ethernet.begin(mac) == 0) {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> Serial.println("Failed to configure Ethernet using DHCP");</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> //Put "e" (error) on the dis</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> digitalWrite(latchPin, LOW);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[15]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> digitalWrite(latchPin, HIGH);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // no point in carrying on, so do nothing forevermore:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> while(true);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // give the Ethernet shield a second to initialize:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> delay(1000);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void loop()</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> checkOnlineStatus();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> delay(2000);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void checkOnlineStatus()</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> //Serial.println("connecting...");</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> boolean newLine = true;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> String line = "";</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> if (client.connect(serverName, 80)) {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> //Serial.println("connected");</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // Make a HTTP request:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> client.println("GET / HTTP/1.0");</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> client.println("Host: rogier.nu");</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> client.println();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">while(client.available()){</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> char c = client.read();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> //Serial.print(c);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // if you've gotten to the end of the line (received a newline</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // character) and the line is blank, the http request has ended,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // so you can send a reply</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> if (c == '\n' && newLine) {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> if (c == '\n') {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // you're starting a new line</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> newLine = true;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> line = "";</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> } </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> else if (c != '\r') {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // you've gotten a character on the current line</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> newLine = false;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> line += c; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> processLine(line);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // if the server's disconnected, stop the client:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> if (!client.connected()) {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> client.stop();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void processLine(String line)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> if(line.length() > 0) {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> //Serial.println("Verwerken:" + line);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> digitalWrite(latchPin, LOW);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> //Putting up the online value</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> for(int i=line.length()-1; i >= 0; i--)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> int bitToSet = (byte)line.charAt(i) - 48;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[bitToSet]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> //Putting up the leading zeroes</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> for(int i=0; i<8-line.length(); i++)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> shiftOut(dataPin, clockPin, MSBFIRST, chars[10]);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> digitalWrite(latchPin, HIGH);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<div>
<b>Improvements</b></div>
<div>
My sketch is relying on an external PHP-script, to make the Arduino code as simple as possible. A better way to do this is by having the Arduino make direct connections to Facebook, as is done in this project: <a href="http://www.skolti.com/lab/exp8/eng/">Facebook Like box</a></div>
Anonymoushttp://www.blogger.com/profile/07872324688604427960noreply@blogger.com2tag:blogger.com,1999:blog-6540870080517546568.post-47417742397569478902013-03-06T12:48:00.000+01:002015-04-21T17:42:24.996+02:00Control lights with an Arduino remotely with 433MhzI wanted to use Arduino's for a domotica project. The main purpose is to control the lights in my livingroom, using a web-interface. This way I can switch on and off my lights with my mobile phone, iPad, etc. even when I am not home (over the internet)!
Because making elektrical connections with Arduino's and the outlet power supply went wrong one time earlier (blew all the fuses!), I wanted to use secure standard components for the high-power part. So, I bought these:
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKDQO3xfp8n_Ly2VstckTybD9f1ey5MLo02sLZli35H2Y2bHz5NoSADYZ_a4E_txHXs56cTKU89ETHZMKio1ua5sx1eXaL9zHiZbUfTJsBYkfNK0nTpf6SpGsljSR2vaeV6ztONL6FC56R/s1600/Elro+plugs.jpg" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKDQO3xfp8n_Ly2VstckTybD9f1ey5MLo02sLZli35H2Y2bHz5NoSADYZ_a4E_txHXs56cTKU89ETHZMKio1ua5sx1eXaL9zHiZbUfTJsBYkfNK0nTpf6SpGsljSR2vaeV6ztONL6FC56R/s320/Elro+plugs.jpg" /></a><br />
<br />
<br />
This is a set containing of one transmitter and a couple receivers to wirelessly switch lights (plugged into the outlets) on or off.<br />
<br />
The Arduino has a 433 Mhz transmitter and receiver. This way I can listen to what is being broadcast, or I can send signals/codes myself. This is the one I am using: <a href="http://www.emartee.com/product/41357/">http://www.emartee.com/product/41357/</a><br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAtL060WRzrcBYYkjjI1KVsQnVW4ogey9CErGfSIUbH-zvcXQd-4AmZRSB48e8nPlzG-tAMa_tX9eyl7yP_Amy6Ui1K15iEvS88cwD6ZZ8JTJBaJwp0Bsmz27d9aVsum-7oxHj9ozKDu_n/s1600/RF+Transmitter+receiver.jpg" imageanchor="1"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAtL060WRzrcBYYkjjI1KVsQnVW4ogey9CErGfSIUbH-zvcXQd-4AmZRSB48e8nPlzG-tAMa_tX9eyl7yP_Amy6Ui1K15iEvS88cwD6ZZ8JTJBaJwp0Bsmz27d9aVsum-7oxHj9ozKDu_n/s320/RF+Transmitter+receiver.jpg" /></a><br />
<br />
I used my Arduino to "sniff" the sent signal from the transmitter to the receiver switching the lights. I did this for all on/off combinations for all lights.<br />
<br />
The Arduino is also equipped with an ethernet shield, so I can host a litte web application on it. I use this to be able to command my Arduino over the internet or my house network.<br />
<br />
So I have:<br />
<ul>
<li>An Arduino that "understands" the remote control and can learn from it;</li>
<li>The possibility to send signals myself as well;</li>
<li>A small web application running on the Arduino.</li>
</ul>
In the video below, you can see I am learning the codes from the original transmitter to my Arduino. After learning, I can use the web interface on the Arduino, to retransmit those codes, to switch my lights on and off!<br />
<br />
<iframe allowfullscreen="" frameborder="0" height="297" src="//www.youtube.com/embed/H__5nYFuY6A" width="528"></iframe>
<br />
<h3>
Useful links</h3>
<ul>
<li>To be able to send and receive the remote's signals, I used the <a _mce_href="http://randysimons.com/overige/browsable/433MHz/ArduinoRemoteSwitchLibrary.7z" href="http://randysimons.com/overige/browsable/433MHz/ArduinoRemoteSwitchLibrary.7z">RemoteSwitch library</a> as RF-library, check <a href="https://bitbucket.org/fuzzillogic/433mhzforarduino/wiki/Home">https://bitbucket.org/fuzzillogic/433mhzforarduino/wiki/Home</a></li>
<li>For the webserver on the Arduino, I used the <a _mce_href="http://code.google.com/p/webduino/" href="http://code.google.com/p/webduino/">Webduino Library</a>.</li>
<li>To store the learned codes, and be able to remember them (even after a reset of the Arduino), I store them in the EEPROM. An easy way to store stuff in the EEPROM, is by using the <a _mce_href="http://www.arduino.cc/playground/Code/EEPROMWriteAnything" href="http://www.arduino.cc/playground/Code/EEPROMWriteAnything">EEPROMAnything code.</a></li>
<li>My code examples:</li>
<ul>
<li>Simplified source using GET requests and without 7-segment LED display: <a href="https://gist.github.com/rogiervandenberg/1f923f0760225054946d">https://gist.github.com/rogiervandenberg/1f923f0760225054946d</a></li>
<li>Source code I am using in the video: <a href="https://gist.github.com/rogiervandenberg/1d9c138bbc44524c004c">https://gist.github.com/rogiervandenberg/1d9c138bbc44524c004c</a></li>
</ul>
</ul>
<br />Anonymoushttp://www.blogger.com/profile/07872324688604427960noreply@blogger.com4tag:blogger.com,1999:blog-6540870080517546568.post-82549827090188557212010-10-13T18:00:00.000+02:002013-03-07T14:56:57.187+01:00Android Arduino Switch with a TinyWebDB hackYou can easily control your Arduino with an <a href="http://appinventor.mit.edu/">Android App Inventor App</a>. Make a basic app, using the TinyWebDB in the Android App Inventor. If you specify the IP of the Arduino as a server, the Android app things it is storing values in a WebDB. But basically, it is just triggering a command on the Arduino.<br />
<br />
<a href="http://www.youtube.com/watch?v=r7y0IpGhk_w">View what it looks like, "App Inventor for Android Arduino Switch", on YouTube</a><br />
<br />
My Arduino Sketch:<br />
<br />
<pre>/*
Web Server
A simple web server that switches LED's on and off, based on input from an
Android App Inventor application
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* LED outputs attached to pins 5 and 6
created 13 Oct 2010
by Rogier van den Berg / rogiervandenberg.nl
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0, 201 };
//Settings for the two LED's
int ledPin = 5;
int ledState = LOW;
int powerLedPin = 6;
int powerLedState = LOW;
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);
void setup()
{
//Set the LED pins as output
pinMode(ledPin, OUTPUT);
pinMode(powerLedPin, OUTPUT);
//For debugging, set the Serial Output
Serial.begin(9600);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
//Turn one of the LED's on, to know it is ready to go!
digitalWrite(powerLedPin, HIGH);
}
void loop()
{
//Make sure requests are taken care of
handleIncomingInstruction();
//Make sure the power led stays on, when nothing happens.
if(powerLedState == LOW)
switchPowerLed();
}
void handleIncomingInstruction()
{
// listen for incoming clients
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean newLine = true;
String line = "";
while (client.connected() && client.available()) {
char c = client.read();
//Serial.print(c);
switchPowerLed();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && newLine) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
}
if (c == '\n') {
// you're starting a new line
newLine = true;
evaluateLine(line);
line = "";
}
else if (c != '\r') {
// you've gotten a character on the current line
newLine = false;
line += c;
}
}
evaluateLine(line);
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
void evaluateLine(String line)
{
if (line.startsWith("tag", 0)) {
String instruction = line.substring(4, line.length());
Serial.println(instruction);
if (instruction == "TestOpdracht")
switchLed();
}
}
void switchLed()
{
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
Serial.println("We switchen de LED!");
}
void switchPowerLed()
{
// if the LED is off turn it on and vice-versa:
if (powerLedState == LOW)
powerLedState = HIGH;
else
powerLedState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(powerLedPin, powerLedState);
}</pre>
Was originally posted on Posterous (October 13th, 2010)Anonymoushttp://www.blogger.com/profile/07872324688604427960noreply@blogger.com4