100% found this document useful (1 vote)
26 views

ArduinoBlocks en

Uploaded by

esgam312
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
26 views

ArduinoBlocks en

Uploaded by

esgam312
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

‭Built-in LED‬

‭ rduino‬‭incorporates‬‭a‬‭led‬‭on‬‭the‬‭board‬‭connected‬‭to‬‭pin‬‭13‬‭through‬‭a‬‭resistor.‬‭Thus‬‭we‬
A
‭can‬ ‭make‬ ‭a‬‭first‬‭test‬‭of‬‭the‬‭operation‬‭of‬‭the‬‭board‬‭without‬‭having‬‭to‬‭connect‬‭any‬‭other‬
‭component to the Arduino board.‬
‭Built-in‬‭LED equivalent circuit:‬

‭ ractice 1: Built-in LED blink‬


P
‭Pin 13 will work as an output. The program makes the built-in LED,‬
‭so that it remains ON for a time and another time OFF. Delay time‬
‭will determine the blink rate, you can try different values ​to see the difference in‬
‭blink speed. This process is repeated infinitely within the main "loop".‬
‭ ractice 2: LED block‬
P
‭The “Led” block of the actuators works exactly the same as the “Write Digital” block.‬
‭We can use it in the same way.‬

‭ he‬‭following‬‭program‬‭make‬‭the‬‭led‬‭connected‬‭to‬‭pin‬‭13‬‭blink‬‭using‬‭a‬‭variable‬‭to‬‭set‬‭the‬
T
‭delay time and using the “Led” block.‬

‭LED sequence‬
‭ e‬‭will‬‭connect‬‭5‬‭leds‬‭to‬‭the‬‭Arduino‬‭board‬‭on‬‭pins‬‭2,‬‭3,‬‭4,‬‭5,‬‭6‬‭by‬‭connecting‬‭a‬‭220‬‭Ω‬
W
‭resistor‬ ‭before‬ ‭the‬ ‭led‬‭anode‬‭(long‬‭pin)‬‭and‬‭all‬‭the‬‭cathodes‬‭of‬‭the‬‭leds‬‭(short‬‭pin)‬‭will‬
‭be joined directly to GND.‬
‭ ractice 3: odd and even‬
P
‭Switch on even leds and then odd leds after a while and start over again.‬

‭ ractice 4: move a light‬


P
‭Switch‬‭on‬‭a‬‭led‬‭consecutively‬‭one‬‭after‬‭the‬‭other‬‭from‬‭left‬‭to‬‭right‬‭(only‬‭one‬‭led‬‭on‬‭at‬‭a‬
‭time). When the last one is reached, the sequence begins again.‬
‭ ractice 5: all on one by one and all off one by one‬
P
‭Switch‬ ‭on‬ ‭the‬ ‭leds‬ ‭consecutively‬ ‭one‬ ‭after‬ ‭the‬ ‭other‬ ‭from‬‭left‬‭to‬‭right‬‭until‬‭they‬‭are‬‭all‬
‭on.‬‭Then‬‭they‬‭go‬‭off‬‭consecutively‬‭in‬‭the‬‭reverse‬‭order‬‭that‬‭they‬‭were‬‭switched‬‭on‬‭until‬
‭they are all off and start over.‬

‭ ractice 6:‬‭A single led lights from side to side‬


P
‭A single led lights from side to side.‬
‭ ractice 7:‬‭from the outside to the inside‬
P
‭Make‬ ‭a‬ ‭sequence‬ ‭of‬ ‭leds‬ ‭so‬ ‭that‬ ‭the‬ ‭leds‬ ‭light‬ ‭up‬ ‭from‬ ‭the‬ ‭outside‬ ‭to‬ ‭the‬ ‭inside‬ ‭and‬
‭then vice versa. The speed can be adjusted by changing the value of a variable.‬

‭ ractice 8:‬‭functions‬
P
‭Functions‬ ‭allow‬ ‭us‬ ‭to‬ ‭group‬ ‭blocks‬ ‭under‬ ‭a‬ ‭single‬‭name‬‭and‬‭to‬‭be‬‭able‬‭to‬‭execute‬‭all‬
‭the blocks simply by adding the block to call the function.‬
‭Definition of a function:‬ ‭Function calling:‬

