Skip to Content
Author's profile photo Former Member

Let’s build a robot! Part 1: Let there be light

Excuse the expression, but men’s urinals are smarter than computers. Computers are isolated from what’s around them.

Alex Pentland, academic head of the MIT Media Laboratory

I still remember the time I received my first printer. It was a great feeling to see how my computer was creating things. Having worked with computers for a few years back then, all my creations had been only virtual. And suddenly it changed. Think outside of the box started to mean something different and I was able now to make things (just printouts, but it really felt great back then).

Now that printers are a commonplace thing, and 3d printers are becoming a commodity, the ability to create things using our computers is more or less given. The next frontier is to have our devices interact with the real world – perceiving the world through their sensors (just think how many sensors you have in your phone), and changing it through actuators (not many of them yet – but our devices already make sounds, vibrate and blink, and there’s more to come). And like in the quote above – our computers are a bit behind – even urinals can now sense a person in front of them and flush after the person has left. My PC will not flush water, no matter how sophisticated code I am going to write! My computer doesn’t have arms or legs, it cannot really interact with the real world.

This is exactly why I find robotics a super exciting field. I’ve been playing with tin robots as a kid, I had robots all around me at home – I have Roomba, Scooba, Dirt Dog, you could argue that a washing machine is a robot too! But I don’t have that many robots at work – I wonder why. And so I want to build a robot that I can hook up to an SAP system (HANA!) and make it do some cool things based on the data it can access. Yes, “some cool things” – that’s exactly how specific I want to be with my goal!

Starting with this post, I want to take you through the process of building a robot. The intention is to explain every single step of what I am doing, so that you can build something too! I will be using cheap and common electronic components. Oh, and by the way – as I am writing this post, I have absolutely no idea what the outcome is going to be. So feel free to suggest the next steps in the comments!

Disclaimer: I do not know much about electronics, I am an amateur and have no idea what I am doing. Sometimes I might be writing things that are not precise, or completely wrong. Read on, try these things out, but at your own risk. 😉

Let there be light

Let’s start with a super simple example and build a small circuit that will blink a LED. This is the “Hello World!” of electronics. In this example I am using an Arduino Uno board, a super simple microcontroller. You can buy original Arduinos for less than $30 online, and since it is an open-source hardware, you might be able to find way cheaper clones too. If you don’t yet have an Arduino board, it’s a good idea to buy a kit – with a few components and a breadboard for prototyping. You’ll find great choice online!

The hardware

Here is my setup: my Arduino Uno and the breadboard. You can see a number of pins on both sides of the board. There are pins for power and analog input on one side, there are also digital pins (input/output) on the other side. The top end of the board has a USB port for communicating with a computer and a power port for independently powered projects (in the beginning we will just use USB as the power source). There’s also a RESET button right next to the USB port.

/wp-content/uploads/2013/09/arduino_277548.jpg/wp-content/uploads/2013/09/protype_set_277549.jpg

For the project in this post, we will need four more pieces: two wires, one LED, one 330 Ohm resistor. Oh, and a USB cable to connect to a computer (not in the photo).

/wp-content/uploads/2013/09/cables_277604.jpeg

The software

Arduino comes with a super simple IDE for writing programs (called sketches) which, after compiling, are sent to the board. The programing language is an implementation of Wiring, but it doesn’t matter that much now. You’ll see in a second that it’s super simple. Arduino IDE can be downloaded from the main Arduino site: http://arduino.cc/en/main/software

Here is a screenshot of the IDE. It comes with a lot of sample sketches, and I have opened one which we will use in this blog.

IDE.png

The top bar has only six buttons, and they are used for: (1) Verifying the code, (2) Uploading the compiled code to the board, (3) Creating new sketches, (4) Opening saved sketches, (5) Saving sketches, (6) Opening the serial monitor – more on it later. There is a console view at the bottom of the screen, and that’s pretty much it!

Go!

Let’s first set up the circuit. Arduino Uno has 14 digital pins (0-13). They are the best for on-off scenarios, basically whenever we need to switch something (or read a binary value).LED.jpeg

  1. I have connected the LED to pin 13. To make the process easy, I  use the breadboard and connect the red cable from pin 13 to the first row in the breadboard.
  2. The first row is also where I insert the cathode (plus) end of my LED – this is the longer leg of the LED. All the rows in the breadboard are connected horizontally (apart from the two outermost “columns” on both sides for providing power, but let’s ignore it for now), so this setup means that the red wire and the cathode will be connected.
  3. Next, I have inserted one end of the resistor in the second row (so that anode/minus) of the LED is connected to it. I also put in the other end of the resistor a bit below and the white cable next to it. The resistor is required to control the current flowing through the LED. Or so I am told. Without it, the LED will initially burn pretty brightly, and after a while it will burn out (like I said, I am an amateur here, I am sure you can tell).
  4. As a final step, I am connecting the white cable to the GND (ground) pin in the Arduino, to complete the circuit. Now the current can flow through it, and by controlling the state of pin 13, I will be able to turn the LED on and off.

