This is a tiny robot with chassis made from scrap wire I got from inductors in my parts box. The servo motors are hacked for continuous spinning. An ATmega8 runs Arduino code to control the servos and poll an ultrasonic sensor for obstacle avoiding. I started this project to participate in the Circuit Sculpture Contest.
This is a tiny robot with chassis made from AWG 16 wire soldered together. The servos are micro servos hacked for continuous rotation, these also give the robot some support. The brains of the robot is an Atmega8 with code for avoiding objects with aid of an ultrasonic sensor.
When bulding this I had the wire "jump" at my face of throw solder at me, as it behaves as a spring. If you would make something like this, please use protection goggles . I know someone who lost an eye to a piece of wire when they were a child. Vision is too important to be careless.
Finally installed the battery and a power switch. I tried getting a reverse polarity protection feature to work, but none of the mosfets I had here seems to be able to saturate with the low voltage the battery provides. I just have to be careful then :)
Everything works as planned. Hope I can upload a video soon!
Now that the microcontroller seems to be working fine with the other components, it is time to find a power source. I bought this 3.7 lipo battery for powering the robot, it is quite light and provides enough voltage and current to power the circuit.
The circuit seems to work fine with just 3.7V, so I am glad I don't have to add in a step-up circuit, that would be a power waste and would not match the overall look of the project.
Lipo batteries are know for causing trouble, so I have to take at least some care. These batteries cannot over discharge, so I use a free analog pin to monitor the voltage of the battery, which can somewhat represent the battery charge.
I added a resistor divider (not seen in the picture, as it is under the microcontroller) connected to an analog pin. This resistor divider halves the battery voltage (4.2V max), which is then read by the microcontroller (2.1V max). As the battery voltage changes, the internal reference of the microcontroller is used instead of VCC. Thankfully, Arduino allows one to easily change the voltage reference of the microcontroller's ADC without direct register manipulation. So I use:
analogReference(INTERNAL); //sets the ADC reference to internal 2.56V reference
Note: The ATmega8 has a internal reference of 2.56V, but most of the AVR Arduino boards actually have a 1.1V reference.
As the battery voltage (3.7 - 4.2V) is higher than the internal reference (2.56V), we need some trick in order to measure it. I have used a simple resistor divider. I used these blue resistors, which I despise because I cant read them without a meter, but have good precision (1%). Two 10K resistors split the battery voltage to a max of 2.1V. Sweet.
To get the voltage measurement from the ADC, we multiply the value read by two(because of the divider), then by 2.56V divided by the resolution of the ADC (1024). This is done with the following line of code:
I plan not letting the battery voltage get any lower than 3.7V, so when that voltage is achieved, the robot will stop the motors and start to blink the LEDs, warning that the battery should be charged.
I still have have to add a power switch to the circuit, and I am also at the moment looking for options for reverse polarity protection. I have had bad experiences with plugging batteries the wrong way in the past, and would not like another one. My options are limited to the components I have at the moment though, as the deadline of the contest is approaching.
To program the microcontroller I went on the simplest route, which is using Arduino. The ATmega8 can be programmed with the Arduino IDE very easily, without modifications to the IDE files (if you use a 16MHz crystal). Simply choose "Arduino NG or older" on the boards list, then you can burn the chip directly with a supported programmer (I use the USBASP) or burn the bootloader if you are keen to program the chip with just a USB-serial bridge.
I have implemented the following code, which allows simple obstacle avoiding. Pins 11 and 12 are used by the ultrasonic sensor (HC-SR04), while pins 9 and 10 are used by the servos.
The hacked servos are deprived of the closed loop positioning. The potentiometer used for knowing the position of the servo's shaft is replaced by two resistors of same value. This way, when telling the motor to go towards 180 or 0 degrees, the servo will try to reach this value, without success, rotating continuously in the process. The motor should stop at 90 degrees, but this depends on the motor and the precision of the resistors used. You have to find the value at which your motor stops, but it should be 90 degrees or very close.
I have tested the circuit components with the robot hooked to external 5V, the servos were working fine as intended. As they are hacked for continuous rotation, setting them to 0 degrees makes them spin in one direction, while 180 degrees makes them spin on the opposite direction.
The ultrasonic sensor I added on the last log was not working, but thankfully I had a spare one, which was new and still in the package, so no problem. I was afraid the chassis of the robot would get in the way of the sensor, spoiling the measurements, but thankfully the working angle of the sensor is sharp enough to avoid any changes on the structure.
I also added two LEDs to report the readings of the ultrasonic sensor. The red LED lights up when a obstacle is found, while the blue one is on when the path is free.
Finished soldering together the basic structure of the robot. I used magnet wire for the structure, which is coated with a thin layer of insulating material. I used a file or a razor knife to remove this material where the wires are soldered together.
I started by gathering some pieces of wire from the junk bin and figuring out the dimensions of the robot. I could not find the wire I wanted in the local stores, so I used 16 awg wire from old inductors.
The servos were reused from another project and had already been hacked for continuous rotation long ago. I don't have pictures for that, unfortunately, but a tutorial can be found here. Heavy duty double sided tape was used to hold the servos secure back to back.
You can visit the gallery for pictures of the building process of my robot.
I can't add step by step building of the freeform circuit, of course, but I can add the schematic of my circuit here as example. Then you can build it as you like, or just design your own with the microcontroller and sensors that suit you.
This assumes you have basic knowledge of how to program a controller with a programmer. The code I use can be found in the Files section.
The ATmega8 used can be programmed with the Arduino IDE. I used the mega8 because I have many of them, but an ATmega328p could have been used too.
To program an ATmega8 with the Arduino IDE, just select Arduino NG or older and ATmega8 from the Tools menu. Then select the programmer you have. If you don't have a standalone programmer, a Arduino can be used, just search online for "Arduino as ISP"
It is a good idea to use the "Burn Bootloader" option once, even if you don't plan to use it, as it also programs the correct fuse values into the chip. The microcontroller needs to be configured to use a external crystal, this is done separately from the code thru specif bits called fuse bits and they are not reset when you upload new code. The Burn Bootloader option does that automatically, then you can overwrite the bootloader with the "Upload Using Programmer" tool, which keeps the fuse bits programmed.
Then you can program the chip using the Upload Using Programmer option. Just select under the Sketch Menu. Skipping the bootloader gives you extra flash, but I use it simply because the bootloader for the ATmega8 takes forever to startup the main code.