Tag Archives: DIY projects

Make your houseplants smile with ATtiny85


This simple sensor can tell you exactly how your plants “feel.”


Faced with hectic schedules, it is often easy for us to forget to water our favorite plants. Typically the strong and silent type, plants likely won’t notify you when they are in need of a drink or some nutrients. However, that may all change after one Maker’s clever Atmel based design which now provides plant owners with a visual representation of just how their plant is feeling.

Feelings

“Thanasisloi7” hooked an ATtiny85 to a soil hydrometer sensor that analyzes the current moisture within the plants soil. When the soil is properly watered, an LED matrix displays a happy face. Conversely, when the soil moisture falls below a specified level, the smiling face disappears. Thus, any plant owner with common sense can know when to replenish the pot’s water supply.

feeling2

Though just a simple project, this quick design will make sure you never let your plants go thirsty again. As they say, a smile is worth a thousand words. Looking to build a better bond with your plants? Check out his official project page here.

This isn’t the first time once-ordinary objects have been transformed into “sentient beings.” Last summer, digital agency Soap Creative launched Cars That Feel, an interactive festival installation designed with Toyota. The project featured a number of cars, each of which boasted their own personality and connected with people via light projections, color and sound. The vehicles were equipped six internal BenQ projectors, Atmel powered controllers and high intensity LED light rigs. Meanwhile, a custom app was tasked with controlling internal projection mapping, lighting, sound and animation.

Tutorial: Building cool projects with MCUs (Part 5)

I finally received the circuit boards! And, in this fifth and final part of the microcontroller tutorial, we are going to solder the components to the circuit board and program the MCU using the USB port of a computer.

Just to refresh our memories, so far we have learned:

Microcontroller PCB

I recently ordered the PCBs from Seeed Studio. In order to expedite their delivery, I used a more expensive shipping option from UPS. I did get the boards pretty fast – but I also got an unexpected bill from them because they had to take it through customs.

So, even though the boards were only $10, I ended up with paying about $60 in shipping and customs… But luckily, there exists a much cheaper shipping option (about $3-4) – you just have to wait a little bit longer for the boards to arrive.

Let’s solder the board!

I wanted to make this circuit in such a way that it was possible to make it at home. To solder the circuit, I’m going to use my old Ersa soldering iron and some standard solder wire. The tip of the iron is a bit thick, so it’s really not ideal for this job. However, I know many people only have a simple soldering iron like this lying around the house – so it’s the perfect test to see if this is something that anyone can build from the comfort of your home.

Ersa30 Soldering Iron

The first thing we’re going to solder is the MCU chip. This is also the hardest part to solder. I have to admit – when I looked at my soldering iron, then looked at the chip – I was a bit worried that it was going to be hard. But the main trick here was to be patient!

To solder the surface mount components, we can use the techniques described in this smd soldering article.

First, we solder one corner pin of the chip. When we have managed to solder this one pin correctly – and all the pins are aligned over their pads – we move on to the corner on the other side. With two corners soldered properly, all we need to do is to add a tiny bit of solder to all the other pins and pads.

MCU chip soldered

Don’t rush it. Take your time. Inspect the pins closely to see if they are soldered and that they don’t have a “solder bridges” to their neighbors. And, don’t worry if it looks a bit like a war-zone with solder all over – just look at mine above – it still works!

Now, safe to say that the worst part is over. The other components are pretty straightforward to solder. Just make sure the LED and the polarized capacitor is placed in the correct direction.

Microcontroller circuit board

Programming the circuit

Once we are confident that the components are soldered properly, it’s time to test it! First, we need to check if the USB interface works. Otherwise, we won’t be able to program the circuit. To test the USB interface, all we need to do is to connect a USB cable and connect the circuit to our computer. From there, we can just check if it pops up as a USB device on the computer.

And… it does!

So, let’s program the MCU. A simple way of testing it is to make an LED-blink program. This is a simple program that, well, makes our LED blink. It looks like this:

#define F_CPU 1000000 // The chip runs at 1 MHz as default (even if you are using a 8MHz crystal)

#include
#include

int main(void)
{
DDRC = (1<<PC7); //Sets the direction of the PC7 to output
PORTC = (1<<PC7); //Sets PC7 high

while(1)
{
_delay_ms(500); //Wait 500 milliseconds
PORTC &= ~(1<<PC7); //Turn LED off

_delay_ms(500); //Wait 500 milliseconds
PORTC |= (1<<PC7); //Turn LED on
}

return 0;
}

We save this code in a file called led-blink.c

Compiling our code

