Archive for the ‘dc motors’ tag
Mouse Pad documentation second part (a few weeks after the piece is done)
Here is the second part of the documentation. It shows you the up and down of the project. We have photos of h bridges, dc motors relays and mouse hacking. We learn a lot about serial communication, dc motors, relays, and the most important how to work in group.
Below is the code we finally use:
// Analog Sensors
int analogOne = 0; // Left moving Sensor
int analogTwo = 1; // Up moving Sensor
int analogThree = 2; // Right moving Sensor
int analogFour = 3; // Down moving Sensor
// Digital sensors
int digitalOne = 12; // Left Mouse Click
int digitalTwo = 13; // Right Mouse Click
int relay1Pin = 2; // Relay for left click
int relay2Pin = 7; // Relay for right click
int leftClick = 0; //variable for the left click
int rightClick = 0; //variable for the right click
// For motor # 1
int motor1Pin = 10; // H-bridge leg 1 (pin 2, 1A)
int motor2Pin = 11; // H-bridge leg 2 (pin 7, 2A)
// For motor # 2
int motor3Pin = 5; // H-bridge leg 3? (pin ??, 1A)
int motor4Pin = 6; // H-bridge leg 4? (pin ??, 2A)
// Pin “9”
int enablePin = 9; // H-bridge enable pin
int enablePin2 = 8; // H-bridge enable pin2
int sensorValue = 0; // reading from the sensor
void setup() {
Serial.begin(9600);
pinMode(digitalOne, INPUT);
pinMode(digitalTwo, INPUT);
pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(motor3Pin, OUTPUT);
pinMode(motor4Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, HIGH);
pinMode(enablePin2, OUTPUT);
digitalWrite(enablePin2, HIGH);
}
void loop() {
if (analogRead(analogOne) > 100) {
//turn left
analogWrite(motor1Pin, 0); // set leg 1 of the H-bridge low
analogWrite(motor2Pin, 96); // set leg 2 of the H-bridge high
}
else {
//turn right
if (analogRead(analogThree) > 100) {
analogWrite(motor1Pin, 96); // set leg 1 of the H-bridge low
analogWrite(motor2Pin, 0); // set leg 2 of the H-bridge high
}
else {
// dont move left or right
analogWrite(motor1Pin, 0); // set leg 1 of the H-bridge low
analogWrite(motor2Pin, 0); // set leg 2 of the H-bridge low
}
}
if (analogRead(analogTwo) > 100) {
// Go up
analogWrite(motor3Pin, 0); // set leg 3 of the H-bridge low
analogWrite(motor4Pin, 96); // set leg 4 of the H-bridge high
}
else {
// Go down
if (analogRead(analogFour) > 100) {
analogWrite(motor3Pin, 96); // set leg 3 of the H-bridge high
analogWrite(motor4Pin, 0); // set leg 4 of the H-bridge low
}
else {
// Dont go up or down
analogWrite(motor3Pin, 0); // set leg 3 of the H-bridge low
analogWrite(motor4Pin, 0); // set leg 4 of the H-bridge low
}
}
// Mouse Clicks
leftClick = digitalRead(digitalOne);
if (leftClick > 0) {
digitalWrite(relay1Pin, HIGH); // Turn on relay 1
}
else {
digitalWrite(relay1Pin, LOW); // Turn off relay 1
}
rightClick = digitalRead(digitalTwo);
if (rightClick > 0) {
digitalWrite(relay2Pin, HIGH); // Turn on relay 2
}
else {
digitalWrite(relay2Pin, LOW); // Turn off relay 2
}
// Print the values to serial for monitoring
sensorValue = analogRead(analogOne);
Serial.print(sensorValue, DEC);
Serial.print(“,”);
sensorValue = analogRead(analogTwo);
Serial.print(sensorValue, DEC);
Serial.print(“,”);
sensorValue = analogRead(analogThree);
Serial.print(sensorValue, DEC);
Serial.print(“,”);
sensorValue = analogRead(analogFour);
Serial.print(sensorValue, DEC);
Serial.print(“,”);
sensorValue = digitalRead(digitalOne);
Serial.print(sensorValue, DEC);
Serial.print(“,”);
sensorValue = digitalRead(digitalTwo);
Serial.println(sensorValue, DEC);
}
Also Gordie made the second version of the housing of the mouse. This made the mouse pad more reliable. Below is the video

