Control Arduino Car Using Smartphone

car1

Hello Robotics geeks.

One of the first projects you practice on when learning Arduino is to build a car.
A simple car is a chassis with motors controlled by a motor driver and an Arduino board to operate the movement of the car.

Several methods can be used to control the car, an IR remote, a joystick with an RF transmitter, phone application, or simply make it automated by adding a few sensors (Obstacle Avoidance, Ultrasonic, Line tracker). I will have a post on each method of those, but now I prefer to talk about controlling the car with a Mobile Application since it is much easier now using new platforms like RemoteXY.

RemoteXY allows you to create the app with simple graphics and provides you with the code to program your Arduino board.

Let’s start building our project:

First, build a chassis of your choice and assemble it as follows.

Requirements:

  • Arduino Board of your choice.
  • Motor Driver (L298N H-Bridge).
  • Bluetooth Module (HC-05 or 06).
  • Battery (9V battery).
  • Jumper wires.

car

Now let’s build the application:

We want the car to move forward, backward, right and left, we can add few tweaks too like make it turn around itself in place.

Frist drag a joystick, place wherever you like, and click on it to show the properties.
In the configuration tab, Set the communication method to Bluetooth, select your board, the communication module you’re using, and the IDE you will code on.
Set the connection interface to “Hardware Serial“, the Serial Port to “Serial 0(RX) and 1(TX), and the baud rate to 9600″.
You can add Additional Control like a Centering button or a Gravity sensor button so you can control the car using the orientation of your phone.
Finally, add an ON/OFF button.

appl

  1. Press “Get source code
  2. Download the code into the Arduino IDE.
  3. Install RemoteXY library for Arduino IDE.
  4. Compile the source code and upload it to the Arduino board using the Arduino IDE.
  5. Correctly connect the Bluetooth module to the Arduino board.
  6. Install the mobile app RemoteXY ver.4.1.1 for smartphone/tablet.
  7. Connect to Arduino using the mobile app.

 

Feel free to ask any question.
Think . Build . Code
and stay creative.

Raspberry pi connection to a Server

raspb

//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js

(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: “ca-pub-7488335657740026”,
enable_page_level_ads: true
});

A good idea to take your project to a next level is to communicate with it online, instead of having the data displayed on a screen, you can check all the data on your phone or computer and interact with your PI from anywhere.

The process is easy, it is a small python code, with a PHP script, and a server to host the communication.

A brief description:
we will start by writing the python code on the pi, let’s say we want to send a distance measured by an Ultrasonic sensor, we will write our normal code to measure the distance, and and then we will use a ‘socket’ to send the data to our server. A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to.
The data will be concatenated with an HTTP address linked to the server, where this is the way our PHP script can read the data as an input.

You can also check the code on Github.
Here is the python code:

[sourcecode language="python"]
import RPi.GPIO as GPIO
import socket //importing socket library
import time
import math
GPIO.setmode(GPIO.BCM)
host = "alawiya51.mypressonline.com" //hostname goes here
port = 80
//setting the ultrasonic sensor pins
TRIG = 23
ECHO = 24
print "Distance Measuremnet In Progress"
GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)
GPIO.output(TRIG, False)
print "Waiting for Sensor to Settle"
//Create a method to send the data
def sendData():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) //initiating a socket
s.connect((host , port)) // connecting to the server
time.sleep(2)
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
while GPIO.input(ECHO)==0:
pulse_start = time.time()
while GPIO.input(ECHO)==1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start //measuring the time between both pulses
distance = pulse_duration * 171.50
distance = round(distance,2) //calculating the distance
request = "GET /insert.php?x=" + str(distance) + \
" HTTP/1.1\r\nHost: " + host + "\r\n\r\n" //writing the request
s.send(request) //sending the request to the server
request = ""
print "Distance : ",distance, "m\n"
while True:
sendData();
time.sleep(60) //send the data to the server every minute
done;
GPIO.cleanup()
 [/sourcecode ]

The PHP script will only read the data embedded in the link when called, and it will be stored in a database we previously created.

Here is the PHP code:

[sourcecode language="php"]
echo "Executing: insert.php";
$con= mysqli_connect('hostname', 'database_name', 'your_username', 'your_password');
$x = $_GET["x"];
echo "
x = " .$x. "";
$sql ="INSERT INTO ultraValue (ultvalue) VALUES ('$x')";
mysqli_query($con, $sql); 
mysqli_close($con);
echo "
done";
?> [/sourcecode ]

I hope this was helpful, don’t hesitate to leave any question if you had any problem.
Stay creative and talk to you in the next tutorial.
Continue reading “Raspberry pi connection to a Server”

GY-NEO6MV2 GPS Module

Hello Robotics geeks!!

The Global Positioning System known as GPS is launched 40 years ago, nowadays it works with 31 Sattelite orbiting our earth.
The early use of the GPS was for military purposes, however, today industries brought it to our pockets integrating them in our cellphone and we use them daily in the majority of apps.

The GPS was introduced to the Robotics field too, and it becomes so easy to use when working with microcontrollers, and if you need a GPS for your next project and you want an affordable reliable module, the GY-NEO6MV2 GPS Module is the one to go with.
GY-NEO6MV2 GPS Module

This tiny GPS Module can connect to 4 Sattelite and it is pretty accurate.
The library I use to interact with this module makes getting coordinates very easy., just add it to your libraries, connect the module, and run the code below.
You will need to download SoftwareSerial library to communicate with the module.

gps

To check if the module is properly connected to a satellite, a red led should blink on it.

Here is the code:

Code

The library has few useful examples too, so go and try them yourself.

That’s it!! Best of Luck guys. Feel free to ask anything and suggest what sensors do you want me to blog about.

Think . Build . Code

Arduino Workshop for beginners

work

Hello Guys, I know the internet is filled up with Arduino courses, but sometimes you will be looking for few slides to introduce beginners to Robotics through Arduino.
The first file is an introduction to Arduino, board, pins, and code. The slides contain headlines with a small explanation, so of course, you should do the rest of the work, I recommend Arduino Official Website to build a well-structured knowledge on Arduino as a teacher to pass it to students.

The second file covers the most important sensors used along with Arduino like Ultrasonic, temperature sensor, motor drivers, and motor drivers, which will show students how Arduino interacts with sensors, how to read their data, and how to use them properly.

Arduino_Introduction
Arduino_Extentions

Please suggest any edit or new ideas, this post will be updated everytime I create a new version or add new info.

And soon I will upload a full curriculum for schools for teachers to follow.

Mr. Robotrick

roboschool

Hello Robotics geeks, my name is MAC. This is my first post on my blog. I created it to share my ideas and experience in this awesome domain. I have a bachelor degree in Computer Science, and I worked in several companies until I decided to follow my dream and start my own business.  Now I teach students in schools and universities how to code, design, and build their own projects. We mainly use Arduino as the brain of our robots, some f my students mastered the work so I moved up a level with them and start programming on a Raspberry Pi. I want a generation of robotics geek, I need my students to unleash their creativity and take a strong step into a world of Robotics, AI, and VR with the required knowledge to make a difference.

Please, feel free to ask anything, I will work on making two posts per week. My posts will cover Arduino boards, sensors, projects, raspberry pi, courses, quizzes, and a lot more. I will be glad to create posts based on your suggestions.

Talk to you soon friends!!

Think . Build . Code