The first thing we need to do is to compile our code into machine code that the MCU can read. One way of doing this is through Atmel Studio. But, since I am a big fan of using the Linux terminal, I’ll show you how to compile and upload a program using Ubuntu.

First, install avr-gcc with the command:

sudo apt-get install avr-gcc

Then, compile the code and make it into the right format with the following commands:

avr-gcc -mmcu=atmega32u2 -Os blink-led.c -o blink-led.out
avr-objcopy -j .text -j .data -O ihex blink-led.out blink-led.hex

The resulting file – blink-led.hex – can now be uploaded to the microcontroller. You can find more information on the commands here.

Uploading the code to the MCU

Time to upload the program and see if it works. One way to do this is by using Atmel’s FLIP software. But, once again, let’s see how we can do it with the Linux terminal.

Install dfu-programmer with the command:

sudo apt-get install dfu-programmer

Then, erase the old flash memory on the MCU and upload the compiled .hex file:

sudo dfu-programmer atmega32u2 erase
sudo dfu-programmer atmega32u2 flash blink-led.hex

Unplug the circuit from your computer, then plug it in again. And what do you know, the LED starts to blink!

Blink LED microcontroller circuit

Making something cool

Now that we’ve got it working, we’re ready to make something cool. There are so many cool things you can make with a microcontroller. For example, you can connect it to this Wi-Fi module and make the LED blink every time @AtmelMakes posts a new tweet.

Or, how about connecting it to this sound module and this motion sensor, and make it play a Christmas song every time someone goes near your Christmas tree? As Atmel always says, the possibilities are truly endless.

If you missed any of the previous parts of this tutorial – you can find them here:

3D print your very own working Stargate

While it may not be able to create an actual wormhole just yet, one Maker recently devised her own 3D-printed, Arduino-powered Stargate that actually dials.

HeroWide_preview_featured

Cara McNab brought the project to brought to life using an AT90USB1286 powered Printrbot Simple Metal 3D printer extruding gray (and some transparent ) PLA materials, before adding a stepper motor to drive the inner ring and 5mm NeoPixels to light up the chevrons. To round out the build, the DIY Stargate is controlled by an Arduino Uno (ATmega328) along with an Adafruit Motor Shield that uses a customized Arduino sketch.

IMG_20141122_222202__Large__preview_featured

“The gear was modified to snugly fit onto the stepper motor, and added a hole through which the stepper motor could be tightened to its mount,” McNab notes. “I combined some parts that were 2 pieces into one piece so that the build required less gluing and was structurally stronger.”

IMG_20141124_131346__Large__preview_featured

The entire creation measures just over 16 inches wide, making it a suitable decoration for any diehard Stargate fan — or for those with some serious intergalactic travel aspirations.

Intrigued? Well, travel on over to the project’s official page on Thingiverse here. You may also get a kick out of this ATmega2560 based DIY wormhole actualization machine as well.

Play games on 3DS using a GameCube controller

A common problem among video gamers playing Nintendo 3DS is using the circle pad for prolonged periods of time. In response to frequent hand cramps and broken pads, a Maker by the name of “dekuNukem” decided to mod his 3DS enabling the use of a GameCube controller to play Super Smash Bros. on the handheld console.

nintendo-3ds-gamecube-controller-mod-by-deku-nukem-620x930

In his open-source project, the Maker used an Arduino Nano (ATmega328) to read input from the GameCube controller, then replicate the actions to the Nintendo 3DS with a maximum delay of less than a millisecond.

nintendo-3ds-gamecube-controller-mod-by-deku-nukem-2-620x413

According to dekuNukem, users can also customize and adjust button mappings between the controller and 3DS with a LCD screen, which for his build, he utilized an old phone display.

“When you’re done, simply remove the microcontroller and GameCube cable to make it just as portable as before,” he notes.

Interested in learning more? You can check out dekuNukem’s project page here, and get ready to say ‘so long’ to thumb cramps!

Tutorial: Building cool projects with MCUs (Part 3)

As we proceed onto the third portion of this microcontroller tutorial, let’s first revisit what we have accomplished thus far.

In Part 1, we defined what a microcontroller actually was. I wanted to get everybody on-board (no pun intended) for this, so I started from scratch. Feel free to jump back there if you need a refresher.

Then in Part 2, we looked at the various types of MCUs. And, it turns out that there were a lot! However, by using Atmel’s selection tool, we managed to narrow it down to a few different ones, before choosing a winner — an ATmega32U2. Why? Mainly because it can be programmed through the USB interface without any extra components or tools, and since it did not have too many pins – so we should be able to solder it at home.

