COIMBATORE – 641 004 SESSION 1 DEPARTMENT OF ROBOTICS & AUTOMATION ENGINEERING PSG COLLEGE OF TECHNOLOGY ARDUINO WORK SHOP FOR BEGINERS 1 Selvaraj . K Project Engineer PSG-Robotics
OVERVIEW Microcontroller Defined Arduino Defined Arduino Advantages Arduino Applications Types of Arduino Boards Analog, Digital, Inputs and Outputs
MICROCONTROLLER Microcontroller Like as Brain It make decision in the Robots It collect the information from the Sensors and control the actuator by the command
MICROCONTROLLER Microcontroller It is a Decision maker with help of ROM,RAM and Arithmetic Logic Unit. Input port- Eye(Sensor) Output Port- Mouth(Actuators or Speaker) All input and output ports are controlled by the programming
MICROCONTROLLER Programmers work in the virtual world. Machinery works in the physical world. How does one connect the virtual world to the physical world? A microcontroller is basically a small-scale computer with generalized (and programmable) inputs and outputs. The inputs and outputs can be manipulated by and can manipulate the physical world
INTRODUCTION ABOUT ARDUINO Based on a simple micro-controller board, and A development environment (IDE) for writing software for the board Open source electronics prototyping platform based on flexible ,Easy to use hardware and software Arduino can be used to develop interactive objects, taking inputs from a variety of switches or sensors, and controlling a variety of lights, motors, and other physical outputs. Arduino projects can be stand-alone, or they can be communicate with software running on your computer (e.g. Flash, Processing, MaxMSP .) The boards can be assembled by hand or purchased preassembled; the open-source IDE can be downloaded for free . The Arduino programming language is an implementation of Wiring, a similar physical computing platform, which is based on the Processing multimedia programming environment .
MAIN ADVANTAGES OF ARDUINO Arduino microcontrollers have become the de facto standard. Make Magazine features many projects using Arduino microcontrollers. Strives for the balance between ease of use and usefulness. Programming languages seen as major obstacle. Arduino C is a greatly simplified version of C ++. Unit price around Rs.1400
APPLICATION AREAS Light control Motor control Automation Robotics Networking Custom protocols Your imagination is the limit…
TYPES OF ARDUINO BOARDS Many different versions Number of input/output channels Form factor Processor Leonardo Due Micro LilyPad Esplora Uno Mega
LEONARDO Compared to the Uno, a slight upgrade Built in USB compatibility
DUE Much faster processor, many more pins Operates on 3.3 volts Similar to the Mega
MICRO When size matters: Micro, Nano, Mini Includes all functionality of the Leonardo Easily usable on a breadboard
LILYPAD LilyPad is popular for clothing-based projects . It is a Low weight and flexible
ESPLORA Game controller Includes joystick, four buttons, linear potentiometer (slider), microphone, light sensor, temperature sensor, three-axis accelerometer. Not the standard set of IO pins.
MEGA Compared to the Uno, the Mega: Many more communication pins More memory
ARDUINO MEGA Physically larger than all the other boards Offers significantly more digital and analog pins. Uses a different processor allowing greater program size Microcontroller : ATmega1280 Operating Voltage 5V Input Voltage: 7-12V Digital I/O Pins 54 (of which 14 provide PWM output )
ARDUINO MEGA Analog Input Pins 16 Flash Memory 128 KB of which 4 KB used by boot loader SRAM 8 KB EEPROM 4 KB Clock Speed 16 MHZ
ARDUINO UNO The pins are in three groups : Invented in 2010 14 digital pins 6 analog pins power
ARDUINO UNO Microcontroller ATmega 328 Operating Voltage 5V Input Voltage (recommended) 7-12V Input Voltage (limits) 6-20V Digital I/O Pins 14 (of which 6 provide PWM output) Analog Input Pins 6 DC Current per I/O Pin 40 mA DC Current for 3.3V Pin 50 mA Flash Memory 32 KB (of which 0.5 KB used by boot loader ) SRAM 2 KB (ATmega328) EEPROM 1 KB (ATmega328) Clock Speed 16 MHz
Totally Arduino Uno have 14 Digital Input and Output p ins. They are numbered 0 to 13. Analog Input Pins are A0 to A5
ARDUINO COMPONENTS
UNDERSTANDING INPUT VS OUTPUT INPUT PIN Inputs is a signal / information going into the board. OUTPUT PIN Output is any signal exiting the board .
ANALOG VS DIGITAL ANALOG Microcontrollers are digital devices – ON or OFF DIGITAL An Analog signal is anything that can be a full range of values. What are some examples? Think of like a ramp or a hill.
INPUT and OUTPUT analogRead -Analog INPUT analogWrite -Analog OUTPUT digitalRead - digital INPUT digitalWrite - digital OUTPUT
BASIC KNOWLEDGE REQUIRED Ohms LAW Current Voltage Resister Capacitor Inductor Voltage LAW Current Law Rheostat function Transformer Rectifier Regulator Inverter Amplifier Diode Transistor AC and DC Voltages Types of Motors Basic sensors
PULL UP RESISTER PULL DOWN RESISTER
ANALOG VS DIGITAL To create an analog signal, the microcontroller uses a technique called PWM. Pins 3, 5, 6, 9, 10, 11 are capable of producing an Analog Output Pulse Width Modulation (PWM)
BEGINNING ARDUINO PROGRAMMING SESSION II
OVERVIEW Objectives Startup Arduino IDE Arduino Sketch Details Commands ,Operators, Variables Basic Repetitions Settings and Configurations
OBJECTIVES Provide a thorough introduction to the Arduino programming environment. Develop a use of simple functions to interact with the LEDs, light sensor, push button, and buzzer on the Protosnap Pro Mini.
STARTUP ARDUINO IDE Double-click on either the Arduino Icon or wherever you installed (saved) the Arduino program.
PLUG IT IN
THE ENVIRONMENT
PARTS OF THE SKETCH
COMMENTS Comments can be anywhere Comments created with // or /* and */ Comments do not affect code You may not need comments, but think about the community.
OPERATORS The equals sign = is used to assign a value == is used to compare values And & Or && is “and” || is “or”
BASIC VARIABLE TYPES Boolean Integer Double Float Character String
ASSIGNING VARIABLES Boolean: variableName = true; or variableName = false; Integer: variableName = 32767; or variableName = -32768;
VARIABLE SCOPE Where you declare your variables matters?
SETUP void setup ( ) { } The setup function comes before the loop function and is necessary for all Arduino sketches
SETUP void setup ( ) { } The setup header will never change, everything else that occurs in setup happens inside the curly brackets
SETUP void setup ( ) { pinMode (13, OUTPUT); } Outputs are declare in setup , this is done by using the pinMode function This particular example declares digital pin # 13 as an output, remember to use CAPS
SETUP void setup ( ) { Serial.begin ; } Serial communication also begins in setup This particular example declares Serial communication at a baud rate of 9600 . More on Serial later...
Setup, Internal Pullup Resistors void setup ( ) { digitalWrite (12, HIGH); } You can also create internal pullup resistors in setup, to do so digitalWrite the pin HIGH This takes the place of the pullup resistors currently on your circuit 7 buttons
Setup, Interrupts void setup ( ) { attachInterrupt (interrupt, function, mode) } You can designate an interrupt function to Arduino pins # 2 and 3 volatile unsigned int L=1; volatile double Le,Re ; void setup() { attachInterrupt (0, countpulsesL , FALLING); Serial.begin (9600);} void loop() { Serial.println (L); delay(1000);} void countpulsesL () {L++;}
Setup, Interrupts void setup ( ) { attachInterrupt (interrupt, function, mode) } Interrupt: the number of the interrupt, 0 or 1, corresponding to Arduino pins # 2 and 3 respectively Function: the function to call when the interrupt occurs Mode: defines when the interrupt should be triggered
Setup, Interrupts void setup ( ) { attachInterrupt (interrupt, function, mode ) } LOW whenever pin state is low CHANGE whenever pin changes value RISING whenever pin goes from low to high FALLING whenever pin goes from low to high Don’t forget to CAPITALIZE
BASIC REPETITION for (int count = 0; count<10; count++) {// for action code goes here //this could be anything}
BASIC REPETITION for (int count = 0; count<10; count++) { //for action code goes here }
BASIC REPETITION for (int count = 0; count<10; count++) { //for action code goes here }
BASIC REPETITION for ( int count = 0; count<10; count++) { //for action code goes here }
Basic Repetition for (int count = 0; count<10; count++) { //for action code goes here }
BASIC REPETITION for (int count = 0; count<10; count++ ) { //for action code goes here }
Basic Repetition for (int count = 0; count<10; count++) { //for action code goes here }
BASIC REPETITION while ( count<10 ) { //while action code goes here //should include a way to change count //variable so the computer is not stuck //inside the while loop forever }
BASIC REPETITION while ( count<10 ) { //looks basically like a “for” loop //except the variable is declared before //and incremented inside the while //loop }
ARDUINO DATA COMMUNICATION SETUP 68
CONFIGURING ARDUINO Setup Board (Arduino UNO/ ATmega328) Setup COM Port PC – Highest COM #
Settings: Tools Board
Settings: Tools Serial Port
Input Status Bar Program Notification Area
5 .- Verify/Compile 6.- Once it compiles, you must see the following messages in the Status bar and the Program notification Area
7 . Upload it 8 . Once it upload, you must see the following messages in the Status bar and the Program notification Area
Error avrdude : stk500_getsync(): not in sync: resp =0x00 can't open device "COM10": The system cannot find the file specified
ARDUINO PROGRAMMING CHALLENGES Session III &IV
CHALLENGES Introduction to use Electronic components LED Control by Arduino Multiple LEDs Control by looping Operators conditions test Analog sensor test Analog Sensor Value based LED control
LIST OF COMPONENTS Arduino board USB cable L293 driver board Battery
LIST OF COMPONENTS Dc motor Line array sensor Potentiometer Ultrasonic sensor adapter
LIST OF COMPONENTS Connecting wires Ultrasonic sensor LEDs Resisters Reset button/switch
ARDUINO PROGRAMMING INSTRUCTIONS pinMode(pin, mode) Designates the specified pin for input or output digitalWrite(pin, value) Sends a voltage level to the designated pin digitalRead(pin) Reads the current voltage level from the designated pin analog versions of above analogRead's range is 0 to 1023 serial commands print , println, write
ARDUINO USING SOLDERLESSBREADBOARD Solderless Board is useful to build proto types . Time consuming process of soldering parts together to make connections Most important thing in using a solder less breadboard in understanding its connections wiring underneath the white cover to be able to connect parts in a way that complete and flawless lines are provided for electricity flow 82
Instruction to Components handling Doing circuit connection – Don’t power up Controller board Don’t use metal surface and maintain at free surface Circuit check before power up Don’t make short circuit After completion of Experiments- all components put in to box and cross check the list
LED PROGRAMMING FOR BLINKING FUNCTIONS
CIRCUIT CONNECTION
DIGITAL OUTPUT-LED 86 Digital pin 10 connected with Resister. Long leg connected with resister end. short Leg connected with Ground . Ground Pin Digital Pin
LED FUNCTION INSTRUCTIONS Connect the positive (+) lead of a power source to the long leg of an LED. Connect other leg of the LED to a resistor. High resistance means a darker light. Low resistance means brighter light. No resistance means to the negative lead of the power source. a burned out LED. Connect other leg of the resistor
LED FUNCTION
ARDUINO-DIGITAL OUTPUT-LED 89
BOARD SELECTION
COM PORT SELECTION
COMPILING AND UPLOADING CODE
CHALLENGES IN LED CONTROL Challenge 1A : Blink LED Every one second Challenge 1B : Multiple LEDs Blink once at a time Challenge 1C : Multiple LEDs- Knight Riders Style Challenge 1D: Color Brightness control using PWM function Challenge 1E: Color Brightness control using potentiometer Challenge 1F: Arduino-Analog Output LED Dimming Using for Loop Structure
1B. MULTIPLE LEDS CONNECTION LED1: Arduino pin2 LED2: Arduino pin3 LED3: Arduino pin4 All LED’s Gnd- Connected with Arduino Ground
MULTIPLE LEDs CONNECTION
1B. MULTIPLE LED BLINKING AT A TIME
1C. LEDS KNIGHT RIDERS STYLE
1D.BRIGHTNESS CONTROL USING analogWrite()
1E.Color Brightness control using potentiometer
1F. LED DIMMING USING FOR LOOP STRUCTURE 100
IF CONDITION
IF CONDITION LOGIC
Push button working principle
LED CONTROLLED BY PUSH BUTTON Switch output connected with Arduino pin2 Led pin connected with Arduino pin 6
PUSH BUTTON FUNCTION SWITCH IN OPEN SWITCH IN CLOSED If switch ON- circuit is closed, current will flow in the circuit path. So input voltage is 5V. Else switch OFF- circuit is open, no current flow in this path, so input current 0V.
PROGRAM FOR PUSH BUTTON CONTROL
2. CHALLENGES CHALLENGE 2A: LED ON When press any One push button at a time CHALLENGE 2B: LED ON when press all push button at a time CHALLENGE 2C: LED ON when press at least 2 push button at a time in 4 push buttons using application CHALLENGE 2D: LED ON when press at least 3 push button at a time in 4 push buttons using application
2. MULTIPLE SWICH FUNCTION
3. SERIAL MONITOR CONFIGURE BAUD RATE Serial. begin (baud rate) Some Examples Baud rate 4800,9600,14400,19200,28800,38400,5760 and 115200… etc AnalogRead Value is 0 to 1023 WATCHING OUTPUT AT SERIAL MONITOR Serial.println();
SERIAL MONITOR TEST PROGRAM
OPEN UP SERIAL MONITOR
JOYSTICK DEVELOPMENT LEFT UP DOWN RIGHT Display: RIGHT LEFT UP DOWN
PROGRAM FOR LED BRIGHTNESS CONTROL LED BRIGHT: int pot = A0; // pin that the sensor is attached to pot int LED=9; void setup() { pinMode(LED, OUTPUT); Serial.begin (9600); } void loop() { int analogValue = analogRead (pot)/4; analogWrite(LED, analogValue ); Serial.println ( analogValue ); delay(100); }
LED ON/OFF CONTROLLED WITH RESPECT TO COMPARISON OF THRESHOLD Led on/off controlled with respect to comparison of threshold and analog value from potentiometer
PROGRAM
5.Potentiometr Voltage -Voltage Display Analog Read value is 0-1023 Divisions (0-5V) 1 Division= 5/ 1023 V= 0.00488 V Formula: int POT= analogRead (A0); int Voltage = POT X 0.0049
HOME MADE AUTOMATION If push button is pressed at once - Automatically electrical fans and lights will ON If again press the same push button Automatically electrical fans and lights will OFF Experiments: LED will ON/ OFF based on this condition
Relay Board
Relay Application
CIRCUIT
int inPin = 2; // the number of the input pin int outPin = 6; // the number of the output pin int state = HIGH; // the current state of the output pin int reading; // the current reading from the input pin int previous = LOW; // the previous reading from the input pin long time = 0; // the last time the output pin was toggled long debounce = 200; // the debounce time, increase if the output flickers void setup() { pinMode ( inPin , INPUT); pinMode ( outPin , OUTPUT); } void loop() { reading = digitalRead ( inPin ); if (reading == HIGH && previous == LOW && millis () - time > debounce ) { if (state == HIGH) state = LOW; else state = HIGH; time = millis (); } digitalWrite ( outPin , state); previous = reading; }
MOTOR CONTROL AND SENSORS INTERFACING SESSION V & VI
OVERVIEW Introduction about Sensors Introduction about Motors Motor control Ultrasonic Sensor Testing IR array sensor Testing Motor speed control based on Sensors value
INTRODUCTION ABOUT SENSORS Sensor Types of sensors IR sensor Sound sensor Temperature sensor How to use it? Where to use it?
WHAT IS A SENSOR….? A sensor is a device that measures a physical quantity and converts it into a signal which can be read by an observer or by an instrument Sensors are used in everyday objects such as touch-sensitive elevator buttons (tactile sensor) and lamps which dim or brighten by touching the base Applications include cars, machines, aerospace, medicine, manufacturing and robotics
IR SENSOR
WORKING IR sensor works on the principle of emitting IR rays and receiving the reflected ray by a receiver (Photo Diode) IR source (LED) is used in forward bias IR Receiver (Photodiode) is used in bias
IR SENSOR CIRCUIT
VOLTAGE COMPARATOR A Comparator is a device which compares two voltages or currents and switches its output to indicate which is larger. Comparator is an Op-amp. PIN DIAGRAM LM 358
LIGHT SENSOR CIRCUIT
TEMPERATURE SENSOR
TIMER 555 IC The 555 Timer IC is an integrated circuit (chip) implementing a variety of timer and multivibrator applications. PIN DIAGRAM
Solar Cell Digital Infrared Ranging Compass Touch Switch Pressure Switch Limit Switch Magnetic Reed Switch Magnetic Sensor Miniature Polaroid Sensor Polaroid Sensor Board Piezo Ultrasonic Transducers Pyroelectric Detector Thyristor Gas Sensor Gieger-Muller Radiation Sensor Piezo Bend Sensor Resistive Bend Sensors Mechanical Tilt Sensors Pendulum Resistive Tilt Sensors CDS Cell Resistive Light Sensor Hall Effect Magnetic Field Sensors Compass IRDA Transceiver IR Amplifier Sensor IR Modulator Receiver Lite-On IR Remote Receiver Radio Shack Remote Receiver IR Sensor w/lens Gyro Accelerometer IR Reflection Sensor IR Pin Diode UV Detector Metal Detector
A motor is any of a class of rotary electrical motors that converts electrical energy into mechanical energy. The most common types rely on the forces produced by magnetic fields. INTRODUCTION ABOUT MOTOR
16/11/2021 PSG College of Technology TYPES OF MOTORS AC motors DC motors DC geared motors Stepper motors Servo motors
16/11/2021 PSG College of Technology AC MOTOR These are the motors which convert alternating signal into rotational motion. Examples are the motor in water pumps, table fan, ceiling fan.
16/11/2021 PSG College of Technology DC MOTOR These are the motors which convert DC signals into rotational motion In robotics applications they are preferred over AC motors as the motor and the complete circuit require same kind of supply i.e DC supply
16/11/2021 PSG College of Technology DC GEARED MOTORS These are the DC geared motors having external gear arrangement attached with motor. These are the motors that are most commonly used in robotics as they are having considerable torque.
16/11/2021 PSG College of Technology
16/11/2021 PSG College of Technology STEPPER MOTOR A type of motor which takes DC pulse input and gives rotating motion in steps. They are of two types : Unipolar : which moves in one direction only. Bipolar : which moves in both directions
16/11/2021 PSG College of Technology
16/11/2021 PSG College of Technology Servo motors are the most powerful motors for robotic applications. They comes in both variants , AC and DC. They can change the direction with same supply. SERVO MOTOR
16/11/2021 PSG College of Technology A servomechanism , or servo is an automatic device that uses error-sensing feedback to correct the performance of a mechanism The term correctly applies only to systems where the feedback or error-correction signals help control mechanical position or other parameters
For both way motion ( clockwise and anticlockwise ) of one DC motor, an “H-Bridge” can be employed. For both way motion of two DC motors “dual H-Bridge IC L293D” can be employed. 16/11/2021 PSG College of Technology S1-S4 ON, S2-S3 OFF (for one direction). S2-s3 on and s1-s4 off (for other direction). ONLY POSSIBLE SWITCHES SETTING FOR ROTATION
16/11/2021 PSG College of Technology
16/11/2021 PSG College of Technology
MOTOR DRIVER CONCEPT
L293D DRIVER BOARD
L293D DRIVER IC
MOTOR CONTROL
MOTOR SPEED CONTROL
DC MOTOR SPEED CONTROL BY USING POTENTIOMETER TASK EXPLANATION: 1. Speed Control by Potentiometer 2. Direction change when potentiometer value move less than 500
ULTRASONIC SENSOR Measurement Principle of Ultrasonic Sensor Ultrasonic sensors transmit ultrasonic waves from its sensor head and again receives the ultrasonic waves reflected from an object. By measuring the length of time from the transmission to reception of the sonic wave, it detects the position of the object.
Master Sender #include < Wire.h > void setup() { Wire.begin (); // join i2c bus (address optional for master) } byte x = 0; void loop() { Wire.beginTransmission (8); // transmit to device #8 Wire.write ("x is "); // sends five bytes Wire.write (x); // sends one byte Wire.endTransmission (); // stop transmitting x++; delay(500); }
Slave Receiver #include < Wire.h > void setup() { Wire.begin (8); // join i2c bus with address #8 Wire.onReceive ( receiveEvent ); // register event Serial.begin (9600); // start serial for output } void loop() { delay(100); } void receiveEvent (int howMany ) { while (1 < Wire.available ()) { // loop through all but the last char c = Wire.read (); // receive byte as a character Serial.print (c); } int x = Wire.read (); // receive byte as an integer Serial.println (x); // print the integer }