Posts with «wireless» label

Tutorial – Using Long Range 315MHz RF Wireless Transceivers with Arduino

You can send data from one Arduino to another, or create a wireless remote-control system using inexpensive long-range 315MHz or 433MHz wireless data units.

Using this tutorial so you can quickly test and use your units, giving you the knowledge to build upon and make your own projects. So let’s get started!

Testing the modules

Our first guide is to simply test that data can be sent and received from one module to another. This is also an ideal setup for testing the radio range of the units in your area.

You will need:

You also need to install the VirtualWire Arduino library. To do this:

  • Download this .zip file into a temporary or your download directory.
  • Open the Arduino IDE and select Sketch > Include Library > Add .zip Library…
  • Navigate to the library .zip download and click “Open”:

After a few moments the library will be installed. You can check that this has completed by selecting Sketch > Include Library> then scroll down the long pop-up menu until you see “VirtualWire” as shown below:

Now – back to the hardware. Allocate one Arduino to be the transmitter, and one the receiver. Upload the following sketch to the transmitter board:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// transmitter.ino
//
// Simple example of how to use VirtualWire to transmit messages
// Implements a simplex (one-way) transmitter with an TX-C1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
#include <VirtualWire.h>
const int led_pin = 11;
const int transmit_pin = 12;
const int receive_pin = 2;
const int transmit_en_pin = 3;
void setup()
{
// Initialise the IO and ISR
vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
vw_set_ptt_pin(transmit_en_pin);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
pinMode(led_pin, OUTPUT);
}
byte count = 1;
void loop()
{
char msg[7] = {'h','e','l','l','o',' ','#'};
msg[6] = count;
digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
vw_send((uint8_t *)msg, 7);
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(led_pin, LOW);
delay(1000);
count = count + 1;
}
view raw transmitter.ino hosted with ❤ by GitHub

… and upload the following sketch to the receiver board:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// receiver.ino
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
#include <VirtualWire.h>
const int led_pin = 2;
const int transmit_pin = 12;
const int receive_pin = 11;
const int transmit_en_pin = 3;
void setup()
{
delay(1000);
Serial.begin(9600);
Serial.println("setup");
// Initialise the IO and ISR
vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
vw_set_ptt_pin(transmit_en_pin);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
pinMode(led_pin, OUTPUT);
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
digitalWrite(led_pin, HIGH); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i], HEX);
Serial.print(' ');
}
Serial.println();
digitalWrite(led_pin, LOW);
}
}
view raw receiver.ino hosted with ❤ by GitHub

Wiring the modules is very easy, they are labelled well and drop straight into a solderless breadboard:

Now connect the transmitter module to your transmitter Arduino as such:

  • Arduino GND to transmitter GND
  • Arduino 5V to transmitter Vcc
  • Arduino digital pin 12 to transmitter SIG:

Next, connect the receiver module to your transmitter Arduino as such:

  • Arduino GND to receiver GND
  • Arduino 5V to receiver Vcc
  • Arduino digital pin 11 to receiver SIG
  • LED and resistor in series between Arduino digital pin 2 and GND

Now that you’ve assembled both circuits, and uploaded the transmitter and receiver sketches to each board – it’s time to test. 

Connect the transmitter board to power, and connect the receiver board to the PC. If not already open, run the Arduino IDE and open the serial monitor. You should notice two things:

  1. The LED on your receiver circuit should blink around once per second. When the LED blinks, this indicates the receiver circuit has successfully received a complete message from the transmitter
  2. The data sent from the transmitter is displayed in the serial monitor.

You can see this in action through the following video:

Our camera had trouble capturing the LED blink in some moments, but that’s ok.

You can also use this two Arduino setup to test the radio range – simply power the transmitter, and power the receiver circuit with a portable source of energy, such as a USB power bank – then walk away from the transmitter. The LED will stop blinking when you’re out of radio range. 

You can increase the radio range by increasing the voltage to the transmitter unit – up to 12V DC. 

Wireless Remote Control

Now to do something useful – create a wireless digital output control. Our transmitter will have two buttons, and our receiver will control two LEDs via digital outputs. Naturally this is an example, you can use this as a base to control other devices if required. 

You will need:

We will use two tactile buttons and 10k Ohm pull-down resistors for input. If you’re not familiar with digital inputs and buttons, the building block for this is shown below.

