Вы находитесь на странице: 1из 11

1

Introduction The Salisbury High School project is part of the C2C initiative. The function of this system is to design a small security system that responds to a change in light level or a switch contact. This page details the electronics part of the project. Power Supply. The system requires a loud speaker output and the amplifiers perform best at about 9V. This voltage is too high for the microcontroller so a simple regulator circuit was designed. The LM2940 supplies about 100mA at 5V and is adequate to operate the microcontroller. The 9V battery connects through a screw terminal block and reverse damage to any components is prevented with a diode. Microcontroller A PICAXE 08M device was chosen because it is easy to program with a flowchart system that reinforces the planning process. External screw connectors were used for the switch input on J3, Led output of J4 and J5 Amplifier An LM386 audio amplifier was chosen to generate about 200mW output power. The microcontroller output labelled OUT2 drives the amplifier. Summary of HARDWARE connections Switch on J3 - use the if PIN3 command Led on J4 - use the High 4 command Led on J5 - use the High 0 command Sound is on OUTPUT 2 Light sensor is read with the READADC , 1 command TASK 1 : Use the Flowchart. 1. Open the Programming Editor and set up a flowchart. 2. Set up the correct part names. This makes it easier to refer to specific parts on the boards. You can give your own names that make sense. Select the Flowchart symbol table. 3. Enter appropriate names

4. Flash the lights for a test Use the output commands to make lines 0 and 4 high and low. This will make your leds flash on and off. 5. Set up the following flowchart.

You will see that the default value if zero, you can select the appropriate symbol name 6. Run the simulation Click on simulate window to test your program. You will the lights flash as you step through the program. 7. Download to your controller. Make sure that the LEDS are connected to the connectors with the anode and cathode in the appropriate side of the socket. Select the CONVERT TO BASIC option. You will see your program in text mode. Select the download option on the tool bar. You should see a progress bar and the leds will flash when the download is complete.

