-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
822 lines (740 loc) · 29 KB
/
index.html
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
<!DOCTYPE html>
<html>
<head>
<title>Kerala IOT Workshop</title>
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<h1><strong>Kerala IOT level 1 challenge</strong></h1>
<hr>
<div class="para1">
<h3><strong><u>About Me</u></strong></h3>
<p>Hello everyone,My name is Abin T Sunil.<br>I am a first year btech computer science student studying at <a href="https://ceconline.edu/">College of Engineering Chengannur</a></p>
<p>My social media handles<br>LinkedIn-<a href="https://www.linkedin.com/in/abin-t-sunil-89b760205/">Click Me</a></p>
<img width="300px" height="200px" src="iot_images_and_videos/profile photo.jpeg">
<h3><strong><u>About this page</u></strong></h3>
<p>This page is used to track the improvements in my workshop conducted by GTech Mulearn in associated with FoxLab</p>
<h3><strong><u>Experiment List</u></strong></h3>
<table border="2px">
<thead>
<tr>
<th>Exp No</th>
<th>List</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>LED Blinking</td>
</tr>
<tr>
<td>2</td>
<td>Traffic Light</td>
</tr>
<tr>
<td>3</td>
<td>LED Chasing</td>
</tr>
<tr>
<td>4</td>
<td>Button controlled LED</td>
</tr>
<tr>
<td>5</td>
<td>Buzzer</td>
</tr>
<tr>
<td>6</td>
<td>RGB LED</td>
</tr>
<tr>
<td>7</td>
<td>LDR Light sensor</td>
</tr>
<tr>
<td>8</td>
<td>Flame sensor</td>
</tr>
<tr>
<td>9</td>
<td>Temperature sensor</td>
</tr>
<tr>
<td>10</td>
<td>IR Remote control</td>
</tr>
<tr>
<td>11</td>
<td>Potentiometer Analog value reading</td>
</tr>
<tr>
<td>12</td>
<td>7 Segment display</td>
</tr>
</tbody>
</table>
<h2><strong><u> Experiment:1</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>220 ohm resistor x 1</li>
<li>LED(Any colour) x 1</li>
<li>Breadboard x 1</li>
<li>Jumper wires(male to male) x 2</li>
</ul>
<h3><stong>Code</stong></h3>
<code>void setup()<br> {<br>
pinMode(8,OUTPUT);<br>
}<br>
void loop() <br>{<br>
digitalWrite(8,HIGH);<br>
delay(5000);<br>
digitalWrite(8,LOW);<br>
delay(5000);<br>
}</code>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/led blinking video.mp4">
</video>
<h2><strong><u>Experiment:2</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>220 ohm resistor x 3</li>
<li>Red M5 LED x 1</li>
<li>Yellow M5 LED x 1</li>
<li>Green M5 LED x 1</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
</ul>
<h3><stong>Code</stong></h3>
<code>int greenled=12;<br>
int yellowled=9;<br>
int redled=6;<br>
void setup() <br>{<br>
pinMode(greenled,OUTPUT);<br>
pinMode(yellowled,OUTPUT);<br>
pinMode(redled,OUTPUT);<br>
}<br>
void loop()<br> {<br>
digitalWrite(greenled,HIGH);<br>
delay(5000);<br>
digitalWrite(greenled,LOW);<br>
for(int i=0;i<3;i++)<br>
{<br>
delay(500);<br>
digitalWrite(yellowled,HIGH);<br>
delay(500);<br>
digitalWrite(yellowled,LOW);<br>
}<br>
delay(500);<br>
digitalWrite(redled, HIGH);<br>
delay(5000);<br>
digitalWrite(redled, LOW);<br>
}<br>
</code>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/traffic light video.mp4">
</video>
<h2><strong><u> Experiment:3</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>220 ohm resistor x 1</li>
<li>LED(Any colour) x 4</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
</ul>
<h3><stong>Code</stong></h3>
<code>int BASE = 2;<br>
int NUM = 4;<br>
void setup()<br>
{<br>
for (int i = BASE; i < BASE + NUM; i ++)<br>
{<br>
pinMode(i, OUTPUT);<br>
}<br>
}<br>
void loop()<br>
{<br>
for (int i = BASE; i < BASE + NUM; i ++) <br>
{<br>
digitalWrite(i, LOW);<br>
delay(200); <br>
}<br>
for (int i = BASE; i < BASE + NUM; i ++) <br>
{<br>
digitalWrite(i, HIGH);<br>
delay(200);<br>
} <br>
}
</code>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/led chasing video.mp4">
</video>
<h2><strong><u> Experiment:4</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>220 ohm resistor x 1</li>
<li>10k ohm resistor x 1</li>
<li>LED(Any colour) x 1</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
<li>Button switch x 1</li>
</ul>
<h3><stong>Code</stong></h3>
<code>
int ledpin=11;// initialize pin 11<br>
int inpin=7;// initialize pin 7<br>
int val;// define val<br>
void setup()<br>
{<br>
pinMode(ledpin,OUTPUT);// set LED pin as “output”<br>
pinMode(inpin,INPUT);// set button pin as “input”<br>
}<br>
void loop()<br>
{<br>
val=digitalRead(inpin);// read the level value of pin 7 and assign if to val<br>
if(val==LOW)// check if the button is pressed, if yes, turn on the LED<br>
{ digitalWrite(ledpin,LOW);}<br>
else<br>
{ digitalWrite(ledpin,HIGH);}<br>
}<br>
</code>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/button controlled led.mp4">
</video>
<h2><strong><u> Experiment:5</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>Buzzer x 1</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
</ul>
<h3><stong>Code</stong></h3>
<code>
int buzzer=8;// initialize digital IO pin that controls the buzzer<br>
void setup() <br>
{ <br>
pinMode(buzzer,OUTPUT);// set pin mode as “output”<br>
} <br>
void loop() <br>
{<br>
digitalWrite(buzzer, HIGH); // produce sound<br>
}<br>
</code>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/buzzer.mp4">
</video>
<h2><strong><u> Experiment:6</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>RGB LED x 1</li>
<li>Resistors</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
</ul>
<h3><stong>Code</stong></h3>
<code>
int redpin = 11; //select the pin for the red LED<br>
int bluepin =10; // select the pin for the blue LED<br>
int greenpin =9;// select the pin for the green LED<br>
int val;<br>
void setup() {<br>
pinMode(redpin, OUTPUT);<br>
pinMode(bluepin, OUTPUT);<br>
pinMode(greenpin, OUTPUT);<br>
Serial.begin(9600);<br>
}<br>
void loop() <br>
{<br>
for(val=255; val>0; val--)<br>
{<br>
analogWrite(11, val);<br>
analogWrite(10, 255-val);<br>
analogWrite(9, 128-val);<br>
delay(1); <br>
}<br>
for(val=0; val<255; val++) <br>
{<br>
analogWrite(11, val);<br>
analogWrite(10, 255-val);<br>
analogWrite(9, 128-val);<br>
delay(1); <br>
}
Serial.println(val, DEC);<br>
}
</code>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/RGB LED.mp4">
</video>
<h2><strong><u> Experiment:7</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>Red M5 LED x 1</li>
<li>10k ohm Resistors</li>
<li>220 ohm resistor</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
<li>Photoresistor x 1</li>
</ul>
<h3><stong>Code</stong></h3>
<code>
const int ldr = 7;<br>
const int led = 13;<br>
void setup() {<br>
pinMode(ldr,INPUT);//define pin as input sensor<br>
pinMode(led,OUTPUT);//define pin as output sensor<br>
}<br>
void loop() {<br>
int y =digitalRead(ldr);//read the sensor<br>
if (y==1){<br>
digitalWrite(led,HIGH);//turn on led<br>
}else{digitalWrite(led,LOW);//turn off led<br>
}<br>
delay(500);<br>
}
</code>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/LDR.mp4">
</video>
<h2><strong><u> Experiment:8</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>Flame sensor x 1</li>
<li>10k ohm Resistor x 1</li>
<li>Buzzer x 1</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
</ul>
<h3><stong>Code</stong></h3>
<code>
int flame=0;// select analog pin 0 for the sensor<br>
int Beep=9;// select digital pin 9 for the buzzer<br>
int val=0;// initialize variable<br>
void setup() <br>
{<br>
pinMode(Beep,OUTPUT);// set LED pin as “output”<br>
pinMode(flame,INPUT);// set buzzer pin as “input”<br>
Serial.begin(9600);// set baud rate at “9600”<br>
} <br>
void loop()<br>
{ <br>
val=analogRead(flame);// read the analog value of the sensor <br>
Serial.println(val);// output and display the analog value<br>
if(val>=600)// when the analog value is larger than 600, the buzzer will buzz<br>
{ <br>
digitalWrite(Beep,HIGH);<br>
}else <br>
{ <br>
digitalWrite(Beep,LOW);<br>
}<br>
delay(500); <br>
}<br>
</code>
<h3><strong>Problems faced</strong></h3>
<p>I tried this experiments and watched others work.But I am not able to solve the problem</p>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/">
</video>
<h2><strong><u> Experiment:9</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>LM35 x 1</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
</ul>
<h3><stong>Code</stong></h3>
<code>
int potPin = 0; // initialize analog pin 0 for LM35 temperature sensor<br>
void setup()<br>
{<br>
Serial.begin(9600);// set baud rate at”9600”<br>
}<br>
void loop()<br>
{<br>
int val;// define variable<br>
int dat;// define variable<br>
val=analogRead(0);// read the analog value of the sensor and assign it to val<br>
dat=(125*val)>>8;// temperature calculation formula<br>
Serial.print("Tep");// output and display characters beginning with Tep<br>
Serial.print(dat);// output and display value of dat<br>
Serial.println("C");// display “C” characters<br>
delay(500);// wait for 0.5 second<br>
}<br>
</code>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/Temperature sensor.mp4">
</video>
<h2><strong><u> Experiment:10</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>Infrared receiver x 1</li>
<li>220 ohm Resistor x 6</li>
<li>Infrared remote controller x 1</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
</ul>
<h3><stong>Code</stong></h3>
<code>
#include <IRremote.h><br>
int RECV_PIN = 11;<br>
int LED1 = 2;<br>
int LED2 = 3;<br>
int LED3 = 4;<br>
int LED4 = 5;<br>
int LED5 = 6;<br>
int LED6 = 7;<br>
long on1 = 0x00FF6897;<br>
long off1 = 0x00FF9867;<br>
long on2 = 0x00FFB04F;<br>
long off2 = 0x00FF30CF;<br>
long on3 = 0x00FF18E7;<br>
long off3 = 0x00FF7A85;<br>
long on4 = 0x00FF10EF;<br>
long off4 = 0x00FF38C7;<br>
long on5 = 0x00FF5AA5;<br>
long off5 = 0x00FF42BD;<br>
long on6 = 0x00FF4AB5;<br>
long off6 = 0x00FF52AD;<br>
IRrecv irrecv(RECV_PIN);<br>
decode_results results;<br>
// Dumps out the decode_results structure.<br>
// Call this after IRrecv::decode()<br>
// void * to work around compiler issue<br>
//void dump(void *v) {<br>
// decode_results *results = (decode_results *)v<br>
void dump(decode_results *results) {<br>
int count = results->rawlen;<br>
if (results->decode_type == UNKNOWN) <br>
{<br>
Serial.println("Could not decode message");<br>
} <br>
else <br>
{<br>
if (results->decode_type == NEC) <br>
{<br>
Serial.print("Decoded NEC: ");<br>
} <br>
else if (results->decode_type == SONY)<br>
{<br>
Serial.print("Decoded SONY: ");<br>
} <br>
else if (results->decode_type == RC5) <br>
{<br>
Serial.print("Decoded RC5: ");<br>
} <br>
else if (results->decode_type == RC6)<br>
{<br>
Serial.print("Decoded RC6: ");<br>
}<br>
Serial.print(results->value, HEX);<br>
Serial.print(" (");<br>
Serial.print(results->bits, DEC);<br>
Serial.println(" bits)");<br>
}<br>
Serial.print("Raw (");<br>
Serial.print(count, DEC);<br>
Serial.print("): ");<br>
for (int i = 0; i < count; i++)<br>
{<br>
if ((i % 2) >= 1) {<br>
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);<br>
} <br>
else <br>
{<br>
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);<br>
}<br>
Serial.print(" ");<br>
}<br>
Serial.println("");<br>
}<br>
void setup()<br>
{<br>
pinMode(RECV_PIN, INPUT);<br>
pinMode(LED1, OUTPUT);<br>
pinMode(LED2, OUTPUT);<br>
pinMode(LED3, OUTPUT);<br>
pinMode(LED4, OUTPUT);<br>
pinMode(LED5, OUTPUT);<br>
pinMode(LED6, OUTPUT); <br>
pinMode(13, OUTPUT);<br>
Serial.begin(9600);<br>
irrecv.enableIRIn(); // Start the receiver<br>
}<br>
int on =0;<br>
unsigned long last = millis();<br>
void loop() <br>
{<br>
if (irrecv.decode(&results))<br>
{<br>
// If it's been at least 1/4 second since the last<br>
// IR received, toggle the relay<br>
if (millis() - last > 250) <br>
{<br>
on = ! on;<br>
// digitalWrite(8, on ? HIGH : LOW);<br>
digitalWrite(13, on ? HIGH: LOW);<br>
dump(&results);<br>
}<br>
if (results.value == on1 )<br>
digitalWrite(LED1, HIGH);<br>
if (results.value == off1 )<br>
digitalWrite(LED1, LOW); <br>
if (results.value == on2 )<br>
digitalWrite(LED2, HIGH);<br>
if (results.value == off2 )<br>
digitalWrite(LED2, LOW); <br>
if (results.value == on3 )<br>
digitalWrite(LED3, HIGH);<br>
if (results.value == off3 )<br>
digitalWrite(LED3, LOW);<br>
if (results.value == on4 )<br>
digitalWrite(LED4, HIGH);<br>
if (results.value == off4 )<br>
digitalWrite(LED4, LOW); <br>
if (results.value == on5 )<br>
digitalWrite(LED5, HIGH);<br>
if (results.value == off5 )<br>
digitalWrite(LED5, LOW); <br>
if (results.value == on6 )<br>
digitalWrite(LED6, HIGH);<br>
if (results.value == off6 )<br>
digitalWrite(LED6, LOW); <br>
last = millis(); <br>
irrecv.resume(); // Receive the next value<br>
}<br>
}<br>
</code>
<h3><strong>Problems faced</strong></h3>
<p>I tried this experiment several times.But i failed to solve the problem.<br>My first issue was due to some spacing between the codes(stray/302/ willbe shown while compilation).<br>My second problem was due to the decodation of IR signal.But unfortunatily I cannot solve that problem.</p>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/">
</video>
<h2><strong><u> Experiment:11</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>10k potentiometer x 1</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
</ul>
<h3><stong>Code</stong></h3>
<code>
int potpin=0;// initialize analog pin 0<br>
int ledpin=13;// initialize digital pin 13<br>
int val=0;// define val, assign initial value 0<br>
void setup()<br>
{<br>
pinMode(ledpin,OUTPUT);// set digital pin as “output”<br>
Serial.begin(9600);// set baud rate at 9600<br>
}<br>
void loop()<br>
{<br>
digitalWrite(ledpin,HIGH);// turn on the LED on pin 13<br>
delay(50);// wait for 0.05 second<br>
digitalWrite(ledpin,LOW);// turn off the LED on pin 13<br>
delay(50);// wait for 0.05 second<br>
val=analogRead(potpin);// read the analog value of analog pin 0, and assign it to val <br>
Serial.println(val);// display val’s value<br>
}<br>
</code>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/">
</video>
<h2><strong><u> Experiment:12</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>1-digit LED segment display x 1</li>
<li>220 ohm resistor x 8</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
</ul>
<h3><stong></stong></h3>
<code>
</code>
<h3><strong>Problems faced</strong></h3>
<p>I didn't have the segmet display to do the experiment</p>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/">
</video>
<h2><strong><u> ASSIGNMENT 1:Automatic night lamp</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>LDR x 1</li>
<li>LED</li>
<li>220 ohm resistor X 3</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
</ul>
<h3><stong>Code</stong></h3>
<code>
const int ldr = 7;<br>
const int led = 13;<br>
const int led1 = 12;<br>
const int led2 = 11;<br>
void setup() {<br>
pinMode(ldr,INPUT);//define pin as input sensor<br>
pinMode(led,OUTPUT);//define pin as output sensor<br>
pinMode(led1,OUTPUT);<br>
pinMode(led2 ,OUTPUT);<br>
}<br>
void loop() {<br>
int y =digitalRead(ldr);//read the sensor<br>
if (y==1){<br>
digitalWrite(led,HIGH);//turn on led<br>
digitalWrite(led1,HIGH);<br>
digitalWrite(led2,HIGH);<br>
}else{digitalWrite(led,LOW);//turn off led<br>
digitalWrite(led1,LOW);<br>
digitalWrite(led2,LOW);<br>
}<br>
delay(500);<br>
}<br>
</code>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/Automatic led light.mp4">
</video>
<h2><strong><u> ASSIGNMENT 2:Digital dice using 6 LEDs and push button</u></strong></h2>
<h3><strong>Hardware needed</strong></h3>
<ul>
<li>Arduino uno board x 1</li>
<li>USB cable x 1</li>
<li>Push button x 1</li>
<li>LED x 6</li>
<li>220 ohm resistor X 7</li>
<li>Breadboard x 1</li>
<li>Jumper wires</li>
</ul>
<h3><stong>Code</stong></h3>
<code>
#define DEBUG 0<br>
// 6 consecutive digital pins for the LEDs<br>
int first = 2;<br>
int second = 3;<br>
int third = 4;<br>
int fourth = 5;<br>
int fifth = 6;<br>
int sixth = 7;<br>
// pin for the button switch<br>
int button = 12;<br>
// value to check state of button switch<br>
int pressed = 0;<br>
void setup() {<br>
// set all LED pins to OUTPUT<br>
for (int i=first; i<=sixth; i++) {<br>
pinMode(i, OUTPUT);<br>
}<br>
// set buttin pin to INPUT<br>
pinMode(button, INPUT);<br>
// initialize random seed by noise from analog pin 0 (should be unconnected)<br>
randomSeed(analogRead(0));<br>
// if we're debugging, connect to serial <br>
#ifdef DEBUG<br>
Serial.begin(9600);<br>
#endif<br>
}<br>
void buildUpTension() {<br>
// light LEDs from left to right and back to build up tension<br>
// while waiting for the dice to be thrown<br>
// left to right<br>
for (int i=first; i<=sixth; i++) {<br>
if (i!=first) {<br>
digitalWrite(i-1, LOW);<br>
}<br>
digitalWrite(i, HIGH);<br>
delay(100);<br>
}<br>
// right to left<br>
for (int i=sixth; i>=first; i--) {<br>
if (i!=sixth) {<br>
digitalWrite(i+1, LOW);<br>
}<br>
digitalWrite(i, HIGH);<br>
delay(100);<br>
}<br>
}<br>
void showNumber(int number) {<br>
digitalWrite(first, HIGH);<br>
if (number >= 2) {<br>
digitalWrite(second, HIGH);<br>
}<br>
if (number >= 3) {<br>
digitalWrite(third, HIGH); <br>
}<br>
if (number >= 4) {<br>
digitalWrite(fourth, HIGH); <br>
}<br>
if (number >= 5) {<br>
digitalWrite(fifth, HIGH);<br>
}<br>
if (number == 6) {<br>
digitalWrite(sixth, HIGH);<br>
}<br>
}<br>
int throwDice() {<br>
// get a random number in the range [1,6]<br>
int randNumber = random(1,7);<br>
#ifdef DEBUG<br>
Serial.println(randNumber);<br>
#endif<br>
return randNumber;<br>
}<br>
void setAllLEDs(int value) {<br>
for (int i=first; i<=sixth; i++) {<br>
digitalWrite(i, value);<br>
}<br>
}<br>
void loop() {<br>
// if button is pressed - throw the dice<br>
pressed = digitalRead(button);<br>
if (pressed == HIGH) {<br>
// remove previous number<br>
setAllLEDs(LOW);<br>
buildUpTension();<br>
int thrownNumber = throwDice();<br>
showNumber(thrownNumber);<br>
} <br>
}<br>
</code>
<h3><strong>Video</strong></h3>
<video width="500px" height="300px" controls loop>
<source src="iot_images_and_videos/Dice led.mp4">
</video>
</div>
</body>
</html>