Now that we’re comfortable with using our Nanos, breadboards, and navigating the Arduino IDE, it is time to start learning! We’re still in the introductory stages of this series, so I’ll give you very basic explanations now, to help you understand, and expand your knowledge with more in-depth details as we progress in future posts. Part 1 of this project covers resistors (electrical resistance) and, Part 2 will cover writing your code so that it uses functions (re-usability).
In order to illustrate these two topics, we’re going to set up a series of buttons on your breadboard that are connected to different value resistors and a voltage divider. We’re going to start with the electronic components before moving to the code, where I’ll show you how to use the values received from the breadboard to make decisions in your code – in this case, we’ll create a keyboard by assigning letters to those values!
In case you don’t already have your Nano board and your component kit, here is the parts list (with coupons):
eMakeFun Electronic Components Starter Kit 20% Coupon – JVJRAPR9
eMakeFun Arduino Nano 5 pack 20% Off Coupon – 8H4NTIYN
And here is a link to the prior entries in the series: Arduino For Beginners
Here are the basic points for you to start with in Part 1:
- We’re working with a DC (Direct Current) circuit.
- In DC circuits, electricity flows from the negative to the positive.
- Resistors provide electrical resistance (impedance or resistance to a circuit – in DC circuits, the two terms mean the same, so that’s enough to understand for now).
- Electrical resistance reduces the voltage flowing through a circuit (again, simplification).
- A voltage divider is a circuit made of two resistors which allows you to determine the voltage in a circuit.
Think of your circuit as the flow of traffic along a street. Speed bumps, the equivalent of resistors, slow down speeding cars. The size of the speed bump determines how little or how greatly traffic is impeded. The higher the value, the number, of the resistor’s value, the greater its ability to restrict the flow of electricity in the circuit. Also, there is a color coding system that allows you to visually inspect a resistor to determine its value. For now, there is a cheat page to help you out: http://resisto.rs/
eMakeFun also included a reference card in your component kit:
Don’t worry, as we progress further in the series, I’ll teach you how to read the bands and understand what everything means.
Here are the components you will use in this part of the project:
You will build this circuit on your breadboard, so there are a few points to mention.
- Don’t work on the breadboard with power connected. You’re going to fry something.
- When you insert a component into the breadboard, be firm as you insert components into the tie points (the holes in the board).
- At the same time, don’t go all “strong like bull” – you can make a solid connection without breaking anything.
- Use the ground and power buses to supply ground and voltage
- The power & ground buses breadboard in your component kit have a break that you’ll need to jumper (look at the middle of the breadboard).
- Later on, when you’re experimenting, know the maximum voltage for your components and provide a resistor that keeps voltage below that max.
Sooner or later, you’re going to burn up a component. It happens to all of us. Don’t try to use it once the magic smoke comes out, just grab another one. ALSO – if you want to reuse your resistors, don’t trim the “legs,” but I prefer to trim them – resistors are cheap and trimming the legs reduces the chance of accidentally touching another component and causing a short.
In case you need a refresher, here’s the pinout for the Nano:
The first part of the circuit is going to be a voltage divider. Plug your Nano into the breadboard and grab two 57k resistors.
Connect one resistor to the power bus and also to the row of tie points to the left of the trench.
Connect the other resistor to the row of tie points on the right side fo the trench and to the ground bus on the far side.
Connect a jumper from a tie point connected to the GND pin on the Nano and to the top tie point on the right side’s ground bus.
Connect another jumper from the 5V pinto the top tie point on the left side’s power bus.
Connect a jumper from A0 (fourth row down on the left side of the Nano) to a tie point on the row with the two resistors.
You’ve created a voltage divider! Current will flow from the Nano through the GND pin to the ground bus. The 57k resistor allows current to flow to the jumper that bridges the trencht. The next 57k resistor, in turn, allows current to flow to the power bus while current simultaneously flows to pin A0. The circuit is completed as the jumper bridging the power bus connects to the 5V pin. If your Nano were connected to your computer at this moment you could display the voltage of the circuit in your Serial Monitor.
To continue, we’re going to insert 6 buttons and an assortment of resistors. Specifically, we want a different resistor value for each button. I used these:
Resistor(1k)
Resistor(2k)
Resistor(4.7k)
Resistor(10k)
Resistor(20k)
Resistor(57k)
We need to make a couple of small changes to the voltage diver before moving forward. The wire that is jumpered from the two 57k resistors should be shifted down two rows, as we’ll connect jumpers from our buttons here. You’ll also want to jumper the trench on this row. Finally, jumper a wire from the row with the two 57k resistors over to the power bus on the right side. We’ll also connect your buttons to this bus.
Next, install your buttons – there are 4 pins which allow you to bridge the trench with a set of pins on each side. Be careful, as it is easy to flatten a pin out instead of getting it into a tie point.
Connect each of the resistors in the list above to the ground bus (right side) and to a tie point on the same row as the bottom right pin for each button. Remember, no two buttons should have the same value resistor!
Next, connect a series of jumpers from the power bus (right side) to the row for each button’s top right pin, as above.
Finally, jumper the row from each button’s top left pin up to the row where you jumpered pin A0 from your Nano
Connect the USB cable from your computer to the Nano, open the Arduino IDE and enter this code in a new sketch:
int voltageInput = A0;
void setup() {
pinMode(voltageInput, INPUT);
Serial.begin(115200);
}
void loop() {
Serial.println(analogRead(voltageInput));
delay(100);
}
Save the sketch and upload it to your Nano. Click the Tools menu and select “Serial Monitor.” Press press a button and hold it for a moment.
The value displayed in the Serial monitor should change – in fact, you should see a different value displayed for each button or combination of buttons you push. The exact value will fluctuate a bit, but it doesn’t matter for our purposes – which we’ll cover in tomorrow’s post (Part 2)!
SmarterHome.club is the website for our Facebook community, The Smarter Home Club – which is an umbrella for all kinds of smart home technologies – home automation, security, custom electronics, weather stations, alternative energy, you name it. DIY focused.
If you’re interested in joining the Smarter Home Club’s Facebook group, please follow this link: