In this lesson, we will show how to use a Button Switch module to turn on/off an LED through Arduino Graphic programming technology.
Both LED and Switch module will be connected to OSOYOO Magic I/O shield. Here, “I/O” refers to the INPUT and OUTPUT. OSOYOO Magic I/O Shield is an extension board which can help use to easily connect sensors, actuators and Robot car control ports to Arduino I/O pins.
We will plug LED module into D8 port of the shield and plug Switch module to D2 port on the shield. We will tell Arduino D8 will be an OUTPUT port which will send out signal to control LED. D2 is an INPUT port which gets input signal from Switch button.
Firstly, please plug Osoyoo Magic I/O shield into UNO board as following:
Then connect the LED and Button module to the ports of the Magic I/O shield with four 3-pin PNP cables as below:
Note:
Step 1) If you haven’t install mBlock software in your PC, please read Lesson 1, download and install the software.
Step 2) Run the mBlock PC software by double click the lovely Panda icon. Drag and Drop osoyoo_uno_mext file(downloaded in Step 1) to mBlock software as following:
Now you will see a new device firmware in mBlock, see following picture:
Now mBlock software and OSOYOO_UNO device firmware have been successfully installed in our PC!
Step 2: Click Events, add when Arduino Uno starts up block to the top:
Step 3: Click Control , drag if else block to forever loop,
Step 4: Click Sensor, Add Button Pressed blocks to if condition area, change Pin number to 2:
Step 5: Click Light, Then add 2 pcs LED pin blocks to if and else area, then change pin number to 8 and change else area LED pin 8 to LOW:
Now all the programming blocks have been completed! From above picture, the logic is pretty straightforward:
1)you need click the Connect button in the bottom of the mBlock software, you will see a USB window pop up,
2) select Show all connectable device check box , then a device drop-down menu will show up,
3) select your Arduino port from device drop-down menu
4) click Connect button to connect your PC to Arduino
5)After you PC is connected to Arduino UNO board, please click Upload button in the bottom of your software, then the code will be uploaded to Arduino UNO board:
When you press the button in D2 , the LED in D8 will turn on, when you release the button, the LED will turn off.
DownLoad Url osoyoo.com