‭ reate‬ ‭a‬ ‭function‬ ‭“all‬ ‭off”‬ ‭to‬ ‭start‬ ‭switching‬ ‭off‬ ‭all‬ ‭the‬ ‭leds,‬ ‭another‬ ‭function‬ ‭for‬
C
‭“sequence‬ ‭1”,‬ ‭another‬ ‭for‬ ‭“sequence‬ ‭2”‬ ‭and‬ ‭one‬ ‭for‬ ‭“sequence‬ ‭3”.‬ ‭In‬ ‭the‬ ‭main‬ ‭loop‬
‭execute‬ ‭3‬ ‭times‬ ‭the‬ ‭sequence‬ ‭1,‬ ‭4‬ ‭times‬ ‭sequence‬ ‭2‬ ‭and‬ ‭5‬ ‭times‬ ‭sequence‬ ‭3‬
‭continuously.‬
‭PWM outputs‬
‭ ulse‬ ‭width‬ ‭modulation‬ ‭(also‬ ‭known‬ ‭as‬ ‭PWM)‬ ‭of‬ ‭a‬ ‭signal‬ ‭or‬ ‭power‬ ‭source‬ ‭is‬ ‭a‬
P
‭technique‬‭in‬‭which‬‭the‬‭duty‬‭cycle‬‭of‬‭a‬‭periodic‬‭(cyclic)‬‭signal‬‭is‬‭modified,‬‭to‬‭control‬‭the‬
‭amount‬ ‭of‬ ‭energy‬ ‭sent‬ ‭to‬ ‭a‬ ‭load.‬ ‭With‬ ‭this‬ ‭technique‬ ‭we‬ ‭can‬ ‭control‬ ‭the‬ ‭intensity‬ ‭of‬
‭LEDs, speed of motors, etc.‬
‭This‬ ‭is‬ ‭the‬ ‭way‬ ‭Arduino‬ ‭generates‬ ‭a‬ ‭pseudo-analog‬ ‭signal‬ ‭on‬ ‭its‬ ‭outputs‬ ‭from‬ ‭digital‬
‭pulses to vary the energy that it sends through the relevant pin.‬

‭Charts of PWM from 0% to 100% of intensity‬ ‭Pins that allow PWM operation are marked with the symbol ~‬

‭Connect a LED to pin 3 as follows:‬

‭The values ​that we can write to the pin using PWM are from 0 to 255 (from 0 to 100%):‬
‭ ractice 9:‬‭Switching on a led in several steps of‬‭intensity‬
P
‭Switching on a led in several steps of intensity.‬
‭Calculate the table with the values ​to write to the PWM output pin‬
‭ ractice 10:‬‭Switching on and off a Led slowly‬
P
‭Switching‬‭on‬‭and‬‭off‬‭a‬‭Led‬‭slowly:‬‭The‬‭values‬‭​from‬‭0‬‭to‬‭255‬‭will‬‭be‬‭written‬‭on‬‭pin‬‭3‬‭so‬
‭that‬ ‭the‬‭LED‬‭illuminates‬‭slowly.‬‭When‬‭reaching‬‭100%‬‭(255)‬‭the‬‭process‬‭will‬‭be‬‭carried‬
‭out in reverse until reaching 0.‬
‭Modify the delay value to speed up or slow down the process.‬

‭ ractice 11: Random intensity‬


P
‭Make a program that changes the intensity of the led randomly every second.‬
‭ ractice 12: Contrary leds‬
P
‭Make‬ ‭a‬ ‭program‬ ‭with‬ ‭two‬ ‭leds‬ ‭connected‬ ‭to‬ ‭PWM‬ ‭pins,‬ ‭when‬ ‭the‬ ‭intensity‬ ‭of‬ ‭one‬
‭increases the other decreases. Leds connected to pins 3 and 5.‬
‭ ractice 13: light increases and decreases progressively‬
P
‭Connect 3 leds to pins 9,10 and 11.‬
‭Carry‬ ‭out‬ ‭a‬ ‭sequence‬ ‭where‬ ‭intensity‬ ‭of‬ ‭the‬ ‭LEDs‬ ‭increases‬ ‭and‬ ‭then‬ ‭decreases‬
‭progressively.‬
‭RGB LEDs‬
‭ ‬ ‭RGB‬ ‭LED‬ ‭is‬ ‭actually‬ ‭the‬ ‭union‬ ‭of‬ ‭three‬ ‭LEDs‬ ‭of‬ ‭the‬ ‭basic‬ ‭colors,‬ ‭in‬ ‭a‬ ‭common‬
A
‭encapsulation, sharing the cathode (-) or the anode (+).‬

‭Example of connection of a common cathode RGB LED to pins 9~, 10~ and 11~:‬

