Robotics 1st Quarter Reviewer.pdf
Document Details
Uploaded by Deleted User
Tags
Full Transcript
ARDUINO PROGRAMMING Arduino IDE Arduino Language - Arduino - C++ libs - C/C++: Readable Code - Assemble: Readable Code - Machine Language: Binary Code Hello World (Blink) - Code Hello...
ARDUINO PROGRAMMING Arduino IDE Arduino Language - Arduino - C++ libs - C/C++: Readable Code - Assemble: Readable Code - Machine Language: Binary Code Hello World (Blink) - Code Hello World Serial Example - int led = 13; is the Variable - // are Comments - - void , pinmode, digitalwrite, delay, and the brackets are all Functions Serial Objects - pinMode(led, OUTPUT); } is an - Serial.begin : Enables Serial Instruction - (9600) : Baud Rate - The ; or semicolon is an - Serial.println : Print and Println Instruction - (“Hello World”) : Variables, Strings, and - pinMode is a Function Call Control Character - (led, OUTPUT) is an Argument - Baud rate: a number that measures the IDE Tools Menu (Integrated Development speed of data transmission Environment - IDE) - Note: String and Variables can’t be used on the same line - Board: Arduino Uno - Serial Port: /dev/tty.usbmodem1411 - Use Auto Format - No programmer and Burn Bootloader ARDUINO IDE DIFFERENT PARTS OF THE PROGRAM Void Setup - Only run once Integrated Development Environment (IDE) - At the beginning of the program - Software application that provides Void Loop comprehensive facilities to computer - Code that will repeat the code inside programmers for software the loop functions runs over and over development as long as the maker board is turned on - Normally consists of at least a source Input code editor, build automation tools and - Inputs a value to the microcontroller a debugger - Has high resistance PARTS OF THE ARDUINO IDE Output Verify - Outputs value to a device - Compiles and checks your code - Has low resistance - Catch errors in syntax (like missing analogRead() semicolons or parenthesis) - Reads an analog value from 0-255 Upload - Allows you to get readings from analog - Upload or sends your code to the sensors or interfaces that have more arduino board than two states - When you click it, you should see the analogWrite() lights on your board blink rapidly - Writes an analog value from 0-255 New digitalRead() - This button opens up a new code - Reads a digital value window tab - LOW OR HIGH (0 or 1) Open - Reads the value from a specified digital - This button will let you open up an pin either HIGH or LOW existing sketch digitalWrite() Save - Writes a digital value - Saves the currently active sketch - LOW OR HIGH (0 or 1) Serial Monitor - Assigns a HIGH or LOW value to a pin - Opens a window that displays any serial already declared information your arduino board is Serial.begin() transmitting - Starts the serial monitor - Very useful for debugging - Value inside the function is the baud Sketch Name rate - Shows the name of the sketch you are Serial.print() currently working on - Prints value or text without a new line Code Area Serial.println() - Area where you write the code for your - Prints value creating a new line sketch DIFFERENCES OF THE PARTS Message Area Void Setup and Void Loop - Where the IDE tells you if there were - Void setup runs only once any errors in your code - Void Loop runs repeatedly Text Console Input and Output - Shows complete error messages - Input is what goes in the function - When debugging, it is very useful - Output is what comes out (result) of Board and Serial Port the function - Shows you what board and the serial port selections Arduino ID analogRead and analogWrite - Analog sensor that serves as the - analogRead reads that analog value primary component in sumo robot - analogWrite writes the PWM value Piezo Buzzer digitalRead and digitalWrite - One integrated electronic transducers, - digitalRead reads the button voltage (if DC voltage supply, widely used in HIGH or LOW) computers ,printers, copiers, alarm, - digitalWrite turns it on (HIGH) and off electronic toys, automotive electronic (LOW) equipment, telephones, timers, and HIGH AND LOW other electronic products for sounds - HIGH means its on devices - LOW means its off - Produces a tone or sound Serial.print and Serial.println - Can be driven by oscillating electronic - Serial.print prints only the number or circuit or other audio signal source string - Positive: longer terminal of the device; - Serial.pintln prints it with a newline red wire; represented by + character - Negative: shorter terminal, black wire; represented by - ELECTRONIC SOLID-STATE DEVICES LM35 (Temperature Sensor) - A temperature measuring device having an analog output voltage LED proportional to the temperature - Light-emitting Diode - Provides output voltage in Centigrade - A semiconductor light source that (Celsius) emits light when current flows through - Does not require any external it calibration circuitry - Electrons in the semiconductor - Output voltage linear relationship recombine with electron holes, between the Celcius temperature scale releasing energy in the form of photons - The legs of an LM35 needs to be - The longer is anode which is positive connected to 5V, Analog, Ground (from (connected to pin) left to right) - The shorter is anode which is negative IR Sensor (connected to GND) - Infrared Sensor - An electronic device that measures and detects infrared radiation in its surrounding environment Motor Driver - L293D Motor Driver - Acts as an interface between the motors and the control circuits - Enables you to perform automatic Ultrasonic Sensor tasks using electrical power - An electronic devices that measures - Takes a low current signal and then the distance of a target by emitting turn it into a higher current signal that ultrasonic sounds waves can drive a motor - Converts the reflected sound into an Potentiometer electrical signal - A three-terminal resistor with a sliding - TrigPin is for OUTPUT or rotating contact that forms an - EchoPin is for INPUT adjustable voltage divide - A simple knob that provides a variable - For Statement: used to repeat a block resistance, which we can read into the of statements enclosed in curly braces arduino board as an analog value Floating Pin - Returns an analog value between 0 - When the button is not being pressed and 1023 - It is not connected to anything - Middle pin should be connected to buttonState = digitalRead(buttonPin) analog pin - Check the condition of the tact switch 3 and 5 Channel Line Tracking Sensor (Line delay(ms) Sensor - Pauses the program for the amount of - Designed for mobile robot tracking time (in milliseconds) specified as application parameter - Five or three infrared reflective sensors Resistor CNY70 will reliably detected dark lines - Device having a designed resistance to printed over light color surface the passage of an electric current - Detection distance Sumo - >10mm from sensor face is possible - Came from an old Japanese sport - Adjustable sensitive for each sensors - Two opponents fighting in a ring, each of the trying to push the other TERMS opponent out of it Robot-Sumo - A sport in which two robots attempt to Line Number push each other out of a circle - Shows you what line number your Capacitance cursor is on - The ability of a material to hold an - Useful since the compiler gives error electrical charge messages with a line number Constant Compiling - Named identified that cannot change - Before you program “code” can be sent its value in a program to the board, it needs to be converted Debugging into instructions that the board - Process of going through a circuit code understands and finding errors until the expected - Compiling is the word for this process behavior is achieved setup() Float - Often used to set pinmode to input or - Data type used to represent a fraction output which entails the use of decimal points loop() for floating point numbers - This code happens over and over again Microcontroller PWM (Pulse Width Modulation) - Brains of the arduino - A method of emulating an analog - A small computer that you will program signal through a digital to listen for process and display - A way to stimulate a varying static information voltage Sensor - 8 is not a PWM Pin on most Arduino - Component that measures one form of boards energy and converts it to voltage or Pulse Width current - Defined as the duration of “on time” Serial Communication For Loop - Type of serial protocol between two - If the condition becomes false, the loop devices ends Switch 7 Segment LED - Component that can open or close an electrical circuit Variable - Data type that stores values which are likely to change as your program runs Tone() - Generates a square wave of the specified frequency (and 50% duty cycle) on a pin While Loop - Will continuously and infinitely, until CODES the expression inside the parenthesis becomes false Running Lights 10 LEDS If Else Statement - Checks for a condition and executes the proceeding statement or set of statements if the condition is true #define - Useful C component that allows the programmer to give a name to a constant value before the program is compiled ; (Semicolon) - Syntax used to end a statement Void() - Function used to initializes variables, pin modes, start using libraries, etc. Nixie Tube - Electronic device for displaying numerals or other information using glow discharge Analog - Form of electronic communication sent as signals of varying frequency instead of ON or OFF like a digital data transmission Arduino Grammar - The arduino grammar is built on the basis of C grammar Ultrasonic Sensor Additional Info - TrigPin: used to trigger the ultrasonic sound pulses - EchoPin: produces a pulse when the reflected signal is received - Vcc = power - Gnd = ground Traffic Lights with 10 LED Traffic Light Countdown (7 Segment) Ultrasonic Sensor with LED Serial Monitor Basic Serial Monitor LED void setup() { Serial.begin(9600); } void loop() { Serial.println("Hello world!"); delay(1000); } Serial Monitor Notification int trigPin = 3; int echoPin = 2; int pinButton = 6; int LED1 = 5; int LED2 = 4; long duration, cm; void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(pinButton, INPUT); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); } void loop() { int stateButton = digitalRead(pinButton); digitalWrite(trigPin, 0); delayMicroseconds(5); digitalWrite(trigPin, 1); delayMicroseconds(10); digitalWrite(trigPin, 0); duration = pulseIn(echoPin, 1); cm = (duration/2) / 29; if(cm >300){ Serial.println("No Motion Detected"); digitalWrite(LED1, 0); digitalWrite(LED2, 0); } if (cm = 121){ Serial.println("Motion Detected"); digitalWrite(LED1, 1); digitalWrite(LED2, 0); } if(cm = 0){ Serial.println("Motion Detected! [WARNING: UNKNOWN OBJECT CLOSE!]"); digitalWrite(LED1, 0); digitalWrite(LED2, 1); if (stateButton == 0){ Serial.println("Emergency! Calling For Help!"); } delay (300); } }