Showing posts with label arduino. Show all posts
Showing posts with label arduino. Show all posts

Monday, 16 December 2013

Building a simple two servo walker

School's out! Its been an extremely crazy few weeks at school so I'm falling behind in all the documentation of the random tiny experiments and projects I've been working on lately.

This morning I tried to make a two servo walker for fun. Something relatively uncomplicated. There are many tutorials online for one servo walkers (eg: B.E.A.M walkers) with something called a bi-core, which is a simple oscillator that allows it to produce more complex behaviours, and which also involves some gears (which I do not have). So I decided to try to build a simpler two servo walker.

PC168287

This was my simple design for the walker's feet. The script I used was a very basic edit to the default servo "sweep" script which probably needs no elaboration on how to use... because it just works.

PC168284

Assembling it together - I used an Arduino Uno, two mini servos, a small breadboard, some garden wire, mounting board and electrical tape. In my mind, having the front legs go in a different rotational axis seems to make sense so that the feet will lift off the ground. [Later I did try making them on the same plane (but opposite directions) and it did not work as well... but this is a design that can certainly be improved on...]

PC168285

One hour later and we're already done!

PC168286

Not terribly complex but it does walk about slowly...

Sunday, 4 August 2013

Simple Colour-changing Ambient Lamp (Arduino + 3 LED)

P8034922

In this continuation of posts on learning to do the most basic of things with the Arduino, the next experiment I made was a colour-changing lamp with 3 different LEDs. I followed this simple instructable but edited slightly. I noticed there were lots of "#define" in the instructable - it seems that #define is something from C that is for defining a constant. What is the difference between using #define and int to define which pins each LED is controlled via? Well in practice nothing much seems to be different except the conceptual difference is that #define is for defining a CONSTANT whereas technically speaking an int would be initialising a VARIABLE that can be changed later on in the program, although in this case we don't really intend to change the pin number. But we could, if we wanted to.

Things with # in front of them like #include and #define are preprocessed before the program compiles. Also, apparently #define does not take up any program space, whereas int is stored as variable in RAM. For more info see this wiki entry on C Preprocessor.

Colour Changing Lamp


For this you'll need: an arduino uno, 4 jumper wires, 3 LEDs of different colour, and 3 x 330ohm resistors

int delayTime = 2;
int maxBrightness = 255;
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
int red = 0;
int green = 170;
int blue = 170;

// Indicates whether a color will be incrementing (1) or decrementing (0) in brightness
int incR = 1;
int incG = 1;
int incB = 0;

void transition()
{
  if (red >= maxBrightness)
    incR = 0;
  else if (red <= 0)
    incR = 1;
  if (green >= maxBrightness)
    incG = 0;
  else if (green <= 0)
    incG = 1;
  if (blue >= maxBrightness)
    incB = 0;
  else if (blue <= 0)
    incB = 1;
  
  if (incR)
    red++;
  else
    red--;
  if(incG)
    green++;
  else
    green--;
  if(incB)
    blue++;
  else
    blue--;
}

void setColor()
{
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
}

void setup()
{
  // do nothing
}

void loop()
{
  transition();
  setColor();
  delay(delayTime);
}
ambientled_bb

Stopping an Arduino Sketch

Now that you have this running, you might want to know how to make sketches stop. This baffled me for some time. My solution was eventually to create a blank sketch and to run it.
void setup(){}
void loop(){}

See also: Simple Light Meter (Arduino, Photocell and Servo)

Friday, 2 August 2013

Simple Light Meter (Arduino + Servo + Photocell)

Today I almost attended a 24-hour programming contest but at the briefing I decided I didn't fancy sitting there overnight, or being told where I can go and can't. So I simply left. Since the point of me signing up for such an event was mainly to force myself to set aside a little time to figure out how to use Arduino, I sat there for a little while looking up what I was interested in exploring, and went to Sim Lim, where I bought a few bits and bobs and a little servo - and then went home and made my own dumb experiment...

Arduino Uno + Photocell + 1 kΩ Resistor + Small Servo


P8024918

BRIGHT!

