-
Finished the hardware
12/30/2018 at 22:28 • 0 commentsFinally 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!
-
Battery and Voltage Monitoring
12/29/2018 at 01:20 • 0 commentsNow 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:
battery_level = (analogRead(A1)*0.005);//0.005=2*2.56/1024;
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.
-
Programming the microcontroller
12/26/2018 at 23:52 • 0 commentsTo 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.
#include <Servo.h> // pin definitions #define TRIGGER 11 #define ECHO 12 #define MR 9 #define ML 10 #define LEDB 14 #define LEDR 17 #define THRSHLD 10 //cm Servo motor_r; Servo motor_l; int distance = 0; void setup() { pinMode(TRIGGER, OUTPUT); pinMode(ECHO, INPUT); pinMode(LEDB, OUTPUT); pinMode(LEDR, OUTPUT); motor_r.attach(MR); motor_l.attach(ML); } void loop() { distance = measure(); if (distance > THRSHLD) { forward(); blue(); delay(200); } else { left(); red(); delay(50); } } int measure() { int duration, distance; digitalWrite(TRIGGER, LOW); delayMicroseconds(2); digitalWrite(TRIGGER, HIGH); delayMicroseconds(10); digitalWrite(TRIGGER, LOW); duration = pulseIn(ECHO, HIGH); distance = duration/58; return distance; } void blue() { digitalWrite(LEDR, LOW); digitalWrite(LEDB, HIGH); } void red() { digitalWrite(LEDR, HIGH); digitalWrite(LEDB, LOW); } void forward() { motor_r.write(180); motor_l.write(0); } void right() { motor_r.write(180); motor_l.write(180); } void left() { motor_r.write(0); motor_l.write(0); }
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.
-
First tests
12/24/2018 at 00:57 • 0 commentsI 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.
Up next: Programming and then battery.
-
Started working on the electronics
12/19/2018 at 22:40 • 0 commentsThe ultrasonic sensor is held to the servos with double sided foam tape. I also had to shorten the servos' cables to achieve a cleaner look, otherwise they would be sticking out of the robot.
-
Finished the chassis
12/19/2018 at 22:21 • 0 commentsFinished 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.
-
Started Project
12/19/2018 at 22:11 • 0 commentsI 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.