Say Hi to Raspberry Pi!

Raspberry Pi is a zero calorie treat for your brain! It is a tiny computer that can fit in your hand, but it is surprisingly capable! It is an awesome platform to learn coding on, and it will do just about anything you can imagine. For our introduction, I hooked it up to an ultrasonic distance sensor, and with a few lines of python, it was taking a picture of anyone who came within range and saving it in a folder.

Like any computer, the Raspberry Pi is versatile. You don't have to know anything about coding to use it. However, you can play Minecraft or whatever on your own time! We aim to make it do things just for us. Lots of people think Python is a good language to learn on, so we'll start there. Raspberry Pi!

With a camera and ultrasonic distance sensor hooked up.
In my opinion, there are lots of good computer languages, and they all have similarities. My best advice is not to be intimidated by any of it and not to be worried about things you don't understand. After all, you don't have to know how a car works to drive it, you just have to familiarize yourself with the controls and the features of that particular car.
In the old days, we used to tough it out, pull out our hair, and build things from scratch. Not any more! There are some magic keywords: import and include, which allow you to bring a package of tools called a library into your code. All you have to know is the names of the tools, called functions or methods, and what their needs are, and you can use them!
To use the ultrasonic distance sensor, our very first line of code is:

from gpiozero import DistanceSensor

gpiozero is the name of a library that allows you access all those pins on your Raspberry Pi. DistanceSensor is in that library.

We added to our first basic circuit. First a push button to allow us to turn the LED on and off

This is what it looks like as a schematic.

Next, we will replace the push button with a transistor. A transistor is the most important component in all electronics. There are millions of them, sometimes billions in everything from cell phones to computers. The simplest use of a transistor is as a switch, much like the push button we used in our circuit. The middle wire of this transistor (called the base) is like the button we push to turn it on. All we have to do is give it a small voltage, and it will start to conduct.

Here, we actually used our fingers to turn on the transistor. We held one wire in each hand, and it lit the LED! It turns out that the tiny current that passes through our bodies is enough to turn the transistor on.
Next we added a photocell, or Light Dependent Resistor, to control the transistor. Now the LED turns off when we cast a shadow over the photocell.

Just like I mentioned above, you don't have to understand all of this to use it! We live in a world of things that have been developed and refined by many minds, and what you really need to understand is that there are ways to do just about anything, and if you search, you can find a solution, or at least something that you can modify.

There is one very useful thing you can learn from this circuit, though. The photocell and resistor are working together in what is called a voltage divider. When the photocell has light on it, its resistance goes down, and since it is connected to the positive supply, it will pull the base of the transistor higher, increasing the amount it conducts. When the photocell is in the dark, the resistance is high, and the resistor is less in comparison, so it pulls the base lower.

Look at this! It is the same circuit with the photocell and the resistor positions swapped. Now the behaviour is reversed! The LED will turn on when a shadow is cast over the photocell.

This is a good demonstration on how easy it is to reverse logic in electronics. More on this later.