Raspberry Pi Setup

Several months ago, the Raspberry Pi Model B came into stock at Sparkfun, so I quickly placed my order and secured one, even though I didn’t have a clear idea what I wanted to do with it. A week or so ago, I finally got around to setting up. My first step was downloading the Occidentalis distribution from Adafruit. I chose this because it has support for I2C and SPI which is useful for connecting the Pi to various sensors. To write the image to an SD card, I used the following commands:

diskutil list

gave an initial listing of the drives on my Mac. I then attached the SD card and issued the diskutil list command again and took note of which device represented the SD card.

diskutil unmountDisk /dev/disk1

unmounted the SD card, and finally

sudo dd bs=1m if=Documents/Occidentalis_v02.img of=/dev/disk1

wrote the image to the SD card. The dd command took about 45 minutes to complete, so periodically, in a new shell, I issued

kill -info 307

to get information on the dd process. Here 307 was the process identifier of the dd command, which I ascertained by

ps -Al | grep dd

Finally the PI was ready to boot. Almost anyway … first I had to get a an HDMI to DVI cable so that I could connect the Pi to my monitor. After spending $30 on a cable for my $35 Pi, it was ready to boot.

A Motion Controlled Night Light

For anyone who’s had the experience of getting up in the middle of the night and fumbling around for the light switch, here’s a simple solution that uses some easily sourced and reasonably priced components – a PIR motion sensor (Sparkfun SEN-08630), a 10K resistor, an Arduino Uno and an LED, or in my case, a 1 metre analog RGB LED strip (Sparkfun COM-10261) – just because it’s fun to work with. If you choose to use an LED strip, you will also need to get three power transistors, since each segment in the LED strip can sink up to 60mA of current for a total of 600mA per metre of LED strip, while the Arduino Uno’s digital output pins can only source around 40mA. I got some 60V 30A N-Channel MOSFETs from Sparkfun (COM-10213). These come in a TO-220 package which seems to only just fit into a breadboard. I had to use a little force to get the MOSFET legs into the breadboard but eventually they slotted in and hopefully no damage was caused to the breadboard. The transistors allow you to control a large current, sourced directly from the battery in this case, with a much a smaller current sourced from the Arduino’s 5V digital output pins. Even though the LED strip is rated for 12V, I’ve powered this system from a 9V battery and found that the LEDs are sufficiently bright.

The principle behind this system is dead simple – the PIR motion sensor detects (warm-blooded) movement and signals the Arduino by pulling its alarm pin low. The Arduino detects the alarm signal and turns on the LEDs for a period of time. I followed the advice in the following two tutorials in figuring out how to wire the whole system up. This Bildr tutorial does a great job in explaining how the PIR sensor works, while this Adafruit tutorial takes care of the LED strip.

Here is the system on a breadboard. My apologies, but the LED strip is off to the right of this shot.

IMG_0433

As you can see, even for this simple system, the wiring is pretty messy. I could cut the wires to length but this is just a proof of concept. Here is the same system simplified somewhat in a Fritzing breadboard view. Again, the LED strip is not included, as I don’t have the part in Fritzing yet. The LED strip connects to the four wires in the bottom half of the breadboard – the strip’s common anode connects to the red wire going from VIN on the Arduino to the lower power rail on the breadboard. The red, green and blue wires on the LED strip connect to the corresponding red, green and blue wires emerging from their respective MOSFET drain pins.

LEDStripAndPIR_bb

 

One important thing to note from this diagram is the use of a 10k resistor between the PIR alarm pin and 5V. This is necessary as the alarm pin is an open-collector which means that the alarm line floats whenever the PIR sensor is not actively pulling it low. Consequently, we need to ensure that the alarm line is held high whenever an alarm is not signalled by the sensor, either by using an internal pull-up on the Arduino, or by using an external resistor. This ensures that the Arduino can read a stable high or low on the alarm input pin. This also means that we can hook up more PIR motion sensors to this pin, and an alarm would be triggered whenever one of the PIR sensors detected motion.

Well that’s it for now. Code and a video will follow shortly…