Linux Format

Arduino-powered robot

Les Pounder shows us how to build a web-controlled robot using the Arduino IOT Cloud.

-

Les Pounder builds a web-controlled robot using the free Arduino IOT Cloud.

Building a robot with an Arduino is great fun, but building a web-controlled robot is much more fun. In this tutorial we will build a simple robot that will be controlled using the Arduino IOT Cloud. We will create a button to start the robot, and write the code to control how the robot moves – all using the familiar Arduino programmin­g language.

In this project the Arduino Nano 33 IOT connects to an L9110S motor controller so that when GPIO pins on the Nano are turned on and off, they trigger the L9110S motor controller to turn on a motor in a specific direction. To power the motors we use four AA batteries; to power the Nano 33 IOT we use the USB battery.

The circuit is built using a breadboard to connect everything. See the diagram on the opposite page to ensure your circuit is correct.

Plug in your Arduino Nano 33 IOT and in a browser visit https://create.arduino.cc and create a new account. When prompted, install the Arduino Create app. The app will detect your Nano 33 IOT board, and make it available to the Arduino IOT Cloud. You will be asked to set up the crypto chip on the Nano 33 IOT. This is essential for a secure connection the Arduino IOT Cloud.

The Arduino IOT Cloud is split into six sections, but for this tutorial we will only need the Arduino Web Editor (where code is written), Device Manager – where we can add/edit/delete Arduino boards– and the Arduino IOT Cloud, where ‘things’ are made.

Create a thing

A ‘thing’ is a device connected to the internet and programmed using the Arduino IOT Cloud. Click ‘ADD NEW THING’ and give your thing the name ‘Robot’ and link it to your Nano 33 IOT board, then click Create. You will now be taken to the page for that thing.

We have four tabs, but we only need to refer to Properties and Dashboard in this tutorial. In the Properties tab click ‘ADD PROPERTY’ and a new menu opens. In this tutorial the ‘property’ is a switch which, when pressed, will trigger our code to run. In the new menu we need to name the property – in this case call it ‘button’ and set the variable name to ‘button’ also. The type needs to be set to ON/OFF (Boolean). Finally, click Save.

To spin the robot left, the next function will move one motor forwards, and the other backwards. void left(){ digitalwri­te(6, LOW); digitalwri­te(5, HIGH); digitalwri­te(8, LOW); digitalwri­te(7, HIGH);

}

And here is the code to spin right. void right(){ digitalwri­te(6, HIGH); digitalwri­te(5, LOW); digitalwri­te(8, HIGH); digitalwri­te(7, LOW);

}

The last function will stop the robot moving. void stop(){ digitalwri­te(6, LOW); digitalwri­te(5, LOW); digitalwri­te(8, LOW); digitalwri­te(7, LOW);

}

In the setup section of code we need to add a few lines to configure the GPIO pins. In this case we are using pins 5 to 8 as outputs.

pinmode(8, OUTPUT); pinmode(7, OUTPUT); pinmode(6, OUTPUT); pinmode(5, OUTPUT);

The final section of code is triggered when the button is pressed. In a section of code called onbuttonch­ange

we will write code to move the robot if the button has been pressed. Each movement will have a delay of three seconds between it, and a debug message is printed to the serial monitor. First we print a message, then check to see if the button has been pressed, and if so we print another message.

Serial.print(“the robot is... “); if (button) {

Serial.println(“dancing!”);

The if condition continues by calling the pre-written functions to handle moving the robot.

forward(); delay(3000); reverse(); delay(3000); left(); delay(3000); right(); delay(3000); stop();

What happens if the button is not pressed? The else

condition is activated and so we indicate that the robot is “resting”.

} else { Serial.println(“resting”); } }

Upload the code

That’s all of the code for this project; and now we should save before clicking the upload button (an arrow pointing right), which sends the code to the Nano 33 IOT connected to our computer. This will take around two minutes to complete. Click the Monitor link to see the board connect to your Wi-fi and then state that it is resting. Your robot is online! Now click ‘GO TO IOT CLOUD’ and in the new screen click ‘Dashboard’. Click the button to turn on the robot, and watch as it moves!

Remove the USB cable to your computer and now plug in the USB battery to the Nano 33 IOT. After 30 seconds the robot will connect to the Arduino IOT Cloud, and you can now press the button once again and watch the robot drive off around your home. Try adding some new functions!

 ??  ?? This robot can be built for under £30, and in the maker spirit, it uses easily sourced components – leaving you to focus on coding.
This robot can be built for under £30, and in the maker spirit, it uses easily sourced components – leaving you to focus on coding.
 ??  ?? OUR EXPERT Les Pounder is a freelance maker who works with organisati­ons such as the Raspberry Pi Foundation to promote maker skills.
OUR EXPERT Les Pounder is a freelance maker who works with organisati­ons such as the Raspberry Pi Foundation to promote maker skills.
 ??  ?? The schematic for this project’s wiring.
The schematic for this project’s wiring.
 ??  ?? The robot is coded using typical Arduino code, which is easy to read and understand, even if you are new to code. Remember to save often!
The robot is coded using typical Arduino code, which is easy to read and understand, even if you are new to code. Remember to save often!

Newspapers in English

Newspapers from Australia