Grade 11 week3 lesson 1.pdf

Full Transcript

Grade 11 Computing Creative Design and Innovation Objectives By the end of the session students will be able to, differentiate between digital and analogue signals. Read and generate analogue signals with a microcontroller-based board. Analogue signals Analogue signals vs...

Grade 11 Computing Creative Design and Innovation Objectives By the end of the session students will be able to, differentiate between digital and analogue signals. Read and generate analogue signals with a microcontroller-based board. Analogue signals Analogue signals vs digital signals Analogue and digital signals are the two types of signals carrying information. Analogue signals vs digital signals Search what are the differences between Analogue signals and digital signals Analogue signals vs digital signals Analogue signals Digital signals continuous signals with electrical signals that an infinite number of represent information in possibilities the pattern of bits (0s and 1s) Analogue signals vs digital signals Analogue signals Digital signals represented by sine represented by square waves waves Analogue signals vs digital signals Analogue signals Digital signals use a continuous range use discrete data to of values to represent represent information information Analogue signals vs digital signals Analogue signals Digital signals suitable for audio and suitable for computing video transmission and digital electronics Analogue signals vs digital signals Analogue signals Examples – human voice, natural sound, FM radio signals and analogue electronic devices (temperature sensors, photocells, light sensor) Analogue signals vs digital signals Digital signals Examples – computer, optical drives (CDs and DVDs) and other electronic devices (Pushbutton, LED) Reminder Arduino can use digital signals as input or output. For Arduino to read an analogue signal, it must digitalize it Reminder Digitalizing a signal means representing its values by finite numbers instead of infinite ones. Analogue output Arduino generates analogue signals by using the pulse width modulation (PWM) technique. Analogue output PWM allows you to generate analogue signals using digital pulses. The width of the pulse is defined by its ‘on’ time (when the signal has a high value). Analogue output By changing the width of the pulses, we change the on-off time of the signal. If these changes happen fast enough, it will seem as if we have an analogue signal. Analogue output To change the width of the pulse, we change the duty cycle of the signal. Which depends on two values, the signal’s time period (T) and its ‘on-time’ Analogue output The time period (T) represents the time needed for one cycle of a signal to be completed. This is the on and off time combined. Analogue output The frequency (f) is the number of complete cycles per second. This is measured in the units of hertz (Hz). Analogue output Frequency is the inverse of the time period of the signal. f=1/T Analogue output The ratio between the ‘on time’ divided by the ‘time period’ is called the duty cycle (D) of the signal Analogue output The duty cycle of a signal has a value between 0% and 100% of the time period. Analogue output The square wave can simulate voltages between full-on (5V) and full-off (0V). It does this by changing the duty cycle. Analogue output Arduino scales the duty cycle in the range of 0 to 255, as follows: 255 is 100% of the duty cycle (100% of 255 is 255) 0 is 0% of the duty cycle value Analogue output To generate a PWM signal using Arduino, you need to use the following function: analogWrite(pin#,Value); analogWrite(pin#,Value); pin#: is the number you Value: is where you want to generate the pwm specify the value of the at. This number must be PWM signal (0 – 255). one of the seven pins that have a ‘~’ sign on the Arduino board. analogWrite(pin#,Value); We know that 100% duty cycle corresponds to 255. Hence, to calculate the required value for your signal use the following formula: 𝑑𝑒𝑠𝑖𝑟𝑒𝑑 𝑑𝑢𝑡𝑦 𝑐𝑦𝑐𝑙𝑒 ∗ 255 PWM Value= 100 You can control the LED using both ‘digitalWrite’ and ‘analogWrite’ functions. Using the digital function, you can only specify if the LED turns on (1: high) or off (0: low). However, by using the analogue function with the PWM technique, you can specify the exact value for the LED’s brightness (25%, 45%, 80% brightness etc.) For example, if you wanted to set the LED to half of its maximum brightness, the duty cycle value should be on 50%. Using the above formula (PWM Value= (50 ×255)/100), the PWM value, in this case, should be 127.5 (round to 127). Therefore, to set the LED’s brightness to half, the line of code in Arduino is as follows: analogWrite(pin#,127); Analogue output – Practical work For this practical task, you will write a code to control the brightness of an LED directly from Arduino. You will do this by manipulating the voltage across it. Declare the Arduino pin numbers ,or any initialization void setup() { Declare each component as input or output } void loop() { The instuction } Code int LED=9; Declare the Arduino pin numbers. int Brightness=0; Initialize a variable to hold the value of the LED’s brightness value. Code void setup() { pinMode(LED, OUTPUT); } Initialize the LED pin to behave as an output. Code void loop() { analogWrite(LED, Brightness); Generate the PWM signal using the PWM value Code delay(1000); // Wait for 1000millisecond(s) Apply a delay to observe the brightness. Code Brightness=Brightness+102; } Increase the brightness value by 40%. Challenge Change the place of the LED to 13 change the circuit and the code Exit Card

Use Quizgecko on...
Browser
Browser