The example diagram uses D12 as the input pin, however for this project your transmitter circuit will need two button circuits, using D8 and D7:

To save time we will use button breakout boards which combine the circuit into a neat unit ideal for prototyping:

Your receiver circuit is the same as the test circuit at the start of this tutorial, except that anothe LED circuit is added to digital pin 3.

Now for the sketches. Upload the following sketch to the transmitter (buttons) Arduino…

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// transmitter sketch
//
#include <VirtualWire.h>
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
const char *on2 = "a";
const char *off2 = "b";
const char *on3 = "c";
const char *off3 = "d";
void setup()
{
vw_set_ptt_inverted(true); // Required for RF Link modules
vw_setup(300); // set data speed
vw_set_tx_pin(12);
pinMode(8, INPUT);
pinMode(7, INPUT);
}
void loop()
{
if (digitalRead(8)==HIGH)
{
vw_send((uint8_t *)on2, strlen(on2)); // send the data out to the world
vw_wait_tx(); // wait a moment
delay(200);
}
if (digitalRead(8)==LOW)
{
vw_send((uint8_t *)off2, strlen(off2));
vw_wait_tx();
delay(200);
}
if (digitalRead(7)==HIGH)
{
vw_send((uint8_t *)on3, strlen(on3));
vw_wait_tx();
delay(200);
}
if (digitalRead(7)==LOW)
{
vw_send((uint8_t *)off3, strlen(off3));
vw_wait_tx();
delay(200);
}
}
view raw tx.ino hosted with ❤ by GitHub

… and upload the following sketch to the receiver (LEDs) Arduino:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// receiver sketch
//
#include <VirtualWire.h>
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
void setup()
{
vw_set_ptt_inverted(true); // Required for RF link modules
vw_setup(300);
vw_set_rx_pin(11);
vw_rx_start();
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
}
void loop()
{
if (vw_get_message(buf, &buflen))
{
switch(buf[0])
{
case 'a':
digitalWrite(2, HIGH);
break;
case 'b':
digitalWrite(2, LOW);
break;
case 'c':
digitalWrite(3, HIGH);
break;
case 'd':
digitalWrite(3, LOW);
break;
}
}
}
view raw rx2.ino hosted with ❤ by GitHub

You can see a quick demonstration in the following video:

So how did that work? 

Review the transmitter sketch. A character is sent over the wireless link which determines the latest operation of the buttons – a, b, c or d (button one high/low, button two high/low).

Review the receiver sketch – on line 19 the switch-case function interrogates the incoming character from the wireless link and determines the action – in this case, controlling the digital outputs which have the two LEDs. 

The response speed may seem a little slow – this will be affected by the data speed (300 bps). You can experiment with data speed and radio range (and voltage to the transmitter unit)

You can then alter this for your own means. You may not want to continuously send data as our example does, depending on your needs. As always, have fun and experiment. 

Sending data wirelessly from one Arduino to another

Now we’ll show how to send some data in the form of an integer over our wireless link. This is ideal for sending the values of analog inputs, or other data that can be represented as an integer.

The hardware is the same as before – one Arduino transmitting and one Arduino receiving – with the receiver unit connected to a PC so we can use the Serial Monitor to display the received data. 

Upload the following sketch to the transmitter Arduino…

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// data transmitter sketch//
//
#include <VirtualWire.h>
// use onboard LED for status
const int ledPin = 13;
// we'll send the value of analog pin 1
const int Sensor1Pin = A1;
int Sensor1Data;
char Sensor1CharMsg[4];
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(A1, INPUT);
vw_setup(2000); // data speed in bps
vw_set_tx_pin(12); //digital pin to data transmitter
}
void loop()
{
// get data from analog pin 1
Sensor1Data = analogRead(Sensor1Pin);
// convert data from integer to character array
itoa(Sensor1Data, Sensor1CharMsg, 10);
digitalWrite(13, true); // onboard LED on to indicate transmitting
vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg)); // send array
vw_wait_tx(); // wait until data is sent
digitalWrite(13, false); // onboard LED off to indicate finished transmitting
delay(1000); // wait
}
view raw dtx1.ino hosted with ❤ by GitHub

