NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Skateboard project, new to programming.

February 04, 2010
by SkateboardTeam
SkateboardTeam's Avatar

As part of a Senior Project at my high school, I am working on a team to design and build a motorized skateboard. Our teacher said that we needed to include a safety mechanism, so we have decided to build a docking station for the board that will not release the skateboard unless someone who weighs at least 115 pounds will step on a scale attached to the docking station. I plan to use the NerdKit and some motors to make this work. Here is my general idea: The LCD will display "Please step on the scale" then, once a person steps on the scale, the NerdKit will evaluate their weight and if it is less than 115 pounds, the LCD will read "Sorry, you do not weigh enough to ride the skateboard" If they weigh more than 115, the LCD will display "Enjoy your ride" and the NerdKit will power a motor which will raise a bar off the board so that it is no secured to the docking station. At this point a person will be free to take the board. I plan to follow the "Digital Scale Strain Gauge Weight Sensor" tutorial on the website for tips on how to work with a scale. I have adequate resources to complete this project, like time, motors and money, however, I'm still a little lost on how I might write my program. Does anyone have suggestions? All suggestions are helpful, thanks again!

February 05, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi SkateboardTeam,

It sounds like you have a very interesting project in mind. My suggestion is to take it step by step, break the problem down into its different components and tackle them separately. The first thing I would do is try to interface the MCU with a digital scale. As you mentioned, you can pretty much follow the example at our Weigh Scale Tutorial. Once you have that working, think of the physical restraint for the skateboard. You might need to interface with motors to move the bar that is locking the skateboard Motors and Microcontrollers. Once you have those projects working separately, you can think about how to integrate them together into your working skateboard restraint. Let us know how your project moves along, and be sure to ask for help if you get stuck. There are plenty of friendly people on the forums here ready to help.

Humberto

February 15, 2010
by SkateboardTeam
SkateboardTeam's Avatar

Hey,

Thank you for your input. I have an idea about how I want to make this project work, but I'm kind of frustrated with the difficulty of programming. Maybe I'm just approaching it wrong, but I have absolutely no idea at all how/why the programs run the way they do. I've read the NerdKits guide over and over but when it gets to embedded programming I am lost. It says to read the datasheet to learn more about how to program and use the analog to digital function, but I dont really know where exactly to look and the datasheet is over 300 pages long. Is there any website or source that can teach me from the ABSOLUTE beginning on how to program the microcontroller? I have plenty of time on my hands to learn this, and plenty of ambition, but just do not know where to start.

Thanks,

Julian

February 15, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Julian,

I think the motivation you have to get going will be more than enough to get you through the initial frustration of not having any clue what is going on! Try stepping a bit from the temperature sensor tutorial and take a look at the blinking LED project, and the bitwise arithmetic project both in the guide. These two are much simpler projects that I hope will give you a better idea of the way we program microcontrollers, and how to approach the problems that arise.

The best way to learn really is to go for it and ask any questions you have along the way. There plenty of folk here eager to help. Remember to break the problem down and solve little chunks of it a time.

Humberto

February 18, 2010
by SkateboardTeam
SkateboardTeam's Avatar

Hey,

I followed the blinking light tutorial. I still am extremely confused about certain aspects of programming, but at least I believe I know what direction to get started in for this project. I think rather than using a motor to retract the skateboard, we are going to use a pneumatic cylinder. The way we will do this will be to add a small metal latch to the top of the board. The pneumatic cylinder will go through the latch on the top of the board to restrict the board. If a weight of over 125 pounds is detected, the nerdkit will have the cylinder retract from out of the latch and free the board.
My question is: If the NerdKit can only run 5 volts through it, how do I power a pneumatic cylinder (or a motor) that runs on more voltage. Would a relay work for this purpose? My second question is: When programming, how do I go about specifying which pin will be used as an output? I'm sorry if this is an extremely basic question, I just am not sure where to look in the datasheet for this fundamental info.

Thank you again for all your help,

Julian

February 18, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Julian,

Glad you are making some progress on your project. It is great to see you are getting more into the planning stages of figuring out what you are going to use. In order to power devices that need more voltage you do need to do something other than powering straight off the NerdKit. You can see that we did just that using a MOSFET in the motors tutorial. The motor is running off a 12V power supply, but is being controlled by the NerdKit via a MOSFET. You could also use a relay if you want to.

For your programming question. The "direction" of a pin (whether it is an input or an output) is determined by the DDRX register where X is the letter that your particular pin belongs to. So if I wanted to make PC4 into an output pin. I would do

DDRC |= (1<<PC4);

Note how what I am doing is setting a bit on a register, that has a physical effect on how the pin behaves. To set it back into an input pin, I would have to set that bit back to 0 (I'll let you figure out to do that). Does that make sense?

Humberto

February 19, 2010
by SkateboardTeam
SkateboardTeam's Avatar

Hello,

First of all I want thank you for all of your help. It has been really great getting quick and knowledgable responses by someone who is so familiar with the field. Your last response taught me a lot, and I think we will use a MOSFET. Our pneumatic switch runs off of 24V, would this also be possible on a MOSFET? I understand how to set an input and output now, and how to power them. However, I need to ask the ultimate beginners question: how does a pin in the programming such as "PC4" or "PC1", etc. relate to the physical pins of the microcontroller? Early in the NerdKit guide, the pins are referred to as pin 1-28. When it gets to programming, they are referred to as PC1, and things like that. Sorry for asking such basic questions, but I cannot express how much I appreciate the help!

Thanks,

Julian

February 19, 2010
by bretm
bretm's Avatar

The atmega168 datasheet (which you can download from this site) shows this on the very first diagram, Figure 1-1 on page 2.

PB0    14
PB1    15
PB2    16
PB3    17
PB4    18
PB5    19
PB6    9
PB7    10

PC0    23
PC1    24
PC2    25
PC3    26
PC4    27
PC5    28
PC6    1

PD0    2
PD1    3
PD2    4
PD3    5
PD4    6
PD5    11
PD6    12
PD7    13
February 20, 2010
by SkateboardTeam
SkateboardTeam's Avatar

Bretm,

Thanks for the reply. I admit, I feel pretty clumsy now for overlooking that. I looked at that diagram several times, but by some miracle/inexperience I didn't even recognize that it contained the just information I needed. I just sort of incorrectly assumed the datasheet contained 300 pages of information that I would never really understand or use. Thanks again for helping a newbie in need :)

Julian

Post a Reply

Please log in to post a reply.

Did you know that negative numbers are represented in two's complement notation in binary? Learn more...