Implementing a traffic light controller system using Arduino.pdf

April 2, 2018 | Author: Heaklig Vladimir Ayala | Category: Programmable Logic Controller, Arduino, Printed Circuit Board, Electronic Circuits, Microcontroller


Comments



Description

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