… and the following sketch to the receiver Arduino.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
// data receiver sketch
//
#include <VirtualWire.h>
// use onboard LED for status
const int ledPin = 13;
int Sensor1Data;
// holds data from receiver
char Sensor1CharMsg[4];
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
vw_set_ptt_inverted(true);
vw_setup(2000); // data speed in bps
vw_set_rx_pin(11); // receiver data pin to digital 11
vw_rx_start();
}
void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{
int i;
// LED on to indicate message coming in
digitalWrite(13, true);
for (i = 0; i < buflen; i++)
{
// fill array with data from receiver
Sensor1CharMsg[i] = char(buf[i]);
}
// null terminate the char array, indicates the end of the data
Sensor1CharMsg[buflen] = '\0';
// convert data in array to a usable integer
Sensor1Data = atoi(Sensor1CharMsg);
// send data to serial monitor
Serial.print("tx analog pin 1 reads: ");
Serial.println(Sensor1Data);
// message reception finished, turn off onboard LED
digitalWrite(13, false);
}
}
view raw drx2.ino hosted with ❤ by GitHub

Once operating and in radio range, the onboard LEDs will indicate successful transmission and reception of data. Open the serial monitor, and after a moment you will be presented with the data from analogue pin 1 of the transmitter Arduino – for example:

So how did that work? 

Review the trasmitter sketch. We took a value from analog pin 1, and stored it into an integer variable on line 25. The VirtualWire library is geared to send data as characters so we convert the integer to a character array on line 28 – which is then sent as usual as shown in line 31.

Now review the receiver sketch. Nothing unusual, and the data from the receiver (in character form) is fed into the array at line 35. Once completed, we add “\0” to the end of the array to signify the end of the data. 

The array is then converted back to an integer on line 42, then sent to the Serial Monitor.

So there you have it, we’ve sent integers across the airwaves. You can use your own “codes” with integers to mean all sorts of things and send them across. Ideal for temperature sensors, or anything really. 

I hope you had fun experimenting with wireless units, or at least enjoyed reading about the possibilities. To keep up to date with new posts at tronixstuff.com, please subscribe to the mailing list in the box on the right, or follow us on x – @tronixstuff.

If you find this sort of thing interesting, please consider ordering one or more of my books from amazon:

Tronixstuff 23 Apr 06:05
arduino  wireless  

Hackaday Prize 2023: Bolt Bot Micro Servo Droids

This Hackaday prize entry from [saul] is the beginning of a reconfigurable kit of 3D printed parts and servo motors for robotics learning. With just access to a printer, a few cheap-as-chips servo motors, an Arduino, and some nuts and bolts, you could be hacking together robot walkers within a few hours of starting!

Bolt Bots is very simple to understand, with all the mechanics and wiring out there in the breeze, but strictly for indoor use we reckon. If you want to add remote control to your application, then drop in one of the ubiquitous nRF24L01 boards and build yourself a copy of the remote control [saul] handily provides in this other project.

There really isn’t a great deal we can say about this, as it’s essentially a build kit with quite a few configuration options, and you just have to build with it and see what’s possible. We expect the number of parts to proliferate over time giving even more options. So far [saul] demonstrates a few flavors of ‘walkers’, a rudimentary ‘robot arm’, and even a hanging drawbot.

The bolt hardware can be found in this GitHub repo, and the remote control code in this second one.

Servo-based designs are sometimes sneered at due to their dubious accuracy and repeatability, but with a little of effort, this can be vastly improved upon. Also, multi-legged walkers need multiple servos and controllers to drive ’em. Or do they?

The HackadayPrize 2023 is Sponsored by:

Mechanical Keyboard Is Also a Mouse

The mechanical keyboard community is a vibrant, if not fanatical, group of enthusiasts determined to find as many possible ways of assembling, building, and using as many high-quality keyboards as possible. With so many dedicated participants, most things that can be done with a keyboard already have been done. So when something as unique as this split keyboard that also doubles as a mouse pops up, we take notice.

The keyboard is a custom build from [Taliyah Huang] which uses a pair of Arduinos, one in each half of the keyboard, to communicate key and mouse information to a third Arduino which is plugged in to her laptop. The right-hand half of the keyboard also includes the circuitry from an optical mouse, which gets powered up when the caps lock button is held down. When activated, this allows the keyboard to be used as a mouse directly. It also includes support for most Mac gestures as well, making it just as useful as a trackpad.

While there were some problems with the design, including being slightly too tall to be ergonomic and taking nearly 24 hours of soldering to complete, the prototype device is an interesting one especially since it allows for full control of a computer without needing a dedicated mouse. For other unique mechanical keyboard concepts, we recently featured this build which takes design and functionality cues from the Commodore 64.