With this setup we are done, and we can switch to the software part. Remember: connect the white wire to GND on your board, and the red one to pin 13.

Now to software. The sample sketch, which I am pasting below, is really self explanatory. The only thing you should now is that the typical Arduino sketch consists of two main blocks: setup(), which is executed at the beginning (after starting/resetting the board or after uploading a new program to the board) and loop(), which is continuously executed while the board runs.

// Pin 13 has an LED connected on most Arduino boards.

// give it a name:

int led = 13;

// the setup routine runs once when you press reset:

void setup() {               

  // initialize the digital pin as an output.

  pinMode(led, OUTPUT);    

}

// the loop routine runs over and over again forever:

void loop() {

  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)

  delay(1000);               // wait for a second

  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW

  delay(1000);               // wait for a second

}

Note the very first comment: yes, most Arduino boards have a super small LED on the board itself. It happens to be pin 13 too. So in this sense our hardware setup is redundant. If you don’t like the idea of using pin 13, just switch to another one – let’s say pin 12 – and update the code. The LED on the board will not be blinking anymore.

Now  the final step of verifying and uploading the compiled code to the board: just connect the board to your computer using a USB cable, ensure the IDE knows where your board is, press the right buttons and voila – the LED should start blinking! If you have an external source of power (could be a USB battery pack, or a charger connected to the power port), you can unplug the board from the computer and it will operate independently.

/wp-content/uploads/2013/09/blinking_277643.jpeg

We’re done!

With this super simple “Hello World” example, I wanted to introduce the basics of microcontrollers. There are many more steps we need to take before we build a robot that can interact with an enterprise system. Slowly but surely we will get there!

What’s next?

So far, our LED has been blinking independently. But what if we wanted to have more control over it? In the next post I am going to show you how we can control the hardware from a computer – press a button to turn the LED on, press a button to turn it off. This can be a basis for a simple “If This Then That” scenario. Further on this will help us understand how to control hardware over the network (from an SAP system? why not!), and sooner or later we might try to replace the LED with a robotic arm… Stay tuned!

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Witalij Rudnicki
      Witalij Rudnicki

      Should we think about creating a new subspace on Developer Center? Something like "Internet of Things" or so, discussing building, wiring and connecting things?

      The topic is certainly trending now thanks to rapid technology advancements, enthusiastic community involvement and price reductions. There is even the whole new conference Makerland on "Hardware for Software Developers" coming next year in March to Warsaw: http://www.makerland.org, and workshops with 3D modelling and printers, Arduino, Lego Mindstorms, Bluetooth 4.0 and microlocalization in November for those who cannot wait too long http://meetup.makerland.org 🙂

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hey Vitaliy - I like your idea. Let's just wait first to see whether we have readers interested in the topic! I am preparing a next post on making things move and controlling them from a computer. I've also just received pieces for a robotic arm - this will come soon too.

      I think this is a great opportunity for software developers to start building robots. There are so many cool things coming, among them BrickPi - I will play with it soon too! 🙂 I like the idea of having a Linux in a Lego toy!

      Author's profile photo Paul Aschmann
      Paul Aschmann

      Hi Guys,

      I too am a big fan of Arduino (I recently built a motorized slider for my DSLR & Timelapses), I enjoy the topic and agree it would be nice to have some cross over on SCN where people can share their experiences and ideas.

      Stepping outside of the Arduino space I am looking forward to products like Wimoto and their integration with the enterprise 🙂

      http://www.indiegogo.com/projects/wimotos-tiny-wireless-helpers-for-your-life--47

      I also have a free SAP HANA App I plan to release shortly which will also start to display some opportunities 🙂 We just need the hardware to catch up! 🙂

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      I love Wimotos, never heard of them before, but it was love at a first sight! I agree, there's a lot of interesting opportunities ahead! The best thing is - even with Arduinos, we can effectively prototype most of what Wimotos offer. It would be just much bigger and also more expensive (but parts can be reused for other projects).

      Can you share more details about your HANA app? A blog post soon? 🙂

      Author's profile photo Paul Aschmann
      Paul Aschmann

      Yes, a blog post will be coming soon and the app - I hope I have not set too high expectations now though 😉

      Re: Wimotos + Arduino - yes you are 100% correct