Sunday 9 June 2013

Raspberry Pi case: Tin can

Here is the case I made from a coconut milk tin can. The case is big enough to fit Raspberry Pi with Pi-Face attached. I wanted to paint it as a Duracell battery but then decided not to use this case, as it may Do a Barrel Roll!




Friday 7 June 2013

Connecting temperature and motion sensors to Pi-Face

I will assemble the same circuit as in my previous post but this time I will use Pi-Face. The parts are the same except for one minor change: I will use 10k Ohm pull-up resistors for both of the sensors. So grab an additional 10k Ohm resistor and lets wire things up.

Because Pi-Face cannot read DS18B20 temperature sensor's input, I will connect the sensor's data terminal pin directly to Raspberry Pi GPIO, while having everything else connected to Pi-Face. Pi-Face connects to Raspberry Pi through SPI which leaves me with plenty of free GPIO pins. Here is the link to Pi-Face design and its beakout board with the connection pins marked green.

Here is the circuit

 


The big red square are Raspberry Pi (Model B) pins. The pins differ on Model A. Two smaller red squares are sensors - temperature and motion. Four tiny red squares are resistors. Plus two diodes (LEDs). Green lines are wires and green dots are wire junctions. There are also 8 + 8 pins on Pi-Face, marked as Input and Output, the Input set of pins has one ground pin and the Output set of pins has one 5V pin. And finally, green squares on Raspberry Pi pins connect it to Pi-Face.

Connecting Pi-Face to Raspberry Pi


I used a bunch of jumper wires to connect only the required pins marked as green squares on the circuit. So, every male pin on Raspberry Pi marked with a green square should be connected to its female slot on Pi-Face. Triple check that this connection is proper, not upside down, not mirrored. Then you may plug power supply and run this Python program which will enable Pi-Face output pins so you can see its on-board LEDs flash.

Wiring sensors and LEDs


Please read my previous post to understand how to calculate resistor values and wire sensors into the circuit. Note that I am still using 100 Ohm resistors for LEDs because the current does not exceed 20 mAmps (measured 18 mAmps) and I've got plenty of those cheap LEDs! Also note that the voltage provided through Pi-Face Output pins (which act as ground) is not 5V but 4.2V (measured), I guess this is because every output pin has an on-board LED which provides additional resistance.

Summary:
  • Use 5V pin of Pi-Face to power both sensors and both LEDs.
  • Connect the temperature sensor's data terminal to Raspberry Pi GPIO4.
  • Connect the motion sensor data terminal to Pi-Face input pin 0 (the first pin as input pins count starts from 0).
  • Connect ground terminal of the first LED to Pi-Face output pin 2 (4th pin, first pin is 5V and output pins count also starts from 0) and ground terminal of the second LED right next to it - output pin 3.

Python program


It checks room temperature every half a second and lights up one LED when the temperature is above 20 C (just breath on the sensor). Lights up another LED when it detects motion.  You may want to alter the temperature limit ans change the device directory (mine is 28-0000047b16ad) in the source code. Download link.

And finally, a set of pretty pictures



Saturday 1 June 2013

Connecting temperature and motion sensors to Raspberry Pi

I will connect a temperature sensor and a motion sensor directly to Raspberry Pi (Model B), both sensors are digital and one-wire. I will also use two LEDs as signals. When the temperature raises or motion detected those will flash.

Below are the links to the actual parts I used. Eventually these links may stop working, but all the parts are very common and easily obtainable.
  1. Yellow LED
  2. Red LED
  3. Breadboard
  4. Jumper wires M/M
  5. Jumper wires M/F 
  6. Two 100 Ohm resistors
  7. One 4.7k Ohm resistor
  8. One 10k Ohm resistor
  9. DS18B20 digital temperature sensor
  10. SparkFun SE-10 PIR motion sensor

Here is the circuit



The big red square are Raspberry Pi (Model B) pins. The pins differ on Model A. Two smaller red squares are sensors - temperature and motion. Four tiny red squares are resistors. Plus two diodes (LEDs). Green lines are wires and green dots are wire junctions. Wire properly and it should work.

Calculating LED resistor: why 100 Ohm?


Ohm's Law:   I = V / R    →   R = V / I
  • I is the current measured in amperes, V is the voltage measured in volts, R is the resistance measured in ohms.
The board supplies 3.3V and a LED maximum current is 20 mAmps (according to manufacturer). Thus the safe current for the LED is around 12 mAmps.

R = 3.3 / 0.012 = 275 Ohm

Oh, the LED itself acts as a resistor of approximately 175 Ohm (measured manually), thus:
R = 275 - 175 = 100 Ohm

So, if we put a 100 Ohm resistor in a circuit with one LED, the current in the entire circuit will be 12 mAmps.

Pull-up resistor


A pull-up resistor connects sensor's power terminal with data terminal. Read more about pull-up resistors here. One sensor in the circuit is using 4.7k Ohm and another is using 10k Ohm pull-ups.

Wiring sensors and LEDs


Read manufacturer's data sheet to understand which of the sensor's terminals connects to power, data and ground. E.g. on my motion sensor the white wire was ground and the black wire was alarm (data).

To wire and enable DS18B20 temperature sensor please use this guide. Follow the guide and the sensor will be connected to the GPIO4 pin exactly as on my circuit. Here is the data sheet.

Motion sensor connects in the similar manner to GPIO14 and uses 5V. It will send data directly to the GPIO14 pin. Here is the data sheet.

Wiring a LED is pretty simple but you may use this guide, it has pictures!

Python program


It checks room temperature every half a second and lights up one LED when the temperature is above 20 C (just breath on the sensor). Lights up another LED when it detects motion.  You may want to alter the temperature limit ans change the device directory (mine is 28-0000047b16ad) in the source code. Download link.

 And finally, a pretty picture

 


In my next post I will assemble the same circuit using Pi-Face.