Turn your Arduino into an AM radio transmitter!

Hmmm. Compiles and runs OK on 1.0.6 and 1.6.4 buts lots of compile errors on 1.6.7

What don't I understand??

I got compiled all of two using 1.6.7 but in the second one by headpigeons I had to move the calcDelayTimeForFreq function before the others declarations, just after "const byte ANTENNA = 9;"

This is a very fun project for learning about radio frequencies. I am wondering if there is a way to increase the range of the transmission. I have figured out how to change the frequency by modifying the OCR1A variable. Adding a longer antenna wire doesn't seem to make much of a difference. I have about 1ft of antenna wire attached and I can notice the signal works up to about 1-2 feet.

Would tuning the antenna length to some fraction of a full wavelength (375m at 800KHz) increase the output?

Would an opamp drive the signal far enough to be of any use?

Hi Smoke & Nick,

Hmmm..
13 - ~570 khz

I gotta run this; I used to work for the Straus Broadcasting Group (WMCA Good Guys 50 KW on 570 KHz ).

And I am doing a little with Morse (AKA Real Simple Digital Communications) with kids. Some info here:
http://arduino-info.wikispaces.com/YourSmartArduino

Would tuning the antenna length to some fraction of a full wavelength (375m at 800KHz) increase the output?

5V signal should be able to put 10 Mv/M at over 100 feet I would think.. I'll do some testing...

I'd like to do something about Switches... to "How can you communicate with just one Switch?" to kids communicating across a classroom. In the Internet Era this is still relevant.

(I had to move this to the beginning to get it to compile on 1.8.2 )

unsigned long calcDelayTimeForFreq(unsigned long freq) {
  return 500000/freq;
}

Hi, OK got this working for very simple Morse Key mode. I'll use it this week with 4th grade. we are doing Electricity, serial-parallel, and SWITCHES.. Last week I manually sent "HI" with a piezo buzzer and two wires. They were intrigued with "Signals"...

I have a hand-cranked radio (shows conversion of mechanical energy to electrical energy)... I'll use that to show "wireless" communication. AKA "RADIO"...

Here's the simplified code:

/* YourDuinoStarter Example: Morse Radio Transmitter
 - WHAT IT DOES: User sends Morse code in the AM Broadcast Band - very low power
 - SEE the comments after "//" on each line below
 - CONNECTIONS:
   - Pin 2  - Morse key to ground
   - Pin 9  - Antenna (20+ feet long)
 - V1.00 05/01/2017
   Questions: terry@yourduino.com */

/*-----( Declare Constants and Pin Numbers )-----*/
#define MORSE_KEY 2
#define ANTENNA 9

/*
 The OCR1A variable is related to the frequency.
The OCR1A variable is one less than the actual divisor.
OCR1A - Frequency
15 - 500 khz
14 - ~530 khz
13 - ~570 khz   (WMCA New York )
12 - ~610 khz
11 - ~670 khz
10 - ~730 khz
9 - 800 khz
8 - ~890 khz
7 - 1000 khz   (Good for test)
6 - ~1140 khz
5 - ~1330 khz
4 - 1600 khz* 
 */
#define MORSE_KEY 2
#define ANTENNA 9

void setup()   /****** SETUP: RUNS ONCE ******/
{
  // set up Timer 1
  TCCR1A = _BV (COM1A0);           // toggle OC1A on Compare Match
  TCCR1B = _BV(WGM12) | _BV(CS10); // CTC, no prescaler
  OCR1A =  7; //(From frequency Table Above ( compare A register value to 10 (zero relative))
  pinMode(MORSE_KEY,INPUT_PULLUP);
}  // end of setup



void loop()   /****** LOOP: RUNS CONSTANTLY ******/ 
{
  if (digitalRead(MORSE_KEY) == LOW)
  {
    pinMode (ANTENNA, OUTPUT);  // Modulate the RF carrier on-off at audio rate
    delayMicroseconds(800);
    pinMode (ANTENNA, INPUT);
    delayMicroseconds(800);     
  }
  else  
  {
    pinMode (ANTENNA, OUTPUT);   // Unmodulated carrier: not so much background noice
  }

}//--(end main loop )---
1 Like

