Galileo code for DC motor speed control

Open the IDE and then enter the following code:

Galileo code for DC motor speed control

This code sends basic commands to the Galileo to control the speed of the motor. Here are the details:

  • int motorPin = 11;:- This sets digital I/O pin 11 to the control pin you'll be using.
  • void setup():– The setup function executes once you set up your Galileo.
  • pinMode(motorPin, OUTPUT);:- This sets this pin to function as an output pin.
  • Serial.begin(9600);:- This starts the serial port with a baud rate of 9600.
  • Serial.println("Set Speed 0 - 255");:- This prints the line "Set Speed 0 – 255".
  • void loop():– This loop is performed over and over again on the Galileo.
  • if (Serial.available()):– If there is a serial input date on the serial port, then do the following statements.
  • int speed = Serial.parseInt();:- This brings in the data as an integer.
  • Serial.println("Speed");:- This prints the line "Speed".
  • Serial.print(speed);:- This prints the value input from the serial port.
  • Serial.println(" " );:- This finishes the line and goes to the next line.
  • if (speed >= 0 && speed <= 255):– If the speed is in the proper range, then this sends it on.
  • analogWrite(motorPin, speed);:- This writes this value to the pin 11. This will set the PWM signal to the proper value to control the speed of the motor.

Now upload the code to your Galileo. Your motor should start running. Once you have uploaded the code, you'll want to open up the Serial Monitor so you can command your motor to run at different speeds. To open this, you'll select Tools | Serial Monitor. When you open this, you should see the following window pop up, displaying the text from your program:

Galileo code for DC motor speed control

Enter a value, say 255, and then click on Send. Your motor should speed up. Enter another number, say 0, click on Send, and your motor should stop. Numbers between these two values should adjust the speed of your DC motor. Unfortunately, the motor can only go in one direction. The next example will provide a solution if you'd like bidirectional control of your DC motor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.8.222