Print document Implementing a Traffic Light Controller System using Arduino In order to print this document from Scribd, you'll Seyedreza Fattahzadeh first need to download it. Cancel
Download And Print
Print document Implementing a Traffic Light Controller System using Arduino In order to print this document from Scribd, you'll Seyedreza Fattahzadeh first need to download it. Cancel
Download And Print
© 2015 Seyedreza Fattahzadeh Print document
In order
[email protected] print this document from Scribd, you'll first need to download it.
[email protected]
No part of this book may be reproduced, in any form or by any means, without the Cancel Download And Print written permission from the author / publisher.
Print document NOTICE TO THE READER
In order to print this document from Scribd, you'll All rights reserved. No part of this book may be reproduced, in any form or by any first need to download it. means, without permission in writing from the publisher.
Every effort has been made to Cancel ensure our books are accurate as possible. However, However, Download And as Print there may be mistakes, both typo and in content. This content should be used as a general guide and not as the solution. The author does not warrant or guarantee any of the products described herein. Also, the author does not warrant or guarantee any of the equipment or programs described herein or accept liability for any damages resulting from their use. The reader is warned that both electricity and the construction of electrical equipment can be dangerous. It is the responsibility of the reader to use common sense and safe electrical and mechanical practices. Arduino ® is a registered trademark of Arduino. CodevisionAVR ® is a registered trademark of HP Info Teach Proteus ® is a registered trademark of Lab center Electronics Company. Company. Altium Designer ® is a registered trademark of Altiume Company. Company. AVR and Atmega32 are trademarks Atmel Company. Please be informed that: This book contains many images. Since eReaders don’t always display images well, upon request, I will provide you with the PDF file which contains the complete e-Book, including the images, if you need an easier-to-read format. To To receive a PDF version of this e-book or any other software which is mentioned in the content of this text, you can email me the proof of your purchase of the kindle version of the book from Amazon.com to
[email protected] [email protected].. Upon receipt of that proof, a PDF version will be sent to t o your email address.
Table of Contents Preface About the author
Print document
In order to print this document from Scribd, you'll first need to download it.
How to use this book
Cancel
Download And Print
Objective and scope of the project Files developed for this project Chapter Ch apter 1 Step Ste p 1: Project performance specification Generating schematic diagram of the project Step Ste p 2: Program explanation Generating the main control code Step Ste p 3: Getting Getting to manufacturing the PCBs of the prototype model An overview of circuits Step 4: Designing electronic circuitry Step Ste p 5: Uploading the control program into the ATm ATmega16 ega16 microcontroller (hex file) Chapter Ch apter 2 Step Ste p 1: Generating schematic diagram diagram of the project Step Ste p 2: Generating the main contr control ol code for the Arduino Microcontroller Step 3: Getting to manufacturing the PCBs of the prototype model Functional Fun ctional explanation of PCBs PCBs related to intersections Functional Fun ctional explanation explanation of PCBs related to main controller board Step Ste p 4: Building Building the PCBs of the t he prototype Traffic Light system Step 5: Uploading the control program into the Arduino board Conclusion My e-book product list
Preface
Print document
In this project, we will learn design forfrom a traffic light control. This text consists In ordercircuit to print this document Scribd, you'll first need to download it. of two Chapters. Chapter 1 is devoted to the design and implementation of a Traffic light Control Cancel And Print system using an AVR Microcontroller (e.g. Download Atmega8). You can use the following link to see its performance: http://www.youtube.com/watch?v=q0eWsX2kMeU Chapter 2 is devoted to redesigning the same Traffic light system using the Arduino Mega 2560 board, which is a microcontroller board, based on the ATmega2560. You can use the following link to see the performance of this project with Arduino board. http://www.youtube.com/watch?v=f-ZbP8juB20 This project is about a model of simple Traffic light, located at a four-way junction. Text provides a reader with steps he/she needs to take to come up with a hardware and software to implement the traffic light system. The reason I selected to author this text is that I already have written a text about design and implementation of Traffic light controls using a PLC. I thought it was not a bad idea this time to show how the same design guides can be used to implement the same system, but this time with a Microcontroller. I love Traffic light systems, as they do a great job wherever they are installed. When a programmer can generate control software for a simple Traffic light system, that will mean that he knows 'what he is talking about' when it comes to programming for any kind of CPU. The final aspect of this experiment was to organize the main control code in C language to control the whole system hardware intelligently. Hence the purpose behind developing a manual like this is an attempt to make learning microcontroller\or a typical a Microcontroller based board more enjoyable!
About the Author
Print document
Seyedreza Fattahzadeh holds Bachelor of Science Electrical Engineering from In order toaprint this document from Scribd,in you'll first need to download it. expertise is in digital systems, electronics, the University of Texas at Arlington. His main and computer engineering. Cancel Download And Print Seyedreza has extensive experience in the field of programmable controllers. He worked for a few industrial manufacturers as a programmable controller consulting firm. His industrial experience includes designing and implementing mid - class automation systems, based upon PLC.
Seyedreza has authored several other books about programmable controllers. You can find more info on these at the end of this book.
How to use this Book Print document
This book details the generating code an ATmega8 Microcontroller chip and The In order to print thisfor document from Scribd, you'll first need to download it. light system in general. This book has been Arduino Mega 2560 board to control a Traffic prepared for those who are already familiar with basic instructions related to any brand of Microcontroller and may have already some based programs Cancel developed Download And Microcontroller Print for different purposes. Therefore, this text is prepared for those who want to challenge their programming knowledge to generate even more complex programs with extra features. The project specification will be presented to you. It contains all goals, functionality, and details required for a development of this controller system to fulfill the project's typical minimum requirements. Study the project requirements presented in t his text carefully. Your job is to generate the main control program to satisfy the project's requirements. Take as much time as you think it is needed. You can use a pen and paper and any typical simulator software to develop the control program. When you have completed your project, review and compare it with the one presented in this text. If your solution is working properly, then you can celebrate your accomplishment and perhaps go on to learn something new to further improve your level of capability when it comes to Microcontroller programming. If the solution you came up with has some problem(s), and somehow it is not functioning as it is supposed to, then you can compare your solution against mine. In this case, you know that you did your best, and tried it on your own and then you can use my solution to find out what is wrong with yours. When you find it out what went wrong, then you can resolve the issue to make it function correctly. That is the whole purpose of this text; to give you enough motivation and make you enthusiastic to complete a relatively complex Microcontroller based program. In Chapter 1, the main control program solution is prepared in C language using CodevisionAVR ® software. In addition, the schematic of all the hardware used in project is provided. In Chapter 2, the same main control program which was prepared for the AVR Microcontroller is redone for an Arduino based platform. The amount of effort you want to place in implementing this project is completely up to you and your interest. If you wish, you can build your own controller hardware similar to the one presented in this text, or even tailor it to the one with more features as you prefer. In either case, even by just simulating the presented program and checking its performance, you can improve your programming knowledge and ultimately, from my side, this is the overall purpose behind developing the text.
Objective and scope ofPrint thedocument project
In this project, a Traffic In light going be produced by using an ordercontrol to print thissystem documentis from Scribd,to you'll first an needArduino to downloadMega it. ATmega8 Microcontroller and 2560 board. Thus, the main objectives for this project is to design and construct a Microcontroller based Traffic light control system. Cancel Download And Print The hardware part for this project is a model of four-way junction traffic light. The Control program is developed for a main street (S/N) with four intersections (4 E/W streets) to control their traffic lights. On locations where each secondary East-West roads intersects the main one, I have two traffic light boxes each with 3 light indicators and a 1×2 digits countdown meter. Thus, the purpose of the project is to control all these timers and traffic lights all in harmony. The purpose of using a countdown meter is to remind drivers and pedestrians of the waiting time through counting down numbers to effectively reduce the rate of traffic accidents. In this book, has been prepared for those who are familiar with programming a typical Microcontroller and who want to challenge their knowledge by writing a more complex control program. By reading this book, you will be able to better understand how to prepare a control program for a traffic light system. The schematics diagrams of all other hardware used in this project are given for this model. If you wish, you can build your own traffic light simulator similar to mine, or even tailor it to the one with more features you like. Programming of Microcontrollers is simple to learn. It is not much complicated and we can use simulators on computers to see the practical results of our program. We can work on an embedded project without even buying the required components. Thus, we can virtually see the working of our project or program.
Print document Files developed for this project:
The table below specifies the files project, explained in this text. In order to printdeveloped this documentfor from this Scribd, you'll need text. to download it. these files emailed to your address, please These files are not included first in the To get contact me as you are directed in the 'Please be informed' section of this text. Cancel
Download And Print
Files related to Chapter 1
Simulation Proteus based file: ms.DSN
CodevisionAVR based generated file: slrtc.prj
Sheet1.pcb to sheet7.Pcb (PCB layout files)
Files related to Chapter 2
Traffic_light.ino (Main controller file)
A_traffic light.PrjPCB (PCB layout files)
Print document Chapter 1
In order to print this document from Scribd, you'll first need to download it.
Step 1: Project performance specification
In this project, we are going to develop traffic light control system. It is Cancel a practical Download And Print primarily designed to be used as a training project to teach students how to write a complex control program through using a network consisting of many timers, basic digital devices, etc. We consider the following features for this project (look at Figure 1-1). 1. It has eight (two digits for each one) LED countdown timers to remind drivers and pedestrians of the waiting time through counting down numbers to effectively reduce the rate of traffic accidents. 2. It has one (two digits) LED numerical display to display the calculated speed of the car passing between two IR sensors, installed at the distance of 100 meters (the distance is defined in the control program). Based on the time it takes for a car to pass these two IR sensors, Microcontroller calculates the speed of the car and displays it on the 9th two digit numerical display in Km/h. Red LED is turned on, i f speed is >=30 Km/h, and the green LED is turned on if speed is < 30 Km/h. 3. It has one (six digits) LED numerical display to show the current time and date. 4. It has one main control PCB to feed data to numerical displays, and indicators (red, yellow and green LEDs), transfer depression of pushbuttons, and IR sensors to Microcontroller via its Input or Output terminals.
Figure 1-1: An overview of the project
Print document Generating schematic diagram of the project
After determining what the project to do, the next step is to come up with In order to print needs this document from Scribd, you'll first needAfter to download Schematic diagram of the project. all, it.this is the hardware and software parts of the project, supposed to function in a way to carry out the main task of the project. Download And Print Let's draw schematic diagram Cancel of the project in a way that we think it can carry out the task of controlling all push buttons, 7-segment displays, bunch of LEDs, etc.
We might be able to come up with a circuit diagram as shown in Figure 1-2 and try to figure out if that is capable of controlling different electronics of our project nicely. There isn’t any problem to test the circuit and code at this stage. Our big brothers already have developed two great software - CodevisionAVR ® and Proteus ® - that can help us to generate code and simulate the circuit respectively. Therefore, at step 3, we may go ahead and start generating code after putting all components on the edit screen of the great Proteus software.
Figure 1-2: displays Proteus generated schematic diagram of the project
Print document Step 2: Program explanation
In orderup to print thisthe document from Scribd, you'll of my project, I do need Now that I managed to come with schematic diagram need to download it. to generate the control code first to simulate the circuit shown in Figure 1-2 to ensure the components shown in Figure 1-2 function properly. I go ahead and use my Cancelthe main Download CodevisionAVR software to generate codeAnd andPrint save it in a Hex format. In the next step, I will need to go back to Proteus and call the Hex file, which I already have created, and start simulating the schematic diagram that is shown in Figure 1-2.
In this chapter, we are going to develop the main control program in C language with CodevistionAVR for a ATmega8 microcontroller, which when executed, will get all display PCBs activated with all input devices such as pushbuttons and IR sensors being connected to the related input terminals, cause Microcontroller to receive and execute the input signals.
Print document How the program is supposed to function?
We wish to have a control program, that whenfrom RUN, commands are issued to the In order to print this document Scribd, you'll first need to functions, download it. as detailed below: microcontroller. Its output performs We would like all stoplights at each intersection to turn on and off based on the data And Print times are Download shown on table in Figure 1-3. All Cancel in seconds, and Figure 1-4 displays the location of each stop light and the LED countdown timers.
Figure 1-3: Traffic lights Timing
Figure 1-4 From Figure 1-4, notice that it takes about 145 seconds for the signal lights to complete one cycle at the (S/N) first intersection. After G1 turns on, and the counter starts counting down from 80 to 0 seconds, the yellow traffic light = 5, and finally, the red signal light turns on for 60 seconds. Cycle time = 145 seconds. Driving within the speed limit (30km/h), it takes 600 seconds to get to the next intersection traffic lights. We have 10 min. × 60 = 600 seconds. Since the cycle time of the second traffic light is 115 seconds, and we want the same car gets to the second traffic lights to receive a green signal light, then 25 seconds after G1 turns on, we want G3 to be turned on. Therefore, we can write 600 = (5 × 115 + 25 = 575 + 25). The third traffic lights (G5) have a cycle time of 145 seconds and it takes 30 minutes × 60 = 1800 seconds = (12 ×145 + 60 = 1740 + 60) to get to the third signal light (from the second traffic lights). And we want the same car to get a green traffic light when it reaches the third one. Then, 60 seconds after G3 is on, G5 can be turned on. So far, we have 3 green signal lights turned on. Cycle time of G7 is 140 seconds, but it takes 40 minutes × 60 = 2400 seconds for the car to get from G5 to G7. The cycle time of G7 = 140 seconds. So we have 2400 =
40 minutes × 60 = 2400 seconds (17 ×140 +20 = 2380 + 20) which means 20 seconds Print =document after G5 turns on, G7 must also be turned on. In order to print this document from Scribd, you'll lights alternating the right of way granted first need to download it.
Now we have 8 traffic displaying lights of standard colors (red, yellow, and green).
to road users by
Cancel phase Download Print (when system is turned on for Figure 1-5 displays the initialization of theAnd system the first time) too. It must be understood that, all E/W street traffic lights must be turned on after related S/N green light is turned on. Also Figure 1-4 shows what is the approximate distance between each intersection stop light. From Figure 1-4, notice that the distance between first and second intersections is about 5 Km. Therefore, if the speed limit on that road is about 30 km/h, then the speed equation is 5 km = 30 km/h × h or h = 1/6 × 60 = 10 minutes.
The next flowchart describes the sequencer of turning lights in normal state.
Figure 1-5: A flowchart of timing lights. The system takes the current time and date from RTC's internal clock, and shows it on a 6 digit seven segment numerical display (Figure 1-6). When the system is displaying the current time, 4 LEDs blink and 2 LEDs blink when it is displaying the current date. Figure 1-6 determines the position of two optocoupler sensors. The distance between these sensors is 100 meters and when a car passed between them, according to its elapsed time and distance (=100 m), the car speed is computed by microcontroller and displayed by two seven segments. Then if the car speed is >=30, the red and if it is <30km/h, the
UU is displayed on two green LED are turned on. If Print the car speed is greater than 99, then document 7segments. In order to print this document from Scribd, you'll Emergency pushbutton, first need to download it. we can force the
By depressing the system into Emergency mode. In Emergency mode, number 00 will be shown on all LED displays. Cancel
Figure 1-6
Download And Print
Print document Generating the main Control Code
Now we’re going to explainInthe main parts of written program. order to print this document from Scribd, you'll First-time-initi() function
first need to download it.
There is a predefined state for Cancel all LEDsDownload and 7segments. And PrintNaturally, one of its applications is at the starting time. Therefore, the system starts its work from these defined states. Notice that s1 to s8 variables hold the times values that are displayed on eight pairs of LED numerical (Figure 1-6). In addition, the led Matrix (24×1) indicates the state of each light on each intersection. The digit matrix (16×1) is used to display each digit of timer value. For example if s1=20 then digit[0]=0 and digit[1]=2.
Figure 1-7 The following cod defines the initial state void first_time_init () { led[0]=0;
//red 1
led[1]=0;
//yellow 1
led[2]=1;
//green 1
led[3]=0;
//green 2
led[4]=0;
//yellow 2
led[5]=1;
//red 2
s1=80; s2=85; digit[0]=s1%10; digit[1]=s1/10; digit[2]=s2%10; digit[3]=s2/10; ↓ //other
variables led[6] to led[23],…
perm2=0; perm3=0; perm4=0; first_time=0; first1=1; first2=1;
first3=1; count2=0; TCCR0=0x03;
Print document
In order to print this document from Scribd, you'll first need to download it.
display(); display_led();
Cancel
Download And Print
}
The first-time_init function uses display and display_led functions to update the state of lights and 7segments. Display and display_led function(s) We use these functions when the states of outputs such as Lights are changed. The number of needed outputs in this project is more than the microcontroller pins. Therefore, in the main controller board, we use some 74HC595 shift register that is connected to the microcontroller. Now by using three pins of the microcontroller (DS, SH_CP and ST_CP in the program), we can control many outputs serially. For example, the code program of display_led function is given here. The first loop sends the state of traffic light on ds_led output pin and then shifts it to send the state of another light. The second loop does the same work for two LEDs about speed of cars. Third loop shifts all data 6 times, thus each output will go to i ts correct position on shift register outputs. Then st_cp_led pin updates the state of all LEDs or lights. void display_led() { for(i=0;i<24;i++) { //m=n&led[i]; ds_led=led[i]; sh_cp_led=0; sh_cp_led=1; } for(i=0;i<2;i++) { ds_led=distance_led[i]; sh_cp_led=0; sh_cp_led=1; } for(i=0;i<6;i++) { sh_cp_led=0; sh_cp_led=1; }
st_cp_led=0; st_cp_led=1;
Print document
In order to print this document from Scribd, you'll first need to download it.
}
The first loop sends the state of traffic light on ds_led output pin and then shifts it to send the state of another light. The second loop does a same work for two led about speed Cancel Download Print cars. Third loop shift all data 6 times thus each output will And go to its correct position on shift register outputs. Then st_cp_led pin updates the state of all LEDs or lights. Read time from RTC Another important part in the program is tracking time. RTC (Real time second) is an exact clock that is designed using DS1307, and is connected to the microcontroller with I2C protocol. To use it: 1. Open the CodeWizardAVR dialog box in CodevisionAVR software 2. Click I2C tab. 3. Select a port from I2C Port menu. 4. Select two pins for time and date from SDA Bi and SCL Bi menu. 5. Click DS1307. 6. Click Enabled (
Enabled change to
Enabled )
Now in the program, the following command can be used to update the time in the system. The data type of hour, min and sec variables is unsigned char type. rtc_get_time(&hour,&min,&sec); The microcontroller reads the time with above command and then compares it with the previous time. If there is a difference between two times (old and new seconds), it means one second is elapsed and the program tracks the flowchart on.
Print document
In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
Figure 1-8 The program for the first Intersection in this function is given here if((second_new!=second_old)&&(start==1)) { second_old=second_new; ///////////////////// first intersection /////////////////////////// s1—; s2—; if((s1<2)&&(a==0)) /// or E/W ///
a variable
{ s1=1; led[0]=0;
//red 1
led[1]=1;
//yellow 1
led[2]=0;
//green 1
} if((s2<1)&&(a==0)) {
is determine which street is open :N/S
Print document
s1=60; s2=55;
In order to print this document from Scribd, you'll first need to download it.
a=1; led[0]=1;
//red 1
led[1]=0;
//yellow 1Cancel
led[2]=0;
//green 1
led[3]=1;
//green 2
led[4]=0;
//yellow 2
led[5]=0;
//red 2
} if((s2<2)&&(a==1)) { s2=1; led[3]=0;
//green 2
led[4]=1;
//yellow 2
led[5]=0;
//red 2
} if((s1<1)&&(a==1)) { s1=80; s2=85; a=0; led[0]=0;
//red 1
led[1]=0;
//yellow 1
led[2]=1;
//green 1
led[3]=0;
//green 2
led[4]=0;
//yellow 2
led[5]=1;
//red 2
} if(perm2==0) { s3=60; s4=65; } ↓//other perm condition digit[0]=s1%10; digit[1]=s1/10; digit[2]=s2%10; digit[3]=s2/10;
Download And Print
↓//other digit display(); display_led(); }
Display time
Print document
In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
In the beginningof program, 6 functions are written to display time (hour: minute: second) and (year. month. day). When the program wants to change and update the time and date, it uses them. For example look at show_sec function code for displaying second. void show_sec() { if(set==0) { clock[0]=sec%10; clock[1]=sec/10; } for(i=0;i<2;i++) { for(j=0;j<4;j++) { m=n&clock[i]; ds=m; sh_cp=0; sh_cp=1; n=n<<1; } n=0x01; } //PORTB=0x0d; address1=1; address2=0; address3=1; address4=1; st_cp=0; st_cp=1; out_en=0; delay_ms(1); out_en=1; }
Modify Time
Print document
order to print this document from Scribd, you'll Two keys are consideredInto modify time and date. By the first key, we can select which first need to download it. parameter we like to modify (second, minute, hour, day, month or year). By the second key, we can increase the selected parameter and when i t reaches its upper limit, it starts Cancel Download And Print again from zero (for example for second: …,58,59,0,1,2,… ).
When the first key (PIND.0) is depressed the following flowchart is tracked.
Notice that when a key is depressed, because of the high speed of microcontroller processing, it may receive several commands from one key in one depressing. To prevent this state, a timer is turned on by the first depressing command not to receive other commands from that key for a certain time. After 6 depressions the time settings are sent to RTC, and the system displays the time. The program tracks the following flowchart when the second key (PIND.1) is depressed:
Print document
In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
Compute car speed and display it Two sensors are installed on N/S Street (Figure 1-9). These sensors are connected to external interrupt pin0, 1 of the microcontroller
Figure 1-9 The first sensor is connected to external Interrupt 0. In this interrupt, if the Timer0 is on, it is turned off, given an initial value to related speed variable, and then turns the Timer0 on. interrupt [EXT_INT0] void ext_int0_isr(void) { if((key==0)&&(first_time==1)) { TCCR0=0x00; count=0; speed_time=0; TCNT0=0x05; TCCR0=0x03; time=0; distance=0;
distance_led[0]=0; distance_led[1]=0; display_led();
Print document
In order to print this document from Scribd, you'll first need to download it.
key=1; TCCR2=0x04;
Cancel
Download And Print
} }
When the car reaches to the second sensor, the external Interrupt of pin1 is activated. In this interrupt, if the timer0 is has been turn on, the program turns it off and computes the car speed. If the speed is less than 30km/h the green LED is turned on and the speed is shown. If the speed is greater than or equal to 30km/h, the red LED is turned on. Finally, the program executes show_distance function to display the speed on speed displaying screen. interrupt [EXT_INT1] void ext_int1_isr(void) { // Place your code here if((key==0)&&(first_time==1)) { if(TCCR0!=0x00) { TCCR0=0x00; time=(count*2)/100; distance=3600/time; count=0; speed_time=0; TCNT0=0x05; if(distance<=30) { distance_led[0]=0; distance_led[1]=1; display_led(); show_distance(); } if(distance>30) { distance_led[0]=1; distance_led[1]=0; display_led(); show_distance(); }
} key=1; TCCR2=0x04;
Print document
In order to print this document from Scribd, you'll first need to download it.
} }
Cancel
Download And Print
Show_distance function In the considered hardware, two digits seven segment are used to show speed. So if the speed is more than 99, the UU sign is displayed and if it’s less than 100, it will be displayed. The logic of this function is like display_second function that was explained before. Emergency states When the streets are deserted, for N/S street we want only yellow light blink and for W/E streets the red LEDs. To do it, a pushbutton is considered that is connected to PINC.3. If it is depressed one time, the emergency state is activated and if it is depressed again, the emergency state is turned off. In this part, the all 7segments and LEDs are turned off and the Timer1 is turned on. For again depressing, the Timer1 is turned off and system comes back to its normal state. In emergency state the Timer1 makes the LED blinking at the rate of 0.4s per cycle (next code program)
Print documentthe PCBs of the prototype model lift Step 3: Getting to manufacturing
system
In order to print this document from Scribd, you'll first need to download it.
It was very encouraging to see that simulation was carried out successfully and now we wish to get the PCBs built and test the traffic light system functionality manually in the Cancel Download And Print first place. This might be also related to a project that we are working on it as a collage final year project and our instructors have advised us the course grade will not be give in full unless we show them the whole hardware of the system working properly! No sweat again. Some other big brothers already have developed great software that their application allows us to design and generate the PCB layout of our circuits. Altium Designer ®, which is a registered trademark of Altiume Company is a sample of that software that can be used to create PCBs of any complexity. According to the Figure 1-10, it seems that I am going to need eight PCBs to simulate traffic lights that need to be installed at each intersection, one is for displaying car speed, and another circuit is related to display time and date. The main PCB is the controller section of the project that consists of needed keys, microcontroller, etc.
Figure 1-10: an overview of all needed PCBs Another important tip is here that actually this project has been implemented earlier with PLC. An important deference between AVR microcontroller and PLC is their working voltages. PLC works with 24v but AVR microcontroller work with 5vdc. So every time that I want to use a signal for microcontroller, maybe it needs a circuit (Figure 1-11) to decrease the voltage level.
Print document In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
Figure 1-11: A simple circuit to decrease voltage level
An overview of circuitsPrint document
We need eight PCBs to display timefrom and light states for four intersections In order to remaining print this document Scribd, you'll first need to download it. see Figure 1-10. Cancel
Download And Print
Figure 1-12: A sample of a traffic light PCB for each intersection In the above figure, three LEDs (red, yellow and green) are used to simulate traffic lights and two 7segments are used to display the remaining time. This board just receives command from microcontroller at its input pins. The U1 and U2 in Figure 1-12 shows the same IC (SN74LS47N) to transfer the received BCD code to a suitable code for two 7segments and U3 is a flip-flop (74HC2773AP) to hold the last received data from the microcontroller. Figure 1-13 shows the same circuit with more details.
Print document
In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
Figure 1-13: Displays wiring diagram of each 2 seven segment display board plus 3 LED indicators as traffic signal lights (red, yellow, and green). We need another two circuits to display speed and date-time. The logics of these PCBs (Figure 1-14 and Figure 1-15) are similar to that of the previous PCB (Figure 1-13).
Figure 1-14: Displays speed screen
Print document
In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
Figure 1-15: A circuit to display time and date Another PCB that we need is a PCB for the main controller board. Figure 1-16 shows the important section of this board.
Figure 1-16: A diagram of the main controller board According to Figure 1-16, this board receives data from system and decreases its voltage to +5vdc for microcontroller, if it’s needed. Microcontroller gives this data and tracks time from RTC and the state of pushbuttons. Then with some shift register and decoder (to control a more number of outputs with less number of pins) sends necessary commands to other PCBs.
layout Step 4: Designing the PCB Print document
After designing and simulating thetowhole system with and CodevisionAVR In order print this document fromProteus Scribd, you'll software, I start designing the PCB layout with Altium designer software. first need to download it. Cancel
Download And Print
Speedometer electronic circuitry Print document
Figure 1-17 displays the schematic circuitry of the IR sensor (Break-Beam Sensor). In order to print this document from Scribd, you'll Notice that when circuit in Figure 1-17 is energized, the NO terminal of the circuit is first need to download it. raised to 24 VDC. And when the IR ray is broken by the presence of a car crossing S1 or S2 (Figure 1-9), the relay is activated (NC = 1) and that is the time when the Download AndFigure Print 1-18 displays the microcontroller is notified that a car isCancel crossing either sensor. physical view of the IR sensor. Electronic components shown in Figure 1-17 are soldered to a printed circuit board to create the IR sensor PCB shown in Figure 1-18.
Figure 1-17: Circuit diagram of IR sensor
Figure 1-18: IR PCB sensor
Print document In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
Figure 1-19: The PCB to simulate traffic lights
Figure 1-19 note
1
Three LEDs
2
Two 7segments
3
14×330Ω Resistors
4
Two SN74LS47N
5
One SN74HC273N Flip-flop
6
2×14 female pin
7
One 10kΩ Resistor
Print document
In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
Figure 1-20: The PCB to display Speed that is similar to Figure 1-19
Figure 1-21: A circuit to display time and date
Figure 1-21 note
1
2
Six Seven segments Print document Four Red LEDs
In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
3
42×330Ω resistors + 2 another 330Ω on the Circuit
4
Six SN74LS47N IC
5
Three SN74HC273N flip flop
6
2×14 female pin
Figure 1-22: Main Controller boar with AVR
Figure 1-22 Note
1
17 female pins for input data and power supply
2
Print document Five 2×15 male pin to send command to other PCBs In order to print this document from Scribd, you'll first need to download it.
3
Two M74HC138B1 Decoder Cancel
Download And Print
4
Four 74HC595N shift register
5
A jumper
6
AGY 2324 Relay
7
SN74HC595N Flip-flop
8
Five small pushbuttons
9
ATMega8 AVR microcontroller
10
0.1 uf (104) Ceramic Disk Capacitor
11
DS1307 is a Serial Real-Time Clock(RTC)
12
Lithium Battery
13
Some Zener diode and resistors in the circuit
document control program into the ATmega16 Step 5: Uploading thePrint
microcontroller (hex file) In order to print this document from Scribd, you'll first need to download it.
Now that all needed PCBs are designed in Step4, last step before powering up the system is to 1- assemble the PCBs 2- burn the code developed at step 1 into AVR ATmega Cancel Download And Print 8 controller user memory. I used my little mega16 programmer to upload the hex file developed in step 2 and completed project final step.
Figure 1-23: Displays programmer used to program Atmega16 micro controller
Print document Chapter 2
In order to print this document from Scribd, you'll first need to download it.
Step 1: Generating schematic diagram of the project The Arduino board has a nearly limitless array ofAnd innovative applications for Cancel Download Print everything from robotics and lighting to games etc. It's a fun way to automate everything, enabling you to control simple devices or manage complex other projects. In this text, I selected an Arduino to control a Traffic light System and I think if you manage to do the same project using the Arduino Development Board, you can learn how to educate and inspire yourself to make great things with easily-available tools. To view this project using an Arduino board in action, click on the following link: http://youtu.be/WU2arv-yghw
Figure 2-1: Displays the Arduino MEGA 2560 Development Board In this project, to have a simpler circuit, we reuse some parts in previous project on the main controller board. Therefore, instead of using two sensors and their PCBs we use two pushbuttons on the main controller board. Also the main controller board uses LCD to display speed, time and date and now we don’t need to build another PCB for showing these parameters. In addition, the main controller does not have separate connections to other PCBs. It makes connection to all PCBs with a serial data transformation. So, now the main controller board can control whatever intersection we want, just by changing the program but not the hardware. All other conditions and tasks of both of these projects are similar. The same schematic diagram (less few components) that was designed for AVR Microcontroller will be used in this section of the project. Notice that in Figure 2-2, ATmega8 Microcontroller is replaced with the Arduino Development Board.
Print document
In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
Figure 2-2: The wiring diagram of the project based on an Arduino board
Print document main Control Code for the Arduino Step 2: Generating the
Microcontroller
In order to print this document from Scribd, you'll first need to download it.
Now we’re going to explain each part of the control code adapted for the Arduino Board based on the logic that is developed already for AVR program presented in chapter Cancel And Print 1 except for a few differences between theseDownload two codes. At first, we define needed libraries and symbols. To use the RTC in the program, we need to insert two libraries to the program. The wire library is used to make a connection with RTC with i2c protocol and DS1307RTC library is used to control RTC. At first, the program goes into setup function for one time. In this function, we configure The LCD and RTC. Then the program goes into Loop function and recalls some prewritten functions that are needed. First _time_init function There is a predefined state for LEDs and 7segments. Therefore, the system starts its work from these defined states. Timing function In this function, various times are generated with millis() instruction. In this function, each written condition is about a timing that is used in the program. The first condition is run for each 500ms and if the emergency variable equals 1 (the system is in emergency mode) then the related yellow and red lights start to blink. The second one is for generating an interrupt after depressing a key to prevent receiving several commands for each depressing key. The next three conditions are to make delays in starting lights for second to 4th intersection until all the lights are synchronized together. Therefore, if a car has a 30k/h speed then it can pass all intersections without any stopping. In the last condition, the program shows computed speed on LCD for 5 seconds. Show_lcd function This function displays the needed message on LCD. There are three states according the content of show_speed variable if the program isn’t in the modifying time mode (select=0) 1. Show_speed=0, in this state, the time and date are shown on LCD. First line is for writing time and second line is for date. 2. Show_speed=1, in this case the time is written on first line too but the second line shows the time for car speed calculation. 3. Show_speed=2, in this state, the car speed is written on the first line of the LCD and on the second line shows over limit or under limit according to whether the speeds are greater or lower than 30k/h speed. Write_output function
This function updates allPrint 7segments and LEDs. Notice that s1 to s8 variables hold the document times value that are displayed at intersections. Also the led Matrix (24×1) determines the In order to print this document from Scribd, you'll state of each light on 4 intersections. The digit matrix (16×1) is used for each digit of time first need to download it. value. For example if s1=20 then digit[0]=0 and digit[1]=2. The good tip is here that the Arduino board has a useful instruction (shiftout) to work with 74hc595 shift register. Stoplight function
Cancel
Download And Print
This is the most important function. Its task is to control all time and lights at each intersection. At first, the microcontroller reads the time with above command and then compares it with the previous time. If there is a difference between the two times (old and new seconds), it means one second of time elapses and the program tracks the following flowchart shown in the following Figure 2-3. Speed_begin function This function works with external Interrupt1. When the first sensor that is connected to this interrupt, gives a pulse to microcontroller, this function is run once. In this function, the related variables for the speed are changed to zero and it stores current time on related variable. Also it sends out a command for the LCD to display a timer time for the passed car.
Figure 2-3 Speed_end function
The second sensor activates function. This sensor is connected to external Printthis document Interrupt0. This pin receives a pulse, if the first pulse is activated before, then the order to print this document from Scribd, you'll microcontroller performs theIn following tasks. first need to download it.
The car speed is computed according to time and distance (it’s constant and equals 100 meters). The needed commands are sent to LCD to display Cancel Download And Printthe car speed. Then after 5 seconds, LCD should display the time and date again. Set_pb function Three keys are considered to modify time and date. The set_pb function is for the first key. By the first key, we can select which parameter we like to modify (second, minute, hour, day, month or year) according to the number of times the key is depressed. By two other keys, we can modify the selected parameter. Up_key and Down_key function These two functions are similar. For example Up_key function is related to external Interrupt4. Every time the up key is depressed, the selected parameter (according first key and set_key function) is increased by one unit. When it reaches its upper limit, then the related variable starts from zero. Emergency_pb function By depressing em key, this function is activated and all 7segments and LEDs are turned off. Then shows a line instead of number on 7segments. Also the red LEDs on W/E streets and yellow light on S/N streets start to blink. If this key is depressed again, System exits from emergency mode and comes back to its normal condition. Auto_em function The system should be in emergency state between 24 to 7:00 a.m. So this function compares the current time with these times, and at 24 o’clock activates the emergency mode and at 7 am deactivates it.
Print document the PCBs of the prototype model lift Step 3: Getting to manufacture
system
In order to print this document from Scribd, you'll first need to download it.
It was very encouraging to see that simulation was carried out successfully and now we wish to get the PCBs built and test the Traffic light system functionality manually in Cancel Download And Print the first place. No sweat again. Altium Designer ® which is a registered trademark of Altiume Company is a sample of that software that can be used to create PCBs of any complexity. Figure 2-4 displays an overview of the whole system. It seems that I am going to need Two PCBs to simulate Traffic lights (respectively for N/S and E/W streets) that are needed to be installed at four intersections. So they need eight PCBs. And another PCB related to main controller section.
Figure 2-4: An overview of whole system
document Functional explanationPrint of PCB related to intersections
Each of these four PCBs is supposed tothis bedocument installed inScribd, eachyou'll intersection. Figure 2-5 In order to print from need to download it. displays more details of the first components installed on these PCBs. Cancel
Download And Print
Figure 2-5 According to the above figure, the PCB circuit for E/W Street and N/S are similar. Both of them have three LEDs (red, yellow, green) and two seven segments to display reminded time. These PCBs do not send any command and just receive commend from the main controller board, use them and send them serially to another PCB. So I can consider easily more intersections in the project, depending on how many I want. We use 74HC595 Shift register to send data serially in these boards.
document Functional explanationPrint of PCB related to Main controller board
As given in Figure 2-4, the main controller board receives In order to print this document from Scribd, you'll signals, tracks time from first need to download it. RTC and sends necessary commands. But, here the number of output pins is decreased because we use just one port to control all other PCBs. Therefore, the number of used ICs is decreased too (compare Figure 2-9 with Figure 1-22. Cancel Download And Print
Print document of the prototype Traffic light system Step 4: Building the PCBs In orderItohope print this document from Scribd, I am glad to see you in this step. you can design andyou'll build a similar PCB with first need to download it. Altium designer. Following figures show all the designed PCBs in this project: Cancel
Figure 2-6: Traffic lights for E/W streets
Figure 2-6 note
1
Three LED (Red, Yellow, Green)
2
Two 7 segments
3
3×1kΩ Resistors
4
16×330Ω Resistors
Download And Print
5
6
Three Shift registers (74HC595) Print document In order to print this document from Scribd, you'll first need to download it.
2×5 male pin for receiving data
Cancel
7
Download And Print
25 ×male pin for sending data
The designed board for N/S street is similar the E/W PCB (see Figure 2-6)
Figure 2-7: Traffic light for N/S Street Figure 2-7 is related to LCD shell which is going to be installed on the top of the Arduino board.
Print document
In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
Figure 2-8: The LCD shell which is installed on the top of the Main Controller PCB In the next figure, we have indicated all the sections.
Print document
In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print
Figure 2-9: the circuit of the Main Controller board (is installed on the top of The Arduino PCB)
Figure 2-9 note
1
2×5 female pins to send command
2
Two female pins for power input
3
1×16 female pin for connecting LCD
4
1N4007 diode
5
A 10kΩ Potentiometer
6-7-8
seven small push Print buttons to modify time document
In order to print this document from Scribd, you'll first need to download it.
9
CRISTAL QUARTZO 32,768KHZ Cancel
Download And Print
10
DS1307 is a Serial Real-Time Clock
11
Lithium Battery
12
A 330Ω and two 10kΩ Resistors
13
6×10kΩ Resistors
14
Male Pin t to connect to the Arduino Board
The above PCB should be put on the Arduino board. (Next figure)
Figure 2-10: displays the main controller board with Arduino (the blue board in the bottom ) and LCD component
document control program into the Arduino board Step 5: Uploading thePrint In order to print this document from you'll do not need to have a One great thing that I like about Arduino board isScribd, that you need to download it. programmer to upload your first developed code. If this is the first time you are using an Arduino board for building your project, there is tons of information on the internet to Cancel Print teach you how to do it, or you might try thisDownload link forAnd example: http://www.ladyada.net/learn/arduino/lesson1.html
Print document Conclusion
In order to print this document from Scribd, you'll
Now you have the information you need to become a successful a Microcontroller first need to download it. programmer. This is a moment for you to take the information you’ve been given and not be afraid to put it to use. Cancel
Download And Print
The primary thing that keeps people from becoming successful is fear. If you can overcome this fear then you will succeed and prosper. All you need to do at this point is to stop putting things off and just do it. Start working and you will find it becomes easier as you go along. Once you accomplish any new skill or task, you will realize just how easy it is. That is when you want to kick yourself for not starting sooner. So don’t hesitate. Start right now. Start today. Break that cycle of doubt and enjoy your newfound skills and succeed in exploiting them. To your success and happiness, Seyedreza
Print document My e-book product list
In order to print this document from Scribd, you'll www.plc-doc.com first need to download it.
Hardware, software and more Download And Print We would like to introduce ourCancel Teach Yourself Consumer PLC books as an excellent resource for readers who want to learn more about PLCs. So far, we have launched this groundbreaking new series with four exciting titles:
1. Programming with SIMATIC S7 300/400 Programming Controllers 2. Programming with SIMATIC S7-200 PLCs using STEP 7-Micro/win software 3. Introduction to programming a SIEMENS LOGO! PLC 3. Basics of Programmable Logic Controllers (PLC) 4. Programming Allen Bradley series of PLCs using RSLogix 500 software compiler 5. Introduction to programming Allen-Bradley series of PLCs (Second Edition) Design and Implementation of typical end year college projects using a PLC with youtube.com site links to watch the projects in action: 1. Programming a 4 floor elevator with SIMATIC STEP 7 and LOGO! SoftComfort http://youtu.be/dqkeHD5WNcc 2. Programming SIEMENS LOGO! PLC as a dyeing machine temperature controller http://youtu.be/mJfT4z1oCeo 3. Programming a Traffic Light Controller system using SIMATIC S7-300 & HMI display http://youtu.be/0ADfFPOzIUE 4. Programming a PLC based car Parking System with SIMATIC S7-300 PLC http://youtu.be/51oqLRxXcHk 5. Implementing a PLC-based temperature controller with PID algorithm http://youtu.be/yhSyKObMlgA 6. Design and implementation of an 8 Floor Elevator Control System with a PLC http://youtu.be/M3qgxkEIDw8 Design and Implementation of typical end year college projects using AVR Microcontroller\the Arduino board based controllers with youtube.com site links to watch the projects in action: 1. Simple Arduino based 4 Floor Elevator Project http://youtu.be/WU2arv-yghw 1(A). Microcontroller based 4 Floor Elevator System http://youtu.be/UQbGcntcVP4 2. Implementing a Traffic Light Controller System using Arduino http://youtu.be/f-ZbP8juB20
LIGHT CONTROL system 2(A). Programming a TRAFFIC using an AVR Print document microcontroller In order to print this document from Scribd, you'll http://youtu.be/q0eWsX2kMeU first need to download it.
3. Simple Arduino based Automated Parking lot System http://youtu.be/CNt2DIlwrso Cancel Download And Print 3(A). Design and implementation of a Microcontroller-Based Car Parking System http://youtu.be/7aIp2iCC_mU 4. Implementing an Arduino based temperature controller with PID algorithm http://youtu.be/i2nxqLs9wBg 4(A). Temperature controller and monitoring with a microcontroller http://youtu.be/mIyixludYaE 5. Analog LED clock with chime, alarm, calendar and temperature display (not published yet) http://youtu.be/Mi5zAdctp4g Free microcontroller \Arduino based project Downloads from our www.plc-doc.com or www.plcgoods.net websites: 1. How to control a Stepper motor with an ATmega8 microcontroller http://youtu.be/XBWCsl512Lc 2. MATLAB/PC and Microcontroller based advanced Line following Robot http://youtu.be/2Y_qSzKL_2Y 3. 2 Zones microcontroller based weekly digital timer http://youtu.be/xbIEKI3qqNM
Print document In order to print this document from Scribd, you'll first need to download it. Cancel
Download And Print