This week assignement is about output devices, I designed a circuit with 9V DC motor as output device to implement vibration motion. I use sashakit board , H-bridge to drive the motor, Vout 5V regulator, and 10K potentiometer for analog input value. to eliminate motor noise in the code I add a threshold value of 500, the motor turn in one direction if the analog input value is greater than 500 if the value is less motor speed is 0. mapping speed increase to input value is (500-1023) to (0-255). I used the same board of input device project sashakit and 2X1 pin headers for VCC and GND and an H-bridge board here are the bridge shematic, board, the complete circuit, output device progarm, and video of the result.please find satshakit schematic and board in Input device project.
Dc motor block diagram
H-bridge schematic
H-bridge board
H-bridge board milled
H bridge driving DC Motor circuit
DC motor code
code
according to the schematic above in the code I declare constants for input and output pins
const int controlPin1 = 2; here to define that controlpin1 in Hbridge is connected to pin2 in satshakit board
const int controlPin2 = 3; controlpin2 in H bridge is connected to pin3 in satshakit board
const int enablePin = 9; enable pin in hbridge is connected to pin9 in satshakit board.
const int potpin = A0; input pin for potentiometer in A0 port in satshakit board.
int motorenabled = 0; define that motor enable is 0 in the beginning means motor is not enabled.
int motorspeed = 0; starting speed of the motor is 0.
int threshold = 500; threshold value is defined to 500
void setup() {
// declare input and output pins
setup section is to define input output pins in the IDE code
pinMode(controlPin1, OUTPUT); controlpin1 and contolpin2 are output ports value sent to h bridge to drive the dc motor forward or reverse
pinMode(controlPin2, OUTPUT);
pinMode(enablePin, OUTPUT); enable pin value is output pin in satshakit board and send to h bride to enable or disable the chip
digitalWrite(enablePin, LOW); enable pin is low means that the chip is not enabled in the beginning. motor is in stop state.
void loop(): here in this section reside the code of the card
{
if (analogRead(potpin) < threshold): I read input value of potentiometer in A0 port in satshakit board I turn potentiometer right and left one is to read ascending values or descending values accordng to the installation, values read fropotentiometer will be from 0 to 1023. here I compare the value read with threshol value 500.
{
motorenabled = 0; if condition is true means potentiometer input is less than 500 motor is not enabled
}
else
{
motorenabled = 1; if condition is false value read greater or equal 500 motor is enabled this is to filter the noise.
motorspeed = analogRead(potpin) / 4; this is to map values from 0-1023 to 0-255. this mapping is necessary because the motor speed should be within the range of 0-255.
}
digitalWrite(controlPin1, HIGH); at default state control pin1 is 1 and control pin2 is 0 this set the motor turning forward in one direction, if I want the motor to turn in the reverse direction these values should be LOW and HIGH respectively. here Im running motor in forward direction. digitalWrite(controlPin1, HIGH); digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
if (motorenabled == 1) check for motor enable value if 1 is enabled and we can send the speed of running to its input port, otherwise its not running and motor speed is 0.
{
analogWrite(enablePin, motorspeed); motor speed is the value read and mapped of the potentiometer, enable pin will receive the motor speed value as well if its different than 0.
}
else
{
analogWrite(enablePin, 0); if condition is false enable pin is 0 and motor speed is 0 as well, as the first state.
} close open brackets.
}
no need to install the bootloader this time for uploading program. board programming.
result on video
all sashakit_pot files you can find in input devices page. To download design on eagle and png files.
here is the design H-bridge board on eagle
here is the shematic H-bridge board on eagle
here is H-bridge board traces and outline.
here H-bridge driving Dc motor program in arduino IDE