You Are Here: Home » Game – Entertainment Project Ideas » BlindBot usisng Atmel Mega32 MCU

BlindBot usisng Atmel Mega32 MCU




Introduction

   Our project is an autonomous toy car that tracks a high pitched audio signal. Using two microphones, a microcontroller, and two DC motors on an existing remote controlled car and, we implemented our own control logic to detect high pitched 3.5kHz audio signals and drive the car.

BlindBot usisng Atmel Mega32 MCU

This project consists of both software and hardware designs. Starting from the high level point of view, we divided this project into three components: Signal Processing Unit, MCU and Motor Control Unit. Based on the functionalities of our projects, we made a Signal Processing unit that can identify the existence of a sound source and convert the intensity of the sound into a measurable voltage level. Thus, our blind bot will be able to firstly hear the sound, secondly distinguish the intensity of the sound which indicates the distance of the sound source and receiving unit, and lastly position the sound source with a reasonable accuracy. The MCU is designed by taking the voltage generated by the Signal Processing Unit which basically tells where the sound source is, then output the control bits to regulate the Motor Control Unit. Since our blind bot should be able to move forward and make left/right turns, we have two motors included in the Motor Control Units. By controlling a switch, we are able to turn on/off the back motor, and by using an H-bridge we are able to control the three movements of the front motor: turning left, turning right, and stop.

High Level Design

Our motivation for this project came arose from the DARPA Grand Challenge, a national contest to create an autonomous ground vehicle that would successfully complete an obstacle course. We decided that a scaled-down version of this challenge would be appropriate for our final project.

The major math components in this project arise from our Signal Processing Unit, in which we designed a bandpass filter to pass the 3.5kHz audio signal and filter out noise at other frequencies. We combined a sequence of lowpass and highpass filters to act as a bandpass filter centered at 3.5kHz frequency, with cutoff frequencies of 1kHz and 5 kHz. Another calculation involved is the amplification from the RMS-to-DC converter. Since the signal from the integrator is typically under 10mV, we made an amplifier using LMC7111 opamp chips with a gain of roughly 500. Therefore the output from the signal processing unit is in between 1 to 5 volts.

Our autonomous car has two microphones to detect a 3.5kHz audio signal. We measure the intensity of these two signals using a RMS-to-DC converter and connect them to our Atmel Mega32 microcontroller (MCU). The MCU takes analyzes these two input signals and outputs 3 signals to drive the motor attached to the rear wheels, and one signal to drive the motor attached to the front wheels.

After testing our project with the real 12V power source (8 AA Batteries), we discovered that we could not use pulse width modulation (PWM) to drive the front and rear motors at the same time  the 12V power source could not deliver enough power. We decided to use only one H-bridge to drive the front motor (turning the car left and right) and use another circuit to drive the rear motor.

There are no known standards that are related to our project. Our sound source, a 3.5kHz high pitched audio signal is in the range of auditory signals which are not restricted, except by noise level, in certain communities. Our sound source is definitely not loud enough to violate any noise ordinances.

Hardware Design

The autonomous car we built runs on two power supplies. A 9V battery is connected to a 5V regulator (LM340) to power the microcontroller, microphones, amplifiers, and RMS-to-DC converters. A 12V power supply powers the H-bridges and motors.

Two microphones on the toy car receive audio input. We connect each of the microphones to a band pass filter with a pass band including 3.5kHz. The filtered signals are passed to a RMS-to-DC converter (AD636), and the outputs of our RMS-to-DC converters are amplified and fed as inputs to the MCU.

The MCU is connected to two different circuits that drive the front and rear motors. The MCU outputs 3 different signals (PWM, DIR, BRAKE) that are optoisolated using 4N35 transistors. This isolation is necessary to prevent voltage spikes from the motors power supply to wipe out transistors on the MCU. We connect these optoisolated signals to an H-bridge, which enables the front motor to be driven in both directions, allowing the car to turn left and right. The two outputs of the H-bridge are either at 0V or 12V, but we discovered that a 12V voltage drop across the front motor was starting to burn the motor out. We connected two 5V voltage regulators (LM340) to the output to restrict the output voltages to either 0V or 5V. We connected the two leads of the front motor to the output terminals of the voltage regulators.

