top of page

Search Results

125 items found for ""

  • Digital | SimpleMechatronics| Simple MECHATRONICSsimple mechatronics

    PAGE IS UNDER CONSTRUCTION. ​ PLEASE ALLOW SOME TIME FOR COMPLETION. ​ SORRY FOR INCONVENIENCE CAUSED.

  • Arduino_BLINK_LED | SimpleMechatronics| Simple MECHATRONICSsimple mechatronics

    Introduction to Arduino Blink LED Do you know C-language? What is your first program in C-language? "Hello World"? Ya!!! This BLINK LED project is similar to HELLO WORLD Project in C-language. This is the first project on Arduino Board not only to learn yourself about Arduino, but to test a new Arduino board also. The BLINK LED project is explained in simple steps, to create interest in starting Arduino projects without having much knowledge about micro-controllers and Arduino. To start with Arduino Blink LED project, the following items should be ready with you. (Arduino uno is good for start with) 1) Arduino Uno board with matching USB cable. (USB A to B, also called USB printer cable). (click here to know about Arduino Boards) 2) Download and Install Arduino IDE software on your system (your PC / laptop) (click here to know about Arduino IDE) Start Arduino BLINK LED : The Blink LED project is explained in pictorial form for easy understanding. Just follow them. 1) Connect the Arduino USB cable (type A) in USB port of PC (Personal Comupter) or Laptop. 2) Connect the Arduino USB cable (type B) in USB port of Arduino Uno Board. Then, a power ON indicator will glow on the Arduino Uno board (1 and 2 are interchangeable) 3) Click "ARDUINO" shortcut on your desktop (or where you have saved it). Then, the Arduino IDE, will be displayed on your system. 4) Goto menu: "FILE" , Click "EXAMPLES", Select "01.BASICS", then Select "BLINK". (i.e. menu-> File -> Examples -> 01.Basics -> Blink) Then, a new window appears with BLINK LED code with comments before the actual code. Scroll UP to view actual code. 5) Goto menu: "Tools" , Click "BOARD", then Select "ARDUINO/GENUINO UNO". (i.e. menu-> Tools -> Board -> Arduino/Genuino Uno ) [normally, it is set as default] 6) Goto menu: "Tools" , Click "PORT", then Select "COMX:ARDUINO/GENUINO UNO". (i.e. menu-> Tools -> Port -> PortX:Arduino/Genuino Uno ) where X is a number. Normally, the port recognizes the arduino board by default and visible in the list for selection. 7) Goto menu: "Tools" , Click "PROGRAMMER", then Select "AVRMSP MKII". ( i.e. menu-> Tools -> Programmer -> AVRMSP mkII ) Normally, AVRMSP mkII is set as the the default programmer. If not, change it as AVRMSP mkII. 8) Goto menu: "Tools" , Click "GET BOARD INFO". ( i.e. menu-> Tools -> Get Board Info ) This operation is for confirming the connection to your Arduino Uno board. You may skip this step, if the board is automatically recognized by the port number. A message box will display the details of the Ardunio board immediately. In case of improper connection, it takes much time and displays an error message in the output screen (black screen at bottom) 9) Goto menu: "SKETCH" , Click "VERIFY/COMPILE". ( i.e. menu-> Sketch -> Verify/Compile ) or click tool bar icon A text message "Compiling sketch..." and a progress bar appears in between text editor area and output area (black screen). On completion of compiling, the progress bar disappears and "Done compiling" message appears. 10) Goto menu: "SKETCH" , Click "UPLOAD". ( i.e. menu-> Sketch -> Upoload ) or click tool bar icon Again text message "Compiling sketch...", then "Uploading..." along with a progress bar appears in between text editor area and output area. Two LEDs (TXD & RXD)on Arduino Uno board quickly blinks for a while and stops when uploading is completed. On completion of uploading, the progress bar disappears and "Done Uploading" message appears. Now, THE INBUILT LED on the Arduino Uno board STARTS BLINKING at 1 second ON time and 1 second OFF time. ​ In case of any error, the error message is displayed at the output screen (black screen at bottom). The error message appears, mostly due to port connection problem or wrong Programmer selection. In that case, s et the Board, Port and Programmer as explained above ( point 5, 6 & 7 ) and test the connection as explained above ( point 8 ). Then, retry for compiling and uploading the sketch. Understanding Arduino BLINK LED : 11) Goto void setup ( ) in editor area. The setup function runs once , when the Arduino Board is powered On (or pressed reset button). So, the setup function is used for initializing the input and output devices connected to the Arduino board. ​ In the Blink sketch, only one statement (using pinMode) is available in setup function, pinMode(LED_BUILTIN, OUTPUT); ​ which sets the LED available (soldered) on Arduino Uno board at pin number 13 , as output. The LED_BUILTIN keyword is pre-defined as 13 for Arduino Uno and automatically varies as per the selection of Board (refer above point 5) 12) Goto void loop ( ) in editor area. The loop function runs infinite times , after the above setup function is called (or run) So, the loop function is used for reading input signal(s) from Arduino pins, process the input value(s), then send output signal(s) accordingly to Arduino pins. This is a continuous process, so is called loop function. ​ In the Blink sketch, only four statements are available, which uses in-built functions digitalWrite and delay, in loop function. The statements also have comments/remarks as suffix for each statement as explanation. ​ digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); ​ The digitalWrite function is used to set any Arduino pin to logical value. i.e., digital high (+5V) or digital low (0V). The LED connected to the particular arduino pin glows when the pin is set as logical HIGH and goes off when the pin is set as logical LOW. So, the digitalWrite function is used to control (on/off) the LED at pin number 13 (which is declared as OUTPUT for LED_BUILTIN in setup function) ​ The delay function is used to make the micro-controller (on Arduino board) idle for a specific time, in milli-seconds. So, delay(1000); statement makes the micro-controller to just count time delay, set as 1000 milli-seconds and then process the next statement. ​ So, in the loop function, the statement 1 makes the LED to glow, the statement 2 makes the micro-controller wait (idle) for 1000 milli-seconds ( say one second ), the statement 3 makes the LED to go off and the statement 4 makes the micro-controller wait (idle) for 1000 milli-seconds again. Once, all the statements (4 in this case) are executed in the loop function, then, the control goes to starting of loop function, which executes the statements 1, 2, 3 & 4 and so on, until the power to Arduino board is switched off. Playing with Arduino BLINK LED : 13) Editing Blink Sketch: You may edit the Blink sketch and play with it. Here, you should not change pinMode and digitalWrite statements, since you are using only one pin for control (LED at pin 13). You may interchange statement 1 and 3, which makes the LED to go OFF first and goes ON next. But, due to continuous loop of OFF and ON (or ON and OFF), you may hardly notice the difference. ​ The second option is varying the delay time for the built-in LED, i.e., ON and OFF.. If you change the delay value after digitalWrite(LED_BUILTIN, HIGH) , the ON time of LED effects. Similarly If you change the delay value after digitalWrite(LED_BUILTIN, LOW) , the OFF time of LED effects. ​ An example code is shown below using swapping (this is optional) of statements 1 and 3 and changing delay for ON and OFF time of LED. ​ digitalWrite(LED_BUILTIN, LOW); delay(100); digitalWrite(LED_BUILTIN, HIGH); delay(300); ​ By changing the code (sketch), the LED glows for 250 milli-seconds and goes off for 100 milliseconds. The difference may be easily identified by the naked eye 14) Compile and Upload Again: After editing/changing the sketch as per your requirement (various delay timings), again COMPILE and UPLOAD it to the Arduino Uno board as explained earlier (refer point 9 and 10). Customizing Arduino BLINK LED : 15) Customizing Blink LED Sketch: So, you are using the example code so far and editing the delay timings for changing the ON or OFF of the On-board-LED (identified as LED_BUILTIN). But, in actual practice, any pin may be used as output pin and blink a LED by connecting it externally. For convenience, the pin number may be identified by a variable name and the same name is used throughout the sketch. ​ The following sketch (code) blinks an LED connected to pin number 8 and identified by the name LED_PIN . Remarks/comments are written against each statement for easy understanding. ​ #define LED_PIN 8 // name the pin number 8 as LED_PIN ​ // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_PIN as an output. pinMode(LED_PIN, OUTPUT); } ​ // the loop function runs over and over again forever void loop() { digitalWrite(LED_PIN, HIGH); // turn the LED on (logic HIGH, means Vcc voltage level) delay(1000); // wait for ONE second ON time; i.e., 1000 milli-seconds digitalWrite(LED_PIN, LOW); // turn the LED off (logic LOW, means GND or 0 voltage level) delay(1000); // wait for ONE second OFF time } ​ ​ The output is shown here. So, You may define any pin as output and connect an LED with a series resistor ( in between 1k to 2.2K ) to limit the current flow through the pin. If you want to WALK FAST, walk alone. But, if you want to WALK FAR, walk together – Dr. Ratan Tata

  • Inductors | SimpleMechatronics| Simple MECHATRONICSsimple mechatronics

    Inductors (Coils): Inductor is an electric conductor in coil form (shape), which generates self inductance due to change in direction of flow of current through it. The property of inductor is inductance ( denoted by L in formulae) , which is measured in (units) Henrys. Since Henry is big unit, milli Henry (mH) is used in general Inductance: One Henry is defined as generating one volt by changing direction of one Ampere current in the coil at a rate of once per a second. ​ A magnetic field is produced in the coil due to change in direction of flow of current through the conductor and opposes the cause producing it may be called as Self Inductance . Choke used in a Tube-light set is a practical example for self inductance. ​ In case, the magnetic field produced by self inductance is effecting another coil surrounded by the first coil and producing voltage across the second coil, then is called Mutual Inductance . Transformer works on Mutual Inductance concept. ​ Inductor in DC circuits: Since the inductor works on change of direction of current flow through its conductor, there is no effect of inductance, if a constant uni-direction current flows through it. So, it has no effect in DC Circuits, except resistance caused by the conductor, which depends on the material property of the conductor. ​ One of the main use of Inductor (coil) in DC circuits is to prevent any signal or noise disturbance in DC line, if connected in series. Inductor in AC circuits: Inductors are highly used in AC circuits due to its self inductance with various frequencies. ​ As the frequency passing through the Inductor increases, it offers more resistance due to opposing nature of cause, which produces it. The resistance offered in AC signal across a Inductor (coil) is called Impedence marked as Z . So, for DC signal or power supply, a coil offers Zero impdence. Inductor - Mini Size: Now-a-days inductors (coils) are available as Concealed coils. Either the inductance value is marked on the surface or Colour band code used to identify the inductance value. The colour code is followed as per resistor color code and the units are milli Henrys (mH). ​ Two models of concealed inductors are shown here. These inductors are easy to fix on PCBs.

  • Arduino_TYPES | SimpleMechatronics| Simple MECHATRONICSsimple mechatronics

    Arduino: Introduction & TYPES If you are new to Arduino, just go through the page and successive pages. Just have a glance on the differences in the Arduino Boards. Initially, it is not possible to have full idea about all Arduino boards. Just read on . . . Arduino is a brand name and available as development boards for quick connection and programming. Many varieties of development boards are available from Arduino. Almost all Arduino boards use one AVR micro-controller IC (or chip) on its board, with boot-loader program (pre-loaded by default). In addition to the micro-controller, the board is generally equipped with a voltage regulator IC(s) and USB interface IC. The USB interface IC is useful to UPLOAD the program code and communicate external equipment using USB port (like PC). Now (for the time being), our discussion is made limited to Make-at-Home projects. We are explaining about the Arduino boards, which are easily available and easily used for our projects. Normally, Arduino boards operates between 7VDC to 12VDC (input at Vin pin) and a crystal is used for system frequency (for on-board micro-controller). The voltage regulator IC(s) convert input voltage available through DC jack, to 5VDC & 3.3VDC output voltages, which are available on the Arduino board. You may also directly connect 5VDC supply to 5V pin on Arduino board instead of 7 to 12VDC from DC jack. (refer images below) The basic data about the Arduino boards, which are frequently used in our projects, is listed below for quick reference. The pin outs are labelled and power supply pins are marked in red and blue colours for easy identification. Arduino UNO: Arduino UNO is one of the highly used Arduino boards. Most of the Arduino starters, use Arduino Uno board initially for learning. The ATMEGA328P micro-controller is used for Arduino Uno board. Small differences are observed in Arduino Boards, which are shown here. In case of PDIP, you may replace the micro controller (ATMEGA328P) and upload BOOT LOADER to the new micro-controller. ​ In case of CH340 IC is used for USB to Serial converter, then suitable driver has to be installed on your computer. The main pin-outs of Arduino UNO is shown below for easy identification and under standing. So, some pins are connected internally to work as one or more than one function. You have to write suitable code to control the particular pin for the required functionality. It is a general practice that the code written for Arduino is called as SKETCH. ​ The Arduino Uno board is programmed through USB type-B port (normally available for USB printers) and a separate DC power supply jack is available in addition to Vin pin. Arduino NANO: Arduino NANO board is bread-board friendly pin-outs, smaller in size and frequently used for Arduino projects. Due to its compactness with most of the required features and low-cost, it is loved by Arduino programmers. For Arduino Nano also, ATMEGA328P micro-controller is used. ​ The main differences w.r.t. Arduino Uno are: 1) mini USB socket for programming. 2) two extra ADC channels A6 & A7 3) positions of pin nos 0 & 1 are reversed 4) No DC jack is available. use Vin only for power input. Arduino MEGA: Arduino MEGA board is bigger in size and frequently used for Arduino projects, where more number of digital pins are required. Almost all features and pin-outs will match with Arduino Uno, where as extra pins are available for Arduino Mega. You may replace Arduino Uno with Arduino Mega, but, reverse may not be possible, if the program uses the extra pins. The ATMEGA2560 micro-controller is used for Arduino Mega board. You may expect explanation about some more types of Arduino boards in future . . . ​ SUCCESS is, when your SIGNATURE changes to Autograph. – Dr. A.P.J Abdul Kalam

  • AVR_USART | SimpleMechatronics| Simple MECHATRONICSsimple mechatronics

    AVR - USART: Read Before: Micro-controller Communications >> All AVR micro-controllers have Digital Input and Output Communcation, which is explained in AVR-GPIO . Some AVR micro-controllers have Analog-Digital Conversion, which is an important communication with the real world is explained in AVR-ADC/DAC . Now, we will go through some other important and frequently used communication methods, mostly Serial Coomucations, available for AVR micro-controllers. All AVR micro-controllers have Digital Input and Output Communcation, which is explained in AVR-GPIO . Some AVR micro-controllers have Analog-Digital Conversion, which is an important communication with the real world is explained in AVR-ADC/DAC . Now, we will go through some other important and frequently used communication methods, mostly Serial Coomucations, available for AVR micro-controllers. USART: USART (Universal Synchronous Asynchronous Receiver and Transmitter) : This is the highly used programmable, Full Duplex, serial communication available in AVR micro-controllers. The external pins marked as TX is used as Transmitter (data out) and RX is used as Receiver (data in). USART is a digital data FRAME FORMAT, transmitted and received by AVR micro controllers. The frame format contains one start bit, 5 / 6/ 7/ 8 / 9 data bits, [no/odd/even] parity bit and one or two stop bits. The digital data (in frame work) is transmitted at a particular frequency to match transmitter and receiver asynchronously (no clock pulse for matching). Where as, in synchronous transmission, one micro controller programmed as MASTER, sends clock pulse along with the data bits to match the frequency of transmission for other micro controller for processing. The frequency at which the serial data bits is transmitted is called as BAUD RATE. The Baud Rates are standard and may be programmed by you to set a standard baud rate, by programming UBRRH and UBRRL registers, which together is called UBRR register . A double speed option is also available for asynchronous mode. USART:Setting BAUD RATE: Some of the Standard Baud Rates are : 1200, 2400, 4800, 9600, 14400 and so on. One of the following formulae is used to set the value for UBRR register, where MCU_FREQ is the micro-controller clock frequency. ​ ubrr_value = ( MCU_FREQ / (2*baud_rate) ) -1; //for synchronous transmission ubrr_value = ( MCU_FREQ / (16*baud_rate) ) -1; //for asynchronous normal (single speed) transmission ubrr_value = ( MCU_FREQ / (8 *baud_rate) ) -1; //for asynchronous double speed transmission ​ now, set the ubrr_value to UBRR Register which is combination of UBRRH (contains 8 MSB) and UBRRL (contains 8 LSB) ​ UBRRH = ubrr_value>>8; // to set 8 MSB UBRRL = ubrr_value; // to set 8 LSB ​ For DOUBLE SPEED transmission, set U2X bit (bit 2) in UCSRA register, which is valid for asynchronous transmission only. ​ UCSRA |= (1<>8; // to set 8 MSB of ubrr_value UBRRL = ubrr_value; // to set 8 LSB of ubrr_value ​ UCSRC | = (1 <

  • DUMMY | SimpleMechatronics| Simple MECHATRONICSsimple mechatronics

    Science STEM Program Register Now FANTASTIC LIGHTS SHOP FANTASTIC LIGHTS SHOP Empower local families Join Our CSA "Testimonials are a great way to showcase positive feedback from others." Timberly Williams Once Small Robot's Base Frame is made, then, various control systems for Small Robot is developed and available below to select. BUDGET Friendly

  • About Me | SimpleMechatronics| Simple MECHATRONICSsimple mechatronics

    About . . . Myself... When I have gone through the internet, I got an idea to develop this blog, which will explain about electronics, mechatronics and simple projects in one place from basics to make-at-home projects in easily understandable way. ​ I tried my level best for easy explanation of the concepts, keeping novice in mind. ​ I am very grateful to all the Author(s) of Simple Mechatronics, who supported me in developing this website / blog. ​ Thanks for your support. ​ -SBM ​

  • Arduino_7SEGMENT | SimpleMechatronics| Simple MECHATRONICSsimple mechatronics

    Introduction to 7Segment Display : The Seven Segment displays are commonly used to display alpha-numerics, which have 7 straight LEDs arranged in 8 format and a dot shaped LED at right bottom corner, packed in a rectangular shape There are two types of 7 segment displays, while considering internal electrical circuit. 1) Common Anode Displays 2) Common Cathode Displays ​ If all the anodes of the 8 LEDs in the package are connected to common wire, which is available as one or two pins externally and all the cathode pins are available individually, externally, then it is called Common Anode (CA) displays . ​ Similarly, if all the cathodes of the 8 LEDs in the package are connected to common wire, which is available as one or two pins externally and all the anode pins are available individually, externally, then it is called Common Cathode (CC) displays . ​ The 7 segments are available in various sizes from 1/4" to 4" or more. The pin diagrams (pinouts) depends on manufacturers and size. Now-a-days, 7 segments displays can emit various colours (using various colour LEDs), like, red, green, blue, white and multi-colour also. The seven segment LEDs are identified as a,b,c,d,e,f,g and the round LED as dp (decimal point). Some vardious sizes of 7 segment displays and a model 7 segment display with segment and pin connections are shown here, for easy understanding. Connecting 7Segment Display to Arduino : To connect a 7 segment display to Arduino, the 8 pins of built-in LEDs (available in rectangular package) have to be connected to 8 pins of Arduino, through series resistances. The common pin(s) have to be connected to either 5V (for Common Anode) or Ground (for Common Cathode) pins. ​ A test circuit diagram of conecting 7 segment display (CA & CC) to Arduino Nano is shown below. Now, open File->New in Arduino IDE, then initially, declare the pin connections of 7 segment display to Arduino pin connections, in proper order, as shown below. ​ // Pin connection sequence a , b , c , d , e , f , g , dp int segPins[] = { 4, 5, A4, A3, A2, 3 ,2, A5 }; ​ Then, set the declared pins as out put using pinMode function in setup function, as shown below. ​ void setup() { // set all 8 pins as output for (int i = 0; i < 8; i++) { pinMode(segPins[i], OUTPUT); } } ​ Then, let the each segment glow, one-after-another in sequence, as a self test. So, in the loop function, start with switching OFF all the segments and dp in a for loop using digitalWrite as LOW . Then, switching ON each segment, one-by-one, in consecutively using digitalWrite as HIGH . A delay function is used to visualize the sequence of glowing each LED easily. ​ void loop() // for CC display { for (int i = 0; i < 8; i++) { digitalWrite(segPins[i], LOW ); // 0 } for (int i = 0; i < 8; i++) { digitalWrite(segPins[i], HIGH ); // 1 delay(1000); } } ​ The above sketch is written for Common Cathode display. For, Common Anode Display, invert the key word LOW with HIGH and vice-versa. In case of Common Anode, the common pin should be connected to 5V pin and incase of Common Cathode, the common pin should be connected to GND pin of Arduino. ​ In place of HIGH, 1 may be used and similarly, in place of LOW, 0 (zero) may be used. The loop function is modified for Common Anode and using 0 and 1 in place of LOW and HIGH keywords below. ​ void loop() // for CA display { for (int i = 0; i < 8; i++) { digitalWrite(segPins[i], 1 ); // HIGH } for (int i = 0; i < 8; i++) { digitalWrite(segPins[i], 0 ); //LOW delay(1000); } } ​ So, you have to invert the LOW to HIGH and vice-versa for CA and CC displays and connect to 5V or GND pins for CA or CC displays. The successive coding (sketch) is written for CC only and follow the same rule for CA displays, which are marked as remarks /* */ in brown colour. Showing Numbers on 7Segment Display : To show Numbers on a 7 segment display using Arduino (or a micro-controller), the segments' ON/OFF control is to be declared initially, in an array, for easy editing and accessing the code to be displayed. Here, integer array is declared, using code 1 for ON and 0 (zero) for OFF state of each segment and dp sequentially, to display number 0 to 9 and dp LED (as 10). Remember to declare the array before setup function, as shown below. ​ // Pin connection sequence a , b , c , d , e , f , g , dp int segPins[] = { 4, 5, A4, A3, A2, 3 ,2, A5 }; int number[11][8] = { { 1, 1, 1, 1, 1, 1, 0, 0 }, // 0 { 0, 1, 1, 0, 0, 0, 0, 0 }, // 1 { 1, 1, 0, 1, 1, 0, 1, 0 }, // 2 { 1, 1, 1, 1, 0, 0, 1, 0 }, // 3 { 0, 1, 1, 0, 0, 1, 1, 0 }, // 4 { 1, 0, 1, 1, 0, 1, 1, 0 }, // 5 { 1, 0, 1, 1, 1, 1, 1, 0 }, // 6 { 1, 1, 1, 0, 0, 0, 0, 0 }, // 7 { 1, 1, 1, 1, 1, 1, 1, 0 }, // 8 { 1, 1, 1, 1, 0, 1, 1, 0 }, // 9 { 0, 0, 0, 0, 0, 0, 0, 1 } // dot or dp }; There is no change in setup function. Now, you have to control the output code at 8 pins of Arduino board. For showing the number as per the code declared in the array, a user defined function, show , is to be added in between setup and loop functions. ​ void show ( int n ) // n is the row number of the array { for (int i = 0; i < 8; i++) // elements (or columns) in each row of array { // write each element to each pin of Arduino as per the value 1 or 0 digitalWrite(segPins[i], number[n][i]); // for CC /* digitalWrite(segPins[i], 1-number[n][i]); // invert for CA */ } } ​ Now, you have to write code to display the numbers (and dp) sequentially in loop function as shown below. ​ void loop() { for (int i = 0; i < 11; i++) // select each row of the array { show ( i ); // show the code written for the row in the array delay(1000); } } ​ The output is shown below: Showing Alphabet on 7Segment Display : 7 segment displays are highly used to display numbers, but, it may be used to show specific Alphabet also, which are easy to read / understand. For showing Alphabet, similar to numbers, a new array declaration is required, using code 1 for ON and 0 (zero) for OFF state of each segment. The array is declared before setup function, as shown below. ​ // Pin connection sequence a , b , c , d , e , f , g , dp int segPins[] = { 4, 5, A4, A3, A2, 3 ,2, A5 }; int alpha[16][8] = { { 1, 1, 1, 0, 1, 1, 1, 0 }, // A { 1, 1, 1, 1, 1, 0, 1, 0 }, // a { 0, 0, 1, 1, 1, 1, 1, 0 }, // b { 1, 0, 0, 1, 1, 1, 0, 0 }, // C { 0, 0, 0, 1, 1, 0, 1, 0 }, // c { 0, 1, 1, 1, 1, 0, 1, 0 }, // d { 1, 0, 0, 1, 1, 1, 1, 0 }, // E { 1, 0, 0, 0, 1, 1, 1, 0 }, // F { 1, 0, 1, 1, 1, 1, 0, 0 }, // G { 0, 1, 1, 0, 1, 1, 1, 0 }, // H { 0, 1, 1, 1, 1, 0, 0, 0 }, // J { 0, 0, 0, 1, 1, 1, 0, 0 }, // L { 1, 1, 0, 0, 1, 1, 1, 0 }, // P { 0, 0, 0, 1, 1, 1, 1, 0 }, // t { 0, 1, 1, 1, 1, 1, 0, 0 }, // U { 0, 1, 1, 1, 0, 1, 1, 0 } // Y }; There is no change in setup and show functions. Now, you have to modify code to display the alphabet ( now the array size is 16 instead of 11 ) sequentially in loop function as shown below. ​ void loop() { for (int i = 0; i < 16; i++) // select each row of the array; 16 rows { show ( i ); // show the code written for the row in the array delay(1000); } } ​ The output is shown below: Playing DICE with 7Segment Display : As an entertainment, you may write a code to display random numbers 1 to 6, like a Dice (which is having 6 faces indicating 1 to 6 with dots on each face). The circuit diagram is shown below for digital dice display. There is no much difference w.r.t. previous circuit, but, a push button switch is added in between pin 7 and pin GND of Arduino Nano board. ​ You may connect the push button switch to any button and declare the same number in the sketch (instead of 7). The complete sketch for DICE is shown below with comments/remarks for easy understanding. ​ // Pin connection sequence a , b , c , d , e , f , g , dp int segPins[] = { 4, 5, A4, A3, A2, 3 ,2, A5 }; #define readPin 7 // declare pin 7 as readPin for input int num = 0; // declare num variable as counter (1 to 6) // declare number array and set the code to be displayed int number[11][8] = { { 1, 1, 1, 1, 1, 1, 0, 0 }, // 0 { 0, 1, 1, 0, 0, 0, 0, 0 }, // 1 { 1, 1, 0, 1, 1, 0, 1, 0 }, // 2 { 1, 1, 1, 1, 0, 0, 1, 0 }, // 3 { 0, 1, 1, 0, 0, 1, 1, 0 }, // 4 { 1, 0, 1, 1, 0, 1, 1, 0 }, // 5 { 1, 0, 1, 1, 1, 1, 1, 0 }, // 6 { 1, 1, 1, 0, 0, 0, 0, 0 }, // 7 { 1, 1, 1, 1, 1, 1, 1, 0 }, // 8 { 1, 1, 1, 1, 0, 1, 1, 0 }, // 9 { 0, 0, 0, 0, 0, 0, 0, 1 } // dot }; //========================== void setup() { // select and set all the pins as output for (int i = 0; i < 8; i++) { pinMode(segPins[i], OUTPUT); } pinMode(readPin, INPUT); // set the readPin i.e., 7 as input to read the digital value digitalWrite(readPin, HIGH); // internal pull-up resistor activated show ( 0 ); // intially show zero } //========================== void show ( int n ) // function to show the required number / dp { for (int i = 0; i < 8; i++) // show the code for each pin (total 8 pins connected) { // output the code to specific pin ( 1 to 8 ) as per the number (CC) digitalWrite(segPins[i], number[n][i]); // use following statement in case of Common Anode Display /* digitalWrite(segPins[i], 1-number[n][i]); // invert for CA */ } } //========================== void loop() { // check and run the code when button is PRESSED if ( digitalRead ( readPin ) == LOW ) { show ( 10 ); // show DOT only when button is PRESSED num++; // increment number when button is PRESSED if (num>6) // reset to 1 if exceeds 6 num = 1; } else // run this code when button is NOT PRESSED show( num ); // show the current number when button is NOT PRESSED } //========================== Good Luck to you.

  • AVR_ADC_DAC | SimpleMechatronics| Simple MECHATRONICSsimple mechatronics

    AVR - ADC (Analog to Digital Conversion) Almost all AVR microcontrollers have ADC (Analog to Digital Conversion) pins, except a few, like ATTINY 2313 / 4313 series. ​ The main concept of ADC is, a stair-case type reference voltage is generated in steps by the micro-controller internally and compares the signal / input voltage with the generated reference voltage. If the input voltage just crosses the reference voltage, then the step number in the stair case is noted and saved in to its related Register (ADC). Our code reads the related Register and process as per our requirement. RESOLUTION AND REFERENCE VOLTAGE SELECTION: So, the Resolution of the ADC value depends on the number of steps generated for a range of voltage. Normally AVR micro-controllers generate 1024 steps (equals to 2 to power 10) from 0VDC to Reference Voltage. So, the data shows 10 bit resolution of ADC. The Reference voltage may be Vcc voltage or separate external input voltage other than Vcc or fixed internal reference voltage ( like 1.2V). The reference voltage input may be selected by setting the required bits in the related register (ADMUX ). ​ Bits 7 & 6 of ADMUX are named as REFS1 and REFS0. The bit setting serves for various input reference voltages in combination as shown below: REFS1=0 and REFS0=0 means external voltage as reference at VREF pin. REFS1=0 and REFS0=1 means Vcc as reference and connect 0.1uF capacitor at VREF pin to ground. REFS1=1 and REFS0=1 means Internal Reference Voltage used as reference and connect 0.1uF capacitor at VREF pin to ground. ​ eg: assume that the reference voltage is set to 5VDC. then, the ADC divides it into 1024 steps, ranging from 0000 to 1023 digital values. so, each step of 5V (= 5000 milli Volts) is equals to 5000/1024 = 4.8828125 mV which is approximately equal to 5 milli Volts. ​ So, the ADC of AVR in this case cannot measure less than 5 milli Volt fraction, in other wards, the ADC value of output available in the Register is approximately multiples of 5 milli Volts (= 0.005V) ​ So, you should not expect less than 5 milli volt accuracy with the above settings. ​ Similarly, you may calculate and set your input. ​ Note/Tip: if the external input reference voltage is 1.023V, then the ADC value is directly proportional to the milli Volt signal input. (1 ADC unit = 1 milli Volt) ACCURACY AND speed of ADC conversion: ​ The accuracy of ADC for AVR micro-controller also depends on the speed of the comparision with the step voltage. You have to sacrifice accuracy to a little extent to get the conversion quickly. The accuracy is sufficiently good upto 200 KHz clock set for the ADC comparision. If the ADC clock speed is set more than 200 KHz, then little accuracy will lost in ADC conversion. The frequency dividing w.r.t. CPU clock is called Prescaling for ADC conversion. ​ ​ In case 8 bit conversion (0 to 255 steps) is suffiecient for your requirement, then the conversion may cross 200 KHz. ​ The clock speed may be set by division factor w.r.t. to the main CPU clock in related Register (ADCSRA ), i.e., ADC Control and Status Register A. The LSB bits of ADCSRA are names as ADPS2, ADPS1, ADPS0 and 16, 4 and 2 are the division factors respectively. The minimum division factor is 2 by default if all set to zeroes. ​ eg: if ADPS2=1, ADPS1=0 and ADPS0=1 means division factor is 16X2 = 32. ​ SELECTING CHANNEL FOR ADC conversion: ​ Normally, AVR micro-controllers have more than one ADC channel connected to specific pins to the exeternal world for ADC conversion. Internally the ADC processor is same for all the channels, but a multiplexer is used to select a specific pin at a time for conversion. ​ The multiplexing Register (ADMUX ) is not only used for selection of the particular pin, but also to select differential input and gain in some micro-controllers by setting the specific bits. The LSBs of the ADMUX are used for directly selecting the channel (or pin). ​ eg: set 000 to LSB of ADMUX , to select channel 0(pin ADC0), 001 for channel 1 (pin ADC1) etc. ​ READING ADC VALUE FROM THE REGISTER: ​ The ADC value, which is the digital value for the analog voltage / signal input is stored in Register (ADC ). The result is also available in ADCL and ADCH registers, which contains 8 LSB of the ADC and 8 MSB of ADC. The value may be directly read from the ADC register by setting / returning to the variable name set by you in the program. ​ eg: a = ADC; or return ADC; b = ADCL; or return ADCL; c = ADCH; or return ADCH; ​ The result of conversion of ADC is 10 bit resolution. i.e. it varies from 0000 to 1023. ​ If required, the result may be converted to 8 bit resolution by setting bit 5 (ADLAR) in ADMUX register as shown below: starting the adc: Before starting the Analog to Digital Conversion, the settings as required, as explained above to be processed in the program. Also, bit 7 ,ADEN (ADC enable), should be set (to 1). ​ Now, to start ADC for every loop, the bit 6 ,ADSC (ADC Start conversion) of ADCSRA should be set to 1. Then the Analog to Digital Conversion will start. On completion of conversion bit 4, ADIF (ADC Interrupt Flag) of ADCSRA will be set (to 1) and also ADSC will be reset (to 0). So, by checking the status of ADIF or ADSC bit in ADCSRA register, you will come to know the conversion status. Example code for adc: ​ //================================================= void initializeAdc ( ) { //SET DIVISION FACTOR FOR F_CPU TO GET ADC CLOCK FREQUENCY ADCSRA |= ( (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0) ); //ADPS2 divides by 16. ADPS1 divides by 4. ADPS0 divides by 2. ​ //SET REFERENCE VOLTAGE SOURCE ADCSRA |= ( (1 << REFS1) | (1 << REFS0) ); //set REFS1,REFS0 = 0,0 for Reference at AREF pin. // 0,1 for AVCC as Reference. 1,1 for Internal Reference Voltage. ​ // ENABLE ADC ADCSRA |= (1 << ADEN); } //================================================= int readAdc ( int channelno ) { // reset previous channel number upto 8 channels, if any. ADMUX &= (0b11111000); ​ // select current Channel number to read ADC. ADMUX = (channelno); // START conversion now. ADCSRA |= (1 << ADSC); // WAIT till conversion is complete while (ADCSRA & (1 << ADSC)); ​ // READ ADC value and return the function. return ADC; } //================================================= Note: ​ This is a general concept of ADC conversion in AVR micro controllers. Some small changes may be observed for each AVR micro-controller, which may be obtained from the data sheet specific to the micro-controller. ​ eg:for ATTINY micro-controllers have only 4 ADC channels and only two options for reference voltage selection. REFS0=0 means Vcc or REFS0=1 means 1.1V internal Voltage Reference. REFS1 is not available. ​ More controls are available while reading ADC of AVR micro controller. The specific ADC usage is available in programs and explained the specific concept and usage in the project. ​ << AVR: TYPES

bottom of page