The Ease of Wireless Charging, Without the Wait

Historically, there have been a few cases of useful wireless power transmission over great distances, like a team at MIT that was able to light up a 60 W bulb at several meters, and of course Nikola Tesla had grand dreams of drawing energy from the atmosphere. But for most of us wireless power is limited to small, short-range devices like cellphone chargers. While it’s not a lot of work to plug in a phone when it needs a charge, even this small task can be automated.

This build begins with a 3D printed cradle for the smartphone to sit in. When the device detects that the phone has been placed in the cradle, it uses a linear actuator to drive a custom-built charging cable into the phone’s USB port. Similarly, when the phone is lifted from the cradle the cable is automatically removed. It appears that there is some play in the phone’s position that lets the charger be plugged in smoothly, and the project’s creator [Larpushka] points out that the linear actuator is not particularly strong so we don’t imagine the risk of damage is very high.

While wireless charging still may have the edge when it comes to keeping debris out of the port, we still really enjoy a project like this that seems to be done for its own sake. There are some improvements that [Larpushka] plans to make, but for now we’re delighted by this build. For anyone looking to add true wireless charging to any phone that doesn’t have it, though, it’s not too difficult to accomplish either.

Mini Wireless Thermal Printers Get Arduino Library (and MacOS App)

[Larry Bank]’s Arduino library to print text and graphics on BLE (Bluetooth Low Energy) thermal printers has some excellent features, and makes sending wireless print jobs to a number of common models about as easy as can be. These printers are small, inexpensive, and wireless. That’s a great mix that makes them attractive for projects that would benefit from printing out a hardcopy.

It’s not limited to simple default text, either. Fancier output can be done using Adafruit_GFX library-style fonts and options, which sends the formatted text as graphics. You can read all about what the library can do in this succinct list of concise functions.

But [Larry] hasn’t stopped there. While experimenting with microcontrollers and BLE thermal printers, he also wanted to explore talking to these printers from his Mac using BLE directly. Print2BLE is a MacOS application that allows dragging image files into the application’s window, and if the preview looks good, the print button makes it come out of the printer as a 1-bpp dithered image.

Small thermal printers make for neat projects, like this retrofitted Polaroid camera, and now that these little printers are both wireless and economical, things can only get easier with the help of a library like this. Of course, if that’s all starting to look a little too easy, one can always put the thermal back in thermal printing by using plasma, instead.

Fail of the Week: The Arduino Walkie That Won’t Talkie

There’s something seriously wrong with the Arduino walkie-talkie that [GreatScott!] built.

The idea is simple: build a wireless intercom so a group of motor scooter riders can talk in real-time. Yes, such products exist commercially, but that’s no fun at all. With a little ingenuity and a well-stocked parts bin, such a device should be easy to build on the cheap, right?

Apparently not. [GreatScott!] went with an Arduino-based design, partly due to familiarity with the microcontroller but also because it made the RF part of the project seemingly easier due to cheap and easily available nRF24 2.4 GHz audio streaming modules. Everything seems straightforward enough on the breadboard – an op-amp to boost the signal from the condenser mic, a somewhat low but presumably usable 16 kHz sampling rate for the ADC. The radio modules linked up, but the audio quality was heavily distorted.

[GreatScott!] assumed that the rat’s nest of jumpers on the breadboard was to blame, so he jumped right to a PCB build. It’s a logical step, but it seems like it might be where he went wrong, because the PCB version was even worse. We’d perhaps have isolated the issue with the breadboard circuit first; did the distortion come from the audio stage? Or perhaps did the digitization inject some distortion? Or could the distortion be coming from the RF stage? We’d want to answer a few questions like that before jumping to a final design.

We love that [GreatScott!] has no issue with posting his failures – we’ve covered his suboptimal CPU handwarmer, and his 3D-printed BLDC motor stator was a flop too. It’s always nice to post mortem these things to avoid a similar fate.

Simple, Self-Contained LoRa Repeater In About an Hour

[Dave Akerman]’s interest in high-altitude projects means he is no stranger to long-range wireless communications, for which LoRa is amazingly useful. LoRa is a method of transmitting at relatively low data rates with low power over long distances.