Hello, can anyone post receiver circuit? I need it just to turn led on/off on signal received. Thanks.

terryking228, did you ever listen to Waltzing Matilda on a portable radio set on top of an IBM 1401/1440?

Paul

ArduinoUser:
Hello, can anyone post receiver circuit? I need it just to turn led on/off on signal received. Thanks.

Search on crystal radio set for how to build a receiver. What can be heard on an earphone can be detected by Arduino.

Test the transmitter with an ordinary AM radio.

I'm not a ham operator (or FCC narc), but both of those would love to string you up by the short & curliest if this was ever released in the wild!
Let's extend the range with a power amplifier :wink:

1 Like

HAM operator gets upset over extremely short range AM transmitter....

I think that my PC with the box side panel removed makes more radio noise and I've not had any trouble in over 30 years of running that way.

terryking228, did you ever listen to Waltzing Matilda on a portable radio set on top of an IBM 1401/1440?

No, but I heard about it! I worked with guys at IBM who would happily spend hours coding something that would produce the coveted response from peers: "What the Hell is THAT??"

Dave Millman would talk to you while nonchalantly twirling the front panel hex switch knobs on an idle System 7 and stabbing buttons. Then he would hit reset and the panel lights would do a cool pattern. He'd walk away, saying:

"A Busy Computer is a Happy Computer!"

I have that ditty posted here on a placard I wrote in 1975...

ArduinoUser:
Hello, can anyone post receiver circuit? I need it just to turn led on/off on signal received. Thanks.

Just google, "am receiver circuit" :slight_smile:

I picked one for you.

http://www2.eng.cam.ac.uk/~dmh/ptialcd/trf/trf.htm

Hi everyone,

I realize this is somewhat of an older thread. I tried this project with my Uno and it worked really well! After all, with only one component to plug in, it was hard to mess up the wiring.

I was trying to port this project over to the ATtiny85 chip, and I got lost when it came to setting the clock. For the Uno, the code to set up the 1MHz square wave signal is:

// set up Timer 1
TCCR1A = _BV (COM1A0); // toggle OC1A on Compare Match
TCCR1B = _BV(WGM12) | _BV(CS10); // CTC, no prescaler
OCR1A = 7; //(From frequency Table Above ( compare A register value to 10 (zero relative))

What would the analogous set of commands be on the ATtiny85 architecture?

Many thanks in advance,
Dave

