Go Down

Topic: Turn your Arduino into an AM radio transmitter! (Read 31241 times) previous topic - next topic

terryking228

#15
Apr 09, 2017, 04:41 pm Last Edit: Apr 09, 2017, 04:57 pm by terryking228
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

Quote
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 )
Code: [Select]
unsigned long calcDelayTimeForFreq(unsigned long freq) {
  return 500000/freq;
}
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

terryking228

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:

Code: [Select]
/* 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 )---
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

arduinouser0

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

Paul_KD7HB

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

Paul

GoForSmoke

#19
Jun 01, 2017, 08:14 am Last Edit: Jun 01, 2017, 08:15 am by GoForSmoke
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.

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

lastchancename

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 ;)
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

GoForSmoke

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.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

terryking228

Quote
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...
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

aarg

Hello, can anyone post receiver circuit? I need it just to turn led on/off on signal received. Thanks.
Just google, "am receiver circuit" :)

I picked one for you.

http://www2.eng.cam.ac.uk/~dmh/ptialcd/trf/trf.htm
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

dndubins

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

GoForSmoke

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, 
http://www.microchip.com/wwwproducts/en/ATmega328P

http://ww1.microchip.com/downloads/en/devicedoc/atmel-2586-avr-8-bit-microcontroller-attiny25-attiny45-attiny85

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,
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

dndubins

#26
Aug 05, 2017, 02:46 am Last Edit: Aug 05, 2017, 02:52 am by dndubins
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:

http://becomingmaker.com/tuning-attiny-oscillator/

I could set the frequency based on the following code:
Code: [Select]

// 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

Paul_KD7HB

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

dndubins

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.

Paul_KD7HB

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

Go Up