P8024919

DARK...

Okay this is basically a superbeginner mashup of these two basic tutorials: Adafruit's Making Sounds (Lesson 10) + Adafruit's Servo Motors (lesson 14). Well I guess I gotta start somewhere so don't laugh at the simpleness of this. I'm just writing it out here because I will probably forget it all if I don't write it down properly, and god knows actual hardware is an undiscovered country for me.

#include  
 
int servoPin = 9;
Servo servo;   
int angle = 0;   // servo position in degrees 
int photocellPin = 0;
 
void setup() 
{ 
  servo.attach(servoPin); 
  //Serial.begin(9600);
} 
 
void loop() 
{ 
  int reading = analogRead(photocellPin); 
  int newAngle = reading/3 - 100;
  //Serial.print(newAngle);
  //Serial.print("\n");
  servo.write(newAngle);           
  delay(60);  
} 


Fritzing


I made a sketch of the above with Fritzing. Fritzing is a useful tool for designers and programmers to design and document their prototypes for pcb boards, arduino-based and other electronics projects. Drag and drop and pull...

Untitled Sketch_bb

Screen Shot 2013-08-03 at 12.00.39 PM.png

Sunday, 7 July 2013

Disconnected from the Internet of Things in Singapore

Yesterday I attended a training for Arduino and Windows Azure at the Singapore Science Centre. Part of a training session conducted in the run-up to a programming contest organised by the ITSC to be held on the 2nd August, the initiative seems generally well-intentioned, but perhaps, ever so slightly lagging with the times. You know, the same feeling one gets when one first hears about Windows Azure... "Um, isn't it kinda almost too late for Windows Azure to try to compete with Amazon Web Services to be the biggest public cloud provider...? What exactly is the difference anyway?"

Nevertheless I'm always keen to explore to new classes about things that I don't know about because sometimes you find interesting leads from them. So I thought I'd give Azure a chance, hopefully find out how its different from AWS. I mean, sometimes one is very pleasantly surprised about how excellent some of these free classes can be - for example, once I attended a brilliant Rails for Girls class (walking us through Railsbridge's curriculum); it was a joy to learn and we all made something up and running within a day, and the instructors were so generous and patient with everyone...



Unfortunately, this is not going to be one of those happy stories.

If the tutorial was to inform people about the bigger picture of why its important to explore new technologies like Arduino, Windows Azure, xively, etc, then I suppose that was achieved. However, if this tutorial was to arm its attendees with the actual practical skills to do it, then this drew a complete blank.

For an introduction to connecting Arduino to the internet, you would have thought they would have informed attendees to get and bring an Arduino and Wifi shield in advance, in order to make the session more meaningful. The Arduinos connected to the computers in the lab were resultantly just for show, because without the wifi shield we could not follow the example shown on screen, and staring for half an hour at the code on the big screen was generally pointless, even if I could follow the instructor's general reasoning and chain of thought.

The room used for the training had Windows computers stuck in the dark ages - only running IE8, meaning that sites with minimum browser requirements such like xively (which was being demoed) could not run on them. The most bizarre of all was that the room where the talk was held did not have a free/open or reliable wifi connection, which you would imagine, IS SOMETHING THAT WOULD BE VITAL WHEN CONDUCTING A TALK ON HOW TO USE THE WIFI SHIELD FOR ARDUINO? How does the Science Centre NOT have its own wifi network? Why is the Wireless@SG there so infuriatingly slow to the point that trying to surf the internet was like trying to eat jelly with chopsticks? I could only facepalm in the corner as the instructor asked people if they could ping him to see if he was online. My iPhone-tethered 3G connection was disappointingly slow from that location as well.

The software introduced was not free or open source, although there is 30 day trial for Azure. The signup for Windows Azure requires a credit card authorization (similar to AWS) although you will not be charged, something which I suspect most of the secondary school students in the room would not have been able to provide on their own. I could not immediately find a simple way to access their educators schemes as well, it required the educator to submit lesson plans involving Windows Azure in order to obtain an educators' pass for students and educator.