You need the ATtiny85 full datasheet (I don't have here, ATMEL does.) PDF and the one for ATmega328P. Each covers a whole line of similar AVRs with memory differences but same pins and ports.

Funny, I don't find the full family sheet for 328P. It's compatible with even less than the 168P,

You want a window or tab for each PDF and open the Arduino IDE.

ATtiny serial ports are not as featured as ATmega serial ports.
Read the 328 timer section overview and then the 85's, the differences will show right away,

Thank you GoForSmoke.

I did wade through the datasheet for the attiny85, and the section on setting the clock is unfortunately over my head. I tried various approaches based on what I found in newsgroups. I had good results using code here:

I could set the frequency based on the following code:

// Timer/Counter0 Compare Match A interrupt handler 
ISR (TIMER0_COMPA_vect) {
   PORTB ^= 1 << PINB4;        // Invert pin PB4
}
 
void setup() {
    OSCCAL += 3;                // User calibration
    pinMode(4,OUTPUT);          // Set PB4 to output
    TCNT0 = 0;                  // Count up from 0
    TCCR0A = 2 << WGM00;        // CTC mode
    if (CLKPR == 3)             // If clock set to 1MHz
        TCCR0B = (1<<CS00);     // Set prescaler to /1 (1uS at 1Mhz)
    else                        // Otherwise clock set to 8MHz
        TCCR0B = (2<<CS00);     // Set prescaler to /8 (1uS at 8Mhz)
    GTCCR |= 1 << PSR0;         // Reset prescaler
    OCR0A = 49;                 // 49 + 1 = 50 microseconds (10KHz)
    TIFR = 1 << OCF0A;          // Clear output compare interrupt flag
    TIMSK |= 1 << OCIE0A;       // Enable output compare interrupt
}
 
void loop()

I found that shrinking the delay (OCR0A) increased the frequency, but I hit a ceiling at about 200 kHz no matter how hard I tried - and that's with setting the ATtiny's internal oscillator to 16 MHz.

So as it turns out, I lack the basic understanding necessary to set the clock on my own without following other people's code. I was looking for a good online tutorial. There were various sites, but the knowledge seems to be finely dispersed in staggered message threads. The whole experience made me REALLY appreciate the Arduino IDE taking care of all these commands for you with the Uno.

To make a long story short, I ended up using a CMOS 555 timer today for the carrier signal, which did the job quite nicely, and broadcast morse code all over my lab at 1 MHz. Since the range is quite limited and I doubt people listen to AM in my building, I don't think anyone heard "scott rocks" repeatedly, the message that was embedded in the example code from here:

http://www.swharden.com/wp/2011-08-06-ridiculously-simple-avr-mcu-am-radio-transmitter/

I really like the 555 solution because I can fine-tune the frequency with a 10K trimmer, rather than perhaps be constrained to multiples of a clock divider. Still, if anyone knows offhand how to elicit a 1MHz signal from an ATtiny85, or would be patient enough to tell me the secrets of setting the clock beyond 200 kHz, it will be useful for this and other projects.

Kind regards,
Dave

Here is the secret to what you are doing, from my pulse and digital circuits class from many years ago. A square wave, like from your NE555 circuit contains a fundamental frequency, plus an infinite number of third and higher harmonics of your fundamental frequency. The squareness of the corners of the square wave, seen on an oscilloscope depends on the power in those odd harmonics. More power, the sharper the corners.

What you are listening to is a harmonic of your fundamental square wave frequency. You don't need to get the square wave to be the frequency you want to listen to, but can be 1/2, 1/3, or any other division. The power goes down as you divide down, but can still be heard on your receiver.

If the code signal, CW, you heard was a pure sine wave, you would not hear it on an AM receiver, no AM modulation. So, it is really a really bad square wave that makes it audible on an AM receiver.

Paul

Thanks for that, Paul. It's fascinating, isn't it? How a series of sin curves can add up to (and eventually approximate) a square wave, and although we see it as square on the scope, it's really the sum of a bunch of harmonics. My instinct after looking at the waveform today was that if I were to use a more sinusoidal-shaped carrier wave, I would get a clearer signal, but I can see from your response that those harmonics can actually help you catch the signal close by, and indeed I heard that while tuning the radio to find my signal. There was more than one sweet spot on the dial where it came through. What amazes me the most is how many signals must be in the air in downtown Toronto (where I live). It's a wonder to me that so many cellphones can operate simultaneously. It would be fun to harness that power somehow, at the expense of course of people sending selfies to each other.

All the RF power you are referring to amounts to microwatts per square meter. Some researches have developed equipment that can power themselves with the power floating around. Not very practical, yet, but will be.

All the cell signals operate in narrow bands with various coding schemes from the cell towers, so many cell phones can receive on the same frequency. Technology changes from time to time. One connection does not effect the other, even adjacent devices.

Paul

Thanks for this thread - this is a really fun project starter.

I've been hoping to do some proper amplitude modulation of the carrier, but it seems as though whatever the carrier level is set to once the code is flashed is a constant value (on or off), rather than one that can be varying with the modulating signal.

So I was wondering...is it possible to vary our carrier (if the project is set up as in the original post) to achieve proper amplitude modulation?

Would varying the carrier by an arbitrary amplitude envelope ( e.g a song from an mp3 player or smartphone) result in successful modulation for radio transmission? And if so, how many ways are there to do that with a basic arduino kit?

Sorry if these seem like daft questions - I normally work with AM/FM signals in the audio domain, not radio.