‭ e can control the RGB led in several different ways from ArduinoBlocks:‬
W
‭-Digital outputs (ON/OFF):‬

‭-Analogue outputs (0…255):‬

‭-RGB Led block (actuators):‬

‭ ractice 14: on/off control of RGB Led‬


P
‭With‬‭the‬‭use‬‭of‬‭blocks‬‭to‬‭control‬‭digital‬‭outputs‬‭(ON/OFF)‬‭we‬‭will‬‭show‬‭the‬‭color‬‭green,‬
‭red,‬ ‭blue,‬ ‭yellow‬ ‭(R+G),‬ ‭white‬ ‭(R+G+B)‬ ‭and‬ ‭black‬ ‭(all‬ ‭off)‬ ‭for‬ ‭1‬ ‭second‬ ‭each‬ ‭color.‬
‭(RGB LEDs of common cathode).‬
‭ ractice 15: PWM control of RGB Led‬
P
‭We‬ ‭will‬ ‭progressively‬ ‭increase‬ ‭the‬ ‭intensity‬ ‭of‬ ‭Red,‬ ‭then‬ ‭Green‬ ‭and‬ ‭finally‬ ‭Blue‬
‭(Common cathode RGB LED)‬

‭ ractice 16:‬‭RGB Led block‬‭control‬


P
‭Sequential change of colours.‬
‭ ractice 17:‬‭Random colour‬
P
‭Random colour change every 2 seconds.‬

‭ ractice 18:‬‭Random colour with smooth transition‬


P
‭Generates‬‭random‬‭RGB‬‭colours‬‭and‬‭smoothly‬‭transitions‬‭from‬‭the‬‭current‬‭colour‬‭to‬‭the‬
‭next.‬
‭Digital inputs‬
‭ rduino‬ ‭incorporates‬ ‭multiple‬ ‭pins‬ ‭that‬ ‭can‬‭function‬‭as‬‭input‬‭or‬‭output.‬‭Let's‬‭try‬‭to‬‭use‬
A
‭them as input to read data from external sensors.‬
‭The‬‭digital‬‭inputs‬‭allow‬‭reading‬‭an‬‭ON‬‭/‬‭OFF‬‭value‬‭depending‬‭on‬‭the‬‭voltage‬‭applied‬‭to‬
‭the relevant pin.‬
‭If a voltage less than 2v is applied, a LOW value will be read (a logical "0")‬
‭If a value greater than 3v is applied, a HIGH value will be read (a logical "1")‬
‭The diagram to connect a push-button/switch to an Arduino digital input is:‬
I‭n‬ ‭most‬ ‭cases‬ ‭we‬ ‭can‬ ‭use‬ ‭a‬ ‭push-button‬ ‭module‬ ‭that‬ ‭incorporates‬ ‭the‬ ‭resistor‬ ‭and‬
‭simplifies the connections:‬

‭ ome‬ ‭of‬ ‭these‬ ‭modules‬ ‭are‬ ‭connected‬ ‭in‬‭an‬‭inverted‬‭way‬‭to‬‭the‬‭previous‬‭scheme,‬‭so‬


S
‭that‬‭the‬‭input‬‭will‬‭be‬‭active‬‭(HIGH/ON)‬‭at‬‭rest‬‭and‬‭will‬‭be‬‭deactivated‬‭(LOW/OFF)‬‭when‬
‭pressed.‬
‭The blocks used to read the value of a digital input or a button are:‬

‭ ush button or sensor with HIGH/ON output‬


P ‭ ush button or sensor with LOW/OFF output‬
P
‭when pressed or active‬ ‭when pressed or active‬
‭ ractice 19: LED on by pressing button‬
P
‭We will turn on a led while the button is pressed, otherwise the led will remain off.‬

‭ ractice 20: switch LED by pressing button‬


P
‭Turn a led on and off with a single button.‬

‭ hat is the "repeat while..." block for?‬


W
‭What happens if we remove it?‬
‭ ractice 21:‬‭Two-button intensity control‬
P
‭We‬‭will‬‭connect‬‭two‬‭buttons‬‭and‬‭a‬‭led.‬‭One‬‭button‬‭will‬‭increase‬‭the‬‭intensity‬‭of‬‭the‬‭led‬
‭and another will decrease it.‬

‭ ractice 22:‬‭led control with a clap‬