Task 2. Reading a switch You have a switch input on the board that is part of the security system. Your program must test if this switch is ON or OFF. The usual electronics lingo for this is HIGH or LOW. You need to use the IF icon in the flowchart. Return to your original flow chart and remove the icons. Start with a clean sheet. NOTE: MAKE SURE YOU CHANGE THE SWITCH WORD IN THE SYMBOL TABLE BECAUSE THAT GENERATES AN ERROR. Set up the following icons. You can run the simulation and click on input 3 to see the program change directions. Convert to BASIC Select the conversion option. You should see the following program. Download the program and you should see the light stay off until you press the switch. You can play a tune at this point with the sound or tune command (http://www.intellecta.net/salisbury_high_school.html)

1 CT1 3.5mm stereo socket 1 B1 Borne placa C.I. 2 terminales 1 CN1 Tira pines (2 pines) 3 R1-R3-R1 10k_/0,25W 1 R1 1k_/0,25W
6

1 R2 22k_/0,25W 1 R5 330_/0,25W 1 Q1 BC548B 1 C1 100F Electroltico 1 IC1 Zcalo 8 pin 1 IC1 Microcontrolador PICAXE-08 1 D1 Diodo LED 1 BZ1 Altavoz piezoelctrico 1 R2 Resistencia LDR

Programa:
Programa 1
Alarma para PICAXE-08 ' Entrada analogical en pin 1 ' Entrada digital en pin 3 ' LED en pin 0 ' Altavoz piezoelctrico en pin 2 ' Salida en pin 4 symbol luz = b1 ' ***** Menu principal ***** ' Bucle chequeo luz y sensores inicio: ' Endendido de LED y lectura del valor de la luz high 0 readadc 1, luz ' Si el valor analgico ledo es bajo (inferior a 40) emite sonido if luz < 40 then sonido ' Si el interruptor esta activado activar la alarma if pin3 = 1 then alarma ' Pausa (prdida de tiempo) de 500 ms = s pause 500 ' Apagado de LED y lectura del valor de la luz low 0 readadc 1, luz ' Si el valor analgico ledo es bajo (inferior a 40) emite sonido if luz < 40 then sonido ' Si el interruptor esta activado activar la alarma if pin3 = 1 then alarma ' Pausa (prdida de tiempo) de 500 ms = s pause 500

Proyecto de alarma
'Ir a inicio para repetir el bucle goto inicio ' ***** Genera sonido***** sonido: sound 2,(120,50,80,50,120,50) pause 200 goto inicio ' ***** Activacin salida alarma **** alarma: high 4 pause 2000 low 4 goto inicio

Programa 2
' ***** Menu principal ***** ' Bucle chequeo de sensores inicio: 'LED apagado low 0 'Lectura del valor de la luz covertidor A/D y carga valor en variable b1 readadc 1,b1 'Si el valor analgico ledo es bajo (inferior a 40) emite sonido

if b1 < 40 then alarma ' Si el interruptor esta activado activar el sonido if pin3 = 1 then sonido 'Ir a inicio para repetir el bucle goto inicio ' ***** Genera sonido hasta que el interruptor se cierre ***** sonido: high 0 sound 2,(120,100) if pin 3 = 1 then inicio ' ***** Activacin de la alarma indefinidamente***** alarma: high 4 goto alarma

Programa 1:
' *********************** ' **** bucle despacio *** ' *********************** Main: lento: high 0 ' LEDs on high 1 high 2 pause 500 'espera 0,5 s ' Si la luz es baja salta a bucle rpido if pin3 = 0 then rapido low 0 ' LEDS off

low 1 low 2 pause 500 ' espera 0,5 s ' Si la luz es baja salta a bucle rpido if pin3 = 0 then rapido goto lento ' *********************** ' **** bucle rpido ***** ' *********************** rapido: high 0 ' LEDs on high 1 high 2 pause 100 'espera 0,1 s ' Si la luz es alta salta a bucle lento if pin3 = 1 then lento low 0 ' LEDS off low 1 low 2 pause 100 'espera 0,1 s ' Si la luz es alta salta a bucle lento if pin3 = 1 then lento goto rpido

Programa 2:
************************************************ ******* Test programa Tringulo de emergencia ******** *******encendido de LEDS con distintos patrones******* inicio: ' poner pines 0, 1 y 2 a nivel bajo low 0 low 1 low 2 main: ' todos los LEDs on y despus todos off for b1 = 1 to 20 let pins = %00000111 pause 100 let pins = %00000000 pause 100 next b1 ' en circulo for b1 = 1 to 20 let pins = %00000001 pause 100 let pins = %00000010 pause 100 let pins = %00000100 pause 100 next b1 ' flash en circulo for b1 = 1 to 20 let pins = %00000001

pause 100 let pins = %00000000 pause 100 let pins = %00000010 pause 100 let pins = %00000000 pause 100 let pins = %00000100 pause 100 let pins = %00000000 pause 100 let pins = %00000010 pause 100 let pins = %00000000 pause 100 next b1 'repite el bucle goto main `NOTA: `Modificar el programa 1 para que funcione como sealizador, es decir, debe permanecer apagado en todo `momento que exista luz y encenderse la secuencia luminosa en el momento que oscurezca.

Propuesta A. El ventilador se encender y apagar automticamente a intervalos de

tiempo programados.
Una posibilidad para el programa de control seria: input 1 symbol pulsa_on=input1 inicio: if pulsa_on is on then encender low 0 goto inicio encender: high 0 wait 3 low 0 wait 6

goto inicio
Propuesta B. Encendemos y apagamos el ventilador mediante dos pulsadores A y B. El A encender el ventilador de forma continua. El B lo encender y apagar en intervalos de tiempo de 3 segundos. Una posibilidad para el programa de control seria: input 1 input 2 symbol pulsa_A=input1 symbol pulsa_B=input2 inicio: if pulsa_A is on then encender if pulsa B is on then intervalos low 0 10

goto inicio
encender: high 0 goto inicio intervalos: high 0 wait 3 low 0 wait 3

goto inicio
Propuesta C. Sustituir los pulsadores por un DS18S20 que encienda automticamente el ventilador a partir de una determinada temperatura. Para este

ejemplo es necesario el uso del picaxe 08M.


symbol tempe=b1 output 4 inicio: readtemp 4,tempe if tempe>30 then encender if tempe<20 then apagar goto inicio encender: high 4 goto inicio: apagar: low 4

goto inicio

11

Вам также может понравиться