Page 123 - KEC Khaitan C8.2 Flipbook
P. 123

pinMode(BLUE, OUTPUT);

                 }



                 void loop() {

                   if (BTSerial.available()) {

                     char command = BTSerial.read();
                     Serial.println(command);




                     if (command == ‘R’) { digitalWrite(RED, HIGH); }
                     if (command == ‘G’) { digitalWrite(GREEN, HIGH); }

                     if (command == ‘B’) { digitalWrite(BLUE, HIGH); }

                     if (command == ‘O’) {
                       digitalWrite(RED, LOW);

                       digitalWrite(GREEN, LOW);

                       digitalWrite(BLUE, LOW);

                     }
                   }

                 }



                 Now your Arduino can listen to commands from a phone and change what it does on the fly—an
                 essential first step into the world of IoT. By exploring Bluetooth, you’ve seen how short-range
                 wireless communication can add convenience and flexibility to your projects.

                 You’ve now made your first wireless and IoT-inspired project. Next, we’ll take it up a gear and
                 move from stationary builds to moving robots—using Bluetooth again, but this time to drive a
                 motorized car. By combining motor drivers, DC motors, and Bluetooth control, you’ll soon have
                 a simple robot that obeys your smartphone commands, cruising around your room like a true
                 mini-vehicle!


                   Remember: A connected device is a powerful device. By giving your Arduino the ability to

                   receive commands from your phone or share data online, you transform it from a standalone
                   gadget into part of a global network of interactive, automated technology.












                                                                                                 Hands-On Project  121
   118   119   120   121   122   123   124   125   126   127   128