P
‭We‬ ‭will‬ ‭use‬ ‭a‬ ‭sound‬ ‭sensor‬ ‭with‬ ‭digital‬ ‭output‬ ‭(0/OFF‬ ‭without‬ ‭sound‬ ‭and‬‭1/ON‬‭when‬
‭sound is detected).‬
‭The program will turn on the led for 5s when a loud sound is detected.‬
‭Check the sensor pins. You must connect the digital output D0 of the sensor to pin 8.‬
‭ ractice 23:‬‭PIR motion detector‬
P
‭The‬‭PIR‬‭(Passive‬‭Infrared)‬‭motion‬‭sensor‬‭reacts‬‭only‬‭to‬‭certain‬‭energy‬‭sources‬‭such‬‭as‬
‭human‬‭or‬‭animal‬‭body‬‭heat.‬‭They‬‭receive‬‭the‬‭variation‬‭of‬‭the‬‭infrared‬‭radiation‬‭from‬‭the‬
‭environment‬ ‭it‬ ‭covers.‬ ‭It‬ ‭is‬ ‭called‬ ‭passive‬ ‭because‬ ‭it‬ ‭does‬ ‭not‬ ‭emit‬ ‭radiation,‬ ‭but‬
‭receives‬ ‭them.‬ ‭These‬ ‭capture‬ ‭the‬ ‭presence‬ ‭by‬ ‭detecting‬ ‭the‬ ‭difference‬ ‭between‬ ‭the‬
‭heat emitted by the human body and the space around it.‬
‭ reate‬ ‭a‬ ‭program‬ ‭that‬ ‭turns‬ ‭on‬ ‭a‬ ‭led‬ ‭connected‬ ‭to‬ ‭pin‬ ‭3‬ ‭for‬ ‭5s‬ ‭when‬ ‭it‬ ‭detects‬
C
‭movement.‬
‭We will connect the PIR motion sensor to pin 7.‬
‭Serial communication‬
‭ rduino‬ ‭incorporates‬ ‭a‬ ‭serial‬ ‭connection‬ ‭that‬ ‭allows‬ ‭connection‬ ‭with‬ ‭the‬ ‭PC‬ ‭(or‬ ‭with‬
A
‭many other devices).‬
‭This‬ ‭is‬ ‭the‬ ‭same‬ ‭connection‬ ‭used‬ ‭to‬ ‭upload‬ ‭the‬ ‭program‬ ‭to‬ ‭the‬ ‭Arduino.‬ ‭Using‬ ‭this‬
‭connection we can send information from Arduino to the PC and vice versa.‬

‭ o‬‭display‬‭the‬‭information‬‭received‬‭on‬‭the‬‭PC‬‭and‬‭be‬‭able‬‭to‬‭send‬‭data‬‭to‬‭the‬‭Arduino‬
T
‭the easiest is to use a serial terminal or serial console.‬
‭ erial‬‭console‬‭allows‬‭data‬‭to‬‭be‬‭sent‬‭from‬‭the‬‭PC‬‭to‬‭the‬‭Arduino‬‭board.‬‭And‬‭vice‬‭versa,‬
S
‭it allows to receive and visualise the data received from the Arduino board.‬

‭ ractice 24:‬‭Sending messages from Arduino‬


P
‭The‬ ‭program‬ ‭will‬ ‭send‬ ‭text‬ ‭messages‬ ‭from‬ ‭Arduino,‬ ‭to‬ ‭display‬‭the‬‭data‬‭received‬‭from‬
‭the serial connection we will use the console that ArduinoBlocks incorporates.‬

‭ ractice 25:‬‭Display the value of a variable‬


P
‭We‬ ‭are‬ ‭going‬ ‭to‬ ‭see‬ ‭how‬ ‭to‬ ‭send‬ ‭the‬ ‭value‬ ‭of‬ ‭a‬ ‭variable.‬ ‭In‬ ‭this‬ ‭case,‬ ‭the‬ ‭variable‬
‭increases and its value is shown in the serial console.‬
‭ ractice 26: Switch on a LED from the PC‬
P
‭Upon‬ ‭receiving‬ ‭the‬ ‭value‬ ‭1‬ ‭from‬ ‭the‬ ‭console‬ ‭we‬ ‭will‬ ‭turn‬ ‭off‬ ‭the‬ ‭led,‬ ‭upon‬ ‭receiving‬
‭value 2 we will turn it on.‬

‭ ractice 27:‬‭LED intensity regulation from PC‬