The free trial comes with up to $200 credits, although this was sadly not explained in terms of what $200 amounted to in services. On the other hand, I should note that at the AWS seminars which I attended in the past (and which were attended by working professionals), the payment charges and estimated payments for types of volume of service were explained in detail.

A survey of the room showed that none of the attendees besides myself had dabbled in making mobile apps before (and I have only dabbled on a very low-level), thus any deeper discussion of the technical aspects of Windows Azure was probably lost on many, which was a real pity.

Nevertheless, the Microsoft instructors made a good go at "selling" to us the overall importance of understanding the internet of things and the wide and amazing possibilities of what we could explore making. Pity he was already speaking to the converted though - because I mean, if I dragged myself OUT OF BED at 7.30AM ON A SATURDAY MORNING to travel from the eastside to the distant unholy nether regions of Jurong East to attend this talk at the Science Centre, you'd better damn well believe that I already have a pretty good interest in wanting to learn more about the internet of things!

As someone who has spent a little time being an instructor (AS3), I know that I have a tendency to be very critical about how people conduct any form of IT/programming instruction. And I know its also hard to teach even if you are brilliant at the language - teaching is another thing entirely. But I think it is really important for IT education to be conducted PROPERLY and thoughtfully. I think a lot of people are put off from doing programming and learning technical stuff BECAUSE the classes are terminally dull, are intimidating in terms of what they expect you to know already before coming to the class (they did not ask what level of programming or what languages people used, so for all we know all that json or processing-type stuff they were showing on screen could have all been complete gobbledygook to the attendees!!!). And as usual, it was not really a female-friendly environment either, there were maybe a total of 4 females amongst a couple dozen males, and THE WHOLE COMPUTER LAB WAS PAINTED FROM FLOOR TO CEILING IN BLUE! Talk about overkilling on the gender signifiers...

Anyway the most important thing I want to say is:

DON'T HOLD A TALK ABOUT THE INTERNET OF THINGS
IN A ROOM WITHOUT RELIABLE WIFI!!!




But on to more productive things. Instead of trotting to the Science Centre again, I think I should embark on my own self-study of how to build small projects with Arduino and Raspberry Pi here instead. And yesterday to the credit of one of the instructors, he did introduce something called xively, a service that one can get up and running in a jiffy:

xively.com

Some might remember this as pachube, and them cosm. Xively is a cloud service that allows you to store data points collected from sensors on objects/devices/buildings on the web. From there, you can develop apps and other programs to use this data intelligently. The free option on xively allows you to connect up to 5 devices.

Within five minutes of signing up you can get a very simple example working with any smartphone - the test drive shows you an example of a "package" with gps and gyro sensor (in this case, your phone) and allows you to see what direction it is tilted at.

IMG_8637

On the iPhone

Screen Shot 2013-07-06 at 10.30.45 AM.jpg

On the xively site

Real-time visualizations can be made on websites, real-time alerts can be sent out triggered by the datastream, from which other devices or environments can be controlled and changed, or scripts can be triggered. In this example, if it is shaken too violently, it will indicate a Warning alert on the site in real-time. In the workbench, you can see all the numbers changing in real-time.

Screen Shot 2013-07-06 at 10.34.11 AM.jpg

Workbench

So getting the datastream online is so very easy and all the historic data will also be stored in case you should need to use it later on. It looks like a quick and easy solution to hooking up devices and sensors to the internet in real-time! And it is all connected up online and completely in real-time...

Well, that is unless you're in a room disconnected from the Internet. Because god knows, you certainly won't be connected to the Internet of things if you're in a room without the Internet. It should be SO BLINDINGLY OBVIOUS, but hey, case in point...

DON'T HOLD A TALK ABOUT THE INTERNET OF THINGS
IN A ROOM WITHOUT RELIABLE WIFI!!!




I didn't get to mention about Windows Azure because the introduction I had at this training session was very brief and I was too busy in the month to play with Azure. Nevertheless to their credit, a customer service officer DID call me back to ask me if i had problems or questions with it. Pity I had no time to explore it further in the month...