My final project is degining a gravity car, the turing is controlled by the distance between the weight and the plate of car. And all the messages like the distance, circles the car has gone, the efficiency of tranfering from gravity to engrgy of motion, etc can send to phone. and all control like start, stop can execute by phone. This weel two boards were designed and build. One is the input devices with a blue tooth, the other is excuting devices and a blue tooth. They were showed in the fllowing figure.
Part 1 PCB Board Design
MCU attiny 44 X1
BLE CC2541 X1
Servo X2
LED red X1
LED green X1
FTDI X1
ISP 2X3pin X1
Capacitor for MCU X1
Capacitor for BLE X1
Resonator for MCU X1
Resistor for ISP X1
Resistor for led X2
Regulartor for BLE X1
Part 2 Create the board
Part 3 Soldering
Part 4 Programming and testing
For I have finished my final electronic board, so I programmed it in the final board, and I send the distance to phone.
#define TrigPin A4
#define EchoPin A5
float getDistance(void)
{
float distance;
// 产生一个10us的高脉冲去触发TrigPin
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
digitalWrite(TrigPin, HIGH);
delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
// 检测脉冲宽度,并计算出距离
distance = pulseIn(EchoPin, HIGH) / 58.00;
return distance;
}
void setup()
{
// 初始化串口通信及连接SR04的引脚
Serial.begin(9600);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
}
float dis = 0;
void loop()
{
dis = getDistance() * 10; //mm
Serial.println(dis);
delay(300);
}