P
‭Connect‬ ‭a‬ ‭led‬ ‭to‬ ‭pin‬ ‭3.‬ ‭Receive‬ ‭a‬ ‭number‬ ‭from‬ ‭the‬ ‭computer‬ ‭through‬ ‭the‬ ‭serial‬ ‭port.‬
‭The‬ ‭number‬ ‭received‬ ‭must‬ ‭be‬ ‭between‬ ‭0‬ ‭and‬ ‭255‬ ‭and‬ ‭will‬ ‭be‬ ‭written‬ ‭to‬ ‭the‬ ‭analog‬
‭output (PWM) pin 3.‬
‭ ractice 28: Guess the number‬
P
‭We‬ ‭will‬‭play‬‭a‬‭game‬‭where‬‭the‬‭Arduino‬‭board‬‭will‬‭"think"‬‭a‬‭random‬‭number‬‭between‬‭1‬
‭and 100.‬
‭From‬ ‭the‬‭console‬‭we‬‭will‬‭say‬‭numbers‬‭and‬‭it‬‭will‬‭tell‬‭us‬‭if‬‭the‬‭secret‬‭number‬‭is‬‭greater‬
‭or less until it is guessed and shows us the total number of guesses we've used.‬

‭Analog inputs‬
‭ rduino‬ ‭incorporates‬ ‭6‬ ‭pins‬ ‭that‬ ‭can‬ ‭function‬ ‭as‬ ‭analog‬ ‭inputs.‬ ‭Let's‬ ‭try‬ ‭how‬ ‭we‬ ‭can‬
A
‭read data from external sensors through them.‬
‭The‬ ‭analog‬ ‭inputs‬ ‭allow‬ ‭you‬ ‭to‬ ‭read‬ ‭the‬ ‭voltage‬ ‭that‬ ‭is‬ ‭applied‬ ‭to‬ ‭it‬‭as‬‭an‬‭input.‬‭That‬
‭voltage‬ ‭may‬ ‭vary‬‭between‬‭0‬‭and‬‭5v.‬‭The‬‭voltage‬‭value‬‭read‬‭is‬‭converted‬‭to‬‭a‬‭numeric‬
‭value between 0 and 1023.‬

‭Blocks to read an analog input:‬

‭The reading blocks of an analog input will return a value between 0...1023.‬
‭Input voltage‬ ‭Read value‬

‭0 V‬ ‭0‬

‭2.5 V‬ ‭512‬

‭5 V‬ ‭1023‬
‭ nother‬ ‭interesting‬ ‭block‬ ‭is‬‭“map”,‬‭which‬‭allows‬‭changing‬‭the‬‭range‬‭of‬‭the‬‭value‬‭read.‬
A
‭For‬‭example,‬‭if‬‭I‬‭want‬‭to‬‭change‬‭the‬‭range‬‭read‬‭from‬‭0...1023‬‭to‬‭0..100‬‭I‬‭can‬‭"map"‬‭it‬‭as‬
‭follows:‬

‭ ractice 29: Read the position of a potentiometer‬


P
‭We‬‭will‬‭read‬‭the‬‭value‬‭of‬‭the‬‭analog‬‭input‬‭where‬‭the‬‭potentiometer‬‭is‬‭connected‬‭and‬‭we‬
‭will send it to the serial console to be able to visualize it on the PC.‬
‭ ractice 30:‬‭Regulate the intensity of led with‬‭a‬‭potentiometer‬
P
‭We‬ ‭will‬ ‭read‬ ‭the‬‭value‬‭of‬‭a‬‭potentiometer‬‭(0...1023)‬‭and‬‭map‬‭it‬‭to‬‭a‬‭proportional‬‭value‬
‭between 0 and 255 to regulate a led connected to pin 3 as a PWM output.‬
‭ ractice 31:‬‭Measure the ambient light‬
P
‭We‬‭will‬‭connect‬‭an‬‭LDR‬‭resistor‬‭to‬‭the‬‭analog‬‭input‬‭A0,‬‭through‬‭which‬‭we‬‭will‬‭measure‬
‭the level of ambient light detected.‬
‭We‬‭will‬‭send‬‭the‬‭value‬‭read‬‭through‬‭the‬‭serial‬‭connection‬‭to‬‭view‬‭it‬‭on‬‭the‬‭serial‬‭console‬
‭every 2s.‬

‭ ractice 32: Joystick‬