Now, the time has come for us to design the circuit diagram. We’ll start with outlining what we need, then we’ll dive into the datasheet to figure out exactly how we can do this.

Microcontroller in a circuit

What Components Do We Need?

If you’ve never done it before, putting all the necessary components onto the circuit diagram is not a super easy task. Well, the process is not that hard; but until you know how to do it, it will seem a bit difficult. So, let me take you through my thought process:

We need to power the chip somehow. There are some pins on the microcontroller that need power. We have to figure out which pins that need power, and what voltage they need.

We also want to program the chip trough USB, so we need a USB connector and learn how to connect it to the chip.

Then, there is extra stuff. Like maybe an LED to play around with, and definitely some connection pins that we can connect other stuff to later when we want to experiment.

So, we need to figure out:

  • How to power the circuit
  • How to connect the USB part
  • How to connect pins to the chip

Using the Datasheet to Find the Details of Our Circuit

The datasheet for the ATmega32U2 is a must when we are designing our circuit. Here, we can find all the necessary technical details.

We don’t have to read it from beginning to end; instead, we simply look up the parts we are curious about, and study them in more depth. We can find a table of contents at the end of the document.

For instance, if we wanted to use the timer of the MCU, we’d look up the part about timers. If we wanted to use the SPI communication part, we would look that up.

Connecting Power and USB

As you probably know, USB devices can be powered through, well, USB. By doing this, we simplify our circuit and require less components. So, let’s do this.

To figure out exactly HOW we can do this, we’re going to read the datasheet. By going to the table of contents, we find that the section that describes the USB part of the microcontroller is on page 186.

Here, there are different images showing how to connect the USB connector to the microcontroller to make it a USB powered device. For our circuit, we’ll use the bus-powered 5V version:

How to setup the MCU as a USB-powered device

Under Design Guidelines on page 189, we find the exact values we need for the resistors. It’s also there that we learn it’s highly recommended to use a 10µF capacitor on the VBUS, so let’s add that too.

Adding a Crystal

Another interesting thing to note from the image of how to connect the USB, is that there is also a crystal and a couple of capacitors connected to the XTAL1 and XTAL2 pins. This gives us the idea that we probably need a crystal too. But why?

Microcontrollers rely on clock signals to work. Every time the clock signal gives a pulse, something will happen in the processor. Most MCUs come with an internal RC-oscillator that can create this clock signal; however, the USB part of the microcontroller cannot operate from this internal clock — it needs a crystal oscillator to work.

To create a crystal oscillator, we need to connect a crystal and two capacitors to XTAL1 and XTAL2. By looking up “Crystal Oscillator” in the datasheet on page 36, we can also identify exactly what crystal and which capacitors are required.

Connecting an LED And Some Pins

By now, we have everything we need for the microcontroller circuit to work. But, we won’t be able to have much fun with it if we don’t add some connections to the input and output pins. And, it’s also good to add an LED. Everything gets better with an LED!

The LED needs to be connected through a resistor. We call this a current limiting resistor — this is to control the amount of current going through it.

From there, we will need a few physical pins that we can use to connect other stuff to our circuit. There are 22 I/O pins on the ATmega32U2, yet some of the pins are used for other purposes (like XTAL2), so we can’t use them all. For this circuit, we’ll add 16 I/O pins, as it’s a nice and round number.

What Else Do We Need?

On MCU circuits, it’s very common to include a RESET button. This makes it possible to reset the MCU without removing the power connection. This will add a couple of more components to our circuit and isn’t necessary to make it work, but it’s very handy, so let’s add it.

In the datasheet, we can see that pin 24 on the chip is the reset signal. It has a line over itself, which means that it’s activated when pulled low.

To make the reset signal stay in a high-state when the button is not pushed, we’ll add a pull-up resistor. This is a resistor up to VCC. And, we connect the button so that it will pull the reset-pin to ground when pushed.

The pull-up resistor should have a value of around 10k Ohm. For reference, SparkFun has a good article on how to choose a pull-up value.

Our Microcontroller Circuit Diagram

Now that we have figured out the different pieces of the circuit, it’s time to put them all into one circuit diagram. By adding everything into one circuit diagram, we end up with this:

Complete microcontroller circuit

Next, we need to create a circuit board out of this. Creating a circuit board does not have to be very complicated. In the subsequent part of the microcontroller tutorial series, we’ll design and make the circuit board.

Stay tuned for Parts 4-5 in the coming days…

Tutorial: Building cool projects with MCUs (Part 1)