Despite LoRa’s long range, sometimes the transmissions of a device (like a balloon’s landed payload) cannot be received directly because it is too far away, or hidden behind buildings and geography. In these cases a useful solution is [Dave]’s self-contained LoRa repeater. The repeater hardware is simple, and [Dave] says that if one has the parts on hand, it can be built in about an hour.

The device simply re-transmits any telemetry packets it receives, and all that takes is an Arduino Mini Pro and a small LoRa module. A tiny DC-DC converter, battery, and battery charger rounds out the bill of materials to create a small and self-contained unit that can be raised up on a mast, flown on a kite, or carried by a drone.

The repeater’s frequency and other settings can even be reprogrammed (using a small windows program) for maximum flexibility, making the little device invaluable when going hunting for landed payloads like the one [Dave] used to re-create a famous NASA image using a plastic model and a high-altitude balloon. Check out the details on the GitHub repository for the project and start mashing “add to cart” for parts at your favorite reseller.

Wireless Controllers For Retro Gaming

There’s no limit to the amount of nostalgia that can be minted through various classic platforms such as the NES classic. The old titles are still extremely popular, and putting them in a modern package makes them even more accessible. On the other hand, if you still have the original hardware things can start getting fussy. With modern technology it’s possible to make some changes, though, as [PJ Allen] did by adding wireless capabilities to his Commodore 64.

Back when the system was still considered “modern”, [PJ] tried to build a wireless controller using DTMF over FM radio. He couldn’t get it to work exactly right and ended up shelving the project until the present day. Now, we have a lot more tools at our disposal than analog radio, so he pulled out an Arduino and a few Bluetooth modules. There’s a bit of finesse to getting the old hardware to behave with the modern equipment, though, but once [PJ] worked through the kinks he was able to play his classic games like Defender without the limitations of wired controllers.

The Commodore 64 was incredibly popular in the ’80s and early ’90s, and its legacy is still seen today. People are building brand new machines, building emulators for them, or upgrading their hardware.

SENSEation Shows The Importance of Good Physical Design

Sensor network projects often focus primarily on electronic design elements, such as architecture and wireless transmission methods for sensors and gateways. Equally important, however, are physical and practical design elements such as installation, usability, and maintainability. The SENSEation project by [Mario Frei] is a sensor network intended for use indoors in a variety of buildings, and it showcases the deep importance of physical design elements in order to create hardware that is easy to install, easy to maintain, and effective. The project logs have an excellent overview of past versions and an analysis of what worked well, and where they fell short.

One example is the power supply for the sensor nodes. Past designs used wall adapters to provide constant and reliable power, but there are practical considerations around doing so. Not only do power adapters mean each sensor requires some amount of cable management, but one never really knows what one will find when installing a node somewhere in a building; a power outlet may not be nearby, or it may not have any unoccupied sockets. [Mario] found that installations could take up to 45 minutes per node as a result of these issues. The solution was to move to battery power for the sensor nodes. With careful power management, a node can operate for almost a year before needing a recharge, and removing any cable management or power adapter meant that installation time dropped to an average of only seven minutes.

That’s just one example of the practical issues discovered in the deployment of a sensor network in a real-world situation, and the positive impact of some thoughtful design changes in response. The GitHub repository for SENSEation has all the details needed to reproduce the modular design, so check it out.

A Better Battery Arduino

We’ve seen [Johan]’s AA-battery-sized Arduino/battery crossover before, but soon (we hope!) there will be a new version with more MIPS in the same unique form factor! The original Aarduino adhered to classic Arduino part choices and was designed to run as the third “cell” in a 3 cell battery holder to relay temperature readings via a HopeRF RFM69CW. But as [Johan] noticed, it turns out that ARM development tools are cheap now. In some cases very cheap and very open source. So why not update an outstanding design to something with a little more horsepower?

The Aarduino Zero uses the same big PTH battery terminals and follows the same pattern as the original design; the user sticks it in a battery holder for power and it uses an RFM69CW for wireless communication. But now the core is an STM32L052, a neat low power Cortex-M0+ with a little EEPROM onboard. [Johan] has also added a medium size serial flash to facilitate offline data logging or OTA firmware update. Plus there’s a slick new test fixture to go along with it all.

So how do you get one? Well… that’s the rub. It looks like when this was originally posted at the end of 2017 [Johan] was planning to launch a Crowd Supply campaign that hasn’t quite materialized yet. Until that launches the software sources for the Zero are available, and there are always the sources from the original Aarduino to check out.