The MCU also outputs another signal, also optoisolated in the same manner, to drive the rear motor. We connect the rear motor in the circuit shown below. When the MCU outputs 5V, the motor turns on and the car moves forward. This circuit uses the same design as Lab5 of ECE476.

Program Design

When the MCU boots up, we initialize timer 1 to run at 250kHz and to interrupt on an output compare match value of 249. With these settings, our timer 1 Output Compare Match ISR executes every 1 ms. This ISR decrements a variable time1, which is used to flash a LED connected to the microcontroller to indicate the microcontroller is running.

The ADC is also initialized at startup to run at its slowest frequency (125 kHz) and to use AVcc (connected to 5V) as the ADC voltage reference. Thus, voltage to ADC conversion result is given by ADC = VIN * 256 / VREF, where VREF is 5V. We enable the ADC conversion complete interrupt. In our ADC Conversion Complete ISR, we store the latest result into an array named adc_data, switch input channels (we need to continuously sample the intensity of the two microphones), and start the next ADC conversion.

After the MCU is initialized and interrupts are enabled, the microcontroller enters into the heart of the program, our endless loop which continuously runs 3 functions. Our first function flashLED() in the loop flashes the LED using the time1 variable to detect the number of milliseconds that have elapsed since the last flash. Our second function scanAudio()takes the last ADC conversions from the audio inputs and analyzes them to determine how to drive the car. Our last function driveCar() uses state variables to drive and steer the car.

Function scanAudio() takes the latest ADC conversions from the left and right microphones. The variable searchState indicates whether the car is tracking an existing signal or searching for a signal. If the car is searching for a signal and detects a signal above a certain threshold, we start the car going forwards. Otherwise, the car remains stopped. If the car is already tracking a signal, and the signal falls out of range, we stop the car. If the signal becomes too strong, we assume the car has reached its destination and stop the car. We only turn the car when the car is moving. We analyze the intensity of the signals to determine if the car should turn.

BlindBot usisng Atmel Mega32 MCU block diagram




Function driveCar() uses the state variables FWDState, and RWDState, which are set in scanAudio() to drive the motors. FWDState indicates the desired state of the front motor, and RWDState indicates the desired state of the rear motor. Recall that an H-bridge, requiring 3 inputs, drives the front motor. Thus, we send the correct PWM, DIR, BRAKE bits to the H-bridge when we want the car to turn left, right, or continue going straight. Recall that we drive the rear motor using the circuit shown in Figure 1. Thus, we sent out a logical high if we want the car to go forward and a logical low for the car to stop.

We had originally setup our program to output two PWM signals coming from Timer 0 and Timer 2 of the MCU that drives two H-bridges. We simply changed the OCR values to change the duty cycle of our square waves that drive the DIR input pins of the H-bridges. Because the 12V batteries could not supply enough power to drive the motors, we had to change the code in driveCar() to drive the motors using logial low and high values of output port pins.

We did not borrow any code from anyone else, but we did use Codevisions source code generator to initialize all the relevant registers in the MCU.

Parts list:

QuantityItem DescriptionSamples?Unit CostTotal Cost

1

Atmel Mega32 MCU

$8.00

$8.00

3

Big Solder Boards

$2.50

$7.50

2

Horn Microphones (359-1007-ND)

$1.11

$2.22

1

Piezzo Buzzer (302-1120-ND)

$3.36

$3.36

4

Fairchild 4N35 Optoisolators

LAB

$0.00

$0.00

1

TIP31 NPN BJT

LAB

$0.00

$0.00

2

Analog AD636 RMS-DC Converters

YES

$0.00

$0.00

1

National LMD18200 H-Bridge

YES

$0.00

$0.00

3

National LM340 5V Regulator

LAB

$0.00

$0.00

2

National LMC7111 Op Amp

LAB

$0.00

$0.00

1

Old RC Car (including Stepper Motors)

$0.00

$0.00

Total

$21.08

 

 

For more info: BlindBot

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Super Breakout using Atmel Mega32

Get ready for the next generation of the classic game Breakout which features a standalone device, interactive user control, and...

Close
Scroll to top