First prototype
The first prototype that we will build is pretty simple and designed to be used in the next couple chapters where we learn to program the Arduino. This prototype will have one button that will be used to turn a LED on or off, another LED that we can turn on or off and a TMP36 temperature sensor.
In this prototype, we will have two inputs (a push button and temperature sensor) and two outputs (the two LEDs). We will use the 5V output from the Arduino to power the components. Here is the Fritzing diagram of this prototype:
In this diagram, starting from left to right, we have the button, the two LEDs, and the TMP36 temperature sensor. Each of the LEDs has the same 330-ohm resistor that used in Chapter 3, Circuit Diagram. Since the power from the Arduino is only 5 volts, we could lower the value of the resistor to 100 ohms, but the 330-ohm resistors will work fine as well.
The resistor that we are using the button is called a pull-down resistor because one end is connected to ground. A digital logic circuit can really have three states: high, low, and floating. The floating state occurs when the pin is neither pulled high or low but is instead left floating. In this floating state, the microcontroller could unpredictably interpret this state as either high or low. To solve this issue, a pull-down resistor is used to pull the floating state low.
If the resistor was connected to the voltage supply, rather than ground, it would be considered a pull-up resistor. A pull-up resistor works in the same manner as a pull-down resistor but rather than pulling the floating stated low, a pull-up resistor pulls it high. We will be using pull-down and pull-up resistors in several projects in this book.
The push button is connected to pin 12 of the Arduino; therefore, we will be able to read the state of the button by checking the state of pin 12. The LEDs are connected to pins 11 and 3; therefore, we will be able to turn them on by sending a digital high to those pins or turn them off by sending a digital low. Finally, the output pin on the TMP36 temperature sensor (the middle pin) is connected to the analog 5 pin since the output from the sensor in analog. The voltage and ground pins on the TMP36 temperature sensor are connected to the voltage and ground rails on the breadboard.
The Fritzing diagram makes the prototype look so nice and organized; however, most prototypes do not look like that. The following is what the prototype looked like when I built it for this book:
It is nice to have your prototype neat and looking good, but it is not necessary as long as you can work with it. It is especially hard to have the prototype neat when you only have one or two lengths of Dupont (jumper) cables.
You will also notice the short wires that run across the power rails. On this breadboard, the power rails are not connected all the way across horizontally. This is an example of a breadboard that is configured a little differently. You can tell that the power rails do not run all the way across because the red and blue lines on the breadboard have a gap halfway across; therefore, we used small cables to connect the two sides. There are times that we need different power sources so having the power rails split like this can be very helpful but for this prototype, since we are using the same power source for all components, we connected the power rails together.