I don’t remember exactly when I learned programming, but I played around with computers from an early age. I remember that it was such an amazing thing to be able to make my own programs. I made games and I made websites. And, it was so fun. When I was around 14 years old, I also started playing with electronic circuits. I made simple circuits of blinking lights and such. Also, a lot of fun.

Then at one point, I discovered microcontrollers. Oh, my God. I realized that by using microcontrollers I could combine programming and electronics to build robots, music players and what-not. It was a shockingly cool discovery. Wow!

electronics-project-with-dev-board-and-7-segment-1024x682

But understanding how to use a microcontroller wasn’t straightforward. There were programmers, EEPROM’s, debuggers, integrated development environments and a lot of different types of microcontrollers. It took me a few years before I started building projects using microcontrollers. Not because it took that long to learn it – but because the whole thing felt so overwhelming. And, I didn’t know where to start. But once I committed to just figure it out, it was actually quite fast to get up and running.

In this five-part microcontroller tutorial series, I will take you from knowing nothing – to being able to build and program a microcontroller circuit from home. To make sure we have everybody on board – let’s start from scratch by taking a look at what a microcontroller is.

Like a Tiny Computer

A microcontroller is somewhat like a tiny little computer. And, simiar to a computer, you can hook up things like a display, a motor, buttons and much more to it. Then, you put programs onto it and run them to make it do something.

OLYMPUS DIGITAL CAMERA

The things you can use a microcontroller for are endless! Among the countless possibilities include building robots, flying quadcopters, music players, or even smartphones.

Learning how to use microcontrollers opens so many opportunities for building new cool projects. Throughout this microcontroller tutorial, you will learn all you need to know, step-by-step, in order to get started with MCUs.

Getting Started With Microcontrollers

Let’s start by taking a closer look at the microcontroller chip. The chip has several pins, most of them input and output pins. The microcontroller uses these pins to interact with the outside world.

Atmel-microcontroller-pinout

However, a microcontroller doesn’t really do anything without getting any instructions. So to make it do something, you need to write a program and load the program onto the chip. This process is often called programming the microcontroller.

In the program, you use code to read from input pins, and to control output pins. By connecting something, such as a light-emitting diode (LED) to an output pin, you will be able to switch the light on and off from your program. If you connect a push-button to an input pin, you can use code to read the pin and see if the button is pushed or not.

Then, you can create code that turns the light on when the button is pushed, and turns the light off when it is not pushed. Not a very exciting example, I agree, but a very good place to get started. Think of it as the “Hello World” of microcontrollers.

We could easily turn this into a much more interesting application.

Connect a temperature sensor to an input pin instead of the button. And keep the LED on the output. Create a program that reads the temperature and if the temperature is above a certain level, start blinking the light.

Now, attach this to your beer, and a light will start flashing to warn you that your beer is getting warm. Now that’s useful!

Programming a Microcontroller

Okay, so how do we get from having this idea of what to make, into actually creating it? First of all, we have to create a circuit, then we need to program the microcontroller.

Creating the circuit is a matter of creating a schematic with the components we need, then turning this into a circuit board. I’ll show you how to do this later in this tutorial.

When you have your circuit ready, you need to program your microcontroller. I found this a bit confusing in the beginning. There are many ways of doing this, and not all methods work on all microcontrollers.

The steps you need to go through in order to get your program onto the microcontroller can be divided into the following:

1. Create program code
2. Compile the code into machine code
3. Upload the machine code onto your microcontroller

These steps will be different for different types of microcontrollers. When we get to the programming part of this tutorial, I will show you exactly how to do it for the microcontroller we choose.

But choosing a microcontroller can be a very overwhelming task, especially if you are just starting out. In the next part, I’ll show you what is going through my head when I choose a microcontroller – so that you’ll know how to choose one for your next project.

Stay tuned for Parts 2-5 in the coming days…

Creating an automatic cat laser with Arduino

When it comes to cats, one thing is for certain: They love countless hours of laser chasing. Unfortunately, as a pet owner, there is only so much time in the day to spend twirling around a pointer catering to its innate prey drive. That is why a Maker by the name of Joe recently devised the CatBot, an automated cat laser.

F0W3DW6GZACJ0N7.MEDIUM

Equipped with a pair of servos, an inexpensive laser and an Arduino Uno (ATmega328), the DIY toy will be an immediate hit with your feline friend.

FH5DXMCGZACINAK.MEDIUM

Cat lovers with not enough time on your hands, feel free to thank Joe. Now, watch the device Laser Zeppelin glory below!

Interested in creating one of your own? Head on over to Joe’s official Instructables page in laser-like speed!