For our second build in the Make It Last Build Series, we’re constructing a robotic plant. This week, we’re going to put together the brains of the machine, which we will use in the coming weeks to bring our plant to life. This basic circuit will have support for one servo motor, an external crystal to keep accurate time, a capacitive touch input, and plenty of I/O pins to drive LEDs, and read other sensors. This time around, we’ll be soldering it together to make a more permanent design, that will be perfect for placing in your plant pot.
Just getting started? We suggest you take a look at the announcement post for an introduction to the project and a parts list, then follow along with these instructions to build the brains for the robot plant. If you haven’t signed up for the newsletter, now is a good time to do so.
Also, as a reminder, you don’t need to purchase any parts or build our project to be eligible for the contest — in fact, the more creative you get, the better! So without further ado, lets get to the building!
Note: We’re going to be soldering this project together on a perfboard. If you’ve never used them before, check out Collin’s Perfboard Prototyping video for a great introduction. If you’re still nervous, you can certainly just build your circuit on a solderless breadboard!
Step 0: Collect supplies
- 18lf25k22 processor (Digi-Key PIC18LF25K22-I/SP-ND)
- 28-pin chip socket (Digi-Key 3M5480-ND)
- .1″ male headers (Digi-Key A26509-40-ND)
- 10k resistor (Digi-Key 10.0KASCT-ND)
- 220 ohm resistor (Digi-Key 220QBK-ND)
- 1uF bypass capacitor (Digi-Key P5174-ND)
- 32.768 kHz crystal (Digi-Key 631-1205-ND)
- 2x 22pF cap (Digi-Key VY1220K31U2JQ63V0)
- N-channel transistor (Digi-Key NTD4960N-35GOS-ND)
- 3mm red LED (Digi-Key 754-1218-ND)
- 22 AWG solid-core wire
- Modded 3xAA battery holder (Digi-Key SBC331AS-GRN-ND)
- 3x Energizer lithium batteries (Digi-Key N602-ND)
- Protoboard (RadioShack 276-170)
- Continuous rotation servomotor (Digi-Key 900-00008-ND)
- PICkit 3 programmer, for programming the processor
- Soldering iron (with solder)
- Flush cutters
- (optional) drill with 1/16″ bit
Step 1: Chip socket
The first step is to place our chip socket on the board. The sockets provides a way to connect our microcontroller without making it permanent, in case we need to swap it out for some reason.
Step 2: Programming header and power wires
For our circuit, we’ll use the connection strip on the right (labeled ‘X’ on the Radio Shack board) for power, and the one on the left for ground. Connect wires from Pin 20 on the chip socket and Pin 2 on the programming header to the power strip.
Step 3: Ground wires
The ground connection is a bit trickier, since we need to run a wire from the left side of the board to the right side of the chip socket. Connect a wire from the ground strip to Pin 3 on the programming header, then from there to Pin 19 on the chip socket.
Step 4: Reset line
Next, we need to wire the reset line to the processor, so that the programmer will be able to do it’s job. Run a wire from Pin 1 on the chip socket to Pin 1 on the programming header, then place a 10k resistor from there to power. This way, when the programmer is connected, it can overpower the resistor and reset the microcontroller, and when it is disconnected, the microcontroller will stay on.
Step 5: Clock circuit
In the data logger project, we used an oscillator that was built into the microcontroller to keep time. This was convenient because it didn’t require any extra parts, however it isn’t quite as accurate as it could be. For this project, we’ll use an external one to make sure that the plant keeps the correct time. Place the oscillator between Pins 11 and 12 on the microcontroller (it doesn’t matter which way it is inserted). Next, place a 22pF capacitor from each of these pins to ground.
Step 6: Status LED
Next, let’s add a status LED so that we can see if our project is working. Connect a 220 ohm resistor from Pin 2 on the chip socket to an empty row on the breadboard. Then, connect an LED from that row to the ground strip, making sure that the negative (short) lead of the LED is connected to ground.
Step 7: Bypass capacitor
Now, add a .1uF capacitor between Pins 19 and 20 on the chip socket. Note that for this part, orientation does matter. Make sure that the negative side is connected to ground, and the positive to power.
Step 8: Test it out
Let’s take a break from soldering, and test that our circuit works! Stick the microcontroller into the chip socket, then connect the programmer to the programming header (note that Pin 6 on the programmer isn’t connected; it isn’t necessary for this circuit). Download the example project from here (zipped file), give it a look over, then program it to the microcontroller. If all went well, the status LED should flash on then off in intervals of one second.
Step 9: Servo header
The final thing we need to add to our project is a circuit to control the servo motor. Place the transistor in the protoboard just past the chip socket (leaving one row between them worked well), making sure that Pin 1 on the transistor is closest to the chip socket. Next, place the servo header just past that, again skipping a single row between the two.
Step 10: Servo circuit
Next, we need to wire up the connections between the microcontroller and the servo. There are two parts to the circuit- the transistor, which turns power to the servo on and off, and the servo header, which the servo motor plugs into.
Let’s connect up the transistor first. Connect Pin 13 on the microcontroller to Pin 1 (gate) on the transistor. This connection allows the microcontroller to turn on the transistor. As a precaution, place a 10k resistor between Pin 1 on the transistor and ground. This resistor acts as a pull-down, ensuring that the transistor doesn’t accidentally turn on if the microcontroller pin is disconnected. Next, connect a wire from Pin 3 on the transistor (source) to ground. Finally, run a wire from Pin 2 on the transistor (drain) to Pin 3 on the servo header (ground). The transistor can switch the servo off by disconnecting it’s connection to ground.
Finally, run a wire from Pin 14 on the microcontroller to Pin 1 on the servo header (signal). The microcontroller will generate a command signal on this line to control the position of the servo.
Step 11: Battery
The next step in putting together the robot plant brains is to connect up the modified battery holder. If you haven’t already modded yours, see the instructions in the newsletter to do so before continuing.
There are three connections that need to be made here — the ground (black) wire needs to be connected to the ground strip, the +4.5v (red) wire to pin two on the servo header, and the 3v (green, or whatever color wire you used) to the power strip. You could just solder the wires in directly, however a more reliable way to make the connection is to loop the insulated wire through a few holes on the circuit board to provide some strain relief, then solder the ends to the perfboard. You might need to make the holes a bit larger in order to fit the insulated wire through, which you can do using a drill and 1/16″ bit.
Step 12: Touch sensor wire
The last step in building the robot brains is to add a wire for touch sensing. Because the PIC has a nice charge time measurement unit (CTMU) built in, it is possible to detect a human touch using some crafty programming and a single wire. Connect a small length of wire (six inches is fine) to Pin 3 on the microcontroller. Strip a half inch of the insulation off of the opposite end of the wire, leaving a patch of metal as an exposed touch switch. Later on, we’ll connect this to a more suitable button.
Step 13: Done!
Now comes the moment of truth! Be sure to double-check your connections, then plug in the servo motor and switch on the battery. The status light should continue to blink on or off every second, and the servo motor should turn in one direction and then the other when the sensor wire is touched. If everything is working, congratulations! You’re all set to add some more complex behavior to this base next week. If something isn’t working, don’t fret- double-check all of your connections, and if you can’t figure it out, head over to the forum and let us know! Also, it is possible that the touch sensor will need to be calibrated to work reliably- more on that next week.
Join Make: Community Today