IAN LANG ELECTRONICS

Hacking a 27MHz Transmitter to Control a Toy Car by Arduino and Host PC.

That is probably the longest title you're going to find on here. But it does what it says on the tin. We're going to attach the Arduino to a 27MHz transmitter, make an interface in Visual Basic and control the car from the interface. Why? Because I want to. And if this works, the sky's the limit on what I can control by radio control.

 

In this project, we're going to marry together a few of the concepts looked at in twenty or so chapters and develop the ideas a bit. You'll need Visual Basic 2010 to start with, and of course a radio-controlled  car.

Mine came from Primark. I have a large collection of really stupid T-shirts and the above named shop is a very rich seam for acquiring new ones. I particularly liked the one I got with the slogan "Push it. Push it real good." and above that a picture of a Hoover. They do a good line in Daffy Duck themed T shirts as well, not to mention Danger Mouse.

 

But I digress. I was mooching round in Primark looking for T-shirts that fit my stupidity criterion when my eye alighted on the RC Car as left. It cost me the stupendously large sum of six whole pounds and got me wondering if I could hack the TX to make it work with a PC via an Arduino UNO.

It turns out that of course I could- you can do almost anything that requires the movement of electrons if you've got an Arduino. On the right is a small video showing the car on the move, and subsequently crashing into a laptop bag as I am in fact a very bad driver.

 

The movement is controlled by an interface built in Visual Basic 2010 and this feeds serial data to the Arduino. The data the Arduino gets depends on the event happening on the interface, and whichever data it gets causes either pin 2,3,4 or 5 to be in mode output or input.

 

Testing found that when low, the terminal of the transmitter becomes active, and so when an output the pin allows the command, when an input it doesn't. But first we need to make that interface. Here's mine:

The idea is that you waggle your mouse over the red buttons (which are in fact made from oval shapes) and the result is fed to the Arduino as a byte of data which is in fact a single character. The Arduino receives this as an ASCII code and does the appropriate action for whatever has been received.

 

The whole thing is done through the USB port to the UNO and so you need to include in your VB program a serial port and set it to the COM port  that your Arduino is on. The little video below shows the thing at work.

As you can see it is very simple indeed. All you need to do is to solder some jump wires to the terminals that normally would accept input from the levers on the transmitter unit. The Arduino provides the drain and the power supply.

 

In fact you could probably take the TX board out of the transmitter and build yourself a shield rather than the wiring solution I've done here. I on the other hand just couldn't be bothered- you know I'm lazy. Here's some wiring:

Go Back

So, that's pretty much run the gammut of the tangible systems then. All we need to look at now is the code.

 

I'll start with the Visual Basic. Before I do, bear in mind the names of the red buttons on the interface: carforward, carreverse, carleft,carright, carbrakes.

The brakebutton is z.

Behind each of the red buttons is some code, here they all are:

 

Private Sub carright_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles carright.Click

        outgo.Open()

        outgo.Write("S")

        outgo.Close()

        Dim skipper : skipper = 0

        carleft.BackColor = Color.Crimson

        If carright.BackColor = Color.Crimson Then

            carright.BackColor = Color.BlanchedAlmond

            outgo.Open()

            outgo.Write("H")

            outgo.Close()

            skipper = 1

        End If

        If carright.BackColor = Color.BlanchedAlmond And skipper = 0 Then

            carright.BackColor = Color.Crimson

            outgo.Open()

            outgo.Write("S")

            outgo.Close()

        End If

        brakebutton.Focus()

    End Sub

 

 

    Private Sub carreverse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles carreverse.MouseHover

        carreverse.BackColor = Color.BlanchedAlmond

        carforward.BackColor = Color.Crimson

        outgo.Open()

        outgo.Write("R")

        outgo.Close()

        brakebutton.Focus()

    End Sub

 

   

   

    Private Sub carforward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles carforward.MouseHover

        carforward.BackColor = Color.BlanchedAlmond

        carreverse.BackColor = Color.Crimson

        outgo.Open()

        outgo.Write("F")

        outgo.Close()

        brakebutton.Focus()

    End Sub

 

    Private Sub carbrake_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles carbrake.MouseLeave

        carforward.BackColor = Color.Crimson

        carreverse.BackColor = Color.Crimson

        outgo.Open()

        outgo.Write("B")

        outgo.Close()

        brakebutton.Focus()

    End Sub

 

    Private Sub carleft_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles carleft.Click

        Dim skipper : skipper = 0

        outgo.Open()

        outgo.Write("S")

        outgo.Close()

        carright.BackColor = Color.Crimson

        If carleft.BackColor = Color.Crimson Then

            carleft.BackColor = Color.BlanchedAlmond

            outgo.Open()

            outgo.Write("L")

            outgo.Close()

            skipper = 1

        End If

        If carleft.BackColor = Color.BlanchedAlmond And skipper = 0 Then

            carleft.BackColor = Color.Crimson

            outgo.Open()

            outgo.Write("S")

            outgo.Close()

        End If

        brakebutton.Focus()

    End Sub

 

 

 

    Private Sub z(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles brakebutton.KeyPress

        carforward.BackColor = Color.Crimson

        carreverse.BackColor = Color.Crimson

        outgo.Open()

        outgo.Write("B")

        outgo.Close()

        brakebutton.Focus()

 

 

    End Sub

 

    Private Sub brakebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles brakebutton.Click

        outgo.Open()

        outgo.Write("S")

        outgo.Close()

    End Sub

 

So, over the page let's look at how this works.

 

 

More>