P
‭The‬‭“joystick”‬‭type‬‭modules‬‭for‬‭Arduino‬‭are‬‭made‬‭up‬‭of‬‭two‬‭potentiometers,‬‭one‬‭for‬‭the‬
‭movement‬‭of‬‭the‬‭X‬‭axis‬‭and‬‭another‬‭for‬‭the‬‭movement‬‭of‬‭the‬‭Y‬‭axis.‬‭Also‬‭in‬‭the‬‭same‬
‭module they usually incorporate a button.‬
‭GND / -‬ ‭GND = 0V‬

‭VCC / 5V / +‬ ‭VCC = 5V‬

‭Vrx / X‬ ‭X axis potentiometer (to analog pin)‬

‭Vry / Y‬ ‭Y axis potentiometer (to analog pin)‬

‭SW‬ ‭Button (to digital pin)‬


‭ ractice 33: Control of two leds with joystick‬
P
‭Connect‬‭a‬‭joystick‬‭(X‬‭=>‬‭A0‬‭/‬‭Y‬‭=>‬‭A1)‬‭and‬‭two‬‭leds‬‭to‬‭pins‬‭6‬‭and‬‭7‬‭respectively.‬‭A‬‭led‬
‭will‬‭vary‬‭its‬‭intensity‬‭with‬‭the‬‭X‬‭axis‬‭and‬‭another‬‭with‬‭the‬‭Y‬‭axis.‬‭The‬‭two‬‭leds‬‭must‬‭be‬‭lit‬
‭at about half intensity when the joystick is at rest..‬

‭Relay‬
‭ ‬ ‭relay‬ ‭is‬ ‭an‬ ‭electromagnetic‬ ‭device.‬ ‭It‬ ‭works‬ ‭like‬ ‭a‬ ‭switch‬ ‭controlled‬ ‭by‬ ‭an‬ ‭electric‬
A
‭circuit in which, by means of a coil and an electromagnet, a set of one or more‬
‭contacts can open or close other independent circuit.‬
‭ he‬ ‭connection‬ ‭of‬ ‭the‬ ‭relay‬ ‭will‬ ‭be‬ ‭made‬ ‭through‬ ‭a‬ ‭digital‬‭output,‬‭since‬‭we‬‭only‬‭have‬
T
‭two states ON/OFF (relay active or not).‬
‭The‬ ‭most‬ ‭common‬ ‭is‬ ‭to‬ ‭connect‬ ‭a‬ ‭relay‬ ‭module‬ ‭that‬‭simplifies‬‭the‬‭connection‬‭since‬‭it‬
‭already‬‭has‬‭all‬‭the‬‭elements‬‭necessary‬‭for‬‭direct‬‭connection‬‭of‬‭the‬‭relay‬‭to‬‭Arduino.‬‭We‬
‭only‬ ‭have‬ ‭to‬ ‭connect‬ ‭5V‬ ‭(VCC),‬ ‭GND‬ ‭and‬ ‭the‬ ‭signal‬‭relay‬‭activation‬‭input‬‭that‬‭will‬‭be‬
‭connected to the corresponding Arduino pin.‬
‭If‬‭we‬‭use‬‭an‬‭ordinary‬‭relay,‬‭connect‬‭one‬‭of‬‭the‬‭pins‬‭of‬‭the‬‭coil‬‭to‬‭GND‬‭and‬‭the‬‭other‬‭pin‬
‭of the coil to the corresponding Arduino pin to control the relay.‬
‭To‬‭activate‬‭the‬‭relay‬‭in‬‭the‬‭Arduino‬‭program‬‭we‬‭will‬‭simply‬‭use‬‭the‬‭instruction‬‭to‬‭activate‬
‭the pin digitally connected to the relay module (ON/OFF)‬
‭In‬‭the‬‭output‬‭section‬‭we‬‭have‬‭a‬‭relay‬‭module‬‭that‬‭internally‬‭performs‬‭the‬‭same‬‭function‬
‭as the “write digital” instruction,‬
‭These two instructions perform the same function: Activate the output of pin 2.‬
‭ ractice 34: intermittent relay‬
P
‭Carry‬ ‭out‬ ‭an‬ ‭assembly‬ ‭with‬ ‭the‬ ‭relay‬ ‭module‬ ‭connected‬ ‭to‬ ‭pin‬ ‭8,‬ ‭we‬ ‭will‬ ‭carry‬ ‭out‬ ‭a‬
‭program that activates and deactivates the relay in periods of a 1s.‬

‭ ractice 35: Control of relay from PC‬


P
‭We will turn on/off the relay connected to pin 8 through the serial port console.‬
‭1 = turn on / 2 = turn off / 3 = blink‬

You might also like