tag:blogger.com,1999:blog-40604358138406626902024-03-13T09:58:48.734+08:00Arduino BasicsI hope you liked the tutorials I provided for free. Now they are gone :) Scott Chttp://www.blogger.com/profile/10071004090415946390noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-4060435813840662690.post-65190538444289598072020-10-01T21:36:00.004+08:002020-10-01T21:48:30.948+08:00Arduino Discord<h1 style="text-align: left;">Want to learn Arduino ?</h1><h2 style="text-align: left;">
Visit my discord server: <a href="https://discord.gg/FxnBnZx">https://discord.gg/FxnBnZx</a></h2>Scott Chttp://www.blogger.com/profile/10071004090415946390noreply@blogger.com0tag:blogger.com,1999:blog-4060435813840662690.post-63637266011563717092015-07-02T10:00:00.000+08:002022-02-17T22:05:17.783+08:00NeoPixel Playground<g:plusone></g:plusone>
<div style="text-align: justify;">
<P>
<div style="text-align: center;">
<iframe width="640" height="360" src="https://www.youtube.com/embed/POV-qvEx1ws?rel=0" frameborder="0" allowfullscreen></iframe>
</div><br />
</P>
<P>
<div>
<P>
The NeoPixel Digital RGB LED Strip (144 LED/m) is a really impressive product that will have you lighting up your room
in next to no time. The 144 individually addressable LEDs packed onto a 1 metre flexible water resistant strip, enables
a world of luminescent creativity that will blow your blinking Arduino friends away. The following tutorial will show you
how to create an immersive and interactive LED display using an Arduino UNO, a potentiometer and an accelerometer.
There will be a total of FIVE LED sequences to keep you entertained or you can create your own ! <br>
<br>
This tutorial was specifically designed to work with the <a href="http://openlab.com.au/shop/neopixel-digital-rgb-led-strip-144-led/">144 Neopixel Digital RGB LED strip</a> with the ws2812B chipset.
<br>
<BR />
</P>
</div>
</P>
<P>
<H4>Parts Required:</H4>
<P>
<ul>
<li><a href="http://openlab.com.au/shop/arduino-uno-rev3/">Arduino UNO (or compatible board)</a></li>
<li><a href="https://www.adafruit.com/products/658">Adafruit 5V 10A switching power supply (PRODUCT ID: 658)</a></li>
<li><a href="http://openlab.com.au/shop/neopixel-digital-rgb-led-strip-144-led/">NeoPixel Digital RGB LED Strip (144 LED/m)</a></li>
<li><a href="http://openlab.com.au/shop/sensor-assortment-pack/">Potentiometer </a></li>
<li><a href="http://www.freetronics.com.au/products/3-axis-accelerometer-module#.VXR-1uaferg">3-Axis Accelerometer Module</a></li>
<li><a href="http://openlab.com.au/shop/half-size-breadboard/">Breadboard</a></li>
<li><a href="http://openlab.com.au/shop/breadboard-jumper-wire-set-140-pcs-pack/">Breadboard jumper wire</a></li>
<li><a href="http://openlab.com.au/shop/resk-resistor-kit/">300 ohm resitor</a></li>
<li><a href="http://www.jaycar.com.au/Passive-Components/Capacitors/Electrolytic/4700uF-16V-RB-Electrolytic-Capacitor---105oC/p/RE6243">4700uF 16V Electrolytic Capacitor (Jaycar Cat No. RE6243)</a></li>
<li><a href="http://www.jaycar.com.au/Interconnect/Terminals-%26-Headers/Pluggable-Terminal-Blocks/6-Pole-PC-Mount-Pluggable-Header---5-08mm---Horizontal/p/HM3106">6 Pole PC Mount Pluggable Header (Jaycar Cat No. HM3106)</a></li>
<li><a href="http://www.jaycar.com.au/Interconnect/Terminals-%26-Headers/Pluggable-Terminal-Blocks/6-Pole-PC-Mount-Pluggable-Terminal-Block-Socket---5-08mm/p/HM3126">6 Pole PC Mount Pluggable Terminal Block Socket (Jaycar Cat No. HM3126)</a></li>
<li><a href="http://www.jaycar.com.au/Service-Aids/Tapes/Other/Double-sided-Mounting-Tape---10m/p/NM2821">Double Sided mounting tape - 10m (Jaycar Cat No. NM2821) - optional</a></li>
<br />
</ul>
</P>
</P>
<H4>Power Requirements</H4>
<P>
Before you start any LED strip project, the first thing you will need to think about is POWER. According to the <a href="https://learn.adafruit.com/adafruit-neopixel-uberguide/power">Adafruit website</a>,
each individual NeoPixel LED can draw up to 60 milliamps at maximum brightness - white. Therefore the amount of current required for the entire strip will be way more than your Arduino can handle.
If you try to power this LED strip directly from your Arduino, you run the risk of damaging not only your Arduino, but your USB port as well. The Arduino will be used to control the LED strip,
but the LED strip will need to be powered by a separate power supply. The power supply you choose to use is important. It must provide the correct voltage, and must able to supply sufficient current.<br>
<br>
<h3><span style="color: #7FD4FF;">Operating Voltage(5V)</span></h3>
The operating voltage of the NeoPixel strip is 5 volts DC. Excessive voltage will damage/destroy your NeoPixels. <br>
<br>
<span style="color: #7FD4FF;"><h3>Current requirements (8.6 Amps)</h3></span>
OpenLab recommend the use of a 5V 10A power supply. Having more Amps is OK, providing the output voltage is 5V DC.
The LEDs will only draw as much current as they need. To calculate the amount of current this 1m strip can draw with all LEDs turned on at full brightness - white: <br>
<br>
<span style="color: #7FD4FF;"><span style="font-size: large;">144</span> NeoPixel LEDs</span> x <span style="color: #7FD4FF;"><span style="font-size: large;">60</span> mA</span> x <span style="color: #7FD4FF;"><span style="font-size: large;">1</span> m</span> = <span style="color: #7FD4FF;"><span style="font-size: large;">8640</span> mA</span> = <span style="color: #7FD4FF;"><span style="font-size: large;">8.64</span> Amps for a 1 metre strip.</span><br>
<br>
Therefore a 5V 10A power supply would be able to handle the maximum current (8.6 Amps) demanded by a single 1m NeoPixel strip of 144 LEDs. <br>
<br>  
<br>
</P>
<P>
<H4>Arduino Libraries and IDE</H4>
<BR />
Before you start to hook up any components, upload the following sketch to the Arduino microcontroller.
I am assuming that you already have the <a href="http://www.arduino.cc/en/Main/Software">Arduino IDE</a> installed on your computer. If not, the IDE can be downloaded from <a href="http://www.arduino.cc/en/Main/Software">here</a>. <br>
<br>
The <a href="http://fastled.io/">FastLED library</a> is useful for simplifying the code for programming the NeoPixels.
The latest "FastLED library" can be downloaded from <a href="https://github.com/FastLED/FastLED/releases">here</a>. I used FastLED library version <a href="https://github.com/FastLED/FastLED/tree/3.0.3">3.0.3</a> in this project.<br>
<br>
If you have a different LED strip or your NeoPixels have a different chipset, make sure to change the relevant lines of code to accomodate your hardware.
I would suggest you try out a few of the <a href="https://github.com/FastLED/FastLED/tree/3.0.3/examples">FastLED library examples</a> before using the code below, so that you become more familiar with the library, and
will be better equipped to make the necessary changes. If you have a single 144 NeoPixel LED/m strip with the ws2812B chipset, then you will not have to make
any modifications below (unless you want to).<br>
<br>
<h4>ARDUINO CODE:</h4><br>
<div style="background: #ffffff; color: #000000; overflow:auto;width:auto;border:solid rgb(24,186,183);border-width: .6em .3em .3em .3em;padding: 0em 0em;">
<table>
<tr>
<td>
<pre style="margin: 0; line-height: 125%; background: rgb(24,186,183); width: 1.9em"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318 </pre>
</td>
<td>
<pre style="margin: 0; line-height: 126%">
<!-- INSERT ARDUINO CODE HERE -->
<pre>
<span style="color: #434F54;">/* ==================================================================================================================================================</span>
<span style="color: #434F54;"> Project: NeoPixel Playground</span>
<span style="color: #434F54;">Neopixel chipset: ws2812B (144 LED/m strip)</span>
<span style="color: #434F54;"> Author: Scott C</span>
<span style="color: #434F54;"> Created: 12th June 2015</span>
<span style="color: #434F54;"> Arduino IDE: 1.6.4</span>
<span style="color: #434F54;"> Website: http://arduinobasics.blogspot.com/p/arduino-basics-projects-page.html</span>
<span style="color: #434F54;"> Description: This project will allow you to cycle through and control five LED</span>
<span style="color: #434F54;"> animation sequences using a potentiometer and an accelerometer</span>
<span style="color: #434F54;"> Sequence 1: Cylon with Hue Control Control: Potentiometer only</span>
<span style="color: #434F54;"> Sequence 2: Cylon with Brightness Control Control: Potentiometer only</span>
<span style="color: #434F54;"> Sequence 3: Comet effect with Hue and direction control Control: Potentiometer and Accelerometer (Y axis only)</span>
<span style="color: #434F54;"> Sequence 4: FireStarter / Rainbow effect with Hue and Direction control Control: Potentiometer and Accelerometer (Y axis only)</span>
<span style="color: #434F54;"> Sequence 5: Digital Spirit Level Control: Accelerometer only (Y axis)</span>
<span style="color: #434F54;"> </span>
<span style="color: #434F54;"> This project makes use of the FastLED library. Some of the code below was adapted from the FastLED library examples (eg. Cylon routine).</span>
<span style="color: #434F54;"> The Comet, FireStarter and Digital Spirit Level sequence was designed by ScottC.</span>
<span style="color: #434F54;"> The FastLED library can be found here: http://fastled.io/</span>
<span style="color: #434F54;"> You may need to modify the code below to accomodate your specific LED strip. See the FastLED library site for more details.</span>
<span style="color: #434F54;">===================================================================================================================================================== */</span>
<span style="color: #434F54;">//This project needs the FastLED library - link in the description.</span>
#include <span style="color: #006699;">"FastLED.h"</span>
<span style="color: #434F54;">//The total number of LEDs being used is 144</span>
#define NUM_LEDS 144
<span style="color: #434F54;">// The data pin for the NeoPixel strip is connected to digital Pin 6 on the Arduino</span>
#define DATA_PIN 6
<span style="color: #434F54;">//Initialise the LED array, the LED Hue (ledh) array, and the LED Brightness (ledb) array.</span>
<span style="color: #D35400;"><b>CRGB</b></span> leds[NUM_LEDS];
<span style="color: #00979C;">byte</span> ledh[NUM_LEDS];
<span style="color: #00979C;">byte</span> ledb[NUM_LEDS];
<span style="color: #434F54;">//Pin connections</span>
<span style="color: #00979C;">const</span> <span style="color: #00979C;">int</span> potPin = A0; <span style="color: #434F54;">// The potentiometer signal pin is connected to Arduino's Analog Pin 0</span>
<span style="color: #00979C;">const</span> <span style="color: #00979C;">int</span> yPin = A4; <span style="color: #434F54;">// Y pin on accelerometer is connected to Arduino's Analog Pin 4</span>
<span style="color: #434F54;">// The accelerometer's X Pin and the Z Pin were not used in this sketch</span>
<span style="color: #434F54;">//Global Variables ---------------------------------------------------------------------------------</span>
<span style="color: #00979C;">byte</span> potVal; <span style="color: #434F54;">// potVal: stores the potentiometer signal value</span>
<span style="color: #00979C;">byte</span> prevPotVal=0; <span style="color: #434F54;">// prevPotVal: stores the previous potentiometer value</span>
<span style="color: #00979C;">int</span> LEDSpeed=1; <span style="color: #434F54;">// LEDSpeed: stores the "speed" of the LED animation sequence</span>
<span style="color: #00979C;">int</span> maxLEDSpeed = 50; <span style="color: #434F54;">// maxLEDSpeed: identifies the maximum speed of the LED animation sequence</span>
<span style="color: #00979C;">int</span> LEDAccel=0; <span style="color: #434F54;">// LEDAccel: stores the acceleration value of the LED animation sequence (to speed it up or slow it down)</span>
<span style="color: #00979C;">int</span> LEDPosition=72; <span style="color: #434F54;">// LEDPosition: identifies the LED within the strip to modify (leading LED). The number will be between 0-143. (Zero to NUM_LEDS-1)</span>
<span style="color: #00979C;">int</span> oldPos=0; <span style="color: #434F54;">// oldPos: holds the previous position of the leading LED</span>
<span style="color: #00979C;">byte</span> hue = 0; <span style="color: #434F54;">// hue: stores the leading LED's hue value</span>
<span style="color: #00979C;">byte</span> intensity = 150; <span style="color: #434F54;">// intensity: the default brightness of the leading LED</span>
<span style="color: #00979C;">byte</span> bright = 80; <span style="color: #434F54;">// bright: this variable is used to modify the brightness of the trailing LEDs</span>
<span style="color: #00979C;">int</span> animationDelay = 0; <span style="color: #434F54;">// animationDelay: is used in the animation Speed calculation. The greater the animationDelay, the slower the LED sequence.</span>
<span style="color: #00979C;">int</span> effect = 0; <span style="color: #434F54;">// effect: is used to differentiate and select one out of the four effects</span>
<span style="color: #00979C;">int</span> sparkTest = 0; <span style="color: #434F54;">// sparkTest: variable used in the "sparkle" LED animation sequence </span>
<span style="color: #00979C;">boolean</span> constSpeed = <span style="color: #00979C;">false</span>; <span style="color: #434F54;">// constSpeed: toggle between constant and variable speed.</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// setup() : Is used to initialise the LED strip</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> <span style="color: #5E6D03;">setup</span>() {
<span style="color: #D35400;">delay</span>(2000); <span style="color: #434F54;">//Delay for two seconds to power the LEDS before starting the data signal on the Arduino</span>
<span style="color: #D35400;"><b>FastLED</b></span>.<span style="color: #D35400;">addLeds</span><<span style="color: #006699;">WS2812B</span>, DATA_PIN, <span style="color: #006699;">GRB</span>>(leds, NUM_LEDS); <span style="color: #434F54;">//initialise the LED strip </span>
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// loop() : The Arduino will take readings from the potentiometer and accelerometer to control the LED strip</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> <span style="color: #5E6D03;">loop</span>(){
readPotentiometer();
adjustSpeed();
constrainLEDs();
<span style="color: #5E6D03;">switch</span>(effect){
<span style="color: #5E6D03;">case</span> 0: <span style="color: #434F54;">// 1st effect : Cylon with Hue control - using Potentiometer </span>
cylonWithHueControl();
<span style="color: #5E6D03;">break</span>;
<span style="color: #5E6D03;">case</span> 1: <span style="color: #434F54;">// 2nd effect : Cylon with Brightness control - using Potentiometer</span>
cylonWithBrightnessControl();
<span style="color: #5E6D03;">break</span>;
<span style="color: #5E6D03;">case</span> 2: <span style="color: #434F54;">// 3rd effect : Comet effect. Hue controlled by potentiometer, direction by accelerometer</span>
cometEffect();
<span style="color: #5E6D03;">break</span>;
<span style="color: #5E6D03;">case</span> 3: <span style="color: #434F54;">// 4th effect : FireStarter / Rainbow Sparkle effect. Direction controlled by accelerometer, sparkle by potentiometer.</span>
fireStarter();
<span style="color: #5E6D03;">break</span>;
<span style="color: #5E6D03;">case</span> 4:
levelSense(); <span style="color: #434F54;">// 5th effect : LevelSense - uses the accelerometer to create a digital "spirit" level.</span>
<span style="color: #5E6D03;">break</span>;
}
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// readPotentiometer() : Take a potentiometer reading. This value will be used to control various LED animations, and to choose the animation sequence to display.</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> readPotentiometer(){
<span style="color: #434F54;">//Take a reading from the potentiometer and convert the value into a number between 0 and 255</span>
potVal = <span style="color: #D35400;">map</span>(<span style="color: #D35400;">analogRead</span>(potPin), 0, 1023 , 0, 255);
<span style="color: #434F54;">// If the potentiometer reading is equal to zero, then move to the next effect in the list.</span>
<span style="color: #5E6D03;">if</span>(potVal==0){
<span style="color: #5E6D03;">if</span>(prevPotVal>0){ <span style="color: #434F54;">// This allows us to switch effects only when the potentiometer reading has changed to zero (from a positive number). Multiple zero readings will be ignored.</span>
prevPotVal = 0; <span style="color: #434F54;">// Set the prev pot value to zero in order to ignore replicate zero readings.</span>
effect++; <span style="color: #434F54;">// Go to the next effect.</span>
<span style="color: #5E6D03;">if</span>(effect>4){
effect=0; <span style="color: #434F54;">// Go back to the first effect after the fifth effect.</span>
}
}
}
prevPotVal=potVal; <span style="color: #434F54;">// Keep track of the previous potentiometer reading</span>
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// adjustSpeed() : use the Y axis value of the accelerometer to adjust the speed and the direction of the LED animation sequence</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> adjustSpeed(){
<span style="color: #434F54;">// Take a reading from the Y Pin of the accelerometer and adjust the value so that </span>
<span style="color: #434F54;">// positive numbers move in one direction, and negative numbers move in the opposite diraction. </span>
<span style="color: #434F54;">// We use the map function to convert the accelerometer readings, and the constrain function to ensure that it stays within the desired limits</span>
<span style="color: #434F54;">// The values of 230 and 640 were determined by trial and error and are specific to my accelerometer. You will need to adjust these numbers to suit your module.</span>
LEDAccel = <span style="color: #D35400;">constrain</span>(<span style="color: #D35400;">map</span>(<span style="color: #D35400;">analogRead</span>(yPin), 230, 640 , maxLEDSpeed, -maxLEDSpeed),-maxLEDSpeed, maxLEDSpeed);
<span style="color: #434F54;">// If the constSpeed variable is "true", then make sure that the speed of the animation is constant by modifying the LEDSpeed and LEDAccel variables.</span>
<span style="color: #5E6D03;">if</span>(constSpeed){
LEDAccel=0;
<span style="color: #5E6D03;">if</span>(LEDSpeed>0){
LEDSpeed = maxLEDSpeed/1.1; <span style="color: #434F54;">// Adjust the LEDSpeed to half the maximum speed in the positive direction</span>
}
<span style="color: #5E6D03;">if</span> (LEDSpeed<0){
LEDSpeed = -maxLEDSpeed/1.1; <span style="color: #434F54;">// Adjust the LEDSpeed to half the maximum speed in the negative direction</span>
}
}
<span style="color: #434F54;">// The Speed of the LED animation sequence can increase (accelerate), decrease (decelerate) or stay the same (constant speed)</span>
LEDSpeed = LEDSpeed + LEDAccel;
<span style="color: #434F54;">//The following lines of code are used to control the direction of the LED animation sequence, and limit the speed of that animation. </span>
<span style="color: #5E6D03;">if</span> (LEDSpeed>0){
LEDPosition++; <span style="color: #434F54;">// Illuminate the LED in the Next position</span>
<span style="color: #5E6D03;">if</span> (LEDSpeed>maxLEDSpeed){
LEDSpeed=maxLEDSpeed; <span style="color: #434F54;">// Ensure that the speed does not go beyond the maximum speed in the positive direction</span>
}
}
<span style="color: #5E6D03;">if</span> (LEDSpeed<0){
LEDPosition--; <span style="color: #434F54;">// Illuminate the LED in the Prior position</span>
<span style="color: #5E6D03;">if</span> (LEDSpeed<-maxLEDSpeed){
LEDSpeed = -maxLEDSpeed; <span style="color: #434F54;">// Ensure that the speed does not go beyond the maximum speed in the negative direction</span>
}
}
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// constrainLEDs() : This ensures that the LED animation sequence remains within the boundaries of the various arrays (and the LED strip)</span>
<span style="color: #434F54;">// and it also creates a "bouncing" effect at both ends of the LED strip.</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> constrainLEDs(){
LEDPosition = <span style="color: #D35400;">constrain</span>(LEDPosition, 0, NUM_LEDS-1); <span style="color: #434F54;">// Make sure that the LEDs stay within the boundaries of the LED strip</span>
<span style="color: #5E6D03;">if</span>(LEDPosition == 0 || LEDPosition == NUM_LEDS-1) {
LEDSpeed = (LEDSpeed * -0.9); <span style="color: #434F54;">// Reverse the direction of movement when LED gets to end of strip. This creates a bouncing ball effect.</span>
}
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// cylonWithHueControl() : This is the 1st LED effect. The cylon colour is controlled by the potentiometer. The speed is constant.</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> cylonWithHueControl(){
constSpeed = <span style="color: #00979C;">true</span>; <span style="color: #434F54;">// Make the LED animation speed constant</span>
showLED(LEDPosition, potVal, 255, intensity); <span style="color: #434F54;">// Illuminate the LED</span>
fadeLEDs(8); <span style="color: #434F54;">// Fade LEDs by a value of 8. Higher numbers will create a shorter tail.</span>
setDelay(LEDSpeed); <span style="color: #434F54;">// The LEDSpeed is constant, so the delay is constant</span>
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// cylonWithBrightnessControl() : This is the 2nd LED effect. The cylon colour is red (hue=0), and the brightness is controlled by the potentiometer</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> cylonWithBrightnessControl(){
constSpeed = <span style="color: #00979C;">true</span>; <span style="color: #434F54;">// Make speed constant</span>
showLED(LEDPosition, 0, 255, potVal); <span style="color: #434F54;">// Brightness is controlled by potentiometer.</span>
fadeLEDs(16); <span style="color: #434F54;">// Fade LEDs by a value of 16</span>
setDelay(LEDSpeed); <span style="color: #434F54;">// The LEDSpeed is constant, so the delay is constant</span>
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// cometEffect() : This is the 3rd LED effect. The random brightness of the trailing LEDs produces an interesting comet-like effect.</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> cometEffect(){
constSpeed = <span style="color: #00979C;">false</span>; <span style="color: #434F54;">// The speed will be controlled by the slope of the accelerometer (y-Axis)</span>
showLED(LEDPosition, potVal, 255, intensity); <span style="color: #434F54;">// Hue will change with potentiometer.</span>
<span style="color: #434F54;">//The following lines create the comet effect </span>
bright = <span style="color: #D35400;">random</span>(50, 100); <span style="color: #434F54;">// Randomly select a brightness between 50 and 100</span>
leds[LEDPosition] = <span style="color: #D35400;"><b>CHSV</b></span>((potVal+40),255, bright); <span style="color: #434F54;">// The trailing LEDs will have a different hue to the leading LED, and will have a random brightness</span>
fadeLEDs(8); <span style="color: #434F54;">// This will affect the length of the Trailing LEDs</span>
setDelay(LEDSpeed); <span style="color: #434F54;">// The LEDSpeed will be affected by the slope of the Accelerometer's y-Axis</span>
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// fireStarter() : This is the 4th LED effect. It starts off looking like a ball of fire, leaving a trail of little fires. But as you</span>
<span style="color: #434F54;">// turn the potentiometer, it becomes more like a shooting star with a rainbow-sparkle trail.</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> fireStarter(){
constSpeed = <span style="color: #00979C;">false</span>; <span style="color: #434F54;">// The speed will be controlled by the slope of the accelerometer (y-Axis)</span>
ledh[LEDPosition] = potVal; <span style="color: #434F54;">// Hue is controlled by potentiometer</span>
showLED(LEDPosition, ledh[LEDPosition], 255, intensity);
<span style="color: #434F54;">//The following lines create the fire starter effect</span>
bright = <span style="color: #D35400;">random</span>(50, 100); <span style="color: #434F54;">// Randomly select a brightness between 50 and 100</span>
ledb[LEDPosition] = bright; <span style="color: #434F54;">// Assign this random brightness value to the trailing LEDs</span>
sparkle(potVal/5); <span style="color: #434F54;">// Call the sparkle routine to create that sparkling effect. The potentiometer controls the difference in hue from LED to LED.</span>
fadeLEDs(1); <span style="color: #434F54;">// A low number creates a longer tail</span>
setDelay(LEDSpeed); <span style="color: #434F54;">// The LEDSpeed will be affected by the slope of the Accelerometer's y-Axis</span>
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// levelSense() : This is the 5th and final LED effect. The accelerometer is used in conjunction with the LED strip to create a digital "Spirit" Level.</span>
<span style="color: #434F54;">// You can use the illuminated LEDs to identify the angle of the LED strip</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> levelSense(){
constSpeed = <span style="color: #00979C;">true</span>;
LEDPosition = <span style="color: #D35400;">constrain</span>(<span style="color: #D35400;">map</span>(<span style="color: #D35400;">analogRead</span>(yPin), 230, 640, 1, NUM_LEDS-1), 0 , NUM_LEDS-1);
<span style="color: #434F54;">//Jitter correction: this will reduce the amount of jitter caused by the accelerometer reading variability</span>
<span style="color: #5E6D03;">if</span>(<span style="color: #D35400;">abs</span>(LEDPosition-oldPos) < 2){
LEDPosition = oldPos;
}
<span style="color: #434F54;">//The following lines of code will ensure the colours remain within the red to green range, with green in the middle and red at the ends.</span>
hue = <span style="color: #D35400;">map</span>(LEDPosition, 0, NUM_LEDS-1, 0, 200);
<span style="color: #5E6D03;">if</span> (hue>100){
hue = 200 - hue;
}
<span style="color: #434F54;">//Illuminate 2 LEDs next to each other</span>
showLED(LEDPosition, hue, 255, intensity);
showLED(LEDPosition-1, hue, 255, intensity);
<span style="color: #434F54;">//If the position moves, then fade the old LED positions by a factor of 25 (high numbers mean shorter tail)</span>
fadeLEDs(25);
oldPos = LEDPosition;
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// fadeLEDs(): This function is used to fade the LEDs back to black (OFF) </span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> fadeLEDs(<span style="color: #00979C;">int</span> fadeVal){
<span style="color: #5E6D03;">for</span> (<span style="color: #00979C;">int</span> i = 0; i<NUM_LEDS; i++){
leds[i].<span style="color: #D35400;">fadeToBlackBy</span>( fadeVal );
}
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// showLED() : is used to illuminate the LEDs </span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> showLED(<span style="color: #00979C;">int</span> pos, <span style="color: #00979C;">byte</span> LEDhue, <span style="color: #00979C;">byte</span> LEDsat, <span style="color: #00979C;">byte</span> LEDbright){
leds[pos] = <span style="color: #D35400;"><b>CHSV</b></span>(LEDhue,LEDsat,LEDbright);
<span style="color: #D35400;"><b>FastLED</b></span>.<span style="color: #D35400;">show</span>();
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// setDelay() : is where the speed of the LED animation sequence is controlled. The speed of the animation is controlled by the LEDSpeed variable.</span>
<span style="color: #434F54;">// and cannot go faster than the maxLEDSpeed variable.</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> setDelay(<span style="color: #00979C;">int</span> LSpeed){
animationDelay = maxLEDSpeed - <span style="color: #D35400;">abs</span>(LSpeed);
<span style="color: #D35400;">delay</span>(animationDelay);
}
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #434F54;">// sparkle() : is used by the fireStarter routine to create a sparkling/fire-like effect</span>
<span style="color: #434F54;">// Each LED hue and brightness is monitored and modified using arrays (ledh[] and ledb[])</span>
<span style="color: #434F54;">//===================================================================================================================================================</span>
<span style="color: #00979C;">void</span> sparkle(<span style="color: #00979C;">byte</span> hDiff){
<span style="color: #5E6D03;">for</span>(<span style="color: #00979C;">int</span> i = 0; i < NUM_LEDS; i++) {
ledh[i] = ledh[i] + hDiff; <span style="color: #434F54;">// hDiff controls the extent to which the hue changes along the trailing LEDs</span>
<span style="color: #434F54;">// This will prevent "negative" brightness.</span>
<span style="color: #5E6D03;">if</span>(ledb[i]<3){
ledb[i]=0;
}
<span style="color: #434F54;">// The probability of "re-igniting" an LED will decrease as you move along the tail</span>
<span style="color: #434F54;">// Once the brightness reaches zero, it cannot be re-ignited unless the leading LED passes over it again.</span>
<span style="color: #5E6D03;">if</span>(ledb[i]>0){
ledb[i]=ledb[i]-2;
sparkTest = <span style="color: #D35400;">random</span>(0,bright);
<span style="color: #5E6D03;">if</span>(sparkTest>(bright-(ledb[i]/1.1))){
ledb[i] = bright;
} <span style="color: #5E6D03;">else</span> {
ledb[i] = ledb[i] / 2;
}
}
leds[i] = <span style="color: #D35400;"><b>CHSV</b></span>(ledh[i],255,ledb[i]);
}
}
</pre>
<!-- End of Arduino Code -->
</pre>
</td>
</tr>
</table>
</div></P>
<br>
<br>
<P>
<h4>NeoPixel Strip connection </h4>
<P>
The NeoPixel strip is rolled up when you first get it. You will notice that there are wires on both sides of the strip.
This allows you to chain LED strips together to make longer strips. The more LEDs you have, the more current you will need.
Connect your Arduino and power supply to the left side of the strip, with the arrows pointing to the right side of the strip.
<br clear="all">
<br>
</P>
<P>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVWESsaleeKCsX6mqbTy7LxkI1VU1eZYlhvPfVnuDzHEI1m4JLO8WCVFLvT-6TxvJehpRbEJ1ui5um8JWeuiG6Dyv-dctjIab1pBO9ReG72sxKJPcA_8Rtg9lUWrvDPBOP1lBu3wQsew8/s1600/Rolled+up+Neopixels.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img style="border:3px double white;" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVWESsaleeKCsX6mqbTy7LxkI1VU1eZYlhvPfVnuDzHEI1m4JLO8WCVFLvT-6TxvJehpRbEJ1ui5um8JWeuiG6Dyv-dctjIab1pBO9ReG72sxKJPcA_8Rtg9lUWrvDPBOP1lBu3wQsew8/s320/Rolled+up+Neopixels.jpg" width="300" align="top" />
</a>
</div>
</P>
<P>
<h3><span style="color: #7FD4FF;">Follow the Arrows</span></h3>
The arrows are quite hard to see on this particular LED strip because they are so small, plus they are located
right under the thicker part of the NeoPixel weatherproof sheath. I have circled the arrows in RED so that you know where to look:<br>
<br clear="all">
<br>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgILoP2fszLmuEqYN1gecesIwV2mfiVkcAJd31cbOcK8s8_nUrYvVDv4LNI2cAqMufJ3awMQNXMvkvV3MvlKaHDq6qQwY3ybS952ySh5pO1m0BMwsKCVixBnXqnhsr8XOvWnEfMxpGZEEY/s1600/NeoPixel+Arrows.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img style="border:3px double white;" height="232" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgILoP2fszLmuEqYN1gecesIwV2mfiVkcAJd31cbOcK8s8_nUrYvVDv4LNI2cAqMufJ3awMQNXMvkvV3MvlKaHDq6qQwY3ybS952ySh5pO1m0BMwsKCVixBnXqnhsr8XOvWnEfMxpGZEEY/s400/NeoPixel+Arrows.jpg" width="400" />
</a>
</div>
<br />
</P>
</P>
<br clear="all">
<span style="color: #7FD4FF;"><P><h3>NeoPixel Strip Wires</h3></span>
There are 4 wires coming from either side of the NeoPixel LED strip: <br>
<br>
One red wire, one white wire, and two black wires.<br>
<br>
It doesn't matter which Black wire you use to connect to the power supply (or Arduino) GND. Both black wires appear to be going to the
same pin on the LED strip anyway. Use the table below to make the necessary NeoPixel Strip connections to the Arduino and power supply.<br>
<br clear="all">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwYGoYvtbmhhO-Nji4WAogNRjRtu1_6qSHCAhwgZmiIPJPd8z9u3EcsL7EDCRq9essAHcFUtlgh-Q3TYQjFGXAot73kysNgrvCSwZAn9ljV8_VUj1eoB7yS7fua5WJS8Z5bV3TFbRHVyQ/s1600/NeoPixel+Table3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="448" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwYGoYvtbmhhO-Nji4WAogNRjRtu1_6qSHCAhwgZmiIPJPd8z9u3EcsL7EDCRq9essAHcFUtlgh-Q3TYQjFGXAot73kysNgrvCSwZAn9ljV8_VUj1eoB7yS7fua5WJS8Z5bV3TFbRHVyQ/s640/NeoPixel+Table3.jpg" width="640" />
</a>
</div>
<br />
</P>
<P>
<h3><span style="color: #7FD4FF;">Large Capacitor</span></h3>
<a href="https://learn.adafruit.com/adafruit-neopixel-uberguide/power">Adafruit</a> also recommend the use of a large capacitor across the + and - terminals of the LED strip to "prevent the
initial onrush of current from damaging the pixels". Adafruit recommends a capacitor that is 1000uF, 6.3V or higher.
I used a 4700uF 16V Electrolytic Capacitor. <br>
<br>
<span style="color: #7FD4FF;"><h3>Resistor on Data Pin</h3></span>
Another recommendation from <a href="https://learn.adafruit.com/adafruit-neopixel-uberguide/power">Adafruit</a> is to place a "300 to 500 Ohm resistor" between the Arduino's data pin and the data
input on the first NeoPixel to prevent voltage spikes that can damage the first pixel. I used a 330 Ohm resistor. <br>
<br>
<span style="color: #7FD4FF;"><h3>Powering your Arduino (USB vs Power supply)</h3></span>
You can power your Arduino board via USB cable or via the LED strip power supply.<br>
<span style="color: #7FD4FF;">*** Please note:</span> different power supplies will yield different accelerometer readings. I noticed this when changing the Arduino's power source from USB to LED power supply.
My final sketch was designed to eliminate the USB/computer connection, hence I have chosen to power the Arduino via the power supply.
The fritzing sketch below shows the Arduino being powered by a power supply only. <br>
<br>
<span style="color: #FF0000;"><b>**WARNING:</b></span> If you decide to power your Arduino UNO via a USB cable, please make sure to remove (or disconnect) the wire that goes to the
the Arduino VIN pin. The GND connections remain unchanged.
</P>
<br>
<P><H4>Fritzing Sketch - NeoPixel strip connection</H4>
</P>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSGy-wAxx7emvWpaO9dfM6LbGY_CKdgM8MsCSLdpCwsYpBtPu3Y12E6orzmSeehb5aadjN3L6ZqyFLba5puGaBLTMlHtNtEDzzy1-6XU3qVnMaNXXEsXQ-wFWIYCn_yn7c2yKviC8SiKw/s1600/NeoPixel+Fritzing+Sketch1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img style="border:3px double white;" height="478" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSGy-wAxx7emvWpaO9dfM6LbGY_CKdgM8MsCSLdpCwsYpBtPu3Y12E6orzmSeehb5aadjN3L6ZqyFLba5puGaBLTMlHtNtEDzzy1-6XU3qVnMaNXXEsXQ-wFWIYCn_yn7c2yKviC8SiKw/s640/NeoPixel+Fritzing+Sketch1.jpg" width="640" />
</a>
</div>
<br />
<br>
<h4>Potentiometer connection</h4>
<P>The potentiometer will be used to switch between the different LED sequences. When it reads zero, it will switch to
the next sequence in the list. It will jump right back to the beginning after the last sequence.
The potentiometer is also used to interact with the LEDs (e.g. controlling hue, brightness etc etc).
<br>
See the fritzing sketch below to add the potentiometer to this project.</P>
<br>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmuimYqroOvqBdpWWZgmrBHkuPQ570RSXCBqIvnyqNpf11BaIjvCWJdS-XS3GetiIrei57r6V7nGOBVDR5XAkoeVV7ccbSh5DwQXLb-oc6uyDv8d1FRGnFPXt3Ap6-kiZD97S223JwhXw/s1600/Potentiometer+Fritzing.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img style="border:3px double white;" height="512" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmuimYqroOvqBdpWWZgmrBHkuPQ570RSXCBqIvnyqNpf11BaIjvCWJdS-XS3GetiIrei57r6V7nGOBVDR5XAkoeVV7ccbSh5DwQXLb-oc6uyDv8d1FRGnFPXt3Ap6-kiZD97S223JwhXw/s640/Potentiometer+Fritzing.jpg" width="640" />
</a>
</div>
<br />
<br>
<h4>Accelerometer connection (Y-axis)</h4>
<P>The accelerometer makes the LEDs much more fun and interactive. We will only be using the Y-axis of the accelerometer in this sketch. By tilting the accelerometer from one side to the other, the LEDs react and respond accordingly.
The accelerometer is an essential component of the digital spirit level sequence. That's right ! You can use this sketch
to create your own spirit level. This digital version can also be used to measure angles ! <br>
<br>
Have a look below to see how to hook up the accelerometer to the Arduino. The Y-axis is connected to the Arduino analog pin 4.
If you wanted to use the X and Z axis, connect them to one of the other available analog pins (eg. A3 and A5). </P>
<br>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8QGSGxL-jn9dR9ty3gchEvsE2na5lm0FuXkhsiRTqopaCqufFLFAdPRPSZg5-RHMK6mtl_8k-qtZd-UWh4_lEmdgG9TVYyL_Xo3Vckcwm9gyHQrNh4Ao-n6js8xn7ENMQFccB0yCGj4A/s1600/Accelerometer+Fritzing.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img style="border:3px double white;" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8QGSGxL-jn9dR9ty3gchEvsE2na5lm0FuXkhsiRTqopaCqufFLFAdPRPSZg5-RHMK6mtl_8k-qtZd-UWh4_lEmdgG9TVYyL_Xo3Vckcwm9gyHQrNh4Ao-n6js8xn7ENMQFccB0yCGj4A/s640/Accelerometer+Fritzing.jpg" width="630" />
</a>
</div>
<br />
</P>
<BR />
<P>
<h4>Let the fun begin !!</h4>
Now that you have the Arduino code uploaded to the Arduino, and have made all of the necessary wire/component connections,
it is time to turn on the power supply. <br>
<br>
<span style="color: #7FD4FF;"><h3>Sequence 1: Cylon with Hue control</h3></span>
The LEDs will move from one end of the strip to the other. It should start off as a RED cylon effect.
As you turn the potentiometer clockwise, the colour of the LEDs will change and move through the various colours of the rainbow.
If the potentiometer reading gets back to zero (fully anti-clockwise), it will move to sequence 2.<br>
<br>
<span style="color: #7FD4FF;"><h3>Sequence 2: Cylon with brightness control</h3></span>
You will see that the LEDs have turned off. The potentiometer readings correlate with the LED brightness.
At the start of this sequence, the potentiometer readings will be zero, therefore the brightness will be zero (LEDs turned off).
As you turn the potentiometer clockwise, the readings increase, and so will the brightness of the LEDs. <br>
<br>
<span style="color: #7FD4FF;"><h3>Sequence 3: Comet effect with Hue and direction control</h3></span>
This is where the real fun begins. You control the hue of the leading LED with the potentiometer, however the LED will move
along the LED strip as though it were affected by gravity. As it hits the end of the LED strip, it will bounce for a while
and eventually come to a stop. The more you tilt the accelerometer, the greater the acceleration of the leading LED.
The trailing LEDs have an interesting randomised glow, which creates the "comet" effect.<br>
<br>
<span style="color: #7FD4FF;"><h3>Sequence 4: FireStarter / Rainbow effect : Hue and direction control</h3></span>
The initial colours of LEDs in this sequence creates a fire-like animation. As the leading LED moves along the LED strip, it appears
to ignite the LEDs in its path, leaving a fire trail behind it. The fire effect is best when you turn the potentiometer clockwise slightly
to introduce a small amount of yellow into the mix of colours. As you turn the potentiometer further clockwise, the fire trail
turns into a pretty rainbow trail. The accelerometer affects the leading LED in the same way as the previous sequence. <br>
<br>
<span style="color: #7FD4FF;"><h3>Sequence 5: Digital spirit level</h3></span>
This sequence was my original idea for this project, however I thought it would be nice to share some of the other cool effects I created on
my journey of discovery. The idea was to make a digital version of a spirit level. I originally wanted the LEDs to represent a spirit level
bubble that would "float" according to the vertical/horizontal position of the LED strip. However,
as I played around with this sketch, I discovered that it could potentially be used to measure the angle of the strip relative to the horizon.
The angle can be determined by the illuminated LED. If the strip is horizontal, the illuminated LEDs will be close to the middle of the strip, and
their colour will be green. If the strip is vertical, the illuminated LEDs will be close to end of the strip, and their colour will be red.
The colour is just an additional visual indicator. <br>
</P>
</P>
</div>
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<P>
<div style="text-align: justify;">
<h3><span style="color: #7FD4FF;">Concluding Comments</span></h3>
The NeoPixel Digital RGB LED strip is a lot of fun. The FastLED library makes for easy programming,
and allows you to get up and running really quickly. 144 LEDs on a single strip means you have plenty of room for
creative algorithms and lighting effects. Add a few sensors, and "pretty" quickly turns into "awesome" !!<br>
<br>
This tutorial shows you how to control a <a href="http://openlab.com.au/shop/neopixel-digital-rgb-led-strip-144-led/">"144 NeoPixel per metre Digital RGB LED strip"</a> with an Arduino UNO.
Feel free to share your own LED creations in the comments below.<br>
</div>
<div>
<P>
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br />
</P>
</div>
<P>
<div align="center">
If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br>
<BR />
<BR />
Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br>
Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br>
I can also be found on <a href="https://www.pinterest.com/ArduinoBasics/">Pinterest</a> and <a href="https://instagram.com/arduinobasics">Instagram</a>. <br>
Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.<br>
</div>
</P>
<BR />
<BR />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://arduinobasics.blogspot.com.au/p/arduino-basics-projects-page.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAFzcKuKvtoDPNXhi41QTXnXadUAsQ28b85dx_chtjL205bAu7zaIPj9lW3mcMQvPBIKoC6YrGgbfYEPAzOH6ww6c5Pgyv4BIz8cAWAZ4x68bc_rkyfPWAYjJfM_JkxO03NKGsIutZehQ/s320/ArduinoBasics_OpenLogo+on+Black.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;"></div> <br>
<div align="center">This project would not have been possible without the collaborative effort from <a href="http://openlab.com.au/">OpenLab</a>.<br> Please visit their site for more cool projects.</div> <br>
<div>
<P>
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br />
</P>
</div>
<P>
However, if you do not have a google profile... <br>Feel free to share this page with your friends in any way you see fit.
</P>
</P>
</P>
<!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" -->Scott Chttp://www.blogger.com/profile/10071004090415946390noreply@blogger.com25tag:blogger.com,1999:blog-4060435813840662690.post-84511339707256249642014-07-30T02:09:00.000+08:002022-02-17T16:24:45.651+08:00433 MHz RF module with Arduino Tutorial 4:<g:plusone></g:plusone>
<div style="text-align: justify;">
<!-- Title Page Graphic -->
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-AEKIHBVoH3c/U9e2zadMgwI/AAAAAAAAA9E/uRbn07sCriA/s1600/RF+Project+4+Titlepage.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="479" src="https://2.bp.blogspot.com/-AEKIHBVoH3c/U9e2zadMgwI/AAAAAAAAA9E/uRbn07sCriA/s1600/RF+Project+4+Titlepage.jpg" width="640" />
</a>
</div>
<br />
<br />
<div>
<span style="color: red;">
WARNING: Please check whether you can legally use RF transmitters and receivers at your location before attempting this project (or buying the components). This project is aimed at those who are looking to automate their home.
</span>
<br />
<div>
There are 4 parts to this tutorial:<br />
<ul>
<li><a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">Part 1: Testing the 433 MHz RF transmitter and receiver</a></li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">Part 2: Receive and interpret code from an RF remote</a></li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">Part 3: Transmit a known 433 Mhz RF code to a 433 Mhz RF device</a></li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html">Part 4: Record and play back a 433 Mhz RF remote signal</a> - ** you are here **</li>
</ul>
To get the most out of this tutorial - it is best to start at tutorial <a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">Part 1</a>, and then progress to <a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">Part 2</a> then <a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">Part 3</a> and then do <a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html">Part 4</a> last.
Doing the RF tutorials in this order will help you to understand the process better. </div>
<br />
<hr />
<h4>
Project 4 : 433 Mhz RF remote replacement tutorial</h4>
Carrying on from my previous "433MHz transmitter and receiver" tutorials (<a href="http://arduinobasics.blogspot.com/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">1</a>,<a href="http://arduinobasics.blogspot.com/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">2</a> & <a href="http://arduinobasics.blogspot.com/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">3</a>): I have thrown away the need to process the signal with a computer. This means that we can now get the Arduino to record the signal from an RF remote (in close proximity), and play it back in no time at all.
<br />
The Arduino will forget the signal when powered down or when the board is reset. The Arduino does not have an extensive memory - there is a limit to how many signals can be stored on the board at any one time. Some people have opted to create a "code" in their projects to help maximise the number of signals stored on the board. In the name of simplicity, I will not encode the signal like I did in my previous tutorials.
<br />
I will get the Arduino to record the signal and play it back - with the help of a button. The button will help manage the overall process, and control the flow of code.
<br />
Apart from uploading the sketch to the Arduino, this project will not require the use of a computer. Nor will it need a sound card, or any special libraries. Here are the parts required:
</div>
<br />
<br />
<br />
<br />
<h4>
Parts Required:</h4>
<br />
<ul>
<li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=3516" target="_blank">Arduino UNO or compatible board</a></li>
<li>Breadboard</li>
<li>Button</li>
<li>Red and Green LED </li>
<li>330 ohm resistor(s)
</li>
<li>Wires</li>
<li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=7530">RF Module (433 Mhz) - Transmitter and Receiver pair </a></li>
<li><a href="https://ceilingfanswarehouse.com.au/shop/hayman-ceiling-fan-with-light-52-in-antique-brass-by-mercator/">Mercator Ceiling Fan/Light with Remote</a></li>
<br />
</ul>
<br />
<br />
<br />
<h4>
Fritzing Sketch</h4>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-uXBwrHIyS6U/U9fU4wa1lYI/AAAAAAAAA9Y/s4rv_8DtJY0/s1600/Project4_433Mhz_Fritzing+sketch.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img height="640" src="https://2.bp.blogspot.com/-uXBwrHIyS6U/U9fU4wa1lYI/AAAAAAAAA9Y/s4rv_8DtJY0/s1600/Project4_433Mhz_Fritzing+sketch.jpg" style="border: 3px double white;" width="520" /></a>
</div>
<br />
<br />
<br />
<br />
<br />
<h4>
Arduino Sketch</h4>
<br />
<script src="https://gist.github.com/ArduinoBasics/5e7e2b4946d0954d1f2db30b9d311d7e.js"></script>
<!-- End of Arduino Code -->
<br />
<br />
<br />
Now let's see this project in action !<br />
Have a look at the video below to see the Arduino turning a light and fan on/off shortly after receiving the RF signal from the RF remote. The video will also show you how to put this whole project together - step by step.
<br />
<br />
<h4>
The Video</h4>
<br />
<div style="text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="360" src="//www.youtube.com/embed/JUyHL0G6bA0?rel=0" width="480"></iframe>
</div>
</div>
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br />
<div style="text-align: justify;">
This concludes my 433MHz transmitter and receiver tutorials (for now). I hope you enjoyed them. <br />
Please let me know whether this worked for you or not. <br />
I have not tested this project with other remotes or other frequencies - so would be interested to find out whether this technique can be used for ALL RF projects ??
</div>
<br />
<br />
<div>
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br />
</div>
<br />
<div align="center">
If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br />
<br />
Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br />
Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br />
Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.</div>
<br />
<br />
<br />
<div align="center">
<div class="separator" style="clear: both; text-align: center;">
<a href="http://arduino.cc/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1bCCWXpTGENyk_yABABb949-qJaPRa5uiLmlvJIC1t_qU9JIbd7dJFD5F3wGyHqAAP2G6xzheqIEmgKvKsDiR6TKbJkmC6qY3AAfTn0zhitELY7HDun6oB5vhHK90Qrhu0xtLdV9PsuM/s1600/ArduinoLogo.png" /></a>
</div>
</div>
<br />
<br />
<br />
<div>
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br />
</div>
However, if you do not have a google profile... <br />Feel free to share this page with your friends in any way you see fit.
<br />
<!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" -->Scott Chttp://www.blogger.com/profile/10071004090415946390noreply@blogger.com79tag:blogger.com,1999:blog-4060435813840662690.post-60288953226907370532014-07-20T02:30:00.000+08:002022-02-17T16:24:43.706+08:00433 MHz RF module with Arduino Tutorial 3<div style="text-align: justify;">
<!-- Title Page Graphic -->
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-5oPFTU4oizo/U67kMfDFJ3I/AAAAAAAAA7A/6GD7USwp6sE/s1600/433MHzTutorial3TitlePage.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="480" src="https://4.bp.blogspot.com/-5oPFTU4oizo/U67kMfDFJ3I/AAAAAAAAA7A/6GD7USwp6sE/s400/433MHzTutorial3TitlePage.jpg" width="640" />
</a>
</div>
<br />
<br />
<div>
There are 4 parts to this tutorial:<br />
<ul>
<li><a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">Part 1: Testing the 433 MHz RF transmitter and receiver</a></li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">Part 2: Receive and interpret code from an RF remote</a></li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">Part 3: Transmit a known 433 Mhz RF code to a 433 Mhz RF device</a> - ** you are here **</li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html">Part 4: Record and play back a 433 Mhz RF remote signal</a></li>
</ul>
To get the most out of this tutorial - it is best to start at tutorial <a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">Part 1</a>, and then progress to <a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">Part 2</a> then <a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">Part 3</a> and then do <a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html">Part 4</a> last.
Doing the RF tutorials in this order will help you to understand the process better. </div>
<br />
<hr />
<h4>
Project 3: RF Remote Control Emulation</h4>
<div>
In the <a href="http://arduinobasics.blogspot.com/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">first tutorial</a>, I introduced the 433 MHz Transmitter and Receiver with a simple sketch to test their functionality. In the <a href="http://arduinobasics.blogspot.com/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">second tutorial</a>, the 433MHz receiver was used to receive a signal from an RF remote. The RF remote signal was coded based on the pattern and length of its HIGH and LOW signals. The signals received by the remote can be described by the code below:
<br />
<br />
<br />
<!-- Code comparison table between Light Off and Light On -->
Code comparison table<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-lXz2lUaDBSk/U6mnypcD3oI/AAAAAAAAA6Q/TFd1Ct0zkUE/s1600/Code+Comparison.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="94" src="https://2.bp.blogspot.com/-lXz2lUaDBSk/U6mnypcD3oI/AAAAAAAAA6Q/TFd1Ct0zkUE/s1600/Code+Comparison.jpg" width="640" />
</a>
</div>
<br />
<br />
The RF remote that I am using transmits the same signal 6 times in a row. The signal to turn the light on is different from that used to turn the light off.
In <a href="http://arduinobasics.blogspot.com/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">tutorial 2</a>, we were able to "listen to" or receive the signal from the RF remote using the RF receiver. I thought it would be possible to just play back the signal received on the Arduino's analogPin, but the time it takes to perform a digital write is different to the time it takes to do an AnalogRead. Therefore
it won't work. You need to slow down the digitalWrite speed.<br />
I would like to find out if it is possible to apply this delay to all 433 MHz signal projects, however, I only have one 433 MHz remote.<br />
<br />
If the delay in your project is the same as mine (or different) I would be keen to know - please leave a comment at the end of the tutorial.
<br />
<br />
We are going to use trial and error to find the optimal digitalWrite delay time. We will do this by slowly incrementing the delay until the transmission is successful. The transmission is considered successful if the fan-light turns on/off. All we have to do is count the number of transmissions until it is successful, then we should be able to calculate the delay.
<br />
<br />
<br />
<h4>
Parts Required</h4>
<br />
<ul>
<li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=3516" target="_blank">Arduino UNO or compatible board</a></li>
<li>Breadboard</li>
<li>Wires</li>
<li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=7530">RF Module (433 Mhz) - Transmitter and Receiver pair </a></li>
<li><a href="https://ceilingfanswarehouse.com.au/shop/hayman-ceiling-fan-with-light-52-in-antique-brass-by-mercator/">Mercator Ceiling Fan/Light with Remote</a></li>
<br />
</ul>
<br />
<br />
<br />
<h4>
The Transmitter Fritzing Sketch </h4>
<table>
<tbody>
<tr>
<td><div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-mJ7vshWvfzs/U8qOuwMbwTI/AAAAAAAAA8k/YJJ8EOZNZrQ/s1600/433MHz_Transmitter_Fritzing.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;">
<img border="0" src="https://3.bp.blogspot.com/-mJ7vshWvfzs/U8qOuwMbwTI/AAAAAAAAA8k/YJJ8EOZNZrQ/s1600/433MHz_Transmitter_Fritzing.jpg" />
</a>
</div>
</td>
</tr>
</tbody>
</table>
<br />
<br />
<br />
<br />
<br />
<h4>
RF Calibration - Arduino Sketch</h4>
<br />
<script src="https://gist.github.com/ArduinoBasics/a5540a29ff6dd2cfe4b8ebb01b4612af.js"></script>
<!-- End of Arduino Code -->
</div>
<div>
I used an array to hold the RF code for light ON and light OFF. Each number within the code represents a specific sequence of HIGH and LOW lengths. For example, 2 represents a SHORT HIGH and a LONG LOW combination. A short length = 3, a long length = 7, and a very long length = 92. You need to multiply this by the timeDelay variable to identify how much time to transmit the HIGH and LOW signals for.
<br />
The short and long lengths were identified from the experiments performed in <a href="http://arduinobasics.blogspot.com/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">tutorial 2 </a>(using the RF receiver).
Each code is transmitted 6 times. The LED is turned on at the beginning of each transmission, and then turned off at the end of the transmission. The timeDelay variable starts at 5 microseconds, and is incremented by 10 microseconds with every transmission.
<br />
In the <a href="http://youtu.be/8a6KbK9ihmc">video</a>, you will notice that there is some flexibility in the timeDelay value. The Mercator Fan/Light will turn on and off when the timeDelay variable is anywhere between 75 and 135 microseconds in length. It also seems to transmit successfully when the timeDelay variable is 175 microseconds.
<br />
So in theory, if we want to transmit a signal to the fan/light, we should be able to use any value between 75 and 135, however in future projects, I think I will use a value of <b>105</b>, which is right about the middle of the range.
<br />
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br />
<h4>
Video</h4>
<iframe allowfullscreen="" frameborder="0" height="360" src="//www.youtube.com/embed/8a6KbK9ihmc?rel=0" width="480"></iframe>
<br />
<br />
<br />
Now that I have the timeDelay variable, I should be able to simplify the steps required to replicate a remote control RF signal. Maybe there is room for one more tutorial on this topic :)<br />
<br />
<span style="color: red;"><span style="font-size: large;">Update</span></span>: Here it is - <a href="http://arduinobasics.blogspot.com/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html" target="_blank">tutorial 4</a><br />
Where you can record and playback an RF signal (without using your computer).<br />
</div>
</div>
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br />
<!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" -->Scott Chttp://www.blogger.com/profile/10071004090415946390noreply@blogger.com58tag:blogger.com,1999:blog-4060435813840662690.post-49318796276715406892014-06-27T01:05:00.001+08:002022-02-17T16:24:41.726+08:00433 MHz RF module with Arduino Tutorial 2<div style="text-align: justify;">
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.icstation.com/product_info.php?ref=25&products_id=1402&affiliate_banner_id=1" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img height="475" src="https://2.bp.blogspot.com/-bKkqu8Ryg3o/U6gqOdlp8hI/AAAAAAAAA3o/-limYIoQIIU/s1600/433+MHz+Project+2+Titlepage.jpg" style="border: 3px double white;" width="640" />
</a>
</div>
<br />
<div>
<br />
There are 4 parts to this tutorial:<br />
<ul>
<li><a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">Part 1: Testing the 433 MHz RF transmitter and receiver</a></li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">Part 2: Receive and interpret code from an RF remote</a> - ** you are here **</li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">Part 3: Transmit a known 433 Mhz RF code to a 433 Mhz RF device</a></li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html">Part 4: Record and play back a 433 Mhz RF remote signal</a></li>
</ul>
To get the most out of this tutorial - it is best to start at tutorial <a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">Part 1</a>, and then progress to <a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">Part 2</a> then <a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">Part 3</a> and then do <a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html">Part 4</a> last.
Doing the RF tutorials in this order will help you to understand the process better. </div>
<br />
<hr />
<h4>
Project 2: RF Remote Copy</h4>
<div>
In the <a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">previous project</a>, we transmitted a signal wirelessly from one Arduino to another. It was there to help troubleshoot communication between the modules.
It was important to start with a very short distance (1-2 cm) and then move the RF modules further apart to test the range.
The range can be extended by soldering an antenna to the module, or by experimenting with different voltage supplies to the modules (making sure to keep within the voltage limits of the modules.) <br />
In this project - we aim to receive a signal from an RF remote. The remote that I am using is a Mercator Remote Controller for a Fan/Light.
(Remote controller code is FRM94). It is important that you use a remote that transmits at the same frequency as your receiver. In this case, my remote just happens to use a frequency of 433MHz. I was able to receive RF signals from from a distance of about 30cm without an antenna (from my remote to the receiver).</div>
<br />
<br />
<h4>
Video</h4>
<br />
<iframe allowfullscreen="" frameborder="0" height="360" src="//www.youtube.com/embed/AEJC39kTxFg?rel=0" width="480"></iframe><br />
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br />
Here are the parts that you will need to carry out this project:<br />
<br />
<br />
<h4>
Parts Required</h4>
<ul>
<li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=3516" target="_blank">1 x Arduino UNO or compatible board</a></li>
<li>Breadboard</li>
<li>Wires</li>
<li><a href="http://www.mercator.com.au/">Mercator FRM94 Remote Controller for Fan/Light (Transmitter Model: TR107A)</a></li>
<li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=7530">RF Module (433 Mhz) - Receiver </a></li>
</ul>
<br />
<h4>
Remote Controller</h4>
<br />
You can quickly test your remote, by pressing one of the buttons in close proximity to the RF receiver (using the same sketch as in <a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">Project 1</a>), and you should see the LED flicker on an off in response to the button press. If you don't see the LED flickering, then this project will not work for you.
<br />
<br />
Here is a picture of the remote controller that I am using:<br />
<table>
<tbody>
<tr>
<td><div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-hX2IgmEId1M/U6ejlD1SQ8I/AAAAAAAAA3I/8yUzYCO5T-E/s1600/Mercator_Remote_FRM94.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img height="320" src="https://3.bp.blogspot.com/-hX2IgmEId1M/U6ejlD1SQ8I/AAAAAAAAA3I/8yUzYCO5T-E/s1600/Mercator_Remote_FRM94.jpg" style="border: 3px double white;" width="133" />
</a>
</div>
</td>
<td><div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-wIEi6eh6CBQ/U6elSm_-O4I/AAAAAAAAA3U/tGUPHENPwR0/s1600/MercatorRemote_Inside3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img height="320" src="https://3.bp.blogspot.com/-wIEi6eh6CBQ/U6elSm_-O4I/AAAAAAAAA3U/tGUPHENPwR0/s1600/MercatorRemote_Inside3.jpg" style="border: 3px double white;" width="242" />
</a>
</div>
</td>
</tr>
</tbody>
</table>
<br />
<br />
<br />
<br />
<div>
<h4>
Arduino Sketch - Remote Receiver</h4>
<div>
The following sketch will make the Arduino wait until a signal is detected from the remote (or other 433 MHz RF device). Once triggered, it will turn the LED ON, and start to collect and store the signal data into an array.<br />
I did my best to keep the signal reading section of the sketch free from other functions or interruptions.The aim is to get the Arduino to focus on reading ONLY... and once the reading phase is complete, it will report the signal data to the Serial monitor. So you will need to have the Serial monitor open when you press the remote control button.<br />
The remote control signal will be made up of HIGH and LOW signals - which I will try to illustrate later in the tutorial. But for now, all you need to know is that the Signal will alternate between HIGH and LOW signals, and that they can be different lengths. <br />
This sketch aims to identify how long each LOW and HIGH signal is (to make up the complete RF remote signal). I have chosen to capture 500 data points(or 250 LOW/HIGH combinations).You may wish to increase or decrease the dataSize variable to accomodate your specific RF signal. In my case, I only really needed 300 data points, because there was a "flat" signal for the last 200 data points (characterised by 200 repetitions of a LOW signal length of 0 and HIGH signal length of 255)</div>
<br />
--------------------------------------------------
<br />
<script src="https://gist.github.com/ArduinoBasics/76e05a69b1817bef32b171646486d88f.js"></script>
<!-- End of Arduino Code -->
<br />
<br />
<h4>
Receiver Fritzing Sketch</h4>
<div style="overflow: auto; width: auto;">
<table style="border: 3px double white;">
<tbody>
<tr>
<td rowspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-KcIOc9fUYQE/U6gwWXHFnPI/AAAAAAAAA4I/zEWBeEYLaog/s1600/Receiver_Only_Fritzing.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;">
<img border="0" height="400" src="https://2.bp.blogspot.com/-KcIOc9fUYQE/U6gwWXHFnPI/AAAAAAAAA4I/zEWBeEYLaog/s1600/Receiver_Only_Fritzing.jpg" width="290" />
</a>
</div>
</td>
<td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg35n3k_pjSMWCS7Q72co1Wgbo4Jnd3Yi6xnhKy9dbCGI6Wa8lo72XUNcRLtLHKm79jZJYwLKx8f36kPcz8_ZJqco8oybkOI_07LtutirfW0K5cjYhvNIYa3u3WA_gvII3BVlRu5NnIxVQ/s1600/433MhzReceiverFront2.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;">
<img border="0" height="125" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg35n3k_pjSMWCS7Q72co1Wgbo4Jnd3Yi6xnhKy9dbCGI6Wa8lo72XUNcRLtLHKm79jZJYwLKx8f36kPcz8_ZJqco8oybkOI_07LtutirfW0K5cjYhvNIYa3u3WA_gvII3BVlRu5NnIxVQ/s1600/433MhzReceiverFront2.gif" width="200" />
</a>
</div>
</td>
</tr>
<tr>
<td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhARrjD1TYFbxRoFk6Jzzc7Bw4mLhDX24KBptBAOBVj6VW2pkXhEK9mf8bS6t_JmLISahvs39xeWiKJGwWZxiauUCDopgv6RXfJSM_1-mAwsRcvNQpCkyAwrOHqlfklVHUA_XfCZ3JJJs/s1600/RF+Receiver+Table.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhARrjD1TYFbxRoFk6Jzzc7Bw4mLhDX24KBptBAOBVj6VW2pkXhEK9mf8bS6t_JmLISahvs39xeWiKJGwWZxiauUCDopgv6RXfJSM_1-mAwsRcvNQpCkyAwrOHqlfklVHUA_XfCZ3JJJs/s1600/RF+Receiver+Table.gif" width="300" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-xF0vSFF5Hdw/U6mlTvzmpsI/AAAAAAAAA6E/KNlhXtbmg5Q/s1600/433+MHz+RF+Project+2+Live+Sketch.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img height="356" src="https://3.bp.blogspot.com/-xF0vSFF5Hdw/U6mlTvzmpsI/AAAAAAAAA6E/KNlhXtbmg5Q/s1600/433+MHz+RF+Project+2+Live+Sketch.JPG" style="border: 3px solid #464746;" width="600" />
</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<br />
<br />
<div>
<h4>
Results</h4>
After pressing the button on the RF remote, the data signal is printed to the Serial Monitor. You can copy the data to a spreadsheet program for review.
This is an example of the signal produced after pushing the button on the remote for turning the fan/light on.
<br />
<table>
<tbody>
<tr>
<td colspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-1O0eaVqjgOk/U6mlIfJB_oI/AAAAAAAAA4c/TmivvjAOTV8/s1600/LightOn_SerialMonitorReadings.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="400" src="https://3.bp.blogspot.com/-1O0eaVqjgOk/U6mlIfJB_oI/AAAAAAAAA4c/TmivvjAOTV8/s1600/LightOn_SerialMonitorReadings.jpg" width="191" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2">The following code was produced from pushing the button responsible for turning the light off:</td>
</tr>
<tr>
<td colspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-h7lsUzWkH58/U6mlJc4-uJI/AAAAAAAAA4k/roq_l5Hx5Xk/s1600/LightOff_SerialMonitorReadings.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="400" src="https://2.bp.blogspot.com/-h7lsUzWkH58/U6mlJc4-uJI/AAAAAAAAA4k/roq_l5Hx5Xk/s1600/LightOff_SerialMonitorReadings.jpg" width="183" /><br /><br />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2">The code sequence above may seem a bit random until you start graphing it. I grabbed the LOW column - and produced the following chart:
<br />
</td>
</tr>
<tr>
<td colspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-VYdgh5DycPc/U6mlLC5L1iI/AAAAAAAAA40/xKWja_AK78Y/s1600/LightOn_LowSignalLengthChart_Raw.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="185" src="https://4.bp.blogspot.com/-VYdgh5DycPc/U6mlLC5L1iI/AAAAAAAAA40/xKWja_AK78Y/s1600/LightOn_LowSignalLengthChart_Raw.jpg" width="640" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2">The chart above is a bit messy - mainly because the timing is slightly out... in that sometimes it can squeeze an extra read from a particular signal. But what is important to note here is that you can differentiate a LONG signal from a SHORT signal. I have drawn a couple of red dotted lines where I believe most of the readings tend to sit. I then used a formula in the spreadsheet to calibrate the readings and make them a bit more uniform. For example, if the length of the signal was greater than 4 analogReads, then I converted this to 6. If it was less than 4 analogReads, then I converted it to 2. I used a frequency table to help decide on the cutoff value of 4, and just decided to pick the two values (2 for short, and 6 for long) based on the frequency tables below. I could have chosen 5 as the LONG value, but there were more 6's overall. <br />
<br />
**The meaning of "frequency" in the following tables relate to the "number of times" a specific signal length is recorded.</td>
</tr>
<tr>
<td><div class="separator" style="clear: both; text-align: left;">
<a href="http://1.bp.blogspot.com/-L0fIETV1P-Q/U6mlMme-XMI/AAAAAAAAA5E/ar4iYl48VKk/s1600/LightOn_LowLengthFrequency.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" src="https://1.bp.blogspot.com/-L0fIETV1P-Q/U6mlMme-XMI/AAAAAAAAA5E/ar4iYl48VKk/s1600/LightOn_LowLengthFrequency.jpg" />
</a>
</div>
</td>
<td><div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-j8PqCR2wnao/U6mlNRQL_rI/AAAAAAAAA5M/V-QGPzH1EQs/s1600/LightOn_HighLengthFrequency.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" src="https://4.bp.blogspot.com/-j8PqCR2wnao/U6mlNRQL_rI/AAAAAAAAA5M/V-QGPzH1EQs/s1600/LightOn_HighLengthFrequency.jpg" />
</a>
</div>
</td>
</tr>
<tr>
<td><br />
<br />
And this is the resulting chart:</td>
</tr>
<tr>
<td colspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-zuRuXBYDFoA/U6mlL1TwWNI/AAAAAAAAA48/rjfuCGMHEnA/s1600/LightOn_LowSignalLengthChart_Calibrated.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="186" src="https://3.bp.blogspot.com/-zuRuXBYDFoA/U6mlL1TwWNI/AAAAAAAAA48/rjfuCGMHEnA/s1600/LightOn_LowSignalLengthChart_Calibrated.jpg" width="640" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2"><br />
You will notice that the pattern is quite repetitive. I helped to identify the sections with vertical red lines (near the bottom of the chart). In other words, the signal produced by the remote is repeated 6 times. <br />
I then did the same for the HIGH signal column and combined the two to create the following chart:<br />
<br />
</td>
</tr>
<tr>
<td colspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-ReFeYTnfQUw/U6mlOKmBcaI/AAAAAAAAA5U/JjtsO37El8o/s1600/LightOn_Combined+Signals+Chart.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="184" src="https://2.bp.blogspot.com/-ReFeYTnfQUw/U6mlOKmBcaI/AAAAAAAAA5U/JjtsO37El8o/s1600/LightOn_Combined+Signals+Chart.jpg" width="640" />
</a>
</div>
<br />
<br />
</td>
</tr>
<tr>
<td colspan="2">You will notice that the HIGH signals also have a repetitive pattern, however have a Very long length at the end of each section. This is almost a break to separate each section.<br />
This is what a single section looks like zoomed in: <br />
</td>
</tr>
<tr>
<td colspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-n_0FZDRN_kk/U6mlPcENxwI/AAAAAAAAA5c/il3udhEU3RE/s1600/LightOn_Combined+Signals+Zoomed+In.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="184" src="https://2.bp.blogspot.com/-n_0FZDRN_kk/U6mlPcENxwI/AAAAAAAAA5c/il3udhEU3RE/s1600/LightOn_Combined+Signals+Zoomed+In.jpg" width="640" />
</a>
</div>
</td>
</tr>
<tr>
<td colspan="2"><br />
<br />
<br />
SL = [Short LOW] signal. - or short blue bar<br />
SH = [Short HIGH] signal - or short yellow bar<br />
LL = [Long LOW] signal - or long blue bar<br />
LH = [Long HIGH] signal - or long yellow bar<br />
VLH = [Very long HIGH} signal - or very long yellow bar (~92 analogReads in length)<br />
<br />
<br />
You will notice that there are only about 6 different combinations of the signals mentioned above. We can use this to create a coding system as described below:<br />
</td>
</tr>
<tr>
<td colspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-teEoJrwil7Y/U6mlKDPAzjI/AAAAAAAAA4s/EpBZ9B7tGiA/s1600/Coding_System.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="240" src="https://4.bp.blogspot.com/-teEoJrwil7Y/U6mlKDPAzjI/AAAAAAAAA4s/EpBZ9B7tGiA/s1600/Coding_System.jpg" width="640" />
</a>
</div>
<br />
<br />
</td>
</tr>
<tr>
<td colspan="2">We can use this coding system to describe the signals. The charts below show the difference between turning the LIGHT ON and LIGHT OFF. <br />
</td>
</tr>
<tr>
<td colspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-QJFP4aNLi64/U6mlS2zl9bI/AAAAAAAAA58/fsEdIG85lkc/s1600/RF+Chart+Code+Comparison.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="186" src="https://3.bp.blogspot.com/-QJFP4aNLi64/U6mlS2zl9bI/AAAAAAAAA58/fsEdIG85lkc/s1600/RF+Chart+Code+Comparison.gif" width="640" />
</a>
</div>
<br />
<br />
</td>
</tr>
<tr>
<td colspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-lXz2lUaDBSk/U6mnypcD3oI/AAAAAAAAA6Q/TFd1Ct0zkUE/s1600/Code+Comparison.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="94" src="https://2.bp.blogspot.com/-lXz2lUaDBSk/U6mnypcD3oI/AAAAAAAAA6Q/TFd1Ct0zkUE/s1600/Code+Comparison.jpg" width="640" />
</a>
</div>
<br />
<br />
</td>
</tr>
<tr>
<td colspan="2">PLEASE NOTE: You may notice when you copy the signals from the Serial monitor that you get a series of (0,255) combinations. This is actually a timeout sequence - which generally occurs after the signal is complete. <br />
<br />
Here is an example of what I mean.</td>
</tr>
<tr>
<td colspan="2"><div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-PHPdy0eSSbE/U6mlQafHi8I/AAAAAAAAA5s/1W076b4p188/s1600/TimeOut+Sequence.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="320" src="https://1.bp.blogspot.com/-PHPdy0eSSbE/U6mlQafHi8I/AAAAAAAAA5s/1W076b4p188/s1600/TimeOut+Sequence.jpg" width="201" />
</a>
</div>
</td>
</tr>
</tbody>
</table>
<br />
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br />
This is the end of tutorial 2. In the <a href="http://arduinobasics.blogspot.com/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">next tutorial</a>, we will use the code acquired from the remote to turn the FAN LIGHT on and off (using the 433 MHz RF transmitter).
<br />
<br />
<h3>
<a href="http://arduinobasics.blogspot.com/2014/07/433-mhz-rf-module-with-arduino-tutorial.html"> Click here for Tutorial 3</a></h3>
</div>
</div>
</div>
<!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" -->Scott Chttp://www.blogger.com/profile/10071004090415946390noreply@blogger.com83tag:blogger.com,1999:blog-4060435813840662690.post-80358366280031757362014-06-23T12:47:00.000+08:002022-02-17T16:24:37.968+08:00433 MHz RF module with Arduino Tutorial 1<div>
<header><div class="separator" style="clear: both; text-align: center;">
<a href="http://www.icstation.com/product_info.php?ref=25&products_id=1402&affiliate_banner_id=1" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://2.bp.blogspot.com/-Be1965Fn0dg/U6cQnQWNLGI/AAAAAAAAA2k/kokoknq-Hmg/s640/433MHz%2520Tutorial%2520Title%2520Page.jpg" width="640" />
</a>
</div>
</header>
<br />
<div>
There are 4 parts to this tutorial:<br />
<ul>
<li><a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">Part 1: Testing the 433 MHz RF transmitter and receiver</a> <- are="" here="" li="" you="">
</-></li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">Part 2: Receive and interpret code from an RF remote</a></li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">Part 3: Transmit a known 433 Mhz RF code to a 433 Mhz RF device</a></li>
<li><a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html">Part 4: Record and play back a 433 Mhz RF remote signal</a></li>
</ul>
To get the most out of this tutorial - it is best to start at tutorial <a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial.html">Part 1</a>, and then progress to <a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">Part 2</a> then <a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">Part 3</a> and then do <a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html">Part 4</a> last.
Doing the RF tutorials in this order will help you to understand the process better. </div>
<br />
<hr />
<br />
<div style="text-align: justify;">
If you are looking for a way to communicate between Arduinos, but don't have much cash at your disposal, then look no further.
These RF modules are not only affordable, but easy to use. They are much easier to set up than an XBee,
plus you can use them without the need of a special shield.
Before you rush out and buy a ton of these modules, make sure that you are not breaking any radio transmission laws in your country.
Do your research, and buy them only if you are allowed to use them in your area.
There are a few [OPTIONAL] libraries that can be used to help you and your particular project.
<br />
<br />
<ul>
<li><a href="http://www.icstation.com/ebay/IC/All%20data%20modules/1402.zip">Virtual Wire (at ICStation)</a>
</li>
<li><a href="http://www.airspayce.com/mikem/arduino/RadioHead">RadioHead - which supercedes VirtualWire</a></li>
<li><a href="https://code.google.com/p/rc-switch/">RC-Switch for communication with remote controls</a></li>
<li><a href="https://github.com/ninjablocks/433Utils">Ninjablocks 433 Utilities</a></li>
</ul>
<br />
I will mention at this point however, that I did NOT use any libraries in this particular tutorial. That's right. I will show how easy it is to transmit data from one arduino to another using these RF modules WITHOUT libraries.<br />
<br />
Also if you are looking for an easy way to record the signals and play them back without a computer - then jump to <a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html" target="_blank">this tutorial</a>.<br />
<br />
<h4>
Video</h4>
<br />
<iframe allowfullscreen="" frameborder="0" height="360" src="//www.youtube.com/embed/I5ytC2zKj7M?rel=0" width="480"></iframe><br />
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br />
<h4>
Project 1- RF Blink</h4>
<br />
<div>
Firstly we need to test if the RF modules are working. So we will design a very simple transmit and receive sketch to test
their functionality. We will use the Arduino's onboard LED to show when the transmitter is transmitting,
and when the other Arduino is receiving. There will be a slight delay between the two Arduinos. You can solder an antenna onto these modules, however I did not do this, I just kept the modules close together (1-2cm apart). I also found that I was getting better accuracy when I used 3V instead of 5V to power the receiver. While using 5V for VCC on the receiver, I would get a lot of interference, however with 3V, I hardly got any noise. If you find you are getting unpredictable results, I would suggest you switch to 3V on the receiver and move the transmitter and receiver modules right next to each other. Remember this is just a check... you can experiment with an antenna or a greater distance afterwards.
</div>
<br />
Here are the parts that you will need to carry out this project:<br />
<br />
<h4>
Parts Required</h4>
<ul>
<li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=3516" target="_blank">2 x Arduino UNO or compatible boards</a></li>
<li>Breadboard</li>
<li>Wires</li>
<li><a href="http://www.icstation.com/product_info.php?aid=10&products_id=7530">RF Module (433 Mhz) - Transmitter and Receiver pair </a></li>
<br />
</ul>
<br />
<br />
<br />
<h4>
The Transmitter and Receiver Fritzing Sketch </h4>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-SKxrkuqhGtw/U6QqKGBxgTI/AAAAAAAAAuA/0TsUeh2yV2s/s1600/Transmitter_Receiver_Fritzing_V2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="427" src="https://4.bp.blogspot.com/-SKxrkuqhGtw/U6QqKGBxgTI/AAAAAAAAAuA/0TsUeh2yV2s/s1600/Transmitter_Receiver_Fritzing_V2.jpg" width="640" />
</a>
</div>
<br />
<br />
<br />
<br />
<h4>
The Transmitter</h4>
The transmitter has 3 pins
<br />
<br />
<table><tbody>
<tr><td>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrHkzLp7KChemIk1iRMikWoFJmbE0ZZtxHQ5C0jWReXtlJWLGvBt2_YZWkcU68OqAc7rbc7oEIFQolNRX9mBI2Nae4KiuGwcH2R7uELmeE-RwgodU__q8v9B_zhmkzTNDm9NUg0yIDXJg/s1600/433MhzTransmitter2.gif" 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/AVvXsEhrHkzLp7KChemIk1iRMikWoFJmbE0ZZtxHQ5C0jWReXtlJWLGvBt2_YZWkcU68OqAc7rbc7oEIFQolNRX9mBI2Nae4KiuGwcH2R7uELmeE-RwgodU__q8v9B_zhmkzTNDm9NUg0yIDXJg/s1600/433MhzTransmitter2.gif" width="157" />
</a></td>
<td>
<a href="http://1.bp.blogspot.com/-v5FuJwwzGD4/U6RTTrAvZBI/AAAAAAAAAx4/VWLFK2bCuN4/s1600/RF+Transmitter+Table.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="192" src="https://1.bp.blogspot.com/-v5FuJwwzGD4/U6RTTrAvZBI/AAAAAAAAAx4/VWLFK2bCuN4/s400/RF+Transmitter+Table.gif" width="400" /></a></td>
</tr>
</tbody>
</table>
<br />
<br />
<br />
Notice the pin called "ATAD". It took me a while to figure out what ATAD stood for, when I suddenly realised that this was just a word reversed.
It should be DATA (not ATAD). Nevertheless, this is the pin responsible for transmitting the signal.
We will make the Arduino's onboard LED illuminate when the transmitter pin is HIGH, and go off when LOW as described in the following table.<br />
<br />
<br />
<a href="http://4.bp.blogspot.com/-IsIzfzChE_U/U6WpBuVZf3I/AAAAAAAAAzk/WcPlvzEtXWU/s1600/Transmission_Times_High_and_Low.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="320" src="https://4.bp.blogspot.com/-IsIzfzChE_U/U6WpBuVZf3I/AAAAAAAAAzk/WcPlvzEtXWU/s1600/Transmission_Times_High_and_Low.gif" width="200" /> </a><br />
<br />
<br />
<br />
And this is the Arduino Sketch to carry out the data transmission.<br />
<h3>
<br /></h3>
<h3>
<br /></h3>
<h3>
<br /></h3>
<h3>
Arduino sketch - Transmitter</h3>
<div style="background: rgb(24,186,183);">
<script src="https://gist.github.com/ArduinoBasics/9df2880705e9c85a1213131817245d5d.js"></script>
</div>
<br />
<br />
<br />
<br />
<br />
<br />
<h4>
The Receiver</h4>
<br />
<table><tbody>
<tr><td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg35n3k_pjSMWCS7Q72co1Wgbo4Jnd3Yi6xnhKy9dbCGI6Wa8lo72XUNcRLtLHKm79jZJYwLKx8f36kPcz8_ZJqco8oybkOI_07LtutirfW0K5cjYhvNIYa3u3WA_gvII3BVlRu5NnIxVQ/s1600/433MhzReceiverFront2.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;">
<img border="0" height="125" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg35n3k_pjSMWCS7Q72co1Wgbo4Jnd3Yi6xnhKy9dbCGI6Wa8lo72XUNcRLtLHKm79jZJYwLKx8f36kPcz8_ZJqco8oybkOI_07LtutirfW0K5cjYhvNIYa3u3WA_gvII3BVlRu5NnIxVQ/s1600/433MhzReceiverFront2.gif" width="200" />
</a>
</div>
</td>
<td><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhARrjD1TYFbxRoFk6Jzzc7Bw4mLhDX24KBptBAOBVj6VW2pkXhEK9mf8bS6t_JmLISahvs39xeWiKJGwWZxiauUCDopgv6RXfJSM_1-mAwsRcvNQpCkyAwrOHqlfklVHUA_XfCZ3JJJs/s1600/RF+Receiver+Table.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhARrjD1TYFbxRoFk6Jzzc7Bw4mLhDX24KBptBAOBVj6VW2pkXhEK9mf8bS6t_JmLISahvs39xeWiKJGwWZxiauUCDopgv6RXfJSM_1-mAwsRcvNQpCkyAwrOHqlfklVHUA_XfCZ3JJJs/s1600/RF+Receiver+Table.gif" width="320" />
</a>
</div>
</td></tr>
<tr><td colspan="2"><br />
<div>
If all goes to plan, the onboard LED on this Arduino should light up (and go off) at the same time as the onboard LED on
the transmitting Arduino. There is a chance that the receiver may pick up stray signals from other transmitting devices using
that specific frequency. So you may need to play around with the threshold value to eliminate the "noise".
But don't make it too big, or you will eliminate the signal in this experiment.
You will also notice a small delay between the two Arduinos.
</div>
</td></tr>
</tbody></table>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<br />
<h3>
Arduino sketch - Receiver</h3>
<div style="background: rgb(24,186,183);">
<script src="https://gist.github.com/ArduinoBasics/7a9f30e85bf980d59d777eb7483898e1.js"></script>
</div>
</div>
<br />
<div>
<br />
<br />
When a HIGH signal is transmitted to the other Arduino. It will produce an AnalogRead = 0.<br />
When a LOW signal is transmitted, it will produce an AnalogRead = 400. <br />
This may vary depending on on your module, and voltage used.<br />
The signals received can be viewed using the Serial Monitor, and can be copied into a spreadsheet to create a chart like this:</div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-8Pnoi37Y_7Q/U6WpBoPz6YI/AAAAAAAAAzo/edJXomElRQc/s1600/AnalogReadingsChart.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;">
<img border="0" height="200" src="https://4.bp.blogspot.com/-8Pnoi37Y_7Q/U6WpBoPz6YI/AAAAAAAAAzo/edJXomElRQc/s1600/AnalogReadingsChart.gif" width="640" />
</a>
</div>
<br />
<br />
<div>
You will notice that the HIGH signal (H) is constant, whereas the LOW signal (L) is getting smaller with each cycle. I am not sure why the HIGH signal produces a Analog reading of "0". I would have thought it would have been the other way around. But you can see from the results that a HIGH signal produces a 0 result and a LOW signal produces a value of 400 (roughly).
</div>
<br />
<br />
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br />
<br />
<h4>
<a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">Tutorial 2</a></h4>
In <a href="http://arduinobasics.blogspot.com.au/2014/06/433-mhz-rf-module-with-arduino-tutorial_27.html">tutorial 2</a>, we will receive and display a signal from a Mercator RF Remote Controller for Fan/Light.<br />
<br />
<br />
<h4>
<a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">Tutorial 3</a></h4>
In <a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial.html">tutorial 3</a> - we use the signal acquired from tutorial 2, and transmit the signal to the fan/light to turn the light on and off.<br />
<br />
<br />
<h4>
<a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html">Tutorial 4</a></h4>
In <a href="http://arduinobasics.blogspot.com.au/2014/07/433-mhz-rf-module-with-arduino-tutorial_30.html">tutorial 4</a> - we use the information gathered in the first 3 tutorials and do away with the need for a computer. We will listen for a signal, store the signal, and then play it back by pressing a button. Similar to a universal remote ! No libraries, no sound cards, no computer. Just record signal and play it back. Awesome !!<br />
<br />
<br />
<br />
<br />
<div>
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br /></div>
<br />
<div align="center">
If you like this page, please do me a favour and show your appreciation : <g:plusone></g:plusone><br />
<br />
Visit my <a href="https://plus.google.com/u/0/b/107402020974762902161/107402020974762902161/posts">ArduinoBasics Google + page</a>.<br />
Follow me on Twitter by looking for <a href="https://twitter.com/ArduinoBasics">ScottC @ArduinoBasics</a>.<br />
Have a look at my videos on my <a href="https://www.youtube.com/user/ScottCMe/videos">YouTube channel</a>.</div>
<br />
<br />
<br />
<br />
<div align="center">
<div class="separator" style="clear: both; text-align: center;">
<a href="http://arduino.cc/" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1bCCWXpTGENyk_yABABb949-qJaPRa5uiLmlvJIC1t_qU9JIbd7dJFD5F3wGyHqAAP2G6xzheqIEmgKvKsDiR6TKbJkmC6qY3AAfTn0zhitELY7HDun6oB5vhHK90Qrhu0xtLdV9PsuM/s1600/ArduinoLogo.png" /></a>
</div>
</div>
<br />
<br />
<br />
<br />
<div>
<!--separator -->
<img alt="" height="22" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" width="98%" /><br />
<br /></div>
However, if you do not have a google profile... <br />
Feel free to share this page with your friends in any way you see fit.
</div>
<br />
<br />
<br />
<br />
<footer>
© Copyright by ScottC
<br />
</footer>
<!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-XQiwNpdqOxk%2FT_rKCzDh4nI%2FAAAAAAAAAQY%2FOfYBljhU6Lk%2Fs1600%2FSeparator.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-05dRniSqRvHu8QncyNAuOu61uNqeM-wQpytccKH2t-EEJmKKEupI1mqzvYN7KcL-UFPDqt3v-KSn4C8-gMZ3dQ8cHh97Nx9unEwIFPZCDoDp3gpl-3vot4J8ywEFKdPTwWL2wArxgNA/s1600/Separator.jpg" -->Scott Chttp://www.blogger.com/profile/10071004090415946390noreply@blogger.com208