Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Become an IoT expert lecture 3

Become an IoT expert lecture 3

Become an IoT expert lecture 3

Google Slides: https://bit.ly/2M2ZxM7
YouTube Video : https://www.youtube.com/watch?v=pgpeRfoD_OE

Become an IoT expert lecture 2

Google Slides: https://bit.ly/3bpY1Oh
YouTube Video : https://www.youtube.com/watch?v=ToJ--InCLqw

Become an IoT expert lecture 1

Google Slides: https://bit.ly/2Y57UOo
YouTube Video : https://www.youtube.com/watch?v=e0xJIYHRAR4

Ahmed Sobhy

May 27, 2020
Tweet

More Decks by Ahmed Sobhy

Other Decks in Programming

Transcript

  1. Outline Sessions 1 hour • Introduction to Electricity • Introduction

    to Electronics • Introduction to MicroControllers • Introduction to Programming • Introduction to Embedded Systems • …….. Short Videos • Introduction to Electricity & Electronics ◦ AC & DC ◦ Semiconductors , Conductors & insulators ◦ Resistors Diodes ◦ Transistors • Introduction to Programming ◦ Variables & Operators ◦ Loops ◦ Arrays • …….
  2. No registration needed Qwiklabs Code: bit.ly/menadd-apr Feedback: bit.ly/menadd-feedback Weekly challenge:

    bit.ly/menadd-challenge MENA Digital Days - Together we learn! Join us YouTube.com/c/GDGMENA Website: bit.ly/menadd-website Each week Sunday-Thursday 7-11pm (Dubai Time) Content: 20+ LIVE workshops, Talks, & hackathons Speakers: Googlers, Experts & 200+ communities. Stay Home! Stay Safe! Keep learning!
  3. ✌ Help us improve this initiative 1. ATTENDANCE CERTIFICATE weekly

    after filling feedback bit.ly/menadd-feedback 2. JOIN MENA DIGITAL DAYS CHALLENGE … bit.ly/menadd-challenge (Code: bit.ly/menadd-may) All winners who solve 6 quests this week Wins SPECIAL GIFT BOX! All winners who solve 12 quests this week Wins Google Home Mini
  4. programming /ˈprəʊɡramɪŋ/ noun • Is the process of creating a

    set of instructions that tell a computer how to perform a task.
  5. • Ability to write output to the screen • Basic

    math capability • Storage of information as a variable • Organization of code into functions, methods, or modules • Invoke a function or method • Performance of boolean logic evaluations • Branch conditional statements (if / else) • Looping statements Basic constructs most programming languages should contain:
  6. Constant Pins, and variable declaration Constant pin (option) // setup

    initializes serial and the button pin Declare input and output port Void setup() //Use it to initialize variables, pin modes, start using libraries,etc. { pinMode(Pin No. OrName, Status) } void loop() { Program Instruction } Input or output
  7. pinMode() Description Configures the specified pin to behave either as

    an input or an output. Syntax pinMode(pin, mode) Parameters pin: the number of the pin whose mode you wish to set mode: INPUT, OUTPUT, or INPUT_PULLUP. digitalWrite() Description Write a HIGH or a LOW value to a digital pin. Syntax digitalWrite(pin, value) Parameters pin: the pin number value: HIGH or LOW
  8. digitalRead() Description Reads the value from a specified digital pin,

    either HIGH or LOW. Syntax digitalRead(pin) Parameters pin: the number of the digital pin you want to read (int) analogRead() Description Reads the value from a specified analog pin, int (0 to 1023). Syntax analogRead(pin) Parameters pin: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega)
  9. delay() Description Pauses the program for the amount of time

    (in milliseconds) specified as parameter. (There are 1000 milliseconds in a second.) Syntax delay(ms) Parameters ms: the number of milliseconds to pause (unsigned long) analogWrite() Description Write a duty cycle value: between 0 (always off) and 255 (always on). Hint: You do not need to call pinMode() to set the pin as an output before calling analogWrite(). Syntax analogWrite(pin, value) Parameters pin: the pin to write to. value: the duty cycle: between 0 (always off) and 255 (always on).
  10. // set pin numbers const int ledPin = 4; //

    the number of the LED pin void setup() { // initialize the LED pin as an output pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, HIGH); // turn LED on delay(1000); // Wait 1 sec digitalWrite(ledPin, LOW); // turn LED off delay(1000); // Wait 1 sec }
  11. // set pin numbers const int buttonPin = 4; //

    the number of the pushbutton pin const int ledPin = 5; // the number of the LED pin // variable for storing the pushbutton status int buttonState = 0; void setup() { // initialize the pushbutton pin as an input pinMode(buttonPin, INPUT); // initialize the LED pin as an output pinMode(ledPin, OUTPUT); } void loop() { // read the state of the pushbutton value buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH // if it is, the buttonState is HIGH if (buttonState == HIGH) { // turn LED on digitalWrite(ledPin, HIGH); } else { // turn LED off digitalWrite(ledPin, LOW); } }
  12. const int analogInPin = A0; // ESP8266 Analog Pin ADC0

    = A0 int sensorValue = 0; // value read from the pot int outputValue = 0; // value to output to a PWM pin void setup() { // initialize serial communication at 115200 Serial.begin(115200); } void loop() { // read the analog in value sensorValue = analogRead(analogInPin); // map it to the range of the PWM out outputValue = map(sensorValue, 0, 1023, 0, 255); // print the readings in the Serial Monitor Serial.print("sensor = "); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue); delay(1000); }
  13. • Pulse width Modulation (PWM) is a way to fake

    an analog output by pulsing the output. This could be used to dim and brighten an LED or later to control a servo motor. The following example slowly brightens and dims an LED using for loops.
  14. const int ledPin = 2; void setup() { } void

    loop() { // increase the LED brightness for(int dutyCycle = 0; dutyCycle < 1023; dutyCycle++){ // changing the LED brightness with PWM analogWrite(ledPin, dutyCycle); delay(1); } // decrease the LED brightness for(int dutyCycle = 1023; dutyCycle > 0; dutyCycle--){ // changing the LED brightness with PWM analogWrite(ledPin, dutyCycle); delay(1); } }