Arduino Uno Remote Alarm
Introduction
This page describes my experiments with Arduino Uno. I created remote alarm and curve tracer.
Remote sensors station with 433 MHz trasmitter
I have something, that is about 30m from my home and I want to watch it. There is not cable connection, so I decided to make wireless alarm station that uses 433 MHz connection
Schema, function description
ATtiny2313A periodically checks three inputs PD3 - 5, where are PIR, light and fire sensors connected. In case that alarm is signaled, relay switch ON transmitter. UM3758-120A is coder/decoder, that have 3-state inputs, that's used for pairing transmitter with receiver - both must have set this same code on A1 - A12 inputs. So last 3 ones: A10 - A12 I use for signaling 8 alarm types. Remote alarm uses 4, others are reserved for future use:
A10 | A11 | A12 | Signal |
---|---|---|---|
0 | 0 | 0 | Watchdog |
0 | 0 | 1 | Fire alarm |
0 | 1 | 0 | PIR alarm |
0 | 1 | 1 | Light alarm |
When no activity occurred, green LED blinks and watchdog is periodically signaled.
Developing
For developing, I use breadboard and following tools:
- Atmel Studio - IDE for developing and debugging Atmel CPU's
- AVRDUDE - utility to download/upload/manipulate the ROM and EEPROM contents of AVR microcontrollers
- avrdude-GUI - GUI for avrdude
- AVR USBasp - USB in-circuit programmer for Atmel AVR
AVR USBasp is great tool - it allow insert many types of ATxxx family CPU's into socket and load program into it. There are pins that allow connect CPU to breadboard and develop circuit and software in flexible way. Finally, circuit can be moved to PCB.
Source code
Software is very simple: in infinite loop, sensors (PD3 - 5 inputs) are checked and when alarm is signaled, proper code is set to PB0 - 3 outputs (alarm code) and also PB3 switch relay ON for 10 seconds to give time for receiver to scan it. When no alarm occurred, watchdog signal is send every 50 green LED blinks.
Construction
Construction is on universal board, housed in ABS plastic box.
PIR, fire and light sensors |
PCB testing |
PCB detail |
Final |
Arduino Uno base station with 433 MHz receiver
Base station is used for alarm signalling and also for playing and learning.
Schema, function description
This schema contains 6-button keyboard and radio receiver for remote alarm. PCF8574, the I²C 8-bit expander is used for adressing 74HC151, that scans buttons. Also UM3758-120A decoder A10 - A12 inputs allows scan 8 alarm codes from 433 MHz radio receiver.
Construction
Construction is on universal board, it's not like final product, rather used for learning and playing in future
16x2 LCD, driven by PCF8574T |
Main unit |
On base PCB, there is 6-button keyboard with related logic, 16x2 LCD with I²C interface and piezzo buzzer. 433 MHz radio receiver and decoder is on dedicated PCB module.
Software
Base station software I develop using Arduino IDE. This code contains alarm logic, and aditionaly there are routines for playing with PCF8583 (I²C RTC), PCF8574 (I²C 8-bit expander) and PCF8591 (I²C 8-bit A/D and D/A converter). For this reason, following source code is not complete, here is only keyboard, LCD and alarm related code.
Sketch download.
Learning PCF8583, the I²C RTC
PCF8583 is RTC clock/calendar with alarm functionality. The device has 256x8-bits of RAM. On base PCB, I placed two ones - first used for clock/calendar and daily alarm, second used as timer for updating status LED's independently from rest of software.
Both RTC's are backed up with CR232 baterry. Arduino Uno have only two interrupt inputs:
- Interrupt0 (PIN2) is switched using 74HC151 between Conrad DCF77 module and RTC #1, that trigger interrupt once per day. Interrupt0 routine request time update from DCF77 module.
- Interrupt1 (PIN3) is connected to RTC #2 that trigger interrupt every 5 second. Interrupt1 routine updated status LED's
Software
For driving this device, there are some libraries available, but no ones fit's to me. I decided join two ones and make it suitable for my needs. You can download it.
Here is most of my source code for RTC's. Note, that interrupt handlers only sets global variable, that serves as flags. Those flags are checked in main loop and here is required functionality. It's not good idea do some complex work in interrupt handler routine (e.g. I²C communication), because it may conflict with main code.
Note, that in routines handleInterrupt0(), handleInterrupt1()
, alarm must be restarted using appropriate function.
Daily alarm test
Wake up me every day at 17:54, when I watch weather forecast at TV:
Weekday alarm test
Following code trigger daily alarm in next minute, but only in Tuesday:
Dated alarm test
Following code trigger alarm at specified date-time:
Timer alarm test
Following code trigger timer alarm every 5 seconds:
You can use other units, as defined in PCF8583.h : TIMER_HUNDRS_OF_A_SEC, TIMER_SECONDS, TIMER_MINUTES, TIMER_HOURS, TIMER_DAYS
Learning PCF8574, the I²C 8-bit expander
PCF8574 is the I²C 8-bit expander, that allows give another I/O ports, when Arduino ones is consumed. This chip is available in two variants: The PCF8574P has an I²C address starting with 0100 but the PCF8574AP has an address starting with 0111. This means that PCF8574P uses address range 0×20 - 0×27, PCF8574AP uses address range 0×38 - 0×3F.
For playing with it, I made simple circuit with PCF8574AP driving 8 FLUX LED's using ULN2803A.
Testing sketch
This sketch demonstrates bit rotations with sending data to PCF8574 driving LED's:
Another sample:
Learning PCF8591 , the I²C 8-bit A/D and D/A converter
DAC
PCF8591 has one 8-bit DAC. This sketch shows triangle wave on DAC output:
Curve tracer
Introduction
I create simple curve tracer, inspired by this page. Instead of using Arduino PWM outputs, two PCF8591 DAC's are employed.
Schema, function description
For each traced curve, DAC #2 sets base (or gate) voltage, defined in array:
Tracer on the breadborad |
DAC output calibration |
Then sawtooth wave is set as collector voltage by ADC #1 and Uce and Ice are measured by Arduino ADC's. PCF8591 ADC is not used, because it's only 8bit, Arduino have 10 bit ADC's.
Software
Tracer software is divided to two parts: On Arduino is running
sketch
that drive DAC's and make measurement. Measured values
are sended to Serial line
to PC (trough USB connection), where run Processing
sketch
that draws chart. Both sketch are based on Don Sauer's work, I added some functionality, made changes to use PCF8591
and borrow some code for keyboard and LCD support from alarm project.
Note, that I use Processing 2.0.3 - Win 32, because Serial not supported in 64 bit version. Also note that Processing 2.1 have Serial functionality buggy -
Serial.flush();
function not works for me.
28BYJ-48 – 5V Stepper Motor with ULN2003 driver
Original Arduino Stepper
library not works well with this device (because it requires 8-step controlling),
so I modified it - it's compatible with original. Code is
fork of original library and driving of motor is borrowed
from article on Instructable