Posts

Showing posts from May, 2017

Flow Chart

Image
Flow Chart: Self Drifting Cars Self Drifting Cars Flow Chart  Self Drifting Cars Flow Chart as shown in figure above, start with analog infrared sensor to detect distance in front direction of the cars, accelerometer received acceleration of the cars, ultrasonic sensor received distance between the cars and the wall to calculate offset angle by using PID controller to steering car direction and to avoid collision from the wall, then we can limit speed of the cars by using HAL-sensor with PID controller then send command to steering and speeding the cars and then the cars send back about current data to raspberry pi

Self drifting main project code

Image
Main Project Code Flow chart for Main project Code: #include <Wire.h> #include <Servo.h> #include <TimerThree.h> //For Steering #define mins 45 //degree #define maxs 120 //degree #define center 83 //degree #define half_steer 37 //Maximum speed for turn steering 10ms //Speed Sensors #define speed_r 2 #define speed_l 3 #define length_4pulse 8 //80 millimeter 8 centimeter #define speed_mins 0 #define speed_maxs 100 //For Motor Drive #define InA_PIN 5 //Yellow #define InB_PIN 6 //Blue #define PWM_PIN 4 //Green //INA 1 INB 0 clockwise FORWARD //INA 0 INB 1 counterclockwise REVERSE //Ultrasonic //ADDRESS #define Front_Left 112//0x70//0xE0 #define Front_Right 114//0x72//0xE4 #define Back_Left 116//0x74//0xE8 #define Back_Right 118//0x76//0xEC #define CMD 0x00 #define RANGE_CMD 0x02 #define RANGE_SET 0x18 #define Read_inch 0x50 #define Read_cen 0x51 #define Read_micro_sec 0x52 #define Read_pointer 0x02 #define ultrasonic_mins 6 //CMPS03 Compass Module #defi

Hot Lapse

Image
Hot Lapse Code Flow chart for Hot Lapse Challenge Code: #include <Wire.h> #include <Servo.h> //For Steering #define mins 45 //degree #define maxs 120 //degree #define center 83 //degree #define half_steer 37 //Maximum speed for turn steering 10ms //For Motor Drive #define InA_PIN 5 //Yellow #define InB_PIN 6 //Blue #define PWM_PIN 4 //Green //INA 1 INB 0 clockwise FORWARD //INA 0 INB 1 counterclockwise REVERSE //For Ultrasonic //ADDRESS #define Front_Left 112//0x70//0xE0 #define Front_Right 114//0x72//0xE4 #define Back_Left 116//0x74//0xE8 #define Back_Right 118//0x76//0xEC #define CMD 0x00 #define RANGE_CMD 0x02 #define RANGE_SET 0x18 #define Read_inch 0x50 #define Read_cen 0x51 #define Read_micro_sec 0x52 #define Read_pointer 0x02 //Sharp Infrared sensors #define Front_sensor A6 #define Rear_sensor A7 //PID Control #define p_value 6 #define i_value 0 //0.5 #define d_value 0 //4 Servo myservo; int angle = center; float error = 0; float error_p = 0; flo

ET-MMA7331L (3-Axis Analog Output Accelerometer)

Image
ET-MMA7331L ET-MMA7331L This sensor can give an output for accelerometer in 3-axis (X, Y, Z) with analog output. You can set g-force to measure as 4g or 12g and you can convert output from voltage to g unit by using this equation. for Voffset is VDD/2 (VDD is power source voltage) and for sensitivity please use the value from this following table. Table 1: Sensitivity and g-select After you get Vout by using ADC then you can calculate back to get g-value for each channel (X, Y, Z) Important: Voltage tolerant of this module is 3.6V, if you work on a 5V MCU please be careful Sample Code: //Accelerometer #define X_OUT A8 #define Y_OUT A9 #define Z_OUT A10 #define Voffset 337 // 3.3/2 = 1.65v -> 1.65*1023/5 = 337.59 #define sensitivity 63 // 0.308 -> 0.308*1023/5 = 63.0168 float x_value = 0; float y_value = 0; float z_value = 0; void setup() { //Accelerometer Initial pinMode(X_OUT, INPUT); pinMode(Y_OUT, INPUT); pinMode(Z_OUT, INPUT);